function connect() { if (!$this->options['hostname'] || !$this->options['username'] || !$this->options['password']) { if (!defined('SUPPORT_URL')) { define('SUPPORT_URL', getOption('supportURL')); } appUpdateMsg('<a href="' . SUPPORT_URL . 'solution/articles/195233-asking-for-ftp-sftp-details-during-update/" target="_blank">See how to add the FTP details</a>.'); return false; } if (isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect')) { $this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT); } else { $this->link = @ftp_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT); } if (!$this->link) { //$this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port'])); appUpdateMsg(sprintf('Failed to connect to the FTP server "%1$s:%2$s"', $this->options['hostname'], $this->options['port'])); return false; } if (!@ftp_login($this->link, $this->options['username'], $this->options['password'])) { //$this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username'])); appUpdateMsg(sprintf('FTP username or password incorrect for "%s"', $this->options['username'])); return false; } //Set the Connection to use Passive FTP if ($this->options['passive']) { @ftp_pasv($this->link, true); } if (@ftp_get_option($this->link, FTP_TIMEOUT_SEC) < FS_TIMEOUT) { @ftp_set_option($this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT); } return true; }
function connect() { $this->link = new Net_SFTP($this->options['hostname'], $this->options['port']); if (!$this->link) { //$this->errors->add('connect', sprintf(__('Failed to connect to SSH2 Server %1$s:%2$s'), $this->options['hostname'], $this->options['port'])); appUpdateMsg(sprintf('Failed to connect to SSH2 Server %1$s:%2$s', $this->options['hostname'], $this->options['port']), true); return false; } if (!$this->link->login($this->options['username'], $this->options['password'])) { appUpdateMsg(sprintf('Username/Password incorrect for %s', $this->options['username']), true); return false; } return true; }
function isValidNonDirectBasePath($args) { //assuming 1.$GLOBALS['FileSystemObj'] object already created 2.assuming method is non direct $testFile = '/__testFTP' . time() . '.php'; $appPathFile = APP_ROOT . $testFile; $FTPPathFile = rtrim($args['base'], '/') . $testFile; $testFileCreated = $GLOBALS['FileSystemObj']->putContents($FTPPathFile, 'Hello World', FS_CHMOD_FILE); sleep(1); $isTestFileExists = file_exists($appPathFile); if ($testFileCreated) { $GLOBALS['FileSystemObj']->delete($FTPPathFile); } if (!$isTestFileExists) { appUpdateMsg('Invalid FTP base path..', true); exit; } }
function installAddons($addons) { //install and activate the addon foreach ($addons as $addon) { if (empty($addon['process']['unzipDone'])) { continue; } $ok = false; appUpdateMsg('Installing ' . $addon['slug'] . ' addon...'); $isExist = DB::getField("?:addons", "slug", "slug='" . $addon['slug'] . "'"); if ($isExist) { appUpdateMsg('The ' . $addon['slug'] . ' addon is already installed.'); continue; } if (file_exists(APP_ROOT . '/addons/' . $addon['slug'] . '/addon.' . $addon['slug'] . '.php')) { //activating the addon $isDone = DB::insert("?:addons", array('slug' => $addon['slug'], 'addon' => $addon['addon'], 'status' => 'active', 'validityExpires' => $addon['validityExpires'], 'initialVersion' => $addon['version'], 'updateCurrentVersion' => $addon['version'])); if ($isDone) { $ok = true; include_once APP_ROOT . '/addons/' . $addon['slug'] . '/addon.' . $addon['slug'] . '.php'; if (method_exists('addon' . ucfirst($addon['slug']), 'install')) { $isSuccess = call_user_func(array('addon' . ucfirst($addon['slug']), 'install')); if (!$isSuccess) { $ok = false; DB::delete("?:addons", "slug = '" . $addon['slug'] . "'"); appUpdateMsg('An error occurred while installing the ' . $addon['slug'] . ' addon.'); } } if ($ok) { appUpdateMsg($addon['slug'] . ' addon successfully installed.'); //remove addon install available for this addon so that it will stop false notification in next browser app load //$newAddonsAvailableTemp = @unserialize(getOption('newAddonsAvailable')); //if(isset($newAddonsAvailableTemp[ $addon['slug'] ])){ // unset($newAddonsAvailableTemp[ $addon['slug'] ]); // updateOption('newAddonsAvailable', serialize($newAddonsAvailableTemp)); //}//commented because new installed getting deleted in next run } } } else { appUpdateMsg('A file was found missing while installing the ' . $addon['slug'] . ' addon.'); } $optionVer['action'] = 'installed'; $optionVer['actionTime'] = time(); $optionVer['prevVer'] = '0'; $optionVer['newVer'] = $addon['version']; $optionVer['slug'] = $addon['slug']; manipulateOption('versionLogs', $optionVer); } //force update to make new addons to show as installed //checkUpdate(true, true);//commented because this deleting old addons }
/** * Copies a directory from one location to another via the WordPress Filesystem Abstraction. * * @param string $from source directory * @param string $to destination directory * @param array $skipList a list of files/folders to skip copying * @return mixed WP_Error on failure, True on success. */ function copyDir($from, $to, $skipList = array()) { //global $GLOBALS['FileSystemObj']; $dirlist = $GLOBALS['FileSystemObj']->dirList($from); $from = addTrailingSlash($from); $to = addTrailingSlash($to); $skip_regex = ''; foreach ((array) $skipList as $key => $skipFile) { $skip_regex .= preg_quote($skipFile, '!') . '|'; } if (!empty($skip_regex)) { $skip_regex = '!(' . rtrim($skip_regex, '|') . ')$!i'; } foreach ((array) $dirlist as $filename => $fileinfo) { if (!empty($skip_regex)) { if (preg_match($skip_regex, $from . $filename)) { continue; } } if ('f' == $fileinfo['type']) { if (!$GLOBALS['FileSystemObj']->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE)) { // If copy failed, chmod file to 0644 and try again. $GLOBALS['FileSystemObj']->chmod($to . $filename, 0644); if (!$GLOBALS['FileSystemObj']->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE)) { //return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename); appUpdateMsg('Could not copy file ' . $to . $filename, true); return false; } } } elseif ('d' == $fileinfo['type']) { if (!$GLOBALS['FileSystemObj']->isDir($to . $filename)) { if (!$GLOBALS['FileSystemObj']->mkDir($to . $filename, FS_CHMOD_DIR)) { //return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename); appUpdateMsg('Could not create directory while copying ' . $to . $filename, true); return false; } } $result = $this->copyDir($from . $filename, $to . $filename, $skipList); if ($result == false) { return $result; } } } return true; }