public function getInfoByName($filePath) { $this->MAX_FILE_SIZE_FOR_HASHING = 1024 * 1024; $this->absoluteName = $filePath; $this->name = str_replace($this->web_root_dir, '.', $filePath); $this->ctime = 0; $this->mtime = 0; $this->owner = '-'; $this->group = '-'; $this->access = 0; $this->size = -1; $this->md5 = '-'; if (file_exists($filePath)) { $this->ctime = filectime($filePath); $this->mtime = filemtime($filePath); $owner = fileowner($filePath); $ownerInfo = function_exists('posix_getpwuid') ? posix_getpwuid($owner) : array('name' => $owner); $this->owner = $ownerInfo['name']; $group = filegroup($filePath); $groupInfo = function_exists('posix_getgrgid') ? posix_getgrgid($group) : array('name' => $group); $this->group = $groupInfo['name']; $this->access = substr(sprintf('%o', fileperms($filePath)), -4); if (is_file($filePath)) { $this->size = filesize($filePath); if ($this->size <= $this->MAX_FILE_SIZE_FOR_HASHING) { $this->md5 = hash_file('md5', $filePath); } } } return true; }
public function getInfo($path) { if (JFile::exists($path) || JFolder::exists($path)) { return array('path' => $path, 'realpath' => realpath($path), 'owner/group' => filegroup($path) . '/' . fileowner($path), 'permissions' => $this->getPerms($path), 'is_readable' => is_readable($path), 'is_writable' => is_writable($path)); } return 'No exists'; }
public function listFile($pathname, $pattern = "*") { static $_listDirs = array(); $guid = md5($pathname . $pattern); if (!isset($_listDirs[$guid])) { $dir = array(); $list = glob($pathname . $pattern); foreach ($list as $i => $file) { $dir[$i]["filename"] = preg_replace("/^.+[\\\\\\/]/", "", $file); $dir[$i]["pathname"] = realpath($file); $dir[$i]["owner"] = fileowner($file); $dir[$i]["perms"] = fileperms($file); $dir[$i]["inode"] = fileinode($file); $dir[$i]["group"] = filegroup($file); $dir[$i]["path"] = dirname($file); $dir[$i]["atime"] = fileatime($file); $dir[$i]["ctime"] = filectime($file); $dir[$i]["size"] = filesize($file); $dir[$i]["type"] = filetype($file); $dir[$i]["ext"] = is_file($file) ? strtolower(substr(strrchr(basename($file), "."), 1)) : ""; $dir[$i]["mtime"] = filemtime($file); $dir[$i]["isDir"] = is_dir($file); $dir[$i]["isFile"] = is_file($file); $dir[$i]["isLink"] = is_link($file); $dir[$i]["isReadable"] = is_readable($file); $dir[$i]["isWritable"] = is_writable($file); } $cmp_func = create_function("\$a,\$b", "\r\n\t\t\t\$k = \"isDir\";\r\n\t\t\tif(\$a[\$k] == \$b[\$k]) return 0;\r\n\t\t\treturn \$a[\$k]>\$b[\$k]?-1:1;\r\n\t\t\t"); usort($dir, $cmp_func); $this->_values = $dir; $_listDirs[$guid] = $dir; } else { $this->_values = $_listDirs[$guid]; } }
public function matchOwnersIfPossible($target_filename, $match_from_filename) { try { if (false === ($intended_uid = fileowner($match_from_filename))) { throw new \Exception("fileowner failed on source"); } if (false === ($intended_gid = filegroup($match_from_filename))) { throw new \Exception("filegroup failed on source"); } if (false === ($uid = fileowner($target_filename))) { throw new \Exception("fileowner failed on target"); } if (false === ($gid = filegroup($target_filename))) { throw new \Exception("filegroup failed on target"); } if ($intended_uid != $uid && !$this->chown($target_filename, $intended_uid)) { throw new \Exception("chown failed on target"); } if ($intended_gid != $gid && !$this->chgrp($target_filename, $intended_gid)) { throw new \Exception("chgrp failed on target"); } } catch (\Exception $e) { throw new IOException("Cannot assign ownership of [{$target_filename}] to owner of [{$match_from_filename}]: " . $e->getMessage()); } }
/** * Returns an array of found directories * * This function checks every found directory if they match either $uid or $gid, if they do * the found directory is valid. It uses recursive-iterators to find subdirectories. * * @param string $path the path to start searching in * @param int $uid the uid which must match the found directories * @param int $gid the gid which must match the found direcotries * * @return array Array of found valid paths */ function findDirs($path, $uid, $gid) { $_fileList = array(); $path = makeCorrectDir($path); // valid directory? if (is_dir($path)) { try { // create RecursiveIteratorIterator $its = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); // we can limit the recursion-depth, but will it be helpful or // will people start asking "why do I only see 2 subdirectories, i want to use /a/b/c" // let's keep this in mind and see whether it will be useful // @TODO // $its->setMaxDepth(2); // check every file foreach ($its as $fullFileName => $it) { if ($it->isDir() && (fileowner($fullFileName) == $uid || filegroup($fullFileName) == $gid)) { $_fileList[] = makeCorrectDir(dirname($fullFileName)); } } } catch (UnexpectedValueException $e) { // this is thrown if the directory is not found or not readble etc. // just ignore and keep going } } return array_unique($_fileList); }
function ls() { $list = array(); if ($handle = opendir($this->root . $this->cwd)) { while (false !== ($file = readdir($handle))) { if ($file == "." || $file == "..") { continue; } $filename = $this->root . $this->cwd . $file; $filetype = filetype($filename); if ($filetype != "dir" && $filetype != "file") { continue; } $filesize = $filetype == "file" ? filesize($filename) : 0; /* owner, group, last modification and access info added by Phanatic */ $owner = posix_getpwuid(fileowner($filename)); $fileowner = $owner['name']; $group = posix_getgrgid(filegroup($filename)); $filegroup = $group['name']; $mtime = filemtime($filename); $filemod = date("M d H:i", $mtime); $fileperms = $this->perms(fileperms($filename)); clearstatcache(); $info = array("name" => $file, "size" => $filesize, "owner" => $fileowner, "group" => $filegroup, "time" => $filemod, "perms" => $fileperms); $list[] = $info; } closedir($handle); return $list; } else { return false; } }
/** * Open session, adjust UID if required */ public static function open($admin = false) { if (PHP_SESSION_ACTIVE == session_status()) { throw new \LogicException('Session already open'); } // automatic admin mode for command line testing if root $session_file = session_save_path() . DIRECTORY_SEPARATOR . 'sess_' . static::SESSION_ID; if (file_exists($session_file) && is_readable($session_file)) { $session_owner = fileowner($session_file); if ($session_owner !== posix_getuid() && 0 === posix_getuid()) { // echo("o: $session_owner\n"); $admin = true; } $_SESSION['_dirty'] = microtime(); } // set effective uid of session owner if ($admin) { static::$pre_session_uid = posix_getuid(); posix_seteuid(posix_getpwnam(static::SESSION_ADMIN_USER)['uid']); } // tie all users to single session session_id(static::SESSION_ID); if (false === session_start()) { throw new \RuntimeException('Could not start session'); } // update sesson with current configuration // TODO check if necessary foreach (ConfigDB::read('cfg_engine') as $row) { $_SESSION[$row['param']] = $row['value']; } }
function awpcp_setup_uploads_dir() { global $wpcontentdir; $permissions = awpcp_directory_permissions(); $upload_dir_name = get_awpcp_option('uploadfoldername', 'uploads'); $upload_dir = $wpcontentdir . '/' . $upload_dir_name . '/'; // Required to set permission on main upload directory require_once AWPCP_DIR . '/fileop.class.php'; $fileop = new fileop(); $owner = fileowner($wpcontentdir); if (!is_dir($upload_dir) && is_writable($wpcontentdir)) { umask(0); mkdir($upload_dir, $permissions); chown($upload_dir, $owner); } $fileop->set_permission($upload_dir, $permissions); $images_dir = $upload_dir . 'awpcp/'; $thumbs_dir = $upload_dir . 'awpcp/thumbs/'; if (!is_dir($images_dir) && is_writable($upload_dir)) { umask(0); @mkdir($images_dir, $permissions); @chown($images_dir, $owner); } if (!is_dir($thumbs_dir) && is_writable($upload_dir)) { umask(0); @mkdir($thumbs_dir, $permissions); @chown($thumbs_dir, $owner); } $fileop->set_permission($images_dir, $permissions); $fileop->set_permission($thumbs_dir, $permissions); return array($images_dir, $thumbs_dir); }
/** * Returns an array of found directories * * This function checks every found directory if they match either $uid or $gid, if they do * the found directory is valid. It uses recursive function calls to find subdirectories. Due * to the recursive behauviour this function may consume much memory. * * @param string path The path to start searching in * @param integer uid The uid which must match the found directories * @param integer gid The gid which must match the found direcotries * @param array _fileList recursive transport array !for internal use only! * @return array Array of found valid pathes * * @author Martin Burchert <*****@*****.**> * @author Manuel Bernhardt <*****@*****.**> */ function findDirs($path, $uid, $gid) { $list = array($path); $_fileList = array(); while (sizeof($list) > 0) { $path = array_pop($list); $path = makeCorrectDir($path); $dh = opendir($path); if ($dh === false) { standard_error('cannotreaddir', $path); return null; } else { while (false !== ($file = @readdir($dh))) { if ($file == '.' && (fileowner($path . '/' . $file) == $uid || filegroup($path . '/' . $file) == $gid)) { $_fileList[] = makeCorrectDir($path); } if (is_dir($path . '/' . $file) && $file != '..' && $file != '.') { array_push($list, $path . '/' . $file); } } @closedir($dh); } } return $_fileList; }
/** * Chmod a file. */ function rf_chmod($args) { $args = unserialize($args); $path = $args['path']; $mode = $args['mode']; try { if (!is_writable($path)) { throw new RFUtilException(RFUtilException::UNWRITABLE_PATH); } $owner = fileowner($path); $self = posix_getuid(); // can write, not owner owner if ($owner != $self) { $t = tempnam('/tmp', 'rf'); $result = copy($path, $t); if (!$result) { throw new RFUtilException(RFUtilException::CHMOD_COPY_FAILED); } $result = unlink($path); if (!$result) { throw new RFUtilException(RFUtilException::CHMOD_UNLINK_FAILED); } $result = rename($t, $path); if (!$result) { throw new RFUtilException(RFUtilException::CHMOD_RENAME_FAILED); } chgrp($path, 'ousers'); } } catch (RFUtilException $e) { return $e->getCode(); } $result = chmod($path, $mode); return $result; }
function _match_owners_if_possible($target_filename, $match_from_filename) { try { if (false === ($intended_uid = fileowner($match_from_filename))) { throw new Exception("fileowner failed on source"); } if (false === ($intended_gid = filegroup($match_from_filename))) { throw new Exception("filegroup failed on source"); } if (false === ($uid = fileowner($target_filename))) { throw new Exception("fileowner failed on target"); } if (false === ($gid = filegroup($target_filename))) { throw new Exception("filegroup failed on target"); } if ($intended_uid != $uid && !chown($target_filename, $intended_uid)) { throw new Exception("chown failed on target"); } if ($intended_gid != $gid && !chgrp($target_filename, $intended_gid)) { throw new Exception("chgrp failed on target"); } } catch (Exception $e) { error_log("Cannot assign ownership of [{$target_filename}] to owner of [{$match_from_filename}]: " . $e->getMessage()); } }
function has_different_permissions($file) { if (!file_exists($file)) { return false; } return fileowner($file) != getmyuid(); }
/** * collect all fileinformations of given file and * save them to the global fileinformation array * * @param string $file * @return boolean is valid file? */ protected function setFileInformations($file) { $this->fileInfo = array(); // reset previously information to have a cleaned object $this->file = $file instanceof \TYPO3\CMS\Core\Resource\File ? $file : NULL; if (is_string($file) && !empty($file)) { $this->fileInfo = TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($file); $this->fileInfo['mtime'] = filemtime($file); $this->fileInfo['atime'] = fileatime($file); $this->fileInfo['owner'] = fileowner($file); $this->fileInfo['group'] = filegroup($file); $this->fileInfo['size'] = filesize($file); $this->fileInfo['type'] = filetype($file); $this->fileInfo['perms'] = fileperms($file); $this->fileInfo['is_dir'] = is_dir($file); $this->fileInfo['is_file'] = is_file($file); $this->fileInfo['is_link'] = is_link($file); $this->fileInfo['is_readable'] = is_readable($file); $this->fileInfo['is_uploaded'] = is_uploaded_file($file); $this->fileInfo['is_writeable'] = is_writeable($file); } if ($file instanceof \TYPO3\CMS\Core\Resource\File) { $pathInfo = \TYPO3\CMS\Core\Utility\PathUtility::pathinfo($file->getName()); $this->fileInfo = array('file' => $file->getName(), 'filebody' => $file->getNameWithoutExtension(), 'fileext' => $file->getExtension(), 'realFileext' => $pathInfo['extension'], 'atime' => $file->getCreationTime(), 'mtime' => $file->getModificationTime(), 'owner' => '', 'group' => '', 'size' => $file->getSize(), 'type' => 'file', 'perms' => '', 'is_dir' => FALSE, 'is_file' => $file->getStorage()->getDriverType() === 'Local' ? is_file($file->getForLocalProcessing(FALSE)) : TRUE, 'is_link' => $file->getStorage()->getDriverType() === 'Local' ? is_link($file->getForLocalProcessing(FALSE)) : FALSE, 'is_readable' => TRUE, 'is_uploaded' => FALSE, 'is_writeable' => FALSE); } return $this->fileInfo !== array(); }
function get_smt2wp_diagnose_info() { $wp_base_dir = get_wp_base_dir(); $folders = array('server root' => $_SERVER['DOCUMENT_ROOT'], 'wp root' => $wp_base_dir, 'wp content' => $wp_base_dir . '/wp-content', 'wp uploads' => $wp_base_dir . '/wp-content/uploads', 'smt root' => $wp_base_dir . '/wp-content/plugins/' . basename(dirname(__FILE__))); $folders_check_result = array(); foreach ($folders as $key => $folder) { $folder = smt2wp_sanitize_dir_path($folder); // var_dump($folder); $folders_check_result[$key]['path'] = $folder; $folders_check_result[$key]['permissions'] = base_convert(fileperms($folder), 10, 8); // $folders_check_result[$key]['owner'] = posix_getpwuid(fileowner($folder)); $folders_check_result[$key]['owner_id'] = fileowner($folder); // $folders_check_result[$key]['group'] = posix_getgrgid(filegroup($folder)); $folders_check_result[$key]['group_id'] = filegroup($folder); // $folders_check_result[$key]['other_stats'] = stat($folder); $folders_check_result[$key]['is_writable'] = is_writable($folder); $test_folder = smt2wp_sanitize_dir_path($folder . '/test-348214'); $test_file = $test_folder . '/test-file-6542.txt'; $mkdir = mkdir($test_folder); $put_contents = file_put_contents($test_file, 'this is just a test. you can delete this file'); $delete_file = unlink($test_file); $rm_dir = rmdir($test_folder); $folders_check_result[$key]['can_make_dir'] = $mkdir; $folders_check_result[$key]['can_write_file'] = $put_contents === false ? false : true; $folders_check_result[$key]['can_delete_file'] = $delete_file; $folders_check_result[$key]['can_rm_dir'] = $rm_dir; } $all_ini_settings = ini_get_all(); $separator = '<<+>>'; $res = $separator . json_encode($folders_check_result); $res .= $separator . json_encode($all_ini_settings); // var_dump($all_ini_settings); return $res; }
/** * Checks if user can use bug_report plugin * * @return boolean * * @since 1.5.1 * */ function bug_report_check_user() { global $username, $bug_report_allow_users, $bug_report_admin_email; bug_report_init(); if (file_exists(SM_PATH . 'plugins/bug_report/admins')) { $auths = file(SM_PATH . 'plugins/bug_report/admins'); array_walk($auths, 'bug_report_array_trim'); $auth = in_array($username, $auths); } else { if (file_exists(SM_PATH . 'config/admins')) { $auths = file(SM_PATH . 'config/admins'); array_walk($auths, 'bug_report_array_trim'); $auth = in_array($username, $auths); } else { if (($adm_id = fileowner(SM_PATH . 'config/config.php')) && function_exists('posix_getpwuid')) { $adm = posix_getpwuid($adm_id); $auth = $username == $adm['name']; } else { $auth = false; } } } if (!empty($bug_report_admin_email) && $bug_report_allow_users) { $auth = true; } return $auth; }
function check_file($f) { echo "\nFile {$f}\n"; echo '1.' . (file_exists($f) ? ' exists' : ' does NOT exist') . " \n"; if (!file_exists($f)) { echo 'Remaining checks skipped' . " \n"; return; } echo '2. is' . (is_file($f) ? '' : ' NOT') . " a file\n"; echo '3. is' . (is_readable($f) ? '' : ' NOT') . " readable\n"; echo '4. is' . (is_writable($f) ? '' : ' NOT') . " writable\n"; echo '5. has permissions ' . substr(sprintf('%o', fileperms($f)), -4) . "\n"; echo '6. owner id ' . fileowner($f) . " (0 on Windows, blank if not permitted)\n"; if (function_exists('posix_geteuid')) { $details = posix_getpwuid(posix_geteuid()); echo '6. owner name ' . $details['name'] . " \n"; echo '6. owner gid ' . $details['gid'] . " \n"; $details = posix_getgrgid($details['gid']); echo '6. group name ' . $details['name'] . " \n"; } echo '7. group id ' . filegroup($f) . " (0 on Windows, blank if not permitted)\n"; if (function_exists('posix_getegid')) { $details = posix_getgrgid(posix_getegid()); echo '7. group name ' . $details['name'] . " \n"; } }
public function listFile($pathname, $pattern = '*') { static $_listDirs = array(); $guid = md5($pathname . $pattern); if (!isset($_listDirs[$guid])) { $dir = array(); $list = glob($pathname . $pattern); foreach ($list as $i => $file) { $dir[$i]['filename'] = basename($file); $dir[$i]['pathname'] = realpath($file); $dir[$i]['owner'] = fileowner($file); $dir[$i]['perms'] = fileperms($file); $dir[$i]['inode'] = fileinode($file); $dir[$i]['group'] = filegroup($file); $dir[$i]['path'] = dirname($file); $dir[$i]['atime'] = fileatime($file); $dir[$i]['ctime'] = filectime($file); $dir[$i]['size'] = filesize($file); $dir[$i]['type'] = filetype($file); $dir[$i]['ext'] = is_file($file) ? strtolower(substr(strrchr(basename($file), '.'), 1)) : ''; $dir[$i]['mtime'] = filemtime($file); $dir[$i]['isDir'] = is_dir($file); $dir[$i]['isFile'] = is_file($file); $dir[$i]['isLink'] = is_link($file); $dir[$i]['isReadable'] = is_readable($file); $dir[$i]['isWritable'] = is_writable($file); } $cmp_func = create_function('$a,$b', '' . "\r\n" . ' $k = "isDir";' . "\r\n" . ' if($a[$k] == $b[$k]) return 0;' . "\r\n" . ' return $a[$k]>$b[$k]?-1:1;' . "\r\n" . ' '); usort($dir, $cmp_func); $this->_values = $dir; $_listDirs[$guid] = $dir; } else { $this->_values = $_listDirs[$guid]; } }
/** * Hook a ejecutar antes del paso 5 de la instalación * Extrae cuales son las fuentes de datos principales que podría utilizarse * * @param array &$data Los datos a utilizar por las plantillas de tipo stepn */ function idpinstaller_hook_step5(&$data) { $data['datasources'] = getDataSources(); $require_mods = array("saml", "idpinstaller", "modinfo", "ldap", "sqlauth", "core", "portal", "sir2skin"); //Modulos obligatorios $ssphpobj = $data['ssphpobj']; $modules = SimpleSAML_Module::getModules(); sort($modules); $perms_ko = array(); $modules_ko = array(); foreach ($modules as $m) { $f = realpath(__DIR__ . '/../../' . $m); if (!file_exists($f . '/default-disable') && !file_exists($f . '/default-enable') && in_array($m, $require_mods)) { $modules_ko[] = $f; } elseif (file_exists($f . '/default-disable') && !is_writable($f . '/default-disable') || file_exists($f . '/default-enable') && !is_writable($f . '/default-enable')) { $perms_ko[] = $f; } else { if (in_array($m, $require_mods)) { //PARA LOS QUE SI QUEREMOS ACTIVAR if (file_exists($f . '/default-disable')) { @unlink($f . '/default-disable'); @touch($f . '/default-enable'); if (!file_exists($f . '/default-enable')) { $data['errors'][] = $ssphpobj->t('{idpinstaller:idpinstaller:step4_error}'); } } } else { //PARA LOS QUE QUEREMOS DESACTIVAR if (file_exists($f . '/default-enable')) { @unlink($f . '/default-enable'); @touch($f . '/default-disable'); if (!file_exists($f . '/default-disable')) { $data['errors'][] = $ssphpobj->t('{idpinstaller:idpinstaller:step4_error}'); } } } } } if (count($modules_ko) > 0) { $data['errors'][] = $ssphpobj->t('{idpinstaller:idpinstaller:step4_error}'); } elseif (count($perms_ko) > 0) { if (function_exists('posix_getgrnam')) { $aux = "<br/>" . $ssphpobj->t('{idpinstaller:idpinstaller:step4_perms_ko}'); $filename = $perms_ko[0]; $file_owner = posix_getpwuid(fileowner($filename)); $group = posix_getgrgid(posix_getgid()); $recursive = is_dir($filename) ? "-R" : ""; $aux .= "<pre>> chown {$recursive} " . $file_owner['name'] . ":" . $group['name'] . " {$filename}\n> chmod {$recursive} g+w " . $filename . "</pre>"; } $data['errors'][] = $aux; $data['errors'][] = $ssphpobj->t("{idpinstaller:idpinstaller:step1_remember_change_perms}"); } if (count($data['errors']) == 0) { $data['info'][] = $ssphpobj->t('{idpinstaller:idpinstaller:step4_all_ok}'); } /*else { $data['errors'][] = $ssphpobj->t('{idpinstaller:idpinstaller:step4_error}'); }*/ return true; }
function paloConfig($directorio, $archivo, $separador = "", $separador_regexp = "", $usuario_proceso = NULL) { $this->directorio = $directorio; $this->archivo = $archivo; $this->separador = $separador; $this->separador_regexp = $separador_regexp; if (!is_null($usuario_proceso)) { $this->usuario_proceso = $usuario_proceso; } else { $arr_user = posix_getpwuid(posix_getuid()); if (is_array($arr_user) && array_key_exists("name", $arr_user)) { $this->usuario_proceso = $arr_user['name']; } } //Debo setear el usuario de sistema y el grupo dependiendo del usuario y grupo propietario del archivo $ruta_archivo = $directorio . "/" . $archivo; if (file_exists($ruta_archivo)) { $arr_usuario = posix_getpwuid(fileowner($ruta_archivo)); if (is_array($arr_usuario)) { $this->usuario_sistema = $arr_usuario['name']; } $arr_grupo = posix_getgrgid(filegroup($ruta_archivo)); if (is_array($arr_grupo)) { $this->grupo_sistema = $arr_grupo['name']; } } /* echo "ruta_archivo=".$ruta_archivo."<br>usuario_sistema=".$this->usuario_sistema."<br>grupo_sistema=". $this->grupo_sistema."<br>usuario_proceso= ".$this->usuario_proceso."<br>"; echo "<script>alert('alto =)');</script>"; */ }
function dir_get_infos($dir = '') { if ($dir == '') { return; } $dir = str_replace('//', '/', $dir . '/'); foreach (self::glob($dir . '*') as $file) { $array = array(); if (!is_dir($file)) { if (self::webos() !== 'Windows') { if (function_exists('posix_getpwuid')) { $tmp = posix_getpwuid(fileowner($file)); $array['owner'] = $tmp['name']; } } $array['md5file'] = md5_file($file); $array['file'] = $file; $array['filectime'] = filectime($file); $array['filemtime'] = filemtime($file); $array['isdir'] = false; $return[] = $array; } else { $return[] = array('file' => $file, 'isdir' => true); } } return serialize($return); }
/** * Returns an array of found directories * * This function checks every found directory if they match either $uid or $gid, if they do * the found directory is valid. It uses recursive function calls to find subdirectories. Due * to the recursive behauviour this function may consume much memory. * * @param string path The path to start searching in * @param integer uid The uid which must match the found directories * @param integer gid The gid which must match the found direcotries * @param array _fileList recursive transport array !for internal use only! * @return array Array of found valid pathes * * @author Martin Burchert <*****@*****.**> * @author Manuel Bernhardt <*****@*****.**> */ function findDirs($path, $uid, $gid) { $list = array($path); $_fileList = array(); while (sizeof($list) > 0) { $path = array_pop($list); $path = makeCorrectDir($path); if (!is_readable($path) || !is_executable($path)) { //return $_fileList; // only 'skip' this directory, #611 continue; } $dh = opendir($path); if ($dh === false) { /* * this should never be called because we checked * 'is_readable' before...but we never know what might happen */ standard_error('cannotreaddir', $path); return null; } else { while (false !== ($file = @readdir($dh))) { if ($file == '.' && (fileowner($path . '/' . $file) == $uid || filegroup($path . '/' . $file) == $gid)) { $_fileList[] = makeCorrectDir($path); } if (is_dir($path . '/' . $file) && $file != '..' && $file != '.') { array_push($list, $path . '/' . $file); } } @closedir($dh); } } return $_fileList; }
public function LoadFiles($request) { $inRoot = false; if (substr($request['path'], 0, strlen($this->_attributes['file_source'])) != $this->_attributes['file_source']) { $request['path'] = $this->_attributes['file_source']; } if ($request['path'] == $this->_attributes['file_source']) { $inRoot = true; } $path = ROOTPATH . $request['path']; $files = array(); $dirs = array(); if (($dir = opendir($path)) === false) { throw new Exception('Directory "' + $path + '" cannot be listed.'); } while (($file = readdir($dir)) !== false) { if ($file == '.') { continue; } if ($inRoot && $file == '..') { continue; } $filepath = $path . $file; if (is_dir($filepath)) { $dirs[] = array('dir' => true, 'name' => $file, 'path' => $request['path'] . $file, 'size' => '', 'owner' => '' . fileowner($filepath), 'mtime' => date('Y-m-d H:i:s', filemtime($filepath))); } else { $files[] = array('dir' => false, 'name' => $file, 'path' => $request['path'] . $file, 'size' => '' . filesize($filepath), 'owner' => '' . fileowner($filepath), 'mtime' => date('Y-m-d H:i:s', filemtime($filepath))); } } closedir($dir); return array('files' => array_merge($dirs, $files), 'cwd' => $request['path']); }
function list_dir($path, $level = 1) { if ($d = dir($path)) { if (preg_match('/^(.*)\\/$/', $path)) { // удаляем / на конце, если есть $path = substr($path, 0, -1); } while (false !== ($entry = $d->read())) { if ($entry != '.' and $entry != '..') { if (is_dir("{$path}/{$entry}")) { echo sprintf("%{$level}s", ' ') . "[{$path}/{$entry}]\n"; list_dir("{$path}/{$entry}", $level + 1); } else { $level1 = 50 - $level; echo sprintf("%{$level}s", ' ') . sprintf("%-{$level1}s", $entry); echo sprintf("%10s", filesize("{$path}/{$entry}")) . "\t" . filetype("{$path}/{$entry}"); echo "\t" . fileowner("{$path}/{$entry}") . "\n"; } } } // if $d->close(); } // if }
/** * Check if user has access to administrative functions * * @return boolean */ function adm_check_user() { global $PHP_SELF, $plugins; require_once SM_PATH . 'functions/global.php'; if (!in_array('administrator', $plugins)) { return FALSE; } if (!sqgetGlobalVar('username', $username, SQ_SESSION)) { $username = ''; } /* This needs to be first, for all non_options pages */ if (strpos('options.php', $PHP_SELF)) { $auth = FALSE; } else { if (file_exists(SM_PATH . 'plugins/administrator/admins')) { $auths = file(SM_PATH . 'plugins/administrator/admins'); array_walk($auths, 'adm_array_trim'); $auth = in_array($username, $auths); } else { if (file_exists(SM_PATH . 'config/admins')) { $auths = file(SM_PATH . 'config/admins'); array_walk($auths, 'adm_array_trim'); $auth = in_array($username, $auths); } else { if (($adm_id = fileowner(SM_PATH . 'config/config.php')) && function_exists('posix_getpwuid')) { $adm = posix_getpwuid($adm_id); $auth = $username == $adm['name']; } else { $auth = FALSE; } } } } return $auth; }
/** * Make sure there is no existing installation * * @return boolean True if there is no existing installation */ protected function canInstall() { $safe_mode = ini_get('safe_mode'); // Safe mode enabled if ($safe_mode != '' && $safe_mode != 0 && $safe_mode != 'Off') { return false; } // Try to create a folder if (@mkdir('test') === false) { return false; } else { clearstatcache(); $self = posix_getpwuid(@fileowner(dirname(__FILE__))); $test = posix_getpwuid(@fileowner('test')); @rmdir('test'); if ($self != $test) { return false; } } // Try to create a file if (@file_put_contents('test.txt', '') === false) { return false; } else { clearstatcache(); $self = posix_getpwuid(@fileowner(__FILE__)); $test = posix_getpwuid(@fileowner('test.txt')); @unlink('test.txt'); if ($self != $test) { return false; } } return true; }
private function renderRelativeImagePath($imageType, $imageFilename, $imageWidth = 0, $imageHeight = 0, $flagStamp = false) { $imageFilename = trim($imageFilename); $imageWidth = intval($imageWidth); $imageHeight = intval($imageHeight); if (!is_bool($flagStamp)) { $flagStamp = false; } if (!in_array($imageType, array('orig', 'crop', 'scale')) || !strlen($imageFilename)) { return ''; } $postfix = ''; if ($imageWidth && $imageHeight) { $postfix .= '_' . $imageWidth . '_' . $imageHeight; } if ($flagStamp) { $postfix .= '_stamp'; } $path = '/' . $imageType . '/' . substr($imageFilename, 0, 2) . '/' . substr($imageFilename, 2, 2); if (!file_exists($this->pathImage . $path)) { mkdir($this->pathImage . $path, 0775, true); $folderOwnerInfo = posix_getpwuid(fileowner($this->pathImage . $path)); if ($folderOwnerInfo['name'] == Cfg::FILE_SYSTEM_SUPERUSER) { chown($this->pathImage . $path, Cfg::FILE_SYSTEM_USERNAME); chgrp($this->pathImage . $path, Cfg::FILE_SYSTEM_USERNAME); } } return $path . '/' . $imageFilename . $postfix . '.jpg'; }
public static function cleanUpCacheContents() { self::cleanUpDirectoryContents(IA_CACHEDIR, true); file_exists(IA_CACHEDIR) || iaCore::instance()->factory('util')->makeDirCascade(IA_CACHEDIR, 0777); $mask = !function_exists('posix_getuid') || function_exists('posix_getuid') && posix_getuid() != fileowner(IA_HOME . 'index' . iaSystem::EXECUTABLE_FILE_EXT) ? 0777 : 0755; chmod(IA_CACHEDIR, $mask); return true; }
/** * @throws \Exception */ public function owner() { if ($this->exist == True) { return fileowner($this->file); } else { throw new Exception('Unable to find file'); } }
function trustedFile($file) { // only trust local files owned by ourselves if (!eregi("^([a-z]+)://", $file) && fileowner($file) == getmyuid()) { return true; } return false; }
public function getFileOwner() { // get the user-ID of the user who owns the loaded file $fileOwnerId = file_exists($this->filePath) && fileowner($this->filePath); if (!$fileOwnerId) { throw new FileSystemFileException('Unable to fetch file owner of ' . $this->filePath); } return $fileOwnerId; }