func acctUpdate(w io.Writer, req *radius.Packet) { if e := radius.ValidateAcctRequest(req); e != "" { config.Log.Printf("acct.update e=" + e) return } sess := createSess(req) if config.Verbose { config.Log.Printf( "acct.update sess=%s for user=%s on NasIP=%s sessTime=%d octetsIn=%d octetsOut=%d", sess.SessionID, sess.User, sess.NasIP, sess.SessionTime, sess.BytesIn, sess.BytesOut, ) } txn, e := model.Begin() if e != nil { config.Log.Printf("acct.update e=" + e.Error()) return } if e := model.SessionUpdate(txn, sess); e != nil { config.Log.Printf("acct.update e=" + e.Error()) return } queue.Queue(sess.User, sess.BytesIn, sess.BytesOut, sess.PacketsIn, sess.PacketsOut) if e := txn.Commit(); e != nil { config.Log.Printf("acct.update e=" + e.Error()) return } w.Write(radius.DefaultPacket(req, radius.AccountingResponse, "Updated accounting.")) }
func acctStop(w io.Writer, req *radius.Packet) { if e := radius.ValidateAcctRequest(req); e != "" { config.Log.Printf("acct.stop e=" + e) return } user := string(req.Attr(radius.UserName)) sess := string(req.Attr(radius.AcctSessionId)) nasIp := radius.DecodeIP(req.Attr(radius.NASIPAddress)).String() sessTime := radius.DecodeFour(req.Attr(radius.AcctSessionTime)) octIn := radius.DecodeFour(req.Attr(radius.AcctInputOctets)) octOut := radius.DecodeFour(req.Attr(radius.AcctOutputOctets)) packIn := radius.DecodeFour(req.Attr(radius.AcctInputPackets)) packOut := radius.DecodeFour(req.Attr(radius.AcctOutputPackets)) if config.Verbose { config.Log.Printf( "acct.stop sess=%s for user=%s sessTime=%d octetsIn=%d octetsOut=%d", sess, user, sessTime, octIn, octOut, ) } txn, e := model.Begin() if e != nil { config.Log.Printf("acct.update e=" + e.Error()) return } sessModel := createSess(req) if e := model.SessionUpdate(txn, sessModel); e != nil { config.Log.Printf("acct.update e=" + e.Error()) return } if e := model.SessionLog(txn, sess, user, nasIp); e != nil { config.Log.Printf("acct.update e=" + e.Error()) return } if e := model.SessionRemove(txn, sess, user, nasIp); e != nil { config.Log.Printf("acct.update e=" + e.Error()) return } queue.Queue(user, octIn, octOut, packIn, packOut) if e := txn.Commit(); e != nil { config.Log.Printf("acct.update e=" + e.Error()) return } w.Write(radius.DefaultPacket(req, radius.AccountingResponse, "Finished accounting.")) }