]> git.gsnw.org Git - m0n0chwall.git/commitdiff
First working version of fully integrated RADIUS PECL package. This includes NAS...
authorjdegraeve <jdegraeve@e36fee2c-cc09-0410-a7cc-ebac5c6737de>
Mon, 13 Feb 2006 11:58:17 +0000 (11:58 +0000)
committerjdegraeve <jdegraeve@e36fee2c-cc09-0410-a7cc-ebac5c6737de>
Mon, 13 Feb 2006 11:58:17 +0000 (11:58 +0000)
git-svn-id: https://svn.m0n0.ch/wall/trunk@88 e36fee2c-cc09-0410-a7cc-ebac5c6737de

captiveportal/radius_accounting.inc
captiveportal/radius_authentication.inc
phpconf/inc/captiveportal.inc

index 1b3959f150d10dba76e7368586588ac329deff75..79adc173852f377ce716ee33b9ffc94f9f5d496e 100644 (file)
@@ -113,8 +113,8 @@ function RADIUS_ACCOUNTING_START($ruleno,$username,$sessionid,$radiusip,$radiusp
 
     // Extra data to identify the client and nas
     $racct->putAttribute(RADIUS_FRAMED_IP_ADDRESS, $clientip, "addr");
-    $racct->putAttribute(RADIUS_CALLING_STATION_ID, $callingstationid);
     $racct->putAttribute(RADIUS_CALLED_STATION_ID, $calledstationid);
+    $racct->putAttribute(RADIUS_CALLING_STATION_ID, $callingstationid);
 
     // Send request
     $result = $racct->send();
@@ -165,13 +165,6 @@ function RADIUS_ACCOUNTING_STOP($ruleno,$username,$sessionid,$start_time,$radius
     $volume['output_bytes_radius'] = remainder($volume['output_bytes']);
     $volume['output_gigawords'] = gigawords($volume['output_bytes']);
 
-    // Make the volume data safe for our radius.inc functions (It really needs to be integer or we get an error)
-    // Working with an array to hold the data gives problems so we change them to normal vars
-    foreach ($volume as $var => $value) {
-        $var = $value;
-        settype($var, "int");
-    }
-
     switch($radiusvendor) {
 
         case 'cisco':
@@ -210,6 +203,8 @@ function RADIUS_ACCOUNTING_STOP($ruleno,$username,$sessionid,$start_time,$radius
     // Construct data package
     $racct->username = $username;
     $racct->addServer($radiusip, $radiusport, $radiuskey);
+    // Set session_time
+    $racct->session_time = $session_time;
 
     if (PEAR::isError($racct->start())) {
         $retvalue['acct_val'] = 1;
@@ -221,28 +216,29 @@ function RADIUS_ACCOUNTING_STOP($ruleno,$username,$sessionid,$start_time,$radius
         return $retvalue;
     }
 
+    // The RADIUS PECL Package doesn't have this vars so we create them ourself
+    define("RADIUS_ACCT_INPUT_GIGAWORDS", "52");
+    define("RADIUS_ACCT_OUTPUT_GIGAWORDS", "53");
+
     // Default attributes
     $racct->putAttribute(RADIUS_SERVICE_TYPE, RADIUS_OUTBOUND);
     $racct->putAttribute(RADIUS_NAS_PORT_TYPE, RADIUS_ETHERNET);
     $racct->putAttribute(RADIUS_NAS_PORT, $nas_port);
     $racct->putAttribute(RADIUS_ACCT_SESSION_ID, $sessionid);
 
-    // We have 2 ways to set the session-time, We are setting it through a var, reason see method putAuthAttributes()
-    $racct->session_time = $session_time;
-
     // Extra data to identify the client and nas
     $racct->putAttribute(RADIUS_FRAMED_IP_ADDRESS, $clientip, "addr");
-    $racct->putAttribute(RADIUS_CALLING_STATION_ID, $callingstationid);
     $racct->putAttribute(RADIUS_CALLED_STATION_ID, $calledstationid);
+    $racct->putAttribute(RADIUS_CALLING_STATION_ID, $callingstationid);
 
-    // Volume stuff: Ingress (Note: remove the explicit integer if the type conversion works like we expect)
-    $racct->putAttribute(RADIUS_ACCT_INPUT_PACKETS, $input_pkts, "integer");
-    $racct->putAttribute(RADIUS_ACCT_INPUT_OCTETS, $input_bytes_radius, "integer");
-    $racct->putAttribute(RADIUS_ACCT_INPUT_GIGAWORDS, $input_gigawords, "integer");
+    // Volume stuff: Ingress
+    $racct->putAttribute(RADIUS_ACCT_INPUT_PACKETS, $volume['input_pkts'], "integer");
+    $racct->putAttribute(RADIUS_ACCT_INPUT_OCTETS, $volume['input_bytes_radius'], "integer");
+    $racct->putAttribute(RADIUS_ACCT_INPUT_GIGAWORDS, $volume['input_gigawords'], "integer");
     // Volume stuff: Outgress
-    $racct->putAttribute(RADIUS_ACCT_OUTPUT_PACKETS, $output_pkts, "integer");
-    $racct->putAttribute(RADIUS_ACCT_OUTPUT_OCTETS, $output_bytes_radius, "integer");
-    $racct->putAttribute(RADIUS_ACCT_OUTPUT_GIGAWORDS, $output_gigawords, "integer");
+    $racct->putAttribute(RADIUS_ACCT_OUTPUT_PACKETS, $volume['output_pkts'], "integer");
+    $racct->putAttribute(RADIUS_ACCT_OUTPUT_OCTETS, $volume['output_bytes_radius'], "integer");
+    $racct->putAttribute(RADIUS_ACCT_OUTPUT_GIGAWORDS, $volume['output_gigawords'], "integer");
 
     if (!$interimupdate)
         $racct->putAttribute(RADIUS_ACCT_TERMINATE_CAUSE, $term_cause);
@@ -286,6 +282,11 @@ function gigawords($bytes) {
     // We use BCMath functions since normal integers don't work with so large numbers
     $gigawords = bcdiv( bcsub( $bytes, remainder($bytes) ) , 2147483647) ;
 
+    // We need to manually set this to a zero instead of NULL for put_int() safety
+    if (is_null($gigawords)) {
+        $gigawords = 0;
+    }
+
     return $gigawords;
 
 }
@@ -295,6 +296,11 @@ function remainder($bytes) {
     // Calculate the bytes we are going to send to the radius
     $bytes = bcmod($bytes, 2147483647);
 
+    if (is_null($bytes)) {
+        $bytes = 0;
+    }
+
+
     return $bytes;
 
 }
index f84f8b879edc3b66bb9b9e5365bdca80a00fc26a..ccbd3cfd53c3e9d3ff75553cb3e32adf9a690f11 100644 (file)
@@ -102,8 +102,8 @@ function RADIUS_AUTHENTICATION($username,$password,$radiusservers,$clientip,$cli
 
     // Extra data to identify the client and nas
     $rauth->putAttribute(RADIUS_FRAMED_IP_ADDRESS, $clientip, addr);
-    $rauth->putAttribute(RADIUS_CALLING_STATION_ID, $callingstationid);
     $rauth->putAttribute(RADIUS_CALLED_STATION_ID, $calledstationid);
+    $rauth->putAttribute(RADIUS_CALLING_STATION_ID, $callingstationid);
 
     // Send request
     $result = $rauth->send();
index 592d318e6c6d6a3cb0f69f2c6733c66b3870f7bd..b5c0612b70e3a8bf2007b5de1f742da4ab8b88bd 100644 (file)
@@ -901,15 +901,14 @@ function getVolume($ruleno) {
 
     $volume = array();
 
+    // Initialize vars properly, since we don't want NULL vars
+    $volume['input_pkts'] = $volume['input_bytes'] = $volume['output_pkts'] = $volume['output_bytes'] = 0 ;
+
     // Ingress
     exec("/sbin/ipfw show {$ruleno}", $ipfw);
     preg_match("/(\d+)\s+(\d+)\s+(\d+)\s+skipto/", $ipfw[0], $matches);
     $volume['input_pkts'] = $matches[2];
     $volume['input_bytes'] = $matches[3];
-    /* These functions are moved to the accounting part
-    $volume['input_bytes_radius'] = remainder($matches[3]);
-    $volume['input_gigawords'] = gigawords($matches[3]);
-    */
 
     // Flush internal buffer
     unset($matches);
@@ -918,10 +917,6 @@ function getVolume($ruleno) {
     preg_match("/(\d+)\s+(\d+)\s+(\d+)\s+skipto/", $ipfw[1], $matches);
     $volume['output_pkts'] = $matches[2];
     $volume['output_bytes'] = $matches[3];
-    /* These functions are moved to the accounting part
-    $volume['output_bytes_radius'] = remainder($matches[3]);
-    $volume['output_gigawords'] = gigawords($matches[3]);
-    */
 
     return $volume;
 }