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;
}
Beispiel #2
0
 /**
  * A JParameter object holding the parameters for the plugin
  *
  * @var		A JParameter object
  * @access	public
  * @since	1.5
  */
 public function onCheck()
 {
     $mainframe = JFactory::getApplication();
     //Check System requirements for the editor
     define('JCK_BASE', JPATH_CONFIGURATION . DS . 'plugins' . DS . 'editors' . DS . 'jckeditor');
     if (!JFolder::exists(JCK_BASE)) {
         return;
     }
     $perms = fileperms(JPATH_CONFIGURATION . DS . 'index.php');
     $perms = decoct($perms & 0777);
     $default_fperms = '0644';
     $default_dperms = '0755';
     if ($perms == 777 || $perms == 666) {
         $default_fperms = '0666';
         $default_dperms = '0777';
     }
     $fperms = JCK_BASE . DS . 'config.js';
     if (!stristr(PHP_OS, 'WIN') && JPath::canChmod(JCK_BASE) && $perms != decoct(fileperms($fperms) & 0777)) {
         $path = JCK_BASE . DS . 'plugins';
         if (!JPath::setPermissions($path, $default_fperms, $default_dperms)) {
             $mainframe->enqueueMessage(JText::_('Auto correction failed for incorrect file permissions for the JCK Editor'), 'error');
         }
     }
     $mainframe->enqueueMessage(JText::_('System checked and updated'));
 }
Beispiel #3
0
 /**
  * @param string $filename
  * @throws AException
  */
 public function __construct($filename)
 {
     if (is_dir($filename)) {
         $filename .= (substr($filename, -1) != '/' ? '/' : '') . 'error.txt';
     }
     $this->filename = $filename;
     if (!is_writable(pathinfo($filename, PATHINFO_DIRNAME))) {
         // if it happens see errors in httpd error log!
         throw new AException(AC_ERR_LOAD, 'Error: Log directory ' . DIR_LOGS . ' is non-writable. Please change permissions.');
     }
     //check is log-file writable
     //1.create file if it not exists
     $handle = @fopen($filename, 'a+');
     @fclose($handle);
     //2. then change mode to 777
     if (is_file($filename) && decoct(fileperms($filename) & 0777) != 777) {
         chmod($filename, 0777);
         //3.if log-file non-writable create new one
         if (!is_writable($filename)) {
             $this->filename = DIR_LOGS . 'error_0.txt';
             $handle = @fopen($this->filename, 'a+');
             @fclose($handle);
         }
     }
     if (class_exists('Registry')) {
         // for disabling via settings
         $registry = Registry::getInstance();
         if (is_object($registry->get('config'))) {
             $this->mode = $registry->get('config')->get('config_error_log') ? true : false;
         }
     }
 }
Beispiel #4
0
/**
 * Repair problems in a Typeframe installation.
 * This command will configure BaseModel schemas and fix writeable directory
 * permissions.
 */
function fixPermissions($dir)
{
    static $ftp = null;
    static $depth = 0;
    $depth++;
    if (is_null($ftp)) {
        $ftp = new Typeframe_File();
    }
    if (!file_exists(TYPEF_DIR . '/files' . $dir)) {
        $ftp->mkdir('/files' . $dir);
    }
    if (substr(sprintf('%o', fileperms(TYPEF_DIR . '/files/' . $dir)), -4) !== '0777') {
        $ftp->chmod(0777, '/files' . $dir);
    }
    $dh = opendir(TYPEF_DIR . '/files' . $dir);
    while (($file = readdir($dh)) !== false) {
        if (substr($file, 0, 1) != '.') {
            if (is_dir(TYPEF_DIR . '/files' . $dir . '/' . $file)) {
                fixPermissions($dir . '/' . $file);
            } else {
                $perm = substr(decoct(fileperms(TYPEF_DIR . '/files/' . $dir . '/' . $file)), 1);
                if ($perm !== '0666' && $perm !== '0777') {
                    $ftp->chmod(0666, '/files/' . $dir . '/' . $file);
                }
            }
        }
    }
    $depth--;
    if ($depth == 0) {
        $ftp->close();
        $ftp = null;
    }
}
Beispiel #5
0
 /**
  * install an orbit module
  *
  * @param array 		$params 
  */
 public function action_permissions($params)
 {
     $folders = \CCEvent::fire('ccdoctor.permissions');
     if (!is_array($folders)) {
         $folders = array();
     }
     // add storage directories
     foreach (\ClanCats::$config->get('storage.paths') as $folder) {
         $folders[] = $folder;
     }
     foreach ($folders as $folder) {
         $display_folder = \CCStr::replace($folder, array(CCROOT => ''));
         // create directory if not existing
         if (!is_dir($folder)) {
             if (!mkdir($folder, 0755, true)) {
                 $this->error("doctor could not create folder at: {$display_folder}");
             }
         }
         // check permissions
         $perm = substr(decoct(fileperms($folder)), 2);
         if ($perm < 755) {
             CCCli::line(CCCli::color($perm, 'red') . ' - ' . $display_folder . ' fixing with ' . CCCli::color('755', 'green'));
             if (!chmod($folder, 0755)) {
                 CCCli::line("doctor - is not able to change permissions for: {$display_folder}", 'red');
             }
         } elseif ($perm == 777) {
             CCCli::line(CCCli::color($perm, 'yellow') . ' - ' . $display_folder . ' warning! this can be dangerous.');
         } else {
             $this->success('- ' . $display_folder, $perm);
         }
     }
 }
Beispiel #6
0
 /**
  *
  * Safely create a folder and any folders in between
  * Replaces icms_mkdir()
  *
  * @param string	$target		path to the folder to be created
  * @param integer	$mode		permissions to set on the folder. This is affected by umask in effect
  * @param string	$base		root location for the folder, ICMS_ROOT_PATH or ICMS_TRUST_PATH, for example
  * @param array		$metachars	Characters to exclude from a valid path name
  * @return boolean True if folder is created, False if it is not
  */
 public static function mkdir($target, $mode = 0777, $base = ICMS_ROOT_PATH, $metachars = array())
 {
     if (is_dir($target)) {
         return TRUE;
     }
     if (!isset($metachars)) {
         $metachars = array('[', '?', '"', '.', '<', '>', '|', ' ', ':');
     }
     $base = preg_replace('/[\\|\\/]/', DIRECTORY_SEPARATOR, $base);
     $target = preg_replace('/[\\|\\/]/', DIRECTORY_SEPARATOR, $target);
     if ($base !== '') {
         $target = str_ireplace($base . DIRECTORY_SEPARATOR, '', $target);
         $target = $base . DIRECTORY_SEPARATOR . str_replace($metachars, '_', $target);
     } else {
         $target = str_replace($metachars, '_', $target);
     }
     if (mkdir($target, $mode, TRUE)) {
         // create an index.html file in this directory
         if ($fh = @fopen($target . '/index.html', 'w')) {
             fwrite($fh, '<script>history.go(-1);</script>');
             @fclose($fh);
         }
         if (substr(decoct(fileperms($target)), 2) != $mode) {
             chmod($target, $mode);
         }
     }
     return is_dir($target);
 }
Beispiel #7
0
 /**
  * @param   string $path The path of the Folder
  * @param   int $permission The permission to create the folder with.
  *
  * @return  Folder The domain object for further usage
  *
  * @author  Nicolas Pecher
  * @version Version 0.1, 01.05.2012
  * @version Version 0.2, 14.08.2012 (Bug-fix: default permissions are now set to ug+rwx; using PHP's built in recursive path creation)
  */
 public function create($path, $permission = 0770)
 {
     if (!is_dir($path)) {
         // due to a potential PHP bug with directly passing the permissions
         // we have to initiate a workaround containing explicit formatting as
         // well as umask setting to create the folders with correct permissions
         // to provide a common API, octal numbers must be convert to the
         // internal string representation. otherwise we will get wrong
         // permissions with octal numbers!
         if (is_int($permission)) {
             $permission = decoct($permission);
         }
         // now the correct string representation must be created to ensure
         // correct permissions (leading zero is important!)
         $oct = sprintf('%04u', $permission);
         // to be able to pass the argument as an octal number, the string must
         // be correctly formatted
         $permission = octdec($oct);
         // on some boxes, the current umask prevents correct permission appliance.
         // thus, the umask is set to 0000 to avoid permission shifts. this maybe
         // a PHP bug but umasks unlike 0000 lead to wrong permissions, however.
         $oldUmask = umask(0);
         // the last parameter allows the creation of nested directories
         mkdir($path, $permission, true);
         umask($oldUmask);
     }
     $this->open($path);
     return $this;
 }
function jb_fix_perms_recursive($dir)
{
    //static $file_list;
    if (is_dir($dir) && strpos($dir, '.svn') === false) {
        if (chmod($dir . $file, JB_NEW_DIR_CHMOD)) {
            echo "chmod " . decoct(JB_NEW_DIR_CHMOD) . " " . $dir . $file . "\n";
            flush();
        } else {
            echo 'Seems like the system cannot set the permissions for this dir: ' . $dir . $file . '<br> Please try setting permissions from the command line or using FTP' . "\n";
            flush();
        }
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                //echo "$dir . $file<br>";
                if (filetype($dir . $file) == 'file') {
                    //$file_list[] = $dir . $file;
                    if ($file !== 'index.html' && $file !== '.htaccess' && $file !== 'dl.php') {
                        if (chmod($dir . $file, JB_NEW_FILE_CHMOD)) {
                            echo "chmod " . decoct(JB_NEW_FILE_CHMOD) . " " . $dir . $file . "\n";
                            flush();
                        } else {
                            echo 'Seems like the system cannot set the permissions for this file: ' . $dir . $file . '<br> Please try setting permissions from the command line or using FTP' . "\n";
                            flush();
                        }
                    }
                } elseif (filetype($dir . $file) == 'dir' && $file != '.' && $file != '..') {
                    jb_fix_perms_recursive($dir . $file . '/');
                }
                //echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
            }
            closedir($dh);
        }
    }
}
Beispiel #9
0
 function check_permissions($folder)
 {
     // First check if the specified folder is actually a directory and check if the CHMOD permission is 4 characters in length (e.g 0777 is correct while 777 isn't)
     if (is_dir($folder)) {
         // Get the file permissions
         $permission = substr(decoct(fileperms($folder)), 2);
         // Check if the folder is writable
         $dir_writeable = is_writable($folder);
         // Set up a message based on the permissions
         if ($dir_writeable == true) {
             // Message when the directory is writable
             $dir_message = "The output directory is writable, have fun using iScaffold";
             $message_id = "succes-message";
         } else {
             $dir_message = "The output directory isn't writable, please change the CHMOD values. The current CHMOD value is {$permission}";
             $message_id = "error-message";
         }
         // Create an array containing the results
         $info = array('is_writeable' => $dir_writeable, 'dir_message' => $dir_message, 'message_id' => $message_id);
         // Return it
         return $info;
     } else {
         $dir_message = "The 'output' directory doesn't exists, please create in the root directory of iScaffold 2.0 it and make it writable.";
         $message_id = "error-message";
         $dir_writeable = false;
         // Create an array containing the results
         $info = array('is_writeable' => $dir_writeable, 'dir_message' => $dir_message, 'message_id' => 'error-message');
         return $info;
     }
 }
Beispiel #10
0
 /**
  * Return t3lib helper class
  * @return t3lib_cs
  */
 protected static function typo3()
 {
     static $typo3cs = null;
     if (isset($typo3cs)) {
         return $typo3cs;
     }
     global $CFG;
     // Required files
     require_once $CFG->libdir . '/typo3/class.t3lib_cs.php';
     require_once $CFG->libdir . '/typo3/class.t3lib_div.php';
     // do not use mbstring or recode because it may return invalid results in some corner cases
     $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'iconv';
     $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'iconv';
     // Tell Typo3 we are curl enabled always (mandatory since 2.0)
     $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse'] = '1';
     // And this directory must exist to allow Typo to cache conversion
     // tables when using internal functions
     make_temp_directory('typo3temp/cs');
     // Make sure typo is using our dir permissions
     $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = decoct($CFG->directorypermissions);
     // Default mask for Typo
     $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = $CFG->directorypermissions;
     // This full path constants must be defined too, transforming backslashes
     // to forward slashed because Typo3 requires it.
     define('PATH_t3lib', str_replace('\\', '/', $CFG->libdir . '/typo3/'));
     define('PATH_typo3', str_replace('\\', '/', $CFG->libdir . '/typo3/'));
     define('PATH_site', str_replace('\\', '/', $CFG->tempdir . '/'));
     define('TYPO3_OS', stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin') ? 'WIN' : '');
     $typo3cs = new t3lib_cs();
     return $typo3cs;
 }
 public function setupAction()
 {
     $config = $this->assetic->getConfiguration();
     $mode = null !== ($mode = $config->getUmask()) ? $mode : 0775;
     $displayMode = decoct($mode);
     $cachePath = $config->getCachePath();
     $pathExists = is_dir($cachePath);
     if ($cachePath && !$pathExists) {
         mkdir($cachePath, $mode, true);
         echo "Cache path created '{$cachePath}' with mode '{$displayMode}' \n";
     } else {
         if ($pathExists) {
             echo "Creation of cache path '{$cachePath}' skipped - path exists \n";
         } else {
             echo "Creation of cache path '{$cachePath}' skipped - no path provided \n";
         }
     }
     $webPath = $config->getWebPath();
     $pathExists = is_dir($webPath);
     if ($webPath && !$pathExists) {
         mkdir($webPath, $mode, true);
         echo "Web path created '{$webPath}' with mode '{$displayMode}' \n";
     } else {
         if ($pathExists) {
             echo "Creation of web path '{$webPath}' skipped - path exists \n";
         } else {
             echo "Creation of web path '{$webPath}' skipped - no path provided \n";
         }
     }
 }
 /**
  * job_board_rewrite function.
  *
  * @access public
  * @return void
  */
 public function job_board_rewrite()
 {
     if (!function_exists('get_home_path')) {
         require_once ABSPATH . 'wp-admin/includes/file.php';
     }
     $root_path = get_home_path();
     $file_existing_permission = '';
     /* Getting Rules */
     $rules = 'yes' === get_option('job_board_anti_hotlinking') ? $this->job_board_rewrite_rules() : '';
     /* Rules Force Files to be Downloaded  */
     $forcedownload_rule = "AddType application/octet-stream .pdf .txt\n";
     /* Changing File to Writable Mode  */
     if (file_exists($root_path . '.htaccess') && !is_writable($root_path . '.htaccess')) {
         $file_existing_permission = substr(decoct(fileperms($root_path . '.htaccess')), -4);
         chmod($root_path . '.htaccess', 0777);
     }
     /* Appending .htaccess  */
     if (file_exists($root_path . '.htaccess') && is_writable($root_path . '.htaccess')) {
         $rules = explode("\n", $rules);
         $forcedownload_rule = explode("\n", $forcedownload_rule);
         // Anti-Hotlinking Rules Writing in .htaccess file
         if (!function_exists('insert_with_markers')) {
             require_once ABSPATH . 'wp-admin/includes/misc.php';
         }
         insert_with_markers($root_path . '.htaccess', 'Hotlinking', $rules);
         // Force Download Rules Writing in .htaccess file
         insert_with_markers($root_path . '.htaccess', 'Force Download', $forcedownload_rule);
         /* Revert File Permission  */
         if (!empty($file_existing_permission)) {
             chmod($root_path . '.htaccess', $file_existing_permission);
         }
     }
 }
Beispiel #13
0
 /**
  * @inheritdoc
  */
 public function run(&$cmdParams, &$params)
 {
     $res = true;
     $taskRunner = $this->taskRunner;
     $permList = !empty($cmdParams[0]) ? $cmdParams[0] : [];
     foreach ($permList as $mode => $pathList) {
         $mode = is_string($mode) ? octdec((int) $mode) : $mode;
         foreach ($pathList as $path) {
             $path = $taskRunner->parsePath($path);
             if (file_exists($path)) {
                 $this->controller->stdout("Changing permissions of {$path} to ");
                 $this->controller->stdout('0' . decoct($mode), Console::FG_CYAN);
                 if (!$this->controller->dryRun) {
                     @chmod($path, $mode);
                 } else {
                     $this->controller->stdout(' [dry run]', Console::FG_YELLOW);
                 }
             } else {
                 $this->controller->stderr("Not found: {$path}\n", Console::FG_RED);
             }
             $this->controller->stdout("\n");
         }
     }
     return $res;
 }
Beispiel #14
0
 /**
  * Sets the mode (octal)
  *
  * @param $mode
  *
  * @return $this
  */
 public function setMode($mode)
 {
     if (decoct(octdec($mode)) == $mode) {
         $this->mode = $mode;
     }
     return $this;
 }
Beispiel #15
0
function renderPermissions($perms)
{
    if ($perms === false) {
        return '&mdash;';
    }
    return decoct($perms & 0777);
}
Beispiel #16
0
 protected function onBrowse($tpl = null)
 {
     // Default permissions
     if (interface_exists('JModel')) {
         $params = JModelLegacy::getInstance('Storage', 'AdmintoolsModel');
     } else {
         $params = JModel::getInstance('Storage', 'AdmintoolsModel');
     }
     $dirperms = '0' . ltrim(trim($params->getValue('dirperms', '0755')), '0');
     $fileperms = '0' . ltrim(trim($params->getValue('fileperms', '0644')), '0');
     $dirperms = octdec($dirperms);
     if ($dirperms < 0600 || $dirperms > 0777) {
         $dirperms = 0755;
     }
     $this->dirperms = '0' . decoct($dirperms);
     $fileperms = octdec($fileperms);
     if ($fileperms < 0600 || $fileperms > 0777) {
         $fileperms = 0755;
     }
     $this->fileperms = '0' . decoct($fileperms);
     // File lists
     $model = $this->getModel();
     $listing = $model->getListing();
     $this->listing = $listing;
     $relpath = $model->getState('filter_path', '');
     $this->path = $relpath;
 }
 /**
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param array $files
  * @param $permission
  * @return int
  */
 public function createFolders(\Symfony\Component\Console\Output\OutputInterface $output, $files, $permission)
 {
     $dryRun = $this->getConfigurationHelper()->getDryRun();
     if (empty($files)) {
         $output->writeln('<comment>No files found.</comment>');
         return 0;
     }
     $fs = new Filesystem();
     try {
         if ($dryRun) {
             $output->writeln("<comment>Folders to be created with permission " . decoct($permission) . ":</comment>");
             foreach ($files as $file) {
                 $output->writeln($file);
             }
         } else {
             $output->writeln("<comment>Creating folders with permission " . decoct($permission) . ":</comment>");
             foreach ($files as $file) {
                 $output->writeln($file);
             }
             $fs->mkdir($files, $permission);
         }
     } catch (IOException $e) {
         echo "\n An error occurred while removing the directory: " . $e->getMessage() . "\n ";
     }
 }
 /**
  * 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;
         }
     }
 }
 function handleResults(&$data)
 {
     if (empty($data) || !is_array($data)) {
         return;
     }
     // proccess directories
     if (is_array($data[1])) {
         foreach ($data[1] as $entry) {
             $newData = array();
             $target = $entry->dir;
             $status = 'bad_permissions';
             $issue = $entry->permission;
             $newData['permissions'] = $entry->permission;
             parent::handleLog('permission', $target, $newData, decoct($issue), $status);
         }
     }
     // Process files
     if (is_array($data[2])) {
         foreach ($data[2] as $entry) {
             $newData = array();
             $target = $entry->file;
             $status = 'bad_permissions';
             $issue = $entry->permission;
             $newData['permissions'] = $entry->permission;
             parent::handleLog('permission', $target, $newData, decoct($issue), $status);
         }
     }
 }
function save_config($config)
{
    if (!($fp = fopen($config->root_path . 'OBMConfig.tpl', 'r'))) {
        exit("Failed to open config template");
    }
    $config_data = fread($fp, filesize($config->root_path . 'OBMConfig.tpl'));
    if (strlen($config_data) == 0) {
        exit("Failed to read from config template");
    }
    fclose($fp);
    $config_data = str_replace('%title%', smartstrip($config->title), $config_data);
    $config_data = str_replace('%slash%', $config->slash, $config_data);
    $config_data = str_replace('%host%', $config->host, $config_data);
    $config_data = str_replace('%full_url%', $config->full_url, $config_data);
    $config_data = str_replace('%root_path%', smartstrip($config->root_path), $config_data);
    $config_data = str_replace('%language%', $config->language, $config_data);
    $first_weekday = isset($config->first_weekday) && $config->first_weekday != '' ? $config->first_weekday : '0';
    $config_data = str_replace('%first_weekday%', $first_weekday, $config_data);
    $config_data = str_replace('%tmpdir%', $config->tmpdir, $config_data);
    $config_data = str_replace('%theme%', $config->theme, $config_data);
    $allow_themes = $config->allow_themes === true ? 'true' : 'false';
    $config_data = str_replace('%allow_themes%', $allow_themes, $config_data);
    $allow_password_change = $config->allow_password_change === true ? 'true' : 'false';
    $config_data = str_replace('%allow_password_change%', $allow_password_change, $config_data);
    $config_data = str_replace('%mailer%', $config->mailer, $config_data);
    $config_data = str_replace('%smtp_server%', $config->smtp_server, $config_data);
    $config_data = str_replace('%smtp_port%', $config->smtp_port, $config_data);
    $config_data = str_replace('%max_attachment_size%', $config->max_attachment_size, $config_data);
    $config_data = str_replace('%file_storage_path%', $config->file_storage_path, $config_data);
    $config_data = str_replace('%email_connectstring_options%', $config->email_connectstring_options, $config_data);
    if (!is_string($config->create_mode)) {
        $config->create_mode = decoct((string) $config->create_mode);
    }
    if (strlen($config->create_mode) == 3) {
        $config->create_mode = '0' . $config->create_mode;
    }
    $config_data = str_replace('%create_mode%', $config->create_mode, $config_data);
    $config_data = str_replace('%max_file_size%', $config->max_file_size, $config_data);
    $config_data = str_replace('%webmaster_email%', $config->webmaster_email, $config_data);
    $config_data = str_replace('%db_type%', $config->db_type, $config_data);
    $config_data = str_replace('%db_host%', $config->db_host, $config_data);
    $config_data = str_replace('%db_name%', $config->db_name, $config_data);
    $config_data = str_replace('%db_user%', $config->db_user, $config_data);
    $config_data = str_replace('%db_pass%', $config->db_pass, $config_data);
    $login_image = str_replace($config->host, '', $config->login_image);
    $config_data = str_replace('%login_image%', $login_image, $config_data);
    $config_data = str_replace('%composer_width%', $config->composer_width, $config_data);
    $config_data = str_replace('%composer_height%', $config->composer_height, $config_data);
    $config_data = str_replace('%refresh_rate%', $config->refresh_rate, $config_data);
    $config_data = str_replace('%max_users%', $config->max_users, $config_data);
    $config_data = str_replace('%mime_types_file%', $config->mime_types_file, $config_data);
    $config_data = str_replace('%auth_sources%', $config->auth_sources, $config_data);
    if (!($fp = fopen($config->root_path . 'OBMConfig.php', 'w+'))) {
        exit("Failed to open config file");
    } elseif (!fwrite($fp, $config_data)) {
        exit("Failed to write to config file");
    } else {
        return fclose($fp);
    }
}
Beispiel #21
0
 /**
  * Class process method which is used to execute this component.
  */
 public function process()
 {
     if (substr(decoct(fileperms('./file/achievements/')), 1) != "0777") {
         $this->template()->assign(array('bError' => true))->setTitle('Konsort.org Achievements')->setBreadcrumb('Konsort.org Achievements')->setHeader('cache', array('pager.css' => 'style_css'));
     } else {
         if ($this->request()->get('setHighest', false)) {
             if (Phpfox::getService('achievements.process')->setHighest($this->request()->get('id', 0), $this->request()->get('category', 0))) {
                 $this->url()->send('admincp.achievements.list', null, 'Successfully made the selected acheivement the highest achievement for the category.');
             } else {
                 $this->url()->send('admincp.achievements.list', null, 'There was an error processing your request');
             }
         } elseif ($this->request()->get('unsetHighest', false)) {
             if (Phpfox::getService('achievements.process')->unsetHighest($this->request()->get('id', 0), $this->request()->get('category', 0))) {
                 $this->url()->send('admincp.achievements.list', null, 'Successfully unmade the selected acheivement the highest achievement for the category.');
             } else {
                 $this->url()->send('admincp.achievements.list', null, 'There was an error processing your request');
             }
         }
         $sLimit = 10;
         $iPage = $this->request()->get('page', 0);
         if ($iPage > 0) {
             $iPage--;
         }
         list($iCnt, $aAchievements) = Phpfox::getService('achievements')->getList($iPage, $sLimit);
         Phpfox::getLib('pager')->set(array('page' => $iPage + 1, 'size' => $sLimit, 'count' => $iCnt));
         $this->template()->assign(array('bError' => false, 'iCnt' => $iCnt, 'aAchievements' => $aAchievements))->setTitle('Konsort.org Achievements')->setBreadcrumb('Konsort.org Achievements')->setHeader('cache', array('pager.css' => 'style_css'));
     }
 }
 /**
  * @param string $type
  * @return KalturaTypeReflector
  */
 static function get($type)
 {
     if (!self::$_enabled) {
         return new KalturaTypeReflector($type);
     }
     if (!array_key_exists($type, self::$_loadedTypeReflectors)) {
         $cachedDir = KAutoloader::buildPath(kConf::get("cache_root_path"), "api_v3", "typeReflector");
         if (!is_dir($cachedDir)) {
             mkdir($cachedDir);
             chmod($cachedDir, 0755);
         }
         $cachedFilePath = $cachedDir . DIRECTORY_SEPARATOR . $type . ".cache";
         $typeReflector = null;
         if (file_exists($cachedFilePath)) {
             $cachedData = file_get_contents($cachedFilePath);
             $typeReflector = unserialize($cachedData);
         }
         if (!$typeReflector) {
             $typeReflector = new KalturaTypeReflector($type);
             $cachedData = serialize($typeReflector);
             $bytesWritten = kFile::safeFilePutContents($cachedFilePath, $cachedData);
             if (!$bytesWritten) {
                 $folderPermission = substr(decoct(fileperms(dirname($cachedFilePath))), 2);
                 error_log("Kaltura type reflector could not be saved to path [{$cachedFilePath}] type [{$type}] folder permisisons [{$folderPermission}]");
             }
         }
         self::$_loadedTypeReflectors[$type] = $typeReflector;
     }
     return self::$_loadedTypeReflectors[$type];
 }
 /**
  * Transforms a decimal representation of octal_string to an octal string.
  *
  * @param number $value The decimal representation of octal_string
  * @return string The octal string
  *
  * @throws TransformationFailedException If the given value is not a Boolean.
  */
 public function transform($value)
 {
     if (null === $value) {
         return null;
     }
     return str_pad(decoct($value), 4, '0', STR_PAD_LEFT);
 }
 /**
  * Creates a path with the needed permissions
  *
  * @param OutputInterface $output The output object
  * @param string          $which  Which path?
  * @param string          $path   The path
  * @param int             $mode   The permissions
  *
  * @return bool                   Success
  */
 private function createPath(OutputInterface $output, $which, $path, $mode)
 {
     $displayMode = decoct($mode);
     $pathExists = is_dir($path);
     if (!$path) {
         $output->writeln('Creation of ' . $which . ' path skipped - no path provided');
         return true;
     }
     if (!$pathExists) {
         if (mkdir($path, $mode, true)) {
             $output->writeln($which . ' path created "' . $path . '" with mode "' . $displayMode . '"');
             return true;
         } else {
             $output->writeln('<error>' . $which . ' path "' . $path . '" could not be created.</error>');
             return false;
         }
     }
     $readable = is_readable($path);
     $writable = is_writable($path);
     if ($readable && $writable) {
         $output->writeln('Creation of ' . $which . ' path "' . $path . '" skipped - path exists with correct permissions');
         return true;
     } elseif (!$readable && !$writable) {
         $output->writeln('<error>Creation of ' . $which . ' path "' . $path . '" failed - path exists but is neither readable nor writable</error>');
     } elseif (!$readable) {
         $output->writeln('<error>Creation of ' . $which . ' path "' . $path . '" failed - path exists but is not readable</error>');
     } elseif (!$writable) {
         $output->writeln('<error>Creation of ' . $which . ' path "' . $path . '" failed - path exists but is not writable</error>');
     }
     return false;
 }
Beispiel #25
0
 public function testTransforms()
 {
     $t = new IntMethods();
     $this->assertEquals(decbin(255), $t->getBinary(255));
     $this->assertEquals(dechex(255), $t->getHex(255));
     $this->assertEquals(decoct(255), $t->getOctal(255));
 }
Beispiel #26
0
function install0()
{
    $d = dirname(__FILE__);
    if (substr((string) decoct(fileperms($d)), -3) != '755' && substr((string) decoct(fileperms($d)), -3) != '777') {
        echo "<p>警告:安装目录权限" . $d . "不是0755或是0777,可能无法运行在线安装程序.</p>";
    }
}
Beispiel #27
0
 public static function assertPermissions($excpected, $filename)
 {
     clearstatcache(true);
     $perms = fileperms(self::getPath($filename));
     $rigth = substr(decoct($perms), -3);
     self::assertEquals($excpected, $rigth, self::getPath($filename) . ':' . $perms);
 }
Beispiel #28
0
 public static function add($filename, $content)
 {
     $tar = '';
     $filename = ltrim($filename, '/');
     $binary_first = pack('a100a8a8a8a12A12', $filename, '100644 ', '     0 ', '     0 ', sprintf('%11s ', decoct(strlen($content))), sprintf('%11s', decoct(time())));
     $binary_last = pack('a1a100a6a2a32a32a8a8a155a12', '', '', '', '', '', '', '', '', '', '');
     $checksum = 0;
     for ($i = 0; $i < 148; $i++) {
         $checksum += ord(substr($binary_first, $i, 1));
     }
     for ($i = 148; $i < 156; $i++) {
         $checksum += ord(' ');
     }
     for ($i = 156, $j = 0; $i < 512; $i++, $j++) {
         $checksum += ord(substr($binary_last, $j, 1));
     }
     $tar .= $binary_first;
     $tar .= pack('a8', sprintf('%6s ', decoct($checksum)));
     $tar .= $binary_last;
     $i = 0;
     while ('' != ($buffer = substr($content, $i++ * 512, 512))) {
         $tar .= pack('a512', $buffer);
     }
     return $tar;
 }
function git_commitdiff($projectroot, $project, $hash, $hash_parent)
{
    global $tpl;
    $cachekey = sha1($project) . "|" . $hash . "|" . $hash_parent;
    $git = new Git($projectroot . $project);
    $hash = sha1_bin($hash);
    if (isset($hash_parent)) {
        $hash_parent = sha1_bin($hash_parent);
    }
    if (!$tpl->is_cached('commitdiff.tpl', $cachekey)) {
        $co = git_read_commit($git, $hash);
        $ad = date_str($co['author_epoch']);
        $tpl->assign('committer', $co['committer']);
        $tpl->assign('rfc2822', $ad['rfc2822']);
        if (!isset($hash_parent) && isset($co['parent'])) {
            $hash_parent = sha1_bin($co['parent']);
        }
        $a_tree = isset($hash_parent) ? $git->getObject($hash_parent)->getTree() : array();
        $b_tree = $git->getObject(sha1_bin($co['tree']));
        $difftree = GitTree::diffTree($a_tree, $b_tree);
        $tpl->assign("hash", sha1_hex($hash));
        $tpl->assign("tree", $co['tree']);
        $tpl->assign("hashparent", sha1_hex($hash_parent));
        $tpl->assign("title", $co['title']);
        $refs = read_info_ref($git);
        if (isset($refs[$hash])) {
            $tpl->assign("commitref", $refs[$hash]);
        }
        $tpl->assign("comment", $co['comment']);
        $difftreelines = array();
        $status_map = array(GitTree::TREEDIFF_ADDED => "A", GitTree::TREEDIFF_REMOVED => "D", GitTree::TREEDIFF_CHANGED => "M");
        foreach ($difftree as $file => $diff) {
            $difftreeline = array();
            $difftreeline["from_mode"] = decoct($diff->old_mode);
            $difftreeline["to_mode"] = decoct($diff->new_mode);
            $difftreeline["from_id"] = sha1_hex($diff->old_obj);
            $difftreeline["to_id"] = sha1_hex($diff->new_obj);
            $difftreeline["status"] = $status_map[$diff->status];
            $difftreeline["file"] = $file;
            $difftreeline["md5"] = md5($file);
            $difftreeline["from_type"] = file_type($difftreeline["from_mode"]);
            $difftreeline["to_type"] = file_type($difftreeline["to_mode"]);
            if ($diff->status == GitTree::TREEDIFF_ADDED) {
                $difftreeline['diffout'] = explode("\n", git_diff($git, null, "/dev/null", $diff->new_obj, "b/" . $file));
            } else {
                if ($diff->status == GitTree::TREEDIFF_REMOVED) {
                    $difftreeline['diffout'] = explode("\n", git_diff($git, $diff->old_obj, "a/" . $file, null, "/dev/null"));
                } else {
                    if ($diff->status == GitTree::TREEDIFF_CHANGED && $diff->old_obj != $diff->new_obj) {
                        $difftreeline['diffout'] = explode("\n", git_diff($git, $diff->old_obj, "a/" . $file, $diff->new_obj, "b/" . $file));
                    }
                }
            }
            $difftreelines[] = $difftreeline;
        }
        $tpl->assign("difftreelines", $difftreelines);
    }
    $tpl->display('commitdiff.tpl', $cachekey);
}
Beispiel #30
0
function getPermFlags($data)
{
    $codes = ($data & 2048 ? 'u' : '-') . ($data & 1024 ? 'g' : '-') . ($data & 512 ? 's' : '-');
    $owner = ($data & 256 ? 'r' : '-') . ($data & 128 ? 'w' : '-') . ($data & 64 ? 'x' : '-');
    $group = ($data & 32 ? 'r' : '-') . ($data & 16 ? 'w' : '-') . ($data & 8 ? 'x' : '-');
    $world = ($data & 4 ? 'r' : '-') . ($data & 2 ? 'w' : '-') . ($data & 1 ? 'x' : '-');
    return array('codes' => $codes, 'owner' => $owner, 'group' => $group, 'world' => $world, 'octal' => str_pad(decoct($data), 4, '0', STR_PAD_LEFT), 'flags' => $codes . $owner . $group . $world);
}