Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
    if (file_exists($file)) {
        $lines = file($file);
        $output = implode('<br />', $lines);
        $output = str_replace(array('INFO', 'WARN', 'CRIT'), array('<span style="color:#006600">INFO</span>', '<span style="color:#FF6600">WARN</span>', '<span style="color:#990000;font-weight:900;">CRIT</span>'), $output);
        echo $output;
    } else {
        echo CAT_Helper_Validate::getInstance()->lang()->translate("File not found") . ": " . str_ireplace(array(str_replace('\\', '/', CAT_PATH), '\\'), array('/abs/path/to', '/'), $file);
    }
    exit;
}
// download
if (CAT_Helper_Validate::sanitizeGet('dl')) {
    $date = CAT_Helper_Validate::sanitizeGet('dl');
    $file = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/temp/logs/log_' . $date . '.txt');
    if (file_exists($file)) {
        $zip = CAT_Helper_Zip::getInstance(pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME) . '.zip');
        $zip->config('removePath', pathinfo($file, PATHINFO_DIRNAME))->create(array($file));
        if (!$zip->errorCode() == 0) {
            echo CAT_Helper_Validate::getInstance()->lang()->translate("Unable to pack the file") . ": " . str_ireplace(array(str_replace('\\', '/', CAT_PATH), '\\'), array('/abs/path/to', '/'), $file);
        } else {
            $filename = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME) . '.zip';
            header("Pragma: public");
            // required
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Cache-Control: private", false);
            // required for certain browsers
            header("Content-Type: application/zip");
            header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\";");
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: " . filesize($filename));
Ejemplo n.º 3
0
/**
 *
 **/
function export_droplets()
{
    global $parser, $val, $backend;
    $groups = CAT_Users::get_groups_id();
    if (!CAT_Helper_Droplet::is_allowed('export_droplets', $groups)) {
        $backend->print_error($backend->lang()->translate("You don't have the permission to do this"));
    }
    $info = array();
    // get all marked droplets
    $marked = isset($_POST['markeddroplet']) ? $_POST['markeddroplet'] : array();
    if (isset($marked) && !is_array($marked)) {
        $marked = array($marked);
    }
    if (!count($marked)) {
        return $backend->lang()->translate('Please mark some Droplets to export');
    }
    $temp_dir = CAT_PATH . '/temp/droplets/';
    // make the temporary working directory
    @mkdir($temp_dir);
    foreach ($marked as $id) {
        $droplet = CAT_Helper_Droplet::getDroplet($id);
        $name = $droplet["name"];
        $usage = preg_replace('/[\\x00-\\x1F\\x7F]/', "\n//", $droplet['comments']);
        if (substr($usage, -2, 2) == '//') {
            $usage = substr($usage, 0, -3);
        }
        $info[] = 'Droplet: ' . $name . '.php<br />';
        $sFile = $temp_dir . $name . '.php';
        $fh = fopen($sFile, 'w');
        fwrite($fh, '//:' . $droplet['description'] . "\n");
        fwrite($fh, '//:' . $usage . "\n");
        fwrite($fh, $droplet['code']);
        fclose($fh);
        $file = NULL;
        // look for a data file
        if (file_exists(dirname(__FILE__) . '/data/' . $droplet['name'] . '.txt')) {
            $file = CAT_Helper_Directory::sanitizePath(dirname(__FILE__) . '/data/' . $droplet['name'] . '.txt');
        } elseif (file_exists(dirname(__FILE__) . '/data/' . strtolower($droplet['name']) . '.txt')) {
            $file = CAT_Helper_Directory::sanitizePath(dirname(__FILE__) . '/data/' . strtolower($droplet['name']) . '.txt');
        } elseif (file_exists(dirname(__FILE__) . '/data/' . strtoupper($droplet['name']) . '.txt')) {
            $file = CAT_Helper_Directory::sanitizePath(dirname(__FILE__) . '/data/' . strtoupper($droplet['name']) . '.txt');
        }
        if ($file) {
            if (!file_exists($temp_dir . '/data')) {
                @mkdir($temp_dir . '/data');
            }
            copy($file, $temp_dir . '/data/' . basename($file));
        }
    }
    $filename = 'droplets';
    // if there's only a single droplet to export, name the zip-file after this droplet
    if (count($marked) === 1) {
        $filename = 'droplet_' . $name;
    }
    // add current date to filename
    $filename .= '_' . date('Y-m-d');
    // while there's an existing file, add a number to the filename
    if (file_exists(CAT_PATH . '/modules/droplets/export/' . $filename . '.zip')) {
        $n = 1;
        while (file_exists(CAT_PATH . '/modules/droplets/export/' . $filename . '_' . $n . '.zip')) {
            $n++;
        }
        $filename .= '_' . $n;
    }
    $temp_file = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/temp/' . $filename . '.zip');
    // create zip
    $archive = CAT_Helper_Zip::getInstance($temp_file)->config('removePath', $temp_dir);
    $file_list = $archive->create($temp_dir);
    if ($file_list == 0 && !CAT_Helper_Validate::sanitizeGet('ajax')) {
        list_droplets($backend->lang()->translate("Packaging error") . ' - ' . $archive->errorInfo(true));
    } else {
        $export_dir = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/droplets/export');
        // create the export folder if it doesn't exist
        if (!file_exists($export_dir)) {
            mkdir($export_dir, 0777);
        }
        if (!copy($temp_file, $export_dir . '/' . $filename . '.zip') && !CAT_Helper_Validate::sanitizeGet('ajax')) {
            echo '<div class="drfail">', $backend->lang()->translate('Unable to move the exported ZIP-File!'), '</div>';
            $download = CAT_URL . '/temp/' . $filename . '.zip';
        } else {
            unlink($temp_file);
            $download = CAT_Helper_Validate::sanitize_url(CAT_URL . '/modules/droplets/export/' . $filename . '.zip');
        }
    }
    CAT_Helper_Directory::removeDirectory($temp_dir);
    if (CAT_Helper_Validate::sanitizeGet('ajax')) {
        return true;
    }
    return $backend->lang()->translate('Backup created') . '<br /><br />' . implode("\n", $info) . '<br /><br /><a href="' . $download . '">Download</a>';
}
Ejemplo n.º 4
0
 /**
  * constructor
  **/
 public function __construct($zipfile = NULL)
 {
     // get driver
     self::$zip = self::getDriver('PclZip', $zipfile);
     return self::$zip;
 }
Ejemplo n.º 5
0
 /**
  * Install a Droplet from a ZIP file (the ZIP may contain more than one
  * Droplet)
  *
  * @access public
  * @param  string  $temp_file - name of the ZIP file
  * @return array   see droplets_import() method
  *
  **/
 public static function installDroplet($temp_file)
 {
     $self = self::getInstance();
     $temp_unzip = CAT_PATH . '/temp/droplets_unzip/';
     CAT_Helper_Directory::createDirectory($temp_unzip);
     $errors = array();
     $imports = array();
     $count = 0;
     // extract file
     $list = CAT_Helper_Zip::getInstance($temp_file)->config('Path', $temp_unzip)->extract();
     // get .php files
     $files = CAT_Helper_Directory::getPHPFiles($temp_unzip, $temp_unzip . '/');
     // now, open all *.php files and search for the header;
     // an exported droplet starts with "//:"
     foreach ($files as $file) {
         if (pathinfo($file, PATHINFO_FILENAME) !== 'index' && pathinfo($file, PATHINFO_EXTENSION) == 'php') {
             $description = NULL;
             $usage = NULL;
             $code = NULL;
             // Name of the Droplet = Filename
             $name = pathinfo($file, PATHINFO_FILENAME);
             // Slurp file contents
             $lines = file($temp_unzip . '/' . $file);
             // First line: Description
             if (preg_match('#^//\\:(.*)$#', $lines[0], $match)) {
                 $description = addslashes($match[1]);
                 array_shift($lines);
             }
             // Second line: Usage instructions
             if (preg_match('#^//\\:(.*)$#', $lines[0], $match)) {
                 $usage = addslashes($match[1]);
                 array_shift($lines);
             }
             // there may be more comment lines; they will be added to the usage instructions
             while (preg_match('#^//(.*)$#', $lines[0], $match)) {
                 $usage .= addslashes(trim($match[1]));
                 array_shift($lines);
             }
             if (!$description && !$usage) {
                 // invalid file
                 $errors[$file] = CAT_Helper_Directory::getInstance()->lang()->translate('No valid Droplet file (missing description and/or usage instructions)');
                 continue;
             }
             // Remaining: Droplet code
             $code = implode('', $lines);
             // replace 'evil' chars in code
             $tags = array('<?php', '?>', '<?');
             //$code = addslashes(str_replace($tags, '', $code));
             $code = str_replace($tags, '', $code);
             // Already in the DB?
             $stmt = 'INSERT';
             $id = NULL;
             $found = $self->db()->query("SELECT * FROM `:prefix:mod_droplets` WHERE name=:name", array('name' => $name));
             if ($found->rowCount()) {
                 $stmt = 'REPLACE';
                 $id = $found->fetchColumn();
             }
             // execute
             $q = "{$stmt} INTO `:prefix:mod_droplets` SET " . ($id ? 'id=' . $id . ', ' : '') . '`name`=:name, `code`=:code, `description`=:desc, ' . '`modified_when`=:when, `modified_by`=:userid, ' . '`active`=:active, `comments`=:usage';
             $params = array('name' => $name, 'code' => $code, 'desc' => $description, 'when' => time(), 'userid' => CAT_Users::get_user_id(), 'active' => 1, 'usage' => $usage);
             $result = $self->db()->query($q, $params);
             if (!$self->db()->isError()) {
                 $count++;
                 $imports[$name] = 1;
             } else {
                 $errors[$name] = $self->db()->getError();
             }
         }
         // check for data directory
         if (file_exists($temp_unzip . '/data')) {
             // copy all files
             CAT_Helper_Directory::copyRecursive($temp_unzip . '/data', dirname(__FILE__) . '/data/');
         }
     }
     // cleanup; ignore errors here
     CAT_Helper_Directory::removeDirectory($temp_unzip);
     return array('count' => $count, 'errors' => $errors, 'imported' => $imports);
 }
Ejemplo n.º 6
0
     exit;
 } else {
     $current = CAT_Helper_Upload::getInstance($_FILES[$field_name]);
     if ($current->uploaded) {
         // If-schleife wenn überschreiben
         if ($file_overwrite != '') {
             $current->file_overwrite = true;
         } else {
             $current->file_overwrite = false;
         }
         $current->process($file_path);
         if ($current->processed) {
             $unzip_file = $val->sanitizePost('unzip_' . $file_id);
             $delete_file = $val->sanitizePost('delete_zip_' . $file_id);
             if ($unzip_file != '') {
                 $archive = CAT_Helper_Zip::getInstance($current->file_dst_pathname);
                 $archive->config('Path', $dirh->sanitizePath($file_path));
                 $archive->extract();
                 if ($archive->errorInfo() != 0) {
                     $ajax = array('message' => $backend->lang()->translate('The ZIP couldn\'t be unpacked.') . $archive->errorInfo(), 'success' => false);
                     print json_encode($ajax);
                     exit;
                 }
                 // ==============================================
                 // ! Delete archiv after everything worked fine
                 // ==============================================
                 if ($delete_file != '') {
                     $dirh->removeDirectory($current->file_dst_pathname);
                 }
             }
             // =================================
Ejemplo n.º 7
0
            $inc = true;
            break;
        }
    }
    if (!$inc) {
        trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
    }
}
// handle upload
if (CAT_Helper_Validate::sanitizePost('upload') && isset($_FILES['userfile']) && is_array($_FILES['userfile'])) {
    $p = CAT_Helper_Upload::getInstance($_FILES['userfile'], CAT_PATH . '/temp');
    $p->file_overwrite = true;
    $p->process(CAT_PATH . '/temp');
    if ($p->processed) {
        $subdir = $p->file_dst_name_body;
        $z = CAT_Helper_Zip::getInstance(CAT_PATH . '/temp/' . $p->file_dst_name)->config('Path', CAT_PATH . '/modules/lib_jquery/plugins/' . $subdir);
        $z->extract();
    }
}
// get already installed plugins
$files = CAT_Helper_Directory::getInstance()->maxRecursionDepth(0)->getDirectories(CAT_PATH . '/modules/lib_jquery/plugins', CAT_PATH . '/modules/lib_jquery/plugins/');
$readmes = jqpmgr_getReadmes($files);
$parser->setPath(CAT_PATH . '/modules/jquery_plugin_mgr/templates/default');
$parser->output('tool', array('plugins' => $files, 'readmes' => $readmes));
function jqpmgr_getReadmes($plugins)
{
    $readme_filenames = array('readme_' . strtolower(LANGUAGE) . '.html', 'readme.html');
    $dir = CAT_PATH . '/modules/lib_jquery/plugins/';
    $readmes = array();
    foreach ($plugins as $p) {
        foreach ($readme_filenames as $rfile) {
Ejemplo n.º 8
0
    foreach ($files as $file) {
        // only files that have 'droplet_' as prefix
        if (!preg_match('~^droplet_~i', $file)) {
            continue;
        }
        // ignore the result here
        droplets_import($inst_dir . '/' . $file, $temp_unzip);
    }
}
// if it's an upgrade from the old droplets module...
if ($is_upgrade) {
    require CAT_Helper_Directory::sanitizePath(CAT_PATH . '/framework/LEPTON/Helper/Zip.php');
    // create backup copy
    $temp_file = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/temp/droplets_module_backup.zip');
    $temp_dir = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/droplets');
    $zip1 = new CAT_Helper_Zip($temp_file);
    $zip1->config('removePath', $temp_dir);
    $file_list = $zip1->create($temp_dir);
    if ($file_list == 0) {
        $admin->print_error($admin->lang->translate("Packaging error") . ' - ' . $zip1->errorInfo(true));
    }
    // remove the folder
    rm_full_dir(CAT_PATH . '/modules/droplets');
    // re-create the folder
    @mkdir(CAT_PATH . '/modules/droplets', 0755);
    // unpack the compatibility files
    $temp_file = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/droplets/install/droplets.zip');
    $zip2 = new CAT_Helper_Zip($temp_file);
    $zip2->config('Path', CAT_Helper_Directory::sanitizePath(CAT_PATH . '/modules/droplets'));
    $zip2->extract($temp_file);
}