예제 #1
0
파일: command.go 프로젝트: tcdog001/LMS
func (this *CommandController) Post() {
	//检查登录状态
	session := this.GetSession("Admin")
	if session == nil {
		beego.Trace("session verify failed!")
		this.Redirect("/", 302)
		return
	}

	//获取表单信息
	admin := this.Input().Get("CurUser")
	beego.Debug("admin=", admin)
	mac := this.Input().Get("mac")
	beego.Debug("mac=", mac)
	commandContent := this.Input().Get("commandContent")
	beego.Debug("commandContent=", commandContent)

	/*
		//判断该设备命令状态,如果存在命令未执行,则拒绝添加
		exist := models.CheckCommandExist(&command)
		if exist {
			beego.Debug("the device command exist!")
			path := "/deviceinfo?CurUser="******"&CommandExist=" + strconv.FormatBool(true)
			this.Redirect(path, 302)
			return
		}
		beego.Debug("the device command not exist! can add command")
	*/

	//数据库中添加管理员操作记录
	record := models.OperationRecord{
		Operator: admin,
		Mac:      mac,
		Command:  commandContent,
		Executed: false,
	}
	ok := models.AddOperationRecord(&record)
	if ok {
		//下发命令,设置状态为(待取)
		command := models.Command{
			Mac:       mac,
			Command:   commandContent,
			Executed:  false,
			Operecord: &record,
		}
		models.AddDeviceCommand(&command)
	}

	//返回设备页面
	path := "/deviceinfo?CurUser=" + admin
	this.Redirect(path, 302)
	return
}
예제 #2
0
파일: script.go 프로젝트: tcdog001/LMS
func (this *ScriptController) Post() {
	//用户身份认证
	session := this.GetSession("Admin")
	if session == nil {
		beego.Trace("session verify failed!")
		this.Redirect("/", 302)
		return
	}

	//获取post信息
	mac := this.Input().Get("Mac")
	admin := this.Input().Get("CurUser")
	beego.Debug(mac)
	beego.Debug(admin)
	//获取上传脚本
	filename := strconv.FormatInt(int64(time.Now().UnixNano()), 10) + ".sh"
	filepath := ScriptFolder + filename
	beego.Debug("saveFileName=", filepath)

	this.SaveToFile("file", filepath)

	//将script信息写入数据库
	script := models.Script{
		Mac:        mac,
		FilePath:   filename,
		Downloaded: false,
	}
	ok := models.AddScript(&script)
	if !ok {
		url := this.Ctx.Request.URL
		beego.Info(url)
		path := "/deviceinfo?mac=" + mac + "&CurUser="******"/deviceinfo?mac=" + mac + "&CurUser=" + admin
	this.Redirect(path, 302)
	return
}