From 2fb08fe8e2b9bd150e39961058bc8232af3a1ee7 Mon Sep 17 00:00:00 2001
From: Guillaume Rousse <guillaume.rousse@renater.fr>
Date: Wed, 28 Nov 2018 18:31:17 +0100
Subject: [PATCH] allows usage of labels for federations

---
 bin/access-check-manager.cgi.in                  |  2 +-
 conf/manager.conf.in                             |  8 +++++---
 lib/AccountManager/App.pm                        | 13 ++++++++-----
 templates/web/edugain/select_federation.tt2.html |  6 +++---
 templates/web/renater/select_federation.tt2.html |  6 +++---
 5 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/bin/access-check-manager.cgi.in b/bin/access-check-manager.cgi.in
index d2933fe..9cf8b59 100755
--- a/bin/access-check-manager.cgi.in
+++ b/bin/access-check-manager.cgi.in
@@ -11,7 +11,7 @@ use AccountManager::App;
 
 my $configuration_file =
     $ENV{ACCOUNTMANAGER_CONFIG} || '@confdir@/manager.conf';
-my $configuration = Config::Tiny->read($configuration_file);
+my $configuration = Config::Tiny->read($configuration_file, 'utf8');
 if (!$configuration) {
     die Config::Tiny->errstr() . "\n";
 }
diff --git a/conf/manager.conf.in b/conf/manager.conf.in
index 06fb15b..9c4b251 100644
--- a/conf/manager.conf.in
+++ b/conf/manager.conf.in
@@ -9,6 +9,11 @@ templates_dir = @templatesdir@
 # templates theme
 templates_theme = edugain
 accounts_file = /var/lib/access-check/accounts.php
+federations = edugain
+
+[edugain]
+metadata = /var/lib/access-check/edugain.xml
+label = eduGAIN
 
 [logger]
 file = /var/log/access-check/manager.log
@@ -26,9 +31,6 @@ username = idpadmin
 password = secret
 options  = mysql_enable_utf8
 
-[federations]
-edugain = /var/lib/access-check/edugain.xml
-
 [idp]
 scope = my.fqdn
 entityid = https://my.fqdn/simplesaml/saml2/idp/metadata.php
diff --git a/lib/AccountManager/App.pm b/lib/AccountManager/App.pm
index 1be235c..5d2eab7 100644
--- a/lib/AccountManager/App.pm
+++ b/lib/AccountManager/App.pm
@@ -114,7 +114,7 @@ sub new {
         );
     }
 
-    if (!$self->{configuration}->{federations}) {
+    if (!$self->{configuration}->{setup}->{federations}) {
         $self->{logger}->fatal(
             "No federations defined in configuration, aborting"
         );
@@ -250,7 +250,8 @@ sub abort {
 sub req_start {
     my ($self, %args) = @_;
 
-    my @federations = keys %{$self->{configuration}->{federations}};
+    my $federations = $self->{configuration}->{setup}->{federations};
+    my @federations = split(/, */, $federations);
     if (@federations == 1) {
         $self->req_select_sp(federation => $federations[0]);
     } else {
@@ -262,13 +263,15 @@ sub req_start {
 sub req_select_federation {
     my ($self, %args) = @_;
 
-    my @federations = keys %{$self->{configuration}->{federations}};
+    my $federations = $self->{configuration}->{setup}->{federations};
+    my @federations = split(/, */, $federations);
+    my %federations = map { $_ => $self->{configuration}->{$_}->{label} } @federations;
 
     $self->respond(
         template => 'select_federation.tt2.html',
         data     => {
             action      => 'select_federation',
-            federations => \@federations
+            federations => \%federations
         }
     );
 }
@@ -751,7 +754,7 @@ sub get_metadata_file {
 
     my $federation = $args{federation};
 
-    my $file = $self->{configuration}->{federations}->{$federation};
+    my $file = $self->{configuration}->{$federation}->{metadata};
 
     $self->abort(
         log  => "Incorrect parameter: federation",
diff --git a/templates/web/edugain/select_federation.tt2.html b/templates/web/edugain/select_federation.tt2.html
index c19432d..061c094 100644
--- a/templates/web/edugain/select_federation.tt2.html
+++ b/templates/web/edugain/select_federation.tt2.html
@@ -14,9 +14,9 @@
 
         <fieldset>
             <legend>[% lh.maketext("Select the federation corresponding to the service you want to test:") %]</legend>
-        [% FOREACH federation IN federations.sort %]
-            <input id="[% federation %]" name="federation" value="[% federation %]" type="radio" class="required"/>
-            <label for="[% federation %]">[% federation %]</label>
+        [% FOREACH key IN federations.keys.sort %]
+            <input id="[% key %]" name="federation" value="[% key %]" type="radio" class="required"/>
+            <label for="[% key %]">[% federations.$key %]</label>
             <br/>
         [% END %]
             <label for="federation" class="error"></label>
diff --git a/templates/web/renater/select_federation.tt2.html b/templates/web/renater/select_federation.tt2.html
index c19432d..061c094 100644
--- a/templates/web/renater/select_federation.tt2.html
+++ b/templates/web/renater/select_federation.tt2.html
@@ -14,9 +14,9 @@
 
         <fieldset>
             <legend>[% lh.maketext("Select the federation corresponding to the service you want to test:") %]</legend>
-        [% FOREACH federation IN federations.sort %]
-            <input id="[% federation %]" name="federation" value="[% federation %]" type="radio" class="required"/>
-            <label for="[% federation %]">[% federation %]</label>
+        [% FOREACH key IN federations.keys.sort %]
+            <input id="[% key %]" name="federation" value="[% key %]" type="radio" class="required"/>
+            <label for="[% key %]">[% federations.$key %]</label>
             <br/>
         [% END %]
             <label for="federation" class="error"></label>
-- 
GitLab