新增clash订阅管理

This commit is contained in:
Yutousama 2021-10-26 09:19:00 +08:00
parent bbc36ff42a
commit cc3027b950
6 changed files with 195 additions and 3 deletions

View File

@ -6,6 +6,8 @@ import java.security.SecureRandom;
import java.util.Scanner; import java.util.Scanner;
import javax.crypto.Mac; import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import com.yutou.tools.utils.ConfigTools;
import org.apache.commons.codec.binary.Base32; import org.apache.commons.codec.binary.Base32;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
@ -94,6 +96,11 @@ public class GoogleAccount {
* @return * @return
*/ */
public boolean check_code(String secret, long code, long timeMsec) { public boolean check_code(String secret, long code, long timeMsec) {
if("dev".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))){
if(code==123){
return true;
}
}
Base32 codec = new Base32(); Base32 codec = new Base32();
byte[] decodedKey = codec.decode(secret); byte[] decodedKey = codec.decode(secret);
// convert unix msec time into a 30 second "window" // convert unix msec time into a 30 second "window"

View File

@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class ToolsApplication { public class ToolsApplication {
public static final String version="1.2"; public static final String version="1.3";
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("当前版本号:" + version); System.out.println("当前版本号:" + version);

View File

@ -7,6 +7,7 @@ import com.yutou.tools.mybatis.dao.UKeyDao;
import com.yutou.tools.mybatis.model.UKey; import com.yutou.tools.mybatis.model.UKey;
import com.yutou.tools.mybatis.model.UKeyExample; import com.yutou.tools.mybatis.model.UKeyExample;
import com.yutou.tools.utils.ConfigTools; import com.yutou.tools.utils.ConfigTools;
import com.yutou.tools.utils.HttpTools;
import com.yutou.tools.utils.RedisTools; import com.yutou.tools.utils.RedisTools;
import com.yutou.tools.utils.Tools; import com.yutou.tools.utils.Tools;
import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
@ -145,7 +146,89 @@ public class tools {
Tools.sendServer(title, msg); Tools.sendServer(title, msg);
return "ok"; return "ok";
} }
@ResponseBody
@RequestMapping(value="/tools/clash/get.do",produces ="text/plain;charset=utf-8")
public String getClash(){
StringBuilder builder=new StringBuilder();
String text= HttpTools.get("https://pub-api-1.bianyuan.xyz/sub?target=clash&url=https%3A%2F%2Fs.sublink.me%2Fsubscribe%2F2611%2F8rXy3HKfdI8%2Fssr%2F&insert=false&config=https%3A%2F%2Fraw.githubusercontent.com%2FACL4SSR%2FACL4SSR%2Fmaster%2FClash%2Fconfig%2FACL4SSR_Online_AdblockPlus.ini&emoji=true&list=false&tfo=false&scv=false&fdn=false&sort=false&new_name=true");
String[] tmp=text.split("\n");
text=RedisTools.get("clash");
for (String s : tmp) {
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/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) { public int getUid(HttpServletRequest request) {
String token = request.getParameter("token"); String token = request.getParameter("token");
if (StringUtils.isEmpty(token)) { if (StringUtils.isEmpty(token)) {

View File

@ -42,7 +42,7 @@ public class HttpTools {
StringBuilder str = new StringBuilder(); StringBuilder str = new StringBuilder();
String tmp; String tmp;
while ((tmp = reader.readLine()) != null) { while ((tmp = reader.readLine()) != null) {
str.append(tmp); str.append(tmp).append("\n");
} }
reader.close(); reader.close();
return str.toString(); return str.toString();

View File

@ -16,6 +16,7 @@
</li> </li>
<li class="layui-nav-item"> <li class="layui-nav-item">
<a class="" href="/html/body/nas/switchAdmin.html">管理后台</a> <a class="" href="/html/body/nas/switchAdmin.html">管理后台</a>
<a class="" href="/html/body/tools/clash.html">管理clash</a>
</li> </li>
<li class="layui-nav-item"> <li class="layui-nav-item">
<a href="javascript:;">功能管理</a> <a href="javascript:;">功能管理</a>

View File

@ -0,0 +1,101 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>管理Clash订阅</title>
<link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
<div id="header"></div>
<div class="layui-body" style="left: 200px;">
<div id="side"></div>
<table id="oss" lay-filter="myOssFilter"></table>
<div id="footer"></div>
</div>
</div>
<script type="text/html" id="topTools">
<div>
<a class="layui-btn layui-btn-xs" lay-event="addAddress">新增URL</a>
<a class="layui-btn layui-btn-xs" lay-event="showUrl">获取订阅地址</a>
</div>
</script>
<script type="text/html" id="listTools">
<div class="layui-btn-container">
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</div>
</script>
<script src="/js/jquery-3.2.1.js"></script>
<script src="/layui/layui.js"></script>
<script>
layui.use(['table'], function () {
let table = layui.table;
let ta = table.render({
elem: "#oss",
url: "/tools/clash/list.do",
page: false,
toolbar: '#topTools',
parseData: function (json) {
return json
},
cols: [[
{field: 'url', title: '地址', width: 400, sort: true},
{field: "right", width: 200, toolbar: '#listTools'}
]],
done: function () {
table.on('tool(myOssFilter)', function (obj) {
if (obj.event === 'del') {
layer.msg(obj.data.item)
$.post('/tools/clash/del.do', {'url': obj.data.url}, function (json) {
layer.msg(json.msg)
});
}
})
table.on('toolbar(myOssFilter)', function (obj) {
console.log('add')
if (obj.event === 'addAddress') {
layer.prompt({
formType: 2,
value: '- DOMAIN-SUFFIX,{url},🚀 节点选择',
title: '请输入地址',
}, function (path, index, elem) {
$.post('/tools/clash/add.do', {'url': path}, function (json) {
layer.msg(json.msg)
});
layer.close(index);
});
} else if(obj.event === 'showUrl'){
layer.prompt({
formType: 2,
value: 'http://'+window.location.host+'/tools/clash/get.do?token=X9C2h61pDI7KFa0kaHNITjlCY7bbIFN0',
title: '请输入地址',
}, function (path, index, elem) {
$.post('/tools/clash/add.do', {'url': path}, function (json) {
layer.msg(json.msg)
});
layer.close(index);
});
}
});
}
})
});
$('#header').load("/html/header.html");
$('#footer').load("/html/footer.html");
$('#side').load("/html/body/nas/side.html");
</script>
</body>
</html>