package public

//
// quickly Get & Set Json 
//

// Report
 
func GJreport(s string,who string) interface{}{
	var rep MJreport
	rep.init(s)
	if who != "" { rep.Username = who }

	return rep
}
func (rep * MJreport)init(Report string)  {

	rep.Username 		= User_name
	rep.Timestamp		= NowTimestamp()
	rep.Computername 	= User_computername
	rep.MsgType 		= Msg_Report
	rep.Report			= Report
	rep.Version			= Version
}
func (rep * MJreport)PrintExplain(){
	PrintLog(rep.Computername,rep.Username,rep.Explain)
}


// Exec

func GJexec(s string) MJexec{
	var rep MJexec
	rep.init(s)
	return rep
}
func GJexecAck(s string) interface{}{
	var rep MJexec
	rep.init(s)
	rep.Status			= Msg_Exec_State_Ack
	return rep
}
func GJexecInstallSoftware(b bool,s string) interface{}{
	var exec MJexec
	exec.init(s)
	exec.Status				= Msg_Exec_State_Ack
	exec.Extbool			= b
	exec.Cmder				= Msg_Exec_Cmder_ADServer
	exec.Instruction		= Msg_Exec_InstallSoftware
	exec.Command			= s
	return exec
}
func GJexecUserCmd(s string) interface{}{
	var rep MJexec
	rep.init("")
	rep.Command			= s
	rep.Status			= Msg_Exec_State_Ack
	return rep
}
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
	exec.Cmder			= Msg_Exec_Cmder_LocalDaemon
	exec.Status			= Msg_Exec_State_Request
	exec.IfDelay		= false
	exec.Delay			= Rand(RandMax)
	exec.Timestamp		= NowTimestamp()
}


// Backup

func GJbackup()interface{}{
	var rep MJbackup
	rep.init()
	return rep
}
func (bak * MJbackup)init()  {
	bak.Timestamp			= NowTimestamp()
	bak.MsgType 		= Msg_Backup
	bak.Version 		= BackupVersion
	bak.Status			= Msg_Backup_Status_Start
	bak.Version			= Version
}
func (bak * MJbackup)Errorf(s string){
	bak.Status 			= Msg_Backup_Status_Error
	bak.Explain 		= "Backup Error: " + bak.Computername + " -> " + s
}
func (bak * MJbackup)PrintExplain(){
	PrintLog(bak.Username,bak.Status,bak.Explain)
}