Beispiel #1
0
 /**
  * Add themes, addons or data directories to the replace_dirs list only if they're not empty
  *
  */
 public function AddReplaceDir($dir, $temp_name, $merge = false)
 {
     global $dataDir, $langmessage;
     $rel_path = '/data/_temp/' . $temp_name . '/gpexport/' . $dir;
     $full_path = $dataDir . $rel_path;
     if (!file_exists($full_path)) {
         return true;
     }
     $files = scandir($full_path);
     if (count($files) === 0) {
         return true;
     }
     // move to location outside of existing /data directory
     // otherwise ReplaceDirs() will fail when we try to replace the data directory
     $new_relative = \gp\tool\FileSystem::TempFile('/themes');
     if (!$this->FileSystem->RelRename($rel_path, $new_relative)) {
         message($langmessage['revert_failed'] . ' (AddReplaceDir Failed)');
         return false;
     }
     // copy other folders from /data so we don't lose sessions, uploaded content etc
     if ($merge) {
         $source = $dataDir . '/data/';
         $new_full = $dataDir . $new_relative;
         $this->CopyDir($source, $new_full);
     }
     $this->replace_dirs[$dir] = $new_relative;
     return true;
 }
Beispiel #2
0
 /**
  * Add an uploaded plugin
  *
  */
 function UploadPlugin()
 {
     global $langmessage, $dataDir;
     includeFile('admin/admin_uploaded.php');
     $archive = $this->UploadedArchive();
     if (!$archive) {
         return false;
     }
     // get plugin name and check file types
     $list = $archive->ListFiles();
     $plugin_name = '';
     $remove_path = '';
     foreach ($list as $file) {
         //don't check extensions on folder
         if ($file['size'] == 0) {
             continue;
         }
         //check extension
         if (!admin_uploaded::AllowedExtension($file['name'], false)) {
             msg($langmessage['OOPS'] . ' (File type not allowed:' . htmlspecialchars($file['name']) . ')');
             return false;
         }
         //plugin name
         if (strpos($file['name'], 'plugin.js') !== false) {
             $new_plugin_name = $this->FindPluginName($archive, $file['name']);
             if (!$new_plugin_name) {
                 continue;
             }
             //use the most relevant plugin name
             $new_path = dirname($file['name']);
             if (!$plugin_name || strlen($new_path) < strlen($remove_path)) {
                 $plugin_name = $new_plugin_name;
                 $remove_path = $new_path;
             }
         }
     }
     if (!$this->CanUpload($plugin_name)) {
         return;
     }
     //extract to temporary location
     $extract_temp = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/' . $plugin_name);
     if (!$archive->extractTo($extract_temp)) {
         gpFiles::RmAll($extract_temp);
         msg($langmessage['OOPS'] . ' (Couldn\'t extract to temp location)');
         return false;
     }
     //move to _ckeditor folder
     $destination = $dataDir . '/data/_ckeditor/' . $plugin_name;
     $rename_from = $extract_temp . '/' . ltrim($remove_path, '/');
     if (!gpFiles::Replace($rename_from, $destination)) {
         msg($langmessage['OOPS'] . ' (Not replaced)');
         return false;
     }
     // save configuration
     if (!array_key_exists($plugin_name, $this->cke_config['plugins'])) {
         $this->cke_config['plugins'][$plugin_name] = array('installed' => time());
     }
     $this->cke_config['plugins'][$plugin_name]['updated'] = time();
     $this->SaveConfig();
     msg($langmessage['SAVED']);
 }
Beispiel #3
0
 /**
  * Download the source code
  *
  */
 function DownloadSource()
 {
     global $langmessage, $dataDir;
     $this->msg('Downloading version ' . $this->core_package['version'] . ' from ' . CMS_READABLE_DOMAIN . '.');
     /* for testing
      * $download = 'http://gpeasy.loc/x_gpEasy.zip';
      */
     $download = addon_browse_path . '/Special_gpEasy?cmd=download';
     $contents = \gp\tool\RemoteGet::Get_Successful($download);
     if (!$contents || empty($contents)) {
         $this->msg($langmessage['download_failed'] . '(1)');
         return false;
     }
     $this->msg($langmessage['package_downloaded']);
     $md5 = md5($contents);
     if ($md5 != $this->core_package['md5']) {
         $this->msg($langmessage['download_failed_md5'] . '<br/>Downloaded Checksum (' . $md5 . ') != Expected Checksum (' . $this->core_package['md5'] . ')');
         return false;
     }
     $this->msg($langmessage['download_verified']);
     //save contents
     $temp_file = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/update', '.zip');
     if (!\gp\tool\Files::Save($temp_file, $contents)) {
         $this->msg($langmessage['download_failed'] . ' (2)');
         return false;
     }
     $this->core_package['file'] = $temp_file;
     return true;
 }
Beispiel #4
0
 /**
  * Write Archive
  *
  */
 private function ExtractArchive($archive_path)
 {
     global $langmessage, $dataDir;
     $archive = new \gp\tool\Archive($archive_path);
     $extract_temp = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/addon');
     if (!$archive->extractTo($extract_temp)) {
         $this->message($langmessage['download_failed'] . ' (Package not extracted)');
         return false;
     }
     //get archive root
     $archive_root = $archive->GetRoot();
     if (is_null($archive_root)) {
         $this->message($langmessage['download_failed'] . ' (Root not found)');
         return false;
     }
     //rename to source folder
     $rename_from = $extract_temp . '/' . ltrim($archive_root, '/');
     if (!\gp\tool\Files::Replace($rename_from, $this->source)) {
         $this->message($langmessage['download_failed'] . ' (Not replaced)');
         return false;
     }
     return true;
 }