asda?‰PNG
IHDR ? f ??C1 sRGB ??é gAMA ±?üa pHYs ? ??o¨d GIDATx^íüL”÷e÷Y?a?("Bh?_ò???¢§?q5k?*:t0A-o??¥]VkJ¢M??f?±8\k2íll£1]q?ù???T
PK \e[6t)> > Slurp.pmnu [ ###############################################################################
# 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::Slurp;
use strict;
use lib '/usr/local/csf/lib';
use Fcntl qw(:DEFAULT :flock);
use Carp;
use Exporter qw(import);
our $VERSION = 1.02;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(slurp);
our $slurpreg = qr/(?>\x0D\x0A?|[\x0A-\x0C\x85\x{2028}\x{2029}])/;
our $cleanreg = qr/(\r)|(\n)|(^\s+)|(\s+$)/;
# end main
###############################################################################
# start slurp
sub slurp {
my $file = shift;
if (-e $file) {
sysopen (my $FILE, $file, O_RDONLY) or carp "*Error* Unable to open [$file]: $!";
flock ($FILE, LOCK_SH) or carp "*Error* Unable to lock [$file]: $!";
my $text = do {local $/; <$FILE>};
close ($FILE);
return split(/$slurpreg/,$text);
} else {
carp "*Error* File does not exist: [$file]";
}
return;
}
# end slurp
###############################################################################
# start slurpreg
sub slurpreg {
return $slurpreg;
}
# end slurpreg
###############################################################################
# start cleanreg
sub cleanreg {
return $cleanreg;
}
# end cleanreg
###############################################################################
1;PK \e[7 Messenger.pmnu [ ###############################################################################
# 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::Messenger;
use strict;
use lib '/usr/local/csf/lib';
use Fcntl qw(:DEFAULT :flock);
use File::Copy;
use JSON::Tiny;
use IO::Socket::INET;
use Net::CIDR::Lite;
use Net::IP;
use IPC::Open3;
use ConfigServer::Config;
use ConfigServer::CheckIP qw(checkip);
use ConfigServer::Logger qw(logfile);
use ConfigServer::URLGet;
use ConfigServer::Slurp qw(slurp);
use ConfigServer::GetIPs qw(getips);
use ConfigServer::GetEthDev;
use Exporter qw(import);
our $VERSION = 3.00;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
my $slurpreg = ConfigServer::Slurp->slurpreg;
my $cleanreg = ConfigServer::Slurp->cleanreg;
my $config = ConfigServer::Config->loadconfig();
my %config = $config->config();
my $ipv4reg = ConfigServer::Config->ipv4reg;
my $ipv6reg = ConfigServer::Config->ipv6reg;
my $childproc;
my $hostname;
my %ips;
my $ipscidr6;
my %sslcerts;
my %sslkeys;
my %ssldomains;
my @ssldomainkeys;
my $webserver = "apache";
my $sslhost;
my $sslcert;
my $sslkey;
my $sslca;
my $osslcert;
my $osslkey;
my $osslca;
my $sslaliases;
my $litestart = 0;
my $ssldir = "/var/lib/csf/ssl/";
my $phphandler;
my $version = 1;
my $serverroot;
# end main
###############################################################################
# start init
sub init {
my $class = shift;
$version = shift;
my $self = {};
bless $self,$class;
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 ($version == 1) {
if ($config{MESSENGER6}) {
eval('use IO::Socket::INET6;'); ##no critic
if ($@) {$config{MESSENGER6} = "0"}
}
$ipscidr6 = Net::CIDR::Lite->new;
&getethdev;
foreach my $ip (split(/,/,$config{RECAPTCHA_NAT})) {
$ip =~ s/\s*//g;
$ips{$ip} = 1;
}
}
elsif ($version == 2) {
}
elsif ($version == 3) {
mkdir $ssldir;
mkdir $ssldir."certs/";
mkdir $ssldir."keys/";
mkdir $ssldir."ca/";
}
return $self;
}
# end init
###############################################################################
# start start
sub start {
my $self = shift;
my $port = shift;
my $user = shift;
my $type = shift;
my $status;
my $reason;
if ($version == 1) {
($status,$reason) = &messenger($port, $user, $type);
}
elsif ($version == 2) {
($status,$reason) = &messengerv2();
}
elsif ($version == 3) {
($status,$reason) = &messengerv3();
}
return ($status,$reason);
}
# end start
###############################################################################
# start messenger
sub messenger {
my $port = shift;
my $user = shift;
my $type = shift;
my $oldtype = $type;
my $server;
my %sslcerts;
my %sslkeys;
$SIG{CHLD} = 'IGNORE';
$SIG{INT} = \&childcleanup;
$SIG{TERM} = \&childcleanup;
$SIG{HUP} = \&childcleanup;
$SIG{__DIE__} = sub {&childcleanup(@_);};
$0 = "lfd $type messenger";
$childproc = "Messenger ($type)";
if ($type eq "HTTPS") {
eval {
local $SIG{__DIE__} = undef;
require IO::Socket::SSL;
import IO::Socket::SSL;
};
my $start = 0;
my $sslhost;
my $sslcert;
my $sslkey;
my $sslaliases;
my %messengerports;
foreach my $serverports (split(/\,/,$config{MESSENGER_HTTPS_IN})) {$messengerports{$serverports} = 1}
foreach my $file (glob($config{MESSENGER_HTTPS_CONF})) {
if (-e $file) {
foreach my $line (slurp($file)) {
$line =~ s/\'|\"//g;
if ($line =~ /^\s*]+>/) {
$start = 1;
}
if ($webserver eq "apache" and $start) {
if ($line =~ /\s*ServerName\s+(\w+:\/\/)?([a-zA-Z0-9\.\-]+)(:\d+)?/) {$sslhost = $2}
if ($line =~ /\s*ServerAlias\s+(.*)/) {$sslaliases .= " ".$1}
if ($line =~ /\s*SSLCertificateFile\s+(\S+)/) {
my $match = $1;
if (-e $match) {$sslcert = $match}
}
if ($line =~ /\s*SSLCertificateKeyFile\s+(\S+)/) {
my $match = $1;
if (-e $match) {$sslkey = $match}
}
}
if (($webserver eq "apache" and $line =~ /^\s*<\/VirtualHost\s*>/)) {
$start = 0;
if ($sslhost ne "" and !checkip($sslhost) and $sslcert ne "") {
$sslcerts{$sslhost} = $sslcert;
if ($sslkey eq "") {$sslkey = $sslcert}
$sslkeys{$sslhost} = $sslkey;
foreach my $alias (split(/\s+/,$sslaliases)) {
if ($alias eq "") {next}
if (checkip($alias)) {next}
if ($alias =~ /^[a-zA-Z0-9\.\-]+$/) {
if ($config{MESSENGER_HTTPS_SKIPMAIL} and $alias =~ /^mail\./) {next}
$sslcerts{$alias} = $sslcert;
$sslkeys{$alias} = $sslkey;
}
}
}
$sslhost = "";
$sslcert = "";
$sslkey = "";
$sslaliases = "";
}
}
}
}
if (scalar(keys %sslcerts < 1)) {
return (1, "No SSL certs found in MESSENGER_HTTPS_CONF location");
}
if (-e $config{MESSENGER_HTTPS_KEY}) {
$sslkeys{''} = $config{MESSENGER_HTTPS_KEY};
}
if (-e $config{MESSENGER_HTTPS_CRT}) {
$sslcerts{''} = $config{MESSENGER_HTTPS_CRT};
}
if ($config{DEBUG} >= 1) {
foreach my $key (keys %sslcerts) {
logfile("SSL: [$key] [$sslcerts{$key}] [$sslkeys{$key}]");
}
}
eval {
local $SIG{__DIE__} = undef;
if ($config{MESSENGER6}) {
$server = IO::Socket::SSL->new(
Domain => AF_INET6,
LocalPort => $port,
Type => SOCK_STREAM,
ReuseAddr => 1,
Listen => $config{MESSENGER_CHILDREN},
SSL_server => 1,
SSL_use_cert => 1,
SSL_cert_file => \%sslcerts,
SSL_key_file => \%sslkeys,
) or &error("MESSENGER: *Error* cannot open server on port $port: ".IO::Socket::SSL->errstr);
} else {
$server = IO::Socket::SSL->new(
Domain => AF_INET,
LocalPort => $port,
Type => SOCK_STREAM,
ReuseAddr => 1,
Listen => $config{MESSENGER_CHILDREN},
SSL_server => 1,
SSL_use_cert => 1,
SSL_cert_file => \%sslcerts,
SSL_key_file => \%sslkeys,
) or &error("MESSENGER: *Error* cannot open server on port $port: ".IO::Socket::SSL->errstr);
}
&logfile("Messenger HTTPS Service started for ".scalar(keys %sslcerts)." domains");
$type = "HTML";
};
if ($@) {
return (1, $@);
}
}
elsif ($config{MESSENGER6}) {
$server = IO::Socket::INET6->new(
LocalPort => $port,
Type => SOCK_STREAM,
ReuseAddr => 1,
Listen => $config{MESSENGER_CHILDREN}) or &childcleanup(__LINE__,"*Error* cannot open server on port $port: $!");
} else {
$server = IO::Socket::INET->new(
LocalPort => $port,
Type => SOCK_STREAM,
ReuseAddr => 1,
Listen => $config{MESSENGER_CHILDREN}) or &childcleanup(__LINE__,"*Error* cannot open server on port $port: $!");
}
my $index;
if ($type eq "HTML" and $config{RECAPTCHA_SITEKEY} ne "") {$index = "/etc/csf/messenger/index.recaptcha.html"}
elsif ($type eq "HTML") {$index = "/etc/csf/messenger/index.html"}
else {$index = "/etc/csf/messenger/index.text"}
open (my $IN, "<", $index);
flock ($IN, LOCK_SH);
my @message = <$IN>;
close ($IN);
chomp @message;
my %images;
if ($type eq "HTML") {
opendir (DIR, "/etc/csf/messenger");
foreach my $file (readdir(DIR)) {
if ($file =~ /\.(gif|png|jpg)$/) {
open (my $IN, "<", "/etc/csf/messenger/$file");
flock ($IN, LOCK_SH);
my @data = <$IN>;
close ($IN);
chomp @data;
foreach my $line (@data) {
$images{$file} .= "$line\n";
}
}
}
closedir (DIR);
}
my $chldallow = $config{MESSENGER_CHILDREN};
if ($oldtype eq "HTTPS") {
open (my $STATUS,"<", "/proc/$$/status") or next;
flock ($STATUS, LOCK_SH);
my @status = <$STATUS>;
close ($STATUS);
chomp @status;
my $vmsize = 0;
my $vmrss = 0;
foreach my $line (@status) {
if ($line =~ /^VmSize:\s+(\d+) kB$/) {$vmsize = $1}
if ($line =~ /^VmRSS:\s+(\d+) kB$/) {$vmrss = $1}
}
logfile("lfd $oldtype messenger using $vmrss kB of RSS memory at startup, adding up to $config{MESSENGER_CHILDREN} children = ".(($config{MESSENGER_CHILDREN} + 1) * $vmrss)." kB");
logfile("lfd $oldtype messenger using $vmsize kB of VIRT memory at startup, adding up to $config{MESSENGER_CHILDREN} children = ".(($config{MESSENGER_CHILDREN} + 1) * $vmsize)." kB");
}
if ($user ne "") {
my (undef,undef,$uid,$gid,undef,undef,undef,$homedir) = getpwnam($user);
if (($uid > 0) and ($gid > 0)) {
local $( = $gid;
local $) = "$gid $gid";
local $> = local $< = $uid;
if (($) != $gid) or ($> != $uid) or ($( != $gid) or ($< != $uid)) {
logfile("MESSENGER_USER unable to drop privileges - stopping $oldtype Messenger");
exit;
}
my %children;
while (1) {
while (my $client = $server->accept()) {
while (scalar (keys %children) >= $chldallow) {
sleep 1;
foreach my $pid (keys %children) {
unless (kill(0,$pid)) {delete $children{$pid}}
}
$0 = "lfd $oldtype messenger (busy)";
}
$0 = "lfd $oldtype messenger";
$SIG{CHLD} = 'IGNORE';
my $pid = fork;
$children{$pid} = 1;
if ($pid == 0) {
eval {
local $SIG{__DIE__} = undef;
local $SIG{'ALRM'} = sub {die};
alarm(10);
close $server;
$0 = "lfd $oldtype messenger client";
binmode $client;
$| = 1;
my $firstline;
my $hostaddress = $client->sockhost();
my $peeraddress = $client->peerhost();
$peeraddress =~ s/^::ffff://;
$hostaddress =~ s/^::ffff://;
if ($type eq "HTML") {
while ($firstline !~ /\n$/) {
my $char;
$client->read($char,1);
$firstline .= $char;
if ($char eq "") {exit}
if (length $firstline > 2048) {last}
}
chomp $firstline;
if ($firstline =~ /\r$/) {chop $firstline}
}
&messengerlog($homedir,"Client connection [$peeraddress] [$firstline]");
my $error;
my $success;
my $failure;
if (($type eq "HTML") and ($firstline =~ /^GET \/unblk\?g-recaptcha-response=(\S+)/i)) {
my $recv = $1;
my $status = 1;
my $text;
eval {
local $SIG{__DIE__} = undef;
eval("no lib '/usr/local/csf/lib'");
my $urlget = ConfigServer::URLGet->new(2, "", $config{URLPROXY});
my $url = "https://www.google.com/recaptcha/api/siteverify?secret=$config{RECAPTCHA_SECRET}&response=$recv";
($status, $text) = $urlget->urlget($url);
};
if ($status) {
&messengerlog($homedir,"*Error*, ReCaptcha ($peeraddress): $text");
if ($config{DEBUG} >= 1) {
if ($@) {$error .= "Error:".$@}
if ($!) {$error .= "Error:".$!}
$error .= " Error Status: $status";
}
$error .= "Unable to verify with Google reCAPTCHA";
} else {
my $resp = JSON::Tiny::decode_json($text);
if ($resp->{success}) {
my $ip = $resp->{hostname};
unless ($ip =~ /^($ipv4reg|$ipv6reg)$/) {$ip = (getips($ip))[0]}
if ($ips{$ip} or $ip eq $hostaddress or $ipscidr6->find($ip)) {
sysopen (my $UNBLOCK, "$homedir/unblock.txt", O_WRONLY | O_APPEND | O_CREAT) or $error .= "Unable to write to [$homedir/unblock.txt] (make sure that MESSENGER_USER has a home directory)";
flock($UNBLOCK, LOCK_EX);
print $UNBLOCK "$peeraddress;$resp->{hostname};$ip\n";
close ($UNBLOCK);
$success = 1;
&messengerlog($homedir,"*Success*, ReCaptcha ($peeraddress): [$resp->{hostname} ($ip)] requested unblock");
} else {
$error .= "Failed, [$resp->{hostname} ($ip)] does not appear to be hosted on this server.";
&messengerlog($homedir,"*Failed*, ReCaptcha ($peeraddress): [$resp->{hostname} ($ip)] does not appear to be hosted on this server");
}
} else {
$failure = 1;
my @codes = @{$resp->{'error-codes'}};
&messengerlog($homedir,"*Failure*, ReCaptcha ($peeraddress): [$codes[0]]");
}
}
}
if (($type eq "HTML") and ($firstline =~ /^GET\s+(\S*\/)?(\S*\.(gif|png|jpg))\s+/i)) {
my $type = $3;
if ($type eq "jpg") {$type = "jpeg"}
print $client "HTTP/1.1 200 OK\r\n";
print $client "Content-type: image/$type\r\n";
print $client "\r\n";
print $client $images{$2};
} else {
if ($type eq "HTML") {
print $client "HTTP/1.1 403 OK\r\n";
print $client "Content-type: text/html\r\n";
print $client "\r\n";
foreach my $line (@message) {
if ($line =~ /\[IPADDRESS\]/) {$line =~ s/\[IPADDRESS\]/$peeraddress/}
if ($line =~ /\[HOSTNAME\]/) {$line =~ s/\[HOSTNAME\]/$hostname/}
if ($line =~ /\[RECAPTCHA_SITEKEY\]/) {$line =~ s/\[RECAPTCHA_SITEKEY\]/$config{RECAPTCHA_SITEKEY}/}
if ($line =~ /\[RECAPTCHA_ERROR=\"([^\"]+)\"\]/) {
my $text = $1;
if ($error ne "") {$line =~ s/\[RECAPTCHA_ERROR=\"([^\"]+)\"\]/$text $error/} else {$line =~ s/\[RECAPTCHA_ERROR=\"([^\"]+)\"\]//}
}
if ($line =~ /\[RECAPTCHA_SUCCESS=\"([^\"]+)\"\]/) {
my $text = $1;
if ($success) {$line =~ s/\[RECAPTCHA_SUCCESS=\"([^\"]+)\"\]/$text/} else {$line =~ s/\[RECAPTCHA_SUCCESS=\"([^\"]+)\"\]//}
}
if ($line =~ /\[RECAPTCHA_FAILURE=\"([^\"]+)\"\]/) {
my $text = $1;
if ($failure) {$line =~ s/\[RECAPTCHA_FAILURE=\"([^\"]+)\"\]/$text/} else {$line =~ s/\[RECAPTCHA_FAILURE=\"([^\"]+)\"\]//}
}
print $client "$line\r\n";
}
print $client "\r\n";
} else {
foreach my $line (@message) {
if ($line =~ /\[IPADDRESS\]/) {$line =~ s/\[IPADDRESS\]/$peeraddress/}
if ($line =~ /\[HOSTNAME\]/) {$line =~ s/\[HOSTNAME\]/$hostname/}
print $client "$line ";
}
print $client "\n";
}
}
alarm(0);
};
shutdown ($client,2);
$client->close();
alarm(0);
exit;
}
if ($oldtype eq "HTTPS") {
$client->close(SSL_no_shutdown => 1);
} else {
$client->close();
}
}
}
} else {
logfile("MESSENGER_USER invalid - stopping $oldtype Messenger");
}
} else {
logfile("MESSENGER_USER not set - stopping $oldtype Messenger");
}
return;
}
# end messenger
###############################################################################
# start messengerv2
sub messengerv2 {
my (undef,undef,$uid,$gid,undef,undef,undef,$homedir) = getpwnam($config{MESSENGER_USER});
if ($homedir eq "" or $homedir eq "/" or $homedir =~ m[/etc/csf]) {
return (1, "The home directory for $config{MESSENGER_USER} is not valid [$homedir]");
}
if (! -e $homedir) {
return (1, "The home directory for $config{MESSENGER_USER} does not exist [$homedir]");
}
system("chmod","711",$homedir);
my $public_html = $homedir."/public_html";
unless (-e $public_html) {
system("mkdir","-p",$public_html);
system("chown","$config{MESSENGER_USER}:nobody",$public_html);
system("chmod","711",$public_html);
}
unless (-e $public_html."/.htaccess") {
open (my $HTACCESS, ">", $public_html."/.htaccess");
flock ($HTACCESS, LOCK_EX);
print $HTACCESS "Require all granted\n";
print $HTACCESS "DirectoryIndex index.php index.cgi index.html index.htm\n";
print $HTACCESS "Options +FollowSymLinks +ExecCGI\n";
print $HTACCESS "RewriteEngine On\n";
print $HTACCESS "RewriteCond \%{REQUEST_FILENAME} !-f\n";
print $HTACCESS "RewriteCond \%{REQUEST_FILENAME} !-d\n";
print $HTACCESS "RewriteRule ^ /index.php [L,QSA]\n";
system("chown","$config{MESSENGER_USER}:$config{MESSENGER_USER}",$public_html."/.htaccess");
system("chmod","644",$public_html."/.htaccess");
}
unless (-e $public_html."/index.php") {
if ($config{RECAPTCHA_SITEKEY}) {
system("cp","/etc/csf/messenger/index.recaptcha.php",$public_html."/index.php");
} else {
system("cp","/etc/csf/messenger/index.php",$public_html."/index.php");
}
system("chown","$config{MESSENGER_USER}:$config{MESSENGER_USER}",$public_html."/index.php");
system("chmod","644",$public_html."/index.php");
}
unless (-e $homedir."/en.php") {
system("cp","/etc/csf/messenger/en.php",$homedir."/en.php");
system("chown","$config{MESSENGER_USER}:$config{MESSENGER_USER}",$homedir."/en.php");
system("chmod","644",$homedir."/en.php");
}
open (my $CONF, ">", $homedir."/recaptcha.php");
flock ($CONF, LOCK_EX);
print $CONF "\n";
system("chown","$config{MESSENGER_USER}:$config{MESSENGER_USER}",$homedir."/recaptcha.php");
system("chmod","644",$homedir."/recaptcha.php");
open (my $OUT, ">", "/var/lib/csf/csf.conf");
flock ($OUT, LOCK_EX);
if ($config{MESSENGER_HTML_IN} ne "") {
print $OUT "Listen 0.0.0.0:$config{MESSENGER_HTML}\n";
if ($config{IPV6}) {print $OUT "Listen [::]:$config{MESSENGER_HTML}\n"}
print $OUT "\n";
print $OUT " ServerName $hostname\n";
print $OUT " DocumentRoot $public_html\n";
print $OUT " \n";
print $OUT " AllowOverride All\n";
print $OUT " \n";
print $OUT " \n";
print $OUT " suPHP_UserGroup $config{MESSENGER_USER} $config{MESSENGER_USER}\n";
print $OUT " \n";
print $OUT " \n";
print $OUT " \n";
print $OUT " SuexecUserGroup $config{MESSENGER_USER} $config{MESSENGER_USER}\n";
print $OUT " \n";
print $OUT " \n";
print $OUT " \n";
print $OUT " RMode config\n";
print $OUT " RUidGid $config{MESSENGER_USER} $config{MESSENGER_USER}\n";
print $OUT " \n";
print $OUT " \n";
print $OUT " AssignUserID $config{MESSENGER_USER} $config{MESSENGER_USER}\n";
print $OUT " \n";
print $OUT " KeepAlive Off\n";
print $OUT "\n";
}
if ($config{MESSENGER_HTTPS_IN} ne "") {
my %sslcerts;
my %sslkeys;
my %ssldomains;
my $start = 0;
my $sslhost;
my $sslcert;
my $sslkey;
my $sslaliases;
my $ssldir = "/var/lib/csf/ssl/";
unless (-d $ssldir) {
mkdir $ssldir;
mkdir $ssldir."certs/";
mkdir $ssldir."keys/";
}
foreach my $file (glob($config{MESSENGER_HTTPS_CONF})) {
if (-e $file) {
foreach my $line (slurp($file)) {
$line =~ s/\'|\"//g;
if ($line =~ /^\s*]+>/) {
$start = 1;
}
if ($webserver eq "apache" and $start) {
if ($line =~ /\s*ServerName\s+(\w+:\/\/)?([a-zA-Z0-9\.\-]+)(:\d+)?/) {$sslhost = $2}
if ($line =~ /\s*ServerAlias\s+(.*)/) {$sslaliases .= " ".$1}
if ($line =~ /\s*SSLCertificateFile\s+(\S+)/) {
my $match = $1;
if (-e $match) {
copy($match, $ssldir."certs/".$sslhost."\.crt");
$sslcert = $ssldir."certs/".$sslhost."\.crt";
}
}
if ($line =~ /\s*SSLCertificateKeyFile\s+(\S+)/) {
my $match = $1;
if (-e $match) {
copy($match, $ssldir."keys/".$sslhost."\.key");
$sslkey = $ssldir."keys/".$sslhost."\.key";
}
}
}
if (($webserver eq "apache" and $line =~ /^\s*<\/VirtualHost\s*>/)) {
$start = 0;
if ($sslhost ne "" and !checkip($sslhost) and $sslcert ne "") {
$ssldomains{$sslhost}{key} = $sslkey;
$ssldomains{$sslhost}{aliases} = $sslaliases;
$ssldomains{$sslhost}{cert} = $sslcert;
}
$sslhost = "";
$sslcert = "";
$sslkey = "";
$sslaliases = "";
}
}
}
}
if (scalar(keys %ssldomains < 1)) {
return (1, "No SSL domains found in MESSENGER_HTTPS_CONF location");
}
print $OUT "Listen 0.0.0.0:$config{MESSENGER_HTTPS}\n";
if ($config{IPV6}) {print $OUT "Listen [::]:$config{MESSENGER_HTTPS}\n"}
if (-e $config{MESSENGER_HTTPS_KEY}) {
print $OUT "\n";
print $OUT " ServerName $hostname\n";
print $OUT " DocumentRoot $public_html\n";
print $OUT " UseCanonicalName Off\n";
print $OUT " \n";
print $OUT " AllowOverride All\n";
print $OUT " \n";
print $OUT " \n";
print $OUT " suPHP_UserGroup $config{MESSENGER_USER} $config{MESSENGER_USER}\n";
print $OUT " \n";
print $OUT " \n";
print $OUT " \n";
print $OUT " SuexecUserGroup $config{MESSENGER_USER} $config{MESSENGER_USER}\n";
print $OUT " \n";
print $OUT " \n";
print $OUT " \n";
print $OUT " RMode config\n";
print $OUT " RUidGid $config{MESSENGER_USER} $config{MESSENGER_USER}\n";
print $OUT " \n";
print $OUT " \n";
print $OUT " AssignUserID $config{MESSENGER_USER} $config{MESSENGER_USER}\n";
print $OUT " \n";
print $OUT " SSLEngine on\n";
if (-e $config{MESSENGER_HTTPS_KEY}) {
copy($config{MESSENGER_HTTPS_KEY}, $ssldir."keys/".$hostname."\.key");
print $OUT " SSLCertificateKeyFile ".$ssldir."keys/".$hostname."\.key\n";
}
if (-e $config{MESSENGER_HTTPS_CRT}) {
copy($config{MESSENGER_HTTPS_CRT}, $ssldir."certs/".$hostname."\.crt");
print $OUT " SSLCertificateFile ".$ssldir."certs/".$hostname."\.crt\n";
}
print $OUT " SSLUseStapling off\n";
print $OUT " KeepAlive Off\n";
print $OUT "\n";
}
foreach my $key (keys %ssldomains) {
if ($key eq "") {next}
if ($key =~ /^\s+$/) {next}
if (-e $ssldomains{$key}{cert}) {
print $OUT "\n";
print $OUT " ServerName $key\n";
print $OUT " ServerAlias $ssldomains{$key}{aliases}\n";
print $OUT " DocumentRoot $public_html\n";
print $OUT " UseCanonicalName Off\n";
print $OUT " \n";
print $OUT " AllowOverride All\n";
print $OUT " \n";
print $OUT " \n";
print $OUT " suPHP_UserGroup $config{MESSENGER_USER} $config{MESSENGER_USER}\n";
print $OUT " \n";
print $OUT " \n";
print $OUT " \n";
print $OUT " SuexecUserGroup $config{MESSENGER_USER} $config{MESSENGER_USER}\n";
print $OUT " \n";
print $OUT " \n";
print $OUT " \n";
print $OUT " RMode config\n";
print $OUT " RUidGid $config{MESSENGER_USER} $config{MESSENGER_USER}\n";
print $OUT " \n";
print $OUT " \n";
print $OUT " AssignUserID $config{MESSENGER_USER} $config{MESSENGER_USER}\n";
print $OUT " \n";
print $OUT " SSLEngine on\n";
if (-e $ssldomains{$key}{cert}) {print $OUT " SSLCertificateFile $ssldomains{$key}{cert}\n"}
if (-e $ssldomains{$key}{key}) {print $OUT " SSLCertificateKeyFile $ssldomains{$key}{key}\n"}
print $OUT " SSLUseStapling off\n";
print $OUT " KeepAlive Off\n";
print $OUT "\n";
}
}
}
close ($OUT);
system("cp","-f","/var/lib/csf/csf.conf","/etc/apache2/conf.d/csf.messenger.conf");
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, "/usr/sbin/apachectl", "configtest");
my @data = <$childout>;
waitpid ($cmdpid, 0);
if (-e "/var/lib/csf/apachectl.error") {unlink("/var/lib/csf/apachectl.error")}
my $ok = 0;
foreach (@data) {
if ($_ =~ /^Syntax OK/) {$ok = 1}
}
if ($ok) {
system("/scripts/restartsrv_httpd");
logfile("MESSENGERV2: Started Apache MESSENGERV2 service using /etc/apache2/conf.d/csf.messenger.conf");
} else {
logfile("*MESSENGERV2*: Unable to generate a valid Apache configuration, see /var/lib/csf/apachectl.error");
if (-e "/etc/apache2/conf.d/csf.messenger.conf") {unlink("/etc/apache2/conf.d/csf.messenger.conf")}
system("/scripts/restartsrv_httpd");
open (my $ERROR, ">", "/var/lib/csf/apachectl.error");
flock ($ERROR, LOCK_EX);
foreach (@data) {print $ERROR $_}
close ($ERROR);
}
return;
}
# end messengerv2
###############################################################################
# start messengerv3
sub messengerv3 {
my (undef,undef,$uid,$gid,undef,undef,undef,$homedir) = getpwnam($config{MESSENGER_USER});
if ($homedir eq "" or $homedir eq "/" or $homedir =~ m[/etc/csf]) {
return (1, "The home directory for $config{MESSENGER_USER} is not valid [$homedir]");
}
if (! -e $homedir) {
return (1, "The home directory for $config{MESSENGER_USER} does not exist [$homedir]");
}
my $public_html = $homedir."/public_html";
unless (-e $public_html) {
system("mkdir","-p",$public_html);
system("chown","$config{MESSENGER_USER}:$config{MESSENGERV3GROUP}",$public_html);
system("chmod",$config{MESSENGERV3PERMS},$public_html);
}
unless (-e $public_html."/.htaccess") {
open (my $HTACCESS, ">", $public_html."/.htaccess");
flock ($HTACCESS, LOCK_EX);
print $HTACCESS <", $homedir."/recaptcha.php");
flock ($CONF, LOCK_EX);
print $CONF "\n";
system("chown","$config{MESSENGER_USER}:$config{MESSENGER_USER}",$homedir."/recaptcha.php");
system("chmod","644",$homedir."/recaptcha.php");
if ($config{MESSENGERV3WEBSERVER} eq "apache") {
$webserver = "apache";
}
elsif ($config{MESSENGERV3WEBSERVER} eq "litespeed") {
$webserver = "litespeed";
}
open (my $OUT, ">", "/var/lib/csf/csf.conf");
flock ($OUT, LOCK_EX);
if ($config{MESSENGERV3PHPHANDLER} ne "") {
$phphandler = $config{MESSENGERV3PHPHANDLER};
} else {
my $file = "/etc/httpd/conf/extra/httpd-hostname.conf";
if (-e $file) {
foreach my $line (slurp($file)) {
if ($line =~ /^\s*AddHandler\s+.+\s+\.php/) {
$phphandler = $line;
if ($config{DEBUG} >= 1) {logfile("SSL: PHP Handler found in [$file]")}
}
}
}
}
foreach my $line (slurp("/usr/local/csf/tpl/$webserver.main.txt")) {
$line =~ s/\[PORT\]/$config{MESSENGER_HTML}/g;
if ($line =~ /Listen \[::\]:/ and !$config{IPV6}) {next}
$line =~ s/\[SERVERNAME\]/$hostname/g;
$line =~ s/\[DOCUMENTROOT\]/$public_html/g;
$line =~ s/\[DIRECTORY\]/$homedir/g;
$line =~ s/\[USER\]/$config{MESSENGER_USER}/g;
$line =~ s/\[PHPHANDLER\]/$phphandler/g;
print $OUT $line."\n";
}
if ($config{MESSENGER_HTML_IN} ne "") {
foreach my $line (slurp("/usr/local/csf/tpl/$webserver.http.txt")) {
$line =~ s/\[PORT\]/$config{MESSENGER_HTML}/g;
if ($line =~ /Listen \[::\]:/ and !$config{IPV6}) {next}
$line =~ s/\[SERVERNAME\]/$hostname/g;
$line =~ s/\[DOCUMENTROOT\]/$public_html/g;
$line =~ s/\[DIRECTORY\]/$homedir/g;
$line =~ s/\[USER\]/$config{MESSENGER_USER}/g;
$line =~ s/\[PHPHANDLER\]/$phphandler/g;
print $OUT $line."\n";
}
}
if ($config{MESSENGER_HTTPS_IN} ne "") {
if ($webserver eq "litespeed") {
if ($config{MESSENGERV3HTTPS_CONF} =~ /(.*\/lsws\/)/) {
$serverroot = $1;
}
}
&conftree($config{MESSENGERV3HTTPS_CONF});
if ($webserver eq "litespeed") {
if ($sslhost ne "" and $osslcert ne "" and $ssldomains{$sslhost}{cert} eq "") {
if (-e $osslcert) {
$sslcert = $ssldir."certs/".$sslhost."\.crt";
copy($osslcert, $ssldir."certs/".$sslhost."\.crt");
}
if (-e $osslkey) {
$sslkey = $ssldir."keys/".$sslhost."\.key";
copy($osslkey, $ssldir."keys/".$sslhost."\.key");
}
if (-e $osslca) {
$sslca = $ssldir."ca/".$sslhost."\.ca";
copy($osslca, $ssldir."ca/".$sslhost."\.ca");
}
$sslaliases =~ s/\$VH_NAME/$sslhost/;
$ssldomains{$sslhost}{key} = $sslkey;
$ssldomains{$sslhost}{aliases} = $sslaliases;
$ssldomains{$sslhost}{cert} = $sslcert;
$ssldomains{$sslhost}{ca} = $sslca;
push @ssldomainkeys, $sslhost;
$sslhost = "";
$sslcert = "";
$sslkey = "";
$sslca = "";
$osslcert = "";
$osslkey = "";
$osslca = "";
$sslaliases = "";
}
}
if (scalar(keys %ssldomains < 1)) {
return (1, "No SSL domains found in MESSENGERV3HTTPS_CONF location [$config{MESSENGERV3HTTPS_CONF}] for $webserver web server");
}
my @virtualhost;
my $start = 0;
my $key = $ssldomainkeys[0];
foreach my $line (slurp("/usr/local/csf/tpl/$webserver.https.txt")) {
if ($line =~ /^\# Virtualhost start/) {$start = 1}
if ($start) {
if ($line =~ /^\# Virtualhost end/) {$start = 0}
push @virtualhost, $line;
next;
}
$line =~ s/\[SSLPORT\]/$config{MESSENGER_HTTPS}/g;
if ($line =~ /Listen \[::\]:/ and !$config{IPV6}) {next}
$line =~ s/\[SERVERNAME\]/$hostname/g;
$line =~ s/\[DOCUMENTROOT\]/$public_html/g;
$line =~ s/\[DIRECTORY\]/$homedir/g;
$line =~ s/\[USER\]/$config{MESSENGER_USER}/g;
$line =~ s/\[PHPHANDLER\]/$phphandler/g;
if ($line =~ /[MAPS]/) {
my $mapping;
foreach my $map (@ssldomainkeys) {
if (-e $ssldomains{$map}{cert}) {
$mapping .= "map csfssl.${map} ${map}\n\t";
}
}
$line =~ s/\[MAPS\]/$mapping/g;
}
if ($line =~ /\[SSLCERTIFICATEFILE\]/) {
if ( -e $ssldomains{$key}{cert}) {
$line =~ s/\[SSLCERTIFICATEFILE\]/$ssldomains{$key}{cert}/g;
} else {next}
}
if ($line =~ /\[SSLCERTIFICATEKEYFILE\]/) {
if (-e $ssldomains{$key}{key}) {
$line =~ s/\[SSLCERTIFICATEKEYFILE\]/$ssldomains{$key}{key}/g;
} else {next}
}
if ($line =~ /\[SSLCACERTIFICATEFILE\]/) {
if (-e $ssldomains{$key}{ca}) {
$line =~ s/\[SSLCACERTIFICATEFILE\]/$ssldomains{$key}{ca}/g;
} else {next}
}
print $OUT $line."\n";
}
foreach my $key (@ssldomainkeys) {
if ($key eq "") {next}
if ($key =~ /^\s+$/) {next}
if ($config{DEBUG} >= 1) {logfile("SSL: Processing [$key]")}
if (-e $ssldomains{$key}{cert}) {
foreach (@virtualhost) {
my $line = $_;
$line =~ s/\[SSLPORT\]/$config{MESSENGER_HTTPS}/g;
$line =~ s/\[SERVERNAME\]/$key/g;
$line =~ s/\[SERVERALIAS\]/$ssldomains{$key}{aliases}/g;
$line =~ s/\[DOCUMENTROOT\]/$public_html/g;
$line =~ s/\[DIRECTORY\]/$homedir/g;
$line =~ s/\[USER\]/$config{MESSENGER_USER}/g;
$line =~ s/\[PHPHANDLER\]/$phphandler/g;
if ($line =~ /\[SSLCERTIFICATEFILE\]/) {
if ( -e $ssldomains{$key}{cert}) {
$line =~ s/\[SSLCERTIFICATEFILE\]/$ssldomains{$key}{cert}/g;
} else {next}
}
if ($line =~ /\[SSLCERTIFICATEKEYFILE\]/) {
if (-e $ssldomains{$key}{key}) {
$line =~ s/\[SSLCERTIFICATEKEYFILE\]/$ssldomains{$key}{key}/g;
} else {next}
}
if ($line =~ /\[SSLCACERTIFICATEFILE\]/) {
if (-e $ssldomains{$key}{ca}) {
$line =~ s/\[SSLCACERTIFICATEFILE\]/$ssldomains{$key}{ca}/g;
} else {next}
}
print $OUT $line."\n";
}
}
}
}
close ($OUT);
my $location;
if (-d $config{MESSENGERV3LOCATION}) {
system("cp","-f","/var/lib/csf/csf.conf",$config{MESSENGERV3LOCATION}."/csf.messenger.conf");
$location = $config{MESSENGERV3LOCATION}."/csf.messenger.conf";
}
elsif (-f $config{MESSENGERV3LOCATION}) {
my @conf = slurp($config{MESSENGERV3LOCATION});
unless (grep {$_ =~ m[^Include /var/lib/csf/csf.conf]i} @conf) {
sysopen (my $FILE, $config{MESSENGERV3LOCATION}, O_WRONLY | O_APPEND | O_CREAT);
flock ($FILE, LOCK_EX);
if ($webserver eq "apache") {
print $FILE "Include /var/lib/csf/csf.conf\n";
}
elsif ($webserver eq "litespeed") {
print $FILE "include /var/lib/csf/csf.conf\n";
}
close ($FILE);
}
$location = $config{MESSENGERV3LOCATION};
}
else {
logfile("MESSENGERV3: [$config{MESSENGERV3LOCATION}] is neither a directory nor a file. You must manually include /var/lib/csf/csf.conf into the $webserver configuration");
return;
}
if ($config{MESSENGERV3TEST} ne "") {
my ($childin, $childout);
my $cmdpid = open3($childin, $childout, $childout, $config{MESSENGERV3TEST});
my @data = <$childout>;
waitpid ($cmdpid, 0);
if (-e "/var/lib/csf/messenger.error") {unlink("/var/lib/csf/messenger.error")}
my $ok = 0;
foreach (@data) {
if ($_ =~ /^Syntax OK/) {$ok = 1}
}
if ($ok) {
system($config{MESSENGERV3RESTART});
logfile("MESSENGERV3: Restarted $webserver MESSENGERV3 service using $location");
} else {
open (my $ERROR, ">", "/var/lib/csf/messenger.error");
flock ($ERROR, LOCK_EX);
foreach (@data) {print $ERROR $_}
close ($ERROR);
if (-d $config{MESSENGERV3LOCATION}) {
unlink ($config{MESSENGERV3LOCATION}."/csf.messenger.conf");
}
elsif (-f $config{MESSENGERV3LOCATION}) {
my @conf = slurp($config{MESSENGERV3LOCATION});
if (grep {$_ =~ m[^Include /var/lib/csf/csf.conf]i} @conf) {
sysopen (my $FILE, $config{MESSENGERV3LOCATION}, O_WRONLY | O_CREAT | O_TRUNC);
flock ($FILE, LOCK_EX);
foreach my $line (@conf) {
$line =~ s/$cleanreg//g;
if ($line =~ m[^Include /var/lib/csf/csf.conf]i) {next}
print $FILE $line."\n";
}
close ($FILE);
}
}
system($config{MESSENGERV3RESTART});
logfile("*MESSENGERV3*: Unable to generate a valid $webserver configuration, see /var/lib/csf/messenger.error");
}
} else {
system($config{MESSENGERV3RESTART});
logfile("MESSENGERV3: Restarted $webserver MESSENGERV3 service using $location");
}
return;
}
# end messengerv3
###############################################################################
# start messengerlog
sub messengerlog {
my $homedir = shift;
my $message = shift;
if ($config{DEBUG}) {
sysopen (my $LOG, "/var/log/lfd_messenger.log", O_WRONLY | O_APPEND | O_CREAT);
print $LOG "[$$]: ".$message."\n";
close ($LOG);
}
return;
}
# end messengerlog
###############################################################################
# start childcleanup
sub childcleanup {
$SIG{INT} = 'IGNORE';
$SIG{TERM} = 'IGNORE';
$SIG{HUP} = 'IGNORE';
my $line = shift;
my $message = shift;
if (($message eq "") and $line) {
$message = "Child $childproc: $line";
$line = "";
}
$0 = "child - aborting";
if ($message) {
if ($line ne "") {$message .= ", at line $line"}
logfile("$message");
}
exit;
}
# end childcleanup
###############################################################################
# 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) {
my $netip = Net::IP->new($key);
my $type = $netip->iptype();
if ($type eq "PUBLIC") {$ips{$key} = 1}
}
if ($config{IPV6}) {
foreach my $key (keys %g_ipv6) {
if ($key !~ m[::1/128]) {
eval {
local $SIG{__DIE__} = undef;
$ipscidr6->add($key);
};
}
}
}
return;
}
# end getethdev
###############################################################################
# start error
sub error {
my $error = shift;
logfile($error);
exit;
}
# end error
###############################################################################
# start conftree
sub conftree {
my $fileglob = shift;
foreach my $file (glob($fileglob)) {
if ($file =~ /csf\.messenger\.conf$/) {next}
if ($file =~ /\/var\/lib\/csf\/csf.conf$/) {next}
if (-e $file) {
if ($config{DEBUG} >= 1) {logfile("SSL: Processing [$file]")}
my $start = 0;
foreach my $line (slurp($file)) {
if ($webserver eq "apache") {
$line =~ s/\'|\"//g;
if ($line =~ /^\s*ServerRoot\s+\"?(\S+)\"?/) {
$serverroot = $1;
unless (-d $serverroot) {$serverroot = ""}
}
if ($serverroot eq "" and -d "/etc/apache2") {$serverroot = "/etc/apache2"}
if ($line =~ /^\s*Include\s+(\S+)/) {
my $include = $1;
if ($include !~ /^\//) {$include = "$serverroot/$include"}
if ($config{DEBUG} >= 1) {logfile("SSL: Including [$include]")}
&conftree($include);
}
if ($line =~ /^\s*IncludeOptional\s+(\S+)/) {
my $include = $1;
if ($include !~ /^\//) {$include = "$serverroot/$include"}
if ($config{DEBUG} >= 1) {logfile("SSL: IncludeOptional [$include]")}
&conftree($include);
}
if ($line =~ /^\s*]+>/) {
$start = 1;
}
if ($start) {
if ($line =~ /\s*ServerName\s+(\w+:\/\/)?([a-zA-Z0-9\.\-]+)(:\d+)?/) {$sslhost = $2}
if ($line =~ /\s*ServerAlias\s+(.*)/) {$sslaliases .= " ".$1}
if ($line =~ /\s*SSLCertificateFile\s+(\S+)/) {
my $match = $1;
if (-e $match) {
$osslcert = $match;
logfile("SSL: Found [$sslhost] certificate in [$file]");
}
}
if ($line =~ /\s*SSLCertificateKeyFile\s+(\S+)/) {
my $match = $1;
if (-e $match) {
$osslkey = $match;
logfile("SSL: Found [$sslhost] key in [$file]");
}
}
if ($line =~ /\s*SSLCACertificateFile\s+(\S+)/) {
my $match = $1;
if (-e $match) {
$osslca = $match;
logfile("SSL: Found [$sslhost] ca bundle in [$file]");
}
}
}
if ($line =~ /^\s*<\/VirtualHost\s*>/) {
$start = 0;
if ($sslhost ne "" and !checkip($sslhost) and $osslcert ne "") {
if (-e $osslcert) {
$sslcert = $ssldir."certs/".$sslhost."\.crt";
copy($osslcert, $ssldir."certs/".$sslhost."\.crt");
}
if (-e $osslkey) {
$sslkey = $ssldir."keys/".$sslhost."\.key";
copy($osslkey, $ssldir."keys/".$sslhost."\.key");
}
if (-e $osslca) {
$sslca = $ssldir."ca/".$sslhost."\.ca";
copy($osslca, $ssldir."ca/".$sslhost."\.ca");
}
$ssldomains{$sslhost}{key} = $sslkey;
$ssldomains{$sslhost}{aliases} = $sslaliases;
$ssldomains{$sslhost}{cert} = $sslcert;
$ssldomains{$sslhost}{ca} = $sslca;
push @ssldomainkeys, $sslhost;
if ($config{DEBUG} >= 1) {logfile("SSL: Found [$sslhost] in [$file]")}
}
$sslhost = "";
$sslcert = "";
$sslkey = "";
$sslca = "";
$osslcert = "";
$osslkey = "";
$osslca = "";
$sslaliases = "";
}
}
elsif ($webserver eq "litespeed") {
$line =~ s/\'|\"//g;
if ($line =~ /^\s*include\s+(\S+)/) {
my $include = $1;
$include =~ s/\$SERVER_ROOT/$serverroot/;
$include =~ s/\$VH_NAME/$sslhost/;
if ($include !~ /^\//) {$include = "$serverroot/$include"}
if ($config{DEBUG} >= 1) {logfile("SSL: include [$include]")}
&conftree($include);
}
if ($line =~ /^\s*configFile\s+(\S+)/) {
my $include = $1;
$include =~ s/\$SERVER_ROOT/$serverroot/;
$include =~ s/\$VH_NAME/$sslhost/;
if ($include !~ /^\//) {$include = "$serverroot/$include"}
if ($config{DEBUG} >= 1) {logfile("SSL: configFile [$include]")}
&conftree($include);
}
if ($line =~ /^\s*virtualHost\s+([^\{]+)\s+\{/) {
my $newsslhost = $1;
if ($newsslhost ne "" and $config{DEBUG} >= 1) {logfile("SSL: Found [$newsslhost] in [$file]")}
if ($litestart == 1) {
if ($sslhost ne "" and $osslcert ne "") {
if (-e $osslcert) {
$sslcert = $ssldir."certs/".$sslhost."\.crt";
copy($osslcert, $ssldir."certs/".$sslhost."\.crt");
}
if (-e $osslkey) {
$sslkey = $ssldir."keys/".$sslhost."\.key";
copy($osslkey, $ssldir."keys/".$sslhost."\.key");
}
if (-e $osslca) {
$sslca = $ssldir."ca/".$sslhost."\.ca";
copy($osslca, $ssldir."ca/".$sslhost."\.ca");
}
$sslaliases =~ s/\$VH_NAME/$sslhost/;
$ssldomains{$sslhost}{key} = $sslkey;
$ssldomains{$sslhost}{aliases} = $sslaliases;
$ssldomains{$sslhost}{cert} = $sslcert;
$ssldomains{$sslhost}{ca} = $sslca;
push @ssldomainkeys, $sslhost;
$sslhost = "";
$sslcert = "";
$sslkey = "";
$sslca = "";
$osslcert = "";
$osslkey = "";
$osslca = "";
$sslaliases = "";
}
}
$litestart = 1;
$sslhost = $newsslhost;
}
if ($litestart) {
if ($line =~ /\s*vhDomain\s+(\w+:\/\/)?([a-zA-Z0-9\.\-]+)(:\d+)?/) {$sslhost = $2}
if ($line =~ /\s*vhAliases\s+(.*)/) {$sslaliases .= " ".$1}
if ($line =~ /\s*certFile\s+(\S+)/) {
my $match = $1;
if (-e $match) {
$osslcert = $match;
logfile("SSL: Found [$sslhost] certificate in [$file]");
}
}
if ($line =~ /\s*keyFile\s+(\S+)/) {
my $match = $1;
if (-e $match) {
$osslkey = $match;
logfile("SSL: Found [$sslhost] key in [$file]");
}
}
}
}
}
}
}
return;
}
# end conftree
###############################################################################
1;
PK \e[ RegexMain.pmnu [ ###############################################################################
# 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::RegexMain;
use strict;
use lib '/usr/local/csf/lib';
use IPC::Open3;
use ConfigServer::Config;
use ConfigServer::CheckIP qw(checkip);
use ConfigServer::Slurp qw(slurp);
use ConfigServer::Logger qw(logfile);
use ConfigServer::GetEthDev;
use Exporter qw(import);
our $VERSION = 1.03;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
our (%config, %cpconfig, $slurpreg, $cleanreg, %globlogs, %brd, %ips);
my $config = ConfigServer::Config->loadconfig();
%config = $config->config;
$slurpreg = ConfigServer::Slurp->slurpreg;
$cleanreg = ConfigServer::Slurp->cleanreg;
if (-e "/etc/wwwacct.conf") {
foreach my $line (slurp("/etc/wwwacct.conf")) {
$line =~ s/$cleanreg//g;
if ($line =~ /^(\s|\#|$)/) {next}
my ($name,$value) = split (/ /,$line,2);
$cpconfig{$name} = $value;
}
}
if (-e "/usr/local/cpanel/version") {
foreach my $line (slurp("/usr/local/cpanel/version")) {
$line =~ s/$cleanreg//g;
if ($line =~ /\d/) {$cpconfig{version} = $line}
}
}
if ($config{LF_APACHE_ERRPORT} == 0) {
my $apachebin = "";
if (-e "/usr/local/apache/bin/httpd") {$apachebin = "/usr/local/apache/bin/httpd"}
elsif (-e "/usr/sbin/httpd") {$apachebin = "/usr/sbin/httpd"}
elsif (-e "/usr/sbin/apache2") {$apachebin = "/usr/sbin/apache2"}
elsif (-e "/usr/sbin/httpd2") {$apachebin = "/usr/sbin/httpd2"}
if (-e $apachebin) {
my ($childin, $childout);
my $mypid = open3($childin, $childout, $childout, $apachebin,"-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.4) {$config{LF_APACHE_ERRPORT} = 1}
}
}
unless ($config{LF_APACHE_ERRPORT} == 1) {$config{LF_APACHE_ERRPORT} = 2}
ConfigServer::Logger::logfile("LF_APACHE_ERRPORT: Set to [$config{LF_APACHE_ERRPORT}]");
my $ethdev = ConfigServer::GetEthDev->new();
%brd = $ethdev->brd;
%ips = $ethdev->ipv4;
if (-e "/usr/local/csf/bin/regex.custom.pm") {require "/usr/local/csf/bin/regex.custom.pm"} ##no critic
# end main
###############################################################################
# start processline
sub processline {
my $line = shift;
my $lgfile = shift;
my $globlogs_ref = shift;
%globlogs = %{$globlogs_ref};
$line =~ s/\n//g;
$line =~ s/\r//g;
if (-e "/usr/local/csf/bin/regex.custom.pm") {
my ($text,$ip,$app,$trigger,$ports,$temp,$cf) = &custom_line($line,$lgfile);
if ($text) {
return ($text,$ip,$app,$trigger,$ports,$temp,$cf);
}
}
#openSSH
#RH
if (($config{LF_SSHD}) and (($lgfile eq "/var/log/messages") or ($lgfile eq "/var/log/secure") or ($globlogs{SSHD_LOG}{$lgfile})) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sshd\[\d+\]: pam_unix\(sshd:auth\): authentication failure; logname=\S* uid=\S* euid=\S* tty=\S* ruser=\S* rhost=(\S+)\s+(user=(\S+))?/)) {
my $ip = $3;
my $acc = $5;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SSH login from","$ip|$acc","sshd")} else {return}
}
if (($config{LF_SSHD}) and (($lgfile eq "/var/log/messages") or ($lgfile eq "/var/log/secure") or ($globlogs{SSHD_LOG}{$lgfile})) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sshd\[\d+\]: Failed none for (\S*) from (\S+) port \S+/)) {
my $ip = $4;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SSH login from","$ip|$acc","sshd")} else {return}
}
if (($config{LF_SSHD}) and (($lgfile eq "/var/log/messages") or ($lgfile eq "/var/log/secure") or ($globlogs{SSHD_LOG}{$lgfile})) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sshd\[\d+\]: Failed password for (invalid user |illegal user )?(\S*) from (\S+)( port \S+ \S+\s*)?/)) {
my $ip = $5;
my $acc = $4;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SSH login from","$ip|$acc","sshd")} else {return}
}
if (($config{LF_SSHD}) and (($lgfile eq "/var/log/messages") or ($lgfile eq "/var/log/secure") or ($globlogs{SSHD_LOG}{$lgfile})) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sshd\[\d+\]: Failed keyboard-interactive(\/pam)? for (invalid user )?(\S*) from (\S+) port \S+/)) {
my $ip = $6;
my $acc = $4;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SSH login from","$ip|$acc","sshd")} else {return}
}
if (($config{LF_SSHD}) and (($lgfile eq "/var/log/messages") or ($lgfile eq "/var/log/secure") or ($globlogs{SSHD_LOG}{$lgfile})) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sshd\[\d+\]: Invalid user (\S*) from (\S+)/)) {
my $ip = $4;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SSH login from","$ip|$acc","sshd")} else {return}
}
if (($config{LF_SSHD}) and (($lgfile eq "/var/log/messages") or ($lgfile eq "/var/log/secure") or ($globlogs{SSHD_LOG}{$lgfile})) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sshd\[\d+\]: User (\S*) from (\S+)\s* not allowed because not listed in AllowUsers/)) {
my $ip = $4;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SSH login from","$ip|$acc","sshd")} else {return}
}
if (($config{LF_SSHD}) and (($lgfile eq "/var/log/messages") or ($lgfile eq "/var/log/secure") or ($globlogs{SSHD_LOG}{$lgfile})) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sshd\[\d+\]: Did not receive identification string from (\S+)/)) {
my $ip = $3;
my $acc = "";
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SSH login from","$ip|$acc","sshd")} else {return}
}
if (($config{LF_SSHD}) and (($lgfile eq "/var/log/messages") or ($lgfile eq "/var/log/secure") or ($globlogs{SSHD_LOG}{$lgfile})) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sshd\[\d+\]: refused connect from (\S+)/)) {
my $ip = $3;
my $acc = "";
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SSH login from","$ip|$acc","sshd")} else {return}
}
if (($config{LF_SSHD}) and (($lgfile eq "/var/log/messages") or ($lgfile eq "/var/log/secure") or ($globlogs{SSHD_LOG}{$lgfile})) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sshd\[\d+\]: error: maximum authentication attempts exceeded for (\S*) from (\S+)/)) {
my $ip = $4;
my $acc = "";
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SSH login from","$ip|$acc","sshd")} else {return}
}
#Debian/Ubuntu
if (($config{LF_SSHD}) and (($lgfile eq "/var/log/messages") or ($lgfile eq "/var/log/secure") or ($globlogs{SSHD_LOG}{$lgfile})) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sshd\[\d+\]: Illegal user (\S*) from (\S+)/)) {
my $ip = $4;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SSH login from","$ip|$acc","sshd")} else {return}
}
#Gentoo
if (($config{LF_SSHD}) and (($lgfile eq "/var/log/messages") or ($lgfile eq "/var/log/secure") or ($globlogs{SSHD_LOG}{$lgfile})) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sshd\[\d+\]: error: PAM: Authentication failure for (\S*) from (\S+)/)) {
my $ip = $4;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SSH login from","$ip|$acc","sshd")} else {return}
}
#courier-imap
if (($config{LF_POP3D}) and ($globlogs{POP3D_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ pop3d(-ssl)?: LOGIN FAILED, user=(\S*), ip=\[(\S+)\]\s*$/)) {
my $ip = $4;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed POP3 login from","$ip|$acc","pop3d")} else {return}
}
if (($config{LF_IMAPD}) and ($globlogs{IMAPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ imapd(-ssl)?: LOGIN FAILED, user=(\S*), ip=\[(\S+)\]\s*$/)) {
my $ip = $4;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed IMAP login from","$ip|$acc","imapd")} else {return}
}
#uw-imap
if (($config{LF_POP3D}) and ($globlogs{POP3D_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ ipop3d\[\d+\]: Login failed user=(\S*) auth=\S+ host=\S+ \[(\S+)\]\s*$/)) {
my $ip = $3;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed POP3 login from","$ip|$acc","pop3d")} else {return}
}
if (($config{LF_IMAPD}) and ($globlogs{IMAPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ imapd\[\d+\]: Login failed user=(\S*) auth=\S+ host=\S+ \[(\S+)\]\s*$/)) {
my $ip = $3;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed IMAP login from","$ip|$acc","imapd")} else {return}
}
#dovecot
if (($config{LF_POP3D}) and ($globlogs{POP3D_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ dovecot(\[\d+\])?: pop3-login: (Disconnected: )?(Aborted login( by logging out)?|Connection closed|Disconnected|Disconnected: Inactivity)(:\s*\S+\sfailed: Connection reset by peer)?(\s*\(auth failed, \d+ attempts( in \d+ secs)?\))?: (user=(<\S*>)?, )?(method=\S+, )?rip=(\S+), lip=/)) {
my $ip = $12;
my $acc = $10;
$ip =~ s/^::ffff://;
$acc =~ s/^<|>$//g;
if (checkip(\$ip)) {return ("Failed POP3 login from","$ip|$acc","pop3d")} else {return}
}
if (($config{LF_IMAPD}) and ($globlogs{IMAPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ dovecot(\[\d+\])?: imap-login: (Disconnected: )?(Aborted login( by logging out)?|Connection closed|Disconnected|Disconnected: Inactivity)(:\s*\S+\sfailed: Connection reset by peer)?(\s*\(auth failed, \d+ attempts( in \d+ secs)?\))?: (user=(<\S*>)?, )?(method=\S+, )?rip=(\S+), lip=/)) {
my $ip = $12;
my $acc = $10;
$ip =~ s/^::ffff://;
$acc =~ s/^<|>$//g;
if (checkip(\$ip)) {return ("Failed IMAP login from","$ip|$acc","imapd")} else {return}
}
if (($config{LF_POP3D}) and ($globlogs{POP3D_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) pop3-login(\[\d+\])?: Info: (Aborted login( by logging out)?|Connection closed|Disconnected|Disconnected: Inactivity)(\s*\(auth failed, \d+ attempts( in \d+ secs)?\))?: (user=(<\S*>)?, )?(method=\S+, )?rip=(\S+), lip=/)) {
my $ip = $10;
my $acc = $8;
$ip =~ s/^::ffff://;
$acc =~ s/^<|>$//g;
if (checkip(\$ip)) {return ("Failed POP3 login from","$ip|$acc","pop3d")} else {return}
}
if (($config{LF_IMAPD}) and ($globlogs{IMAPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) imap-login(\[\d+\])?: Info: (Aborted login( by logging out)?|Connection closed|Disconnected|Disconnected: Inactivity)(\s*\(auth failed, \d+ attempts( in \d+ secs)?\))?: (user=(<\S*>)?, )?(method=\S+, )?rip=(\S+), lip=/)) {
my $ip = $10;
my $acc = $8;
$ip =~ s/^::ffff://;
$acc =~ s/^<|>$//g;
if (checkip(\$ip)) {return ("Failed IMAP login from","$ip|$acc","imapd")} else {return}
}
#Kerio Mailserver
if (($config{LF_POP3D}) and ($globlogs{POP3D_LOG}{$lgfile}) and ($line =~ /^\S+ \S+ POP3(\[\d+\])?: User (\S*) doesn\'t exist\. Attempt from IP address (\S+)\s*$/)) {
my $ip = $3;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed POP3 login from","$ip|$acc","pop3d")} else {return}
}
if (($config{LF_POP3D}) and ($globlogs{POP3D_LOG}{$lgfile}) and ($line =~ /^\S+ \S+ POP3(\[\d+\])?: Invalid password for user (\S*)\. Attempt from IP address (\S+)\s*$/)) {
my $ip = $3;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed POP3 login from","$ip|$acc","pop3d")} else {return}
}
if (($config{LF_IMAPD}) and ($globlogs{IMAPD_LOG}{$lgfile}) and ($line =~ /^\S+ \S+ IMAP(\[\d+\])?: User (\S*) doesn\'t exist\. Attempt from IP address (\S+)\s*$/)) {
my $ip = $3;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed IMAP login from","$ip|$acc","imapd")} else {return}
}
if (($config{LF_IMAPD}) and ($globlogs{IMAPD_LOG}{$lgfile}) and ($line =~ /^\S+ \S+ IMAP(\[\d+\])?: Invalid password for user (\S*)\. Attempt from IP address (\S+)\s*$/)) {
my $ip = $3;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed IMAP login from","$ip|$acc","imapd")} else {return}
}
if (($config{LF_SMTPAUTH}) and ($globlogs{SMTPAUTH_LOG}{$lgfile}) and ($line =~ /^\S+ \S+ smtp(\[\d+\])?: User (\S*) doesn\'t exist\. Attempt from IP address (\S+)\s*$/)) {
my $ip = $3;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed IMAP login from","$ip|$acc","imapd")} else {return}
}
#pure-ftpd
#Nov 10 04:28:04 w212 pure-ftpd[3269638]: (?@152.57.198.52) [WARNING] Authentication failed for user [www]
if (($config{LF_FTPD}) and ($globlogs{FTPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ pure-ftpd(\[\d+\])?: \(\?\@(\S+)\) \[WARNING\] Authentication failed for user \[(\S*)\]/)) {
my $ip = $3;
my $acc = $4;
$ip =~ s/^::ffff://;
$ip =~ s/\_/\:/g;
if (checkip(\$ip)) {return ("Failed FTP login from","$ip|$acc","ftpd")} else {return}
}
#proftpd
if (($config{LF_FTPD}) and ($globlogs{FTPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ proftpd\[\d+\]:? \S+ \([^\[]+\[(\S+)\]\)( -)?:? - no such user \'(\S*)\'/)) {
my $ip = $2;
my $acc = $4;
$ip =~ s/^::ffff://;
$acc =~ s/:$//g;
if (checkip(\$ip)) {return ("Failed FTP login from","$ip|$acc","ftpd")} else {return}
}
if (($config{LF_FTPD}) and ($globlogs{FTPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ proftpd\[\d+\]:? \S+ \([^\[]+\[(\S+)\]\)( -)?:? USER (\S*) no such user found from/)) {
my $ip = $2;
my $acc = $4;
$ip =~ s/^::ffff://;
$acc =~ s/:$//g;
if (checkip(\$ip)) {return ("Failed FTP login from","$ip|$acc","ftpd")} else {return}
}
if (($config{LF_FTPD}) and ($globlogs{FTPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ proftpd\[\d+\]:? \S+ \([^\[]+\[(\S+)\]\)( -)?:? - SECURITY VIOLATION/)) {
my $ip = $2;
my $acc = "";
$ip =~ s/^::ffff://;
$acc =~ s/:$//g;
if (checkip(\$ip)) {return ("Failed FTP login from","$ip|$acc","ftpd")} else {return}
}
if (($config{LF_FTPD}) and ($globlogs{FTPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ proftpd\[\d+\]:? \S+ \([^\[]+\[(\S+)\]\)( -)?:? - USER (\S*) \(Login failed\): Incorrect password/)) {
my $ip = $2;
my $acc = $4;
$ip =~ s/^::ffff://;
$acc =~ s/:$//g;
if (checkip(\$ip)) {return ("Failed FTP login from","$ip|$acc","ftpd")} else {return}
}
#vsftpd
if (($config{LF_FTPD}) and ($globlogs{FTPD_LOG}{$lgfile}) and ($line =~ /^\S+\s+\S+\s+\d+\s+\S+\s+\d+ \[pid \d+] \[(\S+)\] FAIL LOGIN: Client "(\S+)"/)) {
my $ip = $2;
my $acc = $1;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed FTP login from","$ip|$acc","ftpd")} else {return}
}
if (($config{LF_FTPD}) and ($globlogs{FTPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ vsftpd\[\d+\]: pam_unix\(\S+\): authentication failure; logname=\S*\s+\S+\s+\S+\s+\S+\s+ruser=\S*\s+rhost=(\S+)(\s+user=(\S*))?/)) {
my $ip = $2;
my $acc = $4;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed FTP login from","$ip|$acc","ftpd")} else {return}
}
if (($config{LF_FTPD}) and ($globlogs{FTPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ vsftpd\(pam_unix\)\[\d+\]: authentication failure; logname=\S*\s+\S+\s+\S+\s+\S+\s+ruser=\S*\s+rhost=(\S+)(\s+user=(\S*))?/)) {
my $ip = $2;
my $acc = $4;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed FTP login from","$ip|$acc","ftpd")} else {return}
}
#apache htaccess
if (($config{LF_HTACCESS}) and ($globlogs{HTACCESS_LOG}{$lgfile}) and ($line =~ /^\[\S+\s+\S+\s+\S+\s+\S+\s+\S+\] \[(\S*:)?error\] (\[pid \d+(:tid \d+)?\] )?\[(client|remote) (\S+)\] (\w+: )?user (\S*)(( not found:)|(: authentication failure for))/)) {
my $ip = $5;
my $acc = $7;
$ip =~ s/^::ffff://;
if ($config{LF_APACHE_ERRPORT} == 2 and $ip =~ /(.*):\d+$/) {$ip = $1}
if (checkip(\$ip)) {return ("Failed web page login from","$ip|$acc","htpasswd")} else {return}
}
#nginx
if (($config{LF_HTACCESS}) and ($globlogs{HTACCESS_LOG}{$lgfile}) and ($line =~ /^\S+ \S+ \[error\] \S+ \*\S+ no user\/password was provided for basic authentication, client: (\S+),/)) {
my $ip = $1;
my $acc = "";
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed web page login from","$ip|$acc","htpasswd")} else {return}
}
if (($config{LF_HTACCESS}) and ($globlogs{HTACCESS_LOG}{$lgfile}) and ($line =~ /^\S+ \S+ \[error\] \S+ \*\S+ user \"(\S*)\": password mismatch, client: (\S+),/)) {
my $ip = $2;
my $acc = $1;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed web page login from","$ip|$acc","htpasswd")} else {return}
}
if (($config{LF_HTACCESS}) and ($globlogs{HTACCESS_LOG}{$lgfile}) and ($line =~ /^\S+ \S+ \[error\] \S+ \*\S+ user \"(\S*)\" was not found in \".*?\", client: (\S+),/)) {
my $ip = $2;
my $acc = $1;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed web page login from","$ip|$acc","htpasswd")} else {return}
}
#cxs Apache
if (($config{LF_CXS}) and ($globlogs{MODSEC_LOG}{$lgfile}) and ($line =~ /^\[\S+\s+\S+\s+\S+\s+\S+\s+\S+\] \[(\S*:)?error\] (\[pid \d+(:tid \d+)?\] )?\[(client|remote) (\S+)\]( \[client \S+\])? (\w+: )?ModSecurity:(( \[[^]]+\])*)? Access denied with code \d\d\d \(phase 2\)\. File \"[^\"]*\" rejected by the approver script \"\/etc\/cxs\/cxscgi\.sh\"/)) {
my $ip = $5;
my $acc = "";
my $domain = "";
if ($line =~ /\] \[hostname "([^\"]+)"\] \[/) {$domain = $1}
$ip =~ s/^::ffff://;
if ($config{LF_APACHE_ERRPORT} == 2 and $ip =~ /(.*):\d+$/) {$ip = $1}
if (checkip(\$ip)) {return ("cxs mod_security triggered by","$ip|$acc|$domain","cxs")} else {return}
}
#cxs Litespeed
if (($config{LF_CXS}) and ($globlogs{MODSEC_LOG}{$lgfile}) and ($line =~ /^\[\S+\s+\S+\s+\S+\s+\S+\s+\S+\] \[(\S*:)?error\] (\[pid \d+(:tid \d+)?\] )?\[(client|remote) (\S+)\]( \[client \S+\])? (\w+: )?ModSecurity:(( \[[^]]+\])*)? Access denied with code \d\d\d, \[Rule: 'FILES_TMPNAMES' '\@inspectFile \/etc\/cxs\/cxscgi\.sh'\] \[id "1010101"\]/)) {
my $ip = $5;
my $acc = "";
my $domain = "";
if ($line =~ /\] \[hostname "([^\"]+)"\] \[/) {$domain = $1}
$ip =~ s/^::ffff://;
if ($config{LF_APACHE_ERRPORT} == 2 and $ip =~ /(.*):\d+$/) {$ip = $1}
if (checkip(\$ip)) {return ("cxs mod_security triggered by","$ip|$acc|$domain","cxs")} else {return}
}
#mod_security v1
if (($config{LF_MODSEC}) and ($globlogs{MODSEC_LOG}{$lgfile}) and ($line =~ /^\[\S+\s+\S+\s+\S+\s+\S+\s+\S+\] \[error\] \[(client|remote) (\S+)\] mod_security: Access denied/)) {
my $ip = $2;
my $acc = "";
my $domain = "";
if ($line =~ /\] \[hostname "([^\"]+)"\] \[/) {$domain = $1}
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("mod_security triggered by","$ip|$acc|$domain","mod_security")} else {return}
}
#mod_security v2 (apache)
if (($config{LF_MODSEC}) and ($globlogs{MODSEC_LOG}{$lgfile}) and ($line =~ /^\[\S+\s+\S+\s+\S+\s+\S+\s+\S+\] \[(\S*:)?error\] (\[pid \d+(:tid \d+)?\] )?\[(client|remote) (\S+)\]( \[client \S+\])? (\w+: )?ModSecurity:(( \[[^]]+\])*)? Access denied/)) {
my $ip = $5;
my $acc = "";
my $domain = "";
if ($line =~ /\] \[hostname "([^\"]+)"\] \[/) {$domain = $1}
$ip =~ s/^::ffff://;
if ($config{LF_APACHE_ERRPORT} == 2 and $ip =~ /(.*):\d+$/) {$ip = $1}
my $ruleid = "unknown";
if ($line =~ /\[id "(\d+)"\]/) {$ruleid = $1}
if (checkip(\$ip)) {return ("mod_security (id:$ruleid) triggered by","$ip|$acc|$domain","mod_security")} else {return}
}
#mod_security v2 (nginx)
if (($config{LF_MODSEC}) and ($globlogs{MODSEC_LOG}{$lgfile}) and ($line =~ /^\S+ \S+ \[\S+\] \S+ \[(client|remote) (\S+)\] ModSecurity:(( \[[^]]+\])*)? Access denied/)) {
my $ip = $2;
my $acc = "";
my $domain = "";
if ($line =~ /\] \[hostname "([^\"]+)"\] \[/) {$domain = $1}
$ip =~ s/^::ffff://;
my $ruleid = "unknown";
if ($line =~ /\[id "(\d+)"\]/) {$ruleid = $1}
if (checkip(\$ip)) {return ("mod_security (id:$ruleid) triggered by","$ip|$acc|$domain","mod_security")} else {return}
}
#BIND
if (($config{LF_BIND}) and ($globlogs{BIND_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ named\[\d+\]: client( \S+)? (\S+)\#\d+(\s\(\S+\))?\:( view external\:)? (update|zone transfer|query \(cache\)) \'[^\']*\' denied$/)) {
my $ip = $3;
my $acc = "";
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("bind triggered by","$ip|$acc","bind")} else {return}
}
#suhosin
if (($config{LF_SUHOSIN}) and ($globlogs{SUHOSIN_LOG}{$lgfile})and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ suhosin\[\d+\]: ALERT - .* \(attacker \'(\S+)\'/)) {
my $ip = $2;
my $acc = "";
$ip =~ s/^::ffff://;
if ($line !~ /script tried to increase memory_limit/) {
if (checkip(\$ip)) {return ("Suhosin triggered by","$ip|$acc","suhosin")} else {return}
}
}
#cPanel/WHM
if (($config{LF_CPANEL}) and ($globlogs{CPANEL_LOG}{$lgfile}) and ($line =~ /^\[\S+\s+\S+\s+\S+\] \w+ \[\w+] (\S+) - (\S+) \"[^\"]+\" FAILED LOGIN/)) {
my $ip = $1;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed cPanel login from","$ip|$acc","cpanel")} else {return}
}
if (($config{LF_CPANEL}) and ($globlogs{CPANEL_LOG}{$lgfile}) and ($line =~ /^(\S+) - (\S+)? \[\S+ \S+\] \"[^\"]*\" FAILED LOGIN/)) {
my $ip = $1;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed cPanel login from","$ip|$acc","cpanel")} else {return}
}
#webmin
if (($config{LF_WEBMIN}) and ($globlogs{WEBMIN_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ webmin\[\d+\]: Invalid login as (\S+) from (\S+)/)) {
my $ip = $3;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed Webmin login from","$ip|$acc","webmin")} else {return}
}
#DirectAdmin
if (($config{LF_DIRECTADMIN}) and ($globlogs{DIRECTADMIN_LOG}{$lgfile}) and ($line =~ /^\S+ \'(\S+)\' \d+ (failed login attempts\. Account|failed login attempt on account) \'(\S+)\'/)) {
my $ip = $1;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed DirectAdmin login from","$ip|$acc","directadmin")} else {return}
}
if (($config{LF_DIRECTADMIN}) and ($globlogs{DIRECTADMIN_LOG_R}{$lgfile}) and ($line =~ /^\[\S+\s+\S+\s+\S+\]: (<\S+> )?IMAP Error: Login failed for (\S+) (against \S+ )?from (\S+)\. AUTHENTICATE PLAIN: Authentication failed\. in \/var\/www\/html\/roundcubemail/)) {
my $ip = $4;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed DirectAdmin Roundcube login from","$ip|$acc","directadmin")} else {return}
}
if (($config{LF_DIRECTADMIN}) and ($globlogs{DIRECTADMIN_LOG_S}{$lgfile}) and ($line =~ /^\S+\s+\S+ \[LOGIN_ERROR\] (\S+)( \(\S+\))? from (\S+): Unknown user or password incorrect\.\s*$/)) {
my $ip = $3;
my $acc = $1;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed DirectAdmin SquirrelMail login from","$ip|$acc","directadmin")} else {return}
}
#Jun 12 10:58:00 phpmyadmin: user denied: bill (mysql-denied) from 192.168.254.10
if (($config{LF_DIRECTADMIN}) and ($globlogs{DIRECTADMIN_LOG_P}{$lgfile}) and ($line =~ /^\S+\s+\S+\s+\S+: pma auth user='(\S+)' status='mysql-denied' ip='(\S+)'\s*$/)) {
my $ip = $2;
my $acc = $1;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed DirectAdmin phpMyAdmin login from","$ip|$acc","directadmin")} else {return}
}
if (($config{LF_DIRECTADMIN}) and ($globlogs{DIRECTADMIN_LOG_P}{$lgfile}) and ($line =~ /^\S+\s+\S+\s+\S+ phpmyadmin: user denied: (\S+) \(mysql-denied\) from (\S+)\s*$/)) {
my $ip = $2;
my $acc = $1;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed DirectAdmin phpMyAdmin login from","$ip|$acc","directadmin")} else {return}
}
#Exim SMTP AUTH
if (($config{LF_SMTPAUTH}) and ($globlogs{SMTPAUTH_LOG}{$lgfile}) and ($line =~ /^\S+\s+\S+\s+(\[\d+\] )?(\S+) authenticator failed for \S+ (\S+ )?\[(\S+)\](:\S*:?)?( I=\S+| \d+\:)? 535 Incorrect authentication data( \(set_id=(\S+)\))?/)) {
my $ip = $4;
my $acc = $8;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SMTP AUTH login from","$ip|$acc","smtpauth")} else {return}
}
#Exim Syntax Errors
if (($config{LF_EXIMSYNTAX}) and ($globlogs{SMTPAUTH_LOG}{$lgfile}) and ($line =~ /^\S+\s+\S+\s+(\[\d+\] )?SMTP call from (\S+ )?\[(\S+)\](:\S*:?)?( I=\S+)? dropped: too many syntax or protocol errors/)) {
my $ip = $3;
my $acc = "";
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Exim syntax errors from","$ip|$acc","eximsyntax")} else {return}
}
if (($config{LF_EXIMSYNTAX}) and ($globlogs{SMTPAUTH_LOG}{$lgfile}) and ($line =~ /^\S+\s+\S+\s+(\[\d+\] )?SMTP protocol error in \"[^\"]+\" H=\S+ (\S+ )?\[(\S+)\](:\S*:?)?( I=\S+)? AUTH command used when not advertised/)) {
my $ip = $3;
my $acc = "";
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Exim syntax errors from","$ip|$acc","eximsyntax")} else {return}
}
#mod_qos
if (($config{LF_QOS}) and ($globlogs{HTACCESS_LOG}{$lgfile}) and ($line =~ /^\[\S+\s+\S+\s+\S+\s+\S+\s+\S+\] \[(\S*:)?error\] (\[pid \d+(:tid \d+)?\] )?\[(client|remote) (\S+)\] (\w+: )?mod_qos\(\d+\): access denied,/)) {
my $ip = $5;
my $acc = "";
$ip =~ s/^::ffff://;
if ($config{LF_APACHE_ERRPORT} == 2 and $ip =~ /(.*):\d+$/) {$ip = $1}
if (checkip(\$ip)) {return ("mod_qos triggered by","$ip|$acc","mod_qos")} else {return}
}
#Apache symlink race condition
if (($config{LF_SYMLINK}) and ($globlogs{MODSEC_LOG}{$lgfile}) and ($line =~ /^\[\S+\s+\S+\s+\S+\s+\S+\s+\S+\] \[(\S*:)?error\] (\[pid \d+(:tid \d+)?\] )?\[(client|remote) (\S+)\] (\w+: )?Caught race condition abuser/)) {
my $ip = $5;
my $acc = "";
$ip =~ s/^::ffff://;
if ($config{LF_APACHE_ERRPORT} == 2 and $ip =~ /(.*):\d+$/) {$ip = $1}
if ($line !~ /\/cgi-sys\/suspendedpage\.cgi$/) {
if (checkip(\$ip)) {return ("symlink race condition triggered by","$ip|$acc","symlink")} else {return}
}
}
#courier-imap (Plesk)
if (($config{LF_POP3D}) and ($globlogs{POP3D_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ (courier-)?pop3(?:d|s)(-ssl)?(\[\d+\])?: LOGIN FAILED, user=(\S*), ip=\[(\S+)\]\s*$/)) {
my $ip = $6;
my $acc = $5;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed POP3 login from","$ip|$acc","pop3d")} else {return}
}
if (($config{LF_IMAPD}) and ($globlogs{IMAPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ (courier-)?imap(?:d|s)(-ssl)?(\[\d+\])?: LOGIN FAILED, user=(\S*), ip=\[(\S+)\]\s*$/)) {
my $ip = $6;
my $acc = $5;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed IMAP login from","$ip|$acc","imapd")} else {return}
}
#Qmail SMTP AUTH (Plesk)
if (($config{LF_SMTPAUTH}) and ($globlogs{SMTPAUTH_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ smtp_auth(?:\[\d+\])?: FAILED: (\S*) - password incorrect from \S+ \[(\S+)\]\s*$/)) {
my $ip = $3;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SMTP AUTH login from","$ip|$acc","smtpauth")} else {return}
}
#Postfix SMTP AUTH (Plesk)
if (($config{LF_SMTPAUTH}) and ($globlogs{SMTPAUTH_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ postfix\/(submission\/)?smtpd(?:\[\d+\])?: warning: \S+\[(\S+)\]: SASL (?:(?i)LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed/)) {
my $ip = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SMTP AUTH login from","$ip","smtpauth")} else {return}
}
#InterWorx (dovecot, proftpd, qmail)
if (($config{LF_POP3D}) and ($globlogs{POP3D_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) pop3-login(\[\d+\])?: Info: (Aborted login|Disconnected|Disconnected: Inactivity)( \(auth failed, \d+ attempts( in \d+ secs)?\))?: (user=(<\S*>)?, )?(method=\S+, )?rip=(\S+), lip=/)) {
my $ip = $9;
my $acc = $7;
$ip =~ s/^::ffff://;
$acc =~ s/^<|>$//g;
if (checkip(\$ip)) {return ("Failed POP3 login from","$ip|$acc","pop3d")} else {return}
}
if (($config{LF_IMAPD}) and ($globlogs{IMAPD_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) imap-login(\[\d+\])?: Info: (Aborted login|Disconnected|Disconnected: Inactivity)( \(auth failed, \d+ attempts( in \d+ secs)?\))?: (user=(<\S*>)?, )?(method=\S+, )?rip=(\S+), lip=/)) {
my $ip = $9;
my $acc = $7;
$ip =~ s/^::ffff://;
$acc =~ s/^<|>$//g;
if (checkip(\$ip)) {return ("Failed IMAP login from","$ip|$acc","imapd")} else {return}
}
if (($config{LF_FTPD}) and ($globlogs{FTPD_LOG}{$lgfile}) and ($line =~ /^\S+ \S+ \S+ proftpd\[\d+\]:? \S+ \(\S+?[^\[]+\[(\S+)\]\)( -)?:? USER (\S*): no such user found from/)) {
my $ip = $1;
my $acc = $3;
$ip =~ s/^::ffff://;
$acc =~ s/:$//g;
if (checkip(\$ip)) {return ("Failed FTP login from","$ip|$acc","ftpd")} else {return}
}
if (($config{LF_FTPD}) and ($globlogs{FTPD_LOG}{$lgfile}) and ($line =~ /^\S+ \S+ \S+ proftpd\[\d+\]:? \S+ \(\S+?[^\[]+\[(\S+)\]\)( -)?:? USER (\S*) \(Login failed\): Incorrect password/)) {
my $ip = $1;
my $acc = $3;
$ip =~ s/^::ffff://;
$acc =~ s/:$//g;
if (checkip(\$ip)) {return ("Failed FTP login from","$ip|$acc","ftpd")} else {return}
}
if (($config{LF_SMTPAUTH}) and ($globlogs{SMTPAUTH_LOG}{$lgfile}) and ($line =~ /^\S+ qmail-smtpd\[\d+\]: AUTH failed \[(\S+)\] (\S+)/)) {
my $ip = $1;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed SMTP AUTH login from","$ip|$acc","smtpauth")} else {return}
}
if (($config{LF_INTERWORX}) and ($globlogs{INTERWORX_LOG}{$lgfile}) and ($line =~ /^\S+ \S+ (\S+) (\S+) (\S+)/)) {
my $iw = "SiteWorx";
if ($1 eq "NW") {$iw = "NodeWorx"}
my $ip = $2;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed $iw login from","$ip|$acc","interworx")} else {return}
}
# CWP
if (($config{LF_CWP}) and ($globlogs{CWP_LOG}{$lgfile}) and ($line =~ /^\S+\s+\S+\s+(\S+)\s+Failed Login from:\s+(\S+) on:/)) {
my $ip = $2;
my $acc = $1;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed CWP login from","$ip|$acc","cwp")} else {return}
}
# VestaCP
if (($config{LF_VESTA}) and ($globlogs{VESTA_LOG}{$lgfile}) and ($line =~ /^\S+\s+\S+\s+(\S+)\s+(\S+) failed to login/)) {
my $ip = $2;
my $acc = $1;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("Failed VestaCP login from","$ip|$acc","vesta")} else {return}
}
}
# end processline
###############################################################################
# start processloginline
sub processloginline {
my $line = shift;
#courier-imap
if (($config{LT_POP3D}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ pop3d(-ssl)?: LOGIN, user=(\S*), ip=\[(\S+)\], port=\S+/)) {
my $ip = $4;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("pop3d",$acc,$ip)} else {return}
}
if (($config{LT_IMAPD}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ imapd(-ssl)?: LOGIN, user=(\S*), ip=\[(\S+)\], port=\S+/)) {
my $ip = $4;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("imapd",$acc,$ip)} else {return}
}
#dovecot
if (($config{LT_POP3D}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ dovecot(\[\d+\])?: pop3-login: Login: user=<(\S*)>, method=\S+, rip=(\S+), lip=/)) {
my $ip = $4;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("pop3d",$acc,$ip)} else {return}
}
if (($config{LT_IMAPD}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ dovecot(\[\d+\])?: imap-login: Login: user=<(\S*)>, method=\S+, rip=(\S+), lip=/)) {
my $ip = $4;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("imapd",$acc,$ip)} else {return}
}
#InterWorx (dovecot)
if (($config{LT_POP3D}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) pop3-login: Info: Login: user=<(\S*)>, method=\S+, rip=(\S+), lip=/)) {
my $ip = $3;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("pop3d",$acc,$ip)} else {return}
}
if (($config{LT_IMAPD}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) imap-login: Info: Login: user=<(\S*)>, method=\S+, rip=(\S+), lip=/)) {
my $ip = $3;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ("imapd",$acc,$ip)} else {return}
}
}
# end processloginline
###############################################################################
# start processsshline
sub processsshline {
my $line = shift;
if (($config{LF_SSH_EMAIL_ALERT}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sshd\[\d+\]: Accepted (\S+) for (\S+) from (\S+) port \S+/)) {
my $ip = $5;
my $acc = $4;
my $how = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ($acc,$ip,$how)} else {return}
}
}
# end processsshline
###############################################################################
# start processsuline
sub processsuline {
my $line = shift;
#RH + Debian/Ubuntu
if (($config{LF_SU_EMAIL_ALERT}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?su(\[\d+\])?: pam_unix\(su(-l)?:session\): session opened for user\s+(\S+)\s+by\s+(\S+)\s*$/)) {
return ($5,$6,"Successful login");
}
if (($config{LF_SU_EMAIL_ALERT}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?su(\[\d+\])?: pam_unix\(su(-l)?:auth\): authentication failure; logname=\S*\s+\S+\s+\S+\s+\S+\s+ruser=(\S+)+\s+\S+\s+user=(\S+)\s*$/)) {
return ($6,$5,"Failed login");
}
if (($config{LF_SU_EMAIL_ALERT}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?su(\[\d+\])?: pam_unix\(su(-l)?:session\): session opened for user\s+(\S+)\s+by\s+(\S+)\s*$/)) {
return ($5,$6,"Successful login");
}
if (($config{LF_SU_EMAIL_ALERT}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?su(\[\d+\])?: pam_unix\(su(-l)?:auth\): authentication failure; logname=\S*\s+\S+\s+\S+\s+\S+\s+ruser=(\S+)+\s+\S+\s+user=(\S+)\s*$/)) {
return ($6,$5,"Failed login");
}
if (($config{LF_SU_EMAIL_ALERT}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?su\(pam_unix\)\[\d+\]: session opened for user\s+(\S+)\s+by\s+(\S+)\s*$/)) {
return ($3,$4,"Successful login");
}
if (($config{LF_SU_EMAIL_ALERT}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?su\(pam_unix\)\[\d+\]: authentication failure; logname=\S*\s+\S+\s+\S+\s+\S+\s+ruser=(\S+)+\s+\S+\s+user=(\S+)\s*$/)) {
return ($4,$3,"Failed login");
}
return;
}
# end processsuline
###############################################################################
# start processsudoline
sub processsudoline {
my $line = shift;
if (($config{LF_SUDO_EMAIL_ALERT}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sudo(\[\d+\])?: pam_unix\(sudo(-l)?:auth\): authentication failure; logname=\S*\s+\S+\s+\S+\s+\S+\s+ruser=(\S+)+\s+\S+\s+user=(\S+)\s*$/)) {
return ($6,$5,"Failed login");
}
if (($config{LF_SUDO_EMAIL_ALERT}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sudo\(pam_unix\)\[\d+\]: authentication failure; logname=\S*\s+\S+\s+\S+\s+\S+\s+ruser=(\S+)+\s+\S+\s+user=(\S+)\s*$/)) {
return ($4,$3,"Failed login");
}
if (($config{LF_SUDO_EMAIL_ALERT}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) (\S+ )?sudo(\[\d+\])?:\s+(\S+)\s+:\s+(.*)$/)) {
my $from = $4;
my @items = split(/\s+;\s+/, $5);
if ($items[0] =~ /^TTY/) {
if ($items[2] =~ /^USER=(\S+)$/) {
return ($1,$from,"Successful login");
}
}
elsif ($items[0] =~ /^user NOT in sudoers/) {
if ($items[3] =~ /^USER=(\w+)$/) {
return ($1,$from,"Failed login");
}
}
}
return;
}
# end processsudoline
###############################################################################
# start processconsoleline
sub processconsoleline {
my $line = shift;
if (($config{LF_CONSOLE_EMAIL_ALERT}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ login(\[\d+\])?: ROOT LOGIN/)) {
return 1;
}
}
# end processconsoleline
###############################################################################
# start processcpanelline
sub processcpanelline {
my $line = shift;
if ($config{LF_CPANEL_ALERT} and ($line =~ /^(\S+)\s+\-\s+(\w+)\s+\[[^\]]+\]\s\"[^\"]+\"\s200\s/)) {
my $ip = $1;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ($ip,$acc)} else {return}
}
}
# end processcpanelline
###############################################################################
# start processwebminline
sub processwebminline {
my $line = shift;
if ($config{LF_WEBMIN_EMAIL_ALERT} and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ webmin\[\d+\]: Successful login as (\S+) from (\S+)/)) {
my $ip = $3;
my $acc = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ($acc,$ip)} else {return}
}
}
# end processwebminline
###############################################################################
# start scriptlinecheck
sub scriptlinecheck {
my $line = shift;
if ($config{LF_SCRIPT_ALERT}) {
my $fulldir;
if ($line =~ /^\S+\s+\S+\s+(\[\d+\]\s)?cwd=(.*) \d+ args:/) {$fulldir = $2}
elsif ($line =~ /^\S+\s+\S+\s+(\[\d+\]\s)?\S+ H=localhost (.*)PWD=(.*) REMOTE_ADDR=\S+$/) {$fulldir = $3}
if ($fulldir ne "") {
my (undef,$dir,undef) = split(/\//,$fulldir);
if ($dir eq "home") {return $fulldir}
if ($cpconfig{HOMEDIR} and ($fulldir =~ /^$cpconfig{HOMEDIR}/)) {return $fulldir}
if ($cpconfig{HOMEMATCH} and ($dir =~ /$cpconfig{HOMEMATCH}/)) {return $fulldir}
}
}
}
# end scriptlinecheck
###############################################################################
# start relaycheck
sub relaycheck {
my $line = shift;
my $tline = $line;
$tline =~ s/".*"/""/g;
my @bits =split(/\s+/,$tline);
my $ip;
if ($tline !~ /^\S+\s+\S+\s+(\[\d+\]\s)?\S+ <=/) {return}
#exim
if ($tline =~ / U=(\S+) P=local /) {
return ($1, "LOCALRELAY");
}
if ($tline =~ / H=[^=]*\[(\S+)\]/) {
$ip = $1;
unless (checkip(\$ip) or $ip eq "127.0.0.1" or $ip eq "::1") {return}
} else {
return;
}
if (($tline =~ / A=(courier_plain|courier_login|dovecot_plain|dovecot_login|fixed_login|fixed_plain|login|plain):/) and ($tline =~ / P=(esmtpa|esmtpsa) /)) {
return ($ip, "AUTHRELAY");
}
if ($tline =~ / P=(smtp|esmtp|esmtps) /) {
return ($ip, "RELAY");
}
}
# end relaycheck
###############################################################################
# start pslinecheck
sub pslinecheck {
my $line = shift;
if ($line !~ /^(\S+|\S+\s+\d+\s+\S+) \S+ kernel:\s(\[[^\]]+\]\s)?Firewall:/) {return}
if ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ kernel:\s(\[[^\]]+\]\s)?Firewall: \*INVALID\*/ and $config{PS_PORTS} !~ /INVALID/) {return}
if ($line =~ /IN=\S+.*SRC=(\S+).*DST=(\S+).*PROTO=(\w+).*DPT=(\d+)/) {
my $ip = $1;
my $dst = $2;
my $proto = $3;
my $port = $4;
$ip =~ s/^::ffff://;
if ($config{PS_PORTS} !~ /BRD/ and $proto eq "UDP" and $brd{$dst} and !$ips{$dst}) {return}
if ($config{PS_PORTS} !~ /OPEN/) {
my $hit = 0;
if ($proto eq "TCP" and $line =~ /kernel:\s(\[[^\]]+\]\s)?Firewall: \*TCP_IN Blocked\*/) {
foreach my $ports (split(/\,/,$config{TCP_IN})) {
if ($ports =~ /\:/) {
my ($start,$end) = split(/\:/,$ports);
if ($port >= $start and $port <= $end) {$hit = 1}
}
elsif ($port == $ports) {$hit = 1}
if ($hit) {last}
}
if ($hit) {
if ($config{DEBUG} >= 1) {ConfigServer::Logger::logfile("debug: *Port Scan* ignored TCP_IN port: $ip:$port")}
return;
}
}
elsif ($proto eq "UDP" and $line =~ /kernel:\s(\[[^\]]+\]\s)?Firewall: \*UDP_IN Blocked\*/) {
foreach my $ports (split(/\,/,$config{UDP_IN})) {
if ($ports =~ /\:/) {
my ($start,$end) = split(/\:/,$ports);
if ($port >= $start and $port <= $end) {$hit = 1}
}
elsif ($port == $ports) {$hit = 1}
if ($hit) {last}
}
if ($hit) {
if ($config{DEBUG} >= 1) {ConfigServer::Logger::logfile("debug: *Port Scan* ignored UDP_IN port: $ip:$port")}
return;
}
}
}
if (checkip(\$ip)) {return ($ip,$port)} else {return}
}
if ($line =~ /IN=\S+.*SRC=(\S+).*PROTO=(ICMP)/) {
my $ip = $1;
my $port = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ($ip,$port)} else {return}
}
if ($line =~ /IN=\S+.*SRC=(\S+).*PROTO=(ICMPv6)/) {
my $ip = $1;
my $port = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ($ip,$port)} else {return}
}
}
# end pslinecheck
###############################################################################
# start uidlinecheck
sub uidlinecheck {
my $line = shift;
if ($line !~ /^(\S+|\S+\s+\d+\s+\S+) \S+ kernel(\[\d+\])?:\s(\[[^\]]+\]\s)?Firewall:/) {return}
if ($line =~ /OUT=\S+.*DPT=(\S+).*UID=(\d+)/) {return ($1,$2)}
}
# end uidlinecheck
###############################################################################
# start portknockingcheck
sub portknockingcheck {
my $line = shift;
if ($line !~ /^(\S+|\S+\s+\d+\s+\S+) \S+ kernel(\[\d+\])?:\s(\[[^\]]+\]\s)?Knock: \*\d+_IN\*/) {return}
if ($line =~ /SRC=(\S+).*DPT=(\d+)/) {
my $ip = $1;
my $port = $2;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ($ip,$port)} else {return}
}
}
# end portknockingcheck
###############################################################################
# start processdistftpline
sub processdistftpline {
my $line = shift;
#pure-ftpd
if ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ pure-ftpd(\[\d+\])?: \(\?\@(\S+)\) \[INFO\] (\S*) is now logged in$/) {
my $ip = $3;
my $acc = $4;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ($ip,$acc)} else {return}
}
#proftpd
if ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ proftpd\[\d+\]: \S+ \([^\[]+\[(\S+)\]\) - USER (\S*): Login successful\.\s*$/) {
my $ip = $2;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ($ip,$acc)} else {return}
}
#InterWorx proftpd
if ($line =~ /^\S+ \S+ \S+ proftpd\[\d+\]:? \S+ \(\S+?[^\[]+\[(\S+)\]\)( -)?:? USER (\S*): Login successful/) {
my $ip = $1;
my $acc = $3;
$ip =~ s/^::ffff://;
if (checkip(\$ip)) {return ($ip,$acc)} else {return}
}
}
# end processdistftpline
###############################################################################
# start processdistsmtpline
sub processdistsmtpline {
my $line = shift;
my $tline = $line;
$tline =~ s/".*"/""/g;
my @bits =split(/\s+/,$tline);
my $ip;
#postfix
if ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ postfix\/(submission\/)?smtpd(?:\[\d+\])?: \w+: client=\S+\[(\S+)\], sasl_method=(?:(?i)LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5), sasl_username=(\S+)$/) {
$ip = $3; my $account = $4; $ip =~ s/^::ffff://;
if (checkip(\$ip) and $ip ne "127.0.0.1" and $ip ne "::1") {return ($ip,$account)} else {return}
}
#InterWorx qmail
if ($line =~ /^\S+ qmail-smtpd\[\d+\]: AUTH successful \[(\S+)\] (\S+)/) {
$ip = $1; my $account = $2; $ip =~ s/^::ffff://;
if (checkip(\$ip) and $ip ne "127.0.0.1" and $ip ne "::1") {return ($ip,$account)} else {return}
}
#exim
if ($tline !~ /^\S+\s+\S+\s+(\[\d+\]\s)?\S+ <=/) {return}
if ($tline =~ / U=(\S+) P=local /) {return}
if ($tline =~ / H=[^=]*\[(\S+)\]/) {
$ip = $1;
unless (checkip(\$ip) or $ip eq "127.0.0.1" or $ip eq "::1") {return}
} else {
return;
}
if (($tline =~ / A=(courier_plain|courier_login|dovecot_plain|dovecot_login|fixed_login|fixed_plain|login|plain):(\S+)/)){
my $account = $2;
if (($tline =~ / P=(esmtpa|esmtpsa) /)) {return ($ip, $account)}
}
}
# end processdistsmtpline
###############################################################################
# start loginline404
sub loginline404 {
my $line = shift;
if ($line =~ /^\[\S+\s+\S+\s+\S+\s+\S+\s+\S+\] \[(\S*:)?(error|info)\] (\[pid \d+(:tid \d+)?\] )?\[(client|remote) (\S+)\] (\w+: )?File does not exist\:/) {
my $ip = $6;
$ip =~ s/^::ffff://;
if ($config{LF_APACHE_ERRPORT} == 2 and $ip =~ /(.*):\d+$/) {$ip = $1}
if (checkip(\$ip)) {return ($ip)} else {return}
}
}
# end loginline404
###############################################################################
# start loginline403
sub loginline403 {
my $line = shift;
if ($line =~ /^\[\S+\s+\S+\s+\S+\s+\S+\s+\S+\] \[(\S*:)?error\] (\[pid \d+(:tid \d+)?\] )?\[(client|remote) (\S+)\] (\w+: )?client denied by server configuration\:/) {
my $ip = $5;
$ip =~ s/^::ffff://;
if ($config{LF_APACHE_ERRPORT} == 2 and $ip =~ /(.*):\d+$/) {$ip = $1}
if (checkip(\$ip)) {return ($ip)} else {return}
}
}
# end loginline403
###############################################################################
# start loginline401
sub loginline401 {
my $line = shift;
if ($line =~ /^\[\S+\s+\S+\s+\S+\s+\S+\s+\S+\] \[(\S*:)?error\] (\[pid \d+(:tid \d+)?\] )?\[(client|remote) (\S+)\] (\w+: )?(user not found|user \w+ not found|user \w+: authentication failure for "\/\w+\/")\:/) {
my $ip = $5;
$ip =~ s/^::ffff://;
if ($config{LF_APACHE_ERRPORT} == 2 and $ip =~ /(.*):\d+$/) {$ip = $1}
if (checkip(\$ip)) {return ($ip)} else {return}
}
}
# end loginline401
###############################################################################
# start statscheck
sub statscheck {
my $line = shift;
if ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ kernel:\s(\[[^\]]+\]\s)?(Firewall|Knock):/) {return 1}
}
# end statscheck
###############################################################################
# start syslogcheckline
sub syslogcheckline {
my $line = shift;
my $syslogcheckcode = shift;
if ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ lfd\[\d+\]: SYSLOG check \[(\S+)\]\s*$/) {
if ($2 eq $syslogcheckcode) {return 1} else {return}
}
}
# end syslogcheckline
###############################################################################
1;
PK \e[(T( ( DisplayResellerUI.pmnu [ ###############################################################################
# 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::DisplayResellerUI;
use strict;
use lib '/usr/local/csf/lib';
use Fcntl qw(:DEFAULT :flock);
use POSIX qw(:sys_wait_h sysconf strftime);
use File::Basename;
use Net::CIDR::Lite;
use IPC::Open3;
use ConfigServer::Config;
use ConfigServer::CheckIP qw(checkip);
use ConfigServer::Sendmail;
use ConfigServer::Logger;
use Exporter qw(import);
our $VERSION = 1.01;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw();
umask(0177);
our ($chart, $ipscidr6, $ipv6reg, $ipv4reg, %config, %ips, $mobile,
%FORM, $script, $script_da, $images, $myv, %rprivs, $hostname,
$hostshort, $tz, $panel);
#
###############################################################################
# start main
sub main {
my $form_ref = shift;
%FORM = %{$form_ref};
$script = shift;
$script_da = shift;
$images = shift;
$myv = shift;
open (my $IN,"<","/etc/csf/csf.resellers");
flock ($IN, LOCK_SH);
while (my $line = <$IN>) {
my ($user,$alert,$privs) = split(/\:/,$line);
$privs =~ s/\s//g;
foreach my $priv (split(/\,/,$privs)) {
$rprivs{$user}{$priv} = 1;
}
$rprivs{$user}{ALERT} = $alert;
}
close ($IN);
open (my $HOSTNAME, "<","/proc/sys/kernel/hostname");
flock ($HOSTNAME, LOCK_SH);
$hostname = <$HOSTNAME>;
chomp $hostname;
close ($HOSTNAME);
$hostshort = (split(/\./,$hostname))[0];
$tz = strftime("%z", localtime);
my $config = ConfigServer::Config->loadconfig();
%config = $config->config();
$panel = "cPanel";
if ($config{GENERIC}) {$panel = "Generic"}
if ($config{INTERWORX}) {$panel = "InterWorx"}
if ($config{DIRECTADMIN}) {$panel = "DirectAdmin"}
if ($FORM{ip} ne "") {$FORM{ip} =~ s/(^\s+)|(\s+$)//g}
if ($FORM{action} ne "" and !checkip(\$FORM{ip})) {
print "\n";
print "| ";
print "[$FORM{ip}] is not a valid IP address\n";
print " |
\n";
print "
\n";
} else {
if ($FORM{action} eq "qallow" and $rprivs{$ENV{REMOTE_USER}}{ALLOW}) {
if ($FORM{comment} eq "") {
print "\n";
print "| You must provide a Comment for this option |
\n";
} else {
$FORM{comment} =~ s/"//g;
print "\n";
print "| ";
print " Allowing $FORM{ip}... \n\n";
my $text = &printcmd("/usr/sbin/csf","-a",$FORM{ip},"ALLOW by Reseller $ENV{REMOTE_USER} ($FORM{comment})");
print "\n...Done. \n";
print " |
\n";
if ($rprivs{$ENV{REMOTE_USER}}{ALERT}) {
open (my $IN, "<", "/usr/local/csf/tpl/reselleralert.txt");
flock ($IN, LOCK_SH);
my @alert = <$IN>;
close ($IN);
chomp @alert;
my @message;
foreach my $line (@alert) {
$line =~ s/\[reseller\]/$ENV{REMOTE_USER}/ig;
$line =~ s/\[action\]/ALLOW/ig;
$line =~ s/\[ip\]/$FORM{ip}/ig;
$line =~ s/\[rip\]/$ENV{REMOTE_HOST}/ig;
$line =~ s/\[text\]/Result of ALLOW:\n\n$text/ig;
push @message, $line;
}
ConfigServer::Sendmail::relay("", "", @message);
}
ConfigServer::Logger::logfile("$panel Reseller [$ENV{REMOTE_USER}]: ALLOW $FORM{ip}");
}
print "\n";
}
elsif ($FORM{action} eq "qdeny" and $rprivs{$ENV{REMOTE_USER}}{DENY}) {
if ($FORM{comment} eq "") {
print "\n";
print "| You must provide a Comment for this option |
\n";
} else {
$FORM{comment} =~ s/"//g;
print "\n";
print "| ";
print " Blocking $FORM{ip}... \n\n";
my $text = &printcmd("/usr/sbin/csf","-d",$FORM{ip},"DENY by Reseller $ENV{REMOTE_USER} ($FORM{comment})");
print "\n...Done. \n";
print " |
\n";
if ($rprivs{$ENV{REMOTE_USER}}{ALERT}) {
open (my $IN, "<", "/usr/local/csf/tpl/reselleralert.txt");
flock ($IN, LOCK_SH);
my @alert = <$IN>;
close ($IN);
chomp @alert;
my @message;
foreach my $line (@alert) {
$line =~ s/\[reseller\]/$ENV{REMOTE_USER}/ig;
$line =~ s/\[action\]/DENY/ig;
$line =~ s/\[ip\]/$FORM{ip}/ig;
$line =~ s/\[rip\]/$ENV{REMOTE_HOST}/ig;
$line =~ s/\[text\]/Result of DENY:\n\n$text/ig;
push @message, $line;
}
ConfigServer::Sendmail::relay("", "", @message);
}
ConfigServer::Logger::logfile("$panel Reseller [$ENV{REMOTE_USER}]: DENY $FORM{ip}");
}
print "\n";
}
elsif ($FORM{action} eq "qkill" and $rprivs{$ENV{REMOTE_USER}}{UNBLOCK}) {
my $text = "";
if ($rprivs{$ENV{REMOTE_USER}}{ALERT}) {
my ($childin, $childout);
my $pid = open3($childin, $childout, $childout, "/usr/sbin/csf","-g",$FORM{ip});
while (<$childout>) {$text .= $_}
waitpid ($pid, 0);
}
print "\n";
print "| ";
print " Unblock $FORM{ip}, trying permanent blocks... \n\n";
my $text1 = &printcmd("/usr/sbin/csf","-dr",$FORM{ip});
print "\n...Done. \n";
print "Unblock $FORM{ip}, trying temporary blocks... \n\n";
my $text2 = &printcmd("/usr/sbin/csf","-tr",$FORM{ip});
print "\n...Done. \n";
print " |
\n";
print "\n";
if ($rprivs{$ENV{REMOTE_USER}}{ALERT}) {
open (my $IN, "<", "/usr/local/csf/tpl/reselleralert.txt");
flock ($IN, LOCK_SH);
my @alert = <$IN>;
close ($IN);
chomp @alert;
my @message;
foreach my $line (@alert) {
$line =~ s/\[reseller\]/$ENV{REMOTE_USER}/ig;
$line =~ s/\[action\]/UNBLOCK/ig;
$line =~ s/\[ip\]/$FORM{ip}/ig;
$line =~ s/\[rip\]/$ENV{REMOTE_HOST}/ig;
$line =~ s/\[text\]/Result of GREP before UNBLOCK:\n$text\n\nResult of UNBLOCK:\nPermanent:\n$text1\nTemporary:\n$text2\n/ig;
push @message, $line;
}
ConfigServer::Sendmail::relay("", "", @message);
}
ConfigServer::Logger::logfile("$panel Reseller [$ENV{REMOTE_USER}]: UNBLOCK $FORM{ip}");
}
elsif ($FORM{action} eq "grep" and $rprivs{$ENV{REMOTE_USER}}{GREP}) {
print "\n";
print "| ";
print " Searching for $FORM{ip}... \n\n";
&printcmd("/usr/sbin/csf","-g",$FORM{ip});
print "\n...Done. \n";
print " |
\n";
print "\n";
}
else {
print "
\n";
}
}
print "
\n";
print "csf: v$myv
";
print "©2006-2023, ConfigServer Services (Way to the Web Limited)
\n";
return;
}
# end main
###############################################################################
# start printcmd
sub printcmd {
my @command = @_;
my $text;
my ($childin, $childout);
my $pid = open3($childin, $childout, $childout, @command);
while (<$childout>) {print $_ ; $text .= $_}
waitpid ($pid, 0);
return $text;
}
# end printcmd
###############################################################################
1;
PK \e[ԠM<