summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/inc/captiveportal.inc52
-rw-r--r--etc/inc/radius.inc34
-rw-r--r--etc/inc/system.inc7
3 files changed, 92 insertions, 1 deletions
diff --git a/etc/inc/captiveportal.inc b/etc/inc/captiveportal.inc
index 4c1145c..3f91627 100644
--- a/etc/inc/captiveportal.inc
+++ b/etc/inc/captiveportal.inc
@@ -338,6 +338,9 @@ EOD;
unlink_if_exists("{$g['vardb_path']}/captiveportal_radius_{$cpzone}.db");
captiveportal_init_radius_servers();
+ /* send Accounting-On to server */
+ captiveportal_send_server_accounting();
+
if ($g['booting'])
echo "done\n";
@@ -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..8bddec8 100644
--- a/etc/inc/radius.inc
+++ b/etc/inc/radius.inc
@@ -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");
OpenPOWER on IntegriCloud