cvs: pearweb /include pear-auth.php pear-database.php pear-format-html.php site.php /public_html account-request.php admin.php index.php login.php
xmlrpc.php /sql notes.sql
| From: | Stig Bakken | Date: | Wed, 01 Aug 2001 14:34:27 +0000 |
| Subject: | cvs: pearweb /include pear-auth.php pear-database.php pear-format-html.php site.php /public_html account-request.php admin.php index.php login.php xmlrpc.php /sql notes.sql |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-400@lists.php.net to get a copy of this message | ||
ssb Wed Aug 1 10:34:27 2001 EDT
Added files:
/pearweb/public_html admin.php
Modified files:
/pearweb/include pear-auth.php pear-database.php
pear-format-html.php site.php
/pearweb/public_html account-request.php index.php login.php
xmlrpc.php
/pearweb/sql notes.sql
Log:
* PEAR account request stuff done
Index: pearweb/include/pear-auth.php diff -u pearweb/include/pear-auth.php:1.5 pearweb/include/pear-auth.php:1.6 --- pearweb/include/pear-auth.php:1.5 Sat Jul 28 22:23:54 2001 +++ pearweb/include/pear-auth.php Wed Aug 1 10:34:25 2001 @@ -16,13 +16,14 @@ exit; } -function auth_require($level = 0, $doexit = true) +function auth_require($admin = false) { - global $PHP_AUTH_USER, $PHP_AUTH_PW, $dbh, $auth_user; + global $PHP_AUTH_USER, $PHP_AUTH_PW, $dbh; + global $auth_user; - $user = strtolower($PHP_AUTH_USER); - $auth_user =& new PEAR_User(&$dbh, $user); - if (md5($PHP_AUTH_PW) != $auth_user->password || !$auth_user->registered) { + $user = $PHP_AUTH_USER; + $auth_user =& new PEAR_User($dbh, $user); + if (md5($PHP_AUTH_PW) != @$auth_user->password || !$auth_user->registered) { if (cvs_verify_password($user, $PHP_AUTH_PW)) { $auth_user = (object)array('handle' => $user); } else { @@ -30,6 +31,12 @@ } } $auth_user->_readonly = true; + if ($admin && empty($auth_user->admin)) { + response_header("Insufficient Privileges"); + report_error("Insufficient Privileges"); + response_footer(); + exit; + } } $cvspasswd_file = "/repository/CVSROOT/passwd"; @@ -38,9 +45,8 @@ { global $cvspasswd_file; $fp = fopen($cvspasswd_file,"r"); - while (!feof($fp)) { - $line = fgets($fp, 120); - list($luser, $passwd, $junk) = explode(":", $line); + while ($line = fgets($fp, 120)) { + list($luser, $passwd, $groups) = explode(":", $line); if ($user == $luser) { fclose($fp); return $passwd; Index: pearweb/include/pear-database.php diff -u pearweb/include/pear-database.php:1.6 pearweb/include/pear-database.php:1.7 --- pearweb/include/pear-database.php:1.6 Sat Jul 28 22:25:57 2001 +++ pearweb/include/pear-database.php Wed Aug 1 10:34:25 2001 @@ -1,6 +1,8 @@ <?php -function validate($entity, $field, $value) { +// {{{ validate() + +function validate($entity, $field, $value /* , $oldvalue, $object */) { switch ("$entity/$field") { case "users/handle": if (!preg_match('/^[a-z][a-z0-9]+$/i', $value)) { @@ -21,6 +23,10 @@ return true; } +// }}} + +// {{{ visit_node() + /* Some useful "visitation model" tricks: @@ -41,6 +47,10 @@ SELECT * FROM table WHERE left BETWEEN <self.left> AND <self.right> "ORDER BY left" gives tree view +To get all leaf nodes: + + SELECT * FROM table WHERE right-1 = left; + */ function visit_node(&$tree, $node) { static $visitno; @@ -56,6 +66,9 @@ $tree[$node]['rightvisit'] = $visitno++; } +// }}} +// {{{ renumber_visitations() + function renumber_visitations($debug = false) { global $dbh; @@ -99,6 +112,10 @@ return true; } +// }}} + +// {{{ get_recent_releases() + function &get_recent_releases($n = 5) { global $dbh; $sth = $dbh->query("SELECT packages.name, packages.summary, ". @@ -115,6 +132,8 @@ return $recent; } +// }}} +// {{{ release_upload() function release_upload($package, $version, $relnotes, &$tarball, $md5sum) { @@ -172,41 +191,128 @@ } -function invalidHandle($handle) { - if (preg_match('/^[a-z]+-?[a-z]+$/i', $handle)) { - return false; - } - return 'handle must be all letters, optionally with one dash'; +// }}} + +// {{{ add_note() + +function add_note($key, $value, $note) +{ + global $dbh, $PHP_AUTH_USER; + $nby = $PHP_AUTH_USER; + $nid = $dbh->nextId("notes"); + $stmt = $dbh->prepare("INSERT INTO notes (id,$key,nby,ntime,note) ". + "VALUES(?,?,?,?,?)"); + return $dbh->execute($stmt, array($nid, $value, $nby, + gmdate('Y-m-d H:i'), $note)); } -function invalidName($name) { - if (trim($name)) { - return $false; - } - return 'name must not be empty'; +// }}} +// {{{ delete_note() + +function delete_note($id) +{ + global $dbh; + $id = (int)$id; + return $dbh->query("DELETE FROM notes WHERE id = $id"); +} + +// }}} +// {{{ delete_all_notes() + +function delete_all_notes($key, $value) +{ + global $dbh; + return $dbh->query("DELETE FROM notes WHERE $key = ". + $dbh->quote($value)); } -function invalidEmail($email) { - if (preg_match('/[a-z0-9_\.\+%]@[a-z0-9\.]+\.[a-z]+$', $email)) { +// }}} + +// {{{ delete_account() + +function delete_account($uid) +{ + global $dbh; + delete_all_notes("uid", $uid); + $dbh->query('DELETE FROM users WHERE handle = '. + $dbh->quote($uid)); + return ($dbh->affectedRows() > 0); +} + +// }}} +// {{{ reject_account_request() + +function reject_account_request($uid, $reason) +{ + global $PHP_AUTH_USER, $dbh; + list($email) = $dbh->getRow('SELECT email FROM users WHERE handle = ?', + array($uid)); + add_note("uid", $uid, "Account rejected: $reason"); + $msg = "Your PEAR account request was rejected by $PHP_AUTH_USER:\n". + "$reason\n"; + $xhdr = "From: $PHP_AUTH_USER@php.net"; + mail($email, "Your PEAR Account Request", $msg, $xhdr); + return true; +} + +// }}} +// {{{ open_account() + +function open_account($uid) +{ + global $PHP_AUTH_USER, $dbh; + + $user =& new PEAR_User($dbh, $uid); + if (@$user->registered) { return false; } - return 'invalid email address'; + @$arr = unserialize($user->userinfo); + delete_all_notes("uid", $uid); + $user->set('registered', 1); + if (is_array($arr)) { + $user->set('userinfo', $arr[1]); + } + $user->set('created', gmdate('Y-m-d H:i')); + $user->set('createdby', $PHP_AUTH_USER); + $user->store(); + add_note("uid", $uid, "Account opened"); + $msg = "Your PEAR account request has been opened.\n". + "To log in, go to http://pear.php.net/ and click on \"login\" in\n". + "the top-right menu.\n"; + $xhdr = "From: $PHP_AUTH_USER@php.net"; + mail($user->email, "Your PEAR Account Request", $msg, $xhdr); + return true; } -function invalidHomepage($homepage) { - if (preg_match('!http://.+!i', $homepage)) { - return false; +// }}} + +// {{{ mail_pear_admins() + +function mail_pear_admins($subject, $msg, $xhdr = '') +{ + global $dbh; + $admins = $dbh->getCol("SELECT email FROM users WHERE admin = 1"); + if (is_array($admins)) { + $oks = 0; + foreach ($admins as $email) { + $oks += mail($email, "PEAR Account Request", $msg, $xhdr); + } + if ($oks == sizeof($admins)) { + return true; + } } - return 'invalid URL'; + return false; } +// }}} +// {{{ class PEAR_User class PEAR_User extends DB_storage { function PEAR_User(&$dbh, $user) { - $this->DB_storage("users", "handle", &$dbh); + $this->DB_storage("users", "handle", $dbh); // XXX horrible hack until we get temporary error handlers $oldmode = $this->_default_error_mode; $this->_default_error_mode = PEAR_ERROR_RETURN; @@ -219,11 +325,14 @@ } } +// }}} +// {{{ class PEAR_Package + class PEAR_Package extends DB_storage { function PEAR_Package(&$dbh, $package) { - $this->DB_storage("packages", "id", &$dbh); + $this->DB_storage("packages", "id", $dbh); // XXX horrible hack until we get temporary error handlers $oldmode = $this->_default_error_mode; $this->_default_error_mode = PEAR_ERROR_RETURN; @@ -236,11 +345,14 @@ } } +// }}} +// {{{ class PEAR_Release + class PEAR_Release extends DB_storage { function PEAR_Release(&$dbh, $release) { - $this->DB_storage("releases", "id", &$dbh); + $this->DB_storage("releases", "id", $dbh); // XXX horrible hack until we get temporary error handlers $oldmode = $this->_default_error_mode; $this->_default_error_mode = PEAR_ERROR_RETURN; @@ -252,5 +364,7 @@ } } } + +// }}} ?> Index: pearweb/include/pear-format-html.php diff -u pearweb/include/pear-format-html.php:1.5 pearweb/include/pear-format-html.php:1.6 --- pearweb/include/pear-format-html.php:1.5 Sat Jul 28 22:25:57 2001 +++ pearweb/include/pear-format-html.php Wed Aug 1 10:34:25 2001 @@ -75,4 +75,27 @@ exit; } +function border_box_start($title, $width = "90%", $indent = "") +{ + print "$indent<table cellpadding=\"0\" cellspacing=\"1\" border=\"0\" width=\"$width\">\n"; + print "$indent <tr>\n"; + print "$indent <td bgcolor=\"#000000\">\n"; + print " <table cellpadding=\"2\" cellspacing=\"1\" border=\"0\" width=\"100%\">\n"; + print "$indent <tr bgcolor=\"#cccccc\">\n"; + print "$indent <th>$title</th>\n"; + print "$indent </tr>\n"; + print "$indent <tr bgcolor=\"#ffffff\">\n"; + print "$indent <td>\n"; +} + +function border_box_end($indent = "") +{ + print "$indent </td>\n"; + print "$indent </tr>\n"; + print "$indent </table>\n"; + print "$indent </td>\n"; + print "$indent </tr>\n"; + print "$indent</table>\n"; +} + ?> Index: pearweb/include/site.php diff -u pearweb/include/site.php:1.3 pearweb/include/site.php:1.4 --- pearweb/include/site.php:1.3 Thu Jul 5 03:49:49 2001 +++ pearweb/include/site.php Wed Aug 1 10:34:25 2001 @@ -104,6 +104,4 @@ $MIRRORS[$MYSITE] = array('xx', $MYSITE, 'none', $MYSITE, 2, 0, 'en'); } -echo "<!-- $MYSITE -->"; - ?> Index: pearweb/public_html/account-request.php diff -u pearweb/public_html/account-request.php:1.2 pearweb/public_html/account-request.php:1.3 --- pearweb/public_html/account-request.php:1.2 Sun Jul 29 10:47:15 2001 +++ pearweb/public_html/account-request.php Wed Aug 1 10:34:26 2001 @@ -47,7 +47,7 @@ } $handle = strtolower($handle); - $obj = new PEAR_User(&$dbh, $handle); + $obj =& new PEAR_User($dbh, $handle); if (isset($obj->created)) { display_error("Sorry, that username is already taken"); $jumpto = "handle"; @@ -61,43 +61,64 @@ } $display_form = false; - $obj->name = $name; - $obj->email = $email; - $obj->homepage = $homepage; - $obj->showemail = (bool)@$showemail; - $obj->password = md5($password); - $obj->registered = false; - - $admins = $dbh->getCol("SELECT email FROM users WHERE admin = 1"); - $oks = 0; - $msg = "Username: {$obj->handle}\n". - "Email: {$obj->email}". - ($obj->showemail ? " (show address)" : " (hide address)") . "\n". - "Password (MD5): {$obj->password}\n\n". + $md5pw = md5($password); + $showemail = @(bool)$showemail; + // hack to temporarily embed the "purpose" in + // the user's "userinfo" column + $userinfo = serialize(array($purpose, $moreinfo)); + $set_vars = array('name' => $name, + 'email' => $email, + 'homepage' => $homepage, + 'showemail' => $showemail, + 'password' => $md5pw, + 'registered' => 0, + 'userinfo' => $userinfo); + $errors = 0; + foreach ($set_vars as $var => $value) { + $err = $obj->set($var, $value); + if (PEAR::isError($err)) { + print "Failed setting $var: "; + print $err->getMessage(); + print "<BR>\n"; + $errors++; + } + } + if ($errors > 0) { + break; + } + + $msg = "Username: {$handle}\n". + "Real Name: {$name}\n". + "Email: {$email}". + (@$showemail ? " (show address)" : " (hide address)") . "\n". + "Password (MD5): {$md5pw}\n\n". "Purpose:\n". "$purpose\n\n". - "More info:\n". - "$moreinfo\n"; - $xhdr = "From: PEAR Web Site <pear-dev@lists.php.net>"; - foreach ($admins as $email) { - $oks += mail($email, "PEAR Account Request", $msg, $xhdr); - } + "To handle: http://{$SERVER_NAME}/admin.php?acreq={$handle}\n"; + if ($moreinfo) { + $msg .= "\nMore info:\n$moreinfo\n"; + } + $xhdr = "From: $name <$email>"; + $subject = "PEAR Account Request"; + $ok = mail_pear_admins($subject, $msg, $xhdr); response_header("Account Request Submitted"); - if ($oks != sizeof($admins)) { - print "<H2>Possible Problem!</H2>\n"; - print "Your account request has been submitted, but there ". - "was problems mailing one or more administrators. ". - "If you don't hear anything about your account in a few ". - "days, drop a mail about it to the <i>pear-dev</i> mailing ". - "list."; - } else { + if ($ok) { print "<H2>Account Request Submitted</H2>\n"; print "Your account request has been submitted, it will ". - "be reviewed by a human. This may take from two minutes ". - "to several days, depending on how much time people have. ". + "be reviewed by a human shortly. This may take from two ". + "minutes to several days, depending on how much time people ". + "have. ". "You will get an email when your account is open, or if ". "your request was rejected for some reason."; + } else { + print "<H2>Possible Problem!</H2>\n"; + print "Your account request has been submitted, but there ". + "were problems mailing one or more administrators. ". + "If you don't hear anything about your account in a few ". + "days, please drop a mail about it to the <i>pear-dev</i> ". + "mailing list."; } + print "<br />Click the top-left PEAR logo to go back to the front page.\n"; } } while (0); @@ -123,7 +144,7 @@ } $width = 60; - $form = new HTML_Form($PHP_SELF, "POST"); + $form =& new HTML_Form($PHP_SELF, "POST"); $form->addText("handle", "Username", null, 12); $form->addText("name", "Real Name", null, $width); $form->addPassword("password", "Password", null, 10); Index: pearweb/public_html/index.php diff -u pearweb/public_html/index.php:1.15 pearweb/public_html/index.php:1.16 --- pearweb/public_html/index.php:1.15 Sun Jul 29 10:46:44 2001 +++ pearweb/public_html/index.php Wed Aug 1 10:34:26 2001 @@ -15,7 +15,8 @@ menu_link("Documentation", "http://php.net/manual/en/pear.php"); if ($SERVER_NAME != "pear.php.net") { - menu_link("Request a PEAR Account", "account-request.php"); + menu_link("Request PEAR Account", "account-request.php"); + menu_link("Administrators", "admin.php"); menu_link("Browse Packages", "packages.php"); menu_link("Want to contribute?", "signup.php"); menu_link("Upload Release", "release-upload.php"); Index: pearweb/public_html/login.php diff -u pearweb/public_html/login.php:1.3 pearweb/public_html/login.php:1.4 --- pearweb/public_html/login.php:1.3 Thu Jul 5 03:34:43 2001 +++ pearweb/public_html/login.php Wed Aug 1 10:34:26 2001 @@ -6,7 +6,7 @@ <?php /** -auth_require(0); +auth_require(); header("Location: ./"); */ Index: pearweb/public_html/xmlrpc.php diff -u pearweb/public_html/xmlrpc.php:1.4 pearweb/public_html/xmlrpc.php:1.5 --- pearweb/public_html/xmlrpc.php:1.4 Wed May 9 14:30:58 2001 +++ pearweb/public_html/xmlrpc.php Wed Aug 1 10:34:26 2001 @@ -33,7 +33,7 @@ $md5sum = $mmd5sum->scalarval(); // (1) verify that user has access - auth_require(0); + auth_require(); if (isset($_return_value)) return $_return_value; // XXX FIXME check acl table Index: pearweb/sql/notes.sql diff -u pearweb/sql/notes.sql:1.1 pearweb/sql/notes.sql:1.2 --- pearweb/sql/notes.sql:1.1 Sat Jul 28 22:22:59 2001 +++ pearweb/sql/notes.sql Wed Aug 1 10:34:26 2001 @@ -1,7 +1,12 @@ CREATE TABLE notes ( - id INTEGER NOT NULL, - uid VARCHAR(20) REFERENCES users(handle), - pid INTEGER REFERENCES packages(id), + id INTEGER NOT NULL, + uid VARCHAR(20), -- REFERENCES users(handle), + pid INTEGER, -- REFERENCES packages(id), + nby VARCHAR(20) REFERENCES users(handle), + ntime DATETIME, + note TEXT, - PRIMARY KEY(id) + PRIMARY KEY(id), + INDEX(uid), + INDEX(pid) ); Index: pearweb/public_html/admin.php +++ pearweb/public_html/admin.php <?php auth_require(true); $SIDEBAR_DATA=' This is the PEAR administration page. <noscript><p> <!-- be annoying! --> <b><blink>You must enable Javascript to use this page!</blink></b> </p></noscript> '; response_header("PEAR Administration"); //print "GET: ";var_dump($HTTP_GET_VARS);print "<br />\n"; //print "POST: ";var_dump($HTTP_POST_VARS);print "<br />\n"; // {{{ adding and deleting notes if (@$cmd == "Add note" && !empty($note) && !empty($key) && !empty($id)) { add_note($key, $id, $note); unset($cmd); } elseif (@$cmd == "Delete note" && !empty($id)) { delete_note($id); } // }}} // {{{ open account elseif (@$cmd == "Open Account" && !empty($uid)) { // another hack to remove the temporary "purpose" field // from the user's "userinfo" if (open_account($uid)) { print "<p>Opened account $uid...</p>\n"; } } // }}} // {{{ reject account request elseif (@$cmd == "Reject Request" && !empty($uid)) { if (reject_account_request($uid, $reason)) { print "<p>Rejected account request for $uid...</p>\n"; } } // }}} // {{{ delete account request elseif (@$cmd == "Delete Request" && !empty($uid)) { if (delete_account($uid)) { print "<p>Deleted account request for \"$uid\"...</p>"; } } // }}} // {{{ javascript functions ?> <script language="javascript"> <!-- function confirmed_goto(url, message) { if (confirm(message)) { location = url; } } function confirmed_submit(button, action, required, errormsg) { if (required && required.value == '') { alert(errormsg); return; } if (confirm('Are you sure you want to ' + action + '?')) { button.form.cmd.value = button.value; button.form.submit(); } } // --> </script> <?php // }}} do { // {{{ "approve account request" form if (!empty($acreq)) { $requser =& new PEAR_User($dbh, $acreq); if (empty($requser->name)) { break; } list($purpose, $moreinfo) = @unserialize($requser->userinfo); border_box_start("Account request from $requser->name <$requser->email>"); ?> <table cellpadding="2" cellspacing="0" border="0"> <tr> <td>Requested User Name:</td> <td><?= $requser->handle ?></td> </tr> <tr> <td>Real Name:</td> <td><?= $requser->name ?></td> </tr> <tr> <td>Email Address:</td> <td><a href="mailto:<?= $requser->email ?>"><?= $requser->email ?></td> </tr> <tr> <td>MD5-encrypted password:</td> <td><?= $requser->password ?></td> </tr> <tr> <td>Purpose of account:</td> <td valign="top"><?= $purpose ?></td> </tr> <tr> <td>More information:</td> <td><?= $moreinfo ?></td> </tr> </table> <?php border_box_end(); print "<br />\n"; border_box_start("Notes for user $requser->handle"); $notes = $dbh->getAssoc("SELECT id,nby,ntime,note FROM notes ". "WHERE uid = ? ORDER BY ntime", true, array($requser->handle)); $i = " "; if (is_array($notes) && sizeof($notes) > 0) { print "$i<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\">\n"; foreach ($notes as $nid => $data) { list($nby, $ntime, $note) = $data; print "$i <tr>\n"; print "$i <td>\n"; print "$i <b>$nby $ntime:</b>"; if ($nby == $PHP_AUTH_USER) { $url = "$PHP_SELF?acreq=$acreq&cmd=Delete+note&id=$nid"; $msg = "Are you sure you want to delete this note?"; print "[<a href=\"javascript:confirmed_goto('$url', '$msg')\">delete your note</a>]"; } print "<br />\n"; print "$i ".htmlspecialchars($note)."\n"; print "$i </td>\n"; print "$i </tr>\n"; print "$i <tr><td> </td></tr>\n"; } print "$i</table>\n"; } else { print "No notes."; } print "$i<form action=\"$PHP_SELF\" method=\"POST\">\n"; print "$i<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\">\n"; print "$i <tr>\n"; print "$i <td>\n"; print "$i To add a note, enter it here:<br />\n"; print "$i <textarea rows=\"3\" cols=\"55\" name=\"note\"></textarea><br />\n"; print "$i <input type=\"submit\" value=\"Add note\" name=\"cmd\">\n"; print "$i <input type=\"hidden\" name=\"key\" value=\"uid\">\n"; print "$i <input type=\"hidden\" name=\"id\" value=\"$requser->handle\">\n"; print "$i <input type=\"hidden\" name=\"acreq\" value=\"$acreq\">\n"; print "$i </td>\n"; print "$i </tr>\n"; print "$i</table>\n"; print "$i</form>\n"; border_box_end(); ?> <form action="<?= $PHP_SELF ?>" method="POST"> <input type="hidden" name="cmd" value=""> <input type="hidden" name="uid" value="<?= $requser->handle ?>"> <table cellpadding="3" cellspacing="0" border="0" width="90%"> <tr> <td align="center"><input type="button" value="Open Account" onclick="confirmed_submit(this, 'open this account')" /></td> <td align="center"><input type="button" value="Reject Request" onclick="confirmed_submit(this, 'reject this request', this.form.reason, 'You must give a reason for rejecting the request.')" /></td> <td align="center"><input type="button" value="Delete Request" onclick="confirmed_submit(this, 'delete this request')" /></td> </tr> <tr> <td colspan="3"> If dismissing an account request, enter the reason here (will be emailed to <?= $requser->email ?>):<br /> <textarea rows="3" cols="60" name="reason"></textarea> </td> </table> </form> <?php // }}} // {{{ admin menu } else { border_box_start("Account Requests", "30%"); $requests = $dbh->getAssoc("SELECT handle,name,email FROM users ". "WHERE registered = 0"); if (is_array($requests) && sizeof($requests) > 0) { foreach ($requests as $handle => $data) { list($name, $email) = $data; print "<a href=\"$PHP_SELF?acreq=$handle\">$name ($handle)</a><br />\n"; } } else { print "No account requests."; } border_box_end(); } // }}} } while (false); response_footer(); ?>
Index: pearweb/include/pear-auth.php diff -u pearweb/include/pear-auth.php:1.5 pearweb/include/pear-auth.php:1.6 --- pearweb/include/pear-auth.php:1.5 Sat Jul 28 22:23:54 2001 +++ pearweb/include/pear-auth.php Wed Aug 1 10:34:25 2001 @@ -16,13 +16,14 @@ exit; } -function auth_require($level = 0, $doexit = true) +function auth_require($admin = false) { - global $PHP_AUTH_USER, $PHP_AUTH_PW, $dbh, $auth_user; + global $PHP_AUTH_USER, $PHP_AUTH_PW, $dbh; + global $auth_user; - $user = strtolower($PHP_AUTH_USER); - $auth_user =& new PEAR_User(&$dbh, $user); - if (md5($PHP_AUTH_PW) != $auth_user->password || !$auth_user->registered) { + $user = $PHP_AUTH_USER; + $auth_user =& new PEAR_User($dbh, $user); + if (md5($PHP_AUTH_PW) != @$auth_user->password || !$auth_user->registered) { if (cvs_verify_password($user, $PHP_AUTH_PW)) { $auth_user = (object)array('handle' => $user); } else { @@ -30,6 +31,12 @@ } } $auth_user->_readonly = true; + if ($admin && empty($auth_user->admin)) { + response_header("Insufficient Privileges"); + report_error("Insufficient Privileges"); + response_footer(); + exit; + } } $cvspasswd_file = "/repository/CVSROOT/passwd"; @@ -38,9 +45,8 @@ { global $cvspasswd_file; $fp = fopen($cvspasswd_file,"r"); - while (!feof($fp)) { - $line = fgets($fp, 120); - list($luser, $passwd, $junk) = explode(":", $line); + while ($line = fgets($fp, 120)) { + list($luser, $passwd, $groups) = explode(":", $line); if ($user == $luser) { fclose($fp); return $passwd; Index: pearweb/include/pear-database.php diff -u pearweb/include/pear-database.php:1.6 pearweb/include/pear-database.php:1.7 --- pearweb/include/pear-database.php:1.6 Sat Jul 28 22:25:57 2001 +++ pearweb/include/pear-database.php Wed Aug 1 10:34:25 2001 @@ -1,6 +1,8 @@ <?php -function validate($entity, $field, $value) { +// {{{ validate() + +function validate($entity, $field, $value /* , $oldvalue, $object */) { switch ("$entity/$field") { case "users/handle": if (!preg_match('/^[a-z][a-z0-9]+$/i', $value)) { @@ -21,6 +23,10 @@ return true; } +// }}} + +// {{{ visit_node() + /* Some useful "visitation model" tricks: @@ -41,6 +47,10 @@ SELECT * FROM table WHERE left BETWEEN <self.left> AND <self.right> "ORDER BY left" gives tree view +To get all leaf nodes: + + SELECT * FROM table WHERE right-1 = left; + */ function visit_node(&$tree, $node) { static $visitno; @@ -56,6 +66,9 @@ $tree[$node]['rightvisit'] = $visitno++; } +// }}} +// {{{ renumber_visitations() + function renumber_visitations($debug = false) { global $dbh; @@ -99,6 +112,10 @@ return true; } +// }}} + +// {{{ get_recent_releases() + function &get_recent_releases($n = 5) { global $dbh; $sth = $dbh->query("SELECT packages.name, packages.summary, ". @@ -115,6 +132,8 @@ return $recent; } +// }}} +// {{{ release_upload() function release_upload($package, $version, $relnotes, &$tarball, $md5sum) { @@ -172,41 +191,128 @@ } -function invalidHandle($handle) { - if (preg_match('/^[a-z]+-?[a-z]+$/i', $handle)) { - return false; - } - return 'handle must be all letters, optionally with one dash'; +// }}} + +// {{{ add_note() + +function add_note($key, $value, $note) +{ + global $dbh, $PHP_AUTH_USER; + $nby = $PHP_AUTH_USER; + $nid = $dbh->nextId("notes"); + $stmt = $dbh->prepare("INSERT INTO notes (id,$key,nby,ntime,note) ". + "VALUES(?,?,?,?,?)"); + return $dbh->execute($stmt, array($nid, $value, $nby, + gmdate('Y-m-d H:i'), $note)); } -function invalidName($name) { - if (trim($name)) { - return $false; - } - return 'name must not be empty'; +// }}} +// {{{ delete_note() + +function delete_note($id) +{ + global $dbh; + $id = (int)$id; + return $dbh->query("DELETE FROM notes WHERE id = $id"); +} + +// }}} +// {{{ delete_all_notes() + +function delete_all_notes($key, $value) +{ + global $dbh; + return $dbh->query("DELETE FROM notes WHERE $key = ". + $dbh->quote($value)); } -function invalidEmail($email) { - if (preg_match('/[a-z0-9_\.\+%]@[a-z0-9\.]+\.[a-z]+$', $email)) { +// }}} + +// {{{ delete_account() + +function delete_account($uid) +{ + global $dbh; + delete_all_notes("uid", $uid); + $dbh->query('DELETE FROM users WHERE handle = '. + $dbh->quote($uid)); + return ($dbh->affectedRows() > 0); +} + +// }}} +// {{{ reject_account_request() + +function reject_account_request($uid, $reason) +{ + global $PHP_AUTH_USER, $dbh; + list($email) = $dbh->getRow('SELECT email FROM users WHERE handle = ?', + array($uid)); + add_note("uid", $uid, "Account rejected: $reason"); + $msg = "Your PEAR account request was rejected by $PHP_AUTH_USER:\n". + "$reason\n"; + $xhdr = "From: $PHP_AUTH_USER@php.net"; + mail($email, "Your PEAR Account Request", $msg, $xhdr); + return true; +} + +// }}} +// {{{ open_account() + +function open_account($uid) +{ + global $PHP_AUTH_USER, $dbh; + + $user =& new PEAR_User($dbh, $uid); + if (@$user->registered) { return false; } - return 'invalid email address'; + @$arr = unserialize($user->userinfo); + delete_all_notes("uid", $uid); + $user->set('registered', 1); + if (is_array($arr)) { + $user->set('userinfo', $arr[1]); + } + $user->set('created', gmdate('Y-m-d H:i')); + $user->set('createdby', $PHP_AUTH_USER); + $user->store(); + add_note("uid", $uid, "Account opened"); + $msg = "Your PEAR account request has been opened.\n". + "To log in, go to http://pear.php.net/ and click on \"login\" in\n". + "the top-right menu.\n"; + $xhdr = "From: $PHP_AUTH_USER@php.net"; + mail($user->email, "Your PEAR Account Request", $msg, $xhdr); + return true; } -function invalidHomepage($homepage) { - if (preg_match('!http://.+!i', $homepage)) { - return false; +// }}} + +// {{{ mail_pear_admins() + +function mail_pear_admins($subject, $msg, $xhdr = '') +{ + global $dbh; + $admins = $dbh->getCol("SELECT email FROM users WHERE admin = 1"); + if (is_array($admins)) { + $oks = 0; + foreach ($admins as $email) { + $oks += mail($email, "PEAR Account Request", $msg, $xhdr); + } + if ($oks == sizeof($admins)) { + return true; + } } - return 'invalid URL'; + return false; } +// }}} +// {{{ class PEAR_User class PEAR_User extends DB_storage { function PEAR_User(&$dbh, $user) { - $this->DB_storage("users", "handle", &$dbh); + $this->DB_storage("users", "handle", $dbh); // XXX horrible hack until we get temporary error handlers $oldmode = $this->_default_error_mode; $this->_default_error_mode = PEAR_ERROR_RETURN; @@ -219,11 +325,14 @@ } } +// }}} +// {{{ class PEAR_Package + class PEAR_Package extends DB_storage { function PEAR_Package(&$dbh, $package) { - $this->DB_storage("packages", "id", &$dbh); + $this->DB_storage("packages", "id", $dbh); // XXX horrible hack until we get temporary error handlers $oldmode = $this->_default_error_mode; $this->_default_error_mode = PEAR_ERROR_RETURN; @@ -236,11 +345,14 @@ } } +// }}} +// {{{ class PEAR_Release + class PEAR_Release extends DB_storage { function PEAR_Release(&$dbh, $release) { - $this->DB_storage("releases", "id", &$dbh); + $this->DB_storage("releases", "id", $dbh); // XXX horrible hack until we get temporary error handlers $oldmode = $this->_default_error_mode; $this->_default_error_mode = PEAR_ERROR_RETURN; @@ -252,5 +364,7 @@ } } } + +// }}} ?> Index: pearweb/include/pear-format-html.php diff -u pearweb/include/pear-format-html.php:1.5 pearweb/include/pear-format-html.php:1.6 --- pearweb/include/pear-format-html.php:1.5 Sat Jul 28 22:25:57 2001 +++ pearweb/include/pear-format-html.php Wed Aug 1 10:34:25 2001 @@ -75,4 +75,27 @@ exit; } +function border_box_start($title, $width = "90%", $indent = "") +{ + print "$indent<table cellpadding=\"0\" cellspacing=\"1\" border=\"0\" width=\"$width\">\n"; + print "$indent <tr>\n"; + print "$indent <td bgcolor=\"#000000\">\n"; + print " <table cellpadding=\"2\" cellspacing=\"1\" border=\"0\" width=\"100%\">\n"; + print "$indent <tr bgcolor=\"#cccccc\">\n"; + print "$indent <th>$title</th>\n"; + print "$indent </tr>\n"; + print "$indent <tr bgcolor=\"#ffffff\">\n"; + print "$indent <td>\n"; +} + +function border_box_end($indent = "") +{ + print "$indent </td>\n"; + print "$indent </tr>\n"; + print "$indent </table>\n"; + print "$indent </td>\n"; + print "$indent </tr>\n"; + print "$indent</table>\n"; +} + ?> Index: pearweb/include/site.php diff -u pearweb/include/site.php:1.3 pearweb/include/site.php:1.4 --- pearweb/include/site.php:1.3 Thu Jul 5 03:49:49 2001 +++ pearweb/include/site.php Wed Aug 1 10:34:25 2001 @@ -104,6 +104,4 @@ $MIRRORS[$MYSITE] = array('xx', $MYSITE, 'none', $MYSITE, 2, 0, 'en'); } -echo "<!-- $MYSITE -->"; - ?> Index: pearweb/public_html/account-request.php diff -u pearweb/public_html/account-request.php:1.2 pearweb/public_html/account-request.php:1.3 --- pearweb/public_html/account-request.php:1.2 Sun Jul 29 10:47:15 2001 +++ pearweb/public_html/account-request.php Wed Aug 1 10:34:26 2001 @@ -47,7 +47,7 @@ } $handle = strtolower($handle); - $obj = new PEAR_User(&$dbh, $handle); + $obj =& new PEAR_User($dbh, $handle); if (isset($obj->created)) { display_error("Sorry, that username is already taken"); $jumpto = "handle"; @@ -61,43 +61,64 @@ } $display_form = false; - $obj->name = $name; - $obj->email = $email; - $obj->homepage = $homepage; - $obj->showemail = (bool)@$showemail; - $obj->password = md5($password); - $obj->registered = false; - - $admins = $dbh->getCol("SELECT email FROM users WHERE admin = 1"); - $oks = 0; - $msg = "Username: {$obj->handle}\n". - "Email: {$obj->email}". - ($obj->showemail ? " (show address)" : " (hide address)") . "\n". - "Password (MD5): {$obj->password}\n\n". + $md5pw = md5($password); + $showemail = @(bool)$showemail; + // hack to temporarily embed the "purpose" in + // the user's "userinfo" column + $userinfo = serialize(array($purpose, $moreinfo)); + $set_vars = array('name' => $name, + 'email' => $email, + 'homepage' => $homepage, + 'showemail' => $showemail, + 'password' => $md5pw, + 'registered' => 0, + 'userinfo' => $userinfo); + $errors = 0; + foreach ($set_vars as $var => $value) { + $err = $obj->set($var, $value); + if (PEAR::isError($err)) { + print "Failed setting $var: "; + print $err->getMessage(); + print "<BR>\n"; + $errors++; + } + } + if ($errors > 0) { + break; + } + + $msg = "Username: {$handle}\n". + "Real Name: {$name}\n". + "Email: {$email}". + (@$showemail ? " (show address)" : " (hide address)") . "\n". + "Password (MD5): {$md5pw}\n\n". "Purpose:\n". "$purpose\n\n". - "More info:\n". - "$moreinfo\n"; - $xhdr = "From: PEAR Web Site <pear-dev@lists.php.net>"; - foreach ($admins as $email) { - $oks += mail($email, "PEAR Account Request", $msg, $xhdr); - } + "To handle: http://{$SERVER_NAME}/admin.php?acreq={$handle}\n"; + if ($moreinfo) { + $msg .= "\nMore info:\n$moreinfo\n"; + } + $xhdr = "From: $name <$email>"; + $subject = "PEAR Account Request"; + $ok = mail_pear_admins($subject, $msg, $xhdr); response_header("Account Request Submitted"); - if ($oks != sizeof($admins)) { - print "<H2>Possible Problem!</H2>\n"; - print "Your account request has been submitted, but there ". - "was problems mailing one or more administrators. ". - "If you don't hear anything about your account in a few ". - "days, drop a mail about it to the <i>pear-dev</i> mailing ". - "list."; - } else { + if ($ok) { print "<H2>Account Request Submitted</H2>\n"; print "Your account request has been submitted, it will ". - "be reviewed by a human. This may take from two minutes ". - "to several days, depending on how much time people have. ". + "be reviewed by a human shortly. This may take from two ". + "minutes to several days, depending on how much time people ". + "have. ". "You will get an email when your account is open, or if ". "your request was rejected for some reason."; + } else { + print "<H2>Possible Problem!</H2>\n"; + print "Your account request has been submitted, but there ". + "were problems mailing one or more administrators. ". + "If you don't hear anything about your account in a few ". + "days, please drop a mail about it to the <i>pear-dev</i> ". + "mailing list."; } + print "<br />Click the top-left PEAR logo to go back to the front page.\n"; } } while (0); @@ -123,7 +144,7 @@ } $width = 60; - $form = new HTML_Form($PHP_SELF, "POST"); + $form =& new HTML_Form($PHP_SELF, "POST"); $form->addText("handle", "Username", null, 12); $form->addText("name", "Real Name", null, $width); $form->addPassword("password", "Password", null, 10); Index: pearweb/public_html/index.php diff -u pearweb/public_html/index.php:1.15 pearweb/public_html/index.php:1.16 --- pearweb/public_html/index.php:1.15 Sun Jul 29 10:46:44 2001 +++ pearweb/public_html/index.php Wed Aug 1 10:34:26 2001 @@ -15,7 +15,8 @@ menu_link("Documentation", "http://php.net/manual/en/pear.php"); if ($SERVER_NAME != "pear.php.net") { - menu_link("Request a PEAR Account", "account-request.php"); + menu_link("Request PEAR Account", "account-request.php"); + menu_link("Administrators", "admin.php"); menu_link("Browse Packages", "packages.php"); menu_link("Want to contribute?", "signup.php"); menu_link("Upload Release", "release-upload.php"); Index: pearweb/public_html/login.php diff -u pearweb/public_html/login.php:1.3 pearweb/public_html/login.php:1.4 --- pearweb/public_html/login.php:1.3 Thu Jul 5 03:34:43 2001 +++ pearweb/public_html/login.php Wed Aug 1 10:34:26 2001 @@ -6,7 +6,7 @@ <?php /** -auth_require(0); +auth_require(); header("Location: ./"); */ Index: pearweb/public_html/xmlrpc.php diff -u pearweb/public_html/xmlrpc.php:1.4 pearweb/public_html/xmlrpc.php:1.5 --- pearweb/public_html/xmlrpc.php:1.4 Wed May 9 14:30:58 2001 +++ pearweb/public_html/xmlrpc.php Wed Aug 1 10:34:26 2001 @@ -33,7 +33,7 @@ $md5sum = $mmd5sum->scalarval(); // (1) verify that user has access - auth_require(0); + auth_require(); if (isset($_return_value)) return $_return_value; // XXX FIXME check acl table Index: pearweb/sql/notes.sql diff -u pearweb/sql/notes.sql:1.1 pearweb/sql/notes.sql:1.2 --- pearweb/sql/notes.sql:1.1 Sat Jul 28 22:22:59 2001 +++ pearweb/sql/notes.sql Wed Aug 1 10:34:26 2001 @@ -1,7 +1,12 @@ CREATE TABLE notes ( - id INTEGER NOT NULL, - uid VARCHAR(20) REFERENCES users(handle), - pid INTEGER REFERENCES packages(id), + id INTEGER NOT NULL, + uid VARCHAR(20), -- REFERENCES users(handle), + pid INTEGER, -- REFERENCES packages(id), + nby VARCHAR(20) REFERENCES users(handle), + ntime DATETIME, + note TEXT, - PRIMARY KEY(id) + PRIMARY KEY(id), + INDEX(uid), + INDEX(pid) ); Index: pearweb/public_html/admin.php +++ pearweb/public_html/admin.php <?php auth_require(true); $SIDEBAR_DATA=' This is the PEAR administration page. <noscript><p> <!-- be annoying! --> <b><blink>You must enable Javascript to use this page!</blink></b> </p></noscript> '; response_header("PEAR Administration"); //print "GET: ";var_dump($HTTP_GET_VARS);print "<br />\n"; //print "POST: ";var_dump($HTTP_POST_VARS);print "<br />\n"; // {{{ adding and deleting notes if (@$cmd == "Add note" && !empty($note) && !empty($key) && !empty($id)) { add_note($key, $id, $note); unset($cmd); } elseif (@$cmd == "Delete note" && !empty($id)) { delete_note($id); } // }}} // {{{ open account elseif (@$cmd == "Open Account" && !empty($uid)) { // another hack to remove the temporary "purpose" field // from the user's "userinfo" if (open_account($uid)) { print "<p>Opened account $uid...</p>\n"; } } // }}} // {{{ reject account request elseif (@$cmd == "Reject Request" && !empty($uid)) { if (reject_account_request($uid, $reason)) { print "<p>Rejected account request for $uid...</p>\n"; } } // }}} // {{{ delete account request elseif (@$cmd == "Delete Request" && !empty($uid)) { if (delete_account($uid)) { print "<p>Deleted account request for \"$uid\"...</p>"; } } // }}} // {{{ javascript functions ?> <script language="javascript"> <!-- function confirmed_goto(url, message) { if (confirm(message)) { location = url; } } function confirmed_submit(button, action, required, errormsg) { if (required && required.value == '') { alert(errormsg); return; } if (confirm('Are you sure you want to ' + action + '?')) { button.form.cmd.value = button.value; button.form.submit(); } } // --> </script> <?php // }}} do { // {{{ "approve account request" form if (!empty($acreq)) { $requser =& new PEAR_User($dbh, $acreq); if (empty($requser->name)) { break; } list($purpose, $moreinfo) = @unserialize($requser->userinfo); border_box_start("Account request from $requser->name <$requser->email>"); ?> <table cellpadding="2" cellspacing="0" border="0"> <tr> <td>Requested User Name:</td> <td><?= $requser->handle ?></td> </tr> <tr> <td>Real Name:</td> <td><?= $requser->name ?></td> </tr> <tr> <td>Email Address:</td> <td><a href="mailto:<?= $requser->email ?>"><?= $requser->email ?></td> </tr> <tr> <td>MD5-encrypted password:</td> <td><?= $requser->password ?></td> </tr> <tr> <td>Purpose of account:</td> <td valign="top"><?= $purpose ?></td> </tr> <tr> <td>More information:</td> <td><?= $moreinfo ?></td> </tr> </table> <?php border_box_end(); print "<br />\n"; border_box_start("Notes for user $requser->handle"); $notes = $dbh->getAssoc("SELECT id,nby,ntime,note FROM notes ". "WHERE uid = ? ORDER BY ntime", true, array($requser->handle)); $i = " "; if (is_array($notes) && sizeof($notes) > 0) { print "$i<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\">\n"; foreach ($notes as $nid => $data) { list($nby, $ntime, $note) = $data; print "$i <tr>\n"; print "$i <td>\n"; print "$i <b>$nby $ntime:</b>"; if ($nby == $PHP_AUTH_USER) { $url = "$PHP_SELF?acreq=$acreq&cmd=Delete+note&id=$nid"; $msg = "Are you sure you want to delete this note?"; print "[<a href=\"javascript:confirmed_goto('$url', '$msg')\">delete your note</a>]"; } print "<br />\n"; print "$i ".htmlspecialchars($note)."\n"; print "$i </td>\n"; print "$i </tr>\n"; print "$i <tr><td> </td></tr>\n"; } print "$i</table>\n"; } else { print "No notes."; } print "$i<form action=\"$PHP_SELF\" method=\"POST\">\n"; print "$i<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\">\n"; print "$i <tr>\n"; print "$i <td>\n"; print "$i To add a note, enter it here:<br />\n"; print "$i <textarea rows=\"3\" cols=\"55\" name=\"note\"></textarea><br />\n"; print "$i <input type=\"submit\" value=\"Add note\" name=\"cmd\">\n"; print "$i <input type=\"hidden\" name=\"key\" value=\"uid\">\n"; print "$i <input type=\"hidden\" name=\"id\" value=\"$requser->handle\">\n"; print "$i <input type=\"hidden\" name=\"acreq\" value=\"$acreq\">\n"; print "$i </td>\n"; print "$i </tr>\n"; print "$i</table>\n"; print "$i</form>\n"; border_box_end(); ?> <form action="<?= $PHP_SELF ?>" method="POST"> <input type="hidden" name="cmd" value=""> <input type="hidden" name="uid" value="<?= $requser->handle ?>"> <table cellpadding="3" cellspacing="0" border="0" width="90%"> <tr> <td align="center"><input type="button" value="Open Account" onclick="confirmed_submit(this, 'open this account')" /></td> <td align="center"><input type="button" value="Reject Request" onclick="confirmed_submit(this, 'reject this request', this.form.reason, 'You must give a reason for rejecting the request.')" /></td> <td align="center"><input type="button" value="Delete Request" onclick="confirmed_submit(this, 'delete this request')" /></td> </tr> <tr> <td colspan="3"> If dismissing an account request, enter the reason here (will be emailed to <?= $requser->email ?>):<br /> <textarea rows="3" cols="60" name="reason"></textarea> </td> </table> </form> <?php // }}} // {{{ admin menu } else { border_box_start("Account Requests", "30%"); $requests = $dbh->getAssoc("SELECT handle,name,email FROM users ". "WHERE registered = 0"); if (is_array($requests) && sizeof($requests) > 0) { foreach ($requests as $handle => $data) { list($name, $email) = $data; print "<a href=\"$PHP_SELF?acreq=$handle\">$name ($handle)</a><br />\n"; } } else { print "No account requests."; } border_box_end(); } // }}} } while (false); response_footer(); ?>