예제 #1
0
 /**
  * copy directory structure with files
  *
  * @access public
  * @param  string  $dirsource
  * @param  string  $dirdest
  **/
 public static function copyRecursive($dirsource, $dirdest)
 {
     if (is_dir($dirsource)) {
         $dir_handle = dir($dirsource);
     } else {
         return false;
     }
     if (!is_object($dir_handle)) {
         return false;
     }
     while ($file = $dir_handle->read()) {
         if ($file != "." && $file != "..") {
             if (!is_dir($dirsource . "/" . $file)) {
                 copy($dirsource . "/" . $file, $dirdest . '/' . $file);
                 if ($file != '.svn' && $file != '.git') {
                     CAT_Helper_Directory::setPerms($dirdest . "/" . $file);
                 }
             } else {
                 CAT_Helper_Directory::createDirectory($dirdest . '/' . $file);
                 self::copyRecursive($dirsource . "/" . $file, $dirdest . '/' . $file);
             }
         }
     }
     $dir_handle->close();
     return true;
 }
예제 #2
0
 function change_mode($name)
 {
     return CAT_Helper_Directory::setPerms($name);
 }
예제 #3
0
 if (is_writable(CAT_PATH . $ajax['folder_path'])) {
     $folder_name = $val->sanitizePost('name');
     if (!$folder_name) {
         $folder_name = $backend->lang()->translate('New folder');
     }
     $create_folder = CAT_PATH . $ajax['folder_path'] . '/' . $folder_name;
     $counter = 1;
     while (is_dir($create_folder)) {
         $create_folder = CAT_PATH . $ajax['folder_path'] . '/' . $folder_name . ' ' . $counter;
         $counter++;
     }
     // =====================================================
     // ! Try to create new folder; also creates an index.php
     // =====================================================
     if (CAT_Helper_Directory::createDirectory($create_folder, NULL, true)) {
         CAT_Helper_Directory::setPerms($create_folder);
         if (is_writable($create_folder)) {
             $ajax['message'] = $backend->lang()->translate('Folder created successfully');
             $ajax['created'] = true;
         } else {
             $ajax['message'] = $backend->lang()->translate('Unable to write to the target directory');
             $ajax['created'] = false;
         }
     } else {
         $ajax['message'] = $backend->lang()->translate('Unable to write to the target directory');
         $ajax['created'] = false;
     }
 } else {
     $ajax['message'] = $backend->lang()->translate('Unable to write to the target directory');
     $ajax['created'] = false;
 }
예제 #4
0
 /**
  * This function is used to install a module (addon); requires an
  * already existing ZIP file. Use installUploaded() to handle uploads.
  *
  * @access public
  * @param
  **/
 public static function installModule($zipfile, $silent = false, $remove_zip_on_error = false)
 {
     // keep old modules happy
     global $wb, $admin, $database, $backend;
     if (!is_object($admin) && is_object($backend)) {
         $admin =& $backend;
     }
     // keep old modules happy
     $self = self::getInstance();
     $self->log()->LogDebug('installModule');
     $extension = pathinfo($zipfile, PATHINFO_EXTENSION);
     $sourcedir = pathinfo($zipfile, PATHINFO_DIRNAME);
     // Set temp vars
     $temp_dir = CAT_PATH . '/temp/';
     $temp_unzip = $temp_dir . '/unzip_' . pathinfo($zipfile, PATHINFO_FILENAME) . '/';
     $self->log()->LogDebug(sprintf('file extension [%s], source dir [%s], remove zip [%s]', $extension, $sourcedir, $remove_zip_on_error));
     $self->log()->LogDebug(sprintf('temp dir [%s], unzip dir [%s]', $temp_dir, $temp_unzip));
     // Check for language or template/module
     if ($extension == 'php') {
         $temp_unzip = $zipfile;
     } elseif ($extension == 'zip') {
         $self->log()->LogDebug(sprintf('creating temp. unzip dir [%s]', $temp_unzip));
         CAT_Helper_Directory::createDirectory($temp_unzip);
         $self->log()->LogDebug(sprintf('zip file [%s], output dir [%s]', $zipfile, $temp_unzip));
         // Setup the PclZip object and unzip the files to the temp unzip folder
         $list = CAT_Helper_Zip::getInstance($zipfile)->config('Path', CAT_Helper_Directory::sanitizePath($temp_unzip))->extract();
         // check if anything was extracted
         if (!$list) {
             $self->log()->LogDebug(sprintf('No $list from ZIP-Helper, removing [%s]', $temp_unzip));
             CAT_Helper_Directory::removeDirectory($temp_unzip);
             if ($remove_zip_on_error) {
                 CAT_Helper_Directory::removeDirectory($zipfile);
             }
             if (!$silent) {
                 self::printError('Unable to extract the file. Please check the ZIP format.');
             }
             return false;
         }
         // check for info.php
         if (!file_exists($temp_unzip . '/info.php')) {
             // check subfolders for info.php
             $info = CAT_Helper_Directory::getInstance(1)->maxRecursionDepth(4)->findFile('info.php', $temp_unzip);
             if (!$info) {
                 $self->log()->LogDebug(sprintf('No info.php found, removing [%s]', $temp_unzip));
                 CAT_Helper_Directory::removeDirectory($temp_unzip);
                 if ($remove_zip_on_error) {
                     CAT_Helper_Directory::removeDirectory($zipfile);
                 }
                 if (!$silent) {
                     self::printError('Invalid installation file. No info.php found. Please check the ZIP format.');
                 }
                 return false;
             } else {
                 $temp_infofile = pathinfo($info, PATHINFO_DIRNAME);
                 $self->log()->LogDebug(sprintf('set $temp_infofile to [%s]', $temp_infofile));
             }
         } else {
             $temp_infofile = $temp_unzip;
         }
     } else {
         $self->log()->LogDebug(sprintf('Unknown extension [%s], "php" or "zip" expected, removing [%s]', $extension, $temp_unzip));
         CAT_Helper_Directory::removeDirectory($temp_unzip);
         if ($remove_zip_on_error) {
             CAT_Helper_Directory::removeDirectory($zipfile);
         }
         if (!$silent) {
             self::printError('Invalid installation file. Wrong extension. Please check the ZIP format.');
         }
         return false;
     }
     // Check the info.php file / language file
     $precheck_errors = NULL;
     if ($addon_info = self::checkInfo($temp_infofile)) {
         $precheck_errors = self::preCheckAddon($zipfile, $temp_infofile, false);
     } else {
         $self->log()->LogDebug(sprintf('Unable to load info file [%s], removing [%s]', $temp_infofile, $temp_unzip));
         CAT_Helper_Directory::removeDirectory($temp_unzip);
         if ($remove_zip_on_error) {
             CAT_Helper_Directory::removeDirectory($zipfile);
         }
         if (!$silent) {
             self::printError($self->lang()->translate('Invalid installation file. {{error}}', array('error' => $self->lang()->translate('Unable to find info.php'))));
         }
         return false;
     }
     // precheck failed
     if ($precheck_errors != '' && !is_bool($precheck_errors)) {
         $self->log()->LogDebug(sprintf('Pre-installation check(s) failed, removing [%s]', $temp_unzip));
         CAT_Helper_Directory::removeDirectory($temp_unzip);
         if (!$silent) {
             self::printError($precheck_errors, $_SERVER['SCRIPT_NAME'], false);
         }
         return false;
     }
     // So, now we have done all preinstall checks, lets see what to do next
     $addon_directory = $addon_info['addon_function'] == 'language' ? $addon_info['module_code'] . '.php' : $addon_info['module_directory'];
     // Set module directory
     $addon_dir = CAT_PATH . '/' . $addon_info['addon_function'] . 's/' . $addon_directory;
     $action = 'install';
     if (file_exists($addon_dir) && $addon_info['addon_function'] != 'language') {
         $action = 'upgrade';
         // look for old info.php
         $previous_info = self::checkInfo($addon_dir);
         if ($previous_info) {
             // compare versions
             if (self::versionCompare($previous_info['module_version'], $addon_info['module_version'], '>=')) {
                 $self->log()->LogDebug(sprintf('Version check found no difference between installed and uploaded version, removing [%s]', $temp_unzip));
                 CAT_Helper_Directory::removeDirectory($temp_unzip);
                 if ($remove_zip_on_error) {
                     CAT_Helper_Directory::removeDirectory($zipfile);
                 }
                 if (!$silent) {
                     self::printError('Already installed');
                 } else {
                     self::$error = 'already installed';
                 }
                 return false;
             }
         }
     }
     // Make sure the module dir exists, and chmod if needed
     if ($addon_info['addon_function'] != 'language') {
         $self->log()->LogDebug(sprintf('Creating addon directory [%s]', $addon_dir));
         CAT_Helper_Directory::createDirectory($addon_dir);
         // copy files from temp folder
         // we use $temp_infofile here as source as it is the folder the
         // info.php file resides
         if (CAT_Helper_Directory::copyRecursive($temp_infofile, $addon_dir) !== true) {
             $self->log()->LogDebug(sprintf('Copy failed, removing [%s]', $temp_unzip));
             CAT_Helper_Directory::removeDirectory($temp_unzip);
             if ($remove_zip_on_error) {
                 CAT_Helper_Directory::removeDirectory($zipfile);
             }
             if (!$silent) {
                 self::printError('Unable to install - error copying files');
             }
             return false;
         }
         // remove temp
         $self->log()->LogDebug(sprintf('removing [%s]', $temp_unzip));
         CAT_Helper_Directory::removeDirectory($temp_unzip);
         if ($remove_zip_on_error) {
             CAT_Helper_Directory::removeDirectory($zipfile);
         }
     }
     // load the module info into the database
     if (!self::loadModuleIntoDB($addon_dir, $action, self::checkInfo($addon_dir))) {
         $self->log()->LogDebug(sprintf('Loading module into DB failed, removing [%s]', $temp_unzip));
         CAT_Helper_Directory::removeDirectory($temp_unzip);
         CAT_Helper_Directory::removeDirectory($addon_dir);
         if (!$silent) {
             self::printError($self->db()->getError());
         }
         return false;
     }
     // Run the modules install // upgrade script if there is one
     if (file_exists($addon_dir . '/' . $action . '.php')) {
         $self->log()->LogDebug(sprintf('Running [%s]', $addon_dir . '/' . $action . '.php'));
         require $addon_dir . '/' . $action . '.php';
     }
     if ($action == 'install' && $addon_info['addon_function'] == 'language') {
         $target = CAT_Helper_Directory::sanitizePath($addon_dir);
         // for manual install...
         if ($zipfile !== $target) {
             rename($zipfile, $addon_directory);
             CAT_Helper_Directory::setPerms($addon_directory);
         }
     }
     // set module permissions
     if ($addon_info['addon_function'] == 'module' && ($addon_info['module_function'] == 'page' || $addon_info['module_function'] == 'tool') || $addon_info['addon_function'] == 'template') {
         self::setModulePermissions($addon_info);
     }
     return true;
 }
예제 #5
0
파일: Page.php 프로젝트: ircoco/BlackCatCMS
 /**
  *
  *
  **/
 public static function createAccessFile($filename, $page_id)
 {
     $filename = CAT_Helper_Directory::sanitizePath($filename);
     // check if $filename is a full path (may be 'link' db value)
     if (!preg_match('~^' . CAT_Helper_Directory::sanitizePath(CAT_PATH . PAGES_DIRECTORY) . '~i', $filename)) {
         $filename = CAT_Helper_Directory::sanitizePath(CAT_PATH . PAGES_DIRECTORY . '/' . dirname($filename) . '/' . self::getFilename(basename($filename)) . PAGE_EXTENSION);
     }
     $pages_path = CAT_Helper_Directory::sanitizePath(CAT_PATH . PAGES_DIRECTORY);
     $rel_pages_dir = str_replace($pages_path, '', CAT_Helper_Directory::sanitizePath(dirname($filename)));
     $rel_filename = str_replace($pages_path, '', CAT_Helper_Directory::sanitizePath($filename));
     // prevent system directories and files from being overwritten (level 0)
     $denied = false;
     if (PAGES_DIRECTORY == '') {
         $forbidden_dirs = self::$instance->_config['forbidden_l0'];
         $forbidden_files = self::$instance->_config['forbidden_filenames_l0'];
         $search = explode('/', $rel_filename);
         $denied = in_array($search[1], $forbidden_dirs);
         $denied = in_array($search[1], $forbidden_files);
     }
     if (true === is_writable($pages_path) && false == $denied) {
         // First make sure parent folder exists
         $parent_folders = explode('/', $rel_pages_dir);
         $parents = '';
         foreach ($parent_folders as $parent_folder) {
             if ($parent_folder != '/' && $parent_folder != '') {
                 $parents .= '/' . $parent_folder;
                 if (!file_exists($pages_path . $parents)) {
                     // create dir; also creates index.php (last param = true)
                     CAT_Helper_Directory::createDirectory($pages_path . $parents, OCTAL_DIR_MODE, true);
                     CAT_Helper_Directory::setPerms($pages_path . $parents);
                 }
             }
         }
         $step_back = str_repeat('../', substr_count($rel_pages_dir, '/') + (PAGES_DIRECTORY == "" ? 0 : 1));
         $content = '<?php' . "\n";
         $content .= "/**\n *\tThis file is autogenerated by BlackCat CMS Version " . CAT_VERSION . "\n";
         $content .= " *\tDo not modify this file!\n */\n";
         $content .= "\t" . '$page_id = ' . $page_id . ';' . "\n";
         $content .= "\t" . 'require_once \'' . $step_back . 'index.php\';' . "\n";
         $content .= '?>';
         /**
          *  write the file
          */
         $fp = fopen($filename, 'w');
         if ($fp) {
             fwrite($fp, $content, strlen($content));
             fclose($fp);
             /**
              *  Chmod the file
              */
             CAT_Helper_Directory::getInstance()->setPerms($filename);
         } else {
             CAT_Backend::getInstance()->print_error('Error creating access file in the pages directory, cannot open file');
             return false;
         }
         return true;
     } else {
         CAT_Backend::getInstance()->print_error('Error creating access file in the pages directory, path not writable or forbidden file / directory name');
         return false;
     }
 }