コード例 #1
0
 /**
  * Save config file on the disk or over ftp
  *
  * @return bool
  */
 public function store()
 {
     $result = false;
     if ($this->_forceSave || $this->_configLoaded || strlen($this->remote_config) > 0) {
         $data = serialize($this->toArray());
         if (strlen($this->remote_config) > 0) {
             //save config over ftp
             $confFile = $this->downloader_path . DIRECTORY_SEPARATOR . "connect.cfg";
             try {
                 $ftpObj = new Mage_Connect_Ftp();
                 $ftpObj->connect($this->remote_config);
             } catch (Exception $e) {
                 $this->_configError = 'Cannot access to deployment FTP path. ' . 'Check deployment FTP Installation path settings.';
                 return $result;
             }
             try {
                 $tempFile = tempnam(sys_get_temp_dir(), 'config');
                 $f = fopen($tempFile, "w+");
                 fwrite($f, self::HEADER);
                 fwrite($f, $data);
                 fclose($f);
             } catch (Exception $e) {
                 $this->_configError = 'Cannot access to temporary file storage to save Settings.' . 'Contact your system administrator.';
                 return $result;
             }
             try {
                 $result = $ftpObj->upload($confFile, $tempFile);
                 $ftpObj->close();
             } catch (Exception $e) {
                 $this->_configError = 'Cannot write file over FTP. ' . 'Check deployment FTP Installation path settings.';
                 return $result;
             }
             if (!$result) {
                 $this->_configError = '';
             }
         } elseif (is_file($this->_configFile) && is_writable($this->_configFile) || is_writable(getcwd())) {
             try {
                 $f = fopen($this->_configFile, "w+");
                 fwrite($f, self::HEADER);
                 fwrite($f, $data);
                 fclose($f);
                 $result = true;
             } catch (Exception $e) {
                 $result = false;
             }
         }
     }
     return $result;
 }
コード例 #2
0
ファイル: Packager.php プロジェクト: jpbender/mage_virtual
 public function getRemoteConfig($ftpString)
 {
     $ftpObj = new Mage_Connect_Ftp();
     $ftpObj->connect($ftpString);
     $cfgFile = self::CONFIG_FILE_NAME;
     $wd = $ftpObj->getcwd();
     $remoteConfigExists = $ftpObj->fileExists($cfgFile);
     $tempConfigFile = tempnam(sys_get_temp_dir(), 'conf_');
     if (!$remoteConfigExists) {
         $remoteCfg = new Mage_Connect_Config($tempConfigFile);
         $remoteCfg->store();
         $ftpObj->upload($cfgFile, $tempConfigFile);
     } else {
         $ftpObj->get($tempConfigFile, $cfgFile);
         $remoteCfg = new Mage_Connect_Config($tempConfigFile);
     }
     $ftpObj->chdir($wd);
     return array($remoteCfg, $ftpObj);
 }
コード例 #3
0
 /**
  * Begin install package(s)
  */
 public function startInstall()
 {
     if ($this->_getMaintenanceFlag()) {
         $maintenance_filename = 'maintenance.flag';
         $config = $this->config();
         if (!$this->isWritable() || strlen($config->__get('remote_config')) > 0) {
             $ftpObj = new Mage_Connect_Ftp();
             $ftpObj->connect($config->__get('remote_config'));
             $tempFile = tempnam(sys_get_temp_dir(), 'maintenance');
             @file_put_contents($tempFile, 'maintenance');
             $ftpObj->upload($maintenance_filename, $tempFile);
             $ftpObj->close();
         } else {
             @file_put_contents($this->_getMaintenanceFilePath(), 'maintenance');
         }
     }
     if (!empty($_GET['archive_type'])) {
         $backupName = $_GET['backup_name'];
         $connect = $this->model('connect', true)->connect();
         $isSuccess = true;
         if (!preg_match('/^[a-zA-Z0-9\\ ]{0,50}$/', $backupName)) {
             $connect->runHtmlConsole('Please use only letters (a-z or A-Z), numbers (0-9) or space in ' . 'Backup Name field. Other characters are not allowed.');
             $isSuccess = false;
         }
         if ($isSuccess) {
             $isSuccess = $this->_createBackup($_GET['archive_type'], $_GET['backup_name']);
         }
         if (!$isSuccess) {
             $this->endInstall();
             $this->cleanCache();
             throw new Mage_Exception('The installation process has been canceled because of the backup creation error');
         }
     }
 }
コード例 #4
0
ファイル: Packager.php プロジェクト: hirentricore/devmagento
 public function getRemoteConfig($ftpString)
 {
     $ftpObj = new Mage_Connect_Ftp();
     $ftpObj->connect($ftpString);
     $cfgFile = "connect.cfg";
     $wd = $ftpObj->getcwd();
     $remoteConfigExists = $ftpObj->fileExists($cfgFile);
     $tempConfigFile = uniqid($cfgFile . "_temp");
     if (!$remoteConfigExists) {
         $remoteCfg = new Mage_Connect_Config($tempConfigFile);
         $remoteCfg->store();
         $ftpObj->upload($cfgFile, $tempConfigFile);
     } else {
         $ftpObj->get($tempConfigFile, $cfgFile);
         $remoteCfg = new Mage_Connect_Config($tempConfigFile);
     }
     $ftpObj->chdir($wd);
     return array($remoteCfg, $ftpObj);
 }
コード例 #5
0
ファイル: Connect.php プロジェクト: newedge-media/iwantmymeds
 /**
  * Validate settings post data.
  *
  * @param array $p
  */
 public function validateConfigPost($p)
 {
     $errors = array();
     $configTestFile = 'connect.cfgt';
     $configObj = $this->connect()->getConfig();
     if ('ftp' == $p['deployment_type'] || '1' == $p['inst_protocol']) {
         /*check ftp*/
         $confFile = $configObj->downloader_path . DIRECTORY_SEPARATOR . $configTestFile;
         try {
             $ftpObj = new Mage_Connect_Ftp();
             $ftpObj->connect($p['ftp']);
             $tempFile = tempnam(sys_get_temp_dir(), 'config');
             $serial = md5('config test file');
             $f = @fopen($tempFile, "w+");
             @fwrite($f, $serial);
             @fclose($f);
             $ret = $ftpObj->upload($confFile, $tempFile);
             //read file
             if (!$errors && is_file($configTestFile)) {
                 $size = filesize($configTestFile);
                 if (!$size) {
                     $errors[] = 'Unable to read saved settings. Please check Installation Path of FTP Connection.';
                 }
                 if (!$errors) {
                     $f = @fopen($configTestFile, "r");
                     @fseek($f, 0, SEEK_SET);
                     $contents = @fread($f, strlen($serial));
                     if ($serial != $contents) {
                         $errors[] = 'Wrong Installation Path of FTP Connection.';
                     }
                     fclose($f);
                 }
             } else {
                 $errors[] = 'Unable to read saved settings. Please check Installation Path of FTP Connection.';
             }
             $ftpObj->delete($confFile);
             $ftpObj->close();
         } catch (Exception $e) {
             $errors[] = 'Deployment FTP Error. ' . $e->getMessage();
         }
     } else {
         $p['ftp'] = '';
     }
     if ('1' == $p['use_custom_permissions_mode']) {
         /*check permissions*/
         if (octdec(intval($p['mkdir_mode'])) < 73 || octdec(intval($p['mkdir_mode'])) > 511) {
             $errors[] = 'Folders permissions not valid. ';
         }
         if (octdec(intval($p['chmod_file_mode'])) < 73 || octdec(intval($p['chmod_file_mode'])) > 511) {
             $errors[] = 'Files permissions not valid. ';
         }
     }
     //$this->controller()->session()->addMessage('success', 'Settings has been successfully saved');
     return $errors;
 }
コード例 #6
0
ファイル: Controller.php プロジェクト: relue/magento2
 /**
  * Begin install package(s)
  */
 public function startInstall()
 {
     if ($this->_getMaintenanceFlag()) {
         $maintenance_filename = 'maintenance.flag';
         $config = $this->config();
         if (!$this->isWritable() || strlen($config->__get('remote_config')) > 0) {
             $ftpObj = new Mage_Connect_Ftp();
             $ftpObj->connect($config->__get('remote_config'));
             $tempFile = tempnam(sys_get_temp_dir(), 'maintenance');
             @file_put_contents($tempFile, 'maintenance');
             $ftpObj->upload($maintenance_filename, $tempFile);
             $ftpObj->close();
         } else {
             @file_put_contents($this->_getMaintenanceFilePath(), 'maintenance');
         }
     }
 }
コード例 #7
0
ファイル: Packager.php プロジェクト: buttasg/cowgirlk
 /**
  * Install package over FTP
  *
  * @param Mage_Connect_Package $package
  * @param string $file
  * @param Mage_Connect_Config $configObj
  * @param Mage_Connect_Ftp $ftp
  * @return void
  */
 public function processInstallPackageFtp($package, $file, $configObj, $ftp)
 {
     $ftpDir = $ftp->getcwd();
     $contents = $package->getContents();
     $arc = $this->getArchiver();
     $target = dirname($file) . DS . $package->getReleaseFilename();
     @mkdir($target, 0777, true);
     $tar = $arc->unpack($file, $target);
     $modeFile = $this->_getFileMode($configObj);
     $modeDir = $this->_getDirMode($configObj);
     foreach ($contents as $file) {
         $source = $tar . DS . $file;
         if (file_exists($source) && is_file($source)) {
             $args = array(ltrim($file, "/"), $source);
             if ($modeDir || $modeFile) {
                 $args[] = $modeDir;
                 $args[] = $modeFile;
             }
             call_user_func_array(array($ftp, 'upload'), $args);
         }
     }
     $localXml = $tar . Mage_Connect_Package_Reader::DEFAULT_NAME_PACKAGE;
     if (is_file($localXml)) {
         $remoteXml = Mage_Connect_Package::PACKAGE_XML_DIR . DS . $package->getReleaseFilename() . '.xml';
         $ftp->upload($remoteXml, $localXml, $modeDir, $modeFile);
     }
     $ftp->chdir($ftpDir);
     Mage_System_Dirs::rm(array("-r", $target));
 }
コード例 #8
0
ファイル: Config.php プロジェクト: votanlean/Magento-Pruebas
 public function store()
 {
     if ($this->_configLoaded || strlen($this->remote_config) > 0) {
         // @TODO: use ftp to save config
         $data = serialize($this->toArray());
         if (strlen($this->remote_config) > 0) {
             $confFile = $this->downloader_path . DIRECTORY_SEPARATOR . "connect.cfg";
             $ftpObj = new Mage_Connect_Ftp();
             $ftpObj->connect($this->remote_config);
             $tempFile = tempnam(sys_get_temp_dir(), 'config');
             $f = @fopen($tempFile, "w+");
             @fwrite($f, self::HEADER);
             @fwrite($f, $data);
             @fclose($f);
             $ret = $ftpObj->upload($confFile, $tempFile);
             $ftpObj->close();
         } elseif (is_file($this->_configFile) && is_writable($this->_configFile) || is_writable(getcwd())) {
             $f = @fopen($this->_configFile, "w+");
             @fwrite($f, self::HEADER);
             @fwrite($f, $data);
             @fclose($f);
         }
     }
 }
コード例 #9
0
ファイル: Abstract.php プロジェクト: cewolf2002/magento
 /**
  * Save file
  *
  * @return Maged_Model_Config
  */
 public function save()
 {
     if (!is_writable($this->getFilename()) && is_file($this->getFilename()) || dirname($this->getFilename()) != '' && !is_writable(dirname($this->getFilename()))) {
         if (isset($this->_data['ftp']) && !empty($this->_data['ftp']) && strlen($this->get('downloader_path')) > 0) {
             $confFile = $this->get('downloader_path') . DIRECTORY_SEPARATOR . basename($this->getFilename());
             $ftpObj = new Mage_Connect_Ftp();
             $ftpObj->connect($this->_data['ftp']);
             $tempFile = tempnam(sys_get_temp_dir(), 'configini');
             $fp = fopen($tempFile, 'w');
             foreach ($this->_data as $k => $v) {
                 fwrite($fp, $k . '=' . $v . "\n");
             }
             fclose($fp);
             $ret = $ftpObj->upload($confFile, $tempFile);
             $ftpObj->close();
         } else {
             /* @TODO: show Warning message*/
             $this->controller()->session()->addMessage('warning', 'Invalid file permissions, could not save configuration.');
             return $this;
         }
         /**/
     } else {
         $fp = fopen($this->getFilename(), 'w');
         foreach ($this->_data as $k => $v) {
             fwrite($fp, $k . '=' . $v . "\n");
         }
         fclose($fp);
     }
     return $this;
 }
コード例 #10
0
ファイル: Packager.php プロジェクト: okite11/frames21
 /**
  * Install package over FTP
  *
  * @param Mage_Connect_Package $package
  * @param string $file
  * @param Mage_Connect_Config $configObj
  * @param Mage_Connect_Ftp $ftp
  * @throws RuntimeException
  */
 public function processInstallPackageFtp($package, $file, $configObj, $ftp)
 {
     $ftpDir = $ftp->getcwd();
     $contents = $package->getContents();
     $arc = $this->getArchiver();
     $target = dirname($file) . DS . $package->getReleaseFilename();
     if (!@mkdir($target, 0777, true)) {
         throw new RuntimeException("Can't create directory " . $target);
     }
     $tar = $arc->unpack($file, $target);
     $modeFile = $this->_getFileMode($configObj);
     $modeDir = $this->_getDirMode($configObj);
     $failedFiles = array();
     foreach ($contents as $file) {
         $source = $tar . DS . $file;
         if (file_exists($source) && is_file($source)) {
             $args = array(ltrim($file, "/"), $source);
             if ($modeDir || $modeFile) {
                 $args[] = $modeDir;
                 $args[] = $modeFile;
             }
             if (call_user_func_array(array($ftp, 'upload'), $args) === false) {
                 $failedFiles[] = $source;
             }
         }
     }
     if (!empty($failedFiles)) {
         $msg = sprintf("Failed to upload files: %s \r\n Check permissions", implode("\r\n", $failedFiles));
         throw new RuntimeException($msg);
     }
     $localXml = $tar . Mage_Connect_Package_Reader::DEFAULT_NAME_PACKAGE;
     if (is_file($localXml)) {
         $remoteXml = Mage_Connect_Package::PACKAGE_XML_DIR . DS . $package->getReleaseFilename() . '.xml';
         $ftp->upload($remoteXml, $localXml, $modeDir, $modeFile);
     }
     $ftp->chdir($ftpDir);
     Mage_System_Dirs::rm(array("-r", $target));
 }