acl.php.svn-base

来自「j2me is based on j2mepolish, client & se」· SVN-BASE 代码 · 共 804 行 · 第 1/2 页

SVN-BASE
804
字号
#!/usr/bin/php -q<?php/* SVN FILE: $Id: acl.php 4202 2006-12-25 12:06:13Z phpnut $ *//** * Short description for file. * * Long description for file * * PHP versions 4 and 5 * * CakePHP :  Rapid Development Framework <http://www.cakephp.org/> * Copyright (c)	2006, Cake Software Foundation, Inc. *								1785 E. Sahara Avenue, Suite 490-204 *								Las Vegas, Nevada 89104 * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @filesource * @copyright		Copyright (c) 2006, Cake Software Foundation, Inc. * @link				http://www.cakefoundation.org/projects/info/cakephp CakePHP Project * @package			cake * @subpackage		cake.cake.scripts * @since			CakePHP v 0.10.0.1232 * @version			$Revision: 4202 $ * @modifiedby		$LastChangedBy: phpnut $ * @lastmodified	$Date: 2006-12-25 06:06:13 -0600 (Mon, 25 Dec 2006) $ * @license			http://www.opensource.org/licenses/mit-license.php The MIT License *//** * Enter description here... */	ini_set('display_errors', '1');	ini_set('error_reporting', '7');	define ('DS', DIRECTORY_SEPARATOR);	$app = 'app';	$core = null;	$root = dirname(dirname(dirname(__FILE__)));	$here = $argv[0];	$dataSource = 'default';	$unset = array();	for ($i = 1; $i < count($argv); $i++) {		// Process command-line modifiers here		switch (strtolower($argv[$i])) {			case '-app':				$app = $argv[$i + 1];				$unset[$i] = $argv[$i];				$unset[$i + 1] = $argv[$i + 1]; 			break;			case '-core':				$core = $argv[$i + 1];				$unset[$i] = $argv[$i];				$unset[$i + 1] = $argv[$i + 1]; 			break;			case '-root':				$root = $argv[$i + 1];				$unset[$i] = $argv[$i];				$unset[$i + 1] = $argv[$i + 1]; 			break;			case '-datasource':				$dataSource = $argv[$i + 1];				$unset[$i] = $argv[$i];				$unset[$i + 1] = $argv[$i + 1]; 			break;		}	}	if (strlen($app) && $app[0] == DS) {		$cnt = substr_count($root, DS);		$app = str_repeat('..' . DS, $cnt) . $app;	}	define ('ROOT', $root.DS);	define ('APP_DIR', $app);	define ('DEBUG', 1);;	define('CAKE_CORE_INCLUDE_PATH', ROOT);	define('DATASOURCE', $dataSource);	if(function_exists('ini_set')) {		ini_set('include_path',ini_get('include_path').			PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.DS.			PATH_SEPARATOR.CORE_PATH.DS.			PATH_SEPARATOR.ROOT.DS.APP_DIR.DS.			PATH_SEPARATOR.APP_DIR.DS.			PATH_SEPARATOR.APP_PATH);		define('APP_PATH', null);		define('CORE_PATH', null);	} else {		define('APP_PATH', ROOT . DS . APP_DIR . DS);		define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);	}	require ('cake'.DS.'basics.php');	require ('cake'.DS.'config'.DS.'paths.php');	require (CONFIGS.'core.php');	uses ('object', 'configure', 'neat_array', 'session', 'security', 'inflector', 'model'.DS.'connection_manager',			'model'.DS.'datasources'.DS.'dbo_source', 'model'.DS.'model');	require(CAKE.'app_model.php');	uses ('controller'.DS.'components'.DS.'acl', 'controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aclnode',			'controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aco', 'controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'acoaction',			'controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aro');	//Get and format args: first arg is the name of the script.	$serverArgs = $argv;	if(!empty($unset)) {		$serverArgs = array_values(array_diff($argv, $unset));	}		$wasted = array_shift($serverArgs);	$command = array_shift($serverArgs);	$args = $serverArgs;	$aclCLI = new AclCLI ($command, $args);/** * @package		cake * @subpackage	cake.cake.scritps */class AclCLI {/** * Enter description here... * * @var unknown_type */	var $stdin;/** * Enter description here... * * @var unknown_type */	var $stdout;/** * Enter description here... * * @var unknown_type */	var $stderr;/** * Enter description here... * * @var unknown_type */	var $acl;/** * Enter description here... * * @var unknown_type */	var $args;/** * Enter description here... * * @var unknown_type */	var $dataSource = 'default';/** * Enter description here... * * @param unknown_type $command * @param unknown_type $args * @return AclCLI */	function AclCLI($command, $args) {		$this->__construct($command, $args);	}/** * Enter description here... * * @param unknown_type $command * @param unknown_type $args */	function __construct ($command, $args) {		$this->stdin = fopen('php://stdin', 'r');		$this->stdout = fopen('php://stdout', 'w');		$this->stderr = fopen('php://stderr', 'w');		if (ACL_CLASSNAME != 'DB_ACL'){			$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";			fwrite($this->stderr, $out);			exit();		}				if(!in_array($command, array('help'))) {			if(!file_exists(CONFIGS.'database.php')) {				$this->stdout('');				$this->stdout('Your database configuration was not found.');				$this->stdout('Take a moment to create one:');				$this->doDbConfig();			}			require_once (CONFIGS.'database.php');						if(!in_array($command, array('initdb'))) {				$this->dataSource = DATASOURCE;				$this->Acl = new AclComponent();				$this->args = $args;				$this->db =& ConnectionManager::getDataSource($this->dataSource);			}		}		switch ($command) {			case 'create':				$this->create();			break;			case 'delete':				$this->delete();			break;			case 'setParent':				$this->setParent();			break;			case 'getPath':				$this->getPath();			break;			case 'grant':				$this->grant();			break;			case 'deny':				$this->deny();			break;			case 'inherit':				$this->inherit();			break;			case 'view':				$this->view();			break;			case 'initdb':				$this->initdb();			break;			case 'upgrade':				$this->upgradedb();			break;			case 'help':				$this->help();			break;			default:			break;				//fwrite($this->stderr, "Unknown ACL command '$command'.\nFor usage, try 'php acl.php help'.\n\n");		}	}/** * Enter description here... * */	function create() {		$this->checkArgNumber(4, 'create');		$this->checkNodeType();		extract($this->__dataVars());				$parent = (is_numeric($this->args[2])) ? intval($this->args[2]) : $this->args[2];		if(!$this->Acl->{$class}->create(intval($this->args[1]), $parent, $this->args[3])){			$this->displayError("Parent Node Not Found", "There was an error creating the ".$class.", probably couldn't find the parent node.\n If you wish to create a new root node, specify the <parent_id> as '0'.");		}		$this->stdout("New $class '".$this->args[3]."' created.\n\n");	}/** * Enter description here... * */	function delete() {		$this->checkArgNumber(2, 'delete');		$this->checkNodeType();		extract($this->__dataVars());		$this->Acl->{$class}->del($this->args[1]);		$this->stdout("$class deleted.\n\n");	}/** * Enter description here... * */	function setParent() {		$this->checkArgNumber(3, 'setParent');		$this->checkNodeType();		extract($this->__dataVars());		if (!$this->Acl->{$class}->setParent($this->args[2], $this->args[1])){			$this->stdout("Error in setting new parent. Please make sure the parent node exists, and is not a descendant of the node specified.\n");		} else {			$this->stdout("Node parent set to ".$this->args[2]."\n\n");		}	}/** * Enter description here... * */	function getPath() {		$this->checkArgNumber(2, 'getPath');		$this->checkNodeType();		extract($this->__dataVars());		$suppliedNode = $this->nodeExists($this->args[0], $this->args[1]);		if (!$suppliedNode) {			$this->displayError("Supplied Node '".$args[1]."' not found. No tree returned.");		}		$id = (is_numeric($this->args[2])) ? intval($this->args[1]) : $this->args[1];		$nodes = $this->Acl->{$class}->getPath($id);		for ($i = 0; $i < count($nodes); $i++) {			$this->stdout(str_repeat('  ', $i) . "[" . $nodes[$i][$class]['id'] . "]" . $nodes[$i][$class]['alias'] . "\n");		}	}/** * Enter description here... * */	function grant() {		$this->checkArgNumber(3, 'grant');		//add existence checks for nodes involved		$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->allow($aro, $aco, $this->args[2]);		$this->stdout("Permission granted.\n");	}/** * Enter description here... * */	function deny() {		$this->checkArgNumber(3, 'deny');		//add existence checks for nodes involved		$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->allow($aro, $aco, $this->args[2]);		$this->stdout("Requested permission successfully denied.\n");	}/** * Enter description here... * */	function inherit() {		$this->stdout("not implemented. sorry.\n");	}/** * Enter description here... * */	function view() {		$this->checkArgNumber(2, 'view');		$this->checkNodeType();		extract($this->__dataVars());		$conditions = $this->Acl->{$class}->_resolveID($this->args[1]);		$nodes = $this->Acl->{$class}->findAll($conditions, null, 'lft ASC');		$right = array();		$this->stdout($class . " tree:\n");		$this->stdout("------------------------------------------------\n");		for($i = 0; $i < count($nodes); $i++){			if (count($right) > 0){				while ($right[count($right)-1] < $nodes[$i][$class]['rght']){					if ($right[count($right)-1]){						array_pop($right);					} else {						break;					}				}			}			$this->stdout(str_repeat('  ',count($right)) . "[" . $nodes[$i][$class]['id'] . "]" . $nodes[$i][$class]['alias']."\n");			$right[] = $nodes[$i][$class]['rght'];		}		$this->stdout("------------------------------------------------\n");	}/** * Enter description here... * */	function initdb() {		$db =& ConnectionManager::getDataSource($this->dataSource);		$this->stdout("Initializing Database...\n");		$this->stdout("Creating access control objects table (acos)...\n");		$sql = " CREATE TABLE ".$db->fullTableName('acos')." (				".$db->name('id')." ".$db->column($db->columns['primary_key']).",				".$db->name('object_id')." ".$db->column($db->columns['integer'])." default NULL,				".$db->name('alias')." ".$db->column($db->columns['string'])." NOT NULL default '',				".$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').")				);";		if ($db->query($sql) === false) {			die("Error: " . $db->lastError() . "\n\n");		}		$this->stdout("Creating access request objects table (aros)...\n");		$sql2 = "CREATE TABLE ".$db->fullTableName('aros')." (				".$db->name('id')." ".$db->column($db->columns['primary_key']).",				".$db->name('foreign_key')." ".$db->column($db->columns['integer'])." default NULL,				".$db->name('alias')." ".$db->column($db->columns['string'])." NOT NULL default '',				".$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').")				);";		if ($db->query($sql2) === false) {			die("Error: " . $db->lastError() . "\n\n");		}		$this->stdout("Creating relationships table (aros_acos)...\n");		$sql3 = "CREATE TABLE ".$db->fullTableName('aros_acos')." (				".$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,				".$db->name('_create')." ".$db->column($db->columns['integer'])." NOT NULL default '0',

⌨️ 快捷键说明

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