Example #1
0
func run() {
	for {
		for k, v := range alive {
			beego.Debug("keepalive", k, v)

			if time.Now().Sub(v.HitTime) >= time.Duration(TIMEOUT_INTERVAL)*time.Minute {
				//step 1: get and delete user status
				user := &UserStatus{
					UserMac: k,
				}
				user.Get() // first get for stop radius
				user.Delete()

				//step 2: stop radius
				user.Reason = int(radgo.DeauthReasonAging)
				radusr := &RadUser{
					User: user,
				}
				radgo.ClientAcctStop(radusr)

				//step 3: unregister user info
				info := &UserInfo{
					UserName: v.UserName,
				}
				info.UnRegister()

				//step 4: delete alive
				delete(alive, k)
			}
		}

		beego.Debug("Listener Gc running...")
		time.Sleep(GC_INTERVAL * time.Minute)
	}
}
Example #2
0
func (this *DeauthController) Post() {
	body := this.Ctx.Input.RequestBody
	beego.Info("request body=", string(body))

	//step 1: get input
	code := &StatusCode{}
	input := &deauthInput{}

	if err := json.Unmarshal(body, input); nil != err {
		code.Write(this.Ctx, ErrUmsInputError, err)

		return
	}
	beego.Debug("deauth input", input)

	//step 2: get user from db
	user := input.UserStatus()
	if nil != user.Get() {
		code.Write(this.Ctx, ErrUmsUserStatusNotExist, nil)

		return
	}

	user.Reason = int(radgo.GetDeauthReason(input.Reason))

	//step 3: radius acct stop
	raduser := user.RadUser()
	if err, aerr := radgo.ClientAcctStop(raduser); err != nil {
		code.Write(this.Ctx, ErrUmsRadAcctStopError, err)

		return
	} else if aerr != nil {
		code.Write(this.Ctx, ErrUmsRadError, aerr)

		return
	}
	beego.Debug("Redius stop success!")

	if nil != user.Delete() {
		code.Write(this.Ctx, ErrUmsUserStatusDeleteError, nil)

		return
	}

	//step 4: delete user(db)
	if err := user.Delete(); nil != err {
		beego.Debug("delete user", user)

		// NOT abort, must do below
	}

	//step 5: stop keepalive
	mod.DelAlive(user.UserMac)

	//step 6: log user record
	mod.LogUserRecord(user)

	//step 7: output
	code.Write(this.Ctx, 0, nil)

	return
}