* @copyright 2004 by http://wombat.exit0.net * @package wombatSite * @subpackage install */ /** * make tool: set per site permission * * does nothing... * * @version 1.0.0 * @package wombatSite * @subpackage install */ class wbMaker_SitePermission extends wbMaker { /** * information * * @access private * @var array $_info */ var $_info = array( 'maker' => 'SitePermission', 'state' => 'new', 'brief' => 'Set read permission for site specific files', 'msg' => '' ); /** * @access private * @var string $_baseDir */ var $_baseDir; /** * @access private * @var string $_htdocDic */ var $_htdocDir; /** * permission codes * * @access private * @var array $_perms */ var $_perms = array( 'dir' => 0755, 'file' => 0644, 'link' => 0777, ); /** * touched files and folders * * @access private * @var array $_touch */ var $_touch = array( 'dir' => array(), 'file' => array(), 'link' => array() ); /** * self * * @access private * @var array $_self */ var $_self = array( 'uid' => 0, 'gid' => 0 ); /** * bring birth! * * @access public * @return boolean $result true on success */ function __construct() { umask( 0000 ); $this->_baseDir = wbFactory::getParam( 'baseDir' ); $this->_htdocDir = wbFactory::getParam( 'htdocDir' ); // if posic functions don't exist, we assume to have the right permissions if( function_exists( 'posix_geteuid' ) ) { $this->_self['uid'] = posix_geteuid(); $this->_self['gid'] = posix_getegid(); } } /** * php4 constructor wrapper * * @access public * @see __construct() */ function wbMaker_SitePermission() { $this->__construct(); } /** * run... * * @access public * @return boolean true on success, false if any target has failed (or patError object on error!) */ function make() { // check base dir if( !is_dir( $this->_baseDir ) ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Could not find system directory "'. $this->_baseDir .'"!'; return false; } // system dir is same as base dir if( $this->_baseDir == wbFactory::getParam( 'systemDir' ) ) { $this->_info['msg'] = 'BaseDir is the same as SystemDir - nothing left to do.'; return true; } if( !$this->_setPerms( $this->_baseDir ) ) { return false; } if( !$this->_scanDir( $this->_baseDir ) ) { return false; } // it's all good! $this->_info['msg'] = 'Adjusted permissions of ' . count( $this->_touch['dir'] ) .' dir(s) / ' . count( $this->_touch['file'] ) .' file(s) / ' . count( $this->_touch['link'] ) .' link(s).'; return true; } /** * set permissions for entry * * @access private * @param string $file * @return string $type file type or false on error */ function _setPerms( $file ) { $owner = fileowner( $file ); // check owner! if( $this->_self['uid'] && ( $owner != $this->_self['uid'] ) ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Only owner (or root) may change file permisions, file: "'. $file .'"!'; return false; } $type = false; if( is_file( $file ) ) { $type = 'file'; } else if( is_dir( $file ) ) { $type = 'dir'; } else if( is_link( $file ) ) { $type = 'link'; } if( !$type ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Unknown filetype of file: "'. $file .'"!'; return false; } $res = chmod( $file, $this->_perms[$type] ); if( !$res ) { $this->_info['state'] = 'failed'; $this->_info['msg'] = 'Changing permission of file "'. $file .'" failed for an unknown reason!'; wbDebugger::addMsg( 'Make', 'Changemode failed: chmod(' . $file . ', '. (string) $perms .')', 'SitePermission' ); return false; } array_push( $this->_touch[$type], $file ); return $type; } /** * scan directory recursivly * * @access private * @param string dir * @return boolean true on success, false if any target has failed (or patError object on error!) */ function _scanDir( $dir ) { $dh = dir( $dir ); while( false !== ( $file = $dh->read() ) ) { //skip hidden files and dirs if( $file[0] == '.') { continue; } $type = $this->_setPerms( $dir . '/' . $file ); if( !$type ) { return false; } if( $type == 'dir' ) { if( !$this->_scanDir( $dir . '/' . $file ) ) { return false; } } } return true; } } ?>