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

Commit

Permalink
Base for repository-specific authentication via a prompt dialog. Test…
Browse files Browse the repository at this point in the history
… in FTP by uncommenting the line. Could be used for the dropbox stuff.
  • Loading branch information
cdujeu committed May 2, 2014
1 parent ff94d58 commit 0dfaeaa
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 12 deletions.
91 changes: 91 additions & 0 deletions core/src/core/classes/class.AJXP_PromptException.php
@@ -0,0 +1,91 @@
<?php
/*
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://pyd.io/>.
*/
defined('AJXP_EXEC') or die( 'Access not allowed');

define('AJXP_PROMPT_EXCEPTION_PROMPT', 'AJXP_PROMPT_EXCEPTION_PROMPT');
define('AJXP_PROMPT_EXCEPTION_CONFIRM', 'AJXP_PROMPT_EXCEPTION_CONFIRM');
define('AJXP_PROMPT_EXCEPTION_ALERT', 'AJXP_PROMPT_EXCEPTION_ALERT');

class AJXP_PromptException extends AJXP_Exception{

private $promptType = "prompt";
/**
* @var array
*/
private $promptData = array();

/**
* @return array
*/
public function getPromptData()
{
return $this->promptData;
}

/**
* @return string
*/
public function getPromptType()
{
return $this->promptType;
}

/**
* @param $promptType
* @param array $data
* @param String $messageString
* @param string|bool $messageId
*/
public function __construct($promptType, $data, $messageString, $messageId = false)
{
$this->promptType = $promptType;
$this->promptData = $data;
parent::__construct($messageString, $messageId);
}

public static function testOrPromptForCredentials($sessionVariable, $switchToRepositoryId){
if(isSet($_GET["prompt_passed_data"]) && isSet($_GET["variable_name"]) && $_GET["variable_name"] == $sessionVariable){
$_SESSION[$sessionVariable] = true;
}
if(!isSet($_SESSION[$sessionVariable])){
throw new AJXP_PromptException(
"confirm",
array(
"DIALOG" => "Please enter your credentials for this workspace
<input type='hidden' name='get_action' value='switch_repository'>
<input type='hidden' name='repository_id' value='".$switchToRepositoryId."'>
<input type='hidden' name='prompt_passed_data' value='true'>
<input type='hidden' name='variable_name' value='".$sessionVariable."'>
",
"OK" => array(
"GET_FIELDS" => array("get_action", "repository_id", "prompt_passed_data", "variable_name"),
"EVAL" => "ajaxplorer.loadXmlRegistry();"
),
"CANCEL" => array(
"EVAL" => "ajaxplorer.loadXmlRegistry();"
)
),
"Credentials Needed");
}

}

}
8 changes: 6 additions & 2 deletions core/src/core/classes/class.AJXP_XMLWriter.php
Expand Up @@ -229,7 +229,11 @@ public static function catchError($code, $message, $fichier, $ligne, $context)
}
}
if(!headers_sent()) AJXP_XMLWriter::header();
AJXP_XMLWriter::sendMessage(null, SystemTextEncoding::toUTF8($message), true);
if(!empty($context) && is_object($context) && is_a($context, "AJXP_PromptException")){
AJXP_XMLWriter::write("<prompt type=\"".$context->getPromptType()."\"><message>".$message."</message><data><![CDATA[".json_encode($context->getPromptData())."]]></data></prompt>", true);
}else{
AJXP_XMLWriter::sendMessage(null, SystemTextEncoding::toUTF8($message), true);
}
AJXP_XMLWriter::close();
exit(1);
}
Expand All @@ -241,7 +245,7 @@ public static function catchError($code, $message, $fichier, $ligne, $context)
public static function catchException($exception)
{
try {
AJXP_XMLWriter::catchError($exception->getCode(), SystemTextEncoding::fromUTF8($exception->getMessage()), $exception->getFile(), $exception->getLine(), null);
AJXP_XMLWriter::catchError($exception->getCode(), SystemTextEncoding::fromUTF8($exception->getMessage()), $exception->getFile(), $exception->getLine(), $exception);
} catch (Exception $innerEx) {
error_log(get_class($innerEx)." thrown within the exception handler!");
error_log("Original exception was: ".$innerEx->getMessage()." in ".$innerEx->getFile()." on line ".$innerEx->getLine());
Expand Down
1 change: 1 addition & 0 deletions core/src/plugins/access.ftp/class.ftpAccessDriver.php
Expand Up @@ -69,6 +69,7 @@ public function initRepository()
if ($recycle != "") {
RecycleBinManager::init($this->urlBase, "/".$recycle);
}
//AJXP_PromptException::testOrPromptForCredentials("ftp_ws_credentials", $this->repository->getId());
}

public function uploadActions($action, $httpVars, $filesVars)
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/gui.ajax/res/js/ajaxplorer.js

Large diffs are not rendered by default.

Expand Up @@ -431,12 +431,50 @@ Class.create("ActionsManager", {
{
if(childs[i].tagName == "message")
{

var messageTxt = "No message";
if(childs[i].firstChild) messageTxt = childs[i].firstChild.nodeValue;
ajaxplorer.displayMessage(childs[i].getAttribute('type'), messageTxt);
if(childs[i].getAttribute('type') == 'ERROR') error = true;
}
else if(childs[i].tagName == "reload_instruction")

}else if(childs[i].tagName == "prompt"){

var message = XPathSelectSingleNode(childs[i], "message").firstChild.nodeValue;
var jsonData = XPathSelectSingleNode(childs[i], "data").firstChild.nodeValue;
var json = jsonData.evalJSON();
var dialogContent = new Element('div').update(json["DIALOG"]);
modal.showSimpleModal(modal.messageBox?modal.messageBox:document.body, dialogContent, function(){
// ok callback;
if(json["OK"]["GET_FIELDS"]){
var params = $H();
$A(json["OK"]["GET_FIELDS"]).each(function(fName){
params.set(fName, dialogContent.down('input[name="'+fName+'"]').getValue());
});
var conn = new Connexion();
conn.setParameters(params);
if(json["OK"]["EVAL"]){
conn.onComplete = function(){
eval(json["OK"]["EVAL"]);
};
}
conn.sendAsync();
}else{
if(json["OK"]["EVAL"]){
eval(json["OK"]["EVAL"]);
}
}
return true;
}, function(){
// cancel callback
if(json["CANCEL"]["EVAL"]){
eval(json["CANCEL"]["EVAL"]);
}
return true;
});
throw new Error();

}
else if(childs[i].tagName == "reload_instruction")
{
var obName = childs[i].getAttribute('object');
if(obName == 'data')
Expand Down
Expand Up @@ -759,10 +759,10 @@ Class.create("Ajaxplorer", {
var connexion = new Connexion();
connexion.addParameter('get_action', 'switch_repository');
connexion.addParameter('repository_id', repositoryId);
oThis = this;
connexion.onComplete = function(transport){
this.repositoryId = null;
this.loadXmlRegistry();
this.actionBar.parseXmlMessage(transport.responseXML);
this.repositoryId = null;
this.loadXmlRegistry();
}.bind(this);
var root = this._contextHolder.getRootNode();
if(root){
Expand Down
5 changes: 1 addition & 4 deletions core/src/plugins/gui.ajax/res/js/lib/leightbox/lightbox.js
Expand Up @@ -336,8 +336,5 @@ function addLightboxMarkupToElement(element, skipElement)

function removeLightboxFromElement(element)
{
var tmp = $(element).select('#element_overlay');
if(tmp.length){
tmp[0].remove();
}
$(element).select('#element_overlay').invoke('remove');
}

0 comments on commit 0dfaeaa

Please sign in to comment.