From 10a76f6fd45bbbf4443fb8626d35aae3a388c490 Mon Sep 17 00:00:00 2001 From: frank Date: Sun, 20 Feb 2005 11:45:06 +0100 Subject: acl-administration rc1 darcs-hash:20050220104506-b7c55-01c85b4b688597c8405987e0f7ea30aa4fb1472f.gz --- inc/acl_admin.php | 121 ++++++++++++++++++++++++++++++++++++++++++++ inc/auth.php | 32 +++++++++++- inc/html.php | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 298 insertions(+), 2 deletions(-) create mode 100644 inc/acl_admin.php (limited to 'inc') diff --git a/inc/acl_admin.php b/inc/acl_admin.php new file mode 100644 index 000000000..f7cd7fbd7 --- /dev/null +++ b/inc/acl_admin.php @@ -0,0 +1,121 @@ + + */ +function get_acl_config($ID){ + global $AUTH_ACL; + + $acl_config=array(); + + // match exact name + $matches = preg_grep('/^'.$ID.'\s+.*/',$AUTH_ACL); + if(count($matches)){ + foreach($matches as $match){ + $match = preg_replace('/#.*$/','',$match); //ignore comments + $acl = preg_split('/\s+/',$match); + //0 is pagename, 1 is user, 2 is acl + $acl_config["$acl[0]"][]=array($acl[1],$acl[2]); + } + } + + $specific_found=array(); + // match ns + if(($ID=getNS($ID)) !== false){ + $matches = preg_grep('/^'.$ID.':\*\s+.*/',$AUTH_ACL); + if(count($matches)){ + foreach($matches as $match){ + $match = preg_replace('/#.*$/','',$match); //ignore comments + $acl = preg_split('/\s+/',$match); + //0 is pagename, 1 is user, 2 is acl + $acl_config["$acl[0]"][]=array($acl[1],$acl[2]); + $specific_found[]=$acl[1]; + } + } + } + + //include *-config + $matches = preg_grep('/^\*\s+.*/',$AUTH_ACL); + if(count($matches)){ + foreach($matches as $match){ + $match = preg_replace('/#.*$/','',$match); //ignore comments + $acl = preg_split('/\s+/',$match); + // only include * for this user if not already found in ns + if(!in_array($acl[1], $specific_found)){ + //0 is pagename, 1 is user, 2 is acl + $acl_config["$acl[0]"][]=array($acl[1],$acl[2]); + } + } + } + + //sort + //FIXME: better sort algo: first sort by key, then sort by first value + krsort($acl_config, SORT_STRING); + + return($acl_config); +} + +/** + * adds new acl-entry to conf/acl.auth + * + * @author Frank Schubert + */ +function acl_admin_add($acl_scope, $acl_user, $acl_level){ + if($acl_scope === '' || $acl_user === '' || $acl_level === '') { return false; } + + $acl_config = join("",file('conf/acl.auth')); + + // max level for pagenames is 2 + if(strpos("*", $acl_scope) === false) { + if($acl_level > 2) { $acl_level = 2; } + } + + $new_acl = "$acl_scope\t$acl_user\t$acl_level\n"; + + $new_config = $acl_config.$new_acl; + + return io_saveFile("conf/acl.auth", $new_config); +} + +/** + * remove acl-entry from conf/acl.auth + * + * @author Frank Schubert + */ +function acl_admin_del($acl_scope, $acl_user, $acl_level){ + if($acl_scope === '' || $acl_user === '' || $acl_level === '') { return false; } + + $acl_pattern = preg_quote($acl_scope)."\s+".$acl_user."\s+".$acl_level."\n"; + + $acl_config = file('conf/acl.auth'); + + // save all non!-matching + $new_config = preg_grep("/$acl_pattern/", $acl_config, PREG_GREP_INVERT); + + return io_saveFile("conf/acl.auth", join("",$new_config)); +} + +/** + * change existing acl entries + * + * @author Frank Schubert + */ +function acl_admin_change($acl_scope, $acl_user, $acl_level, $acl_checkbox){ + + $new_level = 0; + if(is_array($acl_checkbox)) { + foreach($acl_checkbox as $acl_num => $value){ + if( ($value == "on") && + ($acl_num > $new_level)) { + $new_level = $acl_num; + } + } + } + + acl_admin_del($acl_scope, $acl_user, $acl_level); + acl_admin_add($acl_scope, $acl_user, $new_level); +} +?> diff --git a/inc/auth.php b/inc/auth.php index 094319377..1e84d6552 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -16,6 +16,7 @@ require_once(DOKU_INC.'inc/mail.php'); // load the the auth functions require_once(DOKU_INC.'inc/auth_'.$conf['authtype'].'.php'); + require_once(DOKU_INC.'inc/acl_admin.php'); // some ACL level defines define('AUTH_NONE',0); @@ -23,11 +24,11 @@ define('AUTH_EDIT',2); define('AUTH_CREATE',4); define('AUTH_UPLOAD',8); - define('AUTH_GRANT',255); + define('AUTH_ADMIN',255); if($conf['useacl']){ auth_login($_REQUEST['u'],$_REQUEST['p'],$_REQUEST['r']); - // load ACL into a global array + //load ACL into a global array $AUTH_ACL = file('conf/acl.auth'); } @@ -212,6 +213,16 @@ function auth_aclcheck($id,$user,$groups){ # if no ACL is used always return upload rights if(!$conf['useacl']) return AUTH_UPLOAD; + + //if user is superuser return 255 (acl_admin) + if($conf['superuser'] == $user) { return AUTH_ADMIN; } + + //prepend groups with @ + for($i=0; $i AUTH_UPLOAD) $acl[2] = AUTH_UPLOAD; //no admins in the ACL! if($acl[2] > $perm){ $perm = $acl[2]; } @@ -260,6 +272,7 @@ function auth_aclcheck($id,$user,$groups){ foreach($matches as $match){ $match = preg_replace('/#.*$/','',$match); //ignore comments $acl = preg_split('/\s+/',$match); + if($acl[2] > AUTH_UPLOAD) $acl[2] = AUTH_UPLOAD; //no admins in the ACL! if($acl[2] > $perm){ $perm = $acl[2]; } @@ -390,4 +403,19 @@ function register(){ } } +/** + * Uses a regular expresion to check if a given mail address is valid + * + * May not be completly RFC conform! + * + * @link http://www.webmasterworld.com/forum88/135.htm + * + * @param string $email the address to check + * @return bool true if address is valid + */ +function isvalidemail($email){ + return eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$", $email); +} + + ?> diff --git a/inc/html.php b/inc/html.php index d848f89b4..9cceee82c 100644 --- a/inc/html.php +++ b/inc/html.php @@ -428,6 +428,10 @@ function html_footer(){ }else{ print html_btn('login',$ID,'',array('do' => 'login')); } + #//acl-admin button + #if($INFO['perm'] == AUTH_GRANT){ + # print html_btn('acl_admin',$ID,'',array('do' => 'acl_admin')); + #} } ?> 'index'))?> @@ -1171,4 +1175,147 @@ function html_debug(){ print ''; } +/** + * prints the acl-admin form(s) + * + * @author Frank Schubert + */ +function html_acl_admin(){ + global $lang; + global $ID; + global $INFO; + + print parsedLocale('acl_admin'); +?> +
+ + +
+ + + + + + + + + + + + + + + + +
+
+
+
+ +
+
+
+ +
+
+ +
+ $value){ + if($pagename != '*') { + $ID_cur=$pagename; + while(($piece=getNS($ID_cur)) !== false){ + $url="".noNS($piece).":".$url;; + $ID_cur=$piece; + } + $url.="".noNS($pagename).""; + print $url; + $url=''; + }else{ + print $pagename; + } ?> + + + + + + + + + + + + + + + + + + + + + + +
nameRWCUUPDATEDELETE
+ + + + +
+ + + + + + =$num) { + ?> checked="checked" /> + +
+ + + + + + +
+
+
+
+
+ -- cgit v1.2.3