From fa6ce598ecbfff25c1100c56525a31f618406ec2 Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Wed, 23 Mar 2011 12:14:36 +0100 Subject: [PATCH] bacula-web: Major change with bacula-web configuration - Renammed bacula.conf to config.php - bacula-web configuration file is now a php script (more simple) - BW_Config php class was adapted regarding this change - Multi catalog support has been improved in bweb php classe --- gui/bacula-web/classes/bweb.inc.php | 4 +- gui/bacula-web/classes/cfg/config.classe.php | 19 +++--- gui/bacula-web/config.inc.php | 3 +- gui/bacula-web/config/bacula.conf | 28 -------- gui/bacula-web/config/config.php | 69 ++++++++++++++++++++ gui/bacula-web/index.php | 2 +- 6 files changed, 85 insertions(+), 40 deletions(-) delete mode 100644 gui/bacula-web/config/bacula.conf create mode 100644 gui/bacula-web/config/config.php diff --git a/gui/bacula-web/classes/bweb.inc.php b/gui/bacula-web/classes/bweb.inc.php index cd8f80c3a2..482fc66940 100644 --- a/gui/bacula-web/classes/bweb.inc.php +++ b/gui/bacula-web/classes/bweb.inc.php @@ -42,12 +42,12 @@ class Bweb extends DB { else $this->bwcfg->Load_Config(); - // Select which catalog to connect + // Select which catalog to connect to if( isset( $_POST['catalog_id'] ) ) $dsn = $this->bwcfg->Get_Dsn( $_POST['catalog_id'] ); else $dsn = $this->bwcfg->Get_Dsn( 0 ); - + // Connect to the database $this->db_link = $this->connect( $dsn ); diff --git a/gui/bacula-web/classes/cfg/config.classe.php b/gui/bacula-web/classes/cfg/config.classe.php index 217d7619a2..6a500c9e98 100644 --- a/gui/bacula-web/classes/cfg/config.classe.php +++ b/gui/bacula-web/classes/cfg/config.classe.php @@ -2,12 +2,14 @@ class BW_Config { + private $config_params; private $config; private $catalogs = array(); function __construct() { - + global $config; + $this->config = $config; } public function Check_Config_file() @@ -18,24 +20,25 @@ public function Load_Config() { - $this->config = parse_ini_file( CONFIG_FILE, true ); + global $config; - if( !$this->config == false ) { + if( is_array($config) && !empty($config) ) { // Loading database connection information - foreach( $this->config as $parameter => $value ) + foreach( $config as $parameter => $value ) { if( is_array($value) ) // Parsing database section array_push( $this->catalogs, $value ); } return true; - }else + }else { return false; + } } public function Get_Config_Param( $param ) { - if( isset( $this->config[$param] ) ) - return $this->config[$param]; + if( isset( $config[$param] ) ) + return $config[$param]; } public function Count_Catalogs() @@ -49,7 +52,7 @@ $dsn = array(); $dsn['hostspec'] = $this->catalogs[$catalog_id]["host"]; $dsn['username'] = $this->catalogs[$catalog_id]["login"]; - $dsn['password'] = $this->catalogs[$catalog_id]["pass"]; + $dsn['password'] = $this->catalogs[$catalog_id]["password"]; $dsn['database'] = $this->catalogs[$catalog_id]["db_name"]; $dsn['phptype'] = $this->catalogs[$catalog_id]["db_type"]; return $dsn; diff --git a/gui/bacula-web/config.inc.php b/gui/bacula-web/config.inc.php index 3bf2354924..2035808a94 100644 --- a/gui/bacula-web/config.inc.php +++ b/gui/bacula-web/config.inc.php @@ -20,7 +20,8 @@ // Global constants define('CONFIG_DIR', BW_ROOT . "/config/"); - define('CONFIG_FILE', CONFIG_DIR . "bacula.conf"); + define('CONFIG_FILE', CONFIG_DIR . "config.php"); + require_once( CONFIG_FILE ); // Time intervals in secondes define( 'LAST_DAY', 86400 ); diff --git a/gui/bacula-web/config/bacula.conf b/gui/bacula-web/config/bacula.conf deleted file mode 100644 index 2111e25e64..0000000000 --- a/gui/bacula-web/config/bacula.conf +++ /dev/null @@ -1,28 +0,0 @@ -; Language -; en_EN -> English -; es_ES -> Spanish, Mantained by Juan Luis Francés Jiménez. -; it_IT -> Italian, Mantained by Gian Domenico Messina (gianni.messina AT c-ict.it). -; fr_FR -> Frech, Mantained by Morgan LEFIEUX (comete AT daknet.org). -; de_DE -> German, Mantained by Florian Heigl. -lang = en_EN - -; Database connection configuration - -[.DATABASE] -host = localhost ; Database host or IP -login = root ; Database account name -pass = p@ssw0rd ; Database account password -db_name = bacula ; Database name -db_type = mysql ; Database type -;db_port = 3306 ; Uncomment if not standard port - -; Multi-Catalog support -; If you want to configure more than 1 Bacula catalog in Bacula-Web, simply copy the previous line (See example below) -; Don't forget the change the name of the section (DATABASE2 in this case) - -;[.DATABASE2] -;host = 192.168.2.55 -;login = bacula -;pass = -;db_name = bacula -;db_type = mysql diff --git a/gui/bacula-web/config/config.php b/gui/bacula-web/config/config.php new file mode 100644 index 0000000000..521bbcb6ba --- /dev/null +++ b/gui/bacula-web/config/config.php @@ -0,0 +1,69 @@ + English + es_ES -> Spanish, Mantained by Juan Luis Francés Jiménez. + it_IT -> Italian, Mantained by Gian Domenico Messina (gianni.messina AT c-ict.it). + fr_FR -> Frech, Mantained by Morgan LEFIEUX (comete AT daknet.org). + de_DE -> German, Mantained by Florian Heigl. + */ + + $config['language'] = 'en_EN'; + + //MySQL bacula catalog + $config[0]['label'] = 'Backup Server'; + $config[0]['host'] = 'localhost'; + $config[0]['login'] = 'root'; + $config[0]['password'] = 'p@ssw0rd'; + $config[0]['db_name'] = 'bacula'; + $config[0]['db_type'] = 'mysql'; + $config[0]['db_port'] = '3306'; + + //MySQL bacula catalog + $config[1]['label'] = 'Backup Server'; + $config[1]['host'] = 'localhost'; + $config[1]['login'] = 'bacula'; + $config[1]['password'] = 'bacula'; + $config[1]['db_name'] = 'bacula'; + $config[1]['db_type'] = 'pgsql'; + $config[1]['db_port'] = '5432'; + + /* Catalog(s) connection parameters + Just copy/paste and modify regarding your configuration + + Example: + + //MySQL bacula catalog + $config[0]['label'] = 'Backup Server'; + $config[0]['host'] = 'localhost'; + $config[0]['login'] = 'bacula'; + $config[0]['password'] = 'verystrongpassword'; + $config[0]['db_name'] = 'bacula'; + $config[0]['db_type'] = 'mysql'; + $config[0]['db_port'] = '3306'; + + // PostgreSQL bacula catalog + $config[0]['label'] = 'Prod Server'; + $config[0]['host'] = 'db-server.domain.com'; + $config[0]['login'] = 'bacula'; + $config[0]['password'] = 'otherstrongpassword'; + $config[0]['db_name'] = 'bacula'; + $config[0]['db_type'] = 'pgsql'; + $config[0]['db_port'] = '5432'; + + // SQLite bacula catalog + $config[0]['label'] = 'Dev backup server'; + $config[0]['db_path'] = '/path/to/database/db.sdb'; + + If you want to configure more than one catalog in Bacula-Web, just copy the first parameters and increment by one the index + + //MySQL bacula catalog + $config[1]['label'] = 'Dev backup server'; + $config[1]['host'] = 'mysql-server.domain.net'; + $config[1]['login'] = 'bacula'; + $config[1]['password'] = 'verystrongpassword'; + $config[1]['db_name'] = 'bacula'; + $config[1]['db_type'] = 'mysql'; + $config[1]['db_port'] = '3306'; + */ +?> diff --git a/gui/bacula-web/index.php b/gui/bacula-web/index.php index 806bc17183..0b51e2c5c3 100644 --- a/gui/bacula-web/index.php +++ b/gui/bacula-web/index.php @@ -22,7 +22,7 @@ $dbSql = new Bweb(); $mode = ""; // Assign to template catalogs number -// $dbSql->tpl->assign( "dbs", $dbSql->Get_Nb_Catalogs() ); +//$dbSql->tpl->assign( "dbs", $dbSql->bwcfg->Count_Catalogs() ); // Assign dbs /* if ( count($dbSql->dbs) >1 ) { -- 2.39.5