Add squid helper to get the username
authorNeutron Soutmun <neo.neutron@gmail.com>
Tue, 17 Mar 2009 06:09:47 +0000 (13:09 +0700)
committerNeutron Soutmun <neo.neutron@gmail.com>
Tue, 17 Mar 2009 06:09:47 +0000 (13:09 +0700)
2009-03-17  Neutron Soutmun <neo.neutron@gmail.com>

* weblogin/squid_helper.php:
  - Add squid helper to get the username from rahunasd via XMLRPC,
    using the squid external_acl_type config option to archeive the point.

ChangeLog
weblogin/squid_helper.php [new file with mode: 0644]

index f6bc06f..93f679b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-03-17  Neutron Soutmun <neo.neutron@gmail.com>
 
+       * weblogin/squid_helper.php: 
+         - Add squid helper to get the username from rahunasd via XMLRPC, 
+           using the squid external_acl_type config option to archeive the point.
+
+2009-03-17  Neutron Soutmun <neo.neutron@gmail.com>
+
        * example/firewall.sh.in, example/rahunas.conf.in:
          - Add the bittorrent allow list in config file and according support 
            firewall script
diff --git a/weblogin/squid_helper.php b/weblogin/squid_helper.php
new file mode 100644 (file)
index 0000000..59f873e
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+include_once 'config.php';
+require_once 'rahu_xmlrpc.class.php';
+
+define(CACHE_TIME, 120);
+
+if (! defined(STDIN)) {
+  define("STDIN", fopen("php://stdin", "r"));
+}
+
+$user_list = array();
+
+while (!feof(STDIN)) {
+  $arg = trim(fgets(STDIN));
+  $srcip = rawurldecode($arg);
+
+  // Check cache
+  if (!empty($user_list[$srcip]['username']) && 
+    (time() - $user_list[$srcip]['timestamp']) < CACHE_TIME) {
+    fwrite(STDOUT, "OK user=". $user_list[$srcip]['username']  ."\n");
+    continue;
+  }
+
+  $xmlrpc = new rahu_xmlrpc_client();
+  $xmlrpc->host = $config["RAHUNAS_HOST"];
+  $xmlrpc->port = $config["RAHUNAS_PORT"];
+  try {
+    $retinfo = $xmlrpc->do_getsessioninfo($srcip);
+    if (is_array($retinfo) && !empty($retinfo['session_id'])) {
+      $user_list[$srcip]['username'] = $retinfo['username'];      
+      $user_list[$srcip]['timestamp'] = time();      
+      fwrite(STDOUT, "OK user=". $retinfo['username']  ."\n");
+    } else {
+      fwrite(STDOUT, "ERR\n");
+    }
+
+  } catch (XML_RPC2_FaultException $e) {
+      fwrite(STDOUT, "ERR\n");
+  } catch (Exception $e) {
+      fwrite(STDOUT, "ERR\n");
+  }
+  unset($xmlrpc);
+}
+?>