Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
H
haikang-client
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
杨立
haikang-client
Commits
a9d77600
提交
a9d77600
authored
9月 22, 2021
作者:
wangqiang
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
上级
91988743
802a7f91
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
54 行增加
和
17 行删除
+54
-17
MqttServiceImpl.java
...java/com/priusis/client/service/core/MqttServiceImpl.java
+1
-1
RemoteControlController.java
.../java/com/priusis/controller/RemoteControlController.java
+52
-15
application.yml
apq-pc-client/src/main/resources/application.yml
+1
-1
没有找到文件。
apq-pc-client/src/main/java/com/priusis/client/service/core/MqttServiceImpl.java
浏览文件 @
a9d77600
...
...
@@ -358,7 +358,7 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
try
{
if
(
"remote_control"
.
equals
(
mqttRpcDataMessage
.
getMethod
()))
{
// 远程控制请求
SysConfigUtil
.
saveProperty
(
"control.request"
,
mqttRpcDataMessage
.
getParams
());
// 存储参数
SysConfigUtil
.
saveProperty
(
"control.request"
,
"1"
);
return
;
}
...
...
apq-pc-client/src/main/java/com/priusis/controller/RemoteControlController.java
浏览文件 @
a9d77600
package
com
.
priusis
.
controller
;
import
cn.hutool.core.
date.DateField
;
import
cn.hutool.core.
date.DateTime
;
import
cn.hutool.core.
convert.Convert
;
import
cn.hutool.core.
util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
com.priusis.cache.InstalledProgramCache
;
import
com.priusis.lib.R
;
import
com.priusis.util.SysConfigUtil
;
import
lombok.SneakyThrows
;
import
lombok.extern.slf4j.Slf4j
;
import
org.ini4j.ConfigParser
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
oshi.hardware.NetworkIF
;
import
javax.annotation.Resource
;
import
javax.validation.constraints.NotNull
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.net.UnknownHostException
;
import
java.util.Timer
;
import
java.util.TimerTask
;
...
...
@@ -26,6 +35,7 @@ import java.util.TimerTask;
* @author yangli
* @since 2021/09/16
*/
@Slf4j
@Validated
@RestController
@RequestMapping
(
value
=
"remote_control"
)
...
...
@@ -35,6 +45,12 @@ public class RemoteControlController {
@Value
(
value
=
"${vnc-repeater}"
)
private
String
vncRepeater
;
@Value
(
value
=
"${apq.iot-gateway}"
)
private
String
gateway
;
@Value
(
value
=
"${apq.url.device_info}"
)
private
String
deviceInfoUrl
;
@Resource
private
InstalledProgramCache
installedProgramCache
;
...
...
@@ -42,20 +58,22 @@ public class RemoteControlController {
* 前端定时任务查询远程控制请求,不为空则表示有请求,展示确认弹窗
*/
@GetMapping
(
value
=
"get_control_request"
)
public
R
<
JSONObject
>
getControlRequest
()
throws
IOException
{
return
R
.
success
(
JSONUtil
.
parseObj
(
SysConfigUtil
.
getProperty
(
"control.request"
)
));
public
R
<
Boolean
>
getControlRequest
()
throws
IOException
{
return
R
.
success
(
Convert
.
toBool
(
SysConfigUtil
.
getProperty
(
"control.request"
),
false
));
}
/**
* 接受远程控制请求
*/
@GetMapping
(
value
=
"accept_request"
)
public
R
<
Void
>
acceptRequest
()
throws
IOException
,
ConfigParser
.
DuplicateSectionException
,
ConfigParser
.
NoSectionException
{
String
requestParams
=
SysConfigUtil
.
saveProperty
(
"control.request"
,
null
);
if
(
StrUtil
.
isBlank
(
requestParams
))
return
R
.
error
(
"无远程请求"
);
JSONObject
obj
=
JSONUtil
.
parseObj
(
requestParams
);
String
id
=
obj
.
getStr
(
"id"
);
// 设置ID
public
R
<
Void
>
acceptRequest
(
@RequestParam
@NotNull
Long
minutes
)
throws
IOException
,
ConfigParser
.
DuplicateSectionException
,
ConfigParser
.
NoSectionException
{
Boolean
hasRequest
=
Convert
.
toBool
(
SysConfigUtil
.
saveProperty
(
"control.request"
,
"0"
),
false
);
if
(!
hasRequest
)
return
R
.
error
(
"无远程请求"
);
// 查询设备的远程ID
String
remoteId
=
getRemoteId
();
if
(
StrUtil
.
isBlank
(
remoteId
))
return
R
.
error
(
"未查询到设备的远程ID"
);
// 设置远程ID
String
path
=
installedProgramCache
.
getPrograms
().
stream
()
.
filter
(
m
->
"UltraVNC"
.
equalsIgnoreCase
(
m
.
get
(
"name"
)))
.
findFirst
()
...
...
@@ -67,15 +85,13 @@ public class RemoteControlController {
configParser
.
read
(
file
);
if
(!
configParser
.
hasSection
(
"admin"
))
configParser
.
addSection
(
"admin"
);
configParser
.
set
(
"admin"
,
"service_commandline"
,
StrUtil
.
format
(
"-autoreconnect ID:{} -connect {} -run"
,
i
d
,
vncRepeater
));
StrUtil
.
format
(
"-autoreconnect ID:{} -connect {} -run"
,
remoteI
d
,
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"
);
// 定时任务,指定分钟后执行一次
Timer
timer
=
new
Timer
();
timer
.
schedule
(
new
TimerTask
()
{
...
...
@@ -86,16 +102,37 @@ public class RemoteControlController {
Runtime
.
getRuntime
().
exec
(
"cmd /c net stop uvnc_service"
);
timer
.
cancel
();
}
},
DateTime
.
now
().
offset
(
DateField
.
MINUTE
,
minute
)
);
},
minutes
*
60
*
1000
);
return
R
.
success
();
}
/**
* 拒绝远程控制请求
*/
@GetMapping
(
value
=
"refuse_request"
)
public
R
<
Void
>
refuseRequest
()
throws
IOException
{
SysConfigUtil
.
saveProperty
(
"control.request"
,
null
);
SysConfigUtil
.
saveProperty
(
"control.request"
,
"0"
);
return
R
.
success
();
}
private
String
getMacAddress
()
throws
UnknownHostException
,
SocketException
{
NetworkIF
networkIF
=
new
NetworkIF
();
networkIF
.
setNetworkInterface
(
NetworkInterface
.
getByInetAddress
(
InetAddress
.
getLocalHost
()));
return
networkIF
.
getMacaddr
();
}
private
String
remoteId
;
private
String
getRemoteId
()
throws
SocketException
,
UnknownHostException
{
if
(
StrUtil
.
isNotBlank
(
remoteId
))
return
remoteId
;
String
mac
=
getMacAddress
();
JSONObject
rsp
=
JSONUtil
.
parseObj
(
HttpUtil
.
get
(
gateway
+
StrUtil
.
format
(
deviceInfoUrl
,
mac
)));
if
(
ObjectUtil
.
notEqual
(
rsp
.
getInt
(
"code"
),
0
))
{
log
.
warn
(
"查询设备信息失败, msg: {}"
,
rsp
.
getStr
(
"msg"
));
return
null
;
}
return
remoteId
=
rsp
.
getJSONObject
(
"data"
).
getStr
(
"remoteId"
);
}
}
apq-pc-client/src/main/resources/application.yml
浏览文件 @
a9d77600
...
...
@@ -48,5 +48,5 @@ apq:
add-program
:
/ops/program/addFacProgram
# VNC中继服务器
vnc-repeater
:
120.
.
24.236.245:5500
vnc-repeater
:
120.24.236.245:5500
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论