init
This commit is contained in:
13
src/main/java/com/yutou/tools/ToolsApplication.java
Normal file
13
src/main/java/com/yutou/tools/ToolsApplication.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.yutou.tools;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ToolsApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ToolsApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
76
src/main/java/com/yutou/tools/nas/UpdateIp.java
Normal file
76
src/main/java/com/yutou/tools/nas/UpdateIp.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package com.yutou.tools.nas;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
|
||||
@Controller
|
||||
public class UpdateIp {
|
||||
private static final String nasToken = "zIrsh9TUZP2lfRW753PannG49E7VJvor";
|
||||
|
||||
@RequestMapping({"/nas/updateip.do"})
|
||||
public void updateIp(HttpServletRequest request, String token, String ip) {
|
||||
if (!"zIrsh9TUZP2lfRW753PannG49E7VJvor".equals(token)) {
|
||||
System.out.println("验证不通过:" + token);
|
||||
return;
|
||||
}
|
||||
File file = new File("/etc/nginx/nginx.conf");
|
||||
if (file.exists()) {
|
||||
System.out.println("文件存在,修改 ip>" + ip);
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
StringBuilder stringBuffer = new StringBuilder();
|
||||
String line = null;
|
||||
boolean isNas = false;
|
||||
boolean isBt = false;
|
||||
boolean isSamba = false;
|
||||
boolean isSSH = false;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.contains("nas.yutou233.cn")) {
|
||||
isNas = true;
|
||||
}
|
||||
if (isNas && line.contains("proxy_pass")) {
|
||||
line = "proxy_pass http://" + ip + ":801/;";
|
||||
isNas = false;
|
||||
}
|
||||
if (line.contains("bt.yutou233.cn")) {
|
||||
isBt = true;
|
||||
}
|
||||
if (isBt && line.contains("proxy_pass")) {
|
||||
line = "proxy_pass http://" + ip + ":9091/;";
|
||||
isBt = false;
|
||||
}
|
||||
if (line.contains("samba445-server") || line.contains("samba139-server")) {
|
||||
isSamba = true;
|
||||
}
|
||||
if (isSamba && (line.trim().endsWith(":444;") || line.trim().endsWith(":138;"))) {
|
||||
line = "server " + ip + ":" + (line.split(":")[1]);
|
||||
isSamba = false;
|
||||
}
|
||||
if(line.contains("nas-ssh-server")){
|
||||
isSSH=true;
|
||||
}
|
||||
if(isSSH&&line.endsWith(":23;")){
|
||||
line = "server " + ip + ":" + (line.split(":")[1]);
|
||||
isSSH=false;
|
||||
}
|
||||
stringBuffer.append(line).append("\n");
|
||||
}
|
||||
reader.close();
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.write(stringBuffer.toString());
|
||||
writer.flush();
|
||||
writer.close();
|
||||
System.out.println("修改完成");
|
||||
Runtime.getRuntime().exec("nginx -s reload");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/test/java/com/yutou/tools/ToolsApplicationTests.java
Normal file
13
src/test/java/com/yutou/tools/ToolsApplicationTests.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.yutou.tools;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class ToolsApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user