Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Add support for authenticated upgrade site.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Nov 3, 2015
1 parent 51b2ca4 commit 53c7dd8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
37 changes: 29 additions & 8 deletions core/src/plugins/action.updater/class.AjaXplorerUpgrader.php
Expand Up @@ -87,15 +87,32 @@ public function __construct($archiveURL, $hash, $method, $backupFiles = array())

}

public static function configureProxy($proxyHost, $proxyUser, $proxyPass)
public static function configureProxy($proxyHost, $proxyUser, $proxyPass, $siteUser = "", $sitePass = "")
{
$proxy = array( 'http' => array( 'proxy' => 'tcp://'.$proxyHost, 'request_fulluri' => true ) );
$proxy['ssl']['SNI_enabled'] = false;
if (!empty($proxyUser) && !empty($proxyPass)) {
$auth = base64_encode($proxyUser.":".$proxyPass);
$proxy['http']['header'] = "Proxy-Authorization: Basic $auth";
$contextData = array('http' => array());
if(!empty($proxyHost)){
$contextData['http']['proxy'] = 'tcp://'.$proxyHost;// $proxy = array( 'http' => array( 'proxy' => 'tcp://'.$proxyHost, 'request_fulluri' => true ) );
$contextData['http']['request_fulluri'] = true;
$contextData['ssl']['SNI_enabled'] = false;
if (!empty($proxyUser) && !empty($proxyPass)) {
$auth = base64_encode($proxyUser.":".$proxyPass);
$contextData['http']['header'] = "Proxy-Authorization: Basic $auth";
}
}
if(!empty($siteUser) && !empty($sitePass)){
$headerString = "Authorization: Basic " . base64_encode("$siteUser:$sitePass");
if(isSet($contextData['http']['header'])){
$contextData['http']['header'] .= "; ".$headerString;
}else{
$contextData['http']['header'] = $headerString;
}
}
self::$context = stream_context_create($proxy);

self::$context = stream_context_create($contextData);
}

public static function getContext(){
return self::$context;
}

public static function getUpgradePath($url, $format = "php", $channel="stable")
Expand Down Expand Up @@ -170,7 +187,11 @@ public function downloadArchive()
if ($this->debugMode && is_file($this->archive)) {
return "Already downloaded";
}
$content = AJXP_Utils::getRemoteContent($this->archiveURL);
if(self::$context){
$content = file_get_contents($this->archiveURL, null, self::$context);
}else{
$content = AJXP_Utils::getRemoteContent($this->archiveURL);
}
if ($content === false || strlen($content) == 0) {
throw new Exception("Error while downloading");
}
Expand Down
19 changes: 17 additions & 2 deletions core/src/plugins/action.updater/class.UpdateController.php
Expand Up @@ -64,11 +64,13 @@ public function switchAction($action, $httpVars, $fileVars)
$loggedUser = AuthService::getLoggedUser();
if(AuthService::usersEnabled() && !$loggedUser->isAdmin()) return ;
require_once(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/action.updater/class.AjaXplorerUpgrader.php");
if (!empty($this->pluginConf["PROXY_HOST"])) {
if (!empty($this->pluginConf["PROXY_HOST"]) || !empty($this->pluginConf["UPDATE_SITE_USER"])) {
AjaXplorerUpgrader::configureProxy(
$this->pluginConf["PROXY_HOST"],
$this->pluginConf["PROXY_USER"],
$this->pluginConf["PROXY_PASS"]
$this->pluginConf["PROXY_PASS"],
$this->pluginConf["UPDATE_SITE_USER"],
$this->pluginConf["UPDATE_SITE_PASS"]
);
}

Expand All @@ -88,6 +90,19 @@ public function switchAction($action, $httpVars, $fileVars)

break;

case "display_upgrade_note":

$url = $httpVars["url"];
$context = AjaXplorerUpgrader::getContext();
if($context != null){
$content = file_get_contents($url, null, $context);
}else{
$content = file_get_contents($url);
}
echo $content;

break;

case "test_upgrade_scripts":

if(!AJXP_SERVER_DEBUG
Expand Down
12 changes: 10 additions & 2 deletions core/src/plugins/action.updater/manifest.xml
Expand Up @@ -4,7 +4,8 @@
<global_param name="UPDATE_SITE" group="CONF_MESSAGE[Updater Configuration]" type="string" label="CONF_MESSAGE[Update Site]" description="CONF_MESSAGE[Where to update]" default="https://pyd.io/update/"/>
<global_param name="UPDATE_CHANNEL" group="CONF_MESSAGE[Updater Configuration]" type="select" choices="stable|CONF_MESSAGE[Stable],dev|CONF_MESSAGE[Development],test|CONF_MESSAGE[Testing (blank)]" label="CONF_MESSAGE[Update Channel]" description="CONF_MESSAGE[Check stable or dev channel]" default="stable" mandatory="true"/>
<global_param name="PRESERVE_FILES" group="CONF_MESSAGE[Updater Configuration]" type="textarea" label="CONF_MESSAGE[Preserve Files]" description="CONF_MESSAGE[Files declared here (enter pathes from the root of Ajxp installation, comma-separated) will be backed up and restored before and after upgrade.]" default=""/>
<global_param name="ENABLE_324_IMPORT" group="CONF_MESSAGE[Updater Configuration]" type="boolean" label="CONF_MESSAGE[Enable Import From v3.2.4]" description="CONF_MESSAGE[Enable the migration action, available in the Settings repository]" default="false"/>
<global_param name="UPDATE_SITE_USER" group="CONF_MESSAGE[Authenticated Update Site]" type="string" label="CONF_MESSAGE[Update Site User]" description="CONF_MESSAGE[Required if the update site is requiring credentials.]" default="" mandatory="false"/>
<global_param name="UPDATE_SITE_PASS" group="CONF_MESSAGE[Authenticated Update Site]" type="password" label="CONF_MESSAGE[Update Site Password]" description="CONF_MESSAGE[Required if the update site is requiring credentials.]" default="" mandatory="false"/>
<global_param name="PROXY_HOST" group="CONF_MESSAGE[Proxy configuration]" type="string" label="CONF_MESSAGE[Proxy Host]" description="CONF_MESSAGE[Use a predefined proxy to establish connexion]" default="" mandatory="false"/>
<global_param name="PROXY_USER" group="CONF_MESSAGE[Proxy configuration]" type="string" label="CONF_MESSAGE[Proxy User]" description="CONF_MESSAGE[Predefined proxy user name]" default="" mandatory="false"/>
<global_param name="PROXY_PASS" group="CONF_MESSAGE[Proxy configuration]" type="password" label="CONF_MESSAGE[Proxy Pass]" description="CONF_MESSAGE[Predefined proxy password]" default="" mandatory="false"/>
Expand All @@ -23,6 +24,11 @@
</serverCallback>
</processing>
</action>
<action name="display_upgrade_note">
<processing>
<serverCallback methodName="switchAction" restParams="/" developerComment="Display upgrade note"/>
</processing>
</action>
<action name="perform_upgrade">
<gui text="updater.1" title="updater.2" iconClass="icon-lightbulb" src="download_manager.png" hasAccessKey="false">
<context selection="false" dir="false" recycle="hidden" behaviour="hidden"
Expand Down Expand Up @@ -50,7 +56,9 @@
var stepsContainer = $(oForm).down('iframe[id="upgrade_steps"]');
fitHeightToBottom(stepsContainer, null, 40);
if(response.latest_note){
stepsContainer.src = response.latest_note;
var conn = new Connexion();
var url = conn._baseUrl + "&get_action=display_upgrade_note&url=" + encodeURIComponent(response.latest_note);
stepsContainer.src = url;
}
var startButton = $(oForm).down('div[id="start_upgrade_button"]');
startButton.observe("click", function(){
Expand Down

0 comments on commit 53c7dd8

Please sign in to comment.