1package PandoraFMS::Config;
2##########################################################################
3# Configuration Package
4# Pandora FMS. the Flexible Monitoring System. http://www.pandorafms.org
5##########################################################################
6# Copyright (c) 2005-2011 Artica Soluciones Tecnologicas S.L
7#
8# This program is free software; you can redistribute it and/or
9# modify it under the terms of the GNU Lesser General Public License
10# as published by the Free Software Foundation; version 2.
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18##########################################################################
19
20use warnings;
21use POSIX qw(strftime);
22use Time::Local;
23
24# Default lib dir for RPM and DEB packages
25use lib '/usr/lib/perl5';
26
27use PandoraFMS::Tools;
28use PandoraFMS::DB;
29use PandoraFMS::Core;
30require Exporter;
31
32our @ISA = ("Exporter");
33our %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
34our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
35our @EXPORT = qw(
36	pandora_help_screen
37	pandora_init
38	pandora_load_config
39	pandora_start_log
40	pandora_get_sharedconfig
41	pandora_get_tconfig_token
42	);
43
44# version: Defines actual version of Pandora Server for this module only
45my $pandora_version = "6.0SP2";
46my $pandora_build = "160408";
47our $VERSION = $pandora_version." ".$pandora_build;
48
49# Setup hash
50my %pa_config;
51
52# Public functions
53##########################################################################
54# SUB pandora_help_screen()
55# Shows a help screen and exits
56##########################################################################
57
58sub help_screen {
59	print "\nSyntax: \n\n pandora_server [ options ] < fullpathname to configuration file (pandora_server.conf) > \n\n";
60	print "Following options are optional : \n";
61	print "	-v        :  Verbose mode activated. Writes more information in the logfile \n";
62	print "	-d        :  Debug mode activated. Writes extensive information in the logfile \n";
63	print "	-D        :  Daemon mode (runs in background)\n";
64	print "	-P <file> :  Store PID to file.\n";
65	print "	-q        :  Quiet startup \n";
66	print "	-S <install|uninstall|run>:  Manage the win32 service.\n";
67	print "	-h        :  This screen. Shows a little help screen \n";
68	print " \n";
69	exit;
70}
71
72##########################################################################
73# SUB pandora_init ( %pandora_cfg )
74# Makes the initial parameter parsing, initializing and error checking
75##########################################################################
76
77sub pandora_init {
78	my $pa_config = $_[0];
79	my $init_string = $_[1];
80	print "\n$init_string $pandora_version Build $pandora_build Copyright (c) 2004-2015 ArticaST\n";
81	print "This program is OpenSource, licensed under the terms of GPL License version 2.\n";
82	print "You can download latest versions and documentation at http://www.pandorafms.org \n\n";
83
84	# Load config file from command line
85	if ($#ARGV == -1 ){
86		print "I need at least one parameter: Complete path to Pandora FMS Server configuration file \n";
87		help_screen;
88		exit;
89	}
90	$pa_config->{"verbosity"}=0;	# Verbose 1 by default
91	$pa_config->{"daemon"}=0;	# Daemon 0 by default
92	$pa_config->{'PID'}="";	# PID file not exist by default
93	$pa_config->{"quiet"}=0;	# Daemon 0 by default
94
95	# If there are not valid parameters
96	my $parametro;
97	my $ltotal=$#ARGV; my $ax;
98
99	for ($ax=0;$ax<=$ltotal;$ax++){
100		$parametro = $ARGV[$ax];
101		if (($parametro =~ m/-h\z/i ) || ($parametro =~ m/help\z/i )) {
102			help_screen();
103		}
104		elsif ($parametro =~ m/-v\z/i) {
105			$pa_config->{"verbosity"}=5;
106		}
107		elsif ($parametro =~ m/^-P\z/i) {
108			$pa_config->{'PID'}= clean_blank($ARGV[$ax+1]);
109		}
110		elsif ($parametro =~ m/-d\z/) {
111			$pa_config->{"verbosity"}=10;
112		}
113		elsif ($parametro =~ m/-q\z/) {
114			$pa_config->{"quiet"}=1;
115		}
116		elsif ($parametro =~ m/-D\z/) {
117			$pa_config->{"daemon"}=1;
118		}
119		elsif ($parametro =~ m/^-S\z/i) {
120			$pa_config->{'win32_service'}= clean_blank($ARGV[$ax+1]);
121		}
122		else {
123			($pa_config->{"pandora_path"} = $parametro);
124		}
125	}
126	if ($pa_config->{"pandora_path"} eq ""){
127		print " [ERROR] I need at least one parameter: Complete path to Pandora FMS configuration file. \n";
128		print "		For example: ./pandora_server /etc/pandora/pandora_server.conf \n\n";
129		exit;
130	}
131}
132
133##########################################################################
134# Read some config tokens from database set by the console
135##########################################################################
136sub pandora_get_sharedconfig ($$) {
137	my ($pa_config, $dbh) = @_;
138
139	# Agentaccess option
140	$pa_config->{"agentaccess"} = pandora_get_tconfig_token ($dbh, 'agentaccess', 1);
141
142	# Realtimestats 0 disabled, 1 enabled.
143	# Master servers will generate all the information (global tactical stats).
144	# and each server will generate it's own server stats (lag, etc).
145	$pa_config->{"realtimestats"} = pandora_get_tconfig_token ($dbh, 'realtimestats', 0);
146
147	# Stats_interval option
148	$pa_config->{"stats_interval"} = pandora_get_tconfig_token ($dbh, 'stats_interval', 300);
149
150	# Netflow configuration options
151	$pa_config->{"activate_netflow"} = pandora_get_tconfig_token ($dbh, 'activate_netflow', 0);
152	$pa_config->{"netflow_path"} = pandora_get_tconfig_token ($dbh, 'netflow_path', '/var/spool/pandora/data_in/netflow');
153	$pa_config->{"netflow_interval"} = pandora_get_tconfig_token ($dbh, 'netflow_interval', 300);
154	$pa_config->{"netflow_daemon"} = pandora_get_tconfig_token ($dbh, 'netflow_daemon', '/usr/bin/nfcapd');
155
156	# Log module configuration
157	$pa_config->{"log_dir"} = pandora_get_tconfig_token ($dbh, 'log_dir', '/var/spool/pandora/data_in/log');
158	$pa_config->{"log_interval"} = pandora_get_tconfig_token ($dbh, 'log_interval', 3600);
159
160	# Pandora FMS Console's attachment directory
161	$pa_config->{"attachment_dir"} = pandora_get_tconfig_token ($dbh, 'attachment_store', '/var/www/pandora_console/attachment');
162
163	# Metaconsole agent cache.
164	$pa_config->{"metaconsole_agent_cache"} = pandora_get_tconfig_token ($dbh, 'metaconsole_agent_cache', 0);
165
166	#Limit of events replicate in metaconsole
167	$pa_config->{'replication_limit'} = pandora_get_tconfig_token ($dbh, 'replication_limit', 1000);
168}
169
170##########################################################################
171# Read external configuration file
172##########################################################################
173
174sub pandora_load_config {
175	my $pa_config = $_[0];
176	my $archivo_cfg = $pa_config->{'pandora_path'};
177	my $buffer_line;
178	my @command_line;
179	my $tbuf;
180
181	# Default values
182	$pa_config->{'version'} = $pandora_version;
183	$pa_config->{'build'} = $pandora_build;
184	$pa_config->{"dbengine"} = "mysql";
185	$pa_config->{"dbuser"} = "pandora";
186	$pa_config->{"dbpass"} = "pandora";
187	$pa_config->{"dbhost"} = "localhost";
188	$pa_config->{'dbport'} = undef; # set to standard port of "dbengine" later
189	$pa_config->{"dbname"} = "pandora";
190	$pa_config->{"basepath"} = $pa_config->{'pandora_path'}; # Compatibility with Pandora 1.1
191	$pa_config->{"incomingdir"} = "/var/spool/pandora/data_in";
192	$pa_config->{"server_threshold"} = 30;
193	$pa_config->{"alert_threshold"} = 60;
194	$pa_config->{"logfile"} = "/var/log/pandora_server.log";
195	$pa_config->{"errorlogfile"} = "/var/log/pandora_server.error";
196	$pa_config->{"networktimeout"} = 5;	# By default, not in config file yet
197	$pa_config->{"pandora_master"} = 1;	# on by default
198	$pa_config->{"pandora_check"} = 0; 	# Deprecated since 2.0
199	$pa_config->{"servername"} = `hostname`;
200	$pa_config->{"servername"} =~ s/\s//g; # Replace ' ' chars
201	$pa_config->{"dataserver"} = 1; # default
202	$pa_config->{"networkserver"} = 1; # default
203	$pa_config->{"snmpconsole"} = 1; # default
204	$pa_config->{"reconserver"} = 1; # default
205	$pa_config->{"wmiserver"} = 1; # default
206	$pa_config->{"pluginserver"} = 1; # default
207	$pa_config->{"predictionserver"} = 1; # default
208	$pa_config->{"exportserver"} = 1; # default
209	$pa_config->{"inventoryserver"} = 1; # default
210	$pa_config->{"webserver"} = 1; # 3.0
211	$pa_config->{"servermode"} = "";
212	$pa_config->{'snmp_logfile'} = "/var/log/pandora_snmptrap.log";
213	$pa_config->{"network_threads"} = 3; # Fixed default
214	$pa_config->{"keepalive"} = 60; # 60 Seconds initially for server keepalive
215	$pa_config->{"keepalive_orig"} = $pa_config->{"keepalive"};
216	$pa_config->{"icmp_checks"} = 1; # Introduced on 1.3.1
217	$pa_config->{"icmp_packets"} = 1; # > 5.1SP2
218	$pa_config->{"alert_recovery"} = 0; # Introduced on 1.3.1
219	$pa_config->{"snmp_checks"} = 1; # Introduced on 1.3.1
220	$pa_config->{"snmp_timeout"} = 8; # Introduced on 1.3.1
221	$pa_config->{"snmp_trapd"} = '/usr/sbin/snmptrapd'; # 3.0
222	$pa_config->{"tcp_checks"} = 1; # Introduced on 1.3.1
223	$pa_config->{"tcp_timeout"} = 20; # Introduced on 1.3.1
224	$pa_config->{"snmp_proc_deadresponse"} = 1; # Introduced on 1.3.1 10 Feb08
225	$pa_config->{"plugin_threads"} = 2; # Introduced on 2.0
226	$pa_config->{"plugin_exec"} = '/usr/bin/timeout'; # 3.0
227	$pa_config->{"recon_threads"} = 2; # Introduced on 2.0
228	$pa_config->{"prediction_threads"} = 1; # Introduced on 2.0
229	$pa_config->{"plugin_timeout"} = 5; # Introduced on 2.0
230	$pa_config->{"wmi_threads"} = 2; # Introduced on 2.0
231	$pa_config->{"wmi_timeout"} = 5; # Introduced on 2.0
232	$pa_config->{"wmi_client"} = 'wmic'; # 3.0
233	$pa_config->{"dataserver_threads"} = 2; # Introduced on 2.0
234	$pa_config->{"inventory_threads"} = 2; # 2.1
235	$pa_config->{"export_threads"} = 1; # 3.0
236	$pa_config->{"web_threads"} = 1; # 3.0
237	$pa_config->{"web_engine"} = 'lwp'; # 5.1
238	$pa_config->{"activate_gis"} = 0; # 3.1
239	$pa_config->{"location_error"} = 50; # 3.1
240	$pa_config->{"recon_reverse_geolocation_mode"} = 'disabled'; # 3.1
241	$pa_config->{"recon_reverse_geolocation_file"} = '/usr/local/share/GeoIP/GeoIPCity.dat'; # 3.1
242	$pa_config->{"recon_location_scatter_radius"} = 50; # 3.1
243	$pa_config->{"update_parent"} = 0; # 3.1
244	$pa_config->{"google_maps_description"} = 0;
245	$pa_config->{'openstreetmaps_description'} = 0;
246	$pa_config->{"eventserver"} = 1; # 4.0
247	$pa_config->{"event_window"} = 3600; # 4.0
248	$pa_config->{"icmpserver"} = 0; # 4.0
249	$pa_config->{"icmp_threads"} = 3; # 4.0
250	$pa_config->{"snmpserver"} = 0; # 4.0
251	$pa_config->{"snmp_threads"} = 3; # 4.0
252	$pa_config->{"block_size"} = 15; # 4.0
253	$pa_config->{"max_queue_files"} = 500;
254	$pa_config->{"snmp_ignore_authfailure"} = 1; # 5.0
255	$pa_config->{"snmp_pdu_address"} = 0; # 5.0
256	$pa_config->{"snmp_storm_protection"} = 0; # 5.0
257	$pa_config->{"snmp_storm_timeout"} = 600; # 5.0
258	$pa_config->{"snmpconsole_threads"} = 1; # 5.1
259	$pa_config->{"translate_variable_bindings"} = 0; # 5.1
260	$pa_config->{"translate_enterprise_strings"} = 1; # 5.1
261
262	# Internal MTA for alerts, each server need its own config.
263	$pa_config->{"mta_address"} = '127.0.0.1'; # Introduced on 2.0
264	$pa_config->{"mta_port"} = '25'; # Introduced on 2.0
265	$pa_config->{"mta_user"} = ''; # Introduced on 2.0
266	$pa_config->{"mta_pass"} = ''; # Introduced on 2.0
267	$pa_config->{"mta_auth"} = 'none'; # Introduced on 2.0 (Support LOGIN PLAIN CRAM-MD5 DIGEST-MD)
268	$pa_config->{"mta_from"} = 'pandora@localhost'; # Introduced on 2.0
269	$pa_config->{"mail_in_separate"} = 1; # 1: eMail deliver alert mail in separate mails.
270					      # 0: eMail deliver 1 mail with all destination.
271
272	# nmap for recon OS fingerprinting and tcpscan (optional)
273	$pa_config->{"nmap"} = "/usr/bin/nmap";
274	$pa_config->{"nmap_timing_template"} = 2; # > 5.1
275	$pa_config->{"recon_timing_template"} = 3; # > 5.1
276
277	$pa_config->{"fping"} = "/usr/sbin/fping"; # > 5.1SP2
278
279	# braa for enterprise snmp server
280	$pa_config->{"braa"} = "/usr/bin/braa";
281
282	# SNMP enterprise retries (for braa)
283	$pa_config->{"braa_retries"} = 3; # 5.0
284
285	# Xprobe2 for recon OS fingerprinting and tcpscan (optional)
286	$pa_config->{"xprobe2"} = "/usr/bin/xprobe2";
287
288
289	# Snmpget for snmpget system command (optional)
290	$pa_config->{"snmpget"} = "/usr/bin/snmpget";
291
292	$pa_config->{'autocreate_group'} = -1;
293	$pa_config->{'autocreate'} = 1;
294
295	# max log size (bytes)
296	$pa_config->{'max_log_size'} = 1048576;
297
298	# max log generation
299	$pa_config->{'max_log_generation'} = 1;
300
301	# Ignore the timestamp in the XML and use the file timestamp instead
302	$pa_config->{'use_xml_timestamp'} = 0;
303
304	# Server restart delay in seconds
305	$pa_config->{'restart_delay'} = 60;
306
307	# Auto restart every x seconds
308	$pa_config->{'auto_restart'} = 0;
309
310	# Restart server on error
311	$pa_config->{'restart'} = 0;
312
313	# Self monitoring
314	$pa_config->{'self_monitoring'} = 0;
315
316	# Self monitoring interval
317	$pa_config->{'self_monitoring_interval'} = 300; # 5.1SP1
318
319	# Process XML data files as a stack
320	$pa_config->{"dataserver_lifo"} = 0; # 5.0
321
322	# Patrol process of policies queue
323	$pa_config->{"policy_manager"} = 0; # 5.0
324
325	# Event replication process
326	$pa_config->{"event_replication"} = 0; # 5.0
327
328	# Event auto-validation
329	$pa_config->{"event_auto_validation"} = 1; # 5.0
330
331	# Export events to a text file
332	$pa_config->{"event_file"} = ''; # 5.0
333
334	# Default event messages
335	$pa_config->{"text_going_down_normal"} = "Module '_module_' is going to NORMAL (_data_)"; # 5.0
336	$pa_config->{"text_going_up_critical"} = "Module '_module_' is going to CRITICAL (_data_)"; # 5.0
337	$pa_config->{"text_going_up_warning"} = "Module '_module_' is going to WARNING (_data_)"; # 5.0
338	$pa_config->{"text_going_down_warning"} = "Module '_module_' is going to WARNING (_data_)"; # 5.0
339	$pa_config->{"text_going_unknown"} = "Module '_module_' is going to UNKNOWN"; # 5.0
340
341	# Event auto-expiry time
342	$pa_config->{"event_expiry_time"} = 0; # 5.0
343
344	# Event auto-expiry time window
345	$pa_config->{"event_expiry_window"} = 86400; # 5.0
346
347	# Event auto-expiry time window
348	$pa_config->{"claim_back_snmp_modules"} = 1; # 5.1
349
350	# Auto-recovery of asynchronous modules.
351	$pa_config->{"async_recovery"} = 1; # 5.1SP1
352
353	# Console API connection
354	$pa_config->{"console_api_url"} = 'http://localhost/pandora_console/include/api.php'; # 6.0
355	$pa_config->{"console_api_pass"} = ''; # 6.0
356	$pa_config->{"console_user"} = 'admin'; # 6.0
357	$pa_config->{"console_pass"} = 'pandora'; # 6.0
358
359	# Database password encryption passphrase
360	$pa_config->{"encryption_passphrase"} = ''; # 6.0
361
362	# Unknown interval (as a multiple of the module's interval)
363	$pa_config->{"unknown_interval"} = 2; # > 5.1SP2
364
365	# -------------------------------------------------------------------------
366	# This values are not stored in .conf files.
367	# This values should be stored in database, not in .conf files!
368	# Default values are set here because if they are not present in config DB
369	# don't get an error later.
370	$pa_config->{"realtimestats"} = 0;
371	$pa_config->{"stats_interval"} = 300;
372	$pa_config->{"agentaccess"} = 1;
373	$pa_config->{"event_storm_protection"} = 0;
374	# -------------------------------------------------------------------------
375
376	#SNMP Forwarding tokens
377	$pa_config->{"snmp_forward_trap"}=0;
378	$pa_config->{"snmp_forward_secName"}= '';
379	$pa_config->{"snmp_forward_engineid"}= '';
380	$pa_config->{"snmp_forward_authProtocol"}= '';
381	$pa_config->{"snmp_forward_authPassword"}= '';
382	$pa_config->{"snmp_forward_community"}= 'public';
383	$pa_config->{"snmp_forward_privProtocol"}= '';
384	$pa_config->{"snmp_forward_privPassword"}= '';
385	$pa_config->{"snmp_forward_secLevel"}= '';
386	$pa_config->{"snmp_forward_version"}= 2;
387	$pa_config->{"snmp_forward_ip"}= '';
388
389	# Global Timeout for Custom Commands Alerts
390	$pa_config->{"global_alert_timeout"}= 15; # 6.0
391
392	# Server Remote Config
393	$pa_config->{"remote_config"}= 0; # 6.0
394
395	# Remote config server address
396	$pa_config->{"remote_config_address"} = 'localhost'; # 6.0
397
398	# Remote config server port
399	$pa_config->{"remote_config_port"} = 41121; # 6.0
400
401	# Remote config server options
402	$pa_config->{"remote_config_opts"} = ''; # 6.0
403
404	# Temp path for file sendinn and receiving
405	$pa_config->{"temporal"} = '/tmp'; # 6.0
406
407	# Warmup intervals.
408	$pa_config->{"warmup_alert_interval"} = 0; # 6.1
409	$pa_config->{"warmup_alert_on"} = 0; # 6.1
410	$pa_config->{"warmup_event_interval"} = 0; # 6.1
411	$pa_config->{"warmup_event_on"} = 0; # 6.1
412	$pa_config->{"warmup_unknown_interval"} = 300; # 6.1
413	$pa_config->{"warmup_unknown_on"} = 1; # 6.1
414
415	# Check for UID0
416	if ($pa_config->{"quiet"} != 0){
417		if ($> == 0){
418			printf " [W] Not all Pandora FMS components need to be executed as root\n";
419			printf "	please consider starting it with a non-privileged user.\n";
420		}
421	}
422
423	# Check for file
424	if ( ! -f $archivo_cfg ) {
425		printf "\n [ERROR] Cannot open configuration file at $archivo_cfg. \n";
426		printf "	Please specify a valid Pandora FMS configuration file in command line. \n";
427		print "	Standard configuration file is at /etc/pandora/pandora_server.conf \n";
428		exit 1;
429	}
430
431	# Collect items from config file and put in an array
432	if (! open (CFG, "< $archivo_cfg")) {
433		print "[ERROR] Error opening configuration file $archivo_cfg: $!.\n";
434		exit 1;
435	}
436
437	while (<CFG>){
438		$buffer_line = $_;
439		if ($buffer_line =~ /^[a-zA-Z]/){ # begins with letters
440			if ($buffer_line =~ m/([\w\-\_\.]+)\s([0-9\w\-\_\.\/\?\&\=\)\(\_\-\!\*\@\#\%\$\~\"\']+)/){
441				push @command_line, $buffer_line;
442			}
443		}
444	}
445 	close (CFG);
446
447 	# Process this array with commandline like options
448 	# Process input parameters
449
450 	my @args = @command_line;
451 	my $parametro;
452 	my $ltotal=$#args;
453	my $ax;
454
455 	# Has read setup file ok ?
456 	if ( $ltotal == 0 ) {
457		print "[ERROR] No valid setup tokens readed in $archivo_cfg ";
458		exit;
459 	}
460
461 	for ($ax=0;$ax<=$ltotal;$ax++){
462		$parametro = $args[$ax];
463
464		if ($parametro =~ m/^incomingdir\s(.*)/i) {
465			$tbuf= clean_blank($1);
466			if ($tbuf =~ m/^\.(.*)/){
467				$pa_config->{"incomingdir"} =$pa_config->{"basepath"}.$1;
468			} else {
469				$pa_config->{"incomingdir"} = $tbuf;
470			}
471		}
472
473		elsif ($parametro =~ m/^log_file\s(.*)/i) {
474			$tbuf= clean_blank($1);
475			if ($tbuf =~ m/^\.(.*)/){
476				$pa_config->{"logfile"} = $pa_config->{"basepath"}.$1;
477			} else {
478				$pa_config->{"logfile"} = $tbuf;
479			}
480		}
481
482		elsif ($parametro =~ m/^errorlog_file\s(.*)/i) {
483			$tbuf= clean_blank($1);
484			if ($tbuf =~ m/^\.(.*)/){
485				$pa_config->{"errorlogfile"} = $pa_config->{"basepath"}.$1;
486			} else {
487				$pa_config->{"errorlogfile"} = $tbuf;
488			}
489		}
490
491	# MTA setup (2.0)
492		elsif ($parametro =~ m/^mta_user\s(.*)/i) {
493			$pa_config->{'mta_user'}= clean_blank($1);
494		}
495		elsif ($parametro =~ m/^mta_pass\s(.*)/i) {
496			$pa_config->{'mta_pass'}= clean_blank($1);
497		}
498		elsif ($parametro =~ m/^mta_address\s(.*)/i) {
499			$pa_config->{'mta_address'}= clean_blank($1);
500		}
501		elsif ($parametro =~ m/^mta_port\s(.*)/i) {
502			$pa_config->{'mta_port'}= clean_blank($1);
503		}
504		elsif ($parametro =~ m/^mta_auth\s(.*)/i) {
505			$pa_config->{'mta_auth'}= clean_blank($1);
506		}
507		elsif ($parametro =~ m/^mta_from\s(.*)/i) {
508			$pa_config->{'mta_from'}= clean_blank($1);
509		}
510		elsif ($parametro =~ m/^mail_in_separate\s([0-9]*)/i) {
511			$pa_config->{'mail_in_separate'}= clean_blank($1);
512		}
513		elsif ($parametro =~ m/^snmp_logfile\s(.*)/i) {
514			$pa_config->{'snmp_logfile'}= clean_blank($1);
515		}
516		elsif ($parametro =~ m/^snmp_ignore_authfailure\s+([0-1])/i) {
517			$pa_config->{'snmp_ignore_authfailure'}= clean_blank($1);
518		}
519		elsif ($parametro =~ m/^snmp_pdu_address\s+([0-1])/i) {
520			$pa_config->{'snmp_pdu_address'}= clean_blank($1);
521		}
522		elsif ($parametro =~ m/^snmp_storm_protection\s+(\d+)/i) {
523			$pa_config->{'snmp_storm_protection'}= clean_blank($1);
524		}
525		elsif ($parametro =~ m/^snmp_storm_timeout\s+(\d+)/i) {
526			$pa_config->{'snmp_storm_timeout'}= clean_blank($1);
527		}
528		elsif ($parametro =~ m/^snmpconsole_threads\s+(\d+)/i) {
529			$pa_config->{'snmpconsole_threads'}= clean_blank($1);
530		}
531		elsif ($parametro =~ m/^translate_variable_bindings\s+([0-1])/i) {
532			$pa_config->{'translate_variable_bindings'}= clean_blank($1);
533		}
534		elsif ($parametro =~ m/^translate_enterprise_strings\s+([0-1])/i) {
535			$pa_config->{'translate_enterprise_strings'}= clean_blank($1);
536		}
537		elsif ($parametro =~ m/^dbengine\s(.*)/i) {
538			$pa_config->{'dbengine'}= clean_blank($1);
539		}
540		elsif ($parametro =~ m/^dbname\s(.*)/i) {
541			$pa_config->{'dbname'}= clean_blank($1);
542		}
543		elsif ($parametro =~ m/^dbuser\s(.*)/i) {
544			$pa_config->{'dbuser'}= clean_blank($1);
545		}
546		elsif ($parametro =~ m/^dbpass\s(.*)/i) {
547			$pa_config->{'dbpass'}= clean_blank($1);
548		}
549		elsif ($parametro =~ m/^dbhost\s(.*)/i) {
550			$pa_config->{'dbhost'}= clean_blank($1);
551		}
552		elsif ($parametro =~ m/^dbport\s(.*)/i) {
553			$pa_config->{'dbport'}= clean_blank($1);
554		}
555		elsif ($parametro =~ m/^daemon\s([0-9]*)/i) {
556			$pa_config->{'daemon'}= clean_blank($1);
557		}
558		elsif ($parametro =~ m/^dataserver\s([0-9]*)/i){
559			$pa_config->{'dataserver'}= clean_blank($1);
560		}
561		elsif ($parametro =~ m/^networkserver\s([0-9]*)/i){
562			$pa_config->{'networkserver'}= clean_blank($1);
563		}
564		elsif ($parametro =~ m/^pluginserver\s([0-9]*)/i){
565			$pa_config->{'pluginserver'}= clean_blank($1);
566		}
567		elsif ($parametro =~ m/^predictionserver\s([0-9]*)/i){
568			$pa_config->{'predictionserver'}= clean_blank($1);
569		}
570		elsif ($parametro =~ m/^reconserver\s([0-9]*)/i) {
571			$pa_config->{'reconserver'}= clean_blank($1);
572		}
573		elsif ($parametro =~ m/^reconserver\s([0-9]*)/i) {
574			$pa_config->{'reconserver'}= clean_blank($1);
575		}
576		elsif ($parametro =~ m/^wmiserver\s([0-9]*)/i) {
577			$pa_config->{'wmiserver'}= clean_blank($1);
578		}
579		elsif ($parametro =~ m/^exportserver\s([0-9]*)/i) {
580			$pa_config->{'exportserver'}= clean_blank($1);
581		}
582		elsif ($parametro =~ m/^inventoryserver\s([0-9]*)/i) {
583			$pa_config->{'inventoryserver'}= clean_blank($1);
584		}
585		elsif ($parametro =~ m/^webserver\s([0-9]*)/i) {
586			$pa_config->{'webserver'}= clean_blank($1);
587		}
588		elsif ($parametro =~ m/^eventserver\s([0-9]*)/i) {
589			$pa_config->{'eventserver'}= clean_blank($1);
590		}
591		elsif ($parametro =~ m/^icmpserver\s([0-9]*)/i) {
592			$pa_config->{'icmpserver'}= clean_blank($1);
593		}
594		elsif ($parametro =~ m/^icmp_threads\s([0-9]*)/i) {
595			$pa_config->{'icmp_threads'}= clean_blank($1);
596		}
597		elsif ($parametro =~ m/^servername\s(.*)/i) {
598			$pa_config->{'servername'}= clean_blank($1);
599		}
600		elsif ($parametro =~ m/^checksum\s([0-9])/i) {
601			$pa_config->{"pandora_check"} = clean_blank($1);
602		}
603		elsif ($parametro =~ m/^master\s([0-9])/i) {
604			$pa_config->{"pandora_master"} = clean_blank($1);
605		}
606		elsif ($parametro =~ m/^icmp_checks\s([0-9]*)/i) {
607			$pa_config->{"icmp_checks"} = clean_blank($1);
608		}
609		elsif ($parametro =~ m/^icmp_packets\s([0-9]*)/i) {
610			$pa_config->{"icmp_packets"} = clean_blank($1);
611		}
612		elsif ($parametro =~ m/^snmpconsole\s([0-9]*)/i) {
613			$pa_config->{"snmpconsole"} = clean_blank($1);
614		}
615		elsif ($parametro =~ m/^snmpserver\s([0-9]*)/i) {
616			$pa_config->{"snmpserver"} = clean_blank($1);
617		}
618		elsif ($parametro =~ m/^alert_recovery\s([0-9]*)/i) {
619			$pa_config->{"alert_recovery"} = clean_blank($1);
620		}
621		elsif ($parametro =~ m/^snmp_checks\s([0-9]*)/i) {
622			$pa_config->{"snmp_checks"} = clean_blank($1);
623		}
624		elsif ($parametro =~ m/^snmp_timeout\s([0-9]*)/i) {
625			$pa_config->{"snmp_timeout"} = clean_blank($1);
626		}
627		elsif ($parametro =~ m/^tcp_checks\s([0-9]*)/i) {
628			$pa_config->{"tcp_checks"} = clean_blank($1);
629		}
630		elsif ($parametro =~ m/^tcp_timeout\s([0-9]*)/i) {
631			$pa_config->{"tcp_timeout"} = clean_blank($1);
632		}
633		elsif ($parametro =~ m/^snmp_proc_deadresponse\s([0-9]*)/i) {
634			$pa_config->{"snmp_proc_deadresponse"} = clean_blank($1);
635		}
636		elsif ($parametro =~ m/^verbosity\s([0-9]*)/i) {
637			$pa_config->{"verbosity"} = clean_blank($1);
638		}
639		elsif ($parametro =~ m/^server_threshold\s([0-9]*)/i) {
640			$pa_config->{"server_threshold"} = clean_blank($1);
641		}
642		elsif ($parametro =~ m/^alert_threshold\s([0-9]*)/i) {
643			$pa_config->{"alert_threshold"} = clean_blank($1);
644		}
645		elsif ($parametro =~ m/^network_timeout\s([0-9]*)/i) {
646			$pa_config->{'networktimeout'}= clean_blank($1);
647		}
648		elsif ($parametro =~ m/^network_threads\s([0-9]*)/i) {
649			$pa_config->{'network_threads'}= clean_blank($1);
650		}
651		elsif ($parametro =~ m/^plugin_threads\s([0-9]*)/i) {
652			$pa_config->{'plugin_threads'}= clean_blank($1);
653		}
654		elsif ($parametro =~ m/^prediction_threads\s([0-9]*)/i) {
655			$pa_config->{'prediction_threads'}= clean_blank($1);
656		}
657		elsif ($parametro =~ m/^plugin_timeout\s([0-9]*)/i) {
658			$pa_config->{'plugin_timeout'}= clean_blank($1);
659		}
660		elsif ($parametro =~ m/^dataserver_threads\s([0-9]*)/i) {
661			$pa_config->{'dataserver_threads'}= clean_blank($1);
662		}
663		elsif ($parametro =~ m/^server_keepalive\s([0-9]*)/i) {
664			$pa_config->{"keepalive"} = clean_blank($1);
665			$pa_config->{"keepalive_orig"} = clean_blank($1);
666		}
667		elsif ($parametro =~ m/^nmap\s(.*)/i) {
668			$pa_config->{'nmap'}= clean_blank($1);
669		}
670		elsif ($parametro =~ m/^fping\s(.*)/i) {
671			$pa_config->{'fping'}= clean_blank($1);
672		}
673		elsif ($parametro =~ m/^nmap_timing_template\s([0-9]*)/i) {
674			$pa_config->{'nmap_timing_template'}= clean_blank($1);
675		}
676		elsif ($parametro =~ m/^recon_timing_template\s([0-9]*)/i) {
677			$pa_config->{'recon_timing_template'}= clean_blank($1);
678		}
679		elsif ($parametro =~ m/^braa\s(.*)/i) {
680			$pa_config->{'braa'}= clean_blank($1);
681		}
682		elsif ($parametro =~ m/^braa_retries\s([0-9]*)/i) {
683			$pa_config->{"braa_retries"} = clean_blank($1);
684		}
685		elsif ($parametro =~ m/^xprobe2\s(.*)/i) {
686			$pa_config->{'xprobe2'}= clean_blank($1);
687		}
688		elsif ($parametro =~ m/^snmpget\s(.*)/i) {
689			$pa_config->{'snmpget'}= clean_blank($1);
690		}
691		elsif ($parametro =~ m/^autocreate\s([0-9*]*)/i) {
692			$pa_config->{'autocreate'}= clean_blank($1);
693		}
694		elsif ($parametro =~ m/^autocreate_group\s([0-9*]*)/i) {
695			$pa_config->{'autocreate_group'}= clean_blank($1);
696		}
697		elsif ($parametro =~ m/^recon_threads\s([0-9]*)/i) {
698			$pa_config->{'recon_threads'}= clean_blank($1);
699		}
700		elsif ($parametro =~ m/^max_log_size\s([0-9]*)/i) {
701			$pa_config->{'max_log_size'}= clean_blank($1);
702		}
703		elsif ($parametro =~ m/^max_log_generation\s([1-9])/i) {
704			$pa_config->{'max_log_generation'}= clean_blank($1);
705		}
706		elsif ($parametro =~ m/^wmi_threads\s([0-9]*)/i) {
707			$pa_config->{'wmi_threads'}= clean_blank($1);
708		}
709		elsif ($parametro =~ m/^wmi_client\s(.*)/i) {
710			$pa_config->{'wmi_client'}= clean_blank($1);
711		}
712		elsif ($parametro =~ m/^web_threads\s([0-9]*)/i) {
713			$pa_config->{'web_threads'}= clean_blank($1);
714		}
715		elsif ($parametro =~ m/^web_engine\s(.*)/i) {
716			$pa_config->{'web_engine'}= clean_blank($1);
717		}
718		elsif ($parametro =~ m/^snmp_trapd\s(.*)/i) {
719			$pa_config->{'snmp_trapd'}= clean_blank($1);
720		}
721		elsif ($parametro =~ m/^plugin_exec\s(.*)/i) {
722			$pa_config->{'plugin_exec'}= clean_blank($1);
723		}
724		elsif ($parametro =~ m/^inventory_threads\s([0-9]*)/i) {
725			$pa_config->{'inventory_threads'}= clean_blank($1);
726		}
727		elsif ($parametro =~ m/^export_threads\s([0-9]*)/i) {
728			$pa_config->{'export_threads'}= clean_blank($1);
729		}
730		elsif ($parametro =~ m/^max_queue_files\s([0-9]*)/i) {
731			$pa_config->{'max_queue_files'}= clean_blank($1);
732		}
733		elsif ($parametro =~ m/^use_xml_timestamp\s([0-1])/i) {
734			$pa_config->{'use_xml_timestamp'} = clean_blank($1);
735		}
736		elsif ($parametro =~ m/^restart_delay\s+(\d+)/i) {
737			$pa_config->{'restart_delay'} = clean_blank($1);
738		}
739		elsif ($parametro =~ m/^auto_restart\s+(\d+)/i) {
740			$pa_config->{'auto_restart'} = clean_blank($1);
741		}
742		elsif ($parametro =~ m/^restart\s+([0-1])/i) {
743			$pa_config->{'restart'} = clean_blank($1);
744		}
745		elsif ($parametro =~ m/^google_maps_description\s+([0-1])/i) {
746			$pa_config->{'google_maps_description'} = clean_blank($1);
747		}
748		elsif ($parametro =~ m/^openstreetmaps_description\s+([0-1])/i) {
749			$pa_config->{'openstreetmaps_description'} = clean_blank($1);
750		}
751		elsif ($parametro =~ m/^activate_gis\s+([0-1])/i) {
752			$pa_config->{'activate_gis'} = clean_blank($1);
753		}
754		elsif ($parametro =~ m/^location_error\s+(\d+)/i) {
755			$pa_config->{'location_error'} = clean_blank($1);
756		}
757		elsif ($parametro =~ m/^recon_reverse_geolocation_mode\s+(\w+)/i) {
758			$pa_config->{'recon_reverse_geolocation_mode'} = clean_blank($1);
759		} #FIXME: Find a better regexp to validate the path
760		elsif ($parametro =~ m/^recon_reverse_geolocation_file\s+(.*)/i) {
761			$pa_config->{'recon_reverse_geolocation_file'} = clean_blank($1);
762		}
763		elsif ($parametro =~ m/^recon_location_scatter_radius\s+(\d+)/i) {
764			$pa_config->{'recon_location_scatter_radius'} = clean_blank($1);
765		}
766		elsif ($parametro =~ m/^self_monitoring\s+([0-1])/i) {
767			$pa_config->{'self_monitoring'} = clean_blank($1);
768		}
769		elsif ($parametro =~ m/^self_monitoring_interval\s+([0-9]*)/i) {
770			$pa_config->{'self_monitoring_interval'} = clean_blank($1);
771		}
772		elsif ($parametro =~ m/^update_parent\s+([0-1])/i) {
773			$pa_config->{'update_parent'} = clean_blank($1);
774		}
775		elsif ($parametro =~ m/^event_window\s+([0-9]*)/i) {
776			$pa_config->{'event_window'}= clean_blank($1);
777		}
778		elsif ($parametro =~ m/^snmp_threads\s+([0-9]*)/i) {
779			$pa_config->{'snmp_threads'}= clean_blank($1);
780		}
781		elsif ($parametro =~ m/^block_size\s+([0-9]*)/i) {
782			$pa_config->{'block_size'}= clean_blank($1);
783		}
784		elsif ($parametro =~ m/^dataserver_lifo\s+([0-1])/i) {
785			$pa_config->{'dataserver_lifo'}= clean_blank($1);
786		}
787		elsif ($parametro =~ m/^policy_manager\s+([0-1])/i) {
788			$pa_config->{'policy_manager'}= clean_blank($1);
789		}
790		elsif ($parametro =~ m/^event_replication\s+([0-1])/i) {
791			$pa_config->{'event_replication'}= clean_blank($1);
792		}
793		elsif ($parametro =~ m/^event_auto_validation\s+([0-1])/i) {
794			$pa_config->{'event_auto_validation'}= clean_blank($1);
795		}
796		elsif ($parametro =~ m/^event_file\s+(.*)/i) {
797			$pa_config->{'event_file'}= clean_blank($1);
798		}
799		elsif ($parametro =~ m/^text_going_down_normal\s+(.*)/i) {
800			$pa_config->{'text_going_down_normal'} = safe_input ($1);
801		}
802		elsif ($parametro =~ m/^text_going_up_critical\s+(.*)/i) {
803			$pa_config->{'text_going_up_critical'} = safe_input ($1);
804		}
805		elsif ($parametro =~ m/^text_going_up_warning\s+(.*)/i) {
806			$pa_config->{'text_going_up_warning'} = safe_input ($1);
807		}
808		elsif ($parametro =~ m/^text_going_down_warning\s+(.*)/i) {
809			$pa_config->{'text_going_down_warning'} = safe_input ($1);
810		}
811		elsif ($parametro =~ m/^text_going_unknown\s+(.*)/i) {
812			$pa_config->{'text_going_unknown'} = safe_input ($1);
813		}
814		elsif ($parametro =~ m/^event_expiry_time\s+([0-9]*)/i) {
815			$pa_config->{'event_expiry_time'}= clean_blank($1);
816		}
817		elsif ($parametro =~ m/^event_expiry_window\s+([0-9]*)/i) {
818			$pa_config->{'event_expiry_window'}= clean_blank($1);
819		}
820		elsif ($parametro =~ m/^snmp_forward_trap\s+([0-1])/i) {
821			$pa_config->{'snmp_forward_trap'}= safe_input($1);
822		}
823		elsif ($parametro =~ m/^snmp_forward_secName\s(.*)/i) {
824			$pa_config->{'snmp_forward_secName'}= safe_input($1);
825		}
826		elsif ($parametro =~ m/^snmp_forward_engineid\s(.*)/i) {
827                        $pa_config->{'snmp_forward_engineid'}= safe_input($1);
828                }
829		elsif ($parametro =~ m/^snmp_forward_authProtocol\s(.*)/i) {
830                        $pa_config->{'snmp_forward_authProtocol'}= safe_input($1);
831                }
832		elsif ($parametro =~ m/^snmp_forward_authPassword\s(.*)/i) {
833                        $pa_config->{'snmp_forward_authPassword'}= safe_input($1);
834                }
835		elsif ($parametro =~ m/^snmp_forward_community\s(.*)/i) {
836                        $pa_config->{'snmp_forward_community'}= safe_input($1);
837                }
838		elsif ($parametro =~ m/^snmp_forward_privProtocol\s(.*)/i) {
839                        $pa_config->{'snmp_forward_privProtocol'}= safe_input($1);
840                }
841		elsif ($parametro =~ m/^snmp_forward_privPassword\s(.*)/i) {
842                        $pa_config->{'snmp_forward_privPassword'}= safe_input($1);
843                }
844		elsif ($parametro =~ m/^snmp_forward_secLevel\s(.*)/i) {
845                        $pa_config->{'snmp_forward_secLevel'}= safe_input($1);
846                }
847		elsif ($parametro =~ m/^snmp_forward_version\s(.*)/i) {
848                        $pa_config->{'snmp_forward_version'}= safe_input($1);
849                }
850		elsif ($parametro =~ m/^snmp_forward_ip\s(.*)/i) {
851			$pa_config->{'snmp_forward_ip'}= safe_input($1);
852			if ($pa_config->{'snmp_forward_trap'}==1 && ($pa_config->{'snmp_forward_ip'} eq '127.0.0.1' || $pa_config->{'snmp_forward_ip'} eq 'localhost')) {
853				printf "\n [ERROR] Cannot set snmp_forward_ip to localhost or 127.0.0.1 \n";
854                		exit 1;
855
856			}
857		}
858		elsif ($parametro =~ m/^claim_back_snmp_modules\s(.*)/i) {
859			$pa_config->{'claim_back_snmp_modules'}= safe_input($1);
860		}
861		elsif ($parametro =~ m/^async_recovery\s+([0-1])/i) {
862			$pa_config->{'async_recovery'}= safe_input($1);
863		}
864		elsif ($parametro =~ m/^console_api_url\s(.*)/i) {
865			$pa_config->{'console_api_url'}= safe_input($1);
866		}
867		elsif ($parametro =~ m/^console_api_pass\s(.*)/i) {
868			$pa_config->{'console_api_pass'}= safe_input($1);
869		}
870		elsif ($parametro =~ m/^console_user\s(.*)/i) {
871			$pa_config->{'console_user'}= safe_input($1);
872		}
873		elsif ($parametro =~ m/^console_pass\s(.*)/i) {
874			$pa_config->{'console_pass'}= safe_input($1);
875		}
876		elsif ($parametro =~ m/^encryption_passphrase\s(.*)/i) { # 6.0
877			$pa_config->{'encryption_passphrase'}= safe_input($1);
878		}
879		elsif ($parametro =~ m/^unknown_interval\s([0-9]*)/i) { # > 5.1SP2
880			$pa_config->{'unknown_interval'}= safe_input($1);
881		}
882		elsif ($parametro =~ m/^global_alert_timeout\s+([0-9]*)/i) {
883			$pa_config->{'global_alert_timeout'}= clean_blank($1);
884		}
885		elsif ($parametro =~ m/^remote_config\s+([0-9]*)/i) {
886			$pa_config->{'remote_config'}= clean_blank($1);
887		}
888		elsif ($parametro =~ m/^remote_config_address\s(.*)/i) {
889			$pa_config->{'remote_config_address'}= clean_blank($1);
890		}
891		elsif ($parametro =~ m/^remote_config_port\s+([0-9]*)/i) {
892			$pa_config->{'remote_config_port'}= clean_blank($1);
893		}
894		elsif ($parametro =~ m/^remote_config_opts\s(.*)/i) {
895			$pa_config->{'remote_config_opts'}= clean_blank($1);
896		}
897		elsif ($parametro =~ m/^temporal\s(.*)/i) {
898			$pa_config->{'temporal'}= clean_blank($1);
899		}
900		elsif ($parametro =~ m/^warmup_event_interval\s+([0-9]*)/i ||
901		       $parametro =~ m/^warmup_alert_interval\s+([0-9]*)/i) {
902			$pa_config->{'warmup_event_interval'}= clean_blank($1);
903			$pa_config->{'warmup_event_on'} = 1 if ($pa_config->{'warmup_event_interval'} > 0); # Off by default.
904			# The same interval is used for alerts and events.
905			$pa_config->{'warmup_alert_interval'}= clean_blank($1);
906			$pa_config->{'warmup_alert_on'} = 1 if ($pa_config->{'warmup_event_interval'} > 0); # Off by default.
907		}
908		elsif ($parametro =~ m/^warmup_unknown_interval\s+([0-9]*)/i) {
909			$pa_config->{'warmup_unknown_interval'}= clean_blank($1);
910			$pa_config->{'warmup_unknown_on'} = 0 if ($pa_config->{'warmup_unknown_interval'} == 0); # On by default.
911		}
912	} # end of loop for parameter #
913
914	# Set to RDBMS' standard port
915	if (!defined($pa_config->{'dbport'})) {
916		if ($pa_config->{'dbengine'} eq "mysql") {
917			$pa_config->{'dbport'} = 3306;
918		}
919		elsif ($pa_config->{'dbengine'} eq "postgresql") {
920			$pa_config->{'dbport'} = 5432;
921		}
922		elsif ($pa_config->{'dbengine'} eq "oracle") {
923			$pa_config->{'dbport'} = 1521;
924		}
925	}
926
927	if (($pa_config->{"verbosity"} > 4) && ($pa_config->{"quiet"} == 0)){
928		if ($pa_config->{"PID"} ne ""){
929			print " [*] PID File is written at ".$pa_config->{'PID'}."\n";
930		}
931		print " [*] Server basepath is ".$pa_config->{'basepath'}."\n";
932		print " [*] Server logfile at ".$pa_config->{"logfile"}."\n";
933		print " [*] Server errorlogfile at ".$pa_config->{"errorlogfile"}."\n";
934		print " [*] Server incoming directory at ".$pa_config->{"incomingdir"}."\n";
935		print " [*] Server keepalive ".$pa_config->{"keepalive"}."\n";
936		print " [*] Server threshold ".$pa_config->{"server_threshold"}."\n";
937	}
938 	# Check for valid token token values
939 	if (( $pa_config->{"dbuser"} eq "" ) || ( $pa_config->{"basepath"} eq "" ) || ( $pa_config->{"incomingdir"} eq "" ) || ( $pa_config->{"logfile"} eq "" ) || ( $pa_config->{"dbhost"} eq "") || ( $pa_config->{"pandora_master"} eq "") || ( $pa_config->{"dbpass"} eq "" ) ) {
940		print " [ERROR] Bad Config values. Be sure that $archivo_cfg is a valid setup file. \n\n";
941		exit;
942	}
943
944	if (($pa_config->{"quiet"} == 0) && ($pa_config->{"verbosity"} > 4)) {
945		if ($pa_config->{"pandora_check"} == 1) {
946			print " [*] MD5 Security enabled.\n";
947		}
948		if ($pa_config->{"pandora_master"} != 0) {
949			print " [*] This server is running with MASTER priority " . $pa_config->{"pandora_master"} . "\n";
950		}
951	}
952
953	logger ($pa_config, "Launching $pa_config->{'version'} $pa_config->{'build'}", 1);
954	my $config_options = "Logfile at ".$pa_config->{"logfile"}.", Basepath is ".$pa_config->{"basepath"}.", Checksum is ".$pa_config->{"pandora_check"}.", Master is ".$pa_config->{"pandora_master"}.", SNMP Console is ".$pa_config->{"snmpconsole"}.", Server Threshold at ".$pa_config->{"server_threshold"}." sec, verbosity at ".$pa_config->{"verbosity"}.", Alert Threshold at $pa_config->{'alert_threshold'}, ServerName is '".$pa_config->{'servername'}.$pa_config->{"servermode"}."'";
955	logger ($pa_config, "Config options: $config_options", 1);
956}
957
958
959##########################################################################
960# Open the log file and start logging.
961##########################################################################
962sub pandora_start_log ($){
963	my $pa_config = shift;
964
965	# Dump all errors to errorlog
966	open (STDERR, ">> " . $pa_config->{'errorlogfile'}) or die " [ERROR] Pandora FMS can't write to Errorlog. Aborting : \n $! \n";
967	print STDERR strftime ("%Y-%m-%d %H:%M:%S", localtime()) . ' - ' . $pa_config->{'servername'} . $pa_config->{'servermode'} . " Starting Pandora FMS Server. Error logging activated.\n";
968}
969
970##########################################################################
971# Read the given token from the tconfig table.
972##########################################################################
973sub pandora_get_tconfig_token ($$$) {
974	my ($dbh, $token, $default_value) = @_;
975
976	my $token_value = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = ?", $token);
977	if (defined ($token_value)) {
978		return safe_output ($token_value);
979	}
980
981	return $default_value;
982}
983
984# End of function declaration
985# End of defined Code
986
9871;
988__END__
989