Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
AD-Control-Golang
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陶腾飞
AD-Control-Golang
Commits
1c3dee1f
Commit
1c3dee1f
authored
Apr 11, 2022
by
陶腾飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2022/04/11 v2.3.1
parent
c21ecf1d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
18 deletions
+40
-18
adct/adct.go
+9
-4
public/msg_deal.go
+7
-3
public/msg_init.go
+1
-1
public/win.go
+23
-10
No files found.
adct/adct.go
View file @
1c3dee1f
...
...
@@ -134,10 +134,15 @@ func hour() {
}
}
func
hourUserActivitydetection
()
{
r
:=
pub
.
Execcmd_outputIgnoreError
(
"query user"
)
if
len
(
r
)
==
0
{
pub
.
SendADMsg
(
pub
.
Msg_Exec
,
pub
.
GJexec
(
pub
.
Msg_Exec_UserActivitydetection
,
"0"
))
}
// r2, err := pub.Execcmd_waitOutput("cmd /c query user")
// if err != nil {
// fmt.Printf("err %v\n", err)
// }
// fmt.Printf("return %s\n", string(r2))
// r := pub.Execcmd_outputIgnoreError("cmd /c query user")
// if len(r) == 0 {
pub
.
SendADMsg
(
pub
.
Msg_Exec
,
pub
.
GJexec
(
pub
.
Msg_Exec_UserActivitydetection
,
"0"
))
// }
}
//直接指定mac地址,不带主机名参数
...
...
public/msg_deal.go
View file @
1c3dee1f
...
...
@@ -225,6 +225,12 @@ func (exec *MJexec) MsgDeal() interface{} {
exec
.
Status
=
Msg_Exec_State_Over
case
Msg_Exec_UserActivitydetection
:
exec
.
Status
=
Msg_Exec_State_Over
r
:=
Execcmd_outputIgnoreError
(
fmt
.
Sprintf
(
"query user /server:%s"
,
exec
.
Computername
))
if
!
strings
.
Contains
(
string
(
r
),
"没有用户"
)
{
break
}
switch
Opt_UserActivitydetection_state
{
case
"0"
:
LOG
(
INFO
,
"opt_deny"
,
fmt
.
Sprintf
(
"禁止 %s 关机"
,
exec
.
Computername
))
...
...
@@ -232,12 +238,10 @@ func (exec *MJexec) MsgDeal() interface{} {
LOG
(
INFO
,
"opt_allow"
,
fmt
.
Sprintf
(
"允许 %s 关机"
,
exec
.
Computername
))
exec
.
Command
=
Msg_Exec_TurnOffPC_cmd
exec
.
IfMsg
=
true
exec
.
Explain
=
"没有活跃用户,
立即
关机"
exec
.
Explain
=
"没有活跃用户,
即将
关机"
exec
.
PsExec
()
}
exec
.
Status
=
Msg_Exec_State_Over
}
return
exec
}
...
...
public/msg_init.go
View file @
1c3dee1f
...
...
@@ -51,7 +51,7 @@ const Msg_Exec_State_Ack string = "ack"
const
Msg_Exec_State_Over
string
=
"over"
const
Msg_Exec_UserActivitydetection
string
=
"UserActivitydetection"
const
Msg_Exec_TurnOffPC
string
=
TurnOffPC
const
Msg_Exec_TurnOffPC_cmd
string
=
"shutdown -s -t 0"
const
Msg_Exec_TurnOffPC_cmd
string
=
"shutdown -s -t
30
0"
const
Msg_Exec_LogOffUser
string
=
LogOutUser
const
Msg_Exec_LogOffUser_cmd
string
=
"shutdown -l"
const
Msg_Exec_RebootWindows
string
=
"rebootWindows"
...
...
public/win.go
View file @
1c3dee1f
...
...
@@ -87,6 +87,24 @@ func Execcmd_wait(cmdargs string) {
LOG
(
ERROR
,
NULL
,
err
)
}
}
func
Execcmd_waitOutput
(
cmdargs
string
)
([]
byte
,
error
)
{
app
,
appargs
,
err
:=
execcmd_base
(
cmdargs
)
if
err
!=
nil
{
LOG
(
ERROR
,
NULL
,
err
)
return
nil
,
err
}
cmd
:=
exec
.
Command
(
app
,
appargs
...
)
if
err
:=
cmd
.
Start
();
err
!=
nil
{
LOG
(
ERROR
,
NULL
,
err
)
return
nil
,
err
}
err
=
cmd
.
Wait
()
if
err
!=
nil
{
LOG
(
ERROR
,
NULL
,
err
)
return
nil
,
err
}
return
cmd
.
CombinedOutput
()
}
// 包含标准错误的结果输出
func
Execcmd_output
(
cmdargs
string
)
[]
byte
{
...
...
@@ -104,16 +122,11 @@ func Execcmd_output(cmdargs string) []byte {
return
nil
}
func
Execcmd_outputIgnoreError
(
cmdargs
string
)
[]
byte
{
app
,
appargs
,
err
:=
execcmd_base
(
cmdargs
)
if
err
!=
nil
{
return
nil
}
out
,
err2
:=
exec
.
Command
(
app
,
appargs
...
)
.
Output
()
if
err2
!=
nil
{
return
nil
}
else
{
return
out
}
app
,
appargs
,
_
:=
execcmd_base
(
cmdargs
)
out
,
_
:=
exec
.
Command
(
app
,
appargs
...
)
.
CombinedOutput
()
outchinese
,
_
:=
simplifiedchinese
.
GBK
.
NewDecoder
()
.
Bytes
(
out
)
return
outchinese
}
func
Execcmd_wait_noargs
(
app
string
)
{
cmd
:=
exec
.
Command
(
app
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment