Пример #1
0
 /**
  * Add info on the user who uploaded the file and the date it was uploaded, and create thumb if it doesn't exist
  */
 protected function get_file_object($file_name)
 {
     // Create the thumb if it doesn't exist
     $thumb = $this->options['upload_dir'] . 'thumb/' . $file_name;
     if (!file_exists(jQueryUpload::thumbFilename($thumb))) {
         $this->create_scaled_image($file_name, $this->options['image_versions']['thumbnail']);
     }
     // Call the parent method to create the file object
     $file = parent::get_file_object($file_name);
     // Add the meta data to the object
     if (is_object($file)) {
         $meta = $this->options['upload_dir'] . 'meta/' . $file_name;
         $file->info = $file->desc = "";
         // If the meta data file exists, extract and render the content
         if (is_file($meta)) {
             $data = unserialize(file_get_contents($meta));
             $file->info = self::renderData($data);
             $file->desc = array_key_exists(2, $data) ? $data[2] : '';
         } elseif (is_link($this->options['upload_dir'] . $file_name)) {
             $title = Title::newFromText($file_name, NS_FILE);
             if (is_object($title) && $title->exists()) {
                 list($uid, $ts, $file->desc) = self::getUploadedFileInfo($title);
                 $file->info = self::renderData(array($uid, wfTimestamp(TS_UNIX, $ts)));
             }
         }
     }
     return $file;
 }
Пример #2
0
function chmod_r($path, $filemode)
{
    if (!is_dir($path)) {
        return chmod($path, $filemode);
    }
    $dh = opendir($path);
    while (($file = readdir($dh)) !== false) {
        if ($file != '.' && $file != '..') {
            $fullpath = $path . '/' . $file;
            if (is_link($fullpath)) {
                return FALSE;
            } elseif (!is_dir($fullpath)) {
                if (!chmod($fullpath, $filemode)) {
                    return FALSE;
                } elseif (!chmod_r($fullpath, $filemode)) {
                    return FALSE;
                }
            }
        }
    }
    closedir($dh);
    if (chmod($path, $filemode)) {
        return TRUE;
    } else {
        return FALSE;
    }
}
Пример #3
0
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     parent::execute($arguments, $options);
     $projectWebPath = sfConfig::get('sf_web_dir');
     $filesystem = new dmFilesystem($this->dispatcher, $this->formatter);
     foreach (array('dmAdminPlugin', 'dmFrontPlugin') as $plugin) {
         $this->logSection('plugin', 'Configuring plugin - ' . $plugin);
         $this->installPluginAssets($plugin, dm::getDir() . '/' . $plugin);
     }
     // remove useless doctrine assets
     if (is_readable($doctrineAssetPath = dmOs::join($projectWebPath, 'sfDoctrinePlugin'))) {
         if (!is_link($doctrineAssetPath)) {
             $filesystem->deleteDirContent($doctrineAssetPath);
         }
         $filesystem->remove($doctrineAssetPath);
     }
     // remove web cache dir
     $webCacheDir = sfConfig::get('sf_web_dir') . '/cache';
     if (is_link($webCacheDir)) {
         $filesystem->remove($webCacheDir);
     }
     // create web cache dir
     $filesystem->mkdir($webCacheDir);
     if (!file_exists(dmOs::join($projectWebPath, 'sf'))) {
         $filesystem->relativeSymlink(realpath(sfConfig::get('sf_symfony_lib_dir') . '/../data/web/sf'), dmOs::join($projectWebPath, 'sf'), true);
     }
 }
 /**
  * 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();
 }
Пример #5
0
 private function add_dir($base, $subdir = "")
 {
     global $page;
     $list = "";
     $dir = opendir("{$base}/{$subdir}");
     while ($filename = readdir($dir)) {
         $fullpath = "{$base}/{$subdir}/{$filename}";
         if (is_link($fullpath)) {
             // ignore
         } else {
             if (is_dir($fullpath)) {
                 if ($filename[0] != ".") {
                     $this->add_dir($base, "{$subdir}/{$filename}");
                 }
             } else {
                 $tmpfile = $fullpath;
                 $tags = $subdir;
                 $tags = str_replace("/", " ", $tags);
                 $tags = str_replace("__", " ", $tags);
                 $list .= "<br>" . html_escape("{$subdir}/{$filename} (" . str_replace(" ", ",", $tags) . ")...");
                 $error = $this->add_image($tmpfile, $filename, $tags);
                 if (is_null($error)) {
                     $list .= "ok\n";
                 } else {
                     $list .= "failed: {$error}\n";
                 }
             }
         }
     }
     closedir($dir);
     // $this->theme->add_status("Adding $subdir", $list);
 }
/**
 * Copy a file, or recursively copy a folder and its contents
 *
 * @author      Aidan Lister <*****@*****.**>
 * @version     1.0.1
 * @link        http://aidanlister.com/2004/04/recursively-copying-directories-in-php/
 * @param       string   $source    Source path
 * @param       string   $dest      Destination path
 * @return      bool     Returns TRUE on success, FALSE on failure
 */
function copyr($source, $dest)
{
    // Check for symlinks
    if (is_link($source)) {
        return symlink(readlink($source), $dest);
    }
    // Simple copy for a file
    if (is_file($source)) {
        return copy($source, $dest);
    }
    // Make destination directory
    if (!is_dir($dest)) {
        mkdir($dest);
    }
    // Loop through the folder
    $dir = dir($source);
    while (false !== ($entry = $dir->read())) {
        // Skip pointers
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        // Deep copy directories
        copyr("{$source}/{$entry}", "{$dest}/{$entry}");
    }
    // Clean up
    $dir->close();
    return true;
}
Пример #7
0
 /**
  * Determine the webroot for a site.
  *
  * Most of this is cribbed from drush's implementation.
  */
 public function get_root_path_and_environment($start_path)
 {
     $root_path = FALSE;
     $start_path = empty($start_path) ? getcwd() : $start_path;
     foreach (array(TRUE, FALSE) as $follow_symlinks) {
         $path = $start_path;
         if ($follow_symlinks && is_link($path)) {
             $path = realpath($path);
         }
         // Check the start path.
         if ($this->determine_valid_root($path)) {
             $root_path = $path;
             break;
         } else {
             // Move up dir by dir and check each.
             while ($path = $this->shift_path_up($path)) {
                 if ($follow_symlinks && is_link($path)) {
                     $path = realpath($path);
                 }
                 if ($this->determine_valid_root($path)) {
                     $root_path = $path;
                     break 2;
                 }
             }
         }
     }
     $this->root_path = $root_path;
 }
/**
 * Locate the actual Drupal root. Based on drush_locate_root().
 */
function locate_root()
{
    $drupal_root = FALSE;
    $start_path = isset($_SERVER['PWD']) ? $_SERVER['PWD'] : '';
    if (empty($start_path)) {
        $start_path = getcwd();
    }
    foreach (array(TRUE, FALSE) as $follow_symlinks) {
        $path = $start_path;
        if ($follow_symlinks && is_link($path)) {
            $path = realpath($path);
        }
        // Check the start path.
        if (valid_root($path)) {
            $drupal_root = $path;
            break;
        } else {
            // Move up dir by dir and check each.
            while ($path = shift_path_up($path)) {
                if ($follow_symlinks && is_link($path)) {
                    $path = realpath($path);
                }
                if (valid_root($path)) {
                    $drupal_root = $path;
                    break 2;
                }
            }
        }
    }
    return $drupal_root;
}
Пример #9
0
 function setUp()
 {
     $this->fixDir = dirname(__FILE__) . '/_fixtures/big_dir';
     $this->readPath = $this->fixDir . '/file_2.5GB';
     // Generate big file
     if (is_link($this->fixDir)) {
         $parentPath = realpath($this->fixDir);
     } else {
         $parentPath = $this->fixDir;
     }
     if (!is_dir($parentPath)) {
         mkdir($this->fixDir);
     }
     $cmd = '/bin/df --portability ' . escapeshellarg($parentPath) . ' | tail -1 | awk \'{print $4}\'';
     //echo $cmd.PHP_EOL;
     $spaceLeft = `{$cmd}`;
     if ($spaceLeft < 5200000) {
         trigger_error("No sufficient space to create " . $this->readPath . ". Cannot test big files. Tip: link " . $this->fixDir . " to a partition with more than 5GB available.", E_USER_WARNING);
     } else {
         $output = null;
         $returnValue = null;
         exec('dd if=/dev/urandom of=' . $this->readPath . ' bs=1M count=2500', $output, $returnValue);
         if ($returnValue != 0) {
             trigger_error('dd failed, unable to generate the big file');
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function failureDescription($other)
 {
     if (!is_string($other)) {
         if (is_object($other)) {
             $type = sprintf('%s#%s', get_class($other), method_exists($other, '__toString') ? $other->__toString() : '');
         } elseif (null === $other) {
             $type = 'null';
         } else {
             $type = gettype($other) . '#' . $other;
         }
         return $type . ' ' . $this->toString();
     }
     if (!file_exists($other)) {
         return 'not file or directory#' . $other . ' ' . $this->toString();
     }
     if (is_link($other)) {
         $type = 'link';
         $perms = lstat($other);
         $perms = $perms['mode'];
     } else {
         $type = is_file($other) ? 'file' : (is_dir($other) ? 'directory' : 'other');
         $perms = fileperms($other);
     }
     return sprintf('%s#%s %o %s %o', $type, $other, $perms, $this->toString(), $this->mask);
 }
Пример #11
0
 public function __construct($environment, $debug)
 {
     if (!ini_get('date.timezone') || !date_default_timezone_get()) {
         $timezone = "Europe/Berlin";
         if (is_link('/etc/localtime')) {
             // Mac OS X (and older Linuxes)
             // /etc/localtime is a symlink to the
             // timezone in /usr/share/zoneinfo.
             $filename = readlink('/etc/localtime');
             if (strpos($filename, '/usr/share/zoneinfo/') === 0) {
                 $timezone = substr($filename, 20);
             }
         } elseif (file_exists('/etc/timezone')) {
             // Ubuntu / Debian.
             $data = file_get_contents('/etc/timezone');
             if ($data) {
                 $timezone = $data;
             }
         } elseif (file_exists('/etc/sysconfig/clock')) {
             // RHEL / CentOS
             $data = parse_ini_file('/etc/sysconfig/clock');
             if (!empty($data['ZONE'])) {
                 $timezone = $data['ZONE'];
             }
         }
         $timezone = preg_replace("/[\\n\\r]+/", "", $timezone);
         date_default_timezone_set($timezone);
     }
     parent::__construct($environment, $debug);
 }
 /**
  * https://bojanz.wordpress.com/2014/03/11/detecting-the-system-timezone-php/
  */
 public function getTimeZone()
 {
     /*
      * Mac OS X (and older Linuxes)
      * /etc/localtime is a symlink to the
      * timezone in /usr/share/zoneinfo.
      */
     if (is_link('/etc/localtime')) {
         $filename = readlink('/etc/localtime');
         if (strpos($filename, '/usr/share/zoneinfo/') === 0) {
             return substr($filename, 20);
         }
         /*
          * Ubuntu / Debian.
          */
     } elseif (file_exists('/etc/timezone')) {
         $data = file_get_contents('/etc/timezone');
         if ($data) {
             return $data;
         }
         /*
          * RHEL / CentOS
          */
     } elseif (file_exists('/etc/sysconfig/clock')) {
         $data = parse_ini_file('/etc/sysconfig/clock');
         if (!empty($data['ZONE'])) {
             return $data['ZONE'];
         }
     }
 }
 public function generatePhpbbLink($varValue, DataContainer $dc)
 {
     if (is_link($dc->activeRecord->phpbb_alias) && readlink($dc->activeRecord->phpbb_alias) == $varValue) {
         Message::addInfo("Path to forum already set");
         return $varValue;
     }
     if (is_link($dc->activeRecord->phpbb_alias) !== false && readlink($dc->activeRecord->phpbb_alias) != $varValue) {
         Message::addInfo("Removing old link");
         unlink($dc->activeRecord->phpbb_alias);
     }
     Message::addInfo("Trying to set Forum Symlink");
     if (file_exists($varValue . "/viewtopic.php")) {
         Message::addInfo("Forum found. Setting Link");
         $result = symlink($varValue, $dc->activeRecord->phpbb_alias);
         if ($result === true) {
             Message::addInfo("Link Set");
         }
         if (!is_link($dc->activeRecord->phpbb_alias . '/ext/ctsmedia') || readlink($dc->activeRecord->phpbb_alias . '/ext/ctsmedia') != "../../contao/vendor/ctsmedia/contao-phpbb-bridge-bundle/src/Resources/phpBB/ctsmedia") {
             Message::addInfo("Setting Vendor Link");
             symlink(TL_ROOT . "/vendor/ctsmedia/contao-phpbb-bridge-bundle/src/Resources/phpBB/ctsmedia", $dc->activeRecord->phpbb_alias . '/ext/ctsmedia');
         }
         Message::addInfo("Please activate the contao extension in the phpbb backend");
     } else {
         //Message::addError("Forum could not be found: ".$varValue . "/viewtopic.php");
         throw new Exception("Forum could not be found: " . $varValue . "/viewtopic.php");
     }
     return $varValue;
 }
Пример #14
0
function fstab()
{
    $sock = new sockets();
    $unix = new unix();
    $mkdir = $unix->find_program("mkdir");
    $mount = $unix->find_program("mount");
    $rm = $unix->find_program("rm");
    $ln = $unix->find_program("ln");
    if (!is_link("/run/shm")) {
        if (!is_dir("/run/shm")) {
            shell_exec("{$mkdir} -m 1777 /run/shm");
        }
        if (!is_link("/dev/shm")) {
            shell_exec("{$rm} -rf /dev/shm");
            shell_exec("{$ln} -s /run/shm /dev/shm");
        }
    }
    echo "Starting......: " . date("H:i:s") . " [SMP] checking fstab...\n";
    $datas = explode("\n", @file_get_contents("/etc/fstab"));
    while (list($num, $val) = each($datas)) {
        if (preg_match("#^shm.*?tmpfs#", $val, $re)) {
            echo "Starting......: " . date("H:i:s") . " [SMP] checking fstab already set...\n";
            return;
        }
    }
    echo "Starting......: " . date("H:i:s") . " [SMP] Adding SHM mount point\n";
    $datas[] = "shm\t/dev/shm\ttmpfs\tnodev,nosuid,noexec\t0\t0";
    @file_put_contents("/etc/fstab", @implode("\n", $datas) . "\n");
    echo "Starting......: " . date("H:i:s") . " [SMP] mounting shm point\n";
    exec("{$mount} shm 2>&1", $results);
    while (list($num, $val) = each($results)) {
        echo "Starting......: " . date("H:i:s") . " [SMP] mounting shm `{$val}`\n";
    }
}
Пример #15
0
function run_files($file)
{
    if (is_link($file)) {
        return;
    }
    if (is_dir($file . '/.')) {
        $dh = opendir($file);
        $files = array();
        while (false !== ($f = readdir($dh))) {
            if ($f[0] != '.') {
                $files[] = $file . '/' . $f;
            }
        }
        closedir($dh);
        foreach ($files as $f) {
            run_files($f);
        }
    } else {
        if (basename($file) == __FILE__) {
            echo "Skipping " . __FILE__ . "\n";
            continue;
        }
        if (preg_match('/\\.php$/', $file)) {
            fix_up_file($file);
        }
    }
}
Пример #16
0
 /**
  * This will go through a peticualr directory and sort it out in to file folders and links
  */
 public function scanDir()
 {
     $this->autoRender = false;
     $dir = $this->request->data('dir');
     $all = scandir($dir);
     array_shift($all);
     array_shift($all);
     $folders = [];
     $files = [];
     foreach ($all as $item) {
         if (is_dir($dir . $item)) {
             array_push($folders, ['name' => $item, 'dir' => $dir, 'connected' => true]);
         } elseif (is_link($dir . $item)) {
             array_push($folders, ['name' => $item . ' (Not Connected)', 'dir' => $dir, 'connected' => false]);
         } else {
             array_push($files, ['name' => $item, 'dir' => $dir]);
         }
     }
     $this->set('files', $files);
     $this->set('folders', $folders);
     if ($this->request->data('first') == true) {
         $this->render();
     } else {
         $this->render('/Elements/DirElement');
     }
 }
Пример #17
0
 /**
  * Remove orphan repositories.
  */
 public static function removeOrphanRepositories()
 {
     $path = Pluf::f('idf_plugin_syncgit_base_repositories', '/home/git/repositories');
     if (!is_dir($path) || is_link($path)) {
         throw new Pluf_Exception_SettingError(sprintf('Directory %s does not exist! Setting "idf_plugin_syncgit_base_repositories not set.', $path));
     }
     if (!is_writable($path)) {
         throw new Exception(sprintf('Repository %s is not writable.', $path));
     }
     $projects = array();
     foreach (Pluf::factory('IDF_Project')->getList() as $project) {
         $projects[] = $project->shortname;
     }
     unset($project);
     $it = new DirectoryIterator($path);
     $orphans = array();
     while ($it->valid()) {
         if (!$it->isDot() && $it->isDir() && !in_array(basename($it->getFileName(), '.git'), $projects)) {
             $orphans[] = $it->getPathName();
         }
         $it->next();
     }
     if (count($orphans)) {
         $cmd = Pluf::f('idf_exec_cmd_prefix', '') . 'rm -rf ' . implode(' ', $orphans);
         exec($cmd);
         clearstatcache();
         while (list(, $project) = each($orphans)) {
             if (is_dir($project)) {
                 throw new Exception(sprintf('Cannot remove %s directory.', $project));
             }
         }
     }
 }
Пример #18
0
 public static function deleteDirectory($dir, $expireTime = null)
 {
     if (!file_exists($dir)) {
         return false;
     }
     if (!is_dir($dir) || is_link($dir)) {
         if ($expireTime) {
             $fileCreationTime = filectime($dir);
             if (time() - $fileCreationTime < $expireTime) {
                 return true;
             }
         }
         return unlink($dir);
     }
     foreach (scandir($dir) as $item) {
         if ($item == '.' || $item == '..') {
             continue;
         }
         if (!org_glizy_helpers_Files::deleteDirectory($dir . "/" . $item, $expireTime)) {
             chmod($dir . "/" . $item, 0777);
             if (!org_glizy_helpers_Files::deleteDirectory($dir . "/" . $item, $expireTime)) {
                 return false;
             }
         }
     }
     return @rmdir($dir);
 }
Пример #19
0
 /**
  * @param $dir
  * @return bool
  */
 public static function deleteDir($dir)
 {
     if (!file_exists($dir)) {
         return true;
     }
     if (!is_dir($dir) || is_link($dir)) {
         return @unlink($dir);
     }
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         $dir = str_replace('/', '\\', $dir);
         exec('rd /s /q "' . $dir . '"');
         return true;
     }
     foreach (scandir($dir) as $item) {
         if ($item === '.' || $item === '..') {
             continue;
         }
         if (!self::deleteDir($dir . DIRECTORY_SEPARATOR . $item)) {
             chmod($dir . DIRECTORY_SEPARATOR . $item, 0777);
             if (!self::deleteDir($dir . DIRECTORY_SEPARATOR . $item)) {
                 return false;
             }
         }
     }
     return @rmdir($dir);
 }
 public function file_list($base, $follow_symlink = false)
 {
     $ret = array($base);
     if (is_dir($base) && ($follow_symlink || !is_link($base))) {
         $dir = scandir($base);
         if ($dir !== false) {
             foreach ($dir as $file) {
                 if ($file == '.' || $file == '..') {
                     continue;
                 }
                 # searching for 225609 files
                 # $ time find /path/to/dir
                 # real	0m2.199s
                 # user	0m0.268s
                 # sys	0m0.592s
                 # $ time php file_list_function.php /path/to/dir
                 # real	0m25.207s
                 # user	0m23.077s
                 # sys	0m1.356s
                 # --------------------------------------------------
                 # $ret = array_merge($ret, file_list("$base/$file"));
                 # --------------------------------------------------
                 # $ time php file_list_function.php /path/to/dir
                 # real	0m3.549s
                 # user	0m2.252s
                 # sys	0m1.284s
                 foreach ($this->file_list($base . DIRECTORY_SEPARATOR . $file, $follow_symlink) as $a) {
                     $ret[] = $a;
                 }
             }
         }
     }
     return $ret;
 }
 /**
  * Clear all files in a given directory.
  *
  * @param  string An absolute filesystem path to a directory.
  *
  * @return void
  */
 public static function clearDirectory($directory)
 {
     if (!is_dir($directory)) {
         return;
     }
     // open a file point to the cache dir
     $fp = opendir($directory);
     // ignore names
     $ignore = array('.', '..', 'CVS', '.svn');
     while (($file = readdir($fp)) !== false) {
         if (!in_array($file, $ignore)) {
             if (is_link($directory . '/' . $file)) {
                 // delete symlink
                 unlink($directory . '/' . $file);
             } else {
                 if (is_dir($directory . '/' . $file)) {
                     // recurse through directory
                     self::clearDirectory($directory . '/' . $file);
                     // delete the directory
                     rmdir($directory . '/' . $file);
                 } else {
                     // delete the file
                     unlink($directory . '/' . $file);
                 }
             }
         }
     }
     // close file pointer
     closedir($fp);
 }
Пример #22
0
 function copyr($source, $dest)
 {
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     if (is_file($source)) {
         $copied = copy($source, $dest);
         $content = file_get_contents($dest);
         $content = str_replace("Forone\\Admin\\Controllers", "App\\Http\\Controllers\\Forone\\Admin\\Controllers", $content);
         file_put_contents($dest, $content);
         return $copied;
     }
     if (!is_dir($dest)) {
         mkdir($dest, 0777, true);
     }
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         copyr("{$source}/{$entry}", "{$dest}/{$entry}");
     }
     $dir->close();
     return true;
 }
Пример #23
0
 protected function _toHtml()
 {
     if (is_link(dirname(Mage::getModuleDir('', 'PostcodeNl_Api'))) && !Mage::getStoreConfig('dev/template/allow_symlink')) {
         throw new Mage_Core_Exception('Postcode.nl API Development: Symlinks not enabled! (set at Admin->System->Configuration->Advanced->Developer->Template Settings)');
     }
     return parent::_toHtml();
 }
Пример #24
0
 /**
  *
  * get size of files in folder
  *
  * @param string $folder the folder to calculate
  * @param bool $deep went thrue suborders
  * @return int folder size in byte
  */
 public static function get_folder_size($folder, $deep = TRUE)
 {
     $files_size = 0;
     if (!is_readable($folder)) {
         return $files_size;
     }
     if ($dir = opendir($folder)) {
         while (FALSE !== ($file = readdir($dir))) {
             if (in_array($file, array('.', '..')) || is_link($folder . '/' . $file)) {
                 continue;
             }
             if ($deep && is_dir($folder . '/' . $file)) {
                 $files_size = $files_size + self::get_folder_size($folder . '/' . $file, TRUE);
             } elseif (is_link($folder . '/' . $file)) {
                 continue;
             } elseif (is_readable($folder . '/' . $file)) {
                 $file_size = filesize($folder . '/' . $file);
                 if (empty($file_size) || !is_int($file_size)) {
                     continue;
                 }
                 $files_size = $files_size + $file_size;
             }
         }
         closedir($dir);
     }
     return $files_size;
 }
Пример #25
0
function getDirectorySize($path)
{
    $totalsize = 0;
    $totalcount = 0;
    $dircount = 0;
    if ($handle = opendir($path)) {
        while (false !== ($file = readdir($handle))) {
            $nextpath = $path . '/' . $file;
            if ($file != '.' && $file != '..' && !is_link($nextpath)) {
                if (is_dir($nextpath)) {
                    $dircount++;
                    $result = getDirectorySize($nextpath);
                    $totalsize += $result['size'];
                    $totalcount += $result['count'];
                    $dircount += $result['dircount'];
                } elseif (is_file($nextpath)) {
                    $totalsize += filesize($nextpath);
                    $totalcount++;
                }
            }
        }
    }
    closedir($handle);
    $total['size'] = $totalsize;
    $total['count'] = $totalcount;
    $total['dircount'] = $dircount;
    return $total;
}
Пример #26
0
 /**
  * Add the complete contents of a directory, recursively.
  */
 public function addDirectory($source)
 {
     $source = str_replace('\\', '/', realpath($source));
     if (is_dir($source) === true) {
         $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
         foreach ($files as $file) {
             $file = str_replace('\\', '/', $file);
             // Ignore "." and ".." folders
             if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) {
                 continue;
             }
             if (!is_link($file)) {
                 $file = realpath($file);
             }
             if (!is_link($file) && is_dir($file)) {
                 $this->addEmptyDir(str_replace($source . '/', '', $file . '/'));
             } else {
                 if (is_link($file)) {
                     // @fixme This actually does not work. It will create a file in the zip, but it
                     // won't be a link pointing somewhere.
                     // I have not found a way to add a working symlink to a zip archive.
                     $this->addFile($file, str_replace($source . '/', '', $file));
                 } else {
                     if (is_file($file)) {
                         $this->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                     }
                 }
             }
         }
     } else {
         if (is_file($source) === true) {
             $this->addFromString(basename($source), file_get_contents($source));
         }
     }
 }
Пример #27
0
 public function validate($input)
 {
     if ($input instanceof \SplFileInfo) {
         return $input->isLink();
     }
     return is_string($input) && is_link($input);
 }
Пример #28
0
function upload_crash_report($files, $agent)
{
    global $g;
    $post = array();
    $counter = 0;
    foreach ($files as $filename) {
        if (is_link($filename) || $filename == '/var/crash/minfree.gz' || $filename == '/var/crash/bounds.gz') {
            continue;
        }
        $post["file{$counter}"] = curl_file_create($filename, "application/x-gzip", basename($filename));
        $counter++;
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://crash.opnsense.org/');
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_VERBOSE, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: multipart/form-data;'));
    $response = curl_exec($ch);
    curl_close($ch);
    return !$response;
}
Пример #29
0
 /**
  * Chmod recursive
  *
  * @see http://www.php.net/manual/fr/function.chmod.php#105570
  */
 private function chmod_R($path, $filemode, $dirmode)
 {
     if (is_dir($path)) {
         if (!chmod($path, $dirmode)) {
             $dirmode_str = decoct($dirmode);
             print "Failed applying filemode '{$dirmode_str}' on directory '{$path}'\n";
             print "  `-> the directory '{$path}' will be skipped from recursive chmod\n";
             return;
         }
         $dh = opendir($path);
         while (($file = readdir($dh)) !== false) {
             if ($file != '.' && $file != '..') {
                 // skip self and parent pointing directories
                 $fullpath = $path . '/' . $file;
                 $this->chmod_R($fullpath, $filemode, $dirmode);
             }
         }
         closedir($dh);
     } else {
         if (is_link($path)) {
             print "link '{$path}' is skipped\n";
             return;
         }
         if (!chmod($path, $filemode)) {
             $filemode_str = decoct($filemode);
             print "Failed applying filemode '{$filemode_str}' on file '{$path}'\n";
             return;
         }
     }
 }
Пример #30
0
Файл: Fso.php Проект: irs/fso
 public static function delete($filename)
 {
     if (!file_exists($filename)) {
         throw new \InvalidArgumentException("File '{$filename}' does not exist.");
     }
     if (is_file($filename) || is_link($filename)) {
         if (is_dir($filename) && self::isOsWindowsNt()) {
             return rmdir($filename);
         } else {
             return unlink($filename);
         }
     }
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($filename), \RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($iterator as $item) {
         if ('.' == $item->getFilename() || '..' == $item->getFilename()) {
             continue;
         }
         if ($item->isDir()) {
             if ($item->isLink() && !self::isOsWindowsNt()) {
                 unlink((string) $item);
             } else {
                 rmdir((string) $item);
             }
         } else {
             unlink((string) $item);
         }
     }
     unset($iterator);
     rmdir($filename);
 }