diff options
author | Warren Baker <warren@decoy.co.za> | 2013-02-14 23:16:52 -0800 |
---|---|---|
committer | Warren Baker <warren@decoy.co.za> | 2013-02-14 23:16:52 -0800 |
commit | d896f86751bae79625197da6c80d709fdf185448 (patch) | |
tree | 8f104508f9a6265b47916dc10fd1926f61ea298c | |
parent | 2ccc41c1c537994e10c9deb4ac061ce55edb6537 (diff) | |
parent | e35ab948a3f9bbf016a1317cdd3c527761d86d79 (diff) | |
download | pfsense-d896f86751bae79625197da6c80d709fdf185448.zip pfsense-d896f86751bae79625197da6c80d709fdf185448.tar.gz |
Merge pull request #236 from miken32/nas_accounting
NAS accounting
-rw-r--r-- | etc/inc/captiveportal.inc | 54 | ||||
-rw-r--r-- | etc/inc/radius.inc | 48 | ||||
-rw-r--r-- | etc/inc/system.inc | 7 |
3 files changed, 100 insertions, 9 deletions
diff --git a/etc/inc/captiveportal.inc b/etc/inc/captiveportal.inc index 4c1145c..c63e3c9 100644 --- a/etc/inc/captiveportal.inc +++ b/etc/inc/captiveportal.inc @@ -338,8 +338,11 @@ EOD; unlink_if_exists("{$g['vardb_path']}/captiveportal_radius_{$cpzone}.db"); captiveportal_init_radius_servers(); - if ($g['booting']) + if ($g['booting']) { + /* send Accounting-On to server */ + captiveportal_send_server_accounting(); echo "done\n"; + } } else { killbypid("{$g['varrun_path']}/lighty-{$cpzone}-CaptivePortal.pid"); @@ -351,6 +354,11 @@ EOD; captiveportal_radius_stop_all(); + /* send Accounting-Off to server */ + if (!$g['booting']) { + captiveportal_send_server_accounting(true); + } + /* remove old information */ unlink_if_exists("{$g['vardb_path']}/captiveportal{$cpzone}.db"); unlink_if_exists("{$g['vardb_path']}/captiveportal_radius_{$cpzone}.db"); @@ -2027,4 +2035,48 @@ function captiveportal_write_usedmacs_db($usedmacs) { unlock($cpumaclck); } +function captiveportal_send_server_accounting($off = false) { + global $cpzone, $config; + + if (!isset($config['captiveportal'][$cpzone]['radacct_enable'])) { + return; + } + if ($off) { + $racct = new Auth_RADIUS_Acct_Off; + } else { + $racct = new Auth_RADIUS_Acct_On; + } + $radiusservers = captiveportal_get_radius_servers(); + if (empty($radiusservers)) { + return; + } + foreach ($radiusservers['first'] as $radsrv) { + // Add a new server to our instance + $racct->addServer($radsrv['ipaddr'], $radsrv['acctport'], $radsrv['key']); + } + if (PEAR::isError($racct->start())) { + $retvalue['acct_val'] = 1; + $retvalue['error'] = $racct->getMessage(); + + // If we encounter an error immediately stop this function and go back + $racct->close(); + return $retvalue; + } + // Send request + $result = $racct->send(); + // Evaluation of the response + // 5 -> Accounting-Response + // See RFC2866 for this. + if (PEAR::isError($result)) { + $retvalue['acct_val'] = 1; + $retvalue['error'] = $result->getMessage(); + } else if ($result === true) { + $retvalue['acct_val'] = 5 ; + } else { + $retvalue['acct_val'] = 1 ; + } + + $racct->close(); + return $retvalue; +} ?> diff --git a/etc/inc/radius.inc b/etc/inc/radius.inc index 7e69e36..24d15b6 100644 --- a/etc/inc/radius.inc +++ b/etc/inc/radius.inc @@ -43,12 +43,12 @@ * Adding of VENDOR Bay Networks (Nortel) * Adding of VENDOR Nomadix * Adding of VENDOR WISPr (Wi-Fi Alliance) - * Adding of VENDOR ChilliSpot (bandwidth-attributes only) + * Adding of VENDOR ChilliSpot (bandwidth-attributes only) */ /* - pfSense_MODULE: auth + pfSense_MODULE: auth */ require_once("PEAR.inc"); @@ -645,10 +645,10 @@ class Auth_RADIUS extends PEAR { } elseif ($vendor == 8744) { /* Colubris / HP MSM wireless */ - //documented at http://bizsupport1.austin.hp.com/bc/docs/support/SupportManual/c02704528/c02704528.pdf pg 15-67 + //documented at http://bizsupport1.austin.hp.com/bc/docs/support/SupportManual/c02704528/c02704528.pdf pg 15-67 if ($attrv == 0) { /* Colubris AV-Pair */ - $datav = explode('=', $datav); - switch ($datav[0]) { + $datav = explode('=', $datav); + switch ($datav[0]) { case 'max-input-rate': // "Controls the data rate [kbps] at which traffic can be transferred from the user to the [router]." $this->attributes['bw_up'] = radius_cvt_int($datav[1]); @@ -1095,14 +1095,14 @@ class Auth_RADIUS_Acct extends Auth_RADIUS } $this->putAttribute(RADIUS_ACCT_STATUS_TYPE, $this->status_type); //if (isset($this->session_time) && $this->status_type == RADIUS_STOP) { - if (isset($this->session_time)) { + if (isset($this->session_time)) { $this->putAttribute(RADIUS_ACCT_SESSION_TIME, $this->session_time); } if (isset($this->authentic)) { $this->putAttribute(RADIUS_ACCT_AUTHENTIC, $this->authentic); } - $this->putStandardAttributes(); + $this->putStandardAttributes(); } } @@ -1161,4 +1161,38 @@ class Auth_RADIUS_Acct_Update extends Auth_RADIUS_Acct var $status_type = RADIUS_UPDATE; } +/** + * class Auth_RADIUS_Acct_On + * + * Class for sending Accounting-On updates + * + * @package Auth_RADIUS + */ +class Auth_RADIUS_Acct_On extends Auth_RADIUS_Acct +{ + /** + * Defines the type of the accounting request. + * It is set to RADIUS_ACCOUNTING_ON by default in this class. + * @var integer + */ + var $status_type = RADIUS_ACCOUNTING_ON; +} + +/** + * class Auth_RADIUS_Acct_Off + * + * Class for sending Accounting-Off updates + * + * @package Auth_RADIUS + */ +class Auth_RADIUS_Acct_Off extends Auth_RADIUS_Acct +{ + /** + * Defines the type of the accounting request. + * It is set to RADIUS_ACCOUNTING_OFF by default in this class. + * @var integer + */ + var $status_type = RADIUS_ACCOUNTING_OFF; +} + ?> diff --git a/etc/inc/system.inc b/etc/inc/system.inc index de3d197..2bd0f91 100644 --- a/etc/inc/system.inc +++ b/etc/inc/system.inc @@ -1344,9 +1344,14 @@ function system_reboot_sync() { } function system_reboot_cleanup() { + global $config, $cpzone; + mwexec("/usr/local/bin/beep.sh stop"); require_once("captiveportal.inc"); - captiveportal_radius_stop_all(); + foreach ($config['captiveportal'] as $cpzone=>$cp) { + captiveportal_radius_stop_all(); + captiveportal_send_server_accounting(true); + } require_once("voucher.inc"); voucher_save_db_to_config(); require_once("pkg-utils.inc"); |