#!/usr/bin/perl ## 09/09/2014, Olivier Salaün ## Command-line script to remove expired test accounts ## The script also updates the simpleSamlPhp config file use strict; use utf8; use lib "/opt/testidp/IdPAccountManager/lib"; use Getopt::Long; use POSIX; use IdPAccountManager::TestAccount; my %options; unless (&GetOptions(\%options, 'help', 'list_only')) { die "Unknown options."; } if ($options{'help'}) { printf "$0 --list_only\n"; } if ($options {'list_only'}) { my $all = IdPAccountManager::TestAccount::list_test_accounts('query' => ['expiration_date' => {lt => time}]); foreach my $test_account (@$all) { printf "Account ID=%s; password=%s; sp_entityid=%s; account_profile=%s; creation_date=%s; expiration_date=%s\n", $test_account->id, $test_account->user_password, $test_account->sp_entityid, $test_account->account_profile, &POSIX::strftime('%Y:%m:%d', localtime($test_account->creation_date)), &POSIX::strftime('%Y:%m:%d', localtime($test_account->expiration_date)); } }else { ## Remove expired test accounts my $all = IdPAccountManager::TestAccount::list_test_accounts('query' => ['expiration_date' => {lt => time}]); printf "Removing expired test accounts...\n"; foreach my $test_account (@$all) { printf "\tAccount ID=%s; password=%s; sp_entityid=%s; account_profile=%s; creation_date=%s; expiration_date=%s\n", $test_account->id, $test_account->user_password, $test_account->sp_entityid, $test_account->account_profile, &POSIX::strftime('%Y:%m:%d', localtime($test_account->creation_date)), &POSIX::strftime('%Y:%m:%d', localtime($test_account->expiration_date)); $test_account->delete || die; } printf "%d accounts removed\n", $#{$all}+1; #&IdPAccountManager::Tools::dump_var(\%IdPAccountManager::Conf::global, 0, \*STDOUT); ## Update simpleSamlPhp configuration file printf "Update simpleSamlPhp configuration file...\n"; IdPAccountManager::Tools::update_ssp_authsources(); }