From 9f12d229565cd096bbac0dacd8d6402d322ea81c Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 10 Oct 2019 15:18:24 +0200 Subject: [PATCH 1/4] Fix for NGINX --- htdocs/api/index.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 2a734b9336d..318b47c6d36 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -38,6 +38,9 @@ if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is p if (! empty($_SERVER['HTTP_DOLAPIENTITY'])) define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']); +// Fix for NGINX +$url = $_SERVER["SCRIPT_URI"] !== null ? $_SERVER["SCRIPT_URI"] : $_SERVER['PHP_SELF']; + $res=0; if (! $res && file_exists("../main.inc.php")) $res=include '../main.inc.php'; if (! $res) die("Include of main fails"); @@ -67,7 +70,7 @@ if (empty($conf->global->MAIN_MODULE_API)) } // Test if explorer is not disabled -if (preg_match('/api\/index\.php\/explorer/', $_SERVER["PHP_SELF"]) && ! empty($conf->global->API_EXPLORER_DISABLED)) +if (preg_match('/api\/index\.php\/explorer/', $url) && ! empty($conf->global->API_EXPLORER_DISABLED)) { $langs->load("admin"); dol_syslog("Call Dolibarr API interfaces with module REST disabled"); @@ -91,7 +94,7 @@ if (preg_match('/api\/index\.php\/explorer/', $_SERVER["PHP_SELF"]) && ! empty($ $reg=array(); -preg_match('/index\.php\/([^\/]+)(.*)$/', $_SERVER["PHP_SELF"], $reg); +preg_match('/index\.php\/([^\/]+)(.*)$/', $url, $reg); // .../index.php/categories?sortfield=t.rowid&sortorder=ASC From 2c06969c2a818fb8866e38081d8dbf62d2327652 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 25 Oct 2019 10:09:24 +0200 Subject: [PATCH 2/4] Fix travis-ci error in RestAPIUserTest.php --- htdocs/api/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 318b47c6d36..613580785a5 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -39,7 +39,7 @@ if (! empty($_SERVER['HTTP_DOLAPIENTITY'])) define("DOLENTITY", (int) $_SERVER[' // Fix for NGINX -$url = $_SERVER["SCRIPT_URI"] !== null ? $_SERVER["SCRIPT_URI"] : $_SERVER['PHP_SELF']; +$url = (isset($_SERVER['SCRIPT_URI']) && $_SERVER["SCRIPT_URI"] !== null) ? $_SERVER["SCRIPT_URI"] : $_SERVER['PHP_SELF']; $res=0; if (! $res && file_exists("../main.inc.php")) $res=include '../main.inc.php'; From 74473edb0caa49c32b95ac3abac2f04fa3c6c101 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Nov 2019 13:52:24 +0100 Subject: [PATCH 3/4] Update index.php --- htdocs/api/index.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 613580785a5..6a081a87a20 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -38,9 +38,6 @@ if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is p if (! empty($_SERVER['HTTP_DOLAPIENTITY'])) define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']); -// Fix for NGINX -$url = (isset($_SERVER['SCRIPT_URI']) && $_SERVER["SCRIPT_URI"] !== null) ? $_SERVER["SCRIPT_URI"] : $_SERVER['PHP_SELF']; - $res=0; if (! $res && file_exists("../main.inc.php")) $res=include '../main.inc.php'; if (! $res) die("Include of main fails"); @@ -58,7 +55,13 @@ require_once DOL_DOCUMENT_ROOT.'/api/class/api_access.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - +$url = $_SERVER['PHP_SELF']; +// Fix for some NGINX setups (this should not be required even with NGINX, however setup of NGINX are often mysterious and this may help is such cases) +if (! empty($conf->global->MAIN_NGINX_FIX)) +{ + $url = (isset($_SERVER['SCRIPT_URI']) && $_SERVER["SCRIPT_URI"] !== null) ? $_SERVER["SCRIPT_URI"] : $_SERVER['PHP_SELF']; +} + // Enable and test if module Api is enabled if (empty($conf->global->MAIN_MODULE_API)) { From 03bd6e4db3c992644a17dc231ab75863063beaa5 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 2 Nov 2019 12:51:45 +0000 Subject: [PATCH 4/4] Fixing style errors. --- htdocs/api/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 6a081a87a20..7a9ef9ad24d 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -61,7 +61,7 @@ if (! empty($conf->global->MAIN_NGINX_FIX)) { $url = (isset($_SERVER['SCRIPT_URI']) && $_SERVER["SCRIPT_URI"] !== null) ? $_SERVER["SCRIPT_URI"] : $_SERVER['PHP_SELF']; } - + // Enable and test if module Api is enabled if (empty($conf->global->MAIN_MODULE_API)) {