X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=ctdlphp%2Fsessionproxy.php;h=22f4d4a0eddc1272e5e210b17088de6b85c2bc6e;hb=HEAD;hp=9f56d18b58b25eb5e4a917c4743070dde9d373b5;hpb=53dfe6066aac4c141539528e6d268ae804323bde;p=citadel.git diff --git a/ctdlphp/sessionproxy.php b/ctdlphp/sessionproxy.php deleted file mode 100755 index 9f56d18b5..000000000 --- a/ctdlphp/sessionproxy.php +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/php -q - - -// This program is released under the terms of the GNU General Public License. -// - - -// sock_gets() -- reads one line of text from a socket -// -function sock_gets($sock) { - $buf = socket_read($sock, 4096, PHP_NORMAL_READ); - if ($buf == false) return false; - - if (preg_match("'\n$'s", $buf)) { - $buf = substr($buf, 0, strpos($buf, "\n")); - } - - return $buf; -} - - - - - -// *** Start of main program *** - -error_reporting(E_ALL); - -/* Allow the script to hang around waiting for connections. */ -set_time_limit(0); - -/* Turn on implicit output flushing so we see what we're getting - * as it comes in. - */ -ob_implicit_flush(); - -if ($argc != 2) { - echo "usage: ", $argv[0], " sockname\n"; - exit(1); -} - -$sockname = $argv[1]; - -if ($sockname == "/tmp/") { - echo "Invalid socket name.\n"; - exit(1); -} - -// If there's a dead socket already there, remove it. -system("/bin/rm -f " . $sockname); - -$sock = socket_create(AF_UNIX, SOCK_STREAM, 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) { - echo "socket_bind() failed: ", socket_strerror($ret), "\n"; - system("/bin/rm -f " . $sockname); - exit(3); -} - -$ret = socket_listen($sock, 5); -if (!$ret) { - echo "socket_listen() failed: ", socket_strerror($ret), "\n"; - system("/bin/rm -f " . $sockname); - exit(4); -} - -// Set the permissions so someone else doesn't jump into our connection. -chmod($sockname, 0600); - -// We need to get a connection to the Citadel server going now. - -$ctdlsock = fsockopen("uncensored.citadel.org", 504, $errno, $errstr, 30); -//$ctdlsock = fsockopen("/appl/citadel/citadel.socket", 0, $errno, $errstr, 30); -if (!$ctdlsock) { - socket_close ($sock); - system("/bin/rm -f " . $sockname); - exit(5); -} - -// 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 { - // 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); - if ($buf !== false) { - if (!fwrite($ctdlsock, $buf . "\n")) { - fclose($ctdlsock); - socket_close($sock); - system("/bin/rm -f " . $sockname); - exit(9); - } - $talkback = fgets($ctdlsock, 4096); - if (!$talkback) { - fclose($ctdlsock); - socket_close($sock); - system("/bin/rm -f " . $sockname); - exit(10); - } - socket_write($msgsock, $talkback, strlen($talkback)); - - if (substr($talkback, 0, 1) == "1") do { - $buf = fgets($ctdlsock, 4096); - if (!$buf) { - $buf = "000\n" ; - } - else { - socket_write($msgsock, $buf, - strlen($buf)); - } - } while ($buf != "000\n"); - - } - } while($buf !== false); - - socket_close ($msgsock); - -} while (true); - -socket_close($sock); -fclose($ctdlsock); -system("/bin/rm -f " . $sockname); -exit(0); - -?>