From: Marcin Haba Date: Sat, 3 Aug 2019 06:03:09 +0000 (+0200) Subject: baculum: Split API panel, oauth, api and page parts into separate services X-Git-Tag: Release-9.6.0~160 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2aff2232f3f1835d5482b6e3623c75c6b681ec04;p=thirdparty%2Fbacula.git baculum: Split API panel, oauth, api and page parts into separate services --- diff --git a/gui/baculum/examples/deb-template/baculum-api-apache.conf b/gui/baculum/examples/deb-template/baculum-api-apache.conf index 73277c1aa..17b96939f 100644 --- a/gui/baculum/examples/deb-template/baculum-api-apache.conf +++ b/gui/baculum/examples/deb-template/baculum-api-apache.conf @@ -15,10 +15,15 @@ Listen 9096 Options +FollowSymLinks RewriteEngine On + + RewriteCond %{REQUEST_URI} ^/index\.php$ [OR] + RewriteCond %{REQUEST_URI} ^/$ + RewriteRule ^(.+)$ /panel? [L] + RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ index.php/$1 [L] - RedirectMatch ^/$ /api/?api + # Apache 2.2 Order Allow,Deny @@ -34,12 +39,12 @@ Listen 9096 # From: # ...section body... # - # To: + # To: # ...section body... # # - # + # AuthType Basic AuthName "Baculum Auth" AuthUserFile %DOCUMENTROOT/protected/API/Config/baculum.users diff --git a/gui/baculum/examples/deb-template/baculum-api-lighttpd.conf b/gui/baculum/examples/deb-template/baculum-api-lighttpd.conf index 0dede50ce..9887a634d 100644 --- a/gui/baculum/examples/deb-template/baculum-api-lighttpd.conf +++ b/gui/baculum/examples/deb-template/baculum-api-lighttpd.conf @@ -32,7 +32,7 @@ server.modules = ( # # Uncomment this line and closing braces below when you use OAuth2 # -# $HTTP["url"] =~ "^/web/page/.*$" { +#$HTTP["url"] =~ "^/panel.*$" { auth.backend = "htpasswd" auth.backend.htpasswd.userfile = "%DOCUMENTROOT/protected/API/Config/baculum.users" auth.require = ( "/" => ( @@ -41,7 +41,7 @@ server.modules = ( "require" => "valid-user" ) ) -# } +#} index-file.names = ( "index.php" ) @@ -85,7 +85,7 @@ fastcgi.server = ( url.rewrite-once = ( "^/themes/(.+)$" => "/themes/$1", "^/assets/(.+)$" => "/assets/$1", - "^/$" => "/index.php/api/page/home/", + "^/((index\.php)?\?.+)?$" => "/index.php/panel/", "^/(.+)$" => "/index.php/$1" ) diff --git a/gui/baculum/examples/deb/baculum-api-apache.conf b/gui/baculum/examples/deb/baculum-api-apache.conf index f84e3753e..8b14fd345 100644 --- a/gui/baculum/examples/deb/baculum-api-apache.conf +++ b/gui/baculum/examples/deb/baculum-api-apache.conf @@ -15,10 +15,15 @@ Listen 9096 Options +FollowSymLinks RewriteEngine On + + RewriteCond %{REQUEST_URI} ^/index\.php$ [OR] + RewriteCond %{REQUEST_URI} ^/$ + RewriteRule ^(.+)$ /panel? [L] + RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ index.php/$1 [L] - RedirectMatch ^/$ /api/?api + # Apache 2.2 Order Allow,Deny @@ -34,12 +39,12 @@ Listen 9096 # From: # ...section body... # - # To: + # To: # ...section body... # # - # + # AuthType Basic AuthName "Baculum Auth" AuthUserFile /usr/share/baculum/htdocs/protected/API/Config/baculum.users diff --git a/gui/baculum/examples/deb/baculum-api-lighttpd.conf b/gui/baculum/examples/deb/baculum-api-lighttpd.conf index a5fb34028..422b42dd6 100644 --- a/gui/baculum/examples/deb/baculum-api-lighttpd.conf +++ b/gui/baculum/examples/deb/baculum-api-lighttpd.conf @@ -32,7 +32,7 @@ server.modules = ( # # Uncomment this line and closing braces below when you use OAuth2 # -# $HTTP["url"] =~ "^/web/page/.*$" { +#$HTTP["url"] =~ "^/panel.*$" { auth.backend = "htpasswd" auth.backend.htpasswd.userfile = "/usr/share/baculum/htdocs/protected/API/Config/baculum.users" auth.require = ( "/" => ( @@ -41,7 +41,7 @@ server.modules = ( "require" => "valid-user" ) ) -# } +#} index-file.names = ( "index.php" ) @@ -85,7 +85,7 @@ fastcgi.server = ( url.rewrite-once = ( "^/themes/(.+)$" => "/themes/$1", "^/assets/(.+)$" => "/assets/$1", - "^/$" => "/index.php/api/page/home/", + "^/((index\.php)?\?.+)?$" => "/index.php/panel/", "^/(.+)$" => "/index.php/$1" ) diff --git a/gui/baculum/examples/rpm-template/baculum-api-apache.conf b/gui/baculum/examples/rpm-template/baculum-api-apache.conf index 73277c1aa..17b96939f 100644 --- a/gui/baculum/examples/rpm-template/baculum-api-apache.conf +++ b/gui/baculum/examples/rpm-template/baculum-api-apache.conf @@ -15,10 +15,15 @@ Listen 9096 Options +FollowSymLinks RewriteEngine On + + RewriteCond %{REQUEST_URI} ^/index\.php$ [OR] + RewriteCond %{REQUEST_URI} ^/$ + RewriteRule ^(.+)$ /panel? [L] + RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ index.php/$1 [L] - RedirectMatch ^/$ /api/?api + # Apache 2.2 Order Allow,Deny @@ -34,12 +39,12 @@ Listen 9096 # From: # ...section body... # - # To: + # To: # ...section body... # # - # + # AuthType Basic AuthName "Baculum Auth" AuthUserFile %DOCUMENTROOT/protected/API/Config/baculum.users diff --git a/gui/baculum/examples/rpm-template/baculum-api-lighttpd.conf b/gui/baculum/examples/rpm-template/baculum-api-lighttpd.conf index ef3599214..bbc7c481b 100644 --- a/gui/baculum/examples/rpm-template/baculum-api-lighttpd.conf +++ b/gui/baculum/examples/rpm-template/baculum-api-lighttpd.conf @@ -32,7 +32,7 @@ server.modules = ( # # Uncomment this line and closing braces below when you use OAuth2 # -# $HTTP["url"] =~ "^/web/page/.*$" { +#$HTTP["url"] =~ "^/panel.*$" { auth.backend = "htpasswd" auth.backend.htpasswd.userfile = "%DOCUMENTROOT/protected/API/Config/baculum.users" auth.require = ( "/" => ( @@ -41,7 +41,7 @@ server.modules = ( "require" => "valid-user" ) ) -# } +#} index-file.names = ( "index.php" ) @@ -85,7 +85,7 @@ fastcgi.server = ( url.rewrite-once = ( "^/themes/(.+)$" => "/themes/$1", "^/assets/(.+)$" => "/assets/$1", - "^/$" => "/index.php/api/page/home/", + "^/((index\.php)?\?.+)?$" => "/index.php/panel/", "^/(.+)$" => "/index.php/$1" ) diff --git a/gui/baculum/examples/rpm/baculum-api-apache.conf b/gui/baculum/examples/rpm/baculum-api-apache.conf index 64a13e37b..65e3fb81b 100644 --- a/gui/baculum/examples/rpm/baculum-api-apache.conf +++ b/gui/baculum/examples/rpm/baculum-api-apache.conf @@ -15,10 +15,15 @@ Listen 9096 Options +FollowSymLinks RewriteEngine On + + RewriteCond %{REQUEST_URI} ^/index\.php$ [OR] + RewriteCond %{REQUEST_URI} ^/$ + RewriteRule ^(.+)$ /panel? [L] + RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ index.php/$1 [L] - RedirectMatch ^/$ /api/?api + # Apache 2.2 Order Allow,Deny @@ -34,12 +39,12 @@ Listen 9096 # From: # ...section body... # - # To: + # To: # ...section body... # # - # + # AuthType Basic AuthName "Baculum Auth" AuthUserFile /usr/share/baculum/htdocs/protected/API/Config/baculum.users diff --git a/gui/baculum/examples/rpm/baculum-api-lighttpd.conf b/gui/baculum/examples/rpm/baculum-api-lighttpd.conf index fe19b62ab..4c0a56f85 100644 --- a/gui/baculum/examples/rpm/baculum-api-lighttpd.conf +++ b/gui/baculum/examples/rpm/baculum-api-lighttpd.conf @@ -32,7 +32,7 @@ server.modules = ( # # Uncomment this line and closing braces below when you use OAuth2 # -# $HTTP["url"] =~ "^/web/page/.*$" { +#$HTTP["url"] =~ "^/panel.*$" { auth.backend = "htpasswd" auth.backend.htpasswd.userfile = "/usr/share/baculum/htdocs/protected/API/Config/baculum.users" auth.require = ( "/" => ( @@ -41,7 +41,7 @@ server.modules = ( "require" => "valid-user" ) ) -# } +#} index-file.names = ( "index.php" ) @@ -85,7 +85,7 @@ fastcgi.server = ( url.rewrite-once = ( "^/themes/(.+)$" => "/themes/$1", "^/assets/(.+)$" => "/assets/$1", - "^/$" => "/index.php/api/page/home/", + "^/((index\.php)?\?.+)?$" => "/index.php/panel/", "^/(.+)$" => "/index.php/$1" ) diff --git a/gui/baculum/protected/API/Class/OAuth2/BaculumOAuth2.php b/gui/baculum/protected/API/Class/OAuth2/BaculumOAuth2.php index 7f2b753c2..43c2dfc32 100644 --- a/gui/baculum/protected/API/Class/OAuth2/BaculumOAuth2.php +++ b/gui/baculum/protected/API/Class/OAuth2/BaculumOAuth2.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2017 Kern Sibbald + * Copyright (C) 2013-2019 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -101,6 +101,7 @@ class BaculumOAuth2 extends OAuth2 { $error['state'] = $state; } + header('Content-Type: application/json'); header($header); echo json_encode($error); exit(); diff --git a/gui/baculum/protected/API/Pages/Panel/MainPage.php b/gui/baculum/protected/API/Class/OAuthUrlMapping.php similarity index 58% rename from gui/baculum/protected/API/Pages/Panel/MainPage.php rename to gui/baculum/protected/API/Class/OAuthUrlMapping.php index 8a798b532..80e343fe0 100644 --- a/gui/baculum/protected/API/Pages/Panel/MainPage.php +++ b/gui/baculum/protected/API/Class/OAuthUrlMapping.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2017 Kern Sibbald + * Copyright (C) 2013-2019 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -20,21 +20,15 @@ * Bacula(R) is a registered trademark of Kern Sibbald. */ -Prado::using('Application.API.Class.BaculumAPIPage'); +Prado::using('System.Web.TUrlMapping'); -class MainPage extends BaculumAPIPage { +class OAuthUrlMapping extends TUrlMappingPattern { - public $auth_params; + const SERVICE_ID = 'oauth'; - public function onInit($param) { - parent::onInit($param); - $url = $this->getRequest()->getUrl()->getPath(); - $params = explode('/', $url); - if ($url === '/' || (count($params) === 3 && $params[1] === 'api') || (count($params) >= 3 && $params[2] === 'page')) { - $this->goToPage('Panel.APIHome'); - } else { - $this->goToPage('API.Welcome'); - } + public function __construct(BaculumUrlMapping $manager) { + parent::__construct($manager); + $this->setServiceID(self::SERVICE_ID); } } ?> diff --git a/gui/baculum/protected/API/Class/PanelUrlMapping.php b/gui/baculum/protected/API/Class/PanelUrlMapping.php new file mode 100644 index 000000000..f6c7b8db6 --- /dev/null +++ b/gui/baculum/protected/API/Class/PanelUrlMapping.php @@ -0,0 +1,34 @@ +setServiceID(self::SERVICE_ID); + } +} +?> diff --git a/gui/baculum/protected/API/Pages/config.xml b/gui/baculum/protected/API/Pages/API/config.xml similarity index 77% rename from gui/baculum/protected/API/Pages/config.xml rename to gui/baculum/protected/API/Pages/API/config.xml index 65e2c34a2..25baaf7e8 100644 --- a/gui/baculum/protected/API/Pages/config.xml +++ b/gui/baculum/protected/API/Pages/API/config.xml @@ -1,9 +1,10 @@ - + + @@ -21,20 +22,10 @@ - - - - - - - - - - diff --git a/gui/baculum/protected/API/Pages/API/endpoints.xml b/gui/baculum/protected/API/Pages/API/endpoints.xml new file mode 100644 index 000000000..a58c4b4eb --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/endpoints.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gui/baculum/protected/API/Pages/OAuth2/config.xml b/gui/baculum/protected/API/Pages/OAuth2/config.xml new file mode 100644 index 000000000..7351d9e0a --- /dev/null +++ b/gui/baculum/protected/API/Pages/OAuth2/config.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/gui/baculum/protected/API/Pages/OAuth2/endpoints.xml b/gui/baculum/protected/API/Pages/OAuth2/endpoints.xml new file mode 100644 index 000000000..a207467c3 --- /dev/null +++ b/gui/baculum/protected/API/Pages/OAuth2/endpoints.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/gui/baculum/protected/API/Pages/Panel/APIHome.page b/gui/baculum/protected/API/Pages/Panel/APIHome.page index 258422712..18f96728b 100644 --- a/gui/baculum/protected/API/Pages/Panel/APIHome.page +++ b/gui/baculum/protected/API/Pages/Panel/APIHome.page @@ -1,7 +1,7 @@ <%@ MasterClass="Application.API.Layouts.Main" Theme="Baculum-v1"%> /> -

<%[ Welcome on the Baculum API default page ]%>

+

<%[ Welcome on the Baculum API default page ]%>

  • <%[ Baculum API Client ]%>
  • @@ -305,7 +305,7 @@ return; } this.set_progress(1, 'Sending auth code request...'); - var authorization_uri = document.location.origin + '/api/auth'; + var authorization_uri = document.location.origin + '/oauth/authorize'; var auth_params = { response_type: 'code', client_id: this.baculum_auth.client_id, @@ -329,7 +329,7 @@ }, send_token_request: function(code) { this.set_progress(2, 'Sending token request...'); - var uri = document.location.origin + '/api/token'; + var uri = document.location.origin + '/oauth/token'; var auth_params = { grant_type: 'authorization_code', code: code, diff --git a/gui/baculum/protected/API/Pages/Panel/config.xml b/gui/baculum/protected/API/Pages/Panel/config.xml new file mode 100644 index 000000000..399a78e79 --- /dev/null +++ b/gui/baculum/protected/API/Pages/Panel/config.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gui/baculum/protected/API/Pages/Panel/endpoints.xml b/gui/baculum/protected/API/Pages/Panel/endpoints.xml new file mode 100644 index 000000000..d4b74bc33 --- /dev/null +++ b/gui/baculum/protected/API/Pages/Panel/endpoints.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/gui/baculum/protected/API/endpoints.xml b/gui/baculum/protected/API/endpoints.xml deleted file mode 100644 index d1cc5721b..000000000 --- a/gui/baculum/protected/API/endpoints.xml +++ /dev/null @@ -1,194 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/gui/baculum/protected/Common/Class/BaculumUrlMapping.php b/gui/baculum/protected/Common/Class/BaculumUrlMapping.php index cab9b8278..6b7db0392 100644 --- a/gui/baculum/protected/Common/Class/BaculumUrlMapping.php +++ b/gui/baculum/protected/Common/Class/BaculumUrlMapping.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2019 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -33,7 +33,17 @@ class BaculumUrlMapping extends TUrlMapping { 'api' => array( 'url_manager' => 'Application.API.Class.APIUrlMapping', 'url_pattern' => '!^(/index\.php)?/api([/,].*)?$!', - 'endpoints' => 'Application.API.endpoints' + 'endpoints' => 'Application.API.Pages.API.endpoints' + ), + 'oauth' => array( + 'url_manager' => 'Application.API.Class.OAuthUrlMapping', + 'url_pattern' => '!^(/index\.php)?/oauth([/,].*)?$!', + 'endpoints' => 'Application.API.Pages.OAuth2.endpoints' + ), + 'panel' => array( + 'url_manager' => 'Application.API.Class.PanelUrlMapping', + 'url_pattern' => '!^(/index\.php)?/panel([/,].*)?$!', + 'endpoints' => 'Application.API.Pages.Panel.endpoints' ) ); diff --git a/gui/baculum/protected/Common/Pages/CommonPage.php b/gui/baculum/protected/Common/Pages/CommonPage.php new file mode 100644 index 000000000..5dda41767 --- /dev/null +++ b/gui/baculum/protected/Common/Pages/CommonPage.php @@ -0,0 +1,27 @@ + diff --git a/gui/baculum/protected/Web/Class/BaculumAPIClient.php b/gui/baculum/protected/Web/Class/BaculumAPIClient.php index 1721c08a5..7d2496140 100644 --- a/gui/baculum/protected/Web/Class/BaculumAPIClient.php +++ b/gui/baculum/protected/Web/Class/BaculumAPIClient.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2018 Kern Sibbald + * Copyright (C) 2013-2019 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -50,8 +50,8 @@ class BaculumAPIClient extends WebModule { /** * OAuth2 authorization endpoints */ - const OAUTH2_AUTH_URL = 'api/auth/'; - const OAUTH2_TOKEN_URL = 'api/token/'; + const OAUTH2_AUTH_URL = 'oauth/authorize/'; + const OAUTH2_TOKEN_URL = 'oauth/token/'; /** * API server version for current request. diff --git a/gui/baculum/protected/application.xml b/gui/baculum/protected/application.xml index 4cbdc09f6..86d5351a0 100644 --- a/gui/baculum/protected/application.xml +++ b/gui/baculum/protected/application.xml @@ -17,7 +17,10 @@ - + + + +