Commit c21ecf1d by 陶腾飞

2022/04/11 v2.3.1

parent b3732fea
...@@ -92,6 +92,7 @@ ...@@ -92,6 +92,7 @@
- 2022/04/05 v2.2.4 将支持通过adct全局唤醒 - 2022/04/05 v2.2.4 将支持通过adct全局唤醒
- 2022/04/09 v2.2.5 修复IP地址、MAC地址获取失败的问题,添加cmdb信息更新时间字段,优化log日志,开机时将确定主机位置,修复DDR4的判断超过速率字段出现的场景导致无法判断DDR4的问题,小工具菜单名优化,远程唤醒优化 - 2022/04/09 v2.2.5 修复IP地址、MAC地址获取失败的问题,添加cmdb信息更新时间字段,优化log日志,开机时将确定主机位置,修复DDR4的判断超过速率字段出现的场景导致无法判断DDR4的问题,小工具菜单名优化,远程唤醒优化
- 2022/04/11 v2.3.0 添加无用户登录时的工位活动检测 - 2022/04/11 v2.3.0 添加无用户登录时的工位活动检测
- 2022/04/11 v2.3.1 修复运行时无法检测环境变量问题
## 四、其他说明 ## 四、其他说明
......
...@@ -132,7 +132,6 @@ func hour() { ...@@ -132,7 +132,6 @@ func hour() {
if hour >= 18 || hour <= 6 { if hour >= 18 || hour <= 6 {
hourUserActivitydetection() hourUserActivitydetection()
} }
hourUserActivitydetection()
} }
func hourUserActivitydetection() { func hourUserActivitydetection() {
r := pub.Execcmd_outputIgnoreError("query user") r := pub.Execcmd_outputIgnoreError("query user")
......
...@@ -3,6 +3,7 @@ package main ...@@ -3,6 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os"
"time" "time"
pub "git.zhiweidata.top/taotengfei/AD-Control-Golang/public" pub "git.zhiweidata.top/taotengfei/AD-Control-Golang/public"
...@@ -12,15 +13,32 @@ import ( ...@@ -12,15 +13,32 @@ import (
const reg_cmdb_token = "cmdb_token" const reg_cmdb_token = "cmdb_token"
func messionloop() { func messionloop() {
ticker := time.NewTicker(3600 * time.Second)
defer ticker.Stop()
// 若通道为空,则阻塞 // 若通道为空,则阻塞
// 若通道有数据,则读取 // 若通道有数据,则读取
// 若通道关闭,则退出 // 若通道关闭,则退出
for range ticker.C { if !setCMDBToken() {
setCMDBToken() os.Exit(-1)
} }
pub.Opt_UserActivitydetection_state = getOption(pub.Opt_UserActivitydetection)
pub.Opt_SendWX_state = getOption(pub.Opt_SendWX)
go func() {
onehour := time.NewTicker(1 * time.Minute)
defer onehour.Stop()
for range onehour.C {
setCMDBToken()
}
}()
go func() {
oneminute := time.NewTicker(1 * time.Minute)
defer oneminute.Stop()
for range oneminute.C {
pub.Opt_UserActivitydetection_state = getOption(pub.Opt_UserActivitydetection)
pub.Opt_SendWX_state = getOption(pub.Opt_SendWX)
}
}()
} }
func setCMDBToken() bool { func setCMDBToken() bool {
...@@ -50,3 +68,6 @@ func setCMDBToken() bool { ...@@ -50,3 +68,6 @@ func setCMDBToken() bool {
pub.Cmdb_token = string(r.Token) pub.Cmdb_token = string(r.Token)
return true return true
} }
func getOption(opt string) string {
return reg.Query_DC(opt)
}
...@@ -18,10 +18,6 @@ const NULL = pub.NULL ...@@ -18,10 +18,6 @@ const NULL = pub.NULL
//pub.Loglevel = pub.DEBUG //pub.Loglevel = pub.DEBUG
func mainInit() { func mainInit() {
if !setCMDBToken() {
os.Exit(-1)
}
if !pub.DomainCotroller() && pub.Windows() { if !pub.DomainCotroller() && pub.Windows() {
os.Exit(-1) os.Exit(-1)
} }
...@@ -37,12 +33,12 @@ func mainInit() { ...@@ -37,12 +33,12 @@ func mainInit() {
pub.AD_User_ADControl = reg.Query_DC("ADControl") pub.AD_User_ADControl = reg.Query_DC("ADControl")
pub.AD_User_ADControl_key = reg.Query_DC("ADControl_key") pub.AD_User_ADControl_key = reg.Query_DC("ADControl_key")
pub.CmdbUrl = reg.Query_DC("cmdb_url") pub.CmdbUrl = reg.Query_DC("cmdb_url")
pub.CmdbCITypeComputer = reg.Query_DC("cmdb_CITypeComputer")
messionloop()
} }
func main() { func main() {
mainInit() mainInit()
go messionloop()
go listenLog() go listenLog()
listenMsg() listenMsg()
......
...@@ -11,7 +11,7 @@ const SymbolHostname = "-" ...@@ -11,7 +11,7 @@ const SymbolHostname = "-"
// AD-Control // // AD-Control //
const Version string = "2.3.0" const Version string = "2.3.1"
const Host_adserver string = "ADSERVER" const Host_adserver string = "ADSERVER"
const Host_adserver_ip string = "192.168.0.20" const Host_adserver_ip string = "192.168.0.20"
const Host_thserver string = "THSERVER" const Host_thserver string = "THSERVER"
...@@ -108,5 +108,8 @@ var AD_User_ADControl string ...@@ -108,5 +108,8 @@ var AD_User_ADControl string
var AD_User_ADControl_key string var AD_User_ADControl_key string
// RealTimeEnv // // RealTimeEnv //
var Env_UserActivitydetection = "ADControl_UserActivitydetection" const Opt_UserActivitydetection = "ADControl_UserActivitydetection"
var Env_sendwx = "ADControl_sendwx" const Opt_SendWX = "ADControl_SendWX"
var Opt_UserActivitydetection_state string
var Opt_SendWX_state string
...@@ -225,18 +225,19 @@ func (exec *MJexec) MsgDeal() interface{} { ...@@ -225,18 +225,19 @@ 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:
s := GetEnv(Env_UserActivitydetection) switch Opt_UserActivitydetection_state {
if s == "1" { case "0":
LOG(INFO, "", fmt.Sprintf("%s 允许 %s 关机", s, exec.Computername)) LOG(INFO, "opt_deny", fmt.Sprintf("禁止 %s 关机", exec.Computername))
case "1":
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
} else {
LOG(INFO, "", fmt.Sprintf("%s 禁止 %s 关机", s, exec.Computername))
} }
exec.Status = Msg_Exec_State_Over
} }
return exec return exec
} }
......
...@@ -114,8 +114,8 @@ func SendPostRequestWithData(link *string, data interface{}) ([]byte, error) { ...@@ -114,8 +114,8 @@ func SendPostRequestWithData(link *string, data interface{}) ([]byte, error) {
func SendWX(Content string) { func SendWX(Content string) {
if DomainCotroller() { if DomainCotroller() {
if GetEnv(Env_sendwx) == "0" { if Opt_SendWX_state == "0" {
LOG(WARN, "ENV", "系统变量检测到取消微信发送") LOG(WARN, "opt_deny", "取消微信发送")
return return
} }
} }
......
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