From 10c6967869a1bd9ad49e948b1836f9096ef000df Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 6 Mar 2023 15:25:41 +0800 Subject: [PATCH] update --- .../java/com/yutou/tools/other/tools.java | 157 ++++++++++-------- 1 file changed, 89 insertions(+), 68 deletions(-) diff --git a/src/main/java/com/yutou/tools/other/tools.java b/src/main/java/com/yutou/tools/other/tools.java index 260a4e3..9187f86 100644 --- a/src/main/java/com/yutou/tools/other/tools.java +++ b/src/main/java/com/yutou/tools/other/tools.java @@ -6,12 +6,11 @@ import com.yutou.tools.ToolsApplication; import com.yutou.tools.mybatis.dao.UKeyDao; import com.yutou.tools.mybatis.model.UKey; import com.yutou.tools.mybatis.model.UKeyExample; -import com.yutou.tools.utils.ConfigTools; import com.yutou.tools.utils.HttpTools; import com.yutou.tools.utils.RedisTools; import com.yutou.tools.utils.Tools; +import lombok.SneakyThrows; import org.springframework.core.io.FileSystemResource; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.util.StringUtils; @@ -66,6 +65,7 @@ public class tools { return ToolsApplication.version; } + @SneakyThrows @ResponseBody @RequestMapping("/public/request.do") public String testRequest(HttpServletRequest request) { @@ -81,11 +81,21 @@ public class tools { cookies.add(ck); } } + BufferedInputStream stream = new BufferedInputStream(request.getInputStream()); + byte[] bytes = new byte[1024]; + int len = 0, size; + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + while ((len = stream.read(bytes)) != -1) { + outputStream.write(bytes, 0, len); + outputStream.flush(); + } Enumeration enumeration = request.getHeaderNames(); while (enumeration != null && enumeration.hasMoreElements()) { String tmp = enumeration.nextElement(); header.put(tmp, request.getHeader(tmp)); } + String str = outputStream.toString(StandardCharsets.UTF_8); + System.out.println("str = " + str); JSONObject json = new JSONObject(); json.put("code", 0); json.put("method", request.getMethod()); @@ -95,7 +105,8 @@ public class tools { json.put("params", params); json.put("cookie", cookies); json.put("header", header); - Tools.sendServer("打印请求", json.toJSONString()); + System.out.println("json = " + json); + // Tools.sendServer("打印请求", json.toJSONString()); try { switch (RedisTools.get("request")) { case "success": @@ -148,115 +159,125 @@ public class tools { Tools.sendServer(title, msg); return "ok"; } + @ResponseBody - @RequestMapping(value="/tools/clash/get.do",produces ="text/plain;charset=utf-8") - public String getClash(){ - StringBuilder builder=new StringBuilder(); - String ssrUrl=RedisTools.get("ssr"); - String url="http://127.0.0.1:25500/sub?target=clash&new_name=true&url="+URLEncoder.encode(ssrUrl, StandardCharsets.UTF_8) +"&insert=false&config=https%3A%2F%2Fgit.yutou233.cn%2Fyutou%2FACL4SSR%2Fraw%2Fmaster%2FClash%2Fconfig%2FACL4SSR.ini"; - String text= HttpTools.get(url); - if(text==null){ + @RequestMapping(value = "/tools/clash/get.do", produces = "text/plain;charset=utf-8") + public String getClash(String ssr) { + StringBuilder builder = new StringBuilder(); + String ssrUrl = RedisTools.get("ssr"); + if (!StringUtils.isEmpty(ssr)) { + ssrUrl = ssr; + } + String url = "http://127.0.0.1:25500/sub?target=clash&new_name=true&url=" + URLEncoder.encode(ssrUrl, StandardCharsets.UTF_8) + "&insert=false&config=https%3A%2F%2Fgit.yutou233.cn%2Fyutou%2FACL4SSR%2Fraw%2Fbranch%2Fmaster%2FClash%2Fconfig%2FACL4SSR_Online_Full.ini"; + String text = HttpTools.get(url); + if (text == null) { System.out.println("ssr is Null = " + url); return ""; } - String[] tmp=text.split("\n"); - text=RedisTools.get("clash"); + String[] tmp = text.split("\n"); + text = RedisTools.get("clash"); builder.append("mixed-port: 7890").append("\n"); for (String s : tmp) { - if("port: 7890".equals(s)||"socks-port: 7891".equals(s)){ + if ("port: 7890".equals(s) || "socks-port: 7891".equals(s)) { continue; } builder.append(s).append("\n"); - if("rules:".equals(s.trim())){ - if(text!=null){ - JSONArray array=JSONArray.parseArray(text); + if ("rules:".equals(s.trim())) { + if (text != null) { + JSONArray array = JSONArray.parseArray(text); for (Object o : array) { - builder.append(" ").append(((JSONObject)o).getString("url").trim()).append("\n"); + builder.append(" ").append(((JSONObject) o).getString("url").trim()).append("\n"); } } } } return builder.toString(); } + @ResponseBody @RequestMapping("/tools/clash/ssr.do") - public JSONObject setClashSSR(String url){ - RedisTools.set("ssr",url); - JSONObject json=new JSONObject(); - json.put("msg","OK~"); + public JSONObject setClashSSR(String url) { + RedisTools.set("ssr", url); + JSONObject json = new JSONObject(); + json.put("msg", "OK~"); return json; } + @ResponseBody @RequestMapping("/tools/clash/getssr.do") - public JSONObject getClashSSR(){ - JSONObject json=new JSONObject(); - json.put("code",0); - json.put("data",RedisTools.get("ssr")); + public JSONObject getClashSSR() { + JSONObject json = new JSONObject(); + json.put("code", 0); + json.put("data", RedisTools.get("ssr")); return json; } + @ResponseBody @RequestMapping("/tools/clash/list.do") - public JSONObject clashList(){ - String text=RedisTools.get("clash"); + public JSONObject clashList() { + String text = RedisTools.get("clash"); JSONArray array; - if(text!=null){ - array=JSONArray.parseArray(text); - }else{ - array=new JSONArray(); + if (text != null) { + array = JSONArray.parseArray(text); + } else { + array = new JSONArray(); } - RedisTools.set("clash",array.toJSONString()); - JSONObject json=new JSONObject(); - json.put("code",0); - json.put("msg","ok~"); - json.put("data",array); - return json; + RedisTools.set("clash", array.toJSONString()); + JSONObject json = new JSONObject(); + json.put("code", 0); + json.put("msg", "ok~"); + json.put("data", array); + return json; } + @ResponseBody @RequestMapping("/tools/clash/add.do") - public JSONObject clashAddUrl(String url){ - String text=RedisTools.get("clash"); + public JSONObject clashAddUrl(String url) { + String text = RedisTools.get("clash"); JSONArray array; - if(text!=null){ - array=JSONArray.parseArray(text); - }else{ - array=new JSONArray(); + if (text != null) { + array = JSONArray.parseArray(text); + } else { + array = new JSONArray(); } - JSONObject data=new JSONObject(); - data.put("url",url); + JSONObject data = new JSONObject(); + data.put("url", url); array.add(data); - RedisTools.set("clash",array.toJSONString()); - JSONObject json=new JSONObject(); - json.put("code",0); - json.put("msg","ok~"); - return json; + RedisTools.set("clash", array.toJSONString()); + JSONObject json = new JSONObject(); + json.put("code", 0); + json.put("msg", "ok~"); + return json; } + @ResponseBody @RequestMapping("/tools/clash/del.do") - public JSONObject clashDelUrl(String url){ - String text=RedisTools.get("clash"); + public JSONObject clashDelUrl(String url) { + String text = RedisTools.get("clash"); JSONArray array; - if(text!=null){ - array=JSONArray.parseArray(text); - }else{ - array=new JSONArray(); + if (text != null) { + array = JSONArray.parseArray(text); + } else { + array = new JSONArray(); } - int delIndex=-1; + int delIndex = -1; for (int i = 0; i < array.size(); i++) { - JSONObject item=array.getJSONObject(i); - if(item.getString("url").trim().equals(url.trim())){ - delIndex=i; + JSONObject item = array.getJSONObject(i); + if (item.getString("url").trim().equals(url.trim())) { + delIndex = i; break; } } - if(delIndex!=-1){ - array.remove(delIndex); - } - RedisTools.set("clash",array.toJSONString()); - JSONObject json=new JSONObject(); - json.put("code",0); - json.put("msg","ok~"); - return json; + if (delIndex != -1) { + array.remove(delIndex); + } + RedisTools.set("clash", array.toJSONString()); + JSONObject json = new JSONObject(); + json.put("code", 0); + json.put("msg", "ok~"); + return json; } + public int getUid(HttpServletRequest request) { String token = request.getParameter("token"); if (StringUtils.isEmpty(token)) {