\n";
}
return;
}
# end editfile
###############################################################################
# start savefile
sub savefile {
my $file = shift;
my $restart = shift;
$FORM{formdata} =~ s/\r//g;
if ($FORM{ace} == "1") {
if ($FORM{formdata} !~ /^# Do not remove or change this line as it is a safeguard for the UI editor\n/) {
print "
UI editor safeguard missing, changes have not been saved.
\n";
return;
}
$FORM{formdata} =~ s/^# Do not remove or change this line as it is a safeguard for the UI editor\n//g;
}
sysopen (my $OUT, $file, O_WRONLY | O_CREAT) or die "Unable to open file: $!";
flock ($OUT, LOCK_EX);
seek ($OUT, 0, 0);
truncate ($OUT, 0);
if ($FORM{formdata} !~ /\n$/) {$FORM{formdata} .= "\n"}
print $OUT $FORM{formdata};
close ($OUT);
if ($restart eq "csf") {
print "
Changes saved. You should restart csf.
Changes saved. You should restart lfd.
Changes saved. You should restart csf and lfd.\n";
print "
\n";
}
else {
print "
Changes saved.
\n";
}
return;
}
# end cloudflare
###############################################################################
# start cloudflare
sub cloudflare {
my $scope = &ConfigServer::CloudFlare::getscope();
print "
\n";
print "\n";
print "\n";
print "
\n";
print "csf - CloudFlare ";
print "Select the user(s), then select the action below \n";
foreach my $user (keys %{$scope->{user}}) {print "$user \n"}
print " \n";
# } else {
# print "Select the domain(s), then select the action below \n";
# foreach my $domain (keys %{$scope->{domain}}) {print "$domain \n"}
# print " \n";
# }
print "CF List Rules ";
print "CloudFlare Add \n";
print "CloudFlare Delete \n";
print "CF Temp Allow/Deny ";
print "
\n";
print "
\n";
print "
Note:\n
\n";
print "target can be one of:An IP address \n2 letter Country Code \nIP range CIDR \n \n";
print "Only Enterprise customers can block a Country Code, but all can allow and challenge \n";
print " \nIP range CIDR is limited to /16 and /24 \n";
print "\n";
&printreturn;
return;
}
# end cloudflare
###############################################################################
# start resize
sub resize {
my $part = shift;
my $scroll = shift;
if ($part eq "top") {
print "
a \n";
print "A
\n";
} else {
print "
EOF
}
return;
}
# end resize
###############################################################################
# start printreturn
sub printreturn {
print "
\n";
return;
}
# end printreturn
###############################################################################
# start confirmmodal
# print "
Submit \n";
# &confirmmodal;
sub confirmmodal {
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print "
text \n";
print "\n";
print "\n";
print "
\n";
print "
\n";
print "
\n";
print "\n";
return;
}
# end confirmmodal
###############################################################################
# start csgetversion
sub csgetversion {
my $product = shift;
my $current = shift;
my $upgrade = 0;
my $newversion;
if (-e "/var/lib/configserver/".$product.".txt.error") {
open (my $VERSION, "<", "/var/lib/configserver/".$product.".txt.error");
flock ($VERSION, LOCK_SH);
$newversion = <$VERSION>;
close ($VERSION);
chomp $newversion;
if ($newversion eq "") {
$newversion = "Failed to retrieve latest version from ConfigServer";
} else {
$newversion = "Failed to retrieve latest version from ConfigServer: $newversion";
}
}
elsif (-e "/var/lib/configserver/".$product.".txt") {
open (my $VERSION, "<", "/var/lib/configserver/".$product.".txt");
flock ($VERSION, LOCK_SH);
$newversion = <$VERSION>;
close ($VERSION);
chomp $newversion;
if ($newversion eq "") {
$newversion = "Failed to retrieve latest version from ConfigServer";
} else {
if ($newversion =~ /^[\d\.]*$/) {
if ($newversion > $current) {$upgrade = 1} else {$newversion = ""}
} else {$newversion = ""}
}
}
elsif (-e "/var/lib/configserver/error") {
open (my $VERSION, "<", "/var/lib/configserver/error");
flock ($VERSION, LOCK_SH);
$newversion = <$VERSION>;
close ($VERSION);
chomp $newversion;
if ($newversion eq "") {
$newversion = "Failed to retrieve latest version from ConfigServer";
} else {
$newversion = "Failed to retrieve latest version from ConfigServer: $newversion";
}
} else {
$newversion = "Failed to retrieve latest version from ConfigServer";
}
return ($upgrade, $newversion);
}
# end csgetversion
###############################################################################
# start manualversion
sub manualversion {
my $current = shift;
my $upgrade = 0;
my $url = "https://$config{DOWNLOADSERVER}/csf/version.txt";
if ($config{URLGET} == 1) {$url = "http://$config{DOWNLOADSERVER}/csf/version.txt";}
my ($status, $newversion) = $urlget->urlget($url);
if (!$status and $newversion ne "" and $newversion =~ /^[\d\.]*$/ and $newversion > $current) {$upgrade = 1} else {$newversion = ""}
return ($upgrade, $newversion);
}
# end manualversion
###############################################################################
1;
Service.pm 0000644 00000005602 15103002075 0006476 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::Service;
use strict;
use lib '/usr/local/csf/lib';
use Carp;
use IPC::Open3;
use Fcntl qw(:DEFAULT :flock);
use ConfigServer::Config;
use Exporter qw(import);
our $VERSION = 1.01;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
my $config = ConfigServer::Config->loadconfig();
my %config = $config->config();
open (my $IN, "<", "/proc/1/comm");
flock ($IN, LOCK_SH);
my $sysinit = <$IN>;
close ($IN);
chomp $sysinit;
if ($sysinit ne "systemd") {$sysinit = "init"}
# end main
###############################################################################
# start type
sub type {
return $sysinit;
}
# end type
###############################################################################
# start startlfd
sub startlfd {
if ($sysinit eq "systemd") {
&printcmd($config{SYSTEMCTL},"start","lfd.service");
&printcmd($config{SYSTEMCTL},"status","lfd.service");
} else {
&printcmd("/etc/init.d/lfd","start");
}
return;
}
# end startlfd
###############################################################################
# start stoplfd
sub stoplfd {
if ($sysinit eq "systemd") {
&printcmd($config{SYSTEMCTL},"stop","lfd.service");
}
else {
&printcmd("/etc/init.d/lfd","stop");
}
return;
}
# end stoplfd
###############################################################################
# start restartlfd
sub restartlfd {
if ($sysinit eq "systemd") {
&printcmd($config{SYSTEMCTL},"restart","lfd.service");
&printcmd($config{SYSTEMCTL},"status","lfd.service");
}
else {
&printcmd("/etc/init.d/lfd","restart");
}
return;
}
# end restartlfd
###############################################################################
# start restartlfd
sub statuslfd {
if ($sysinit eq "systemd") {
&printcmd($config{SYSTEMCTL},"status","lfd.service");
}
else {
&printcmd("/etc/init.d/lfd","status");
}
return 0
}
# end restartlfd
###############################################################################
# start printcmd
sub printcmd {
my @command = @_;
if ($config{DIRECTADMIN}) {
my $doublepid = fork;
if ($doublepid == 0) {
my ($childin, $childout);
my $pid = open3($childin, $childout, $childout, @command);
while (<$childout>) {print $_}
waitpid ($pid, 0);
exit;
}
waitpid ($doublepid, 0);
} else {
my ($childin, $childout);
my $pid = open3($childin, $childout, $childout, @command);
while (<$childout>) {print $_}
waitpid ($pid, 0);
}
return;
}
# end printcmd
###############################################################################
1; Sendmail.pm 0000644 00000010361 15103002075 0006630 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::Sendmail;
use strict;
use lib '/usr/local/csf/lib';
use Carp;
use POSIX qw(strftime);
use Fcntl qw(:DEFAULT :flock);
use ConfigServer::Config;
use ConfigServer::CheckIP qw(checkip);
use Exporter qw(import);
our $VERSION = 1.02;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
my $config = ConfigServer::Config->loadconfig();
my %config = $config->config();
my $tz = strftime("%z", localtime);
my $hostname;
if (-e "/proc/sys/kernel/hostname") {
open (my $IN, "<", "/proc/sys/kernel/hostname");
flock ($IN, LOCK_SH);
$hostname = <$IN>;
chomp $hostname;
close ($IN);
} else {
$hostname = "unknown";
}
if ($config{LF_ALERT_SMTP}) {
require Net::SMTP;
import Net::SMTP;
}
# end main
###############################################################################
# start sendmail
sub relay {
my ($to, $from, @message) = @_;
my $time = localtime(time);
if ($to eq "") {$to = $config{LF_ALERT_TO}} else {$config{LF_ALERT_TO} = $to}
if ($from eq "") {$from = $config{LF_ALERT_FROM}} else {$config{LF_ALERT_FROM} = $from}
my $data;
if ($from =~ /([\w\.\=\-\_]+\@[\w\.\-\_]+)/) {$from = $1}
if ($from eq "") {$from = "root"}
if ($to =~ /([\w\.\=\-\_]+\@[\w\.\-\_]+)/) {$to = $1}
if ($to eq "") {$to = "root"}
my $header = 1;
foreach my $line (@message) {
$line =~ s/\r//;
if ($line eq "") {$header = 0}
$line =~ s/\[time\]/$time $tz/ig;
$line =~ s/\[hostname\]/$hostname/ig;
if ($header) {
if ($line =~ /^To:\s*(.*)\s*$/i) {
my $totxt = $1;
if ($config{LF_ALERT_TO} ne "") {
$line =~ s/^To:.*$/To: $config{LF_ALERT_TO}/i;
} else {
$to = $totxt;
}
}
if ($line =~ /^From:\s*(.*)\s*$/i) {
my $fromtxt = $1;
if ($config{LF_ALERT_FROM} ne "") {
$line =~ s/^From:.*$/From: $config{LF_ALERT_FROM}/i;
} else {
$from = $1;
}
}
}
$data .= $line."\n";
}
$data = &wraptext($data, 990);
if ($config{LF_ALERT_SMTP}) {
if ($from !~ /\@/) {$from .= '@'.$hostname}
if ($to !~ /\@/) {$to .= '@'.$hostname}
my $smtp = Net::SMTP->new($config{LF_ALERT_SMTP}, Timeout => 10) or carp("Unable to send SMTP alert via [$config{LF_ALERT_SMTP}]: $!");
if (defined $smtp) {
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend($data);
$smtp->dataend();
$smtp->quit();
}
} else {
local $SIG{CHLD} = 'DEFAULT';
my $error = 0;
open (my $MAIL, "|-", "$config{SENDMAIL} -f $from -t") or carp("Unable to send SENDMAIL alert via [$config{SENDMAIL}]: $!");
print $MAIL $data;
close ($MAIL) or $error = 1;
if ($error and $config{DEBUG}) {
logfile("Failed to send message via sendmail binary: $?");
logfile("Failed message: [$data]");
}
}
return;
}
# end sendmail
###############################################################################
# start wraptext
sub wraptext {
my $text = shift;
my $column = shift;
my $original = $text;
my $return = "";
my $hit = 1;
my $loop = 0;
while ($hit) {
$hit = 0;
$return = "";
foreach my $line (split(/\n/, $text)) {
if (length($line) > $column) {
foreach ($line =~ /(.{1,$column})/g) {
my $chunk = $_;
my $newchunk = "";
my $thishit = 0;
my @chars = split(//,$chunk);
for (my $x = length($chunk)-1;$x >= 0; $x--) {
if ($chars[$x] =~ /\s/) {
for (0..$x) {$newchunk .= $chars[$_]}
$newchunk .= "\n";
for ($x+1..length($chunk)-1) {$newchunk .= $chars[$_]}
$thishit = 1;
last;
}
}
if ($thishit) {
$hit = 1;
$thishit = 0;
$return .= $newchunk;
} else {
$return .= $chunk."\n";
}
}
} else {
$return .= $line."\n";
}
}
$text = $return;
$loop++;
if ($loop > 1000) {
return $original;
last;
}
}
if (length($return) < length($original)) {$return = $original}
return $return;
}
# end wraptext
###############################################################################
1; ServerStats.pm 0000644 00000414671 15103002075 0007375 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::ServerStats;
use strict;
use lib '/usr/local/csf/lib';
use Fcntl qw(:DEFAULT :flock);
use Exporter qw(import);
our $VERSION = 1.02;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
my %minmaxavg;
# end main
###############################################################################
# start init
sub init {
eval ('use GD::Graph::bars;'); ##no critic
if ($@) {return undef}
eval ('use GD::Graph::pie;'); ##no critic
if ($@) {return undef}
eval ('use GD::Graph::lines;'); ##no critic
if ($@) {return undef}
}
# end init
###############################################################################
# start graphs
sub graphs {
my $type = shift;
my $system_maxdays = shift;
my $imghddir = shift;
my $img;
$| = 1;
require GD::Graph::bars;
import GD::Graph::bars;
require GD::Graph::pie;
import GD::Graph::pie;
require GD::Graph::lines;
import GD::Graph::lines;
sysopen (my $STATS,"/var/lib/csf/stats/system", O_RDWR | O_CREAT);
flock ($STATS, LOCK_SH);
my @stats = <$STATS>;
chomp @stats;
close ($STATS);
if (@stats > 1) {
local $SIG{__DIE__} = undef;
my $time = time;
my %stata;
foreach my $line (@stats) {
my ($thistime,undef) = split(/\,/,$line);
if (time - $thistime > (86400 * $system_maxdays)) {next}
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($thistime);
$stata{$year}{$mon}{$mday}{$hour}{$min} = $line;
}
if ($type eq "cpu") {
my (@h,@p,@t);
my $cputotal_prev;
my $cpuidle_prev;
my $cpuiowait_prev;
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $cputotal eq "") {
$cputotal_prev = 0;
$cpuidle_prev = 0;
$cpuiowait_prev = 0;
push @p,undef;
push @t,undef;
} else {
my $idle_diff = $cpuidle - $cpuidle_prev;
my $iowait_diff = $cpuiowait - $cpuiowait_prev;
my $total_diff = $cputotal - $cputotal_prev;
if ($total_diff == 0) {
$cputotal_prev = 0;
$cpuidle_prev = 0;
$cpuiowait_prev = 0;
push @p,undef;
push @t,undef;
next;
}
my $idle_use = 100 - 100 * ($total_diff - $idle_diff) / $total_diff;
my $iowait_use = 100 - 100 * ($total_diff - $iowait_diff) / $total_diff;
$cpuidle_prev = $cpuidle;
$cpuiowait_prev = $cpuiowait;
$cputotal_prev = $cputotal;
push @p,$idle_use;
push @t,$iowait_use;
&minmaxavg("HOUR","1Idle",$idle_use);
&minmaxavg("HOUR","2IOWAIT",$iowait_use);
}
}
if ($minmaxavg{HOUR}{"1Idle"}{CNT} > 0) {$minmaxavg{HOUR}{"1Idle"}{AVG} /= $minmaxavg{HOUR}{"1Idle"}{CNT}}
if ($minmaxavg{HOUR}{"2IOWAIT"}{CNT} > 0) {$minmaxavg{HOUR}{"2IOWAIT"}{AVG} /= $minmaxavg{HOUR}{"2IOWAIT"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => '% CPU',
x_label_skip => 3,
line_width => 2,
title => 'CPU Usage in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Idle IOWAIT));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "cpu") {
my (@h,@p,@t);
my $cputotal_prev;
my $cpuidle_prev;
my $cpuiowait_prev;
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $cputotal eq "") {
$cputotal_prev = 0;
$cpuidle_prev = 0;
$cpuiowait_prev = 0;
push @p,undef;
push @t,undef;
} else {
my $idle_diff = $cpuidle - $cpuidle_prev;
my $iowait_diff = $cpuiowait - $cpuiowait_prev;
my $total_diff = $cputotal - $cputotal_prev;
if ($total_diff == 0) {
$cputotal_prev = 0;
$cpuidle_prev = 0;
$cpuiowait_prev = 0;
push @p,undef;
push @t,undef;
next;
}
my $idle_use = 100 - 100 * ($total_diff - $idle_diff) / $total_diff;
my $iowait_use = 100 - 100 * ($total_diff - $iowait_diff) / $total_diff;
$cpuidle_prev = $cpuidle;
$cpuiowait_prev = $cpuiowait;
$cputotal_prev = $cputotal;
push @p,$idle_use;
push @t,$iowait_use;
&minmaxavg("DAY","1Idle",$idle_use);
&minmaxavg("DAY","2IOWAIT",$iowait_use);
}
}
if ($minmaxavg{DAY}{"1Idle"}{CNT} > 0) {$minmaxavg{DAY}{"1Idle"}{AVG} /= $minmaxavg{DAY}{"1Idle"}{CNT}}
if ($minmaxavg{DAY}{"2IOWAIT"}{CNT} > 0) {$minmaxavg{DAY}{"2IOWAIT"}{AVG} /= $minmaxavg{DAY}{"2IOWAIT"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => '% CPU',
x_label_skip => 60,
title => 'CPU Usage in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Idle IOWAIT));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "cpu") {
my (@h,@p,@t);
my $cputotal_prev;
my $cpuidle_prev;
my $cpuiowait_prev;
$minmaxavg{WEEK}{"1Idle"}{MIN} = 100;
$minmaxavg{WEEK}{"1Idle"}{MAX} = 0;
$minmaxavg{WEEK}{"2IOWAIT"}{MIN} = 100;
$minmaxavg{WEEK}{"2IOWAIT"}{MAX} = 0;
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $idle_avg;
my $iowait_avg;
my $cnt_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $cputotal ne "") {
my $idle_diff = $cpuidle - $cpuidle_prev;
my $iowait_diff = $cpuiowait - $cpuiowait_prev;
my $total_diff = $cputotal - $cputotal_prev;
if ($total_diff == 0) {
$cputotal_prev = 0;
$cpuidle_prev = 0;
$cpuiowait_prev = 0;
next;
}
my $idle_use = 100 - 100 * ($total_diff - $idle_diff) / $total_diff;
my $iowait_use = 100 - 100 * ($total_diff - $iowait_diff) / $total_diff;
$cpuidle_prev = $cpuidle;
$cpuiowait_prev = $cpuiowait;
$cputotal_prev = $cputotal;
$idle_avg += $idle_use;
$iowait_avg += $iowait_use;
$cnt_avg++;
} else {
$cputotal_prev = 0;
$cpuidle_prev = 0;
$cpuiowait_prev = 0;
}
}
unless (defined $cnt_avg) {
push @p,undef;
push @t,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$idle_avg/$cnt_avg;
push @t,$iowait_avg/$cnt_avg;
&minmaxavg("WEEK","1Idle",($idle_avg/$cnt_avg));
&minmaxavg("WEEK","2IOWAIT",($iowait_avg/$cnt_avg));
}
}
if ($minmaxavg{WEEK}{"1Idle"}{CNT} > 0) {$minmaxavg{WEEK}{"1Idle"}{AVG} /= $minmaxavg{WEEK}{"1Idle"}{CNT}}
if ($minmaxavg{WEEK}{"2IOWAIT"}{CNT} > 0) {$minmaxavg{WEEK}{"2IOWAIT"}{AVG} /= $minmaxavg{WEEK}{"2IOWAIT"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => '% CPU',
x_label_skip => 24,
title => 'CPU Usage in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Idle IOWAIT));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "cpu") {
my (@h,@p,@t);
my $cputotal_prev;
my $cpuidle_prev;
my $cpuiowait_prev;
$minmaxavg{MONTH}{"1Idle"}{MIN} = 100;
$minmaxavg{MONTH}{"1Idle"}{MAX} = 0;
$minmaxavg{MONTH}{"2IOWAIT"}{MIN} = 100;
$minmaxavg{MONTH}{"2IOWAIT"}{MAX} = 0;
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $idle_avg;
my $iowait_avg;
my $cnt_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $cputotal ne "") {
my $idle_diff = $cpuidle - $cpuidle_prev;
my $iowait_diff = $cpuiowait - $cpuiowait_prev;
my $total_diff = $cputotal - $cputotal_prev;
if ($total_diff == 0) {
$cputotal_prev = 0;
$cpuidle_prev = 0;
$cpuiowait_prev = 0;
next;
}
my $idle_use = 100 - 100 * ($total_diff - $idle_diff) / $total_diff;
my $iowait_use = 100 - 100 * ($total_diff - $iowait_diff) / $total_diff;
$cpuidle_prev = $cpuidle;
$cpuiowait_prev = $cpuiowait;
$cputotal_prev = $cputotal;
$idle_avg += $idle_use;
$iowait_avg += $iowait_use;
$cnt_avg++;
} else {
$cputotal_prev = 0;
$cpuidle_prev = 0;
$cpuiowait_prev = 0;
}
}
unless (defined $cnt_avg) {
push @p,undef;
push @t,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$idle_avg/$cnt_avg;
push @t,$iowait_avg/$cnt_avg;
&minmaxavg("MONTH","1Idle",($idle_avg/$cnt_avg));
&minmaxavg("MONTH","2IOWAIT",($iowait_avg/$cnt_avg));
}
}
if ($minmaxavg{MONTH}{"1Idle"}{CNT} > 0) {$minmaxavg{MONTH}{"1Idle"}{AVG} /= $minmaxavg{MONTH}{"1Idle"}{CNT}}
if ($minmaxavg{MONTH}{"2IOWAIT"}{CNT} > 0) {$minmaxavg{MONTH}{"2IOWAIT"}{AVG} /= $minmaxavg{MONTH}{"2IOWAIT"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => '% CPU',
x_label_skip => 24,
title => "CPU Usage in last $system_maxdays days",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Idle IOWAIT));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mem") {
my (@h,@p,@t,@c,@a,@b);
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $memtotal eq "") {
push @p,undef;
push @t,undef;
push @c,undef;
push @a,undef;
push @b,undef;
} else {
$memfree = $memtotal - $memfree;
$memswapfree = $memswaptotal - $memswapfree;
push @p,$memtotal;
push @t,$memfree;
push @c,$memcached;
push @a,$memswaptotal;
push @b,$memswapfree;
&minmaxavg("HOUR","1Used",$memfree);
&minmaxavg("HOUR","2Cached",$memcached);
&minmaxavg("HOUR","3SwapUsed",$memswapfree);
}
}
if ($minmaxavg{HOUR}{"1Used"}{CNT} > 0) {$minmaxavg{HOUR}{"1Used"}{AVG} /= $minmaxavg{HOUR}{"1Used"}{CNT}}
if ($minmaxavg{HOUR}{"2Cached"}{CNT} > 0) {$minmaxavg{HOUR}{"2Cached"}{AVG} /= $minmaxavg{HOUR}{"2Cached"}{CNT}}
if ($minmaxavg{HOUR}{"3SwapUsed"}{CNT} > 0) {$minmaxavg{HOUR}{"3SwapUsed"}{AVG} /= $minmaxavg{HOUR}{"3SwapUsed"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t],[reverse @c],[reverse @a],[reverse @b]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple blue green) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => 'Memory (KB)',
x_label_skip => 3,
title => 'Memory Usage in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Total Used Cached SwapTotal SwapUsed));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mem") {
my (@h,@p,@c,@t,@a,@b);
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $memtotal eq "") {
push @p,undef;
push @t,undef;
push @c,undef;
push @a,undef;
push @b,undef;
} else {
$memfree = $memtotal - $memfree;
$memswapfree = $memswaptotal - $memswapfree;
push @p,$memtotal;
push @t,$memfree;
push @c,$memcached;
push @a,$memswaptotal;
push @b,$memswapfree;
&minmaxavg("DAY","1Used",$memfree);
&minmaxavg("DAY","2Cached",$memcached);
&minmaxavg("DAY","3SwapUsed",$memswapfree);
}
}
if ($minmaxavg{DAY}{"1Used"}{CNT} > 0) {$minmaxavg{DAY}{"1Used"}{AVG} /= $minmaxavg{DAY}{"1Used"}{CNT}}
if ($minmaxavg{DAY}{"2Cached"}{CNT} > 0) {$minmaxavg{DAY}{"2Cached"}{AVG} /= $minmaxavg{DAY}{"2Cached"}{CNT}}
if ($minmaxavg{DAY}{"3SwapUsed"}{CNT} > 0) {$minmaxavg{DAY}{"3SwapUsed"}{AVG} /= $minmaxavg{DAY}{"3SwapUsed"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t],[reverse @c],[reverse @a],[reverse @b]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple blue green) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'Memory (KB)',
x_label_skip => 60,
title => 'Memory Usage in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Total Used Cached SwapTotal SwapUsed));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mem") {
my (@h,@p,@t,@c,@a,@b);
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $memtotal_avg;
my $memfree_avg;
my $memcached_avg;
my $memswaptotal_avg;
my $memswapfree_avg;
my $cnt_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $memtotal ne "") {
$memfree = $memtotal - $memfree;
$memswapfree = $memswaptotal - $memswapfree;
$memtotal_avg += $memtotal;
$memfree_avg += $memfree;
$memcached_avg += $memcached;
$memswaptotal_avg += $memswaptotal;
$memswapfree_avg += $memswapfree;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
push @t,undef;
push @c,undef;
push @a,undef;
push @b,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$memtotal_avg/$cnt_avg;
push @t,$memfree_avg/$cnt_avg;
push @c,$memcached_avg/$cnt_avg;
push @a,$memswaptotal_avg/$cnt_avg;
push @b,$memswapfree_avg/$cnt_avg;
&minmaxavg("WEEK","1Used",($memfree_avg/$cnt_avg));
&minmaxavg("WEEK","2Cached",($memcached_avg/$cnt_avg));
&minmaxavg("WEEK","3SwapUsed",($memswapfree_avg/$cnt_avg));
}
}
if ($minmaxavg{WEEK}{"1Used"}{CNT} > 0) {$minmaxavg{WEEK}{"1Used"}{AVG} /= $minmaxavg{WEEK}{"1Used"}{CNT}}
if ($minmaxavg{WEEK}{"2Cached"}{CNT} > 0) {$minmaxavg{WEEK}{"2Cached"}{AVG} /= $minmaxavg{WEEK}{"2Cached"}{CNT}}
if ($minmaxavg{WEEK}{"3SwapUsed"}{CNT} > 0) {$minmaxavg{WEEK}{"3SwapUsed"}{AVG} /= $minmaxavg{WEEK}{"3SwapUsed"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t],[reverse @c],[reverse @a],[reverse @b]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple blue green) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Memory (KB)',
x_label_skip => 24,
title => 'Memory Usage in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Total Used Cached SwapTotal SwapUsed));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mem") {
my (@h,@p,@t,@c,@a,@b);
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $memtotal_avg;
my $memfree_avg;
my $memcached_avg;
my $memswaptotal_avg;
my $memswapfree_avg;
my $cnt_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $memtotal ne "") {
$memfree = $memtotal - $memfree;
$memswapfree = $memswaptotal - $memswapfree;
$memtotal_avg += $memtotal;
$memfree_avg += $memfree;
$memcached_avg += $memcached;
$memswaptotal_avg += $memswaptotal;
$memswapfree_avg += $memswapfree;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
push @t,undef;
push @c,undef;
push @a,undef;
push @b,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$memtotal_avg/$cnt_avg;
push @t,$memfree_avg/$cnt_avg;
push @c,$memcached_avg/$cnt_avg;
push @a,$memswaptotal_avg/$cnt_avg;
push @b,$memswapfree_avg/$cnt_avg;
&minmaxavg("MONTH","1Used",($memfree_avg/$cnt_avg));
&minmaxavg("MONTH","2Cached",($memcached_avg/$cnt_avg));
&minmaxavg("MONTH","3SwapUsed",($memswapfree_avg/$cnt_avg));
}
}
if ($minmaxavg{MONTH}{"1Used"}{CNT} > 0) {$minmaxavg{MONTH}{"1Used"}{AVG} /= $minmaxavg{MONTH}{"1Used"}{CNT}}
if ($minmaxavg{MONTH}{"2Cached"}{CNT} > 0) {$minmaxavg{MONTH}{"2Cached"}{AVG} /= $minmaxavg{MONTH}{"2Cached"}{CNT}}
if ($minmaxavg{MONTH}{"3SwapUsed"}{CNT} > 0) {$minmaxavg{MONTH}{"3SwapUsed"}{AVG} /= $minmaxavg{MONTH}{"3SwapUsed"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t],[reverse @c],[reverse @a],[reverse @b]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple blue green) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Memory (Bytes)',
x_label_skip => 24,
title => "Memory Usage in last $system_maxdays days",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Total Used Cached SwapTotal SwapUsed));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "load") {
my (@h,@p,@t,@a);
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $load1 eq "") {
push @p,undef;
push @t,undef;
push @a,undef;
} else {
push @p,$load1;
push @t,$load5;
push @a,$load15;
&minmaxavg("HOUR","1Load_1",$load1);
&minmaxavg("HOUR","2Load_5",$load5);
&minmaxavg("HOUR","3Load_15",$load15);
}
}
if ($minmaxavg{HOUR}{"1Load_1"}{CNT} > 0) {$minmaxavg{HOUR}{"1Load_1"}{AVG} /= $minmaxavg{HOUR}{"1Load_1"}{CNT}}
if ($minmaxavg{HOUR}{"2Load_5"}{CNT} > 0) {$minmaxavg{HOUR}{"2Load_5"}{AVG} /= $minmaxavg{HOUR}{"2Load_5"}{CNT}}
if ($minmaxavg{HOUR}{"3Load_15"}{CNT} > 0) {$minmaxavg{HOUR}{"3Load_15"}{AVG} /= $minmaxavg{HOUR}{"3Load_15"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t],[reverse @a]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => 'Load Average',
x_label_skip => 3,
title => 'Load Averages in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Load_1 Load_5 Load_15));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "load") {
my (@h,@p,@t,@a);
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $load1 eq "") {
push @p,undef;
push @t,undef;
push @a,undef;
} else {
push @p,$load1;
push @t,$load5;
push @a,$load15;
&minmaxavg("DAY","1Load_1",$load1);
&minmaxavg("DAY","2Load_5",$load5);
&minmaxavg("DAY","3Load_15",$load15);
}
}
if ($minmaxavg{DAY}{"1Load_1"}{CNT} > 0) {$minmaxavg{DAY}{"1Load_1"}{AVG} /= $minmaxavg{DAY}{"1Load_1"}{CNT}}
if ($minmaxavg{DAY}{"2Load_5"}{CNT} > 0) {$minmaxavg{DAY}{"2Load_5"}{AVG} /= $minmaxavg{DAY}{"2Load_5"}{CNT}}
if ($minmaxavg{DAY}{"3Load_15"}{CNT} > 0) {$minmaxavg{DAY}{"3Load_15"}{AVG} /= $minmaxavg{DAY}{"3Load_15"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t],[reverse @a]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'Load Average',
x_label_skip => 60,
title => 'Load Averages in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Load_1 Load_5 Load_15));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "load") {
my (@h,@p,@t,@a);
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $load1_avg;
my $load5_avg;
my $load15_avg;
my $cnt_avg = 0;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $load1 ne "") {
$load1_avg += $load1;
$load5_avg += $load5;
$load15_avg += $load15;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
push @t,undef;
push @a,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$load1_avg/$cnt_avg;
push @t,$load5_avg/$cnt_avg;
push @a,$load15_avg/$cnt_avg;
&minmaxavg("WEEK","1Load_1",($load1_avg/$cnt_avg));
&minmaxavg("WEEK","2Load_5",($load5_avg/$cnt_avg));
&minmaxavg("WEEK","3Load_15",($load15_avg/$cnt_avg));
}
}
if ($minmaxavg{WEEK}{"1Load_1"}{CNT} > 0) {$minmaxavg{WEEK}{"1Load_1"}{AVG} /= $minmaxavg{WEEK}{"1Load_1"}{CNT}}
if ($minmaxavg{WEEK}{"2Load_5"}{CNT} > 0) {$minmaxavg{WEEK}{"2Load_5"}{AVG} /= $minmaxavg{WEEK}{"2Load_5"}{CNT}}
if ($minmaxavg{WEEK}{"3Load_15"}{CNT} > 0) {$minmaxavg{WEEK}{"3Load_15"}{AVG} /= $minmaxavg{WEEK}{"3Load_15"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t],[reverse @a]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Load Average',
x_label_skip => 24,
title => 'Load Averages in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Load_1 Load_5 Load_15));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "load") {
my (@h,@p,@t,@a);
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $load1_avg;
my $load5_avg;
my $load15_avg;
my $cnt_avg = 0;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $load1 ne "") {
$load1_avg += $load1;
$load5_avg += $load5;
$load15_avg += $load15;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
push @t,undef;
push @a,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$load1_avg/$cnt_avg;
push @t,$load5_avg/$cnt_avg;
push @a,$load15_avg/$cnt_avg;
&minmaxavg("MONTH","1Load_1",($load1_avg/$cnt_avg));
&minmaxavg("MONTH","2Load_5",($load5_avg/$cnt_avg));
&minmaxavg("MONTH","3Load_15",($load15_avg/$cnt_avg));
}
}
if ($minmaxavg{MONTH}{"1Load_1"}{CNT} > 0) {$minmaxavg{MONTH}{"1Load_1"}{AVG} /= $minmaxavg{MONTH}{"1Load_1"}{CNT}}
if ($minmaxavg{MONTH}{"2Load_5"}{CNT} > 0) {$minmaxavg{MONTH}{"2Load_5"}{AVG} /= $minmaxavg{MONTH}{"2Load_5"}{CNT}}
if ($minmaxavg{MONTH}{"3Load_15"}{CNT} > 0) {$minmaxavg{MONTH}{"3Load_15"}{AVG} /= $minmaxavg{MONTH}{"3Load_15"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t],[reverse @a]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple blue) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Load Average',
x_label_skip => 24,
title => "Load Averages in last $system_maxdays days",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Load_1 Load_5 Load_15));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "net") {
my (@h,@p,@t);
my $netin_prev;
my $netout_prev;
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $netin eq "") {
$netin_prev = 0;
$netout_prev = 0;
push @p,undef;
push @t,undef;
} else {
if ($netin_prev < $netin or $netin eq "") {
push @p,undef;
$netin_prev = $netin;
} else {
my $netin_val = ($netin_prev - $netin) / 60;
push @p,$netin_val;
$netin_prev = $netin;
&minmaxavg("HOUR","1Inbound",$netin_val);
}
if ($netout_prev < $netout or $netout eq "") {
push @t,undef;
$netout_prev = $netout;
} else {
my $netout_val = ($netout_prev - $netout) / 60;
push @t,$netout_val;
$netout_prev = $netout;
&minmaxavg("HOUR","2Outbound",$netout_val);
}
}
}
if ($minmaxavg{HOUR}{"1Inbound"}{CNT} > 0) {$minmaxavg{HOUR}{"1Inbound"}{AVG} /= $minmaxavg{HOUR}{"1Inbound"}{CNT}}
if ($minmaxavg{HOUR}{"2Outbound"}{CNT} > 0) {$minmaxavg{HOUR}{"2Outbound"}{AVG} /= $minmaxavg{HOUR}{"2Outbound"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => 'Bytes/Second',
x_label_skip => 3,
title => 'Network Usage in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Inbound Outbound));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "net") {
my (@h,@p,@t);
my $netin_prev;
my $netout_prev;
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $netin eq "") {
$netin_prev = 0;
$netout_prev = 0;
push @p,undef;
push @t,undef;
} else {
if ($netin_prev < $netin or $netin eq "") {
push @p,undef;
$netin_prev = $netin;
} else {
my $netin_val = ($netin_prev - $netin) / 60;
push @p,$netin_val;
$netin_prev = $netin;
&minmaxavg("DAY","1Inbound",$netin_val);
}
if ($netout_prev < $netout or $netout eq "") {
push @t,undef;
$netout_prev = $netout;
} else {
my $netout_val = ($netout_prev - $netout) / 60;
push @t,$netout_val;
$netout_prev = $netout;
&minmaxavg("DAY","2Outbound",$netout_val);
}
}
}
if ($minmaxavg{DAY}{"1Inbound"}{CNT} > 0) {$minmaxavg{DAY}{"1Inbound"}{AVG} /= $minmaxavg{DAY}{"1Inbound"}{CNT}}
if ($minmaxavg{DAY}{"2Outbound"}{CNT} > 0) {$minmaxavg{DAY}{"2Outbound"}{AVG} /= $minmaxavg{DAY}{"2Outbound"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'Bytes/Second',
x_label_skip => 60,
title => 'Network Usage in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Inbound Outbound));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "net") {
my (@h,@p,@t);
my $netin_prev;
my $netout_prev;
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $netin_avg;
my $netout_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $netin eq "") {
$netin_prev = 0;
$netout_prev = 0;
} else {
if ($netin_prev < $netin or $netin eq "") {
$netin_prev = $netin;
} else {
my $netin_val = ($netin_prev - $netin) / 60;
$netin_avg = $netin_avg + $netin_val;
$netin_prev = $netin;
}
if ($netout_prev < $netout or $netout eq "") {
$netout_prev = $netout;
} else {
my $netout_val = ($netout_prev - $netout) / 60;
$netout_avg = $netout_avg + $netout_val;
$netout_prev = $netout;
}
}
}
unless (defined $netin_avg) {
push @p,undef;
} else {
push @p,($netin_avg/60);
&minmaxavg("WEEK","1Inbound",($netin_avg/60));
}
unless (defined $netout_avg) {
push @t,undef;
} else {
push @t,($netout_avg/60);
&minmaxavg("WEEK","2Outbound",($netout_avg/60));
}
}
if ($minmaxavg{WEEK}{"1Inbound"}{CNT} > 0) {$minmaxavg{WEEK}{"1Inbound"}{AVG} /= $minmaxavg{WEEK}{"1Inbound"}{CNT}}
if ($minmaxavg{WEEK}{"2Outbound"}{CNT} > 0) {$minmaxavg{WEEK}{"2Outbound"}{AVG} /= $minmaxavg{WEEK}{"2Outbound"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Bytes/Second',
x_label_skip => 24,
title => 'Network Usage in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Inbound Outbound));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "net") {
my (@h,@p,@t);
my $netin_prev;
my $netout_prev;
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $netin_avg;
my $netout_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $netin eq "") {
$netin_prev = 0;
$netout_prev = 0;
} else {
if ($netin_prev < $netin or $netin eq "") {
$netin_prev = $netin;
} else {
my $netin_val = ($netin_prev - $netin) / 60;
$netin_avg = $netin_avg + $netin_val;
$netin_prev = $netin;
}
if ($netout_prev < $netout or $netout eq "") {
$netout_prev = $netout;
} else {
my $netout_val = ($netout_prev - $netout) / 60;
$netout_avg = $netout_avg + $netout_val;
$netout_prev = $netout;
}
}
}
unless (defined $netin_avg) {
push @p,undef;
} else {
push @p,($netin_avg/60);
&minmaxavg("MONTH","1Inbound",($netin_avg/60));
}
unless (defined $netout_avg) {
push @t,undef;
} else {
push @t,($netout_avg/60);
&minmaxavg("MONTH","2Outbound",($netout_avg/60));
}
}
if ($minmaxavg{MONTH}{"1Inbound"}{CNT} > 0) {$minmaxavg{MONTH}{"1Inbound"}{AVG} /= $minmaxavg{MONTH}{"1Inbound"}{CNT}}
if ($minmaxavg{MONTH}{"2Outbound"}{CNT} > 0) {$minmaxavg{MONTH}{"2Outbound"}{AVG} /= $minmaxavg{MONTH}{"2Outbound"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Bytes/Second',
x_label_skip => 24,
title => "Network Usage in last $system_maxdays days",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Inbound Outbound));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "disk") {
my (@h,@p,@t);
my $diskread_prev;
my $diskwrite_prev;
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $diskread eq "") {
$diskread_prev = 0;
$diskwrite_prev = 0;
push @p,undef;
push @t,undef;
} else {
if ($diskread_prev < $diskread or $diskread eq "") {
push @p,undef;
$diskread_prev = $diskread;
} else {
my $diskread_val = ($diskread_prev - $diskread) / 60;
push @p,$diskread_val;
$diskread_prev = $diskread;
&minmaxavg("HOUR","1Reads",$diskread_val);
}
if ($diskwrite_prev < $diskwrite or $diskwrite eq "") {
push @t,undef;
$diskwrite_prev = $diskwrite;
} else {
my $diskwrite_val = ($diskwrite_prev - $diskwrite) / 60;
push @t,$diskwrite_val;
$diskwrite_prev = $diskwrite;
&minmaxavg("HOUR","2Writes",$diskwrite_val);
}
}
}
if ($minmaxavg{HOUR}{"1Reads"}{CNT} > 0) {$minmaxavg{HOUR}{"1Reads"}{AVG} /= $minmaxavg{HOUR}{"1Reads"}{CNT}}
if ($minmaxavg{HOUR}{"2Writes"}{CNT} > 0) {$minmaxavg{HOUR}{"2Writes"}{AVG} /= $minmaxavg{HOUR}{"2Writes"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => 'IO/Second',
x_label_skip => 3,
title => 'Disk Usage in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Reads Writes));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "disk") {
my (@h,@p,@t);
my $diskread_prev;
my $diskwrite_prev;
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $diskread eq "") {
$diskread_prev = 0;
$diskwrite_prev = 0;
push @p,undef;
push @t,undef;
} else {
if ($diskread_prev < $diskread or $diskread eq "") {
push @p,undef;
$diskread_prev = $diskread;
} else {
my $diskread_val = ($diskread_prev - $diskread) / 60;
push @p,$diskread_val;
$diskread_prev = $diskread;
&minmaxavg("DAY","1Reads",$diskread_val);
}
if ($diskwrite_prev < $diskwrite or $diskwrite eq "") {
push @t,undef;
$diskwrite_prev = $diskwrite;
} else {
my $diskwrite_val = ($diskwrite_prev - $diskwrite) / 60;
push @t,$diskwrite_val;
$diskwrite_prev = $diskwrite;
&minmaxavg("DAY","2Writes",$diskwrite_val);
}
}
}
if ($minmaxavg{DAY}{"1Reads"}{CNT} > 0) {$minmaxavg{DAY}{"1Reads"}{AVG} /= $minmaxavg{DAY}{"1Reads"}{CNT}}
if ($minmaxavg{DAY}{"2Writes"}{CNT} > 0) {$minmaxavg{DAY}{"2Writes"}{AVG} /= $minmaxavg{DAY}{"2Writes"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'IO/Second',
x_label_skip => 60,
title => 'Disk Usage in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Reads Writes));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "disk") {
my (@h,@p,@t);
my $diskread_prev;
my $diskwrite_prev;
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $diskread_avg;
my $diskwrite_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $diskread eq "") {
$diskread_prev = 0;
$diskwrite_prev = 0;
} else {
if ($diskread_prev < $diskread or $diskread eq "") {
$diskread_prev = $diskread;
} else {
$diskread_avg = $diskread_avg + ($diskread_prev - $diskread)/60;
$diskread_prev = $diskread;
}
if ($diskwrite_prev < $diskwrite or $diskwrite eq "") {
$diskwrite_prev = $diskwrite;
} else {
$diskwrite_avg = $diskwrite_avg + ($diskwrite_prev - $diskwrite)/60;
$diskwrite_prev = $diskwrite;
}
}
}
unless (defined $diskread_avg) {
push @p,undef;
} else {
push @p,($diskread_avg/60);
&minmaxavg("WEEK","1Reads",($diskread_avg/60));
}
unless (defined $diskwrite_avg) {
push @t,undef;
} else {
push @t,($diskwrite_avg/60);
&minmaxavg("WEEK","2Writes",($diskwrite_avg/60));
}
}
if ($minmaxavg{WEEK}{"1Reads"}{CNT} > 0) {$minmaxavg{WEEK}{"1Reads"}{AVG} /= $minmaxavg{WEEK}{"1Reads"}{CNT}}
if ($minmaxavg{WEEK}{"2Writes"}{CNT} > 0) {$minmaxavg{WEEK}{"2Writes"}{AVG} /= $minmaxavg{WEEK}{"2Writes"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'IO/Second',
x_label_skip => 24,
title => 'Disk Usage in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Reads Writes));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "disk") {
my (@h,@p,@t);
my $diskread_prev;
my $diskwrite_prev;
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $diskread_avg;
my $diskwrite_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $diskread eq "") {
$diskread_prev = 0;
$diskwrite_prev = 0;
} else {
if ($diskread_prev < $diskread or $diskread eq "") {
$diskread_prev = $diskread;
} else {
$diskread_avg = $diskread_avg + ($diskread_prev - $diskread)/60;
$diskread_prev = $diskread;
}
if ($diskwrite_prev < $diskwrite or $diskwrite eq "") {
$diskwrite_prev = $diskwrite;
} else {
$diskwrite_avg = $diskwrite_avg + ($diskwrite_prev - $diskwrite)/60;
$diskwrite_prev = $diskwrite;
}
}
}
unless (defined $diskread_avg) {
push @p,undef;
} else {
push @p,($diskread_avg/60);
&minmaxavg("MONTH","1Reads",($diskread_avg/60));
}
unless (defined $diskwrite_avg) {
push @t,undef;
} else {
push @t,($diskwrite_avg/60);
&minmaxavg("MONTH","2Writes",($diskwrite_avg/60));
}
}
if ($minmaxavg{MONTH}{"1Reads"}{CNT} > 0) {$minmaxavg{MONTH}{"1Reads"}{AVG} /= $minmaxavg{MONTH}{"1Reads"}{CNT}}
if ($minmaxavg{MONTH}{"2Writes"}{CNT} > 0) {$minmaxavg{MONTH}{"2Writes"}{AVG} /= $minmaxavg{MONTH}{"2Writes"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'IO/Second',
x_label_skip => 24,
title => "Disk Usage in last $system_maxdays days",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Reads Writes));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "email") {
my (@h,@p,@t);
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $mailin eq "") {
push @p,undef;
push @t,undef;
} else {
push @p,$mailin;
push @t,$mailout;
&minmaxavg("HOUR","1Received",$mailin);
&minmaxavg("HOUR","2Sent",$mailout);
}
}
if ($minmaxavg{HOUR}{"1Received"}{CNT} > 0) {$minmaxavg{HOUR}{"1Received"}{AVG} /= $minmaxavg{HOUR}{"1Received"}{CNT}}
if ($minmaxavg{HOUR}{"2Sent"}{CNT} > 0) {$minmaxavg{HOUR}{"2Sent"}{AVG} /= $minmaxavg{HOUR}{"2Sent"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => 'Emails',
x_label_skip => 3,
title => 'Email Usage in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Received Sent));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "email") {
my (@h,@p,@t);
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $mailin eq "") {
push @p,undef;
push @t,undef;
} else {
push @p,$mailin;
push @t,$mailout;
&minmaxavg("DAY","1Received",$mailin);
&minmaxavg("DAY","2Sent",$mailout);
}
}
if ($minmaxavg{DAY}{"1Received"}{CNT} > 0) {$minmaxavg{DAY}{"1Received"}{AVG} /= $minmaxavg{DAY}{"1Received"}{CNT}}
if ($minmaxavg{DAY}{"2Sent"}{CNT} > 0) {$minmaxavg{DAY}{"2Sent"}{AVG} /= $minmaxavg{DAY}{"2Sent"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'Emails',
x_label_skip => 60,
title => 'Email Usage in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Received Sent));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "email") {
my (@h,@p,@t);
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $mailin_avg;
my $mailout_avg;
my $cnt_avg = 0;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $mailin ne "") {
$mailin_avg += $mailin;
$mailout_avg += $mailout;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
push @t,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$mailin_avg/$cnt_avg;
push @t,$mailout_avg/$cnt_avg;
&minmaxavg("WEEK","1Received",($mailin_avg/$cnt_avg));
&minmaxavg("WEEK","2Sent",($mailout_avg/$cnt_avg));
}
}
if ($minmaxavg{WEEK}{"1Received"}{CNT} > 0) {$minmaxavg{WEEK}{"1Received"}{AVG} /= $minmaxavg{WEEK}{"1Received"}{CNT}}
if ($minmaxavg{WEEK}{"2Sent"}{CNT} > 0) {$minmaxavg{WEEK}{"2Sent"}{AVG} /= $minmaxavg{WEEK}{"2Sent"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Emails',
x_label_skip => 24,
title => 'Email Usage in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Received Sent));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "email") {
my (@h,@p,@t);
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $mailin_avg;
my $mailout_avg;
my $cnt_avg = 0;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $mailin ne "") {
$mailin_avg += $mailin;
$mailout_avg += $mailout;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
push @t,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$mailin_avg/$cnt_avg;
push @t,$mailout_avg/$cnt_avg;
&minmaxavg("MONTH","1Received",($mailin_avg/$cnt_avg));
&minmaxavg("MONTH","2Sent",($mailout_avg/$cnt_avg));
}
}
if ($minmaxavg{MONTH}{"1Received"}{CNT} > 0) {$minmaxavg{MONTH}{"1Received"}{AVG} /= $minmaxavg{MONTH}{"1Received"}{CNT}}
if ($minmaxavg{MONTH}{"2Sent"}{CNT} > 0) {$minmaxavg{MONTH}{"2Sent"}{AVG} /= $minmaxavg{MONTH}{"2Sent"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Emails',
x_label_skip => 24,
title => "Email Usage in last $system_maxdays",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Received Sent));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "temp") {
my (@h,@p);
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $cputemp eq "") {
push @p,undef;
} else {
push @p,$cputemp;
&minmaxavg("HOUR","1CPU",$cputemp);
}
}
if ($minmaxavg{HOUR}{"1CPU"}{CNT} > 0) {$minmaxavg{HOUR}{"1CPU"}{AVG} /= $minmaxavg{HOUR}{"1CPU"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => 'Centigrade',
x_label_skip => 3,
title => 'CPU Temp in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend("Highest Core Temperature");
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "temp") {
my (@h,@p);
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $cputemp eq "") {
push @p,undef;
} else {
push @p,$cputemp;
&minmaxavg("DAY","1CPU",$cputemp);
}
}
if ($minmaxavg{DAY}{"1CPU"}{CNT} > 0) {$minmaxavg{DAY}{"1CPU"}{AVG} /= $minmaxavg{DAY}{"1CPU"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'Centigrade',
x_label_skip => 60,
title => 'CPU Temp in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend("Highest Core Temperature");
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "temp") {
my (@h,@p);
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $cputemp_avg;
my $cnt_avg = 0;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $cputemp ne "") {
$cputemp_avg += $cputemp;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$cputemp_avg/$cnt_avg;
&minmaxavg("WEEK","1CPU",($cputemp_avg/$cnt_avg));
}
}
if ($minmaxavg{WEEK}{"1CPU"}{CNT} > 0) {$minmaxavg{WEEK}{"1CPU"}{AVG} /= $minmaxavg{WEEK}{"1CPU"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Centigrade',
x_label_skip => 24,
title => 'CPU Temp in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend("Highest Core Temperature");
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "temp") {
my (@h,@p);
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $cputemp_avg;
my $cnt_avg = 0;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $cputemp ne "") {
$cputemp_avg += $cputemp;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$cputemp_avg/$cnt_avg;
&minmaxavg("MONTH","1CPU",($cputemp_avg/$cnt_avg));
}
}
if ($minmaxavg{MONTH}{"1CPU"}{CNT} > 0) {$minmaxavg{MONTH}{"1CPU"}{AVG} /= $minmaxavg{MONTH}{"1CPU"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Centigrade',
x_label_skip => 24,
title => "CPU Temp in last $system_maxdays days",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend("Highest Core Temperature");
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqldata") {
my (@h,@p,@t);
my $mysqlin_prev;
my $mysqlout_prev;
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $mysqlin eq "") {
$mysqlin_prev = 0;
$mysqlout_prev = 0;
push @p,undef;
push @t,undef;
} else {
if ($mysqlin_prev < $mysqlin or $mysqlin eq "") {
push @p,undef;
$mysqlin_prev = $mysqlin;
} else {
my $mysqlin_val = ($mysqlin_prev - $mysqlin) / 60;
push @p,$mysqlin_val;
$mysqlin_prev = $mysqlin;
&minmaxavg("HOUR","1Inbound",$mysqlin_val);
}
if ($mysqlout_prev < $mysqlout or $mysqlout eq "") {
push @t,undef;
$mysqlout_prev = $mysqlout;
} else {
my $mysqlout_val = ($mysqlout_prev - $mysqlout) / 60;
push @t,$mysqlout_val;
$mysqlout_prev = $mysqlout;
&minmaxavg("HOUR","2Outbound",$mysqlout_val);
}
}
}
if ($minmaxavg{HOUR}{"1Inbound"}{CNT} > 0) {$minmaxavg{HOUR}{"1Inbound"}{AVG} /= $minmaxavg{HOUR}{"1Inbound"}{CNT}}
if ($minmaxavg{HOUR}{"2Outbound"}{CNT} > 0) {$minmaxavg{HOUR}{"2Outbound"}{AVG} /= $minmaxavg{HOUR}{"2Outbound"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => 'Bytes/Second',
x_label_skip => 3,
title => 'MySQL Data in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Inbound Outbound));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqldata") {
my (@h,@p,@t);
my $mysqlin_prev;
my $mysqlout_prev;
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $mysqlin eq "") {
$mysqlin_prev = 0;
$mysqlout_prev = 0;
push @p,undef;
push @t,undef;
} else {
if ($mysqlin_prev < $mysqlin or $mysqlin eq "") {
push @p,undef;
$mysqlin_prev = $mysqlin;
} else {
my $mysqlin_val = ($mysqlin_prev - $mysqlin) / 60;
push @p,$mysqlin_val;
$mysqlin_prev = $mysqlin;
&minmaxavg("DAY","1Inbound",$mysqlin_val);
}
if ($mysqlout_prev < $mysqlout or $mysqlout eq "") {
push @t,undef;
$mysqlout_prev = $mysqlout;
} else {
my $mysqlout_val = ($mysqlout_prev - $mysqlout) / 60;
push @t,$mysqlout_val;
$mysqlout_prev = $mysqlout;
&minmaxavg("DAY","2Outbound",$mysqlout_val);
}
}
}
if ($minmaxavg{DAY}{"1Inbound"}{CNT} > 0) {$minmaxavg{DAY}{"1Inbound"}{AVG} /= $minmaxavg{DAY}{"1Inbound"}{CNT}}
if ($minmaxavg{DAY}{"2Outbound"}{CNT} > 0) {$minmaxavg{DAY}{"2Outbound"}{AVG} /= $minmaxavg{DAY}{"2Outbound"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'Bytes/Second',
x_label_skip => 60,
title => 'MySQL Data in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Inbound Outbound));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqldata") {
my (@h,@p,@t);
my $mysqlin_prev;
my $mysqlout_prev;
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $mysqlin_avg;
my $mysqlout_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $mysqlin eq "") {
$mysqlin_prev = 0;
$mysqlout_prev = 0;
} else {
if ($mysqlin_prev < $mysqlin or $mysqlin eq "") {
$mysqlin_prev = $mysqlin;
} else {
my $mysqlin_val = ($mysqlin_prev - $mysqlin) / 60;
$mysqlin_avg = $mysqlin_avg + $mysqlin_val;
$mysqlin_prev = $mysqlin;
}
if ($mysqlout_prev < $mysqlout or $mysqlout eq "") {
$mysqlout_prev = $mysqlout;
} else {
my $mysqlout_val = ($mysqlout_prev - $mysqlout) / 60;
$mysqlout_avg = $mysqlout_avg + $mysqlout_val;
$mysqlout_prev = $mysqlout;
}
}
}
unless (defined $mysqlin_avg) {
push @p,undef;
} else {
push @p,($mysqlin_avg/60);
&minmaxavg("WEEK","1Inbound",($mysqlin_avg/60));
}
unless (defined $mysqlout_avg) {
push @t,undef;
} else {
push @t,($mysqlout_avg/60);
&minmaxavg("WEEK","2Outbound",($mysqlout_avg/60));
}
}
if ($minmaxavg{WEEK}{"1Inbound"}{CNT} > 0) {$minmaxavg{WEEK}{"1Inbound"}{AVG} /= $minmaxavg{WEEK}{"1Inbound"}{CNT}}
if ($minmaxavg{WEEK}{"2Outbound"}{CNT} > 0) {$minmaxavg{WEEK}{"2Outbound"}{AVG} /= $minmaxavg{WEEK}{"2Outbound"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Bytes/Second',
x_label_skip => 24,
title => 'MySQL Data in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Inbound Outbound));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqldata") {
my (@h,@p,@t);
my $mysqlin_prev;
my $mysqlout_prev;
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $mysqlin_avg;
my $mysqlout_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $mysqlin eq "") {
$mysqlin_prev = 0;
$mysqlout_prev = 0;
} else {
if ($mysqlin_prev < $mysqlin or $mysqlin eq "") {
$mysqlin_prev = $mysqlin;
} else {
my $mysqlin_val = ($mysqlin_prev - $mysqlin) / 60;
$mysqlin_avg = $mysqlin_avg + $mysqlin_val;
$mysqlin_prev = $mysqlin;
}
if ($mysqlout_prev < $mysqlout or $mysqlout eq "") {
$mysqlout_prev = $mysqlout;
} else {
my $mysqlout_val = ($mysqlout_prev - $mysqlout) / 60;
$mysqlout_avg = $mysqlout_avg + $mysqlout_val;
$mysqlout_prev = $mysqlout;
}
}
}
unless (defined $mysqlin_avg) {
push @p,undef;
} else {
push @p,($mysqlin_avg/60);
&minmaxavg("MONTH","1Inbound",($mysqlin_avg/60));
}
unless (defined $mysqlout_avg) {
push @t,undef;
} else {
push @t,($mysqlout_avg/60);
&minmaxavg("MONTH","2Outbound",($mysqlout_avg/60));
}
}
if ($minmaxavg{MONTH}{"1Inbound"}{CNT} > 0) {$minmaxavg{MONTH}{"1Inbound"}{AVG} /= $minmaxavg{MONTH}{"1Inbound"}{CNT}}
if ($minmaxavg{MONTH}{"2Outbound"}{CNT}) {$minmaxavg{MONTH}{"2Outbound"}{AVG} /= $minmaxavg{MONTH}{"2Outbound"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Bytes/Second',
x_label_skip => 24,
title => "MySQL Data in last $system_maxdays days",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Inbound Outbound));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqlqueries") {
my (@h,@p,@t);
my $mysqlq_prev;
my $mysqlsq_prev;
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $mysqlq eq "") {
$mysqlq_prev = 0;
push @p,undef;
} else {
if ($mysqlq_prev < $mysqlq or $mysqlq eq "") {
push @p,undef;
$mysqlq_prev = $mysqlq;
} else {
my $mysqlq_val = ($mysqlq_prev - $mysqlq);
push @p,$mysqlq_val;
$mysqlq_prev = $mysqlq;
&minmaxavg("HOUR","1Queries",$mysqlq_val);
}
}
}
if ($minmaxavg{HOUR}{"1Queries"}{CNT} > 0) {$minmaxavg{HOUR}{"1Queries"}{AVG} /= $minmaxavg{HOUR}{"1Queries"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => 'Queries',
x_label_skip => 3,
title => 'MySQL Queries in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Queries));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqlqueries") {
my (@h,@p,@t);
my $mysqlq_prev;
my $mysqlsq_prev;
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $mysqlq eq "") {
$mysqlq_prev = 0;
push @p,undef;
} else {
if ($mysqlq_prev < $mysqlq or $mysqlq eq "") {
push @p,undef;
$mysqlq_prev = $mysqlq;
} else {
my $mysqlq_val = ($mysqlq_prev - $mysqlq);
push @p,$mysqlq_val;
$mysqlq_prev = $mysqlq;
&minmaxavg("DAY","1Queries",$mysqlq_val);
}
}
}
if ($minmaxavg{DAY}{"1Queries"}{CNT} > 0) {$minmaxavg{DAY}{"1Queries"}{AVG} /= $minmaxavg{DAY}{"1Queries"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'Queries',
x_label_skip => 60,
title => 'MySQL Queries in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Queries));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqlqueries") {
my (@h,@p,@t);
my $mysqlq_prev;
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $mysqlq_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $mysqlq eq "") {
$mysqlq_prev = 0;
} else {
if ($mysqlq_prev < $mysqlq or $mysqlq eq "") {
$mysqlq_prev = $mysqlq;
} else {
my $mysqlq_val = ($mysqlq_prev - $mysqlq);
$mysqlq_avg = $mysqlq_avg + $mysqlq_val;
$mysqlq_prev = $mysqlq;
}
}
}
unless (defined $mysqlq_avg) {
push @p,undef;
} else {
push @p,($mysqlq_avg/60);
&minmaxavg("WEEK","1Queries",($mysqlq_avg/60));
}
}
if ($minmaxavg{WEEK}{"1Queries"}{CNT} > 0) {$minmaxavg{WEEK}{"1Queries"}{AVG} /= $minmaxavg{WEEK}{"1Queries"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Queries',
x_label_skip => 24,
title => 'MySQL Queries in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Queries));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqlqueries") {
my (@h,@p,@t);
my $mysqlq_prev;
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $mysqlq_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $mysqlq eq "") {
$mysqlq_prev = 0;
} else {
if ($mysqlq_prev < $mysqlq or $mysqlq eq "") {
$mysqlq_prev = $mysqlq;
} else {
my $mysqlq_val = ($mysqlq_prev - $mysqlq);
$mysqlq_avg = $mysqlq_avg + $mysqlq_val;
$mysqlq_prev = $mysqlq;
}
}
}
unless (defined $mysqlq_avg) {
push @p,undef;
} else {
push @p,($mysqlq_avg/60);
&minmaxavg("MONTH","1Queries",($mysqlq_avg/60));
}
}
if ($minmaxavg{MONTH}{"1Queries"}{CNT} > 0) {$minmaxavg{MONTH}{"1Queries"}{AVG} /= $minmaxavg{MONTH}{"1Queries"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Queries',
x_label_skip => 24,
title => "MySQL Queries in last $system_maxdays",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Queries));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqlslowqueries") {
my (@h,@p,@t);
my $mysqlsq_prev;
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $mysqlq eq "") {
$mysqlsq_prev = 0;
push @t,undef;
} else {
if ($mysqlsq_prev < $mysqlsq or $mysqlsq eq "") {
push @t,undef;
$mysqlsq_prev = $mysqlsq;
} else {
my $mysqlsq_val = ($mysqlsq_prev - $mysqlsq);
push @t,$mysqlsq_val;
$mysqlsq_prev = $mysqlsq;
&minmaxavg("HOUR","1Slow_Queries",$mysqlsq_val);
}
}
}
if ($minmaxavg{HOUR}{"1Slow_Queries"}{CNT} > 0) {$minmaxavg{HOUR}{"1Slow_Queries"}{AVG} /= $minmaxavg{HOUR}{"1Slow_Queries"}{CNT}}
my @data = ([reverse @h],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => 'Slow Queries',
x_label_skip => 3,
title => 'MySQL Slow Queries in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Slow_Queries));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqlslowqueries") {
my (@h,@p,@t);
my $mysqlsq_prev;
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $mysqlq eq "") {
$mysqlsq_prev = 0;
push @t,undef;
} else {
if ($mysqlsq_prev < $mysqlsq or $mysqlsq eq "") {
push @t,undef;
$mysqlsq_prev = $mysqlsq;
} else {
my $mysqlsq_val = ($mysqlsq_prev - $mysqlsq);
push @t,$mysqlsq_val;
$mysqlsq_prev = $mysqlsq;
&minmaxavg("DAY","1Slow_Queries",$mysqlsq_val);
}
}
}
if ($minmaxavg{DAY}{"1Slow_Queries"}{CNT} > 0) {$minmaxavg{DAY}{"1Slow_Queries"}{AVG} /= $minmaxavg{DAY}{"1Slow_Queries"}{CNT}}
my @data = ([reverse @h],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'Slow Queries',
x_label_skip => 60,
title => 'MySQL Slow Queries in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Slow_Queries));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqlslowqueries") {
my (@h,@p,@t);
my $mysqlsq_prev;
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $mysqlsq_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $mysqlsq eq "") {
$mysqlsq_prev = 0;
} else {
if ($mysqlsq_prev < $mysqlsq or $mysqlsq eq "") {
$mysqlsq_prev = $mysqlsq;
} else {
my $mysqlsq_val = ($mysqlsq_prev - $mysqlsq);
$mysqlsq_avg = $mysqlsq_avg + $mysqlsq_val;
$mysqlsq_prev = $mysqlsq;
}
}
}
unless (defined $mysqlsq_avg) {
push @t,undef;
} else {
push @t,($mysqlsq_avg/60);
&minmaxavg("WEEK","1Slow_Queries",($mysqlsq_avg/60));
}
}
if ($minmaxavg{WEEK}{"1Slow_Queries"}{CNT} > 0) {$minmaxavg{WEEK}{"1Slow_Queries"}{AVG} /= $minmaxavg{WEEK}{"1Slow_Queries"}{CNT}}
my @data = ([reverse @h],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Slow Queries',
x_label_skip => 24,
title => 'MySQL Slow Queries in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Slow_Queries));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqlslowqueries") {
my (@h,@p,@t);
my $mysqlsq_prev;
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $mysqlsq_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $mysqlsq eq "") {
$mysqlsq_prev = 0;
} else {
if ($mysqlsq_prev < $mysqlsq or $mysqlsq eq "") {
$mysqlsq_prev = $mysqlsq;
} else {
my $mysqlsq_val = ($mysqlsq_prev - $mysqlsq);
$mysqlsq_avg = $mysqlsq_avg + $mysqlsq_val;
$mysqlsq_prev = $mysqlsq;
}
}
}
unless (defined $mysqlsq_avg) {
push @t,undef;
} else {
push @t,($mysqlsq_avg/60);
&minmaxavg("MONTH","1Slow_Queries",($mysqlsq_avg/60));
}
}
if ($minmaxavg{MONTH}{"1Slow_Queries"}{CNT} > 0) {$minmaxavg{MONTH}{"1Slow_Queries"}{AVG} /= $minmaxavg{MONTH}{"1Slow_Queries"}{CNT}}
my @data = ([reverse @h],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Slow Queries',
x_label_skip => 24,
title => "MySQL Slow Queries in last $system_maxdays",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Slow_Queries));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqlconns") {
my (@h,@p,@t);
my $mysqlcn_prev;
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $mysqlq eq "") {
$mysqlcn_prev = 0;
push @p,undef;
push @t,undef;
} else {
if ($mysqlcn_prev < $mysqlcn or $mysqlcn eq "") {
push @p,undef;
$mysqlcn_prev = $mysqlcn;
} else {
my $mysqlcn_val = ($mysqlcn_prev - $mysqlcn);
push @p,$mysqlcn_val;
$mysqlcn_prev = $mysqlcn;
&minmaxavg("HOUR","1Connections",$mysqlcn_val);
}
if ($mysqlth eq "") {
push @t,undef;
} else {
push @t,$mysqlth;
&minmaxavg("HOUR","2Threads",$mysqlth);
}
}
}
if ($minmaxavg{HOUR}{"1Connections"}{CNT} > 0) {$minmaxavg{HOUR}{"1Connections"}{AVG} /= $minmaxavg{HOUR}{"1Connections"}{CNT}}
if ($minmaxavg{HOUR}{"2Threads"}{CNT} > 0) {$minmaxavg{HOUR}{"2Threads"}{AVG} /= $minmaxavg{HOUR}{"2Threads"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => '',
x_label_skip => 3,
title => 'MySQL Connections & Threads in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Connections Threads));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqlconns") {
my (@h,@p,@t);
my $mysqlcn_prev;
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $mysqlq eq "") {
$mysqlcn_prev = 0;
push @p,undef;
push @t,undef;
} else {
if ($mysqlcn_prev < $mysqlcn or $mysqlcn eq "") {
push @p,undef;
$mysqlcn_prev = $mysqlcn;
} else {
my $mysqlcn_val = ($mysqlcn_prev - $mysqlcn);
push @p,$mysqlcn_val;
$mysqlcn_prev = $mysqlcn;
&minmaxavg("DAY","1Connections",$mysqlcn_val);
}
if ($mysqlth eq "") {
push @t,undef;
} else {
push @t,$mysqlth;
&minmaxavg("DAY","2Threads",$mysqlth);
}
}
}
if ($minmaxavg{DAY}{"1Connections"}{CNT} > 0) {$minmaxavg{DAY}{"1Connections"}{AVG} /= $minmaxavg{DAY}{"1Connections"}{CNT}}
if ($minmaxavg{DAY}{"2Threads"}{CNT} > 0) {$minmaxavg{DAY}{"2Threads"}{AVG} /= $minmaxavg{DAY}{"2Threads"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => '',
x_label_skip => 60,
title => 'MySQL Connections & Threads in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Connections Threads));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqlconns") {
my (@h,@p,@t);
my $mysqlcn_prev;
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $mysqlcn_avg;
my $mysqlth_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $mysqlq eq "") {
$mysqlcn_prev = 0;
} else {
if ($mysqlcn_prev < $mysqlcn or $mysqlcn eq "") {
$mysqlcn_prev = $mysqlcn;
} else {
my $mysqlcn_val = ($mysqlcn_prev - $mysqlcn);
$mysqlcn_avg = $mysqlcn_avg + $mysqlcn_val;
$mysqlcn_prev = $mysqlcn;
}
$mysqlth_avg = $mysqlth_avg + $mysqlth;
}
}
unless (defined $mysqlcn_avg) {
push @p,undef;
} else {
push @p,($mysqlcn_avg/60);
&minmaxavg("WEEK","1Connections",($mysqlcn_avg/60));
}
unless (defined $mysqlth_avg) {
push @t,undef;
} else {
push @t,($mysqlth_avg/60);
&minmaxavg("WEEK","2Threads",($mysqlth_avg/60));
}
}
if ($minmaxavg{WEEK}{"1Connections"}{CNT} > 0) {$minmaxavg{WEEK}{"1Connections"}{AVG} /= $minmaxavg{WEEK}{"1Connections"}{CNT}}
if ($minmaxavg{WEEK}{"2Threads"}{CNT} > 0) {$minmaxavg{WEEK}{"2Threads"}{AVG} /= $minmaxavg{WEEK}{"2Threads"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => '',
x_label_skip => 24,
title => 'MySQL Connections & Threads in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Connections Threads));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "mysqlconns") {
my (@h,@p,@t);
my $mysqlcn_prev;
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $mysqlcn_avg;
my $mysqlth_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $mysqlq eq "") {
$mysqlcn_prev = 0;
} else {
if ($mysqlcn_prev < $mysqlcn or $mysqlcn eq "") {
$mysqlcn_prev = $mysqlcn;
} else {
my $mysqlcn_val = ($mysqlcn_prev - $mysqlcn);
$mysqlcn_avg = $mysqlcn_avg + $mysqlcn_val;
$mysqlcn_prev = $mysqlcn;
}
$mysqlth_avg = $mysqlth_avg + $mysqlth;
}
}
unless (defined $mysqlcn_avg) {
push @p,undef;
} else {
push @p,($mysqlcn_avg/60);
&minmaxavg("MONTH","1Connections",($mysqlcn_avg/60));
}
unless (defined $mysqlth_avg) {
push @t,undef;
} else {
push @t,($mysqlth_avg/60);
&minmaxavg("MONTH","2Threads",($mysqlth_avg/60));
}
}
if ($minmaxavg{MONTH}{"1Connections"}{CNT} > 0) {$minmaxavg{MONTH}{"1Connections"}{AVG} /= $minmaxavg{MONTH}{"1Connections"}{CNT}}
if ($minmaxavg{MONTH}{"2Threads"}{CNT} > 0) {$minmaxavg{MONTH}{"2Threads"}{AVG} /= $minmaxavg{MONTH}{"2Threads"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => '',
x_label_skip => 24,
title => "MySQL Connections & Threads in last $system_maxdays days",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Connections Threads));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "apachecpu") {
my (@h,@p);
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $apachecpu eq "") {
push @p,undef;
} else {
push @p,$apachecpu;
&minmaxavg("HOUR","1Apache_CPU",$apachecpu);
}
}
if ($minmaxavg{HOUR}{"1Apache_CPU"}{CNT} > 0) {$minmaxavg{HOUR}{"1Apache_CPU"}{AVG} /= $minmaxavg{HOUR}{"1Apache_CPU"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => 'Percentage',
x_label_skip => 3,
title => 'Apache CPU Usage in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend("Apache CPU");
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "apachecpu") {
my (@h,@p);
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $apachecpu eq "") {
push @p,undef;
} else {
push @p,$apachecpu;
&minmaxavg("DAY","1Apache_CPU",$apachecpu);
}
}
if ($minmaxavg{DAY}{"1Apache_CPU"}{CNT} > 0) {$minmaxavg{DAY}{"1Apache_CPU"}{AVG} /= $minmaxavg{DAY}{"1Apache_CPU"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'Percentage',
x_label_skip => 60,
title => 'Apache CPU Usage in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend("Apache CPU");
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "apachecpu") {
my (@h,@p);
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $apachecpu_avg;
my $cnt_avg = 0;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $apachecpu ne "") {
$apachecpu_avg += $apachecpu;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$apachecpu_avg/$cnt_avg;
&minmaxavg("WEEK","1Apache_CPU",($apachecpu_avg/$cnt_avg));
}
}
if ($minmaxavg{WEEK}{"1Apache_CPU"}{CNT} > 0) {$minmaxavg{WEEK}{"1Apache_CPU"}{AVG} /= $minmaxavg{WEEK}{"1Apache_CPU"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Percentage',
x_label_skip => 24,
title => 'Apache CPU Usage in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend("Apache CPU");
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "apachecpu") {
my (@h,@p);
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $apachecpu_avg;
my $cnt_avg = 0;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $apachecpu ne "") {
$apachecpu_avg += $apachecpu;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$apachecpu_avg/$cnt_avg;
&minmaxavg("MONTH","1Apache_CPU",($apachecpu_avg/$cnt_avg));
}
}
if ($minmaxavg{MONTH}{"1Apache_CPU"}{CNT} > 0) {$minmaxavg{MONTH}{"1Apache_CPU"}{AVG} /= $minmaxavg{MONTH}{"1Apache_CPU"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Percentage',
x_label_skip => 24,
title => "Apache CPU Usage in last $system_maxdays",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend("Apache CPU");
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "apacheconn") {
my (@h,@p);
my $apacheacc_prev;
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $apacheacc eq "") {
$apacheacc_prev = 0;
push @p,undef;
} else {
if ($apacheacc_prev < $apacheacc or $apacheacc eq "") {
push @p,undef;
$apacheacc_prev = $apacheacc;
} else {
my $apacheacc_val = ($apacheacc_prev - $apacheacc);
push @p,$apacheacc_val;
$apacheacc_prev = $apacheacc;
&minmaxavg("HOUR","1Connections",$apacheacc_val);
}
}
}
if ($minmaxavg{HOUR}{"1Connections"}{CNT} > 0) {$minmaxavg{HOUR}{"1Connections"}{AVG} /= $minmaxavg{HOUR}{"1Connections"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => '',
x_label_skip => 3,
title => 'Apache Connections in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Connections));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "apacheconn") {
my (@h,@p,@t);
my $apacheacc_prev;
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $apacheacc eq "") {
$apacheacc_prev = 0;
push @p,undef;
} else {
if ($apacheacc_prev < $apacheacc or $apacheacc eq "") {
push @p,undef;
$apacheacc_prev = $apacheacc;
} else {
my $apacheacc_val = ($apacheacc_prev - $apacheacc);
push @p,$apacheacc_val;
$apacheacc_prev = $apacheacc;
&minmaxavg("DAY","1Connections",$apacheacc_val);
}
}
}
if ($minmaxavg{DAY}{"1Connections"}{CNT} > 0) {$minmaxavg{DAY}{"1Connections"}{AVG} /= $minmaxavg{DAY}{"1Connections"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => '',
x_label_skip => 60,
title => 'Apache Connections in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Connections));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "apacheconn") {
my (@h,@p,@t);
my $apacheacc_prev;
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $apacheacc_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $apacheacc eq "") {
$apacheacc_prev = 0;
} else {
if ($apacheacc_prev < $apacheacc or $apacheacc eq "") {
$apacheacc_prev = $apacheacc;
} else {
my $apacheacc_val = ($apacheacc_prev - $apacheacc);
$apacheacc_avg = $apacheacc_avg + $apacheacc_val;
$apacheacc_prev = $apacheacc;
}
}
}
unless (defined $apacheacc_avg) {
push @p,undef;
} else {
push @p,($apacheacc_avg/60);
&minmaxavg("WEEK","1Connections",($apacheacc_avg/60));
}
}
if ($minmaxavg{WEEK}{"1Connections"}{CNT} > 0) {$minmaxavg{WEEK}{"1Connections"}{AVG} /= $minmaxavg{WEEK}{"1Connections"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => '',
x_label_skip => 24,
title => 'Apache Connections in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Connections Threads));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "apacheconn") {
my (@h,@p,@t);
my $apacheacc_prev;
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $apacheacc_avg;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time eq "" or $apacheacc eq "") {
$apacheacc_prev = 0;
} else {
if ($apacheacc_prev < $apacheacc or $apacheacc eq "") {
$apacheacc_prev = $apacheacc;
} else {
my $apacheacc_val = ($apacheacc_prev - $apacheacc);
$apacheacc_avg = $apacheacc_avg + $apacheacc_val;
$apacheacc_prev = $apacheacc;
}
}
}
unless (defined $apacheacc_avg) {
push @p,undef;
} else {
push @p,($apacheacc_avg/60);
&minmaxavg("MONTH","1Connections",($apacheacc_avg/60));
}
}
if ($minmaxavg{MONTH}{"1Connections"}{CNT} > 0) {$minmaxavg{MONTH}{"1Connections"}{AVG} /= $minmaxavg{MONTH}{"1Connections"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => '',
x_label_skip => 24,
title => "Apache Connections in last $system_maxdays",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Connections Threads));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "apachework") {
my (@h,@p,@t);
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $apachebwork eq "") {
push @p,undef;
push @t,undef;
} else {
push @p,$apachebwork;
push @t,$apacheiwork;
&minmaxavg("HOUR","1Busy",$apachebwork);
&minmaxavg("HOUR","2Idle",$apacheiwork);
}
}
if ($minmaxavg{HOUR}{"1Busy"}{CNT} > 0) {$minmaxavg{HOUR}{"1Busy"}{AVG} /= $minmaxavg{HOUR}{"1Busy"}{CNT}}
if ($minmaxavg{HOUR}{"2Idle"}{CNT} > 0) {$minmaxavg{HOUR}{"2Idle"}{AVG} /= $minmaxavg{HOUR}{"2Idle"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => 'Workers',
x_label_skip => 3,
title => 'Apache Workers in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Busy Idle));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "apachework") {
my (@h,@p,@t);
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $apachebwork eq "") {
push @p,undef;
push @t,undef;
} else {
push @p,$apachebwork;
push @t,$apacheiwork;
&minmaxavg("DAY","1Busy",$apachebwork);
&minmaxavg("DAY","2Idle",$apacheiwork);
}
}
if ($minmaxavg{DAY}{"1Busy"}{CNT} > 0) {$minmaxavg{DAY}{"1Busy"}{AVG} /= $minmaxavg{DAY}{"1Busy"}{CNT}}
if ($minmaxavg{DAY}{"2Idle"}{CNT} > 0) {$minmaxavg{DAY}{"2Idle"}{AVG} /= $minmaxavg{DAY}{"2Idle"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'Workers',
x_label_skip => 60,
title => 'Apache Workers in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Busy Idle));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "apachework") {
my (@h,@p,@t);
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $apachebwork_avg;
my $apacheiwork_avg;
my $cnt_avg = 0;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $apachebwork ne "") {
$apachebwork_avg += $apachebwork;
$apacheiwork_avg += $apacheiwork;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
push @t,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$apachebwork_avg/$cnt_avg;
push @t,$apacheiwork_avg/$cnt_avg;
&minmaxavg("WEEK","1Busy",($apachebwork_avg/$cnt_avg));
&minmaxavg("WEEK","2Idle",($apacheiwork_avg/$cnt_avg));
}
}
if ($minmaxavg{WEEK}{"1Busy"}{CNT} > 0) {$minmaxavg{WEEK}{"1Busy"}{AVG} /= $minmaxavg{WEEK}{"1Busy"}{CNT}}
if ($minmaxavg{WEEK}{"2Idle"}{CNT} > 0) {$minmaxavg{WEEK}{"2Idle"}{AVG} /= $minmaxavg{WEEK}{"2Idle"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Workers',
x_label_skip => 24,
title => 'Apache Workers in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Busy Idle));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "apachework") {
my (@h,@p,@t);
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $apachebwork_avg;
my $apacheiwork_avg;
my $cnt_avg = 0;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $apachebwork ne "") {
$apachebwork_avg += $apachebwork;
$apacheiwork_avg += $apacheiwork;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
push @t,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$apachebwork_avg/$cnt_avg;
push @t,$apacheiwork_avg/$cnt_avg;
&minmaxavg("MONTH","1Busy",($apachebwork_avg/$cnt_avg));
&minmaxavg("MONTH","2Idle",($apacheiwork_avg/$cnt_avg));
}
}
if ($minmaxavg{MONTH}{"1Busy"}{CNT} > 0) {$minmaxavg{MONTH}{"1Busy"}{AVG} /= $minmaxavg{MONTH}{"1Busy"}{CNT}}
if ($minmaxavg{MONTH}{"2Idle"}{CNT} > 0) {$minmaxavg{MONTH}{"2Idle"}{AVG} /= $minmaxavg{MONTH}{"2Idle"}{CNT}}
my @data = ([reverse @h],[reverse @p],[reverse @t]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'Workers',
x_label_skip => 24,
title => "Apache Workers in last $system_maxdays",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend( qw(Busy Idle));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "diskw") {
my (@h,@p);
for (my $mins = 0; $mins < 60;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$min;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $diskw eq "") {
push @p,undef;
} else {
push @p,$diskw;
&minmaxavg("HOUR","1Disk_Write",$diskw);
}
}
if ($minmaxavg{HOUR}{"1Disk_Write"}{CNT} > 0) {$minmaxavg{HOUR}{"1Disk_Write"}{AVG} /= $minmaxavg{HOUR}{"1Disk_Write"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Minute',
y_label => 'MB/s',
x_label_skip => 3,
title => 'Disk Write Performance in last hour',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend("Disk_Write");
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemhour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "diskw") {
my (@h,@p);
for (my $mins = 0; $mins < 1440;$mins++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($mins * 60));
push @h,$hour;
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$min});
if ($time eq "" or $diskw eq "") {
push @p,undef;
} else {
push @p,$diskw;
&minmaxavg("DAY","1Disk_Write",$diskw);
}
}
if ($minmaxavg{DAY}{"1Disk_Write"}{CNT} > 0) {$minmaxavg{DAY}{"1Disk_Write"}{AVG} /= $minmaxavg{DAY}{"1Disk_Write"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred purple) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'MB/s',
x_label_skip => 60,
title => 'Disk Write Performance in last 24 hours',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend("Disk_Write");
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemday.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "diskw") {
my (@h,@p);
for (my $hours = 0; $hours < 168;$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $diskw_avg;
my $cnt_avg = 0;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $diskw ne "") {
$diskw_avg += $diskw;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$diskw_avg/$cnt_avg;
&minmaxavg("WEEK","1Disk_Write",($diskw_avg/$cnt_avg));
}
}
if ($minmaxavg{WEEK}{"1Disk_Write"}{CNT} > 0) {$minmaxavg{WEEK}{"1Disk_Write"}{AVG} /= $minmaxavg{WEEK}{"1Disk_Write"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'MB/s',
x_label_skip => 24,
title => 'Disk Write Performance in last 7 days',
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend("Disk_Write");
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemweek.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
if ($type eq "diskw") {
my (@h,@p);
for (my $hours = 0; $hours < (24 * $system_maxdays);$hours++) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time - ($hours * 60 * 60));
push @h,$mday;
my $diskw_avg;
my $cnt_avg = 0;
for (my $mins = 59; $mins >= 0;$mins--) {
my ($time,$cputotal,$cpuidle,$cpuiowait,$memtotal,$memfree,$memswaptotal,$memswapfree,$load1,$load5,$load15,$netin,$netout,$diskread,$diskwrite,$mailin,$mailout,$cputemp,$mysqlin,$mysqlout,$mysqlq,$mysqlsq,$mysqlcn,$mysqlth,$apachecpu,$apacheacc,$apachebwork,$apacheiwork,$diskw,$memcached) = split(/\,/,$stata{$year}{$mon}{$mday}{$hour}{$mins});
if ($time and $diskw ne "") {
$diskw_avg += $diskw;
$cnt_avg++;
}
}
unless (defined $cnt_avg) {
push @p,undef;
} else {
if ($cnt_avg == 0) {$cnt_avg = 1}
push @p,$diskw_avg/$cnt_avg;
&minmaxavg("MONTH","1Disk_Write",($diskw_avg/$cnt_avg));
}
}
if ($minmaxavg{MONTH}{"1Disk_Write"}{CNT} > 0) {$minmaxavg{MONTH}{"1Disk_Write"}{AVG} /= $minmaxavg{MONTH}{"1Disk_Write"}{CNT}}
my @data = ([reverse @h],[reverse @p]);
my $hour_graph = GD::Graph::lines->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Day (Hourly Average)',
y_label => 'MB/s',
x_label_skip => 24,
title => "Disk Write Performance in last $system_maxdays",
borderclrs => $hour_graph->{dclrs},
transparent => 0,
);
$hour_graph->set_legend("Disk_Write");
$hour_graph->plot(\@data);
$img = $imghddir."lfd_systemmonth.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
}
}
return;
}
# end graphs
###############################################################################
# start charts
sub charts {
my $cc_lookups = shift;
my $imghddir = shift;
my $img;
$| = 1;
require GD::Graph::bars;
import GD::Graph::bars;
require GD::Graph::pie;
import GD::Graph::pie;
require GD::Graph::lines;
import GD::Graph::lines;
sysopen (my $STATS,"/var/lib/csf/stats/lfdstats", O_RDWR | O_CREAT);
flock ($STATS, LOCK_SH);
my @stats = <$STATS>;
chomp @stats;
close ($STATS);
if (@stats) {
my $time = time;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
# Blocks by lfd in the last 24 hours
my $cnt = $hour + 1;
if ($cnt > 23) {$cnt = 0}
my (@h,@p,@t,@hp,@cp);
my %triggers;
for (my $hours = 0; $hours < 24;$hours++) {
push @h,$cnt;
my ($permdate,$permcount,$tempdate,$tempcount) = split(/\,/,$stats[$cnt]);
if ($time - $permdate > (24 * 60 * 60)) {$permdate = 0; $permcount = 0}
if ($time - $tempdate > (24 * 60 * 60)) {$tempdate = 0; $tempcount = 0}
push @p,$permcount;
push @t,$tempcount;
my @line = split(/\,/,$stats[$cnt]);
for (my $loop = 4; $loop < @line; $loop+=2) {
if ($time - $line[$loop] > (24 * 60 * 60)) {next}
my ($triggerstat,$triggercount) = split(/\:/,$line[$loop+1]);
$triggers{$triggerstat} += $triggercount;
}
$cnt++;
if ($cnt > 23) {$cnt = 0}
}
my @data = ([@h],[@p],[@t]);
my $hour_graph = GD::Graph::bars->new(750,350);
$hour_graph->set( dclrs => [ qw(yellow dred) ] );
$hour_graph->set(
x_label => 'Hour',
y_label => 'Total Blocks',
long_ticks => 1,
tick_length => 0,
x_ticks => 0,
title => 'Blocks by lfd in the last 24 hours',
cumulate => 1,
borderclrs => $hour_graph->{dclrs},
bar_spacing => 4,
shadow_depth => 1,
transparent => 0,
x_label_position => 1/2,
);
$hour_graph->set_legend( qw(Permanent Temporary));
$hour_graph->plot(\@data);
$img = $imghddir."lfd_hour.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $hour_graph->gd->gif();
close ($OUT);
foreach my $key (keys %triggers) {
push @hp, "$key ($triggers{$key})";
push @cp, $triggers{$key};
}
my @piedata = ([@hp],[@cp]);
my $hour_pie_graph = GD::Graph::pie->new( 400, 300 );
$hour_pie_graph->set(
title => 'Block triggers in the last 24 hours',
label => 'Trigger in csf.conf',
axislabelclr => 'black',
pie_height => 36,
l_margin => 15,
r_margin => 15,
start_angle => 235,
transparent => 0,
);
$hour_pie_graph->plot(\@piedata);
$img = $imghddir."lfd_pie_hour.gif";
open (my $OUT2, ">", "$img");
flock ($OUT2, LOCK_EX);
binmode ($OUT2);
print $OUT2 $hour_pie_graph->gd->gif();
close ($OUT2);
# Blocks by lfd in the last 30 Days
my $maxdays = 30;
my ($hsec,$hmin,$hhour,$hmday,$hmon,$hyear,$hwday,$hyday,$hisdst) = localtime($time - (29 * 24 * 60 * 60));
my $hdim = (31,28,31,30,31,30,31,31,30,31,30,31)[$hmon];
if ($hmon == 1 && (($hyear % 4 == 0) && ($hyear % 100 != 0) && ($hyear % 400 == 0))) {$hdim++}
if ($hmon == 1) {
$maxdays = $hdim;
($hsec,$hmin,$hhour,$hmday,$hmon,$hyear,$hwday,$hyday,$hisdst) = localtime($time - (($maxdays - 1) * 24 * 60 * 60));
}
$cnt = $hmday;
my (@hh,@ph,@th,@hhp,@hcp);
my %htriggers;
for (my $days = 1; $days <= $maxdays;$days++) {
push @hh,$cnt;
my ($permdate,$permcount,$tempdate,$tempcount) = split(/\,/,$stats[$cnt+24]);
if ($time - $permdate > (($maxdays - 1) * 24 * 60 * 60)) {$permdate = 0; $permcount = 0}
if ($time - $tempdate > (($maxdays - 1) * 24 * 60 * 60)) {$tempdate = 0; $tempcount = 0}
push @ph,$permcount;
push @th,$tempcount;
my @line = split(/\,/,$stats[$cnt+24]);
for (my $loop = 4; $loop < @line; $loop+=2) {
if ($time - $line[$loop] > (($maxdays - 1) * 24 * 60 * 60)) {next}
my ($triggerstat,$triggercount) = split(/\:/,$line[$loop+1]);
$htriggers{$triggerstat} += $triggercount;
}
$cnt++;
if ($cnt > $hdim) {$cnt = 1}
}
my @datah = ([@hh],[@ph],[@th]);
my $day_graph = GD::Graph::bars->new(750,350);
$day_graph->set( dclrs => [ qw(yellow dred) ] );
$day_graph->set(
x_label => 'Day',
y_label => 'Total Blocks',
long_ticks => 1,
tick_length => 0,
x_ticks => 0,
title => "Blocks by lfd in the last $maxdays Days",
cumulate => 1,
borderclrs => $day_graph->{dclrs},
bar_spacing => 4,
shadow_depth => 1,
transparent => 0,
x_label_position => 1/2,
);
$day_graph->set_legend( qw(Permanent Temporary));
$day_graph->plot(\@datah);
$img = $imghddir."lfd_month.gif";
open (my $OUT3, ">", "$img");
flock ($OUT3, LOCK_EX);
binmode ($OUT3);
print $OUT3 $day_graph->gd->gif();
close ($OUT3);
foreach my $key (keys %htriggers) {
push @hhp, "$key ($htriggers{$key})";
push @hcp, $htriggers{$key};
}
my @hpiedata = ([@hhp],[@hcp]);
my $day_pie_graph = GD::Graph::pie->new( 400, 300 );
$day_pie_graph->set(
title => "Block triggers in the last $maxdays days",
label => 'Trigger in csf.conf',
axislabelclr => 'black',
pie_height => 36,
l_margin => 15,
r_margin => 15,
start_angle => 235,
transparent => 0,
);
$day_pie_graph->plot(\@hpiedata);
$img = $imghddir."lfd_pie_day.gif";
open (my $OUT4, ">", "$img");
flock ($OUT4, LOCK_EX);
binmode ($OUT4);
print $OUT4 $day_pie_graph->gd->gif();
close ($OUT4);
# Blocks by lfd in the last 12 months
$cnt = $mon + 2;
if ($cnt > 12) {$cnt = 1}
my (@hy,@py,@ty,@yhp,@ycp);
my %ytriggers;
for (my $months = 1; $months < 13;$months++) {
push @hy,$cnt;
my ($permdate,$permcount,$tempdate,$tempcount) = split(/\,/,$stats[$cnt+55]);
if ($time - $permdate > (364 * 24 * 60 * 60)) {$permdate = 0; $permcount = 0}
if ($time - $tempdate > (364 * 24 * 60 * 60)) {$tempdate = 0; $tempcount = 0}
push @py,$permcount;
push @ty,$tempcount;
my @line = split(/\,/,$stats[$cnt+55]);
for (my $loop = 4; $loop < @line; $loop+=2) {
if ($time - $line[$loop] > (364 * 24 * 60 * 60)) {next}
my ($triggerstat,$triggercount) = split(/\:/,$line[$loop+1]);
$ytriggers{$triggerstat} += $triggercount;
}
$cnt++;
if ($cnt > 12) {$cnt = 1}
}
my @datay = ([@hy],[@py],[@ty]);
my $year_graph = GD::Graph::bars->new(750,350);
$year_graph->set( dclrs => [ qw(yellow dred) ] );
$year_graph->set(
x_label => 'Month',
y_label => 'Total Blocks',
long_ticks => 1,
tick_length => 0,
x_ticks => 0,
title => 'Blocks by lfd in the last 12 months',
cumulate => 1,
borderclrs => $year_graph->{dclrs},
bar_spacing => 4,
shadow_depth => 1,
transparent => 0,
x_label_position => 1/2,
);
$year_graph->set_legend( qw(Permanent Temporary));
$year_graph->plot(\@datay);
$img = $imghddir."lfd_year.gif";
open (my $OUT5, ">", "$img");
flock ($OUT5, LOCK_EX);
binmode ($OUT5);
print $OUT5 $year_graph->gd->gif();
close ($OUT5);
foreach my $key (keys %ytriggers) {
push @yhp, "$key ($ytriggers{$key})";
push @ycp, $ytriggers{$key};
}
my @ypiedata = ([@yhp],[@ycp]);
my $year_pie_graph = GD::Graph::pie->new( 400, 300 );
$year_pie_graph->set(
title => 'Block triggers in the last 12 months',
label => 'Trigger in csf.conf',
axislabelclr => 'black',
pie_height => 36,
l_margin => 15,
r_margin => 15,
start_angle => 235,
transparent => 0,
);
$year_pie_graph->plot(\@ypiedata);
$img = $imghddir."lfd_pie_year.gif";
open (my $OUT6, ">", "$img");
flock ($OUT6, LOCK_EX);
binmode ($OUT6);
print $OUT6 $year_pie_graph->gd->gif();
close ($OUT6);
if ($cc_lookups) {
# Total Top 30 Country Code blocks by lfd
my (@ccy,@ccx);
my %ccs;
my $cntcc;
my @line = split(/\,/,$stats[69]);
for (my $x = 0; $x < @line; $x+=2) {$ccs{$line[$x]} = $line[$x+1]}
foreach my $key (sort {$ccs{$b} <=> $ccs{$a}} keys %ccs) {
push @ccy,$key;
push @ccx,$ccs{$key};
$cntcc++;
if ($cntcc > 29) {last}
}
my @datacc = ([@ccy],[@ccx]);
my $cc_graph = GD::Graph::bars->new(750,350);
$cc_graph->set( dclrs => [ qw(yellow) ] );
$cc_graph->set(
x_label => 'Country Code',
y_label => 'Total Blocks',
long_ticks => 1,
tick_length => 0,
x_ticks => 0,
title => 'Total Top 30 Country Code blocks by lfd',
cumulate => 1,
borderclrs => $cc_graph->{dclrs},
bar_spacing => 4,
shadow_depth => 1,
transparent => 0,
x_label_position => 1/2,
);
$cc_graph->plot(\@datacc);
$img = $imghddir."lfd_cc.gif";
open (my $OUT, ">", "$img");
flock ($OUT, LOCK_EX);
binmode ($OUT);
print $OUT $cc_graph->gd->gif();
close ($OUT);
}
}
return;
}
# end charts
###############################################################################
# start minmaxavg
sub minmaxavg {
my $graph = shift;
my $name = shift;
my $value = shift;
unless (defined $minmaxavg{$graph}{$name}{MIN}) {$minmaxavg{$graph}{$name}{MIN} = $value}
unless (defined $minmaxavg{$graph}{$name}{MAX}) {$minmaxavg{$graph}{$name}{MAX} = $value}
if ($minmaxavg{$graph}{$name}{MIN} > $value) {$minmaxavg{$graph}{$name}{MIN} = $value}
if ($minmaxavg{$graph}{$name}{MAX} < $value) {$minmaxavg{$graph}{$name}{MAX} = $value}
$minmaxavg{$graph}{$name}{AVG} += $value;
$minmaxavg{$graph}{$name}{CNT}++;
return;
}
# end minmaxavg
###############################################################################
# start graphs_html
sub graphs_html {
my $imgdir = shift;
my $html;
$html .= "
\n";
$html .= "\n";
$html .= "
\n";
foreach my $key (sort keys %{$minmaxavg{HOUR}}) {
my $item = $key;
if ($key =~ /^\d(.*)$/) {$item = $1}
$html .= "$item ";
$html .= "Min:".sprintf("%.2f",$minmaxavg{HOUR}{$key}{MIN})." ";
$html .= "Max:".sprintf("%.2f",$minmaxavg{HOUR}{$key}{MAX})." ";
$html .= "Avg:".sprintf("%.2f",$minmaxavg{HOUR}{$key}{AVG})." \n";
}
$html .= "
Note: This graph displays per minute statistics unless otherwise stated
\n";
$html .= "
\n";
foreach my $key (sort keys %{$minmaxavg{DAY}}) {
my $item = $key;
if ($key =~ /^\d(.*)$/) {$item = $1}
$html .= "$item ";
$html .= "Min:".sprintf("%.2f",$minmaxavg{DAY}{$key}{MIN})." ";
$html .= "Max:".sprintf("%.2f",$minmaxavg{DAY}{$key}{MAX})." ";
$html .= "Avg:".sprintf("%.2f",$minmaxavg{DAY}{$key}{AVG})." \n";
}
$html .= "
Note: This graph displays per minute statistics unless otherwise stated
\n";
$html .= "
\n";
foreach my $key (sort keys %{$minmaxavg{WEEK}}) {
my $item = $key;
if ($key =~ /^\d(.*)$/) {$item = $1}
$html .= "$item ";
$html .= "Min:".sprintf("%.2f",$minmaxavg{WEEK}{$key}{MIN})." ";
$html .= "Max:".sprintf("%.2f",$minmaxavg{WEEK}{$key}{MAX})." ";
$html .= "Avg:".sprintf("%.2f",$minmaxavg{WEEK}{$key}{AVG})." \n";
}
$html .= "
Note: This graph displays an hourly average of the per minute statistics, so you will not see the peak minute values
\n";
$html .= "
\n";
foreach my $key (sort keys %{$minmaxavg{MONTH}}) {
my $item = $key;
if ($key =~ /^\d(.*)$/) {$item = $1}
$html .= "$item ";
$html .= "Min:".sprintf("%.2f",$minmaxavg{MONTH}{$key}{MIN})." ";
$html .= "Max:".sprintf("%.2f",$minmaxavg{MONTH}{$key}{MAX})." ";
$html .= "Avg:".sprintf("%.2f",$minmaxavg{MONTH}{$key}{AVG})." \n";
}
$html .= "
Note: This graph displays an hourly average of the per minute statistics, so you will not see the peak minute values
\n
\n";
return $html;
}
# end graphs_html
###############################################################################
# start charts_html
sub charts_html {
my $cc_lookups = shift;
my $imgdir = shift;
my $html;
$html .= "
\n";
$html .= "\n";
$html .= "
\n";
$html .= "
\n";
$html .= " \n";
$html .= "
\n";
$html .= "
\n";
if ($cc_lookups) {
$html .= " \n";
$html .= "
\n";
$html .= "
\n";
$html .= " \n\n";
$html .= "
\n";
} else {
$html .= " \n\n";
$html .= "
\n";
$html .= "
\n";
}
$html .= " \n
\n";
return $html;
}
# end charts_html
###############################################################################
1; CheckIP.pm 0000644 00000006006 15103002075 0006343 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::CheckIP;
use strict;
use lib '/usr/local/csf/lib';
use Carp;
use Net::IP;
use ConfigServer::Config;
use Exporter qw(import);
our $VERSION = 1.03;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(checkip cccheckip);
my $ipv4reg = ConfigServer::Config->ipv4reg;
my $ipv6reg = ConfigServer::Config->ipv6reg;
# end main
###############################################################################
# start checkip
sub checkip {
my $ipin = shift;
my $ret = 0;
my $ipref = 0;
my $ip;
my $cidr;
if (ref $ipin) {
($ip,$cidr) = split(/\//,${$ipin});
$ipref = 1;
} else {
($ip,$cidr) = split(/\//,$ipin);
}
my $testip = $ip;
if ($cidr ne "") {
unless ($cidr =~ /^\d+$/) {return 0}
}
if ($ip =~ /^$ipv4reg$/) {
$ret = 4;
if ($cidr) {
unless ($cidr >= 1 && $cidr <= 32) {return 0}
}
if ($ip eq "127.0.0.1") {return 0}
}
if ($ip =~ /^$ipv6reg$/) {
$ret = 6;
if ($cidr) {
unless ($cidr >= 1 && $cidr <= 128) {return 0}
}
$ip =~ s/://g;
$ip =~ s/^0*//g;
if ($ip == 1) {return 0}
if ($ipref) {
eval {
local $SIG{__DIE__} = undef;
my $netip = Net::IP->new($testip);
my $myip = $netip->short();
if ($myip ne "") {
if ($cidr eq "") {
${$ipin} = $myip;
} else {
${$ipin} = $myip."/".$cidr;
}
}
};
if ($@) {return 0}
}
}
return $ret;
}
# end checkip
###############################################################################
# start cccheckip
sub cccheckip {
my $ipin = shift;
my $ret = 0;
my $ipref = 0;
my $ip;
my $cidr;
if (ref $ipin) {
($ip,$cidr) = split(/\//,${$ipin});
$ipref = 1;
} else {
($ip,$cidr) = split(/\//,$ipin);
}
my $testip = $ip;
if ($cidr ne "") {
unless ($cidr =~ /^\d+$/) {return 0}
}
if ($ip =~ /^$ipv4reg$/) {
$ret = 4;
if ($cidr) {
unless ($cidr >= 1 && $cidr <= 32) {return 0}
}
if ($ip eq "127.0.0.1") {return 0}
my $type;
eval {
local $SIG{__DIE__} = undef;
my $netip = Net::IP->new($testip);
$type = $netip->iptype();
};
if ($@) {return 0}
if ($type ne "PUBLIC") {return 0}
}
if ($ip =~ /^$ipv6reg$/) {
$ret = 6;
if ($cidr) {
unless ($cidr >= 1 && $cidr <= 128) {return 0}
}
$ip =~ s/://g;
$ip =~ s/^0*//g;
if ($ip == 1) {return 0}
if ($ipref) {
eval {
local $SIG{__DIE__} = undef;
my $netip = Net::IP->new($testip);
my $myip = $netip->short();
if ($myip ne "") {
if ($cidr eq "") {
${$ipin} = $myip;
} else {
${$ipin} = $myip."/".$cidr;
}
}
};
if ($@) {return 0}
}
}
return $ret;
}
# end cccheckip
###############################################################################
1; KillSSH.pm 0000644 00000004671 15103002075 0006354 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::KillSSH;
use strict;
use lib '/usr/local/csf/lib';
use Fcntl qw(:DEFAULT :flock);
use ConfigServer::Logger;
use Exporter qw(import);
our $VERSION = 1.00;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
# end main
###############################################################################
# start iplookup
sub find {
my $ip = shift;
my $ports = shift;
my %inodes;
if ($ports eq "" or $ip eq "") {return}
foreach my $proto ("tcp","tcp6") {
open (my $IN, "<", "/proc/net/$proto");
flock ($IN, LOCK_SH);
while (<$IN>) {
my @rec = split();
if ($rec[9] =~ /uid/) {next}
my ($dip,$dport) = split(/:/,$rec[2]);
$dport = hex($dport);
my ($sip,$sport) = split(/:/,$rec[1]);
$sport = hex($sport);
$dip = &hex2ip($dip);
$sip = &hex2ip($sip);
if ($sip eq '0.0.0.1') {next}
if ($dip eq $ip) {
foreach my $port (split(/\,/, $ports)) {
if ($port eq $sport) {
$inodes{$rec[9]} = 1;
}
}
}
}
close ($IN);
}
opendir (my $PROCDIR, "/proc");
while (my $pid = readdir($PROCDIR)) {
if ($pid !~ /^\d+$/) {next}
opendir (DIR, "/proc/$pid/fd") or next;
while (my $file = readdir (DIR)) {
if ($file =~ /^\./) {next}
my $fd = readlink("/proc/$pid/fd/$file");
if ($fd =~ /^socket:\[?([0-9]+)\]?$/) {
if ($inodes{$1} and readlink("/proc/$pid/exe") =~ /sshd/) {
kill (9,$pid);
ConfigServer::Logger::logfile("*PT_SSHDKILL*: Process PID:[$pid] killed for blocked IP:[$ip]");
}
}
}
closedir (DIR);
}
closedir ($PROCDIR);
return;
}
# end find
###############################################################################
## start hex2ip
sub hex2ip {
my $bin = pack "C*" => map hex, $_[0] =~ /../g;
my @l = unpack "L*", $bin;
if (@l == 4) {
return join ':', map { sprintf "%x:%x", $_ >> 16, $_ & 0xffff } @l;
}
elsif (@l == 1) {
return join '.', map { $_ >> 24, ($_ >> 16 ) & 0xff, ($_ >> 8) & 0xff, $_ & 0xff } @l;
}
}
## end hex2ip
###############################################################################
1; RBLLookup.pm 0000644 00000005653 15103002075 0006715 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::RBLLookup;
use strict;
use lib '/usr/local/csf/lib';
use Fcntl qw(:DEFAULT :flock);
use IPC::Open3;
use Net::IP;
use ConfigServer::Config;
use ConfigServer::CheckIP qw(checkip);
use Exporter qw(import);
our $VERSION = 1.01;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(rbllookup);
my $config = ConfigServer::Config->loadconfig();
my %config = $config->config();
my $ipv4reg = ConfigServer::Config->ipv4reg;
my $ipv6reg = ConfigServer::Config->ipv6reg;
# end main
###############################################################################
# start rbllookup
sub rbllookup {
my $ip = shift;
my $rbl = shift;
my %rblhits;
my $netip;
my $reversed_ip;
my $timeout = 4;
my $rblhit;
my $rblhittxt;
if (checkip(\$ip)) {
eval {
local $SIG{__DIE__} = undef;
$netip = Net::IP->new($ip);
$reversed_ip = $netip->reverse_ip();
};
if ($reversed_ip =~ /^(\S+)\.in-addr\.arpa/) {$reversed_ip = $1}
if ($reversed_ip =~ /^(\S+)\s+(\S+)\.in-addr\.arpa/) {$reversed_ip = $2}
if ($reversed_ip =~ /^(\S+)\.ip6\.arpa/) {$reversed_ip = $1}
if ($reversed_ip =~ /^(\S+)\s+(\S+)\.ip6\.arpa/) {$reversed_ip = $2}
if ($reversed_ip ne "") {
my $lookup_ip = $reversed_ip.".".$rbl;
my $cmdpid;
eval {
local $SIG{__DIE__} = undef;
local $SIG{'ALRM'} = sub {die};
alarm($timeout);
my ($childin, $childout);
$cmdpid = open3($childin, $childout, $childout, $config{HOST},"-t","A",$lookup_ip);
close $childin;
my @results = <$childout>;
waitpid ($cmdpid, 0);
chomp @results;
if ($results[0] =~ /^${reversed_ip}.+ ($ipv4reg|$ipv6reg)$/) {$rblhit = $1}
alarm(0);
};
alarm(0);
if ($@) {$rblhit = "timeout"}
if ($cmdpid =~ /\d+/ and $cmdpid > 1 and kill(0,$cmdpid)) {kill(9,$cmdpid)}
if ($rblhit ne "") {
if ($rblhit ne "timeout") {
my $cmdpid;
eval {
local $SIG{__DIE__} = undef;
local $SIG{'ALRM'} = sub {die};
alarm($timeout);
my ($childin, $childout);
$cmdpid = open3($childin, $childout, $childout, $config{HOST},"-t","TXT",$lookup_ip);
close $childin;
my @results = <$childout>;
waitpid ($cmdpid, 0);
chomp @results;
foreach my $line (@results) {
if ($line =~ /^${reversed_ip}.+ "([^\"]+)"$/) {$rblhittxt .= "$1\n"}
}
alarm(0);
};
alarm(0);
if ($cmdpid =~ /\d+/ and $cmdpid > 1 and kill(0,$cmdpid)) {kill(9,$cmdpid)}
}
}
}
}
return ($rblhit,$rblhittxt);
}
# end rbllookup
###############################################################################
1;
Ports.pm 0000644 00000013277 15103002075 0006214 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::Ports;
use strict;
use lib '/usr/local/csf/lib';
use Fcntl qw(:DEFAULT :flock);
use ConfigServer::Config;
use Exporter qw(import);
our $VERSION = 1.02;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
my %printable = ( ( map { chr($_), unpack('H2', chr($_)) } (0..255) ), "\\"=>'\\', "\r"=>'r', "\n"=>'n', "\t"=>'t', "\""=>'"' ); ##no critic
my %tcpstates = ("01" => "ESTABLISHED",
"02" => "SYN_SENT",
"03" => "SYN_RECV",
"04" => "FIN_WAIT1",
"05" => "FIN_WAIT2",
"06" => "TIME_WAIT",
"07" => "CLOSE",
"08" => "CLOSE_WAIT",
"09" => "LAST_ACK",
"0A" => "LISTEN",
"0B" => "CLOSING");
# end main
###############################################################################
# start listening
sub listening {
my %net;
my %conn;
my %listen;
foreach my $proto ("tcp","udp","tcp6","udp6") {
open (my $IN, "<","/proc/net/$proto");
flock ($IN, LOCK_SH);
while (<$IN>) {
my @rec = split();
if ($rec[9] =~ /uid/) {next}
my ($dip,$dport) = split(/:/,$rec[1]);
$dport = hex($dport);
my ($sip,$sport) = split(/:/,$rec[2]);
$sport = hex($sport);
$dip = &hex2ip($dip);
$sip = &hex2ip($sip);
my $inode = $rec[9];
my $state = $tcpstates{$rec[3]};
my $protocol = $proto;
$protocol =~ s/6//;
if ($protocol eq "udp" and $state eq "CLOSE") {$state = "LISTEN"}
if ($state eq "ESTABLISHED") {$conn{$dport}{$protocol}++}
if ($dip =~ /^127\./) {next}
if ($dip =~ /^0\.0\.0\.1/) {next}
if ($state eq "LISTEN") {$net{$inode}{$protocol} = $dport}
}
close ($IN);
}
opendir (PROCDIR, "/proc");
while (my $pid = readdir(PROCDIR)) {
if ($pid !~ /^\d+$/) {next}
my $exe = readlink("/proc/$pid/exe") || "";
my $cwd = readlink("/proc/$pid/cwd") || "";
my $uid;
my $user;
if (defined $exe) {$exe =~ s/([\r\n\t\"\\\x00-\x1f\x7F-\xFF])/\\$printable{$1}/sg}
open (my $CMDLINE,"<","/proc/$pid/cmdline");
flock ($CMDLINE, LOCK_SH);
my $cmdline = <$CMDLINE>;
close ($CMDLINE);
if (defined $cmdline) {
chomp $cmdline;
$cmdline =~ s/\0$//g;
$cmdline =~ s/\0/ /g;
$cmdline =~ s/([\r\n\t\"\\\x00-\x1f\x7F-\xFF])/\\$printable{$1}/sg;
$cmdline =~ s/\s+$//;
$cmdline =~ s/^\s+//;
}
if ($exe eq "") {next}
my @fd;
opendir (DIR, "/proc/$pid/fd") or next;
while (my $file = readdir (DIR)) {
if ($file =~ /^\./) {next}
push (@fd, readlink("/proc/$pid/fd/$file"));
}
closedir (DIR);
open (my $STATUS,"<", "/proc/$pid/status") or next;
flock ($STATUS, LOCK_SH);
my @status = <$STATUS>;
close ($STATUS);
chomp @status;
foreach my $line (@status) {
if ($line =~ /^Uid:(.*)/) {
my $uidline = $1;
my @uids;
foreach my $bit (split(/\s/,$uidline)) {
if ($bit =~ /^(\d*)$/) {push @uids, $1}
}
$uid = $uids[-1];
$user = getpwuid($uid);
if ($user eq "") {$user = $uid}
}
}
my $files;
my $sockets;
foreach my $file (@fd) {
if ($file =~ /^socket:\[?([0-9]+)\]?$/) {
my $ino = $1;
if ($net{$ino}) {
foreach my $protocol (keys %{$net{$ino}}) {
$listen{$protocol}{$net{$ino}{$protocol}}{$pid}{user} = $user;
$listen{$protocol}{$net{$ino}{$protocol}}{$pid}{exe} = $exe;
$listen{$protocol}{$net{$ino}{$protocol}}{$pid}{cmd} = $cmdline;
$listen{$protocol}{$net{$ino}{$protocol}}{$pid}{cmd} = $cmdline;
$listen{$protocol}{$net{$ino}{$protocol}}{$pid}{conn} = $conn{$net{$ino}{$protocol}}{$protocol} | "-";
}
}
}
}
}
closedir (PROCDIR);
return %listen;
}
# end listening
###############################################################################
# start openports
sub openports {
my $config = ConfigServer::Config->loadconfig();
my %config = $config->config();
my %ports;
$config{TCP_IN} =~ s/\s//g;
foreach my $entry (split(/,/,$config{TCP_IN})) {
if ($entry =~ /^(\d+):(\d+)$/) {
my $from = $1;
my $to = $2;
for (my $port = $from; $port < $to ; $port++) {
$ports{tcp}{$port} = 1;
}
} else {
$ports{tcp}{$entry} = 1;
}
}
$config{TCP6_IN} =~ s/\s//g;
foreach my $entry (split(/,/,$config{TCP6_IN})) {
if ($entry =~ /^(\d+):(\d+)$/) {
my $from = $1;
my $to = $2;
for (my $port = $from; $port < $to ; $port++) {
$ports{tcp6}{$port} = 1;
}
} else {
$ports{tcp6}{$entry} = 1;
}
}
$config{UDP_IN} =~ s/\s//g;
foreach my $entry (split(/,/,$config{UDP_IN})) {
if ($entry =~ /^(\d+):(\d+)$/) {
my $from = $1;
my $to = $2;
for (my $port = $from; $port < $to ; $port++) {
$ports{udp}{$port} = 1;
}
} else {
$ports{udp}{$entry} = 1;
}
}
$config{UDP6_IN} =~ s/\s//g;
foreach my $entry (split(/,/,$config{UDP6_IN})) {
if ($entry =~ /^(\d+):(\d+)$/) {
my $from = $1;
my $to = $2;
for (my $port = $from; $port < $to ; $port++) {
$ports{udp6}{$port} = 1;
}
} else {
$ports{udp6}{$entry} = 1;
}
}
return %ports;
}
# end openports
###############################################################################
## start hex2ip
sub hex2ip {
my $bin = pack "C*" => map hex, $_[0] =~ /../g;
my @l = unpack "L*", $bin;
if (@l == 4) {
return join ':', map { sprintf "%x:%x", $_ >> 16, $_ & 0xffff } @l;
}
elsif (@l == 1) {
return join '.', map { $_ >> 24, ($_ >> 16 ) & 0xff, ($_ >> 8) & 0xff, $_ & 0xff } @l;
}
}
## end hex2ip
###############################################################################
1; Sanity.pm 0000644 00000003603 15103002075 0006344 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::Sanity;
use strict;
use lib '/usr/local/csf/lib';
use Fcntl qw(:DEFAULT :flock);
use Carp;
use ConfigServer::Config;
use Exporter qw(import);
our $VERSION = 1.02;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(sanity);
my %sanity;
my %sanitydefault;
my $sanityfile = "/usr/local/csf/lib/sanity.txt";
open (my $IN, "<", $sanityfile);
flock ($IN, LOCK_SH);
my @data = <$IN>;
close ($IN);
chomp @data;
foreach my $line (@data) {
my ($name,$value,$def) = split(/\=/,$line);
$sanity{$name} = $value;
$sanitydefault{$name} = $def;
}
my $config = ConfigServer::Config->loadconfig();
my %config = $config->config();
if ($config{IPSET}) {
delete $sanity{"DENY_IP_LIMIT"};
delete $sanitydefault{"DENY_IP_LIMIT"};
}
# end main
###############################################################################
# start sanity
sub sanity {
my $sanity_item = shift;
my $sanity_value = shift;
my $insane = 0;
$sanity_item =~ s/\s//g;
$sanity_value =~ s/\s//g;
if (defined $sanity{$sanity_item}) {
$insane = 1;
foreach my $check (split(/\|/,$sanity{$sanity_item})) {
if ($check =~ /-/) {
my ($from,$to) = split(/\-/,$check);
if (($sanity_value >= $from) and ($sanity_value <= $to)) {$insane = 0}
} else {
if ($sanity_value eq $check) {$insane = 0}
}
}
$sanity{$sanity_item} =~ s/\|/ or /g;
}
return ($insane,$sanity{$sanity_item},$sanitydefault{$sanity_item});
}
# end sanity
###############################################################################
1; GetEthDev.pm 0000644 00000007171 15103002075 0006720 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::GetEthDev;
use strict;
use lib '/usr/local/csf/lib';
use Carp;
use Fcntl qw(:DEFAULT :flock);
use IPC::Open3;
use POSIX qw(locale_h);
use ConfigServer::Config;
use ConfigServer::CheckIP qw(checkip);
use ConfigServer::Logger;
use Exporter qw(import);
our $VERSION = 1.01;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
my (%ifaces, %ipv4, %ipv6, %brd);
# end main
###############################################################################
# start new
sub new {
my $class = shift;
my $self = {};
bless $self,$class;
my $status;
my $config = ConfigServer::Config->loadconfig();
my %config = $config->config();
my $ipv4reg = $config->ipv4reg;
my $ipv6reg = $config->ipv6reg;
$brd{"255.255.255.255"} = 1;
setlocale(LC_ALL, "POSIX");
if (-e $config{IP}) {
my ($childin, $childout);
my $pid = open3($childin, $childout, $childout, $config{IP}, "-oneline", "addr");
my @ifconfig = <$childout>;
waitpid ($pid, 0);
chomp @ifconfig;
foreach my $line (@ifconfig) {
if ($line =~ /^\d+:\s+([\w\.\-]+)/ ) {
$ifaces{$1} = 1;
}
if ($line =~ /inet.*?($ipv4reg)/) {
my ($ip,undef) = split(/\//,$1);
if (checkip(\$ip)) {
$ipv4{$ip} = 1;
}
}
if ($line =~ /brd\s+($ipv4reg)/) {
my ($ip,undef) = split(/\//,$1);
if (checkip(\$ip)) {
$brd{$ip} = 1;
}
}
if ($line =~ /inet6.*?($ipv6reg)/) {
my ($ip,undef) = split(/\//,$1);
$ip .= "/128";
if (checkip(\$ip)) {
$ipv6{$ip} = 1;
}
}
}
$status = 0;
}
elsif (-e $config{IFCONFIG}) {
my ($childin, $childout);
my $pid = open3($childin, $childout, $childout, $config{IFCONFIG});
my @ifconfig = <$childout>;
waitpid ($pid, 0);
chomp @ifconfig;
foreach my $line (@ifconfig) {
if ($line =~ /^([\w\.\-]+)/ ) {
$ifaces{$1} = 1;
}
if ($line =~ /inet.*?($ipv4reg)/) {
my ($ip,undef) = split(/\//,$1);
if (checkip(\$ip)) {
$ipv4{$ip} = 1;
}
}
if ($line =~ /Bcast:($ipv4reg)/) {
my ($ip,undef) = split(/\//,$1);
if (checkip(\$ip)) {
$brd{$ip} = 1;
}
}
if ($line =~ /inet6.*?($ipv6reg)/) {
my ($ip,undef) = split(/\//,$1);
$ip .= "/128";
if (checkip(\$ip)) {
$ipv6{$ip} = 1;
}
}
}
$status = 0;
}
else {
$status = 1;
}
if (-e "/var/cpanel/cpnat") {
open (my $NAT, "<", "/var/cpanel/cpnat");
flock ($NAT, LOCK_SH);
while (my $line = <$NAT>) {
chomp $line;
if ($line =~ /^(\#|\n|\r)/) {next}
my ($internal,$external) = split(/\s+/,$line);
if (checkip(\$internal) and checkip(\$external)) {
$ipv4{$external} = 1;
}
}
close ($NAT);
}
$self->{status} = $status;
return $self;
}
# end main
###############################################################################
# start ifaces
sub ifaces {
return %ifaces;
}
# end ifaces
###############################################################################
# start ipv4
sub ipv4 {
return %ipv4;
}
# end ipv4
###############################################################################
# start ipv6
sub ipv6 {
return %ipv6;
}
# end ipv6
###############################################################################
# start brd
sub brd {
return %brd;
}
# end brd
###############################################################################
1; ServerCheck.pm 0000644 00000233172 15103002075 0007307 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::ServerCheck;
use strict;
use lib '/usr/local/csf/lib';
use Fcntl qw(:DEFAULT :flock);
use File::Basename;
use IPC::Open3;
use ConfigServer::Slurp qw(slurp);
use ConfigServer::Sanity qw(sanity);;
use ConfigServer::Config;
use ConfigServer::GetIPs qw(getips);
use ConfigServer::CheckIP qw(checkip);
use ConfigServer::Service;
use ConfigServer::GetEthDev;
use Exporter qw(import);
our $VERSION = 1.05;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
my (%config, $cpconf, %daconfig, $cleanreg, $mypid, $childin, $childout,
$verbose, $cpurl, @processes, $total, $failures, $current, $DEBIAN,
$output, $sysinit, %g_ifaces, %g_ipv4, %g_ipv6);
my $ipv4reg = ConfigServer::Config->ipv4reg;
my $ipv6reg = ConfigServer::Config->ipv6reg;
use Exporter qw(import);
# end main
###############################################################################
# start report
sub report {
$verbose = shift;
my $config = ConfigServer::Config->loadconfig();
%config = $config->config();
$cleanreg = ConfigServer::Slurp->cleanreg;
$| = 1;
if (defined $ENV{WEBMIN_VAR} and defined $ENV{WEBMIN_CONFIG}) {
$config{GENERIC} = 1;
$config{DIRECTADMIN} = 0;
}
elsif (-e "/usr/local/cpanel/version") {
use lib "/usr/local/cpanel";
require Cpanel::Form;
import Cpanel::Form;
require Cpanel::Config;
import Cpanel::Config;
$cpconf = Cpanel::Config::loadcpconf();
}
elsif (-e "/usr/local/directadmin/conf/directadmin.conf") {
my ($childin, $childout);
my $mypid = open3($childin, $childout, $childout, "/usr/local/directadmin/directadmin", "c");
my @data = <$childout>;
waitpid ($mypid, 0);
chomp @data;
foreach my $line (@data) {
my ($name,$value) = split(/\=/,$line);
$daconfig{lc($name)} = $value;
}
$config{DIRECTADMIN} = 1;
}
elsif (-e "/etc/psa/psa.conf") {
$config{PLESK} = 1;
}
$failures = 0;
$total = 0;
if ($ENV{cp_security_token}) {$cpurl = $ENV{cp_security_token}}
$DEBIAN = 0;
if (-e "/etc/lsb-release" or -e "/etc/debian_version") {$DEBIAN = 1}
$sysinit = ConfigServer::Service::type();
if ($sysinit ne "systemd") {$sysinit = "init"}
opendir (PROCDIR, "/proc");
while (my $pid = readdir(PROCDIR)) {
if ($pid !~ /^\d+$/) {next}
push @processes, readlink("/proc/$pid/exe");
}
my $ethdev = ConfigServer::GetEthDev->new();
%g_ifaces = $ethdev->ifaces;
%g_ipv4 = $ethdev->ipv4;
%g_ipv6 = $ethdev->ipv6;
&startoutput;
&firewallcheck;
&servercheck;
&sshtelnetcheck;
unless ($config{DNSONLY} or $config{GENERIC}) {&mailcheck}
unless ($config{DNSONLY} or $config{GENERIC}) {&apachecheck}
unless ($config{DNSONLY} or $config{GENERIC}) {&phpcheck}
unless ($config{DNSONLY} or $config{GENERIC}) {&whmcheck}
if ($config{DIRECTADMIN}) {
&mailcheck;
&apachecheck;
&phpcheck;
&dacheck;
}
&servicescheck;
&endoutput;
return $output;
}
# end report
###############################################################################
# start startoutput
sub startoutput {
if ($config{THIS_UI} and !$config{GENERIC}) {
$output .= "
Note: Internal WHM links will not work within the csf Integrated UI
\n";
}
return;
}
# end startoutput
###############################################################################
# start addline
sub addline {
my $status = shift;
my $check = shift;
my $comment = shift;
$total++;
if ($status) {
$output .= "
\n";
$output .= "
$check
\n";
$output .= "
$comment
\n";
$output .= "
\n";
$failures ++;
$current++;
}
elsif ($verbose) {
$output .= "
\n";
$output .= "
$check
\n";
$output .= "
$comment
\n";
$output .= "
\n";
$current++;
}
return;
}
# end addline
###############################################################################
# start addtitle
sub addtitle {
my $title = shift;
if (defined $current and $current == 0) {
$output .= "
OK
\n";
}
$current = 0;
$output .= "
$title
\n";
return;
}
# end addtitle
###############################################################################
# start endoutput
sub endoutput {
if (defined $current and $current == 0) {
$output .= "
OK
\n";
}
$output .= "
\n";
my $gap = int(($total-3)/4);
my $score = ($total - $failures);
my $width = int ((400 / $total) * $score) - 4;
$output .= "
\n
\n\n";
$output .= "
Server Score: $score/$total* \n";
$output .= "
\n";
$output .= "
\n";
$output .= "\n";
$output .= " \n";
$output .= " \n";
$output .= " \n";
$output .= " $total (max) \n";
$output .= " \n";
$output .= "
\n";
$output .= "
\n";
$output .= "
\n";
$output .= "
\n";
$output .= "\n";
$output .= " \n";
$output .= " \n";
$output .= " $score (score) \n";
$output .= " \n";
$output .= "
\n";
$output .= "
\n";
$output .= "
* This scoring does not necessarily reflect the security of the server or the relative merits of each check
";
$output .= "
";
return;
}
# end endoutput
###############################################################################
# start firewallcheck
sub firewallcheck {
&addtitle("Firewall Check");
my $status = 0;
open (my $IN, "<", "/etc/csf/csf.conf");
flock ($IN, LOCK_SH);
my @config = <$IN>;
chomp @config;
foreach my $line (@config) {
if ($line =~ /^\#/) {next}
if ($line !~ /=/) {next}
my ($name,$value) = split (/=/,$line,2);
$name =~ s/\s//g;
if ($value =~ /\"(.*)\"/) {
$value = $1;
} else {
&error(__LINE__,"Invalid configuration line");
}
$config{$name} = $value;
}
$status = 0;
if (-e "/etc/csf/csf.disable") {$status = 1}
&addline($status,"csf enabled check","csf is currently disabled and should be enabled otherwise it is not functioning");
if (-x $config{IPTABLES}) {
my ($childin, $childout);
my $mypid = open3($childin, $childout, $childout, "$config{IPTABLES} $config{IPTABLESWAIT} -L INPUT -n");
my @iptstatus = <$childout>;
waitpid ($mypid, 0);
chomp @iptstatus;
if ($iptstatus[0] =~ /# Warning: iptables-legacy tables present/) {shift @iptstatus}
$status = 0;
if ($iptstatus[0] =~ /policy ACCEPT/) {$status = 1}
&addline($status,"csf running check","iptables is not configured. You need to start csf");
}
$status = 0;
if ($config{TESTING}) {$status = 1}
&addline($status,"TESTING mode check","csf is in TESTING mode. If the firewall is working set TESTING to \"0\" in the Firewall Configuration otherwise it will continue to be stopped");
$status = 0;
unless ($config{RESTRICT_SYSLOG}) {$status = 1}
&addline($status,"RESTRICT_SYSLOG option check","Due to issues with syslog/rsyslog you should consider enabling this option. See the Firewall Configuration (/etc/csf/csf.conf) for more information");
$status = 0;
unless ($config{AUTO_UPDATES}) {$status = 1}
&addline($status,"AUTO_UPDATES option check","To keep csf up to date and secure you should enable AUTO_UPDATES. You should also monitor our
blog ");
$status = 0;
unless ($config{LF_DAEMON}) {$status = 1}
&addline($status,"lfd enabled check","lfd is disabled in the csf configuration which limits the affectiveness of this application");
$status = 0;
if ($config{TCP_IN} =~ /\b3306\b/) {$status = 1}
&addline($status,"Incoming MySQL port check","The TCP incoming MySQL port (3306) is open. This can pose both a security and server abuse threat since not only can hackers attempt to break into MySQL, any user can host their SQL database on your server and access it from another host and so (ab)use your server resources");
unless ($config{DNSONLY} or $config{GENERIC}) {
unless ($config{VPS}) {
$status = 0;
unless ($config{SMTP_BLOCK}) {$status = 1}
&addline($status,"SMTP_BLOCK option check","This option will help prevent the most common form of spam abuse on a server that bypasses exim and sends spam directly out through port 25. Enabling this option will prevent any web script from sending out using socket connection, such scripts should use the exim or sendmail binary instead");
}
$status = 0;
unless ($config{LF_SCRIPT_ALERT}) {$status = 1}
&addline($status,"LF_SCRIPT_ALERT option check","This option will notify you when a large amount of email is sent from a particular script on the server, helping track down spam scripts");
}
$status = 0;
my @options = ("LF_SSHD","LF_FTPD","LF_SMTPAUTH","LF_POP3D","LF_IMAPD","LF_HTACCESS","LF_MODSEC","LF_CPANEL","LF_CPANEL_ALERT","SYSLOG_CHECK","RESTRICT_UI");
if ($config{GENERIC}) {@options = ("LF_SSHD","LF_FTPD","LF_SMTPAUTH","LF_POP3D","LF_IMAPD","LF_HTACCESS","LF_MODSEC","SYSLOG_CHECK","FASTSTART","RESTRICT_UI");}
if ($config{DNSONLY}) {@options = ("LF_SSHD","LF_CPANEL","SYSLOG_CHECK","FASTSTART","RESTRICT_UI")}
foreach my $option (@options) {
$status = 0;
unless ($config{$option}) {$status = 1}
&addline($status,"$option option check","This option helps prevent brute force attacks on your server services or overall server stability");
}
$status = 0;
unless ($config{LF_DIRWATCH}) {$status = 1}
&addline($status,"LF_DIRWATCH option check","This option will notify when a suspicious file is found in one of the common temp directories on the server");
$status = 0;
unless ($config{LF_INTEGRITY}) {$status = 1}
&addline($status,"LF_INTEGRITY option check","This option will notify when an executable in one of the common directories on the server changes in some way. This helps alert you to potential rootkit installation or server compromise");
$status = 0;
unless ($config{FASTSTART}) {$status = 1}
&addline($status,"FASTSTART option check","This option can dramatically improve the startup time of csf and the rule loading speed of lfd");
$status = 0;
if ($config{URLGET} == 1) {$status = 1}
&addline($status,"URLGET option check","This option determines which perl module is used to upgrade csf. It is recommended to set this to use LWP rather than HTTP::Tiny so that upgrades are performed over an SSL connection");
$status = 0;
if ($config{PT_USERKILL} == 1) {$status = 1}
&addline($status,"PT_USERKILL option check","This option should not normally be enabled as it can easily lead to legitimate processes being terminated, use csf.pignore instead");
unless ($config{DNSONLY} or $config{GENERIC}) {
$status = 0;
if ($config{PT_SKIP_HTTP}) {$status = 1}
&addline($status,"PT_SKIP_HTTP option check","This option disables checking of processes running under apache and can limit false-positives but may then miss running exploits");
}
$status = 0;
if (!$config{LF_IPSET} and !$config{VPS} and ($config{CC_DENY} or $config{CC_ALLOW} or $config{CC_ALLOW_FILTER} or $config{CC_ALLOW_PORTS} or $config{CC_DENY_PORTS})) {$status = 1}
&addline($status,"LF_IPSET option check","If support by your OS, you should install ipset and enable LF_IPSET when using Country Code (CC_*) filters");
unless ($config{DNSONLY} or $config{GENERIC}) {
$status = 0;
unless ($config{PT_ALL_USERS}) {$status = 1}
&addline($status,"PT_ALL_USERS option check","This option ensures that almost all Linux accounts are checked with Process Tracking, not just the cPanel ones");
}
sysopen (my $CONF, "/etc/csf/csf.conf", O_RDWR | O_CREAT);
flock ($CONF, LOCK_SH);
my @confdata = <$CONF>;
close ($CONF);
chomp @confdata;
foreach my $line (@confdata) {
if (($line !~ /^\#/) and ($line =~ /=/)) {
my ($start,$end) = split (/=/,$line,2);
my $name = $start;
$name =~ s/\s/\_/g;
if ($end =~ /\"(.*)\"/) {$end = $1}
my ($insane,$range,$default) = sanity($start,$end);
if ($insane) {
&addline(1,"$start sanity check","$start = $end. Recommended range: $range (Default: $default)");
}
}
}
return;
}
# end firewallcheck
###############################################################################
# start servercheck
sub servercheck {
&addtitle("Server Check");
my $status = 0;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("/tmp");
my $pmode = sprintf "%03o", $mode & oct("07777");
$status = 0;
if ($pmode != 1777) {$status = 1}
&addline($status,"Check /tmp permissions","/tmp should be chmod 1777");
$status = 0;
if (($uid != 0) or ($gid != 0)) {$status = 1}
&addline($status,"Check /tmp ownership","/tmp should be owned by root:root");
if (-d "/var/tmp") {
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("/var/tmp");
$pmode = sprintf "%04o", $mode & oct("07777");
$status = 0;
if ($pmode != 1777) {$status = 1}
&addline($status,"Check /var/tmp permissions","/var/tmp should be chmod 1777");
$status = 0;
if (($uid != 0) or ($gid != 0)) {$status = 1}
&addline($status,"Check /var/tmp ownership","/var/tmp should be owned by root:root");
}
if (-d "/usr/tmp") {
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("/usr/tmp");
$pmode = sprintf "%04o", $mode & oct("07777");
$status = 0;
if ($pmode != 1777) {$status = 1}
&addline($status,"Check /usr/tmp permissions","/usr/tmp should be chmod 1777");
$status = 0;
if (($uid != 0) or ($gid != 0)) {$status = 1}
&addline($status,"Check /usr/tmp ownership","/usr/tmp should be owned by root:root");
}
$status = 0;
if (&getportinfo(53)) {
my @files = ("/var/named/chroot/etc/named.conf","/etc/named.conf","/etc/bind/named.conf","/var/named/chroot/etc/bind/named.conf");
my @namedconf;
my @morefiles;
my $hit;
foreach my $file (@files) {
if (-e $file) {
$hit = 1;
open (my $IN, "<", "$file");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
if (my @ls = grep {$_ =~ /^\s*include\s+(.*)\;\s*$/i} @conf) {
foreach my $more (@ls) {
if ($more =~ /^\s*include\s+\"(.*)\"\s*\;\s*$/i) {push @morefiles, $1}
}
}
@namedconf = (@namedconf, @conf);
}
}
foreach my $file (@morefiles) {
if (-e $file) {
open (my $IN, "<", "$file");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
@namedconf = (@namedconf, @conf);
}
}
if ($hit) {
# if (my @ls = grep {$_ =~ /^\s*(recursion\s+no|allow-recursion)/} @namedconf) {$status = 0} else {$status = 1}
# &addline($status,"Check for DNS recursion restrictions","You have a local DNS server running but do not appear to have any recursion restrictions set. This is a security and performance risk and you should look at restricting recursive lookups to the local IP addresses only");
if (my @ls = grep {$_ =~ /^\s*(query-source\s[^\;]*53)/} @namedconf) {$status = 1} else {$status = 0}
&addline($status,"Check for DNS random query source port","ISC recommend that you do not configure BIND to use a static query port. You should remove/disable the query-source line that specifies port 53 from the named configuration files");
}
}
if (!$DEBIAN and $sysinit eq "init" and -x "/sbin/runlevel") {
$status = 0;
$mypid = open3($childin, $childout, $childout, "/sbin/runlevel");
my @conf = <$childout>;
waitpid ($mypid, 0);
chomp @conf;
my (undef,$runlevel) = split(/\s/,$conf[0]);
if ($runlevel != 3) {$status = 1}
&addline($status,"Check server runlevel","The servers runlevel is currently set to $runlevel. For a secure server environment you should only run the server at runlevel 3. You can fix this by editing /etc/inittab and changing the initdefault line to:
id:3:initdefault: and then rebooting the server");
}
$status = 0;
if ((-e "/var/spool/cron/nobody") and !(-z "/var/spool/cron/nobody")) {$status = 1}
&addline($status,"Check nobody cron","You have a nobody cron log file - you should check that this has not been created by an exploit");
$status = 0;
my ($isfedora, $isrh, $version, $conf) = 0;
if (-e "/etc/fedora-release") {
open (my $IN, "<", "/etc/fedora-release");
flock ($IN, LOCK_SH);
$conf = <$IN>;
close ($IN);
$isfedora = 1;
if ($conf =~ /release (\d+)/i) {$version = $1}
} elsif (-e "/etc/redhat-release") {
open (my $IN, "<", "/etc/redhat-release");
flock ($IN, LOCK_SH);
$conf = <$IN>;
close ($IN);
$isrh = 1;
if ($conf =~ /release (\d+)/i) {$version = $1}
}
chomp $conf;
if ($isrh or $isfedora) {
if (($isfedora and $version < 30) or ($isrh and $version < 6)) {$status = 1}
&addline($status,"Check Operating System support","You are running an OS -
$conf - that is no longer supported by the OS vendor, or is about to become obsolete. This means that you will be receiving no OS updates (i.e. application or security bug fixes) or kernel updates and should consider moving to an OS that is supported as soon as possible");
}
$status = 0;
if ($] < 5.008008) {
$status = 1;
} else {$status = 0}
&addline($status,"Check perl version","The version of perl (v$]) is out of date and you should upgrade it");
$status = 0;
while (my ($name,undef,$uid) = getpwent()) {
if (($uid == 0) and ($name ne "root")) {$status = 1}
}
&addline($status,"Check SUPERUSER accounts","You have accounts other than root set up with UID 0. This is a considerable security risk. You should use
su , or best of all
sudo for such access");
if (-e "/usr/local/cpanel/version" or $config{DIRECTADMIN}) {
$status = 0;
unless (-e "/etc/cxs/cxs.pl") {
$status = 1;
}
&addline($status,"Check for cxs","You should consider using
cxs to scan web script uploads and user accounts for exploits uploaded to the server");
$status = 0;
unless (-e "/etc/osm/osmd.pl") {
$status = 1;
}
&addline($status,"Check for osm","You should consider using
osm to provide protection from spammers exploiting the server");
}
unless ($config{IPV6}) {
$status = 0;
my $ipv6 = "";
foreach my $key (keys %g_ipv6) {
if ($ipv6) {$ipv6 .= ", "}
$ipv6 .= $key;
$status = 1;
}
if ($ipv6 eq "::1") {$ipv6 = ""; $status = 0}
&addline($status,"Check for IPv6","IPv6 appears to be enabled [
$ipv6 ]. If ip6tables is installed, you should enable the csf IPv6 firewall (IPV6 in csf.conf)");
}
if ($sysinit eq "init") {
$status = 1;
my $syslog = 0;
if (grep {$_ =~ /\/syslogd\s*/} @processes) {
$syslog = 1;
if (grep {$_ =~ /\/klogd$/} @processes) {$status = 0}
&addline($status,"Check for kernel logger","syslogd appears to be running, but not klogd which logs kernel firewall messages to syslog. You should ensure that klogd is running");
}
if (grep {$_ =~ /\/rsyslogd\s*/} @processes) {
$syslog = 1;
if (grep {$_ =~ /\/rklogd\s*/} @processes) {
$status = 0;
} else {
open (my $IN, "<", "/etc/rsyslog.conf");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
if (grep {$_ =~ /^\$ModLoad imklog/} @conf) {$status = 0}
}
&addline($status,"Check for kernel logger","rsyslogd appears to be running, but klog may not be loaded which logs kernel firewall messages to rsyslog. You should modify /etc/rsyslogd to load the klog module with:
\$ModLoad imklog Then restart rsyslog");
}
unless ($syslog) {
$status = 1;
&addline($status,"Check for syslog or rsyslog","Neither syslog nor rsyslog appear to be running");
}
}
$status = 0;
if (grep {$_ =~ /\/dhclient\s*/} @processes) {$status = 1}
&addline($status,"Check for dhclient","dhclient appears to be running which suggests that the server is obtaining an IP address via DHCP. This can pose a security risk. You should configure static IP addresses for all ethernet controllers");
unless ($config{VPS}) {
$status = 1;
open (my $IN, "<", "/proc/swaps");
flock ($IN, LOCK_SH);
my @swaps = <$IN>;
close ($IN);
if (scalar(@swaps) > 1) {$status = 0}
&addline($status,"Check for swap file","The server appears to have no swap file. This is usually considered a stability and performance risk. You should either add a swap partition, or
create one via a normal file on an existing partition ");
if (-e "/etc/redhat-release") {
open (my $IN, "<", "/etc/redhat-release");
flock ($IN, LOCK_SH);
$conf = <$IN>;
close ($IN);
chomp $conf;
if ($conf =~ /^CloudLinux/i) {
$status = 0;
if (-e "/usr/sbin/cagefsctl") {
} else {$status = 1}
&addline($status,"CloudLinux CageFS","CloudLinux
CageFS is not installed. This CloudLinux option greatly improves server security on we servers by separating user accounts into their own environment");
unless ($status) {
$status = 0;
$mypid = open3($childin, $childout, $childout, "/usr/sbin/cagefsctl","--cagefs-status");
my @conf = <$childout>;
waitpid ($mypid, 0);
chomp @conf;
if ($conf[0] !~ /^Enabled/) {$status = 1}
&addline($status,"CloudLinux CageFS Enabled","CloudLinux
CageFS is not enabled. This CloudLinux option greatly improves server security on we servers by separating user accounts into their own environment");
}
$status = 0;
open (my $ENFORCE_SYMLINKSIFOWNER, "<", "/proc/sys/fs/enforce_symlinksifowner");
flock ($ENFORCE_SYMLINKSIFOWNER, LOCK_SH);
$conf = <$ENFORCE_SYMLINKSIFOWNER>;
close ($ENFORCE_SYMLINKSIFOWNER);
chomp $conf;
if ($conf < 1) {$status = 1}
&addline($status,"CloudLinux Symlink Protection","CloudLinux
Symlink Protection is not configured. You should configure it in /etc/sysctl.conf to prevent symlink attacks on web servers");
$status = 0;
open (my $PROC_CAN_SEE_OTHER_UID, "<", "/proc/sys/fs/proc_can_see_other_uid");
flock ($PROC_CAN_SEE_OTHER_UID, LOCK_SH);
$conf = <$PROC_CAN_SEE_OTHER_UID>;
close ($PROC_CAN_SEE_OTHER_UID);
chomp $conf;
if ($conf > 0) {$status = 1}
&addline($status,"CloudLinux Virtualised /proc","CloudLinux
Virtualised /proc is not configured. You should configure it in /etc/sysctl.conf to prevent users accessing server resources that they do not need on web servers");
$status = 0;
open (my $USER_PTRACE, "<", "/proc/sys/kernel/user_ptrace");
flock ($USER_PTRACE, LOCK_SH);
$conf = <$USER_PTRACE>;
close ($USER_PTRACE);
chomp $conf;
if ($conf > 0) {$status = 1}
&addline($status,"CloudLinux Disable ptrace","CloudLinux
Disable ptrace is not configured. You should configure it in /etc/sysctl.conf to prevent users accessing server resources that they do not need on web servers");
}
}
}
return;
}
# end servercheck
###############################################################################
# start whmcheck
sub whmcheck {
my $status = 0;
&addtitle("WHM Settings Check");
$status = 0;
unless ($cpconf->{alwaysredirecttossl}) {$status = 1}
&addline($status,"Check cPanel login is SSL only","You should check
WHM > Tweak Settings > Choose the closest matched domain for which that the system has a valid certificate when redirecting from non-SSL to SSL URLs ");
$status = 0;
unless ($cpconf->{skipboxtrapper}) {$status = 1}
&addline($status,"Check boxtrapper is disabled","Having boxtrapper enabled can very easily lead to your server being listed in common RBLs and usually has the effect of increasing the overall spam load, not reducing it. You should disable it in
WHM > Tweak Settings > BoxTrapper Spam Trap ");
$status = 0;
if (-e "/var/cpanel/greylist/enabled") {$status = 1}
&addline($status,"Check GreyListing is disabled","Using GreyListing can and will lead to lost legitimate emails. It can also cause significant problems with \"password verification\" systems. See
here for more information");
if (defined $cpconf->{popbeforesmtp}) {
$status = 0;
if ($cpconf->{popbeforesmtp}) {$status = 1}
&addline($status,"Check popbeforesmtp is disabled","Using pop before smtp is considered a security risk, SMTP AUTH should be used instead. You should disable it in
WHM > Tweak Settings > Allow users to relay mail if they use an IP address through which someone has validated an IMAP or POP3 login ");
}
$status = 0;
unless ($cpconf->{maxemailsperhour}) {$status = 1}
&addline($status,"Check max emails per hour is set","To limit the damage that can be caused by potential spammers on the server you should set a value for
WHM > Tweak Settings > Max hourly emails per domain ");
$status = 0;
if ($cpconf->{resetpass}) {$status = 1}
&addline($status,"Check Reset Password for cPanel accounts","This poses a potential security risk and should be disabled unless necessary in
WHM > Tweak Settings > Reset Password for cPanel accounts ");
$status = 0;
if ($cpconf->{resetpass_sub}) {$status = 1}
&addline($status,"Check Reset Password for Subaccounts","This poses a potential security risk and should be disabled unless necessary in
WHM > Tweak Settings > Reset Password for Subaccounts ");
foreach my $openid (glob "/var/cpanel/authn/openid_connect/*") {
open (my $IN, "<", $openid);
flock ($IN, LOCK_SH);
my $line = <$IN>;
close ($IN);
chomp $line;
my ($file, $filedir) = fileparse($openid);
$status = 0;
if ($line =~ /\{"cpanelid"/) {$status = 1}
&addline($status,"Check cPanelID for $file","You should only enable this option if you are going to use it otherwise it is a potential security risk in
WHM > Manage External Authentications > $file ");
}
unless ($cpconf->{nativessl} eq undef) {
$status = 0;
unless ($cpconf->{nativessl}) {$status = 1}
&addline($status,"Check whether native cPanel SSL is enabled","You should enable this option so that lfd tracks SSL cpanel login attempts
WHM > Tweak Settings > Use native SSL support if possible, negating need for Stunnel ");
}
$status = 0;
my $cc = '/usr/bin/cc';
while ( readlink($cc) ) {
$cc = readlink($cc);
}
if ( $cc !~ /^\// ) { $cc = '/usr/bin/' . $cc; }
my $mode = substr( sprintf( "%o", ( ( stat($cc) )[2] ) ), 2, 4 );
if ( $mode > 750 ) {$status = 1}
&addline($status,"Check compilers","You should disable compilers
WHM > Security Center > Compilers Access ");
if (-e "/etc/pure-ftpd.conf" and ($cpconf->{ftpserver} eq "pure-ftpd") and !(-e "/etc/ftpddisable")) {
$status = 0;
open (my $IN, "<", "/etc/pure-ftpd.conf");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
if (my @ls = grep {$_ =~ /^\s*NoAnonymous\s*(no|off)/i} @conf) {$status = 1}
&addline($status,"Check Anonymous FTP Logins","Used as an attack vector by hackers and should be disabled unless actively used
WHM > FTP Server Configuration > Allow Anonymous Logins > No ");
$status = 0;
if (my @ls = grep {$_ =~ /^\s*AnonymousCantUpload\s*(no|off)/i} @conf) {$status = 1}
&addline($status,"Check Anonymous FTP Uploads","Used as an attack vector by hackers and should be disabled unless actively used
WHM > FTP Server Configuration > Allow Anonymous Uploads > No ");
$status = 0;
my $ciphers;
my $error;
if (my @ls = grep {$_ =~ /^\s*TLSCipherSuite/} @conf) {
if ($ls[0] =~ /TLSCipherSuite\s+(.*)$/) {$ciphers = $1}
$ciphers =~ s/\s*|\"|\'//g;
if ($ciphers eq "") {
$status = 1;
}
elsif ($ciphers !~ /SSL/) {
$status = 0
} else {
if (-x "/usr/bin/openssl") {
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/bin/openssl","ciphers","-v",$ciphers);
my @openssl = <$childout>;
waitpid ($cmdpid, 0);
chomp @openssl;
if (my @ls = grep {$_ =~ /error/i} @openssl) {$error = $openssl[0]; $status=2}
if (my @ls = grep {$_ =~ /SSLv2/} @openssl) {$status = 1}
}
}
} else {$status = 1}
if ($status == 2) {
&addline($status,"Check pure-ftpd weak SSL/TLS Ciphers (TLSCipherSuite)","Unable to determine cipher list for [$ciphers] from openssl:
[$error]");
}
&addline($status,"Check pure-ftpd weak SSL/TLS Ciphers (TLSCipherSuite)","Cipher list [$ciphers]. Due to weaknesses in the SSLv2 cipher you should disable SSLv2 in
WHM > FTP Server Configuration > TLS Cipher Suite > Remove +SSLv2 or Add -SSLv2 ");
$status = 0;
unless (-e "/var/cpanel/conf/pureftpd/root_password_disabled") {$status = 1}
&addline($status,"Check FTP Logins with Root Password","Allowing root login via FTP is a considerable security risk and should be disabled
WHM > FTP Server Configuration > Allow Logins with Root Password > No ");
}
if (-e "/var/cpanel/conf/proftpd/main" and ($cpconf->{ftpserver} eq "proftpd") and !(-e "/etc/ftpddisable")) {
$status = 0;
open (my $IN, "<", "/var/cpanel/conf/proftpd/main");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
if (my @ls = grep {$_ =~ /^cPanelAnonymousAccessAllowed: 'yes'/i} @conf) {$status = 1}
&addline($status,"Check Anonymous FTP Logins","Used as an attack vector by hackers and should be disabled unless actively used
WHM > FTP Server Configuration > Allow Anonymous Logins > No ");
$status = 0;
my $ciphers;
my $error;
if (my @ls = grep {$_ =~ /^\s*TLSCipherSuite/} @conf) {
if ($ls[0] =~ /TLSCipherSuite\:\s+(.*)$/) {$ciphers = $1}
$ciphers =~ s/\s*|\"|\'//g;
if ($ciphers eq "") {
$status = 1;
} else {
if (-e "/usr/bin/openssl") {
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/bin/openssl","ciphers","-v",$ciphers);
my @openssl = <$childout>;
waitpid ($cmdpid, 0);
chomp @openssl;
if (my @ls = grep {$_ =~ /error/i} @openssl) {$error = $openssl[0]; $status=2}
if (my @ls = grep {$_ =~ /SSLv2/} @openssl) {$status = 1}
}
}
} else {$status = 1}
if ($status == 2) {
&addline($status,"Check proftpd weak SSL/TLS Ciphers (TLSCipherSuite)","Unable to determine cipher list for [$ciphers] from openssl:
[$error]");
}
&addline($status,"Check proftpd weak SSL/TLS Ciphers (TLSCipherSuite)","Cipher list [$ciphers]. Due to weaknesses in the SSLv2 cipher you should disable SSLv2 in
WHM > FTP Server Configuration > TLS Cipher Suite > Remove +SSLv2 or Add -SSLv2 ");
if ($config{VPS}) {
$status = 0;
open (my $IN, "<", "/etc/proftpd.conf");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
if (my @ls = grep {$_ =~ /^\s*PassivePorts\s+(\d+)\s+(\d+)/} @conf) {
if ($config{TCP_IN} !~ /\b$1:$2\b/) {$status = 1}
} else {$status = 1}
&addline($status,"Check VPS FTP PASV hole","Since the Virtuozzo VPS iptables ip_conntrack_ftp kernel module is currently broken you have to open a PASV port hole in iptables for incoming FTP connections to work correctly. See the csf readme.txt under 'A note about FTP Connection Issues' on how to do this");
}
}
$status = 0;
if ($cpconf->{allowremotedomains}) {$status = 1}
&addline($status,"Check allow remote domains","User can park domains that resolve to other servers on this server. You should disable WHM >
Tweak Settings > Allow Remote Domains");
$status = 0;
unless ($cpconf->{blockcommondomains}) {$status = 1}
&addline($status,"Check block common domains","User can park common domain names on this server. You should disable WHM >
Tweak Settings > Prevent cPanel users from creating specific domains");
$status = 0;
if ($cpconf->{allowparkonothers}) {$status = 1}
&addline($status,"Check allow park domains","User can park/addon domains that belong to other users on this server. You should disable WHM >
Tweak Settings > Allow cPanel users to create subdomains across accounts");
$status = 0;
if ($cpconf->{proxysubdomains}) {$status = 1}
&addline($status,"Check proxy subdomains","This option can mask a users real IP address and hinder security. You should disable WHM >
Tweak Settings > Service subdomains");
$status = 1;
if ($cpconf->{cpaddons_notify_owner}) {$status = 0}
&addline($status,"Check cPAddons update email to resellers","You should have cPAddons email users if cPAddon installations require updating WHM >
Tweak Settings > Notify reseller of cPAddons Site Software installations");
$status = 1;
if ($cpconf->{cpaddons_notify_root}) {$status = 0}
&addline($status,"Check cPAddons update email to root","You should have cPAddons email root if cPAddon installations require updating WHM >
Tweak Settings > Notify root of cPAddons Site Software installations");
if (-e "/etc/cpupdate.conf") {
open (my $IN, "<", "/etc/cpupdate.conf");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
$status = 0;
if (my @ls = grep {$_ =~ /^CPANEL=(edge|beta|nightly)/i} @conf) {$status = 1}
&addline($status,"Check cPanel tree","Running EDGE/BETA on a production server could lead to server instability");
$status = 1;
if (my @ls = grep {$_ =~ /^UPDATES=daily/i} @conf) {$status = 0}
&addline($status,"Check cPanel updates","You have cPanel updating disabled, this can pose a security and stability risk.
WHM > Update Preferences > Enabled Automatic Updates ");
# $status = 0;
# if (grep {$_ =~ /^SYSUP=/i} @conf) {$status = 1}
# if (grep {$_ =~ /^SYSUP=daily/i} @conf) {$status = 0}
# &addline($status,"Check package updates","You have package updating disabled, this can pose a security and stability risk.
WHM > Update Config >cPanel Package Updates > Automatic ");
# $status = 1;
# if (my @ls = grep {$_ =~ /^RPMUP=daily/i} @conf) {$status = 0}
# &addline($status,"Check security updates","You have security updating disabled, this can pose a security and stability risk.
WHM > Update Config >Operating System Package Updates > Automatic ");
} else {&addline(1,"Check cPanel updates","Unable to find /etc/cpupdate.conf");}
$status = 1;
if ($cpconf->{account_login_access} eq "user") {$status = 0}
&addline($status,"Check accounts that can access a cPanel user","You should consider setting this option to \"user\" after use. WHM >
Tweak Settings > Accounts that can access a cPanel user account");
unless ($status) {
$status = 0;
open (my $IN, "<", "/usr/local/cpanel/3rdparty/etc/php.ini");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
if (my @ls = grep {$_ =~ /^\s*register_globals\s*=\s*on/i} @conf) {$status = 1}
&addline($status,"Check cPanel php.ini file for register_globals","PHP register_globals is considered a high security risk. It is currently enabled in /usr/local/cpanel/3rdparty/etc/php.ini and should be disabled (disabling may break 3rd party PHP cPanel apps)");
}
$status = 0;
if ($cpconf->{emailpasswords}) {$status = 1}
&addline($status,"Check cPanel passwords in email","You should not send passwords out in plain text emails. You should disable WHM >
Tweak Settings > Send passwords when creating a new account");
$status = 0;
if ($cpconf->{coredump}) {$status = 1}
&addline($status,"Check core dumps","You should disable WHM >
Tweak Settings > Allow WHM/Webmail/cPanel services to create core dumps for debugging purposes");
$status = 1;
if ($cpconf->{cookieipvalidation} eq "strict") {$status = 0}
&addline($status,"Check Cookie IP Validation","You should enable strict Cookie IP validation in WHM >
Tweak Settings > Cookie IP validation");
$status = 1;
if ($cpconf->{use_apache_md5_for_htaccess}) {$status = 0}
&addline($status,"Check MD5 passwords with Apache","You should enable WHM >
Tweak Settings > Use MD5 passwords with Apache");
$status = 1;
if ($cpconf->{referrerblanksafety}) {$status = 0}
&addline($status,"Check Referrer Blank Security","You should enable WHM >
Tweak Settings > Blank referrer safety check");
$status = 1;
if ($cpconf->{referrersafety}) {$status = 0}
&addline($status,"Check Referrer Security","You should enable WHM >
Tweak Settings > Referrer safety check");
$status = 1;
if ($cpconf->{skiphttpauth}) {$status = 0}
&addline($status,"Check HTTP Authentication","You should disable skiphttpauth in /var/cpanel/cpanel.config");
$status = 0;
if ($cpconf->{skipparentcheck}) {$status = 1}
&addline($status,"Check Parent Security","You should disable WHM >
Tweak Settings > Allow other applications to run the cPanel and admin binaries");
$status = 0;
if ($cpconf->{"cpsrvd-domainlookup"}) {$status = 1}
&addline($status,"Check Domain Lookup Security","You should disable WHM >
Tweak Settings > cpsrvd username domain lookup");
$status = 1;
if ($cpconf->{"cgihidepass"}) {$status = 0}
&addline($status,"Check Password ENV variable","You should enable WHM >
Tweak Settings > Hide login password from cgi scripts ");
$status = 0;
if (-e "/var/cpanel/smtpgidonlytweak") {$status = 1}
&addline($status,"Check SMTP Restrictions","This option in WHM will not function when running csf. You should disable WHM > Security Center >
SMTP Restrictions and use the csf configuration option SMTP_BLOCK instead");
if (-e "/etc/wwwacct.conf") {
$status = 1;
open (my $IN, "<", "/etc/wwwacct.conf");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
my %ips;
foreach my $key (keys %g_ipv4) {
$ips{$key} = 1;
}
my $nameservers;
my $local = 0;
my $allns = 0;
foreach my $line (@conf) {
if ($line =~ /^NS(\d)?\s+(.*)\s*$/) {
my $ns = $2;
$ns =~ s/\s//g;
if ($ns) {
$allns++;
$nameservers .= "
$ns \n";
my $ip;
if (checkip(\$ns)) {
$ip = $ns;
if ($ips{$ip}) {$local++}
} else {
my @ips = getips($ns);
unless (scalar @ips) {&addline(1,"Check nameservers","Unable to resolve nameserver [$ns]")}
my $hit = 0;
foreach my $oip (@ips) {
if ($ips{$oip}) {$hit = 1}
}
if ($hit) {$local++}
}
}
}
}
if ($local < $allns) {$status = 0}
&addline($status,"Check nameservers","At least one of the configured nameservers:
\n$nameservers should be located in a topologically and geographically dispersed location on the Internet - See RFC 2182 (Section 3.1)");
}
if (-e "/usr/local/cpanel/bin/register_appconfig") {
$status = 0;
if ($cpconf->{permit_unregistered_apps_as_reseller}) {$status = 1}
&addline($status,"Check AppConfig Required","You should disable WHM >
Tweak Settings > Allow apps that have not registered with AppConfig to be run when logged in as a reseller in WHM");
$status = 0;
if ($cpconf->{permit_unregistered_apps_as_root}) {$status = 1}
&addline($status,"Check AppConfig as root","You should disable WHM >
Tweak Settings > Allow apps that have not registered with AppConfig to be run when logged in as root or a reseller with the \"all\" ACL in WHM");
$status = 0;
if ($cpconf->{permit_appconfig_entries_without_acls}) {$status = 1}
&addline($status,"Check AppConfig ACLs","You should disable WHM >
Tweak Settings > Allow WHM apps registered with AppConfig to be executed even if a Required ACLs list has not been defined");
$status = 0;
if ($cpconf->{permit_appconfig_entries_without_features}) {$status = 1}
&addline($status,"Check AppConfig Feature List","You should disable WHM >
Tweak Settings > Allow cPanel and Webmail apps registered with AppConfig to be executed even if a Required Features list has not been defined");
}
$status = 0;
if ($cpconf->{"disable-security-tokens"}) {$status = 1}
&addline($status,"Check Security Tokens","Security Tokens should not be disabled as without them security of WHM/cPanel is compromised. The setting disable-security-tokens=0 should be set in /var/cpanel/cpanel.config");
return;
}
# end whmcheck
###############################################################################
# start dacheck
sub dacheck {
my $status = 0;
&addtitle("DirectAdmin Settings Check");
$status = 0;
unless ($daconfig{ssl}) {$status = 1}
&addline($status,"Check DirectAdmin login is SSL only","You should enable SSL only login to
DirectAdmin ");
if (($daconfig{ftpconfig} =~ /proftpd.conf/) and ($daconfig{pureftp} != 1)) {
$status = 0;
open (my $IN, "<", $daconfig{ftpconfig});
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
my $ciphers;
my $error;
if (my @ls = grep {$_ =~ /^\s*TLSCipherSuite/} @conf) {
if ($ls[0] =~ /TLSCipherSuite\s+(.*)$/) {$ciphers = $1}
$ciphers =~ s/\s*|\"|\'//g;
if ($ciphers eq "") {
$status = 1;
} else {
if (-e "/usr/bin/openssl") {
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/bin/openssl","ciphers","-v",$ciphers);
my @openssl = <$childout>;
waitpid ($cmdpid, 0);
chomp @openssl;
if (my @ls = grep {$_ =~ /error/i} @openssl) {$error = $openssl[0]; $status=2}
if (my @ls = grep {$_ =~ /SSLv2/} @openssl) {$status = 1}
}
}
} else {$status = 1}
if ($status == 2) {
&addline($status,"Check proftpd weak SSL/TLS Ciphers (TLSCipherSuite)","Unable to determine cipher list for [$ciphers] from openssl:
[$error]");
}
&addline($status,"Check proftpd weak SSL/TLS Ciphers (TLSCipherSuite)","Cipher list [$ciphers]. Due to weaknesses in the SSLv2 cipher you should add a TLSCipherSuite with SSLv2 disabled in $daconfig{ftpconfig}. For example,
<IfModule mod_tls.c> TLSCipherSuite HIGH </IfModule> container ");
if ($config{VPS}) {
$status = 0;
if (my @ls = grep {$_ =~ /^\s*PassivePorts\s+(\d+)\s+(\d+)/} @conf) {
if ($config{TCP_IN} !~ /\b$1:$2\b/) {$status = 1}
} else {$status = 1}
&addline($status,"Check VPS FTP PASV hole","Since the Virtuozzo VPS iptables ip_conntrack_ftp kernel module is currently broken you have to open a PASV port hole in iptables for incoming FTP connections to work correctly. See the csf readme.txt under 'A note about FTP Connection Issues' on how to do this");
}
}
$status = 1;
my %ips;
foreach my $key (keys %g_ipv4) {
$ips{$key} = 1;
}
my $nameservers;
for (my $x = 1; $x < 3; $x++) {
my $ns = $daconfig{"ns$x"};
$ns =~ s/\s//g;
if ($ns) {
$nameservers .= "
$ns \n";
my $ip;
if ($ns =~ /\d+\.\d+\.\d+\.d+/) {
$ip = $ns;
} else {
eval {
local $SIG{__DIE__} = undef;
local $SIG{'ALRM'} = sub {die};
alarm(5);
$ip = gethostbyname($ns);
$ip = inet_ntoa($ip);
alarm(0);
};
alarm(0);
unless ($ip) {&addline(1,"Check nameservers","Unable to resolve nameserver [$ns] within 5 seconds")}
}
if ($ip) {
unless ($ips{$ip}) {$status = 0}
}
}
}
&addline($status,"Check nameservers","At least one of the configured nameservers:
\n$nameservers should be located in a topologically and geographically dispersed location on the Internet - See RFC 2182 (Section 3.1)");
return;
}
# end dacheck
###############################################################################
# start mailcheck
sub mailcheck {
&addtitle("Mail Check");
my $status = 0;
unless ($config{DIRECTADMIN}) {
if (-e "/root/.forward") {
if (-z "/root/.forward") {$status = 1}
} else {$status = 1}
&addline($status,"Check root forwarder","The root account should have a forwarder set so that you receive essential email from your server");
}
if (-e "/etc/exim.conf" and -x "/usr/sbin/exim") {
$status = 0;
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/sbin/exim","-bP");
my @eximconf = <$childout>;
waitpid ($cmdpid, 0);
chomp @eximconf;
if (my @ls = grep {$_ =~ /^\s*log_selector/} @eximconf) {
if (($ls[0] !~ /\+all/) and ($ls[0] !~ /\+arguments/) and ($ls[0] !~ /\+arguments/)) {$status = 1}
} else {$status = 1}
if ($config{DIRECTADMIN}) {
&addline($status,"Check exim for extended logging (log_selector)","You should enable extended exim logging to enable easier tracking potential outgoing spam issues. Add:
log_selector = +arguments +subject +received_recipients to /etc/exim.conf");
} else {
&addline($status,"Check exim for extended logging (log_selector)","You should enable extended exim logging to enable easier tracking potential outgoing spam issues. Add:
log_selector = +arguments +subject +received_recipients in WHM >
Exim Configuration Manager > Advanced Editor > log_selector");
}
$status = 0;
my $ciphers;
my $error;
if (my @ls = grep {$_ =~ /^\s*tls_require_ciphers/} @eximconf) {
(undef,$ciphers) = split(/\=/,$ls[0]);
$ciphers =~ s/\s*|\"|\'//g;
if ($ciphers eq "") {
$status = 1;
} else {
if (-x "/usr/bin/openssl") {
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/bin/openssl","ciphers","-v",$ciphers);
my @openssl = <$childout>;
waitpid ($cmdpid, 0);
chomp @openssl;
if (my @ls = grep {$_ =~ /error/i} @openssl) {$error = $openssl[0]; $status=2}
if (my @ls = grep {$_ =~ /SSLv2/} @openssl) {$status = 1}
}
}
} else {$status = 1}
if ($status == 2) {
&addline($status,"Check exim weak SSL/TLS Ciphers (tls_require_ciphers)","Unable to determine cipher list for [$ciphers] from openssl:
[$error]");
}
if ($config{DIRECTADMIN}) {
&addline($status,"Check exim weak SSL/TLS Ciphers (tls_require_ciphers)","Cipher list [$ciphers]. Due to weaknesses in the SSLv2 cipher you should edit /etc/exim.conf and set tls_require_ciphers to explicitly exclude it. For example:
tls_require_ciphers=ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP ");
} else {
&addline($status,"Check exim weak SSL/TLS Ciphers (tls_require_ciphers)","Cipher list [$ciphers]. Due to weaknesses in the SSLv2 cipher you should disable WHM >
Exim Configuration Manager > Allow weak ssl/tls ciphers to be used, and also ensure tls_require_ciphers in /etc/exim.conf does not allow SSLv2 as openssl currently shows that it does");
}
} else {&addline(1,"Check exim configuration","Unable to find /etc/exim.conf and/or /usr/sbin/exim");}
if (-e "/etc/exim.conf.localopts") {
$status = 0;
open (my $IN, "<", "/etc/exim.conf.localopts");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
if (my @ls = grep {$_ =~ /require_secure_auth=0/i} @conf) {$status = 1}
&addline($status,"Check exim for secure authentication","You should require clients to connect with SSL or issue the STARTTLS command before they are allowed to authenticate with the server, otherwise passwords may be sent in plain text
in WHM >
Exim Configuration Manager ");
}
if ($config{DIRECTADMIN}) {
if (-e "/etc/dovecot.conf" and ($daconfig{dovecot})) {
$status = 0;
open (my $IN, "<", "/etc/dovecot.conf");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
my @morefiles;
if (my @ls = grep {$_ =~ /^\s*\!\s*include(_try)?\s+(.*)\s*$/i} @conf) {
foreach my $more (@ls) {
if ($more =~ /^\s*\!\s*include(_try)?\s+(.*)\s*$/i) {
my $conf = $2;
if ($conf !~ /^\//) {$conf = "/etc/dovecot/".$conf}
push @morefiles, $conf;
}
}
}
foreach my $file (@morefiles) {
if (-e $file) {
open (my $IN, "<", "$file");
flock ($IN, LOCK_SH);
my @moreconf = <$IN>;
close ($IN);
chomp @conf;
@conf = (@conf, @moreconf);
}
}
my $ciphers;
my $error;
if (my @ls = grep {$_ =~ /^ssl_cipher_list/} @conf) {
(undef,$ciphers) = split(/\=/,$ls[0]);
$ciphers =~ s/\s*|\"|\'//g;
if ($ciphers eq "") {
$status = 1;
} else {
if (-x "/usr/bin/openssl") {
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/bin/openssl","ciphers","-v",$ciphers);
my @openssl = <$childout>;
waitpid ($cmdpid, 0);
chomp @openssl;
if (my @ls = grep {$_ =~ /error/i} @openssl) {$error = $openssl[0]; $status=2}
if (my @ls = grep {$_ =~ /SSLv2/} @openssl) {$status = 1}
}
}
} else {$status = 1}
if ($status == 2) {
&addline($status,"Check dovecot weak SSL/TLS Ciphers (ssl_cipher_list)","Unable to determine cipher list for [$ciphers] from openssl:
[$error]");
}
&addline($status,"Check dovecot weak SSL/TLS Ciphers (ssl_cipher_list)","Cipher list [$ciphers]. Due to weaknesses in the SSLv2 cipher you should /etc/dovecot.conf and set ssl_cipher_list to explicitly exclude it. For example:
ssl_cipher_list = ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:-LOW:-SSLv2:-EXP ");
}
} else {
if (-e "/etc/dovecot/dovecot.conf" and ($cpconf->{mailserver} eq "dovecot")) {
$status = 0;
open (my $IN, "<", "/etc/dovecot/dovecot.conf");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
my @morefiles;
if (my @ls = grep {$_ =~ /^\s*\!?include(_try)?\s+(.*)\s*$/i} @conf) {
foreach my $more (@ls) {
if ($more =~ /^\s*\!?include(_try)?\s+(.*)\s*$/i) {push @morefiles, $2}
}
}
foreach my $file (@morefiles) {
if (-e $file) {
open (my $IN, "<", "$file");
flock ($IN, LOCK_SH);
my @moreconf = <$IN>;
close ($IN);
chomp @conf;
@conf = (@conf, @moreconf);
}
}
$status = 0;
my $ciphers;
my $error;
if (my @ls = grep {$_ =~ /^ssl_cipher_list/} @conf) {
(undef,$ciphers) = split(/\=/,$ls[0]);
$ciphers =~ s/\s*|\"|\'//g;
if ($ciphers eq "") {
$status = 1;
} else {
if (-x "/usr/bin/openssl") {
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/bin/openssl","ciphers","-v",$ciphers);
my @openssl = <$childout>;
waitpid ($cmdpid, 0);
chomp @openssl;
if (my @ls = grep {$_ =~ /error/i} @openssl) {$error = $openssl[0]; $status=2}
if (my @ls = grep {$_ =~ /SSLv2/} @openssl) {$status = 1}
}
}
} else {$status = 1}
if ($status == 2) {
&addline($status,"Check dovecot weak SSL/TLS Ciphers (ssl_cipher_list)","Unable to determine cipher list for [$ciphers] from openssl:
[$error]");
}
&addline($status,"Check dovecot weak SSL/TLS Ciphers (ssl_cipher_list)","Cipher list [$ciphers]. Due to weaknesses in the SSLv2 cipher you should disable SSLv2 in
WHM > Mailserver Configuration > SSL Cipher List > Remove +SSLv2 or Add -SSLv2 ");
}
if (-e "/usr/lib/courier-imap/etc/imapd-ssl" and ($cpconf->{mailserver} eq "courier")) {
$status = 0;
open (my $IN, "<", "/usr/lib/courier-imap/etc/imapd-ssl");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
$status = 0;
my $ciphers;
my $error;
if (my @ls = grep {$_ =~ /^TLS_CIPHER_LIST/} @conf) {
(undef,$ciphers) = split(/\=/,$ls[0]);
$ciphers =~ s/\s*|\"|\'//g;
if ($ciphers eq "") {
$status = 1;
} else {
if (-x "/usr/bin/openssl") {
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/bin/openssl","ciphers","-v",$ciphers);
my @openssl = <$childout>;
waitpid ($cmdpid, 0);
chomp @openssl;
if (my @ls = grep {$_ =~ /error/i} @openssl) {$error = $openssl[0]; $status=2}
if (my @ls = grep {$_ =~ /SSLv2/} @openssl) {$status = 1}
}
}
} else {$status = 1}
if ($status == 2) {
&addline($status,"Check Courier IMAP weak SSL/TLS Ciphers (TLS_CIPHER_LIST)","Unable to determine cipher list for [$ciphers] from openssl:
[$error]");
}
&addline($status,"Check Courier IMAP weak SSL/TLS Ciphers (TLS_CIPHER_LIST)","Cipher list [$ciphers]. Due to weaknesses in the SSLv2 cipher you should disable SSLv2 in
WHM > Mailserver Configuration > IMAP TLS/SSL Cipher List > Remove +SSLv2 or Add -SSLv2 ");
}
if (-e "/usr/lib/courier-imap/etc/pop3d-ssl" and ($cpconf->{mailserver} eq "courier")) {
$status = 0;
open (my $IN, "<", "/usr/lib/courier-imap/etc/pop3d-ssl");
flock ($IN, LOCK_SH);
my @conf = <$IN>;
close ($IN);
chomp @conf;
$status = 0;
my $ciphers;
my $error;
if (my @ls = grep {$_ =~ /^TLS_CIPHER_LIST/} @conf) {
(undef,$ciphers) = split(/\=/,$ls[0]);
$ciphers =~ s/\s*|\"|\'//g;
if ($ciphers eq "") {
$status = 1;
} else {
if (-x "/usr/bin/openssl") {
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/bin/openssl","ciphers","-v",$ciphers);
my @openssl = <$childout>;
waitpid ($cmdpid, 0);
chomp @openssl;
if (my @ls = grep {$_ =~ /error/i} @openssl) {$error = $openssl[0]; $status=2}
if (my @ls = grep {$_ =~ /SSLv2/} @openssl) {$status = 1}
}
}
} else {$status = 1}
if ($status == 2) {
&addline($status,"Check Courier POP3D weak SSL/TLS Ciphers (TLS_CIPHER_LIST)","Unable to determine cipher list for [$ciphers] from openssl:
[$error]");
}
&addline($status,"Check Courier POP3D weak SSL/TLS Ciphers (TLS_CIPHER_LIST)","Cipher list [$ciphers]. Due to weaknesses in the SSLv2 cipher you should disable SSLv2 in
WHM > Mailserver Configuration > POP3 TLS/SSL Cipher List > Remove +SSLv2 or Add -SSLv2 ");
}
}
return;
}
# end mailcheck
###############################################################################
# start phpcheck
sub phpcheck {
&addtitle("PHP Check");
my %phpbinaries;
my %phpinis;
if (-e "/usr/local/cpanel/version" and -e "/etc/cpanel/ea4/is_ea4") {
foreach my $phpdir (glob("/opt/cpanel/ea-*")) {
if (-e "${phpdir}/root/usr/bin/php") {$phpbinaries{"${phpdir}/root/usr/bin/php"} = 1}
}
}
elsif ($config{DIRECTADMIN}) {
foreach my $phpdir (glob("/usr/local/php*")) {
if (-e "${phpdir}/bin/php") {$phpbinaries{"${phpdir}/bin/php"} = 1}
}
}
elsif (-e "/usr/local/bin/php") {$phpbinaries{"/usr/local/bin/php"} = 1}
elsif (-e "/usr/bin/php") {$phpbinaries{"/usr/bin/php"} = 1}
if (-e "/opt/alt/alt-php-config") {
foreach my $phpdir (glob("/opt/alt/php*")) {
if (-e "${phpdir}/usr/bin/php") {$phpbinaries{"${phpdir}/usr/bin/php"} = 1}
}
}
if (scalar(keys %phpbinaries) == 0) {
&addline(1,"PHP Binary","PHP binary not found or not executable");
return;
}
foreach my $phpbin (keys %phpbinaries) {
if ($phpbin =~ /php44/) {$phpinis{"/opt/alt/php44/etc/php.ini"} = $phpbin}
elsif ($phpbin =~ /php51/) {$phpinis{"/opt/alt/php51/etc/php.ini"} = $phpbin}
else {
my ($childin, $childout);
my $mypid = open3($childin, $childout, $childout, $phpbin,"-d","zlib.output_compression=Off","--ini");
my @conf = <$childout>;
waitpid ($mypid, 0);
chomp @conf;
foreach my $line (@conf) {
if ($line =~ /^Loaded Configuration File:\s*(\S+)$/) {$phpinis{$1} = $phpbin}
}
}
}
my %phpconf;
foreach my $phpini (sort keys %phpinis) {
my $phpbin = $phpinis{$phpini};
my $status = 0;
my ($childin, $childout);
my $mypid;
if ($phpbin =~ /php44|php51/) {
$mypid = open3($childin, $childout, $childout, $phpbin,"-i");
} else {
$mypid = open3($childin, $childout, $childout, $phpbin,"-d","zlib.output_compression=Off","-i");
}
my @conf = <$childout>;
waitpid ($mypid, 0);
chomp @conf;
if (my @ls = grep {$_ =~ /^PHP License/} @conf) {
my $version = 0;
my ($mas,$maj,$min);
if (my @ls = grep {$_ =~ /^PHP Version\s*=>\s*/i} @conf) {
my $line = $ls[0];
$line =~ /^PHP Version\s*=>\s*(.*)/i;
($mas,$maj,$min) = split(/\./,$1);
$version = "$mas.$maj.$min";
if ($mas < 8) {$status = 1}
if ($mas == 8 and $maj < 1) {$status = 1}
}
open (my $IN, "<", "/usr/local/apache/conf/php.conf.yaml");
flock ($IN, LOCK_SH);
my @phpyamlconf = <$IN>;
close ($IN);
chomp @phpyamlconf;
if (my @ls = grep {$_ =~ /php4:/i} @phpyamlconf) {
if ($ls[0] !~ /none/) {
$status = 1;
$version = "4.*";
}
}
unless ($phpbin =~ m[^/opt/alt/php]) {
if ($status) {$phpconf{version} .= "$version ($phpbin),"}
}
$status = 1;
if (my @ls = grep {$_ =~ /^enable_dl\s*=>\s*Off/i} @conf) {
$status = 0;
}
if (my @ls = grep {$_ =~ /^disable_functions\s*=>.*dl.*/i} @conf) {
$status = 0;
}
if ($status) {$phpconf{enable_dl} .= "$phpini ($phpbin),"}
$status = 1;
if (my @ls = grep {$_ =~ /^disable_functions\s*=>.*\,/i} @conf) {
$status = 0;
}
if ($status) {$phpconf{disable_functions} .= "$phpini ($phpbin),"}
$status = 1;
if (my @ls = grep {$_ =~ /^disable_functions\s*=>.*ini_set.*/i} @conf) {
$status = 0;
}
if ($status) {$phpconf{ini_set} .= "$phpini ($phpbin),"}
my $oldver = "$mas.$maj";
if ($oldver < 5.4) {
$status = 1;
if (my @ls = grep {$_ =~ /^register_globals\s*=>\s*Off/i} @conf) {
$status = 0;
}
if ($status) {$phpconf{register_globals} .= "$phpini ($phpbin),"}
}
} else {
$status = 1;
&addline($status,"Check php
[$phpbin]","Unable to examine PHP settings due to an error in the output from: [$phpbin -i]");
}
}
foreach my $key ("version","enable_dl","disable_functions","ini_set","register_globals") {
my $values;
foreach my $value (split(/\,/,$phpconf{$key})) {
if ($value eq "") {next}
$values .= "
$value\n";
}
if ($key eq "version") {
my $status = 0;
if ($values ne "") {$status = 1}
&addline($status,"Check php version","Any version of PHP older than v8.1.* is now obsolete and should be considered a security threat. You should upgrade to at least PHP v8.1+:
Affected PHP versions: $values");
}
if ($key eq "enable_dl") {
my $status = 0;
if ($values ne "") {$status = 1}
&addline($status,"Check php for enable_dl or disabled dl()","You should set:
enable_dl = Off This prevents users from loading php modules that affect everyone on the server. Note that if use dynamic libraries, such as ioncube, you will have to load them directly in the PHP configuration:
Affected PHP versions: $values");
}
if ($key eq "disable_functions") {
my $status = 0;
if ($values ne "") {$status = 1}
&addline($status,"Check php for disable_functions","You should consider disabling commonly abused php functions, e.g.:
disable_functions = show_source, system, shell_exec, passthru, exec, popen, proc_open Some client web scripts may break with some of these functions disabled, so you may have to remove them from this list:
Affected PHP versions: $values");
}
if ($key eq "register_globals") {
my $status = 0;
if ($values ne "") {$status = 1}
&addline($status,"Check php for register_globals","You should set:
register_globals = Off unless it is absolutely necessary as it is seen as a significant security risk:
Affected PHP versions: $values");
}
}
return;
}
# end phpcheck
###############################################################################
# start apachecheck
sub apachecheck {
&addtitle("Apache Check");
my $status = 0;
my $mypid;
my ($childin, $childout);
my %ea4;
if (-e "/usr/local/cpanel/version" and -e "/etc/cpanel/ea4/is_ea4" and -e "/etc/cpanel/ea4/paths.conf") {
my @file = slurp("/etc/cpanel/ea4/paths.conf");
$ea4{enabled} = 1;
foreach my $line (@file) {
$line =~ s/$cleanreg//g;
if ($line =~ /^(\s|\#|$)/) {next}
if ($line !~ /=/) {next}
my ($name,$value) = split (/=/,$line,2);
$value =~ s/^\s+//g;
$value =~ s/\s+$//g;
$ea4{$name} = $value;
}
}
if ($ea4{enabled}) {
unless (-x $ea4{bin_httpd}) {&addline(1,"HTTP Binary","$ea4{bin_httpd} not found or not executable"); return}
}
elsif ($config{DIRECTADMIN}) {
unless (-x "/usr/sbin/httpd") {&addline(1,"HTTP Binary","/usr/sbin/httpd not found or not executable"); return}
}
else {
unless (-x "/usr/local/apache/bin/httpd") {&addline(1,"HTTP Binary","/usr/local/apache/bin/httpd not found or not executable"); return}
}
if ($ea4{enabled}) {
$mypid = open3($childin, $childout, $childout, $ea4{bin_httpd},"-v");
}
elsif ($config{DIRECTADMIN}) {
$mypid = open3($childin, $childout, $childout, "/usr/sbin/httpd","-v");
}
else {
$mypid = open3($childin, $childout, $childout, "/usr/local/apache/bin/httpd","-v");
}
my @version = <$childout>;
waitpid ($mypid, 0);
chomp @version;
$version[0] =~ /Apache\/(\d+)\.(\d+)\.(\d+)/;
my $mas = $1;
my $maj = $2;
my $min = $3;
if ("$mas.$maj" < 2.2) {$status = 1}
&addline($status,"Check apache version","You are running a legacy version of apache (v$mas.$maj.$min) and should consider upgrading to v2.2.* as recommended by the Apache developers");
unless ($config{DIRECTADMIN}) {
my $ruid2 = 0;
if ($ea4{enabled}) {
$mypid = open3($childin, $childout, $childout, $ea4{bin_httpd},"-M");
}
else {
$mypid = open3($childin, $childout, $childout, "/usr/local/apache/bin/httpd","-M");
}
my @modules = <$childout>;
waitpid ($mypid, 0);
chomp @modules;
if (my @ls = grep {$_ =~ /ruid2_module/} @modules) {$ruid2 = 1}
if (my @ls = grep {$_ =~ /mpm_itk_module/} @modules) {$ruid2 = 1}
$status = 0;
if (my @ls = grep {$_ =~ /security2_module/} @modules) {$status = 0} else {$status = 1}
&addline($status,"Check apache for ModSecurity","You should install the ModSecurity apache module during the easyapache build process to help prevent exploitation of vulnerable web scripts, together with a set of rules");
$status = 0;
if (my @ls = grep {$_ =~ /cloudflare_module/} @modules) {$status = 1} else {$status = 0}
if ($config{CF_ENABLE}) {$status = 0}
&addline($status,"Check apache for mod_cloudflare","This module logs the real users IP address to Apache. If this is reported to lfd via ModSecurity, cxs or some other vector through Apache it will lead to that IP being blocked, but because the IP is coming through the CloudFlare service the IP will
not be blocked as so far as iptables is concerned the originating IP address is CloudFlare itself and the abuse will continue. To block these IP's in the CloudFlare Firewall look at using CF_ENABLE in csf.conf");
$status = 0;
if (my @ls = grep {$_ =~ /frontpage_module/} @modules) {$status = 1}
&addline($status,"Check apache for FrontPage","Microsoft Frontpage Extensions were EOL in 2006 and there is no support for bugs or security issues. For this reason, it should be considered a security risk to continue using them. You should rebuild apache through easyapache and deselect the option to build them");
my @conf;
if (-e "/usr/local/apache/conf/httpd.conf") {
open (my $IN, "<", "/usr/local/apache/conf/httpd.conf");
flock ($IN, LOCK_SH);
@conf = <$IN>;
close ($IN);
chomp @conf;
}
if (-e "$ea4{file_conf}") {
open (my $IN, "<", "$ea4{file_conf}");
flock ($IN, LOCK_SH);
@conf = <$IN>;
close ($IN);
chomp @conf;
}
if (@conf) {
$status = 0;
my $ciphers;
my $error;
if (my @ls = grep {$_ =~ /^\s*SSLCipherSuite/} @conf) {
$ls[0] =~ s/^\s+//g;
(undef,$ciphers) = split(/\ /,$ls[0]);
$ciphers =~ s/\s*|\"|\'//g;
if ($ciphers eq "") {
$status = 1;
} else {
if (-x "/usr/bin/openssl") {
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/bin/openssl","ciphers","-v",$ciphers);
my @openssl = <$childout>;
waitpid ($cmdpid, 0);
chomp @openssl;
if (my @ls = grep {$_ =~ /error/i} @openssl) {$error = $openssl[0]; $status=2}
if (my @ls = grep {$_ =~ /SSLv2/} @openssl) {$status = 1}
}
}
} else {$status = 1}
if ($status == 2) {
&addline($status,"Check Apache weak SSL/TLS Ciphers (SSLCipherSuite)","Unable to determine cipher list for [$ciphers] from openssl:
[$error]");
}
&addline($status,"Check Apache weak SSL/TLS Ciphers (SSLCipherSuite)","Cipher list [$ciphers]. Due to weaknesses in the SSLv2 cipher you should disable SSLv2 in WHM > Apache Configuration >
Global Configuration > SSLCipherSuite > Add -SSLv2 to SSLCipherSuite and/or remove +SSLv2. Do not forget to Save AND then Rebuild Configuration and Restart Apache, otherwise the changes will not take effect in httpd.conf");
$status = 0;
if (my @ls = grep {$_ =~ /^\s*TraceEnable Off/} @conf) {
$status = 0;
} else {$status = 1}
&addline($status,"Check apache for TraceEnable","You should set TraceEnable to Off in: WHM > Apache Configuration >
Global Configuration > Trace Enable > Off. Do not forget to Save AND then Rebuild Configuration and Restart Apache, otherwise the changes will not take effect in httpd.conf");
$status = 0;
if (my @ls = grep {$_ =~ /^\s*ServerSignature Off/} @conf) {
$status = 0;
} else {$status = 1}
&addline($status,"Check apache for ServerSignature","You should set ServerSignature to Off in: WHM > Apache Configuration >
Global Configuration > Server Signature > Off. Do not forget to Save AND then Rebuild Configuration and Restart Apache, otherwise the changes will not take effect in httpd.conf");
$status = 0;
if (my @ls = grep {$_ =~ /^\s*ServerTokens ProductOnly/} @conf) {
$status = 0;
} else {$status = 1}
&addline($status,"Check apache for ServerTokens","You should set ServerTokens to ProductOnly in: WHM > Apache Configuration >
Global Configuration > Server Tokens > Product Only. Do not forget to Save AND then Rebuild Configuration and Restart Apache, otherwise the changes will not take effect in httpd.conf");
$status = 0;
if (my @ls = grep {$_ =~ /^\s*FileETag None/} @conf) {
$status = 0;
} else {$status = 1}
&addline($status,"Check apache for FileETag","You should set FileETag to None in: WHM > Apache Configuration >
Global Configuration > File ETag > None. Do not forget to Save AND then Rebuild Configuration and Restart Apache, otherwise the changes will not take effect in httpd.conf");
}
my @apacheconf;
if (-e "/usr/local/apache/conf/php.conf.yaml") {
open (my $IN, "<", "/usr/local/apache/conf/php.conf.yaml");
flock ($IN, LOCK_SH);
@apacheconf = <$IN>;
close ($IN);
chomp @apacheconf;
}
if (-e "$ea4{dir_conf}/php.conf.yaml") {
open (my $IN, "<", "$ea4{dir_conf}/php.conf.yaml");
flock ($IN, LOCK_SH);
@apacheconf = <$IN>;
close ($IN);
chomp @apacheconf;
}
if (@apacheconf) {
unless ($ruid2) {
$status = 0;
if (my @ls = grep {$_ =~ /suphp/} @apacheconf) {
$status = 0;
} else {$status = 1}
&addline($status,"Check suPHP","To reduce the risk of hackers accessing all sites on the server from a compromised PHP web script, you should enable suPHP when you build apache/php. Note that there are sideeffects when enabling suPHP on a server and you should be aware of these before enabling it.
Don\'t forget to enable it as the default PHP handler in
WHM > PHP 5 Handler ");
$status = 0;
unless ($cpconf->{userdirprotect}) {$status = 1}
&addline($status,"Check mod_userdir protection","To prevents users from stealing bandwidth or hackers hiding access to your servers, you should check
WHM > Security Center > mod_userdir Tweak ");
$status = 1;
if (my @ls = grep {$_ =~ /suexec_module/} @modules) {$status = 0}
&addline($status,"Check Suexec","To reduce the risk of hackers accessing all sites on the server from a compromised CGI web script, you should set
WHM > Suexec on ");
}
}
}
return;
}
# end apachecheck
###############################################################################
# start sshtelnetcheck
sub sshtelnetcheck {
my $status = 0;
&addtitle("SSH/Telnet Check");
if (-e "/etc/ssh/sshd_config") {
open (my $IN, "<", "/etc/ssh/sshd_config");
flock ($IN, LOCK_SH);
my @sshconf = <$IN>;
close ($IN);
chomp @sshconf;
if (my @ls = grep {$_ =~ /^\s*Protocol/i} @sshconf) {
if ($ls[0] =~ /1/) {$status = 1}
} else {$status = 0}
&addline($status,"Check SSHv1 is disabled","You should disable SSHv1 by editing /etc/ssh/sshd_config and setting:
Protocol 2 ");
$status = 0;
my $sshport = "22";
if (my @ls = grep {$_ =~ /^\s*Port/i} @sshconf) {
if ($ls[0] =~ /^\s*Port\s+(\d*)/i) {
$sshport = $1;
if ($sshport eq "22") {$status = 1}
} else {$status = 1}
} else {$status = 1}
&addline($status,"Check SSH on non-standard port","You should consider moving SSH to a non-standard port [currently:$sshport] to evade basic SSH port scans. Don't forget to open the port in the firewall first if necessary");
$status = 0;
if (my @ls = grep {$_ =~ /^\s*PasswordAuthentication/i} @sshconf) {
if ($ls[0] =~ /\byes\b/i) {$status = 1}
} else {$status = 1}
&addline($status,"Check SSH PasswordAuthentication","You should disable PasswordAuthentication and only allow access using PubkeyAuthentication to improve brute-force SSH security");
$status = 0;
if (my @ls = grep {$_ =~ /^\s*UseDNS/i} @sshconf) {
if ($ls[0] !~ /\bno\b/i) {$status = 1}
} else {$status = 1}
&addline($status,"Check SSH UseDNS","You should disable UseDNS by editing /etc/ssh/sshd_config and setting:
UseDNS no Otherwise, lfd will be unable to track SSHD login failures successfully as the log files will not report IP addresses");
} else {&addline(1,"Check SSH configuration","Unable to find /etc/ssh/sshd_config");}
$status = 0;
my $check = &getportinfo("23");
if ($check) {$status = 1}
&addline($status,"Check telnet port 23 is not in use","It appears that something is listening on port 23 which is normally used for telnet. Telnet is an insecure protocol and you should disable the telnet daemon if it is running");
unless ($config{DNSONLY} or $config{GENERIC}) {
unless ($config{VPS}) {
if (-e "/etc/redhat-release") {
open (my $IN, "<", "/etc/redhat-release");
flock ($IN, LOCK_SH);
my $conf = <$IN>;
close ($IN);
chomp $conf;
unless ($conf =~ /^CloudLinux/i) {
if (-e "/etc/profile") {
$status = 0;
open (my $IN, "<", "/etc/profile");
flock ($IN, LOCK_SH);
my @profile = <$IN>;
close ($IN);
chomp @profile;
if (grep {$_ =~ /^LIMITUSER=\$USER/} @profile) {
$status = 0;
} else {$status = 1}
&addline($status,"Check shell limits","You should enable shell resource limits to prevent shell users from consuming server resources - DOS exploits typically do this. A quick way to set this is to use WHM >
Shell Fork Bomb Protection ");
} else {
&addline(1,"Check shell limits","Unable to find /etc/profile");
}
}
}
}
$status = 0;
if (-e "/var/cpanel/killproc.conf") {
open (my $IN, "<", "/var/cpanel/killproc.conf");
flock ($IN, LOCK_SH);
my @proc = <$IN>;
close ($IN);
chomp @proc;
if (@proc < 9) {$status = 1}
&addline($status,"Check Background Process Killer","You should enable each item in the WHM >
Background Process Killer ");
} else {&addline(1,"Check Background Process Killer","You should enable each item in the WHM >
Background Process Killer ")}
}
return;
}
# end sshtelnetcheck
###############################################################################
# start servicescheck
sub servicescheck {
my $systemctl = "/usr/bin/systemctl";
my $chkconfig = "/sbin/chkconfig";
my $servicebin = "/sbin/service";
if (-e "/bin/systemctl") {$systemctl = "/bin/systemctl"}
if (-e "/usr/sbin/chkconfig") {$chkconfig = "/usr/sbin/chkconfig"}
if (-e "/usr/sbin/service") {$servicebin = "/usr/sbin/service"}
&addtitle("Server Services Check");
my @services = ("abrt-xorg", "abrtd", "alsa-state", "anacron", "avahi-daemon", "avahi-dnsconfd", "bluetooth", "bolt", "canna", "colord", "cups", "cups-config-daemon", "cupsd", "firewalld", "FreeWnn", "gdm", "gpm", "gssproxy", "hidd", "iiim", "ksmtuned", "mDNSResponder", "ModemManager", "nfslock", "nifd", "packagekit", "pcscd", "portreserve", "pulseaudio", "qpidd", "rpcbind", "rpcidmapd", "saslauthd", "sbadm", "wpa_supplicant", "xfs", "xinetd");
my $disable;
my ($childin, $childout);
my $mypid;
if ($sysinit eq "init") {
$disable = "$servicebin [service] stop
$chkconfig [service] off";
$mypid = open3($childin, $childout, $childout, $chkconfig,"--list");
} else {
$disable = "$systemctl stop [service]
$systemctl disable [service]";
$mypid = open3($childin, $childout, $childout, $systemctl,"list-unit-files","--state=enabled","--no-pager","--no-legend");
}
my @chkconfig = <$childout>;
waitpid ($mypid, 0);
chomp @chkconfig;
my @enabled;
foreach my $service (@services) {
if ($service eq "xinetd" and $config{PLESK}) {next}
if ($sysinit eq "init") {
if (my @ls = grep {$_ =~ /^$service\b/} @chkconfig) {
if ($ls[0] =~ /\:on/) {push @enabled, $service}
}
} else {
if (my @ls = grep {$_ =~ /^$service\.service/} @chkconfig) {push @enabled, $service}
}
}
if (scalar @enabled > 0) {
my $list;
foreach my $service (@enabled) {
if (length($list) == 0) {
$list = $service;
} else {
$list .= ",".$service;
}
}
&addline("1","Check server services","On most servers the following services are not needed and should be stopped and disabled from starting unless used:
$list
\nEach service can usually be disabled using:
$disable ");
} else {
&addline("0","Check server services","On most servers the following services are not needed and should be stopped and disabled from starting unless used:
none found
\nEach service can usually be disabled using:
$disable ");
}
return;
}
# end servicescheck
###############################################################################
# start getportinfo
sub getportinfo {
my $port = shift;
my $hit = 0;
foreach my $proto ("udp","tcp","udp6","tcp6") {
open (my $IN, "<", "/proc/net/$proto");
flock ($IN, LOCK_SH);
while (<$IN>) {
my @rec = split();
if ($rec[9] =~ /uid/) {next}
my (undef,$sport) = split(/:/,$rec[1]);
if (hex($sport) == $port) {$hit = 1}
}
close ($IN);
}
return $hit;
}
# end getportinfo
###############################################################################
1;
Config.pm 0000644 00000042645 15103002075 0006313 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::Config;
use strict;
use lib '/usr/local/csf/lib';
use version;
use Fcntl qw(:DEFAULT :flock);
use Carp;
use IPC::Open3;
use ConfigServer::Slurp qw(slurp);
use Exporter qw(import);
our $VERSION = 1.05;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
our $ipv4reg = qr/(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/;
our $ipv6reg = qr/((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?/;
my %config;
my %configsetting;
my $warning;
my $version;
my $slurpreg = ConfigServer::Slurp->slurpreg;
my $cleanreg = ConfigServer::Slurp->cleanreg;
my $configfile = "/etc/csf/csf.conf";
# end main
###############################################################################
# start loadconfig
sub loadconfig {
my $class = shift;
my $self = {};
bless $self,$class;
if (%config) {
$self->{warning} = $warning;
return $self;
}
undef %configsetting;
undef %config;
undef $warning;
my @file = slurp($configfile);
foreach my $line (@file) {
$line =~ s/$cleanreg//g;
if ($line =~ /^(\s|\#|$)/) {next}
if ($line !~ /=/) {next}
my ($name,$value) = split (/=/,$line,2);
$name =~ s/\s//g;
if ($value =~ /\"(.*)\"/) {
$value = $1;
} else {
croak "*Error* Invalid configuration line [$line] in $configfile";
}
if ($configsetting{$name}) {
croak "*Error* Setting $name is repeated in $configfile - you must remove the duplicates and then restart csf and lfd";
}
$config{$name} = $value;
$configsetting{$name} = 1;
}
if ($config{LF_IPSET}) {
unless ($config{LF_IPSET_HASHSIZE}) {
$config{LF_IPSET_HASHSIZE} = "1024";
$configsetting{LF_IPSET_HASHSIZE} = 1;
}
unless ($config{LF_IPSET_MAXELEM}) {
$config{LF_IPSET_MAXELEM} = "65536";
$configsetting{LF_IPSET_MAXELEM} = 1;
}
}
if ($config{USE_FTPHELPER} eq "1") {
$warning .= "USE_FTPHELPER should be set to your FTP server port (21), not 1. USE_FTPHELPER has been disabled\n";
$config{USE_FTPHELPER} = 0;
}
if ($config{IPTABLES} eq "" or !(-x $config{IPTABLES})) {
croak "*Error* The path to iptables is either not set or incorrect for IPTABLES [$config{IPTABLES}] in /etc/csf/csf.conf";
}
if (-e "/proc/sys/net/netfilter/nf_conntrack_helper" and !$config{USE_FTPHELPER}) {
my $setting = slurp("/proc/sys/net/netfilter/nf_conntrack_helper");
chomp $setting;
if ($setting == 0) {
open (my $PROC, ">", "/proc/sys/net/netfilter/nf_conntrack_helper");
print $PROC "1\n";
close $PROC;
}
}
if ($config{WAITLOCK}) {$config{IPTABLESWAIT} = "--wait";}
my @results = &systemcmd("$config{IPTABLES} $config{IPTABLESWAIT} --version");
if ($results[0] =~ /iptables v(\d+\.\d+\.\d+)/) {
$version = $1;
$config{IPTABLESWAIT} = "";
if ($config{WAITLOCK}) {
my @ipdata;
eval {
local $SIG{__DIE__} = undef;
local $SIG{'ALRM'} = sub {die "alarm\n"};
alarm($config{WAITLOCK_TIMEOUT});
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "$config{IPTABLES} --wait -L OUTPUT -nv");
@ipdata = <$childout>;
waitpid ($cmdpid, 0);
chomp @ipdata;
if ($ipdata[0] =~ /# Warning: iptables-legacy tables present/) {shift @ipdata}
alarm(0);
};
alarm(0);
if ($@ eq "alarm\n") {
croak "*ERROR* Timeout after $config{WAITLOCK_TIMEOUT} seconds for iptables --wait - WAITLOCK\n";
}
if ($ipdata[0] =~ /^Chain OUTPUT/) {
$config{IPTABLESWAIT} = "--wait";
} else {
$warning .= "*WARNING* This version of iptables does not support the --wait option - disabling WAITLOCK\n";
$config{WAITLOCK} = 0;
}
}
} else {
$warning .= "*WARNING* Unable to detect iptables version [$results[0]]\n";
}
if ($config{CC_LOOKUPS} and $config{CC_LOOKUPS} != 4 and $config{CC_SRC} eq "1") {
if ($config{MM_LICENSE_KEY} eq "") {
$warning .= "*ERROR*: Country Code Lookups setting MM_LICENSE_KEY must be set in /etc/csf/csf.conf to continue using the MaxMind databases\n";
}
}
foreach my $cclist ("CC_DENY","CC_ALLOW","CC_ALLOW_FILTER","CC_ALLOW_PORTS","CC_DENY_PORTS","CC_ALLOW_SMTPAUTH") {
$config{$cclist} =~ s/\s//g;
my $newcclist;
foreach my $cc (split(/\,/,$config{$cclist})) {
if ($cc ne "" and ((length($cc) == 2 and $cc =~ /^[a-zA-Z][a-zA-Z]$/i) or (length($cc) > 2 and $cc =~ /^AS\d+$/i))) {
$cc = lc $cc;
if ($newcclist eq "") {$newcclist = "$cc"} else {$newcclist .= ",$cc"}
} else {
$warning .= "*WARNING* $cclist contains an invalid entry [$cc]\n";
}
}
$config{$cclist} = $newcclist;
}
if ($config{CC_DENY} or $config{CC_ALLOW} or $config{CC_ALLOW_FILTER} or $config{CC_ALLOW_PORTS} or $config{CC_DENY_PORTS} or $config{CC_ALLOW_SMTPAUTH}) {
if ($config{MM_LICENSE_KEY} eq "" and $config{CC_SRC} eq "1") {
$warning .= "*ERROR*: Country Code Filters setting MM_LICENSE_KEY must be set in /etc/csf/csf.conf to continue updating the MaxMind databases\n";
}
}
if ($config{DROP_OUT} ne "DROP") {
my @data = &systemcmd("$config{IPTABLES} $config{IPTABLESWAIT} -N TESTDENY");
unless ($data[0] =~ /^iptables/) {
my @ipdata = &systemcmd("$config{IPTABLES} $config{IPTABLESWAIT} -I TESTDENY -j $config{DROP_OUT}");
if ($ipdata[0] =~ /^iptables/) {
$warning .= "*WARNING* Cannot use DROP_OUT value of [$config{DROP_OUT}] on this server, set to DROP\n";
$config{DROP_OUT} = "DROP";
}
&systemcmd("$config{IPTABLES} $config{IPTABLESWAIT} -F TESTDENY");
&systemcmd("$config{IPTABLES} $config{IPTABLESWAIT} -X TESTDENY");
}
}
my @raw = &systemcmd("$config{IPTABLES} $config{IPTABLESWAIT} -L PREROUTING -t raw");
if ($raw[0] =~ /^Chain PREROUTING/) {$config{RAW} = 1} else {$config{RAW} = 0}
my @mangle = &systemcmd("$config{IPTABLES} $config{IPTABLESWAIT} -L PREROUTING -t mangle");
if ($mangle[0] =~ /^Chain PREROUTING/) {$config{MANGLE} = 1} else {$config{MANGLE} = 0}
if ($config{IPV6} and -x $config{IP6TABLES} and $version) {
if ($config{USE_CONNTRACK} and version->parse($version) <= version->parse("1.3.5")) {$config{USE_CONNTRACK} = 0}
if ($config{PORTFLOOD} and version->parse($version) >= version->parse("1.4.3")) {$config{PORTFLOOD6} = 1}
if ($config{CONNLIMIT} and version->parse($version) >= version->parse("1.4.3")) {$config{CONNLIMIT6} = 1}
if ($config{MESSENGER} and version->parse($version) >= version->parse("1.4.17")) {$config{MESSENGER6} = 1}
if ($config{SMTP_REDIRECT} and version->parse($version) >= version->parse("1.4.17")) {$config{SMTP_REDIRECT6} = 1}
my @ipdata = &systemcmd("$config{IP6TABLES} $config{IPTABLESWAIT} -t nat -L POSTROUTING -nv");
if ($ipdata[0] =~ /^Chain POSTROUTING/) {
$config{NAT6} = 1;
}
elsif (version->parse($version) >= version->parse("1.4.17")) {
if ($config{SMTP_REDIRECT}) {
$warning .= "*WARNING* ip6tables nat table not present - disabling SMTP_REDIRECT for IPv6\n";
$config{SMTP_REDIRECT6} = 0;
}
if ($config{MESSENGER}) {
$warning .= "*WARNING* ip6tables nat table not present - disabling MESSENGER Service for IPv6\n";
$config{MESSENGER6} = 0;
}
if ($config{DOCKER} and $config{DOCKER_NETWORK6} ne "") {
$warning .= "*WARNING* ip6tables nat table not present - disabling DOCKER for IPv6\n";
}
}
my @raw = &systemcmd("$config{IP6TABLES} $config{IPTABLESWAIT} -L PREROUTING -t raw");
if ($raw[0] =~ /^Chain PREROUTING/) {$config{RAW6} = 1} else {$config{RAW6} = 0}
my @mangle = &systemcmd("$config{IP6TABLES} $config{IPTABLESWAIT} -L PREROUTING -t mangle");
if ($mangle[0] =~ /^Chain PREROUTING/) {$config{MANGLE6} = 1} else {$config{MANGLE6} = 0}
}
elsif ($config{IPV6}) {
$warning .= "*WARNING* incorrect ip6tables binary location [$config{IP6TABLES}] - IPV6 disabled\n";
$config{IPV6} = 0;
}
if (!$config{GENERIC} and -e "/var/cpanel/dnsonly") {$config{DNSONLY} = 1}
if (-e "/var/cpanel/smtpgidonlytweak" and !$config{GENERIC}) {
if ($config{DNSONLY}) {
$warning .= "*WARNING* The cPanel option to 'Restrict outgoing SMTP to root, exim, and mailman' is incompatible with this firewall. The option must be disabled using \"/usr/local/cpanel/scripts/smtpmailgidonly off\" and the SMTP_BLOCK alternative in csf used instead\n";
} else {
$warning .= "*WARNING* The option \"WHM > Tweak Settings > Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak)\" is incompatible with this firewall. The option must be disabled in WHM and the SMTP_BLOCK alternative in csf used instead\n";
}
}
if (-e "/proc/vz/veinfo") {$config{VPS} = 1}
else {
foreach my $line (slurp("/proc/self/status")) {
$line =~ s/$cleanreg//g;
if ($line =~ /^envID:\s*(\d+)\s*$/) {
if ($1 > 0) {
$config{VPS} = 1;
last;
}
}
}
}
if ($config{DROP_IP_LOGGING} and $config{PS_INTERVAL}) {
$warning .= "*WARNING* Cannot use PS_INTERVAL with DROP_IP_LOGGING enabled. DROP_IP_LOGGING disabled\n";
$config{DROP_IP_LOGGING} = 0;
}
if ($config{FASTSTART}) {
unless (-x $config{IPTABLES_RESTORE}) {
$warning .= "*WARNING* Unable to use FASTSTART as [$config{IPTABLES_RESTORE}] is not executable or does not exist\n";
$config{FASTSTART} = 0;
}
if ($config{IPV6}) {
unless (-x $config{IP6TABLES_RESTORE}) {
$warning .= "*WARNING* Unable to use FASTSTART as (IPv6) [$config{IP6TABLES_RESTORE}] is not executable or does not exist\n";
$config{FASTSTART} = 0;
}
}
}
if ($config{MESSENGER}) {
if ($config{MESSENGERV2}) {
if (!-e "/etc/cpanel/ea4/is_ea4") {
$warning .= "*WARNING* EA4 is not in use - disabling MESSENGERV2 and MESSENGER HTTPS Service\n";
$config{MESSENGERV2} = "0";
$config{MESSENGER_HTTPS_IN} = "";
$config{MESSENGER_HTTPS_DISABLED} = "*WARNING* EA4 is not in use - disabling MESSENGERV2 and MESSENGER HTTPS Service";
}
}
if ($config{MESSENGER_HTTPS_IN} and (!$config{MESSENGERV2} or $config{MESSENGER_HTTPS_DISABLED})) {
eval {
local $SIG{__DIE__} = undef;
require IO::Socket::SSL;
};
if ($@) {
$warning .= "*WARNING* Perl module IO::Socket::SSL missing - disabling MESSENGER HTTPS Service\n";
$config{MESSENGER_HTTPS_IN} = "";
$config{MESSENGER_HTTPS_DISABLED} = "*WARNING* Perl module IO::Socket::SSL missing - disabling MESSENGER HTTPS Service";
}
elsif (version->parse($IO::Socket::SSL::VERSION) < version->parse("1.83")) {
$warning .= "*WARNING* Perl module IO::Socket::SSL v$IO::Socket::SSL::VERSION does not support SNI - disabling MESSENGER HTTPS Service\n";
$config{MESSENGER_HTTPS_IN} = "";
$config{MESSENGER_HTTPS_DISABLED} = "*WARNING* Perl module IO::Socket::SSL v$IO::Socket::SSL::VERSION does not support SNI - disabling MESSENGER HTTPS Service";
}
}
my $pcnt = 0;
foreach my $port (split(/\,/,$config{MESSENGER_HTML_IN})) {
$pcnt++;
}
if ($pcnt > 15) {
$warning .= "*WARNING* MESSENGER_HTML_IN contains more than 15 ports - disabling MESSENGER Service\n";
$config{MESSENGER} = 0;
} else {
$pcnt = 0;
foreach my $port (split(/\,/,$config{MESSENGER_TEXT_IN})) {
$pcnt++;
}
if ($pcnt > 15) {
$warning .= "*WARNING* MESSENGER_TEXT_IN contains more than 15 ports - disabling MESSENGER Service\n";
$config{MESSENGER} = 0;
} else {
$pcnt = 0;
foreach my $port (split(/\,/,$config{MESSENGER_HTTPS_IN})) {
$pcnt++;
}
if ($pcnt > 15) {
$warning .= "*WARNING* MESSENGER_HTTPS_IN contains more than 15 ports - disabling MESSENGER Service\n";
$config{MESSENGER} = 0;
}
}
}
}
if ($config{IPV6} and $config{IPV6_SPI}) {
open (my $FH, "<", "/proc/sys/kernel/osrelease");
flock ($FH, LOCK_SH);
my @data = <$FH>;
close ($FH);
chomp @data;
if ($data[0] =~ /^(\d+)\.(\d+)\.(\d+)/) {
my $maj = $1;
my $mid = $2;
my $min = $3;
if (($maj > 2) or (($maj > 1) and ($mid > 6)) or (($maj > 1) and ($mid > 5) and ($min > 19))) {
} else {
$warning .= "*WARNING* Kernel $data[0] may not support an ip6tables SPI firewall. You should set IPV6_SPI to \"0\" in /etc/csf/csf.conf\n\n";
}
}
}
if (($config{CLUSTER_SENDTO} or $config{CLUSTER_RECVFROM})) {
if (-f $config{CLUSTER_SENDTO}) {
if ($config{DEBUG} >= 1) {$warning .= "*DEBUG* CLUSTER_SENDTO retrieved from $config{CLUSTER_SENDTO} and set to: "}
$config{CLUSTER_SENDTO} = join(",", slurp($config{CLUSTER_SENDTO}));
if ($config{DEBUG} >= 1) {$warning .= "[$config{CLUSTER_SENDTO}]\n"}
}
if (-f $config{CLUSTER_RECVFROM}) {
if ($config{DEBUG} >= 1) {$warning .= "*DEBUG* CLUSTER_RECVFROM retrieved from $config{CLUSTER_RECVFROM} and set to: "}
$config{CLUSTER_RECVFROM} = join(",", slurp($config{CLUSTER_RECVFROM}));
if ($config{DEBUG} >= 1) {$warning .= "[$config{CLUSTER_RECVFROM}]\n"}
}
}
my @ipdata = &systemcmd("$config{IPTABLES} $config{IPTABLESWAIT} -t nat -L POSTROUTING -nv");
if ($ipdata[0] =~ /^Chain POSTROUTING/) {
$config{NAT} = 1;
} else {
if ($config{MESSENGER}) {
$warning .= "*WARNING* iptables nat table not present - disabling MESSENGER Service\n";
$config{MESSENGER} = 0;
}
}
if ($config{PT_USERKILL}) {
$warning .= "*WARNING* PT_USERKILL should not normally be enabled as it can easily lead to legitimate processes being terminated, use csf.pignore instead\n";
}
$config{cc_src} = "MaxMind";
$config{asn_src} = "MaxMind";
$config{cc_country} = "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip&license_key=$config{MM_LICENSE_KEY}";
$config{cc_city} = "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip&license_key=$config{MM_LICENSE_KEY}";
$config{cc_asn} = "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN-CSV&suffix=zip&license_key=$config{MM_LICENSE_KEY}";
if ($config{CC_SRC} eq "2") {
$config{cc_src} = "DB-IP";
$config{asn_src} = "iptoasn.com";
$config{ccl_src} = "ipdeny.com";
my ($month,$year) = sub{ 1+shift, 1900+shift }->((localtime time)[4,5]);
$month = sprintf("%02d", $month);
$config{cc_country} = "http://download.db-ip.com/free/dbip-country-lite-$year-$month.csv.gz";
$config{cc_city} = "http://download.db-ip.com/free/dbip-city-lite-$year-$month.csv.gz";
$config{cc_asn} = "http://iptoasn.com/data/ip2asn-combined.tsv.gz";
$config{cc_cc} = "http://download.geonames.org/export/dump/countryInfo.txt";
}
$config{DOWNLOADSERVER} = &getdownloadserver;
$self->{warning} = $warning;
return $self;
}
# end loadconfig
###############################################################################
# start config
sub config {
return %config;
}
# end config
###############################################################################
# start resetconfig
sub resetconfig {
undef %config;
undef %configsetting;
undef $warning;
return;
}
# end resetconfig
###############################################################################
# start configsetting
sub configsetting {
return %configsetting;
}
# end configsetting
###############################################################################
# start ipv4reg
sub ipv4reg {
return $ipv4reg;
}
# end ipv4reg
###############################################################################
# start ipv6reg
sub ipv6reg {
return $ipv6reg;
}
# end ipv6reg
###############################################################################
# start systemcmd
sub systemcmd {
my @command = @_;
my @result;
eval {
my ($childin, $childout);
my $pid = open3($childin, $childout, $childout, @command);
@result = <$childout>;
waitpid ($pid, 0);
chomp @result;
if ($result[0] =~ /# Warning: iptables-legacy tables present/) {shift @result}
};
return @result;
}
# end systemcmd
###############################################################################
## start getdownloadserver
sub getdownloadserver {
my @servers;
my $downloadservers = "/etc/csf/downloadservers";
my $chosen;
if (-e $downloadservers) {
## open (my $DOWNLOAD, "<", $downloadservers);
## flock ($DOWNLOAD, LOCK_SH);
## my @data = <$DOWNLOAD>;
## close ($DOWNLOAD);
## chomp @data;
## foreach my $line (@data) {
## if ($line =~ /^download/) {push @servers, $line}
## }
foreach my $line (slurp($downloadservers)) {
$line =~ s/$cleanreg//g;
if ($line =~ /^download/) {push @servers, $line}
}
$chosen = $servers[rand @servers];
}
if ($chosen eq "") {$chosen = "download.configserver.com"}
return $chosen;
}
## end getdownloadserver
###############################################################################
1; AbuseIP.pm 0000644 00000005543 15103002075 0006372 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::AbuseIP;
use strict;
use lib '/usr/local/csf/lib';
use Carp;
use IPC::Open3;
use Net::IP;
use ConfigServer::Config;
use ConfigServer::CheckIP qw(checkip);
use Exporter qw(import);
our $VERSION = 1.03;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(abuseip);
my $abusemsg = 'Abuse Contact for [ip]: [[contact]]
The Abuse Contact of this report was provided by the Abuse Contact DB by abusix.com. abusix.com does not maintain the content of the database. All information which we pass out, derives from the RIR databases and is processed for ease of use. If you want to change or report non working abuse contacts please contact the appropriate RIR. If you have any further question, contact abusix.com directly via email (info@abusix.com). Information about the Abuse Contact Database can be found here:
https://abusix.com/global-reporting/abuse-contact-db
abusix.com is neither responsible nor liable for the content or accuracy of this message.';
my $config = ConfigServer::Config->loadconfig();
my %config = $config->config();
# end main
###############################################################################
# start abuseip
sub abuseip {
my $ip = shift;
my $abuse = "";
my $netip;
my $reversed_ip;
if (checkip(\$ip)) {
eval {
local $SIG{__DIE__} = undef;
$netip = Net::IP->new($ip);
$reversed_ip = $netip->reverse_ip();
};
if ($reversed_ip =~ /^(\S+)\.in-addr\.arpa/) {$reversed_ip = $1}
if ($reversed_ip =~ /^(\S+)\s+(\S+)\.in-addr\.arpa/) {$reversed_ip = $2}
if ($reversed_ip =~ /^(\S+)\.ip6\.arpa/) {$reversed_ip = $1}
if ($reversed_ip =~ /^(\S+)\s+(\S+)\.ip6\.arpa/) {$reversed_ip = $2}
if ($reversed_ip ne "") {
$reversed_ip .= ".abuse-contacts.abusix.org";
my $cmdpid;
eval {
local $SIG{__DIE__} = undef;
local $SIG{'ALRM'} = sub {die};
alarm(10);
my ($childin, $childout);
$cmdpid = open3($childin, $childout, $childout, $config{HOST},"-W","5","-t","TXT",$reversed_ip);
close $childin;
my @results = <$childout>;
waitpid ($cmdpid, 0);
chomp @results;
if ($results[0] =~ /^${reversed_ip}.+"(.*)"$/) {$abuse = $1}
alarm(0);
};
alarm(0);
if ($cmdpid =~ /\d+/ and $cmdpid > 1 and kill(0,$cmdpid)) {kill(9,$cmdpid)}
if ($abuse ne "") {
my $msg = $abusemsg;
$msg =~ s/\[ip\]/$ip/g;
$msg =~ s/\[contact\]/$abuse/g;
return $abuse, $msg;
}
}
}
}
# end abuseip
###############################################################################
1;
URLGet.pm 0000644 00000016570 15103002075 0006206 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::URLGet;
use strict;
use lib '/usr/local/csf/lib';
use Fcntl qw(:DEFAULT :flock);
use Carp;
use IPC::Open3;
use ConfigServer::Config;
use Exporter qw(import);
our $VERSION = 2.00;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
my $agent = "ConfigServer";
my $option = 1;
my $proxy = "";
my $config = ConfigServer::Config->loadconfig();
my %config = $config->config();
$SIG{PIPE} = 'IGNORE';
# end main
###############################################################################
# start new
sub new {
my $class = shift;
$option = shift;
$agent = shift;
$proxy = shift;
my $self = {};
bless $self,$class;
if ($option == 3) {
return $self;
}
elsif ($option == 2) {
eval ('use LWP::UserAgent;'); ##no critic
if ($@) {return undef}
}
else {
eval {
local $SIG{__DIE__} = undef;
eval ('use HTTP::Tiny;'); ##no critic
};
}
return $self;
}
# end new
###############################################################################
# start urlget
sub urlget {
my $self = shift;
my $url = shift;
my $file = shift;
my $quiet = shift;
my $status;
my $text;
if (!defined $url) {carp "url not specified"; return}
if ($option == 3) {
($status, $text) = &binget($url,$file,$quiet);
}
elsif ($option == 2) {
($status, $text) = &urlgetLWP($url,$file,$quiet);
}
else {
($status, $text) = &urlgetTINY($url,$file,$quiet);
}
return ($status, $text);
}
# end urlget
###############################################################################
# start urlgetTINY
sub urlgetTINY {
my $url = shift;
my $file = shift;
my $quiet = shift;
my $status = 0;
my $timeout = 1200;
if ($proxy eq "") {undef $proxy}
my $ua = HTTP::Tiny->new(
'agent' => $agent,
'timeout' => 300,
'proxy' => $proxy
);
my $res;
my $text;
($status, $text) = eval {
local $SIG{__DIE__} = undef;
local $SIG{'ALRM'} = sub {die "Download timeout after $timeout seconds"};
alarm($timeout);
if ($file) {
local $|=1;
my $expected_length;
my $bytes_received = 0;
my $per = 0;
my $oldper = 0;
open (my $OUT, ">", "$file\.tmp") or return (1, "Unable to open $file\.tmp: $!");
flock ($OUT, LOCK_EX);
binmode ($OUT);
$res = $ua->request('GET', $url, {
data_callback => sub {
my($chunk, $res) = @_;
$bytes_received += length($chunk);
unless (defined $expected_length) {$expected_length = $res->{headers}->{'content-length'} || 0}
if ($expected_length) {
my $per = int(100 * $bytes_received / $expected_length);
if ((int($per / 5) == $per / 5) and ($per != $oldper) and !$quiet) {
print "...$per\%\n";
$oldper = $per;
}
} else {
unless ($quiet) {print "."}
}
print $OUT $chunk;
}
});
close ($OUT);
unless ($quiet) {print "\n"}
} else {
$res = $ua->request('GET', $url);
}
alarm(0);
if ($res->{success}) {
if ($file) {
rename ("$file\.tmp","$file") or return (1, "Unable to rename $file\.tmp to $file: $!");
return (0, $file);
} else {
return (0, $res->{content});
}
} else {
my $reason = $res->{reason};
if ($res->{status} == 599) {$reason = $res->{content}}
($status, $text) = &binget($url,$file,$quiet,$reason);
return ($status, $text);
}
};
alarm(0);
if ($@) {return (1, $@)}
return ($status,$text);
}
# end urlgetTINY
###############################################################################
# start urlgetLWP
sub urlgetLWP {
my $url = shift;
my $file = shift;
my $quiet = shift;
my $status = 0;
my $timeout = 300;
my $ua = LWP::UserAgent->new;
$ua->agent($agent);
$ua->timeout(30);
if ($proxy ne "") {$ua->proxy([ 'http', 'https' ], $proxy)}
#use LWP::ConnCache;
#my $cache = LWP::ConnCache->new;
#$cache->total_capacity([1]);
#$ua->conn_cache($cache);
my $req = HTTP::Request->new(GET => $url);
my $res;
my $text;
($status, $text) = eval {
local $SIG{__DIE__} = undef;
local $SIG{'ALRM'} = sub {die "Download timeout after $timeout seconds"};
alarm($timeout);
if ($file) {
local $|=1;
my $expected_length;
my $bytes_received = 0;
my $per = 0;
my $oldper = 0;
open (my $OUT, ">", "$file\.tmp") or return (1, "Unable to open $file\.tmp: $!");
flock ($OUT, LOCK_EX);
binmode ($OUT);
$res = $ua->request($req,
sub {
my($chunk, $res) = @_;
$bytes_received += length($chunk);
unless (defined $expected_length) {$expected_length = $res->content_length || 0}
if ($expected_length) {
my $per = int(100 * $bytes_received / $expected_length);
if ((int($per / 5) == $per / 5) and ($per != $oldper) and !$quiet) {
print "...$per\%\n";
$oldper = $per;
}
} else {
unless ($quiet) {print "."}
}
print $OUT $chunk;
});
close ($OUT);
unless ($quiet) {print "\n"}
} else {
$res = $ua->request($req);
}
alarm(0);
if ($res->is_success) {
if ($file) {
rename ("$file\.tmp","$file") or return (1, "Unable to rename $file\.tmp to $file: $!");
return (0, $file);
} else {
return (0, $res->content);
}
} else {
($status, $text) = &binget($url,$file,$quiet,$res->message);
return ($status, $text);
}
};
alarm(0);
if ($@) {
return (1, $@);
}
if ($text) {
return ($status,$text);
} else {
return (1, "Download timeout after $timeout seconds");
}
}
# end urlget
###############################################################################
# start binget
sub binget {
my $url = shift;
my $file = shift;
my $quiet = shift;
my $errormsg = shift;
$url = "'$url'";
my $cmd;
if (-e $config{CURL}) {
$cmd = $config{CURL}." -skLf -m 120";
if ($file) {$cmd = $config{CURL}." -kLf -m 120 -o";}
}
elsif (-e $config{WGET}) {
$cmd = $config{WGET}." -qT 120 -O-";
if ($file) {$cmd = $config{WGET}." -T 120 -O"}
}
if ($cmd ne "") {
if ($file) {
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, $cmd." $file\.tmp $url");
my @output = <$childout>;
waitpid ($cmdpid, 0);
unless ($quiet and $option != 3) {
print "Using fallback [$cmd]\n";
print @output;
}
if (-e "$file\.tmp") {
rename ("$file\.tmp","$file") or return (1, "Unable to rename $file\.tmp to $file: $!");
return (0, $file);
} else {
if ($option == 3) {
return (1, "Unable to download: ".$cmd." $file\.tmp $url".join("",@output));
} else {
return (1, "Unable to download: ".$errormsg);
}
}
} else {
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, $cmd." $url");
my @output = <$childout>;
waitpid ($cmdpid, 0);
if (scalar @output > 0) {
return (0, join("",@output));
} else {
if ($option == 3) {
return (1, "Unable to download: [$cmd $url]".join("",@output));
} else {
return (1, "Unable to download: ".$errormsg);
}
}
}
}
if ($option == 3) {
return (1, "Unable to download (CURL/WGET also not present, see csf.conf)");
} else {
return (1, "Unable to download (CURL/WGET also not present, see csf.conf): ".$errormsg);
}
}
# end binget
###############################################################################
1; LookUpIP.pm 0000644 00000026642 15103002075 0006547 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::LookUpIP;
use strict;
use lib '/usr/local/csf/lib';
use Carp;
use Fcntl qw(:DEFAULT :flock);
use IPC::Open3;
use JSON::Tiny;
use Net::IP;
use Socket;
use ConfigServer::CheckIP qw(checkip);
use ConfigServer::Config;
use ConfigServer::URLGet;
use Exporter qw(import);
our $VERSION = 2.00;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(iplookup);
my $config = ConfigServer::Config->loadconfig();
my %config = $config->config();
my $urlget;
if ($config{CC_LOOKUPS} == 4) {
$urlget = ConfigServer::URLGet->new($config{URLGET}, "", $config{URLPROXY});
unless (defined $urlget) {
$config{URLGET} = 1;
$urlget = ConfigServer::URLGet->new($config{URLGET}, "", $config{URLPROXY});
}
}
# end main
###############################################################################
# start iplookup
sub iplookup {
my $ip = shift;
my $cconly = shift;
my $host = "-";
my $iptype = checkip(\$ip);
if ($config{LF_LOOKUPS} and !$cconly) {
my $dnsip;
my $dnsrip;
my $dnshost;
my $cachehit;
open (my $DNS, "<", "/var/lib/csf/csf.dnscache");
flock ($DNS, LOCK_SH);
while (my $line = <$DNS>) {
chomp $line;
($dnsip,$dnsrip,$dnshost) = split(/\|/,$line);
if ($ip eq $dnsip) {
$cachehit = 1;
last;
}
}
close ($DNS);
if ($cachehit) {
$host = $dnshost;
} else {
if (-e $config{HOST} and -x $config{HOST}) {
my $cmdpid;
eval {
local $SIG{__DIE__} = undef;
local $SIG{'ALRM'} = sub {die};
alarm(10);
my ($childin, $childout);
$cmdpid = open3($childin, $childout, $childout, $config{HOST},"-W","5",$ip);
close $childin;
my @results = <$childout>;
waitpid ($cmdpid, 0);
chomp @results;
if ($results[0] =~ /(\S+)\.$/) {$host = $1}
alarm(0);
};
alarm(0);
if ($cmdpid =~ /\d+/ and $cmdpid > 1 and kill(0,$cmdpid)) {kill(9,$cmdpid)}
} else {
if ($iptype == 4) {
eval {
local $SIG{__DIE__} = undef;
local $SIG{'ALRM'} = sub {die};
alarm(10);
my $ipaddr = inet_aton($ip);
$host = gethostbyaddr($ipaddr, AF_INET);
alarm(0);
};
alarm(0);
}
elsif ($iptype == 6) {
eval {
local $SIG{__DIE__} = undef;
local $SIG{'ALRM'} = sub {die};
alarm(10);
eval('use Socket6;'); ##no critic
my $ipaddr = inet_pton(AF_INET6, $ip);
$host = gethostbyaddr($ipaddr, AF_INET6);
alarm(0);
};
alarm(0);
}
}
sysopen (DNS, "/var/lib/csf/csf.dnscache", O_WRONLY | O_APPEND | O_CREAT);
flock (DNS, LOCK_EX);
print DNS "$ip|$ip|$host\n";
close (DNS);
}
if ($host eq "") {$host = "-"}
}
if (($config{CC_LOOKUPS} and $iptype == 4) or ($config{CC_LOOKUPS} and $config{CC6_LOOKUPS} and $iptype == 6)) {
my @result;
eval {
local $SIG{__DIE__} = undef;
@result = &geo_binary($ip,$iptype);
};
my $asn = $result[4];
if ($result[0] eq "") {$result[0] = "-"}
if ($result[1] eq "") {$result[1] = "-"}
if ($result[2] eq "") {$result[2] = "-"}
if ($result[3] eq "") {$result[3] = "-"}
if ($result[4] eq "") {$result[4] = "-"} else {$result[4] = "[$result[4]]"}
if ($config{CC_LOOKUPS} == 3) {
if ($cconly) {return ($result[0],$asn)}
my $return = "$ip ($result[0]/$result[1]/$result[2]/$result[3]/$host/$result[4])";
if ($result[0] eq "-") {$return = "$ip ($host)"}
$return =~ s/'|"//g;
return $return;
}
elsif ($config{CC_LOOKUPS} == 2 or $config{CC_LOOKUPS} == 4) {
if ($cconly) {return $result[0]}
my $return = "$ip ($result[0]/$result[1]/$result[2]/$result[3]/$host)";
if ($result[0] eq "-") {$return = "$ip ($host)"}
$return =~ s/'|"//g;
return $return;
}
else {
if ($cconly) {return $result[0]}
my $return = "$ip ($result[0]/$result[1]/$host)";
if ($result[0] eq "-") {$return = "$ip ($host)"}
$return =~ s/'|"//g;
return $return;
}
}
if ($config{LF_LOOKUPS}) {
if ($host eq "-") {$host = "Unknown"}
my $return = "$ip ($host)";
$return =~ s/'//g;
return $return;
} else {
return $ip;
}
}
# end iplookup
###############################################################################
# start geo_binary
sub geo_binary {
my $myip = shift;
my $ipv = shift;
my @return;
my $netip = Net::IP->new($myip);
my $ip = $netip->binip();
my $type = $netip->iptype();
if ($type eq "PRIVATE") {return}
if ($config{CC_LOOKUPS} == 4) {
my ($status, $text) = $urlget->urlget("http://api.db-ip.com/v2/free/$myip");
if ($status) {$text = ""}
if ($text ne "") {
my $json = JSON::Tiny::decode_json($text);
return ($json->{countryCode},$json->{countryName},$json->{stateProv},$json->{city});
} else {
return;
}
return;
}
if ($config{CC_SRC} eq "" or $config{CC_SRC} eq "1") {
my $file = "/var/lib/csf/Geo/GeoLite2-Country-Blocks-IPv${ipv}.csv";
if ($config{CC_LOOKUPS} == 2 or $config{CC_LOOKUPS} == 3) {
$file = "/var/lib/csf/Geo/GeoLite2-City-Blocks-IPv${ipv}.csv";
}
my $start = 0;
my $end = -s $file;
$end += 4;
my $cnt = 0;
my $last;
my $range;
my $geoid;
open (my $CSV, "<", $file);
flock ($CSV, LOCK_SH);
while (1) {
my $mid = int (($end + $start) / 2);
seek ($CSV, $mid, 0);
my $a = <$CSV>;
my $b = <$CSV>;
chomp $b;
($range,$geoid,undef) = split(/\,/,$b);
if ($range !~ /^\d/ or $range eq $last or $range eq "") {return}
$last = $range;
my $netip = Net::IP->new($range);
my $lastip = $netip->last_ip();
$lastip = Net::IP::ip_iptobin($lastip,$ipv);
my $firstip = $netip->ip();
$firstip = Net::IP::ip_iptobin($firstip,$ipv);
if (Net::IP::ip_bincomp($ip,'lt',$firstip) == 1) {
$end = $mid;
}
elsif (Net::IP::ip_bincomp($ip,'gt',$lastip) == 1) {
$start = $mid;
} else {
last;
}
$cnt++;
if ($cnt > 200) {return}
}
close ($CSV);
if ($geoid > 0) {
my $file = "/var/lib/csf/Geo/GeoLite2-Country-Locations-en.csv";
if ($config{CC_LOOKUPS} == 2 or $config{CC_LOOKUPS} == 3) {
$file = "/var/lib/csf/Geo/GeoLite2-City-Locations-en.csv";
}
my $start = 0;
my $end = -s $file;
$end += 4;
my $cnt = 0;
my $last;
open (my $CSV, "<", $file);
flock ($CSV, LOCK_SH);
while (1) {
my $mid = int (($end + $start) / 2);
seek ($CSV, $mid, 0);
my $a = <$CSV>;
my $b = <$CSV>;
chomp $b;
my @bits = split(/\,/,$b);
if ($range !~ /^\d/ or $bits[0] eq $last or $bits[0] eq "") {last}
$last = $bits[0];
if ($geoid < $bits[0]) {
$end = $mid;
}
elsif ($geoid > $bits[0]) {
$start = $mid + 1;
} else {
$b =~ s/\"//g;
my ($geoname_id, $locale_code, $continent_code, $continent_name, $country_iso_code, $country_name, $subdivision_1_iso_code, $subdivision_1_name, $subdivision_2_iso_code, $subdivision_2_name, $city_name, $metro_code, $time_zone) = split(/\,/,$b);
my $region = $subdivision_2_name;
if ($region eq "" or $region eq $city_name) {$region = $subdivision_1_name}
$return[0] = $country_iso_code;
$return[1] = $country_name;
$return[2] = $region;
$return[3] = $city_name;
last;
}
$cnt++;
if ($cnt > 200) {return}
}
close ($CSV);
}
if ($config{CC_LOOKUPS} == 3) {
my $file = "/var/lib/csf/Geo/GeoLite2-ASN-Blocks-IPv${ipv}.csv";
my $start = 0;
my $end = -s $file;
$end += 4;
my $cnt = 0;
my $last;
my $range;
my $asn;
my $asnorg;
open (my $CSV, "<", $file);
flock ($CSV, LOCK_SH);
while (1) {
my $mid = int (($end + $start) / 2);
seek ($CSV, $mid, 0);
my $a = <$CSV>;
my $b = <$CSV>;
chomp $b;
($range,$asn,$asnorg) = split(/\,/,$b,3);
if ($range !~ /^\d/ or $range eq $last or $range eq "") {last}
$last = $range;
my $netip = Net::IP->new($range);
my $lastip = $netip->last_ip();
$lastip = Net::IP::ip_iptobin($lastip,$ipv);
my $firstip = $netip->ip();
$firstip = Net::IP::ip_iptobin($firstip,$ipv);
if (Net::IP::ip_bincomp($ip,'lt',$firstip) == 1) {
$end = $mid;
}
elsif (Net::IP::ip_bincomp($ip,'gt',$lastip) == 1) {
$start = $mid + 1;
} else {
$return[4] = "AS$asn $asnorg";
last;
}
$cnt++;
if ($cnt > 200) {last}
}
close ($CSV);
}
} elsif ($config{CC_SRC} eq "2") {
my %country_name;
open (my $CC, "<", "/var/lib/csf/Geo/countryInfo.txt");
flock ($CC, LOCK_SH);
foreach my $line (<$CC>) {
if ($line eq "" or $line =~ /^\#/ or $line =~ /^\s/) {next}
my ($cc,undef,undef,undef,$country,undef) = split(/\t/, $line);
if ($cc ne "" and $country ne "") {$country_name{$cc} = $country}
}
close ($CC);
my $file = "/var/lib/csf/Geo/dbip-country-lite.csv";
if ($config{CC_LOOKUPS} == 2 or $config{CC_LOOKUPS} == 3) {
$file = "/var/lib/csf/Geo/dbip-city-lite.csv";
}
my $start = 0;
my $end = -s $file;
$end += 4;
my $cnt = 0;
my $last;
my $range;
my $geoid;
open (my $CSV, "<", $file);
flock ($CSV, LOCK_SH);
while (1) {
my $mid = int (($end + $start) / 2);
seek ($CSV, $mid, 0);
my $a = <$CSV>;
my $b = <$CSV>;
chomp $b;
my ($firstip,$lastip,$cc_lookups1,$country_iso_code,$region,$city_name,undef) = split(/\,/,$b);
if ($firstip eq $lastip or $firstip eq "") {return}
if (checkip(\$firstip) ne $ipv) {
if ($ipv eq "6") {
$start = $mid;
} else {
$end = $mid;
}
} else {
my $netfirstip = Net::IP->new($firstip);
my $firstip = $netfirstip->binip();
my $netlastip = Net::IP->new($lastip);
my $lastip = $netlastip->binip();
if (Net::IP::ip_bincomp($ip,'lt',$firstip) == 1) {
$end = $mid;
}
elsif (Net::IP::ip_bincomp($ip,'gt',$lastip) == 1) {
$start = $mid + 1;
} else {
if ($config{CC_LOOKUPS} == 1) {$country_iso_code = $cc_lookups1}
if ($country_iso_code eq "ZZ") {last}
$return[0] = $country_iso_code;
$return[1] = $country_name{$country_iso_code};
$return[2] = $region;
$return[3] = $city_name;
last;
}
}
$cnt++;
if ($cnt > 200) {return}
}
close ($CSV);
if ($config{CC_LOOKUPS} == 3) {
my $file = "/var/lib/csf/Geo/ip2asn-combined.tsv";
my $start = 0;
my $end = -s $file;
$end += 4;
my $cnt = 0;
my $last;
my $range;
my $asn;
my $asnorg;
open (my $CSV, "<", $file);
flock ($CSV, LOCK_SH);
while (1) {
my $mid = int (($end + $start) / 2);
seek ($CSV, $mid, 0);
my $a = <$CSV>;
my $b = <$CSV>;
chomp $b;
my ($firstip,$lastip,$asn,undef,$asnorg) = split(/\t/,$b);
if ($firstip eq $lastip or $firstip eq "") {last}
if (checkip(\$firstip) ne $ipv) {
if ($ipv eq "6") {
$start = $mid;
} else {
$end = $mid;
}
} else {
my $netfirstip = Net::IP->new($firstip);
my $firstip = $netfirstip->binip();
my $netlastip = Net::IP->new($lastip);
my $lastip = $netlastip->binip();
if (Net::IP::ip_bincomp($ip,'lt',$firstip) == 1) {
$end = $mid;
}
elsif (Net::IP::ip_bincomp($ip,'gt',$lastip) == 1) {
$start = $mid + 1;
} else {
if ($asn eq "0") {last}
$return[4] = "AS$asn $asnorg";
last;
}
}
$cnt++;
if ($cnt > 200) {last}
}
close ($CSV);
}
}
return @return;
}
# end geo_binary
###############################################################################
1; Logger.pm 0000644 00000003526 15103002075 0006320 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::Logger;
use strict;
use lib '/usr/local/csf/lib';
use Carp;
use Fcntl qw(:DEFAULT :flock);
use ConfigServer::Config;
use Exporter qw(import);
our $VERSION = 1.02;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(logfile);
my $config = ConfigServer::Config->loadconfig();
my %config = $config->config();
my $hostname;
if (-e "/proc/sys/kernel/hostname") {
open (my $IN, "<", "/proc/sys/kernel/hostname");
flock ($IN, LOCK_SH);
$hostname = <$IN>;
chomp $hostname;
close ($IN);
} else {
$hostname = "unknown";
}
my $hostshort = (split(/\./,$hostname))[0];
my $sys_syslog;
if ($config{SYSLOG}) {
eval('use Sys::Syslog;'); ##no critic
unless ($@) {$sys_syslog = 1}
}
# end main
###############################################################################
# start logfile
sub logfile {
my $line = shift;
my @ts = split(/\s+/,scalar localtime);
if ($ts[2] < 10) {$ts[2] = " ".$ts[2]}
my $logfile = "/var/log/lfd.log";
if ($< != 0) {$logfile = "/var/log/lfd_messenger.log"}
sysopen (my $LOGFILE, $logfile, O_WRONLY | O_APPEND | O_CREAT);
flock ($LOGFILE, LOCK_EX);
print $LOGFILE "$ts[1] $ts[2] $ts[3] $hostshort lfd[$$]: $line\n";
close ($LOGFILE);
if ($config{SYSLOG} and $sys_syslog) {
eval {
local $SIG{__DIE__} = undef;
openlog('lfd', 'ndelay,pid', 'user');
syslog('info', $line);
closelog();
}
}
return;
}
# end logfile
###############################################################################
1; cseUI.pm 0000644 00000110041 15103002075 0006100 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
package ConfigServer::cseUI;
use strict;
use Fcntl qw(:DEFAULT :flock);
use File::Find;
use File::Copy;
use IPC::Open3;
use Exporter qw(import);
our $VERSION = 2.03;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
umask(0177);
our ($chart, $ipscidr6, $ipv6reg, $ipv4reg, %config, %ips, $mobile,
%FORM, $script, $script_da, $images, $myv);
our ($act, $destpath, $element, $extramessage, $fieldname, $fileinc,
$filetemp, $message, $name, $origpath, $storepath, $tgid, $thisdir,
$tuid, $value, $webpath, %ele, %header, @bits, @dirs, @filebodies,
@filenames, @files, @months, @parts, @passrecs, @thisdirs, @thisfiles,
$files);
#
###############################################################################
# start main
sub main {
my $FORM_ref = shift;
%FORM = %{$FORM_ref};
$fileinc = shift;
$script = shift;
$script_da = shift;
$images = shift;
$myv = shift;
$| = 1;
&loadconfig;
$webpath = '/';
if ($FORM{do} eq "view") {
&view;
exit;
}
print "Content-type: text/html\r\n\r\n";
my $bootstrapcss = "
";
my $jqueryjs = "";
my $bootstrapjs = "";
print <
ConfigServer Explorer
$bootstrapcss
$jqueryjs
$bootstrapjs
EOF
unless ($FORM{do} eq "console") {
print "\n";
print "
\n";
if ($config{UI_CXS} or $config{UI_CSE}) {
print "
\n";
}
print "
cse Logout \n";
print "
\n";
print <
ConfigServer Explorer - cse
EOF
}
$message = "";
if ($fileinc) {&uploadfile}
elsif ($FORM{do} eq "") {&browse}
elsif ($FORM{quit} == 2) {&browse}
elsif ($FORM{do} eq "b") {&browse}
elsif ($FORM{do} eq "p") {&browse}
elsif ($FORM{do} eq "o") {&browse}
elsif ($FORM{do} eq "c") {&browse}
elsif ($FORM{do} eq "m") {&browse}
elsif ($FORM{do} eq "pw") {&browse}
elsif ($FORM{do} eq "r") {&browse}
elsif ($FORM{do} eq "newf") {&browse}
elsif ($FORM{do} eq "newd") {&browse}
elsif ($FORM{do} eq "cnewf") {&cnewf}
elsif ($FORM{do} eq "cnewd") {&cnewd}
elsif ($FORM{do} eq "ren") {&ren}
elsif ($FORM{do} eq "del") {&del}
elsif ($FORM{do} eq "setp") {&setp}
elsif ($FORM{do} eq "seto") {&seto}
elsif ($FORM{do} eq "cd") {&cd}
elsif ($FORM{do} eq "console") {&console}
elsif ($FORM{do} eq "edit") {&edit}
elsif ($FORM{do} eq "Cancel") {&browse}
elsif ($FORM{do} eq "Save") {&save}
elsif ($FORM{do} eq "copyit") {©it}
elsif ($FORM{do} eq "moveit") {&moveit}
else {print "Invalid action"};
unless ($FORM{do} eq "console") {
print "©2006-2023, ConfigServer Services (Way to the Web Limited)
\n";
}
print <
EOF
exit;
}
# end main
###############################################################################
# start browse
sub browse {
my $extra;
if ($FORM{c}) {
if (-e "$webpath$FORM{c}") {
$extra = "&c=$FORM{c}";
} else {
$FORM{c} = "";
}
}
if ($FORM{m}) {
if (-e "$webpath$FORM{m}") {
$extra = "&m=$FORM{m}"
} else {
$FORM{m} = "";
}
}
print "\n";
$thisdir = $webpath;
if ($thisdir !~ /\/$/) {$thisdir .= "/"}
$thisdir .= $FORM{p};
$thisdir =~ s/\/+/\//g;
@months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
my $errordir = 0;
opendir (DIR, "$thisdir") or $errordir = 1;
while (my $file = readdir(DIR)) {
if (-d "$thisdir/$file") {
if ($file !~ /^\.$|^\.\.$/) {push (@thisdirs, $file)}
} else {
push (@thisfiles, $file);
}
}
closedir (DIR);
@thisdirs = sort @thisdirs;
@thisfiles = sort @thisfiles;
print "\n";
print "WARNING! While this utility can be very useful it is also very dangerous indeed. You can easily render your server inoperable and unrecoverable by performing ill advised actions. No warranty or guarantee is provided with the product that protects against system damage.\n";
print "
\n";
if ($message) {print "
$message \n";}
print "\n";
print "";
print "[Home ]";
my $path = "";
my $cnt = 2;
my @path = split(/\//,$FORM{p});
foreach my $dir (@path) {
if ($dir ne "" and ($dir ne "/")) {
if ($cnt == @path) {
print "/$dir";
} else {
print "/$dir ";
}
$path .= "/$dir";
$cnt++;
}
}
if ($FORM{c}) {print " Copy buffer:$FORM{c} \n"}
if ($FORM{m}) {print " Move buffer:$FORM{m} \n"}
print " \n";
if ($errordir) {
print "Permission Denied ";
} else {
if (@thisdirs > 0) {
print "\n";
print "";
print "Directory Name ";
print "Size ";
print "Date ";
print "User(uid)/Group(gid) ";
print "Perms ";
print "Actions ";
print " \n";
}
my $class = "tdshade2";
foreach my $dir (@thisdirs) {
if ($dir =~/'|"|\||\`/) {
print "".quotemeta($dir)."Invalid directory name - ignored ";
next;
}
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$thisdir/$dir");
if ($size < 1024) {
}
elsif ($size < (1024 * 1024)) {
$size = sprintf("%.1f",($size/1024));
$size .= "k";
}
else {
$size = sprintf("%.1f",($size/(1024 * 1024)));
$size .= "M";
}
$mode = sprintf "%04o", $mode & oct("07777");
$tgid = getgrgid($gid);
if ($tgid eq "") {$tgid = $gid}
$tuid = getpwuid($uid);
if ($tuid eq "") {$tuid = $uid}
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mtime);
$year += 1900;
my $time = sprintf "%02d:%02d:%02d", $hour, $min, $sec;
$mday = sprintf "%02d", $mday;
$mtime = "$mday-$months[$mon]-$year $time";
my $pp = "";
my $passfile = "$FORM{p}/$dir";
$passfile =~ s/\//\_/g;
$passfile =~ s/\\/\_/g;
$passfile =~ s/\:/\_/g;
if (-e "$storepath/$passfile.htpasswd") {
open (my $PASSFILE, "<","$storepath/$passfile.htpasswd") or die $!;
flock ($PASSFILE, LOCK_SH);
@passrecs = <$PASSFILE>;
close ($PASSFILE);
chomp @passrecs;
if (@passrecs > 0) {$pp = "**"}
}
print "";
if ($FORM{do} eq "r" and ($FORM{f} eq $dir)) {
print "\n";
}
elsif (-r "$webpath$FORM{p}/$dir") {
print "$dir $pp ";
}
else {
print "$dir ";
}
print "$size ";
print "$mtime ";
if ($FORM{do} eq "o" and ($FORM{f} eq $dir)) {
print "\n";
}
else {
print "$tuid($uid)/$tgid($gid) ";
}
if ($FORM{do} eq "p" and ($FORM{f} eq $dir)) {
print "\n";
}
else {
print "$mode ";
}
print " ";
print " ";
print " ";
print " ";
print " ";
print " \n";
}
if ($FORM{do} eq "newd") {
print "";
print "\n";
print " ";
print " ";
print " ";
print " ";
print " ";
print " \n";
}
if (($FORM{do} eq "c") and (-d "$webpath$FORM{c}")) {
my $newf = (split(/\//,$FORM{c}))[-1];
print "";
print "\n";
print " ";
print " ";
print " ";
print " ";
print " ";
print " \n";
}
if (($FORM{do} eq "m") and (-d "$webpath$FORM{m}")) {
my $newf = (split(/\//,$FORM{m}))[-1];
print "";
print "\n";
print " ";
print " ";
print " ";
print " ";
print " ";
print " \n";
}
if (@thisfiles > 0) {
print " \n";
print "";
print "File Name ";
print "Size ";
print "Date ";
print "User(uid)/Group(gid) ";
print "Perms ";
print "Actions ";
print " \n";
}
$class = "tdshade2";
foreach my $file (@thisfiles) {
if ($file =~/'|"|\||\`/) {
print "".quotemeta($file)."Invalid file name - ignored ";
next;
}
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$thisdir/$file");
if ($size < 1024) {
}
elsif ($size < (1024 * 1024)) {
$size = sprintf("%.1f",($size/1024));
$size .= "k";
}
else {
$size = sprintf("%.1f",($size/(1024 * 1024)));
$size .= "M";
}
$mode = sprintf "%03o", $mode & oct("00777");
$tgid = getgrgid($gid);
if ($tgid eq "") {$tgid = $gid}
$tuid = getpwuid($uid);
if ($tuid eq "") {$tuid = $uid}
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mtime);
$year += 1900;
my $time = sprintf "%02d:%02d:%02d", $hour, $min, $sec;
$mday = sprintf "%02d", $mday;
$mtime = "$mday-$months[$mon]-$year $time";
print "";
if ($FORM{do} eq "r" and ($FORM{f} eq $file)) {
print "\n";
}
else {
$act = "$script?do=view&p=$FORM{p}&f=$file$extra\#new";
print "$file ";
}
print "$size ";
print "$mtime ";
if ($FORM{do} eq "o" and ($FORM{f} eq $file)) {
print "\n";
}
else {
print "$tuid($uid)/$tgid($gid) ";
}
if ($FORM{do} eq "p" and ($FORM{f} eq $file)) {
print "\n";
}
else {
print "$mode ";
}
my $ext = (split(/\./,$file))[-1];
if (-T "$webpath$FORM{p}/$file") {
my $act = "";
print " $act ";
} else {
print " ";
}
print " ";
print " ";
print " ";
print " ";
print " \n";
}
if ($FORM{do} eq "newf") {
print "";
print "\n";
print " ";
print " ";
print " ";
print " ";
print " ";
print " \n";
}
if (($FORM{do} eq "c") and (-f "$webpath$FORM{c}")) {
my $newf = (split(/\//,$FORM{c}))[-1];
print "";
print "\n";
print " ";
print " ";
print " ";
print " ";
print " ";
print " \n";
}
if (($FORM{do} eq "m") and (-f "$webpath$FORM{m}")) {
my $newf = (split(/\//,$FORM{m}))[-1];
print "";
print "\n";
print " ";
print " ";
print " ";
print " ";
print " ";
print " \n";
}
}
print "
\n";
print "All the following actions apply to the current directory
\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
return;
}
# end browse
###############################################################################
# start setp
sub setp {
my $status = 0;
chmod (oct("0$FORM{newp}"),"$webpath$FORM{p}/$FORM{f}") or $status = $!;
if ($status) {$message = "Operation Failed - $status"} else {$message = ""}
&browse;
return;
}
# end setp
###############################################################################
# start seto
sub seto {
my $status = "";
my ($uid,$gid) = split (/\:/,$FORM{newo});
if ($uid !~ /^\d/) {$uid = (getpwnam($uid))[2]}
if ($gid !~ /^\d/) {$gid = (getgrnam($gid))[2]}
if ($uid eq "") {$message .= "No such user \n"}
if ($gid eq "") {$message .= "No such group \n"}
if ($message eq "") {
chown ($uid,$gid,"$webpath$FORM{p}/$FORM{f}") or $status = $!;
if ($status) {$message = "Operation Failed - $status"} else {$message = ""}
}
&browse;
return;
}
# end seto
###############################################################################
# start ren
sub ren {
my $status = 0;
rename ("$webpath$FORM{p}/$FORM{f}","$webpath$FORM{p}/$FORM{newf}") or $status = $!;
if ($status) {$message = "Operation Failed - $status"} else {$message = ""}
&browse;
return;
}
# end ren
###############################################################################
# start moveit
sub moveit {
if ("$webpath$FORM{m}" eq "$webpath$FORM{p}/$FORM{newf}") {
$message = "Move Failed - Cannot overwrite original";
}
elsif ((-d "$webpath$FORM{m}") and ("$webpath$FORM{p}/$FORM{newf}" =~ /^$webpath$FORM{m}\//)) {
$message = "Move Failed - Cannot move inside original";
}
else {
my $status = 0;
rename ("$webpath$FORM{m}","$webpath$FORM{p}/$FORM{newf}") or $status = $!;
if ($status) {$message = "Operation Failed - $status"} else {$message = ""}
}
if ($message eq "") {$FORM{m} = ""}
&browse;
return;
}
# end moveit
###############################################################################
# start copyit
sub copyit {
if ("$webpath$FORM{c}" eq "$webpath$FORM{p}/$FORM{newf}") {
$message = "Copy Failed - Cannot overwrite original";
}
elsif ((-d "$webpath$FORM{c}") and ("$webpath$FORM{p}/$FORM{newf}" =~ /^$webpath$FORM{c}\//)) {
$message = "Copy Failed - Cannot copy inside original";
}
else {
if (-d "$webpath$FORM{c}") {
$origpath = "$webpath$FORM{c}";
$destpath = "$webpath$FORM{p}/$FORM{newf}";
find(\&mycopy, $origpath);
} else {
copy ("$webpath$FORM{c}","$webpath$FORM{p}/$FORM{newf}") or $message = "Copy Failed - $!";
if ($message eq "") {
my $mode = sprintf "%04o", (stat("$webpath$FORM{c}"))[2] & oct("00777");
chmod (oct($mode),"$webpath$FORM{p}/$FORM{newf}") or $message = "Permission Change Failed - $!";
}
}
}
if ($message eq "") {$FORM{c} = ""}
&browse;
return;
}
# end copyit
###############################################################################
# start mycopy
sub mycopy {
my $file = $File::Find::name;
(my $dest = $file) =~ s/^\Q$origpath/$destpath/;
my $status = "";
if (-d $file) {
my $err = (split(/\//,$dest))[-1];
mkpath ($dest) or $status = "Copy Failed Making New Dir [$err] - $! \n";
} elsif (-f $file) {
my $err = (split(/\//,$file))[-1];
copy ($file,$dest) or $status = "Copy Failed [$err] - $! \n";
}
if ($status eq "") {
my $err = (split(/\//,$file))[-1];
my $mode = sprintf "%04o", (stat("$file"))[2] & oct("00777");
chmod (oct($mode),"$dest") or $message .= "Copy Failed Setting Perms [$err] - $! \n";
} else {
$message .= $status;
}
return;
}
# end mycopy
###############################################################################
# start cnewd
sub cnewd {
my $status = 0;
if ($FORM{newf} ne "") {
mkdir ("$webpath$FORM{p}/$FORM{newf}",0777) or $status = $!;
}
if ($status) {$message = "Operation Failed - $status"} else {$message = ""}
&browse;
return;
}
# end cnewd
###############################################################################
# start cnewf
sub cnewf {
my $status = 0;
if ($FORM{newf} ne "") {
if (-f "$webpath$FORM{p}/$FORM{newf}") {
$status = "File exists";
} else {
open (my $OUT, ">","$webpath$FORM{p}/$FORM{newf}") or $status = $!;
flock ($OUT, LOCK_EX);
close ($OUT);
}
}
if ($status) {$message = "Operation Failed - $status"} else {$message = ""}
&browse;
return;
}
# end cnewf
###############################################################################
# start del
sub del {
my $status = 0;
if (-d "$webpath$FORM{p}/$FORM{f}") {
rmtree("$webpath$FORM{p}/$FORM{f}", 0, 0) or $status = $!;
} else {
unlink ("$webpath$FORM{p}/$FORM{f}") or $status = $!;
}
if ($status) {$message = "Operation Failed - $status"} else {$message = ""}
&browse;
return;
}
# end del
###############################################################################
# start view
sub view {
if (-e "$webpath$FORM{p}/$FORM{f}" ) {
if (-T "$webpath$FORM{p}/$FORM{f}") {
print "content-type: text/plain\r\n";
} else {
print "content-type: application/octet-stream\r\n";
}
print "content-disposition: attachment; filename=$FORM{f}\r\n\r\n";
open(my $IN,"<","$webpath$FORM{p}/$FORM{f}") or die $!;
flock ($IN, LOCK_SH);
while (<$IN>) {print}
close($IN);
}else{
print "content-type: text/html\r\n\r\n";
print "File [$webpath$FORM{p}/$FORM{f}] not found!";
}
return;
}
# end view
###############################################################################
# start console
sub console {
my $thisdir = "$webpath$FORM{p}";
$thisdir =~ s/\/+/\//g;
print "
\n";
print "root [$thisdir]# $FORM{cmd}\n";
chdir $thisdir;
$| = 1;
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, $FORM{cmd});
while (my $line = <$childout>) {
$line =~ s/\\<\;/g;
$line =~ s/\>/\>\;/g;
print $line;
}
waitpid ($cmdpid, 0);
print "root [$thisdir]# _ \n";
print "";
return;
}
# end console
###############################################################################
# start cd
sub cd {
if (-d $FORM{directory}) {
$FORM{p} = $FORM{directory};
} else {
$message = "No such directory [$FORM{directory}]";
}
&browse;
return;
}
# end cd
###############################################################################
# start edit
sub edit {
open (my $IN, "<","$webpath$FORM{p}/$FORM{f}") or die $!;
flock ($IN, LOCK_SH);
my @data = <$IN>;
close ($IN);
my $filedata;
foreach my $line (@data) {
$line =~ s/\</g;
$line =~ s/\>/>/g;
$filedata .= $line;
}
my $lf = 0;
if ($filedata =~ /\r/) {$lf = 1}
print "\n";
print "\n";
return;
}
# end edit
###############################################################################
# start save
sub save {
unless ($FORM{lf}) {$FORM{newf} =~ s/\r//g}
my $status = 0;
open (my $OUT, ">","$webpath$FORM{p}/$FORM{f}") or $status = $!;
flock ($OUT, LOCK_EX);
print $OUT $FORM{newf};
close ($OUT);
if ($status) {$message = "Operation Failed - $status"} else {$message = ""}
&browse;
return;
}
# end save
###############################################################################
# start uploadfile
sub uploadfile {
my $crlf = "\r\n";
my @data = split (/$crlf/,$fileinc);
my $boundary = $data[0];
$boundary =~ s/\"//g;
$boundary =~ s/$crlf//g;
my $start = 0;
my $part_cnt=-1;
undef @parts;
my $fileno = 0;
foreach my $line (@data) {
if ($line =~ /^$boundary--/) {
last;
}
if ($line =~ /^$boundary/) {
$part_cnt++;
$start = 1;
next;
}
if ($start) {
$parts[$part_cnt] .= $line.$crlf;
}
}
foreach my $part (@parts) {
my @partdata = split(/$crlf/,$part);
undef %header;
my $body = "";
my $dobody = 0;
my $lastfieldname = "";
foreach my $line (@partdata) {
if (($line eq "") and !($dobody)) {
$dobody = 1;
next;
}
if ($dobody) {
$body .= $line.$crlf;
} else {
if ($line =~ /^\s/) {
$header{$lastfieldname} .= $line;
} else {
($fieldname, $value) = split (/\:\s/,$line,2);
$fieldname = lc $fieldname;
$fieldname =~ s/-/_/g;
$header{$fieldname} = $value;
$lastfieldname = $fieldname;
}
}
}
my @elements = split(/\;/,$header{content_disposition});
foreach my $element (@elements) {
$element =~ s/\s//g;
$element =~ s/\"//g;
($name,$value) = split(/\=/,$element);
$FORM{$value} = $body;
$ele{$name} = $value;
$ele{$ele{name}} = $value;
if ($value =~ /^file(.*)$/) {$files = $1}
}
my $filename = $ele{"file$files"};
if ($filename ne "") {
$fileno++;
$filename =~ s/\"//g;
$filename =~ s/\r//g;
$filename =~ s/\n//g;
@bits = split(/\\/,$filename);
$filetemp=$bits[-1];
@bits = split(/\//,$filetemp);
$filetemp=$bits[-1];
@bits = split(/\:/,$filetemp);
$filetemp=$bits[-1];
@bits = split(/\"/,$filetemp);
$filename=$bits[0];
push (@filenames, $filename);
push (@filebodies, $body);
}
}
$FORM{p} =~ s/\r//g;
$FORM{p} =~ s/\n//g;
$FORM{type} =~ s/\r//g;
$FORM{type} =~ s/\n//g;
$FORM{c} =~ s/\r//g;
$FORM{c} =~ s/\n//g;
$FORM{m} =~ s/\r//g;
$FORM{m} =~ s/\n//g;
$FORM{caller} =~ s/\r//g;
$FORM{caller} =~ s/\n//g;
for (my $x = 0;$x < @filenames ;$x++) {
$filenames[$x] =~ s/\r//g;
$filenames[$x] =~ s/\n//g;
$filenames[$x] =~ s/^file-//g;
$filenames[$x] = (split (/\\/,$filenames[$x]))[-1];
$filenames[$x] = (split (/\//,$filenames[$x]))[-1];
if ($FORM{type} eq "ascii") {$filebodies[$x] =~ s/\r//g}
if (-e "$webpath$FORM{p}/$filenames[$x]") {
$extramessage .= " $filenames[$x] - Already exists, delete the original first";
$fileno--;
next;
}
sysopen (my $OUT,"$webpath$FORM{p}/$filenames[$x]", O_WRONLY | O_CREAT);
flock ($OUT, LOCK_EX);
print $OUT $filebodies[$x];
close ($OUT);
$extramessage .= " $filenames[$x] - Uploaded";
}
$message = "$fileno File(s) Uploaded".$extramessage;
&browse;
return;
}
# end uploadfile
###############################################################################
# start countfiles
sub countfiles {
if (-d $File::Find::name) {push (@dirs, $File::Find::name)} else {push (@files, $File::Find::name)}
return;
}
# end countfiles
###############################################################################
# loadconfig
sub loadconfig {
sysopen (my $IN, "/etc/csf/csf.conf", O_RDWR | O_CREAT) or die "Unable to open file: $!";
flock ($IN, LOCK_SH);
my @config = <$IN>;
close ($IN);
chomp @config;
foreach my $line (@config) {
if ($line =~ /^\#/) {next}
if ($line !~ /=/) {next}
my ($name,$value) = split (/=/,$line,2);
$name =~ s/\s//g;
if ($value =~ /\"(.*)\"/) {
$value = $1;
} else {
&error(__LINE__,"Invalid configuration line");
}
$config{$name} = $value;
}
return;
}
# end loadconfig
###############################################################################
1;
RBLCheck.pm 0000644 00000015431 15103002075 0006454 0 ustar 00 ###############################################################################
# Copyright 2006-2023, Way to the Web Limited
# URL: http://www.configserver.com
# Email: sales@waytotheweb.com
###############################################################################
## no critic (RequireUseWarnings, ProhibitExplicitReturnUndef, ProhibitMixedBooleanOperators, RequireBriefOpen)
# start main
package ConfigServer::RBLCheck;
use strict;
use lib '/usr/local/csf/lib';
use Fcntl qw(:DEFAULT :flock);
use ConfigServer::Config;
use ConfigServer::CheckIP qw(checkip);
use ConfigServer::Slurp qw(slurp);
use ConfigServer::GetIPs qw(getips);
use ConfigServer::RBLLookup qw(rbllookup);
use IPC::Open3;
use Net::IP;
use ConfigServer::GetEthDev;
use Exporter qw(import);
our $VERSION = 1.01;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
my ($ui, $failures, $verbose, $cleanreg, $status, %ips, $images, %config,
$ipresult, $output);
my $ipv4reg = ConfigServer::Config->ipv4reg;
my $ipv6reg = ConfigServer::Config->ipv6reg;
# end main
###############################################################################
# start report
sub report {
$verbose = shift;
$images = shift;
$ui = shift;
my $config = ConfigServer::Config->loadconfig();
%config = $config->config();
$cleanreg = ConfigServer::Slurp->cleanreg;
$failures = 0;
$| = 1;
&startoutput;
&getethdev;
my @RBLS = slurp("/usr/local/csf/lib/csf.rbls");
if (-e "/etc/csf/csf.rblconf") {
my @entries = slurp("/etc/csf/csf.rblconf");
foreach my $line (@entries) {
if ($line =~ /^Include\s*(.*)$/) {
my @incfile = slurp($1);
push @entries,@incfile;
}
}
foreach my $line (@entries) {
$line =~ s/$cleanreg//g;
if ($line eq "") {next}
if ($line =~ /^\s*\#|Include/) {next}
if ($line =~ /^enablerbl:(.*)$/) {
push @RBLS, $1;
}
elsif ($line =~ /^disablerbl:(.*)$/) {
my $hit = $1;
for (0..@RBLS) {
my $x = $_;
my ($rbl,$rblurl) = split(/:/,$RBLS[$x],2);
if ($rbl eq $hit) {$RBLS[$x] = ""}
}
}
if ($line =~ /^enableip:(.*)$/) {
if (checkip(\$1)) {$ips{$1} = 1}
}
elsif ($line =~ /^disableip:(.*)$/) {
if (checkip(\$1)) {delete $ips{$1}}
}
}
}
@RBLS = sort @RBLS;
foreach my $ip (sort keys %ips) {
my $netip = Net::IP->new($ip);
my $type = $netip->iptype();
if ($type eq "PUBLIC") {
if ($verbose and -e "/var/lib/csf/${ip}.rbls") {
unlink "/var/lib/csf/${ip}.rbls";
}
if (-e "/var/lib/csf/${ip}.rbls") {
my $text = join("\n",slurp("/var/lib/csf/${ip}.rbls"));
if ($ui) {print $text} else {$output .= $text}
} else {
if ($verbose) {
$ipresult = "";
my $hits = 0;
&addtitle("Checked $ip ($type) on ".localtime());
foreach my $line (@RBLS) {
my ($rbl,$rblurl) = split(/:/,$line,2);
if ($rbl eq "") {next}
my ($rblhit,$rbltxt) = rbllookup($ip,$rbl);
my @tmptxt = $rbltxt;
$rbltxt = "";
foreach my $line (@tmptxt) {
$line =~ s/(http(\S+))/$1<\/a>/g;
$rbltxt .= "${line}\n";
}
$rbltxt =~ s/\n/ \n/g;
if ($rblhit eq "timeout") {
&addline(0,$rbl,$rblurl,"TIMEOUT");
}
elsif ($rblhit eq "") {
if ($verbose == 2) {
&addline(0,$rbl,$rblurl,"OK");
}
}
else {
&addline(1,$rbl,$rblurl,$rbltxt);
$hits++;
}
}
unless ($hits) {
my $text;
$text .= "OK
\n";
if ($ui) {print $text} else {$output .= $text}
$ipresult .= $text;
}
sysopen (my $OUT, "/var/lib/csf/${ip}.rbls", O_WRONLY | O_CREAT);
flock($OUT, LOCK_EX);
print $OUT $ipresult;
close ($OUT);
} else {
&addtitle("New $ip ($type)");
my $text;
$text .= "Not Checked
\n";
if ($ui) {print $text} else {$output .= $text}
}
}
} else {
if ($verbose == 2) {
&addtitle("Skipping $ip ($type)");
my $text;
$text .= "OK
\n";
if ($ui) {print $text} else {$output .= $text}
}
}
}
&endoutput;
return ($failures,$output);
}
# end report
###############################################################################
# start startoutput
sub startoutput {
return;
}
# end startoutput
###############################################################################
# start addline
sub addline {
my $status = shift;
my $rbl = shift;
my $rblurl = shift;
my $comment = shift;
my $text;
my $check = $rbl;
if ($rblurl ne "") {$check = " $rbl "}
if ($status) {
$text .= "\n";
$text .= "
$check
\n";
$text .= "
$comment
\n";
$text .= "
\n";
$failures ++;
$ipresult .= $text;
}
elsif ($verbose) {
$text .= "\n";
$text .= "
$check
\n";
$text .= "
$comment
\n";
$text .= "
\n";
}
if ($ui) {print $text} else {$output .= $text}
return;
}
# end addline
###############################################################################
# start addtitle
sub addtitle {
my $title = shift;
my $text;
$text .= "$title
\n";
$ipresult .= $text;
if ($ui) {print $text} else {$output .= $text}
return;
}
# end addtitle
###############################################################################
# start endoutput
sub endoutput {
if ($ui) {print " \n"} else {$output .= " \n"}
return;
}
# end endoutput
###############################################################################
# start getethdev
sub getethdev {
my $ethdev = ConfigServer::GetEthDev->new();
my %g_ipv4 = $ethdev->ipv4;
my %g_ipv6 = $ethdev->ipv6;
foreach my $key (keys %g_ipv4) {
$ips{$key} = 1;
}
# if ($config{IPV6}) {
# foreach my $key (keys %g_ipv6) {
# eval {
# local $SIG{__DIE__} = undef;
# $ipscidr6->add($key);
# };
# }
# }
return;
}
# end getethdev
###############################################################################
1;
\n/g; print "$line
\n"; } } print "