From 7ebd0530e7e0ff0538ac4bb5f26ed62fff907138 Mon Sep 17 00:00:00 2001 From: "renater.salaun" <renater.salaun@047e039d-479c-447e-8a29-aa6bf4a09bab> Date: Fri, 3 Oct 2014 10:15:51 +0000 Subject: [PATCH] Moved Conf.pm to conf/ directory git-svn-id: https://svn.geant.net/GEANT/edugain_testidp_account_manager/trunk@15 047e039d-479c-447e-8a29-aa6bf4a09bab --- bin/account-manager-client.pl | 17 ++++++++++++++--- bin/account-manager-web.pl | 9 +++++---- bin/create-database.pl | 11 ++++++----- bin/expire-test-accounts.pl | 3 ++- lib/IdPAccountManager/SAMLMetadata.pm | 2 +- lib/IdPAccountManager/TestAccount.pm | 4 ++-- lib/IdPAccountManager/Tools.pm | 18 +++++++++--------- 7 files changed, 39 insertions(+), 25 deletions(-) diff --git a/bin/account-manager-client.pl b/bin/account-manager-client.pl index 3e71271..c1dccd6 100755 --- a/bin/account-manager-client.pl +++ b/bin/account-manager-client.pl @@ -6,15 +6,17 @@ use strict; use utf8; use lib "/opt/testidp/IdPAccountManager/lib"; +use lib "/opt/testidp/IdPAccountManager/conf"; use Getopt::Long; use POSIX; use IdPAccountManager::TestAccount; use IdPAccountManager::SAMLMetadata; +use IdPAccountManager::ServiceProvider; my %options; -unless (&GetOptions(\%options, 'help', 'create_test_account', 'account_profile=s', 'sp_entityid=s', 'list_test_accounts', 'parse_federation_metadata')) { +unless (&GetOptions(\%options, 'help', 'create_test_account', 'account_profile=s', 'sp_entityid=s', 'list_test_accounts', 'parse_federation_metadata', 'list_service_providers')) { die "Unknown options."; } @@ -65,7 +67,7 @@ if ($options{'create_test_account'}) { } }elsif ($options{'parse_federation_metadata'}) { my $federation_metadata = new IdPAccountManager::SAMLMetadata; - unless ($federation_metadata->load(federation_metadata_file_path => $IdPAccountManager::Conf::global{'federation_metadata_file_path'})) { + unless ($federation_metadata->load(federation_metadata_file_path => $Conf::global{'federation_metadata_file_path'})) { die; } @@ -78,12 +80,21 @@ if ($options{'create_test_account'}) { die; } - printf "Document %s parsed\n", $IdPAccountManager::Conf::global{'federation_metadata_file_path'}; + printf "Document %s parsed\n", $Conf::global{'federation_metadata_file_path'}; ## List SAML entities printf "Hashref representing the metadata:\n"; &IdPAccountManager::Tools::dump_var($federation_metadata->{'federation_metadata_as_hashref'}, 0, \*STDOUT); +}elsif ($options{'list_service_providers'}) { + + my %args; + + my $all = IdPAccountManager::ServiceProvider::list_service_providers(%args); + + foreach my $service_provider (@$all) { + $service_provider->print(); + } }else { die "Missing arguments"; diff --git a/bin/account-manager-web.pl b/bin/account-manager-web.pl index 6415ecd..5707ee9 100755 --- a/bin/account-manager-web.pl +++ b/bin/account-manager-web.pl @@ -6,6 +6,7 @@ use strict vars; use utf8; use lib "/opt/testidp/IdPAccountManager/lib"; +use lib "/opt/testidp/IdPAccountManager/conf"; use CGI; use CGI::Cookie; @@ -35,7 +36,7 @@ my %actions = ('select_sp' => {'title_en' => 'Select your Service Provider' } ## Gives writes for the group umask 0002; -chdir $IdPAccountManager::Conf::global{'root_manager_dir'}; +chdir $Conf::global{'root_manager_dir'}; my $request = new WebRequest; @@ -71,7 +72,7 @@ sub new { $request->{'param_out'}{'url_cgi'} = $ENV{'SCRIPT_NAME'}; $request->{'param_out'}{'env'} = \%ENV; $request->{'param_out'}{'actions'} = \%actions; - $request->{'param_out'}{'conf'} = \%IdPAccountManager::Conf::global; + $request->{'param_out'}{'conf'} = \%Conf::global; ## Dumping input data #open TMP, ">/tmp/account_manager.in"; &IdPAccountManager::Tools::dump_var($request->{'param_in'}, 0, \*TMP); close TMP; @@ -228,7 +229,7 @@ sub req_get_sp_list { &IdPAccountManager::Tools::do_log('info', ""); my $federation_metadata = new IdPAccountManager::SAMLMetadata; - unless ($federation_metadata->load(federation_metadata_file_path => $IdPAccountManager::Conf::global{'federation_metadata_file_path'})) { + unless ($federation_metadata->load(federation_metadata_file_path => $Conf::global{'federation_metadata_file_path'})) { push @{$self->{'param_out'}{'errors'}}, "internal"; &IdPAccountManager::Tools::do_log('error', "Failed to load federation metadata : $!"); return undef; @@ -258,7 +259,7 @@ sub req_select_sp { } my $federation_metadata = new IdPAccountManager::SAMLMetadata; - unless ($federation_metadata->load(federation_metadata_file_path => $IdPAccountManager::Conf::global{'federation_metadata_file_path'})) { + unless ($federation_metadata->load(federation_metadata_file_path => $Conf::global{'federation_metadata_file_path'})) { push @{$self->{'param_out'}{'errors'}}, "internal"; &IdPAccountManager::Tools::do_log('error', "Failed to load federation metadata : $!"); return undef; diff --git a/bin/create-database.pl b/bin/create-database.pl index c464be9..a154a59 100755 --- a/bin/create-database.pl +++ b/bin/create-database.pl @@ -2,24 +2,25 @@ ## Initialize Rose::DB code given the DB structure use lib "/opt/testidp/IdPAccountManager/lib"; +use lib "/opt/testidp/IdPAccountManager/conf"; use Rose::DB; use Rose::DB::Object::Loader; use Getopt::Long; -use IdPAccountManager::Conf; +use Conf; my %options; unless (&GetOptions(\%options, 'database=s')) { die "Unknown options."; } -my $dbname = $options{'database'} || $IdPAccountManager::Conf::global{'database_name'}; +my $dbname = $options{'database'} || $Conf::global{'database_name'}; $loader = Rose::DB::Object::Loader->new( - db_dsn => 'dbi:'.$IdPAccountManager::Conf::global{'database_type'}.':dbname='.$dbname.';host='.$IdPAccountManager::Conf::global{'database_host'}, - db_username => $IdPAccountManager::Conf::global{'database_user'}, - db_password => $IdPAccountManager::Conf::global{'database_password'}, + db_dsn => 'dbi:'.$Conf::global{'database_type'}.':dbname='.$dbname.';host='.$Conf::global{'database_host'}, + db_username => $Conf::global{'database_user'}, + db_password => $Conf::global{'database_password'}, db_options => { AutoCommit => 1, ChopBlanks => 1 }, class_prefix => 'IdPAccountManager::Data', #with_unique_keys => 0, diff --git a/bin/expire-test-accounts.pl b/bin/expire-test-accounts.pl index 070f7c7..cba9519 100755 --- a/bin/expire-test-accounts.pl +++ b/bin/expire-test-accounts.pl @@ -7,6 +7,7 @@ use strict; use utf8; use lib "/opt/testidp/IdPAccountManager/lib"; +use lib "/opt/testidp/IdPAccountManager/conf"; use Getopt::Long; use POSIX; @@ -40,7 +41,7 @@ if ($options {'list_only'}) { } printf "%d accounts removed\n", $#{$all}+1; - #&IdPAccountManager::Tools::dump_var(\%IdPAccountManager::Conf::global, 0, \*STDOUT); + #&IdPAccountManager::Tools::dump_var(\%Conf::global, 0, \*STDOUT); ## Update simpleSamlPhp configuration file printf "Update simpleSamlPhp configuration file...\n"; diff --git a/lib/IdPAccountManager/SAMLMetadata.pm b/lib/IdPAccountManager/SAMLMetadata.pm index 85e3467..37a705e 100644 --- a/lib/IdPAccountManager/SAMLMetadata.pm +++ b/lib/IdPAccountManager/SAMLMetadata.pm @@ -3,7 +3,7 @@ package IdPAccountManager::SAMLMetadata; use strict; use IdPAccountManager::Tools; -use IdPAccountManager::Conf; +use Conf; use XML::LibXML; diff --git a/lib/IdPAccountManager/TestAccount.pm b/lib/IdPAccountManager/TestAccount.pm index b7d43b3..22cf234 100644 --- a/lib/IdPAccountManager/TestAccount.pm +++ b/lib/IdPAccountManager/TestAccount.pm @@ -6,7 +6,7 @@ use IdPAccountManager::Data::Testaccount; use IdPAccountManager::Data::Testaccount::Manager; use IdPAccountManager::Tools; -use IdPAccountManager::Conf; +use Conf; require Exporter; my @ISA = qw(Exporter); @@ -58,7 +58,7 @@ sub save { ## If no id is defined, it is a new account unless (defined $self->{'persistent'}->id) { $self->{'persistent'}->creation_date(time); - $self->{'persistent'}->expiration_date(time + ($IdPAccountManager::Conf::global{'accounts_validity_period'} * 3600 * 24)); + $self->{'persistent'}->expiration_date(time + ($Conf::global{'accounts_validity_period'} * 3600 * 24)); $self->{'user_password'} = &IdPAccountManager::Tools::generate_password(); $self->{'persistent'}->user_password_hash(&IdPAccountManager::Tools::sha256_hash($self->{'user_password'})); } diff --git a/lib/IdPAccountManager/Tools.pm b/lib/IdPAccountManager/Tools.pm index 4451346..e0df349 100644 --- a/lib/IdPAccountManager/Tools.pm +++ b/lib/IdPAccountManager/Tools.pm @@ -56,11 +56,11 @@ sub generate_password{ ## Updates simpleSamlPhp authsources.php configuration file sub update_ssp_authsources { - my $tt2 = Template->new({'INCLUDE_PATH' => $IdPAccountManager::Conf::global{'root_manager_dir'}.':'.$IdPAccountManager::Conf::global{'root_manager_dir'}.'/templates/accountProfiles'}); + my $tt2 = Template->new({'INCLUDE_PATH' => $Conf::global{'root_manager_dir'}.':'.$Conf::global{'root_manager_dir'}.'/templates/accountProfiles'}); my %args = ('accounts' => IdPAccountManager::TestAccount::list_test_accounts(), - 'conf' => \%IdPAccountManager::Conf::global); + 'conf' => \%Conf::global); - #chdir $IdPAccountManager::Conf::global{'root_manager_dir'}; + #chdir $Conf::global{'root_manager_dir'}; my $template_file = 'templates/accountProfiles/valid-accounts.php.tt2'; my $output_file = 'conf/valid-accounts.php'; @@ -107,7 +107,7 @@ sub do_log { my $level = shift; my $message = shift; - unless ($log_levels{$level} < $log_levels{$IdPAccountManager::Conf::global{'log_level'}}) { + unless ($log_levels{$level} < $log_levels{$Conf::global{'log_level'}}) { ## Determine calling function and parameters ## If in 'err' level, build a stack trace @@ -131,7 +131,7 @@ sub do_log { my $ip = $ENV{'REMOTE_HOST'}.'/'.$ENV{'REMOTE_ADDR'} || 'NOIP'; my $date = POSIX::strftime ("%Y:%m:%d %H:%M:%S", localtime(time)); my $user = lc($ENV{'mail'}) || 'NOEMAIL'; - open LOG, ">>".$IdPAccountManager::Conf::global{'log_file'}; printf LOG "$date - ($level) - $ip - $user - $caller_string $message\n", @_; close LOG; + open LOG, ">>".$Conf::global{'log_file'}; printf LOG "$date - ($level) - $ip - $user - $caller_string $message\n", @_; close LOG; } return 1; } @@ -147,14 +147,14 @@ sub mail_notice { my $tt2_file = $in{'template'}; my $mail_data = $in{'data'}; - $mail_data->{'conf'} ||= \%IdPAccountManager::Conf::global; + $mail_data->{'conf'} ||= \%Conf::global; - my $notice_email = $in{'to'} || $IdPAccountManager::Conf::global{'admin_email'}; + my $notice_email = $in{'to'} || $Conf::global{'admin_email'}; $mail_data->{'to'} = $notice_email; ## Protection to prevent notifications during test dev phases ## Notify only adresses @renater.fr - if ($IdPAccountManager::Conf::global{'no_mail_outside'}) { + if ($Conf::global{'no_mail_outside'}) { foreach my $email (split /,/, $notice_email) { unless ($email =~ /\@(cru|renater)\.fr$/) { &do_log('error',"Notification to an external address skipped"); @@ -165,7 +165,7 @@ sub mail_notice { &do_log('trace', '(template=%s, to=%s)', $in{'template'}, $mail_data->{'to'}); - open SENDMAIL, "|/usr/sbin/sendmail -f ".$IdPAccountManager::Conf::global{'notice_from'}." $notice_email"; + open SENDMAIL, "|/usr/sbin/sendmail -f ".$Conf::global{'notice_from'}." $notice_email"; my $tt2 = Template->new(FILTERS => {qencode => [\&qencode, 0]}); unless ($tt2->process($tt2_file, $mail_data, \*SENDMAIL)) { -- GitLab