From 82b5392b71d56d75b84e76599004391dd7f16d39 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 31 Oct 2003 04:16:16 +0000 Subject: [PATCH] * Cleanup of session creation --- ctdlphp/ctdlheader.php | 9 --------- ctdlphp/ctdlprotocol.php | 3 ++- ctdlphp/ctdlsession.php | 17 +++++++++++------ ctdlphp/logout.php | 2 +- ctdlphp/sessionproxy.php | 33 +++++++++++++++++++-------------- 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/ctdlphp/ctdlheader.php b/ctdlphp/ctdlheader.php index 590fc6992..57e78cbad 100644 --- a/ctdlphp/ctdlheader.php +++ b/ctdlphp/ctdlheader.php @@ -43,18 +43,9 @@ test_for_echo(); function bbs_page_footer() { - global $clientsocket; - echo "
"; - - if (!fclose($clientsocket)) { - echo "Error closing client socket.
\n"; - } - echo "Copyright © 2003 by The SCO Group.
\n"; echo "\n"; - - } ?> diff --git a/ctdlphp/ctdlprotocol.php b/ctdlphp/ctdlprotocol.php index 50a3e012a..4f0b60e62 100644 --- a/ctdlphp/ctdlprotocol.php +++ b/ctdlphp/ctdlprotocol.php @@ -10,7 +10,8 @@ function test_for_echo() { flush(); echo "Writing...
\n"; flush(); - fwrite($clientsocket, $command, strlen($command)); + // fwrite($clientsocket, $command, strlen($command)); + fwrite($clientsocket, $command); echo "Reading...
\n"; flush(); $response = fgets($clientsocket, 4096); diff --git a/ctdlphp/ctdlsession.php b/ctdlphp/ctdlsession.php index 605529b52..25427420b 100644 --- a/ctdlphp/ctdlsession.php +++ b/ctdlphp/ctdlsession.php @@ -51,13 +51,13 @@ function establish_citadel_session() { echo "Connected. Performing echo tests.
\n"; flush(); $cmd = "ECHO test echo string upon connection\n"; - fwrite($clientsocket, $cmd, strlen($cmd)); + fwrite($clientsocket, $cmd); $response = fgets($clientsocket, 4096); echo "Response is: ", $response, "
\n"; flush(); $cmd = "ECHO second test for echo\n"; - fwrite($clientsocket, $cmd, strlen($cmd)); + fwrite($clientsocket, $cmd); $response = fgets($clientsocket, 4096); echo "Response is: ", $response, "
\n"; flush(); @@ -71,15 +71,20 @@ function establish_citadel_session() { } +// +// Clear out both our Citadel session and our PHP session. We're done. +// function ctdl_end_session() { global $clientsocket, $session; - session_destroy(); + // Tell the Citadel server to terminate our connection. + fwrite($clientsocket, "QUIT\n"); + fclose($clientsocket); unset($clientsocket); - unset($session); - echo "Session destroyed.
\n"; - + // Now clear our PHP session. + unset($session); + session_destroy(); } ?> diff --git a/ctdlphp/logout.php b/ctdlphp/logout.php index 14a2c68d7..284983c8a 100644 --- a/ctdlphp/logout.php +++ b/ctdlphp/logout.php @@ -13,8 +13,8 @@ You are being logged out. LITERAL; - ctdl_end_session(); bbs_page_footer(); + ctdl_end_session(); ?> diff --git a/ctdlphp/sessionproxy.php b/ctdlphp/sessionproxy.php index 5c5ee40c3..d9977a636 100755 --- a/ctdlphp/sessionproxy.php +++ b/ctdlphp/sessionproxy.php @@ -60,18 +60,21 @@ system("/bin/rm -f " . $sockname); $sock = socket_create(AF_UNIX, SOCK_STREAM, 0); if ($sock < 0) { echo "socket_create() failed: ", socket_strerror($sock), "\n"; + system("/bin/rm -f " . $sockname); exit(2); } $ret = socket_bind($sock, $sockname); if ($ret < 0) { echo "socket_bind() failed: ", socket_strerror($ret), "\n"; + system("/bin/rm -f " . $sockname); exit(3); } $ret = socket_listen($sock, 5); if ($ret < 0) { echo "socket_listen() failed: ", socket_strerror($ret), "\n"; + system("/bin/rm -f " . $sockname); exit(4); } @@ -85,20 +88,23 @@ if (!$ctdlsock) { exit(5); } -echo "Connected to Citadel server.\n"; -$buf = fgets($ctdlsock, 4096); -echo $buf, "\n"; +// Read the greeting from the Citadel server. +if (!$buf = fgets($ctdlsock, 4096)) { + socket_close ($sock); + system("/bin/rm -f " . $sockname); + exit(6); +} + +// Make sure the server is allowing logins. +if (substr($buf, 0, 1) != "2") { + socket_close ($sock); + system("/bin/rm -f " . $sockname); + exit(7); +} do { $msgsock = socket_accept($sock); - if ($msgsock < 0) { - echo "socket_accept() failed: ", - socket_strerror($msgsock), "\n"; - break; - } - - do { - echo "Reading a line...\n"; + if ($msgsock >= 0) do { $buf = sock_gets($msgsock); if ($buf !== false) { fwrite($ctdlsock, $buf . "\n", (strlen($buf)+1) ); @@ -107,13 +113,12 @@ do { } } while($buf !== false); - echo "Closing socket.\n"; - socket_close ($msgsock); } while (true); -socket_close ($sock); +socket_close($sock); +socket_close($ctdlsock); system("/bin/rm -f " . $sockname); exit(0); -- 2.30.2