* experiments on user creation... not yet ready, but maybe helpfull to others.
authorWilfried Göesgens <willi@citadel.org>
Mon, 28 May 2007 22:01:14 +0000 (22:01 +0000)
committerWilfried Göesgens <willi@citadel.org>
Mon, 28 May 2007 22:01:14 +0000 (22:01 +0000)
ctdlphp/ctdlelements.php
ctdlphp/ctdlheader.php
ctdlphp/ctdlprotocol.php
ctdlphp/ctdlsession.php
ctdlphp/do_login.php
ctdlphp/myinfo.php [new file with mode: 0644]
ctdlphp/sessionproxy.php
ctdlphp/sitestyle.css

index 8834601c4e7657a03c4cd235cefd8d127072e8d2..e165b71eb2500bde159c69cb38590661e962c7ad 100644 (file)
@@ -59,6 +59,25 @@ function display_message($msgnum) {
        echo '</TD></TR></TABLE><BR>' ;
 }
 
+function get_message_partlist($msgnum) {
+
+       // Fetch the message from the server
+       list($ok, $response, $fields) = ctdl_fetch_message($msgnum);
+
+       // Bail out gracefully if the message isn't there.
+       if (!$ok) {
+               echo "Error: " . htmlspecialchars($response) . "<BR>" ;
+               return false;
+       }
+       if (isset($fields['part']))
+       {
+               $parts = explode('|', $fields['part']);
+               return $parts;
+
+       }
+       return false;
+}
+
 
 
 ?>
index 43c0f335b5c6d6c97df508ce4e97ebee693ef3b5..d097117e0a54373b0d88d53eb05e8d4f431748b6 100644 (file)
@@ -81,6 +81,22 @@ LITERAL;
                        'Enter msg</a><BR>' .
                        '<a href="who.php">' .
                        'Who is online?</a><BR>' .
+                       '<a href="myinfo.php">' .
+                       'My information</a><BR>' .
+                       '<A HREF="logout.php">' .
+                       'Log out</A>' .
+                       '</div>' ;
+               echo    '<div id="demolinks">' .
+                       '<a href="testcommand.php">' .
+                       'demolist</A><BR>' .
+                       '<a href="readmsgs.php?mode=all&count=0">' .
+                       'Read all</a><BR>' .
+                       '<a href="readmsgs.php?mode=new&count=0">' .
+                       'Read new</a><BR>' .
+                       '<a href="display_enter.php">' .
+                       'Enter msg</a><BR>' .
+                       '<a href="who.php">' .
+                       'Who is online?</a><BR>' .
                        '<A HREF="logout.php">' .
                        'Log out</A>' .
                        '</div>' ;
index bd619598e257c688a8e0bac8c0cd77e012d6529e..677ad5c000e9e482955c51d67aba9f44b1469d21 100644 (file)
@@ -20,14 +20,55 @@ function serv_gets($readblock=FALSE) {
        $buf = fgets($clientsocket, 4096);              // Read line
        $buf = substr($buf, 0, (strlen($buf)-1) );      // strip trailing LF
        if (CITADEL_DEBUG_CITPROTO == 1) {
-               if (!$readblock) printf ("<div class='ctdldbgRead'>");
+               if (!$readblock) printf ("<div class='ctdldbgRead'>\n");
                printf($buf);
-               if (!$readblock) printf ("</div>");
-               else printf ("<br>");
+               if (!$readblock) printf ("\n</div>\n");
+               else printf ("<br>\n");
        }
        return $buf;
 }
 
+//
+// serv_get_n() -- generic function to read a binary blob from the server
+//
+function serv_get_n($nBytes) {
+       global $clientsocket;
+
+       if (CITADEL_DEBUG_CITPROTO == 1) {
+               printf ("<div class='ctdldbgRead'>\n");
+               printf("reading ".$nBytes." bytes from server\n");
+               printf ("</div>\n");
+       }
+       $i = 0;
+       $buf = "";
+       $nRead = 0;
+//     while ($nRead < $nBytes)
+       {
+               $buf = fread($clientsocket, $nBytes);
+//             $buf.=fgetc($clientsocket) | die ("fgetc failed");
+//             $buf .= serv_gets(TRUE);
+//             $tbuf = fgets($clientsocket, $nBytes - $nRead);
+               if (CITADEL_DEBUG_CITPROTO == 1) {
+                       if (!$buf) printf ("<div class='ctdldbgRead'>\n");
+                       printf($buf);
+                       if (!$buf) printf ("</div>\n");
+                       else printf ("<br>\n");
+               }
+//             $buf .= $tbuf;
+//             $nRead = strlen ($buf);
+
+       }
+               
+       //$buf = fread($clientsocket, $nBytes) | die ("fread failed");          // Read line
+       if (CITADEL_DEBUG_CITPROTO == 1) {
+               printf ("<div class='ctdldbgRead'>\n");
+               printf($buf);
+               printf ("</div>\n");
+       }
+       print_r($buf);
+       return $buf;
+}
+
 //
 // serv_puts() -- generic function to write one line of text to the server
 //
@@ -37,13 +78,14 @@ function serv_puts($buf) {
        fwrite($clientsocket, $buf . "\n", (strlen($buf)+1) );
        fflush($clientsocket);
        if (CITADEL_DEBUG_CITPROTO == 1)
-               printf ("<div class='ctdldbgWrite'>".$buf."</div>");
+               printf ("<div class='ctdldbgWrite'>".$buf."</div>\n");
 }
 
+
 function read_array() {
        $nLines = 0;
        if (CITADEL_DEBUG_CITPROTO == 1)
-           printf ("<div class='ctdldbgRead'>");
+           printf ("<div class='ctdldbgRead'>\n");
        $buf = serv_gets(TRUE);
        $ret = array();
        while (strcasecmp($buf, "000")){
@@ -52,12 +94,37 @@ function read_array() {
                $nLines++;
        }
        if (CITADEL_DEBUG_CITPROTO == 1){
-               echo "read ".$nLines." lines from the server.";
-               printf ("</div>");
+               echo "read ".$nLines." lines from the server.\n";
+               printf ("</div>\n");
        }
        return $ret;
 }
 
+function read_binary() {
+       $nLines = 0;
+       if (CITADEL_DEBUG_CITPROTO == 1)
+           printf ("<div class='ctdldbgRead'>\n");
+       $buf = serv_gets(TRUE);
+       
+       if (CITADEL_DEBUG_CITPROTO == 1){
+               echo "status line from the server\n";
+       }
+
+       $statusline = explode(" ", $buf);
+       
+       if ($statusline[0] == 600)
+       {
+               $buf = serv_get_n($statusline[1]);
+               
+       }
+       
+       if (CITADEL_DEBUG_CITPROTO == 1){
+               echo "read ".$statusline[1]." bytes from the server.\n";
+               printf ("</div>\n");
+       }
+       return array($statusline, $buf);
+}
+
 
 
 // 
@@ -310,6 +377,19 @@ function ctdl_get_serv_info() {
 
 }
 
+//
+// Learn all sorts of interesting things about the Citadel server to
+// which we are connected.
+/* http://www.citadel.org/doku.php/documentation:appproto:connection#info.get.server.info */
+//
+function ctdl_get_registration_info() {
+       serv_puts("GREG");
+       $reply = read_array();
+       print_r($reply);
+//             die ("didn't understand the reply to the INFO command");
+
+}
+
 
 //
 // Display a system banner.  (Returns completed HTML.)
@@ -464,12 +544,11 @@ function ctdl_knrooms() {
        global $clientsocket;
 
        serv_puts("LKRA");
-       $results = read_array();
-
-       if (substr($results[0], 0, 1) != "1") {
+       $response = serv_gets();
+       if (substr($response, 0, 1) != "1") {
                return array(0, NULL);
        }
-       array_shift($results);
+       $results = read_array();
        $all_lines = array();
        $num_lines = 0;
 
@@ -505,6 +584,46 @@ function ctdl_knrooms() {
 
 }
 
+//
+// Fetch the list of known floors.
+//
+/* http://www.citadel.org/doku.php/documentation:appproto:rooms#lflr.list.all.known.floors */
+function ctdl_knfloors() {
+       global $clientsocket;
+
+       serv_puts("LFLR");
+       $response = serv_gets();
+       if (substr($response, 0, 1) != "1") {
+               return array(0, NULL);
+       }
+
+       $results = read_array();
+       $all_lines = array();
+       $num_lines = 0;
+
+       foreach ($results as $result){
+               $oneline = array();
+               $tokens = explode("|",$result);
+
+               $oneline["id"] = $tokens[0];            
+               $oneline["name"]   = $tokens[1];                
+               $oneline["nref"] = $tokens[2];
+
+               if (CITADEL_DEBUG_CITPROTO == 1)
+               {
+                       echo "<pre>";
+                       print_r($oneline);
+                       echo "</pre>";
+
+               }
+               $num_lines = array_push($all_lines, $oneline);
+       }
+
+       return array($num_lines, $all_lines);
+
+}
+
+/* http://www.citadel.org/doku.php/documentation:appproto:rooms#cflr.create.a.new.floor */
 
 //
 // Fetch the list of messages in one room.
@@ -611,4 +730,18 @@ function ctdl_msg4_from_server() {
 }
 
 
+
+function downoad_attachment($msgnum, $attindex)
+{
+       $command = "DLAT ".$msgnum."|".$attindex;
+       serv_puts($command);
+       $reply = read_binary();
+
+       print_r($reply);
+       return $reply;
+
+}
+
+
+
 ?>
index db56974ef3c398f9ea94674744104cc2554efe07..9dbf0ec22aa6736ed4d138aca88f08f190b34850 100644 (file)
@@ -71,14 +71,14 @@ function establish_citadel_session() {
 
                ctdl_iden($identity);   // Identify client
                ctdl_MessageFormatsPrefered(array("text/html","text/plain"));
-               if ($_SESSION["username"]) {
+               if (isset($_SESSION["username"])) {
                        login_existing_user(
                                $_SESSION["username"],
                                $_SESSION["password"]
                        );
                }
 
-               if ($_SESSION["room"]) {
+               if (isset($_SESSION["room"])) {
                        ctdl_goto($_SESSION["room"]);
                }
                else {
index cc15c791e8def7b0fb577ee205a65e6a4b438883..97c87d9f80f2d935224bb482ae07f2cc4cc5c033 100644 (file)
@@ -32,7 +32,7 @@ if ($retval == FALSE) {
 else {
        echo "<A HREF=\"welcome.php\">Logged in.  ";
        echo "Click to continue if your browser does not refresh.</a><BR>";
-       echo "<meta http-equiv=\"refresh\" content=\"0;url=welcome.php\">\n";
+       echo "<meta http-equiv=\"refresh\" content=\"15;url=welcome.php\">\n";
 }
 
 bbs_page_footer();
diff --git a/ctdlphp/myinfo.php b/ctdlphp/myinfo.php
new file mode 100644 (file)
index 0000000..a473318
--- /dev/null
@@ -0,0 +1,58 @@
+<?PHP
+
+       include "ctdlheader.php";
+       bbs_page_header();
+
+       echo    "This is an example of the use of " .
+               "ctdl_get_registration_info() to display " .
+               "your personal data.<BR><BR>\n" ;
+
+       echo    "<TABLE border=1>" .
+               "<TR>" .
+               "<TD><B>User</B></TD>" .
+               "<TD><B>Room</B></TD>" .
+               "<TD><B>Host</B></TD>" .
+               "</TR>" ;
+
+        ctdl_goto("My Citadel Config");
+       list($num_msgs, $response, $msgs) = ctdl_msgs($_REQUEST["mode"],
+                                                       $_REQUEST["count"] );
+
+       echo "num_msgs: " . $num_msgs . "<BR>\n" ;
+       echo "response: " . htmlspecialchars($response) . "<BR>\n" ;
+
+        if ($num_msgs > 0) foreach ($msgs as $msgnum) {
+               print_r($msgnum);
+               $result = get_message_partlist($msgnum);
+               if (is_array($result) &&
+                   ($result[4]=="text/vcard"))
+               {
+                       $vcard = downoad_attachment($msgnum, $result[2]);
+
+
+               }
+       }
+
+///phpinfo();
+///    list($num_users, $wholist) =
+// ctdl_get_registration_info();
+/*
+       if ($num_users > 0) foreach ($wholist as $x) {
+               echo "<TR>";
+               echo "<TD>", htmlspecialchars($x["user"]), "</TD>";
+               echo "<TD>", htmlspecialchars($x["room"]), "</TD>";
+               echo "<TD>", htmlspecialchars($x["host"]), "</TD>";
+               echo "</TR>\n";
+       }
+*/
+       echo "</TABLE>\n";
+
+?>
+
+<BR>Sample links<BR>
+<a href="welcome.php">Page One</a><BR>
+<a href="page3.php">Page Three</a><BR>
+
+<?PHP
+       bbs_page_footer();
+?>
index 90e7ca3e380600b5f7599a284536b72520b99e58..59b84c0f8af081449858c6ac808f8b1a4f9d3754 100755 (executable)
@@ -17,6 +17,7 @@ include "config_ctdlclient.php";
 
 // sock_gets() -- reads one line of text from a socket
 // 
+$logfd = 
 function sock_gets($sock) {
        socket_clear_error($msgsock);
        $buf = socket_read($sock, 4096, PHP_NORMAL_READ);
index 027cef121d20608af33c5e70c9a48210f6950b60..73c11ef8299f948c5e25816ba93c3d456c43386a 100644 (file)
@@ -107,6 +107,37 @@ body>#Menu {width:8em;}
        text-indent: 0;
 }
 
+#demolinks {
+       position:absolute;
+       top:200px;
+       left:20px;
+       width:8em;
+       padding:0.5em;
+       background-color:#eee;
+       border:1px dashed #999;
+/* Again, the ugly brilliant hack. */
+       voice-family: "\"}\"";
+       voice-family:inherit;
+       width:8em;
+       }
+/* Again, "be nice to Opera 5". */
+body>#demolinks {width:8em;}
+
+/* For convenience */
+.centered {
+       text-align: center;
+       margin-left: auto;
+       margin-right: auto;
+       }
+
+.notebox {
+       background-color:#eee;
+       border:1px dashed #999;
+       margin: 15px;
+       font-size:small;
+       text-indent: 0;
+}
+
 .ctdldbgRead {
         color:#ff0000;
        background-color:#eee;