Modules

toughradius.common

Common module

radiusd

toughradius.common.radiusd.run()[源代码]

startup default radius server

radclient

toughradius.common.radclient.get_dictionary(dictfile=None)[源代码]

Instantiated radius dictionary, if dictfile not exists, use default dictionary file path

参数:dictfile
返回:
toughradius.common.radclient.send_acct(server, port=1813, secret='testing123', debug=False, dictfile=None, **kwargs)[源代码]

send accounting request

参数:
  • server – radius server ipaddr
  • port – acct port, default 1813
  • secret – nas share secret
  • debug – logging level
  • dictfile – dictionary file path
  • kwargs – request params
返回:

acct response

toughradius.common.radclient.send_auth(server, port=1812, secret='testing123', debug=False, dictfile=None, **kwargs)[源代码]

send auth request

参数:
  • server – radius server ipaddr
  • port – auth port, default 1812
  • secret – nas share secret
  • debug – logging level
  • dictfile – dictionary file path
  • kwargs – request params
返回:

auth response

toughradius.common.radclient.send_coadm(server, port=3799, secret='testing123', debug=False, dictfile=None, **kwargs)[源代码]

send coa disconnect request to nas

参数:
  • server – nas server ipaddr
  • port – coa port, default 3799
  • secret – nas share secret
  • debug – logging level
  • dictfile – dictionary file path
  • kwargs – request params
返回:

coa response

radtest

toughradius.common.radtest.test_acct()[源代码]

send test acct request, include start,update,stop

toughradius.common.radtest.test_auth()[源代码]

send test auth request

tools

toughradius.common.tools.safestr(val)[源代码]

Convert to string

参数:val – source str
返回:
toughradius.common.tools.safeunicode(val)[源代码]

Convert to unicode

参数:val
返回:

json_log_formater

class toughradius.common.json_log_formater.JSONFormatter(fmt=None, datefmt=None)[源代码]

基类:logging.Formatter

JSON log formatter.

Usage example:

import logging

import json_log_formatter

json_handler = logging.FileHandler(filename='/var/log/my-log.json')
json_handler.setFormatter(json_log_formatter.JSONFormatter())

logger = logging.getLogger('my_json')
logger.addHandler(json_handler)

logger.info('Sign up', extra={'referral_code': '52d6ce'})

The log file will contain the following log record (inline):

{
    "message": "Sign up",
    "time": "2015-09-01T06:06:26.524448",
    "referral_code": "52d6ce"
}
extra_from_record(record)[源代码]

Returns extra dict you passed to logger.

The extra keyword argument is used to populate the __dict__ of the LogRecord.

format(record)[源代码]
json_lib = <module 'json' from '/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.pyc'>
json_record(message, extra, record)[源代码]

Prepares a JSON payload which will be logged.

Override this method to change JSON log format.

参数:
  • message – Log message, e.g., logger.info(msg=’Sign up’).
  • extra – Dictionary that was passed as extra param logger.info(‘Sign up’, extra={‘referral_code’: ‘52d6ce’}).
  • recordLogRecord we got from JSONFormatter.format().
返回:

Dictionary which will be passed to JSON lib.

mutate_json_record(json_record)[源代码]

Override it to convert fields of json_record to needed types.

Default implementation converts datetime to string in ISO8601 format.

to_json(record)[源代码]

Converts record dict to a JSON string.

Override this method to change the way dict is converted to JSON.

toughradius.radiusd

master

class toughradius.radiusd.master.RudiusAcctServer(adapter, host='0.0.0.0', port=1813, pool_size=32)[源代码]

基类:gevent.server.DatagramServer

Radius acct server

handle(data, address)[源代码]
class toughradius.radiusd.master.RudiusAuthServer(adapter, host='0.0.0.0', port=1812, pool_size=32)[源代码]

基类:gevent.server.DatagramServer

Radius auth server

handle(data, address)[源代码]

adapters

base

class toughradius.radiusd.adapters.base.BasicAdapter(settings)[源代码]

基类:object

acctReply(req, prereply)[源代码]

process radius accounting response

参数:
  • req
  • prereply
返回:

authReply(req, prereply)[源代码]

process radius auth response

返回类型:

object

参数:
  • req
  • prereply – dict
返回:

radius reply

static freeReply(req, **params)[源代码]

gen free auth response

参数:
  • req
  • params
返回:

getClients()[源代码]

fetch nas clients

Usage example:

def getClients(self):
    nas = dict(
        status=1,
        nasid='toughac',
        name='toughac',
        vendor=0,
        ipaddr='127.0.0.1',
        secret='testing123',
        coaport=3799
    )
    return { 'toughac' : nas, '127.0.0.1' : nas}
返回:nas dict
handleAcct(socket, data, address)[源代码]

acct request handle

参数:
  • socket
  • data
  • address
返回:

handleAuth(socket, data, address)[源代码]

auth request handle

参数:
  • socket
  • data
  • address
返回:

parseAcctPacket(datagram, (host, port))[源代码]

parse radius accounting request

参数:datagram
返回:pyrad.message
parseAuthPacket(datagram, (host, port))[源代码]

parse radius auth request

参数:datagram
返回:pyrad.message
processAcct(req)[源代码]

Function delivery to subclass implementation

参数:req
返回:
processAuth(req)[源代码]

Function delivery to subclass implementation

参数:req
返回:
static rejectReply(req, errmsg='')[源代码]

gen reject radius auth response

参数:
  • req
  • errmsg
返回:

static verifyAcctRequest(req)[源代码]

verify radius accounting request

参数:req

free

class toughradius.radiusd.adapters.free.FreeAdapter(settings)[源代码]

基类:toughradius.radiusd.adapters.base.BasicAdapter

Free auth mode

getClients()[源代码]
processAcct(req)[源代码]
processAuth(req)[源代码]
exception toughradius.radiusd.adapters.free.RestError[源代码]

基类:exceptions.BaseException

toughradius.radiusd.adapters.free.adapter

FreeAdapter 的别名

rest

class toughradius.radiusd.adapters.rest.RestAdapter(settings)[源代码]

基类:toughradius.radiusd.adapters.base.BasicAdapter

Http rest mode adapter

getClients()[源代码]
makeSign(message)[源代码]
processAcct(req)[源代码]
processAuth(req)[源代码]
exception toughradius.radiusd.adapters.rest.RestError[源代码]

基类:exceptions.BaseException

toughradius.radiusd.adapters.rest.adapter

RestAdapter 的别名

modules

accept_attr_process

toughradius.radiusd.modules.accept_attr_process.handle_radius(req, reply)[源代码]

accept_rate_process

toughradius.radiusd.modules.accept_rate_process.aikuai_rate(resp, _in, _out, rate_code=None)[源代码]
toughradius.radiusd.modules.accept_rate_process.cisco_rate(resp, _in, _out, rate_code=None)[源代码]
toughradius.radiusd.modules.accept_rate_process.h3c_rate(resp, _in, _out, rate_code=None)[源代码]
toughradius.radiusd.modules.accept_rate_process.handle_radius(req, reply)[源代码]
toughradius.radiusd.modules.accept_rate_process.huawei_e1_rate(resp, _in, _out, rate_code=None)[源代码]
toughradius.radiusd.modules.accept_rate_process.huawei_rate(resp, _in, _out, rate_code=None)[源代码]
toughradius.radiusd.modules.accept_rate_process.radback_rate(resp, _in, _out, rate_code=None)[源代码]
toughradius.radiusd.modules.accept_rate_process.ros_rate(resp, _in, _out, rate_code=None)[源代码]
toughradius.radiusd.modules.accept_rate_process.std_rate(resp, _in, _out, rate_code=None)[源代码]
toughradius.radiusd.modules.accept_rate_process.zte_rate(resp, _in, _out, rate_code=None)[源代码]

request_logger

toughradius.radiusd.modules.request_logger.handle_radius(req)[源代码]
toughradius.radiusd.modules.request_logger.log_acct(req)[源代码]
toughradius.radiusd.modules.request_logger.log_auth(req)[源代码]

request_mac_parse

toughradius.radiusd.modules.request_mac_parse.get_radius_attr(req, key)[源代码]
toughradius.radiusd.modules.request_mac_parse.handle_radius(req)[源代码]
toughradius.radiusd.modules.request_mac_parse.parse_cisco(req)[源代码]
toughradius.radiusd.modules.request_mac_parse.parse_h3c(req)[源代码]
toughradius.radiusd.modules.request_mac_parse.parse_normal(req)[源代码]
toughradius.radiusd.modules.request_mac_parse.parse_radback(req)[源代码]
toughradius.radiusd.modules.request_mac_parse.parse_zte(req)[源代码]

request_vlan_parse

toughradius.radiusd.modules.request_vlan_parse.handle_radius(req)[源代码]
toughradius.radiusd.modules.request_vlan_parse.parse_cisco(req)[源代码]

phy_slot/phy_subslot/phy_port:XPI.XCI

toughradius.radiusd.modules.request_vlan_parse.parse_radback(req)

phy_slot/phy_subslot/phy_port:XPI.XCI

toughradius.radiusd.modules.request_vlan_parse.parse_ros(req)

phy_slot/phy_subslot/phy_port:XPI.XCI

toughradius.radiusd.modules.request_vlan_parse.parse_std(req)[源代码]
toughradius.radiusd.modules.request_vlan_parse.parse_zte(req)

phy_slot/phy_subslot/phy_port:XPI.XCI

response_logger

toughradius.radiusd.modules.response_logger.handle_radius(req, reply)[源代码]
toughradius.radiusd.modules.response_logger.log_accept(req, reply)[源代码]
toughradius.radiusd.modules.response_logger.log_acct(req, reply)[源代码]
toughradius.radiusd.modules.response_logger.log_reject(req, reply)[源代码]