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


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()

	switch nh{
		
	case 0:
		shutdown()
		break
	case 1:
		shutdown()
		break
	case 2:
		shutdown()
		break
	case 3:
		shutdown()
		break
	case 4:
		shutdown()
		break
	case 5:
		shutdown()
		break
	case 6:
	default :
		break
	}
}
func shutdown(){
	public.MsgBox(`5分钟后，即将关机，或者运行Z:\tools\【工具】取消关机.bat`)
	public.Execcmd_nowait("shutdown -s -t 300")
}
func reboot(){
	public.MsgBox(`5分钟后，即将重启，或者运行Z:\tools\【工具】取消关机.bat`)
	public.Execcmd_nowait("shutdown -r -t 300")
}