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


func main(){
	pub.AutoGetWeDriveDir()
	pub.Loger = pub.NewLoger(pub.Dir_tmp + `\adct.log`)
	var backupText	= flag.String(	pub.Msg_Backup	,""		,"backup status to AD")
	var reportText  = flag.String(	pub.Msg_Report	,""		,"report to AD")
	var execText	= flag.String(	pub.Msg_Exec	,""		,"exec to LocalDaemon")
	var regText		= flag.String(	pub.Msg_Reg		,""		,"mod reg")
	var userText	= flag.String(	"user"			,""		,"who is running me")
	var passText	= flag.String(	"pass"			,""		,"input passwork,but not need")
	var wolmacText	= flag.String(	"wolmac"		,""		,"input mac address for wake pc")
	var woluserText = flag.String(	"woluser"		,""		,"input name for walk pc")
	var wolallText 	= flag.Bool(	"wolall"		,false	,"wake all Domain Computer")
	var hourText 	= flag.Bool(	"hour"			,false	,"exec task at the time")
	
	flag.Parse()

	if *hourText 			{ flag_hour(						);return}
	if *reportText 	!= "" 	{ flag_report(	reportText			);return}
	if *backupText 	!= ""	{ flag_bakcup(	backupText			);return}
	if *execText 	!= "" 	{ flag_exec(	execText			);return}
	if *regText 	!= "" 	{ flag_reg(		regText				);return}
	if *wolmacText	!= "" 	{ flag_wolmac(	wolmacText			);return}
	if *woluserText	!= ""	{ flag_woluser(	woluserText			);return}
	if *wolallText		 	{ flag_wolall(	userText,passText	);return}

	return 
}
func flag_report(s *string){
	pub.SendServerReport(*s)
}
func flag_bakcup(s *string){
	;
}
func flag_exec(s * string){
	pub.SendServerExec(*s)
}
func flag_reg(s * string){
	;
}
func flag_wolmac(mac * string){
	if err := pub.Wol(*mac); err != nil{
		pub.PntError(err)
	} else {
		pub.PntWol(*mac)
	}
}
func flag_woluser(user * string){
	pub.PntWol("暂未开发")
}
func flag_hour(){
	nh := pub.GetHour()

	switch nh{
		
	case 0:
		pub.SendServerReport(pub.Msg_Report_StartBak)

		break
	case 1:
		pub.SendServerExec(pub.Msg_Report_TurnOffPC)
		break
	case 2:
		pub.SendServerExec(pub.Msg_Report_TurnOffPC)
		break
	case 3:
		pub.SendServerExec(pub.Msg_Report_TurnOffPC)
		break
	case 4:
		pub.SendServerExec(pub.Msg_Report_TurnOffPC)
		break
	default :
		pub.SendServerExec(pub.Msg_Report_TurnOffPC)
		break
	}
}
func flag_wolall(user* string,pass * string){
	if *user != pub.AD_User_wol {return}
	pcgroup := pub.LDAP_Get_PCGroup(user,pass)
	for i,pc := range pcgroup{
		mac := pub.Reg_query_key_one(
			pub.Reg_Root_ac,
			pub.Reg_Path_home_ac+pc,
			pub.Reg_Name_MACaddress)
		if mac == ""{
			pub.PntError(pc,"查找注册表失败")
			continue
		}else{
			pub.PntInfo(i,pc)
			pub.RandDelay(10)
			flag_wolmac(&mac)
		}
	}
}