Example #1
0
function langPackUnpack($unpack_type, $full_file)
{
    global $sugar_config;
    global $base_upgrade_dir;
    global $base_tmp_upgrade_dir;
    $manifest = array();
    if (!empty($full_file)) {
        $base_filename = pathinfo(urldecode($full_file), PATHINFO_FILENAME);
    } else {
        return "Empty filename supplied";
    }
    $manifest_file = extractManifest($full_file, $base_tmp_upgrade_dir);
    if ($unpack_type == 'module') {
        $license_file = extractFile($full_file, 'LICENSE.txt', $base_tmp_upgrade_dir);
    }
    if (is_file($manifest_file)) {
        if ($unpack_type == 'module' && is_file($license_file)) {
            copy($license_file, $base_upgrade_dir . '/' . $unpack_type . '/' . $base_filename . "-license.txt");
        }
        copy($manifest_file, $base_upgrade_dir . '/' . $unpack_type . '/' . $base_filename . "-manifest.php");
        require_once $manifest_file;
        validate_manifest($manifest);
        $upgrade_zip_type = $manifest['type'];
        mkdir_recursive("{$base_upgrade_dir}/{$upgrade_zip_type}");
        $target_path = "{$base_upgrade_dir}/{$upgrade_zip_type}/{$base_filename}";
        $target_manifest = $target_path . "-manifest.php";
        if (isset($manifest['icon']) && $manifest['icon'] != "") {
            $icon_location = extractFile($full_file, $manifest['icon'], $base_tmp_upgrade_dir);
            $path_parts = pathinfo($icon_location);
            copy($icon_location, $target_path . "-icon." . $path_parts['extension']);
        }
        // move file from uploads to cache
        // FIXME: where should it be?
        if (copy($full_file, $target_path . ".zip")) {
            copy($manifest_file, $target_manifest);
            unlink($full_file);
            // remove tempFile
            return "The file {$base_filename} has been uploaded.<br>\n";
        } else {
            unlinkTempFiles($manifest_file, $full_file);
            return "There was an error uploading the file, please try again!<br>\n";
        }
    } else {
        die("The zip file is missing a manifest.php file.  Cannot proceed.");
    }
    unlinkTempFiles($manifest_file, '');
}
function extractManifest($zip_file)
{
    return extractFile($zip_file, "manifest.php");
}
Example #3
0
 function extractManifest($zip_file)
 {
     logThis('extracting manifest.');
     return extractFile($zip_file, "manifest.php");
 }
Example #4
0
function langPackUnpack($unpack_type = 'langpack', $full_file = '')
{
    global $sugar_config;
    global $base_upgrade_dir;
    global $base_tmp_upgrade_dir;
    $manifest = array();
    if (!empty($full_file)) {
        $tempFile = $full_file;
        $base_filename = urldecode($tempFile);
        $base_filename = preg_replace("#\\\\#", "/", $base_filename);
        $base_filename = basename($base_filename);
    } else {
        $tempFile = getcwd() . '/' . $sugar_config['upload_dir'] . $_FILES['language_pack']['name'];
        $base_filename = $_FILES['language_pack']['name'];
    }
    $manifest_file = extractManifest($tempFile, $base_tmp_upgrade_dir);
    if ($unpack_type == 'module') {
        $license_file = extractFile($tempFile, 'LICENSE.txt', $base_tmp_upgrade_dir);
    }
    if (is_file($manifest_file)) {
        if ($unpack_type == 'module' && is_file($license_file)) {
            copy($license_file, getcwd() . '/' . $sugar_config['upload_dir'] . 'upgrades/' . $unpack_type . '/' . remove_file_extension($base_filename) . "-license.txt");
        }
        copy($manifest_file, getcwd() . '/' . $sugar_config['upload_dir'] . 'upgrades/' . $unpack_type . '/' . remove_file_extension($base_filename) . "-manifest.php");
        require_once $manifest_file;
        validate_manifest($manifest);
        $upgrade_zip_type = $manifest['type'];
        // exclude the bad permutations
        /*if($upgrade_zip_type != "langpack") {
              unlinkTempFiles($manifest_file, $tempFile);
              die( "You can only upload module packs, theme packs, and language packs on this page." );
          }*/
        //$base_filename = urldecode( $_REQUEST['language_pack_escaped'] );
        $base_filename = preg_replace("#\\\\#", "/", $base_filename);
        $base_filename = basename($base_filename);
        mkdir_recursive("{$base_upgrade_dir}/{$upgrade_zip_type}");
        $target_path = getcwd() . "/{$base_upgrade_dir}/{$upgrade_zip_type}/{$base_filename}";
        $target_manifest = remove_file_extension($target_path) . "-manifest.php";
        if (isset($manifest['icon']) && $manifest['icon'] != "") {
            $icon_location = extractFile($tempFile, $manifest['icon'], $base_tmp_upgrade_dir);
            $path_parts = pathinfo($icon_location);
            copy($icon_location, remove_file_extension($target_path) . "-icon." . $path_parts['extension']);
        }
        // move file from cache/upload to cache/upload/langpack
        if (copy($tempFile, $target_path)) {
            copy($manifest_file, $target_manifest);
            unlink($tempFile);
            // remove tempFile
            return "The file {$base_filename} has been uploaded.<br>\n";
        } else {
            unlinkTempFiles($manifest_file, $tempFile);
            return "There was an error uploading the file, please try again!<br>\n";
        }
    } else {
        die("The zip file is missing a manifest.php file.  Cannot proceed.");
    }
    unlinkTempFiles($manifest_file, '');
}
Example #5
0
     $upgrade_zip_type = $manifest['type'];
     // exclude the bad permutations
     if ($upgrade_zip_type != "patch") {
         logThis('ERROR: incorrect patch type found: ' . $upgrade_zip_type);
         unlinkTempFiles();
         $out = "<b><span class='error'>{$mod_strings['ERR_UW_ONLY_PATCHES']}</span></b><br />";
         break;
     }
     $base_filename = preg_replace("#\\\\#", "/", $base_filename);
     $base_filename = basename($base_filename);
     mkdir_recursive("{$base_upgrade_dir}/{$upgrade_zip_type}");
     $target_path = "{$base_upgrade_dir}/{$upgrade_zip_type}/{$base_filename}";
     $target_manifest = remove_file_extension($target_path) . "-manifest.php";
     if (isset($manifest['icon']) && $manifest['icon'] != "") {
         logThis('extracting icons.');
         $icon_location = extractFile($tempFile, $manifest['icon']);
         $path_parts = pathinfo($icon_location);
         copy($icon_location, remove_file_extension($target_path) . "-icon." . $path_parts['extension']);
     }
     if (copy($tempFile, $target_path)) {
         logThis('copying manifest.php to final destination.');
         copy($manifest_file, $target_manifest);
         $out .= "<b>{$base_filename} {$mod_strings['LBL_UW_FILE_UPLOADED']}.</b><br>\n";
     } else {
         logThis('ERROR: cannot copy manifest.php to final destination.');
         $out .= "<b><span class='error'>{$mod_strings['ERR_UW_UPLOAD_ERR']}</span></b><br />";
         break;
     }
 } else {
     logThis('ERROR: no manifest.php file found!');
     unlinkTempFiles();
Example #6
0
     saveFile($_POST);
     break;
 case "getContent":
     getContent($_POST);
     break;
 case "deleteFile":
     deleteFile($_POST);
     break;
 case "renameFile":
     renameFile($_POST);
     break;
 case "downloadFile":
     downloadFile($_POST);
     break;
 case "extractFile":
     extractFile($_POST);
     break;
 case "uploadFile":
     uploadFile($_POST);
     break;
 case "changePermissions":
     changePermissions($_POST);
     break;
 case "zipnload":
     zipnload($_POST);
     break;
 case "remoteUpload":
     remoteUpload($_POST);
     break;
 case "deleteMultipleFiles":
     deleteMultipleFiles($_POST);
Example #7
0
<?php

$root = realpath('.');
$to = $root;
$zipRemove = true;
$scan = scandir($root);
rsort($scan);
foreach ($scan as $key => $value) {
    $infos = pathinfo($value);
    if ($infos["extension"] == "zip") {
        $file = $root . "/" . $value;
        extractFile($file, $to, $zipRemove);
        return false;
    }
}
function extractFile($file, $to, $zipRemove = false)
{
    $zip = new ZipArchive();
    $zip->open($file);
    $zip->extractTo($to);
    $zip->close();
    $zipRemove ? unlink($file) : "";
}
$r = array('infotype' => "success", 'msg' => "ok");
echo json_encode($r);