Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
H
haikang-client
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
杨立
haikang-client
Commits
aef8a52b
提交
aef8a52b
authored
9月 22, 2021
作者:
yangli
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
.
上级
68f6fe94
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
93 行增加
和
54 行删除
+93
-54
InstalledProgramCache.java
...rc/main/java/com/priusis/cache/InstalledProgramCache.java
+66
-0
ProgramController.java
...c/main/java/com/priusis/controller/ProgramController.java
+14
-51
RemoteControlController.java
.../java/com/priusis/controller/RemoteControlController.java
+13
-3
没有找到文件。
apq-pc-client/src/main/java/com/priusis/cache/InstalledProgramCache.java
0 → 100644
浏览文件 @
aef8a52b
package
com
.
priusis
.
cache
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author yangli
* @since 2021/09/22
*/
@Component
public
class
InstalledProgramCache
{
private
static
List
<
Map
<
String
,
String
>>
programList
;
public
List
<
Map
<
String
,
String
>>
getPrograms
()
throws
IOException
{
if
(
programList
==
null
)
loadProgramListJob
();
return
programList
;
}
@Scheduled
(
fixedDelay
=
3000
)
protected
void
loadProgramListJob
()
throws
IOException
{
List
<
Map
<
String
,
String
>>
programs
=
new
ArrayList
<>();
Process
process
=
Runtime
.
getRuntime
()
.
exec
(
"cmd /c reg query HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
);
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
(),
"GBK"
)))
{
String
key
;
while
((
key
=
reader
.
readLine
())
!=
null
)
{
Map
<
String
,
String
>
info
=
queryProgramInfo
(
key
);
if
(
info
.
containsKey
(
"name"
))
programs
.
add
(
info
);
}
process
.
destroy
();
}
programList
=
programs
;
}
private
Map
<
String
,
String
>
queryProgramInfo
(
String
key
)
throws
IOException
{
Map
<
String
,
String
>
info
=
new
HashMap
<>();
Process
process
=
Runtime
.
getRuntime
().
exec
(
"cmd /c reg query "
+
key
);
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
(),
"GBK"
)))
{
reader
.
readLine
();
reader
.
readLine
();
String
line
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
line
=
line
.
trim
();
if
(
line
.
startsWith
(
"DisplayName"
))
{
info
.
put
(
"name"
,
line
.
replace
(
"DisplayName"
,
""
).
replace
(
"REG_SZ"
,
""
).
trim
());
}
else
if
(
line
.
startsWith
(
"DisplayVersion"
))
{
info
.
put
(
"version"
,
line
.
replace
(
"DisplayVersion"
,
""
).
replace
(
"REG_SZ"
,
""
).
trim
());
}
else
if
(
line
.
startsWith
(
"InstallLocation"
))
{
info
.
put
(
"path"
,
line
.
replace
(
"InstallLocation"
,
""
).
replace
(
"REG_SZ"
,
""
).
trim
());
}
}
process
.
destroy
();
}
return
info
;
}
}
apq-pc-client/src/main/java/com/priusis/controller/ProgramController.java
浏览文件 @
aef8a52b
...
...
@@ -11,6 +11,7 @@ import cn.hutool.json.JSONArray;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.priusis.cache.InstalledProgramCache
;
import
com.priusis.lib.R
;
import
com.priusis.util.SysConfigUtil
;
import
lombok.SneakyThrows
;
...
...
@@ -21,19 +22,20 @@ import org.springframework.validation.annotation.Validated;
import
org.springframework.web.bind.annotation.*
;
import
oshi.hardware.NetworkIF
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.Pattern
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.net.UnknownHostException
;
import
java.text.DecimalFormat
;
import
java.util.*
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -57,7 +59,8 @@ public class ProgramController {
@Value
(
value
=
"${apq.url.add-program}"
)
private
String
addProgramUrl
;
private
static
List
<
Map
<
String
,
String
>>
programList
;
@Resource
private
InstalledProgramCache
installedProgramCache
;
private
static
final
double
MIN_MATCH
=
0.5
;
...
...
@@ -66,18 +69,16 @@ public class ProgramController {
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
Integer
current
,
@RequestParam
(
required
=
false
,
defaultValue
=
"10"
)
Integer
size
)
throws
IOException
{
Page
<
Map
<
String
,
String
>>
page
=
new
Page
<>();
page
.
setCurrent
(
current
).
setSize
(
size
);
String
mac
=
getMacAddress
();
if
(
StrUtil
.
isBlank
(
mac
))
return
R
.
success
(
page
.
setTotal
(
0
).
setRecords
(
Collections
.
emptyList
())
);
if
(
StrUtil
.
isBlank
(
mac
))
return
R
.
error
(
"未获取到MAC地址"
);
String
url
=
gateway
+
StrUtil
.
format
(
type
.
equals
(
"install"
)
?
installUrl
:
upgradeUrl
,
mac
,
current
,
size
);
JSONObject
rsp
=
JSONUtil
.
parseObj
(
HttpUtil
.
get
(
url
));
if
(
ObjectUtil
.
notEqual
(
rsp
.
getInt
(
"code"
),
0
))
return
R
.
error
(
rsp
.
getStr
(
"msg"
));
page
.
setTotal
(
rsp
.
getLong
(
"total"
));
Page
<
Map
<
String
,
String
>>
page
=
new
Page
<>();
page
.
setCurrent
(
current
).
setSize
(
size
).
setTotal
(
rsp
.
getLong
(
"total"
));
JSONArray
rows
=
rsp
.
getJSONArray
(
"rows"
);
if
(
CollUtil
.
isEmpty
(
rows
))
return
R
.
success
(
page
.
setRecords
(
Collections
.
emptyList
()));
if
(
programList
==
null
)
loadProgramListJob
();
List
<
Map
<
String
,
String
>>
programs
=
programList
;
List
<
Map
<
String
,
String
>>
programs
=
installedProgramCache
.
getPrograms
();
List
<
Map
<
String
,
String
>>
list
=
rows
.
stream
().
map
(
JSONObject
.
class
::
cast
)
.
map
(
o
->
MapUtil
.<
String
,
String
>
builder
()
.
put
(
"id"
,
o
.
getStr
(
"id"
))
...
...
@@ -136,8 +137,7 @@ public class ProgramController {
@GetMapping
(
value
=
"get_version"
)
public
R
<
String
>
getVersion
(
@RequestParam
@NotBlank
String
name
)
throws
IOException
{
if
(
programList
==
null
)
loadProgramListJob
();
return
programList
.
stream
()
return
installedProgramCache
.
getPrograms
().
stream
()
.
collect
(
Collectors
.
toMap
(
p
->
StrUtil
.
similar
(
p
.
get
(
"name"
).
toLowerCase
(),
name
.
toLowerCase
()),
p
->
p
.
get
(
"version"
),
(
l
,
r
)
->
r
))
.
entrySet
()
...
...
@@ -150,52 +150,15 @@ public class ProgramController {
}
@Scheduled
(
fixedDelay
=
3000
)
protected
void
loadProgramListJob
()
throws
IOException
{
List
<
Map
<
String
,
String
>>
programs
=
new
ArrayList
<>();
Process
process
=
Runtime
.
getRuntime
()
.
exec
(
"cmd /c reg query HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
);
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
(),
"GBK"
)))
{
String
key
;
while
((
key
=
reader
.
readLine
())
!=
null
)
{
Map
<
String
,
String
>
info
=
queryProgramInfo
(
key
);
if
(
info
.
containsKey
(
"name"
))
programs
.
add
(
info
);
}
process
.
destroy
();
}
programList
=
programs
;
}
private
Map
<
String
,
String
>
queryProgramInfo
(
String
key
)
throws
IOException
{
Map
<
String
,
String
>
info
=
new
HashMap
<>();
Process
process
=
Runtime
.
getRuntime
().
exec
(
"cmd /c reg query "
+
key
);
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
(),
"GBK"
)))
{
reader
.
readLine
();
reader
.
readLine
();
String
line
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
line
=
line
.
trim
();
if
(
line
.
startsWith
(
"DisplayName"
))
{
info
.
put
(
"name"
,
line
.
replace
(
"DisplayName"
,
""
).
replace
(
"REG_SZ"
,
""
).
trim
());
}
else
if
(
line
.
startsWith
(
"DisplayVersion"
))
{
info
.
put
(
"version"
,
line
.
replace
(
"DisplayVersion"
,
""
).
replace
(
"REG_SZ"
,
""
).
trim
());
}
}
process
.
destroy
();
}
return
info
;
}
@Scheduled
(
fixedDelay
=
60000
)
protected
void
addProgram2Platform
()
throws
IOException
{
if
(
programList
==
null
)
loadProgramListJob
();
String
mac
=
getMacAddress
();
if
(
StrUtil
.
isBlank
(
mac
))
{
log
.
warn
(
"未获取到MAC地址"
);
return
;
}
List
<
String
>
programNames
=
programList
.
stream
().
map
(
p
->
p
.
get
(
"name"
)).
collect
(
Collectors
.
toList
());
List
<
String
>
programNames
=
installedProgramCache
.
getPrograms
()
.
stream
().
map
(
p
->
p
.
get
(
"name"
)).
collect
(
Collectors
.
toList
());
HttpUtil
.
post
(
gateway
+
addProgramUrl
,
JSONUtil
.
createObj
().
set
(
"macAddress"
,
mac
).
set
(
"programList"
,
programNames
).
toString
());
}
...
...
apq-pc-client/src/main/java/com/priusis/controller/RemoteControlController.java
浏览文件 @
aef8a52b
...
...
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateTime;
import
cn.hutool.core.util.StrUtil
;
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
;
...
...
@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Timer
;
...
...
@@ -30,10 +32,12 @@ import java.util.TimerTask;
public
class
RemoteControlController
{
@Value
(
value
=
"${vnc-repeater}"
)
private
String
vncRepeater
;
@Resource
private
InstalledProgramCache
installedProgramCache
;
/**
* 前端定时任务查询远程控制请求,不为空则表示有请求,展示确认弹窗
*/
...
...
@@ -52,10 +56,16 @@ public class RemoteControlController {
JSONObject
obj
=
JSONUtil
.
parseObj
(
requestParams
);
String
id
=
obj
.
getStr
(
"id"
);
// 设置ID
File
file
=
new
File
(
"C:\\Program Files\\uvnc bvba\\UltraVNC\\ultravnc.ini"
);
String
path
=
installedProgramCache
.
getPrograms
().
stream
()
.
filter
(
m
->
"UltraVNC"
.
equalsIgnoreCase
(
m
.
get
(
"name"
)))
.
findFirst
()
.
map
(
m
->
m
.
get
(
"path"
))
.
orElse
(
null
);
if
(
StrUtil
.
isBlank
(
path
))
return
R
.
error
(
"未安装UltraVNC"
);
File
file
=
new
File
(
path
+
"ultravnc.ini"
);
ConfigParser
configParser
=
new
ConfigParser
();
configParser
.
read
(
file
);
if
(!
configParser
.
hasSection
(
"admin"
))
configParser
.
addSection
(
"admin"
);
if
(!
configParser
.
hasSection
(
"admin"
))
configParser
.
addSection
(
"admin"
);
configParser
.
set
(
"admin"
,
"service_commandline"
,
StrUtil
.
format
(
"-autoreconnect ID:{} -connect {} -run"
,
id
,
vncRepeater
));
configParser
.
write
(
file
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论