Beispiel #1
0
/**
 * this method may be called by modules to handle a droplet upload
 **/
function droplets_upload($input)
{
    // Set temp vars
    $temp_dir = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/temp/');
    $temp_file = CAT_Helper_Directory::sanitizePath($temp_dir . $_FILES[$input]['name']);
    $temp_unzip = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/temp/unzip/');
    $errors = array();
    // Try to upload the file to the temp dir
    if (!move_uploaded_file($_FILES[$input]['tmp_name'], $temp_file)) {
        return array('error', CAT_Helper_Directory::getInstance()->lang()->translate('Upload failed'));
    }
    $result = droplets_import($temp_file, $temp_unzip);
    // Delete the temp zip file
    if (file_exists($temp_file)) {
        unlink($temp_file);
    }
    CAT_Helper_Directory::removeDirectory($temp_unzip);
    // show errors
    if (isset($result['errors']) && is_array($result['errors']) && count($result['errors']) > 0) {
        return array('error', $result['errors'], NULL);
    }
    // return success
    return array('success', $result['count']);
}
Beispiel #2
0
/**
 * let the user manage the available backups
 **/
function manage_droplet_backups()
{
    global $parser, $settings, $val, $backend;
    $groups = CAT_Users::get_groups_id();
    if (!CAT_Helper_Droplet::is_allowed('manage_backups', $groups)) {
        $backend->print_error(CAT_Backend::getInstance()->lang()->translate("You don't have the permission to do this"));
    }
    $rows = array();
    $info = NULL;
    $dirh = CAT_Helper_Directory::getInstance();
    // recover
    $recover = $val->get('_REQUEST', 'recover');
    if ($recover && file_exists($dirh->sanitizePath(dirname(__FILE__) . '/export/' . $recover))) {
        if (!function_exists('droplets_upload')) {
            @(include_once dirname(__FILE__) . '/include.php');
        }
        $temp_unzip = $dirh->sanitizePath(CAT_PATH . '/temp/unzip/');
        $result = droplets_import($dirh->sanitizePath(dirname(__FILE__) . '/export/' . $recover), $temp_unzip);
        $info = $backend->lang()->translate('Successfully imported [{{count}}] Droplet(s)', array('count' => $result['count']));
    }
    // delete single backup
    $delbackup = $val->get('_REQUEST', 'delbackup');
    if ($delbackup && file_exists($dirh->sanitizePath(dirname(__FILE__) . '/export/' . $delbackup))) {
        @unlink($dirh->sanitizePath(dirname(__FILE__) . '/export/' . $delbackup));
        $info = $backend->lang()->translate('Backup file deleted: {{file}}', array('file' => $delbackup));
    }
    // delete a list of backups
    // get all marked droplets
    $marked = isset($_POST['markeddroplet']) ? $_POST['markeddroplet'] : array();
    if (count($marked)) {
        $deleted = array();
        foreach ($marked as $file) {
            $file = $dirh->sanitizePath(dirname(__FILE__) . '/export/' . $file);
            if (file_exists($file)) {
                @unlink($file);
                $deleted[] = $backend->lang()->translate('Backup file deleted: {{file}}', array('file' => basename($file)));
            }
        }
        if (count($deleted)) {
            $info = implode('<br />', $deleted);
        }
    }
    $backups = $dirh->scanDirectory($dirh->sanitizePath(dirname(__FILE__) . '/export'), true, true, NULL, array('zip'));
    if (count($backups) > 0) {
        // sort by name
        sort($backups);
        foreach ($backups as $file) {
            // stat
            $stat = stat($file);
            // get zip contents
            $count = CAT_Helper_Zip::getInstance($file)->listContent();
            $rows[] = array('name' => basename($file), 'size' => $stat['size'], 'date' => strftime('%c', $stat['ctime']), 'files' => count($count), 'listfiles' => implode(", ", array_map(create_function('$cnt', 'return $cnt["filename"];'), $count)), 'download' => CAT_Helper_Validate::sanitize_url(CAT_URL . '/modules/droplets/export/' . basename($file)));
        }
    }
    $parser->output('backups', array('rows' => $rows, 'info' => $info, 'backups' => count($backups) ? 1 : NULL));
}
Beispiel #3
0
}
if (!function_exists('droplets_import')) {
    @(include dirname(__FILE__) . '/include.php');
}
$inst_dir = CAT_Helper_Directory::sanitizePath(dirname(__FILE__) . '/install');
$temp_unzip = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/temp/unzip/');
$dirh = CAT_Helper_Directory::getInstance();
$files = $dirh->scanDirectory($inst_dir, true, true, $inst_dir . '/', array('zip'));
if (is_array($files) && count($files)) {
    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