From 6a53e02c3c1d2c5216cf68aa9788756feb223abf Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 5 Apr 2020 14:02:51 +0200 Subject: [PATCH 1/3] FIX better url for get conf with REST API need to be more userfriendly and similar to other api (without a variable with GET varible in URL "?confname=" --- htdocs/api/class/api_setup.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 7b47c59dbb7..05d9214389f 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -1409,15 +1409,15 @@ class Setup extends DolibarrApi * * Note that conf variables that stores security key or password hashes can't be loaded with API. * - * @url GET /conf - * - * @param string $confname Name of conf variable to get + * @param string $constante Name of conf variable to get * @return array|mixed Data without useless information * + * @url GET conf/{constante} + * * @throws RestException 403 Forbidden - * @throws RestException 500 Error Bad or unknown value for constname + * @throws RestException 500 Error Bad or unknown value for constname */ - public function getConf($confname) + public function getConf($constante) { global $conf; @@ -1426,14 +1426,14 @@ class Setup extends DolibarrApi throw new RestException(403, 'Error API open to admin users only or to the login user defined with constant API_LOGIN_ALLOWED_FOR_ADMIN_CHECK'); } - if (! preg_match('/^[a-zA-Z0-9_]+$/', $confname) || ! isset($conf->global->$confname)) { + if (! preg_match('/^[a-zA-Z0-9_]+$/', $constante) || ! isset($conf->global->$constante)) { throw new RestException(500, 'Error Bad or unknown value for constname'); } - if (preg_match('/(_pass|password|secret|_key|key$)/i', $confname)) { + if (preg_match('/(_pass|password|secret|_key|key$)/i', $constante)) { throw new RestException(403, 'Forbidden'); } - return $conf->global->$confname; + return $conf->global->$constante; } /** From 1827541f88dab73951f49371d0f4c19d8a0205fa Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 5 Apr 2020 12:04:25 +0000 Subject: [PATCH 2/3] Fixing style errors. --- htdocs/api/class/api_setup.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 05d9214389f..d6ee0f1a79e 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -1413,7 +1413,7 @@ class Setup extends DolibarrApi * @return array|mixed Data without useless information * * @url GET conf/{constante} - * + * * @throws RestException 403 Forbidden * @throws RestException 500 Error Bad or unknown value for constname */ From 26bc5381e47e2757d4bae54a977c301813216f5c Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 8 Apr 2020 14:57:34 +0200 Subject: [PATCH 3/3] Update api_setup.class.php --- htdocs/api/class/api_setup.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index d6ee0f1a79e..5f867c066c7 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -1409,15 +1409,15 @@ class Setup extends DolibarrApi * * Note that conf variables that stores security key or password hashes can't be loaded with API. * - * @param string $constante Name of conf variable to get + * @param string $constantname Name of conf variable to get * @return array|mixed Data without useless information * - * @url GET conf/{constante} + * @url GET conf/{constantname} * * @throws RestException 403 Forbidden * @throws RestException 500 Error Bad or unknown value for constname */ - public function getConf($constante) + public function getConf($constantname) { global $conf; @@ -1426,14 +1426,14 @@ class Setup extends DolibarrApi throw new RestException(403, 'Error API open to admin users only or to the login user defined with constant API_LOGIN_ALLOWED_FOR_ADMIN_CHECK'); } - if (! preg_match('/^[a-zA-Z0-9_]+$/', $constante) || ! isset($conf->global->$constante)) { + if (! preg_match('/^[a-zA-Z0-9_]+$/', $constantname) || ! isset($conf->global->$constantname)) { throw new RestException(500, 'Error Bad or unknown value for constname'); } - if (preg_match('/(_pass|password|secret|_key|key$)/i', $constante)) { + if (preg_match('/(_pass|password|secret|_key|key$)/i', $constantname)) { throw new RestException(403, 'Forbidden'); } - return $conf->global->$constante; + return $conf->global->$constantname; } /**