Exemple #1
0
 public static function downloadDistr()
 {
     // Get needed version
     $version_info = self::GetNextVersionInfo();
     if (!$version_info['next_version'] || !$version_info['update_url']) {
         return false;
     }
     $download_file_dir = TWIGMO_UPGRADE_DIR . $version_info['next_version'] . '/';
     $download_file_path = $download_file_dir . 'twigmo.tgz';
     $unpack_path = $download_file_path . '_unpacked';
     fn_rm($download_file_dir);
     fn_mkdir($download_file_dir);
     fn_mkdir($unpack_path);
     $data = fn_get_contents($version_info['update_url']);
     if (!fn_is_empty($data)) {
         fn_put_contents($download_file_path, $data);
         $res = fn_decompress_files($download_file_path, $unpack_path);
         if (!$res) {
             fn_set_notification('E', __('error'), __('twgadmin_failed_to_decompress_files'));
             return false;
         }
         return $unpack_path . '/';
     } else {
         fn_set_notification('E', __('error'), __('text_uc_cant_download_package'));
         return false;
     }
 }
Exemple #2
0
 /**
  * Installs new language from ZIP pack
  *
  * @param string $path   Path to ZIP file
  * @param array  $params
  *  reinstall: Skip adding new language
  *  validate_lang_code:Check meta information (lang_code) with updated language data (lang_code) and forbid to update if does not match
  *  force_lang_code: Skip meta lang code and use this one in all laguage variables
  * @return int Language ID
  */
 public static function installZipPack($path, $params = array())
 {
     $result = false;
     // Extract language pack and check the permissions
     $extract_path = fn_get_cache_path(false) . 'tmp/language_pack/';
     // Re-create source folder
     fn_rm($extract_path);
     fn_mkdir($extract_path);
     fn_copy($path, $extract_path . 'pack.zip');
     if (fn_decompress_files($extract_path . 'pack.zip', $extract_path)) {
         fn_rm($extract_path . 'pack.zip');
         $result = self::installCrowdinPack($extract_path, $params);
     } else {
         fn_set_notification('E', __('error'), __('broken_po_pack'));
     }
     return $result;
 }
Exemple #3
0
         fn_set_notification('W', __('warning'), __('warning_theme_clone_dir_exists'));
     }
 } elseif ($mode == 'upload') {
     $theme_pack = fn_filter_uploaded_data('theme_pack', Registry::get('config.allowed_pack_exts'));
     if (empty($theme_pack[0])) {
         fn_set_notification('E', __('error'), __('text_allowed_to_upload_file_extension', array('[ext]' => implode(',', Registry::get('config.allowed_pack_exts')))));
     } else {
         $theme_pack = $theme_pack[0];
         // Extract the add-on pack and check the permissions
         $extract_path = fn_get_cache_path(false) . 'tmp/theme_pack/';
         $destination = Registry::get('config.dir.themes_repository');
         // Re-create source folder
         fn_rm($extract_path);
         fn_mkdir($extract_path);
         fn_copy($theme_pack['path'], $extract_path . $theme_pack['name']);
         if (fn_decompress_files($extract_path . $theme_pack['name'], $extract_path)) {
             fn_rm($extract_path . $theme_pack['name']);
             $non_writable_folders = fn_check_copy_ability($extract_path, $destination);
             if (!empty($non_writable_folders)) {
                 Tygh::$app['view']->assign('non_writable', $non_writable_folders);
                 if (defined('AJAX_REQUEST')) {
                     Tygh::$app['view']->display('views/themes/components/correct_permissions.tpl');
                     exit;
                 }
             } else {
                 fn_copy($extract_path, $destination);
                 fn_rm($extract_path);
                 if (defined('AJAX_REQUEST')) {
                     Tygh::$app['ajax']->assign('force_redirection', fn_url('themes.manage'));
                     exit;
                 }
Exemple #4
0
 if (defined('RESTRICTED_ADMIN') || Registry::get('runtime.company_id')) {
     fn_set_notification('E', __('error'), __('access_denied'));
     return array(CONTROLLER_STATUS_REDIRECT, 'addons.manage');
 }
 $addon_pack = fn_filter_uploaded_data('addon_pack', Registry::get('config.allowed_pack_exts'));
 if (empty($addon_pack[0])) {
     fn_set_notification('E', __('error'), __('text_allowed_to_upload_file_extension', array('[ext]' => implode(',', Registry::get('config.allowed_pack_exts')))));
 } else {
     // Extract the add-on pack and check the permissions
     $extract_path = fn_get_cache_path(false) . 'tmp/addon_pack/';
     $addon_pack = $addon_pack[0];
     // Re-create source folder
     fn_rm($extract_path);
     fn_mkdir($extract_path);
     fn_copy($addon_pack['path'], $extract_path . $addon_pack['name']);
     if (fn_decompress_files($extract_path . $addon_pack['name'], $extract_path)) {
         fn_rm($extract_path . $addon_pack['name']);
         $struct = fn_get_dir_contents($extract_path, false, true, '', '', true);
         $addon_name = '';
         $relative_addon_path = str_replace(Registry::get('config.dir.root') . '/', '', Registry::get('config.dir.addons'));
         foreach ($struct as $file) {
             if (preg_match('#' . $relative_addon_path . '[^a-zA-Z0-9_]*([a-zA-Z0-9_-]+).+?addon.xml$#i', $file, $matches)) {
                 if (!empty($matches[1])) {
                     $addon_name = $matches[1];
                 }
             }
         }
         if (empty($addon_name)) {
             fn_set_notification('E', __('error'), __('broken_addon_pack'));
             if (defined('AJAX_REQUEST')) {
                 Tygh::$app['ajax']->assign('non_ajax_notifications', true);
Exemple #5
0
 /**
  * Unpacks and checks the uploaded upgrade pack
  *
  * @param  string $path Path to the zip/tgz archive with the upgrade
  * @return true   if upgrade pack is ready to use, false otherwise
  */
 public function uploadUpgradePack($pack_info)
 {
     // Extract the add-on pack and check the permissions
     $extract_path = fn_get_cache_path(false) . 'tmp/upgrade_pack/';
     $destination = $this->getPackagesDir();
     // Re-create source folder
     fn_rm($extract_path);
     fn_mkdir($extract_path);
     fn_copy($pack_info['path'], $extract_path . $pack_info['name']);
     if (fn_decompress_files($extract_path . $pack_info['name'], $extract_path)) {
         if (file_exists($extract_path . 'schema.json')) {
             $schema = json_decode(fn_get_contents($extract_path . 'schema.json'), true);
             if ($this->validateSchema($schema)) {
                 $package_id = preg_replace('/\\.(zip|tgz|gz)$/i', '', $pack_info['name']);
                 $this->deletePackage($package_id);
                 fn_mkdir($destination . $package_id);
                 fn_copy($extract_path, $destination . $package_id);
                 list($result, $message) = $this->checkPackagePermissions($package_id);
                 if ($result) {
                     $this->setNotification('N', __('notice'), __('uc_downloaded_and_ready'));
                 } else {
                     $this->setNotification('E', __('error'), $message);
                     $this->deletePackage($package_id);
                 }
             } else {
                 $this->setNotification('E', __('error'), __('uc_broken_upgrade_connector', array('[connector_id]' => $pack_info['name'])));
             }
         } else {
             $this->setNotification('E', __('error'), __('uc_unable_to_read_schema'));
         }
     }
     // Clear obsolete unpacked data
     fn_rm($extract_path);
     return false;
 }
Exemple #6
0
         fn_echo('<br />' . fn_get_lang_var('compressing_backup') . '...');
         fn_compress_files($dbdump_filename . '.tgz', $dbdump_filename, dirname($dump_file));
         unlink($dump_file);
     }
     fn_stop_scroller();
 }
 // Restore
 if ($mode == 'restore') {
     if (!empty($_REQUEST['backup_files'])) {
         // Log database restore
         fn_log_event('database', 'restore');
         fn_start_scroller();
         foreach ($_REQUEST['backup_files'] as $file) {
             fn_echo('<br />' . fn_get_lang_var('restoring_from') . ': <b>' . $file . '</b><hr width="100%" />');
             if (strpos($file, '.tgz') !== false) {
                 fn_decompress_files($file, DIR_DATABASE . '/backup');
                 $file = substr($file, 0, strpos($file, '.tgz'));
             }
             db_import_sql_file(DIR_DATABASE . 'backup/' . $file);
         }
         fn_stop_scroller();
         fn_rm(DIR_CACHE, false);
         // cleanup cache
     }
     $suffix = '?selected_section=restore';
 }
 if ($mode == 'delete') {
     if (!empty($_REQUEST['backup_files'])) {
         foreach ($_REQUEST['backup_files'] as $file) {
             @unlink(DIR_DATABASE . 'backup/' . $file);
         }
        $object_base = is_file($repo_path) ? 'file' : (is_dir($repo_path) ? 'directory' : '');
        if (!empty($object_base) && fn_copy($repo_path, $file_path)) {
            fn_set_notification('N', __('notice'), __("text_{$object_base}_restored", array("[{$object_base}]" => fn_basename($file_path))));
            Registry::get('ajax')->assign('content', fn_get_contents($file_path));
            $copied = true;
        }
    }
    if (!$copied) {
        $object_base = empty($object_base) ? 'file' : $object_base;
        fn_set_notification('E', __('error'), __("text_cannot_restore_{$object_base}", array("[{$object_base}]" => fn_basename($file_path))));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'file_editor.init_view?dir=' . $_REQUEST['file_path'] . '/' . $_REQUEST['file']);
} elseif ($mode == 'decompress') {
    $pname = fn_te_normalize_path($_REQUEST, $section_root_dir);
    if (fn_te_check_path($pname, $_SESSION['active_section'])) {
        fn_decompress_files($pname, dirname($pname));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'file_editor.init_view?dir=' . $_REQUEST['file_path']);
} elseif ($mode == 'compress') {
    $pname = fn_te_normalize_path($_REQUEST, $section_root_dir);
    if (fn_te_check_path($pname, $_SESSION['active_section']) && file_exists($pname)) {
        $archive_file = $pname . '.zip';
        if (file_exists($archive_file)) {
            fn_rm($archive_file);
        }
        fn_compress_files(fn_basename($archive_file), array(fn_basename($pname)), dirname($pname));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'file_editor.init_view?dir=' . $_REQUEST['file_path']);
}
/**
 * Gets file/directory permissions in human-readable notation
function fn_uc_get_edition_package($new_license, $package, $uc_settings, $backend_files)
{
    $result = true;
    $data = fn_get_contents(Registry::get('config.resources.updates_server') . '/index.php?dispatch=product_updates.get_edition_upgrade&license_number=' . $uc_settings['license_number'] . '&new_license_number=' . $new_license . '&ver=' . PRODUCT_VERSION);
    if (!empty($data)) {
        fn_put_contents(Registry::get('config.dir.upgrade') . 'uc.tgz', $data);
        if (md5_file(Registry::get('config.dir.upgrade') . 'uc.tgz') == $package['md5']) {
            $dir = fn_basename($package['file']);
            fn_mkdir(Registry::get('config.dir.upgrade') . $dir);
            $result = fn_decompress_files(Registry::get('config.dir.upgrade') . 'uc.tgz', Registry::get('config.dir.upgrade') . $dir);
            if ($result) {
                if (is_file(Registry::get('config.dir.upgrade') . $dir . '/packages_info.xml')) {
                    // if multipackage archive
                    $packages = simplexml_load_file(Registry::get('config.dir.upgrade') . $dir . '/packages_info.xml', NULL, LIBXML_NOERROR);
                    foreach ($packages->item as $item) {
                        $filename = (string) $item;
                        fn_uc_rename_backend_files($backend_files, Registry::get('config.dir.upgrade') . "{$dir}/{$filename}/package/");
                        $_package = $package;
                        $_package = array('to_version' => substr($filename, strrpos($filename, '-') + 1), 'name' => str_replace('upgrade_', '', $filename), 'description' => '', 'size' => '');
                        $_package['contents'] = fn_uc_get_package_contents_from_uc_xml(Registry::get('config.dir.upgrade') . "{$dir}/{$filename}");
                        fn_put_contents(Registry::get('config.dir.upgrade') . "{$dir}/{$filename}/package_details.php", "<?php\n return " . var_export($_package, true) . "; \n?>");
                    }
                } else {
                    fn_uc_rename_backend_files($backend_files, Registry::get('config.dir.upgrade') . $dir . '/package/');
                    $package['contents'] = fn_uc_get_package_contents_from_uc_xml(Registry::get('config.dir.upgrade') . $dir);
                    fn_put_contents(Registry::get('config.dir.upgrade') . $dir . '/package_details.php', "<?php\n return " . var_export($package, true) . "; \n?>");
                }
            } else {
                fn_set_notification('E', __('error'), __('text_uc_failed_to_decompress_files'));
            }
        } else {
            fn_set_notification('E', __('error'), __('text_uc_broken_package'));
            $result = false;
        }
        return $result;
    } else {
        fn_set_notification('E', __('error'), __('text_uc_cant_download_package'));
        $result = false;
    }
    return $result;
}
function fn_restore_dump($files)
{
    if (empty($files)) {
        return false;
    }
    fn_set_progress('parts', sizeof($files));
    foreach ($files as $file) {
        $is_archive = false;
        $list = array($file);
        if (in_array(fn_get_file_ext($file), array('zip', 'tgz'))) {
            $is_archive = true;
            fn_decompress_files(Registry::get('config.dir.database') . $file, Registry::get('config.dir.database') . '_tmp');
            $list = fn_get_dir_contents(Registry::get('config.dir.database') . '_tmp', false, true, 'sql', '_tmp/');
        }
        foreach ($list as $_file) {
            db_import_sql_file(Registry::get('config.dir.database') . $_file);
        }
        if ($is_archive) {
            fn_rm(Registry::get('config.dir.database') . '_tmp');
        }
    }
    // Log database restore
    fn_log_event('database', 'restore');
    fn_set_hook('database_restore', $files);
    fn_clear_cache();
    return true;
}
/**
 * Get upgrade package
 *
 * @param int $package_id package ID
 * @param string $md5 md5 hash of package
 * @param array $package package details
 * @param array $uc_settings Upgrade center settings
 * @return boolean true if package downloaded and extracted successfully, false - otherwise
 */
function fn_uc_get_package($package_id, $md5, $package, $uc_settings)
{
    $result = true;
    if ($package['is_avail'] != 'Y') {
        return false;
    }
    $data = fn_get_contents($uc_settings['updates_server'] . '/index.php?target=product_updates&mode=get_package&package_id=' . $package_id);
    /* NULLED BY FLIPMODE! @ 2010/09/06 */
    // $data = fn_get_contents($uc_settings['updates_server'] . '/index.php?target=product_updates&mode=get_package&package_id=' . $package_id . '&license_number=' . $uc_settings['license_number']);
    if (!empty($data)) {
        fn_put_contents(DIR_UPGRADE . 'uc.tgz', $data);
        if (md5_file(DIR_UPGRADE . 'uc.tgz') == $md5) {
            $dir = basename($package['file']);
            fn_mkdir(DIR_UPGRADE . $dir);
            fn_put_contents(DIR_UPGRADE . $dir . '/package_details.php', "<?php\n return " . var_export($package, true) . "; \n?>");
            return fn_decompress_files(DIR_UPGRADE . 'uc.tgz', DIR_UPGRADE . $dir);
        } else {
            fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('text_uc_broken_package'));
            $result = false;
        }
    } else {
        fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('text_uc_cant_download_package'));
        $result = false;
    }
    return $result;
}