提交 68f6fe94 authored 作者: yangli's avatar yangli

.

上级 d3587f55
...@@ -129,6 +129,11 @@ ...@@ -129,6 +129,11 @@
<artifactId>oshi-core</artifactId> <artifactId>oshi-core</artifactId>
<version>3.5.0</version> <version>3.5.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.2</version>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
......
...@@ -8,14 +8,15 @@ import cn.hutool.json.JSONUtil; ...@@ -8,14 +8,15 @@ import cn.hutool.json.JSONUtil;
import com.priusis.lib.R; import com.priusis.lib.R;
import com.priusis.util.SysConfigUtil; import com.priusis.util.SysConfigUtil;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.ini4j.ConfigParser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.io.BufferedReader; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
...@@ -29,6 +30,10 @@ import java.util.TimerTask; ...@@ -29,6 +30,10 @@ import java.util.TimerTask;
public class RemoteControlController { public class RemoteControlController {
@Value(value = "${vnc-repeater}")
private String vncRepeater;
/** /**
* 前端定时任务查询远程控制请求,不为空则表示有请求,展示确认弹窗 * 前端定时任务查询远程控制请求,不为空则表示有请求,展示确认弹窗
*/ */
...@@ -41,16 +46,25 @@ public class RemoteControlController { ...@@ -41,16 +46,25 @@ public class RemoteControlController {
* 接受远程控制请求 * 接受远程控制请求
*/ */
@GetMapping(value = "accept_request") @GetMapping(value = "accept_request")
public R<Void> acceptRequest() throws IOException { public R<Void> acceptRequest() throws IOException, ConfigParser.DuplicateSectionException, ConfigParser.NoSectionException {
String requestParams = SysConfigUtil.getProperty("control.request"); String requestParams = SysConfigUtil.saveProperty("control.request", null);
if (StrUtil.isBlank(requestParams)) return R.error("无远程请求"); if (StrUtil.isBlank(requestParams)) return R.error("无远程请求");
SysConfigUtil.saveProperty("control.request", null);
JSONObject obj = JSONUtil.parseObj(requestParams); JSONObject obj = JSONUtil.parseObj(requestParams);
String id = obj.getStr("id"); String id = obj.getStr("id");
// 开启VNC Server todo 设置ID // 设置ID
Runtime.getRuntime().exec("cmd /c C:\\Program Files\\RealVNC\\VNC Server\\vncserver.exe"); File file = new File("C:\\Program Files\\uvnc bvba\\UltraVNC\\ultravnc.ini");
ConfigParser configParser = new ConfigParser();
configParser.read(file);
if(!configParser.hasSection("admin")) configParser.addSection("admin");
configParser.set("admin", "service_commandline",
StrUtil.format("-autoreconnect ID:{} -connect {} -run", id, vncRepeater));
configParser.write(file);
// 从参数里取出控制的时间,单位分钟 // 重启VNC Server服务
Runtime.getRuntime().exec("cmd /c net stop uvnc_service");
Runtime.getRuntime().exec("cmd /c net start uvnc_service");
// 请求控制的时间,单位分钟
int minute = obj.getInt("time"); int minute = obj.getInt("time");
// 定时任务,指定分钟后执行一次 // 定时任务,指定分钟后执行一次
Timer timer = new Timer(); Timer timer = new Timer();
...@@ -58,16 +72,8 @@ public class RemoteControlController { ...@@ -58,16 +72,8 @@ public class RemoteControlController {
@SneakyThrows @SneakyThrows
@Override @Override
public void run() { public void run() {
// 杀掉VNC Server进程 // 停止VNC Server服务
Process process = Runtime.getRuntime().exec("cmd /c tasklist /fo csv | findstr vncserver.exe"); Runtime.getRuntime().exec("cmd /c net stop uvnc_service");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"))) {
String line;
while ((line = reader.readLine()) != null) {
String pid = line.split(",")[1].replace("\"", "");
Runtime.getRuntime().exec("cmd /c taskkill /pid " + pid).destroy();
}
process.destroy();
}
timer.cancel(); timer.cancel();
} }
}, DateTime.now().offset(DateField.MINUTE, minute)); }, DateTime.now().offset(DateField.MINUTE, minute));
...@@ -79,7 +85,7 @@ public class RemoteControlController { ...@@ -79,7 +85,7 @@ public class RemoteControlController {
*/ */
@GetMapping(value = "refuse_request") @GetMapping(value = "refuse_request")
public R<Void> refuseRequest() throws IOException { public R<Void> refuseRequest() throws IOException {
SysConfigUtil.saveProperty("control.request", null);// 直接清除请求参数 SysConfigUtil.saveProperty("control.request", null);
return R.success(); return R.success();
} }
} }
...@@ -20,13 +20,15 @@ public final class SysConfigUtil { ...@@ -20,13 +20,15 @@ public final class SysConfigUtil {
return loadProperties(configFile()).getProperty(key, defaultVal); return loadProperties(configFile()).getProperty(key, defaultVal);
} }
public static void saveProperty(String key, String val) throws IOException { public static String saveProperty(String key, String val) throws IOException {
File file = configFile(); File file = configFile();
Properties properties = loadProperties(file); Properties properties = loadProperties(file);
String oldVal = properties.getProperty(key);
properties.setProperty(key, val); properties.setProperty(key, val);
try (OutputStream out = new FileOutputStream(file)) { try (OutputStream out = new FileOutputStream(file)) {
properties.store(out, null); properties.store(out, null);
} }
return oldVal;
} }
private static Properties loadProperties(File file) throws IOException { private static Properties loadProperties(File file) throws IOException {
...@@ -44,6 +46,4 @@ public final class SysConfigUtil { ...@@ -44,6 +46,4 @@ public final class SysConfigUtil {
if (!file.exists()) file.createNewFile(); if (!file.exists()) file.createNewFile();
return file; return file;
} }
} }
...@@ -46,3 +46,7 @@ apq: ...@@ -46,3 +46,7 @@ apq:
install: /ops/install/getList?macAddress={}&pageNum={}&pageSize={} install: /ops/install/getList?macAddress={}&pageNum={}&pageSize={}
upgrade: /ops/upgrade/getList?macAddress={}&pageNum={}&pageSize={} upgrade: /ops/upgrade/getList?macAddress={}&pageNum={}&pageSize={}
add-program: /ops/program/addFacProgram add-program: /ops/program/addFacProgram
# VNC中继服务器
vnc-repeater: 120..24.236.245:5500
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论