Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
PandoraNext-tokensTool v 0.4.9.3版本,再次强化JWT令牌并修复相关Web转Api修改,添加,刷新token…
Browse files Browse the repository at this point in the history
…的bug
  • Loading branch information
Yanyutin753 committed Dec 19, 2023
1 parent 0839b14 commit 871f742
Show file tree
Hide file tree
Showing 49 changed files with 88 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public Process executeCommand(String command){
/**
* 查询PandoraNext的额度
*/
@GetMapping("gePandoraNext")
@GetMapping("getPandoraNext")
public Result getPandoraLimit(){
try {
PandoraLimit pandoraLimit = apiService.getPandoraLimit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class loginColltroller {
public Result login(@RequestBody systemSetting setting) {
boolean res = loginService.login(setting);
if(res){
String password = setting.getLoginPassword();
String password = JwtUtils.getJwtPassword().toString();
String username = setting.getLoginUsername();
Map<String,Object> chaims = new HashMap<String,Object>();

Expand All @@ -58,7 +58,7 @@ public Result login(@RequestBody systemSetting setting) {
@PostMapping("/loginToken")
public Result loginToken(@RequestParam("token") String token){
systemSetting systemSetting = systemService.selectSetting();
String password = systemSetting.getLoginPassword();
String password = JwtUtils.getJwtPassword();
String username = systemSetting.getLoginUsername();

if(!StringUtils.hasLength(token)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class LoginCheckInterceptor implements HandlerInterceptor {
@Override //目标资源方法运行前运行, 返回true: 放行, 放回false, 不放行
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
systemSetting systemSetting = systemService.selectSetting();
String password = systemSetting.getLoginPassword();
String password = JwtUtils.getJwtPassword();
String username = systemSetting.getLoginUsername();

//1.获取请求url。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,21 @@ public String requiredToken(token tem) {
ObjectMapper objectMapper = new ObjectMapper();
// 读取JSON文件并获取根节点
JsonNode rootNode = objectMapper.readTree(new File(parent));

// 要修改的节点名称
String nodeNameToModify = tem.getName();

// 获取要修改的节点
JsonNode nodeToModify = rootNode.get(nodeNameToModify);

if (nodeToModify != null && nodeToModify.isObject()) {
// 创建新的 ObjectNode,并复制原始节点内容
ObjectNode newObjectNode = JsonNodeFactory.instance.objectNode();
newObjectNode.setAll((ObjectNode) rootNode);

// 获取要修改的节点
ObjectNode nodeToModifyInNew = newObjectNode.with(nodeNameToModify);

// 获取之前的节点值
String previousToken = nodeToModifyInNew.has("token") ? nodeToModifyInNew.get("token").asText() : null;
// 获取之前的setPoolToken的值
boolean previousSetPoolToken = nodeToModifyInNew.has("setPoolToken") ? nodeToModifyInNew.get("setPoolToken").asBoolean() : true;

// 修改节点的值
nodeToModifyInNew.put("token", tem.getToken());
nodeToModifyInNew.put("username", tem.getUsername());
Expand All @@ -334,8 +332,6 @@ public String requiredToken(token tem) {
nodeToModifyInNew.put("access_token", tem.getAccess_token());
nodeToModifyInNew.put("share_token", tem.getShare_token());
nodeToModifyInNew.put("checkSession",tem.isCheckSession());

// 检查是否需要 TokenPassword
if (tem.getPassword() != null && tem.getPassword().length() > 0) {
nodeToModifyInNew.put("password", tem.getPassword());
} else {
Expand All @@ -346,26 +342,16 @@ public String requiredToken(token tem) {
if (!previousToken.equals(tem.getToken())
&& tem.getToken().contains("eyJhbG")
&& tem.isSetPoolToken()) {
//获取access_token或share_token
String access_token = getAccessToken(tem);
if (access_token != null) {
tem.setAccess_token(access_token);
String share_token = getShareToken(tem);
nodeToModifyInNew.put("access_token", access_token);
nodeToModifyInNew.put("checkSession",true);
if (share_token != null) {
nodeToModifyInNew.put("share_token", share_token);
} else {
nodeToModifyInNew.put("share_token", "检查session是否过期,请重新刷新获取");
}
} else {
nodeToModifyInNew.put("access_token", "检查session是否过期,请重新刷新获取");
nodeToModifyInNew.put("checkSession",false);
require_UpdateToken(tem,nodeToModifyInNew);
}
if(tem.isSetPoolToken() && previousSetPoolToken == false){
String resSessionToken = updateSessionToken(tem);
if(resSessionToken != null){
tem.setToken(resSessionToken);
nodeToModifyInNew.put("token", resSessionToken);
require_UpdateToken(tem,nodeToModifyInNew);
}
LocalDateTime now = LocalDateTime.now();
nodeToModifyInNew.put("updateTime", now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
}

//如果不能生成API
if (tem.isSetPoolToken() == false) {
nodeToModifyInNew.put("token", tem.getUsername() + "," + tem.getUserPassword());
Expand All @@ -387,6 +373,29 @@ public String requiredToken(token tem) {
return "修改失败!";
}

public void require_UpdateToken(token tem,ObjectNode nodeToModifyInNew){
try {
String access_token = getAccessToken(tem);
if (access_token != null) {
tem.setAccess_token(access_token);
String share_token = getShareToken(tem);
nodeToModifyInNew.put("access_token", access_token);
nodeToModifyInNew.put("checkSession",true);
if (share_token != null) {
nodeToModifyInNew.put("share_token", share_token);
} else {
nodeToModifyInNew.put("share_token", "检查session是否过期,请重新刷新获取");
}
} else {
nodeToModifyInNew.put("access_token", "检查session是否过期,请重新刷新获取");
nodeToModifyInNew.put("checkSession",false);
}
LocalDateTime now = LocalDateTime.now();
nodeToModifyInNew.put("updateTime", now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* 删除token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void initializeConfigJson() {
keysAndDefaults.put("proxy_file_service", false);
keysAndDefaults.put("custom_doh_host", "");

// 0.4.9.2
// 0.4.9.3
keysAndDefaults.put("auto_updateSession",false);
keysAndDefaults.put("auto_updateTime",5);
keysAndDefaults.put("auto_updateNumber",1);
Expand Down Expand Up @@ -202,7 +202,7 @@ public String requiredSetting(systemSetting tem){
updateJsonValue(jsonObject,"proxy_file_service",tem.getProxy_file_service());
updateJsonValue(jsonObject,"custom_doh_host",tem.getCustom_doh_host());

// 0.4.9.2
// 0.4.9.3
updateJsonValue(jsonObject,"auto_updateSession",tem.getAuto_updateSession());
updateJsonValue(jsonObject,"auto_updateTime",tem.getAuto_updateTime());
updateJsonValue(jsonObject,"auto_updateNumber",tem.getAuto_updateNumber());
Expand Down Expand Up @@ -292,7 +292,7 @@ public systemSetting selectSetting() {
config.setProxy_file_service(jsonObject.optBoolean("proxy_file_service"));
config.setCustom_doh_host(jsonObject.optString("custom_doh_host"));

// 0.4.9.2
// 0.4.9.3
config.setAuto_updateSession(jsonObject.optBoolean("auto_updateSession"));
config.setAuto_updateTime(jsonObject.optInt("auto_updateTime"));
config.setAuto_updateNumber(jsonObject.optInt("auto_updateNumber"));
Expand Down Expand Up @@ -334,7 +334,7 @@ public String requireTimeTask(systemSetting tem){
String jsonContent = new String(Files.readAllBytes(Paths.get(parent)));

JSONObject jsonObject = new JSONObject(jsonContent);
// 0.4.9.2
// 0.4.9.3
updateJsonValue(jsonObject,"auto_updateSession",tem.getAuto_updateSession());
updateJsonValue(jsonObject,"auto_updateTime",tem.getAuto_updateTime());
updateJsonValue(jsonObject,"auto_updateNumber",tem.getAuto_updateNumber());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import javax.annotation.PostConstruct;
import java.time.Instant;
import java.util.UUID;

/**
* @author YANGYANG
Expand All @@ -36,13 +37,19 @@ public class tokensToolApplication {
private MyTaskUtils myTaskUtils;

public static void main(String[] args) {
log.info("PandoraNext-tokensTool v 0.4.9.2版本,增加自定义刷新session_token," +
"每天凌晨2点自动更新access_token,share_token,pool_token," +
"并检查session_token,并标记过期session_token");
log.info("PandoraNext-tokensTool v 0.4.9.3版本,再次强化JWT令牌" +
"并修复相关Web转Api修改,添加,刷新token的bug");
Instant instant = Instant.now();
String key = String.valueOf(instant.toEpochMilli());
JwtUtils.setSignKey(key);
log.info("设置专属的signKey成功!");
// 初始化UUID
String uuidString = UUID.randomUUID().toString();
JwtUtils.setJwtPassword(uuidString);
log.info("初始化UUID成功!");
// 启动
SpringApplication.run(tokensToolApplication.class, args);
log.info("原神tokensTool启动!!!!!!!!!!!!!!!");
}

@PostConstruct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
public class JwtUtils{
//硬编码的伤
private static String signKey = "123456";
// JWT里的内容
private static String JwtPassword = "tokensTool";
private static Long expire = 43200000L;

/**
Expand All @@ -36,6 +38,14 @@ public static String getSignKey(){
return signKey;
}

public static void setJwtPassword(String password){
JwtPassword = password;
}

public static String getJwtPassword(){
return JwtPassword;
}

/**
* 生成JWT令牌
* @param claims JWT第二部分负载 payload 中存储的内容
Expand Down
1 change: 1 addition & 0 deletions rearServer/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pandoara_Ip="ip Or default"
hotReload=true



2 changes: 1 addition & 1 deletion rearServer/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Welcome to PandoraNext-TokensTool</title><script defer="defer" src="js/chunk-vendors.ac84f5ac.js"></script><script defer="defer" src="js/app.53b0a635.js"></script><link href="css/chunk-vendors.8a308144.css" rel="stylesheet"></head><body><div id="app"></div></body></html>
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Welcome to PandoraNext-TokensTool</title><script defer="defer" src="js/chunk-vendors.ac84f5ac.js"></script><script defer="defer" src="js/app.bd1696d8.js"></script><link href="css/chunk-vendors.8a308144.css" rel="stylesheet"></head><body><div id="app"></div></body></html>
2 changes: 2 additions & 0 deletions rearServer/src/main/resources/static/js/308.355af989.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 871f742

Please sign in to comment.