Exemple #1
1
 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;
 }
Exemple #2
0
 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];
     }
 }
/**
 * 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;
}
/**
 * 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);
}
Exemple #5
0
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";
    }
}
Exemple #6
0
function dir2array($dir, $content)
{
    if ($dir[strlen($dir) - 1] != '/') {
        $dir .= '/';
    }
    if (!is_dir($dir)) {
        return array();
    }
    $dir_handle = opendir($dir);
    $array = array();
    while ($object = readdir($dir_handle)) {
        if (!in_array($object, array('.', '..'))) {
            $filepath = $dir . $object;
            $file_object = array('name' => $object, 'path' => $dir, 'size' => filesize($filepath), 'type' => filetype($filepath), 'node' => fileinode($filepath), 'group' => filegroup($filepath), 'time' => getTime($filepath), 'perms' => getPermissions($filepath));
            if ($file_object['type'] == 'dir') {
                if ($content == true) {
                    $file_object['content'] = dir2array($filepath, $content);
                }
            } else {
                if ($content == true) {
                    $file_object['content'] = file2base64($filepath);
                }
                $file_object['mime'] = getMime($filepath);
            }
            $array[] = $file_object;
        }
    }
    return $array;
}
 /**
  * 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();
 }
/**
 * 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;
}
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;
}
Exemple #10
0
 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;
     }
 }
Exemple #11
0
 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';
 }
 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>";
     */
 }
Exemple #13
0
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());
    }
}
Exemple #14
0
 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];
     }
 }
Exemple #15
0
 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());
     }
 }
 /**
  * Checking access rights to the folder.
  * @param string $folder - The path to the folder.
  * @return array
  * @static
  * @final
  */
 public static final function PermissionsFolder($folder = null)
 {
     if (Server::Posix() == false) {
         return false;
     }
     if (is_null($folder) === true) {
         $folder = $_SERVER['DOCUMENT_ROOT'];
     }
     return array('value' => substr(sprintf('%o', @fileperms($folder)), -4), 'user' => reset(posix_getpwuid(fileowner($folder))), 'group' => reset(posix_getgrgid(filegroup($folder))));
 }
Exemple #17
0
function get_ownership_groupname($filename)
{
    if (file_exists($filename)) {
        $group = posix_getgrgid(filegroup($filename));
        $groupname = $group['name'];
    } else {
        $groupname = 'no group';
    }
    return $groupname;
}
Exemple #18
0
 public static function matchingLetter($file)
 {
     if (fileowner($file) === getmyuid()) {
         return 'u';
     }
     if (filegroup($file) === getmygid()) {
         return 'g';
     }
     return 'o';
 }
Exemple #19
0
 function getDiff()
 {
     $diff = [];
     if ($this->shouldExist === true || $this->shouldExist === null && file_exists($this->file)) {
         if ($this->contents !== null) {
             if (file_exists($this->file)) {
                 $currentContents = file_get_contents($this->file);
                 if ($currentContents !== $this->contents) {
                     $diff[] = new TextDiff(Diff::change, 'File "' . $this->file . '": updated', [$currentContents, $this->contents]);
                 }
             } else {
                 $diff[] = new TextDiff(Diff::create, 'File "' . $this->file . '": created', ["", $this->contents]);
                 return $diff;
             }
         } else {
             if (!file_exists($this->file)) {
                 $diff[] = new Diff(Diff::create, 'File "' . $this->file . '" created (no content)');
                 return $diff;
             }
         }
         if ($this->permissions !== null) {
             $currentPerm = fileperms($this->file) & 0777;
             if ($currentPerm !== $this->permissions) {
                 $diff[] = new Diff(Diff::change, 'File permissions "' . $this->file . '" changed from ' . $currentPerm . " to " . $this->permissions);
             }
         }
         if ($this->user !== null) {
             $currentUserId = fileowner($this->file);
             $newUserId = $this->user;
             if (!is_numeric($this->user)) {
                 $userDatai = posix_getpwuid($currentUserId);
                 $currentUserId = $userData['name'];
             }
             if ($newUserId !== $currentUserId) {
                 $diff[] = new Diff(Diff::change, 'File owner "' . $this->file . '" changed from ' . $currentUserId . " to " . $newUserId);
             }
         }
         if ($this->group !== null) {
             $currentGroupId = filegroup($this->file);
             $newGroupId = $this->group;
             if (!is_numeric($this->group)) {
                 $groupData = posix_getgrgid($currentGroupId);
                 $currentGroupId = $groupData['name'];
             }
             if ($newGroupId !== $currentGroupId) {
                 $diff[] = new Diff(Diff::change, 'File group "' . $this->file . '" changed from ' . $currentGroupId . " to " . $newGroupId);
             }
         }
     } else {
         if (file_exists($this->file)) {
             $diff[] = new TextDiff(Diff::delete, 'File "' . $this->file . '" deleted', [file_get_contents($this->file), ""]);
         }
     }
     return $diff;
 }
Exemple #20
0
function getGroup($abspath)
{
    if (function_exists('posix_getgrgid')) {
        $gid = @filegroup($abspath);
        $grp = @posix_getgrgid($gid);
        if (@is_string($grp['name']) && !@empty($grp['name'])) {
            return $grp['name'];
        }
    }
    return "?";
}
Exemple #21
0
function getOwner($abspath)
{
    if (function_exists('posix_getpwuid')) {
        $uid = @filegroup($abspath);
        $usr = @posix_getpwuid($uid);
        if (@is_string($usr['name']) && !@empty($usr['name'])) {
            return $usr['name'];
        }
    }
    return "?";
}
 public static function getFileInfo($path)
 {
     $aryFileInfo = array();
     $aryFileInfo["accessed"] = fileatime($path);
     $aryFileInfo["changed"] = filectime($path);
     $aryFileInfo["group"] = filegroup($path);
     $aryFileInfo["inode"] = fileinode($path);
     $aryFileInfo["modified"] = filemtime($path);
     $aryFileInfo["owner"] = fileowner($path);
     $aryFileInfo["permissions"] = fileperms($path);
     $aryFileInfo["size"] = filesize($path);
     return $aryFileInfo;
 }
function test_ecrire($my_dir)
{
    static $chmod = 0;
    $ok = false;
    $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF'];
    $self = basename($script);
    $uid = @fileowner('.');
    $uid2 = @fileowner($self);
    $gid = @filegroup('.');
    $gid2 = @filegroup($self);
    $perms = @fileperms($self);
    // Comparer l'appartenance d'un fichier cree par PHP
    // avec celle du script et du repertoire courant
    if (!$chmod) {
        @rmdir('test');
        spip_unlink('test');
        // effacer au cas ou
        @touch('test');
        if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) {
            $chmod = 0700;
        } else {
            if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) {
                $chmod = 0770;
            } else {
                $chmod = 0777;
            }
        }
        // Appliquer de plus les droits d'acces du script
        if ($perms > 0) {
            $perms = $perms & 0777 | ($perms & 0444) >> 2;
            $chmod |= $perms;
        }
        spip_unlink('test');
    }
    // Verifier que les valeurs sont correctes
    $f = @fopen($my_dir . 'test.php', 'w');
    if ($f) {
        @fputs($f, '<' . '?php $ok = true; ?' . '>');
        @fclose($f);
        @chmod($my_dir . 'test.php', $chmod);
        include $my_dir . 'test.php';
    }
    spip_unlink($my_dir . 'test.php');
    return $ok ? $chmod : false;
}
Exemple #24
0
    /**
     +----------------------------------------------------------
    * 取得目录下面的文件信息
     +----------------------------------------------------------
    * @access public
     +----------------------------------------------------------
    * @param mixed $pathname 路径
     +----------------------------------------------------------
    */
    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);
                //basename取中文名出问题.改用此方法
                //编码转换.把中文的调整一下.
                $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]['isExecutable']= function_exists('is_executable')?is_executable($file):'';
                $dir[$i]['isReadable'] = is_readable($file);
                $dir[$i]['isWritable'] = is_writable($file);
            }
            $cmp_func = create_function('$a,$b', '
			$k  =  "isDir";
			if($a[$k]  ==  $b[$k])  return  0;
			return  $a[$k]>$b[$k]?-1:1;
			');
            // 对结果排序 保证目录在前面
            usort($dir, $cmp_func);
            $this->_values = $dir;
            $_listDirs[$guid] = $dir;
        } else {
            $this->_values = $_listDirs[$guid];
        }
    }
 public function testSbit()
 {
     if ($this->is_windows()) {
         $this->markTestSkipped("s-bit test doesn't apply on Windows.");
     }
     if (is_null(UNISH_USERGROUP)) {
         $this->markTestSkipped("s-bit test skipped because of UNISH_USERGROUP was not set.");
     }
     $dest = UNISH_SANDBOX . '/test-filesystem-sbit';
     mkdir($dest);
     chgrp($dest, UNISH_USERGROUP);
     chmod($dest, 02755);
     // rwxr-sr-x
     $this->drush('pm-download', array('devel'), array('cache' => NULL, 'skip' => NULL, 'destination' => $dest));
     $group = posix_getgrgid(filegroup($dest . '/devel/README.txt'));
     $this->assertEquals($group['name'], UNISH_USERGROUP, 'Group is preserved.');
     $perms = fileperms($dest . '/devel') & 02000;
     $this->assertEquals($perms, 02000, 's-bit is preserved.');
 }
 function isWritable($path)
 {
     if (is_writable($path)) {
         return true;
     }
     $owner = self::owner();
     $group = self::group();
     $perms = self::getPermissions($path);
     if ($owner == fileowner($path)) {
         if ($perms[1] == 'w') {
             return true;
         }
     }
     if ($group == filegroup($path)) {
         if ($perms[4] == 'w') {
             return true;
         }
     }
     return false;
 }
Exemple #27
0
 function have_direct_access()
 {
     if (!is_null($this->have_direct_access)) {
         return $this->have_direct_access;
     }
     $this->have_direct_access = false;
     if (!function_exists('getmyuid') || !function_exists('fileowner') || !function_exists('posix_getgroups') || !function_exists('filegroup')) {
         return $this->have_direct_access;
     }
     $temp_file_name = $this->config->root_path . '/temp-write-test-' . time();
     $temp_handle = @fopen($temp_file_name, 'w');
     if ($temp_handle) {
         if (getmyuid() == @fileowner($temp_file_name) || in_array(@filegroup($temp_file_name), posix_getgroups())) {
             $this->have_direct_access = true;
         }
         @fclose($temp_handle);
         @unlink($temp_file_name);
     }
     return $this->have_direct_access;
 }
Exemple #28
0
 /**
  * testBasic method
  *
  * @access public
  * @return void
  */
 function testBasic()
 {
     $file = __FILE__;
     $this->File = new File($file);
     $result = $this->File->pwd();
     $expecting = $file;
     $this->assertEqual($result, $expecting);
     $result = $this->File->name;
     $expecting = basename(__FILE__);
     $this->assertEqual($result, $expecting);
     $result = $this->File->info();
     $expecting = array('dirname' => dirname(__FILE__), 'basename' => basename(__FILE__), 'extension' => 'php', 'filename' => 'file.test');
     $this->assertEqual($result, $expecting);
     $result = $this->File->ext();
     $expecting = 'php';
     $this->assertEqual($result, $expecting);
     $result = $this->File->name();
     $expecting = 'file.test';
     $this->assertEqual($result, $expecting);
     $result = $this->File->md5();
     $expecting = md5_file($file);
     $this->assertEqual($result, $expecting);
     $result = $this->File->md5(true);
     $expecting = md5_file($file);
     $this->assertEqual($result, $expecting);
     $result = $this->File->size();
     $expecting = filesize($file);
     $this->assertEqual($result, $expecting);
     $result = $this->File->owner();
     $expecting = fileowner($file);
     $this->assertEqual($result, $expecting);
     $result = $this->File->group();
     $expecting = filegroup($file);
     $this->assertEqual($result, $expecting);
     $result = $this->File->Folder();
     $this->assertIsA($result, 'Folder');
     $this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s File permissions tests not supported on Windows');
     $result = $this->File->perms();
     $expecting = '0644';
     $this->assertEqual($result, $expecting);
 }
Exemple #29
0
 public function minify($outfile, $infiles)
 {
     $files = array_slice(func_get_args(), 1);
     $infiles = call_user_func_array('array_merge', $files);
     // 去重复文件
     $infiles = array_unique($infiles, SORT_STRING);
     foreach ($infiles as $filename) {
         $this->load(file_get_contents($filename));
     }
     if ($content = $this->run()) {
         file_put_contents($outfile, str_replace("\n\n", "\n", $content), LOCK_EX);
         if ($filename = reset($infiles)) {
             // 对照修改文件的所有者
             chown($outfile, fileowner($filename));
             chgrp($outfile, filegroup($filename));
         }
         $this->tokens = array();
         $this->ns = array();
     }
     return filesize($outfile);
 }
Exemple #30
0
 /**
  * Factory to build FileInfo from existing file or directory
  *
  * @param string $path path to a file on the local file system
  * @param string $as   optional path to use inside the archive
  * @throws FileInfoException
  * @return FileInfo
  */
 public static function fromPath($path, $as = '')
 {
     clearstatcache(false, $path);
     if (!file_exists($path)) {
         throw new FileInfoException("{$path} does not exist");
     }
     $stat = stat($path);
     $file = new FileInfo();
     $file->setPath($path);
     $file->setIsdir(is_dir($path));
     $file->setMode(fileperms($path));
     $file->setOwner(fileowner($path));
     $file->setGroup(filegroup($path));
     $file->setUid($stat['uid']);
     $file->setGid($stat['gid']);
     $file->setMtime($stat['mtime']);
     if ($as) {
         $file->setPath($as);
     }
     return $file;
 }