Permalink
Browse files

Use restBase parameter.

Use new methods in cmd.php
  • Loading branch information...
1 parent 81c76d9 commit 4a23ca085e79d98f6a0f748e8a80a7eb112c2416 @cdujeu cdujeu committed May 9, 2016
View
@@ -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_]*)=(.*)/';
@@ -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) {
@@ -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) ) {
@@ -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');
/**
@@ -78,7 +76,7 @@ public static function registryReset(){
self::$xPath = null;
self::$hooksCache = array();
}
-
+
/**
* @param ServerRequestInterface $request
@@ -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);
@@ -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;
@@ -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();
@@ -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)
{
View
@@ -27,7 +27,7 @@
include_once("base.conf.php");
-ConfService::currentContextIsRestAPI("api");
+ConfService::currentContextIsRestAPI("/api");
ConfService::registerCatchAll();
ConfService::init();
View
@@ -39,7 +39,7 @@
ConfService::start();
$authDriver = ConfService::getAuthDriverImpl();
-ConfService::currentContextIsRestAPI("api");
+ConfService::currentContextIsRestAPI("/api");
PluginsService::getInstance()->initActivePlugins();
function applyTask($userId, $repoId, $actionName, $parameters){
@@ -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");

0 comments on commit 4a23ca0

Please sign in to comment.