acl.php.svn-base

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

SVN-BASE
804
字号
				".$db->name('_read')." ".$db->column($db->columns['integer'])." NOT NULL default '0',				".$db->name('_update')." ".$db->column($db->columns['integer'])." NOT NULL default '0',				".$db->name('_delete')." ".$db->column($db->columns['integer'])." NOT NULL default '0',				PRIMARY KEY  (".$db->name('id').")				);";		if ($db->query($sql3) === false) {			die("Error: " . $db->lastError() . "\n\n");		}		$this->stdout("\nDone.\n");	}/** * Enter description here... * */	function upgradedb() {		$db =& ConnectionManager::getDataSource($this->dataSource);		$this->stdout("Initializing Database...\n");		$this->stdout("Upgrading table (aros)...\n");		$sql = "ALTER TABLE ".$db->fullTableName('aros')."				CHANGE ".$db->name('user_id')."				".$db->name('foreign_key')."				INT( 10 ) UNSIGNED NULL DEFAULT NULL;";		if ($db->query($sql) === false) {			die("Error: " . $db->lastError() . "\n\n");		}		$this->stdout("\nDatabase upgrade is complete.\n");	}/** * Enter description here... * */	function help() {		$out = "Usage: php acl.php <command> <arg1> <arg2>...\n";		$out .= "-----------------------------------------------\n";		$out .= "Commands:\n";		$out .= "\n";		$out .= "\tcreate aro|aco <link_id> <parent_id> <alias>\n";		$out .= "\t\tCreates a new ACL object under the parent specified by <parent_id>, an id/alias (see\n";		$out .= "\t\t'view'). The link_id allows you to link a user object to Cake's\n";		$out .= "\t\tACL structures. The alias parameter allows you to address your object\n";		$out .= "\t\tusing a non-integer ID. Example: \"\$php acl.php create aro 57 0 John\"\n";		$out .= "\t\twould create a new ARO object at the root of the tree, linked to 57\n";		$out .= "\t\tin your users table, with an internal alias 'John'.";		$out .= "\n";		$out .= "\n";		$out .= "\tdelete aro|aco <id>\n";		$out .= "\t\tDeletes the ACL object with the specified ID (see 'view').\n";		$out .= "\n";		$out .= "\n";		$out .= "\tsetParent aro|aco <id> <parent_id>\n";		$out .= "\t\tUsed to set the parent of the ACL object specified by <id> to the ID\n";		$out .= "\t\tspecified by <parent_id>.\n";		$out .= "\n";		$out .= "\n";		$out .= "\tgetPath aro|aco <id>\n";		$out .= "\t\tReturns the path to the ACL object specified by <id>. This command is\n";		$out .= "\t\tis useful in determining the inhertiance of permissions for a certain\n";		$out .= "\t\tobject in the tree.\n";		$out .= "\n";		$out .= "\n";		$out .= "\tgrant <aro_id> <aco_id> <aco_action>\n";		$out .= "\t\tUse this command to grant ACL permissions. Once executed, the ARO\n";		$out .= "\t\tspecified (and its children, if any) will have ALLOW access to the\n";		$out .= "\t\tspecified ACO action (and the ACO's children, if any).\n";		$out .= "\n";		$out .= "\n";		$out .= "\tdeny <aro_id> <aco_id> <aco_action>\n";		$out .= "\t\tUse this command to deny ACL permissions. Once executed, the ARO\n";		$out .= "\t\tspecified (and its children, if any) will have DENY access to the\n";		$out .= "\t\tspecified ACO action (and the ACO's children, if any).\n";		$out .= "\n";		$out .= "\n";		$out .= "\tinherit <aro_id> \n";		$out .= "\t\tUse this command to force a child ARO object to inherit its\n";		$out .= "\t\tpermissions settings from its parent.\n";		$out .= "\n";		$out .= "\n";		$out .= "\tview aro|aco [id]\n";		$out .= "\t\tThe view command will return the ARO or ACO tree. The optional\n";		$out .= "\t\tid/alias parameter allows you to return only a portion of the requested\n";		$out .= "\t\ttree.\n";		$out .= "\n";		$out .= "\n";		$out .= "\tinitdb\n";		$out .= "\t\tUse this command to create the database tables needed to use DB ACL.\n";		$out .= "\n";		$out .= "\n";		$out .= "\thelp\n";		$out .= "\t\tDisplays this help message.\n";		$out .= "\n";		$out .= "\n";		$this->stdout($out);	}/** * Enter description here... * * @param unknown_type $title * @param unknown_type $msg */	function displayError($title, $msg) {		$out = "\n";		$out .= "Error: $title\n";		$out .= "$msg\n";		$out .= "\n";		$this->stdout($out);		exit();	}/** * Enter description here... * * @param unknown_type $expectedNum * @param unknown_type $command */	function checkArgNumber($expectedNum, $command) {		if (count($this->args) != $expectedNum) {			$this->displayError('Wrong number of parameters: '.count($this->args), 'Please type \'php acl.php help\' for help on usage of the '.$command.' command.');		}	}/** * Enter description here... * */	function checkNodeType() {		if ($this->args[0] != 'aco' && $this->args[0] != 'aro') {			$this->displayError("Missing/Unknown node type: '".$this->args[0]."'", 'Please specify which ACL object type you wish to create.');		}	}/** * Enter description here... * * @param unknown_type $type * @param unknown_type $id * @return unknown */	function nodeExists($type, $id) {		//$this->stdout("Check to see if $type with ID = $id exists...\n");		extract($this->__dataVars($type));		$possibility = $this->Acl->{$class}->find('id = ' . $id);		if (empty($possibility[$class]['id'])) {			return false;		} else {			return $possibility;		}	}/** * Enter description here... * * @param unknown_type $type * @return unknown */	function __dataVars($type = null) {		if ($type == null) {			$type = $this->args[0];		}		$vars = array();		$class = ucwords($type);		$vars['secondary_id'] = ($class == 'aro' ? 'foreign_key' : 'object_id');		$vars['data_name'] = $type;		$vars['table_name'] = $type . 's';		$vars['class'] = $class;		return $vars;	}/** * Database configuration setup. * */	function doDbConfig() {		$this->hr();		$this->stdout('Database Configuration:');		$this->hr();		$driver = '';		while ($driver == '') {			$driver = $this->getInput('What database driver would you like to use?', array('mysql','mysqli','mssql','sqlite','postgres', 'odbc'), 'mysql');			if ($driver == '') {				$this->stdout('The database driver supplied was empty. Please supply a database driver.');			}		}		switch($driver) {			case 'mysql':			$connect = 'mysql_connect';			break;			case 'mysqli':			$connect = 'mysqli_connect';			break;			case 'mssql':			$connect = 'mssql_connect';			break;			case 'sqlite':			$connect = 'sqlite_open';			break;			case 'postgres':			$connect = 'pg_connect';			break;			case 'odbc':			$connect = 'odbc_connect';			break;			default:			$this->stdout('The connection parameter could not be set.');			break;		}		$host = '';		while ($host == '') {			$host = $this->getInput('What is the hostname for the database server?', null, 'localhost');			if ($host == '') {				$this->stdout('The host name you supplied was empty. Please supply a hostname.');			}		}		$login = '';		while ($login == '') {			$login = $this->getInput('What is the database username?', null, 'root');			if ($login == '') {				$this->stdout('The database username you supplied was empty. Please try again.');			}		}		$password = '';		$blankPassword = false;		while ($password == '' && $blankPassword == false) {			$password = $this->getInput('What is the database password?');			if ($password == '') {				$blank = $this->getInput('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n');				if($blank == 'y')				{					$blankPassword = true;				}			}		}		$database = '';		while ($database == '') {			$database = $this->getInput('What is the name of the database you will be using?', null, 'cake');			if ($database == '')  {				$this->stdout('The database name you supplied was empty. Please try again.');			}		}		$prefix = '';		while ($prefix == '') {			$prefix = $this->getInput('Enter a table prefix?', null, 'n');		}		if(low($prefix) == 'n') {			$prefix = '';		}		$this->stdout('');		$this->hr();		$this->stdout('The following database configuration will be created:');		$this->hr();		$this->stdout("Driver:        $driver");		$this->stdout("Connection:    $connect");		$this->stdout("Host:          $host");		$this->stdout("User:          $login");		$this->stdout("Pass:          " . str_repeat('*', strlen($password)));		$this->stdout("Database:      $database");		$this->stdout("Table prefix:  $prefix");		$this->hr();		$looksGood = $this->getInput('Look okay?', array('y', 'n'), 'y');		if (low($looksGood) == 'y' || low($looksGood) == 'yes') {			$this->bakeDbConfig($driver, $connect, $host, $login, $password, $database, $prefix);		} else {			$this->stdout('Bake Aborted.');		}	}	/** * Creates a database configuration file for Bake. * * @param string $host * @param string $login * @param string $password * @param string $database */	function bakeDbConfig( $driver, $connect, $host, $login, $password, $database, $prefix) {		$out = "<?php\n";		$out .= "class DATABASE_CONFIG {\n\n";		$out .= "\tvar \$default = array(\n";		$out .= "\t\t'driver' => '{$driver}',\n";		$out .= "\t\t'connect' => '{$connect}',\n";		$out .= "\t\t'host' => '{$host}',\n";		$out .= "\t\t'login' => '{$login}',\n";		$out .= "\t\t'password' => '{$password}',\n";		$out .= "\t\t'database' => '{$database}', \n";		$out .= "\t\t'prefix' => '{$prefix}' \n";		$out .= "\t);\n";		$out .= "}\n";		$out .= "?>";		$filename = CONFIGS.'database.php';		$this->__createFile($filename, $out);	}/** * Prompts the user for input, and returns it. * * @param string $prompt Prompt text. * @param mixed $options Array or string of options. * @param string $default Default input value. * @return Either the default value, or the user-provided input. */	function getInput($prompt, $options = null, $default = null) {		if (!is_array($options)) {			$print_options = '';		} else {			$print_options = '(' . implode('/', $options) . ')';		}		if($default == null) {			$this->stdout('');			$this->stdout($prompt . " $print_options \n" . '> ', false);		} else {			$this->stdout('');			$this->stdout($prompt . " $print_options \n" . "[$default] > ", false);		}		$result = trim(fgets($this->stdin));		if($default != null && empty($result)) {			return $default;		} else {			return $result;		}	}/** * Outputs to the stdout filehandle. * * @param string $string String to output. * @param boolean $newline If true, the outputs gets an added newline. */	function stdout($string, $newline = true) {		if ($newline) {			fwrite($this->stdout, $string . "\n");		} else {			fwrite($this->stdout, $string);		}	}/** * Outputs to the stderr filehandle. * * @param string $string Error text to output. */	function stderr($string) {		fwrite($this->stderr, $string);	}/** * Outputs a series of minus characters to the standard output, acts as a visual separator. * */	function hr() {		$this->stdout('---------------------------------------------------------------');	}/** * Creates a file at given path. * * @param string $path		Where to put the file. * @param string $contents Content to put in the file. * @return Success */	function __createFile ($path, $contents) {		$path = str_replace('//', '/', $path);		echo "\nCreating file $path\n";		if (is_file($path) && $this->interactive === true) {			fwrite($this->stdout, "File exists, overwrite?" . " {$path} (y/n/q):");			$key = trim(fgets($this->stdin));			if ($key=='q') {				fwrite($this->stdout, "Quitting.\n");				exit;			} elseif ($key == 'a') {				$this->dont_ask = true;			} elseif ($key == 'y') {			} else {				fwrite($this->stdout, "Skip" . " {$path}\n");				return false;			}		}		if ($f = fopen($path, 'w')) {			fwrite($f, $contents);			fclose($f);			fwrite($this->stdout, "Wrote" . "{$path}\n");			return true;		} else {			fwrite($this->stderr, "Error! Could not write to" . " {$path}.\n");			return false;		}	}}?>

⌨️ 快捷键说明

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