Commit 1c3dee1f by 陶腾飞

2022/04/11 v2.3.1

parent c21ecf1d
...@@ -134,10 +134,15 @@ func hour() { ...@@ -134,10 +134,15 @@ func hour() {
} }
} }
func hourUserActivitydetection() { func hourUserActivitydetection() {
r := pub.Execcmd_outputIgnoreError("query user") // r2, err := pub.Execcmd_waitOutput("cmd /c query user")
if len(r) == 0 { // 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")) pub.SendADMsg(pub.Msg_Exec, pub.GJexec(pub.Msg_Exec_UserActivitydetection, "0"))
} // }
} }
//直接指定mac地址,不带主机名参数 //直接指定mac地址,不带主机名参数
......
...@@ -225,6 +225,12 @@ func (exec *MJexec) MsgDeal() interface{} { ...@@ -225,6 +225,12 @@ func (exec *MJexec) MsgDeal() interface{} {
exec.Status = Msg_Exec_State_Over exec.Status = Msg_Exec_State_Over
case Msg_Exec_UserActivitydetection: 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 { switch Opt_UserActivitydetection_state {
case "0": case "0":
LOG(INFO, "opt_deny", fmt.Sprintf("禁止 %s 关机", exec.Computername)) LOG(INFO, "opt_deny", fmt.Sprintf("禁止 %s 关机", exec.Computername))
...@@ -232,12 +238,10 @@ func (exec *MJexec) MsgDeal() interface{} { ...@@ -232,12 +238,10 @@ func (exec *MJexec) MsgDeal() interface{} {
LOG(INFO, "opt_allow", fmt.Sprintf("允许 %s 关机", exec.Computername)) LOG(INFO, "opt_allow", fmt.Sprintf("允许 %s 关机", exec.Computername))
exec.Command = Msg_Exec_TurnOffPC_cmd exec.Command = Msg_Exec_TurnOffPC_cmd
exec.IfMsg = true exec.IfMsg = true
exec.Explain = "没有活跃用户,立即关机" exec.Explain = "没有活跃用户,即将关机"
exec.PsExec() exec.PsExec()
} }
exec.Status = Msg_Exec_State_Over
} }
return exec return exec
} }
......
...@@ -51,7 +51,7 @@ const Msg_Exec_State_Ack string = "ack" ...@@ -51,7 +51,7 @@ const Msg_Exec_State_Ack string = "ack"
const Msg_Exec_State_Over string = "over" const Msg_Exec_State_Over string = "over"
const Msg_Exec_UserActivitydetection string = "UserActivitydetection" const Msg_Exec_UserActivitydetection string = "UserActivitydetection"
const Msg_Exec_TurnOffPC string = TurnOffPC 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 300"
const Msg_Exec_LogOffUser string = LogOutUser const Msg_Exec_LogOffUser string = LogOutUser
const Msg_Exec_LogOffUser_cmd string = "shutdown -l" const Msg_Exec_LogOffUser_cmd string = "shutdown -l"
const Msg_Exec_RebootWindows string = "rebootWindows" const Msg_Exec_RebootWindows string = "rebootWindows"
......
...@@ -87,6 +87,24 @@ func Execcmd_wait(cmdargs string) { ...@@ -87,6 +87,24 @@ func Execcmd_wait(cmdargs string) {
LOG(ERROR, NULL, err) 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 { func Execcmd_output(cmdargs string) []byte {
...@@ -104,16 +122,11 @@ func Execcmd_output(cmdargs string) []byte { ...@@ -104,16 +122,11 @@ func Execcmd_output(cmdargs string) []byte {
return nil return nil
} }
func Execcmd_outputIgnoreError(cmdargs string) []byte { func Execcmd_outputIgnoreError(cmdargs string) []byte {
app, appargs, err := execcmd_base(cmdargs) app, appargs, _ := execcmd_base(cmdargs)
if err != nil { out, _ := exec.Command(app, appargs...).CombinedOutput()
return nil outchinese, _ := simplifiedchinese.GBK.NewDecoder().Bytes(out)
}
out, err2 := exec.Command(app, appargs...).Output() return outchinese
if err2 != nil {
return nil
} else {
return out
}
} }
func Execcmd_wait_noargs(app string) { func Execcmd_wait_noargs(app string) {
cmd := exec.Command(app) cmd := exec.Command(app)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment