#!/usr/bin/perl -X
use DBI;					
use Socket;
use Data::Dumper;
use Getopt::Long;
use Archive::Tar;				
use Term::ANSIColor qw(:constants);	
use POSIX qw(strftime mktime ceil locale_h);
use Cwd;					
use Config::IniFiles;			
use Net::OpenSSH;				
use Date::Parse;				
use LWP::UserAgent;			
use Time::Local;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use Time::HiRes qw(gettimeofday);
use HTTP::Request::Common;
use HTTP::Cookies;
use Switch;
use JSON qw(decode_json);			
use Mail::Sender;
use Email::MessageID;
use MIME::QuotedPrint;
 my $p_name = "Backup Network Devices"; my $p_short = "BNDevices"; my $p_nn = "backupNetworkDevices"; my $p_nntest = "BackupNetworkDevices"; my $p_version = "5.1.0"; my $p_data = "24.09.2016"; my $p_for = "MikroTik RouterOS v3.xx, v4.xx, v5.xx, v6.xx|Ubiquiti IEEE802.11a/b/g Solutions, airMAX ISP Solutions, airFiber|TP-Link|Linksys|DD-WRT"; my $p_lang = "pl_PL"; my $iniCONF = (); my $iniLANG = (); my $iniPath = (); my $iniLOGIN = (); my $tmpLOGIN = (); my $START = time(); my $logSend = ""; my $devsListWWW; my %options = ( "--quiet|q"			=> \my $argQuiet, "--help|h|?"		=> \my $argHelp, "--version|v"		=> \my $argVersion, "--new|n"			=> \my $argNew, "--debug|d"			=> \my $argDebug, "--kill:i"			=> \my $argKill, "--config-file|C=s"	=> \my $argConfigFile, "--database|db=s"		=> \my $argDB,			 "--lms-stations|ls"	=> \my $argLmsStations, "--lms-customers|lk|lc"	=> \my $argLmsCustomer, "--ini-file|I=s"		=> \my $argIniFile, "--lms-config|L=s"	=> \my $argLmsConfig, "--omsystem-config|O=s"	=> \my $argOMSystemConfig, "--run|r=s"			=> \my $argRun, "--norun|nr=s"		=> \my $argNoRun, "--showpassword|sp"	=> \my $argShowPassword, ); Getopt::Long::config("no_ignore_case"); GetOptions(%options) or exit; $argDB = $argDB || "ini"; $argConfigFile = path($argConfigFile) || "/opt/$p_nn/config.ini";   if(!(-f $argConfigFile) and $argConfigFile) { my $log = "File do not exist - ".$argConfigFile;    if(!$argQuiet) { print "\n   "; print RED, "error! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; } exit 1;   } elsif(!(-r $argConfigFile) and $argConfigFile) { my $log = "Unable to read file - ".$argConfigFile;    if(!$argQuiet) { print "\n   "; print RED, "error! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; } exit 1;   } else { $iniCONF = new Config::IniFiles -file => $argConfigFile; my @err = @Config::IniFiles::errors;    if(@err) { my $log = @err[0]." - ".$argConfigFile;    if(!$argQuiet) { print "\n   "; print RED, "error! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; } exit 1;    }   } my $lang = getVal('config', 'lang', $iniCONF) || $p_lang; my @la = split(/\_/, $lang); $lang = lc($la[0])."_".uc($la[1]);   if(!($lang =~ /^\w+\_\w+$/) and $lang) {  my $log = lang("error", "incorrect_val", $argConfigFile, "config", "lang", "$p_lang ...");    if(!$argQuiet) { print "\n   "; print RED, "error! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }  exit 1;   } my $configLang = path("./lang/$lang.ini");   if(!(-f $configLang) and $configLang) { my $log = "File do not exist - ".$configLang;    if(!$argQuiet) { print "\n   "; print RED, "error! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; } exit 1;   } elsif(!(-r $configLang) and $configLang) { my $log = "Unable to read file - ".$configLang;    if(!$argQuiet) { print "\n   "; print RED, "error! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; } exit 1;   } else { $iniLANG = new Config::IniFiles -file => $configLang; my @err = @Config::IniFiles::errors;    if(@err) { my $log = @err[0]." - ".$configLang;    if(!$argQuiet) { print "\n   "; print RED, "error! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; } exit 1;    }   } my $devicesPathFile = "/opt/$p_nn/devicesPaths.ini";   if(!(-f $devicesPathFile)) { my $log = "File do not exist - ".$devicesPathFile;    if(!$argQuiet) { print "\n   "; print RED, "error! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; } exit 1;   } elsif(!(-r $devicesPathFile)) { my $log = "Unable to read file - ".$devicesPathFile;    if(!$argQuiet) { print "\n   "; print RED, "error! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; } exit 1;   } else { $iniPath = new Config::IniFiles -file => $devicesPathFile; my @err = @Config::IniFiles::errors;    if(@err) { my $log = @err[0]." - ".$devicesPathFile;    if(!$argQuiet) { print "\n   "; print RED, "error! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; } exit 1;    }    foreach my $d (@{$iniPath->{'sects'}}) { if(getVal($d, 'protocol', $iniPath) eq "www") { $devsListWWW .= $d."|";  } } $devsListWWW =~ s/\|$//g;   }   if($argHelp){ print " $p_name, ".lang("other", 'version')." v$p_version [$p_data]\n"; print "  ".lang("other", 'for').":\n"; foreach my $o (split(/\|/, $p_for)) { print "    - ".$o."\n"; } print "  ".lang("other", 'author').": seszu (seba\@kazuko.pl)\n"; print "  ".lang("other", 'page').": http://kazuko.pl\n"; print "\n"; print "-q,   -?, --quiet				".lang("arg", 'quiet')."\n"; print "-h,       --help				".lang("arg", 'help')."\n"; print "-v,       --version				".lang("arg", 'version')."\n"; print "-n,       --new					".lang("arg", 'new')."\n"; print "-d,       --debug				".lang("arg", 'debug')."\n"; print "          --kill=30				".lang("arg", 'kill', '30')."\n"; print "-C,       --config-file='/path/config.ini'	".lang("arg", 'config-file', '/opt/'.$p_nn.'/config.ini')."\n"; print "-db,      --database=[ini|lms|elms|omsystem]	".lang("arg", 'database')."\n"; print "-ls,      --lms-stations			".lang("arg", 'lms-stations')."\n"; print "-lc, -lk, --lms-customers			".lang("arg", 'lms-customers')."\n"; print "-I,       --ini-file='/path/baseDevices.ini'	".lang("arg", 'ini-file', '/opt/'.$p_nn.'/baseDevices.ini')."\n"; print "-L,       --lms-config='/path/lms.ini'		".lang("arg", 'lms-config', '/etc/lms/lms.ini')."\n"; print "-O,       --omsystem-file='/path/config.ini'	".lang("arg", 'omsystem-file', '/opt/omsystem/config.ini')."\n"; print "-r,       --run='1.1.1.1 2.2.2.2'		".lang("arg", 'run')."\n"; print "-nr,      --norun='1.1.1.1 2.2.2.2'		".lang("arg", 'norun')."\n"; print "-sp,      --showpassword			".lang("arg", 'showpassword')."\n"; print "\n"; exit 1;   }   if($argVersion) { print " $p_name, ".lang("other", 'version')." v$p_version [$p_data]\n"; print "  ".lang("other", 'for')."\n"; foreach my $o (split(/\|/, $p_for)) { print "    - ".$o."\n"; } print "  ".lang("other", 'author').": seszu (seba\@kazuko.pl)\n"; print "  ".lang("other", 'page').": http://kazuko.pl\n"; print "\n"; exit 1;   }   if($argNew) { print " $p_name, ".lang("other", 'version')." v$p_version [$p_data]\n"; print "  ".lang("other", 'author').": seszu (seba\@kazuko.pl)\n"; print "\n\n"; vTest("http://script.kazuko.pl", $p_nntest); print "\n"; exit 1;   }   if(!(($argDB =~ /^(lms|elms|omsystem)$/ and ($argLmsStations || $argLmsCustomer)) || $argDB eq "ini")) { print " $p_name, ".lang("other", 'version')." v$p_version\n"; print "\n"; print "-db,      --database=[ini|lms|elms|omsystem]	\n"; print "-ls,      --lms-stations			".lang("arg", 'lms-stations')."\n"; print "-lc, -lk, --lms-customers			".lang("arg", 'lms-customers')."\n"; print "\n"; exit 1;   }   if($argDebug) { $argQuiet = 1; print " $p_name v$p_version\n"; print "   CTRL+C - ".lang("other", 'cancel')."\n"; print "\n      "; print BOLD MAGENTA, lang("other", 'vdebug'), RESET; print "\n";   }    if(!$argQuiet) { print " $p_name v$p_version\n"; print "   CTRL+C - ".lang("other", 'cancel')."\n";   }   if($argKill eq "0") { killprog($0, 30); } elsif($argKill) { killprog($0, $argKill); } my $LangYes = lang("other", 'yes') || "yes"; my $LangNo = lang("other", 'no') || "no"; my $LangError = lang("other", 'error') || "error"; my $LangOK = lang("other", 'ok') || "ok"; my $logs = getVal('config', 'logs', $iniCONF) || "no"; my $logsDir = path(getVal('config', 'logs-dir', $iniCONF)) || "/opt/$p_nn/log"; my $logsDirT = getVal('config', 'logs-dir', $iniCONF) || "/opt/$p_nn/log"; my $logsWhat = getVal('config', 'logs-what', $iniCONF) || "all"; my $hpingBinary = path(getVal('config', 'hping-binary', $iniCONF)) || "/usr/sbin/hping3"; my $pingBinary = path(getVal('config', 'ping-binary', $iniCONF)) || "/bin/ping"; my $pingCount = getVal('config', 'ping-count', $iniCONF) || "3"; my $hpingCount = getVal('config', 'hping-count', $iniCONF) || "3"; my $interface = getVal('config', 'interface', $iniCONF) || ""; my $chmod = getVal('config', 'chmod', $iniCONF) || "0755"; my $chown = getVal('config', 'chown', $iniCONF) || '%user%:%group%'; my $limitBackup = getVal('config', 'limit-backup', $iniCONF) || '5M'; my $limitBajty = toBajt($limitBackup); my $mtRscVerbose = getVal('config', 'mt-rsc-verbose', $iniCONF) || 'no'; my $sshAttemptKill = getVal('config', 'ssh-attempt-kill', $iniCONF) || '5'; my $lmsIdNum = getVal('config', 'lms-id-num', $iniCONF) || '4'; my $sendLogs = getVal('send-logs', 'send-logs', $iniCONF) || "no"; my $sendLogsWhat = getVal('send-logs', 'logs-what', $iniCONF) || "all"; my $toMail = getVal('send-logs', 'to-mail', $iniCONF) || ""; my $fromMail = getVal('send-logs', 'from-mail', $iniCONF) || ""; my $smtpLogin = getVal('send-logs', 'smtp-login', $iniCONF) || ""; my $smtpPassword = getVal('send-logs', 'smtp-password', $iniCONF) || ""; my $smtpHost = getVal('send-logs', 'smtp-host', $iniCONF) || ""; my $smtpPort = getVal('send-logs', 'smtp-port', $iniCONF) || "587"; my $smtpAuth = getVal('send-logs', 'smtp-auth', $iniCONF) || "PLAIN";   if(!($logs =~ /^($LangYes|yes|$LangNo|no)$/) and $logs) {  my $log = lang("error", "incorrect_val", $argConfigFile, "config", "logs", "$LangYes|$LangNo|yes|no");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }  exit 1;   }   if(ziro($logs)) {    if(!(-d usunWWyr($logsDirT)) and $logsDirT and ziro($logs)) { my $log = lang("error", "dir_does_not_exist", $logsDirT, $argConfigFile, "config", "logs-dir");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }  exit 1;    } elsif(!(-w usunWWyr($logsDirT)) and $logsDirT and ziro($logs)) { my $log = lang("error", "lack_of_access", $logsDirT, $argConfigFile, "config", "logs-dir");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }  exit 1;    }    if(!($logsWhat =~ /^(done|error|all)$/) and $logsWhat) {  my $log = lang("error", "incorrect_val", $argConfigFile, "config", "logs-what", "done|error|all");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }  exit 1;    }   }   if(!(-f $pingBinary) and $pingBinary) { my $log = lang("error", "file_does_not_exist", $pingBinary, $argConfigFile, "config", "ping-binary");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   } elsif(!(-r $pingBinary) and $pingBinary) { my $log = lang("error", "lack_of_access", $pingBinary, $argConfigFile, "config", "ping-binary");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   }   if(!(-f $hpingBinary) and $hpingBinary) { my $log = lang("error", "file_does_not_exist", $hpingBinary, $argConfigFile, "config", "hping-binary");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   } elsif(!(-r $hpingBinary) and $hpingBinary) { my $log = lang("error", "lack_of_access", $hpingBinary, $argConfigFile, "config", "hping-binary");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   }   if(!($pingCount =~ /^\d+$/) and $pingCount) {  my $log = lang("error", "incorrect_val", $argConfigFile, "config", "ping-count", lang("error", "only_number"));    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   }   if(!($hpingCount =~ /^\d+$/) and $hpingCount) {  my $log = lang("error", "incorrect_val", $argConfigFile, "config", "hping-count", lang("error", "only_number"));    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   }   if($interface) { my $ifconfig = qx(ifconfig $interface 2>> /dev/null);    if(!$ifconfig) { my $log = lang("error", "no_interface", $interface, $argConfigFile, "config", "interface");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    }   }   if(!($chmod =~ /^\d+$/) and $chmod) {  my $log = lang("error", "incorrect_val", $argConfigFile, "config", "chmod", lang("error", "only_number"));    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   }   if(!($chown =~ /^.+\:.+$/) and $chown) {  my $log = lang("error", "incorrect_val", $argConfigFile, "config", "chown", "user:group ".lang("other", "or")." uid:gid");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   }   if(!($limitBackup =~ /^[0-9]*[k|K|m|M|g|G|t|T]?$/)) { my $log = lang("error", "incorrect_val", $argConfigFile, "config", "limit-backup", "5[k|K|m|M|g|G|t|T]");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "\n\n"; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   }   if(!($sshAttemptKill =~ /^\d+$/) and $sshAttemptKill) {  my $log = lang("error", "incorrect_val", $argConfigFile, "config", "ssh-attempt-kill", lang("error", "only_number"));    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   }   if(!($lmsIdNum =~ /^\d+$/) and $lmsIdNum) {  my $log = lang("error", "incorrect_val", $argConfigFile, "config", "lms-id-num", lang("error", "only_number"));    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   }   if(!($argDB =~ /^(ini|lms|elms|omsystem)$/) and $argDB) {  my $log = lang("error", "incorrect_val_arg", $database, "ini|lms|elms|omsystem");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   }   if(!($sendLogs =~ /^($LangYes|yes|$LangNo|no)$/) and $sendLogs) { my $log = lang("error", "incorrect_val", $argConfigFile, "send-logs", "send-logs", "$LangYes|$LangNo|yes|no");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;   }   if(ziro($sendLogs)) {    if(!($sendLogsWhat =~ /^(done|error|all)$/) and $sendLogsWhat) {  my $log = lang("error", "incorrect_val", $argConfigFile, "send-logs", "logs-what", "done|error|all");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    }    if(!$toMail) {  my $log = lang("error", "empty_val", $argConfigFile, "send-logs", "to-mail");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    } elsif(!($toMail =~ /^.+\@.+\..+$/)) { my $log = lang("error", "mail_val", $argConfigFile, "send-logs", "to-mail");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    }    if(!$fromMail) {  my $log = lang("error", "empty_val", $argConfigFile, "send-logs", "from-mail");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    } elsif(!($fromMail =~ /^.+\@.+\..+$/)) { my $log = lang("error", "mail_val", $argConfigFile, "send-logs", "from-mail");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    }    if(!$smtpLogin) {  my $log = lang("error", "empty_val", $argConfigFile, "send-logs", "smtp-login");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    }    if(!$smtpPassword) {  my $log = lang("error", "empty_val", $argConfigFile, "send-logs", "smtp-password");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    }    if(!$smtpHost) {  my $log = lang("error", "empty_val", $argConfigFile, "send-logs", "smtp-host");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    }    if(!($smtpPort =~ /^\d+$/) and $smtpPort) {  my $log = lang("error", "incorrect_val", $argConfigFile, "send-logs", "smtp-port", lang("error", "only_number"));    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    }    if(!($smtpAuth =~ /^(LOGIN|PLAIN)$/) and $smtpAuth) {  my $log = lang("error", "incorrect_val", $argConfigFile, "send-logs", "smtp-auth", "LOGIN|PLAIN");    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    }   } my $LoginFile = "/opt/$p_nn/tmp/login.ini";   if(-f $LoginFile) { $iniLOGIN = new Config::IniFiles -file => $LoginFile; $tmpLOGIN = $iniLOGIN->{'v'}; my @err = @Config::IniFiles::errors;   } my $listALL = join("|",split(/[|,:\s]/, $argRun)); my $listNoALL = join("|",split(/[|,:\s]/, $argNoRun)); my %hostHASH = ();   if($argDB eq "ini") { $listALL = "|$listALL|"; $listNoALL = "|$listNoALL|"; $argIniFile = path($argIniFile) || "/opt/$p_nn/baseDevices.ini";    if(!(-f $argIniFile) and $argIniFile) { my $log = lang("error", "file_base_does_not_exist", $argIniFile);    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    } elsif(!(-r $argIniFile) and $argIniFile) { my $log = lang("error", "file_base_can_not_read", $argIniFile);    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    } else { my $iniBAZ = new Config::IniFiles -file => $argIniFile; my @err = @Config::IniFiles::errors;    if(@err) { my $log = @err[0]." - ".$argIniFile;    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    }    foreach my $li ($iniBAZ->Sections()) { if($li) { my @liArr = $iniBAZ->{v}{$li}; my $liHost = delHash($liArr[0]{'host'});	    if(((($listALL) =~ /\|$liHost\|/ and $argRun) or (($listALL) =~ /\|$li\|/ and $argRun)  or (($liHost =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}$/ or $liHost =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ or $liHost =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\-\d{1,3}$/ or $liHost =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ or $liHost =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.*$/) and $argRun) or !$argRun) and !((($listNoALL) =~ /\|$liHost\|/ and $listNoALL) or (($listNoALL) =~ /\|$li\|/ and $listNoALL))  ) { my @arr = $iniBAZ->{v}{$li}; $arr[0]{'value'} = $li;	 $arr[0]{'name'} = delHash($arr[0]{'name'}) || '%value%'; $arr[0]{'protocol'} = delHash($arr[0]{'protocol'}) || delHash($arr[0]{'log-in'}) || 'auto'; $arr[0]{'host'} = delHash($arr[0]{'host'}); $arr[0]{'ssh-port'} = delHash($arr[0]{'ssh-port'}) || '22'; $arr[0]{'ssh-login'} = delHash($arr[0]{'ssh-login'}) || 'admin'; $arr[0]{'ssh-password'} = delHash($arr[0]{'ssh-password'}) || '';		 $arr[0]{'ssh-key'} = delHash($arr[0]{'ssh-key'}) || 'no'; $arr[0]{'ssh-keydsa'} = path(delHash($arr[0]{'ssh-keydsa'})) || path("~/.ssh/id_dsa"); $arr[0]{'ssh-keypassword'} = delHash($arr[0]{'ssh-keypassword'}) || ''; $arr[0]{'ssh-attempt-kill'} = delHash($arr[0]{'ssh-attempt-kill'}) || $sshAttemptKill || '5'; $arr[0]{'www-port'} = delHash($arr[0]{'www-port'}) || '80'; $arr[0]{'www-login'} = delHash($arr[0]{'www-login'}) || 'admin'; $arr[0]{'www-password'} = delHash($arr[0]{'www-password'}) || 'admin';		 $arr[0]{'path'} = path(delHash($arr[0]{'path'})) || '/opt/'.$p_nn.'/backups'; $arr[0]{'overwrite'} = delHash($arr[0]{'overwrite'}) || 'no'; $arr[0]{'mt-backup'} = delHash($arr[0]{'mt-backup'}) || delHash($arr[0]{'backup'}) || 'all'; $arr[0]{'mt-encrypt'} = delHash($arr[0]{'mt-encrypt'}) || 'no'; $arr[0]{'mt-enpassword'} = delHash($arr[0]{'mt-enpassword'}) || ''; $arr[0]{'mt-rsc-verbose'} = delHash($arr[0]{'mt-rsc-verbose'}) || $mtRscVerbose || 'no'; $arr[0]{'ssh-port'} = podmien($arr[0]{'ssh-port'}, @arr); $arr[0]{'ssh-login'} = podmien($arr[0]{'ssh-login'}, @arr); $arr[0]{'ssh-password'} = podmien($arr[0]{'ssh-password'}, @arr); $arr[0]{'www-port'} = podmien($arr[0]{'www-port'}, @arr); $arr[0]{'www-login'} = podmien($arr[0]{'www-login'}, @arr); $arr[0]{'www-password'} = podmien($arr[0]{'www-password'}, @arr);    foreach my $cch (split(/\s/, $arr[0]{'ssh-port'})) { $cch = delQuotes($cch);  $arr[0]{'ssh-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-login'})) { $cch = delQuotes($cch);  $arr[0]{'ssh-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-password'})) { $cch = delQuotes($cch); $arr[0]{'ssh-password-hash'}{md5_hex($cch)} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-port'})) { $cch = delQuotes($cch);  $arr[0]{'wwww-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-login'})) { $cch = delQuotes($cch);  $arr[0]{'wwww-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-password'})) { $cch = delQuotes($cch); $arr[0]{'wwww-password-hash'}{md5_hex($cch)} = $cch; }    if($arr[0]{'host'} =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}$/) { my @siec = split(/\//, $arr[0]{'host'}); my $cidr = @siec[1]; my $ileIP = ((2**(32-$cidr))-2); my $adressLong = ip2long(@siec[0]);    for ($n = 1; $n <= $ileIP; $n++) { my @ary = (); $ary[0]{'value'} = long2ip($adressLong+$n); $ary[0]{'name'} = $arr[0]{'name'}; $ary[0]{'protocol'} = $arr[0]{'protocol'}; $ary[0]{'host'} = $ary[0]{'value'};    if(((($listALL) =~ /\|$ary[0]{'value'}\|/ and $argRun) or (($listALL) =~ /\|$li\|/ and $argRun) or (($listALL) =~ /\|$arr[0]{'host'}\|/ and $argRun) or !$argRun) and !((($listNoALL) =~ /\|$ary[0]{'value'}\|/ and $listNoALL) or (($listNoALL) =~ /\|$li\|/ and $listNoALL))) {    foreach my $cch (split(/\s/, $arr[0]{'ssh-port'})) { $cch = delQuotes($cch);  $ary[0]{'ssh-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-login'})) { $cch = delQuotes($cch);  $ary[0]{'ssh-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-password'})) { $cch = delQuotes($cch); $ary[0]{'ssh-password-hash'}{md5_hex($cch)} = $cch; } $ary[0]{'ssh-key'} = $arr[0]{'ssh-key'}; $ary[0]{'ssh-keydsa'} = $arr[0]{'ssh-keydsa'}; $ary[0]{'ssh-keypassword'} = $arr[0]{'ssh-keypassword'}; $ary[0]{'ssh-attempt-kill'} = $arr[0]{'ssh-attempt-kill'};    foreach my $cch (split(/\s/, $arr[0]{'wwww-port'})) { $cch = delQuotes($cch);  $ary[0]{'wwww-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-login'})) { $cch = delQuotes($cch);  $ary[0]{'wwww-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-password'})) { $cch = delQuotes($cch); $ary[0]{'wwww-password-hash'}{md5_hex($cch)} = $cch; } $ary[0]{'path'} = $arr[0]{'path'}; $ary[0]{'overwrite'} = $arr[0]{'overwrite'}; $ary[0]{'mt-backup'} = $arr[0]{'mt-backup'}; $ary[0]{'mt-encrypt'} = $arr[0]{'mt-encrypt'}; $ary[0]{'mt-enpassword'} = $arr[0]{'mt-enpassword'}; $ary[0]{'mt-rsc-verbose'} = $arr[0]{'mt-rsc-verbose'};    if($iniLOGIN->{'_read_line_num'}) { $ary[0]{'done-port'} = $iniLOGIN->val($ary[0]{'host'}, 'port'); $ary[0]{'done-login'} = $iniLOGIN->val($ary[0]{'host'}, 'login'); $ary[0]{'done-password'} = $iniLOGIN->val($ary[0]{'host'}, 'password'); $ary[0]{'done-protocol'} = $iniLOGIN->val($ary[0]{'host'}, 'protocol'); $ary[0]{'done-device'} = $iniLOGIN->val($ary[0]{'host'}, 'device');    } $listALL =~ s/\|$ary[0]{'value'}\|//g;		 $listALL =~ s/\|$ary[0]{'host'}\|//g;    if(!($listALL =~ /^\|.*$/)) { $listALL = "|".$listALL; }    if(!($listALL =~ /^.*\|$/)) { $listALL = $listALL."|"; } my %hos = (($adressLong+$n) => @ary); %hostHASH = (%hostHASH, %hos);    }    }    } elsif($arr[0]{'host'} =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { my @siec = split(/\//, $arr[0]{'host'}); my $cidr = mask2cidr(@siec[1]); my $ileIP = ((2**(32-$cidr))-2); my $adressLong = ip2long(@siec[0]);    for ($n = 1; $n <= $ileIP; $n++) { my @ary = (); $ary[0]{'value'} = long2ip($adressLong+$n); $ary[0]{'name'} = $arr[0]{'name'}; $ary[0]{'protocol'} = $arr[0]{'protocol'}; $ary[0]{'host'} = $ary[0]{'value'};    if(((($listALL) =~ /\|$ary[0]{'value'}\|/ and $argRun) or (($listALL) =~ /\|$li\|/ and $argRun) or (($listALL) =~ /\|$arr[0]{'host'}\|/ and $argRun) or !$argRun) and !((($listNoALL) =~ /\|$ary[0]{'value'}\|/ and $listNoALL) or (($listNoALL) =~ /\|$li\|/ and $listNoALL))) {    foreach my $cch (split(/\s/, $arr[0]{'ssh-port'})) { $cch = delQuotes($cch);  $ary[0]{'ssh-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-login'})) { $cch = delQuotes($cch);  $ary[0]{'ssh-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-password'})) { $cch = delQuotes($cch); $ary[0]{'ssh-password-hash'}{md5_hex($cch)} = $cch; } $ary[0]{'ssh-key'} = $arr[0]{'ssh-key'}; $ary[0]{'ssh-keydsa'} = $arr[0]{'ssh-keydsa'}; $ary[0]{'ssh-keypassword'} = $arr[0]{'ssh-keypassword'}; $ary[0]{'ssh-attempt-kill'} = $arr[0]{'ssh-attempt-kill'};    foreach my $cch (split(/\s/, $arr[0]{'wwww-port'})) { $cch = delQuotes($cch);  $ary[0]{'wwww-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-login'})) { $cch = delQuotes($cch);  $ary[0]{'wwww-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-password'})) { $cch = delQuotes($cch); $ary[0]{'wwww-password-hash'}{md5_hex($cch)} = $cch; } $ary[0]{'path'} = $arr[0]{'path'}; $ary[0]{'overwrite'} = $arr[0]{'overwrite'}; $ary[0]{'mt-backup'} = $arr[0]{'mt-backup'}; $ary[0]{'mt-encrypt'} = $arr[0]{'mt-encrypt'}; $ary[0]{'mt-enpassword'} = $arr[0]{'mt-enpassword'}; $ary[0]{'mt-rsc-verbose'} = $arr[0]{'mt-rsc-verbose'};    if($iniLOGIN->{'_read_line_num'}) { $ary[0]{'done-port'} = $iniLOGIN->val($ary[0]{'host'}, 'port'); $ary[0]{'done-login'} = $iniLOGIN->val($ary[0]{'host'}, 'login'); $ary[0]{'done-password'} = $iniLOGIN->val($ary[0]{'host'}, 'password'); $ary[0]{'done-protocol'} = $iniLOGIN->val($ary[0]{'host'}, 'protocol'); $ary[0]{'done-device'} = $iniLOGIN->val($ary[0]{'host'}, 'device');    } $listALL =~ s/\|$ary[0]{'value'}\|//g;		 $listALL =~ s/\|$ary[0]{'host'}\|//g;    if(!($listALL =~ /^\|.*$/)) { $listALL = "|".$listALL; }    if(!($listALL =~ /^.*\|$/)) { $listALL = $listALL."|"; } my %hos = (($adressLong+$n) => @ary); %hostHASH = (%hostHASH, %hos);    }    }    } elsif($arr[0]{'host'} =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\-\d{1,3}$/) { my @siec = split(/\-/, $arr[0]{'host'}); my @IP0 = split(/\./, @siec[0]); my $adressLong = ip2long(@siec[0]);    for ($n = 0; $n <= ((@siec[1]-@IP0[3])); $n++) { my @ary = (); $ary[0]{'value'} = long2ip($adressLong+$n); $ary[0]{'name'} = $arr[0]{'name'}; $ary[0]{'protocol'} = $arr[0]{'protocol'}; $ary[0]{'host'} = $ary[0]{'value'};    if(((($listALL) =~ /\|$ary[0]{'value'}\|/ and $argRun) or (($listALL) =~ /\|$li\|/ and $argRun) or (($listALL) =~ /\|$arr[0]{'host'}\|/ and $argRun) or !$argRun) and !((($listNoALL) =~ /\|$ary[0]{'value'}\|/ and $listNoALL) or (($listNoALL) =~ /\|$li\|/ and $listNoALL))) {    foreach my $cch (split(/\s/, $arr[0]{'ssh-port'})) { $cch = delQuotes($cch);  $ary[0]{'ssh-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-login'})) { $cch = delQuotes($cch);  $ary[0]{'ssh-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-password'})) { $cch = delQuotes($cch); $ary[0]{'ssh-password-hash'}{md5_hex($cch)} = $cch; } $ary[0]{'ssh-key'} = $arr[0]{'ssh-key'}; $ary[0]{'ssh-keydsa'} = $arr[0]{'ssh-keydsa'}; $ary[0]{'ssh-keypassword'} = $arr[0]{'ssh-keypassword'}; $ary[0]{'ssh-attempt-kill'} = $arr[0]{'ssh-attempt-kill'};    foreach my $cch (split(/\s/, $arr[0]{'wwww-port'})) { $cch = delQuotes($cch);  $ary[0]{'wwww-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-login'})) { $cch = delQuotes($cch);  $ary[0]{'wwww-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-password'})) { $cch = delQuotes($cch); $ary[0]{'wwww-password-hash'}{md5_hex($cch)} = $cch; } $ary[0]{'path'} = $arr[0]{'path'}; $ary[0]{'overwrite'} = $arr[0]{'overwrite'}; $ary[0]{'mt-backup'} = $arr[0]{'mt-backup'}; $ary[0]{'mt-encrypt'} = $arr[0]{'mt-encrypt'}; $ary[0]{'mt-enpassword'} = $arr[0]{'mt-enpassword'}; $ary[0]{'mt-rsc-verbose'} = $arr[0]{'mt-rsc-verbose'};    if($iniLOGIN->{'_read_line_num'}) { $ary[0]{'done-port'} = $iniLOGIN->val($ary[0]{'host'}, 'port'); $ary[0]{'done-login'} = $iniLOGIN->val($ary[0]{'host'}, 'login'); $ary[0]{'done-password'} = $iniLOGIN->val($ary[0]{'host'}, 'password'); $ary[0]{'done-protocol'} = $iniLOGIN->val($ary[0]{'host'}, 'protocol'); $ary[0]{'done-device'} = $iniLOGIN->val($ary[0]{'host'}, 'device');    } $listALL =~ s/\|$ary[0]{'value'}\|//g;		 $listALL =~ s/\|$ary[0]{'host'}\|//g;    if(!($listALL =~ /^\|.*$/)) { $listALL = "|".$listALL; }    if(!($listALL =~ /^.*\|$/)) { $listALL = $listALL."|"; } my %hos = (($adressLong+$n) => @ary); %hostHASH = (%hostHASH, %hos);    }    }    } elsif($arr[0]{'host'} =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { my @siec = split(/\-/, $arr[0]{'host'}); my $adressLong0 = ip2long(@siec[0]); my $adressLong1 = ip2long(@siec[1]);    for ($n = 0; $n <= (($adressLong1-$adressLong0)); $n++) { my @ary = (); $ary[0]{'value'} = long2ip($adressLong0+$n); $ary[0]{'name'} = $arr[0]{'name'}; $ary[0]{'protocol'} = $arr[0]{'protocol'}; $ary[0]{'host'} = $ary[0]{'value'};    if(((($listALL) =~ /\|$ary[0]{'value'}\|/ and $argRun) or (($listALL) =~ /\|$li\|/ and $argRun) or (($listALL) =~ /\|$arr[0]{'host'}\|/ and $argRun) or !$argRun) and !((($listNoALL) =~ /\|$ary[0]{'value'}\|/ and $listNoALL) or (($listNoALL) =~ /\|$li\|/ and $listNoALL))) {    foreach my $cch (split(/\s/, $arr[0]{'ssh-port'})) { $cch = delQuotes($cch);  $ary[0]{'ssh-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-login'})) { $cch = delQuotes($cch);  $ary[0]{'ssh-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-password'})) { $cch = delQuotes($cch); $ary[0]{'ssh-password-hash'}{md5_hex($cch)} = $cch; } $ary[0]{'ssh-key'} = $arr[0]{'ssh-key'}; $ary[0]{'ssh-keydsa'} = $arr[0]{'ssh-keydsa'}; $ary[0]{'ssh-keypassword'} = $arr[0]{'ssh-keypassword'}; $ary[0]{'ssh-attempt-kill'} = $arr[0]{'ssh-attempt-kill'};    foreach my $cch (split(/\s/, $arr[0]{'wwww-port'})) { $cch = delQuotes($cch);  $ary[0]{'wwww-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-login'})) { $cch = delQuotes($cch);  $ary[0]{'wwww-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-password'})) { $cch = delQuotes($cch); $ary[0]{'wwww-password-hash'}{md5_hex($cch)} = $cch; } $ary[0]{'path'} = $arr[0]{'path'}; $ary[0]{'overwrite'} = $arr[0]{'overwrite'}; $ary[0]{'mt-backup'} = $arr[0]{'mt-backup'}; $ary[0]{'mt-encrypt'} = $arr[0]{'mt-encrypt'}; $ary[0]{'mt-enpassword'} = $arr[0]{'mt-enpassword'}; $ary[0]{'mt-rsc-verbose'} = $arr[0]{'mt-rsc-verbose'};    if($iniLOGIN->{'_read_line_num'}) { $ary[0]{'done-port'} = $iniLOGIN->val($ary[0]{'host'}, 'port'); $ary[0]{'done-login'} = $iniLOGIN->val($ary[0]{'host'}, 'login'); $ary[0]{'done-password'} = $iniLOGIN->val($ary[0]{'host'}, 'password'); $ary[0]{'done-protocol'} = $iniLOGIN->val($ary[0]{'host'}, 'protocol'); $ary[0]{'done-device'} = $iniLOGIN->val($ary[0]{'host'}, 'device');    } $listALL =~ s/\|$ary[0]{'value'}\|//g;		 $listALL =~ s/\|$ary[0]{'host'}\|//g;    if(!($listALL =~ /^\|.*$/)) { $listALL = "|".$listALL; }    if(!($listALL =~ /^.*\|$/)) { $listALL = $listALL."|"; } my %hos = (($adressLong+$n) => @ary); %hostHASH = (%hostHASH, %hos);    }    }    } elsif($arr[0]{'host'} =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.*$/) {    foreach my $host (split(/\s/, $arr[0]{'host'})) { my @ary = (); $ary[0]{'value'} = $host; $ary[0]{'name'} = $arr[0]{'name'}; $ary[0]{'protocol'} = $arr[0]{'protocol'}; $ary[0]{'host'} = $ary[0]{'value'};    if(((($listALL) =~ /\|$ary[0]{'value'}\|/ and $argRun) or (($listALL) =~ /\|$li\|/ and $argRun) or (($listALL) =~ /\|$arr[0]{'host'}\|/ and $argRun) or (($listALL) =~ /\|$arr[0]{'host'}\|/ and $argRun) or !$argRun) and !((($listNoALL) =~ /\|$ary[0]{'value'}\|/ and $listNoALL) or (($listNoALL) =~ /\|$li\|/ and $listNoALL))) {    foreach my $cch (split(/\s/, $arr[0]{'ssh-port'})) { $cch = delQuotes($cch);  $ary[0]{'ssh-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-login'})) { $cch = delQuotes($cch);  $ary[0]{'ssh-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-password'})) { $cch = delQuotes($cch); $ary[0]{'ssh-password-hash'}{md5_hex($cch)} = $cch; } $ary[0]{'ssh-key'} = $arr[0]{'ssh-key'}; $ary[0]{'ssh-keydsa'} = $arr[0]{'ssh-keydsa'}; $ary[0]{'ssh-keypassword'} = $arr[0]{'ssh-keypassword'}; $ary[0]{'ssh-attempt-kill'} = $arr[0]{'ssh-attempt-kill'};    foreach my $cch (split(/\s/, $arr[0]{'wwww-port'})) { $cch = delQuotes($cch);  $ary[0]{'wwww-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-login'})) { $cch = delQuotes($cch);  $ary[0]{'wwww-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-password'})) { $cch = delQuotes($cch); $ary[0]{'wwww-password-hash'}{md5_hex($cch)} = $cch; } $ary[0]{'path'} = $arr[0]{'path'}; $ary[0]{'overwrite'} = $arr[0]{'overwrite'}; $ary[0]{'mt-backup'} = $arr[0]{'mt-backup'}; $ary[0]{'mt-encrypt'} = $arr[0]{'mt-encrypt'}; $ary[0]{'mt-enpassword'} = $arr[0]{'mt-enpassword'}; $ary[0]{'mt-rsc-verbose'} = $arr[0]{'mt-rsc-verbose'};    if($iniLOGIN->{'_read_line_num'}) { $ary[0]{'done-port'} = $iniLOGIN->val($ary[0]{'host'}, 'port'); $ary[0]{'done-login'} = $iniLOGIN->val($ary[0]{'host'}, 'login'); $ary[0]{'done-password'} = $iniLOGIN->val($ary[0]{'host'}, 'password'); $ary[0]{'done-protocol'} = $iniLOGIN->val($ary[0]{'host'}, 'protocol'); $ary[0]{'done-device'} = $iniLOGIN->val($ary[0]{'host'}, 'device');    } $listALL =~ s/\|$ary[0]{'value'}\|//g;		 $listALL =~ s/\|$ary[0]{'host'}\|//g;    if(!($listALL =~ /^\|.*$/)) { $listALL = "|".$listALL; }    if(!($listALL =~ /^.*\|$/)) { $listALL = $listALL."|"; } my %hos = (ip2long($ary[0]{'host'}) => @ary); %hostHASH = (%hostHASH, %hos);    }    }    } else {    if($iniLOGIN->{'_read_line_num'}) { $arr[0]{'done-port'} = $iniLOGIN->val($arr[0]{'host'}, 'port'); $arr[0]{'done-login'} = $iniLOGIN->val($arr[0]{'host'}, 'login'); $arr[0]{'done-password'} = $iniLOGIN->val($arr[0]{'host'}, 'password'); $arr[0]{'done-protocol'} = $iniLOGIN->val($arr[0]{'host'}, 'protocol'); $arr[0]{'done-device'} = $iniLOGIN->val($arr[0]{'host'}, 'device');    } $listALL =~ s/\|$arr[0]{'value'}\|//g;		 $listALL =~ s/\|$arr[0]{'host'}\|//g;    if(!($listALL =~ /^\|.*$/)) { $listALL = "|".$listALL; }    if(!($listALL =~ /^.*\|$/)) { $listALL = $listALL."|"; } my %hos = (ip2long($arr[0]{'host'}) => @arr); %hostHASH = (%hostHASH, %hos);    }    }     }}    }   } elsif($argDB =~ /^(lms|elms)$/ and ($argLmsStations || $argLmsCustomer)) {       $argLmsConfig = path($argLmsConfig) || "/etc/lms/lms.ini";    if(!(-f $argLmsConfig) and $argLmsConfig) { my $log = lang("error", "file_confLMS_does_not_exist", $argLmsConfig);    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    } elsif(!(-r $argLmsConfig) and $argLmsConfig) { my $log = lang("error", "file_confLMS_can_not_read", $argLmsConfig);    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    } else { my $iniLMS = new Config::IniFiles -file => $argLmsConfig; my @err = @Config::IniFiles::errors;    if(@err) { my $log = @err[0]." - ".$argLmsConfig;    if(!$argQuiet) { print "\n   "; print RED, "$LangError! (", RESET; print $log; print RED, ")\n\n", RESET; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    } my $dbtype = getVal('database', 'type', $iniLMS) || 'mysql'; my $dbhost = getVal('database', 'host', $iniLMS) || 'localhost'; my $dbuser = getVal('database', 'user', $iniLMS) || 'root'; my $dbpassword = getVal('database', 'password', $iniLMS) || ''; my $dbname = getVal('database', 'database', $iniLMS) || 'lms'; my $dbase; my $prepareLMS; my $prepareOMSystem;    if($dbtype =~ /mysql/){ $dbase = DBI->connect("DBI:mysql:database=$dbname;host=$dbhost","$dbuser","$dbpassword", { RaiseError => 1 });	 $prepareLMS = "SELECT id, name, INET_NTOA(ipaddr) AS host, ownerid, netdev, info FROM vnodes WHERE ".($argLmsStations ? "(".($listALL ? "((name REGEXP '^($listALL)\$' or INET_NTOA(ipaddr) REGEXP '^($listALL)\$') and !(name REGEXP '^($listNoALL)\$' or INET_NTOA(ipaddr) REGEXP '^($listNoALL)\$')) and" : "")." ownerid=0 and access=1)" : "").(($argLmsCustomer and $argLmsStations) ? " or " : "").($argLmsCustomer ? "(".($listALL ? "((name REGEXP '^($listALL)\$' or INET_NTOA(ipaddr) REGEXP '^($listALL)\$') and !(name REGEXP '^($listNoALL)\$' or INET_NTOA(ipaddr) REGEXP '^($listNoALL)\$')) and" : "")." ownerid!=0 and access=1)" : "");    } elsif($dbtype eq "postgres") { $dbase = DBI->connect("DBI:Pg:dbname=$dbname;host=$dbhost","$dbuser","$dbpassword", { RaiseError => 1 }); $prepareLMS = "SELECT id, name, INET_NTOA(ipaddr) AS host, ownerid, netdev, info FROM vnodes WHERE ".($argLmsStations ? "(".($listALL ? "((name ~ '^($listALL)\$' or INET_NTOA(ipaddr) ~ '^($listALL)\$') and !(name ~ '^($listNoALL)\$' or INET_NTOA(ipaddr) ~ '^($listNoALL)\$')) and" : "")." ownerid=0 and access=1)" : "").(($argLmsCustomer and $argLmsStations) ? " or " : "").($argLmsCustomer ? "(".($listALL ? "((name ~ '^($listALL)\$' or INET_NTOA(ipaddr) ~ '^($listALL)\$') and !(name ~ '^($listNoALL)\$' or INET_NTOA(ipaddr) ~ '^($listNoALL)\$')) and" : "")." ownerid!=0 and access=1)" : "");    } else { my $log = lang("error", "unsupported_db_type", $dbtype);    if(!$argQuiet) { print "\n\n"; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "\n\n"; print BOLD RED, "\n\tSTOP SCRIPT!\n\n", RESET; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", "", $log, 1); } exit 1;    } $listALL = "|$listALL|"; $listNoALL = "|$listNoALL|";    if($argDB eq "lms") { my $sth = $dbase->prepare("$prepareLMS")or die(lang("error", "error_in_uery")); $sth->execute();    while( my $li = $sth->fetchrow_hashref()) { my @arr = (); my $ss = 0; my $hash = (); my $LLMS;    foreach my $ou (split(/\n/, $li->{'info'})) {    if($ou =~ /\%START\%BACKUP\%/) { $ss = 1; }    if($ou =~ /\%END\%BACKUP\%/) { $ss = 0; }    if($ss and !($ou =~ /\%END\%BACKUP\%/) and !($ou =~ /\%START\%BACKUP\%/)) {    if($ou =~ /^(.+)=(.+)$/) { $hash->{trim($1)} = delHash($2); }    }    }    if($li->{'ownerid'}) { $LLMS = "lms-customer"; $arr[0]{'idComputer'} = $li->{'id'};			$arr[0]{'zidComputer'} = ($li->{'id'} ? sprintf("%0".$lmsIdNum."d", $li->{'id'}) : ""); $arr[0]{'idCustomer'} = $li->{'ownerid'};			$arr[0]{'zidCustomer'} = ($li->{'ownerid'} ? sprintf("%0".$lmsIdNum."d", $li->{'ownerid'}) : "");    } else { $LLMS = "lms-station"; $arr[0]{'idAddress'} = $li->{'id'};				$arr[0]{'zidAddress'} = ($li->{'id'} ? sprintf("%0".$lmsIdNum."d", $li->{'id'}) : ""); $arr[0]{'idDevice'} = $li->{'netdev'};			$arr[0]{'zidDevice'} = ($li->{'netdev'} ? sprintf("%0".$lmsIdNum."d", $li->{'netdev'}) : "");    if($li->{'netdev'}) { my $sthN = $dbase->prepare("SELECT * FROM netdevices WHERE id=".$li->{'netdev'})or die(lang("error", "error_in_uery")); $sthN->execute();    while( my $liN = $sthN->fetchrow_hashref()) { $arr[0]{'idNetNode'} = $liN->{'netnodeid'};	$arr[0]{'zidNetNode'} = ($liN->{'netnodeid'} ? sprintf("%0".$lmsIdNum."d", $liN->{'netnodeid'}) : "");    }    }    }    if($hash->{'ssh-port'} or $hash->{'ssh-login'} or $hash->{'ssh-password'} or $hash->{'www-port'} or $hash->{'www-login'} or $hash->{'www-password'}) { $arr[0]{'value'} = $li->{'name'}; $arr[0]{'name'} = $hash->{'name'} || '%value%'; $arr[0]{'protocol'} = $hash->{'protocol'} || $hash->{'log-in'} || 'auto'; $arr[0]{'host'} = $li->{'host'}; $arr[0]{'ssh-port'} = $hash->{'ssh-port'} || '22'; $arr[0]{'ssh-login'} = $hash->{'ssh-login'} || 'admin'; $arr[0]{'ssh-password'} = $hash->{'ssh-password'} || '';		 $arr[0]{'ssh-key'} = $hash->{'ssh-key'} || 'no'; $arr[0]{'ssh-keydsa'} = path($hash->{'ssh-keydsa'}) || path("~/.ssh/id_dsa"); $arr[0]{'ssh-keypassword'} = $hash->{'ssh-keypassword'} || ''; $arr[0]{'ssh-attempt-kill'} = delHash($arr[0]{'ssh-attempt-kill'}) || $sshAttemptKill || '5'; $arr[0]{'www-port'} = $hash->{'www-port'} || '80'; $arr[0]{'www-login'} = $hash->{'www-login'} || 'admin'; $arr[0]{'www-password'} = $hash->{'www-password'} || 'admin';		 $arr[0]{'path'} = path($hash->{'path'}) || '/opt/'.$p_nn.'/backups'; $arr[0]{'overwrite'} = $hash->{'overwrite'} || 'no'; $arr[0]{'mt-backup'} = $hash->{'mt-backup'} || $hash->{'backup'} || 'all'; $arr[0]{'mt-encrypt'} = $hash->{'mt-encrypt'} || 'no'; $arr[0]{'mt-enpassword'} = $hash->{'mt-enpassword'} || ''; $arr[0]{'mt-rsc-verbose'} = delHash($arr[0]{'mt-rsc-verbose'}) || $mtRscVerbose || 'no'; $arr[0]{'ssh-port'} = podmien($arr[0]{'ssh-port'}, @arr); $arr[0]{'ssh-login'} = podmien($arr[0]{'ssh-login'}, @arr); $arr[0]{'ssh-password'} = podmien($arr[0]{'ssh-password'}, @arr); $arr[0]{'www-port'} = podmien($arr[0]{'www-port'}, @arr); $arr[0]{'www-login'} = podmien($arr[0]{'www-login'}, @arr); $arr[0]{'www-password'} = podmien($arr[0]{'www-password'}, @arr);    foreach my $cch (split(/\s/, $arr[0]{'ssh-port'})) { $cch = delQuotes($cch);  $arr[0]{'ssh-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-login'})) { $cch = delQuotes($cch);  $arr[0]{'ssh-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-password'})) { $cch = delQuotes($cch); $arr[0]{'ssh-password-hash'}{md5_hex($cch)} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-port'})) { $cch = delQuotes($cch);  $arr[0]{'wwww-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-login'})) { $cch = delQuotes($cch);  $arr[0]{'wwww-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-password'})) { $cch = delQuotes($cch); $arr[0]{'wwww-password-hash'}{md5_hex($cch)} = $cch; }    } else { $arr[0]{'value'} = $li->{'name'}; $arr[0]{'host'} = $li->{'host'}; $arr[0]{'name'} = getVal($LLMS, 'name', $iniCONF) || '%value%'; $arr[0]{'protocol'} = getVal($LLMS, 'protocol', $iniCONF) || getVal($LLMS, 'log-in', $iniCONF) || 'auto'; $arr[0]{'ssh-port'} = getVal($LLMS, 'ssh-port', $iniCONF) || '22'; $arr[0]{'ssh-login'} = getVal($LLMS, 'ssh-login', $iniCONF) || 'admin'; $arr[0]{'ssh-password'} = getVal($LLMS, 'ssh-password', $iniCONF) || ''; $arr[0]{'ssh-key'} = getVal($LLMS, 'ssh-key', $iniCONF) || 'no'; $arr[0]{'ssh-keydsa'} = path(getVal($LLMS, 'ssh-keydsa', $iniCONF)) || path("~/.ssh/id_dsa"); $arr[0]{'ssh-keypassword'} = getVal($LLMS, 'ssh-keypassword', $iniCONF) || ''; $arr[0]{'ssh-attempt-kill'} = getVal($LLMS, 'ssh-attempt-kill', $iniCONF) || $sshAttemptKill || '5'; $arr[0]{'www-port'} = getVal($LLMS, 'www-port', $iniCONF) || '80'; $arr[0]{'www-login'} = getVal($LLMS, 'www-login', $iniCONF) || 'admin'; $arr[0]{'www-password'} = getVal($LLMS, 'www-password', $iniCONF) || 'admin'; $arr[0]{'path'} = path(getVal($LLMS, 'path', $iniCONF)) || '/opt/'.$p_nn.'/backups'; $arr[0]{'overwrite'} = getVal($LLMS, 'overwrite', $iniCONF) || 'no'; $arr[0]{'mt-backup'} = getVal($LLMS, 'mt-backup', $iniCONF) || getVal($LLMS, 'backup', $iniCONF) || 'all'; $arr[0]{'mt-encrypt'} = getVal($LLMS, 'mt-encrypt', $iniCONF) || 'no'; $arr[0]{'mt-enpassword'} = getVal($LLMS, 'mt-enpassword', $iniCONF) || ''; $arr[0]{'mt-rsc-verbose'} = getVal($LLMS, 'mt-rsc-verbose', $iniCONF) || $mtRscVerbose || 'no'; $arr[0]{'ssh-port'} = podmien($arr[0]{'ssh-port'}, @arr); $arr[0]{'ssh-login'} = podmien($arr[0]{'ssh-login'}, @arr); $arr[0]{'ssh-password'} = podmien($arr[0]{'ssh-password'}, @arr); $arr[0]{'www-port'} = podmien($arr[0]{'www-port'}, @arr); $arr[0]{'www-login'} = podmien($arr[0]{'www-login'}, @arr); $arr[0]{'www-password'} = podmien($arr[0]{'www-password'}, @arr);    foreach my $cch (split(/\s/, $arr[0]{'ssh-port'})) { $cch = delQuotes($cch);  $arr[0]{'ssh-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-login'})) { $cch = delQuotes($cch);  $arr[0]{'ssh-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'ssh-password'})) { $cch = delQuotes($cch); $arr[0]{'ssh-password-hash'}{md5_hex($cch)} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-port'})) { $cch = delQuotes($cch);  $arr[0]{'wwww-port-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-login'})) { $cch = delQuotes($cch);  $arr[0]{'wwww-login-hash'}{$cch} = $cch; }    foreach my $cch (split(/\s/, $arr[0]{'wwww-password'})) { $cch = delQuotes($cch); $arr[0]{'wwww-password-hash'}{md5_hex($cch)} = $cch; }    }    if($iniLOGIN->{'_read_line_num'}) { $arr[0]{'done-port'} = $iniLOGIN->val($arr[0]{'host'}, 'port'); $arr[0]{'done-login'} = $iniLOGIN->val($arr[0]{'host'}, 'login'); $arr[0]{'done-password'} = $iniLOGIN->val($arr[0]{'host'}, 'password'); $arr[0]{'done-protocol'} = $iniLOGIN->val($arr[0]{'host'}, 'protocol'); $arr[0]{'done-device'} = $iniLOGIN->val($arr[0]{'host'}, 'device');    } $listALL =~ s/\|$arr[0]{'value'}\|//g; $listALL =~ s/\|$arr[0]{'host'}\|//g;    if(!($listALL =~ /^\|.*$/)) { $listALL = "|".$listALL; }    if(!($listALL =~ /^.*\|$/)) { $listALL = $listALL."|"; } my %hos = (ip2long($arr[0]{'host'}) => @arr); %hostHASH = (%hostHASH, %hos);    } $sth->finish();    } elsif($argDB eq "elms") {    } elsif($argDB eq "omsystem") {    }    }   } my $knownHosts = path("/opt/$p_nn/tmp/known_hosts");  if(-f $knownHosts) { unlink($knownHosts); }   foreach my $hkey (sort keys %hostHASH) { my $ex = $hostHASH{$hkey}; my $STARTT = time();    if(!$argQuiet or ($argQuiet and $argDebug)) {     if($ex->{'value'} ne $ex->{'host'}) { print "\n\n "; print BLUE, $ex->{'value'}." - ".$ex->{'host'}, RESET; print ":";    } else { print "\n\n "; print BLUE, $ex->{'value'}, RESET; print ":";    }    }    if(!($ex->{'host'})) { my $log = lang("error", "not_can_blank", "host");    if(!$argQuiet) { print "\n  - "; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}, $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}, $log); } next;    }    if(($ex->{'ssh-key'} =~ /^($LangYes|yes)$/) and !($ex->{'ssh-keydsa'}) and !( -f path("~/.ssh/id_dsa")) and ($ex->{'protocol'} =~ /^(ssh|auto)$/ or $ex->{'protocol'} =~ /^ssh\:(mikroitk|mt|ubiquiti|ubnt|ub)$/)) { my $log = lang("error", "lack", lang("other", "key_dsa"), path("~/.ssh/id_dsa"));    if(!$argQuiet) { print "\n  - "; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    } elsif(($ex->{'ssh-key'} =~ /^($LangYes|yes)$/) and ($ex->{'ssh-keydsa'}) and !( -f "$ex->{'ssh-keydsa'}") and ($ex->{'protocol'} =~ /^(ssh|auto)$/ or $ex->{'protocol'} =~ /^ssh\:(mikroitk|mt|ubiquiti|ubnt|ub)$/)) { my $log = lang("error", "lack", lang("other", "key_dsa"), $ex->{'ssh-keydsa'});    if(!$argQuiet) { print "\n  - "; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    } else { our $ssh; my $err; my $done; my %test = ('ssh' => 1, 'www' => 1);    if($ex->{'done-protocol'} =~ /^(ssh|www)$/ and $ex->{$ex->{'done-protocol'}.'-port-hash'}{$ex->{'done-port'}} and $ex->{'done-device'} and $ex->{$ex->{'done-protocol'}.'-login-hash'}{$ex->{'done-login'}} and $ex->{$ex->{'done-protocol'}.'-password-hash'}{$ex->{'done-password'}}) { my $error = 0;    if(!$argQuiet) { print "\n     --> ".lang("info", 'verification_shortened')."...\n";     } elsif($argQuiet and $argDebug) { print BOLD RED, "\n     --> ".lang("info", 'verification_shortened')."...", RESET; print "\n";    } my $ping = ping($pingBinary, $pingCount, $interface, $ex->{'host'});    if($ping eq "U" or !$ping) { my $log = lang("error", ($interface ? 'host_unreachable_byin' : 'host_unreachable'), $interface);    if(!$argQuiet) { print "\t - ping\t\t\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } next;    }    if(!$argQuiet) { print "\t - ping\t\t\t["; print GREEN, $ping."ms", RESET;  print "]\n"; }    if(!($ex->{'done-port'} =~ /^\d+$/)) { my $log = lang("error", "this_is_not_port", $ex->{'done-port'}, ($ex->{'done-protocol'} eq "ssh" ? "SSH" : "WWW"));    if(!$argQuiet) { print "\t - port ".lang("other", "port", ($ex->{'done-protocol'} eq "ssh" ? "SSH" : "WWW"))."\t\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "]\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } $error = 1;    }    if(!$error) { my $Hinterface = ($interface ? "-I '$interface'" : ""); my $Hping = qx($hpingBinary -S -c $hpingCount $Hinterface -p $ex->{'done-port'} $ex->{'host'} 2> /dev/null);    if($Hping =~ /flags\=RA/ or !($Hping =~ /flags\=SA/)) { my $log = lang("error", ($interface ? 'host_unreachable_for_byin' : 'host_unreachable_for'), ($ex->{'done-protocol'} eq "ssh" ? "SSH" : "WWW"), $ex->{'done-port'}, $interface);    if(!$argQuiet) { print "\t - ".lang("other", 'port_status')." ".($ex->{'done-protocol'} eq "ssh" ? "SSH" : "WWW")."\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } $error = 1;    } elsif(!($Hping =~ /^HPING/)) { my $log = trim($Hping);    if(!$argQuiet) { print "\t - ".lang("other", 'port_status')." ".($ex->{'done-protocol'} eq "ssh" ? "SSH" : "WWW")."\t["; print RED, "$LangError! (", RESET; print "HPING: ".$log; print RED, ")", RESET; print "]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } $error = 1;    }    if(!$error) {    if(!$argQuiet) { print "\t - ".lang("other", 'port_status')." ".($ex->{'done-protocol'} eq "ssh" ? "SSH" : "WWW")."\t["; print GREEN, "otwarty: ".$ex->{'done-port'}, RESET;  print "]\n"; }    }    }    if(!$error) {    if($ex->{'done-protocol'} eq "ssh") { $Net::OpenSSH::debug |= ($argDebug ? 16 : 0); reConnectSSH($ex->{'host'}, $ex->{'done-port'}, $ex->{'done-login'}, $ex->{'ssh-password-hash'}{$ex->{'done-password'}}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts);    if($ssh->error) { my $log = lang("error", "wrong_login_or_password", 'SSH');    if(!$argQuiet) { print "\t - ".lang("info", 'login_after', 'SSH')."\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "][".$ex->{'done-port'}."][".$ex->{'done-login'}."][".($argShowPassword ? $ex->{'ssh-password-hash'}{$ex->{'done-password'}} : "***")."]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." ($log)[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." ($log)[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); } $error = 1; undef $ssh;    }    if(!$error) {    if($ex->{'done-device'} eq "mikrotik") { ($ex->{'get'}{'platform'}, $err) = trim($ssh->capture2(":put [/system resource get board-name]"));    if($ex->{'get'}{'platform'}) { $ex->{'get'}{'platform'} = "Mikrotik"; $ex->{'get'}{'producer'} = "mikrotik"; reConnectSSH($ex->{'host'}, $ex->{'done-port'}, $ex->{'done-login'}, $ex->{'ssh-password-hash'}{$ex->{'done-password'}}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'identity'}, $err) = trim($ssh->capture2(":put [/system identity get name]")); reConnectSSH($ex->{'host'}, $ex->{'done-port'}, $ex->{'done-login'}, $ex->{'ssh-password-hash'}{$ex->{'done-password'}}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'version'}, $err) = trim($ssh->capture2(":put [/system resource get version]")); ($ex->{'get'}{'version-one'}) = $ex->{'get'}{'version'} =~ /^(\d+)\..+$/; reConnectSSH($ex->{'host'}, $ex->{'done-port'}, $ex->{'done-login'}, $ex->{'ssh-password-hash'}{$ex->{'done-password'}}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'board-name'}, $err) = trim($ssh->capture2(":put [/system resource get board-name]")); ($ex->{'get'}{'board-shortname'}, $err) = $ex->{'get'}{'board-name'}; reConnectSSH($ex->{'host'}, $ex->{'done-port'}, $ex->{'done-login'}, $ex->{'ssh-password-hash'}{$ex->{'done-password'}}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'sn'}, $err) = trim($ssh->capture2(":put [/system routerboard get serial-number]")); reConnectSSH($ex->{'host'}, $ex->{'done-port'}, $ex->{'done-login'}, $ex->{'ssh-password-hash'}{$ex->{'done-password'}}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'model'}, $err) = trim($ssh->capture2(":put [/system routerboard get model]"));	$ex->{'get'}{'model'} = ($ex->{'get'}{'model'} ? $ex->{'get'}{'model'} : "x86"); reConnectSSH($ex->{'host'}, $ex->{'done-port'}, $ex->{'done-login'}, $ex->{'ssh-password-hash'}{$ex->{'done-password'}}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'interfaces-ether'}, $err) = trim($ssh->capture2(":foreach i in=[/interface find where type=ether] do={ :put \"\$[/interface get \$i default-name]=\$[/interface get \$i mac-address]=\$[/interface get \$i name]\"; }")); reConnectSSH($ex->{'host'}, $ex->{'done-port'}, $ex->{'done-login'}, $ex->{'ssh-password-hash'}{$ex->{'done-password'}}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'interfaces-wlan'}, $err) = trim($ssh->capture2(":foreach i in=[/interface find where type=wlan] do={ :put \"\$[/interface get \$i default-name]=\$[/interface get \$i mac-address]=\$[/interface get \$i name]\"; }")); reConnectSSH($ex->{'host'}, $ex->{'done-port'}, $ex->{'done-login'}, $ex->{'ssh-password-hash'}{$ex->{'done-password'}}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'group'}, $err) = trim($ssh->capture2(":put [/user get ".$ex->{'done-login'}." group]")); reConnectSSH($ex->{'host'}, $ex->{'done-port'}, $ex->{'done-login'}, $ex->{'ssh-password-hash'}{$ex->{'done-password'}}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'policy'}, $err) = trim($ssh->capture2(":put [/user group get ".$ex->{'get'}{'group'}." policy]"));    foreach my $interface (split(/\n/, $ex->{'get'}{'interfaces-ether'})) { $interface =~ s/\=/            /; $interface =~ s/\=/      /; $ex->{'get'}{'interfaces-ether-print'} .= "#     ".$interface."\n";    } $ex->{'get'}{'interfaces-ether-print'} = ($ex->{'get'}{'interfaces-ether-print'} ? "#     default name:     mac:                   name:\n".$ex->{'get'}{'interfaces-ether-print'} : "");    foreach my $interface (split(/\n/, $ex->{'get'}{'interfaces-wlan'})) { $interface =~ s/\=/             /; $interface =~ s/\=/      /; $ex->{'get'}{'interfaces-wlan-print'} .= "#     ".$interface."\n";    } $ex->{'get'}{'interfaces-wlan-print'} = ($ex->{'get'}{'interfaces-wlan-print'} ? "#     default name:     mac:                   name:\n".$ex->{'get'}{'interfaces-wlan-print'} : "");    if(lc($ex->{'get'}{'platform'}) eq "mikrotik") {    if($ex->{'get'}{'policy'} =~ /\!write/) { my $log = lang("error", "no_permission_to_write", $ex->{'done-login'});    if(!$argQuiet) { print "\t - test\t\t\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } $error = 1; undef $ssh;    }    } else {    if(!$ex->{'get'}{'group'}) { my $log = lang("error", "no_permission_to_read", $ex->{'done-login'});    if(!$argQuiet) { print "\t - test\t\t\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } $error = 1; undef $ssh;    }    }    } else { my $log = lang("error", "this_is_not", "", "Mikrotik");    if(!$argQuiet) { print "\t - ".lang("info", 'login_after', 'SSH')."\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "][".$ex->{'done-port'}."][".$ex->{'done-login'}."][".($argShowPassword ? $ex->{'ssh-password-hash'}{$ex->{'done-password'}} : "***")."]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." ($log)[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." ($log)[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); } $error = 1; undef $ssh;    }    } elsif($ex->{'done-device'} eq "ubiquiti") { ($ex->{'get'}{'platform'}, $err) = trim($ssh->capture2("cat /tmp/system.cfg"));     if($ex->{'get'}{'platform'}) { $ex->{'get'}{'platform'} = "Ubiquiti"; $ex->{'get'}{'producer'} = "ubiquiti"; ($ex->{'get'}{'identity'}, $err) = trim($ssh->capture2("cat /tmp/system.cfg | grep resolv.host.1.name"));		$ex->{'get'}{'identity'} =~ s/^resolv\.host\.1\.name\=//g; ($ex->{'get'}{'version'}, $err) = trim($ssh->capture2("cat /usr/lib/version")); ($ex->{'get'}{'version-one'}) = $ex->{'get'}{'version'} =~ /^.+v(\d+)\..+$/; ($ex->{'get'}{'board-name'}, $err) = trim($ssh->capture2("cat /etc/board.info | grep board.name"));			$ex->{'get'}{'board-name'} =~ s/^board\.name\=//g; ($ex->{'get'}{'board-shortname'}, $err) = trim($ssh->capture2("cat /etc/board.info | grep board.shortname"));	$ex->{'get'}{'board-shortname'} =~ s/^board\.shortname\=//g; ($ex->{'get'}{'sn'}, $err) = trim($ssh->capture2("cat /etc/board.info | grep board.hwadd"));				$ex->{'get'}{'sn'} =~ s/^board\.hwaddr\=//g; $ex->{'get'}{'model'} = $ex->{'get'}{'board-name'};											$ex->{'get'}{'model'} = ($ex->{'get'}{'model'} ? $ex->{'get'}{'model'} : lang("other", 'other')); ($ex->{'get'}{'ifconfig'}, $err) = trim($ssh->capture2("ifconfig")); ($ex->{'get'}{'rc.poststart'}, $err) = trim($ssh->capture2("if [ -f /etc/persistent/rc.poststart ]; then cat /etc/persistent/rc.poststart; fi"));    foreach my $interface (split(/\n/, $ex->{'get'}{'ifconfig'})) {    if($interface =~ /^eth\d+.*Link\sencap/) { my $mac = trim(($interface =~ /^eth\d+\s+Link\sencap.*\sHWaddr\s(.*)$/)[0]); $mac =~ s/\-/\:/g; $mac = (($mac =~ /^(.{2}\:.{2}\:.{2}\:.{2}\:.{2}\:.{2}).*$/)[0]); $ex->{'get'}{'interfaces-ether-print'} .= "#     ".trim(($interface =~ /^(eth\d+)\s+Link\sencap.*$/)[0])."      ".$mac."\n";    }    if($interface =~ /^wifi\d+.*Link\sencap/) { my $mac = trim(($interface =~ /^wifi\d+\s+Link\sencap.*\sHWaddr\s(.*)$/)[0]); $mac =~ s/\-/\:/g; $mac = (($mac =~ /^(.{2}\:.{2}\:.{2}\:.{2}\:.{2}\:.{2}).*$/)[0]); $ex->{'get'}{'interfaces-wlan-print'} .= "#     ".trim(($interface =~ /^(wifi\d+)\s+Link\sencap.*$/)[0])."     ".$mac."\n";    }    } $ex->{'get'}{'interfaces-ether-print'} = ($ex->{'get'}{'interfaces-ether-print'} ? "#     name:     mac:\n".$ex->{'get'}{'interfaces-ether-print'} : ""); $ex->{'get'}{'interfaces-wlan-print'} = ($ex->{'get'}{'interfaces-wlan-print'} ? "#     name:     mac:\n".$ex->{'get'}{'interfaces-wlan-print'} : "");    } else { my $log = lang("error", "this_is_not", "", "Mikrotik");    if(!$argQuiet) { print "\t - ".lang("info", 'login_after', 'SSH')."\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "][".$ex->{'done-port'}."][".$ex->{'done-login'}."][".($argShowPassword ? $ex->{'ssh-password-hash'}{$ex->{'done-password'}} : "***")."]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." ($log)[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." ($log)[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); } $error = 1; undef $ssh;    }    } else { my $log = lang("error", "this_is_not", "", "Mikrotik, Ubiquiti");    if(!$argQuiet) { print "\t - ".lang("info", 'login_after', 'SSH')."\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "][".$ex->{'done-port'}."][".$ex->{'done-login'}."][".($argShowPassword ? $ex->{'ssh-password-hash'}{$ex->{'done-password'}} : "***")."]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." ($log)[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." ($log)[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); } $error = 1; undef $ssh;    }    if(!$error) {    if(!$argQuiet) { print "\t - ".lang("info", 'login_after', 'SSH')."\t["; print GREEN, "$LangOK: ".$ex->{'get'}{'platform'}." ".$ex->{'get'}{'board-name'}." v".$ex->{'get'}{'version'}, RESET;  print "][".$ex->{'done-port'}."][".$ex->{'done-login'}."][".($argShowPassword ? $ex->{'ssh-password-hash'}{$ex->{'done-password'}} : "***")."]\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." (".$ex->{'get'}{'platform'}." ".$ex->{'get'}{'board-name'}.")[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /done/)) { logSend("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." (".$ex->{'get'}{'platform'}." ".$ex->{'get'}{'board-name'}.")[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); } $ex->{'ok-port'} = $ex->{'done-port'}; $ex->{'ok-login'} = $ex->{'done-login'}; $ex->{'ok-password'} = $ex->{'ssh-password-hash'}{$ex->{'done-password'}};    }    }    } else { my $ua = LWP::UserAgent->new; $ua->timeout(15); my $req =  HTTP::Request->new( GET => "http://".$ex->{'host'}.":".$ex->{'done-port'}.getVal($ex->{'done-device'}, 'path', $iniPath)); $req->authorization_basic($ex->{'done-login'}, $ex->{'www-password-hash'}{$ex->{'done-password'}}); my $con = $ua->request($req); $ex->{'get'}{'status_line'} = $con->status_line;    if($con->is_success) { $ex->{'protocol'} = $k; $ex->{'get'}{'platform'} = getVal($ex->{'done-device'}, 'name', $iniPath); $ex->{'get'}{'producer'} = $ex->{'done-device'}; $ex->{'get'}{'model'} = $ex->{'done-device'};    } else { $ex->{'get'}{'platform'} = ""; $ex->{'get'}{'producer'} = ""; $ex->{'get'}{'model'} = "";    } $ex->{'get'}{'producer'} = ($ex->{'get'}{'producer'} ? $ex->{'get'}{'producer'} : lang("other", 'other')); $ex->{'get'}{'model'} = ($ex->{'get'}{'model'} ? $ex->{'get'}{'model'} : lang("other", 'other'));     if(!$ex->{'get'}{'state'}) { my $log = lang("error", "harder_to_fix_the_problem");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'WWW')." ($log)[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); }    if(!$argQuiet) { print "\t - ".lang("info", 'login_after', 'WWW')."\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "][".$ex->{'done-port'}."][".$ex->{'done-login'}."][".($argShowPassword ? $ex->{'www-password-hash'}{$ex->{'done-password'}} : "***")."]\n"; }  $error = 1;    } else { $error = 0; }    if(!$error) {    if(!$argQuiet) { print "\t - ".lang("info", 'login_after', 'WWW')."\t["; print GREEN, "$LangOK: ".$ex->{'get'}{'platform'}, RESET;  print "][".$ex->{'done-port'}."][".$ex->{'done-login'}."][".($argShowPassword ? $ex->{'www-password-hash'}{$ex->{'done-password'}} : "***")."]\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'WWW')." (".$ex->{'get'}{'platform'}.")[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /done/)) { logSend("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'WWW')." (".$ex->{'get'}{'platform'}.")[".$ex->{'done-port'}."][".$ex->{'done-login'}."][***]"); } $ex->{'ok-port'} = $ex->{'done-port'}; $ex->{'ok-login'} = $ex->{'done-login'}; $ex->{'ok-password'} = $ex->{'www-password-hash'}{$ex->{'done-password'}};    }    }    }    }    if(!$ex->{'get'}{'platform'}) {    if(!$argQuiet) { print (($ex->{'done-protocol'} =~ /^(ssh|www)$/ and $ex->{$ex->{'done-protocol'}.'-port-hash'}{$ex->{'done-port'}} and $ex->{'done-device'} and $ex->{$ex->{'done-protocol'}.'-login-hash'}{$ex->{'done-login'}} and $ex->{$ex->{'done-protocol'}.'-password-hash'}{$ex->{'done-password'}}) ? "" : "\n"); print "     --> ".lang("info", 'verification_complete')."...\n";     } elsif($argQuiet and $argDebug) { print (($ex->{'done-protocol'} =~ /^(ssh|www)$/ and $ex->{$ex->{'done-protocol'}.'-port-hash'}{$ex->{'done-port'}} and $ex->{'done-device'} and $ex->{$ex->{'done-protocol'}.'-login-hash'}{$ex->{'done-login'}} and $ex->{$ex->{'done-protocol'}.'-password-hash'}{$ex->{'done-password'}}) ? "" : "\n"); print BOLD RED, "     --> ".lang("info", 'verification_complete')."...", RESET; print "\n";    } my $ping = ping($pingBinary, $pingCount, $interface, $ex->{'host'});    if($ping eq "U" or !$ping) { my $log = lang("error", ($interface ? 'host_unreachable_byin' : 'host_unreachable'), $interface);    if(!$argQuiet) { print "\t - ping\t\t\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } next;    }    if(!$argQuiet) { print "\t - ping\t\t\t["; print GREEN, $ping."ms", RESET;  print "]\n"; }    if($ex->{'protocol'} =~ /^(ssh|auto)$/ or $ex->{'protocol'} =~ /^ssh\:(mikroitk|mt|ubiquiti|ubnt|ub)$/) { my $error = 0; my $ile = keys %{$ex->{'ssh-port-hash'}};    foreach my $portSSH (keys %{$ex->{'ssh-port-hash'}}) {    if(!($portSSH =~ /^\d+$/)) { my $log = lang("error", "this_is_not_port", $portSSH, "SSH");    if(!$argQuiet) { print "\t - ".lang("other", "port", "SSH")."\t\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "]\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } $error += 1; delete $ex->{'ssh-port-hash'}{$portSSH}; next;    } else { $error += 0; } my $Hinterface = ($interface ? "-I '$interface'" : ""); my $Hping = qx($hpingBinary -S -c $hpingCount $Hinterface -p $portSSH $ex->{'host'} 2> /dev/null);    if($Hping =~ /flags\=RA/ or !($Hping =~ /flags\=SA/)) { my $log = lang("error", ($interface ? 'host_unreachable_for_byin' : 'host_unreachable_for'), 'SSH', $portSSH, $interface);    if(!$argQuiet) { print "\t - ".lang("other", 'port_status')." SSH\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } $error += 1; delete $ex->{'ssh-port-hash'}{$portSSH}; next;    } elsif(!($Hping =~ /^HPING/)) { my $log = trim($Hping);    if(!$argQuiet) { print "\t - ".lang("other", 'port_status')." SSH\t["; print RED, "$LangError! (", RESET; print "HPING: ".$log; print RED, ")", RESET; print "]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } $error += 1; delete $ex->{'ssh-port-hash'}{$portSSH}; next;    }    if(!$argQuiet) { print "\t - ".lang("other", 'port_status')." SSH\t["; print GREEN, "otwarty: ".$portSSH, RESET;  print "]\n"; }    }    if(!($ile-$error) or !(keys %{$ex->{'ssh-port-hash'}})) { $test{'ssh'} = "0";    if($ex->{'protocol'} eq "ssh" or $ex->{'protocol'} =~ /^ssh\:(mikroitk|mt|ubiquiti|ubnt|ub)$/) { next; }    }    }    if($ex->{'protocol'} =~ /^(www|auto)$/ or $ex->{'protocol'} =~ /^www\:($devsListWWW)$/) { my $error = 0; my $ile = keys %{$ex->{'www-port-hash'}};    foreach my $portWWW (keys %{$ex->{'www-port-hash'}}) {    if(!($portWWW =~ /^\d+$/)) { my $log = lang("error", "this_is_not_port", $portWWW, "WWW");    if(!$argQuiet) { print "\t - ".lang("other", "port", "WWW")."\t\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "]\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } $error += 1; delete $ex->{'www-port-hash'}{$portSSH}; next;    } else { $error += 0; } my $Hinterface = ($interface ? "-I '$interface'" : ""); my $Hping = qx($hpingBinary -S -c $hpingCount $Hinterface -p $portWWW $ex->{'host'} 2> /dev/null);    if($Hping =~ /flags\=RA/ or !($Hping =~ /flags\=SA/)) { my $log = lang("error", ($interface ? 'host_unreachable_for_byin' : 'host_unreachable_for'), 'WWW', $portWWW, $interface);    if(!$argQuiet) { print "\t - ".lang("other", 'port_status')." WWW\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } $error += 1; delete $ex->{'www-port-hash'}{$portSSH}; next;    } elsif(!($Hping =~ /^HPING/)) { my $log = trim($Hping);    if(!$argQuiet) { print "\t - ".lang("other", 'port_status')." WWW\t["; print RED, "$LangError! (", RESET; print "HPING: ".$log; print RED, ")", RESET; print "]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } $error += 1; delete $ex->{'www-port-hash'}{$portSSH}; next;    }    if(!$argQuiet) { print "\t - ".lang("other", 'port_status')." WWW\t["; print GREEN, "otwarty: ".$portWWW, RESET;  print "]\n"; }    }    if(!($ile-$error) or !(keys %{$ex->{'www-port-hash'}})) { $test{'www'} = "0";    if($ex->{'protocol'} eq "www" or $ex->{'protocol'} =~ /^www\:($devsListWWW)$/) { next; }    }    }    if($test{'ssh'} eq 0 and $test{'www'} eq 0) { next; }    if($test{'ssh'} eq 1 and ($ex->{'protocol'} =~ /^(ssh|auto)$/ or $ex->{'protocol'} =~ /^ssh\:(mikroitk|mt|ubiquiti|ubnt|ub)$/)) { $Net::OpenSSH::debug |= ($argDebug ? 16 : 0);    foreach my $portSSH (keys %{$ex->{'ssh-port-hash'}}) {    foreach my $loginSSH (keys %{$ex->{'ssh-login-hash'}}) {    foreach my $passwordSSH (keys %{$ex->{'ssh-password-hash'}}) { my $passwordSSH = $ex->{'ssh-password-hash'}{$passwordSSH}; reConnectSSH($ex->{'host'}, $portSSH, $loginSSH, $passwordSSH, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts);    if($ssh->error) { my $log = lang("error", "wrong_login_or_password", 'SSH');    if(!$argQuiet) { print "\t - ".lang("info", 'login_after', 'SSH')."\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "][".$portSSH."][".$loginSSH."][".($argShowPassword ? $passwordSSH : "***")."]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." ($log)[".$portSSH."][".$loginSSH."][***]"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." ($log)[".$portSSH."][".$loginSSH."][***]"); } undef $ssh; next;    } ($ex->{'get'}{'platform'}, $err) = trim($ssh->capture2(":put [/system resource get board-name]"));    if($ex->{'get'}{'platform'}) { $ex->{'get'}{'platform'} = "Mikrotik"; $ex->{'get'}{'producer'} = "mikrotik";     }    if(!$ex->{'get'}{'platform'}) { ($ex->{'get'}{'platform'}, $err) = trim($ssh->capture2("cat /tmp/system.cfg")); $ex->{'get'}{'platform'} = ($ex->{'get'}{'platform'} ? "Ubiquiti" : ""); $ex->{'get'}{'producer'} = ($ex->{'get'}{'platform'} ? "ubiquiti" : "");    }    if(!$ex->{'get'}{'platform'}) { my $log = lang("error", "this_is_not", "", "Mikrotik, Ubiquiti");    if(!$argQuiet) { print "\t - ".lang("info", 'login_after', 'SSH')."\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "][".$portSSH."][".$loginSSH."][".($argShowPassword ? $passwordSSH : "***")."]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." ($log)[".$portSSH."][".$loginSSH."][***]"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." ($log)[".$portSSH."][".$loginSSH."][***]"); } undef $ssh; next;    }    if(lc($ex->{'get'}{'platform'}) eq "mikrotik") { reConnectSSH($ex->{'host'}, $portSSH, $loginSSH, $passwordSSH, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'identity'}, $err) = trim($ssh->capture2(":put [/system identity get name]")); reConnectSSH($ex->{'host'}, $portSSH, $loginSSH, $passwordSSH, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'version'}, $err) = trim($ssh->capture2(":put [/system resource get version]")); ($ex->{'get'}{'version-one'}) = $ex->{'get'}{'version'} =~ /^(\d+)\..+$/; reConnectSSH($ex->{'host'}, $portSSH, $loginSSH, $passwordSSH, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'board-name'}, $err) = trim($ssh->capture2(":put [/system resource get board-name]")); ($ex->{'get'}{'board-shortname'}, $err) = $ex->{'get'}{'board-name'}; reConnectSSH($ex->{'host'}, $portSSH, $loginSSH, $passwordSSH, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'sn'}, $err) = trim($ssh->capture2(":put [/system routerboard get serial-number]")); reConnectSSH($ex->{'host'}, $portSSH, $loginSSH, $passwordSSH, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'model'}, $err) = trim($ssh->capture2(":put [/system routerboard get model]"));	$ex->{'get'}{'model'} = ($ex->{'get'}{'model'} ? $ex->{'get'}{'model'} : "x86"); reConnectSSH($ex->{'host'}, $portSSH, $loginSSH, $passwordSSH, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'interfaces-ether'}, $err) = trim($ssh->capture2(":foreach i in=[/interface find where type=ether] do={ :put \"\$[/interface get \$i default-name]=\$[/interface get \$i mac-address]=\$[/interface get \$i name]\"; }")); reConnectSSH($ex->{'host'}, $portSSH, $loginSSH, $passwordSSH, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'interfaces-wlan'}, $err) = trim($ssh->capture2(":foreach i in=[/interface find where type=wlan] do={ :put \"\$[/interface get \$i default-name]=\$[/interface get \$i mac-address]=\$[/interface get \$i name]\"; }")); reConnectSSH($ex->{'host'}, $portSSH, $loginSSH, $passwordSSH, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'group'}, $err) = trim($ssh->capture2(":put [/user get ".$loginSSH." group]")); reConnectSSH($ex->{'host'}, $portSSH, $loginSSH, $passwordSSH, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); ($ex->{'get'}{'policy'}, $err) = trim($ssh->capture2(":put [/user group get ".$ex->{'get'}{'group'}." policy]"));    foreach my $interface (split(/\n/, $ex->{'get'}{'interfaces-ether'})) { $interface =~ s/\=/            /; $interface =~ s/\=/      /; $ex->{'get'}{'interfaces-ether-print'} .= "#     ".$interface."\n";    } $ex->{'get'}{'interfaces-ether-print'} = ($ex->{'get'}{'interfaces-ether-print'} ? "#     default name:     mac:                   name:\n".$ex->{'get'}{'interfaces-ether-print'} : "");    foreach my $interface (split(/\n/, $ex->{'get'}{'interfaces-wlan'})) { $interface =~ s/\=/             /; $interface =~ s/\=/      /; $ex->{'get'}{'interfaces-wlan-print'} .= "#     ".$interface."\n";    } $ex->{'get'}{'interfaces-wlan-print'} = ($ex->{'get'}{'interfaces-wlan-print'} ? "#     default name:     mac:                   name:\n".$ex->{'get'}{'interfaces-wlan-print'} : "");    } elsif(lc($ex->{'get'}{'platform'}) eq "ubiquiti") { ($ex->{'get'}{'identity'}, $err) = trim($ssh->capture2("cat /tmp/system.cfg | grep resolv.host.1.name"));		$ex->{'get'}{'identity'} =~ s/^resolv\.host\.1\.name\=//g; ($ex->{'get'}{'version'}, $err) = trim($ssh->capture2("cat /usr/lib/version")); ($ex->{'get'}{'version-one'}) = $ex->{'get'}{'version'} =~ /^.+v(\d+)\..+$/; ($ex->{'get'}{'board-name'}, $err) = trim($ssh->capture2("cat /etc/board.info | grep board.name"));			$ex->{'get'}{'board-name'} =~ s/^board\.name\=//g; ($ex->{'get'}{'board-shortname'}, $err) = trim($ssh->capture2("cat /etc/board.info | grep board.shortname"));	$ex->{'get'}{'board-shortname'} =~ s/^board\.shortname\=//g; ($ex->{'get'}{'sn'}, $err) = trim($ssh->capture2("cat /etc/board.info | grep board.hwadd"));				$ex->{'get'}{'sn'} =~ s/^board\.hwaddr\=//g; $ex->{'get'}{'model'} = $ex->{'get'}{'board-name'};											$ex->{'get'}{'model'} = ($ex->{'get'}{'model'} ? $ex->{'get'}{'model'} : lang("other", 'other')); ($ex->{'get'}{'ifconfig'}, $err) = trim($ssh->capture2("ifconfig"));    foreach my $interface (split(/\n/, $ex->{'get'}{'ifconfig'})) {    if($interface =~ /^eth\d+.*Link\sencap/) { my $mac = trim(($interface =~ /^eth\d+\s+Link\sencap.*\sHWaddr\s(.*)$/)[0]); $mac =~ s/\-/\:/g; $mac = (($mac =~ /^(.{2}\:.{2}\:.{2}\:.{2}\:.{2}\:.{2}).*$/)[0]); $ex->{'get'}{'interfaces-ether-print'} .= "#     ".trim(($interface =~ /^(eth\d+)\s+Link\sencap.*$/)[0])."      ".$mac."\n";    }    if($interface =~ /^wifi\d+.*Link\sencap/) { my $mac = trim(($interface =~ /^wifi\d+\s+Link\sencap.*\sHWaddr\s(.*)$/)[0]); $mac =~ s/\-/\:/g; $mac = (($mac =~ /^(.{2}\:.{2}\:.{2}\:.{2}\:.{2}\:.{2}).*$/)[0]); $ex->{'get'}{'interfaces-wlan-print'} .= "#     ".trim(($interface =~ /^(wifi\d+)\s+Link\sencap.*$/)[0])."     ".$mac."\n";    }    } $ex->{'get'}{'interfaces-ether-print'} = ($ex->{'get'}{'interfaces-ether-print'} ? "#     name:     mac:\n".$ex->{'get'}{'interfaces-ether-print'} : ""); $ex->{'get'}{'interfaces-wlan-print'} = ($ex->{'get'}{'interfaces-wlan-print'} ? "#     name:     mac:\n".$ex->{'get'}{'interfaces-wlan-print'} : "");    }    if(!$argQuiet) { print "\t - ".lang("info", 'login_after', 'SSH')."\t["; print GREEN, "$LangOK: ".$ex->{'get'}{'platform'}." ".$ex->{'get'}{'board-name'}." v".$ex->{'get'}{'version'}, RESET;  print "][".$portSSH."][".$loginSSH."][".($argShowPassword ? $passwordSSH : "***")."]\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." (".$ex->{'get'}{'platform'}." ".$ex->{'get'}{'board-name'}.")[".$portSSH."][".$loginSSH."][***]"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /done/)) { logSend("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'SSH')." (".$ex->{'get'}{'platform'}." ".$ex->{'get'}{'board-name'}.")[".$portSSH."][".$loginSSH."][***]"); }    if(lc($ex->{'get'}{'platform'}) eq "mikrotik") {    if($ex->{'get'}{'policy'} =~ /\!write/) { my $log = lang("error", "no_permission_to_write", $loginSSH);    if(!$argQuiet) { print "\t - test\t\t\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "]\n"; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $ex->{'value'}." (".$ex->{'host'}.")", $log); } undef $ssh;  next;    }    } $ex->{'ok-port'} = $portSSH; $ex->{'ok-login'} = $loginSSH; $ex->{'ok-password'} = $passwordSSH; $ex->{'mt-enpassword'} = ($ex->{'mt-enpassword'} ? $ex->{'mt-enpassword'} : $passwordSSH); last;    }    if($ex->{'ok-port'} and $ex->{'ok-login'}) { last; }    }    if($ex->{'ok-port'} and $ex->{'ok-login'}) { last; }    }    if(!$ex->{'ok-port'} and !$ex->{'ok-login'}) { next; }    }    }    if($test{'ssh'} eq 1 and ($ex->{'protocol'} =~ /^(ssh|auto)$/ or $ex->{'protocol'} =~ /^ssh\:(mikroitk|mt|ubiquiti|ubnt|ub)$/)) { my $nazwa = podmienName($ex->{"name"}, $ex); my $cNazwa = "cache_".$p_nn; my $nNazwa = "cache_".$nazwa; $ex->{"path"} = podmienPath($ex->{"path"}, $ex);    if(!( -d $ex->{"path"})) { $ex->{"path"} = makeDir("", $ex->{"path"}, $chmod, $chown); }    if(!ziro($ex->{"overwrite"})) {     if($ex->{"path"} eq "/opt/$p_nn/backups") {    if(!( -d $ex->{"path"}."/$nazwa")) { makeDir($ex->{"path"}, $nazwa, $chmod, $chown); } $ex->{"path"} = $ex->{"path"}."/$nazwa";    } $nazwa = $nazwa."_".strftime('%Y-%m-%d_%H-%M-%S',localtime);    } my $coDodac  = "#    ".strftime('%Y/%m/%d %H:%M:%S',localtime)."\n";    $coDodac .= "#    ".lang("info", 'created_by')." $p_name v$p_version [$p_data] ".lang("info", 'more')." http://kazuko.pl\n";    $coDodac .= "#    Version: ".$ex->{'get'}{'version'}."\n";    $coDodac .= "#    Name: ".$ex->{'get'}{'board-name'}."\n";    $coDodac .= (lc($ex->{'get'}{'platform'}) eq "ubiquiti" ? "#    Short Name: ".$ex->{'get'}{"board-shortname"}."\n" : "");    $coDodac .= "#    S\/N: ".$ex->{'get'}{'sn'}."\n";    $coDodac .= "#    Identity: ".$ex->{'get'}{'identity'}."\n";    $coDodac .= (($ex->{'get'}{'interfaces-ether-print'} or $ex->{'get'}{'interfaces-wlan-print'}) ? "\n" : "");    $coDodac .= ($ex->{'get'}{'interfaces-ether-print'} ? "#    Ethernet`s:\n".$ex->{'get'}{'interfaces-ether-print'} : "");    $coDodac .= ($ex->{'get'}{'interfaces-ether-print'} ? "\n" : "");    $coDodac .= ($ex->{'get'}{'interfaces-wlan-print'} ? "#    Wlan`s:\n".$ex->{'get'}{'interfaces-wlan-print'} : "");    if(lc($ex->{'get'}{'platform'}) eq "mikrotik") { %test = (%test, 'rsc' => 0, 'umb' => 0, 'backup' => 0);    if(!$argQuiet) { print "     --> ".lang("info", 'create')."...\n";     } elsif($argQuiet and $argDebug) { print BOLD RED, "\n     --> ".lang("info", 'create')."...", RESET; print "\n";    }    if($ex->{'mt-backup'} =~ /rsc/ or $ex->{'mt-backup'} =~ /all/) {    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } ($done, $err) = $ssh->capture2("/file remove \"$cNazwa.rsc\"");    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } ($done, $err) = $ssh->capture2("/export ".(($ex->{'mt-rsc-verbose'} =~ /^($LangYes|yes)$/) ? "verbose" : "")." file=$cNazwa; :delay 2"); my $pi=0;    for($pi = 0; $pi < 30; $pi++) { sleep 5;    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } my($size, $err) = trim($ssh->capture2(":put [/file get \"$cNazwa.rsc.in_progress\" size]"));    if($size !~ /\d+/) { last;    }    }    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } my($size, $err) = trim($ssh->capture2(":put [/file get \"$cNazwa.rsc\" size]"));    if($size =~ /\d+/ and $size and $size <= $limitBajty) { $test{'rsc'} = 1;    if(!$argQuiet) { print "\t - $nazwa.rsc"; print GREEN, " $LangOK", RESET; print "\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_generated_on')." ($cNazwa.rsc)"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /done/)) { logSend("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_generated_on')." ($cNazwa.rsc)"); }    } else {    if($size > $limitBajty) { my $log = lang("error", "file_larger", $argConfigFile, "config", "limit-backup");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log." ($cNazwa.rsc)"); }    if(!$argQuiet) { print "\t - $nazwa.rsc"; print RED, " $LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } ($done, $err) = $ssh->capture2("/file remove \"$cNazwa.rsc\"");    } else { my $log = lang("error", "lack_file_on");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log." ($cNazwa.rsc)"); }    if(!$argQuiet) { print "\t - $nazwa.rsc"; print RED, " $LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    }    }    }    if($ex->{'mt-backup'} =~ /umb/ or $ex->{'mt-backup'} =~ /all/) {    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } ($done, $err) = $ssh->capture2("/file remove \"$cNazwa.umb\"");    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } my($pUM, $err) = trim($ssh->capture2(":put [/system package get user-manager]"));    if(!($pUM =~ /no\ such\ item/) and $pUM) {    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } ($done, $err) = $ssh->capture2("/tool user-manager database save name=$cNazwa; :delay 2");    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } my($size, $err) = trim($ssh->capture2(":put [/file get \"$cNazwa.umb\" size]"));    if($size =~ /\d+/ and $size and $size <= $limitBajty) { $test{'umb'} = 1;    if(!$argQuiet) { print "\t - $nazwa.umb"; print GREEN, " $LangOK", RESET; print "\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_generated_on')." ($cNazwa.umb)"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /done/)) { logSend("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_generated_on')." ($cNazwa.umb)"); }    } else {    if($size > $limitBajty) { my $log = lang("error", "file_larger", $argConfigFile, "config", "limit-backup");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log." ($cNazwa.umb)"); }    if(!$argQuiet) { print "\t - $nazwa.umb"; print RED, " $LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } ($done, $err) = $ssh->capture2("/file remove \"$cNazwa.umb\"");    } else { my $log = lang("error", "lack_file_on");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log." ($cNazwa.umb)"); }    if(!$argQuiet) { print "\t - $nazwa.umb"; print RED, " $LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    }    }    } else { my $log = lang("error", "no_package_um");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log." ($cNazwa.umb)"); }    if(!$argQuiet) { print "\t - $nazwa.umb"; print RED, " $LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    }    }    if($ex->{'mt-backup'} =~ /backup/ or $ex->{'mt-backup'} =~ /all/) {    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } ($done, $err) = $ssh->capture2("/file remove \"$cNazwa.backup\""); my $run; my @vpol = split(/\./, $ex->{'get'}{'version'});    if($ex->{'mt-encrypt'} =~ /^($LangYes|yes)$/ and $ex->{'mt-enpassword'} and ((@vpol[0] == 6 and @vpol[1] >= 13) or @vpol[0] >= 7)) { $run .= "/system backup save name=$cNazwa dont-encrypt=yes password=".$ex->{'mt-enpassword'};    } else { $run .= "/system backup save name=$cNazwa";    }    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } ($done, $err) = $ssh->capture2($run."; :delay 2");    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } my($size, $err) = trim($ssh->capture2(":put [/file get \"$cNazwa.backup\" size]"));    if($size =~ /\d+/ and $size and $size <= $limitBajty) { $test{'backup'} = 1;    if(!$argQuiet) { print "\t - $nazwa.backup"; print GREEN, " $LangOK", RESET; print "\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_generated_on')." ($cNazwa.backup)"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /done/)) { logSend("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_generated_on')." ($cNazwa.backup)"); }    } else {    if($size > $limitBajty) { my $log = lang("error", "file_larger", $argConfigFile, "config", "limit-backup");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log." ($cNazwa.backup)"); }    if(!$argQuiet) { print "\t - $nazwa.backup"; print RED, " $LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } ($done, $err) = $ssh->capture2("/file remove \"$cNazwa.backup\"");    } else { my $log = lang("error", "lack_file_on");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log." ($cNazwa.backup)"); }    if(!$argQuiet) { print "\t - $nazwa.backup"; print RED, " $LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    }    }    }    if(!$argQuiet) { print "     --> ".lang("info", 'down_and_clean')."...\n";     } elsif($argQuiet and $argDebug) { print BOLD RED, "\n     --> ".lang("info", 'down_and_clean')."...", RESET; print "\n";    }    if($ex->{'mt-backup'} =~ /rsc/ or $ex->{'mt-backup'} =~ /all/ and $test{'rsc'}) {    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } $ssh->scp_get({glob => 1, verbose => ($argDebug ? 1 : 0)}, $cNazwa.".rsc", $ex->{"path"}."/$nNazwa.rsc");    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } ($done, $err) = $ssh->capture2("/file remove \"$cNazwa.rsc\"");    }    if($ex->{'mt-backup'} =~ /umb/ or $ex->{'mt-backup'} =~ /all/ and $test{'umb'}) {    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } $ssh->scp_get({glob => 1, verbose => ($argDebug ? 1 : 0)}, $cNazwa.".umb", $ex->{"path"}."/$nNazwa.umb");    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } ($done, $err) = $ssh->capture2("/file remove \"$cNazwa.umb\"");    }    if($ex->{'mt-backup'} =~ /backup/ or $ex->{'mt-backup'} =~ /all/ and $test{'backup'}) {    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } $ssh->scp_get({glob => 1, verbose => ($argDebug ? 1 : 0)}, $cNazwa.".backup", $ex->{"path"}."/$nNazwa.backup");    if(lc($ex->{'get'}{'platform'}) eq "mikrotik" and $ex->{'get'}{'version-one'} <= 4) { reConnectSSH($ex->{'host'}, $ex->{'ok-port'}, $ex->{'ok-login'}, $ex->{'ok-password'}, $ex->{'ssh-attempt-kill'}, $ex->{'ssh-keypassword'}, $ex->{'ssh-keydsa'}, $knownHosts); } ($done, $err) = $ssh->capture2("/file remove \"$cNazwa.backup\"");    }    if(!$argQuiet) { print "     --> ".lang("info", 'filed_in').": ".$ex->{"path"}."/\n"; }    if($ex->{'mt-backup'} =~ /rsc/ or $ex->{'mt-backup'} =~ /all/) {    if(-f $ex->{"path"}."/$nNazwa.rsc") { plikDopisz($ex->{"path"}."/$nNazwa.rsc", $coDodac."\n\n", "gora", $chmod, $chown); rename($ex->{"path"}."/$nNazwa.rsc", $ex->{"path"}."/$nazwa.rsc"); cchmod($chmod, $ex->{"path"}."/$nazwa.rsc"); cchown($chown, $ex->{"path"}."/$nazwa.rsc");    if(!$argQuiet) { print "\t - $nazwa.rsc"; print GREEN, " $LangOK", RESET; print "\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_saved')." (".$ex->{"path"}."/$nazwa.rsc)"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /done/)) { logSend("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_saved')." (".$ex->{"path"}."/$nazwa.rsc)"); }    } else {  my $log = lang("error", "lack_file");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log." (".$ex->{"path"}."/$nazwa.rsc)"); }    if(!$argQuiet) { print "\t - $nazwa.rsc"; print RED, " $LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    }    }    if($ex->{'mt-backup'} =~ /umb/ or $ex->{'mt-backup'} =~ /all/) {    if(-f $ex->{"path"}."/$nNazwa.umb") { rename($ex->{"path"}."/$nNazwa.umb", $ex->{"path"}."/$nazwa.umb"); cchmod($chmod, $ex->{"path"}."/$nazwa.umb"); cchown($chown, $ex->{"path"}."/$nazwa.umb");    if(!$argQuiet) { print "\t - $nazwa.umb"; print GREEN, " $LangOK", RESET; print "\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_saved')." (".$ex->{"path"}."/$nazwa.umb)"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /done/)) { logSend("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_saved')." (".$ex->{"path"}."/$nazwa.umb)"); }    } else {  my $log = lang("error", "lack_file");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log." (".$ex->{"path"}."/$nazwa.umb)"); }    if(!$argQuiet) { print "\t - $nazwa.umb"; print RED, " $LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    }    }    if($ex->{'mt-backup'} =~ /backup/ or $ex->{'mt-backup'} =~ /all/) {    if(-f $ex->{"path"}."/$nNazwa.backup") { rename($ex->{"path"}."/$nNazwa.backup", $ex->{"path"}."/$nazwa.backup"); cchmod($chmod, $ex->{"path"}."/$nazwa.backup"); cchown($chown, $ex->{"path"}."/$nazwa.backup");    if(!$argQuiet) { print "\t - $nazwa.backup"; print GREEN, " $LangOK", RESET; print "\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_saved')." (".$ex->{"path"}."/$nazwa.backup)"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /done/)) { logSend("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_saved')." (".$ex->{"path"}."/$nazwa.backup)"); }    } else {  my $log = lang("error", "lack_file");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log." (".$ex->{"path"}."/$nazwa.backup)"); }    if(!$argQuiet) { print "\t - $nazwa.backup"; print RED, " $LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    }    }    } elsif(lc($ex->{'get'}{'platform'}) eq "ubiquiti") {    if(!$argQuiet) { print "     --> ".lang("info", 'download')."...\n";     } elsif($argQuiet and $argDebug) { print BOLD RED, "\n     --> ".lang("info", 'download')."...", RESET; print "\n";    } $ssh->scp_get({glob => 1, verbose => ($argDebug ? 1 : 0)}, "/tmp/system.cfg", $ex->{"path"}."/$nNazwa.cfg");    if($ex->{'get'}{'rc.poststart'}) { $coDodac .= "\n\n# /etc/persistent/rc.poststart:\n";    foreach my $lrc (split(/\n/, $ex->{'get'}{'rc.poststart'})) { $coDodac .= "# $lrc\n"; }    }    if(!$argQuiet) { print "     --> ".lang("info", 'filed_in').": ".$ex->{"path"}."/\n"; }    if(-f $ex->{"path"}."/$nNazwa.cfg") { plikDopisz($ex->{"path"}."/$nNazwa.cfg", $coDodac."\n\n", "gora", $chmod, $chown); system("tr -d \"\015\" < ".$ex->{"path"}."/$nNazwa.cfg > ".$ex->{"path"}."/$nazwa.cfg 2> /dev/null"); unlink($ex->{"path"}."/$nNazwa.cfg"); cchmod($chmod, $ex->{"path"}."/$nazwa.cfg"); cchown($chown, $ex->{"path"}."/$nazwa.cfg");    if(!$argQuiet) { print "\t - $nazwa.cfg"; print GREEN, " $LangOK", RESET; print "\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_saved')." (".$ex->{"path"}."/$nazwa.cfg)"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /done/)) { logSend("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_saved')." (".$ex->{"path"}."/$nazwa.cfg)"); }    } else {  my $log = lang("error", "lack_file");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log." (".$ex->{"path"}."/$nazwa.cfg)"); }    if(!$argQuiet) { print "\t - $nazwa.cfg"; print RED, " $LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    }    } $tmpLOGIN->{$ex->{'host'}}{'protocol'} = "ssh"; $tmpLOGIN->{$ex->{'host'}}{'device'} = lc($ex->{'get'}{'platform'}); $tmpLOGIN->{$ex->{'host'}}{'port'} = $ex->{'ok-port'}; $tmpLOGIN->{$ex->{'host'}}{'login'} = $ex->{'ok-login'}; $tmpLOGIN->{$ex->{'host'}}{'password'} = md5_hex($ex->{'ok-password'}); undef $ssh;    }    if(($test{'www'} eq 1 and $test{'ssh'} eq 0 and $ex->{'protocol'} eq "auto") or $ex->{'protocol'} eq "www" or $ex->{'protocol'} =~ /^www\:($devsListWWW)$/) {    foreach my $portWWWW (keys %{$ex->{'www-port-hash'}}) {    foreach my $loginWWW (keys %{$ex->{'www-login-hash'}}) {    foreach my $passwordSSH (keys %{$ex->{'ssh-password-hash'}}) { my $passwordWWW = $ex->{'www-password-hash'}{$passwordWWW}; my %getd = ();    if($ex->{'protocol'} =~ /^www\:($devsListWWW)$/) { $ex->{'protocol'} =~ s/^www\://g;  $getd{$ex->{'protocol'}} = $iniPath->{'v'}{$ex->{'protocol'}};    } else { %getd = %{$iniPath->{'v'}};    }    foreach my $k (sort keys %getd) { my $ua = LWP::UserAgent->new; $ua->timeout(15); my $req =  HTTP::Request->new( GET => "http://".$ex->{'host'}.":".$portWWWW.$getd{$k}{'path'}); $req->authorization_basic($loginWWW, $passwordWWW); my $con = $ua->request($req); $ex->{'get'}{'status_line'} = $con->status_line;    if($con->is_success) { $ex->{'protocol'} = $k; $ex->{'get'}{'platform'} = $getd{$k}{'name'}; $ex->{'get'}{'producer'} = $k; $ex->{'get'}{'model'} = $k; last;    } else { $ex->{'get'}{'platform'} = ""; $ex->{'get'}{'producer'} = ""; $ex->{'get'}{'model'} = "";    }    } $ex->{'get'}{'producer'} = ($ex->{'get'}{'producer'} ? $ex->{'get'}{'producer'} : lang("other", 'other')); $ex->{'get'}{'model'} = ($ex->{'get'}{'model'} ? $ex->{'get'}{'model'} : lang("other", 'other'));     if(!$ex->{'get'}{'platform'}) { my $log = lang("error", "harder_to_fix_the_problem");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'WWW')." ($log)[".$portWWW."][".$loginWWW."][***]"); }    if(!$argQuiet) { print "\t - ".lang("info", 'login_after', 'WWW')."\t["; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; print "][".$portWWW."][".$loginWWW."][".($argShowPassword ? $passwordWWW : "***")."]\n"; }  next;    }    if(!$argQuiet) { print "\t - ".lang("info", 'login_after', 'WWW')."\t["; print GREEN, "$LangOK: ".$ex->{'get'}{'platform'}, RESET;  print "][".$portWWW."][".$loginWWW."][".($argShowPassword ? $passwordWWW : "***")."]\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'WWW')." (".$ex->{'get'}{'platform'}.")[".$portWWW."][".$loginWWW."][***]"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /done/)) { logSend("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("info", 'login_after', 'WWW')." (".$ex->{'get'}{'platform'}.")[".$portWWW."][".$loginWWW."][***]"); } $ex->{'ok-port'} = $portWWWW; $ex->{'ok-login'} = $loginWWW; $ex->{'ok-password'} = $passwordWWW; last;    }    }    if($ex->{'ok-port'} and $ex->{'ok-login'}) { last; }    }    if(!$ex->{'ok-port'} and !$ex->{'ok-login'}) { next; }    if($ex->{'get'}{'platform'}) { my $nazwa = podmienName($ex->{"name"}, $ex); $ex->{"path"} = podmienPath($ex->{"path"}, $ex);    if(!( -d $ex->{"path"})) { $ex->{"path"} = makeDir("", $ex->{"path"}, $chmod, $chown); }    if(!ziro($ex->{"overwrite"})) {     if($ex->{"path"} eq "/opt/$p_nn/backups") {    if(!( -d $ex->{"path"}."/$nazwa")) { makeDir($ex->{"path"}, $nazwa, $chmod, $chown); } $ex->{"path"} = $ex->{"path"}."/$nazwa";    } $nazwa = $nazwa."_".strftime('%Y-%m-%d_%H-%M-%S',localtime);    }    if(!$argQuiet) { print "     --> ".lang("info", 'download')."...\n";     } elsif($argQuiet and $argDebug) { print BOLD RED, "\n     --> ".lang("info", 'download')."...", RESET; print "\n";    } my @tab = split(/\./, getVal($ex->{'protocol'}, 'path', $iniPath)); my $ileTAB =  @tab; my $ua = LWP::UserAgent->new; $ua->timeout(15); my $req =  HTTP::Request->new( GET => "http://".$ex->{'host'}.":".$ex->{'ok-port'}.getVal($ex->{'protocol'}, 'path', $iniPath)); $req->authorization_basic($ex->{'ok-login'}, ($ex->{'ok-password'} ? $ex->{'ok-password'} : "")); my $con = $ua->request($req, $ex->{"path"}."/$nazwa.".@tab[$ileTAB-1]);    if(!$argQuiet) { print "     --> ".lang("info", 'filed_in').": ".$ex->{"path"}."/\n"; }    if(-f $ex->{"path"}."/$nazwa.".@tab[$ileTAB-1]) { cchmod($chmod, $ex->{"path"}."/$nazwa.".@tab[$ileTAB-1]); cchown($chown, $ex->{"path"}."/$nazwa.".@tab[$ileTAB-1]);    if(!$argQuiet) { print "\t - $nazwa.".@tab[$ileTAB-1]; print GREEN, " $LangOK", RESET; print "\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_saved')." (".$ex->{"path"}."/$nazwa.cfg)"); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /done/)) { logSend("done", $ex->{'value'}." (".$ex->{'host'}.")", lang("done", 'file_saved')." (".$ex->{"path"}."/$nazwa.cfg)"); }    } else {  my $log = lang("error", "lack_file");    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $ex->{'value'}." (".$ex->{'host'}.")", $log." (".$ex->{"path"}."/$nazwa.cfg)"); }    if(!$argQuiet) { print "\t - $nazwa.".@tab[$ileTAB-1]; print RED, " $LangError! (", RESET; print $log; print RED, ")", RESET; print "\n"; }    } $tmpLOGIN->{$ex->{'host'}}{'protocol'} = "www"; $tmpLOGIN->{$ex->{'host'}}{'device'} = lc($ex->{'get'}{'platform'}); $tmpLOGIN->{$ex->{'host'}}{'port'} = $ex->{'ok-port'}; $tmpLOGIN->{$ex->{'host'}}{'login'} = $ex->{'ok-login'}; $tmpLOGIN->{$ex->{'host'}}{'password'} = md5_hex($ex->{'ok-password'});    }    }    if(!$argQuiet) { print "     --> ".lang("info", 'time')." "; print CYAN, (time()-$STARTT)." sec", RESET; print "\n"; }    }   }   if($listALL) {    foreach my $nazwa (split(/\|/, $listALL)) { if($nazwa and !(($listNoALL) =~ /\|$nazwa\|/)) {    if(!$argQuiet) { print "\n\n "; print BLUE, $nazwa, RESET; print ":"; } my $log = lang("error", "lack_on_base", $nazwa);    if(!$argQuiet) { print "\n  - "; print RED, "$LangError! (", RESET; print $log; print RED, ")", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", $nazwa, $log); }    if(ziro($sendLogs) and ($sendLogsWhat =~ /all/ or $sendLogsWhat =~ /error/)) { logSend("error", $nazwa, $log); }    }    }   }   if($logSend) { logSend("send", "", "", 1); }   if(scalar keys %{$tmpLOGIN}) { my $iniTMP;    foreach my $section (keys %$tmpLOGIN) {    if($section) {   $iniTMP .= "[$section]\n";      foreach my $key (keys %{$tmpLOGIN->{$section}}) {     $iniTMP .= "$key = $tmpLOGIN->{$section}->{$key}\n";      }   $iniTMP .= "\n";    }    } plikZapisz($LoginFile, $iniTMP, $chmod, $chown);   }
sub ip2long { return unpack('N', inet_aton(shift));}
sub long2ip { return inet_ntoa(pack("N*", shift));}
sub mask2cidr { my($mask) = @_; my(@d, $n, $bits);   if($mask eq "0.0.0.0" ) { return "/0"; } @d = split /\./, $mask; $n = ((((($d[0] * 256) + $d[1])  * 256) + $d[2]) * 256) + $d[3]; $bits = 32;   while (($n % 2) == 0) { $n >>= 1; $bits -= 1; } return "$bits";}
sub ziro {  my($in) = @_;  my $out = 0;    if($in eq $LangYes || $in eq "yes" || $in eq 1) { $out = 1; } else { $out = 0; } return $out; }
sub plikCzytaj {  my($plik) = @_;   open(UCHWYT, $plik);    my @wyjscie = <UCHWYT>;   close (UCHWYT);  return @wyjscie; }
sub plikZapisz {  my($plik, $co, $chmod, $chown) = @_;   open(UCHWYT, '>', $plik) or die lang("error", "unable_to_open", $plik, $!);   print UCHWYT $co;   close UCHWYT;  cchown($chown, $plik); cchmod($chmod, $plik);}
sub plikDopisz {  my($plik,$co,$gdzie,$chmod,$chown) = @_;    if($gdzie eq "gora") { my $odczyt;    foreach my $linia (plikCzytaj($plik)) { $odczyt .= $linia; } plikZapisz($plik, "$co\n".$odczyt);   } else { open(UCHWYT, '>>', $plik) or die lang("error", "unable_to_open", $plik, $!);  print UCHWYT $co;  close UCHWYT;    } cchown($chown, $plik); cchmod($chmod, $plik);}
sub trim($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string;}
sub delHash {  my($tekst) = @_;    if($tekst =~ /^".+".*$/) {  $tekst =~ s/"\s+(#|;)(.*)$//g;   } else {  $tekst =~ s/\s+(#|;)(.*)$//g;  $tekst =~ s/^(#|;).*$//g;   } $tekst =~ s/^\s+//; $tekst =~ s/\s+$//; $tekst =~ s/^("|')//g; $tekst =~ s/("|')$//g; return $tekst;}
sub delCudzyslow {  my($tekst) = @_;  $tekst =~ s/^\s+//; $tekst =~ s/\s+$//; $tekst =~ s/^"//g; $tekst =~ s/"$//g; $tekst =~ s/^'//g; $tekst =~ s/'$//g; return $tekst;}
sub getVal { my($section , $parameter, $ini) = @_; return delHash($ini->val($section, $parameter));}
sub podmien {  my($string, @arr) = @_;  $string =~ s/\%value\%/$arr[0]{'value'}/g; $string =~ s/\%host\%/$arr[0]{'host'}/g; $string =~ s/\%idPC\%/$arr[0]{'idPC'}/g; $string =~ s/\%idKL\%/$arr[0]{'idKL'}/g; $string =~ s/\%ssh\-login\%/$arr[0]{'ssh-login'}/g; $string =~ s/\%ssh\-password\%/$arr[0]{'ssh-password'}/g; $string =~ s/\%ssh\-port\%/$arr[0]{'ssh-port'}/g; $string =~ s/\%www\-login\%/$arr[0]{'www-login'}/g; $string =~ s/\%www\-password\%/$arr[0]{'www-password'}/g; $string =~ s/\%www\-port\%/$arr[0]{'www-port'}/g; return $string;}
sub podmienName {  my($string, $ex) = @_;  $string =~ s/\%value\%/$ex->{'value'}/g; $string =~ s/\%host\%/$ex->{'host'}/g; $string =~ s/\%idComputer\%/$ex->{'idComputer'}/g;		$string =~ s/\%zidComputer\%/$ex->{'zidComputer'}/g; $string =~ s/\%idCustomer\%/$ex->{'idCustomer'}/g;		$string =~ s/\%zidCustomer\%/$ex->{'zidCustomer'}/g; $string =~ s/\%idAddress\%/$ex->{'idAddress'}/g;		$string =~ s/\%zidAddress\%/$ex->{'zidAddress'}/g; $string =~ s/\%idDevice\%/$ex->{'idDevice'}/g;			$string =~ s/\%zidDevice\%/$ex->{'zidDevice'}/g; $string =~ s/\%idNetNode\%/$ex->{'idNetNode'}/g;		$string =~ s/\%zidNetNode\%/$ex->{'zidNetNode'}/g; $string =~ s/\%identity\%/$ex->{'get'}{'identity'}/g;  $string =~ s/\%producer\%/$ex->{'get'}{'producer'}/g; $string =~ s/\%model\%/$ex->{'get'}{'model'}/g; $string =~ s/\%version\%/$ex->{'get'}{'version'}/g; $string =~ s/\s/\_/g; $string =~ s/\(//g; $string =~ s/\)//g; return $string;}
sub podmienPath {  my($string, $ex) = @_;  $string =~ s/\%value\%/$ex->{'value'}/g; $string =~ s/\%host\%/$ex->{'host'}/g; $string =~ s/\%name\%/$ex->{'name'}/g; $string =~ s/\%idComputer\%/$ex->{'idComputer'}/g;		$string =~ s/\%zidComputer\%/$ex->{'zidComputer'}/g; $string =~ s/\%idCustomer\%/$ex->{'idCustomer'}/g;		$string =~ s/\%zidCustomer\%/$ex->{'zidCustomer'}/g; $string =~ s/\%idAddress\%/$ex->{'idAddress'}/g;		$string =~ s/\%zidAddress\%/$ex->{'zidAddress'}/g; $string =~ s/\%idDevice\%/$ex->{'idDevice'}/g;			$string =~ s/\%zidDevice\%/$ex->{'zidDevice'}/g; $string =~ s/\%idNetNode\%/$ex->{'idNetNode'}/g;		$string =~ s/\%zidNetNode\%/$ex->{'zidNetNode'}/g; $string =~ s/\%identity\%/$ex->{'get'}{'identity'}/g;  $string =~ s/\%producer\%/$ex->{'get'}{'producer'}/g; $string =~ s/\%model\%/$ex->{'get'}{'model'}/g; $string =~ s/\%version\%/$ex->{'get'}{'version'}/g; $string =~ s/\s/\_/g; $string =~ s/\(//g; $string =~ s/\)//g; return $string;}
sub usunWWyr {  my($string, @arr) = @_;  $string =~ s/\%dirYear\%//g; $string =~ s/\%dirMonth\%//g; return $string;}
sub path {  my($path) = @_;  my $pwd = trim(gdzieScript($0)) || trim(cwd)."/"; my $domowy = $ENV{"HOME"}; my $year = strftime('%Y',localtime); my $month = sprintf("%02d", strftime('%m',localtime)); $path =~ s/\%dirYear\%/$year/g; $path =~ s/\%dirMonth\%/$month/g; $path =~ s/^\~\//$domowy\//g; $path =~ s/^\.\//$pwd/g; return $path; }
sub gdzieScript { my($polecenie) = @_;  my @tab = split(/\//, $polecenie);  my $ileTAB =  @tab;  $polecenie =~ s/@tab[$ileTAB-1]//g; return trim($polecenie);}
sub cchmod { my($chmod, $path) = @_;  chmod oct(sprintf("%04d", ($chmod || "0755"))), $path;}
sub cchown { my($chown, $path) = @_;  my $whoami = qx(whoami);  $whoami = trim($whoami); $chown =~ s/\%user\%/$whoami/g; $chown =~ s/\%group\%/$whoami/g; my ($uid, $gid) = split(/\:/, $chown); $uid = ($uid ? (($uid =~ /\d+/) ? $uid : getpwnam($uid)) : $whoami); $gid = ($gid ? (($gid =~ /\d+/) ? $gid : getgrnam($gid)) : $whoami); chown $uid, $gid, $path;}
sub makeDir { my($path, $tworz, $chmod, $chown) = @_;     foreach my $ou (split(/\//, $tworz)) { if($ou) { $path = (!($path eq "/" or !$path) ? $path : "")."/".$ou;    if(!( -d $path)) { mkdir($path); cchmod($chmod, $path); cchown($chown, $path); }   }} return $path; }
sub ping { my($pingBinary, $pingCount, $interface, $host) = @_;  my $ping = 0; $interface = ($interface ? "-I '$interface'" : "");   open(PROCESS, "$pingBinary -c $pingCount $interface -w 1 $host | grep 'icmp_[s|r]eq' | grep time |"); $ping = <PROCESS>;   close(PROCESS); $ping =~ m/(.*time=)(.*) (ms|usec)/;   if($2 == "") { $ping = "U"; } elsif($3 eq "usec") { $ping = $2/1000; } else { $ping = $2; } return $ping; }
sub toBajt { my($z, $na) = @_; my $out = 0;   if($z =~ /^[0-9]*[k|K|m|M|g|G|t|T]?$/) {    if($z =~ /^[0-9]*[k|K]$/) { $z =~ s/[k|K]$//g; $z = $z*1024;    } elsif($z =~ /^[0-9]*[m|M]$/) { $z =~ s/[m|M]$//g; $z = $z*1024*1024;    } elsif($z =~ /^[0-9]*[g|G]$/) { $z =~ s/[g|G]$//g; $z = $z*1024*1024*1024;    } elsif($z =~ /^[0-9]*[t|T]$/) { $z =~ s/[t|T]$//g; $z = $z*1024*1024*1024*1024;    }    if($na =~ /^[k|K]$/) { $out = ($z/1024)."k";    } elsif($na =~ /^[m|M]$/) { $out = ($z/(1024*1024))."M";    } elsif($na =~ /^[g|G]$/) { $out = ($z/(1024*1024*1024))."G";    } elsif($na =~ /^[t|T]$/) { $out = ($z/(1024*1024*1024*1024))."T";    } else { $out = $z;    }   } return $out;}
sub vTest {  my($repo, $prog) = @_;  my $out; my $ua = LWP::UserAgent->new; $ua->agent("$prog/$p_version/$p_data/$p_lang"); my $reqCHANGELOG = HTTP::Request->new(POST => "$repo/$prog/".($p_lang ne "pl_PL" ? "lang/$p_lang/" : "")."CHANGELOG_ALL"); $reqCHANGELOG->content_type('application/x-www-form-urlencoded'); $reqCHANGELOG->content('query=libwww-perl&mode=dist'); $resCHANGELOG = $ua->request($reqCHANGELOG);   if($resCHANGELOG->is_success) { my $outCHANGELOG = $resCHANGELOG->content; my %versions; my $dateMnie = $p_data; my $versionMnie = $p_version; my $dateCurrent; my $versionCurrent; my $linkCurrent; my $datePrevious; my $versionPrevious; my $linkPrevious; $outCHANGELOG =~ s/\r//g;    foreach my $line (split(/\n/, $outCHANGELOG)) {    if($line  =~ /^v\d+.*\[\d{2,2}\-\d{2,2}\-\d{4,4}\]$/) { my ($v, $d, $l) = $line =~ /^v(.+)\s*\[(.*)\]\s*\[*(.*)\]*$/;    if(!$dateCurrent) { $dateCurrent = trim($d); $versionCurrent = trim($v); $linkCurrent = trim($l);    } else {    if(!$datePrevious) { $datePrevious = trim($d); $versionPrevious = trim($v); $linkPrevious = trim($l);    }    }    }    }    if($p_data  =~ /^\d{2,2}\.\d{2,2}\.\d{4,4}$/) { my ($dd, $mm, $rrrr) = split(/\./, $p_data); $dateMnie = "$rrrr-$mm-$dd";    }    if($dateCurrent  =~ /^\d{2,2}\-\d{2,2}\-\d{4,4}$/) { my ($dd, $mm, $rrrr) = split(/\-/, $dateCurrent); $dateCurrent = "$rrrr-$mm-$dd";    }    if($datePrevious  =~ /^\d{2,2}\-\d{2,2}\-\d{4,4}$/) { my ($dd, $mm, $rrrr) = split(/\-/, $datePrevious); $datePrevious = "$rrrr-$mm-$dd";    } print " ".lang("arg", 'your-version').":\t\t$versionMnie [$dateMnie]\n"; print " ".lang("arg", 'latest-version').":\t".$versionCurrent." [".$dateCurrent."]\n"; print " ".lang("arg", 'previous-version').":\t".$versionPrevious." [".$datePrevious."]\n"; print " ---------------------------------------------------\n";    if(str2time($dateMnie) >= str2time($dateCurrent)) { print BOLD BLUE, " ".lang("arg", 'current-versions').".\n", RESET;    } else {    if($linkCurrent  =~ /^http\:\/\/.+$/) { print BOLD GREEN, " ".lang("arg", 'new-version'), RESET; print " - ".lang("arg", 'downurl', $linkCurrent).".\n";    } else { print BOLD GREEN, " ".lang("arg", 'new-version'), RESET; print " - ".lang("arg", 'contact', 'seszu (seba@kazuko.pl)').".\n";    } print "\n"; print "  ".lang("other", 'see_changes').": $repo/$prog/".($p_lang ne "pl_PL" ? "lang/$p_lang/" : "")."CHANGELOG_ALL\n";    }   } else { print $resCHANGELOG->status_line, "\n";   }}
sub lang { my($section, $parameter, $var1, $var2, $var3, $var4) = @_;  my $out = delHash($iniLANG->val($section, $parameter));    if($var1) { $out =~ s/\%1/$var1/g; } else { $out =~ s/\s\%1//g; $out =~ s/\%1\s//g; $out =~ s/\%1//g; }    if($var2) { $out =~ s/\%2/$var2/g; } else { $out =~ s/\s\%2//g; $out =~ s/\%2\s//g; $out =~ s/\%2//g; }    if($var3) { $out =~ s/\%3/$var3/g; } else { $out =~ s/\s\%3//g; $out =~ s/\%3\s//g; $out =~ s/\%3//g; }    if($var4) { $out =~ s/\%4/$var4/g; } else { $out =~ s/\s\%4//g; $out =~ s/\%4\s//g; $out =~ s/\%4//g; } $out =~ s/\s\%\d//g; $out =~ s/\%\d\s//g; $out =~ s/\%\d//g; return $out;}
sub logi {  my($stan, $name, $logSave) = @_;  my $whoami = qx(whoami);		 $whoami = trim($whoami); $name = ($name ? $name : "system");   if(!( -d $logsDir) and $logsDir ne "/opt/$p_nn/log") { makeDir("", $logsDir, $chmod, $chown); } $stan = ($stan eq "done" ? $stan."   " : ($stan eq "error" ? $stan."  " : $stan));   if(!( -f "$logsDir/$p_nn.log")) { plikZapisz("$logsDir/$p_nn.log", strftime('%d-%m-%Y %H:%M:%S',localtime)."   $stan   $whoami: [$name]   $logSave\n", "", $chmod, $chown);   } else { plikDopisz("$logsDir/$p_nn.log", strftime('%d-%m-%Y %H:%M:%S',localtime)."   $stan   $whoami: [$name]   $logSave\n", "", $chmod, $chown);   } my $waga = (stat("$logsDir/$p_nn.log"))[7];   if($waga >= 1267206) { 		 my $zz = 0;    foreach my $file (sort glob("$logsDir/$p_nn.*.log.gz")) { $file =~  s/$logsDir\/$p_nn.(\d+).log.gz//g; $zz = $1;    } ++$zz; rename("$logsDir/$p_nn.log", "$logsDir/$p_nn.$zz.log");	 my $tar = Archive::Tar->new(); $tar->add_files("$logsDir/$p_nn.$zz.log"); $tar->write("$logsDir/$p_nn.$zz.log.gz", COMPRESS_GZIP);		 cchmod($chmod, "$logsDir/$p_nn.$zz.log.gz"); cchown($chown, "$logsDir/$p_nn.$zz.log.gz"); unlink("$logsDir/$p_nn.$zz.log");   }}
sub logSend {  my($stan, $name, $logSave, $send) = @_;    if($stan ne "send") {  my $stanLog = ($stan eq "done" ? $stan."   " : ($stan eq "error" ? $stan."  " : $stan));  $logSend .= "<font color='".($stan eq "error" ? "#db0101" : ($stan eq "warning" ? "#d47c0a" : "#22b401"))."'>".strftime('%d-%m-%Y %H:%M:%S',localtime)."   $stanLog   [$name]   $logSave</font>\n";   }   if($send) {    if(!$argQuiet) { print "\n > ".lang("info", 'send_log')."... ";     } elsif($argQuiet and $argDebug) { print BOLD RED, "\n\n > ".lang("info", 'send_log')."...", RESET; print "\n";    } my $fromMailOrg = $fromMail; my $sender = new Mail::Sender;    if(ref($sender->OpenMultipart({ smtp => $smtpHost, port => $smtpPort, from => $fromMail, to => $toMail, subject => "[$p_short] [logi] [".strftime('%d-%m-%Y %H:%M:%S',localtime)."]", auth => $smtpAuth, authid => $smtpLogin, authpwd => $smtpPassword, TLS_allowed => 0, messageid => "<".Email::MessageID->new(host => ((split(/\@/, $fromMailOrg))[1])).">",    }))) { $sender->Body({ ctype => 'text/html',  encoding => 'quoted-printable',  charset => 'UTF-8',  msg => "<pre>".codePL($logSend)."</pre>\n",  }); $sender->Close;    if(!$argQuiet) { print GREEN, " $LangOK", RESET; print "\n"; }    if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /done/)) { logi("done", "", lang("done", "send_log")); }    } else { my $log = lang("error", "send_log")." ($Mail::Sender::Error)";    if(!$argQuiet) { print RED, "\n\t $LangError! (", RESET; print $log; print RED, ")\n", RESET; }     if(ziro($logs) and ($logsWhat =~ /all/ or $logsWhat =~ /error/)) { logi("error", "", $log); }    }   }}
sub codePL { my($txt) = @_; my %code = ("ą" => "&#261;", "ć" => "&#263;", "ę" => "&#281;", "ł" => "&#322;", "ń" => "&#324;", "ó" => "&#243;", "ś" => "&#347;", "ż" => "&#378;", "ź" => "&#380;", "Ą" => "&#260;", "Ć" => "&#262;", "Ę" => "&#280;", "Ł" => "&#321;", "Ń" => "&#323;", "Ó" => "&#242;", "Ś" => "&#346;", "Ż" => "&#377;", "Ź" => "&#379;",);   foreach my $k (keys %code) { $txt =~ s/$k/$code{$k}/g;   } return $txt;}
sub delSpecial { my($tekst) = @_;    foreach my $k (@{$iniLANG->{'parms'}{'special'}}) { my $n=lang("special", $k); $tekst =~ s/$k/$n/g;   } return $tekst;}
sub delQuotes { my($tekst) = @_;  $tekst =~ s/^'//g; $tekst =~ s/'$//g; return $tekst;}
sub killprog {   my($nprog, $life) = @_;   my @lists = qx(ps -aux 2> /dev/null | grep '$nprog' );   foreach my $out (@lists) { if(!($out =~ /^.*grep.*$/)) { $out = trim($out); my @tab = split(/\s+/, $out); my @tim = split(/\:/, @tab[9]);    if(@tim[0] > $life) { system("kill -9 ".@tab[1]." 1> /dev/null 2> /dev/null");	    }   }} return 1;}
sub reConnectSSH {   my($hostSSHin, $portSSHin, $loginSSHin, $passwordSSHin, $attemptKillSSHin, $keypasswordSSHin, $keydsaSSHin, $knownHosts) = @_;   if($ex->{'ssh-key'} =~ /^($LangYes|yes)$/) { $ssh = Net::OpenSSH->new($hostSSHin, user => $loginSSHin, port => $portSSHin, timeout => 30, kill_ssh_on_timeout => $attemptKillSSHin, master_stderr_discard => 1, master_opts => [-o => "UserKnownHostsFile=$knownHosts", -o => "StrictHostKeyChecking=no"], passphrase => $keypasswordSSHin, key_path => $keydsaSSHin);   } else { $ssh = Net::OpenSSH->new($hostSSHin, user => $loginSSHin, password => $passwordSSHin, port => $portSSHin, timeout => 30, kill_ssh_on_timeout => $attemptKillSSHin, master_stderr_discard => 1, master_opts => [-o => "UserKnownHostsFile=$knownHosts", -o => "StrictHostKeyChecking=no"]);   }}   if($argDB ne "ini" and $dbase) { $dbase->disconnect(); }   if(!$argQuiet) { print "\n\n "; print BOLD MAGENTA, lang("other", 'end')." (", RESET; print BOLD CYAN, (time()-$START)." sec", RESET; print BOLD MAGENTA, ")", RESET; print "\n\n";   }