Add Session-Timeout support, prepare bandwidth var
authorNeutron Soutmun <neo.neutron@gmail.com>
Thu, 6 Nov 2008 07:15:01 +0000 (14:15 +0700)
committerNeutron Soutmun <neo.neutron@gmail.com>
Thu, 6 Nov 2008 07:15:01 +0000 (14:15 +0700)
2008-11-06  Neutron Soutmun <neo.neutron@gmail.com>

* src/rahunas.{h,c}, src/rh-task-memset.c, rh-task.h, src/rh-xmlrpc-server.c:
Add Session-Timeout support

* weblogin/login.php, weblogin/logout.php, weblogin/rahu_radius.class.php,
  weblogin/rahu_xmlrpc.class.php:
  Add Session-Timeout support and prepare the WISPr-Bandwidth-Max-{Down,Up}.

ChangeLog
src/rahunasd.c
src/rahunasd.h
src/rh-task-memset.c
src/rh-task.h
src/rh-xmlrpc-server.c
weblogin/login.php
weblogin/logout.php
weblogin/rahu_dictionary.php [new file with mode: 0644]
weblogin/rahu_radius.class.php
weblogin/rahu_xmlrpc.class.php

index e1cca43..1100d27 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-11-06  Neutron Soutmun <neo.neutron@gmail.com>
+
+       * src/rahunas.{h,c}, src/rh-task-memset.c, rh-task.h, src/rh-xmlrpc-server.c:
+               Add Session-Timeout support
+
+       * weblogin/login.php, weblogin/logout.php, weblogin/rahu_radius.class.php,
+         weblogin/rahu_xmlrpc.class.php:
+         Add Session-Timeout support and prepare the WISPr-Bandwidth-Max-{Down,Up}.
+
 2008-11-03  Neutron Soutmun <neo.neutron@gmail.com>
 
        * rahunas.firewall:
index 766d2f0..8615497 100644 (file)
@@ -215,14 +215,25 @@ size_t expired_check(void *data)
   DP("Map size %d", map->size);
  
   for (i = 0; i < map->size; i++) {
-    if (test_bit(IPSET_RAHUNAS_ISSET, (void *)&table[i].flags) && 
-          (time(NULL) - table[i].timestamp) > IDLE_THRESHOLD) {
-        DP("Found IP: %s expired", idtoip(map, i));
+    if (test_bit(IPSET_RAHUNAS_ISSET, (void *)&table[i].flags)) {
+      if ((time(NULL) - table[i].timestamp) > IDLE_THRESHOLD) {
+        // Idle Timeout
+        DP("Found IP: %s idle timeout", idtoip(map, i));
         req.id = i;
         memcpy(req.mac_address, &table[i].ethernet, ETH_ALEN);
         req.req_opt = RH_RADIUS_TERM_IDLE_TIMEOUT;
                          send_xmlrpc_stopacct(map, i, RH_RADIUS_TERM_IDLE_TIMEOUT);
         res = rh_task_stopsess(map, &req);
+      } else if (members[i].session_timeout != 0 && 
+                   time(NULL) > members[i].session_timeout) {
+        // Session Timeout (Expired)
+        DP("Found IP: %s session timeout", idtoip(map, i));
+        req.id = i;
+        memcpy(req.mac_address, &table[i].ethernet, ETH_ALEN);
+        req.req_opt = RH_RADIUS_TERM_SESSION_TIMEOUT;
+                         send_xmlrpc_stopacct(map, i, RH_RADIUS_TERM_SESSION_TIMEOUT);
+        res = rh_task_stopsess(map, &req);
+      }
     }
   }
 }
index eff78b1..00657ec 100644 (file)
@@ -56,6 +56,9 @@ struct rahunas_member {
   unsigned short flags; 
   unsigned short expired;
        time_t session_start;
+  time_t session_timeout;
+  long bandwidth_max_down;
+  long bandwidth_max_up;
        char *username;
   char *session_id;
   unsigned char mac_address[ETH_ALEN];
index 952de6c..a1fd02f 100644 (file)
@@ -106,6 +106,14 @@ static int startsess (struct rahunas_map *map, struct task_req *req)
 
   memcpy(&members[id].mac_address, &(req->mac_address), ETH_ALEN);
 
+  memcpy(&members[id].session_timeout, &req->session_timeout, sizeof(time_t));
+  members[id].bandwidth_max_down = req->bandwidth_max_down;
+  members[id].bandwidth_max_up = req->bandwidth_max_up;
+  DP("Session-Timeout %d", req->session_timeout);
+  DP("Bandwidth - Down: %lu, Up: %lu", req->bandwidth_max_down, 
+       req->bandwidth_max_up);
+
   logmsg(RH_LOG_NORMAL, "Session Start, User: %s, IP: %s, "
                         "Session ID: %s, MAC: %s",
                         members[id].username, 
index 8911d5e..58eb8ea 100644 (file)
@@ -17,6 +17,9 @@ struct task_req {
   const char *session_id;
   unsigned char mac_address[ETH_ALEN];
        time_t session_start;
+  time_t session_timeout;
+  long bandwidth_max_down;
+  long bandwidth_max_up;
   unsigned short req_opt;
 };
 
index 2c8ed31..10006bc 100644 (file)
@@ -30,6 +30,9 @@ int do_startsession(GNetXmlRpcServer *server,
        gchar *username = NULL;
        gchar *session_id = NULL;
   gchar *mac_address = NULL;
+  gchar *session_timeout = NULL;
+  gchar *bandwidth_max_down = NULL;
+  gchar *bandwidth_max_up = NULL;
        uint32_t id;
 
        if (!map)
@@ -47,6 +50,9 @@ int do_startsession(GNetXmlRpcServer *server,
        username    = rh_string_get_sep(param, "|", 2);
        session_id  = rh_string_get_sep(param, "|", 3);
   mac_address = rh_string_get_sep(param, "|", 4);
+  session_timeout    = rh_string_get_sep(param, "|", 5);
+  bandwidth_max_down = rh_string_get_sep(param, "|", 6);
+  bandwidth_max_up   = rh_string_get_sep(param, "|", 7);
 
   if (ip == NULL || username == NULL 
         || session_id == NULL)
@@ -67,6 +73,19 @@ int do_startsession(GNetXmlRpcServer *server,
   req.session_id = session_id;
   parse_mac(mac_address, &ethernet);
   memcpy(req.mac_address, &ethernet, ETH_ALEN);
+  
+  if (session_timeout != NULL) {
+    if (atol(session_timeout) != 0)
+      req.session_timeout = time(NULL) + atol(session_timeout);
+  }
+
+  if (bandwidth_max_down != NULL) {
+    req.bandwidth_max_down = atol(bandwidth_max_down);
+     
+  }
+
+  if (bandwidth_max_up != NULL)
+    req.bandwidth_max_up = atol(bandwidth_max_up);
 
   rh_task_startsess(map, &req);
 
@@ -84,6 +103,9 @@ cleanup:
   g_free(username);
   g_free(session_id);
   g_free(mac_address);
+  g_free(session_timeout);
+  g_free(bandwidth_max_down);
+  g_free(bandwidth_max_up);
   return 0;
 }
 
@@ -205,12 +227,13 @@ int do_getsessioninfo(GNetXmlRpcServer *server,
       return 0;
     }
     
-    *reply_string = g_strdup_printf("%s|%s|%s|%d|%s", 
+    *reply_string = g_strdup_printf("%s|%s|%s|%d|%s|%d", 
                                       ip, 
                                                  members[id].username,
                                                                                                                                                  members[id].session_id,
                                                                                                                                                  members[id].session_start,
-                                      mac_tostring(members[id].mac_address));
+                                      mac_tostring(members[id].mac_address),
+                                      members[id].session_timeout);
                return 0;
        }
 
index a57fec8..e3e0f71 100644 (file)
@@ -47,9 +47,15 @@ if (!empty($_POST['user']) && !empty($_POST['passwd'])) {
                $xmlrpc->port = $config["RAHUNAS_PORT"];
 
     try {
-               $result = $xmlrpc->do_startsession($ip, $_POST['user'], 
-                                         $racct->session_id, 
-                                         returnMacAddress());
+      $prepareData = array (
+        "IP" => $ip,
+        "Username" => $_POST['user'],
+        "SessionID" => $racct->session_id,
+        "MAC" => returnMacAddress(),
+        "Session-Timeout" => $rauth->attributes['session_timeout'],
+        "Bandwidth-Max-Down" => $rauth->attributes['WISPr-Bandwidth-Max-Down'],
+        "Bandwidth-Max-Up" => $rauth->attributes['WISPr-Bandwidth-Max-Up']);
+               $result = $xmlrpc->do_startsession($prepareData);
                if (strstr($result,"Client already login")) {
         $message = "ผู้ใช้นี้ ได้ใช้สิทธิ์เข้าใช้งานแล้ว";
            $forward = false;
@@ -69,6 +75,8 @@ if (!empty($_POST['user']) && !empty($_POST['passwd'])) {
        } else {
     if ($rauth->isLoggedIn()) {
            $message = "ไม่สามารถเข้าระบบได้ มีการเข้าระบบซ้ำ";
+    } else if ($rauth->isTimeout()) {
+           $message = "ไม่สามารถเข้าระบบได้ หมดเวลาการใช้งาน";
     } else {
            $message = "ไม่พบผู้ใช้นี้ หรือรหัสผ่านผิด";
     }
index 9650846..3e89793 100644 (file)
@@ -107,6 +107,11 @@ $valid_text = !$valid ? "" : "" .
 "      </tr>" .
 "" .
 "  <tr>" .
+"        <td align='right'><b>User expired:</b></td>" .
+"              <td>". ($info['session_timeout'] == 0 ? "Never" : date('j F Y H:i', $info['session_timeout'])) . "</td>" .
+"      </tr>" .
+"" .
+"  <tr>" .
 "        <td align='right'><b>Request URL:</b></td>" .
 "              <td><a href='$request_url' target='_new'>$request_url</a></td>" .
 "      </tr>" .
@@ -114,7 +119,8 @@ $valid_text = !$valid ? "" : "" .
 "<table>".
 " <tr>" .
 "        <td>&nbsp;<input type='hidden' name='do_logout' value='yes'></td>" .
-"        <td><input type='submit' value='Logout' id='rh_login_button'></td>" .
+"        <td><input type='button' value='Go! Go! Go!' id='rh_goto_button' onClick='window.open(\"".$request_url."\");'></td>" .
+"        <td><input type='submit' value='Logout' id='rh_logout_button'></td>" .
 "      </tr>" .
 "</table>";
 $request_uri = $_SERVER['REQUEST_URI'];
diff --git a/weblogin/rahu_dictionary.php b/weblogin/rahu_dictionary.php
new file mode 100644 (file)
index 0000000..e560f72
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+  $vendors[14122] = array ( 
+    1 => array ("AttributeName" => "WISPr-Location-ID", 
+                "AttributeType" => "string"),
+    2 => array ("AttributeName" => "WISPr-Location-Name",
+                "AttributeType" => "string"),
+    3 => array ("AttributeName" => "WISPr-Logoff-URL",
+                "AttributeType" => "string"),
+    4 => array ("AttributeName" => "WISPr-Redirection-URL",
+                "AttributeType" => "string"),
+    5 => array ("AttributeName" => "WISPr-Bandwidth-Min-Up",
+                "AttributeType" => "int"),
+    6 => array ("AttributeName" => "WISPr-Bandwidth-Min-Down",
+                "AttributeType" => "int"),
+    7 => array ("AttributeName" => "WISPr-Bandwidth-Max-Up",
+                "AttributeType" => "int"),
+    8 => array ("AttributeName" => "WISPr-Bandwidth-Max-Down", 
+                "AttributeType" => "int"), 
+    9 => array ("AttributeName" => "WISPr-Session-Terminate-Time",
+                "AttributeType" => "string"),
+   10 => array ("AttributeName" => "WISPr-Session-Terminate-End-Of-Day",
+                "AttributeType" => "string"),
+   11 => array ("AttributeName" => "WISPr-Billing-Class-Of-Service",
+                "AttributeType" => "string")
+  );
+?>
index 0dcb54d..87aa49e 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 require_once 'Auth/RADIUS.php';
 require_once 'Crypt/CHAP.php';
+require_once 'rahu_dictionary.php';
 
 class rahu_radius_auth {
   var $type;
@@ -14,17 +15,20 @@ class rahu_radius_auth {
        var $attributes;
        var $rawAttributes;
        var $rawVendorAttributes;
-  var $isLoggedIn;
+  var $LoggedIn;
+  var $Timeout;
 
   function rahu_radius_auth($username, $password, $type = 'CHAP_MD5') {
          $this->type = $type;
     $this->username = $username;
     $this->password = $password;
                $this->error = 0;
-    $this->isLoggedIn = false;
+    $this->LoggedIn = false;
        }
 
        function start() {
+    global $vendors;
+
          $type =& $this->type;
                $username =& $this->username;
                $password =& $this->password;
@@ -82,9 +86,21 @@ class rahu_radius_auth {
                        $this->rawAttributes = $rauth->rawAttributes;
                        $this->rawVendorAttributes = $rauth->rawVendorAttributes;
 
-      if (!empty($this->attributes['reply_message']) &&
-           strstr($this->attributes['reply_message'], "logged in")) {
-        $this->isLoggedIn = true;
+      // Extract the vendor attributes
+      foreach ($this->rawVendorAttributes as $ven_id=>$data) {
+        foreach ($data as $attr_id => $val) {
+          $get_helper = "radius_cvt_" . 
+                        $vendors[$ven_id][$attr_id]["AttributeType"];
+          $this->attributes[$vendors[$ven_id][$attr_id]["AttributeName"]] =
+            $get_helper($val);
+        }
+      }
+      
+      if (!empty($this->attributes['reply_message'])) {
+        if (strstr($this->attributes['reply_message'], "logged in"))
+          $this->LoggedIn = true;
+        else if (strstr($this->attributes['reply_message'], "Your maximum"))
+          $this->Timeout = true;
       }
     }
     
@@ -103,7 +119,11 @@ class rahu_radius_auth {
        }
 
   function isLoggedIn() {
-    return $this->isLoggedIn;
+    return $this->LoggedIn;
+  }
+  
+  function isTimeout() {
+    return $this->Timeout;
   }
 }
 
index 053d4e8..6572e22 100644 (file)
@@ -19,9 +19,10 @@ class rahu_xmlrpc_client {
 
        }
 
-       function do_startsession($ip, $username, $sid, $mac) {
+       function do_startsession($data) {
     $client = $this->getClient(); 
-               $params = sprintf("%s|%s|%s|%s", $ip, $username, $sid, $mac);
+               $params = implode("|", $data);
+    $params .= "|";
     $result = $client->startsession($params);
                return $result;
        }
@@ -46,18 +47,21 @@ class rahu_xmlrpc_client {
                   $ret[1] - username
                         $ret[2] - session_id
                         $ret[3] - session_start
-       $ret[4] - mac_address */
+       $ret[4] - mac_address
+       $ret[5] - session_timeout */
                $ip = $ret[0];
                $username = $ret[1];
                $session_id = $ret[2];
                $session_start = $ret[3];
                $mac_address = $ret[4];
+    $session_timeout = $ret[5];
 
          $result = array("ip"=>$ip, 
                                "username"=>$username, 
                                                                                "session_id"=>$session_id,
                                                                                "session_start"=>$session_start,
-                    "mac_address"=>$mac_address);
+                    "mac_address"=>$mac_address,
+                    "session_timeout"=>$session_timeout);
                return $result;
        }
 }