Skip to content

Added modules for antivirus programs Dr.Web and KESL #931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

AnilAntari
Copy link
Contributor

Added modules for antivirus programs Dr.Web and Kaspersky Endpoint Security.

These modules use Time::Piece for:

1. Data analysis

Converts data strings from the antivirus output (for example, 2025-06-09, February 15, 2023) into temporary objects.

Supports:

  • KESL: Accurate timestamps (2025-05-09, 19:20:00).
  • Dr.Web: Localized month names (February/June).

2. Time check

Compares the dates with the current time to check:

  • The license is valid (expired or not).
  • The freshness of the database (whether it has been updated in the last 2 days).

Some Linux distributions do not include the Time::Piece module by default, requiring manual installation.

Copy link
Member

@g-bougard g-bougard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AnilAntari

thank you for your PR.

Actually, I can't accept it as is.

SERVER_LICENSE is not supported in the format so you can remove related code.

Time::Piece module is used in piece of code to set UPTODATE but with assumption you can't really use. UPTODATE can only be set if AV really tells you it is up-to-date.

Time::Piece module is also used in piece of code to set EXPIRATION, but there I think it's overkill. Can you better get rid of this new dependency ?

Can you also provide output samples for all the used commands ?
Here is the list I'm thinking of:

LANG=C drweb-ctl --version
LANG=C drweb-ctl baseinfo
LANG=C drweb-ctl license
LANG=C kesl-control --app-info

If you have some difference context case with different output, don't hesitate to add them.

Comment on lines +82 to +90
# Check if database is up-to-date (within 2 days)
if ($db_timestamp) {
eval {
my $db_time = Time::Piece->strptime($db_timestamp, "%Y-%b-%d %H:%M:%S");
my $diff = time() - $db_time->epoch;
$av->{UPTODATE} = ($diff <= 172800) ? 1 : 0; # 172800 seconds = 2 days
};
$av->{UPTODATE} = 0 if $@;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fully agree with this test. It doesn't say AV is up-to-date, it says database is not older than 2 days. You assume the editor always publish an update at worst every 2 days. If editor doesn't have to publish an update on 2 consecutive days, glpi-agent will report is no more up-to-date even if it is.

IMHO, if this AV doesn't provide the data itself, just don't set it.

Comment on lines +101 to +104
eval {
my $expire_time = Time::Piece->strptime($1, "%Y-%b-%d");
$av->{EXPIRATION} = $expire_time->strftime("%Y-%m-%d");
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding Time::Piece requirement for such usage is totally overkill. Can you better get rid of Time::Piece ?

Comment on lines +110 to +112
elsif ($line =~ /license is granted by the protection server/i) {
$av->{SERVER_LICENSE} = 1;
last;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far I know, SERVER_LICENSE is not supported by the format. So you can remove this code.

Comment on lines +55 to +62
my $version_output = getFirstLine(
command => 'kesl-control --app-info 2>/dev/null | grep -E "Version|Версия"',
%params
);
# Extract version number from either English or Russian output
if ($version_output && $version_output =~ /(?:Version|Версия):\s+([\d.]+)/) {
$av->{VERSION} = $1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't run command with output piped to grep. As I see you do the same on $license_output and $db_date_output, involving you run kesl-control --app-info 3 times. Indeed, you should better use getAllLines() and analyze each lines.

Also, you shouldn't have to check on Cyrillic string as commands are run with "LANG=C" environment set.

Comment on lines +87 to +95
eval {
my $db_time = Time::Piece->strptime($1, "%Y-%m-%d %H:%M:%S");
my $diff = time() - $db_time->epoch;
# Mark as up-to-date if databases are less than 2 days old (172800 seconds)
$av->{UPTODATE} = ($diff <= 172800) ? 1 : 0;
};
if ($@) {
$logger->debug("Failed to parse database timestamp: $@");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the other module, you assume database is up-to-date where you can't. Just don't set this value or find the real data in another way.

Comment on lines +93 to +96
my @license_info = getAllLines(
command => 'drweb-ctl license 2>/dev/null',
%params
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to redirect stderr to null, getAllLines API still does it.

Comment on lines +47 to +50
my $service_status = getFirstLine(
command => 'systemctl is-active kesl.service 2>/dev/null',
%params
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to redirect stderr to null, getFirstLine API still does it.

Comment on lines +70 to +77
if ($license_output && $license_output =~ /(?:License expiration date|Дата окончания срока действия лицензии):\s+([\d-]+)/) {
eval {
my $expire_time = Time::Piece->strptime($1, "%Y-%m-%d");
$av->{EXPIRATION} = $expire_time->strftime("%Y-%m-%d");
};
if ($@) {
$logger->debug("Failed to parse license expiration: $@");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time::Piece usage is overkill here, please get rid of it.

You shouldn't have to parse against Cyrillic string as command is run with LANG=C set.

return $av;
}

1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A end-of-line seems to miss here.

return $av;
}

1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A end-of-line seems to miss here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants