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
12f94acc
Commit
12f94acc
authored
Jul 21, 2022
by
陶腾飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2022/07/21 v2.6.1
parent
5f2218f8
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
216 additions
and
54 deletions
+216
-54
README.MD
+2
-1
adct/adct.go
+52
-4
adct/go.mod
+3
-0
public/cmdb.go
+1
-2
public/cmdbjson.go
+1
-29
public/dept.go
+44
-2
public/env.go
+3
-1
public/msg_deal.go
+64
-4
public/msg_init.go
+1
-0
public/send.go
+2
-2
public/user.go
+1
-4
public/win.go
+34
-4
registry/registry.go
+8
-1
No files found.
README.MD
View file @
12f94acc
...
@@ -106,7 +106,8 @@
...
@@ -106,7 +106,8 @@
-
2022/06/14 v2.5.7 更新日志输出、删除情报一二三部
-
2022/06/14 v2.5.7 更新日志输出、删除情报一二三部
-
2022/07/06 v2.5.8 增加抖音组,解决walk的反射问题,优化软件安装的下载速度
-
2022/07/06 v2.5.8 增加抖音组,解决walk的反射问题,优化软件安装的下载速度
-
2022/07/07 v2.5.9 隐藏下载软件的窗口
-
2022/07/07 v2.5.9 隐藏下载软件的窗口
-
2022/07/22 v2.6.0 使用企业微信作为注册个人账号的验证方式
-
2022/07/12 v2.6.0 使用企业微信作为注册个人账号的验证方式
-
2022/07/21 v2.6.1 自动初始化
## 四、其他说明
## 四、其他说明
...
...
adct/adct.go
View file @
12f94acc
...
@@ -10,6 +10,9 @@ import (
...
@@ -10,6 +10,9 @@ import (
"strings"
"strings"
pub
"git.zhiweidata.top/taotengfei/AD-Control-Golang/public"
pub
"git.zhiweidata.top/taotengfei/AD-Control-Golang/public"
reg
"git.zhiweidata.top/taotengfei/AD-Control-Golang/registry"
"github.com/lxn/walk"
.
"github.com/lxn/walk/declarative"
.
"github.com/lxn/walk/declarative"
)
)
...
@@ -19,6 +22,8 @@ const NULL = pub.NULL
...
@@ -19,6 +22,8 @@ const NULL = pub.NULL
var
sendserver
func
(
msgtype
string
,
v
interface
{})
var
sendserver
func
(
msgtype
string
,
v
interface
{})
const
reg_init
string
=
"init"
var
LOG
=
pub
.
LOG
var
LOG
=
pub
.
LOG
var
f
struct
{
var
f
struct
{
Force
bool
Force
bool
...
@@ -38,6 +43,7 @@ func main() {
...
@@ -38,6 +43,7 @@ func main() {
var
loglevel
=
flag
.
String
(
"loglevel"
,
INFO
,
""
)
var
loglevel
=
flag
.
String
(
"loglevel"
,
INFO
,
""
)
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"
)
flag
.
Parse
()
flag
.
Parse
()
...
@@ -70,6 +76,9 @@ func main() {
...
@@ -70,6 +76,9 @@ func main() {
pub
.
DomainCotroller
()
pub
.
DomainCotroller
()
wolPart
(
*
wolPartText
)
wolPart
(
*
wolPartText
)
}
else
{
}
else
{
if
reg
.
Query_ADPCLM
(
reg_init
)
==
""
{
reg
.
Write_ADPCLM
(
reg_init
,
*
init
)
}
gui
()
gui
()
}
}
...
@@ -130,7 +139,13 @@ func flag_report(s string) {
...
@@ -130,7 +139,13 @@ func flag_report(s string) {
d
=
[]
byte
(
pub
.
User_name_display
)
d
=
[]
byte
(
pub
.
User_name_display
)
case
pub
.
Msg_Report_WillLogOutUser
:
case
pub
.
Msg_Report_WillLogOutUser
:
d
=
[]
byte
(
pub
.
User_name_display
)
d
=
[]
byte
(
pub
.
User_name_display
)
case
pub
.
Msg_Report_MoveLDAPInstall
:
if
!
pub
.
Zhiweireach
()
{
return
}
if
_
,
err
:=
pub
.
GetHostnamePart
(
pub
.
User_computername
);
err
!=
nil
{
return
}
}
}
pub
.
SendADMsg
(
pub
.
Msg_Report
,
pub
.
GJreportString
(
s
,
string
(
d
)))
pub
.
SendADMsg
(
pub
.
Msg_Report
,
pub
.
GJreportString
(
s
,
string
(
d
)))
}
}
...
@@ -164,10 +179,11 @@ func wolPart(p string) {
...
@@ -164,10 +179,11 @@ func wolPart(p string) {
pub
.
SendADMsg
(
pub
.
Msg_Wake
,
pub
.
GJwakeList
(
p
))
pub
.
SendADMsg
(
pub
.
Msg_Wake
,
pub
.
GJwakeList
(
p
))
}
}
func
gui
()
{
func
gui
()
{
if
_
,
err
:=
(
MainWindow
{
if
_
,
err
:=
(
MainWindow
{
Title
:
"
软件安装
"
,
Title
:
"
域控制工具
"
,
MinSize
:
Size
{
Width
:
150
,
Height
:
1
00
},
MinSize
:
Size
{
Width
:
350
,
Height
:
2
00
},
Size
:
Size
{
Width
:
150
,
Height
:
1
00
},
Size
:
Size
{
Width
:
350
,
Height
:
2
00
},
Layout
:
VBox
{
MarginsZero
:
true
},
// 请勿删除
Layout
:
VBox
{
MarginsZero
:
true
},
// 请勿删除
Children
:
[]
Widget
{
Children
:
[]
Widget
{
PushButton
{
PushButton
{
...
@@ -180,5 +196,37 @@ func gui() {
...
@@ -180,5 +196,37 @@ func gui() {
}
}
}
}
func
guiInitDC
()
{
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
)
}
}
adct/go.mod
View file @
12f94acc
...
@@ -4,8 +4,11 @@ go 1.17
...
@@ -4,8 +4,11 @@ go 1.17
replace git.zhiweidata.top/taotengfei/AD-Control-Golang/public v0.0.0 => ..\public
replace git.zhiweidata.top/taotengfei/AD-Control-Golang/public v0.0.0 => ..\public
replace git.zhiweidata.top/taotengfei/AD-Control-Golang/registry v0.0.0 => ..\registry
require (
require (
git.zhiweidata.top/taotengfei/AD-Control-Golang/public v0.0.0
git.zhiweidata.top/taotengfei/AD-Control-Golang/public v0.0.0
git.zhiweidata.top/taotengfei/AD-Control-Golang/registry v0.0.0
github.com/lxn/walk v0.0.0-20210112085537-c389da54e794
github.com/lxn/walk v0.0.0-20210112085537-c389da54e794
)
)
...
...
public/cmdb.go
View file @
12f94acc
...
@@ -420,8 +420,7 @@ func CmdbPOST(url string, reqdata []byte) ([]byte, error) {
...
@@ -420,8 +420,7 @@ func CmdbPOST(url string, reqdata []byte) ([]byte, error) {
defer
res
.
Body
.
Close
()
defer
res
.
Body
.
Close
()
data
,
errdata
:=
ioutil
.
ReadAll
(
res
.
Body
)
data
,
errdata
:=
ioutil
.
ReadAll
(
res
.
Body
)
if
res
.
StatusCode
!=
200
{
if
res
.
StatusCode
!=
200
{
LOG
(
ERROR
,
"CMDB_POST"
,
fmt
.
Sprintf
(
"状态码:%d,路径:%s,返回数据:%s,参数:%s"
,
res
.
StatusCode
,
url
,
string
(
data
),
string
(
reqdata
)))
return
nil
,
fmt
.
Errorf
(
"状态码:%d,路径:%s,返回数据:%s,参数:%s"
,
res
.
StatusCode
,
url
,
string
(
data
),
string
(
reqdata
))
return
nil
,
err
}
}
if
errdata
!=
nil
&&
errdata
==
io
.
EOF
{
if
errdata
!=
nil
&&
errdata
==
io
.
EOF
{
return
data
,
nil
return
data
,
nil
...
...
public/cmdbjson.go
View file @
12f94acc
...
@@ -180,39 +180,11 @@ func GetCMDBPosition(location, dept string) string {
...
@@ -180,39 +180,11 @@ func GetCMDBPosition(location, dept string) string {
}
}
func
(
cir
*
CIRecordStartup
)
GetDept
()
(
string
,
error
)
{
func
(
cir
*
CIRecordStartup
)
GetDept
()
(
string
,
error
)
{
hostnameSplit
,
err
:=
GetHostnamePart
(
User_computername
)
hostnameSplit
,
err
:=
GetHostnamePart
(
User_computername
)
var
result
string
if
err
!=
nil
{
if
err
!=
nil
{
LOG
(
ERROR
,
""
,
err
)
LOG
(
ERROR
,
""
,
err
)
return
""
,
err
return
""
,
err
}
}
switch
hostnameSplit
[
1
]
{
result
:=
GetLDAPDeptFromHostnameP2
(
hostnameSplit
[
1
],
true
)
case
"JL"
:
result
=
Dept_zw_qbbm_jl_string
+
Dept_zw_qbbm_unit
case
"ZJ"
:
result
=
Dept_zw_qbbm_zj_string
+
Dept_zw_qbbm_unit
case
"MT"
:
result
=
Dept_zw_qbbm_mt_string
+
Dept_zw_qbbm_unit
case
"DD"
:
result
=
Dept_zw_qbbm_dd_string
+
Dept_zw_qbbm_unit
case
"JR"
:
result
=
Dept_zw_qbbm_jr_string
+
Dept_zw_qbbm_unit
case
"TXHD"
:
result
=
Dept_zw_qbbm_txhd_string
+
Dept_zw_qbbm_unit
case
"TXWJ"
:
result
=
Dept_zw_qbbm_txwj_string
+
Dept_zw_qbbm_unit
case
"JS"
:
result
=
Dept_zw_qbbm_js_string
+
Dept_zw_qbbm_unit
case
"JD"
:
result
=
Dept_zw_qbbm_jd_string
+
Dept_zw_qbbm_unit
case
"HW"
:
result
=
Dept_zw_qbbm_hw_string
+
Dept_zw_qbbm_unit
case
"DY"
:
result
=
Dept_zw_qbbm_dy_string
+
Dept_zw_qbbm_unit
case
"BGYJ"
:
result
=
Dept_zw_qbbm_bgyj_string
+
Dept_zw_qbbm_unit
default
:
result
=
ERROR
}
return
result
,
nil
return
result
,
nil
}
}
func
(
cir
*
CIRecordResult
)
String
()
([]
byte
,
error
)
{
func
(
cir
*
CIRecordResult
)
String
()
([]
byte
,
error
)
{
...
...
public/dept.go
View file @
12f94acc
...
@@ -36,6 +36,12 @@ const Dept_ldap_nb_12 = "宁波-12"
...
@@ -36,6 +36,12 @@ const Dept_ldap_nb_12 = "宁波-12"
const
Dept_ldap_nb_7
=
"宁波-704"
const
Dept_ldap_nb_7
=
"宁波-704"
const
Dept_ldap_zz_1613
=
"郑州-1613"
const
Dept_ldap_zz_1613
=
"郑州-1613"
var
Dept_qbbm_cmdb_ldap
map
[
string
]
string
=
map
[
string
]
string
{
Cmdb_Position_12
:
Dept_ldap_nb_12
,
Cmdb_Position_7
:
Dept_ldap_nb_7
,
Cmdb_Position_zhengzhou
:
Dept_ldap_zz_1613
,
}
var
Dept_zw_qbbm_map
map
[
string
]
string
=
map
[
string
]
string
{
var
Dept_zw_qbbm_map
map
[
string
]
string
=
map
[
string
]
string
{
"波塞冬Poseidon(华)"
:
Dept_zw_qbbm_hw_string
,
"波塞冬Poseidon(华)"
:
Dept_zw_qbbm_hw_string
,
"盖娅Gaia(美)"
:
Dept_zw_qbbm_mt_string
,
"盖娅Gaia(美)"
:
Dept_zw_qbbm_mt_string
,
...
@@ -91,12 +97,12 @@ func GetPostationFromHostname(hostname string) (string, error) {
...
@@ -91,12 +97,12 @@ func GetPostationFromHostname(hostname string) (string, error) {
case
HOST_Dept_DY
:
case
HOST_Dept_DY
:
return
Cmdb_Position_7
,
nil
return
Cmdb_Position_7
,
nil
default
:
default
:
return
""
,
fmt
.
Errorf
(
"%s
is error format
"
,
hostname
)
return
""
,
fmt
.
Errorf
(
"%s
不是预定的情报部门的格式
"
,
hostname
)
}
}
case
HOST_Region_ZZ
:
case
HOST_Region_ZZ
:
return
Cmdb_Position_zhengzhou
,
nil
return
Cmdb_Position_zhengzhou
,
nil
default
:
default
:
return
""
,
fmt
.
Errorf
(
"%s
is error format
"
,
hostname
)
return
""
,
fmt
.
Errorf
(
"%s
不是预定的情报部门的格式
"
,
hostname
)
}
}
}
}
...
@@ -120,3 +126,39 @@ func GetQBBMdeptFromHostname(host, region string) (string, error) {
...
@@ -120,3 +126,39 @@ func GetQBBMdeptFromHostname(host, region string) (string, error) {
}
}
return
r
,
err
return
r
,
err
}
}
// 根据主机名的第二部分获取LDAP的名称
func
GetLDAPDeptFromHostnameP2
(
part
string
,
groupname
bool
)
string
{
var
unit
string
if
groupname
{
unit
=
Dept_zw_qbbm_unit
}
var
result
string
switch
part
{
case
"JL"
:
result
=
Dept_zw_qbbm_jl_string
+
unit
case
"ZJ"
:
result
=
Dept_zw_qbbm_zj_string
+
unit
case
"MT"
:
result
=
Dept_zw_qbbm_mt_string
+
unit
case
"DD"
:
result
=
Dept_zw_qbbm_dd_string
+
unit
case
"JR"
:
result
=
Dept_zw_qbbm_jr_string
+
unit
case
"TXHD"
:
result
=
Dept_zw_qbbm_txhd_string
+
unit
case
"TXWJ"
:
result
=
Dept_zw_qbbm_txwj_string
+
unit
case
"JS"
:
result
=
Dept_zw_qbbm_js_string
+
unit
case
"JD"
:
result
=
Dept_zw_qbbm_jd_string
+
unit
case
"HW"
:
result
=
Dept_zw_qbbm_hw_string
+
unit
case
"DY"
:
result
=
Dept_zw_qbbm_dy_string
+
unit
case
"BGYJ"
:
result
=
Dept_zw_qbbm_bgyj_string
+
unit
}
return
result
}
public/env.go
View file @
12f94acc
...
@@ -14,12 +14,14 @@ const SymbolDH = "、"
...
@@ -14,12 +14,14 @@ const SymbolDH = "、"
// AD-Control //
// AD-Control //
const
Version
string
=
"2.6.
0
"
const
Version
string
=
"2.6.
1
"
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"
const
Host_thserver
string
=
"THSERVER"
const
Host_thserver
string
=
"THSERVER"
const
Host_thserver_lan
string
=
"192.168.2.3"
const
Host_zzserver
string
=
"ZZSERVER"
const
Host_zzserver
string
=
"ZZSERVER"
const
Host_zzserver_lan
string
=
"192.168.27.2"
const
DaemonListen
string
=
":16823"
const
DaemonListen
string
=
":16823"
const
DaemonLogListen
string
=
":16824"
const
DaemonLogListen
string
=
":16824"
...
...
public/msg_deal.go
View file @
12f94acc
...
@@ -143,7 +143,9 @@ func (rep *MJreport) MsgDeal() interface{} {
...
@@ -143,7 +143,9 @@ func (rep *MJreport) MsgDeal() interface{} {
case
Msg_Report_WillLogInUser
:
case
Msg_Report_WillLogInUser
:
l
:=
fmt
.
Sprintf
(
"%s 在 %s 登陆"
,
rep
.
DataStr
,
rep
.
Computername
)
l
:=
fmt
.
Sprintf
(
"%s 在 %s 登陆"
,
rep
.
DataStr
,
rep
.
Computername
)
LOG
(
INFO
,
rep
.
Instruction
,
l
)
LOG
(
INFO
,
rep
.
Instruction
,
l
)
SendWXWrokTextToChatAccountManager
(
l
)
if
err
:=
SendWXWrokTextToChatAccountManager
(
l
);
err
!=
nil
{
LOG
(
ERROR
,
rep
.
Instruction
,
err
.
Error
())
}
case
Msg_Report_WillLogOutUser
:
case
Msg_Report_WillLogOutUser
:
l
:=
fmt
.
Sprintf
(
"%s 在 %s 注销"
,
rep
.
DataStr
,
rep
.
Computername
)
l
:=
fmt
.
Sprintf
(
"%s 在 %s 注销"
,
rep
.
DataStr
,
rep
.
Computername
)
...
@@ -300,7 +302,8 @@ func (rep *MJreport) MsgDeal() interface{} {
...
@@ -300,7 +302,8 @@ func (rep *MJreport) MsgDeal() interface{} {
break
break
}
}
LOG
(
INFO
,
rep
.
Instruction
,
dept
+
name
+
" 个人账号注销完成"
)
LOG
(
INFO
,
rep
.
Instruction
,
dept
+
name
+
" 个人账号注销完成"
)
rep
.
SendWXwork
(
"个人账号注销完成"
)
SendWxworkTextToHR
(
dept
+
name
+
" 个人账号注销完成"
)
}
}
// 获取软件文件名
// 获取软件文件名
...
@@ -330,6 +333,63 @@ func (rep *MJreport) MsgDeal() interface{} {
...
@@ -330,6 +333,63 @@ func (rep *MJreport) MsgDeal() interface{} {
case
Msg_status_deal
:
case
Msg_status_deal
:
MS
.
S
=
rep
.
Explain
MS
.
S
=
rep
.
Explain
}
}
// LDAP中移动到安装目录
case
Msg_Report_MoveLDAPInstall
:
switch
rep
.
Status
{
case
Msg_status_commit
:
hostname
:=
strings
.
TrimRight
(
rep
.
Username
,
"$"
)
LOG
(
INFO
,
rep
.
Instruction
,
hostname
+
"移动到安装目录"
)
region
,
err
:=
GetPostationFromHostname
(
hostname
)
if
err
!=
nil
{
LOG
(
WARN
,
rep
.
Instruction
,
err
)
break
}
d
:=
fmt
.
Sprintf
(
`(Get-ADComputer %s).DistinguishedName`
,
hostname
)
dout
,
err
:=
PSCommandOutput
(
d
)
if
err
!=
nil
{
LOG
(
ERROR
,
rep
.
Instruction
,
err
.
Error
()
+
dout
)
break
}
ou
:=
strings
.
Split
(
dout
,
SymbolSplit
)
if
ou
[
2
]
==
"OU=Doc"
{
LOG
(
INFO
,
rep
.
Instruction
,
hostname
+
"移动到情报目录"
)
ps
:=
fmt
.
Sprintf
(
`Get-ADComputer %s | Move-ADObject -TargetPath (Get-ADOrganizationalUnit -Filter "Name -eq '%s'" -searchbase 'OU=情报部门,DC=zhiweireach,DC=com' | Where-Object -filter {$_.DistinguishedName -like "*%s*"}).DistinguishedName`
,
hostname
,
GetLDAPDeptFromHostnameP2
(
strings
.
Split
(
hostname
,
SymbolHostname
)[
1
],
false
),
Dept_qbbm_cmdb_ldap
[
region
])
out
,
err
:=
PSCommandOutput
(
ps
)
if
err
!=
nil
{
LOG
(
ERROR
,
rep
.
Instruction
,
err
.
Error
()
+
out
)
break
}
if
err
:=
RestartRemotePCForNow
(
hostname
);
err
!=
nil
{
LOG
(
ERROR
,
rep
.
Instruction
,
"error restart "
+
hostname
)
}
}
else
if
ou
[
1
]
==
"OU=Doc"
{
LOG
(
INFO
,
rep
.
Instruction
,
hostname
+
"移动到安装目录"
)
ps
:=
fmt
.
Sprintf
(
`Get-ADComputer %s | Move-ADObject -TargetPath (Get-ADOrganizationalUnit -Filter "Name -eq '%s'" -searchbase 'OU=Doc,DC=zhiweireach,DC=com').DistinguishedName`
,
hostname
,
Dept_qbbm_cmdb_ldap
[
region
])
out
,
err
:=
PSCommandOutput
(
ps
)
if
err
!=
nil
{
LOG
(
ERROR
,
rep
.
Instruction
,
err
.
Error
()
+
out
)
break
}
if
err
:=
RestartRemotePCForNow
(
hostname
);
err
!=
nil
{
LOG
(
ERROR
,
rep
.
Instruction
,
"error restart "
+
hostname
)
}
}
else
{
LOG
(
ERROR
,
rep
.
Instruction
,
hostname
+
"异常LDAP:"
+
dout
)
}
case
Msg_status_deal
:
for
{
Execcmd_wait
(
`gpupdate /force /boot`
)
Delay
(
30
)
RestartPCForNow
()
}
}
default
:
default
:
LOG
(
ERROR
,
"Default Report Json"
,
rep
.
Instruction
)
LOG
(
ERROR
,
"Default Report Json"
,
rep
.
Instruction
)
}
}
...
@@ -623,7 +683,7 @@ func (wxwork *MJwxwork) MsgDealSend() {
...
@@ -623,7 +683,7 @@ func (wxwork *MJwxwork) MsgDealSend() {
LOG
(
INFO
,
wxwork
.
Instruction
,
fmt
.
Sprintf
(
"host:%s,name:%s"
,
pc
,
wxwork
.
Name
))
LOG
(
INFO
,
wxwork
.
Instruction
,
fmt
.
Sprintf
(
"host:%s,name:%s"
,
pc
,
wxwork
.
Name
))
if
err
:=
RestartPCForNow
(
pc
);
err
!=
nil
{
if
err
:=
Restart
Remote
PCForNow
(
pc
);
err
!=
nil
{
LOG
(
ERROR
,
wxwork
.
Instruction
,
err
)
LOG
(
ERROR
,
wxwork
.
Instruction
,
err
)
wxwork
.
SendText
(
Error_WXWork_Fail_ReTry
)
wxwork
.
SendText
(
Error_WXWork_Fail_ReTry
)
return
return
...
@@ -682,7 +742,7 @@ func (wxwork *MJwxwork) MsgDealSend() {
...
@@ -682,7 +742,7 @@ func (wxwork *MJwxwork) MsgDealSend() {
LOG
(
INFO
,
wxwork
.
Instruction
,
fmt
.
Sprintf
(
"host:%s,name:%s"
,
pc
,
wxwork
.
Name
))
LOG
(
INFO
,
wxwork
.
Instruction
,
fmt
.
Sprintf
(
"host:%s,name:%s"
,
pc
,
wxwork
.
Name
))
if
err
:=
ShutdownPCForNow
(
pc
);
err
!=
nil
{
if
err
:=
Shutdown
Remote
PCForNow
(
pc
);
err
!=
nil
{
LOG
(
ERROR
,
wxwork
.
Instruction
,
err
)
LOG
(
ERROR
,
wxwork
.
Instruction
,
err
)
wxwork
.
SendText
(
Error_WXWork_Fail_ReTry
)
wxwork
.
SendText
(
Error_WXWork_Fail_ReTry
)
return
return
...
...
public/msg_init.go
View file @
12f94acc
...
@@ -39,6 +39,7 @@ const Msg_Report_SignUPUser string = "SignUPUser"
...
@@ -39,6 +39,7 @@ const Msg_Report_SignUPUser string = "SignUPUser"
const
Msg_Report_Dimission
string
=
"Dimission"
const
Msg_Report_Dimission
string
=
"Dimission"
const
Msg_Report_GetSoftlike
string
=
"GetSoftlike"
const
Msg_Report_GetSoftlike
string
=
"GetSoftlike"
const
Msg_Report_GetURL
string
=
"GetURL"
const
Msg_Report_GetURL
string
=
"GetURL"
const
Msg_Report_MoveLDAPInstall
string
=
"MoveLDAPInstall"
// msg exec type ////////////////////////////////////////////////////////////////
// msg exec type ////////////////////////////////////////////////////////////////
...
...
public/send.go
View file @
12f94acc
...
@@ -206,8 +206,8 @@ func SendWxworkTextToAdmins(nameOrID string) error {
...
@@ -206,8 +206,8 @@ func SendWxworkTextToAdmins(nameOrID string) error {
func
SendWxworkTextToHR
(
nameOrID
string
)
error
{
func
SendWxworkTextToHR
(
nameOrID
string
)
error
{
return
SendWxworkTextToAUser
(
"TaoTengFei|BaoJiaQi|BianShuang"
,
nameOrID
)
return
SendWxworkTextToAUser
(
"TaoTengFei|BaoJiaQi|BianShuang"
,
nameOrID
)
}
}
func
SendWXWrokTextToChatAccountManager
(
Conentstring
string
)
error
{
func
SendWXWrokTextToChatAccountManager
(
content
string
)
error
{
return
SendWXWrokTextToChat
(
WXWORK_zwDevopsChatAccountManager
,
Conentstring
)
return
SendWXWrokTextToChat
(
WXWORK_zwDevopsChatAccountManager
,
content
)
}
}
// 根据主机位置定义发送的服务器
// 根据主机位置定义发送的服务器
...
...
public/user.go
View file @
12f94acc
...
@@ -69,7 +69,7 @@ func Adserver() bool {
...
@@ -69,7 +69,7 @@ func Adserver() bool {
func
DomainCotroller
()
bool
{
func
DomainCotroller
()
bool
{
var
r
bool
var
r
bool
switch
User_computername
{
switch
User_computername
{
case
Host_adserver
:
case
Host_adserver
:
fmt
.
Printf
(
"分发d'd"
,
var
)
r
=
true
r
=
true
case
Host_thserver
:
case
Host_thserver
:
r
=
true
r
=
true
...
@@ -87,9 +87,6 @@ func GetHostnamePart(hostname string) ([]string, error) {
...
@@ -87,9 +87,6 @@ func GetHostnamePart(hostname string) ([]string, error) {
}
}
return
n
,
nil
return
n
,
nil
}
}
func
GetIPFromInterface
()
{
}
// 判断计算机是否在zhiweireach中
// 判断计算机是否在zhiweireach中
func
Zhiweireach
()
bool
{
func
Zhiweireach
()
bool
{
...
...
public/win.go
View file @
12f94acc
...
@@ -52,7 +52,6 @@ func execcmd_base(cmdargs string) (string, []string, error) {
...
@@ -52,7 +52,6 @@ func execcmd_base(cmdargs string) (string, []string, error) {
app
=
cmdargs
app
=
cmdargs
appargs
[
0
]
=
""
appargs
[
0
]
=
""
}
}
fmt
.
Println
(
cmdargs
)
LOG
(
INFO
,
"CMD"
,
cmdargs
)
LOG
(
INFO
,
"CMD"
,
cmdargs
)
return
app
,
appargs
,
nil
return
app
,
appargs
,
nil
}
}
...
@@ -184,6 +183,24 @@ func PSCommandOutput(cmd string) (string, error) {
...
@@ -184,6 +183,24 @@ func PSCommandOutput(cmd string) (string, error) {
}
}
return
strings
.
TrimSpace
(
string
(
out
)),
nil
return
strings
.
TrimSpace
(
string
(
out
)),
nil
}
}
func
PSCommandPromptWait
(
cmd
string
)
error
{
if
cmd
==
""
{
return
Error_Lost_Parameter
}
cmd
=
"powershell -command "
+
cmd
app
,
appargs
,
err
:=
execcmd_base
(
cmd
)
if
err
!=
nil
{
return
err
}
r
:=
exec
.
Command
(
app
,
appargs
...
)
if
err
:=
r
.
Start
();
err
!=
nil
{
return
err
}
if
err
:=
r
.
Wait
();
err
!=
nil
{
return
err
}
return
err
}
func
PSCommandWait
(
cmd
string
)
error
{
func
PSCommandWait
(
cmd
string
)
error
{
if
cmd
==
""
{
if
cmd
==
""
{
return
Error_Lost_Parameter
return
Error_Lost_Parameter
...
@@ -592,7 +609,7 @@ func GetIPFromNslookup() string {
...
@@ -592,7 +609,7 @@ func GetIPFromNslookup() string {
}
}
for
_
,
line
:=
range
strings
.
Split
(
result
,
"
\n
"
)
{
for
_
,
line
:=
range
strings
.
Split
(
result
,
"
\n
"
)
{
ip
:=
strings
.
Split
(
line
,
"."
)
ip
:=
strings
.
Split
(
line
,
"."
)
if
ip
[
0
]
==
"192"
&&
ip
[
1
]
==
"168"
&&
len
(
ip
[
2
])
==
1
{
if
ip
[
0
]
==
"192"
&&
ip
[
1
]
==
"168"
&&
len
(
ip
[
2
])
==
1
&&
(
ip
[
2
]
==
"0"
||
ip
[
2
]
==
"1"
||
ip
[
2
]
==
"2"
||
ip
[
2
]
==
"27"
)
{
return
line
return
line
}
}
}
}
...
@@ -619,12 +636,25 @@ func GetMacaddressFromIP(ip string) string {
...
@@ -619,12 +636,25 @@ func GetMacaddressFromIP(ip string) string {
result
,
_
:=
PSCommandOutputNoSplit
(
cmd
)
result
,
_
:=
PSCommandOutputNoSplit
(
cmd
)
return
strings
.
TrimSpace
(
result
)
return
strings
.
TrimSpace
(
result
)
}
}
func
GetPrimaryDNSFromIP
(
ip
string
)
string
{
cmd
:=
fmt
.
Sprintf
(
`(Get-NetAdapter -ifindex ((Get-NetIPAddress -IPAddress %s).InterfaceIndex) | Get-DnsClientServerAddress -AddressFamily IPV4 ).ServerAddresses`
,
ip
)
result
,
_
:=
PSCommandOutputNoSplit
(
cmd
)
result
=
strings
.
TrimSpace
(
result
)
if
strings
.
Contains
(
result
,
"
\n
"
)
{
return
strings
.
Split
(
result
,
"
\n
"
)[
0
]
}
return
result
}
// 电源管理
// 电源管理
func
RestartPCForNow
(
pc
string
)
error
{
func
Restart
Remote
PCForNow
(
pc
string
)
error
{
return
Execcmd_nowait
(
fmt
.
Sprintf
(
`shutdown -r -t 0 -m \\%s`
,
pc
))
return
Execcmd_nowait
(
fmt
.
Sprintf
(
`shutdown -r -t 0 -m \\%s`
,
pc
))
}
}
func
RestartPCForNow
()
error
{
return
Execcmd_nowait
(
`shutdown -r -t -0`
)
}
func
ShutdownPCForNow
(
pc
string
)
error
{
func
Shutdown
Remote
PCForNow
(
pc
string
)
error
{
return
Execcmd_nowait
(
fmt
.
Sprintf
(
`shutdown -s -t 0 -m \\%s`
,
pc
))
return
Execcmd_nowait
(
fmt
.
Sprintf
(
`shutdown -s -t 0 -m \\%s`
,
pc
))
}
}
registry/registry.go
View file @
12f94acc
...
@@ -45,7 +45,14 @@ func Query_ADPC(key string) string {
...
@@ -45,7 +45,14 @@ func Query_ADPC(key string) string {
Exist_item
(
HKCU
,
REG_ADCONTROL
)
Exist_item
(
HKCU
,
REG_ADCONTROL
)
return
Query_key_one
(
HKCU
,
REG_ADCONTROL
,
key
)
return
Query_key_one
(
HKCU
,
REG_ADCONTROL
,
key
)
}
}
func
Write_ADPCLM
(
key
,
value
string
)
{
Exist_item
(
HKLM
,
REG_ADCONTROL
)
Write_key_one
(
HKLM
,
REG_ADCONTROL
,
key
,
value
)
}
func
Query_ADPCLM
(
key
string
)
string
{
Exist_item
(
HKLM
,
REG_ADCONTROL
)
return
Query_key_one
(
HKLM
,
REG_ADCONTROL
,
key
)
}
func
Exist_item
(
root
int
,
path
string
)
{
func
Exist_item
(
root
int
,
path
string
)
{
registry
.
CreateKey
(
prase
(
&
root
),
path
,
registry
.
ALL_ACCESS
)
registry
.
CreateKey
(
prase
(
&
root
),
path
,
registry
.
ALL_ACCESS
)
}
}
...
...
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