Changeset 1253
- Timestamp:
- 11/15/06 01:21:26 (2 years ago)
- Files:
-
- brains/.htaccess (modified) (1 diff)
- brains/TODO.txt (modified) (1 diff)
- brains/blapi.php (modified) (1 diff)
- brains/index.php (modified) (2 diffs)
- brains/login.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
brains/.htaccess
r1216 r1253 2 2 php_flag register_globals on 3 3 4 # OS X doesnt like this 4 5 RewriteEngine on 5 RewriteBase / 6 7 #RewriteBase / 6 8 7 9 # clean url mappings 10 11 RewriteRule ^foo /ok.html 8 12 9 13 RewriteRule ^lists/([a-z0-9_-]+)/([0-9]+)$ /index.php?op=view&id=$2 [L] brains/TODO.txt
r1222 r1253 1 2 talk to lawrence re: graphics!! 3 1 4 finish authentication 2 5 edit items - http://blablalist.com/editlist?authid=XXXXX&submission=edit&id=LIST_ID&&entryENTRY_ID=Yo+mother brains/blapi.php
r1214 r1253 1 1 <% 2 class Blapi {2 class Blapi { 3 3 4 # FINISH UP HERE: make this look at the authid in the user object and try to authenticate that and do a get-list. parse the responsefor a failure;4 # FINISH UP HERE: make this look at the authid in the user object and try to authenticate that and do a get-list. parse the responsefor a failure; 5 5 6 function authorized() { 7 $response = $this->xform( "transforms/authenticate.xsl", $this->pack( "login", "" )); 8 $response = $response[0]; 9 if( $response != "INVALID:credentials" ) 10 return true; 11 else 12 return false; 13 } 6 function yes() { 7 $bla = new Blapi(); 8 $authid = $_COOKIE["auth_id"]; 9 $u = $_COOKIE["uid"]; 10 echo "$u / $authid<br>"; 11 $bla->init( $u, $p, $authid ); 12 $ok = $bla->authorized(); 13 if( $ok ) 14 echo "we are authorized with the token"; 15 else 16 echo "we are NOT authorized with the token"; 17 } 14 18 15 # inside out this 16 function dump_lists( $a, $func ) { 17 $html = "<ul>"; 18 foreach ($a as $line) { 19 $toks = preg_split("/\t/", $line ); 20 $list_id = $toks[0]; 21 $name = $toks[1]; 22 $num = $toks[2]; 23 $sharing = $toks[3]; 24 $item = "<a href='/lists/$this->user/$list_id'>$name</a> <small>(" . ($num ? "$num items" : "empty") . ") [<a href='/delete/$list_id'>X</a>]"; 25 $item = "$item <a href='/lists/$this->user/$list_id/javascript'>Javascript</a>"; 26 $item = "$item <a href='/lists/$this->user/$list_id/json'>JSON</a></small>"; 27 if( !$num ) 28 $item = "<s>$item</s>"; 29 if( $sharing == "true" ) 30 $item = "<b>$item</b> (shared as <a href='/lists/$this->user/public/$list_id'>/lists/$this->user/public/$list_id</a>)"; 31 $html .= "<li>$item</li>"; 32 } 33 $html .= "</ul>"; 34 return $html; 35 } 19 function authorized() { 20 $response = $this->xform( "transforms/authenticate.xsl", $this->pack( "login", "" )); 21 $response = $response[0]; 22 if( $response != "INVALID:credentials" ) 23 return true; 24 else 25 return false; 26 } 36 27 37 function dump_items( $a, $func ) { 38 $line = array_shift( $a ); 39 $toks = preg_split("/\t/", $line ); 40 $list_id = $toks[0]; 41 $name = $toks[1]; 42 $sharing = $toks[2]; 43 $html = "$name " . ($sharing == "true" ? "(public) <a href='/share/private/$list_id'>stop sharing this list?</a>" : "<a href='/share/public/$list_id'>share this list?</a>") . "</h2>"; 28 # inside out this 29 function dump_lists( $a, $func ) { 30 $html = "<ul>"; 31 foreach ($a as $line) { 32 $toks = preg_split("/\t/", $line ); 33 $list_id = $toks[0]; 34 $name = $toks[1]; 35 $num = $toks[2]; 36 $sharing = $toks[3]; 37 $item = "<a href='/lists/$this->user/$list_id'>$name</a> <small>(" . ($num ? "$num items" : "empty") . ") [<a href='/delete/$list_id'>X</a>]"; 38 $item = "$item <a href='/lists/$this->user/$list_id/javascript'>Javascript</a>"; 39 $item = "$item <a href='/lists/$this->user/$list_id/json'>JSON</a></small>"; 40 if( !$num ) 41 $item = "<s>$item</s>"; 42 if( $sharing == "true" ) 43 $item = "<b>$item</b> (shared as <a href='/lists/$this->user/public/$list_id'>/lists/$this->user/public/$list_id</a>)"; 44 $html .= "<li>$item</li>"; 45 } 46 $html .= "</ul>"; 47 return $html; 48 } 44 49 45 $html .= "<ul>"; 46 foreach ($a as $line) { 47 $toks = preg_split("/\t/", $line ); 48 $id = $toks[0]; 49 $name = $toks[1]; 50 $done = $toks[2]; 51 $item = "$name"; 52 if( $done && $done != "false" ) 53 $item = "<s>$item</s>"; 54 $item = "$item (<a href='/$list_id/toggle/" . ($done == "false" ? "done" : "undone") . "/$id'>" . ($done == "false" ? "Done!" : "re-open") . "</a>) "; 55 $item = "$item <small> [<a href='/$list_id/delete/$id'>x</a>]</small>"; 56 $html .= "<li>$item</li>"; 57 } 58 $html .= "</ul>"; 59 return $html; 50 function dump_items( $a, $func ) { 51 $line = array_shift( $a ); 52 $toks = preg_split("/\t/", $line ); 53 $list_id = $toks[0]; 54 $name = $toks[1]; 55 $sharing = $toks[2]; 56 $html = "$name " . ($sharing == "true" ? "(public) <a href='/share/private/$list_id'>stop sharing this list?</a>" : "<a href='/share/public/$list_id'>share this list?</a>") . "</h2>"; 60 57 61 } 58 $html .= "<ul>"; 59 foreach ($a as $line) { 60 $toks = preg_split("/\t/", $line ); 61 $id = $toks[0]; 62 $name = $toks[1]; 63 $done = $toks[2]; 64 $item = "$name"; 65 if( $done && $done != "false" ) 66 $item = "<s>$item</s>"; 67 $item = "$item (<a href='/$list_id/toggle/" . ($done == "false" ? "done" : "undone") . "/$id'>" . ($done == "false" ? "Done!" : "re-open") . "</a>) "; 68 $item = "$item <small> [<a href='/$list_id/delete/$id'>x</a>]</small>"; 69 $html .= "<li>$item</li>"; 70 } 71 $html .= "</ul>"; 72 return $html; 62 73 63 function init( $u, $p, $authid ) { 64 $this->user = $u; 65 $this->password = $p; 66 $this->authid = $authid; 67 $this->parser = "/usr/bin/xsltproc"; 68 $this->domain = "http://blablalist.com"; 69 } 74 } 70 75 71 function createlist( $list_name ) { 72 return $this->call( "createlist", "submission=create&name=" . urlencode( $list_name ) ); 73 } 76 function init( $u, $p, $authid ) { 77 $this->user = $u; 78 $this->password = $p; 79 $this->authid = $authid; 80 $this->parser = "/usr/bin/xsltproc"; 81 $this->domain = "http://blablalist.com"; 82 } 74 83 75 function toggleentry( $id, $done ) {76 return $this->call( "toggleentry", "submission=toggle&id=" . $id . "&done=$done");77 }84 function createlist( $list_name ) { 85 return $this->call( "createlist", "submission=create&name=" . urlencode( $list_name ) ); 86 } 78 87 79 function addentry( $list_id, $name ) { 80 return $this->call( "addentry", "submission=add&listId=" . $list_id . "&name=" . urlencode( $name )); 81 } 82 83 function deleteentry( $entry_id, $list_id ) { 84 return $this->call( "editlist", "submission=edit&id=" . $list_id . "&remove=" . $entry_id ); 85 } 88 function toggleentry( $id, $done ) { 89 return $this->call( "toggleentry", "submission=toggle&id=" . $id . "&done=$done" ); 90 } 86 91 87 function deletelist( $id ) { 88 return $this->call( "deletelist", "submission=delete&id=" . $id ); 89 } 92 function addentry( $list_id, $name ) { 93 return $this->call( "addentry", "submission=add&listId=" . $list_id . "&name=" . urlencode( $name )); 94 } 95 96 function deleteentry( $entry_id, $list_id ) { 97 return $this->call( "editlist", "submission=edit&id=" . $list_id . "&remove=" . $entry_id ); 98 } 90 99 91 function getlist( $id ) { 92 return $this->dump_items( $this->xform( "transforms/getlist.xsl", $this->pack( "getlist", "&id=" . $id ))); 93 } 94 95 # FIXME: implement this: 96 function getlist_as_javascript( $id ) { 97 return "function render_list() { alert( 'Not yet implemented.' ) };\nrender_list(); "; 98 } 100 function deletelist( $id ) { 101 return $this->call( "deletelist", "submission=delete&id=" . $id ); 102 } 99 103 100 function getlist_as_json( $id ) { 101 $a = $this->xform( "transforms/getlist.xsl", $this->pack( "getlist", "&id=" . $id )); 102 $header = array_shift( $a ); 103 $toks = preg_split("/\t/", $header ); 104 $list_id = $toks[0]; 105 $list_name = $toks[1]; 106 $sharing = $toks[2]; 107 if( $sharing != "true" ) 108 return '{"error": "list not public"}' . $sharing; 109 $j = "{ \"list_id\": $list_id, \"list_name\": \"$list_name\", \"items\": [ "; 104 function getlist( $id ) { 105 return $this->dump_items( $this->xform( "transforms/getlist.xsl", $this->pack( "getlist", "&id=" . $id ))); 106 } 107 108 # FIXME: implement this: 109 function getlist_as_javascript( $id ) { 110 return "function render_list() { alert( 'Not yet implemented.' ) };\nrender_list(); "; 111 } 110 112 111 $c = 0; 112 foreach ($a as $line) { 113 $toks = preg_split("/\t/", $line ); 114 $entry_id = $toks[0]; 115 $name = $toks[1]; 116 $done = $toks[2]; 117 $item = "$name"; 113 function getlist_as_json( $id ) { 114 $a = $this->xform( "transforms/getlist.xsl", $this->pack( "getlist", "&id=" . $id )); 115 $header = array_shift( $a ); 116 $toks = preg_split("/\t/", $header ); 117 $list_id = $toks[0]; 118 $list_name = $toks[1]; 119 $sharing = $toks[2]; 120 if( $sharing != "true" ) 121 return '{"error": "list not public"}' . $sharing; 122 $j = "{ \"list_id\": $list_id, \"list_name\": \"$list_name\", \"items\": [ "; 118 123 119 $j = $j . "[\"id\":$entry_id, \"name\":\"$name\", \"done\":$done]" . ($c++ != count( $a ) - 1 ? "," : "") ; 120 } 124 $c = 0; 125 foreach ($a as $line) { 126 $toks = preg_split("/\t/", $line ); 127 $entry_id = $toks[0]; 128 $name = $toks[1]; 129 $done = $toks[2]; 130 $item = "$name"; 121 131 122 $j = $j . "] }"; 123 return $j; 124 } 132 $j = $j . "[\"id\":$entry_id, \"name\":\"$name\", \"done\":$done]" . ($c++ != count( $a ) - 1 ? "," : "") ; 133 } 125 134 126 function publicsharing( $id, $share, $name ) { 127 return $this->call( "publicsharing", "submission=setupPublicSharing&id=" . $id . "&shortName=" . $name . "&publicList=" . $share );128 }135 $j = $j . "] }"; 136 return $j; 137 } 129 138 130 function pack( $operation, $args ) { 131 $uri = "$operation?submission=credentials&login=" . $this->user . "&password=" . $this->password . "&$args"; ; 132 return $this->domain . "/" . $uri; 133 } 139 function publicsharing( $id, $share, $name ) { 140 return $this->call( "publicsharing", "submission=setupPublicSharing&id=" . $id . "&shortName=" . $name . "&publicList=" . $share ); 141 } 134 142 135 function fetchlists() { 136 return $this->dump_lists( $this->xform( "transforms/fetchlists.xsl", $this->pack( "fetchlists", "" ))); 137 } 143 function pack( $operation, $args ) { 144 $uri = "$operation?submission=credentials&login=" . $this->user . "&password=" . $this->password . "&$args"; ; 145 return $this->domain . "/" . $uri; 146 } 138 147 139 function call( $operation, $args) {140 return implode("", file( $this->pack( $operation, $args )));141 }148 function fetchlists() { 149 return $this->dump_lists( $this->xform( "transforms/fetchlists.xsl", $this->pack( "fetchlists", "" )), ""); 150 } 142 151 143 function dump( $s ) {144 return "<code>" . htmlentities( $s ) . "</code><p />";145 }152 function call( $operation, $args ) { 153 return implode("", file( $this->pack( $operation, $args ))); 154 } 146 155 147 function xform( $xsl, $xml) {148 $lines = array();149 $cmd = $this->parser . " $xsl \"$xml\""; 156 function dump( $s ) { 157 return "<code>" . htmlentities( $s ) . "</code><p />"; 158 } 150 159 151 $debug = 0; 152 if( $debug ) 153 echo "<br>$cmd<br>"; 154 exec( "$cmd", $lines ); 155 if( $debug ) { 156 echo "\$cmd: $cmd<br>"; 157 print "there are " . sizeof( $lines ) . " lines"; 158 print_r( $lines ); 159 foreach ($lines as $line) { echo "$line<br>"; } 160 } 161 return $lines; 162 } 163 } 160 function xform( $xsl, $xml ) { 161 $lines = array(); 162 $cmd = $this->parser . " $xsl \"$xml\""; 163 164 $debug = 0; 165 if( $debug ) 166 echo "<br>$cmd<br>"; 167 exec( "$cmd", $lines ); 168 if( $debug ) { 169 echo "\$cmd: $cmd<br>"; 170 print "there are " . sizeof( $lines ) . " lines"; 171 print_r( $lines ); 172 foreach ($lines as $line) { echo "$line<br>"; } 173 } 174 return $lines; 175 } 176 } 164 177 %> 165 brains/index.php
r1218 r1253 1 1 <% 2 include_once( "blapi.php" );3 include_once( "util.php" ); # FINISH PAGE FUNCTION HERE2 include_once( "blapi.php" ); 3 include_once( "util.php" ); # FINISH PAGE FUNCTION HERE 4 4 5 function h2( $s ) {6 return "<h2>$s</h2>";7 }5 function h2( $s ) { 6 return "<h2>$s</h2>"; 7 } 8 8 9 # FINISH ME AUTHID WORKING LOGIN WE CAN SHARE IT10 #$authid = $_COOKIE["authid"];11 #$u = $_COOKIE["uid"];12 #echo $u;13 #echo $authid;14 #if( $u && $authid && authorized( $authid ))15 #echo "we are authorized with the token";16 #else17 #echo "we are NOT authorized with the token";18 19 $u = "codeswami";20 $p = chop( implode('', file('pass.txt')));9 # FINISH ME AUTHID WORKING LOGIN WE CAN SHARE IT 10 #$authid = $_COOKIE["authid"]; 11 #$u = $_COOKIE["uid"]; 12 #echo $u; 13 #echo $authid; 14 #if( $u && $authid && authorized( $authid )) 15 #echo "we are authorized with the token"; 16 #else 17 #echo "we are NOT authorized with the token"; 18 19 $u = "codeswami"; 20 $p = chop( implode('', file('pass.txt'))); 21 21 22 $bla = new Blapi();23 24 $bla->init( $u, $p);25 $ok = $bla->authorized();26 if( ! $ok ) {22 $bla = new Blapi(); 23 24 $bla->init( $u, $p, $_COOKIE["authid"] ); 25 $ok = $bla->authorized(); 26 if( ! $ok ) { 27 27 %> 28 28 <meta http-equiv="refresh" content="0; URL=/login?message=Invalid+username+or+password" /> 29 29 <% 30 return;31 exit;32 }30 return; 31 exit; 32 } 33 33 34 $op = $op ? $op : "index";35 $forward = true;36 $show_html = true;34 $op = $op ? $op : "index"; 35 $forward = true; 36 $show_html = true; 37 37 38 if( $op == "index" ) {39 $payload = h2( "your lists" ) . $bla->fetchlists();40 $forward = false;41 } else if( $op == "view" ) {42 $payload = "<h2>" . $bla->getlist( $id ); # UGH unbalanced tags, fix this?43 $payload .= " <form name='addentry' action='/$id/add' method='post'><label>add new entry: <input name='entry' /></label></form>";44 $forward = false;45 } else if( $op == "create" ) {46 $payload = h2( "creating list $list_name" ) . $bla->dump( $bla->createlist( $list_name ));47 } else if( $op == "delete" ) {48 $payload = h2( "deleting list $list_name" ) . $bla->dump( $bla->deletelist( $list_id ));49 } else if( $op == "toggle" ) {50 $payload = h2( "toggling list item $id" ) . $bla->dump( $bla->toggleentry( $id, $done ));51 } else if( $op == "addentry" ) {52 $payload = h2( "adding new list item to $list_name" ) . $bla->dump( $bla->addentry( $list_id, $entry ));53 } else if( $op == "share" ) {54 $payload = h2( "sharing $list_name" ) . $bla->dump( $bla->publicsharing( $list_id, $share, $name ));55 } else if( $op == "deleteentry" ) {56 $payload = h2( "deleting $entry_id from $list_id" ) . $bla->dump( $bla->deleteentry( $entry_id, $list_id ));57 } else if( $op == "json" ) {58 $forward = $show_html = false;59 Header( "Content-type: text/plain");60 echo $bla->getlist_as_json( $list_id );61 } else if( $op == "javascript" ) {62 $forward = $show_html = false;63 Header( "Content-type: text/plain");64 echo $bla->getlist_as_javascript( $list_id );65 }38 if( $op == "index" ) { 39 $payload = h2( "your lists" ) . $bla->fetchlists(); 40 $forward = false; 41 } else if( $op == "view" ) { 42 $payload = "<h2>" . $bla->getlist( $id ); # UGH unbalanced tags, fix this? 43 $payload .= " <form name='addentry' action='/$id/add' method='post'><label>add new entry: <input name='entry' /></label></form>"; 44 $forward = false; 45 } else if( $op == "create" ) { 46 $payload = h2( "creating list $list_name" ) . $bla->dump( $bla->createlist( $list_name )); 47 } else if( $op == "delete" ) { 48 $payload = h2( "deleting list $list_name" ) . $bla->dump( $bla->deletelist( $list_id )); 49 } else if( $op == "toggle" ) { 50 $payload = h2( "toggling list item $id" ) . $bla->dump( $bla->toggleentry( $id, $done )); 51 } else if( $op == "addentry" ) { 52 $payload = h2( "adding new list item to $list_name" ) . $bla->dump( $bla->addentry( $list_id, $entry )); 53 } else if( $op == "share" ) { 54 $payload = h2( "sharing $list_name" ) . $bla->dump( $bla->publicsharing( $list_id, $share, $name )); 55 } else if( $op == "deleteentry" ) { 56 $payload = h2( "deleting $entry_id from $list_id" ) . $bla->dump( $bla->deleteentry( $entry_id, $list_id )); 57 } else if( $op == "json" ) { 58 $forward = $show_html = false; 59 Header( "Content-type: text/plain"); 60 echo $bla->getlist_as_json( $list_id ); 61 } else if( $op == "javascript" ) { 62 $forward = $show_html = false; 63 Header( "Content-type: text/plain"); 64 echo $bla->getlist_as_javascript( $list_id ); 65 } 66 66 67 if( $forward ) {68 $url = ($list_id && $op != "delete") ? "/lists/$u/$list_id" : "/";67 if( $forward ) { 68 $url = ($list_id && $op != "delete") ? "/lists/$u/$list_id" : "/"; 69 69 %> 70 70 … … 72 72 73 73 <% 74 } else {75 if( $show_html ) {74 } else { 75 if( $show_html ) { 76 76 %> 77 77 <html> 78 <head>79 <title>80 brains.jm3.net81 </title>78 <head> 79 <title> 80 brains.jm3.net 81 </title> 82 82 83 <script type="text/javascript" src="/brains.js"></script>84 <link rel="stylesheet" type="text/css" href="/stylesheet.css">83 <script type="text/javascript" src="/brains.js"></script> 84 <link rel="stylesheet" type="text/css" href="/stylesheet.css"> 85 85 86 </head>86 </head> 87 87 88 <body onLoad="focus_page();">88 <body onLoad="focus_page();"> 89 89 90 <h1><a href="/">BRAINS</a></h1>90 <h1><a href="/">BRAINS</a></h1> 91 91 92 <p><a href="/logout">log out</a></p>92 <p><a href="/logout">log out</a></p> 93 93 94 <%= $payload %>94 <%= $payload %> 95 95 96 <hr />96 <hr /> 97 97 98 <form name="create" action="/create" method="post">99 <label>100 Create new list:101 <input type="text" name="list_name" value="">102 </label>103 </form>98 <form name="create" action="/create" method="post"> 99 <label> 100 Create new list: 101 <input type="text" name="list_name" value=""> 102 </label> 103 </form> 104 104 105 </body>105 </body> 106 106 </html> 107 107 <% 108 }109 }108 } 109 } 110 110 %> brains/login.php
r1210 r1253 1 1 <% 2 include_once( "blapi.php" );2 include_once( "blapi.php" ); 3 3 4 if( $op == "logout" ) { 4 if( $op == "logout" ) { 5 echo "deleting the cookies"; 5 6 6 # delete the cookie and fwd to /login 7 8 } else if( $user && $password ) { 9 10 # set cookie and fwd to index 11 #http://blablalist.com/login?submission=credentials&login=johnsmith&password=password 12 } 7 # delete the cookie and fwd to /login 8 9 } else if( $user && $password ) { 13 10 14 $show_html = true; 11 # verify the authorized call: 15 12 16 if( $show_html ) { 13 setCookie( 'uid', $user, time()+60*60*24*69, '/' ); 14 setCookie( 'auth_id', md5( $password ), time()+60*60*24*69, '/' ); 15 16 echo "SUCCESS! you are logged in!"; 17 %> 18 <meta http-equiv="refresh" content="0; URL=/" /> 19 <% 20 21 22 # set cookie and fwd to index 23 #http://blablalist.com/login?submission=credentials&login=johnsmith&password=password 24 } 25 26 27 $show_html = true; 28 29 if( $show_html ) { 17 30 %> 18 31 … … 23 36 24 37 <form name="login" action="/login" method="post"> 25 <label>26 Username27 <input name="user" value="<%= $user %>" />28 </label>29 <br />30 <label>31 Password32 <input type="password" name="password" />33 </label>34 <input type="submit" value="Log in" />38 <label> 39 Username 40 <input name="user" value="<%= $user %>" /> 41 </label> 42 <br /> 43 <label> 44 Password 45 <input type="password" name="password" /> 46 </label> 47 <input type="submit" value="Log in" /> 35 48 </form> 36 49