* Got login/logout working. Still need to redirect unloggedin sessions to
authorArt Cancro <ajc@citadel.org>
Sat, 1 Nov 2003 06:12:20 +0000 (06:12 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 1 Nov 2003 06:12:20 +0000 (06:12 +0000)
  a login page.

ctdlphp/ChangeLog
ctdlphp/ctdlheader.php
ctdlphp/ctdlprotocol.php
ctdlphp/ctdlsession.php
ctdlphp/login.php

index a9197843fec29ebfbfb51e0d286241303c9a2b65..7d56f4ed7cefe0512bd04f51b6eaf9167cad02fa 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 1.4  2003/11/01 06:12:20  ajc
+ * Got login/logout working.  Still need to redirect unloggedin sessions to
+   a login page.
+
  Revision 1.3  2003/11/01 05:10:49  ajc
  * When sending the QUIT command to the server, output a bunch more newlines
    so the session proxy has a chance to see that the Citadel server closed
@@ -11,4 +15,3 @@
 
  Revision 1.1  2003/10/31 03:47:13  ajc
  * Initial CVS import
-
index e8073362cd96c45bc878c2f454e941bcac41f672..6fbae0eda8fdfe2a79fabbd313c50d67061a2a7f 100644 (file)
@@ -18,7 +18,18 @@ function bbs_page_header() {
        <meta name="Description" content="Citadel BBS">
        <meta name="Keywords" content="citadel,bbs">
        <meta name="MSSmartTagsPreventParsing" content="TRUE">
-       <title>FIXME NAME BBS</title>
+       <title>
+LITERAL;
+
+       if ($_SESSION["serv_humannode"]) {
+               echo $_SESSION["serv_humannode"] ;
+       }
+       else {
+               echo "BBS powered by Citadel" ;
+       }
+
+       echo <<<LITERAL
+</title>
 </head>
 
 <body
index 2a6545187f5e6ff8bd0895d1460fc2120e161b07..228404872249d430c08e32e1a106b51ae328ab86 100644 (file)
@@ -30,25 +30,79 @@ function serv_puts($buf) {
        fwrite($clientsocket, $buf . "\n", (strlen($buf)+1) );
 }
 
+//
+// login_existing_user() -- attempt to login using a supplied username/password
+// Returns an array with two variables:
+// 0. TRUE or FALSE to determine success or failure
+// 1. String error message (if relevant)
+//
+function login_existing_user($user, $pass) {
+       global $clientsocket;
+
+       serv_puts("USER " . $user);
+       $resp = serv_gets();
+       if (substr($resp, 0, 1) != "3") {
+               return array(FALSE, substr($resp, 4));
+       }
+
+       serv_puts("PASS " . $pass);
+       $resp = serv_gets();
+       if (substr($resp, 0, 1) != "2") {
+               return array(FALSE, substr($resp, 4));
+       }
+
+       $_SESSION["username"] = $user;
+       $_SESSION["password"] = $pass;
+
+       return array(TRUE, "Login successful.  Have fun.");
+}
+
+
+//
+// create_new_user() -- attempt to create a new user 
+//                      using a supplied username/password
+// Returns an array with two variables:
+// 0. TRUE or FALSE to determine success or failure
+// 1. String error message (if relevant)
+//
+function create_new_user($user, $pass) {
+       global $clientsocket;
+
+       serv_puts("NEWU " . $user);
+       $resp = serv_gets();
+       if (substr($resp, 0, 1) != "2") {
+               return array(FALSE, substr($resp, 4));
+       }
+
+       serv_puts("SETP " . $pass);
+       $resp = serv_gets();
+       if (substr($resp, 0, 1) != "2") {
+               return array(FALSE, substr($resp, 4));
+       }
+
+       $_SESSION["username"] = $user;
+       $_SESSION["password"] = $pass;
+
+       return array(TRUE, "Login successful.  Have fun.");
+}
+
+
 
 //
 // Learn all sorts of interesting things about the Citadel server to
 // which we are connected.
 //
 function ctdl_get_serv_info() {
-       global $serv_humannode;
-       global $serv_software;
-
        serv_puts("INFO");
-       serv_gets($buf);
+       $buf = serv_gets();
        if (substr($buf, 0, 1) == "1") {
                $i = 0;
                do {
                        $buf = serv_gets();
-                       if ($i == 2) $serv_humannode = $buf;
-                       if ($i == 4) $serv_software = $buf;
+                       if ($i == 2) $_SESSION["serv_humannode"] = $buf;
+                       if ($i == 4) $_SESSION["serv_software"] = $buf;
                        $i = $i + 1;
-               } while ($buf != "000");
+               } while (strcasecmp($buf, "000"));
        }
 
 }
@@ -77,10 +131,10 @@ function ctdl_mesg($msgname) {
                echo "<DIV ALIGN=CENTER>\n";
                do {
                        $buf = serv_gets();
-                       if ($buf != "000") {
+                       if (strcasecmp($buf, "000")) {
                                echo "<TT>", $buf, "</TT><BR>\n" ;
                        }
-               } while ($buf != "000");
+               } while (strcasecmp($buf, "000"));
                echo "</DIV>\n";
        }
        else {
index 6669eac75af8d4007841273844f834b4c1216050..5683467abae3f93b76b9e42be3ea535b28fb588b 100644 (file)
@@ -42,24 +42,24 @@ function establish_citadel_session() {
 
                // Ok, now try again.
                $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
+
+               // Try to log the user back in.
+               if ($clientsocket) {
+
+
+                       if ($_SESSION["username"]) {
+                               login_existing_user(
+                                       $_SESSION["username"],
+                                       $_SESSION["password"]
+                               );
+                       }
+               }
        }
 
        if ($clientsocket) {
-               /*
-               echo "Connected.  Performing echo tests.<BR>\n";
-               flush();
-               $cmd = "ECHO test echo string upon connection\n";
-               fwrite($clientsocket, $cmd);
-               $response = fgets($clientsocket, 4096);
-               echo "Response is: ", $response, "<BR>\n";
-               flush();
-
-               $cmd = "ECHO second test for echo\n";
-               fwrite($clientsocket, $cmd);
-               $response = fgets($clientsocket, 4096);
-               echo "Response is: ", $response, "<BR>\n";
-               flush();
-               */
+               if (!$_SESSION["serv_humannode"]) {
+                       ctdl_get_serv_info();
+               }
        }
        else {
                echo "ERROR: no Citadel socket!<BR>\n";
index 7938064bc4e62ed1bac84c7beb6da5b16c7e9f0f..2190447d2f029742d1cb8527aaf1d5bbc6349ae9 100644 (file)
@@ -5,6 +5,25 @@
        ctdl_mesg("hello");
 ?>
 
+       <div align=center>
+       <form action="do_login.php" method="POST">
+
+       <table border="0" cellspacing="5" cellpadding="5" BGCOLOR="#EEEEEE">
+               <tr><td>User name:</td>
+               <td><input type="text" name="name" maxlength="25"></td></tr>
+               <tr><td>Password:</td>
+               <td><input type="password" name="pass" maxlength="20"></td></tr>
+
+       <tr><td align=center COLSPAN=2>
+       <input type="submit" name="action" value="Login">
+       <input type="submit" name="action" value="New User">
+       <input type="submit" name="action" value="Exit">
+       </td></tr>
+
+       </table>
+       </form>
+       </div>
+
 <a href="page2.php">Page Two</a><BR>
 <a href="page3.php">Page Three</a><BR>