update
This commit is contained in:
25
src/main/java/com/yutou/tools/nas/AdminManager.java
Normal file
25
src/main/java/com/yutou/tools/nas/AdminManager.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.yutou.tools.nas;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.tools.utils.RedisTools;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Controller
|
||||
public class AdminManager {
|
||||
@Resource
|
||||
RedisTools redisTools;
|
||||
|
||||
public String getAdminAddress(HttpServletRequest request){
|
||||
JSONObject json=new JSONObject();
|
||||
|
||||
String address=redisTools.get("adminAddress");
|
||||
if(address==null){
|
||||
json.put("code",-1);
|
||||
json.put("msg","暂未设置管理后台");
|
||||
}
|
||||
return json.toJSONString();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.yutou.tools.nas;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.tools.mybatis.dao.UKeyDao;
|
||||
import com.yutou.tools.mybatis.model.UKey;
|
||||
import com.yutou.tools.utils.RedisTools;
|
||||
import com.yutou.tools.utils.Tools;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -19,6 +23,8 @@ import java.util.regex.Pattern;
|
||||
@Controller
|
||||
public class UpdateIp {
|
||||
private static List<String> keys = new ArrayList<>();
|
||||
@Resource
|
||||
RedisTools redisTools;
|
||||
|
||||
/* static {
|
||||
keys.add("nas.yutou233.cn;");
|
||||
@@ -71,6 +77,50 @@ public class UpdateIp {
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/nas/getIp.do")
|
||||
@ResponseBody
|
||||
public String getIP(HttpServletRequest request) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", -1);
|
||||
json.put("msg", "未登录");
|
||||
if (Tools.checkWebLogin(request, redisTools) != 1) {
|
||||
// return json.toJSONString();
|
||||
}
|
||||
updateList();
|
||||
File file = new File("/etc/nginx/nginx.conf");
|
||||
file = new File("D:\\nginx.conf");
|
||||
if (file.exists()) {
|
||||
String testIp = "0.0.0.0";
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
boolean isIp = false;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
// System.out.println(line.trim().replace("server_name","").replace("upstream","").trim());
|
||||
if (keys.contains(line.trim().replace("server_name", "").replace("upstream", "").replace("{", "").trim())) {
|
||||
isIp = true;
|
||||
}
|
||||
if (isIp) {
|
||||
testIp = testIp(line);
|
||||
if (testIp != null)
|
||||
break;
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
json.put("code", 0);
|
||||
json.put("msg", "ok");
|
||||
json.put("data", testIp);
|
||||
} else {
|
||||
json.put("code", 0);
|
||||
json.put("msg", "没有找到ip");
|
||||
json.put("data", "0.0.0.0");
|
||||
}
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
public String testIp(String ip) {
|
||||
String pattern = "((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}";
|
||||
Pattern p = Pattern.compile(pattern);
|
||||
@@ -87,12 +137,13 @@ public class UpdateIp {
|
||||
if (!file.exists()) {
|
||||
boolean create = file.createNewFile();
|
||||
if (create)
|
||||
System.out.println("创建文件完成:" +file.getAbsolutePath());
|
||||
System.out.println("创建文件完成:" + file.getAbsolutePath());
|
||||
}
|
||||
BufferedReader reader=new BufferedReader(new FileReader(file));
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
String tmp;
|
||||
while ((tmp=reader.readLine())!=null){
|
||||
keys.add(tmp.trim());
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
if (!keys.contains(tmp.trim()))
|
||||
keys.add(tmp.trim());
|
||||
}
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user