Exemplo n.º 1
0
 function setaclPages(&$request, $pages, $acl)
 {
     $ul = HTML::ul();
     $count = 0;
     $dbi =& $request->_dbi;
     // check new_group and new_perm
     if (isset($acl['_add_group'])) {
         //add groups with perm
         foreach ($acl['_add_group'] as $access => $dummy) {
             $group = $acl['_new_group'][$access];
             $acl[$access][$group] = isset($acl['_new_perm'][$access]) ? 1 : 0;
         }
         unset($acl['_add_group']);
     }
     unset($acl['_new_group']);
     unset($acl['_new_perm']);
     if (isset($acl['_del_group'])) {
         //del groups with perm
         foreach ($acl['_del_group'] as $access => $del) {
             while (list($group, $dummy) = each($del)) {
                 unset($acl[$access][$group]);
             }
         }
         unset($acl['_del_group']);
     }
     if ($perm = new PagePermission($acl)) {
         $perm->sanify();
         foreach ($pages as $pagename) {
             // check if unchanged? we need a deep array_equal
             $page = $dbi->getPage($pagename);
             $oldperm = getPagePermissions($page);
             if ($oldperm) {
                 $oldperm->sanify();
             }
             if ($oldperm and $perm->equal($oldperm->perm)) {
                 // (serialize($oldperm->perm) == serialize($perm->perm))
                 $ul->pushContent(HTML::li(fmt("ACL not changed for page '%s'.", $pagename)));
             } elseif (mayAccessPage('change', $pagename)) {
                 setPagePermissions($page, $perm);
                 $ul->pushContent(HTML::li(fmt("ACL changed for page '%s'.", $pagename)));
                 $count++;
             } else {
                 $ul->pushContent(HTML::li(fmt("Access denied to change page '%s'.", $pagename)));
             }
         }
     } else {
         $ul->pushContent(HTML::li(fmt("Invalid ACL")));
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages have been changed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages changed.")));
     }
 }
Exemplo n.º 2
0
 function chmodPages(&$dbi, &$request, $pages, $permstring)
 {
     $ul = HTML::ul();
     $count = 0;
     $acl = chmodHelper($permstring);
     if ($perm = new PagePermission($acl)) {
         foreach ($pages as $name) {
             if ($perm->store($dbi->getPage($name))) {
                 $ul->pushContent(HTML::li(fmt("chmod page '%s' to '%s'.", $name, $permstring)));
                 $count++;
             } else {
                 $ul->pushContent(HTML::li(fmt("Couldn't chmod page '%s' to '%s'.", $name, $permstring)));
             }
         }
     } else {
         $ul->pushContent(HTML::li(fmt("Invalid chmod string")));
     }
     if ($count) {
         $dbi->touch();
         return HTML($ul, HTML::p(fmt("%s pages have been changed.", $count)));
     } else {
         return HTML($ul, HTML::p(fmt("No pages changed.")));
     }
 }
Exemplo n.º 3
0
 function setaclPages(&$request, $pages, $acl)
 {
     $result = HTML::div();
     $count = 0;
     $dbi =& $request->_dbi;
     // check new_group and new_perm
     if (isset($acl['_add_group'])) {
         //add groups with perm
         foreach ($acl['_add_group'] as $access => $dummy) {
             $group = $acl['_new_group'][$access];
             $acl[$access][$group] = isset($acl['_new_perm'][$access]) ? 1 : 0;
         }
         unset($acl['_add_group']);
     }
     unset($acl['_new_group']);
     unset($acl['_new_perm']);
     if (isset($acl['_del_group'])) {
         //del groups with perm
         foreach ($acl['_del_group'] as $access => $del) {
             while (list($group, $dummy) = each($del)) {
                 unset($acl[$access][$group]);
             }
         }
         unset($acl['_del_group']);
     }
     if ($perm = new PagePermission($acl)) {
         $perm->sanify();
         foreach ($pages as $pagename) {
             // check if unchanged? we need a deep array_equal
             $page = $dbi->getPage($pagename);
             $oldperm = getPagePermissions($page);
             if ($oldperm) {
                 $oldperm->sanify();
             }
             if ($oldperm and $perm->equal($oldperm->perm)) {
                 $result->setAttr('class', 'error');
                 $result->pushContent(HTML::p(fmt("ACL not changed for page '%s'.", $pagename)));
             } elseif (mayAccessPage('change', $pagename)) {
                 setPagePermissions($page, $perm);
                 $result->setAttr('class', 'feedback');
                 $result->pushContent(HTML::p(fmt("ACL changed for page '%s'", $pagename)));
                 $result->pushContent(HTML::p(fmt("from '%s'", $oldperm ? $oldperm->asAclLines() : "None")));
                 $result->pushContent(HTML::p(fmt("to '%s'.", $perm->asAclLines())));
                 // Create new revision so that ACL change appears in history.
                 $current = $page->getCurrentRevision();
                 $version = $current->getVersion();
                 $meta = $current->_data;
                 $text = $current->getPackedContent();
                 $meta['summary'] = sprintf(_("ACL changed for page '%s' from '%s' to '%s'."), $pagename, $oldperm ? $oldperm->asAclLines() : "None", $perm->asAclLines());
                 $meta['is_minor_edit'] = 1;
                 $meta['author'] = $request->_user->UserName();
                 unset($meta['mtime']);
                 // force new date
                 $page->save($text, $version + 1, $meta);
                 $count++;
             } else {
                 $result->setAttr('class', 'error');
                 $result->pushContent(HTML::p(fmt("Access denied to change page '%s'.", $pagename)));
             }
         }
     } else {
         $result->pushContent(HTML::p(fmt("Invalid ACL")));
     }
     if ($count) {
         $dbi->touch();
         $result->setAttr('class', 'feedback');
         if ($count > 1) {
             $result->pushContent(HTML::p(fmt("%s pages have been changed.", $count)));
         }
     } else {
         $result->setAttr('class', 'error');
         $result->pushContent(HTML::p(fmt("No pages changed.")));
     }
     return $result;
 }
Exemplo n.º 4
0
function ParseMimeifiedPerm($string)
{
    if (!class_exists('PagePermission')) {
        return '';
    }
    $hash = array();
    foreach (split(";", trim($string)) as $accessgroup) {
        list($access, $groupstring) = split(":", trim($accessgroup));
        $access = trim($access);
        $groups = split(",", trim($groupstring));
        foreach ($groups as $group) {
            $group = trim($group);
            $bool = (bool) (substr($group, 0, 1) != '-');
            if (substr($group, 0, 1) == '-' or substr($group, 0, 1) == '+') {
                $group = substr($group, 1);
            }
            $hash[$access][$group] = $bool;
        }
    }
    $perm = new PagePermission($hash);
    $perm->sanify();
    return serialize($perm->perm);
}
Exemplo n.º 5
0
 /**
  *  dead code. not needed inside the object. see getPagePermissions($page)
  */
 function retrieve($page)
 {
     $hash = $page->get('perm');
     if ($hash) {
         // hash => object
         $perm = new PagePermission(unserialize($hash));
     } else {
         $perm = new PagePermission();
     }
     $perm->sanify();
     return $perm;
 }