Source of “pachymgmt.php”.
110 lines, 3.3 KBytes.   Last modified 2:46 pm, 9th June 2007 PDT.
1 <?php // Emacs settings: -*- mode: Fundamental; tab-width: 4; -*- 2 3 //////////////////////////////////////////////////////////////////////////// 4 // // 5 // Pachylet: Andrew's Web Mail Interface // 6 // // 7 // Copyright (c) 2002-2004 // 8 // // 9 // See http://birrell.org/pachylet/help.php // 10 // // 11 // User management UI (HTML) // 12 // // 13 //////////////////////////////////////////////////////////////////////////// 14 15 16 function showUsers(&$state) { 17 // Put form for creating, modifying, or deleting users 18 docStart($state); 19 ?> 20 <table class=bb cellspacing=3><tr> 21 <td width="88%" nowrap><b>Pachylet Account Management</b></td> 22 <?php button($state, "logout", "Logout", true) ?> 23 </tr></table> 24 <div class=sep></div> 25 <?php formStart($state, "GET", "manageCreateDelete", false) ?> 26 <tr> 27 <td width="44%" align=right nowrap> 28 User name: 29 </td><td width="44%" nowrap> 30 <input type=text name=dest size=40> 31 &nbsp; 32 <input type=submit value=" Create "> 33 </td> 34 <td width="11%">&nbsp;</td> 35 </tr> 36 <?php 37 $users = enumUsers(); 38 foreach ($users as $user) { 39 echo "\n\n<!-- User $user -->\n"; 40 ?> 41 <tr><td width="44%" align=right nowrap> 42 <a href="<?php 43 echo selfUrl($state, "options&dest=" . urlencode($user)) ?>"> 44 <?php echo $user; ?> 45 </a>&nbsp;&nbsp;&nbsp; 46 </td><td width="44%"> 47 <input type=submit name=victim value="Delete <?php echo $user; ?>"> 48 </td></tr><?php 49 } 50 formEnd(); 51 } 52 53 function doQueryList($file, $user, $pwd) { 54 // Execute a list of queries from a file, substituting in $user 55 $list = getFile($file, filesize($file)); 56 $list = preg_replace('#/USER/#', $user, $list); 57 $list = preg_replace('#/PASSWORD/#', $pwd, $list); 58 $queries = explode(";", $list); 59 foreach ($queries as $query) { 60 $rc = doSqlQuery("doQueryList $file for $user", $query); 61 } 62 } 63 64 if (isset($cancel)) { 65 $state->op = 66 ($state->op=="manageCreateDelete" ? "show" : "manageUsers"); 67 putRedirect($state); 68 } else if ($state->op == "manageUsers") { 69 $state->managing = true; 70 $state->managingUser = ""; 71 showUsers($state); 72 } else if ($state->op == "manageCreateDelete") { 73 if (isset($args["victim"])) { 74 $victim = preg_replace('#^Delete #', "", $args["victim"]); 75 putConfirmForm($state, "manageDelete", 76 "Really delete all messages for user \"$victim\"? " . 77 "(This cannot be undone)", $victim); 78 } else { 79 if (strpos($dest, ".") != false) die("illegal account name"); 80 // The access control check is implicit in doQueryList 81 doQueryList("create.txt", $dest, $PHP_AUTH_PW); 82 $parts = C_partsDir . "/$dest"; 83 if (!file_exists($parts)) mkdir($parts, 0700); 84 $state->op = "options&dest=$dest"; 85 putRedirect($state); 86 } 87 } else if ($state->op == "manageDelete") { 88 if ($dest == "") die("empty deletion victim"); 89 if (strpos($dest, ".") !== false) die("illegal deletion victim"); 90 // The access control check is implicit in doQueryList 91 doQueryList("delete.txt", $dest, ""); 92 $parts = C_partsDir . "/$dest"; 93 if (file_exists($parts)) { 94 $partsDir = opendir($parts); 95 while ($entry = readdir($partsDir)) { 96 if ($entry != "." and $entry != "..") { 97 unlink("$parts/$entry"); 98 } 99 } 100 closedir($partsDir); 101 rmdir($parts); 102 } 103 $state->op = "manageUsers"; 104 putRedirect($state); 105 } else { 106 reportError($state, "Unknown management op=$state->op", false); 107 } 108 docEnd(); 109 110 ?>
End of listing