Skip to content

Commit

Permalink
v3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sprov committed May 14, 2019
1 parent be84730 commit ef29f49
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 91 deletions.
1 change: 0 additions & 1 deletion src/main/java/xyz/sprov/blog/sprovui/SprovUISparkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static void main(String[] args) {
}
Config.setBasePath(basePath);
System.out.println("basePath = " + basePath);
redirect.get("/res/", basePath + "/res/");
path(basePath, SprovUISparkApp::createPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ private JSONObject getInbound(String listen,
inbound.put("port", port);
inbound.put("protocol", protocol);
inbound.put("remark", remark);
// if (!StringUtils.isBlank(tag)) {
// }
try {
inbound.put("settings", JSONObject.parseObject(settings));
} catch (Exception e) {
Expand Down Expand Up @@ -284,51 +282,6 @@ public Msg delDisabled(int port) {
}
}

/**
* 添加一个VMess用户
*/
// @ResponseBody
// @PostMapping("vmess/add")
public Msg vmessAdd(int port, String id, int alterId) {
JSONObject client = new JSONObject();
client.put("port", port);
client.put("id", id);
client.put("alterId", alterId);
try {
configService.addVmessUser(client);
return new Msg(true, "修改配置文件成功,需重启v2ray生效");
} catch (V2rayConfigException e) {
return new Msg(false, e.getMessage());
} catch (IOException e) {
return new Msg(false, "读取或写入配置文件失败");
}
}

/**
* 删除一个VMess入站协议
*/
// @ResponseBody
// @PostMapping("vmess/del")
public Msg vmessDel(int port, String uuid) {
return new Msg(false);
}

/**
* 删除一个ss入站协议
*/
// @ResponseBody
// @PostMapping("ss/del")
public Msg ssDel(int port) {
return new Msg(false);
}

/**
* 删除一个tg代理入站协议
*/
// @ResponseBody
// @PostMapping("mtproto/del")
public Msg mtprotoDel() {
return new Msg(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ public class V2rayController {

private ExtraConfigService extraConfigService = Context.extraConfigService;

// @GetMapping("")
public String index() {
return "v2ray/index";
}

// @GetMapping("accounts")
public String accounts() {
return "v2ray/accounts";
}

// @GetMapping("clients")
public String clients() { return "v2ray/clients"; }

/**
* v2ray状态
* 0:运行
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

public class ExtraConfigService {

private ThreadService threadService = Context.threadService;

private String configPath = "/etc/sprov-ui/v2ray-extra-config.json";

private JSONObject config;
Expand All @@ -48,7 +46,7 @@ public ExtraConfigService() {
System.exit(-1);
}
}
threadService.scheduleAtFixedRate(new UpdateConfigThread(), 1, 1, TimeUnit.MINUTES);
Context.threadService.scheduleAtFixedRate(new UpdateConfigThread(), 1, 1, TimeUnit.MINUTES);
}

public Map<String, JSONObject> getTagInboundMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@

public class ReportService {

private String reportUrl = "https://blog.sprov.xyz/sprov-ui/report";
private static final String REPORT_URL = "https://blog.sprov.xyz/sprov-ui/report";

private V2rayConfigService v2rayConfigService = Context.v2rayConfigService;

private ThreadService threadService = Context.threadService;

public ReportService() {
threadService.scheduleAtFixedRate(new ReportThread(), 30, 30, TimeUnit.MINUTES);
Context.threadService.scheduleAtFixedRate(new ReportThread(), 30, 30, TimeUnit.MINUTES);
}

private class ReportThread implements Runnable {
Expand All @@ -41,7 +39,7 @@ public void run() {
map.put(protocol, n + 1);
map.put("version", Config.currentVersion());
}
HttpUtil.post(reportUrl, map);
HttpUtil.post(REPORT_URL, map);
} catch (Exception ignore) {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ public class ServerService {
// @Autowired
private V2rayService v2rayService = Context.v2rayService;

private ThreadService threadService = Context.threadService;

private GetSystemInfoThread thread = new GetSystemInfoThread();

public ServerService() {
threadService.scheduleAtFixedRate(thread, 1, 1, TimeUnit.SECONDS);
Context.threadService.scheduleAtFixedRate(thread, 1, 1, TimeUnit.SECONDS);
}

/**
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/xyz/sprov/blog/sprovui/service/SprovUIService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,22 @@

public class SprovUIService {

private ThreadService threadService = Context.threadService;

private String githubLastReleaseUrl = "https://github.com/sprov065/sprov-ui/releases/latest";
private static final String GITHUB_LAST_RELEASE_URL = "https://github.com/sprov065/sprov-ui/releases/latest";

private String currentVersion = Config.currentVersion();

private String lastVersion = currentVersion;

private Pattern urlVersionPattern = Pattern.compile("https://github\\.com/[^/]+/[^/]+/releases/tag/(.+)");

private String jarDir = "/usr/local/sprov-ui/";
private static final String JAR_DIR = "/usr/local/sprov-ui/";

public SprovUIService() {
threadService.scheduleAtFixedRate(new GetLastVersionRunnable(), 5, 29, TimeUnit.MINUTES);
Context.threadService.scheduleAtFixedRate(new GetLastVersionRunnable(), 5, 29, TimeUnit.MINUTES);
}

private String getLastVersion() throws Exception {
String url = HttpUtil.getRealUrl(githubLastReleaseUrl);
String url = HttpUtil.getRealUrl(GITHUB_LAST_RELEASE_URL);
Matcher matcher = urlVersionPattern.matcher(url);
if (matcher.find()) {
return matcher.group(1);
Expand Down Expand Up @@ -81,8 +79,8 @@ public void update() throws IOException {
}

// 备份旧版本软件包
File oldJar = new File(jarDir + "sprov-ui.jar");
File copiedOldJar = new File(jarDir + "sprov-ui-" + currentVersion + ".jar");
File oldJar = new File(JAR_DIR + "sprov-ui.jar");
File copiedOldJar = new File(JAR_DIR + "sprov-ui-" + currentVersion + ".jar");
FileUtils.deleteQuietly(copiedOldJar);
try {
FileUtils.copyFile(oldJar, copiedOldJar);
Expand All @@ -92,7 +90,7 @@ public void update() throws IOException {
}

// 写入新版本软件包至目录
File newJar = new File(jarDir + "sprov-ui-" + lastVersion + ".jar");
File newJar = new File(JAR_DIR + "sprov-ui-" + lastVersion + ".jar");
FileUtils.deleteQuietly(newJar);
try {
FileUtils.writeByteArrayToFile(newJar, bytes);
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/xyz/sprov/blog/sprovui/service/V2rayService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public class V2rayService {
// private String active;

// @Value("${v2ray.install}")
private String installCmd = "bash <(curl -L -s https://install.direct/go.sh)";
private static final String INSTALL_CMD = "bash <(curl -L -s https://install.direct/go.sh)";

// @Value("${v2ray.update}")
private String updateCmd = "bash <(curl -L -s https://install.direct/go.sh) -f";
private static final String UPDATE_CMD = "bash <(curl -L -s https://install.direct/go.sh) -f";

private String startCmd = "systemctl start v2ray";
private String restartCmd = "systemctl restart v2ray";
private String stopCmd = "systemctl stop v2ray";
private static final String START_CMD = "systemctl start v2ray";
private static final String RESTART_CMD = "systemctl restart v2ray";
private static final String STOP_CMD = "systemctl stop v2ray";

private final AtomicBoolean inOperation = new AtomicBoolean(false);

Expand Down Expand Up @@ -94,7 +94,7 @@ private boolean install(boolean forceUpdate) throws IOException, InterruptedExce
} else if (!forceUpdate && isInstalled()) {
throw new V2rayException("请不要重复安装");
}
return operation(forceUpdate ? updateCmd : installCmd);
return operation(forceUpdate ? UPDATE_CMD : INSTALL_CMD);
}

/**
Expand All @@ -116,7 +116,7 @@ public boolean uninstall() throws IOException, InterruptedException {
throw new V2rayException("没有安装v2ray");
}
synchronized (inOperation) {
ExecUtil.execForStatus(stopCmd);
ExecUtil.execForStatus(STOP_CMD);
ExecUtil.execForStatus("systemctl disable v2ray");
}
return false;
Expand All @@ -129,7 +129,7 @@ public boolean start() throws IOException, InterruptedException {
if (inOperation.get()) {
throw new V2rayException("正在操作中,请稍后");
}
return operation(startCmd);
return operation(START_CMD);
}

/**
Expand All @@ -139,7 +139,7 @@ public void restart() {
if (inOperation.get()) {
throw new V2rayException("正在操作中,请稍后");
}
threadService.schedule(() -> operation(restartCmd), 3, TimeUnit.SECONDS);
threadService.schedule(() -> operation(RESTART_CMD), 3, TimeUnit.SECONDS);
}

/**
Expand All @@ -149,7 +149,7 @@ public void stop() {
if (inOperation.get()) {
throw new V2rayException("正在操作中,请稍后");
}
threadService.schedule(() -> operation(stopCmd), 3, TimeUnit.SECONDS);
threadService.schedule(() -> operation(STOP_CMD), 3, TimeUnit.SECONDS);
}

private boolean operation(String cmd) throws IOException, InterruptedException {
Expand Down

0 comments on commit ef29f49

Please sign in to comment.