From c139a653e5ea6aabd3f6f316f1d69eeb0e3e1cb2 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 28 Apr 2020 10:22:45 +0100 Subject: [PATCH] Ability to scan all users --- src/cgi/index.cgi | 9 +++++++++ src/lib/WHM/Maldet.pm | 18 +++++++++++++++++- src/templates/maldet.tmpl | 18 ++++++++++++++++++ version.txt | 2 +- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/cgi/index.cgi b/src/cgi/index.cgi index 83eb7b6..ecbe5d1 100644 --- a/src/cgi/index.cgi +++ b/src/cgi/index.cgi @@ -120,7 +120,16 @@ if ( $FORM{'cgiaction'} eq '' ) { "print" => 1, "output" => $output, }); +} elsif ( $FORM{'cgiaction'} eq 'scan_all_recent') { + my $output = Whostmgr::Maldet::scan_all_recent($FORM{'recent'}); + Cpanel::Template::process_template( + 'whostmgr', + { + "template_file" => "maldet/start_scan.tmpl", + "print" => 1, + "output" => $output, + }); } elsif ( $FORM{'cgiaction'} eq 'enableuser' ) { Whostmgr::Maldet::enable_userscan(); Whostmgr::HTMLInterface::redirect('index.cgi'); diff --git a/src/lib/WHM/Maldet.pm b/src/lib/WHM/Maldet.pm index 8c7b12a..3bd35ff 100644 --- a/src/lib/WHM/Maldet.pm +++ b/src/lib/WHM/Maldet.pm @@ -10,6 +10,7 @@ use Whostmgr::Accounts::List (); use Cpanel::SafeRun::Errors; use Cpanel::PwCache; use Config::Tiny; +use Cpanel::Config::LoadWwwAcctConf (); our @config_files = ('conf.maldet', 'ignore_file_ext', 'ignore_inotify', 'ignore_paths', 'ignore_sigs'); our $LMD_BIN = '/usr/local/sbin/maldet'; @@ -114,7 +115,22 @@ sub update_maldet { sub scan_user { my $user = shift; my $homedir = Cpanel::PwCache::gethomedir($user); - my $result = Cpanel::SafeRun::Errors::saferunallerrors($LMD_BIN, '-b', '-a', "$homedir/public_html"); + if ($homedir) { + my $result = Cpanel::SafeRun::Errors::saferunallerrors($LMD_BIN, '-b', '-a', "$homedir/public_html"); + return $result; + } +} + +sub scan_all_recent { + my $recent = shift; + $recent = int( $recent )|| 2; + + my $cref = Cpanel::Config::LoadWwwAcctConf::loadwwwacctconf(); + my $homematch = ( defined $cref->{'HOMEMATCH'} ? $cref->{'HOMEMATCH'} : ( -d '/home' ? '/home' : '/usr/home' ) ); + $homematch =~ s/\*//; + $homematch =~ s/^([^\/].*)/\/$1/; + + my $result = Cpanel::SafeRun::Errors::saferunallerrors($LMD_BIN, '-b', '-r', "$homematch?/?/public_html", $recent); return $result; } diff --git a/src/templates/maldet.tmpl b/src/templates/maldet.tmpl index 5d1999e..492715c 100644 --- a/src/templates/maldet.tmpl +++ b/src/templates/maldet.tmpl @@ -80,6 +80,24 @@ Use the panels below to configure LMD. +

Scan user public_html directory

+

+ +
+

+

Scan All Users

+
+ + +
+

Scan files modified recently

diff --git a/version.txt b/version.txt index 0c62199..ee1372d 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.2.1 +0.2.2