Commit a44fe036 by 陶腾飞

20230-03-01 v2.6.6

parent 7aca468f
...@@ -112,6 +112,7 @@ ...@@ -112,6 +112,7 @@
- 2022/07/28 v2.6.3 小工具初始化excel保护视图问题 - 2022/07/28 v2.6.3 小工具初始化excel保护视图问题
- 2022/07-31 v2.6.4 为支持windows激活添加功能 - 2022/07-31 v2.6.4 为支持windows激活添加功能
- 2022/07-31 v2.6.5 小工具支持批量执行命令 - 2022/07-31 v2.6.5 小工具支持批量执行命令
- 2022/08-18 v2.6.6 adct在开机时判断用户超时登录
## 四、其他说明 ## 四、其他说明
......
package main package main
import ( import (
"log"
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
...@@ -13,7 +11,7 @@ import ( ...@@ -13,7 +11,7 @@ import (
reg "git.zhiweidata.top/taotengfei/AD-Control-Golang/registry" reg "git.zhiweidata.top/taotengfei/AD-Control-Golang/registry"
"github.com/lxn/walk" "github.com/lxn/walk"
. "github.com/lxn/walk/declarative" // . "github.com/lxn/walk/declarative"
) )
const INFO = pub.INFO const INFO = pub.INFO
...@@ -44,6 +42,7 @@ func main() { ...@@ -44,6 +42,7 @@ func main() {
var force = flag.Bool("force", false, "force exec,ignore other") var force = flag.Bool("force", false, "force exec,ignore other")
var quick = flag.Bool("quick", false, "quickly exec") var quick = flag.Bool("quick", false, "quickly exec")
var init = flag.String("init", "", "init args") var init = flag.String("init", "", "init args")
var hoststartup = flag.Bool("hoststartup", false, "set startup")
flag.Parse() flag.Parse()
...@@ -75,11 +74,13 @@ func main() { ...@@ -75,11 +74,13 @@ func main() {
} else if *wolPartText != "" { } else if *wolPartText != "" {
pub.DomainCotroller() pub.DomainCotroller()
wolPart(*wolPartText) wolPart(*wolPartText)
} else if *hoststartup {
host_startup()
} else { } else {
if reg.Query_ADPCLM(reg_init) == "" { if reg.Query_ADPCLM(reg_init) == "" {
reg.Write_ADPCLM(reg_init, *init) reg.Write_ADPCLM(reg_init, *init)
} }
gui() // gui()
} }
} }
...@@ -125,6 +126,7 @@ func flag_report(s string) { ...@@ -125,6 +126,7 @@ func flag_report(s string) {
LOG(ERROR, s, err) LOG(ERROR, s, err)
os.Exit(-1) os.Exit(-1)
} }
case pub.Msg_Report_WillTurnOffPC: case pub.Msg_Report_WillTurnOffPC:
var cir pub.CIRecordShutdown var cir pub.CIRecordShutdown
cir.Shutdown_time = pub.GetNowTimeString() cir.Shutdown_time = pub.GetNowTimeString()
...@@ -178,55 +180,73 @@ func wolALL() { ...@@ -178,55 +180,73 @@ func wolALL() {
func wolPart(p string) { func wolPart(p string) {
pub.SendADMsg(pub.Msg_Wake, pub.GJwakeList(p)) pub.SendADMsg(pub.Msg_Wake, pub.GJwakeList(p))
} }
func gui() {
if _, err := (MainWindow{
Title: "域控制工具",
MinSize: Size{Width: 350, Height: 200},
Size: Size{Width: 350, Height: 200},
Layout: VBox{MarginsZero: true}, // 请勿删除
Children: []Widget{
PushButton{
Text: "初始化域计算机",
OnClicked: guiInitDC,
},
},
}.Run()); err != nil {
log.Fatal(err)
}
}
func guiInitDC() {
checkNet()
joinDomain()
}
// // func gui() {
func checkNet() {
IP := pub.GetIPFromNslookup() // if _, err := (MainWindow{
DNS := pub.GetPrimaryDNSFromIP(IP) // Title: "域控制工具",
if !(DNS == pub.Host_adserver_lan || DNS == pub.Host_thserver_lan || DNS == pub.Host_zzserver_lan) { // MinSize: Size{Width: 350, Height: 200},
go Msg(fmt.Sprintf("IP和DNS不是预定值!\n当前IP:%s,DNS:%s", IP, DNS)) // Size: Size{Width: 350, Height: 200},
return // Layout: VBox{MarginsZero: true}, // 请勿删除
} // Children: []Widget{
// PushButton{
// Text: "初始化域计算机",
// OnClicked: guiInitDC,
// },
// },
// }.Run()); err != nil {
// log.Fatal(err)
// }
// }
// func guiInitDC() {
// checkNet()
// joinDomain()
// }
// //
// func checkNet() {
// IP := pub.GetIPFromNslookup()
// DNS := pub.GetPrimaryDNSFromIP(IP)
// if !(DNS == pub.Host_adserver_lan || DNS == pub.Host_thserver_lan || DNS == pub.Host_zzserver_lan) {
// go Msg(fmt.Sprintf("IP和DNS不是预定值!\n当前IP:%s,DNS:%s", IP, DNS))
// return
// }
// }
// func joinDomain() {
// if pub.Zhiweireach() {
// return
// }
// hostname := reg.Query_ADPCLM(reg_init)
// if hostname == "" {
// go Msg("空值hostname")
// return
// }
// ps := fmt.Sprintf(`Add-Computer -DomainName "zhiweireach.com" -Credential (Get-Credential -Message '输入域管理员账号') -newname %s -restart`, hostname)
// err := pub.PSCommandPromptWait(ps)
// if err != nil {
// go Msg(err.Error())
// return
// }
// }
// 显示带确定的消息框
func Msg(message string) {
walk.MsgBox(*new(walk.Form), "提示", message, walk.MsgBoxIconInformation)
} }
func joinDomain() {
if pub.Zhiweireach() { // adct在启动时的操作
func host_startup() {
var count int = 0
for {
out := pub.Execcmd_output("quser")
if !strings.Contains(string(out), "* 没有用户") {
return return
} }
hostname := reg.Query_ADPCLM(reg_init) count++
if hostname == "" { if count >= 19 {
go Msg("空值hostname") flag_report(pub.Msg_Report_TimeOutTurnOffPC)
return pub.Execcmd_nowait("shutdown -s -t 0")
} }
ps := fmt.Sprintf(`Add-Computer -DomainName "zhiweireach.com" -Credential (Get-Credential -Message '输入域管理员账号') -newname %s -restart`, hostname) pub.Delay(30)
err := pub.PSCommandPromptWait(ps)
if err != nil {
go Msg(err.Error())
return
} }
} }
// 显示带确定的消息框
func Msg(message string) {
walk.MsgBox(*new(walk.Form), "提示", message, walk.MsgBoxIconInformation)
}
...@@ -21,8 +21,9 @@ func mainInit() { ...@@ -21,8 +21,9 @@ func mainInit() {
if !pub.DomainCotroller() && pub.Windows() { if !pub.DomainCotroller() && pub.Windows() {
os.Exit(-1) os.Exit(-1)
} }
l, _ = os.OpenFile(pub.User_userprofile+`\users.log`, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766) l, _ = os.OpenFile(pub.User_userprofile+`\daemon.log`, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
if pub.Adserver() {
pub.WxworkBotLink = reg.Query_DC("WxworkBotLink") pub.WxworkBotLink = reg.Query_DC("WxworkBotLink")
pub.WxworkTokenMsgSend = reg.Query_DC("WxworkTokenMsgSend") pub.WxworkTokenMsgSend = reg.Query_DC("WxworkTokenMsgSend")
pub.WxworkEncodingAseKey = reg.Query_DC("WxworkEncodingAseKey") pub.WxworkEncodingAseKey = reg.Query_DC("WxworkEncodingAseKey")
...@@ -33,8 +34,12 @@ func mainInit() { ...@@ -33,8 +34,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")
pub.Defult_user_key = reg.Query_DC("ad_default_user_key") pub.Defult_user_key = reg.Query_DC("ad_default_user_key")
pub.WxWorkToken = reg.Query_DC("WxworkToken")
messionloop() messionloop()
}
} }
func main() { func main() {
mainInit() mainInit()
......
...@@ -14,7 +14,7 @@ const SymbolDH = "、" ...@@ -14,7 +14,7 @@ const SymbolDH = "、"
// AD-Control // // AD-Control //
const Version string = "2.6.5" const Version string = "2.6.6"
const Host_adserver_lan string = "192.168.0.20" const Host_adserver_lan string = "192.168.0.20"
const Host_adserver_wan string = "115.231.214.234" const Host_adserver_wan string = "115.231.214.234"
const Host_adserver string = "ADSERVER" const Host_adserver string = "ADSERVER"
...@@ -61,6 +61,7 @@ var Dir_tmp string = GetEnv("tmp") ...@@ -61,6 +61,7 @@ var Dir_tmp string = GetEnv("tmp")
const Dir_softlike string = `H:\software\softlike\` const Dir_softlike string = `H:\software\softlike\`
const Dir_application string = `H:\software\application\` const Dir_application string = `H:\software\application\`
const Dir_otherFile string = `H:\file\`
// application // // application //
const App_MultiSplit string = SMB_ADSoftOthTool + "win_MultiSplit.exe" const App_MultiSplit string = SMB_ADSoftOthTool + "win_MultiSplit.exe"
......
...@@ -28,6 +28,7 @@ func DealMsgEnter(w http.ResponseWriter, r *http.Request) { ...@@ -28,6 +28,7 @@ func DealMsgEnter(w http.ResponseWriter, r *http.Request) {
// 处理消息 // 处理消息
func DealMsg(url []string, query string, unmsg []byte) ([]byte, error) { func DealMsg(url []string, query string, unmsg []byte) ([]byte, error) {
msgtype := url[1] msgtype := url[1]
var ret []byte var ret []byte
switch msgtype { switch msgtype {
...@@ -50,8 +51,17 @@ func DealMsg(url []string, query string, unmsg []byte) ([]byte, error) { ...@@ -50,8 +51,17 @@ func DealMsg(url []string, query string, unmsg []byte) ([]byte, error) {
LOG(ERROR, NULL, err) LOG(ERROR, NULL, err)
return nil, err return nil, err
} }
case Msg_WXAuth: case Msg_OthFile:
var err error
file := url[2]
ret, err = ioutil.ReadFile(Dir_otherFile + file)
if err != nil {
LOG(ERROR, NULL, err)
return nil, err
}
case Msg_WXAuth:
LOG(INFO, "", query)
return []byte(WXAuth(query)), nil return []byte(WXAuth(query)), nil
// 报告 消息 // 报告 消息
...@@ -90,6 +100,11 @@ func DealMsg(url []string, query string, unmsg []byte) ([]byte, error) { ...@@ -90,6 +100,11 @@ func DealMsg(url []string, query string, unmsg []byte) ([]byte, error) {
ret = ReParseJson(&ice) ret = ReParseJson(&ice)
// 将包含关于知微运维平台的人员、权限变化的任何消息 // 将包含关于知微运维平台的人员、权限变化的任何消息
case "server_auth":
LOG(INFO, msgtype, "算了直接验证通过吧")
return []byte("success"), nil
default: default:
msg := ParseWX(query, &unmsg) msg := ParseWX(query, &unmsg)
go msg.MsgDealSend() go msg.MsgDealSend()
...@@ -129,6 +144,8 @@ func (rep *MJreport) MsgDeal() interface{} { ...@@ -129,6 +144,8 @@ func (rep *MJreport) MsgDeal() interface{} {
case Msg_status_deal: case Msg_status_deal:
return nil return nil
} }
case Msg_Report_TimeOutTurnOffPC:
LOG(INFO, rep.Instruction, rep.Computername+" 超时关机")
case Msg_Report_WillTurnOnPC: case Msg_Report_WillTurnOnPC:
switch rep.Status { switch rep.Status {
...@@ -776,7 +793,7 @@ func (wxwork *MJwxwork) MsgDealSend() { ...@@ -776,7 +793,7 @@ func (wxwork *MJwxwork) MsgDealSend() {
// 电源管理 电源状态 // 电源管理 电源状态
case WXEK_zwDevopsPowerStatus: case WXEK_zwDevopsPowerStatus:
wxwork.SendText("收到查询指令,正在处理!") wxwork.SendText("收到查询指令,正在处理!")
LOG(INFO, "WXEK_zwDevopsPowerStatus", wxwork.Name)
if c, err := LDAP_ExistAccount(wxwork.Name); err != nil { if c, err := LDAP_ExistAccount(wxwork.Name); err != nil {
LOG(ERROR, wxwork.Instruction, err) LOG(ERROR, wxwork.Instruction, err)
} else { } else {
...@@ -813,6 +830,15 @@ func (wxwork *MJwxwork) MsgDealSend() { ...@@ -813,6 +830,15 @@ func (wxwork *MJwxwork) MsgDealSend() {
} else { } else {
wxwork.Result = "主机已关闭" wxwork.Result = "主机已关闭"
} }
if wxwork.UserID == "ShaoQi" {
status1, _ := PSTest_Connection("192.168.0.4")
status2, _ := PSTest_Connection("192.168.0.197")
if status1 || status2 {
wxwork.Result += ",他在!"
} else {
wxwork.Result += ",他不在!"
}
}
// 主机管理 获取主机信息 // 主机管理 获取主机信息
case WXEK_zwDevopsHostGetinfo: case WXEK_zwDevopsHostGetinfo:
......
...@@ -17,6 +17,7 @@ const Msg_status_deal string = "deal" ...@@ -17,6 +17,7 @@ const Msg_status_deal string = "deal"
const Msg_File string = "file" const Msg_File string = "file"
const Msg_Softlike string = "softlike" const Msg_Softlike string = "softlike"
const Msg_OthFile string = "othfile"
const Msg_WXAuth string = "wxauth" const Msg_WXAuth string = "wxauth"
const Msg_Report string = "report" const Msg_Report string = "report"
const Msg_Exec string = "exec" const Msg_Exec string = "exec"
...@@ -35,6 +36,7 @@ const Msg_Report_TurnOnPC string = "TurnOnPC" ...@@ -35,6 +36,7 @@ const Msg_Report_TurnOnPC string = "TurnOnPC"
const Msg_Report_TurnOffPC string = "TurnOffPC" const Msg_Report_TurnOffPC string = "TurnOffPC"
const Msg_Report_WillTurnOnPC string = "WillTurnOnPC" const Msg_Report_WillTurnOnPC string = "WillTurnOnPC"
const Msg_Report_WillTurnOffPC string = "WillTurnOffPC" const Msg_Report_WillTurnOffPC string = "WillTurnOffPC"
const Msg_Report_TimeOutTurnOffPC string = "TimeOutTurnOffPC"
const Msg_Report_UpdatePrimaryHost string = "UpdatePrimaryHost" const Msg_Report_UpdatePrimaryHost string = "UpdatePrimaryHost"
const Msg_Report_SignUPUser string = "SignUPUser" const Msg_Report_SignUPUser string = "SignUPUser"
const Msg_Report_Dimission string = "Dimission" const Msg_Report_Dimission string = "Dimission"
......
...@@ -215,7 +215,7 @@ func SendWxworkTextToAdmins(nameOrID string) error { ...@@ -215,7 +215,7 @@ func SendWxworkTextToAdmins(nameOrID string) error {
// 发送应用消息给HR // 发送应用消息给HR
func SendWxworkTextToHR(nameOrID string) error { func SendWxworkTextToHR(nameOrID string) error {
return SendWxworkTextToAUser("TaoTengFei|BaoJiaQi|BianShuang", nameOrID) return SendWxworkTextToAUser("TaoTengFei|BaoJiaQi|BianShuang|FengPeiGe", nameOrID)
} }
// 发送应用消息给群聊 域用户管理与通知 // 发送应用消息给群聊 域用户管理与通知
......
...@@ -35,7 +35,6 @@ func GetEnvFqdn(s string) string { ...@@ -35,7 +35,6 @@ func GetEnvFqdn(s string) string {
} }
// local exec // local exec
func execcmd_base(cmdargs string) (string, []string, error) { func execcmd_base(cmdargs string) (string, []string, error) {
if cmdargs == "" { if cmdargs == "" {
return "", nil, Error_Null_Command return "", nil, Error_Null_Command
...@@ -50,7 +49,7 @@ func execcmd_base(cmdargs string) (string, []string, error) { ...@@ -50,7 +49,7 @@ func execcmd_base(cmdargs string) (string, []string, error) {
appargs = strings.Split(cmdargs[spaceindex+1:], " ") appargs = strings.Split(cmdargs[spaceindex+1:], " ")
} else { } else {
app = cmdargs app = cmdargs
appargs[0] = "" // appargs[0] = ""
} }
return app, appargs, nil return app, appargs, nil
} }
...@@ -161,7 +160,6 @@ func Execcmd_nowait_noargs(app string) { ...@@ -161,7 +160,6 @@ func Execcmd_nowait_noargs(app string) {
} }
// PowerShell // PowerShell
func PSCommandOutput(cmd string) (string, error) { func PSCommandOutput(cmd string) (string, error) {
if cmd == "" { if cmd == "" {
return "", Error_Lost_Parameter return "", Error_Lost_Parameter
......
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