Skip to content

Commit

Permalink
Ability to scan all users
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul authored and Paul committed Apr 28, 2020
1 parent c4658b2 commit c139a65
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/cgi/index.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
18 changes: 17 additions & 1 deletion src/lib/WHM/Maldet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

Expand Down
18 changes: 18 additions & 0 deletions src/templates/maldet.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ Use the panels below to configure LMD.
</select>
<input type="submit" class="btn btn-primary" value="Go">
</form>
<p><small>Scan user public_html directory</small></p>
</p>
</div>
<div class="col-md-4">
<p>
<h4>Scan All Users</h4>
<form method="POST" action="index.cgi?cgiaction=scan_all_recent">
<select name="recent">
<option value="2">2 days</option>
<option value="3">3 days</option>
<option value="4">4 days</option>
<option value="5">5 days</option>
<option value="6">6 days</option>
<option value="7">7 days</option>
</select>
<input type="submit" class="btn btn-primary" value="Go">
</form>
<p><small>Scan files modified recently</small></p>
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.1
0.2.2

0 comments on commit c139a65

Please sign in to comment.