]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Improve checking dependencies
authorMarcin Haba <marcin.haba@bacula.pl>
Mon, 12 Aug 2019 04:32:11 +0000 (06:32 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 14 Dec 2019 14:55:58 +0000 (15:55 +0100)
 - Add dependencies checking to API
 - Remove PHP Multibyte String (mbstring) extension from dependencies
 - Prepare general class to check common API and Web dependencies

gui/baculum/examples/rpm-template/baculum.spec
gui/baculum/examples/rpm/baculum.spec
gui/baculum/protected/API/Class/BaculumAPIPage.php
gui/baculum/protected/API/Pages/Requirements.php [new file with mode: 0644]
gui/baculum/protected/Common/Class/GeneralRequirements.php [new file with mode: 0644]
gui/baculum/protected/Web/Class/BaculumWebPage.php
gui/baculum/protected/Web/Init.php
gui/baculum/protected/Web/Pages/Requirements.php

index d1ad17f72e0d5d8327f48663c667ac023ef9c262..8f90ac6bc15bbd95709316bf2cc761e06b4557e8 100644 (file)
@@ -20,7 +20,6 @@ BuildRequires:        checkpolicy
 Requires:      php >= 5.3.4
 Requires:      php-bcmath
 Requires:      php-common
-Requires:      php-mbstring
 Requires:      php-mysqlnd
 Requires:      php-pdo
 Requires:      php-pgsql
@@ -69,7 +68,6 @@ Requires:             php >= 5.3.4
 Requires:              php-common
 Requires:              php-json
 Requires:              php-bcmath
-Requires:              php-mbstring
 Requires:              php-xml
 
 %description web
index d1ad17f72e0d5d8327f48663c667ac023ef9c262..8f90ac6bc15bbd95709316bf2cc761e06b4557e8 100644 (file)
@@ -20,7 +20,6 @@ BuildRequires:        checkpolicy
 Requires:      php >= 5.3.4
 Requires:      php-bcmath
 Requires:      php-common
-Requires:      php-mbstring
 Requires:      php-mysqlnd
 Requires:      php-pdo
 Requires:      php-pgsql
@@ -69,7 +68,6 @@ Requires:             php >= 5.3.4
 Requires:              php-common
 Requires:              php-json
 Requires:              php-bcmath
-Requires:              php-mbstring
 Requires:              php-xml
 
 %description web
index 00ec70655e5f12a123ad68220a08ee87a71208d1..3cf84f466f38edf1110f0cf8666e85453239b271 100644 (file)
@@ -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
@@ -22,6 +22,7 @@
 
 session_start();
 
+Prado::using('Application.API.Pages.Requirements');
 Prado::using('Application.Common.Class.BaculumPage');
 Prado::using('Application.API.Class.APIConfig');
  
diff --git a/gui/baculum/protected/API/Pages/Requirements.php b/gui/baculum/protected/API/Pages/Requirements.php
new file mode 100644 (file)
index 0000000..5b399a1
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2019 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+Prado::using('Application.Common.Class.GeneralRequirements');
+
+/**
+ * API part requirements class.
+ */
+class Requirements extends GeneralRequirements {
+
+       /**
+        * Required PHP extensions.
+        *
+        * Note, requirements page is visible before any language is set and before
+        * translation engine initialization. From this reason all messages are not
+        * translated.
+        */
+       private $req_exts = array(
+               array(
+                       'ext' => 'bcmath',
+                       'help_msg' => 'Please install <b>PHP BCMath module</b>.'
+               )
+       );
+
+       public function __construct($app_dir, $base_dir) {
+               parent::__construct($app_dir, $base_dir);
+               $this->validateEnvironment();
+               parent::showResult('Baculum API');
+       }
+
+       /**
+        * Validate all API environment depenencies.
+        *
+        * @return none
+        */
+       public function validateEnvironment() {
+               parent::validateExtensions($this->req_exts);
+       }
+}
+$service_dir = dirname(__DIR__);
+new Requirements(APPLICATION_DIRECTORY, $service_dir);
+?>
diff --git a/gui/baculum/protected/Common/Class/GeneralRequirements.php b/gui/baculum/protected/Common/Class/GeneralRequirements.php
new file mode 100644 (file)
index 0000000..78ee2a1
--- /dev/null
@@ -0,0 +1,146 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2019 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+/**
+ * General requirement class with common dependencies both for API and Web.
+ */
+abstract class GeneralRequirements {
+
+       /**
+        * Required PHP extensions.
+        *
+        * Note, requirements page is visible before any language is set and before
+        * translation engine initialization. From this reason all messages are not
+        * translated.
+        */
+       private $req_exts = array(
+               array(
+                       'ext' => 'json',
+                       'help_msg' => 'Please install <b>PHP JSON module</b>.'
+               ),
+               array(
+                       'ext' => 'dom',
+                       'help_msg' => 'Please install <b>PHP DOM module</b> to support XML documents (usually included in php-xml binary package).'
+               )
+       );
+
+       /**
+        * Required read/write access for these application directories.
+        */
+       private $req_app_rw_dirs = array(
+               'assets', 'protected/runtime',
+       );
+
+       /**
+        * Required read/wrie access for these directories in base directory.
+        */
+       private $req_base_rw_dirs = array(
+               'Config', 'Logs',
+       );
+
+       /**
+        * Generic help message for directories without fulfilled dependencies.
+        */
+       const DIR_HELP_MSG = 'Please make readable and writeable by the web server user the following directory: <b>%s</b>';
+
+       /**
+        * This static variable stores all dependency messages to show on the page.
+        * If empty, dependencies are fulfilled.
+        */
+       protected static $requirements = array();
+
+       public function __construct($app_dir, $base_dir) {
+               $this->validateEnvironment($app_dir, $base_dir);
+       }
+
+       /**
+        * Validate all environment depenencies.
+        *
+        * @param string $app_dir full path to main application directory
+        * @param string $base_dir full path to service specific base directory
+        * @return none
+        */
+       private function validateEnvironment($app_dir, $base_dir) {
+               $this->validateDirectories($app_dir, $base_dir);
+               $this->validateExtensions($this->req_exts);
+       }
+
+       /**
+        * Validate directory access depenencies.
+        *
+        * @param string $app_dir full path to main application directory
+        * @param string $base_dir full path to service specific base directory
+        * @return none
+        */
+       private function validateDirectories($app_dir, $base_dir) {
+               for ($i = 0; $i < count($this->req_app_rw_dirs); $i++) {
+                       $dir = $app_dir . '/' . $this->req_app_rw_dirs[$i];
+                       if (is_readable($dir) && is_writeable($dir)) {
+                               // test passed, skip
+                               continue;
+                       }
+                       self::$requirements[] = sprintf(self::DIR_HELP_MSG, $dir);
+               }
+               for ($i = 0; $i < count($this->req_base_rw_dirs); $i++) {
+                       $dir = $base_dir . '/' . $this->req_base_rw_dirs[$i];
+                       if (is_readable($dir) && is_writeable($dir)) {
+                               // test passed, skip
+                               continue;
+                       }
+                       self::$requirements[] = sprintf(self::DIR_HELP_MSG, $dir);
+               }
+       }
+
+       /**
+        * Validate PHP extensions.
+        *
+        * @param array $req_exts extension list
+        * @return none
+        */
+       protected static function validateExtensions($req_exts) {
+               for ($i = 0; $i < count($req_exts); $i++) {
+                       if (!extension_loaded($req_exts[$i]['ext'])) {
+                               self::$requirements[] = $req_exts[$i]['help_msg'];
+                       }
+               }
+       }
+
+       /**
+        * Simple method to show results.
+        *
+        * @param string $product product name ('Baculum Web' or 'Baculum API'...etc.)
+        * @return none
+        */
+       protected static function showResult($product) {
+               if (count(self::$requirements) > 0) {
+                       echo '<html><body><h2>' . $product . ' - Missing dependencies</h2><ul>';
+                       for ($i = 0; $i < count(self::$requirements); $i++) {
+                               echo '<li>' . self::$requirements[$i] . '</li>';
+                       }
+                       echo '</ul>';
+                       echo 'To run ' . $product . ' <u>please correct above requirements</u> and refresh this page in web browser.';
+                       echo '</body></html>';
+                       exit();
+               }
+       }
+}
+?>
index b461c64889f5846e67df6a832899be3ef4185b84..371abecc9216c10e6a8386dc715dded118623a46 100644 (file)
@@ -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
@@ -22,6 +22,7 @@
 
 session_start();
 
+Prado::using('Application.Web.Pages.Requirements');
 Prado::using('Application.Common.Class.BaculumPage');
 Prado::using('Application.Web.Init');
 Prado::using('Application.Web.Class.WebConfig');
index 54139122cb8a85ffe8385d0fe6d0f59083c10da9..94271cdbc907315383fe933d808aca953b958e9e 100644 (file)
@@ -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
@@ -40,10 +40,4 @@ if (!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW']) && isse
        // initialize required auth superglobal $_SERVER array
        list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', $decoded_credentials);
 }
-
-// Check requirements and if are some needed then show requirements page
-require_once('Pages/Requirements.php');
-$service_dir = __DIR__;
-new Requirements(APPLICATION_DIRECTORY, $service_dir);
-
 ?>
index ec1ecfd4ad06fc29c48455a9440a61d759082d9b..0befa5c3c0b94758207999a6be229ae3afd4ea7a 100644 (file)
@@ -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
  *
  * Bacula(R) is a registered trademark of Kern Sibbald.
  */
-class Requirements {
-       const ASSETS_DIR = 'assets';
-       const CONFIG_DIR = 'Config';
-       const LOG_DIR = 'Logs';
-       const RUNTIME_DIR = 'protected/runtime';
 
-       public function __construct($app_dir, $base_dir) {
-               $app_dir .= '/';
-               $base_dir .= '/';
-               $this->validateEnvironment($app_dir, $base_dir);
-       }
-
-       private function validateEnvironment($app_dir, $base_dir) {
-               $requirements = array();
-               $assets_dir = $app_dir . self::ASSETS_DIR;
-               if(!is_writable(self::ASSETS_DIR)) {
-                       $requirements[] = 'Please make writable by the web server next directory: <b>' . $assets_dir . '</b>';
-               }
-
-               $config_dir = $base_dir . self::CONFIG_DIR;
-               if(!is_writable($config_dir)) {
-                       $requirements[] = 'Please make writable by the web server next directory: <b>' . $config_dir . '</b>';
-               }
-
-               $log_dir = $base_dir . self::LOG_DIR;
-               if(!is_writable($log_dir)) {
-                       $requirements[] = 'Please make writable by the web server next directory: <b>' . $log_dir . '</b>';
-               }
-
-               $runtime_dir = $app_dir . self::RUNTIME_DIR;
-               if(!is_writable($runtime_dir)) {
-                       $requirements[] = 'Please make writable by the web server next directory: <b>' . $runtime_dir . '</b>';
-               }
-
-               if(!function_exists('curl_init') || !function_exists('curl_setopt') || !function_exists('curl_exec') || !function_exists('curl_close')) {
-                       $requirements[] = 'Please install <b>cURL PHP module</b>.';
-               }
+Prado::using('Application.Common.Class.GeneralRequirements');
 
-               if(!function_exists('bcmul') || !function_exists('bcpow')) {
-                       $requirements[] = 'Please install <b>BCMath PHP module</b>.';
-               }
-
-               if(!function_exists('mb_strlen')) {
-                       $requirements[] = 'Please install <b>MB String PHP module</b> for support for multi-byte string handling to PHP.';
-               }
-
-               if(!function_exists('json_decode')) {
-                       $requirements[] = 'Please install <b>Module for JSON functions in PHP scripts</b>.';
-               }
+/**
+ * Web part requirements class.
+ */
+class Requirements extends GeneralRequirements {
+
+       /**
+        * Required PHP extensions.
+        *
+        * Note, requirements page is visible before any language is set and before
+        * translation engine initialization. From this reason all messages are not
+        * translated.
+        */
+       private $req_exts = array(
+               array(
+                       'ext' => 'curl',
+                       'help_msg' => 'Please install <b>PHP cURL module</b>.'
+               )
+       );
 
-               if(!class_exists('DOMDocument')) {
-                       $requirements[] = 'Please install <b>PHP DOM XML</b> to support XML documents (usually included in php-xml binary package).';
-               }
+       public function __construct($app_dir, $base_dir) {
+               parent::__construct($app_dir, $base_dir);
+               $this->validateEnvironment();
+               parent::showResult('Baculum Web');
+       }
 
-               if(count($requirements) > 0) {
-                       echo '<html><body><h2>Baculum - Missing dependencies</h2><ul>';
-                       for($i = 0; $i < count($requirements); $i++) {
-                               echo '<li>' . $requirements[$i] . '</li>';
-                               
-                       }
-                       echo '</ul>';
-                       echo 'To run Baculum <u>please correct above requirements</u> and refresh this page in web browser.';
-                       echo '</body></html>';
-                       exit();
-               }
+       /**
+        * Validate all Web environment depenencies.
+        *
+        * @return none
+        */
+       public function validateEnvironment() {
+               parent::validateExtensions($this->req_exts);
        }
 }
+
+// Check requirements and if are some needed then show requirements page
+$service_dir = dirname(__DIR__);
+new Requirements(APPLICATION_DIRECTORY, $service_dir);
 ?>