package Rstat::config; # # Copyright (C) Roman Dmitiriev, rnd@rajven.ru # use strict; use English; use FindBin '$Bin'; use lib "$Bin"; use base 'Exporter'; use vars qw(@EXPORT @ISA); use Config::Tiny; use File::Basename; use Data::Dumper; @ISA = qw(Exporter); @EXPORT = qw( $HOME_DIR @FN $MY_NAME $SPID $LOG_DIR $LOG_COMMON $LOG $LOG_ERR $LOG_DEBUG $DHCPD_CONF $BEGIN_STR $END_STR $WARN_MSG $WAIT_TIME $MIN_SLEEP $MAX_SLEEP $admin_email $sender_email $send_email $HOSTNAME $debug $log_enable $log_level $W_INFO $W_ERROR $W_DEBUG $DBHOST $DBNAME $DBUSER $DBPASS $domain_auth $winexe $fping $log_owner_user $log_owner_group $sw_login $sw_password $use_smsd $smsaero_wait $smsd_group $smsd_user $kannel_base_url $kannel_dlr_url $kannel_login $kannel_password $kannel_spool $smsaero_base_url $smsaero_login $smsaero_md5pass $sms_spool_dir $sms_from $smsaero_digital $smsaero_type $smsd_spool_dir $def_timeout $parallel_process_count $save_detail $add_unknown_user $router_ip $dns_server $dhcp_server $snmp_default_version $snmp_default_community $KB $office_networks $hotspot_networks $all_networks @office_network_list @hotspot_network_list @all_network_list $dhcp_pool $mac_discovery $arp_discovery $default_user_id $hotspot_user_id $history $history_dhcp $router_login $router_password $router_port $org_name $domain_name $connections_history $dbh $urgent_sync $ignore_hotspot_dhcp_log $ignore_update_dhcp_event $update_hostname_from_dhcp @subnets %subnets_ref $history_log_day $history_syslog_day $history_trafstat_day $free_networks $vpn_networks @free_network_list @vpn_network_list %config_ref $last_refresh_config ); BEGIN { our $HOME_DIR = dirname($0); my $config_file = $HOME_DIR."/cfg/config"; if (! -e "$config_file") { die "Config $config_file not found!"; } my $Config = Config::Tiny->new; $Config = Config::Tiny->read($config_file, 'utf8' ); #print Dumper($Config); our %config_ref; ### current script pathname our @FN=split("/",$0); ### script pid file name $config_ref{my_name}=$FN[-1]; $config_ref{pid_file}="/var/run/".$FN[-1]; $config_ref{log_dir}=$Config->{_}->{log_dir} || '/var/log/scripts'; $config_ref{log_common}=$config_ref{log_dir}."/$FN[-1].log"; $config_ref{dhcpd_conf}=$Config->{_}->{dhcpd_conf} || "/etc/dnsmasq.d"; $config_ref{DBHOST} = $Config->{_}->{DBSERVER} || '127.0.0.1'; $config_ref{DBNAME} = $Config->{_}->{DBNAME} || "stat"; $config_ref{DBUSER} = $Config->{_}->{DBUSER} || "rstat"; $config_ref{DBPASS} = $Config->{_}->{DBPASS} || "rstat"; $config_ref{domain_auth}= $Config->{_}->{domain_auth} || 'Administrator%password'; $config_ref{winexe} = $Config->{_}->{winexe} || '/usr/bin/winexe'; $config_ref{fping} = $Config->{_}->{fping} || '/sbin/fping'; $config_ref{log_owner_user}= $Config->{_}->{user} || 'nagios'; $config_ref{log_owner_group}= $Config->{_}->{group} || 'nagios'; $config_ref{sw_login}=$Config->{_}->{sw_login} || 'admin'; $config_ref{sw_password}=$Config->{_}->{sw_password} || 'admin'; our $MY_NAME=$FN[-1]; our $SPID="/var/run/".$FN[-1]; #iptables log our $LOG_DIR = $Config->{_}->{log_dir} || '/var/log/scripts'; our $LOG_COMMON = "$LOG_DIR/$FN[-1].log"; our $LOG = $LOG_COMMON; our $LOG_ERR = $LOG_COMMON; our $LOG_DEBUG = $LOG_COMMON; our $DHCPD_CONF = $Config->{_}->{dhcpd_conf} || "/etc/dnsmasq.d"; our $BEGIN_STR ="================= Start transaction ========================"; our $END_STR ="================= Stop transaction ========================"; our $WARN_MSG ="# DYNAMIC GENERATED FILE\n# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN\n"; ### timeout for wait remove lock before exit our $WAIT_TIME =600; our $MIN_SLEEP =5; our $MAX_SLEEP =30; ### mail options our $admin_email; our $sender_email; our $send_email = 0; my $HOSTNAME1=`hostname`; chomp($HOSTNAME1); our $HOSTNAME=$HOSTNAME1; ### debug our $debug=1; our $log_enable = 1; our $log_level = 2; our $W_INFO = 0; our $W_ERROR = 1; our $W_DEBUG = 2; our $DBHOST = $Config->{_}->{DBSERVER} || '127.0.0.1'; our $DBNAME = $Config->{_}->{DBNAME} || "stat"; our $DBUSER = $Config->{_}->{DBUSER} || "rstat"; our $DBPASS = $Config->{_}->{DBPASS} || "rstat"; our $domain_auth = $Config->{_}->{domain_auth} || 'Administrator%password'; our $winexe = $Config->{_}->{winexe} || '/usr/bin/winexe'; our $fping = $Config->{_}->{fping} || '/sbin/fping'; our @subnets=(); our $history_log_day; our $history_syslog_day; our $history_trafstat_day; our $log_owner_user = $Config->{_}->{user} || 'nagios'; our $log_owner_group = $Config->{_}->{group} || 'nagios'; ############### Switch Access ############## our $sw_login=$Config->{_}->{sw_login} || 'admin'; our $sw_password=$Config->{_}->{sw_password} || 'admin'; ################################################################ our $def_timeout = 90; our $parallel_process_count = 10; ################## DB options ################################## our $save_detail; our $add_unknown_user; our $router_ip; our $dns_server; our $dhcp_server; our $snmp_default_version; our $snmp_default_community; our $KB; our $office_networks; our $hotspot_networks; our $all_networks; our @office_network_list; our @hotspot_network_list; our @all_network_list; our $free_networks; our $vpn_networks; our @free_network_list; our @vpn_network_list; our $dhcp_pool; our $mac_discovery; our $arp_discovery; our $default_user_id; our $hotspot_user_id; our $history; our $history_dhcp; our $router_login; our $router_password; our $router_port; our $org_name; our $domain_name; our $connections_history; our $dbh; our $urgent_sync = 0; our $last_refresh_config = time(); mkdir $LOG_DIR unless (-d $LOG_DIR); 1; }