Merge branch 'feature/offline-license' into 'develop'

Add support for offline licenses.

See merge request artica/pandorafms!2001
This commit is contained in:
nramon 2018-11-21 12:10:13 +01:00
commit 8735adc252
2 changed files with 40 additions and 9 deletions

View File

@ -68,6 +68,7 @@ our @EXPORT = qw(
PROVISIONINGSERVER
MIGRATIONSERVER
METACONSOLE_LICENSE
OFFLINE_LICENSE
$DEVNULL
$OS
$OS_VERSION
@ -93,6 +94,7 @@ our @EXPORT = qw(
sqlWrap
is_numeric
is_metaconsole
is_offline
to_number
clean_blank
pandora_sendmail
@ -152,9 +154,12 @@ use constant MODULE_WARNING => 2;
use constant MODULE_UNKNOWN => 3;
use constant MODULE_NOTINIT => 4;
# Value for a metaconsole license type
# Mask for a metaconsole license type
use constant METACONSOLE_LICENSE => 0x01;
# Mask for an offline license type
use constant OFFLINE_LICENSE => 0x02;
# Alert modes
use constant RECOVERED_ALERT => 0;
use constant FIRED_ALERT => 1;
@ -1639,7 +1644,7 @@ sub is_metaconsole ($) {
my ($pa_config) = @_;
if (defined($pa_config->{"license_type"}) &&
$pa_config->{"license_type"} == METACONSOLE_LICENSE &&
($pa_config->{"license_type"} & METACONSOLE_LICENSE) &&
$pa_config->{"node_metaconsole"} == 0) {
return 1;
}
@ -1647,6 +1652,20 @@ sub is_metaconsole ($) {
return 0;
}
###############################################################################
# Returns 1 if a valid offline license is configured, 0 otherwise.
###############################################################################
sub is_offline ($) {
my ($pa_config) = @_;
if (defined($pa_config->{"license_type"}) &&
($pa_config->{"license_type"} & OFFLINE_LICENSE)) {
return 1;
}
return 0;
}
###############################################################################
# Check if a given variable contents a number
###############################################################################

View File

@ -1042,8 +1042,20 @@ else {
# Connect to the DB
my $dbh = db_connect ($conf{'dbengine'}, $conf{'dbname'}, $conf{'dbhost'}, $conf{'dbport'}, $conf{'dbuser'}, $conf{'dbpass'});
my $history_dbh = ($conf{'_history_db_enabled'} eq '1') ? db_connect ($conf{'dbengine'}, $conf{'_history_db_name'},
$conf{'_history_db_host'}, $conf{'_history_db_port'}, $conf{'_history_db_user'}, $conf{'_history_db_pass'}) : undef;
my $history_dbh = undef;
is_metaconsole(\%conf);
if ($conf{'_history_db_enabled'} eq '1') {
eval {
$history_dbh = db_connect ($conf{'dbengine'}, $conf{'_history_db_name'}, $conf{'_history_db_host'}, $conf{'_history_db_port'}, $conf{'_history_db_user'}, $conf{'_history_db_pass'});
};
if ($@) {
if (is_offline(\%conf)) {
log_message ('!', "Cannot connect to the history database. Skipping.");
} else {
die ("$@\n");
}
}
}
# Get a lock
my $lock = db_get_lock ($dbh, 'pandora_db');
@ -1055,13 +1067,13 @@ if ($lock == 0 && $conf{'_force'} == 0) {
# Main
pandoradb_main(\%conf, $dbh, $history_dbh);
# Cleanup and exit
db_disconnect ($history_dbh) if defined ($history_dbh);
db_disconnect ($dbh);
# Release the lock
if ($lock == 1) {
db_release_lock ($dbh, 'pandora_db');
}
exit 0;
# Cleanup and exit
db_disconnect ($history_dbh) if defined ($history_dbh);
db_disconnect ($dbh);
exit 0;