2005-11-05 04:08:14 +00:00
|
|
|
<?php
|
2005-12-23 21:57:26 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
2006-05-26 05:29:17 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-12-23 21:57:26 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2007-02-02 10:39:45 +00:00
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
2007-05-14 01:14:41 +00:00
|
|
|
* @subpackage cake.cake.console.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5012
|
2006-05-26 05:29:17 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-12-23 21:57:26 +00:00
|
|
|
*/
|
2007-05-02 21:19:22 +00:00
|
|
|
uses ('controller'.DS.'components'.DS.'acl', 'model'.DS.'db_acl');
|
2006-05-26 05:29:17 +00:00
|
|
|
/**
|
|
|
|
* @package cake
|
2007-05-13 20:18:57 +00:00
|
|
|
* @subpackage cake.cake.console.libs
|
2006-02-25 19:20:18 +00:00
|
|
|
*/
|
2007-05-12 21:18:07 +00:00
|
|
|
class AclShell extends Shell {
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var unknown_type
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $acl;
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var unknown_type
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $args;
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var unknown_type
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $dataSource = 'default';
|
2007-05-29 06:30:08 +00:00
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var unknown_type
|
2007-06-03 23:56:04 +00:00
|
|
|
*/
|
2007-05-29 06:30:08 +00:00
|
|
|
var $tasks = array('DbConfig');
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2007-06-04 07:21:17 +00:00
|
|
|
* override startup of the Shell
|
2007-05-04 00:25:04 +00:00
|
|
|
*
|
|
|
|
*/
|
2007-06-04 07:21:17 +00:00
|
|
|
function startup() {
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->dataSource = 'default';
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-05-02 21:19:22 +00:00
|
|
|
if (isset($this->params['datasource'])) {
|
|
|
|
$this->dataSource = $this->params['datasource'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ACL_CLASSNAME != 'DB_ACL') {
|
2006-05-26 05:29:17 +00:00
|
|
|
$out = "--------------------------------------------------\n";
|
|
|
|
$out .= "Error: Your current Cake configuration is set to \n";
|
|
|
|
$out .= "an ACL implementation other than DB. Please change \n";
|
|
|
|
$out .= "your core config to reflect your decision to use \n";
|
|
|
|
$out .= "DB_ACL before attempting to use this script.\n";
|
|
|
|
$out .= "--------------------------------------------------\n";
|
|
|
|
$out .= "Current ACL Classname: " . ACL_CLASSNAME . "\n";
|
|
|
|
$out .= "--------------------------------------------------\n";
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->err($out);
|
2006-05-26 05:29:17 +00:00
|
|
|
exit();
|
|
|
|
}
|
2007-05-04 03:49:53 +00:00
|
|
|
|
|
|
|
if($this->command && !in_array($this->command, array('help'))) {
|
2007-06-04 07:21:17 +00:00
|
|
|
if(!config('database')) {
|
|
|
|
$this->out("Your database configuration was not found. Take a moment to create one.\n");
|
|
|
|
$this->args = null;
|
|
|
|
return $this->DbConfig->execute();
|
2006-12-24 16:35:21 +00:00
|
|
|
}
|
|
|
|
require_once (CONFIGS.'database.php');
|
2007-02-18 13:25:37 +00:00
|
|
|
|
2007-05-04 03:49:53 +00:00
|
|
|
if(!in_array($this->command, array('initdb'))) {
|
2006-12-24 16:35:21 +00:00
|
|
|
$this->Acl = new AclComponent();
|
|
|
|
$this->db =& ConnectionManager::getDataSource($this->dataSource);
|
|
|
|
}
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2007-05-12 23:11:58 +00:00
|
|
|
* Override main() for help message hook
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function main() {
|
|
|
|
$out = "Available ACL commands:\n";
|
|
|
|
$out .= "\t - create\n";
|
|
|
|
$out .= "\t - delete\n";
|
|
|
|
$out .= "\t - setParent\n";
|
|
|
|
$out .= "\t - getPath\n";
|
|
|
|
$out .= "\t - grant\n";
|
|
|
|
$out .= "\t - deny\n";
|
|
|
|
$out .= "\t - inherit\n";
|
|
|
|
$out .= "\t - view\n";
|
|
|
|
$out .= "\t - initdb\n";
|
|
|
|
$out .= "\t - help\n\n";
|
|
|
|
$out .= "For help, run the 'help' command. For help on a specific command, run 'help <command>'";
|
|
|
|
$this->out($out);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Creates an ARO/ACO node
|
2006-02-18 23:42:21 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function create() {
|
2007-06-03 23:56:04 +00:00
|
|
|
|
2007-05-12 23:11:58 +00:00
|
|
|
$this->_checkArgs(3, 'create');
|
2006-05-26 05:29:17 +00:00
|
|
|
$this->checkNodeType();
|
|
|
|
extract($this->__dataVars());
|
2007-02-18 13:25:37 +00:00
|
|
|
|
2007-05-14 14:10:32 +00:00
|
|
|
$class = ucfirst($this->args[0]);
|
2007-05-12 23:11:58 +00:00
|
|
|
$object = new $class();
|
|
|
|
|
2007-05-14 14:10:32 +00:00
|
|
|
if (preg_match('/^([\w]+)\.(.*)$/', $this->args[1], $matches) && count($matches) == 3) {
|
2007-05-12 23:11:58 +00:00
|
|
|
$parent = array(
|
|
|
|
'model' => $matches[1],
|
|
|
|
'foreign_key' => $matches[2],
|
|
|
|
);
|
2007-05-02 21:19:22 +00:00
|
|
|
} else {
|
2007-05-14 14:10:32 +00:00
|
|
|
$parent = $this->args[1];
|
2007-05-02 21:19:22 +00:00
|
|
|
}
|
2007-05-04 03:49:53 +00:00
|
|
|
|
2007-05-12 23:11:58 +00:00
|
|
|
if (!empty($parent) && $parent != '/' && $parent != 'root') {
|
|
|
|
@$parent = $object->node($parent);
|
|
|
|
if (empty($parent)) {
|
2007-05-14 14:10:32 +00:00
|
|
|
$this->err('Could not find parent node using reference "' . $this->args[1] . '"');
|
2007-05-12 23:11:58 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
$parent = Set::extract($parent, "0.{$class}.id");
|
|
|
|
}
|
2007-05-04 03:49:53 +00:00
|
|
|
} else {
|
|
|
|
$parent = null;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-05-12 23:11:58 +00:00
|
|
|
|
2007-05-14 14:10:32 +00:00
|
|
|
if (preg_match('/^([\w]+)\.(.*)$/', $this->args[2], $matches) && count($matches) == 3) {
|
2007-05-12 23:11:58 +00:00
|
|
|
$data = array(
|
|
|
|
'model' => $matches[1],
|
|
|
|
'foreign_key' => $matches[2],
|
|
|
|
);
|
|
|
|
} else {
|
2007-05-14 14:10:32 +00:00
|
|
|
$data = array('alias' => $this->args[2]);
|
2007-05-12 23:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$data['parent_id'] = $parent;
|
|
|
|
$object->create();
|
|
|
|
|
|
|
|
if($object->save($data)) {
|
2007-05-14 14:10:32 +00:00
|
|
|
$this->out("New $class '".$this->args[2]."' created.\n\n");
|
2007-05-12 23:11:58 +00:00
|
|
|
} else {
|
2007-05-14 14:10:32 +00:00
|
|
|
$this->err("There was a problem creating a new $class '".$this->args[2]."'.");
|
2007-05-12 23:11:58 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function delete() {
|
2007-05-04 20:12:08 +00:00
|
|
|
$this->_checkArgs(2, 'delete');
|
2006-05-26 05:29:17 +00:00
|
|
|
$this->checkNodeType();
|
|
|
|
extract($this->__dataVars());
|
2007-02-01 17:13:12 +00:00
|
|
|
if(!$this->Acl->{$class}->delete($this->args[1])) {
|
2007-05-14 14:10:32 +00:00
|
|
|
$this->error("Node Not Deleted", "There was an error deleting the ".$class.". Check that the node exists.\n");
|
2007-02-01 17:13:12 +00:00
|
|
|
}
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->out("{$class} deleted.\n\n");
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-12-23 21:57:26 +00:00
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function setParent() {
|
2007-05-04 20:12:08 +00:00
|
|
|
$this->_checkArgs(3, 'setParent');
|
2006-05-26 05:29:17 +00:00
|
|
|
$this->checkNodeType();
|
|
|
|
extract($this->__dataVars());
|
2006-12-24 16:35:21 +00:00
|
|
|
if (!$this->Acl->{$class}->setParent($this->args[2], $this->args[1])){
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->out("Error in setting new parent. Please make sure the parent node exists, and is not a descendant of the node specified.\n");
|
2006-05-26 05:29:17 +00:00
|
|
|
} else {
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->out("Node parent set to ".$this->args[2]."\n\n");
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function getPath() {
|
2007-05-04 20:12:08 +00:00
|
|
|
$this->_checkArgs(2, 'getPath');
|
2006-05-26 05:29:17 +00:00
|
|
|
$this->checkNodeType();
|
|
|
|
extract($this->__dataVars());
|
2007-05-29 06:30:08 +00:00
|
|
|
$id = (is_numeric($this->args[1])) ? intval($this->args[1]) : $this->args[1];
|
2006-12-24 16:35:21 +00:00
|
|
|
$nodes = $this->Acl->{$class}->getPath($id);
|
2007-02-01 17:13:12 +00:00
|
|
|
if (empty($nodes)) {
|
2007-05-14 14:10:32 +00:00
|
|
|
$this->error("Supplied Node '".$this->args[1]."' not found", "No tree returned.");
|
2007-02-01 17:13:12 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
for ($i = 0; $i < count($nodes); $i++) {
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->out(str_repeat(' ', $i) . "[" . $nodes[$i][$class]['id'] . "]" . $nodes[$i][$class]['alias'] . "\n");
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function grant() {
|
2007-05-04 20:12:08 +00:00
|
|
|
$this->_checkArgs(3, 'grant');
|
2006-05-26 05:29:17 +00:00
|
|
|
//add existence checks for nodes involved
|
2006-12-24 16:35:21 +00:00
|
|
|
$aro = (is_numeric($this->args[0])) ? intval($this->args[0]) : $this->args[0];
|
|
|
|
$aco = (is_numeric($this->args[1])) ? intval($this->args[1]) : $this->args[1];
|
2007-06-10 17:38:50 +00:00
|
|
|
if($this->Acl->allow($aro, $aco, $this->args[2])) {
|
|
|
|
$this->out("Permission granted.\n");
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function deny() {
|
2007-05-04 20:12:08 +00:00
|
|
|
$this->_checkArgs(3, 'deny');
|
2006-05-26 05:29:17 +00:00
|
|
|
//add existence checks for nodes involved
|
2006-12-24 16:35:21 +00:00
|
|
|
$aro = (is_numeric($this->args[0])) ? intval($this->args[0]) : $this->args[0];
|
|
|
|
$aco = (is_numeric($this->args[1])) ? intval($this->args[1]) : $this->args[1];
|
2007-01-31 23:04:47 +00:00
|
|
|
$this->Acl->deny($aro, $aco, $this->args[2]);
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->out("Requested permission successfully denied.\n");
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*/
|
2006-12-24 16:35:21 +00:00
|
|
|
function inherit() {
|
2007-05-04 20:12:08 +00:00
|
|
|
$this->_checkArgs(3, 'inherit');
|
2007-01-31 23:04:47 +00:00
|
|
|
$aro = (is_numeric($this->args[0])) ? intval($this->args[0]) : $this->args[0];
|
|
|
|
$aco = (is_numeric($this->args[1])) ? intval($this->args[1]) : $this->args[1];
|
|
|
|
$this->Acl->inherit($aro, $aco, $this->args[2]);
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->out("Requested permission successfully inherited.\n");
|
2006-12-24 16:35:21 +00:00
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function view() {
|
2007-05-04 20:12:08 +00:00
|
|
|
$this->_checkArgs(1, 'view');
|
2006-05-26 05:29:17 +00:00
|
|
|
$this->checkNodeType();
|
|
|
|
extract($this->__dataVars());
|
2007-05-14 14:10:32 +00:00
|
|
|
if (isset($this->args[1]) && !is_null($this->args[1])) {
|
2007-01-31 23:04:47 +00:00
|
|
|
$conditions = $this->Acl->{$class}->_resolveID($this->args[1]);
|
|
|
|
} else {
|
|
|
|
$conditions = null;
|
|
|
|
}
|
2006-12-24 16:35:21 +00:00
|
|
|
$nodes = $this->Acl->{$class}->findAll($conditions, null, 'lft ASC');
|
2007-02-01 17:13:12 +00:00
|
|
|
if (empty($nodes)) {
|
2007-05-14 14:10:32 +00:00
|
|
|
$this->error($this->args[1]." not found", "No tree returned.");
|
2007-02-01 17:13:12 +00:00
|
|
|
}
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->out($class . " tree:");
|
2007-05-14 14:10:32 +00:00
|
|
|
$this->hr();
|
|
|
|
$nodeCount = count($nodes);
|
|
|
|
$right = $left = array();
|
|
|
|
for($i = 0; $i < $nodeCount; $i++) {
|
|
|
|
$count = 0;
|
|
|
|
$right[$i] = $nodes[$i][$class]['rght'];
|
|
|
|
$left[$i] = $nodes[$i][$class]['lft'];
|
2007-06-03 23:56:04 +00:00
|
|
|
if(isset($left[$i]) && isset($left[$i-1]) && $left[$i] > $left[$i-1]) {
|
2007-05-14 14:10:32 +00:00
|
|
|
array_pop($left);
|
2007-06-03 23:56:04 +00:00
|
|
|
$count = count($left);
|
2007-05-14 14:10:32 +00:00
|
|
|
}
|
|
|
|
if(isset($right[$i]) && isset($right[$i-1]) && $right[$i] < $right[$i-1]) {
|
|
|
|
array_pop($right);
|
|
|
|
$count = count($right);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-06-03 23:56:04 +00:00
|
|
|
|
2007-05-14 14:10:32 +00:00
|
|
|
$this->out(str_repeat(' ', $count) . "[" . $nodes[$i][$class]['id'] . "]" . $nodes[$i][$class]['alias']."\n");
|
2006-05-26 05:29:17 +00:00
|
|
|
$right[] = $nodes[$i][$class]['rght'];
|
|
|
|
}
|
2007-05-14 14:10:32 +00:00
|
|
|
$this->hr();
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function initdb() {
|
|
|
|
$db =& ConnectionManager::getDataSource($this->dataSource);
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->out("Initializing Database...\n");
|
|
|
|
$this->out("Creating access control objects table (acos)...\n");
|
2006-08-01 02:19:34 +00:00
|
|
|
$sql = " CREATE TABLE ".$db->fullTableName('acos')." (
|
2006-05-26 05:29:17 +00:00
|
|
|
".$db->name('id')." ".$db->column($db->columns['primary_key']).",
|
2007-05-04 04:37:25 +00:00
|
|
|
".$db->name('parent_id')." ".$db->column($db->columns['integer'])." default NULL,
|
2007-05-06 03:32:06 +00:00
|
|
|
".$db->name('model')." ".$db->column($db->columns['string'])." default '' NOT NULL,
|
2007-05-04 04:37:25 +00:00
|
|
|
".$db->name('foreign_key')." ".$db->column($db->columns['integer'])." default NULL,
|
2007-05-06 03:32:06 +00:00
|
|
|
".$db->name('alias')." ".$db->column($db->columns['string'])." default '' NOT NULL,
|
2006-05-26 05:29:17 +00:00
|
|
|
".$db->name('lft')." ".$db->column($db->columns['integer'])." default NULL,
|
|
|
|
".$db->name('rght')." ".$db->column($db->columns['integer'])." default NULL,
|
|
|
|
PRIMARY KEY (".$db->name('id').")
|
2007-05-06 03:32:06 +00:00
|
|
|
)";
|
2006-08-01 02:47:40 +00:00
|
|
|
if ($db->query($sql) === false) {
|
|
|
|
die("Error: " . $db->lastError() . "\n\n");
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->out("Creating access request objects table (aros)...\n");
|
2006-08-01 02:19:34 +00:00
|
|
|
$sql2 = "CREATE TABLE ".$db->fullTableName('aros')." (
|
2006-05-26 05:29:17 +00:00
|
|
|
".$db->name('id')." ".$db->column($db->columns['primary_key']).",
|
2007-05-04 04:37:25 +00:00
|
|
|
".$db->name('parent_id')." ".$db->column($db->columns['integer'])." default NULL,
|
2007-05-06 03:32:06 +00:00
|
|
|
".$db->name('model')." ".$db->column($db->columns['string'])." default '' NOT NULL,
|
2006-10-28 04:40:30 +00:00
|
|
|
".$db->name('foreign_key')." ".$db->column($db->columns['integer'])." default NULL,
|
2007-05-06 03:32:06 +00:00
|
|
|
".$db->name('alias')." ".$db->column($db->columns['string'])." default '' NOT NULL,
|
2006-05-26 05:29:17 +00:00
|
|
|
".$db->name('lft')." ".$db->column($db->columns['integer'])." default NULL,
|
|
|
|
".$db->name('rght')." ".$db->column($db->columns['integer'])." default NULL,
|
|
|
|
PRIMARY KEY (".$db->name('id').")
|
2007-05-06 03:32:06 +00:00
|
|
|
)";
|
2006-10-26 16:29:10 +00:00
|
|
|
if ($db->query($sql2) === false) {
|
2006-08-01 02:47:40 +00:00
|
|
|
die("Error: " . $db->lastError() . "\n\n");
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->out("Creating relationships table (aros_acos)...\n");
|
2006-08-01 02:19:34 +00:00
|
|
|
$sql3 = "CREATE TABLE ".$db->fullTableName('aros_acos')." (
|
2006-05-26 05:29:17 +00:00
|
|
|
".$db->name('id')." ".$db->column($db->columns['primary_key']).",
|
|
|
|
".$db->name('aro_id')." ".$db->column($db->columns['integer'])." default NULL,
|
|
|
|
".$db->name('aco_id')." ".$db->column($db->columns['integer'])." default NULL,
|
2007-05-06 03:32:06 +00:00
|
|
|
".$db->name('_create')." ".$db->column($db->columns['integer'])." default '0' NOT NULL,
|
|
|
|
".$db->name('_read')." ".$db->column($db->columns['integer'])." default '0' NOT NULL,
|
|
|
|
".$db->name('_update')." ".$db->column($db->columns['integer'])." default '0' NOT NULL,
|
|
|
|
".$db->name('_delete')." ".$db->column($db->columns['integer'])." default '0' NOT NULL,
|
2006-05-26 05:29:17 +00:00
|
|
|
PRIMARY KEY (".$db->name('id').")
|
2007-05-06 03:32:06 +00:00
|
|
|
)";
|
2006-08-01 02:47:40 +00:00
|
|
|
if ($db->query($sql3) === false) {
|
|
|
|
die("Error: " . $db->lastError() . "\n\n");
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-05-02 21:19:22 +00:00
|
|
|
$this->out("\nDone.\n");
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-11-03 06:01:48 +00:00
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function help() {
|
2007-05-12 23:11:58 +00:00
|
|
|
$head = "Usage: cake acl <command> <arg1> <arg2>...\n";
|
|
|
|
$head .= "-----------------------------------------------\n";
|
|
|
|
$head .= "Commands:\n\n";
|
|
|
|
|
|
|
|
$commands = array(
|
|
|
|
'create' => "\tcreate aro|aco <parent> <node>\n" .
|
|
|
|
"\t\tCreates a new ACL object <node> under the parent specified by <parent>, an id/alias.\n" .
|
|
|
|
"\t\tThe <parent> and <node> references can be in one of the following formats:\n" .
|
|
|
|
"\t\t\t- <model>.<id> - The node will be bound to a specific record of the given model\n" .
|
|
|
|
"\t\t\t- <alias> - The node will be given a string alias (or path, in the case of <parent>),\n" .
|
|
|
|
"\t\t\t i.e. 'John'. When used with <parent>, this takes the form of an alias path,\n" .
|
2007-05-14 02:19:26 +00:00
|
|
|
"\t\t\t i.e. <group>/<subgroup>/<parent>.\n" .
|
|
|
|
"\t\tTo add a node at the root level, enter 'root' or '/' as the <parent> parameter.",
|
2007-05-12 23:11:58 +00:00
|
|
|
|
|
|
|
'delete' => "\tdelete aro|aco <node>\n" .
|
|
|
|
"\t\tDeletes the ACL object with the given <node> reference (see 'create' for info on node references).\n",
|
|
|
|
|
|
|
|
'setparent' => "\tsetParent aro|aco <node> <parent>\n" .
|
|
|
|
"\t\tMoves the ACL object specified by <node> beneath the parent ACL object specified by <parent>.\n",
|
|
|
|
|
|
|
|
'getpath' => "\tgetPath aro|aco <node>\n" .
|
|
|
|
"\t\tReturns the path to the ACL object specified by <node>. This command is\n" .
|
|
|
|
"\t\tis useful in determining the inhertiance of permissions for a certain\n" .
|
|
|
|
"\t\tobject in the tree.\n",
|
|
|
|
|
2007-06-10 17:38:50 +00:00
|
|
|
'grant' => "\tgrant <aro_id> <aco_id> [<aco_action>] or '*' (quotes required)\n" .
|
2007-05-12 23:11:58 +00:00
|
|
|
"\t\tUse this command to grant ACL permissions. Once executed, the ARO\n" .
|
|
|
|
"\t\tspecified (and its children, if any) will have ALLOW access to the\n" .
|
|
|
|
"\t\tspecified ACO action (and the ACO's children, if any).\n",
|
|
|
|
|
|
|
|
'deny' => "\tdeny <aro_id> <aco_id> [<aco_action>]\n" .
|
|
|
|
"\t\tUse this command to deny ACL permissions. Once executed, the ARO\n" .
|
|
|
|
"\t\tspecified (and its children, if any) will have DENY access to the\n" .
|
|
|
|
"\t\tspecified ACO action (and the ACO's children, if any).\n",
|
|
|
|
|
|
|
|
'inherit' => "\tinherit <aro_id> <aco_id> [<aco_action>]\n" .
|
|
|
|
"\t\tUse this command to force a child ARO object to inherit its\n" .
|
|
|
|
"\t\tpermissions settings from its parent.\n",
|
|
|
|
|
|
|
|
'view' => "\tview aro|aco [<node>]\n" .
|
|
|
|
"\t\tThe view command will return the ARO or ACO tree. The optional\n" .
|
|
|
|
"\t\tid/alias parameter allows you to return only a portion of the requested\n" .
|
|
|
|
"\t\ttree.\n",
|
|
|
|
|
|
|
|
'initdb' => "\tinitdb\n".
|
|
|
|
"\t\tUse this command to create the database tables needed to use DB ACL.\n",
|
|
|
|
|
|
|
|
'help' => "\thelp [<command>]\n" .
|
|
|
|
"\t\tDisplays this help message, or a message on a specific command.\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->out($head);
|
|
|
|
if (!isset($this->args[1])) {
|
|
|
|
foreach ($commands as $cmd) {
|
|
|
|
$this->out("{$cmd}\n\n");
|
|
|
|
}
|
|
|
|
} elseif (isset($commands[low($this->args[1])])) {
|
2007-05-14 02:19:26 +00:00
|
|
|
$this->out($commands[low($this->args[1])] . "\n\n");
|
2007-05-12 23:11:58 +00:00
|
|
|
} else {
|
|
|
|
$this->out("Command '" . $this->args[1] . "' not found");
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function checkNodeType() {
|
2007-05-14 14:10:32 +00:00
|
|
|
if(!isset($this->args[0])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($this->args[0] != 'aco' && $this->args[0] != 'aro') {
|
|
|
|
$this->error("Missing/Unknown node type: '".$this->args[1]."'", 'Please specify which ACL object type you wish to create.');
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $type
|
|
|
|
* @param unknown_type $id
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function nodeExists($type, $id) {
|
2007-05-02 21:19:22 +00:00
|
|
|
//$this->out("Check to see if $type with ID = $id exists...\n");
|
2006-05-26 05:29:17 +00:00
|
|
|
extract($this->__dataVars($type));
|
2007-02-01 17:13:12 +00:00
|
|
|
$conditions = $this->Acl->{$class}->_resolveID($id);
|
|
|
|
$possibility = $this->Acl->{$class}->findAll($conditions);
|
|
|
|
return $possibility;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-12-23 21:57:26 +00:00
|
|
|
|
2005-12-27 03:33:44 +00:00
|
|
|
/**
|
2006-02-18 23:42:21 +00:00
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $type
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function __dataVars($type = null) {
|
|
|
|
if ($type == null) {
|
|
|
|
$type = $this->args[0];
|
|
|
|
}
|
|
|
|
$vars = array();
|
|
|
|
$class = ucwords($type);
|
2006-10-28 04:40:30 +00:00
|
|
|
$vars['secondary_id'] = ($class == 'aro' ? 'foreign_key' : 'object_id');
|
2006-05-26 05:29:17 +00:00
|
|
|
$vars['data_name'] = $type;
|
|
|
|
$vars['table_name'] = $type . 's';
|
|
|
|
$vars['class'] = $class;
|
|
|
|
return $vars;
|
|
|
|
}
|
2005-11-05 04:08:14 +00:00
|
|
|
}
|
2007-05-02 21:19:22 +00:00
|
|
|
|
2007-05-06 03:32:06 +00:00
|
|
|
?>
|