示例#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;
 }
示例#2
0
 /**
  * id2group
  *
  * @param int    $id
  * @return string
  */
 public static function id2group($id = 0)
 {
     if (Registry::get('sysType') === 'WIN') {
         return '';
     } else {
         if (function_exists('posix_getgrgid') && ($name = posix_getgrgid($id))) {
             return $name['name'];
         }
         /*
                     exec('id -n -u ' . escapeshellarg($id), $outId, $resultId);
                     if ($resultId === 0) {
                         return trim($outId[0]);
                     }
         */
         exec('getent group ' . escapeshellarg($id), $outGetent, $resultGetent);
         if ($resultGetent === 0) {
             $tmp = explode(':', $outGetent[0], 2);
             return trim($tmp[0]);
         }
         exec(escapeshellcmd(Config::get('Perl', 'path')) . ' -e \'print getgrgid(' . escapeshellarg($id) . ');\'', $outPerl, $resultPerl);
         if ($resultPerl === 0) {
             $tmp = explode('*', $outPerl[0], 2);
             return trim($tmp[0]);
         }
     }
     return $id;
 }
示例#3
0
文件: File.php 项目: Norcoen/nanoftpd
 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;
     }
 }
示例#4
0
function alt_stat($file)
{
    $ss = @stat($file);
    if (!$ss) {
        return false;
    }
    //Couldnt stat file
    $ts = array(0140000 => 'ssocket', 0120000 => 'llink', 0100000 => '-file', 060000 => 'bblock', 040000 => 'ddir', 020000 => 'cchar', 010000 => 'pfifo');
    $tmpsize = $ss['size'];
    $sizemod = 0;
    $modnames = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
    while ($tmpsize > 1024) {
        $tmpsize /= 1024;
        $sizemod++;
    }
    $hrsize = number_format($tmpsize, 2) . $modnames[$sizemod];
    $p = $ss['mode'];
    $t = decoct($ss['mode'] & 0170000);
    // File Encoding Bit
    $str = array_key_exists(octdec($t), $ts) ? $ts[octdec($t)][0] : 'u';
    $str .= ($p & 0x100 ? 'r' : '-') . ($p & 0x80 ? 'w' : '-');
    $str .= $p & 0x40 ? $p & 0x800 ? 's' : 'x' : ($p & 0x800 ? 'S' : '-');
    $str .= ($p & 0x20 ? 'r' : '-') . ($p & 0x10 ? 'w' : '-');
    $str .= $p & 0x8 ? $p & 0x400 ? 's' : 'x' : ($p & 0x400 ? 'S' : '-');
    $str .= ($p & 0x4 ? 'r' : '-') . ($p & 0x2 ? 'w' : '-');
    $str .= $p & 0x1 ? $p & 0x200 ? 't' : 'x' : ($p & 0x200 ? 'T' : '-');
    $s = array('perms' => array('umask' => sprintf("%04o", @umask()), 'human' => $str, 'octal1' => sprintf("%o", $ss['mode'] & 0777), 'octal2' => sprintf("0%o", 0777 & $p), 'decimal' => sprintf("%04o", $p), 'fileperms' => @fileperms($file), 'mode1' => $p, 'mode2' => $ss['mode']), 'owner' => array('fileowner' => $ss['uid'], 'filegroup' => $ss['gid'], 'owner' => @posix_getpwuid($ss['uid']), 'group' => @posix_getgrgid($ss['gid'])), 'file' => array('filename' => $file, 'realpath' => @realpath($file), 'dirname' => @dirname($file), 'realdirname' => @dirname(@realpath($file)), 'basename' => @basename($file)), 'filetype' => array('type' => substr($ts[octdec($t)], 1), 'type_octal' => sprintf("%07o", octdec($t)), 'ext' => pathinfo($file, PATHINFO_EXTENSION), 'is_file' => @is_file($file), 'is_dir' => @is_dir($file), 'is_link' => @is_link($file), 'is_readable' => @is_readable($file), 'is_writable' => @is_writable($file)), 'device' => array('device' => $ss['dev'], 'device_number' => $ss['rdev'], 'inode' => $ss['ino'], 'link_count' => $ss['nlink'], 'link_to' => $s['type'] == 'link' ? @readlink($file) : ''), 'size' => array('size' => $ss['size'], 'hrsize' => $hrsize, 'blocks' => $ss['blocks'], 'block_size' => $ss['blksize']), 'time' => array('mtime' => $ss['mtime'], 'atime' => $ss['atime'], 'ctime' => $ss['ctime'], 'accessed' => @date('Y-m-d H:i:s', $ss['atime']), 'modified' => @date('Y-m-d H:i:s', $ss['mtime']), 'created' => @date('Y-m-d H:i:s', $ss['ctime'])));
    return $s;
}
示例#5
0
 public static function install_check()
 {
     //Check the cache folder
     if (!Backend::checkConfigFile()) {
         if (function_exists('posix_getgrgid') && function_exists('posix_getegid')) {
             if ($group = posix_getgrgid(posix_getegid())) {
                 $group = $group['name'];
             }
         }
         $values = array('file' => Backend::getConfigFileLocation(), 'group' => isset($group) ? $group : false);
         Backend::addContent(Render::file('config_value.fix_config.tpl.php', $values));
         return false;
     }
     if (self::get('settings.ConfigValueSet')) {
         return true;
     }
     if (is_post()) {
         $result = true;
         foreach ($_POST as $name => $value) {
             $name = str_replace('_', '.', $name);
             if (in_array($name, array('application.Title', 'application.Moto', 'application.HelpBoxContent', 'application.Description', 'author.Name', 'author.Email', 'author.Website'))) {
                 if (!self::set($name, $value)) {
                     Backend::addError('Could not set ' . $name);
                     $result = false;
                 }
             } else {
                 var_dump('Rejected:', $name);
             }
         }
         self::set('settings.ConfigValueSet', $result);
         Controller::redirect();
     }
     Backend::addContent(Render::file('config_value.values.tpl.php'));
     return false;
 }
示例#6
0
 protected function _getFileGroupName($filePath)
 {
     clearstatcache();
     $rootStats = stat($filePath);
     $groupInfo = posix_getgrgid($rootStats[5]);
     return $groupInfo['name'];
 }
示例#7
0
文件: Task.php 项目: JanOschii/webird
 /**
  * Get the system group of the user of the current process
  *
  * @return string
  */
 protected function getProcessGroup()
 {
     // $groupInfo = posix_getgrgid(posix_getegid());
     $groupInfo = posix_getgrgid(posix_getgid());
     $groupName = $groupInfo['name'];
     return $groupName;
 }
示例#8
0
/**
 * @version $Id: footer.php 107 2008-07-22 17:27:12Z soeren $
 * @package eXtplorer
 * @copyright soeren 2007
 * @author The eXtplorer project (http://sourceforge.net/projects/extplorer)
 * @author The  The QuiX project (http://quixplorer.sourceforge.net)
 * 
 * @license
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * Alternatively, the contents of this file may be used under the terms
 * of the GNU General Public License Version 2 or later (the "GPL"), in
 * which case the provisions of the GPL are applicable instead of
 * those above. If you wish to allow use of your version of this file only
 * under the terms of the GPL and not to allow others to use
 * your version of this file under the MPL, indicate your decision by
 * deleting  the provisions above and replace  them with the notice and
 * other provisions required by the GPL.  If you do not delete
 * the provisions above, a recipient may use your version of this file
 * under either the MPL or the GPL."
 * 
 * Shows the About Box!
 */
function show_about()
{
    // footer for html-page
    echo "\n<div id=\"ext_footer\" style=\"text-align:center;\">\r\n\t<img src=\"" . _EXT_URL . "/images/MangosWeb_small.png\" align=\"middle\" alt=\"Mangosweb Enhanced Logo\" />\r\n\t<br />\r\n\t" . ext_Lang::msg('your_version') . ": <a href=\"" . $GLOBALS['ext_home'] . "\" target=\"_blank\">eXtplorer {$GLOBALS['ext_version']}</a>\r\n\t<br />\r\n (<a href=\"http://virtuemart.net/index2.php?option=com_versions&amp;catid=5&amp;myVersion=" . $GLOBALS['ext_version'] . "\" onclick=\"javascript:void window.open('http://virtuemart.net/index2.php?option=com_versions&catid=5&myVersion=" . $GLOBALS['ext_version'] . "', 'win2', 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=580,directories=no,location=no'); return false;\" title=\"" . $GLOBALS["messages"]["check_version"] . "\">" . $GLOBALS["messages"]["check_version"] . "</a>)\r\n\t\r\n\t";
    if (function_exists("disk_free_space")) {
        $size = disk_free_space($GLOBALS['home_dir'] . $GLOBALS['separator']);
        $free = parse_file_size($size);
    } elseif (function_exists("diskfreespace")) {
        $size = diskfreespace($GLOBALS['home_dir'] . $GLOBALS['separator']);
        $free = parse_file_size($size);
    } else {
        $free = "?";
    }
    echo '<br />' . $GLOBALS["messages"]["miscfree"] . ": " . $free . " \n";
    if (extension_loaded("posix")) {
        $owner_info = '<br /><br />' . ext_Lang::msg('current_user') . ' ';
        if (ext_isFTPMode()) {
            $my_user_info = posix_getpwnam($_SESSION['ftp_login']);
            $my_group_info = posix_getgrgid($my_user_info['gid']);
        } else {
            $my_user_info = posix_getpwuid(posix_geteuid());
            $my_group_info = posix_getgrgid(posix_getegid());
        }
        $owner_info .= $my_user_info['name'] . ' (' . $my_user_info['uid'] . '), ' . $my_group_info['name'] . ' (' . $my_group_info['gid'] . ')';
        echo $owner_info;
    }
    echo "\r\n\t</div>";
}
示例#9
0
function get_stat($file_name, $path)
{
    if (!empty($file_name && !empty($path))) {
        $file_name_path = realpath($path) . "/" . $file_name;
        if (file_exists($file_name_path)) {
            if (is_readable($file_name_path)) {
                $stat = stat($file_name_path);
                $size = $stat["size"];
                if ($size < 1024) {
                    $size = $stat["size"] . ' octets';
                } elseif ($size > 1024 && $size < 1024000) {
                    $size = $stat["size"] / 1024 . ' Ko (' . $stat["size"] . ' octets)';
                } elseif ($size > 1024000 && $size < 1048576000) {
                    $size = $stat["size"] / 1024 / 1024 . ' Mo (' . $stat["size"] . ' octets)';
                } elseif ($size > 1048576000 && $size < 1073741824000) {
                    $size = $stat["size"] / 1024 / 1024 / 1024 . ' Go (' . $stat["size"] . ' octets)';
                } elseif ($size > 1073741824000 && $size < 1099511627776000) {
                    $size = $stat["size"] / 1024 / 1024 / 1024 / 1024 . ' To (' . $stat["size"] . ' octets)';
                } else {
                    $size = $stat["size"] / 1024 / 1024 / 1024 / 1024 / 1024 . ' Po (' . $stat["size"] . ' octets)';
                }
                send_json(null, array("device number" => $stat["dev"], "inode number" => $stat["ino"], "inode protection mode" => $stat["mode"], "links number" => $stat["nlinks"], "size of the file" => $size, "user owner" => posix_getpwuid($stat["uid"]), "group owner" => posix_getgrgid($stat["gid"]), "device type" => $stat["rdev"], "last access date" => date("F d Y H:i:s.", $stat["atime"]), "last modification date" => date("F d Y H:i:s.", $stat["mtime"]), "last changing right date" => date("F d Y H:i:s.", $stat["ctime"]), "block size" => $stat["blksize"], "512 bits block allowed" => $stat["blocks"]));
            } else {
                send_json("The file " . $file_name . "  can't be readable !! Check this project right !!", null);
            }
        } else {
            send_json("The file " . $file_name . "  don't exists !!", null);
        }
    }
}
示例#10
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";
    }
}
示例#11
0
function renderUGID($uid, $gid)
{
    static $users = array();
    static $groups = array();
    if ($uid === false) {
        $user = '******';
    } else {
        if (!array_key_exists($uid, $users)) {
            if (function_exists('posix_getpwuid')) {
                $uArray = posix_getpwuid($uid);
                $users[$uid] = $uArray['name'];
                //." ($uid)";
            } else {
                $users[$uid] = $uid;
            }
        }
        $user = $users[$uid];
    }
    if ($gid === false) {
        $group = '&mdash;';
    } else {
        if (!array_key_exists($gid, $groups)) {
            if (function_exists('posix_getgrgid')) {
                $gArray = posix_getgrgid($gid);
                $groups[$gid] = $gArray['name'];
                //." ($gid)";
            } else {
                $groups[$gid] = $gid;
            }
        }
        $group = $groups[$gid];
    }
    return "{$user}:{$group}";
}
示例#12
0
 function listDirectory()
 {
     global $osC_Language, $toC_Json, $osC_MessageStack;
     $directory = OSC_ADMIN_FILE_MANAGER_ROOT_PATH;
     if (isset($_REQUEST['directory']) && !empty($_REQUEST['directory'])) {
         $directory .= '/' . urldecode($_REQUEST['directory']);
     } elseif (isset($_REQUEST['goto']) && !empty($_REQUEST['goto'])) {
         $directory .= '/' . urldecode($_REQUEST['goto']);
     }
     $osC_DirectoryListing = new osC_DirectoryListing($directory);
     $osC_DirectoryListing->setStats(true);
     $records = array();
     foreach ($osC_DirectoryListing->getFiles() as $file) {
         $file_owner = function_exists('posix_getpwuid') ? posix_getpwuid($file['user_id']) : '-?-';
         $group_owner = function_exists('posix_getgrgid') ? posix_getgrgid($file['group_id']) : '-?-';
         if ($file['is_directory'] === true) {
             $entry_icon = osc_icon('folder_red.png');
             $action = array(array('class' => 'icon-empty-record', 'qtip' => ''), array('class' => 'icon-empty-record', 'qtip' => ''), array('class' => 'icon-delete-record', 'qtip' => $osC_Language->get('icon_trash')));
         } else {
             $entry_icon = osc_icon('file.png');
             $action = array(array('class' => 'icon-edit-record', 'qtip' => $osC_Language->get('icon_edit')), array('class' => 'icon-download-record', 'qtip' => $osC_Language->get('icon_download')), array('class' => 'icon-delete-record', 'qtip' => $osC_Language->get('icon_trash')));
         }
         $records[] = array('icon' => $entry_icon, 'file_name' => $file['name'], 'is_directory' => $file['is_directory'], 'size' => number_format($file['size']), 'permission' => osc_get_file_permissions($file['permissions']), 'file_owner' => $file_owner, 'group_owner' => $group_owner, 'writeable' => osc_icon(is_writable($osC_DirectoryListing->getDirectory() . '/' . $file['name']) ? 'checkbox_ticked.gif' : 'checkbox_crossed.gif'), 'last_modified_date' => osC_DateTime::getShort(osC_DateTime::fromUnixTimestamp($file['last_modified']), true), 'action' => $action);
     }
     $response = array(EXT_JSON_READER_ROOT => $records);
     echo $toC_Json->encode($response);
 }
示例#13
0
function check_writable_relative($dir)
{
    $uid = posix_getuid();
    $gid = posix_getgid();
    $user_info = posix_getpwuid($uid);
    $user = $user_info['name'];
    $group_info = posix_getgrgid($gid);
    $group = $group_info['name'];
    $fix_cmd = '. ' . _("To fix that, execute following commands as root") . ':<br><br>' . "cd " . getcwd() . "<br>" . "mkdir -p {$dir}<br>" . "chown {$user}:{$group} {$dir}<br>" . "chmod 0700 {$dir}";
    if (!is_dir($dir)) {
        $config_nt = array('content' => _("Required directory " . getcwd() . "{$dir} does not exist") . $fix_cmd, 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto;');
        $nt = new Notification('nt_1', $config_nt);
        $nt->show();
        exit;
    }
    if (!($stat = stat($dir))) {
        $config_nt = array('content' => _("Could not stat configs dir") . $fix_cmd, 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto;');
        $nt = new Notification('nt_1', $config_nt);
        $nt->show();
        exit;
    }
    // 2 -> file perms (must be 0700)
    // 4 -> uid (must be the apache uid)
    // 5 -> gid (must be the apache gid)
    if ($stat[2] != 16832 || $stat[4] !== $uid || $stat[5] !== $gid) {
        $config_nt = array('content' => _("Invalid perms for configs dir") . $fix_cmd, 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto;');
        $nt = new Notification('nt_1', $config_nt);
        $nt->show();
        exit;
    }
}
示例#14
0
function walkdir($path, $exclusions, &$array)
{
    global $root_length;
    $rs = @opendir($path);
    if (!$rs) {
        exit(3);
    }
    while ($file = readdir($rs)) {
        if ($file == '.' || $file == '..') {
            continue;
        }
        $current_path = "{$path}/{$file}";
        if (is_excluded($current_path)) {
            continue;
        }
        $stat = stat($current_path);
        $group_entry = posix_getgrgid($stat['gid']);
        $user_entry = posix_getpwuid($stat['uid']);
        $group = $group_entry['name'];
        $user = $user_entry['name'];
        $relative_path = substr($current_path, $root_length + 1);
        $array[] = $relative_path . ';' . $stat['mode'] . ';' . $stat['nlink'] . ';' . $stat['uid'] . ';' . $user . ';' . $stat['gid'] . ';' . $group . ';' . $stat['size'] . ';' . $stat['atime'] . ';' . $stat['mtime'] . ';' . $stat['ctime'];
        if (is_dir($current_path)) {
            walkdir($current_path, $exclusions, $array);
        }
    }
    closedir($rs);
}
 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>";
     */
 }
 protected function getgroupname($group)
 {
     if ($group && function_exists('posix_getgrgid')) {
         $a = posix_getgrgid($group);
         return $a['name'];
     }
     return $group;
 }
示例#17
0
 protected function getFileGroup($filepath)
 {
     $this->markAsSkippedIfPosixIsMissing();
     $infos = stat($filepath);
     if ($datas = posix_getgrgid($infos['gid'])) {
         return $datas['name'];
     }
 }
示例#18
0
 public static function getAll()
 {
     global $lC_Language;
     if (!defined('LC_ADMIN_FILE_MANAGER_ROOT_PATH')) {
         define('LC_ADMIN_FILE_MANAGER_ROOT_PATH', substr(DIR_FS_CATALOG, 0, -1));
     }
     $media = $_GET['media'];
     $goto_array = array(array('id' => '', 'text' => $lC_Language->get('top_level')));
     if ($_SESSION['fm_directory'] != LC_ADMIN_FILE_MANAGER_ROOT_PATH) {
         $path_array = explode('/', substr($_SESSION['fm_directory'], strlen(LC_ADMIN_FILE_MANAGER_ROOT_PATH) + 1));
         foreach ($path_array as $value) {
             if (sizeof($goto_array) < 2) {
                 $goto_array[] = array('id' => $value, 'text' => $value);
             } else {
                 $parent = end($goto_array);
                 $goto_array[] = array('id' => $parent['id'] . '/' . $value, 'text' => $parent['id'] . '/' . $value);
             }
         }
     }
     $lC_DirectoryListing = new lC_DirectoryListing($_SESSION['fm_directory']);
     $lC_DirectoryListing->setStats(true);
     $result = array('aaData' => array());
     if ($_SESSION['fm_directory'] != LC_ADMIN_FILE_MANAGER_ROOT_PATH) {
         $files = '<td>' . lc_link_object(lc_href_link_admin(FILENAME_DEFAULT, 'file_manager&goto=' . $goto_array[sizeof($goto_array) - 2]['id']), '<span class="icon-up-fat icon-blue">&nbsp;' . $lC_Language->get('parent_level')) . '</td>';
         $result['aaData'][] = array("{$files}", "", "", "", "", "", "", "");
     }
     $cnt = 0;
     foreach ($lC_DirectoryListing->getFiles() as $file) {
         $file_owner = posix_getpwuid($file['user_id']);
         $group_owner = posix_getgrgid($file['group_id']);
         if ($file['is_directory'] === true) {
             $entry_url = lc_href_link_admin(FILENAME_DEFAULT, 'file_manager&directory=' . $file['name']);
             $files = '<td>' . lc_link_object($entry_url, '<span class="icon-folder icon-orange">&nbsp;' . $file['name']) . '</td>';
         } else {
             $entry_url = lc_href_link_admin(FILENAME_DEFAULT, 'file_manager&entry=' . $file['name'] . '&action=save');
             $files = '<td><a href="javascript:void(0);" onclick="editEntry(\'' . $file['name'] . '\')">' . '<span class="icon-page-list icon-blue">&nbsp;' . $file['name'] . '</a></td>';
         }
         $size = '<td>' . number_format($file['size']) . '</td>';
         $perms = '<td>' . lc_get_file_permissions($file['permissions']) . '</td>';
         $user = '******' . $file_owner['name'] . '</td>';
         $group = '<td>' . $group_owner['name'] . '</td>';
         $write = '<td>' . is_writable($lC_DirectoryListing->getDirectory() . '/' . $file['name']) ? '<span class="icon-tick icon-green">' : '<span class="icon-cross icon-red">' . '</td>';
         $last = '<td>' . lC_DateTime::getShort(@date('Y-m-d H:i:s', $file['last_modified']), true) . '</td>';
         if ($file['is_directory'] === false) {
             $action_links = '<a href="' . ((int) ($_SESSION['admin']['access']['file_manager'] < 3) ? '#' : 'javascript://" onclick="editEntry(\'' . $file['name'] . '\')') . '" class="button icon-pencil' . ((int) ($_SESSION['admin']['access']['file_manager'] < 3) ? ' disabled' : NULL) . '">' . ($media === 'mobile-portrait' || $media === 'mobile-landscape' ? NULL : $lC_Language->get('icon_edit')) . '</a>' . '<a href="' . ((int) ($_SESSION['admin']['access']['file_manager'] < 2) ? '#' : lc_href_link_admin(FILENAME_DEFAULT, 'file_manager&entry=' . $file['name'] . '&action=download')) . '" class="button icon-download with-tooltip' . ((int) ($_SESSION['admin']['access']['file_manager'] < 2) ? ' disabled' : NULL) . '" title="' . $lC_Language->get('icon_download') . '"></a>' . '<a href="' . ((int) ($_SESSION['admin']['access']['file_manager'] < 4) ? '#' : 'javascript://" onclick="deleteEntry(\'' . $file['name'] . '\', \'' . urlencode($file['name']) . '\')"') . '" class="button icon-trash with-tooltip' . ((int) ($_SESSION['admin']['access']['file_manager'] < 4) ? ' disabled' : NULL) . '" title="' . $lC_Language->get('icon_delete') . '"></a>';
         } else {
             $action_links = '<a href="' . ((int) ($_SESSION['admin']['access']['file_manager'] < 4) ? '#' : 'javascript://" onclick="deleteEntry(\'' . $file['name'] . '\', \'' . urlencode($file['name']) . '\')"') . '" class="button icon-trash' . ((int) ($_SESSION['admin']['access']['file_manager'] < 4) ? ' disabled' : NULL) . '" title="' . $lC_Language->get('icon_delete') . '"></a>';
         }
         $action = '<td class="align-right vertical-center"><span class="button-group compact">
                ' . $action_links . '
              </span></td>';
         $result['aaData'][] = array("{$files}", "{$size}", "{$perms}", "{$user}", "{$group}", "{$write}", "{$last}", "{$action}");
         $cnt++;
     }
     $result['total'] = $cnt;
     return $result;
 }
 protected function getFileGroup($filepath)
 {
     $this->markAsSkippedIfPosixIsMissing();
     $infos = stat($filepath);
     if ($datas = posix_getgrgid($infos['gid'])) {
         return $datas['name'];
     }
     $this->markTestSkipped('Unable to retrieve file group name');
 }
示例#20
0
function get_ownership_groupname($filename)
{
    if (file_exists($filename)) {
        $group = posix_getgrgid(filegroup($filename));
        $groupname = $group['name'];
    } else {
        $groupname = 'no group';
    }
    return $groupname;
}
示例#21
0
 /**
  * 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))));
 }
示例#22
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;
 }
示例#23
0
 public function get($name)
 {
     $data = posix_getpwnam($name);
     if ($data !== false) {
         $data['groups'] = array_map(function ($group) {
             $group = posix_getgrgid($group);
             return $group['name'];
         }, posix_getgroups());
     }
     return $data;
 }
示例#24
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 "?";
}
 /**
  * Constructor
  *
  * @param string path The path to resource (including file's name)
  * @param string root The FTP root directory
  * @return  string uri
  */
 public function __construct($path, $root)
 {
     $this->path = $path;
     $this->f = new File($root . $path);
     $this->st = stat($this->f->getURI());
     if (!extension_loaded('posix')) {
         $this->st['pwuid'] = $this->st['grgid'] = array('name' => 'none');
     } else {
         $this->st['pwuid'] = posix_getpwuid($this->st['uid']);
         $this->st['grgid'] = posix_getgrgid($this->st['gid']);
     }
 }
示例#26
0
文件: utils.php 项目: nexgenta/shell
 protected function gid($gid)
 {
     static $gidcache = array();
     if (!isset($gidcache[$gid])) {
         if ($n = posix_getgrgid($gid)) {
             $gidcache[$gid] = $n['name'];
         } else {
             $gidcache[$gid] = $uid;
         }
     }
     return $gidcache[$gid];
 }
 protected function element_to_check(&$signal)
 {
     if (!$signal->exists_data_block('lstat')) {
         $signal->set_data_element('lstat', stat($signal->data_element('*')));
     }
     if (!$signal->exists_data_block($this->default_data_key)) {
         $stat = $signal->data_element('lstat');
         $signal->set_data_element($this->default_data_key, posix_getgrgid($stat['gid']));
     }
     if ($signal->exists_data_block($this->default_data_key)) {
         return parent::element_to_check($signal);
     } else {
         return NULL;
     }
 }
示例#28
0
 /**
  * Validate Group
  *
  * Checks to see if file group setting matches expected
  *
  * @param SplFileInfo $file     File to check
  * @param array       $badFiles current array of bad files to report
  *
  * @return array
  * @access public
  */
 public function validateSetting(SplFileInfo $file, array $badFiles)
 {
     if (!empty($this->_targetGroup)) {
         //  Account for name and/or gid
         if (filter_var($this->_targetGroup, FILTER_VALIDATE_INT)) {
             $actualGroup = $file->getGroup();
         } else {
             $group = posix_getgrgid($file->getGroup());
             $actualGroup = $group['name'];
         }
         if ($actualGroup != $this->_targetGroup) {
             $path = substr_replace($file->__toString(), '', 0, strlen(Mage::getBaseDir()) + 1);
             $badFiles[$path]['group'] = $actualGroup;
         }
     }
     return parent::validateSetting($file, $badFiles);
 }
 /**
  * Initialize controller
  *
  * @return void
  */
 public function initialize()
 {
     $this->checkAccess();
     $this->path = new Path();
     $this->fileOwner = function (DirectoryIterator $file) {
         // Windows, fallback, etc.
         $userName = getenv('USERNAME') ?: getenv('USER');
         if (function_exists('posix_getpwuid')) {
             $owner = posix_getpwuid($file->getOwner());
             $group = posix_getgrgid($file->getGroup());
             $userName = isset($owner['name']) ? $owner['name'] : '-?-';
             $groupName = isset($group['name']) ? $group['name'] : '-?-';
             $userName = $userName . ' / ' . $groupName;
         }
         return $userName;
     };
     $this->initDirs();
 }
示例#30
0
 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.');
 }