322 lines
12 KiB
Java
322 lines
12 KiB
Java
package com.yutou.tools.other;
|
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
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.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.ResponseEntity;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.Cookie;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.*;
|
|
import java.net.URLEncoder;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Enumeration;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
|
|
@Controller
|
|
public class tools {
|
|
@Resource
|
|
UKeyDao keyDao;
|
|
|
|
@ResponseBody
|
|
@RequestMapping(value = "/tools/get.do")
|
|
public String getJs(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
Enumeration<String> name = request.getHeaderNames();
|
|
while (name.hasMoreElements()) {
|
|
String na = name.nextElement();
|
|
System.out.println(na + " " + request.getHeader(na));
|
|
}
|
|
File file = new File("D:\\IDEA\\web_toolset\\web\\js\\my.js");
|
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
|
String tmp, str = "";
|
|
while ((tmp = reader.readLine()) != null) {
|
|
if (tmp.contains("\"")) {
|
|
// tmp=tmp.replace("\"","\\\"");
|
|
}
|
|
str += tmp;
|
|
}
|
|
reader.close();
|
|
/* response.setHeader("Content-Type","application/javascript; charset=utf-8");
|
|
PrintWriter writer=response.getWriter();
|
|
writer.write(str);
|
|
writer.flush();
|
|
writer.close();*/
|
|
return str;
|
|
//return "function test(){ return \"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1588139022200&di=8cc8405f7514dd54bd82fcd070349603&imgtype=0&src=http%3A%2F%2Fa2.att.hudong.com%2F36%2F48%2F19300001357258133412489354717.jpg\" }";
|
|
}
|
|
|
|
@RequestMapping("/public/version.do")
|
|
@ResponseBody
|
|
public String getVersion() {
|
|
return ToolsApplication.version;
|
|
}
|
|
|
|
@SneakyThrows
|
|
@ResponseBody
|
|
@RequestMapping("/public/request.do")
|
|
|
|
public String testRequest(HttpServletRequest request) {
|
|
return testRequest(request, null);
|
|
}
|
|
@ResponseBody
|
|
@RequestMapping("/public/file/request.do")
|
|
public String testRequest(HttpServletRequest request, @RequestParam("file")MultipartFile file) {
|
|
JSONObject params = new JSONObject();
|
|
JSONArray cookies = new JSONArray();
|
|
JSONObject header = new JSONObject();
|
|
for (String key : request.getParameterMap().keySet()) {
|
|
params.put(key, request.getParameter(key));
|
|
}
|
|
if (request.getCookies() != null) {
|
|
for (Cookie cookie : request.getCookies()) {
|
|
JSONObject ck = JSONObject.parseObject(JSONObject.toJSONString(cookie));
|
|
cookies.add(ck);
|
|
}
|
|
}
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
try {
|
|
BufferedInputStream stream = new BufferedInputStream(request.getInputStream());
|
|
byte[] bytes = new byte[1024];
|
|
int len = 0, size;
|
|
while ((len = stream.read(bytes)) != -1) {
|
|
outputStream.write(bytes, 0, len);
|
|
outputStream.flush();
|
|
}
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
|
|
Enumeration<String> 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());
|
|
json.put("address", Tools.getRemoteAddress(request));
|
|
json.put("UA", request.getHeader("User-Agent"));
|
|
json.put("addressUrl", request.getPathInfo());
|
|
json.put("params", params);
|
|
json.put("cookie", cookies);
|
|
json.put("header", header);
|
|
System.out.println("json = " + json);
|
|
// Tools.sendServer("打印请求", json.toJSONString());
|
|
if(file!=null){
|
|
try {
|
|
Tools.createFile("tmp",file,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).format(new Date())+".zip");
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
Tools.sendServer("打印请求", json.toJSONString());
|
|
try {
|
|
switch (RedisTools.get("request")) {
|
|
case "success":
|
|
return "success";
|
|
case "-999":
|
|
case "param":
|
|
return json.toJSONString();
|
|
default:
|
|
return RedisTools.get("request");
|
|
}
|
|
} catch (Exception e) {
|
|
// e.printStackTrace();
|
|
}
|
|
|
|
return json.toJSONString();
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping("/private/request.do")
|
|
public String setRequest(String ret, String data) {
|
|
switch (ret) {
|
|
case "success":
|
|
RedisTools.set("request", "success");
|
|
break;
|
|
case "user":
|
|
RedisTools.set("request", data);
|
|
break;
|
|
default:
|
|
RedisTools.set("request", "param");
|
|
break;
|
|
}
|
|
return RedisTools.get("request");
|
|
}
|
|
|
|
@RequestMapping("/public/video.do")
|
|
public ResponseEntity<FileSystemResource> getVideo() {
|
|
return Tools.getFile(new File("Z:\\download\\anim\\鬼灭之刃\\[BeanSub&FZSD&LoliHouse] Kimetsu no Yaiba - 07 [WebRip 1080p HEVC-10bit AAC ASSx2]\\[BeanSub&FZSD&LoliHouse] Kimetsu no Yaiba - 07 [WebRip 1080p HEVC-10bit AAC ASSx2].mkv"));
|
|
}
|
|
|
|
//ffmpeg -i "[NC-Raws] 小林家的龙女仆S - 01 [B-Global][WEB-DL][2160p][AVC AAC][CHS_CHT_ENG_TH_SRT][MKV].mkv" -vn -an -map 0:2 sub2.srt
|
|
@RequestMapping("/public/sub.srt")
|
|
public ResponseEntity<FileSystemResource> getVideoSub() {
|
|
|
|
return Tools.getFile(new File("Z:\\download\\anim\\鬼灭之刃\\[BeanSub&FZSD&LoliHouse] Kimetsu no Yaiba - 07 [WebRip 1080p HEVC-10bit AAC ASSx2].SC.ass"));
|
|
}
|
|
|
|
@RequestMapping("/tools/server.do")
|
|
@ResponseBody
|
|
public String sendServer(String title, String msg) {
|
|
Tools.sendServer(title, msg);
|
|
return "ok";
|
|
}
|
|
|
|
@ResponseBody
|
|
@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");
|
|
builder.append("mixed-port: 7890").append("\n");
|
|
for (String s : tmp) {
|
|
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);
|
|
for (Object o : array) {
|
|
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~");
|
|
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"));
|
|
return json;
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping("/tools/clash/list.do")
|
|
public JSONObject clashList() {
|
|
String text = RedisTools.get("clash");
|
|
JSONArray array;
|
|
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;
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping("/tools/clash/add.do")
|
|
public JSONObject clashAddUrl(String url) {
|
|
String text = RedisTools.get("clash");
|
|
JSONArray array;
|
|
if (text != null) {
|
|
array = JSONArray.parseArray(text);
|
|
} else {
|
|
array = new JSONArray();
|
|
}
|
|
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;
|
|
}
|
|
|
|
@ResponseBody
|
|
@RequestMapping("/tools/clash/del.do")
|
|
public JSONObject clashDelUrl(String url) {
|
|
String text = RedisTools.get("clash");
|
|
JSONArray array;
|
|
if (text != null) {
|
|
array = JSONArray.parseArray(text);
|
|
} else {
|
|
array = new JSONArray();
|
|
}
|
|
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;
|
|
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;
|
|
}
|
|
|
|
public int getUid(HttpServletRequest request) {
|
|
String token = request.getParameter("token");
|
|
if (StringUtils.isEmpty(token)) {
|
|
if (Tools.isAdminLogin()) {
|
|
return 1;
|
|
}
|
|
}
|
|
UKeyExample example = new UKeyExample();
|
|
example.createCriteria().andKeyEqualTo(token);
|
|
List<UKey> list = keyDao.selectByExample(example);
|
|
if (list != null && !list.isEmpty()) {
|
|
UKey key = list.get(0);
|
|
return key.getId();
|
|
}
|
|
return -1;
|
|
}
|
|
}
|