⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admin.js

📁 Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是供中,大型企业来管理其发布在互连网
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*
* Copyright 2001-2007 Hippo (www.hippo.nl)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
importClass(Packages.nl.hippo.cocoon.webdav.Property);
importClass(Packages.nl.hippo.cocoon.webdav.WebDAVHelper);
importClass(Packages.org.apache.webdav.lib.Ace);
importClass(Packages.org.apache.webdav.lib.Lock);
importClass(Packages.org.apache.webdav.lib.Privilege);
importClass(Packages.org.apache.webdav.lib.methods.DepthSupport);
importClass(java.util.ArrayList);
importClass(java.util.Collections);
importClass(java.lang.Integer);
importClass(Packages.nl.hippo.cocoon.repository.RepositoryManager);
importClass(Packages.org.apache.cocoon.caching.EventAwareManager);
importClass(Packages.nl.hippo.cms.contentmodel.WebdavRepository);


cocoon.load("site:/login/login.js");

function view() {
  var uri = cocoon.parameters.uri;

  if (cocoon.session.httpstate == undefined) {
    login();
    cocoon.redirectTo("/slide/admin/views/" + uri);
  }
  else {
    cocoon.sendPage("/slide/admin/" + uri);
  }
}

// ---------------------------------------------- permission management

function addAce() {
  var path         = cocoon.request.getParameter("path");
  var uri          = cocoon.request.getParameter("uri");
  var principal    = cocoon.request.getParameter("principal");
  var privilege    = cocoon.request.getParameter("privilege");
  var deny         = cocoon.request.getParameter("grant.x") == null;
  var host         = cocoon.parameters.host;
  var port         = cocoon.parameters.port;

  var state = authentication.getHttpState();

  var ace = new Ace(principal);
  ace.setNegative(deny);
  var indexOfPoundSign = privilege.indexOf('#');
  if (indexOfPoundSign >= 0)
  {
    var privilegeNamespaceUri = privilege.substring(0, indexOfPoundSign);
    var privilegeLocalName = privilege.substring(indexOfPoundSign + 1);
    ace.addPrivilege(new Privilege(privilegeNamespaceUri, privilegeLocalName, null));

    var status = WebDAVHelper.addAce("webdav://" + host + ":" + port + uri, ace, state);
  }

  cocoon.sendPage("/slide/admin/result/dashboardpermissions", {status: status});
}

function editAce() {
  var path         = cocoon.request.path;
  var aceIndex     = cocoon.request.aceIndex;
  var uri          = cocoon.request.uri;
  var host         = cocoon.parameters.host;
  var port         = cocoon.parameters.port;

  var state = authentication.getHttpState();

  var status = null;
  if (cocoon.request.getParameter("deletePermission.x") != null) {
    status = WebDAVHelper.removeAce("webdav://" + host + ":" + port + uri, aceIndex, state);
  }
  else if (cocoon.request.getParameter("movePermissionUp.x") != null) {
    status = WebDAVHelper.moveUpAce("webdav://" + host + ":" + port + uri, aceIndex, state);
  }
  else if (cocoon.request.getParameter("movePermissionDown.x") != null) {
    status = WebDAVHelper.moveDownAce("webdav://" + host + ":" + port + uri, aceIndex, state);
  }

    cocoon.sendPage("/slide/admin/result/dashboardpermissions", {status: status});
}

// ---------------------------------------------- lock management

function lock() {
  var path         = cocoon.request.path;
  var owner        = cocoon.request.owner;
  var type         = cocoon.request.type;
  var expiration   = Integer.parseInt(cocoon.request.expiration);
  var scope        = cocoon.request.exclusive == 'true' ? Lock.SCOPE_EXCLUSIVE : Lock.SCOPE_SHARED;
  var depth        = cocoon.request.inheritable == 'true' ? DepthSupport.DEPTH_INFINITY : DepthSupport.DEPTH_0;
  var root         = cocoon.parameters.root;

  var state = authentication.getHttpState();

  var uri = root + path;
  var lock = new Lock(scope, Lock.TYPE_WRITE, depth, owner, expiration, null);

  var status = WebDAVHelper.lock(uri, lock, state);

  //cocoon.redirectTo("/slide/admin/views/locks" + path);
  cocoon.sendPage("/slide/admin/result/dashboardlocks", {status: status});

}

function unlock() {
  var path         = cocoon.request.path;
  var lockid       = cocoon.request.lockid;
  var root         = cocoon.parameters.root;

  var state = authentication.getHttpState();
  var uri = root + path;

  var status = WebDAVHelper.unlock(uri, lockid, state);

  //cocoon.redirectTo("/slide/admin/views/locks" + path);
  cocoon.sendPage("/slide/admin/result/dashboardlocks", {status: status});

}

// ---------------------------------------------- user management


function adduser() {
  try{
  var host = cocoon.parameters.host;
  var port = cocoon.parameters.port;
  var webdavUri = "webdav://" + host + ":" + port;

  var username  = cocoon.request.username;
  var fullname  = cocoon.request.fullname;
  var email     = cocoon.request.email;
  var password     = cocoon.request.password;

  var state     = authentication.getHttpState();
  var status    = null;

  var users     = cocoon.parameters.users;
  var roles     = cocoon.parameters.roles;

  var useruri   = users + "/" + username;

  var namespace = "DAV:";
  var ace       = null;

  //create user
  WebDAVHelper.mkcol(useruri, state);
  chpwd(useruri, password);

  //check if users role exists and if not create it
  checkIfUsersRoleExists();

  //add read deny for group users on new member
/*  var usersPrincipal = roles.substring(webdavUri.length, roles.length) + "/users";
  ace = new Ace(usersPrincipal);
  ace.setNegative(true);
  ace.addPrivilege(new Privilege(namespace, "read", null));
  status = WebDAVHelper.addAce(useruri, ace, state);
*/  

  //add read/write privilige for group marked as manager
  var principal = cocoon.request.roleuri;
  ace = new Ace(principal);
  ace.addPrivilege(new Privilege(namespace, "read", null));
  ace.addPrivilege(new Privilege(namespace, "write", null));
  status = WebDAVHelper.addAce(useruri, ace, state);

  //add read self to member
  principal = "self";
  ace = new Ace(principal);
  ace.addPrivilege(new Privilege(namespace, "read", null));
  ace.addPrivilege(new Privilege(namespace, "write", null));
  status = WebDAVHelper.addAce(useruri, ace, state);

  //add deny write-acl on self 
  principal = "self";
  ace = new Ace(principal);
  ace.setNegative(true);
  ace.addPrivilege(new Privilege(namespace, "write-acl", null));
  status = WebDAVHelper.addAce(useruri, ace, state);


  //add new member to group users
  status = WebDAVHelper.addMember(roles+"/users", useruri.substring(webdavUri.length, useruri.length), state);

  var namespace="http://hippo.nl/cms/1.0";
  var name="fullname";
  var value=fullname;

  var set = new ArrayList();
  set.add(new Property("property", namespace, name, value));
  set.add(new Property("property", namespace, "emailAddress", email));

  status = WebDAVHelper.proppatch(useruri, set, null, state);
  var emanager = cocoon.getComponent(EventAwareManager.ROLE);
  WebdavRepository.fireEvent(emanager,useruri,false);

  }catch(e){
    print(e);
  }
  cocoon.sendPage("/slide/admin/result/dashboardusers")
}

function editself() {

  var username = cocoon.request.username;
  var fullname = cocoon.request.fullname;
  var email = cocoon.request.email;
  var oldPassword = cocoon.request.oldpassword;
  var newPassword1 = cocoon.request.newpassword1;
  var newPassword2 = cocoon.request.newpassword2;
  var users    = cocoon.parameters.users;

  var state = authentication.getHttpState();
  var useruri = users + "/" + username;

  var cmsNamespace="http://hippo.nl/cms/1.0";
  var slideNamespace="http://jakarta.apache.org/slide/";

  var name="fullname";
  var value=fullname;
  var msg = "";

  var set = new ArrayList();
  set.add(new Property("property", cmsNamespace, name, value));
  set.add(new Property("property", cmsNamespace, "emailAddress", email));

  if(oldPassword.length()>0){
    if(newPassword1.length()>0){
      if(newPassword1.equals(newPassword2)){
        var currentPassword = WebDAVHelper.propfindAsString(useruri, slideNamespace, "password", state);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -