cvs: pearweb /include pear-auth.php
| From: | Martin Jansen | Date: | Fri, 26 Sep 2003 19:49:26 +0000 |
| Subject: | cvs: pearweb /include pear-auth.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-13115@lists.php.net to get a copy of this message | ||
mj Fri Sep 26 15:49:26 2003 EDT
Modified files:
/pearweb/include pear-auth.php
Log:
* Changing to make use of the new karma system.
Index: pearweb/include/pear-auth.php
diff -u pearweb/include/pear-auth.php:1.29 pearweb/include/pear-auth.php:1.30
--- pearweb/include/pear-auth.php:1.29 Sun Sep 14 05:56:01 2003
+++ pearweb/include/pear-auth.php Fri Sep 26 15:49:25 2003
@@ -15,7 +15,7 @@
+----------------------------------------------------------------------+
| Authors: |
+----------------------------------------------------------------------+
- $Id: pear-auth.php,v 1.29 2003/09/14 09:56:01 mj Exp $
+ $Id: pear-auth.php,v 1.30 2003/09/26 19:49:25 mj Exp $
*/
function auth_reject($realm = null, $message = null)
@@ -125,21 +125,69 @@
return false;
}
+function auth_check($atom)
+{
+ global $dbh;
+ static $karma;
+
+ require_once "Damblan/Karma.php";
+
+ global $auth_user;
+
+ // Check for backwards compatibility
+ if (is_bool($atom)) {
+ if ($atom == true) {
+ $atom = "admin";
+ } else {
+ $atom = "dev";
+ }
+ }
+
+ if (is_string($atom)) {
+ switch ($atom) {
+ case "user" :
+ case "dev" :
+ case "admin" :
+ case "group" :
+ if (!isset($karma)) {
+ $karma = new Damblan_Karma($dbh);
+ }
+ return $karma->has($auth_user->handle, "pear." . $atom);
+ break;
+ }
+ }
+
+ return true;
+}
+
function auth_require($admin = false)
{
global $auth_user;
+ $res = true;
$user = @$_COOKIE['PEAR_USER'];
$passwd = @$_COOKIE['PEAR_PW'];
if (!auth_verify($user, $passwd)) {
auth_reject(); // exits
}
- if ($admin && empty($auth_user->admin)) {
+
+ $num = func_num_args();
+ for ($i = 0; $i < $num; $i++) {
+ $arg = func_get_arg($i);
+ $res = auth_check($arg);
+
+ if ($res == true) {
+ return true;
+ }
+ }
+
+ if ($res == false) {
response_header("Insufficient Privileges");
report_error("Insufficient Privileges");
response_footer();
exit;
}
+
return true;
}