Added an option to disable automated ACL
This commit is contained in:
parent
8c3c622475
commit
2e38729a9f
136
action.php
136
action.php
|
@ -116,77 +116,79 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
|
|||
|
||||
function acl(&$event, $param) {
|
||||
global $conf;
|
||||
// ACL
|
||||
$acl = new admin_plugin_acl();
|
||||
// On private namespace
|
||||
if ($this->getConf('create_private_ns')) {
|
||||
// For known users
|
||||
// If use_name_string or group_by_name is enabled, we can't use ACL wildcards so let's create ACL for current user on his private ns
|
||||
if (($this->getConf('use_name_string')) or ($this->getConf('group_by_name'))) {
|
||||
$ns = $this->private_ns.':*';
|
||||
if ($_SERVER['REMOTE_USER'] != null) $acl->_acl_add($ns, strtolower($_SERVER['REMOTE_USER']), AUTH_DELETE);
|
||||
// Otherwise we can set ACL for all known users at once
|
||||
} else {
|
||||
$acl->_acl_add(cleanID($this->getConf('users_namespace')).':%USER%:*', '%USER%', AUTH_DELETE);
|
||||
}
|
||||
// For @ALL
|
||||
if ($this->getConf('acl_all_private') != 'noacl') {
|
||||
$acl->_acl_add(cleanID($this->getConf('users_namespace')).':*', '@ALL', (int)$this->getConf('acl_all_private'));
|
||||
}
|
||||
// For @user
|
||||
if (($this->getConf('acl_user_private') != 'noacl') && ($this->getConf('acl_user_private') !== $this->getConf('acl_all_private'))) {
|
||||
$acl->_acl_add(cleanID($this->getConf('users_namespace')).':*', '@user', (int)$this->getConf('acl_user_private'));
|
||||
}
|
||||
} // end of private namespaces acl
|
||||
// On public user pages
|
||||
if ($this->getConf('create_public_page')) {
|
||||
// For known users
|
||||
$acl->_acl_add(cleanID($this->getConf('public_pages_ns')).':%USER%', '%USER%', AUTH_EDIT);
|
||||
// For others
|
||||
if ($this->getConf('acl_all_public') != 'noacl') {
|
||||
// If both private and public namespaces are identical, we need to force rights for @ALL and/or @user on each public page
|
||||
if ($this->getConf('users_namespace') == $this->getConf('public_pages_ns')) {
|
||||
foreach (glob("data/pages/".$this->getConf('public_pages_ns')."/*.txt") as $filename) {
|
||||
// ACL on templates will be managed another way
|
||||
if (strpos($filename, 'userhomepage_p') == false) {
|
||||
// @ALL
|
||||
$acl->_acl_add($this->getConf('public_pages_ns').':'.explode('.', end(explode('/', $filename)))[0], '@ALL', $this->getConf('acl_all_public'));
|
||||
// @user
|
||||
if (($this->getConf('acl_user_public') != 'noacl') && ($this->getConf('acl_user_public') !== $this->getConf('acl_all_public'))) {
|
||||
$acl->_acl_add($this->getConf('public_pages_ns').':'.explode('.', end(explode('/', $filename)))[0], '@user', $this->getConf('acl_user_public'));
|
||||
if (!$this->getConf('no_acl')) {
|
||||
// ACL
|
||||
$acl = new admin_plugin_acl();
|
||||
// On private namespace
|
||||
if ($this->getConf('create_private_ns')) {
|
||||
// For known users
|
||||
// If use_name_string or group_by_name is enabled, we can't use ACL wildcards so let's create ACL for current user on his private ns
|
||||
if (($this->getConf('use_name_string')) or ($this->getConf('group_by_name'))) {
|
||||
$ns = $this->private_ns.':*';
|
||||
if ($_SERVER['REMOTE_USER'] != null) $acl->_acl_add($ns, strtolower($_SERVER['REMOTE_USER']), AUTH_DELETE);
|
||||
// Otherwise we can set ACL for all known users at once
|
||||
} else {
|
||||
$acl->_acl_add(cleanID($this->getConf('users_namespace')).':%USER%:*', '%USER%', AUTH_DELETE);
|
||||
}
|
||||
// For @ALL
|
||||
if ($this->getConf('acl_all_private') != 'noacl') {
|
||||
$acl->_acl_add(cleanID($this->getConf('users_namespace')).':*', '@ALL', (int)$this->getConf('acl_all_private'));
|
||||
}
|
||||
// For @user
|
||||
if (($this->getConf('acl_user_private') != 'noacl') && ($this->getConf('acl_user_private') !== $this->getConf('acl_all_private'))) {
|
||||
$acl->_acl_add(cleanID($this->getConf('users_namespace')).':*', '@user', (int)$this->getConf('acl_user_private'));
|
||||
}
|
||||
} // end of private namespaces acl
|
||||
// On public user pages
|
||||
if ($this->getConf('create_public_page')) {
|
||||
// For known users
|
||||
$acl->_acl_add(cleanID($this->getConf('public_pages_ns')).':%USER%', '%USER%', AUTH_EDIT);
|
||||
// For others
|
||||
if ($this->getConf('acl_all_public') != 'noacl') {
|
||||
// If both private and public namespaces are identical, we need to force rights for @ALL and/or @user on each public page
|
||||
if ($this->getConf('users_namespace') == $this->getConf('public_pages_ns')) {
|
||||
foreach (glob("data/pages/".$this->getConf('public_pages_ns')."/*.txt") as $filename) {
|
||||
// ACL on templates will be managed another way
|
||||
if (strpos($filename, 'userhomepage_p') == false) {
|
||||
// @ALL
|
||||
$acl->_acl_add($this->getConf('public_pages_ns').':'.explode('.', end(explode('/', $filename)))[0], '@ALL', $this->getConf('acl_all_public'));
|
||||
// @user
|
||||
if (($this->getConf('acl_user_public') != 'noacl') && ($this->getConf('acl_user_public') !== $this->getConf('acl_all_public'))) {
|
||||
$acl->_acl_add($this->getConf('public_pages_ns').':'.explode('.', end(explode('/', $filename)))[0], '@user', $this->getConf('acl_user_public'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Otherwise we just need to give the right permission to each group on public pages namespace
|
||||
} else {
|
||||
// @ALL
|
||||
$acl->_acl_add(cleanID($this->getConf('public_pages_ns')).':*', '@ALL', $this->getConf('acl_all_public'));
|
||||
// @user
|
||||
if (($this->getConf('acl_user_public') != 'noacl') && ($this->getConf('acl_user_public') !== $this->getConf('acl_all_public'))) {
|
||||
$acl->_acl_add(cleanID($this->getConf('public_pages_ns')).':*', '@user', $this->getConf('acl_user_public'));
|
||||
// Otherwise we just need to give the right permission to each group on public pages namespace
|
||||
} else {
|
||||
// @ALL
|
||||
$acl->_acl_add(cleanID($this->getConf('public_pages_ns')).':*', '@ALL', $this->getConf('acl_all_public'));
|
||||
// @user
|
||||
if (($this->getConf('acl_user_public') != 'noacl') && ($this->getConf('acl_user_public') !== $this->getConf('acl_all_public'))) {
|
||||
$acl->_acl_add(cleanID($this->getConf('public_pages_ns')).':*', '@user', $this->getConf('acl_user_public'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end for public pages acl
|
||||
// On templates if they're in data/pages
|
||||
if (strpos($this->getConf('templates_path'),'data/pages') !== false) {
|
||||
// For @ALL
|
||||
if (($this->getConf('acl_all_templates') != 'noacl') && (($this->getConf('create_private_ns')) or ($this->getConf('create_public_page')))) {
|
||||
$acl->_acl_add(end(explode('/',$this->getConf('templates_path'))).':userhomepage_private', '@ALL', (int)$this->getConf('acl_all_templates'));
|
||||
$acl->_acl_add(end(explode('/',$this->getConf('templates_path'))).':userhomepage_public', '@ALL', (int)$this->getConf('acl_all_templates'));
|
||||
}
|
||||
// For @user
|
||||
if (($this->getConf('acl_user_templates') != 'noacl') && ($this->getConf('acl_user_templates') !== $this->getConf('acl_all_templates')) && (($this->getConf('create_private_ns')) or ($this->getConf('create_public_page')))) {
|
||||
$acl->_acl_add(end(explode('/',$this->getConf('templates_path'))).':userhomepage_private', '@user', (int)$this->getConf('acl_user_templates'));
|
||||
$acl->_acl_add(end(explode('/',$this->getConf('templates_path'))).':userhomepage_public', '@user', (int)$this->getConf('acl_user_templates'));
|
||||
}
|
||||
} // end of templates acl
|
||||
// Cleaning duplicated lines in acl
|
||||
$lines = file(DOKU_CONF.'acl.auth.php');
|
||||
// And only keep unique lines (OK, we loose an empty comment line...)
|
||||
$lines = array_unique($lines);
|
||||
// Write things back to conf/acl.auth.php
|
||||
file_put_contents(DOKU_CONF.'acl.auth.php', implode($lines));
|
||||
} // end for public pages acl
|
||||
// On templates if they're in data/pages
|
||||
if (strpos($this->getConf('templates_path'),'data/pages') !== false) {
|
||||
// For @ALL
|
||||
if (($this->getConf('acl_all_templates') != 'noacl') && (($this->getConf('create_private_ns')) or ($this->getConf('create_public_page')))) {
|
||||
$acl->_acl_add(end(explode('/',$this->getConf('templates_path'))).':userhomepage_private', '@ALL', (int)$this->getConf('acl_all_templates'));
|
||||
$acl->_acl_add(end(explode('/',$this->getConf('templates_path'))).':userhomepage_public', '@ALL', (int)$this->getConf('acl_all_templates'));
|
||||
}
|
||||
// For @user
|
||||
if (($this->getConf('acl_user_templates') != 'noacl') && ($this->getConf('acl_user_templates') !== $this->getConf('acl_all_templates')) && (($this->getConf('create_private_ns')) or ($this->getConf('create_public_page')))) {
|
||||
$acl->_acl_add(end(explode('/',$this->getConf('templates_path'))).':userhomepage_private', '@user', (int)$this->getConf('acl_user_templates'));
|
||||
$acl->_acl_add(end(explode('/',$this->getConf('templates_path'))).':userhomepage_public', '@user', (int)$this->getConf('acl_user_templates'));
|
||||
}
|
||||
} // end of templates acl
|
||||
// Cleaning duplicated lines in acl
|
||||
$lines = file(DOKU_CONF.'acl.auth.php');
|
||||
// And only keep unique lines (OK, we loose an empty comment line...)
|
||||
$lines = array_unique($lines);
|
||||
// Write things back to conf/acl.auth.php
|
||||
file_put_contents(DOKU_CONF.'acl.auth.php', implode($lines));
|
||||
}
|
||||
}
|
||||
|
||||
function copyFile($source = null, $target_dir = null, $target_file = null) {
|
||||
|
|
|
@ -22,3 +22,4 @@
|
|||
$conf['templatepath'] = 'lib/plugins/userhomepage/_template.txt';
|
||||
$conf['acl_all_templates'] = '1';
|
||||
$conf['acl_user_templates'] = '1';
|
||||
$conf['no_acl'] = 0;
|
||||
|
|
|
@ -22,3 +22,4 @@
|
|||
$meta['templatepath'] = array('string');
|
||||
$meta['acl_all_templates'] = array('multichoice','_choices'=>array('0','1','2','noacl'));
|
||||
$meta['acl_user_templates'] = array('multichoice','_choices'=>array('0','1','2','noacl'));
|
||||
$meta['no_acl'] = array('onoff');
|
||||
|
|
|
@ -52,3 +52,4 @@
|
|||
$lang['acl_user_templates_o_1'] = 'Read (Default)';
|
||||
$lang['acl_user_templates_o_2'] = 'Edit';
|
||||
$lang['acl_user_templates_o_noacl'] = 'No automatic ACL';
|
||||
$lang['no_acl'] = 'No automated ACL setting at all but you\'ll have to remove those created so far manually. Don\'t forget to set some ACL on templates.';
|
||||
|
|
|
@ -52,3 +52,4 @@
|
|||
$lang['acl_user_templates_o_1'] = 'Lecture (Défaut)';
|
||||
$lang['acl_user_templates_o_2'] = 'Écriture';
|
||||
$lang['acl_user_templates_o_noacl'] = 'Pas de gestion automatique des droits';
|
||||
$lang['no_acl'] = 'Aucun règlage automatique des droits d\'accès mais vous devrez nettoyer manuellement les règles déjà créées. Pensez à protéger les modèles.';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
base userhomepage
|
||||
author Simon Delage
|
||||
email simon.geekitude@gmail.com
|
||||
date 2014-10-26
|
||||
date 2014-12-06
|
||||
name User Homepage
|
||||
desc Automatically create user's private namespace and/or public page and redirects users to private namespace on login.
|
||||
url https://www.dokuwiki.org/plugin:userhomepage
|
||||
|
|
Loading…
Reference in a new issue