From 2fa57561b06bec1ee0ef9b0ed79c0b45c6508550 Mon Sep 17 00:00:00 2001 From: Flaviu Mates Date: Mon, 18 May 2020 18:08:51 +0300 Subject: [PATCH] TT#76111 - Refresh DB admins when executing ngcpcfg apply * Completely manage LI admins by editing www_admin->lawful_intercept_admins in config.yml * Executing ngcpcfg apply will now add new admins found in config.yml, update their email if it is changed in config.yml, and delete them from DB if they're not found in config.yml Change-Id: Iae5874fe77443469354e4446b83a68b178e4730c --- helper/sync-db | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/helper/sync-db b/helper/sync-db index af662a2c..bc4b8c04 100755 --- a/helper/sync-db +++ b/helper/sync-db @@ -56,6 +56,8 @@ exit 1 unless(sync_general_timezone($dbh, exit 1 unless(sync_db_timezones($dbh)); +exit 1 unless(sync_li_admins($dbh, $config->{www_admin}->{lawful_intercept_admins})); + $dbh->disconnect; exit 0; @@ -253,4 +255,78 @@ SQL return 1; } +## add LI admins into MariaDB ############################## +sub sync_li_admins { + my ($dbh, $cfg_admins) = @_; + + my $sql = ''; + eval { + $dbh->begin_work() or die "Cannot start tx: $DBI::errstr\n"; + $dbh->do('USE billing') + or die "Cannot use billing database: $DBI::errstr\n"; + + my $existent_admins = $dbh->selectall_hashref(<{username} && $li_admin->{email}) { + print "A Lawful Intercept Administrator does not have username or password set\n"; + next; + } + if (!exists $existent_admins->{$li_admin->{username}} || + !$existent_admins->{$li_admin->{username}}->{email} || ($li_admin->{email} ne $existent_admins->{$li_admin->{username}}->{email})) { + #new admin or updated email + $vals and $vals .= ","; + $vals .= "('".$li_admin->{username}."','".$li_admin->{email}."','".$password."', 1, 1, 1, 1)"; + } + #delete all admins that have been found in config.yml and use the remaining ones for the delete statement + delete $existent_admins->{$li_admin->{username}}; + } + if ($vals) { + #insert new admins or update email + $dbh->do(<do(<rollback(); + return; + } + $dbh->commit(); + + return 1; +} + ## END OF FILE #################################################################