├── .editorconfig
├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
└── src
├── main
├── java
│ └── love
│ │ └── sola
│ │ └── netsupport
│ │ ├── Index.java
│ │ ├── api
│ │ ├── API.java
│ │ ├── APIRouter.java
│ │ ├── CheckSession.java
│ │ ├── Error.java
│ │ ├── Login.java
│ │ ├── manager
│ │ │ ├── GetUser.java
│ │ │ └── TicketPush.java
│ │ ├── root
│ │ │ ├── DashBoard.java
│ │ │ ├── FlushCache.java
│ │ │ └── SetPassword.java
│ │ ├── stuff
│ │ │ ├── TicketLog.java
│ │ │ ├── TicketLookup.java
│ │ │ ├── TicketTrack.java
│ │ │ ├── TicketUpdate.java
│ │ │ └── ToolsCheck.java
│ │ └── user
│ │ │ ├── ProfileModify.java
│ │ │ ├── Register.java
│ │ │ ├── TicketQuery.java
│ │ │ └── TicketSubmit.java
│ │ ├── auth
│ │ ├── OAuth2.java
│ │ └── OAuth2Handler.java
│ │ ├── config
│ │ ├── Lang.java
│ │ └── Settings.java
│ │ ├── enums
│ │ ├── Access.java
│ │ ├── Attribute.java
│ │ ├── Block.java
│ │ ├── ISP.java
│ │ ├── ISPConverter.java
│ │ └── Status.java
│ │ ├── pojo
│ │ ├── Operator.java
│ │ ├── Ticket.java
│ │ ├── ToolsCheck.java
│ │ └── User.java
│ │ ├── session
│ │ ├── MapSession.java
│ │ ├── MapSessionRepository.java
│ │ ├── WechatSession.java
│ │ └── WxSession.java
│ │ ├── sql
│ │ ├── SQLCore.java
│ │ ├── TableConfig.java
│ │ ├── TableOperator.java
│ │ ├── TableTicket.java
│ │ └── TableUser.java
│ │ ├── util
│ │ ├── Checker.java
│ │ ├── Crypto.java
│ │ ├── ParseUtil.java
│ │ └── Redirect.java
│ │ └── wechat
│ │ ├── Command.java
│ │ ├── WxMpServlet.java
│ │ ├── handler
│ │ ├── AutoReplyHandler.java
│ │ ├── CancelHandler.java
│ │ ├── ProfileHandler.java
│ │ ├── QueryHandler.java
│ │ ├── RegisterHandler.java
│ │ ├── SubmitHandler.java
│ │ ├── SubscribeHandler.java
│ │ └── admin
│ │ │ ├── LoginHandler.java
│ │ │ ├── OperatorInfoHandler.java
│ │ │ └── SignHandler.java
│ │ └── matcher
│ │ ├── CheckSpamMatcher.java
│ │ ├── CommandMatcher.java
│ │ └── RegisterMatcher.java
├── resources
│ ├── hibernate.cfg.xml
│ ├── lang.yml
│ ├── menu-op.json
│ └── menu.json
└── webapp
│ ├── META-INF
│ └── context.xml
│ ├── WEB-INF
│ └── web.xml
│ └── favicon.ico
└── test
└── java
└── love
└── sola
└── netsupport
├── api
└── ReflectionTest.java
├── config
└── ReflectionTest.java
├── enums
└── ReflectionTest.java
└── util
├── GsonTest.java
└── URLEncodeTest.java
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*]
2 | charset=utf-8
3 | end_of_line=lf
4 | trim_trailing_whitespace=true
5 | insert_final_newline=true
6 | indent_style=space
7 | indent_size=4
8 |
9 | [*.json]
10 | indent_style=space
11 | indent_size=2
12 |
13 | [{*.ddl,*.sql}]
14 | indent_style=space
15 | indent_size=2
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /docs
2 | .idea/
3 | *.iml
4 | /target
5 | .vscode
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WechatTicketSystem
2 | WechatTicketSystem is a basic ticket system for network maintaining, based on Wechat.
3 |
4 | ## Build
5 | ### Requirements
6 | - [Apache Maven](https://maven.apache.org/) (latest version recommended)
7 |
8 | ### Steps
9 | 1. Clone the git repository `git clone https://github.com/ZSCNetSupportDept/WechatTicketSystem.git`
10 | 2. Change dir to project root (where the `pom.xml` is)
11 | 3. Build with Maven `mvn clean package`
12 | 4. The out file will be in `target/` folder
13 |
14 | ## Contributing
15 | ### Code Style
16 | The code style configuration is [here](http://stash.sola.love/projects/PSS/repos/ide_configuration/browse/intellij%20idea/Code_Style_Use_Tab.xml).
17 |
18 | In Intellij IDEA, you can import the configuration by Settings-\>Editor-\>Code Style-\>Manage(at right side)-\>Import..
19 | ### Pull Request
20 | Please notice that the pull requests should compare with `develop` branch instead of `master`,
21 | submit pull requests to `master` branch will be ignored.
22 | ## TroubleShooting
23 | - Before you report a bug, please [search the issue tracker](https://github.com/ZSCNetSupportDept/WechatTicketSystem/issues) to see if someone has already reported the problem.
24 | - If the issue doesn’t already exist, [create a new issue](https://github.com/ZSCNetSupportDept/WechatTicketSystem/issues/new).
25 | - Please provide as much information as possible with the issue report, we like to know the version you are using, as well as your Operating System and JVM version.
26 | - If you need to paste code, or include a stack trace use Markdown ```` ``` ```` escapes before and after your text.
27 |
28 | ## License
29 | WechatTicketSystem is distributed under the GNU Lesser General Public License v3.0 (LGPLv3).
30 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | WechatTicketSystem
7 | love.sola.netsupport
8 | WechatTicketSystem
9 | 2.2-SNAPSHOT
10 | war
11 |
12 |
13 | UTF-8
14 | 1.8
15 | 1.8
16 | 1.8
17 |
18 |
19 |
20 |
21 |
22 | org.apache.maven.plugins
23 | maven-compiler-plugin
24 | 3.3
25 |
26 | 1.8
27 | 1.8
28 |
29 |
30 |
31 | org.apache.tomcat.maven
32 | tomcat7-maven-plugin
33 | 2.2
34 |
35 | http://localhost:8080/manager/text
36 | wwbx
37 | /WechatTicketSystem
38 |
39 |
40 |
41 | org.apache.maven.plugins
42 | maven-war-plugin
43 | 3.3.2
44 |
45 |
46 |
47 |
48 |
49 |
50 | javax.servlet
51 | javax.servlet-api
52 | 3.1.0
53 | provided
54 |
55 |
56 | junit
57 | junit
58 | 4.12
59 | test
60 |
61 |
62 | org.slf4j
63 | slf4j-simple
64 | 1.7.12
65 |
66 |
67 | com.google.guava
68 | guava
69 | 19.0-rc2
70 |
71 |
72 | com.google.code.gson
73 | gson
74 | 2.4
75 |
76 |
77 | org.apache.commons
78 | commons-io
79 | 1.3.2
80 |
81 |
82 | org.apache.commons
83 | commons-lang3
84 | 3.4
85 |
86 |
87 | commons-net
88 | commons-net
89 | 3.3
90 |
91 |
92 | me.chanjar
93 | weixin-java-mp
94 | 1.3.3
95 |
96 |
97 | com.mchange
98 | c3p0
99 | 0.9.5.4
100 |
101 |
102 | mysql
103 | mysql-connector-java
104 | 5.1.37
105 |
106 |
107 | org.hibernate
108 | hibernate-core
109 | 5.0.3.Final
110 |
111 |
112 | org.hibernate
113 | hibernate-entitymanager
114 | 5.0.3.Final
115 |
116 |
117 | org.hibernate
118 | hibernate-c3p0
119 | 5.0.3.Final
120 |
121 |
122 | org.hibernate.javax.persistence
123 | hibernate-jpa-2.1-api
124 | 1.0.0.Final
125 |
126 |
127 | org.hibernate
128 | hibernate-envers
129 | 5.0.3.Final
130 |
131 |
132 | de.svenkubiak
133 | jBCrypt
134 | 0.4
135 |
136 |
137 | org.yaml
138 | snakeyaml
139 | 1.16
140 |
141 |
142 | org.reflections
143 | reflections
144 | 0.9.10
145 |
146 |
147 |
148 |
--------------------------------------------------------------------------------
/src/main/java/love/sola/netsupport/Index.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of WechatTicketSystem.
3 | *
4 | * WechatTicketSystem is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * WechatTicketSystem is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with WechatTicketSystem. If not, see .
16 | */
17 |
18 | package love.sola.netsupport;
19 |
20 | import java.io.IOException;
21 | import java.io.PrintWriter;
22 |
23 | import javax.servlet.ServletException;
24 | import javax.servlet.annotation.WebServlet;
25 | import javax.servlet.http.HttpServlet;
26 | import javax.servlet.http.HttpServletRequest;
27 | import javax.servlet.http.HttpServletResponse;
28 |
29 | /**
30 | * @author Sola {@literal }
31 | */
32 | @WebServlet(name = "Index", urlPatterns = "/index", loadOnStartup = 1)
33 | public class Index extends HttpServlet {
34 |
35 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
36 | doGet(request, response);
37 | }
38 |
39 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
40 | request.setCharacterEncoding("utf-8");
41 | response.addHeader("Content-type", "text/plain;charset=utf-8");
42 | response.setCharacterEncoding("utf-8");
43 | PrintWriter out = response.getWriter();
44 | out.println("Wechat Ticket System (WTS) 0.1 Copyright 2015-2016 Sola & LiuYue all rights reserved. | Commercial license for ZSC Network Support Department (ZSCNSD).");
45 | out.println("For any problem, Please contact loli@sola.love.");
46 | if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
47 | out.println("\nError 404: Page not found.");
48 | }
49 | out.close();
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/love/sola/netsupport/api/API.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of WechatTicketSystem.
3 | *
4 | * WechatTicketSystem is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * WechatTicketSystem is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with WechatTicketSystem. If not, see .
16 | */
17 |
18 | package love.sola.netsupport.api;
19 |
20 | import org.apache.commons.lang3.time.DateUtils;
21 |
22 | import java.util.Calendar;
23 | import java.util.Date;
24 |
25 | import javax.servlet.http.HttpServletRequest;
26 |
27 | import love.sola.netsupport.enums.Access;
28 | import love.sola.netsupport.session.WxSession;
29 | import love.sola.netsupport.wechat.Command;
30 |
31 | /**
32 | * @author Sola {@literal }
33 | */
34 | public abstract class API {
35 |
36 | public String url = null; //url
37 | public int access = Access.GOD_MODE; //operator's permission
38 | public Command authorize = null; //session check
39 |
40 | protected abstract Object process(HttpServletRequest req, WxSession session) throws Exception;
41 |
42 | @Override
43 | public String toString() {
44 | return getClass().getSimpleName() + "{" +
45 | "url='" + url + '\'' +
46 | ", access=" + Access.inverseMap.get(access) +
47 | ", authorize=" + authorize +
48 | '}';
49 | }
50 |
51 | public static String getParameterWithDefault(String obj, String def) {
52 | return obj == null ? def : obj;
53 | }
54 |
55 | public static Date getParameterAsDate(String obj, Date def) {
56 | return obj == null ? def : new Date(Long.valueOf(obj));
57 | }
58 |
59 | public static Date getToday() {
60 | return DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
61 | }
62 |
63 | public static Date getDay(Date date) {
64 | return DateUtils.truncate(date, Calendar.DAY_OF_MONTH);
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/love/sola/netsupport/api/APIRouter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of WechatTicketSystem.
3 | *
4 | * WechatTicketSystem is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * WechatTicketSystem is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with WechatTicketSystem. If not, see .
16 | */
17 |
18 | package love.sola.netsupport.api;
19 |
20 | import com.google.gson.Gson;
21 |
22 | import org.hibernate.HibernateException;
23 | import org.reflections.Reflections;
24 |
25 | import java.io.IOException;
26 | import java.io.PrintWriter;
27 | import java.text.ParseException;
28 | import java.util.HashMap;
29 | import java.util.Map;
30 | import java.util.Set;
31 |
32 | import javax.servlet.ServletException;
33 | import javax.servlet.annotation.WebServlet;
34 | import javax.servlet.http.HttpServlet;
35 | import javax.servlet.http.HttpServletRequest;
36 | import javax.servlet.http.HttpServletResponse;
37 |
38 | import love.sola.netsupport.enums.Access;
39 | import love.sola.netsupport.enums.Attribute;
40 | import love.sola.netsupport.pojo.Operator;
41 | import love.sola.netsupport.pojo.User;
42 | import love.sola.netsupport.session.WechatSession;
43 | import love.sola.netsupport.session.WxSession;
44 | import love.sola.netsupport.sql.SQLCore;
45 |
46 | /**
47 | * @author Sola {@literal }
48 | */
49 | @WebServlet(name = "APIRouter", urlPatterns = "/api/*", loadOnStartup = 11)
50 | public class APIRouter extends HttpServlet {
51 |
52 | protected static Gson gson = SQLCore.gson;
53 | private Map nodes = new HashMap<>();
54 |
55 | @Override
56 | public void init() throws ServletException {
57 | super.init();
58 | try {
59 | Reflections reflections = new Reflections(getClass().getPackage().getName());
60 | Set> set = reflections.getSubTypesOf(API.class);
61 | for (Class extends API> clz : set) {
62 | try {
63 | System.out.println("Loading API: " + clz.getName());
64 | API obj = clz.newInstance();
65 | System.out.println("Registered API: " + obj);
66 | nodes.put(obj.url, obj);
67 | } catch (InstantiationException | IllegalAccessException e) {
68 | e.printStackTrace();
69 | }
70 | }
71 | } catch (Exception e) {
72 | e.printStackTrace();
73 | }
74 | System.out.println("Total " + nodes.size() + " API(s) loaded.");
75 | }
76 |
77 | @Override
78 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
79 | req.setCharacterEncoding("utf-8");
80 | resp.setCharacterEncoding("utf-8");
81 | resp.addHeader("Content-type", "application/json;charset=utf-8");
82 | resp.addHeader("Access-Control-Allow-Origin", "*");
83 | Object obj = null;
84 | try {
85 | API api = nodes.get(req.getPathInfo());
86 | if (api == null) {
87 | resp.sendError(HttpServletResponse.SC_FORBIDDEN);
88 | return;
89 | }
90 | WxSession session = getSession(req);
91 | if (session == null) {
92 | obj = Error.UNAUTHORIZED;
93 | return;
94 | }
95 | if (api.authorize != null) {
96 | if (session.getAttribute(Attribute.AUTHORIZED) != api.authorize) {
97 | obj = Error.UNAUTHORIZED;
98 | return;
99 | }
100 | if (api.access == Access.USER) {
101 | User u = session.getAttribute(Attribute.USER);
102 | if (u == null) {
103 | obj = Error.UNAUTHORIZED;
104 | return;
105 | }
106 | }
107 | if (api.access < Access.USER) {
108 | Operator op = session.getAttribute(Attribute.OPERATOR);
109 | if (op == null) {
110 | obj = Error.UNAUTHORIZED;
111 | return;
112 | }
113 | if (op.getAccess() > api.access) {
114 | obj = Error.PERMISSION_DENIED;
115 | return;
116 | }
117 | }
118 | }
119 | obj = api.process(req, session);
120 | } catch (ParseException | NumberFormatException e) {
121 | obj = Error.ILLEGAL_PARAMETER;
122 | } catch (HibernateException e) {
123 | e.printStackTrace();
124 | obj = Error.DATABASE_ERROR;
125 | } catch (Exception e) {
126 | e.printStackTrace();
127 | obj = Error.INTERNAL_ERROR;
128 | } finally {
129 | if (!resp.isCommitted()) {
130 | try (PrintWriter out = resp.getWriter()) {
131 | out.println(gson.toJson(obj));
132 | }
133 | }
134 | }
135 | }
136 |
137 | @Override
138 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
139 | doGet(req, resp);
140 | }
141 |
142 | @Override
143 | protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
144 | resp.addHeader("Access-Control-Allow-Method", "POST, GET, OPTIONS");
145 | resp.addHeader("Access-Control-Allow-Origin", "*");
146 | resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
147 | }
148 |
149 | private static WxSession getSession(HttpServletRequest req) {
150 | String t = req.getParameter("token");
151 | if (t == null || t.isEmpty()) return null;
152 | return WechatSession.get(t);
153 | }
154 |
155 | }
156 |
--------------------------------------------------------------------------------
/src/main/java/love/sola/netsupport/api/CheckSession.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of WechatTicketSystem.
3 | *
4 | * WechatTicketSystem is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * WechatTicketSystem is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with WechatTicketSystem. If not, see .
16 | */
17 |
18 | package love.sola.netsupport.api;
19 |
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | import javax.servlet.http.HttpServletRequest;
24 |
25 | import love.sola.netsupport.enums.Access;
26 | import love.sola.netsupport.enums.Attribute;
27 | import love.sola.netsupport.session.WxSession;
28 |
29 | /**
30 | * @author Sola {@literal }
31 | */
32 | public class CheckSession extends API {
33 |
34 | public CheckSession() {
35 | url = "/checksession";
36 | access = Access.GUEST;
37 | authorize = null;
38 | }
39 |
40 | @Override
41 | protected Object process(HttpServletRequest req, WxSession session) throws Exception {
42 | String more = req.getParameter("more");
43 | Map result = new HashMap<>();
44 | result.put(Attribute.AUTHORIZED, session.getAttribute(Attribute.AUTHORIZED));
45 | if (more != null) {
46 | switch (more) {
47 | case "1":
48 | result.put(Attribute.USER, session.getAttribute(Attribute.USER));
49 | result.put(Attribute.OPERATOR, session.getAttribute(Attribute.OPERATOR));
50 | break;
51 | }
52 | }
53 | return result;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/love/sola/netsupport/api/Error.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of WechatTicketSystem.
3 | *
4 | * WechatTicketSystem is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * WechatTicketSystem is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with WechatTicketSystem. If not, see .
16 | */
17 |
18 | package love.sola.netsupport.api;
19 |
20 | import static love.sola.netsupport.config.Lang.lang;
21 |
22 | /**
23 | * @author Sola {@literal }
24 | */
25 | public class Error {
26 |
27 | public static final Error ALREADY_SUBMITTED = new Error(1);
28 | public static final Object OK = new Object();
29 | public static final Error PARAMETER_REQUIRED = new Error(-1);
30 | public static final Error ILLEGAL_PARAMETER = new Error(-2);
31 | // public static final Error REQUEST_FAILED = new Error(-3); REMOVED
32 | public static final Error LENGTH_LIMIT_EXCEEDED = new Error(-4);
33 | public static final Error INVALID_PARAMETER = new Error(-5);
34 | public static final Error USER_NOT_FOUND = new Error(-11);
35 | public static final Error TICKET_NOT_FOUND = new Error(-12);
36 | public static final Error OPERATOR_NOT_FOUND = new Error(-13);
37 | public static final Error UNAUTHORIZED = new Error(-20);
38 | public static final Error WRONG_PASSWORD = new Error(-22);
39 | public static final Error PERMISSION_DENIED = new Error(-24);
40 | public static final Error INTERNAL_ERROR = new Error(-90);
41 | public static final Error DATABASE_ERROR = new Error(-91);
42 |
43 | public int errCode;
44 | public String errMsg;
45 |
46 | private Error(int code) {
47 | this(code, lang("ERR_" + code));
48 | }
49 |
50 | public Error(int errCode, String errMsg) {
51 | this.errCode = errCode;
52 | this.errMsg = errMsg;
53 | }
54 |
55 | public Error withMsg(String msg) {
56 | return new Error(errCode, msg);
57 | }
58 |
59 | }
--------------------------------------------------------------------------------
/src/main/java/love/sola/netsupport/api/Login.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of WechatTicketSystem.
3 | *
4 | * WechatTicketSystem is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * WechatTicketSystem is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with WechatTicketSystem. If not, see .
16 | */
17 |
18 | package love.sola.netsupport.api;
19 |
20 | import com.google.gson.Gson;
21 |
22 | import java.io.IOException;
23 | import java.io.PrintWriter;
24 |
25 | import javax.servlet.ServletException;
26 | import javax.servlet.annotation.WebServlet;
27 | import javax.servlet.http.HttpServlet;
28 | import javax.servlet.http.HttpServletRequest;
29 | import javax.servlet.http.HttpServletResponse;
30 |
31 | import love.sola.netsupport.enums.Access;
32 | import love.sola.netsupport.enums.Attribute;
33 | import love.sola.netsupport.pojo.Operator;
34 | import love.sola.netsupport.pojo.User;
35 | import love.sola.netsupport.session.WechatSession;
36 | import love.sola.netsupport.session.WxSession;
37 | import love.sola.netsupport.sql.SQLCore;
38 | import love.sola.netsupport.sql.TableOperator;
39 | import love.sola.netsupport.sql.TableUser;
40 | import love.sola.netsupport.util.Crypto;
41 | import love.sola.netsupport.wechat.Command;
42 |
43 | /**
44 | * @author Sola {@literal }
45 | */
46 |
47 | @WebServlet(name = "Login", urlPatterns = "/api/admin/login", loadOnStartup = 12)
48 | public class Login extends HttpServlet {
49 |
50 | private Gson gson = SQLCore.gson;
51 |
52 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
53 | doGet(request, response);
54 | }
55 |
56 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
57 | request.setCharacterEncoding("utf-8");
58 | response.setCharacterEncoding("utf-8");
59 | response.addHeader("Content-type", "application/json;charset=utf-8");
60 | response.addHeader("Access-Control-Allow-Origin", "*");
61 | PrintWriter out = response.getWriter();
62 | out.println(gson.toJson(login(request)));
63 | out.close();
64 | }
65 |
66 | private Object login(HttpServletRequest request) {
67 | try {
68 | int oid = Integer.parseInt(request.getParameter("id"));
69 | String password = request.getParameter("pass");
70 | boolean bypass = request.getParameter("bypass") != null;
71 | Operator op = TableOperator.get(oid);
72 | if (op == null)
73 | return Error.OPERATOR_NOT_FOUND;
74 | else if (op.getAccess() >= Access.NO_LOGIN)
75 | return Error.PERMISSION_DENIED;
76 |
77 | if (!Crypto.check(password, op.getPassword())) {
78 | return Error.WRONG_PASSWORD;
79 | }
80 |
81 | WxSession session = WechatSession.create();
82 | if (bypass) {
83 | session.setAttribute(Attribute.AUTHORIZED, Command.fromId(Integer.parseInt(request.getParameter("bypass"))));
84 | } else {
85 | session.setAttribute(Attribute.AUTHORIZED, Command.LOGIN);
86 | }
87 |
88 | session.setAttribute(Attribute.WECHAT, op.getWechat());
89 | session.setAttribute(Attribute.OPERATOR, op);
90 |
91 | if (request.getParameter("bypassuser") != null) {
92 | User u = TableUser.getById(Long.parseLong(request.getParameter("bypassuser")));
93 | session.setAttribute(Attribute.USER, u);
94 | session.setAttribute(Attribute.WECHAT, u.getWechatId());
95 | }
96 | if (request.getParameter("bypasswechat") != null) {
97 | session.setAttribute(Attribute.WECHAT, request.getParameter("bypasswechat"));
98 | }
99 | return session.getId();
100 | } catch (Exception e) {
101 | e.printStackTrace();
102 | return Error.INTERNAL_ERROR;
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/love/sola/netsupport/api/manager/GetUser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of WechatTicketSystem.
3 | *
4 | * WechatTicketSystem is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * WechatTicketSystem is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with WechatTicketSystem. If not, see .
16 | */
17 |
18 | package love.sola.netsupport.api.manager;
19 |
20 | import javax.servlet.http.HttpServletRequest;
21 |
22 | import love.sola.netsupport.api.API;
23 | import love.sola.netsupport.api.Error;
24 | import love.sola.netsupport.enums.Access;
25 | import love.sola.netsupport.pojo.User;
26 | import love.sola.netsupport.session.WxSession;
27 | import love.sola.netsupport.sql.TableUser;
28 | import love.sola.netsupport.wechat.Command;
29 |
30 | /**
31 | * @author Sola {@literal }
32 | */
33 | public class GetUser extends API {
34 |
35 | public GetUser() {
36 | url = "/admin/getuser";
37 | access = Access.LEADER;
38 | authorize = Command.LOGIN;
39 | }
40 |
41 | @Override
42 | protected Object process(HttpServletRequest req, WxSession session) throws Exception {
43 | String id = req.getParameter("id");
44 | String name = req.getParameter("name");
45 | if ((id == null || id.isEmpty()) && (name == null || name.isEmpty())) {
46 | return Error.PARAMETER_REQUIRED;
47 | }
48 | if (id != null) {
49 | try {
50 | User u = TableUser.getById(Long.parseLong(id));
51 | if (u == null)
52 | return Error.USER_NOT_FOUND;
53 | else
54 | return u;
55 | } catch (NumberFormatException e) {
56 | return Error.ILLEGAL_PARAMETER;
57 | }
58 | } else {
59 | User u = TableUser.getByName(name);
60 | if (u == null)
61 | return Error.USER_NOT_FOUND;
62 | else
63 | return u;
64 | }
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/love/sola/netsupport/api/manager/TicketPush.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of WechatTicketSystem.
3 | *
4 | * WechatTicketSystem is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * WechatTicketSystem is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with WechatTicketSystem. If not, see .
16 | */
17 |
18 | package love.sola.netsupport.api.manager;
19 |
20 | import org.hibernate.Session;
21 |
22 | import javax.servlet.http.HttpServletRequest;
23 |
24 | import love.sola.netsupport.api.API;
25 | import love.sola.netsupport.api.Error;
26 | import love.sola.netsupport.config.Settings;
27 | import love.sola.netsupport.enums.Access;
28 | import love.sola.netsupport.enums.Attribute;
29 | import love.sola.netsupport.enums.Status;
30 | import love.sola.netsupport.pojo.Operator;
31 | import love.sola.netsupport.pojo.Ticket;
32 | import love.sola.netsupport.pojo.User;
33 | import love.sola.netsupport.session.WxSession;
34 | import love.sola.netsupport.sql.SQLCore;
35 | import love.sola.netsupport.util.Checker;
36 | import love.sola.netsupport.wechat.Command;
37 |
38 | /**
39 | * @author Sola {@literal }
40 | */
41 | public class TicketPush extends API {
42 |
43 | public TicketPush() {
44 | url = "/admin/ticketpush";
45 | access = Access.LEADER;
46 | authorize = Command.LOGIN;
47 | }
48 |
49 | @Override
50 | protected Object process(HttpServletRequest req, WxSession session) throws Exception {
51 | String uid = req.getParameter("uid");
52 | String desc = req.getParameter("desc");
53 | if (Checker.hasNull(uid, desc)) {
54 | return Error.PARAMETER_REQUIRED;
55 | }
56 | if (desc.length() > Settings.MAX_DESC_LENGTH) {
57 | return Error.LENGTH_LIMIT_EXCEEDED;
58 | }
59 | Operator op = session.getAttribute(Attribute.OPERATOR);
60 | try (Session s = SQLCore.sf.openSession()) {
61 | s.beginTransaction();
62 | User u = s.get(User.class, Long.parseLong(uid));
63 | if (u == null) {
64 | return Error.USER_NOT_FOUND;
65 | }
66 | Ticket t = new Ticket(u, desc, null, "Pushed By Admin", null, op, Status.UNCHECKED);
67 | s.save(t);
68 | s.getTransaction().commit();
69 | return t;
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/love/sola/netsupport/api/root/DashBoard.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of WechatTicketSystem.
3 | *
4 | * WechatTicketSystem is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * WechatTicketSystem is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with WechatTicketSystem. If not, see .
16 | */
17 |
18 | package love.sola.netsupport.api.root;
19 |
20 | import java.util.Set;
21 |
22 | import javax.servlet.http.HttpServletRequest;
23 |
24 | import love.sola.netsupport.api.API;
25 | import love.sola.netsupport.enums.Access;
26 | import love.sola.netsupport.session.WechatSession;
27 | import love.sola.netsupport.session.WxSession;
28 | import love.sola.netsupport.wechat.Command;
29 |
30 | /**
31 | * @author Sola {@literal }
32 | */
33 | public class DashBoard extends API {
34 |
35 | public DashBoard() {
36 | url = "/root/dashboard";
37 | access = Access.ROOT;
38 | authorize = Command.LOGIN;
39 | }
40 |
41 | @Override
42 | protected Object process(HttpServletRequest req, WxSession session) throws Exception {
43 | StringBuilder sb = new StringBuilder();
44 | for (love.sola.netsupport.session.WxSession ws : WechatSession.list()) {
45 | sb.append("=====").append(ws.getId()).append("=====\n");
46 | Set e = ws.getAttributeNames();
47 | for (String key : e) {
48 | sb.append(key).append(": ").append(ws.getAttribute(key).toString()).append("\n");
49 | }
50 | }
51 | return sb.toString();
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/love/sola/netsupport/api/root/FlushCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of WechatTicketSystem.
3 | *
4 | * WechatTicketSystem is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * WechatTicketSystem is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with WechatTicketSystem. If not, see .
16 | */
17 |
18 | package love.sola.netsupport.api.root;
19 |
20 | import javax.servlet.http.HttpServletRequest;
21 |
22 | import love.sola.netsupport.api.API;
23 | import love.sola.netsupport.api.Error;
24 | import love.sola.netsupport.enums.Access;
25 | import love.sola.netsupport.session.WxSession;
26 | import love.sola.netsupport.sql.TableUser;
27 | import love.sola.netsupport.wechat.Command;
28 |
29 | /**
30 | * @author Sola {@literal }
31 | */
32 | public class FlushCache extends API {
33 |
34 | public FlushCache() {
35 | url = "/root/flushcache";
36 | access = Access.ROOT;
37 | authorize = Command.LOGIN;
38 | }
39 |
40 | @Override
41 | protected Object process(HttpServletRequest req, WxSession session) throws Exception {
42 | TableUser.flushCache();
43 | return Error.OK;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/love/sola/netsupport/api/root/SetPassword.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of WechatTicketSystem.
3 | *
4 | * WechatTicketSystem is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * WechatTicketSystem is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with WechatTicketSystem. If not, see .
16 | */
17 |
18 | package love.sola.netsupport.api.root;
19 |
20 | import org.hibernate.Session;
21 |
22 | import javax.servlet.http.HttpServletRequest;
23 |
24 | import love.sola.netsupport.api.API;
25 | import love.sola.netsupport.api.Error;
26 | import love.sola.netsupport.enums.Access;
27 | import love.sola.netsupport.pojo.Operator;
28 | import love.sola.netsupport.session.WxSession;
29 | import love.sola.netsupport.sql.SQLCore;
30 | import love.sola.netsupport.util.Crypto;
31 | import love.sola.netsupport.wechat.Command;
32 |
33 | /**
34 | * @author Sola {@literal }
35 | */
36 | public class SetPassword extends API {
37 |
38 | public SetPassword() {
39 | url = "/root/setpass";
40 | access = Access.ROOT;
41 | authorize = Command.LOGIN;
42 | }
43 |
44 | @Override
45 | protected Object process(HttpServletRequest req, WxSession session) throws Exception {
46 | String id = req.getParameter("id");
47 | String pass = req.getParameter("pass");
48 | if (pass == null || pass.length() < 8) {
49 | return Error.INVALID_PARAMETER;
50 | }
51 | try (Session s = SQLCore.sf.openSession()) {
52 | s.beginTransaction();
53 | Operator op = s.get(Operator.class, Integer.parseInt(id));
54 | if (op == null) {
55 | return Error.OPERATOR_NOT_FOUND;
56 | }
57 | op.setPassword(Crypto.hash(pass));
58 | s.update(op);
59 | s.getTransaction().commit();
60 | return Error.OK;
61 | }
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/love/sola/netsupport/api/stuff/TicketLog.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of WechatTicketSystem.
3 | *
4 | * WechatTicketSystem is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * WechatTicketSystem is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with WechatTicketSystem. If not, see .
16 | */
17 |
18 | package love.sola.netsupport.api.stuff;
19 |
20 | import love.sola.netsupport.api.API;
21 | import love.sola.netsupport.enums.Access;
22 | import love.sola.netsupport.pojo.Ticket;
23 | import love.sola.netsupport.pojo.User;
24 | import love.sola.netsupport.session.WxSession;
25 | import love.sola.netsupport.sql.SQLCore;
26 | import love.sola.netsupport.sql.TableTicket;
27 | import love.sola.netsupport.wechat.Command;
28 | import org.apache.commons.lang3.time.DateUtils;
29 | import org.hibernate.Session;
30 | import org.hibernate.envers.AuditReader;
31 | import org.hibernate.envers.query.AuditEntity;
32 | import org.hibernate.proxy.HibernateProxy;
33 |
34 | import javax.servlet.http.HttpServletRequest;
35 | import java.text.SimpleDateFormat;
36 | import java.util.Date;
37 | import java.util.List;
38 |
39 | /**
40 | * @author Sola {@literal }
41 | */
42 | public class TicketLog extends API {
43 |
44 | public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
45 |
46 | public TicketLog() {
47 | url = "/admin/ticketlog";
48 | access = Access.MEMBER;
49 | authorize = Command.LOGIN;
50 | }
51 |
52 | @SuppressWarnings("unchecked")
53 | @Override
54 | protected Object process(HttpServletRequest req, WxSession session) throws Exception {
55 | int first;
56 | int limit;
57 | Date start;
58 | Date end;
59 | first = req.getParameter("first") == null ? 0 : Integer.parseInt(req.getParameter("first"));
60 | limit = req.getParameter("limit") == null ? 20 : Integer.parseInt(req.getParameter("limit"));
61 | start = req.getParameter("start") == null ? getToday() : dateFormat.parse(req.getParameter("start"));
62 | end = req.getParameter("end") == null ? getToday() : dateFormat.parse(req.getParameter("end"));
63 | end = DateUtils.addDays(end, 1);
64 | try (Session s = SQLCore.sf.openSession()) {
65 | AuditReader reader = TableTicket.getAuditReader(s);
66 | List