新增clash订阅管理
This commit is contained in:
@@ -6,6 +6,8 @@ import java.security.SecureRandom;
|
||||
import java.util.Scanner;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import com.yutou.tools.utils.ConfigTools;
|
||||
import org.apache.commons.codec.binary.Base32;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
@@ -94,6 +96,11 @@ public class GoogleAccount {
|
||||
* @return
|
||||
*/
|
||||
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();
|
||||
byte[] decodedKey = codec.decode(secret);
|
||||
// convert unix msec time into a 30 second "window"
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ToolsApplication {
|
||||
public static final String version="1.2";
|
||||
public static final String version="1.3";
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("当前版本号:" + version);
|
||||
|
||||
@@ -7,6 +7,7 @@ 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 org.springframework.core.io.FileSystemResource;
|
||||
@@ -145,7 +146,89 @@ 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 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) {
|
||||
String token = request.getParameter("token");
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
|
||||
@@ -42,7 +42,7 @@ public class HttpTools {
|
||||
StringBuilder str = new StringBuilder();
|
||||
String tmp;
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
str.append(tmp);
|
||||
str.append(tmp).append("\n");
|
||||
}
|
||||
reader.close();
|
||||
return str.toString();
|
||||
|
||||
Reference in New Issue
Block a user