Commit 83984473 by 陶腾飞

update

parent 4620e4e1
No preview for this file type
......@@ -11,7 +11,7 @@ func main(){
var reportText = flag.String(public.Msg_Report,"","report to AD")
var backupText = flag.String(public.Msg_Backup,"","backup status to AD")
var execText = flag.String(public.Msg_Exec,"","exec to LocalDaemon")
var userText = flag.String(public.Msg_User,"","who is running me")
var userText = flag.String("user","","who is running me")
var wolmacText = flag.String("wolmac","","input mac address for wake pc")
var woluserText = flag.String("woluser","","input name for walk pc")
var hourText = flag.Bool("hour",false,"exec task at the time")
......@@ -50,9 +50,10 @@ func flag_hour(){
nh := time.Now().Hour()
public.PrintLog(nh)
switch nh{
case 0:
public.MsgBox(`5分钟后,即将重启,运行Z:\tools\【工具】取消关机.bat`)
public.Execcmd_nowait("shutdown -r -t 300")
public.MsgBox(`5分钟后,即将关机,运行Z:\tools\【工具】取消关机.bat`)
public.Execcmd_nowait("shutdown -s -t 300")
break
case 1:
public.MsgBox(`5分钟后,即将重启,运行Z:\tools\【工具】取消关机.bat`)
......
No preview for this file type
......@@ -28,9 +28,7 @@ var User_sessionID string = Reg_query_item_one(HKU,User_sid+`\Volatile Envi
// win-computer env /////////////////////////////////////////////////////
const Env_FreeFileSyncExe string = `C:\Progra~2\zhiwei\FreeFileSync_10.22\FreeFileSync.exe`
const HKCU string = "HKCU"
const HKLM string = "HKLM"
const HKU string = "HKU"
// AD env ///////////////////////////////////////////////////////////
......@@ -54,7 +52,6 @@ var BackupExtFile string = ".ffs_batch"
var BackupReplaceKey =[]byte("-tengfei-")
// other env ///////////////////////////////////////////////////////////////
const Link_WxworkBot string = `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=59107f72-5b72-4a20-a33c-fdb1cd46f2c6`
......@@ -62,6 +59,29 @@ 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 ////////////////////////////////////////////////////////////////
const AD_User_main_admin string = "zhiweiadserver"
const AD_User_tengfei string = "tengfei"
const AD_User_taotengfei string = "taotengfei"
const AD_User_huyibo string = "huyibo"
// reg ////////////////////////////////////////////////////////////////////
const (
HKCU = iota
HKLM
HKU
)
const Reg_Root_achome int = HKLM
const Reg_Path_achome string = `SOFTWARE\ADControl`
const Reg_Path_achome_dc string = Reg_Path_achome + `\DomainComputer\`
const Reg_Name_achome_dc_lastlogin string = "LastLogin"
const Reg_Name_achome_dc_lastclose string = "CloseWindows"
//
//
//
......@@ -81,8 +101,7 @@ const msgerror string = "error"
const Msg_Report string = "report"
const Msg_Exec string = "exec"
const Msg_Backup string = "backup"
const Msg_User string = "user"
const Msg_reg string = "reg"
// msg report type ///////////////////////////////////////////////////////////
......@@ -90,7 +109,7 @@ 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 //////////////////////////////////////////////////////////////
......@@ -103,9 +122,11 @@ const Msg_Backup_Status_Error string = msgerror
// msg exec status ////////////////////////////////////////////////////////////////
const Msg_Exec_Cmder_ADServer int = 0
const Msg_Exec_Cmder_LocalDaemon int = 1
const Msg_Exec_Cmder_LocalUser int = 2
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"
......@@ -121,8 +142,13 @@ 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 msg ////
// group Json ////
// Basic Json Fromat ///////////////////////////////////////////////////////
type MJbase struct{
......@@ -131,6 +157,7 @@ type MJbase struct{
Explain string `json:"explain"`
Username string `json:"username"`
Computername string `json:"computername"`
Timestamp int64 `json:"timestamp"`
}
// report Json Format //////////////////////////////////////////////////////
......@@ -162,10 +189,14 @@ type MJbackup struct{
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"`
// AD User ////////////////////////////////////////////////////////////////
const AD_User_main_admin string = "zhiweiadserver"
const AD_User_tengfei string = "tengfei"
const AD_User_taotengfei string = "taotengfei"
const AD_User_huyibo string = "huyibo"
\ No newline at end of file
}
\ No newline at end of file
......@@ -25,6 +25,13 @@ func DealMsgEnter(ip string,msgtype string,unmsg []byte) []byte {
var pmsg MJbackup
ParseJsonBody(unmsg,&pmsg)
ret = pmsg.Msg_Deal()
// 注册表 消息
case Msg_reg:
var pmsg MJreg
ParseJsonBody(unmsg,&pmsg)
ret = pmsg.Msg_Deal()
}
return JsonToByte(&ret)
......@@ -39,6 +46,7 @@ func DealMsgEnter(ip string,msgtype string,unmsg []byte) []byte {
// 关于 report 报告 的 消息处理
func (rep *MJreport)Msg_Deal() interface{} {
PrintLog(rep)
switch rep.Report{
case Msg_Report_Offwork:
......@@ -48,8 +56,21 @@ func (rep *MJreport)Msg_Deal() interface{} {
SysMsgBox(rep.Computername,"备份结束")
return GJexecAck(Msg_Exec_CloseWindows)
case Msg_Report_UserStart:
case Msg_Report_CloseWindows:
Reg_Write_key_one(
Reg_Root_achome,
Reg_Path_achome_dc + rep.Computername,
Reg_Name_achome_dc_lastclose,
UnixTimeParse(&rep.Timestamp))
case Msg_Report_DaemonStart:
Reg_Write_key_one(
Reg_Root_achome,
Reg_Path_achome_dc + rep.Computername,
Reg_Name_achome_dc_lastlogin,
UnixTimeParse(&rep.Timestamp))
case Msg_Report_UserStart:
if rep.Version != Version{
return GJexecAck(Msg_Exec_UpdateVersion)
}
......@@ -57,7 +78,6 @@ func (rep *MJreport)Msg_Deal() interface{} {
PrintLog("Default Report Json ",rep.Report)
}
return nil
}
......@@ -213,4 +233,11 @@ func (bak * MJbackup)Msg_Deal() interface{}{
}
func (reg * MJreg)Msg_Deal() interface{}{
switch reg.Action{
case Msg_Reg_Query:
reg.DataStr = Reg_query_key_one(reg.Root,reg.Path,reg.Key)
}
return reg
}
\ No newline at end of file
......@@ -16,7 +16,7 @@ func GJreport(s string,who string) interface{}{
func (rep * MJreport)init(Report string) {
rep.Username = User_name
rep.Username = User_name
rep.Timestamp = NowTimestamp()
rep.Computername = User_computername
rep.MsgType = Msg_Report
rep.Report = Report
......@@ -60,6 +60,7 @@ func GJexecUserCmd(s string) interface{}{
func (exec * MJexec)init(s string){
exec.Username = User_name
exec.Computername = User_computername
exec.Timestamp = NowTimestamp()
exec.MsgType = Msg_Exec
exec.Instruction = s
exec.SessionID = User_sessionID
......@@ -67,6 +68,7 @@ func (exec * MJexec)init(s string){
exec.Status = Msg_Exec_State_Request
exec.IfDelay = false
exec.Delay = Rand(RandMax)
exec.Timestamp = NowTimestamp()
}
......@@ -78,6 +80,7 @@ func GJbackup()interface{}{
return rep
}
func (bak * MJbackup)init() {
bak.Timestamp = NowTimestamp()
bak.MsgType = Msg_Backup
bak.Version = BackupVersion
bak.Status = Msg_Backup_Status_Start
......
......@@ -188,9 +188,15 @@ func GetNewestDir(rdir ,extdir string) string {
func HasSuffix(str * string,sub string)bool{
return strings.HasSuffix(*str,sub)
}
fucn TrimSuffix(str ,s string)string{
func TrimSuffix(str ,s string)string{
return strings.TrimSuffix(str,s)
}
func Exit(){
os.Exit(0)
}
func NowTimestamp() int64 {
return time.Now().Unix()
}
func UnixTimeParse(t *int64) string {
return time.Unix(*t,0).String()
}
\ No newline at end of file
package public
import (
"reg"
)
......@@ -106,7 +106,7 @@ func SysMsgBox(pc,message string){
//
// regedit
//
func reg_prase(root * string) registry.Key{
func reg_prase(root * int) registry.Key{
switch *root{
case HKCU:
return registry.CURRENT_USER
......@@ -117,9 +117,7 @@ func reg_prase(root * string) registry.Key{
}
return registry.LOCAL_MACHINE
}
func Reg_query_item_one(root ,path string) string {
PrintLog(root,`\`,path)
func Reg_query_item_one(root int ,path string) string {
if k, kerr := registry.OpenKey(reg_prase(&root),path, registry.READ);kerr==nil{
defer k.Close()
if sk,err := k.ReadSubKeyNames(1); err ==nil{
......@@ -133,7 +131,7 @@ func Reg_query_item_one(root ,path string) string {
return ""
}
}
func Reg_query_key_one(root, path, key string) string {
func Reg_query_key_one(root int, path, key string) string {
if k, kerr := registry.OpenKey(reg_prase(&root),path, registry.READ);kerr==nil{
defer k.Close()
if sk,_,err := k.GetStringValue(key); err ==nil{
......@@ -148,3 +146,13 @@ func Reg_query_key_one(root, path, key string) string {
return ""
}
}
func Reg_Write_key_one(root int, path, name, value string) {
if k, kerr := registry.OpenKey(reg_prase(&root),path, registry.WRITE);kerr==nil{
defer k.Close()
if err := k.SetStringValue(name, value); err !=nil{
PrintLog(err)
}
} else {
PrintLog(kerr)
}
}
\ No newline at end of file
......@@ -134,7 +134,7 @@ func siEnter_admin(softname string){
// WxDrive Sync
//
//---------------------------------------------------------------
func menuInitWxDriveSync(ni){
func menuInitWxDriveSync(ni * walk.NotifyIcon){
fa := "用户工具"
sub := [...]string{"初始化","开启服务器同步到微盘","开启微盘同步到服务器","说明"}
// 建立空菜单
......@@ -179,6 +179,18 @@ func menuInitWxDriveSync(ni){
sysmenu.SetEnabled(true)
}
func wxdsInit(){
public.Msg("开发ing")
}
func wxdsToDrive(){
public.Msg("开发ing")
}
func wxdsToServer(){
public.Msg("开发ing")
}
func wxdsExplain(){
public.Msg("开发ing")
}
//---------------------------------------------------------------
......
No preview for this file type
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