package public

// app env ////////////////////////////////////////////////////////////////

//const Debug								bool
const DaemonPort						string = "16823"
const DaemonListen						string = ":" + DaemonPort
const ADServerDaemon					string = Env_MainADHostname + DaemonListen
var   LocalDaemon						string = User_computername + DaemonListen
const DocuBase							string = `C:\Users\Public\Documents\AD-Control\`
const RandMax							int	   = 60
const Version							string = "0.6"
const Application						string = "AD-Control-Log"


// user env ///////////////////////////////////////////////////////////////

var User_profile						string = GetEnv("USERPROFILE")
var User_name							string = GetEnv("USERNAME")
var User_computername					string = GetEnv("COMPUTERNAME")
var User_homeshare						string = GetEnv("HOMESHARE")
var User_userdomain						string = GetEnv("USERDOMAIN")
var User_fqdn_cn						string = GetEnvFqdn("CN")
var User_dept							string = GetEnvFqdn("OU")
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`)

// win-computer env /////////////////////////////////////////////////////

const Env_FreeFileSyncExe				string = `C:\Progra~2\zhiwei\FreeFileSync_10.22\FreeFileSync.exe`



// AD env ///////////////////////////////////////////////////////////

const Env_MainADHostname				string = "ADSERVER"
const Env_SMBAdserver 					string = `\\` +  Env_MainADHostname + `\`
const Env_ADSoft						string = Env_SMBAdserver + "software"
const Env_ADMain						string = Env_SMBAdserver + "ADMAIN"
var   Env_ADMainDeptShare				string = Env_ADMain + `\` + User_dept + `\` + "部门共享"
const Env_ADSoftlike					string = Env_ADSoft + `\` + "softlike"
const Env_ADApplication					string = Env_ADSoft	+ `\` + "application" + `\`	
const Env_ADSoftTool					string = Env_ADSoft + `\` + "tools" + `\`
const Env_ADSoftTool_RebootUser			string = Env_ADSoftTool + "upusers.bat"
const Env_ADsoftware_local				string = `F:\software\softlike\`


// backup env //////////////////////////////////////////////////////////////

var BackupVersion						string = "0428"
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`
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"

//
//
//
//  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		


// 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_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"`

}