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

Commit

Permalink
Use restBase parameter.
Browse files Browse the repository at this point in the history
Use new methods in cmd.php
  • Loading branch information
cdujeu committed May 9, 2016
1 parent 81c76d9 commit 4a23ca0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 37 deletions.
31 changes: 11 additions & 20 deletions core/src/cmd.php
Expand Up @@ -36,17 +36,9 @@

include_once("base.conf.php");

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
//set_error_handler(array("AJXP_XMLWriter", "catchError"), E_ALL & ~E_NOTICE );
//set_exception_handler(array("AJXP_XMLWriter", "catchException"));

ConfService::init();
ConfService::start();


$optArgs = array();
$options = array();
$regex = '/^-(-?)([a-zA-z0-9_]*)=(.*)/';
Expand Down Expand Up @@ -195,12 +187,9 @@

//Set language
$loggedUser = AuthService::getLoggedUser();
if($loggedUser != null && $loggedUser->getPref("lang") != "") ConfService::setLanguage($loggedUser->getPref("lang"));
else if(isSet($_COOKIE["AJXP_lang"])) ConfService::setLanguage($_COOKIE["AJXP_lang"]);
$mess = ConfService::getMessages();

// THIS FIRST DRIVERS DO NOT NEED ID CHECK
//$ajxpDriver = PluginsService::findPlugin("gui", "ajax");
$authDriver = ConfService::getAuthDriverImpl();
// DRIVERS BELOW NEED IDENTIFICATION CHECK
if (!AuthService::usersEnabled() || ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth") || AuthService::getLoggedUser()!=null) {
Expand All @@ -209,16 +198,18 @@
$Driver = ConfService::loadDriverForRepository($loadRepo);
}
PluginsService::getInstance()->initActivePlugins();
$xmlResult = Controller::findActionAndApply($optAction, $optArgs, array());
if ($xmlResult !== false && $xmlResult != "") {
XMLWriter::header();
print($xmlResult);
XMLWriter::close();
} else if (isset($requireAuth) && Controller::$lastActionNeedsAuth) {
XMLWriter::header();
XMLWriter::requireAuth();
XMLWriter::close();

$fakeRequest = \Zend\Diactoros\ServerRequestFactory::fromGlobals(array(), array(), $optArgs)->withAttribute("action", $optAction);
try{
$response = Controller::run($fakeRequest);
if($response !== false && ($response->getBody()->getSize() || $response instanceof \Zend\Diactoros\Response\EmptyResponse)) {
echo $response->getBody();
}
}catch (Exception $e){
echo "ERROR : ".$e->getMessage()."\n";
echo print_r($e->getTraceAsString())."\n";
}

//echo("NEXT REPO ".$nextRepositories." (".$options["r"].")\n");
//echo("NEXT USERS ".$nextUsers." ( ".$originalOptUser." )\n");
if (!empty($nextUsers) || !empty($nextRepositories) || !empty($optUserQueue) ) {
Expand Down
4 changes: 1 addition & 3 deletions core/src/core/src/pydio/Core/Controller/Controller.php
Expand Up @@ -25,15 +25,13 @@
use Pydio\Core\Exception\AuthRequiredException;
use Pydio\Core\Exception\PydioException;
use Pydio\Auth\Core\AJXP_Safe;
use Pydio\Core\Utils\Utils;
use Pydio\Core\Services;
use Pydio\Core\Services\AuthService;
use Pydio\Core\Services\ConfService;
use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Utils\UnixProcess;
use Pydio\Log\Core\AJXP_Logger;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;

defined('AJXP_EXEC') or die( 'Access not allowed');
/**
Expand Down Expand Up @@ -78,7 +76,7 @@ public static function registryReset(){
self::$xPath = null;
self::$hooksCache = array();
}


/**
* @param ServerRequestInterface $request
Expand Down
3 changes: 2 additions & 1 deletion core/src/core/src/pydio/Core/Http/Server.php
Expand Up @@ -91,9 +91,10 @@ protected function initServerRequest($rest = false){

if($this->mode == PYDIO_SERVER_MODE_REST){

$restBase = ConfService::currentContextIsRestAPI();
$serverData = $request->getServerParams();
$uri = $serverData["REQUEST_URI"];
$scriptUri = ltrim(Utils::safeDirname($serverData["SCRIPT_NAME"]),'/')."/api/";
$scriptUri = ltrim(Utils::safeDirname($serverData["SCRIPT_NAME"]),'/').$restBase."/";
$uri = substr($uri, strlen($scriptUri));
$uri = explode("/", trim($uri, "/"));
$repoID = array_shift($uri);
Expand Down
2 changes: 1 addition & 1 deletion core/src/core/src/pydio/Core/Utils/Utils.php
Expand Up @@ -900,7 +900,7 @@ public static function detectServerURL($withURI = false)
$api = ConfService::currentContextIsRestAPI();
if(!empty($api)){
// Keep only before api base
$explode = explode("/".$api."/", $uri);
$explode = explode($api."/", $uri);
$uri = array_shift($explode);
}
return "$protocol://$name$port".$uri;
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.index/class.CoreIndexer.php
Expand Up @@ -183,7 +183,7 @@ public function recursiveIndexation($node, $depth = 0)
/**
* @param Repository $repository
* @param AbstractAjxpUser $user
* @return Array
* @return string
*/
protected function buildIndexLockKey($repository, $user){
$scope = $repository->securityScope();
Expand Down Expand Up @@ -215,7 +215,7 @@ protected function setIndexStatus($status, $message, $repository, $user)
/**
* @param Repository $repository
* @param AbstractAjxpUser $user
* @return Array Array(STATUS, Message)
* @return array Array(STATUS, Message)
*/
protected function getIndexStatus($repository, $user)
{
Expand Down
2 changes: 1 addition & 1 deletion core/src/rest.php
Expand Up @@ -27,7 +27,7 @@

include_once("base.conf.php");

ConfService::currentContextIsRestAPI("api");
ConfService::currentContextIsRestAPI("/api");

ConfService::registerCatchAll();
ConfService::init();
Expand Down
19 changes: 10 additions & 9 deletions core/src/worker.php
Expand Up @@ -39,7 +39,7 @@
ConfService::start();

$authDriver = ConfService::getAuthDriverImpl();
ConfService::currentContextIsRestAPI("api");
ConfService::currentContextIsRestAPI("/api");
PluginsService::getInstance()->initActivePlugins();

function applyTask($userId, $repoId, $actionName, $parameters){
Expand Down Expand Up @@ -67,14 +67,15 @@ function applyTask($userId, $repoId, $actionName, $parameters){
print("Init plugins\n");
PluginsService::getInstance()->initActivePlugins();

//print "Current repos are" . implode(", ", array_keys(ConfService::getAccessibleRepositories()))."\n";

print("Apply Action\n");
$xmlResult = Controller::findActionAndApply($actionName, $parameters, []);
if (!empty($xmlResult) && !headers_sent()) {
XMLWriter::header();
print($xmlResult);
XMLWriter::close();
$fakeRequest = \Zend\Diactoros\ServerRequestFactory::fromGlobals(array(), array(), $parameters)->withAttribute("action", $actionName);
try{
$response = Controller::run($fakeRequest);
if($response !== false && ($response->getBody()->getSize() || $response instanceof \Zend\Diactoros\Response\EmptyResponse)) {
echo $response->getBody();
}
}catch (Exception $e){
echo "ERROR : ".$e->getMessage()."\n";
echo print_r($e->getTraceAsString())."\n";
}

print("Empty ShutdownScheduler!\n");
Expand Down

0 comments on commit 4a23ca0

Please sign in to comment.