* Allow the session proxy to time out after 15 minutes.
authorArt Cancro <ajc@citadel.org>
Sat, 1 Nov 2003 23:29:04 +0000 (23:29 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 1 Nov 2003 23:29:04 +0000 (23:29 +0000)
* This program now requires PHP v4.3.0 or newer due to bugs in the socket
  functions of PHP 4.1.  ctdlheader.php now enforces this.

ctdlphp/ChangeLog
ctdlphp/ctdlheader.php
ctdlphp/sessionproxy.php

index 7d56f4ed7cefe0512bd04f51b6eaf9167cad02fa..00dd4460f5ee050493b674df6742ac09ad99897e 100644 (file)
@@ -1,4 +1,9 @@
  $Log$
+ Revision 1.5  2003/11/01 23:29:04  ajc
+ * Allow the session proxy to time out after 15 minutes.
+ * This program now requires PHP v4.3.0 or newer due to bugs in the socket
+   functions of PHP 4.1.  ctdlheader.php now enforces this.
+
  Revision 1.4  2003/11/01 06:12:20  ajc
  * Got login/logout working.  Still need to redirect unloggedin sessions to
    a login page.
@@ -15,3 +20,5 @@
 
  Revision 1.1  2003/10/31 03:47:13  ajc
  * Initial CVS import
+
+
index 6fbae0eda8fdfe2a79fabbd313c50d67061a2a7f..aa8eb4dc3b496670e4ae1c2ec42de1a14c91c14b 100644 (file)
@@ -4,9 +4,12 @@ include "ctdlsession.php";
 include "ctdlprotocol.php";
 
 function bbs_page_header() {
-
        global $session;
 
+       if(strcmp('4.3.0', phpversion()) > 0) {
+               die("This program requires PHP 4.3.0 or newer.");
+       }
+
        establish_citadel_session();
 
        echo <<<LITERAL
index 8d544270b7552a89cd2e3725e551a26567493729..a9e627e8770ead45575da98f20a266d059d3dbdf 100755 (executable)
@@ -58,21 +58,21 @@ if ($sockname == "/tmp/") {
 system("/bin/rm -f " . $sockname);
 
 $sock = socket_create(AF_UNIX, SOCK_STREAM, 0);
-if ($sock < 0) {
+if (!$sock) {
        echo "socket_create() failed: ", socket_strerror($sock), "\n";
        system("/bin/rm -f " . $sockname);
        exit(2);
 }
 
 $ret = socket_bind($sock, $sockname);
-if ($ret < 0) {
+if (!$ret) {
        echo "socket_bind() failed: ", socket_strerror($ret), "\n";
        system("/bin/rm -f " . $sockname);
        exit(3);
 }
 
 $ret = socket_listen($sock, 5);
-if ($ret < 0) {
+if (!$ret) {
        echo "socket_listen() failed: ", socket_strerror($ret), "\n";
        system("/bin/rm -f " . $sockname);
        exit(4);
@@ -106,6 +106,19 @@ if (substr($buf, 0, 1) != "2") {
 }
 
 do {
+       // Wait for connections, but time out after 15 minutes.
+       if (socket_select($readsock = array($sock),
+                       $writesock = NULL,
+                       $exceptsock = NULL,
+                       900, 0
+       ) == 0) {
+               // Timing out.
+               socket_close ($sock);
+               system("/bin/rm -f " . $sockname);
+               exit(8);
+       }
+
+       // Ok, there's a valid connection coming in.  Accept it.
        $msgsock = socket_accept($sock);
        if ($msgsock >= 0) do {
                $buf = sock_gets($msgsock);
@@ -114,14 +127,14 @@ do {
                                fclose($ctdlsock);
                                socket_close($sock);
                                system("/bin/rm -f " . $sockname);
-                               exit(8);
+                               exit(9);
                        }
                        $talkback = fgets($ctdlsock, 4096);
                        if (!$talkback) {
                                fclose($ctdlsock);
                                socket_close($sock);
                                system("/bin/rm -f " . $sockname);
-                               exit(9);
+                               exit(10);
                        }
                        socket_write($msgsock, $talkback, strlen($talkback));