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
93a98aca
Commit
93a98aca
authored
May 14, 2020
by
陶腾飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
copy to wedrive
parent
45389ac1
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
316 additions
and
196 deletions
+316
-196
adct/adct.go
+7
-6
daemon/daemon.exe
+0
-0
daemon/daemon.go
+18
-3
public/env.go
+38
-136
public/msg_deal.go
+29
-5
public/msg_init.go
+152
-20
public/print.go
+0
-12
public/public.go
+10
-6
public/win.go
+22
-1
users/menu.go
+23
-4
users/users.exe
+0
-0
users/users.go
+17
-3
No files found.
adct/adct.go
View file @
93a98aca
...
@@ -48,7 +48,7 @@ func flag_woluser(user * string){
...
@@ -48,7 +48,7 @@ func flag_woluser(user * string){
}
}
func
flag_hour
(){
func
flag_hour
(){
nh
:=
time
.
Now
()
.
Hour
()
nh
:=
time
.
Now
()
.
Hour
()
public
.
PrintLog
(
nh
)
switch
nh
{
switch
nh
{
case
0
:
case
0
:
...
@@ -56,12 +56,12 @@ func flag_hour(){
...
@@ -56,12 +56,12 @@ func flag_hour(){
public
.
Execcmd_nowait
(
"shutdown -s -t 300"
)
public
.
Execcmd_nowait
(
"shutdown -s -t 300"
)
break
break
case
1
:
case
1
:
public
.
MsgBox
(
`5分钟后,即将
重启
,运行Z:\tools\【工具】取消关机.bat`
)
public
.
MsgBox
(
`5分钟后,即将
关机
,运行Z:\tools\【工具】取消关机.bat`
)
public
.
Execcmd_nowait
(
"shutdown -
r
-t 300"
)
public
.
Execcmd_nowait
(
"shutdown -
s
-t 300"
)
break
break
case
2
:
case
2
:
public
.
MsgBox
(
`5分钟后,即将
重启
,运行Z:\tools\【工具】取消关机.bat`
)
public
.
MsgBox
(
`5分钟后,即将
关机
,运行Z:\tools\【工具】取消关机.bat`
)
public
.
Execcmd_nowait
(
"shutdown -
r
-t 300"
)
public
.
Execcmd_nowait
(
"shutdown -
s
-t 300"
)
break
break
case
3
:
case
3
:
public
.
MsgBox
(
`5分钟后,即将关机,运行Z:\tools\【工具】取消关机.bat`
)
public
.
MsgBox
(
`5分钟后,即将关机,运行Z:\tools\【工具】取消关机.bat`
)
...
@@ -70,7 +70,7 @@ func flag_hour(){
...
@@ -70,7 +70,7 @@ func flag_hour(){
case
4
:
case
4
:
case
5
:
case
5
:
case
6
:
case
6
:
default
:
default
:
break
break
}
}
}
}
\ No newline at end of file
daemon/daemon.exe
View file @
93a98aca
No preview for this file type
daemon/daemon.go
View file @
93a98aca
...
@@ -6,21 +6,36 @@ import (
...
@@ -6,21 +6,36 @@ import (
"io"
"io"
"bufio"
"bufio"
)
)
//---------------------
//---------------------
//
//
// Daemon
// Daemon
//
//
//---------------------
//---------------------
func
daemonInit
(){
func
daemonInit
(){
if
public
.
NotExist
(
public
.
DocuBase
){
if
public
.
NotExist
(
public
.
DocuBase
){
public
.
PrintLog
(
"init: create Documents Base -> "
,
public
.
DocuBase
)
public
.
PrintLog
(
"init: create Documents Base -> "
,
public
.
DocuBase
)
public
.
Mkdir
(
public
.
DocuBase
)
public
.
Mkdir
(
public
.
DocuBase
)
}
}
public
.
PrintLog
(
public
.
Msg_Report_DaemonStart
)
public
.
PrintLog
(
public
.
Msg_Report_DaemonStart
)
if
notadserver
()
{
// 发送 Daemon Start
if
adserver
()
{
// 同时 检查 版本
// 1 初始化 微盘复制状态
public
.
CopyStatusWeDrive
=
make
(
map
[
string
]
bool
)
public
.
CopyStatusWeDrive
[
public
.
Zhiwei_Dept_HB
]
=
true
public
.
CopyStatusWeDrive
[
public
.
Zhiwei_Dept_LP
]
=
true
public
.
CopyStatusWeDrive
[
public
.
Zhiwei_Dept_JR
]
=
true
public
.
CopyStatusWeDrive
[
public
.
Zhiwei_Dept_JD
]
=
true
public
.
CopyStatusWeDrive
[
public
.
Zhiwei_Dept_TXHD
]
=
true
public
.
CopyStatusWeDrive
[
public
.
Zhiwei_Dept_TXWJ
]
=
true
public
.
CopyStatusWeDrive
[
public
.
Zhiwei_Dept_BGYJZX
]
=
true
public
.
CopyStatusWeDrive
[
public
.
Zhiwei_Dept_TECH
]
=
true
}
else
{
// 1 发送 Daemon Start
public
.
SendServerReport
(
public
.
Msg_Report_DaemonStart
)
public
.
SendServerReport
(
public
.
Msg_Report_DaemonStart
)
}
}
}
}
...
...
public/env.go
View file @
93a98aca
...
@@ -21,10 +21,13 @@ var User_computername string = GetEnv("COMPUTERNAME")
...
@@ -21,10 +21,13 @@ var User_computername string = GetEnv("COMPUTERNAME")
var
User_homeshare
string
=
GetEnv
(
"HOMESHARE"
)
var
User_homeshare
string
=
GetEnv
(
"HOMESHARE"
)
var
User_userdomain
string
=
GetEnv
(
"USERDOMAIN"
)
var
User_userdomain
string
=
GetEnv
(
"USERDOMAIN"
)
var
User_fqdn_cn
string
=
GetEnvFqdn
(
"CN"
)
var
User_fqdn_cn
string
=
GetEnvFqdn
(
"CN"
)
var
User_dept
string
=
GetEnvFqdn
(
"OU"
)
var
User_dept_str
string
=
GetEnvFqdn
(
"OU"
)
var
User_dept
string
=
GetEnv
(
"DEPT"
)
var
User_appdata
string
=
GetEnv
(
"appdata"
)
var
User_sid
string
=
Reg_query_key_one
(
HKCU
,
`Software\Microsoft\Windows\CurrentVersion\FileAssociations`
,
"UserSid"
)
var
User_sid
string
=
Reg_query_key_one
(
HKCU
,
`Software\Microsoft\Windows\CurrentVersion\FileAssociations`
,
"UserSid"
)
var
User_sessionID
string
=
Reg_query_item_one
(
HKU
,
User_sid
+
`\Volatile Environment`
)
var
User_sessionID
string
=
Reg_query_item_one
(
HKU
,
User_sid
+
`\Volatile Environment`
)
var
User_Dir_WeDrive
string
=
User_appdata
+
`\Tencent\WXWork\Data`
// win-computer env /////////////////////////////////////////////////////
// win-computer env /////////////////////////////////////////////////////
const
Env_FreeFileSyncExe
string
=
`C:\Progra~2\zhiwei\FreeFileSync_10.22\FreeFileSync.exe`
const
Env_FreeFileSyncExe
string
=
`C:\Progra~2\zhiwei\FreeFileSync_10.22\FreeFileSync.exe`
...
@@ -37,36 +40,39 @@ const Env_MainADHostname string = "ADSERVER"
...
@@ -37,36 +40,39 @@ const Env_MainADHostname string = "ADSERVER"
const
Env_SMBAdserver
string
=
`\\`
+
Env_MainADHostname
+
`\`
const
Env_SMBAdserver
string
=
`\\`
+
Env_MainADHostname
+
`\`
const
Env_ADSoft
string
=
Env_SMBAdserver
+
"software"
const
Env_ADSoft
string
=
Env_SMBAdserver
+
"software"
const
Env_ADMain
string
=
Env_SMBAdserver
+
"ADMAIN"
const
Env_ADMain
string
=
Env_SMBAdserver
+
"ADMAIN"
var
Env_ADMainDeptShare
string
=
Env_ADMain
+
`\`
+
User_dept
+
`\`
+
"部门共享"
var
Env_ADMainDeptShare
string
=
Env_ADMain
+
`\`
+
User_dept
_str
+
`\`
+
"部门共享"
const
Env_ADSoftlike
string
=
Env_ADSoft
+
`\`
+
"softlike"
const
Env_ADSoftlike
string
=
Env_ADSoft
+
`\`
+
"softlike"
const
Env_ADApplication
string
=
Env_ADSoft
+
`\`
+
"application"
+
`\`
const
Env_ADApplication
string
=
Env_ADSoft
+
`\`
+
"application"
+
`\`
const
Env_ADSoftTool
string
=
Env_ADSoft
+
`\`
+
"tools"
+
`\`
const
Env_ADSoftTool
string
=
Env_ADSoft
+
`\`
+
"tools"
+
`\`
const
Env_ADSoftTool_RebootUser
string
=
Env_ADSoftTool
+
"upusers.bat"
const
Env_ADSoftTool_RebootUser
string
=
Env_ADSoftTool
+
"upusers.bat"
const
Env_ADsoftware_local
string
=
`F:\software\softlike\`
const
Env_ADsoftware_local
string
=
`F:\software\softlike\`
// AD User env ////////////////////////////////////////////////////////////////
// backup env //////////////////////////////////////////////////////////////
const
AD_User_main_admin
string
=
"zhiweiadserver"
const
AD_User_tengfei
string
=
"tengfei"
var
BackupVersion
string
=
"0428"
const
AD_User_taotengfei
string
=
"taotengfei"
var
BackupExtFile
string
=
".ffs_batch"
const
AD_User_huyibo
string
=
"huyibo"
var
BackupReplaceKey
=
[]
byte
(
"-tengfei-"
)
// other env ///////////////////////////////////////////////////////////////
const
Zhiwei_Dept_HB
string
=
"HB"
const
Zhiwei_Dept_LP
string
=
"LP"
const
Zhiwei_Dept_MT
string
=
"MT"
const
Zhiwei_Dept_JR
string
=
"JR"
const
Zhiwei_Dept_JD
string
=
"JD"
const
Zhiwei_Dept_TXHD
string
=
"TXHD"
const
Zhiwei_Dept_TXWJ
string
=
"TXWJ"
const
Zhiwei_Dept_BGYJZX
string
=
"BGYJZX"
const
Zhiwei_Dept_TECH
string
=
"TECH"
const
Link_WxworkBot
string
=
`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=59107f72-5b72-4a20-a33c-fdb1cd46f2c6`
const
Zhiwei_Dept_Count
=
8
const
Link_MultiSplit
string
=
Env_ADApplication
+
"win_MultiSplit.exe"
const
Cmdk
string
=
"cmd /k "
const
Startk
string
=
"cmd /k start "
var
Dir_Windows
string
=
GetEnv
(
"windir"
)
+
`\`
//
AD User //
//////////////////////////////////////////////////////////////
//
backup env
//////////////////////////////////////////////////////////////
const
AD_User_main_admin
string
=
"zhiweiadserver"
var
BackupVersion
string
=
"0428"
const
AD_User_tengfei
string
=
"tengfei"
var
BackupExtFile
string
=
".ffs_batch"
const
AD_User_taotengfei
string
=
"taotengfei"
var
BackupReplaceKey
=
[]
byte
(
"-tengfei-"
)
const
AD_User_huyibo
string
=
"huyibo"
// reg ////////////////////////////////////////////////////////////////////
// reg ////////////////////////////////////////////////////////////////////
...
@@ -78,125 +84,22 @@ const (
...
@@ -78,125 +84,22 @@ const (
)
)
const
Reg_Root_achome
int
=
HKLM
const
Reg_Root_achome
int
=
HKLM
const
Reg_Path_achome
string
=
`SOFTWARE\ADControl`
const
Reg_Path_achome
string
=
`SOFTWARE\ADControl`
const
Reg_Path_achome_dc
string
=
Reg_Path_achome
+
`\DomainComputer\`
const
Reg_Path_achome_dc
string
=
Reg_Path_achome
+
`\DomainComputer\`
// use for adserver,not for dc
const
Reg_Name_achome_dc_lastlogin
string
=
"LastLogin"
const
Reg_Name_achome_dc_lastlogin
string
=
"LastLogin"
const
Reg_Name_achome_dc_lastclose
string
=
"CloseWindows"
const
Reg_Name_achome_dc_lastclose
string
=
"CloseWindows"
const
Reg_Name_achome_dc_WeDriveDir
string
=
"WeDriveDir"
//
// reg value /////////////////////////////////////////////////////////////////
//
var
Reg_Value_WeDriveDir
string
=
Reg_query_key_one
(
HKCU
,
Reg_Path_achome
,
Reg_Name_achome_dc_WeDriveDir
)
//
// msg msG mSg mSG Msg MsG MSg MSG
//
//
// msg env ////////////////////////////////////////////////////////////////
const
EndSign
byte
=
125
const
msgerror
string
=
"error"
// msg type ////////////////////////////////////////////////////////////////
const
Msg_Report
string
=
"report"
const
Msg_Exec
string
=
"exec"
const
Msg_Backup
string
=
"backup"
const
Msg_reg
string
=
"reg"
// msg report type ///////////////////////////////////////////////////////////
const
Msg_Report_DaemonStart
string
=
"Daemon Start"
const
Msg_Report_UserStart
string
=
"User Start"
const
Msg_Report_Offwork
string
=
"offwork"
const
Msg_Report_OverBak
string
=
"overbak"
const
Msg_Report_CloseWindows
string
=
"closewindows"
// msg backup status //////////////////////////////////////////////////////////////
const
Msg_Backup_Status_Start
string
=
"start"
const
Msg_Backup_Status_If
string
=
"if"
const
Msg_Backup_Status_Continue
string
=
"Continue"
const
Msg_Backup_Status_Run
string
=
"run"
const
Msg_Backup_Status_Error
string
=
msgerror
// other env ///////////////////////////////////////////////////////////////
// msg exec status ////////////////////////////////////////////////////////////////
const
Link_WxworkBot
string
=
`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=59107f72-5b72-4a20-a33c-fdb1cd46f2c6`
const
Link_MultiSplit
string
=
Env_ADApplication
+
"win_MultiSplit.exe"
const
(
const
Cmdk
string
=
"cmd /k "
Msg_Exec_Cmder_ADServer
=
iota
const
Startk
string
=
"cmd /k start "
Msg_Exec_Cmder_LocalDaemon
var
Dir_Windows
string
=
GetEnv
(
"windir"
)
+
`\`
Msg_Exec_Cmder_LocalUser
const
zhiwei_WxDrive_Folder
string
=
"办公室部门内部共享"
)
var
Zhiwei_WxDrive_Full_Folder
string
=
Reg_Value_WeDriveDir
+
`\`
+
zhiwei_WxDrive_Folder
const
Msg_Exec_State_Request
string
=
"request"
var
CopyStatusWeDrive
map
[
string
]
bool
const
Msg_Exec_State_Ack
string
=
"ack"
const
Msg_Exec_CloseWindows
string
=
"closewindow"
const
Msg_Exec_CloseWindows_cmd
string
=
"shutdown -s -t 15"
const
Msg_Exec_CancelCloseWindows
string
=
"cancelclosewindows"
const
Msg_Exec_CancelCloseWindows_cmd
string
=
"shutdown -a"
const
Msg_Exec_LogOffUser
string
=
"logoffuser"
const
Msg_Exec_LogOffUser_cmd
string
=
"shutdown -l"
const
Msg_Exec_UserExec
string
=
"userexec"
const
Msg_Exec_RebootWindows
string
=
"rebootWindows"
const
Msg_Exec_RebootWindows_cmd
string
=
"shutdown -r -t 15"
const
Msg_Exec_UpdateVersion
string
=
"updateverion"
const
Msg_Exec_UpdateVersion_cmd
string
=
"Env_ADSoftTool_Update"
const
Msg_Exec_InstallSoftware
string
=
"installsoftware"
const
(
Msg_Reg_Query
=
iota
Msg_Reg_Read
)
//const Msg_Reg_
// group Json ////
// Basic Json Fromat ///////////////////////////////////////////////////////
type
MJbase
struct
{
MsgType
string
`json:"msgtype"`
Status
string
`json:"status"`
Explain
string
`json:"explain"`
Username
string
`json:"username"`
Computername
string
`json:"computername"`
Timestamp
int64
`json:"timestamp"`
}
// report Json Format //////////////////////////////////////////////////////
type
MJreport
struct
{
MJbase
Report
string
`json:"report"`
Version
string
`json:"version"`
}
// Exec Json Fromat ///////////////////////////////////////////////////////
type
MJexec
struct
{
MJbase
Instruction
string
`json:"instruction"`
Command
string
`json:"command"`
Extbool
bool
`json:"extbool"`
Cmder
int
`josn:"cmder"`
SessionID
string
`json:"sessionid"`
IfDelay
bool
`josn:"ifDelay"`
Delay
string
`json:"delay"`
}
// backup Json Format /////////////////////////////////////////////////////
type
MJbackup
struct
{
MJbase
Version
string
`json:"version"`
DiskFree
string
`json:"diskfree"`
Error
bool
`json:"error"`
BatchFileExist
bool
`json:"batchfileexist"`
BatchFileData
[]
byte
`json:"batchfiledata"`
BatchFileName
string
`json:"batchfilename"`
}
type
MJreg
struct
{
MJbase
Action
int
`json:"action"`
Root
int
`json:"root"`
Path
string
`json:"path"`
Key
string
`json:"key"`
DataStr
string
`json:"datastr"`
DataType
int
`json:"datatype"`
DataBool
string
`json:"databool"`
}
\ No newline at end of file
public/msg_deal.go
View file @
93a98aca
...
@@ -38,11 +38,11 @@ func DealMsgEnter(ip string,msgtype string,unmsg []byte) []byte {
...
@@ -38,11 +38,11 @@ func DealMsgEnter(ip string,msgtype string,unmsg []byte) []byte {
}
}
//
//
// 具体消息实现
// 具体消息实现
//
//
// 关于 report 报告 的 消息处理
// 关于 report 报告 的 消息处理
func
(
rep
*
MJreport
)
Msg_Deal
()
interface
{}
{
func
(
rep
*
MJreport
)
Msg_Deal
()
interface
{}
{
...
@@ -73,6 +73,12 @@ func (rep *MJreport)Msg_Deal() interface{} {
...
@@ -73,6 +73,12 @@ func (rep *MJreport)Msg_Deal() interface{} {
if
rep
.
Version
!=
Version
{
if
rep
.
Version
!=
Version
{
return
GJexecAck
(
Msg_Exec_UpdateVersion
)
return
GJexecAck
(
Msg_Exec_UpdateVersion
)
}
}
case
Msg_Report_OverCopyToWeDrive
:
go
func
()
{
Delay
(
600
)
CopyStatusWeDrive
[
rep
.
Dept
]
=
true
}()
default
:
default
:
PrintLog
(
"Default Report Json "
,
rep
.
Report
)
PrintLog
(
"Default Report Json "
,
rep
.
Report
)
...
@@ -109,12 +115,20 @@ func (exec *MJexec)Msg_Deal()interface{}{
...
@@ -109,12 +115,20 @@ func (exec *MJexec)Msg_Deal()interface{}{
case
Msg_Exec_State_Request
:
case
Msg_Exec_State_Request
:
// maybe 当然时我来控制咯
// maybe 当然时我来控制咯
// 修改 请求状态,client daemon才可以执行
// 修改 请求状态,client daemon才可以执行
exec
.
Status
=
Msg_Exec_State_Ack
switch
exec
.
Instruction
{
case
Msg_Exec_CopyWeDrive
:
if
CopyStatusWeDrive
[
exec
.
Dept
]{
exec
.
Status
=
Msg_Exec_State_Ack
CopyStatusWeDrive
[
exec
.
Dept
]
=
false
}
else
{
return
nil
}
}
return
exec
return
exec
case
Msg_Exec_State_Ack
:
case
Msg_Exec_State_Ack
:
// 进行延迟
// 进行延迟
if
exec
.
IfDelay
{
Delay
(
&
exec
.
Delay
)}
//
if exec.IfDelay {Delay(&exec.Delay)}
// 区分执行者
// 区分执行者
switch
exec
.
Cmder
{
switch
exec
.
Cmder
{
...
@@ -132,7 +146,7 @@ func (exec *MJexec)Msg_Deal()interface{}{
...
@@ -132,7 +146,7 @@ func (exec *MJexec)Msg_Deal()interface{}{
// 对于 exe 格式
// 对于 exe 格式
}
else
{
}
else
{
// 如果文件存在,则执行C:\windows目录下的文件
// 如果文件存在,则执行C:\windows目录下的文件
if
exec
.
Extb
ool
{
if
exec
.
DataB
ool
{
PsExec_sdi
(
exec
.
Computername
,
Dir_Windows
+
exec
.
Command
,
exec
.
SessionID
)
PsExec_sdi
(
exec
.
Computername
,
Dir_Windows
+
exec
.
Command
,
exec
.
SessionID
)
// 如果文件不存在,从 ADMIN$ 复制到C:\windows,再执行
// 如果文件不存在,从 ADMIN$ 复制到C:\windows,再执行
}
else
{
}
else
{
...
@@ -144,7 +158,14 @@ func (exec *MJexec)Msg_Deal()interface{}{
...
@@ -144,7 +158,14 @@ func (exec *MJexec)Msg_Deal()interface{}{
Execcmd_nowait
(
exec
.
Command
)
Execcmd_nowait
(
exec
.
Command
)
}
}
switch
exec
.
Instruction
{
case
Msg_Exec_CopyWeDrive
:
Reg_Value_WeDriveDir
=
Reg_query_key_one
(
HKCU
,
Reg_Path_achome
,
Reg_Name_achome_dc_WeDriveDir
)
cmd
:=
`cmd /c xcopy `
+
Env_ADMainDeptShare
+
" /D "
+
Reg_Value_WeDriveDir
+
`\`
+
zhiwei_WxDrive_Folder
+
" /S /T /E /C /y"
Execcmd_wait
(
cmd
)
SendServerReport
(
Msg_Report_OverCopyToWeDrive
)
}
}
}
return
nil
return
nil
}
}
...
@@ -232,6 +253,9 @@ func (bak * MJbackup)Msg_Deal() interface{}{
...
@@ -232,6 +253,9 @@ func (bak * MJbackup)Msg_Deal() interface{}{
}
}
// 关于 registry 注册表 的 消息处理
func
(
reg
*
MJreg
)
Msg_Deal
()
interface
{}{
func
(
reg
*
MJreg
)
Msg_Deal
()
interface
{}{
switch
reg
.
Action
{
switch
reg
.
Action
{
case
Msg_Reg_Query
:
case
Msg_Reg_Query
:
...
...
public/msg_init.go
View file @
93a98aca
package
public
package
public
//
//
//
// msg env ////////////////////////////////////////////////////////////////
//
const
EndSign
byte
=
125
const
msgerror
string
=
"error"
// msg type ////////////////////////////////////////////////////////////////
const
Msg_Report
string
=
"report"
const
Msg_Exec
string
=
"exec"
const
Msg_Backup
string
=
"backup"
const
Msg_reg
string
=
"reg"
// msg report type ///////////////////////////////////////////////////////////
const
Msg_Report_DaemonStart
string
=
"Daemon Start"
const
Msg_Report_UserStart
string
=
"User Start"
const
Msg_Report_Offwork
string
=
"offwork"
const
Msg_Report_OverBak
string
=
"overbak"
const
Msg_Report_CloseWindows
string
=
"closewindows"
const
Msg_Report_OverCopyToWeDrive
string
=
"overcopytowedrive"
// msg backup status //////////////////////////////////////////////////////////////
const
Msg_Backup_Status_Start
string
=
"start"
const
Msg_Backup_Status_If
string
=
"if"
const
Msg_Backup_Status_Continue
string
=
"Continue"
const
Msg_Backup_Status_Run
string
=
"run"
const
Msg_Backup_Status_Error
string
=
msgerror
// msg exec status ////////////////////////////////////////////////////////////////
const
(
Msg_Exec_Cmder_ADServer
=
iota
Msg_Exec_Cmder_LocalDaemon
Msg_Exec_Cmder_LocalUser
)
const
Msg_Exec_State_Request
string
=
"request"
const
Msg_Exec_State_Ack
string
=
"ack"
const
Msg_Exec_CloseWindows
string
=
"closewindow"
const
Msg_Exec_CloseWindows_cmd
string
=
"shutdown -s -t 15"
const
Msg_Exec_CancelCloseWindows
string
=
"cancelclosewindows"
const
Msg_Exec_CancelCloseWindows_cmd
string
=
"shutdown -a"
const
Msg_Exec_LogOffUser
string
=
"logoffuser"
const
Msg_Exec_LogOffUser_cmd
string
=
"shutdown -l"
const
Msg_Exec_UserExec
string
=
"userexec"
const
Msg_Exec_RebootWindows
string
=
"rebootWindows"
const
Msg_Exec_RebootWindows_cmd
string
=
"shutdown -r -t 15"
const
Msg_Exec_UpdateVersion
string
=
"updateverion"
const
Msg_Exec_UpdateVersion_cmd
string
=
"Env_ADSoftTool_Update"
const
Msg_Exec_InstallSoftware
string
=
"installsoftware"
const
Msg_Exec_CopyWeDrive
string
=
"copyWeDrive"
const
(
Msg_Reg_Query
=
iota
Msg_Reg_Read
)
//
//
// group Json ////
//
// Basic Json Fromat ///////////////////////////////////////////////////////
type
MJbase
struct
{
MsgType
string
`json:"msgtype"`
Status
string
`json:"status"`
Explain
string
`json:"explain"`
Username
string
`json:"username"`
Computername
string
`json:"computername"`
Dept
string
`json:"dept"`
Timestamp
int64
`json:"timestamp"`
DataBool
bool
`json:"databool"`
DataStr
string
`json:"datastr"`
}
// report Json Format //////////////////////////////////////////////////////
type
MJreport
struct
{
MJbase
Report
string
`json:"report"`
Version
string
`json:"version"`
}
// Exec Json Fromat ///////////////////////////////////////////////////////
type
MJexec
struct
{
MJbase
Instruction
string
`json:"instruction"`
Command
string
`json:"command"`
Cmder
int
`josn:"cmder"`
SessionID
string
`json:"sessionid"`
IfDelay
bool
`josn:"ifDelay"`
Delay
string
`json:"delay"`
}
// backup Json Format /////////////////////////////////////////////////////
type
MJbackup
struct
{
MJbase
Version
string
`json:"version"`
DiskFree
string
`json:"diskfree"`
//Error bool `json:"error"`
BatchFileExist
bool
`json:"batchfileexist"`
BatchFileData
[]
byte
`json:"batchfiledata"`
BatchFileName
string
`json:"batchfilename"`
}
type
MJreg
struct
{
MJbase
Action
int
`json:"action"`
Root
int
`json:"root"`
Path
string
`json:"path"`
Key
string
`json:"key"`
DataType
int
`json:"datatype"`
}
//
//
// quickly Get & Set Json
// quickly Get & Set Json
//
//
// Report
// Report
func
GJreport
(
s
string
,
who
string
)
interface
{}{
func
GJreport
(
s
string
,
who
string
)
interface
{}{
...
@@ -16,6 +137,8 @@ func GJreport(s string,who string) interface{}{
...
@@ -16,6 +137,8 @@ func GJreport(s string,who string) interface{}{
func
(
rep
*
MJreport
)
init
(
Report
string
)
{
func
(
rep
*
MJreport
)
init
(
Report
string
)
{
rep
.
Username
=
User_name
rep
.
Username
=
User_name
rep
.
Dept
=
User_dept
rep
.
Timestamp
=
NowTimestamp
()
rep
.
Timestamp
=
NowTimestamp
()
rep
.
Computername
=
User_computername
rep
.
Computername
=
User_computername
rep
.
MsgType
=
Msg_Report
rep
.
MsgType
=
Msg_Report
...
@@ -30,34 +153,42 @@ func (rep * MJreport)PrintExplain(){
...
@@ -30,34 +153,42 @@ func (rep * MJreport)PrintExplain(){
// Exec
// Exec
func
GJexec
(
s
string
)
MJexec
{
func
GJexec
(
s
string
)
MJexec
{
var
rep
MJexec
var
exec
MJexec
rep
.
init
(
s
)
exec
.
init
(
s
)
return
rep
return
exec
}
}
func
GJexecAck
(
s
string
)
interface
{}{
func
GJexecAck
(
s
string
)
interface
{}{
var
rep
MJexec
var
exec
MJexec
rep
.
init
(
s
)
exec
.
init
(
s
)
rep
.
Status
=
Msg_Exec_State_Ack
exec
.
Status
=
Msg_Exec_State_Ack
return
rep
return
exec
}
func
GJexecCopyWeDrive
(
s
string
)
MJexec
{
var
exec
MJexec
exec
.
init
(
s
)
exec
.
DataStr
=
User_dept
return
exec
}
}
func
GJexecInstallSoftware
(
b
bool
,
s
string
)
interface
{}{
func
GJexecInstallSoftware
(
b
bool
,
s
string
)
interface
{}{
var
exec
MJexec
var
exec
MJexec
exec
.
init
(
s
)
exec
.
init
(
s
)
exec
.
Status
=
Msg_Exec_State_Ack
exec
.
Status
=
Msg_Exec_State_Ack
exec
.
Extbool
=
b
exec
.
DataBool
=
b
exec
.
Cmder
=
Msg_Exec_Cmder_ADServer
exec
.
Cmder
=
Msg_Exec_Cmder_ADServer
exec
.
Instruction
=
Msg_Exec_InstallSoftware
exec
.
Instruction
=
Msg_Exec_InstallSoftware
exec
.
Command
=
s
exec
.
Command
=
s
return
exec
return
exec
}
}
func
GJexecUserCmd
(
s
string
)
interface
{}{
func
GJexecUserCmd
(
s
string
)
interface
{}{
var
rep
MJexec
var
exec
MJexec
rep
.
init
(
""
)
exec
.
init
(
""
)
rep
.
Command
=
s
exec
.
Command
=
s
rep
.
Status
=
Msg_Exec_State_Ack
exec
.
Status
=
Msg_Exec_State_Ack
return
rep
return
exec
}
}
func
(
exec
*
MJexec
)
init
(
s
string
){
func
(
exec
*
MJexec
)
init
(
s
string
){
exec
.
Dept
=
User_dept
exec
.
Username
=
User_name
exec
.
Username
=
User_name
exec
.
Computername
=
User_computername
exec
.
Computername
=
User_computername
exec
.
Timestamp
=
NowTimestamp
()
exec
.
Timestamp
=
NowTimestamp
()
...
@@ -66,8 +197,8 @@ func (exec * MJexec)init(s string){
...
@@ -66,8 +197,8 @@ func (exec * MJexec)init(s string){
exec
.
SessionID
=
User_sessionID
exec
.
SessionID
=
User_sessionID
exec
.
Cmder
=
Msg_Exec_Cmder_LocalDaemon
exec
.
Cmder
=
Msg_Exec_Cmder_LocalDaemon
exec
.
Status
=
Msg_Exec_State_Request
exec
.
Status
=
Msg_Exec_State_Request
exec
.
IfDelay
=
false
//
exec.IfDelay = false
exec
.
Delay
=
Rand
(
RandMax
)
//
exec.Delay = Rand(RandMax)
exec
.
Timestamp
=
NowTimestamp
()
exec
.
Timestamp
=
NowTimestamp
()
}
}
...
@@ -80,7 +211,8 @@ func GJbackup()interface{}{
...
@@ -80,7 +211,8 @@ func GJbackup()interface{}{
return
rep
return
rep
}
}
func
(
bak
*
MJbackup
)
init
()
{
func
(
bak
*
MJbackup
)
init
()
{
bak
.
Timestamp
=
NowTimestamp
()
bak
.
Dept
=
User_dept
bak
.
Timestamp
=
NowTimestamp
()
bak
.
MsgType
=
Msg_Backup
bak
.
MsgType
=
Msg_Backup
bak
.
Version
=
BackupVersion
bak
.
Version
=
BackupVersion
bak
.
Status
=
Msg_Backup_Status_Start
bak
.
Status
=
Msg_Backup_Status_Start
...
...
public/print.go
View file @
93a98aca
...
@@ -4,16 +4,4 @@ import (
...
@@ -4,16 +4,4 @@ import (
)
)
func
PrintLog
(
v
...
interface
{}){
func
PrintLog
(
v
...
interface
{}){
log
.
Println
(
v
...
)
log
.
Println
(
v
...
)
// logFile, err := os.OpenFile(`C:\` + Application + ".txt", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
// if nil != err {
// log.Println(err)
// }
// loger := log.New(logFile, "", log.LstdFlags)
// if Debug {
// loger.SetPrefix("DEBUG ")
// }
// loger.Println(v ...)
// logFile.Close()
}
}
public/public.go
View file @
93a98aca
...
@@ -10,7 +10,6 @@ import (
...
@@ -10,7 +10,6 @@ import (
"time"
"time"
"os/exec"
"os/exec"
"io/ioutil"
"io/ioutil"
"strconv"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/encoding/simplifiedchinese"
)
)
...
@@ -135,15 +134,20 @@ func PrimaryUser(s string) bool{
...
@@ -135,15 +134,20 @@ func PrimaryUser(s string) bool{
return
false
return
false
}
}
// 随机
// 随机
func
Rand
(
i
int
)
string
{
func
Rand
(
i
*
int
)
int
{
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
return
strconv
.
Itoa
(
rand
.
Intn
(
i
)
)
return
rand
.
Intn
(
*
i
)
}
}
func
Delay
(
s
*
string
){
func
Delay
(
i
int
){
PrintLog
(
"延迟"
,
*
s
,
"秒"
)
PrintLog
(
"Delay "
,
i
)
i
,
_
:=
strconv
.
Atoi
(
*
s
)
time
.
Sleep
(
time
.
Duration
(
i
)
*
time
.
Second
)
time
.
Sleep
(
time
.
Duration
(
i
)
*
time
.
Second
)
}
}
func
RandDelay
(
i
int
){
ri
:=
Rand
(
&
i
)
PrintLog
(
"RandDelay "
,
ri
)
time
.
Sleep
(
time
.
Duration
(
ri
)
*
time
.
Second
)
}
func
AdminUser
(
)
bool
{
func
AdminUser
(
)
bool
{
switch
User_name
{
switch
User_name
{
case
AD_User_taotengfei
:
case
AD_User_taotengfei
:
...
...
public/win.go
View file @
93a98aca
...
@@ -28,7 +28,7 @@ func execcmd_base(cmdargs string) (string,[]string,error){
...
@@ -28,7 +28,7 @@ func execcmd_base(cmdargs string) (string,[]string,error){
app
=
cmdargs
app
=
cmdargs
appargs
[
0
]
=
""
appargs
[
0
]
=
""
}
}
PrintLog
(
cmd
args
)
PrintLog
(
app
,
app
args
)
return
app
,
appargs
,
nil
return
app
,
appargs
,
nil
}
}
...
@@ -70,6 +70,18 @@ func Execcmd_output(cmdargs string)[]byte{
...
@@ -70,6 +70,18 @@ func Execcmd_output(cmdargs string)[]byte{
return
nil
return
nil
}
}
//
//
// local
//
func
ChooseFolder
(
explain
,
initDir
*
string
)
string
{
fg
:=
new
(
walk
.
FileDialog
)
fg
.
Title
=
*
explain
fg
.
InitialDirPath
=
*
initDir
fg
.
ShowBrowseFolder
(
*
new
(
walk
.
Form
))
return
fg
.
FilePath
}
//
//
//
//
// remote exec
// remote exec
...
@@ -117,6 +129,15 @@ func reg_prase(root * int) registry.Key{
...
@@ -117,6 +129,15 @@ func reg_prase(root * int) registry.Key{
}
}
return
registry
.
LOCAL_MACHINE
return
registry
.
LOCAL_MACHINE
}
}
func
Reg_Exist_item
(
root
int
,
path
string
)
{
_
,
exist
,
err
:=
registry
.
CreateKey
(
reg_prase
(
&
root
),
path
,
registry
.
ALL_ACCESS
)
if
err
!=
nil
{
PrintLog
(
err
)
}
if
!
exist
{
PrintLog
(
"Create "
,
path
)
}
}
func
Reg_query_item_one
(
root
int
,
path
string
)
string
{
func
Reg_query_item_one
(
root
int
,
path
string
)
string
{
if
k
,
kerr
:=
registry
.
OpenKey
(
reg_prase
(
&
root
),
path
,
registry
.
READ
);
kerr
==
nil
{
if
k
,
kerr
:=
registry
.
OpenKey
(
reg_prase
(
&
root
),
path
,
registry
.
READ
);
kerr
==
nil
{
defer
k
.
Close
()
defer
k
.
Close
()
...
...
users/menu.go
View file @
93a98aca
...
@@ -136,7 +136,7 @@ func siEnter_admin(softname string){
...
@@ -136,7 +136,7 @@ func siEnter_admin(softname string){
//---------------------------------------------------------------
//---------------------------------------------------------------
func
menuInitWxDriveSync
(
ni
*
walk
.
NotifyIcon
){
func
menuInitWxDriveSync
(
ni
*
walk
.
NotifyIcon
){
fa
:=
"微盘同步"
fa
:=
"微盘同步"
sub
:=
[
...
]
string
{
"初始化"
,
"
开启服务器同步
到微盘"
,
"开启微盘同步到服务器"
,
"说明"
}
sub
:=
[
...
]
string
{
"初始化"
,
"
手动进行一次同步服务器
到微盘"
,
"开启微盘同步到服务器"
,
"说明"
}
// 建立空菜单
// 建立空菜单
nm
,
err
:=
walk
.
NewMenu
()
nm
,
err
:=
walk
.
NewMenu
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -179,10 +179,25 @@ func menuInitWxDriveSync(ni * walk.NotifyIcon){
...
@@ -179,10 +179,25 @@ func menuInitWxDriveSync(ni * walk.NotifyIcon){
sysmenu
.
SetEnabled
(
true
)
sysmenu
.
SetEnabled
(
true
)
}
}
func
wxdsInit
(){
func
wxdsInit
(){
public
.
Msg
(
"开发ing"
)
explain
:=
"选择个人ID,请根据微盘的文件夹所在位置进行选择,确定并选择并点击文件夹(一串数字)后,点击确定继续进行下一步!具体操作方法点击说明!"
initDir
:=
public
.
User_Dir_WeDrive
FullWeDrive
:=
public
.
ChooseFolder
(
&
explain
,
&
initDir
)
FullWeDrive
=
FullWeDrive
+
`\WeDrive\知微数据`
public
.
PrintLog
(
FullWeDrive
)
if
public
.
NotExist
(
FullWeDrive
){
public
.
Msg
(
"不存在知微数据文件夹,请重新选择"
)
return
}
public
.
Reg_Write_key_one
(
public
.
HKCU
,
public
.
Reg_Path_achome
,
public
.
Reg_Name_achome_dc_WeDriveDir
,
FullWeDrive
)
public
.
Msg
(
"初始化完毕,请在微盘中创建文件夹(办公室部门内部共享),并分享给同事,创建后,点击开始同步即可。"
)
}
}
func
wxdsToDrive
(){
func
wxdsToDrive
(){
public
.
Msg
(
"开发ing"
)
public
.
SendServer
(
public
.
GJexecCopyWeDrive
(
public
.
Msg_Exec_CopyWeDrive
))
}
}
func
wxdsToServer
(){
func
wxdsToServer
(){
...
@@ -190,7 +205,11 @@ func wxdsToServer(){
...
@@ -190,7 +205,11 @@ func wxdsToServer(){
}
}
func
wxdsExplain
(){
func
wxdsExplain
(){
public
.
Msg
(
"开发ing"
)
// 此功能,部门内部的路人甲初始化一次即可,并分享微盘文件夹给炮灰乙、流氓丙即可。
// 当路人甲没有启动这个小工具时,土匪丁想要同步的话,也时需要初始化
// 初始化后,凡是启动了小工具,2小时自动同步一次。
// 但限于微盘的特性,当文件共享盘的文件名发生变化,微盘是依旧保留旧文件夹的。所以微盘的文件时需要定期手动清理的。
public
.
Msg
(
"第一次使用此功能时"
)
}
}
//---------------------------------------------------------------
//---------------------------------------------------------------
...
...
users/users.exe
View file @
93a98aca
No preview for this file type
users/users.go
View file @
93a98aca
...
@@ -9,9 +9,21 @@ import (
...
@@ -9,9 +9,21 @@ import (
"AD-Control/public"
"AD-Control/public"
)
)
func
userInit
(){
func
userInit
(){
public
.
SendServerReport
(
public
.
Msg_Report_UserStart
)
public
.
Reg_Exist_item
(
public
.
HKCU
,
public
.
Reg_Path_achome
)
}
// 如果微盘的文件夹存在
// 则,重复执行
// 随机延迟300s,进行复制,固定延迟2h
if
public
.
Reg_Value_WeDriveDir
!=
""
&&
public
.
Exist
(
public
.
Zhiwei_WxDrive_Full_Folder
){
go
func
(){
for
{
public
.
RandDelay
(
300
)
public
.
SendServer
(
public
.
GJexecCopyWeDrive
(
public
.
Msg_Exec_CopyWeDrive
))
public
.
Delay
(
7200
)
}
}()
}
}
func
menuInit
(
ni
*
walk
.
NotifyIcon
){
func
menuInit
(
ni
*
walk
.
NotifyIcon
){
menuInitPower
(
ni
)
menuInitPower
(
ni
)
menuInitSoftwareInstall
(
ni
)
menuInitSoftwareInstall
(
ni
)
...
@@ -25,7 +37,6 @@ func main() {
...
@@ -25,7 +37,6 @@ func main() {
// 用户初始化
// 用户初始化
userInit
()
userInit
()
//if public.Daemon {public.Msg("版本错误")}
//if public.Daemon {public.Msg("版本错误")}
...
@@ -60,6 +71,9 @@ func main() {
...
@@ -60,6 +71,9 @@ func main() {
if
err
:=
ni
.
SetVisible
(
true
);
err
!=
nil
{
if
err
:=
ni
.
SetVisible
(
true
);
err
!=
nil
{
public
.
PrintLog
(
err
)
public
.
PrintLog
(
err
)
}
}
// init over
public
.
SendServerReport
(
public
.
Msg_Report_UserStart
)
// 循环 运行窗体
// 循环 运行窗体
mw
.
Run
()
mw
.
Run
()
...
...
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