]> code.citadel.org Git - citadel.git/blobdiff - ctdlphp/ctdlsession.php
* socket syntax is different in php5. make it configurable.
[citadel.git] / ctdlphp / ctdlsession.php
index a120094023eac2a073c69cf551af9421d0006bfa..988839cc885286be72454637a97b9aa0c5a416f7 100644 (file)
@@ -1,5 +1,4 @@
 <?PHP
-
 // $Id$
 //
 // This gets called from within the header functions.  It establishes or
@@ -22,7 +21,7 @@ function establish_citadel_session() {
 
        session_start();
 
-       if ($_SESSION["ctdlsession"]) {
+       if (isset($_SESSION["ctdlsession"])) {
                $session = $_SESSION["ctdlsession"];
        }
        else {
@@ -36,17 +35,25 @@ function establish_citadel_session() {
 
        $sockname = "/tmp/" . $session . ".socket" ;
 
-       $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
+       $clientsocket = fsockopen(SOCKET_PREFIX.$sockname, 0, $errno, $errstr, 5);
        if (!$clientsocket) {
                // It ain't there, dude.  Open up the proxy. (C version)
                //$cmd = "./sessionproxy " . $sockname ;
                //exec($cmd);
 
                // It ain't there, dude.  Open up the proxy.  (PHP version)
+               if (CITADEL_DEBUG_PROXY){
+                       $stdout = '>>/tmp/sessionproxyout.txt ';
+               }
+               else{
+                       $stdout = '>/dev/null ';
+               }
+
                $cmd = "./sessionproxy.php " . $sockname .
-                       " </dev/null >/dev/null 2>&1 " .
+                       " </dev/null ".$stdout."2>&1 " .
                        " 3>&1 4>&1 5>&1 6>&1 7>&1 8>&1 & " ;
                exec($cmd);
+               sleep(1);
 
                // Keep attempting connections 10 times per second up to 100 times
                $attempts = 0;
@@ -63,17 +70,23 @@ function establish_citadel_session() {
                }
 
                // At this point we have a good connection to Citadel.
-
-               ctdl_iden();    // Identify client
-
-               if ($_SESSION["username"]) {
+               $identity=array(
+                       "DevelNr" => '0',
+                       "ClientID" => '8',
+                       "VersionNumber" => '001',
+                       "ClientInfoString" => 'PHP web client|',
+                       "Remote Address" => $_SERVER['REMOTE_ADDR'] );
+
+               ctdl_iden($identity);   // Identify client
+               ctdl_MessageFormatsPrefered(array("text/html","text/plain"));
+               if (isset($_SESSION["username"])) {
                        login_existing_user(
                                $_SESSION["username"],
                                $_SESSION["password"]
                        );
                }
 
-               if ($_SESSION["room"]) {
+               if (isset($_SESSION["room"])) {
                        ctdl_goto($_SESSION["room"]);
                }
                else {
@@ -81,15 +94,19 @@ function establish_citadel_session() {
                }
        }
 
-       if (!$_SESSION["serv_humannode"]) {
-               ctdl_get_serv_info();
+       if (!isset($_SESSION["serv_humannode"])) {
+               $server_info = ctdl_get_serv_info();
+               print_r($server_info);
+               $keys = array_keys($server_info);
+               foreach ($keys as $key)
+                       $_SESSION[$key] = $server_info[$key];
        }
 
        // If the user is trying to call up any page other than
        // login.php logout.php do_login.php,
        // and the session is not logged in, redirect to login.php
        //
-       if ($_SESSION["logged_in"] != 1) {
+       if (isset($_SESSION["logged_in"]) && ($_SESSION["logged_in"] != 1)) {
                $filename = basename(getenv('SCRIPT_NAME'));
                if (    (strcmp($filename, "login.php"))
                   &&   (strcmp($filename, "logout.php"))