2009-03-05 13:52:59 +01:00
< ? php
2009-06-08 20:26:14 +02:00
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
2009-03-05 13:52:59 +01:00
// This program is free software; you can redistribute it and/or
2009-06-08 20:26:14 +02:00
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
2009-03-05 13:52:59 +01:00
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
2009-06-08 20:26:14 +02:00
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2009-03-05 13:52:59 +01:00
// GNU General Public License for more details.
/**
* Creates a single config value in the database .
*
* @ param string Config token to create .
* @ param string Value to set .
*
* @ return bool Config id if success . False on failure .
*/
function create_config_value ( $token , $value ) {
return process_sql_insert ( 'tconfig' ,
array ( 'value' => $value ,
'token' => $token ));
}
/**
* Update a single config value in the database .
*
* If the config token doesn 't exists, it' s created .
*
* @ param string Config token to update .
* @ param string New value to set .
*
* @ return bool True if success . False on failure .
*/
function update_config_value ( $token , $value ) {
global $config ;
if ( ! isset ( $config [ $token ]))
return ( bool ) create_config_value ( $token , $value );
/* If it has not changed */
2009-03-12 10:20:49 +01:00
if ( $config [ $token ] == $value )
2009-03-05 13:52:59 +01:00
return true ;
$config [ $token ] = $value ;
return ( bool ) process_sql_update ( 'tconfig' ,
array ( 'value' => $value ),
array ( 'token' => $token ));
}
/**
2009-04-13 18:13:55 +02:00
* Updates all config values in case setup page was invoked
2009-03-05 13:52:59 +01:00
*/
function update_config () {
global $config ;
/* If user is not even log it, don't try this */
if ( ! isset ( $config [ 'id_user' ]))
return false ;
2009-03-31 16:32:58 +02:00
if ( ! give_acl ( $config [ 'id_user' ], 0 , " PM " ) && ! is_user_admin ( $config [ 'id_user' ]))
2009-03-05 13:52:59 +01:00
return false ;
$update_config = ( bool ) get_parameter ( 'update_config' );
if ( ! $update_config )
2009-04-13 18:13:55 +02:00
return false ;
2009-03-05 13:52:59 +01:00
$style = ( string ) get_parameter ( 'style' , $config [ " style " ]);
2009-04-02 16:31:10 +02:00
if ( $style != $config [ 'style' ])
$style = substr ( $style , 0 , strlen ( $style ) - 4 );
2009-03-05 13:52:59 +01:00
/* Workaround for ugly language and language_code missmatch */
2009-06-22 09:34:49 +02:00
$config [ 'language_code' ] = $config [ 'language' ]; //Old value for comparation into update_config_value because in php use language but in db is language_code
2009-06-18 16:49:25 +02:00
update_config_value ( 'language_code' , ( string ) get_parameter ( 'language' , $config [ " language " ]));
$config [ " language " ] = ( string ) get_parameter ( 'language' , $config [ " language " ]);
2009-03-05 13:52:59 +01:00
update_config_value ( 'remote_config' , ( string ) get_parameter ( 'remote_config' , $config [ " remote_config " ]));
update_config_value ( 'block_size' , ( int ) get_parameter ( 'block_size' , $config [ " block_size " ]));
update_config_value ( 'days_purge' , ( int ) get_parameter ( 'days_purge' , $config [ " days_purge " ]));
update_config_value ( 'days_compact' , ( int ) get_parameter ( 'days_compact' , $config [ " days_compact " ]));
update_config_value ( 'graph_res' , ( int ) get_parameter ( 'graph_res' , $config [ " graph_res " ]));
update_config_value ( 'step_compact' , ( int ) get_parameter ( 'step_compact' , $config [ " step_compact " ]));
update_config_value ( 'style' , $style );
update_config_value ( 'graph_color1' , ( string ) get_parameter ( 'graph_color1' , $config [ " graph_color1 " ]));
update_config_value ( 'graph_color2' , ( string ) get_parameter ( 'graph_color2' , $config [ " graph_color2 " ]));
update_config_value ( 'graph_color3' , ( string ) get_parameter ( 'graph_color3' , $config [ " graph_color3 " ]));
update_config_value ( 'sla_period' , ( int ) get_parameter ( 'sla_period' , $config [ " sla_period " ]));
update_config_value ( 'date_format' , ( string ) get_parameter ( 'date_format' , $config [ " date_format " ]));
2009-04-13 18:13:55 +02:00
update_config_value ( 'trap2agent' , ( string ) get_parameter ( 'trap2agent' , $config [ " trap2agent " ]));
update_config_value ( 'autoupdate' , ( bool ) get_parameter ( 'autoupdate' , $config [ " autoupdate " ]));
2009-03-05 13:52:59 +01:00
update_config_value ( 'prominent_time' , ( string ) get_parameter ( 'prominent_time' , $config [ " prominent_time " ]));
update_config_value ( 'timesource' , ( string ) get_parameter ( 'timesource' , $config [ " timesource " ]));
update_config_value ( 'event_view_hr' , ( int ) get_parameter ( 'event_view_hr' , $config [ " event_view_hr " ]));
update_config_value ( 'loginhash_pwd' , ( string ) get_parameter ( 'loginhash_pwd' , $config [ " loginhash_pwd " ]));
2009-04-13 18:13:55 +02:00
update_config_value ( 'https' , ( bool ) get_parameter ( 'https' , $config [ " https " ]));
update_config_value ( 'compact_header' , ( bool ) get_parameter ( 'compact_header' , $config [ " compact_header " ]));
update_config_value ( 'round_corner' , ( bool ) get_parameter ( 'round_corner' , $config [ " round_corner " ]));
2009-04-06 13:02:05 +02:00
update_config_value ( 'status_images_set' , ( string ) get_parameter ( 'status_images_set' , $config [ " status_images_set " ]));
2009-06-24 19:03:08 +02:00
update_config_value ( 'agentaccess' , ( int ) get_parameter ( 'agentaccess' , $config [ 'agentaccess' ]));
2009-06-30 Ramon Novoa <rnovoa@artica.es>
* nclude/FusionCharts,
include/FusionCharts/FCF_Column3D.swf,
include/FusionCharts/FCF_Pie3D.swf,
include/FusionCharts/FusionCharts.js,
include/FusionCharts/FCF_MSLine.swf,
include/FusionCharts/FusionCharts_Gen.php,
include/FusionCharts/FCF_StackedArea2D.swf,
include/FusionCharts/FCF_Area2D.swf,
include/FusionCharts/FCF_MSArea2D.swf,
include/FusionCharts/FusionCharts.php: Added to repository. Fusion
Charts Free.
* include/functions_fsgraph.php: Added to repository. Fusion Charts
chart generation functions for Pandora FMS.
* include/pchart_graph.php, include/pandora_graph.php,
include/fgraph2.php, include/pChart, include/Image,
include/fgraph.php: Moved from reporting to include.
* operation/agentes/stat_win.php: Moved from reporting to
operation/agentes.
* reporting: Deleted from repository.
* general/logon_ok.php, godmode/setup/setup.php,
godmode/admin_access_logs.php, godmode/db/db_main.php,
godmode/db/db_info.php, godmode/db/db_purge.php,
godmode/reporting/graph_builder.php,
operation/reporting/reporting_xml.php,
operation/reporting/reporting_viewer.php,
operation/servers/view_server.php,
operation/servers/view_server_detail.php,
operation/incidents/incident_statistics.php
operation/users/user_statistics.php,
operation/events/event_statistics.php, operation/events/events.php,
operation/agentes/estado_ultimopaquete.php,
operation/agentes/estado_generalagente.php,
operation/agentes/tactical.php, include/functions_config.php,
include/functions_custom_graphs.php,
include/functions_visual_map.php,
include/functions_reporting.php: Added flash charts.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1779 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-06-30 17:08:14 +02:00
update_config_value ( 'flash_charts' , ( bool ) get_parameter ( 'flash_charts' , $config [ " flash_charts " ]));
2009-03-05 13:52:59 +01:00
}
/**
2009-04-13 18:13:55 +02:00
* Process config variables
2009-03-05 13:52:59 +01:00
*/
function process_config () {
global $config ;
$configs = get_db_all_rows_in_table ( 'tconfig' );
if ( empty ( $configs )) {
exit ( ' <! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >< head >< title > Pandora FMS Error </ title >
< link rel = " stylesheet " href = " ./include/styles/pandora.css " type = " text/css " >
</ head >< body >< div align = " center " >
< div id = " db_f " >
< div >
< a href = " index.php " >< img src = " images/pandora_logo.png " border = " 0 " alt = " logo " /></ a >
</ div >
< div id = " db_ftxt " >
< h1 id = " log_f " class = " error " > Pandora FMS Console Error DB - 002 </ h1 >
Cannot load configuration variables from database . Please check your database setup in the
< b > include / config . php </ b > file or read the documentation on how to setup Pandora FMS .< i >< br />< br />
Most likely your database schema has been created but there are is no data in it , you have a problem with the database access credentials or your schema is out of date .
</ i >< br />
</ div >
</ div ></ body ></ html > ' );
}
/* Compatibility fix */
foreach ( $configs as $c ) {
switch ( $c [ " token " ]) {
case " language_code " :
$config [ 'language' ] = $c [ 'value' ];
break ;
case " auth " :
exit ( ' <! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head >
< title > Pandora FMS Error </ title >
< link rel = " stylesheet " href = " ./include/styles/pandora.css " type = " text/css " >
</ head >
< body >
< div align = " center " >
< div id = " db_f " >
< div >
< a href = " index.php " >< img src = " images/pandora_logo.png " border = " 0 " alt = " logo " /></ a >
</ div >
< div id = " db_ftxt " >
< h1 id = " log_f " class = " error " > Pandora FMS Console Error DB - 003 </ h1 >
Cannot override authorization variables from the config database . Remove them from your database by executing :
DELETE FROM tconfig WHERE token = " auth " ;
< br />
</ div >
</ div ></ body ></ html > ' );
default :
$config [ $c [ 'token' ]] = $c [ 'value' ];
}
}
if ( isset ( $config [ 'homeurl' ]) && $config [ 'homeurl' ][ 0 ] != '/' ) {
$config [ 'homeurl' ] = '/' . $config [ 'homeurl' ];
}
2009-04-13 18:13:55 +02:00
if ( ! isset ( $config [ 'date_format' ])) {
2009-03-05 13:52:59 +01:00
update_config_value ( 'date_format' , 'F j, Y, g:i a' );
}
2009-04-13 18:13:55 +02:00
if ( ! isset ( $config [ 'event_view_hr' ])) {
2009-03-05 13:52:59 +01:00
update_config_value ( 'event_view_hr' , 8 );
}
2009-04-13 18:13:55 +02:00
if ( ! isset ( $config [ 'loginhash_pwd' ])) {
2009-03-05 13:52:59 +01:00
update_config_value ( 'loginhash_pwd' , rand ( 0 , 1000 ) * rand ( 0 , 1000 ) . " pandorahash " );
}
2009-04-13 18:13:55 +02:00
if ( ! isset ( $config [ " trap2agent " ])) {
2009-03-05 13:52:59 +01:00
update_config_value ( 'trap2agent' , 0 );
}
if ( ! isset ( $config [ " sla_period " ]) || empty ( $config [ " sla_period " ])) {
update_config_value ( 'sla_period' , 604800 );
}
if ( ! isset ( $config [ " prominent_time " ])) {
// Prominent time tells us what to show prominently when a timestamp is
// displayed. The comparation (... days ago) or the timestamp (full date)
update_config_value ( 'prominent_time' , 'comparation' );
}
if ( ! isset ( $config [ " timesource " ])) {
// Timesource says where time comes from (system or mysql)
update_config_value ( 'timesource' , 'system' );
}
if ( ! isset ( $config [ " https " ])) {
// Sets whether or not we want to enforce https. We don't want to go to a
// potentially unexisting config by default
update_config_value ( 'https' , false );
}
if ( ! isset ( $config [ " compact_header " ])) {
update_config_value ( 'compact_header' , false );
}
2009-04-06 13:02:05 +02:00
if ( ! isset ( $config [ 'status_images_set' ])) {
update_config_value ( 'status_images_set' , 'default' );
}
2009-03-05 13:52:59 +01:00
if ( isset ( $_SESSION [ 'id_usuario' ]))
$config [ " id_user " ] = $_SESSION [ " id_usuario " ];
2009-03-31 16:32:58 +02:00
if ( ! isset ( $config [ " round_corner " ])) {
update_config_value ( 'round_corner' , false );
}
2009-06-24 19:03:08 +02:00
if ( ! isset ( $config [ " agentaccess " ])){
update_config_value ( 'agentaccess' , true );
}
if ( ! isset ( $config [ " autoupdate " ])){
update_config_value ( 'autoupdate' , true );
}
2009-03-05 13:52:59 +01:00
if ( ! isset ( $config [ " auth " ])) {
2009-03-05 15:34:39 +01:00
require_once ( $config [ " homedir " ] . " /include/auth/mysql.php " );
2009-03-05 13:52:59 +01:00
} else {
2009-03-05 15:34:39 +01:00
require_once ( $config [ " homedir " ] . " /include/auth/ " . $config [ " auth " ][ " scheme " ] . " .php " );
2009-03-05 13:52:59 +01:00
}
2009-04-06 13:02:05 +02:00
// Next is the directory where "/attachment" directory is placed, to upload files stores.
// This MUST be writtable by http server user, and should be in pandora root.
// By default, Pandora adds /attachment to this, so by default is the pandora console home dir
if ( ! isset ( $config [ 'attachment_store' ])) {
update_config_value ( 'attachment_store' , $config [ 'homedir' ] . '/attachment' );
}
if ( ! isset ( $config [ 'fontpath' ])) {
2009-06-30 Ramon Novoa <rnovoa@artica.es>
* nclude/FusionCharts,
include/FusionCharts/FCF_Column3D.swf,
include/FusionCharts/FCF_Pie3D.swf,
include/FusionCharts/FusionCharts.js,
include/FusionCharts/FCF_MSLine.swf,
include/FusionCharts/FusionCharts_Gen.php,
include/FusionCharts/FCF_StackedArea2D.swf,
include/FusionCharts/FCF_Area2D.swf,
include/FusionCharts/FCF_MSArea2D.swf,
include/FusionCharts/FusionCharts.php: Added to repository. Fusion
Charts Free.
* include/functions_fsgraph.php: Added to repository. Fusion Charts
chart generation functions for Pandora FMS.
* include/pchart_graph.php, include/pandora_graph.php,
include/fgraph2.php, include/pChart, include/Image,
include/fgraph.php: Moved from reporting to include.
* operation/agentes/stat_win.php: Moved from reporting to
operation/agentes.
* reporting: Deleted from repository.
* general/logon_ok.php, godmode/setup/setup.php,
godmode/admin_access_logs.php, godmode/db/db_main.php,
godmode/db/db_info.php, godmode/db/db_purge.php,
godmode/reporting/graph_builder.php,
operation/reporting/reporting_xml.php,
operation/reporting/reporting_viewer.php,
operation/servers/view_server.php,
operation/servers/view_server_detail.php,
operation/incidents/incident_statistics.php
operation/users/user_statistics.php,
operation/events/event_statistics.php, operation/events/events.php,
operation/agentes/estado_ultimopaquete.php,
operation/agentes/estado_generalagente.php,
operation/agentes/tactical.php, include/functions_config.php,
include/functions_custom_graphs.php,
include/functions_visual_map.php,
include/functions_reporting.php: Added flash charts.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1779 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-06-30 17:08:14 +02:00
update_config_value ( 'fontpath' , $config [ 'homedir' ] . '/include/FreeSans.ttf' );
2009-04-06 13:02:05 +02:00
}
if ( ! isset ( $config [ 'style' ])) {
update_config_value ( 'style' , 'pandora' );
}
2009-06-30 Ramon Novoa <rnovoa@artica.es>
* nclude/FusionCharts,
include/FusionCharts/FCF_Column3D.swf,
include/FusionCharts/FCF_Pie3D.swf,
include/FusionCharts/FusionCharts.js,
include/FusionCharts/FCF_MSLine.swf,
include/FusionCharts/FusionCharts_Gen.php,
include/FusionCharts/FCF_StackedArea2D.swf,
include/FusionCharts/FCF_Area2D.swf,
include/FusionCharts/FCF_MSArea2D.swf,
include/FusionCharts/FusionCharts.php: Added to repository. Fusion
Charts Free.
* include/functions_fsgraph.php: Added to repository. Fusion Charts
chart generation functions for Pandora FMS.
* include/pchart_graph.php, include/pandora_graph.php,
include/fgraph2.php, include/pChart, include/Image,
include/fgraph.php: Moved from reporting to include.
* operation/agentes/stat_win.php: Moved from reporting to
operation/agentes.
* reporting: Deleted from repository.
* general/logon_ok.php, godmode/setup/setup.php,
godmode/admin_access_logs.php, godmode/db/db_main.php,
godmode/db/db_info.php, godmode/db/db_purge.php,
godmode/reporting/graph_builder.php,
operation/reporting/reporting_xml.php,
operation/reporting/reporting_viewer.php,
operation/servers/view_server.php,
operation/servers/view_server_detail.php,
operation/incidents/incident_statistics.php
operation/users/user_statistics.php,
operation/events/event_statistics.php, operation/events/events.php,
operation/agentes/estado_ultimopaquete.php,
operation/agentes/estado_generalagente.php,
operation/agentes/tactical.php, include/functions_config.php,
include/functions_custom_graphs.php,
include/functions_visual_map.php,
include/functions_reporting.php: Added flash charts.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1779 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-06-30 17:08:14 +02:00
if ( ! isset ( $config [ 'flash_charts' ])) {
update_config_value ( 'flash_charts' , true );
}
2009-04-06 13:02:05 +02:00
2009-03-05 13:52:59 +01:00
/* Finally, check if any value was overwritten in a form */
update_config ();
}
2009-06-08 20:26:14 +02:00
?>