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
a44fe036
Commit
a44fe036
authored
Mar 01, 2023
by
陶腾飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
20230-03-01 v2.6.6
parent
7aca468f
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
110 additions
and
57 deletions
+110
-57
README.MD
+1
-0
adct/adct.go
+69
-49
daemon/daemon.go
+6
-1
public/env.go
+2
-1
public/msg_deal.go
+28
-2
public/msg_init.go
+2
-0
public/send.go
+1
-1
public/win.go
+1
-3
No files found.
README.MD
View file @
a44fe036
...
...
@@ -112,6 +112,7 @@
-
2022/07/28 v2.6.3 小工具初始化excel保护视图问题
-
2022/07-31 v2.6.4 为支持windows激活添加功能
-
2022/07-31 v2.6.5 小工具支持批量执行命令
-
2022/08-18 v2.6.6 adct在开机时判断用户超时登录
## 四、其他说明
...
...
adct/adct.go
View file @
a44fe036
package
main
import
(
"log"
"encoding/json"
"flag"
"fmt"
...
...
@@ -13,7 +11,7 @@ import (
reg
"git.zhiweidata.top/taotengfei/AD-Control-Golang/registry"
"github.com/lxn/walk"
.
"github.com/lxn/walk/declarative"
//
. "github.com/lxn/walk/declarative"
)
const
INFO
=
pub
.
INFO
...
...
@@ -44,6 +42,7 @@ func main() {
var
force
=
flag
.
Bool
(
"force"
,
false
,
"force exec,ignore other"
)
var
quick
=
flag
.
Bool
(
"quick"
,
false
,
"quickly exec"
)
var
init
=
flag
.
String
(
"init"
,
""
,
"init args"
)
var
hoststartup
=
flag
.
Bool
(
"hoststartup"
,
false
,
"set startup"
)
flag
.
Parse
()
...
...
@@ -75,11 +74,13 @@ func main() {
}
else
if
*
wolPartText
!=
""
{
pub
.
DomainCotroller
()
wolPart
(
*
wolPartText
)
}
else
if
*
hoststartup
{
host_startup
()
}
else
{
if
reg
.
Query_ADPCLM
(
reg_init
)
==
""
{
reg
.
Write_ADPCLM
(
reg_init
,
*
init
)
}
gui
()
//
gui()
}
}
...
...
@@ -125,6 +126,7 @@ func flag_report(s string) {
LOG
(
ERROR
,
s
,
err
)
os
.
Exit
(
-
1
)
}
case
pub
.
Msg_Report_WillTurnOffPC
:
var
cir
pub
.
CIRecordShutdown
cir
.
Shutdown_time
=
pub
.
GetNowTimeString
()
...
...
@@ -178,55 +180,73 @@ func wolALL() {
func
wolPart
(
p
string
)
{
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
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 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 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
}
hostname
:=
reg
.
Query_ADPCLM
(
reg_init
)
if
hostname
==
""
{
go
Msg
(
"空值hostname"
)
return
count
++
if
count
>=
19
{
flag_report
(
pub
.
Msg_Report_TimeOutTurnOffPC
)
pub
.
Execcmd_nowait
(
"shutdown -s -t 0"
)
}
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
pub
.
Delay
(
30
)
}
}
// 显示带确定的消息框
func
Msg
(
message
string
)
{
walk
.
MsgBox
(
*
new
(
walk
.
Form
),
"提示"
,
message
,
walk
.
MsgBoxIconInformation
)
}
daemon/daemon.go
View file @
a44fe036
...
...
@@ -21,8 +21,9 @@ func mainInit() {
if
!
pub
.
DomainCotroller
()
&&
pub
.
Windows
()
{
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
.
WxworkTokenMsgSend
=
reg
.
Query_DC
(
"WxworkTokenMsgSend"
)
pub
.
WxworkEncodingAseKey
=
reg
.
Query_DC
(
"WxworkEncodingAseKey"
)
...
...
@@ -33,8 +34,12 @@ func mainInit() {
pub
.
AD_User_ADControl
=
reg
.
Query_DC
(
"ADControl"
)
pub
.
AD_User_ADControl_key
=
reg
.
Query_DC
(
"ADControl_key"
)
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
.
WxWorkToken
=
reg
.
Query_DC
(
"WxworkToken"
)
messionloop
()
}
}
func
main
()
{
mainInit
()
...
...
public/env.go
View file @
a44fe036
...
...
@@ -14,7 +14,7 @@ const SymbolDH = "、"
// 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_wan
string
=
"115.231.214.234"
const
Host_adserver
string
=
"ADSERVER"
...
...
@@ -61,6 +61,7 @@ var Dir_tmp string = GetEnv("tmp")
const
Dir_softlike
string
=
`H:\software\softlike\`
const
Dir_application
string
=
`H:\software\application\`
const
Dir_otherFile
string
=
`H:\file\`
// application //
const
App_MultiSplit
string
=
SMB_ADSoftOthTool
+
"win_MultiSplit.exe"
...
...
public/msg_deal.go
View file @
a44fe036
...
...
@@ -28,6 +28,7 @@ func DealMsgEnter(w http.ResponseWriter, r *http.Request) {
// 处理消息
func
DealMsg
(
url
[]
string
,
query
string
,
unmsg
[]
byte
)
([]
byte
,
error
)
{
msgtype
:=
url
[
1
]
var
ret
[]
byte
switch
msgtype
{
...
...
@@ -50,8 +51,17 @@ func DealMsg(url []string, query string, unmsg []byte) ([]byte, error) {
LOG
(
ERROR
,
NULL
,
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
// 报告 消息
...
...
@@ -90,6 +100,11 @@ func DealMsg(url []string, query string, unmsg []byte) ([]byte, error) {
ret
=
ReParseJson
(
&
ice
)
// 将包含关于知微运维平台的人员、权限变化的任何消息
case
"server_auth"
:
LOG
(
INFO
,
msgtype
,
"算了直接验证通过吧"
)
return
[]
byte
(
"success"
),
nil
default
:
msg
:=
ParseWX
(
query
,
&
unmsg
)
go
msg
.
MsgDealSend
()
...
...
@@ -129,6 +144,8 @@ func (rep *MJreport) MsgDeal() interface{} {
case
Msg_status_deal
:
return
nil
}
case
Msg_Report_TimeOutTurnOffPC
:
LOG
(
INFO
,
rep
.
Instruction
,
rep
.
Computername
+
" 超时关机"
)
case
Msg_Report_WillTurnOnPC
:
switch
rep
.
Status
{
...
...
@@ -776,7 +793,7 @@ func (wxwork *MJwxwork) MsgDealSend() {
// 电源管理 电源状态
case
WXEK_zwDevopsPowerStatus
:
wxwork
.
SendText
(
"收到查询指令,正在处理!"
)
LOG
(
INFO
,
"WXEK_zwDevopsPowerStatus"
,
wxwork
.
Name
)
if
c
,
err
:=
LDAP_ExistAccount
(
wxwork
.
Name
);
err
!=
nil
{
LOG
(
ERROR
,
wxwork
.
Instruction
,
err
)
}
else
{
...
...
@@ -813,6 +830,15 @@ func (wxwork *MJwxwork) MsgDealSend() {
}
else
{
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
:
...
...
public/msg_init.go
View file @
a44fe036
...
...
@@ -17,6 +17,7 @@ const Msg_status_deal string = "deal"
const
Msg_File
string
=
"file"
const
Msg_Softlike
string
=
"softlike"
const
Msg_OthFile
string
=
"othfile"
const
Msg_WXAuth
string
=
"wxauth"
const
Msg_Report
string
=
"report"
const
Msg_Exec
string
=
"exec"
...
...
@@ -35,6 +36,7 @@ const Msg_Report_TurnOnPC string = "TurnOnPC"
const
Msg_Report_TurnOffPC
string
=
"TurnOffPC"
const
Msg_Report_WillTurnOnPC
string
=
"WillTurnOnPC"
const
Msg_Report_WillTurnOffPC
string
=
"WillTurnOffPC"
const
Msg_Report_TimeOutTurnOffPC
string
=
"TimeOutTurnOffPC"
const
Msg_Report_UpdatePrimaryHost
string
=
"UpdatePrimaryHost"
const
Msg_Report_SignUPUser
string
=
"SignUPUser"
const
Msg_Report_Dimission
string
=
"Dimission"
...
...
public/send.go
View file @
a44fe036
...
...
@@ -215,7 +215,7 @@ func SendWxworkTextToAdmins(nameOrID string) error {
// 发送应用消息给HR
func
SendWxworkTextToHR
(
nameOrID
string
)
error
{
return
SendWxworkTextToAUser
(
"TaoTengFei|BaoJiaQi|BianShuang"
,
nameOrID
)
return
SendWxworkTextToAUser
(
"TaoTengFei|BaoJiaQi|BianShuang
|FengPeiGe
"
,
nameOrID
)
}
// 发送应用消息给群聊 域用户管理与通知
...
...
public/win.go
View file @
a44fe036
...
...
@@ -35,7 +35,6 @@ func GetEnvFqdn(s string) string {
}
// local exec
func
execcmd_base
(
cmdargs
string
)
(
string
,
[]
string
,
error
)
{
if
cmdargs
==
""
{
return
""
,
nil
,
Error_Null_Command
...
...
@@ -50,7 +49,7 @@ func execcmd_base(cmdargs string) (string, []string, error) {
appargs
=
strings
.
Split
(
cmdargs
[
spaceindex
+
1
:
],
" "
)
}
else
{
app
=
cmdargs
appargs
[
0
]
=
""
//
appargs[0] = ""
}
return
app
,
appargs
,
nil
}
...
...
@@ -161,7 +160,6 @@ func Execcmd_nowait_noargs(app string) {
}
// PowerShell
func
PSCommandOutput
(
cmd
string
)
(
string
,
error
)
{
if
cmd
==
""
{
return
""
,
Error_Lost_Parameter
...
...
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