Many ACL changes + republishing

This commit is contained in:
Simon DELAGE 2014-09-13 02:13:16 +02:00
parent 2b5fa08ca9
commit f7aa65f4c4
6 changed files with 182 additions and 99 deletions

View File

@ -16,13 +16,13 @@ require_once (DOKU_PLUGIN . '/acl/admin.php');
class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
function register(&$controller) {
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'init',array());
$controller->register_hook('ACTION_ACT_PREPROCESS', 'AFTER', $this, 'redirect',array());
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'init',array());
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'redirect',array());
$controller->register_hook('ACTION_ACT_PREPROCESS', 'AFTER', $this, 'acl',array());
}
function init(&$event, $param) {
global $conf;
global $INFO;
// CREATE PRIVATE NAMESPACE START PAGE TEMPLATES IF NEEDED
if (($this->getConf('create_private_ns')) && (!file_exists(DOKU_INC.$this->getConf('templates_path').'/userhomepage_private.txt')) && ($_SERVER['REMOTE_USER'] != null)) {
// If old template exists, use it as source to create userhomepage_private.txt in templates_path
@ -50,65 +50,10 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
$this->private_page = $this->private_ns . ':' . $this->privateStart();
// user:simon.txt
$this->public_page = cleanID($this->getConf('public_pages_ns').':'. $_SERVER['REMOTE_USER']);
// ACL
$acl = new admin_plugin_acl();
// For private namespace
if (($this->getConf('create_private_ns')) && ($this->getConf('set_permissions'))) {
// If use_name_string or group_by_name is enabled, we can't use ACL wildcard
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);
} else {
$acl->_acl_add(cleanID($this->getConf('users_namespace')).':%USER%:*', '%USER%', AUTH_DELETE);
}
$acl->_acl_add(cleanID($this->getConf('users_namespace')).':*', '@ALL', (int)$this->getConf('set_permissions_others'));
}
// For public user pages
if (($this->getConf('create_public_page')) && ($this->getConf('set_permissions_public'))) {
$acl->_acl_add(cleanID($this->getConf('public_pages_ns')).':%USER%', '%USER%', AUTH_EDIT);
// If both private and public namespaces are identical, we need more ACL to force read rights for @ALL on public pages
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) {
$acl->_acl_add($this->getConf('public_pages_ns').':'.explode('.', end(explode('/', $filename)))[0], '@ALL', AUTH_READ);
}
}
// Otherwise we just need to give read access to @ALL on public pages namespace
} else {
$acl->_acl_add(cleanID($this->getConf('public_pages_ns')).':*', '@ALL', AUTH_READ);
}
}
// For templates if they're in data/pages
if (strpos($this->getConf('templates_path'),'data/pages') !== false) {
$acl->_acl_add(end(explode('/',$this->getConf('templates_path'))).':userhomepage_private', '@ALL', (int)$this->getConf('set_permissions_templates'));
$acl->_acl_add(end(explode('/',$this->getConf('templates_path'))).':userhomepage_public', '@ALL', (int)$this->getConf('set_permissions_templates'));
}
// If we changed some ACL, we probably duplicated some lines
if (($this->getConf('set_permissions')) or ($this->getConf('set_permissions_public'))) {
// Some lines in conf/acl.auth.php file have probably been duplicated so let's read the file
$lines = file(DOKU_INC.'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_INC.'conf/acl.auth.php', implode($lines));
}
}
function copyFile($source = null, $target_dir = null, $target_file = null) {
if(!@is_dir($target_dir)){
io_mkdir_p($target_dir) || msg("Creating directory $target_dir failed",-1);
}
if (!copy(DOKU_INC.$source, $target_dir.'/'.$target_file)) {
msg($this->getLang('copyerror').' ('.$source.' > '.$target_dir.'/'.$target_file.')', -1);
} else {
msg($this->getLang('copysuccess').' ('.$source.' > '.$target_dir.'/'.$target_file.')', 1);
}
}
function redirect(&$event, $param) {
global $conf;
global $INFO;
global $lang;
$created = array();
// If user just logged in
@ -162,6 +107,95 @@ 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'));
}
}
}
// 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
// If we changed some ACL, we probably duplicated some lines
if (($this->getConf('set_permissions')) or ($this->getConf('set_permissions_public'))) {
// Some lines in conf/acl.auth.php file have probably been duplicated so let's read the file
$lines = file(DOKU_INC.'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_INC.'conf/acl.auth.php', implode($lines));
}
}
function copyFile($source = null, $target_dir = null, $target_file = null) {
if(!@is_dir($target_dir)){
io_mkdir_p($target_dir) || msg("Creating directory $target_dir failed",-1);
}
if (!copy(DOKU_INC.$source, $target_dir.'/'.$target_file)) {
msg($this->getLang('copyerror').' ('.$source.' > '.$target_dir.'/'.$target_file.')', -1);
} else {
msg($this->getLang('copysuccess').' ('.$source.' > '.$target_dir.'/'.$target_file.')', 1);
}
}
function privateNamespace() {
if ( $this->getConf('use_name_string')) {
global $INFO;
@ -184,7 +218,6 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
}
function applyTemplate($type) {
global $INFO;
if ($type == 'private') {
$content = io_readFile($this->private_page_template, false);
} elseif ($type == 'public') {

View File

@ -10,13 +10,15 @@
$conf['use_name_string'] = 0;
$conf['use_start_page'] = 1;
$conf['users_namespace'] = 'user';
$conf['set_permissions'] = 1;
$conf['set_permissions_others'] = '0';
$conf['group_by_name'] = 0;
$conf['edit_before_create'] = 0;
$conf['acl_all_private'] = '0';
$conf['acl_user_private'] = '0';
$conf['create_public_page'] = 0;
$conf['public_pages_ns'] = 'user';
$conf['set_permissions_public'] = 1;
$conf['acl_all_public'] = '1';
$conf['acl_user_public'] = '1';
$conf['templates_path'] = 'data/pages/user';
$conf['set_permissions_templates'] = '0';
$conf['templatepath'] = 'lib/plugins/userhomepage/_template.txt';
$conf['acl_all_templates'] = '1';
$conf['acl_user_templates'] = '1';

View File

@ -10,13 +10,15 @@
$meta['use_name_string'] = array('onoff');
$meta['use_start_page'] = array('onoff');
$meta['users_namespace'] = array('string','_pattern' => '/^(|[a-zA-Z\-:]+)$/');
$meta['set_permissions'] = array('onoff');
$meta['set_permissions_others'] = array('multichoice','_choices'=>array('0','1','2','4','8','16'));
$meta['group_by_name'] = array('onoff');
$meta['edit_before_create'] = array('onoff');
$meta['acl_all_private'] = array('multichoice','_choices'=>array('0','1','2','4','8','16','noacl'));
$meta['acl_user_private'] = array('multichoice','_choices'=>array('0','1','2','4','8','16','noacl'));
$meta['create_public_page'] = array('onoff');
$meta['public_pages_ns'] = array('string','_pattern' => '/^(|[a-zA-Z\-:]+)$/','_caution' => 'warning');
$meta['set_permissions_public'] = array('onoff');
$meta['acl_all_public'] = array('multichoice','_choices'=>array('0','1','2','noacl'));
$meta['acl_user_public'] = array('multichoice','_choices'=>array('0','1','2','noacl'));
$meta['templates_path'] = array('string');
$meta['set_permissions_templates'] = array('multichoice','_choices'=>array('0','1','2'));
$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'));

View File

@ -10,22 +10,45 @@
$lang['use_name_string'] = 'Use user\'s full name instead of login for his private namespace.';
$lang['use_start_page'] = 'Use the wiki\'s start page name for the start page of each private namespace (otherwise, the private namespace name will be used).';
$lang['users_namespace'] = 'Namespace under which user namespaces are created.';
$lang['set_permissions'] = 'Automatically configure ACL for the namespace set above and give full rights to users on their own namespace.';
$lang['set_permissions_others'] = 'If [set_permissions] is enabled, what permission for others?';
$lang['set_permissions_others_o_0'] = 'None';
$lang['set_permissions_others_o_1'] = 'Read';
$lang['set_permissions_others_o_2'] = 'Edit';
$lang['set_permissions_others_o_4'] = 'Create';
$lang['set_permissions_others_o_8'] = 'Upload';
$lang['set_permissions_others_o_16'] = 'Delete';
$lang['group_by_name'] = 'Group users\' namespaces by the first character of user name?';
$lang['edit_before_create'] = 'Allow users to edit the start page of their private namespace on creation (will only work if a public page isn\'t generated at the same time).';
$lang['create_public_page'] = 'Create a public page for each user?';
$lang['acl_all_private'] = 'Permissions for @ALL group on Private Namespaces';
$lang['acl_all_private_o_0'] = 'None (Default)';
$lang['acl_all_private_o_1'] = 'Read';
$lang['acl_all_private_o_2'] = 'Edit';
$lang['acl_all_private_o_4'] = 'Create';
$lang['acl_all_private_o_8'] = 'Upload';
$lang['acl_all_private_o_16'] = 'Delete';
$lang['acl_all_private_o_noacl'] = 'No automatic ACL';
$lang['acl_user_private'] = 'Permissions for @user group on Private Namespaces';
$lang['acl_user_private_o_0'] = 'None (Default)';
$lang['acl_user_private_o_1'] = 'Read';
$lang['acl_user_private_o_2'] = 'Edit';
$lang['acl_user_private_o_4'] = 'Create';
$lang['acl_user_private_o_8'] = 'Upload';
$lang['acl_user_private_o_16'] = 'Delete';
$lang['acl_user_private_o_noacl'] = 'No automatic ACL';
$lang['create_public_page'] = 'Create a user\s public page?';
$lang['public_pages_ns'] = 'Namespace under wich public pages are created.';
$lang['set_permissions_public'] = 'Automatically configure ACL for the public pages (anyone can read but only user can edit his own).';
$lang['templates_path'] = 'Path where templates will be stored (userhomepage_private.txt and userhomepage_public.txt). Examples: <code>data/pages/wiki</code> (makes templates editable within DokuWiki) or <code>lib/plugins/userhomepage</code> (to protect templates or centralize them in a farm setup).';
$lang['set_permissions_templates'] = 'If templates are stored in <code>data/pages...</code>, automatically set following ACL for @ALL)';
$lang['set_permissions_templates_o_0'] = 'None';
$lang['set_permissions_templates_o_1'] = 'Read';
$lang['set_permissions_templates_o_2'] = 'Edit';
$lang['acl_all_public'] = 'Permissions for @ALL group on Public Pages';
$lang['acl_all_public_o_0'] = 'None';
$lang['acl_all_public_o_1'] = 'Read (Default)';
$lang['acl_all_public_o_2'] = 'Edit';
$lang['acl_all_public_o_noacl'] = 'No automatic ACL';
$lang['acl_user_public'] = 'Permissions for @user group on Public Pages';
$lang['acl_user_public_o_0'] = 'None';
$lang['acl_user_public_o_1'] = 'Read (Default)';
$lang['acl_user_public_o_2'] = 'Edit';
$lang['acl_user_public_o_noacl'] = 'No automatic ACL';
$lang['templates_path'] = 'Path where templates will be stored (userhomepage_private.txt and userhomepage_public.txt). Examples: <code>data/pages/user</code> (makes templates editable within DokuWiki) or <code>lib/plugins/userhomepage</code> (to add more protection or centralize them in a farm setup).';
$lang['templatepath'] = 'Template path from version 3.0.4 if it was installed before. If this file exists, it will be used as default source for new private namespace start page template (clear the path if you don\'t want to).';
$lang['acl_all_templates'] = 'Permissions for @ALL group on Templates (if they are stored in <code>data/pages...</code>)';
$lang['acl_all_templates_o_0'] = 'None';
$lang['acl_all_templates_o_1'] = 'Read (Default)';
$lang['acl_all_templates_o_2'] = 'Edit';
$lang['acl_all_templates_o_noacl'] = 'No automatic ACL';
$lang['acl_user_templates'] = 'Permissions for @user group on Templates (if they are stored in <code>data/pages...</code>)';
$lang['acl_user_templates_o_0'] = 'None';
$lang['acl_user_templates_o_1'] = 'Read (Default)';
$lang['acl_user_templates_o_2'] = 'Edit';
$lang['acl_user_templates_o_noacl'] = 'No automatic ACL';

View File

@ -1,9 +1,9 @@
====== @NAME@ (@USER@) - Public Page ======
This public page (//@TARGETPUBLICPAGE@.txt//), as stated by it's name, **can be read by anyone but only you can edit it** (or a superuser)...
* You can introduce yourself, add links to your contributions in this wiki, tell a story or present your other works
* Please, don't create any other page in that namespace (//@TARGETPUBLICNS@//)
* Think about [[wp>http://en.wikipedia.org/wiki/Etiquette_in_technology|netiquette]] ;-)
Limitation:
Limitations:
* You can't create any other page in that namespace (//@TARGETPUBLICNS@//)
* Only a superuser can add a picture
Feel free to remove this paragraph (beside the title)...\\

View File

@ -10,22 +10,45 @@
$lang['use_name_string'] = 'Utiliser le nom complet de l\'utilisateurs au lieu du login pour son espace privé.';
$lang['use_start_page'] = 'Utiliser le nom de page d\'accueil du wiki pour celle de chaque espace privé (sinon le nom de l\'espace privé sera utilisé).';
$lang['users_namespace'] = 'Espace de nom sous lequel créer les espaces privés des utilisateurs.';
$lang['set_permissions'] = 'Configurer automatiquement les droits d\'accès à l\'espace choisit ci-dessus et donner tous les droits aux utilisateurs sur leur espace privé réspectif.';
$lang['set_permissions_others'] = 'Si l\'option [set_permissions] est activée, quels droits donner aux autres?';
$lang['set_permissions_others_o_0'] = 'Aucun';
$lang['set_permissions_others_o_1'] = 'Lecture';
$lang['set_permissions_others_o_2'] = 'Écriture';
$lang['set_permissions_others_o_4'] = 'Création';
$lang['set_permissions_others_o_8'] = 'Envoyer';
$lang['set_permissions_others_o_16'] = 'Effacer';
$lang['group_by_name'] = 'Grouper les espaces privés des utilisateurs par la première lettre de leur nom ?';
$lang['edit_before_create'] = 'Permettre aux utilisateurs d\'éditer la page d\'accueil de leur espace privé à sa création (fonctionnera uniquement si une page publique n\'est pas créée en même temps).';
$lang['acl_all_private'] = 'Droits d\'accès pour le groupe @ALL sur les Espaces Privés';
$lang['acl_all_private_o_0'] = 'Aucun (Défaut)';
$lang['acl_all_private_o_1'] = 'Lecture';
$lang['acl_all_private_o_2'] = 'Écriture';
$lang['acl_all_private_o_4'] = 'Création';
$lang['acl_all_private_o_8'] = 'Envoyer';
$lang['acl_all_private_o_16'] = 'Effacer';
$lang['acl_all_private_o_noacl'] = 'Pas de gestion automatique des droits';
$lang['acl_user_private'] = 'Permissions for @user group on Private Namespaces';
$lang['acl_user_private_o_0'] = 'Aucun (Défaut)';
$lang['acl_user_private_o_1'] = 'Lecture';
$lang['acl_user_private_o_2'] = 'Écriture';
$lang['acl_user_private_o_4'] = 'Création';
$lang['acl_user_private_o_8'] = 'Envoyer';
$lang['acl_user_private_o_16'] = 'Effacer';
$lang['acl_user_private_o_noacl'] = 'Pas de gestion automatique des droits';
$lang['create_public_page'] = 'Créer une page publique pour chaque utilisateur?';
$lang['public_pages_ns'] = 'Espace de nom sous lequel créer les pages publiques.';
$lang['set_permissions_public'] = 'Automatiquement configurer les droits d\'accès aux pages publiques (lecture pour tous mais seul l\'utilisateur peut modifier sa page).';
$lang['templates_path'] = 'Chemin où les modèles seront stockés (userhomepage_private.txt et userhomepage_public.txt). Examples: <code>data/pages/wiki</code> (permet d\'éditer les modèles depuis le wiki) ou <code>lib/plugins/userhomepage</code> (pour protéger les modèles ou les centraliser dans une ferme de wikis).';
$lang['set_permissions_templates'] = 'If templates are stored in <code>data/pages...</code>, automatically set following ACL for @ALL)';
$lang['set_permissions_templates_o_0'] = 'None';
$lang['set_permissions_templates_o_1'] = 'Read';
$lang['set_permissions_templates_o_2'] = 'Edit';
$lang['templatepath'] = 'Chemin vers le modèle de la version 3.0.4 si elle était installée précédement. Cette option n\'est là que pour permettre la rétro-compatibilité. Si le fichier existe, il sera utilisé comme source pour le modèle des pages d\'accueil des espaces privés (videz le chemin si vous ne le voulez pas).';
$lang['acl_all_public'] = 'Permissions for @ALL group on Public Pages';
$lang['acl_all_public_o_0'] = 'Aucun';
$lang['acl_all_public_o_1'] = 'Lecture (Défaut)';
$lang['acl_all_public_o_2'] = 'Écriture';
$lang['acl_all_public_o_noacl'] = 'Pas de gestion automatique des droits';
$lang['acl_user_public'] = 'Permissions for @user group on Public Pages';
$lang['acl_user_public_o_0'] = 'Aucun';
$lang['acl_user_public_o_1'] = 'Lecture (Défaut)';
$lang['acl_user_public_o_2'] = 'Écriture';
$lang['acl_user_public_o_noacl'] = 'Pas de gestion automatique des droits';
$lang['templates_path'] = 'Chemin où les modèles seront stockés (userhomepage_private.txt et userhomepage_public.txt). Exemples: <code>data/pages/wiki</code> (permet d\'éditer les modèles depuis le wiki) ou <code>lib/plugins/userhomepage</code> (pour plus de protecion ou les centraliser dans une ferme de wikis).';
$lang['templatepath'] = 'Chemin vers le modèle de la version 3.0.4 si elle était installée précédement. Si le fichier existe, il sera utilisé comme source pour le modèle des pages d\'accueil des espaces privés (videz le chemin si vous ne le souhaitez pas).';
$lang['acl_all_templates'] = 'Permissions for @ALL group on Templates (if they are stored in <code>data/pages...</code>)';
$lang['acl_all_templates_o_0'] = 'Aucun';
$lang['acl_all_templates_o_1'] = 'Lecture (Défaut)';
$lang['acl_all_templates_o_2'] = 'Écriture';
$lang['acl_all_templates_o_noacl'] = 'Pas de gestion automatique des droits';
$lang['acl_user_templates'] = 'Permissions for @user group on Templates (if they are stored in <code>data/pages...</code>)';
$lang['acl_user_templates_o_0'] = 'Aucun';
$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';