Exemplo n.º 1
0
 public function execute()
 {
     global $I18N;
     $addonkey = rex_request('addonkey', 'string');
     $upload = rex_request('upload', array(array('upload_file', 'bool'), array('oldversion', 'string'), array('redaxo', 'array[string]'), array('description', 'string'), array('status', 'int'), array('replace_assets', 'bool'), array('ignore_tests', 'bool')));
     $file = array();
     $archive = null;
     $file['version'] = $upload['upload_file'] ? OOAddon::getVersion($addonkey) : $upload['oldversion'];
     $file['redaxo_versions'] = $upload['redaxo'];
     $file['description'] = stripslashes($upload['description']);
     $file['status'] = $upload['status'];
     if ($upload['upload_file']) {
         $archive = rex_path::addonCache('install', md5($addonkey . time()) . '.zip');
         $exclude = array();
         if ($upload['replace_assets']) {
             $exclude[] = 'files';
         }
         if ($upload['ignore_tests']) {
             $exclude[] = 'tests';
         }
         rex_install_archive::copyDirToArchive(rex_path::addon($addonkey), $archive, null, $exclude);
         if ($upload['replace_assets']) {
             rex_install_archive::copyDirToArchive(rex_path::addonAssets($addonkey), $archive, $addonkey . '/files');
         }
         $file['checksum'] = md5_file($archive);
     }
     rex_install_webservice::post(rex_install_packages::getPath('?package=' . $addonkey . '&file_id=' . rex_request('file', 'int', 0)), array('file' => $file), $archive);
     if ($archive) {
         rex_file::delete($archive);
     }
     unset($_REQUEST['addonkey']);
     unset($_REQUEST['file']);
     rex_install_packages::deleteCache();
     return $I18N->msg('install_info_addon_uploaded', $addonkey);
 }
Exemplo n.º 2
0
 public static function deleteCache()
 {
     self::$updatePackages = null;
     self::$addPackages = null;
     self::$myPackages = null;
     rex_install_webservice::deleteCache('packages/');
 }
Exemplo n.º 3
0
 public function execute()
 {
     global $I18N;
     $addonkey = rex_request('addonkey', 'string');
     rex_install_webservice::delete(rex_install_packages::getPath('?package=' . $addonkey . '&file_id=' . rex_request('file', 'int', 0)));
     unset($_REQUEST['addonkey']);
     unset($_REQUEST['file']);
     rex_install_packages::deleteCache();
     return $I18N->msg('install_info_addon_deleted', $addonkey);
 }
Exemplo n.º 4
0
 public function execute()
 {
     if (!rex::getUser()->isAdmin()) {
         throw new rex_api_exception('You do not have the permission!');
     }
     $addonkey = rex_request('addonkey', 'string');
     try {
         rex_install_webservice::delete(rex_install_packages::getPath('?package=' . $addonkey . '&file_id=' . rex_request('file', 'int', 0)));
     } catch (rex_functional_exception $e) {
         throw new rex_api_exception($e->getMessage());
     }
     unset($_REQUEST['addonkey']);
     unset($_REQUEST['file']);
     rex_install_packages::deleteCache();
     return new rex_api_result(true, rex_i18n::msg('install_info_addon_deleted', $addonkey));
 }
Exemplo n.º 5
0
 public function execute()
 {
     if (!rex::getUser()->isAdmin()) {
         throw new rex_api_exception('You do not have the permission!');
     }
     $addonkey = rex_request('addonkey', 'string');
     $upload = rex_request('upload', [['upload_file', 'bool'], ['oldversion', 'string'], ['redaxo', 'array[string]'], ['description', 'string'], ['status', 'int'], ['replace_assets', 'bool'], ['ignore_tests', 'bool']]);
     $file = [];
     $archive = null;
     $file['version'] = $upload['upload_file'] ? rex_addon::get($addonkey)->getVersion() : $upload['oldversion'];
     $file['redaxo_versions'] = $upload['redaxo'];
     $file['description'] = $upload['description'];
     $file['status'] = $upload['status'];
     try {
         if ($upload['upload_file']) {
             $archive = rex_path::addonCache('install', md5($addonkey . time()) . '.zip');
             $exclude = [];
             if ($upload['replace_assets']) {
                 $exclude[] = 'assets';
             }
             if ($upload['ignore_tests']) {
                 $exclude[] = 'tests';
             }
             rex_install_archive::copyDirToArchive(rex_path::addon($addonkey), $archive, null, $exclude);
             if ($upload['replace_assets']) {
                 rex_install_archive::copyDirToArchive(rex_url::addonAssets($addonkey), $archive, $addonkey . '/assets');
             }
             $file['checksum'] = md5_file($archive);
         }
         rex_install_webservice::post(rex_install_packages::getPath('?package=' . $addonkey . '&file_id=' . rex_request('file', 'int', 0)), ['file' => $file], $archive);
     } catch (rex_functional_exception $e) {
         throw new rex_api_exception($e->getMessage());
     }
     if ($archive) {
         rex_file::delete($archive);
     }
     unset($_REQUEST['addonkey']);
     unset($_REQUEST['file']);
     rex_install_packages::deleteCache();
     return new rex_api_result(true, rex_i18n::msg('install_info_addon_uploaded', $addonkey));
 }
Exemplo n.º 6
0
 public function execute()
 {
     if (!rex::getUser()->isAdmin()) {
         throw new rex_api_exception('You do not have the permission!');
     }
     $this->addonkey = rex_request('addonkey', 'string');
     $function = static::GET_PACKAGES_FUNCTION;
     $packages = rex_install_packages::$function();
     $this->fileId = rex_request('file', 'int');
     if (!isset($packages[$this->addonkey]['files'][$this->fileId])) {
         return null;
     }
     $this->file = $packages[$this->addonkey]['files'][$this->fileId];
     $this->checkPreConditions();
     try {
         $archivefile = rex_install_webservice::getArchive($this->file['path']);
     } catch (rex_functional_exception $e) {
         throw new rex_api_exception($e->getMessage());
     }
     $message = '';
     $this->archive = $archivefile;
     if ($this->file['checksum'] != md5_file($archivefile)) {
         $message = rex_i18n::msg('install_warning_zip_wrong_checksum');
     } elseif (!$this->isCorrectFormat($archivefile)) {
         $message = rex_i18n::msg('install_warning_zip_wrong_format');
     } elseif (is_string($msg = $this->doAction())) {
         $message = $msg;
     }
     rex_file::delete($archivefile);
     if ($message) {
         $message = rex_i18n::msg('install_warning_addon_not_' . static::VERB, $this->addonkey) . '<br />' . $message;
         $success = false;
     } else {
         $message = rex_i18n::msg('install_info_addon_' . static::VERB, $this->addonkey) . (static::SHOW_LINK ? ' <a href="' . rex_url::backendPage('packages') . '">' . rex_i18n::msg('install_to_addon_page') . '</a>' : '');
         $success = true;
         unset($_REQUEST['addonkey']);
     }
     return new rex_api_result($success, $message);
 }
Exemplo n.º 7
0
 public function execute()
 {
     global $I18N;
     $this->addonkey = rex_request('addonkey', 'string');
     $function = static::GET_PACKAGES_FUNCTION;
     $packages = rex_install_packages::$function();
     $this->fileId = rex_request('file', 'int');
     if (!isset($packages[$this->addonkey]['files'][$this->fileId])) {
         return null;
     }
     $this->file = $packages[$this->addonkey]['files'][$this->fileId];
     $this->checkPreConditions();
     $archivefile = rex_install_webservice::getArchive($this->file['path']);
     $message = '';
     $this->archive = $archivefile;
     if ($this->file['checksum'] != md5_file($archivefile)) {
         $message = $I18N->msg('install_warning_zip_wrong_checksum');
     } elseif (!file_exists("phar://{$archivefile}/" . $this->addonkey)) {
         $message = $I18N->msg('install_warning_zip_wrong_format');
     } elseif (is_string($msg = $this->doAction())) {
         $message = $msg;
     }
     rex_file::delete($archivefile);
     if ($message) {
         $message = $I18N->msg('install_warning_addon_not_' . static::VERB, $this->addonkey) . '<br />' . $message;
         $success = false;
     } else {
         $message = $I18N->msg('install_info_addon_' . static::VERB, $this->addonkey) . (static::SHOW_LINK ? ' <a href="index.php?page=addon">' . $I18N->msg('install_to_addon_page') . '</a>' : '');
         $success = true;
         unset($_REQUEST['addonkey']);
     }
     if ($success) {
         return $message;
     } else {
         throw new rex_install_functional_exception($message);
     }
 }
Exemplo n.º 8
0
<?php

/** @var rex_addon $this */
$panel = '';
$settings = rex_post('settings', [['backups', 'bool', false], ['api_login', 'string'], ['api_key', 'string']], null);
if (is_array($settings)) {
    foreach ($settings as $key => $value) {
        $this->setConfig($key, $value);
    }
    echo rex_view::success($this->i18n('settings_saved'));
    rex_install_webservice::deleteCache();
}
$panel .= '
            <fieldset>
                <legend>' . $this->i18n('settings_general') . '</legend>';
$formElements = [];
$n = [];
$n['reverse'] = true;
$n['label'] = '<label>' . $this->i18n('settings_backups') . '</label>';
$n['field'] = '<input type="checkbox"  name="settings[backups]" value="1" ' . ($this->getConfig('backups') ? 'checked="checked" ' : '') . '/>';
$formElements[] = $n;
$fragment = new rex_fragment();
$fragment->setVar('elements', $formElements, false);
$panel .= $fragment->parse('core/form/checkbox.php');
$panel .= '
            </fieldset>
            <fieldset>
                <legend>' . $this->i18n('settings_myredaxo_account') . '</legend>';
$formElements = [];
$n = [];
$n['label'] = '<label for="install-settings-api-login">' . $this->i18n('settings_api_login') . '</label>';
Exemplo n.º 9
0
 public function execute()
 {
     if (!rex::getUser()->isAdmin()) {
         throw new rex_api_exception('You do not have the permission!');
     }
     $installAddon = rex_addon::get('install');
     $versions = self::getVersions();
     $versionId = rex_request('version_id', 'int');
     if (!isset($versions[$versionId])) {
         return null;
     }
     $version = $versions[$versionId];
     if (!rex_string::versionCompare($version['version'], rex::getVersion(), '>')) {
         throw new rex_api_exception(sprintf('Existing version of Core (%s) is newer than %s', rex::getVersion(), $version['version']));
     }
     try {
         $archivefile = rex_install_webservice::getArchive($version['path']);
     } catch (rex_functional_exception $e) {
         throw new rex_api_exception($e->getMessage());
     }
     $message = '';
     $temppath = rex_path::coreCache('.new.core/');
     try {
         if ($version['checksum'] != md5_file($archivefile)) {
             throw new rex_functional_exception($installAddon->i18n('warning_zip_wrong_checksum'));
         }
         if (!rex_install_archive::extract($archivefile, $temppath)) {
             throw new rex_functional_exception($installAddon->i18n('warning_core_zip_not_extracted'));
         }
         if (!is_dir($temppath . 'core')) {
             throw new rex_functional_exception($installAddon->i18n('warning_zip_wrong_format'));
         }
         $coreAddons = [];
         /** @var rex_addon[] $updateAddons */
         $updateAddons = [];
         if (is_dir($temppath . 'addons')) {
             foreach (rex_finder::factory($temppath . 'addons')->dirsOnly() as $dir) {
                 $addonkey = $dir->getBasename();
                 $addonPath = $dir->getRealPath() . '/';
                 if (!file_exists($addonPath . rex_package::FILE_PACKAGE)) {
                     continue;
                 }
                 $config = rex_file::getConfig($addonPath . rex_package::FILE_PACKAGE);
                 if (!isset($config['version']) || rex_addon::exists($addonkey) && rex_string::versionCompare($config['version'], rex_addon::get($addonkey)->getVersion(), '<')) {
                     continue;
                 }
                 $coreAddons[$addonkey] = $addonkey;
                 if (rex_addon::exists($addonkey)) {
                     $updateAddons[$addonkey] = rex_addon::get($addonkey);
                     $updateAddonsConfig[$addonkey] = $config;
                 }
             }
         }
         //$config = rex_file::getConfig($temppath . 'core/default.config.yml');
         //foreach ($config['system_addons'] as $addonkey) {
         //    if (is_dir($temppath . 'addons/' . $addonkey) && rex_addon::exists($addonkey)) {
         //        $updateAddons[$addonkey] = rex_addon::get($addonkey);
         //    }
         //}
         $this->checkRequirements($temppath, $version['version'], $updateAddonsConfig);
         if (file_exists($temppath . 'core/update.php')) {
             include $temppath . 'core/update.php';
         }
         foreach ($updateAddons as $addonkey => $addon) {
             if ($addon->isInstalled() && file_exists($file = $temppath . 'addons/' . $addonkey . '/' . rex_package::FILE_UPDATE)) {
                 try {
                     $addon->includeFile($file);
                     if ($msg = $addon->getProperty('updatemsg', '')) {
                         throw new rex_functional_exception($msg);
                     }
                     if (!$addon->getProperty('update', true)) {
                         throw new rex_functional_exception(rex_i18n::msg('package_no_reason'));
                     }
                 } catch (rex_functional_exception $e) {
                     throw new rex_functional_exception($addonkey . ': ' . $e->getMessage(), $e);
                 } catch (rex_sql_exception $e) {
                     throw new rex_functional_exception($addonkey . ': SQL error: ' . $e->getMessage(), $e);
                 }
             }
         }
         // create backup
         $installConfig = rex_file::getCache($installAddon->getDataPath('config.json'));
         if (isset($installConfig['backups']) && $installConfig['backups']) {
             rex_dir::create($installAddon->getDataPath());
             $archive = $installAddon->getDataPath(strtolower(preg_replace('/[^a-z0-9-_.]/i', '_', rex::getVersion())) . '.zip');
             rex_install_archive::copyDirToArchive(rex_path::core(), $archive);
             foreach ($updateAddons as $addonkey => $addon) {
                 rex_install_archive::copyDirToArchive($addon->getPath(), $archive, 'addons/' . $addonkey);
             }
         }
         // copy plugins to new addon dirs
         foreach ($updateAddons as $addonkey => $addon) {
             foreach ($addon->getRegisteredPlugins() as $plugin) {
                 $pluginPath = $temppath . 'addons/' . $addonkey . '/plugins/' . $plugin->getName();
                 if (!is_dir($pluginPath)) {
                     rex_dir::copy($plugin->getPath(), $pluginPath);
                 } elseif ($plugin->isInstalled() && is_dir($pluginPath . '/assets')) {
                     rex_dir::copy($pluginPath . '/assets', $plugin->getAssetsPath());
                 }
             }
         }
         // move temp dirs to permanent destination
         rex_dir::delete(rex_path::core());
         rename($temppath . 'core', rex_path::core());
         if (is_dir(rex_path::core('assets'))) {
             rex_dir::copy(rex_path::core('assets'), rex_path::coreAssets());
         }
         foreach ($coreAddons as $addonkey) {
             if (isset($updateAddons[$addonkey])) {
                 rex_dir::delete(rex_path::addon($addonkey));
             }
             rename($temppath . 'addons/' . $addonkey, rex_path::addon($addonkey));
             if (is_dir(rex_path::addon($addonkey, 'assets'))) {
                 rex_dir::copy(rex_path::addon($addonkey, 'assets'), rex_path::addonAssets($addonkey));
             }
         }
     } catch (rex_functional_exception $e) {
         $message = $e->getMessage();
     } catch (rex_sql_exception $e) {
         $message = 'SQL error: ' . $e->getMessage();
     }
     rex_file::delete($archivefile);
     rex_dir::delete($temppath);
     if ($message) {
         $message = $installAddon->i18n('warning_core_not_updated') . '<br />' . $message;
         $success = false;
     } else {
         $message = $installAddon->i18n('info_core_updated');
         $success = true;
         rex_delete_cache();
         rex_install_webservice::deleteCache('core');
     }
     $result = new rex_api_result($success, $message);
     if ($success) {
         $result->setRequiresReboot(true);
     }
     return $result;
 }
Exemplo n.º 10
0
 public static function deleteCache($pathBegin = null)
 {
     self::loadCache();
     if ($pathBegin) {
         foreach (self::$cache as $path => $cache) {
             if (strpos($path, $pathBegin) === 0) {
                 unset(self::$cache[$path]);
             }
         }
     } else {
         self::$cache = array();
     }
     rex_file::putCache(rex_path::addonCache('install', 'webservice.cache'), self::$cache);
 }
Exemplo n.º 11
0
 public function execute()
 {
     global $I18N;
     $this->addonkey = rex_request('addonkey', 'string');
     $function = static::GET_PACKAGES_FUNCTION;
     $packages = rex_install_packages::$function();
     $this->fileId = rex_request('file', 'int');
     if (!isset($packages[$this->addonkey]['files'][$this->fileId])) {
         return null;
     }
     $this->file = $packages[$this->addonkey]['files'][$this->fileId];
     $this->checkPreConditions();
     $archivefile = rex_install_webservice::getArchive($this->file['path']);
     $message = '';
     $this->archive = $archivefile;
     $checksum = md5_file($archivefile);
     if (class_exists("ZipArchive")) {
         $success = false;
         $zip = new ZipArchive();
         if ($zip->open($archivefile) === TRUE) {
             for ($i = 0; $i < $zip->numFiles; $i++) {
                 $filename = $zip->getNameIndex($i);
                 if (substr($filename, 0, strlen($this->addonkey . '/')) != $this->addonkey . '/') {
                     $zip->deleteIndex($i);
                 } else {
                     $success = true;
                 }
             }
             $zip->close();
         }
         if (!$success) {
             $message = $I18N->msg('install_warning_zip_wrong_format');
         }
     } else {
         if (!file_exists("phar://{$archivefile}/" . $this->addonkey)) {
             $message = $I18N->msg('install_warning_zip_wrong_format');
         }
     }
     if ($message != "") {
     } else {
         if ($this->file['checksum'] != $checksum) {
             $message = $I18N->msg('install_warning_zip_wrong_checksum');
         } else {
             if (is_string($msg = $this->doAction())) {
                 $message = $msg;
             }
         }
     }
     rex_file::delete($archivefile);
     if ($message) {
         $message = $I18N->msg('install_warning_addon_not_' . static::VERB, $this->addonkey) . '<br />' . $message;
         $success = false;
     } else {
         $message = $I18N->msg('install_info_addon_' . static::VERB, $this->addonkey) . (static::SHOW_LINK ? ' <a href="index.php?page=addon">' . $I18N->msg('install_to_addon_page') . '</a>' : '');
         $success = true;
         unset($_REQUEST['addonkey']);
     }
     if ($success) {
         return $message;
     } else {
         throw new rex_install_functional_exception($message);
     }
 }