Esempio n. 1
0
 /**
  * Creates a ZIP package of the extension and prepares it for downloading.
  * @param string $ext_name The name of the extension.
  * @return null|bool
  */
 public static function download_extension($ext_name)
 {
     $composery = files::getComposer(objects::$phpbb_root_path . 'ext/' . $ext_name);
     if (!$composery) {
         return false;
     }
     $string = @file_get_contents($composery);
     if ($string === false) {
         return false;
     }
     $json_a = json_decode($string, true);
     $composer_ext_name = isset($json_a['name']) ? $json_a['name'] : '';
     $composer_ext_type = isset($json_a['type']) ? $json_a['type'] : '';
     if ($composer_ext_name !== $ext_name || $composer_ext_type !== "phpbb-extension") {
         return false;
     }
     $ext_version = isset($json_a['version']) ? $json_a['version'] : '0.0.0';
     $ext_delete_suffix = objects::$request->variable('ext_delete_suffix', false);
     if ($ext_delete_suffix) {
         $restore_composery = false;
         if (isset($json_a['version']) && preg_match("/^([\\d]+\\.[\\d]+\\.[\\d]+)(.+)\$/u", $ext_version, $matches)) {
             $restore_composery = $string;
             $fp = @fopen($composery, 'w');
             if ($fp) {
                 $string = preg_replace("/\"version\"\\:[\\s]*\"" . preg_quote($ext_version, "/") . "\"/u", "\"version\": \"" . $matches[1] . "\"", $string);
                 fwrite($fp, $string);
                 fclose($fp);
                 $ext_version = $matches[1];
             }
         }
     }
     $download_name = str_replace('/', '_', $ext_name) . "_" . str_replace('.', '_', $ext_version);
     $ext_tmp = objects::$phpbb_root_path . 'ext/' . objects::$upload_ext_name . '/tmp/' . (int) objects::$user->data['user_id'];
     // Ensure that we don't have any previous files in the working directory.
     if (is_dir($ext_tmp)) {
         if (!files::catch_errors(files::rrmdir($ext_tmp))) {
             return false;
         }
     } else {
         files::recursive_mkdir($ext_tmp);
     }
     $download_path = $ext_tmp . '/' . $download_name;
     files::save_zip_archive('ext/' . $ext_name . '/', $download_name, $ext_tmp);
     filedownload::download_file($download_path, $download_name, 'application/zip');
     files::rrmdir($ext_tmp);
     // No errors are printed here.
     if ($ext_delete_suffix && $restore_composery) {
         $fp = @fopen($composery, 'w');
         if ($fp) {
             fwrite($fp, $restore_composery);
             fclose($fp);
         }
     }
 }
Esempio n. 2
0
 /**
  * Original copyright information for the function from AutoMOD.
  * The function was almost totally changed by the authors of Upload Extensions.
  * @package       automod
  * @copyright (c) 2008 phpBB Group
  * @license       http://opensource.org/licenses/gpl-2.0.php GNU Public License
  *
  * @param string $action Requested action.
  * @return \filespec|bool
  */
 public function proceed_upload($action)
 {
     global $phpbb_root_path, $phpEx, $user, $request;
     //$can_upload = (@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !@extension_loaded('zlib')) ? false : true;
     $user->add_lang('posting');
     // For error messages
     if (!class_exists('\\fileupload')) {
         include $phpbb_root_path . 'includes/functions_upload.' . $phpEx;
     }
     $upload = new \fileupload();
     $upload->set_allowed_extensions(array('zip'));
     // Only allow ZIP files
     // Make sure the ext/ directory exists and if it doesn't, create it
     if (!is_dir($phpbb_root_path . 'ext')) {
         if (!files::catch_errors(files::recursive_mkdir($phpbb_root_path . 'ext'))) {
             return false;
         }
     }
     if (!is_writable($phpbb_root_path . 'ext')) {
         files::catch_errors($user->lang['EXT_NOT_WRITABLE']);
         return false;
     }
     if (!is_dir(objects::$zip_dir)) {
         if (!files::catch_errors(files::recursive_mkdir(objects::$zip_dir))) {
             return false;
         }
     }
     if (!is_writable($phpbb_root_path . 'ext/' . objects::$upload_ext_name . '/tmp')) {
         if (!phpbb_chmod($phpbb_root_path . 'ext/' . objects::$upload_ext_name . '/tmp', CHMOD_READ | CHMOD_WRITE)) {
             files::catch_errors($user->lang['EXT_TMP_NOT_WRITABLE']);
             return false;
         }
     }
     $file = false;
     // Proceed with the upload
     if ($action == 'upload') {
         if (!$request->is_set("extupload", \phpbb\request\request_interface::FILES)) {
             files::catch_errors($user->lang['NO_UPLOAD_FILE']);
             return false;
         }
         $file = $upload->form_upload('extupload');
     } else {
         if ($action == 'upload_remote') {
             $php_ini = new \phpbb\php\ini();
             if (!$php_ini->get_bool('allow_url_fopen')) {
                 files::catch_errors($user->lang['EXT_ALLOW_URL_FOPEN_DISABLED']);
                 return false;
             }
             $remote_url = $request->variable('remote_upload', '');
             if (!extension_loaded('openssl') && 'https' === substr($remote_url, 0, 5)) {
                 files::catch_errors($user->lang['EXT_OPENSSL_DISABLED']);
                 return false;
             }
             $file = files::remote_upload($upload, $user, $remote_url);
         }
     }
     return $file;
 }