package main
import (
	"AD-Control/public"
	"time"
	"flag"
)


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("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")
	
	flag.Parse()
	if *hourText 		{flag_hour();return}

	if *reportText 	!= "" { flag_report(reportText,userText)}
	if *backupText 	!= "" { flag_bakcup(backupText)}
	if *execText 	!= "" { flag_exec(execText)}
	if *wolmacText	!= "" { flag_wolmac(wolmacText)}
	if *woluserText	!= "" { flag_woluser(woluserText)}

	return 
}
func flag_report(s *string,who * string){
	public.SendServer(public.GJreport(*s,*who))
}
func flag_bakcup(s *string){
	;
}
func flag_exec(s * string){
	;
}
func flag_wolmac(mac * string){
	if err := public.Wol(*mac); err != nil{
		public.PrintLog(err)
	} else {
		public.PrintLog(*mac)
	}
}
func flag_woluser(user * string){
	public.PrintLog("暂未开发")
}
func flag_hour(){
	nh := time.Now().Hour()
	public.PrintLog(nh)
	switch nh{
		
	case 0:
		public.MsgBox(`5分钟后，即将关机，运行Z:\tools\【工具】取消关机.bat`)
		public.Execcmd_nowait("shutdown -s -t 300")
		break
	case 1:
		public.MsgBox(`5分钟后，即将重启，运行Z:\tools\【工具】取消关机.bat`)
		public.Execcmd_nowait("shutdown -r -t 300")
		break
	case 2:
		public.MsgBox(`5分钟后，即将重启，运行Z:\tools\【工具】取消关机.bat`)
		public.Execcmd_nowait("shutdown -r -t 300")
		break
	case 3:
		public.MsgBox(`5分钟后，即将关机，运行Z:\tools\【工具】取消关机.bat`)
		public.Execcmd_nowait("shutdown -s -t 300")
		break
	case 4:
	case 5:
	case 6:
		default :
		break
	}
}