From a8865ee094c87b6e288554b1b74cf2e7bb704882 Mon Sep 17 00:00:00 2001 From: Thomas CHEMINEAU Date: Fri, 12 Mar 2010 12:56:14 +0000 Subject: [PATCH] SAML: metadata could be now loaded through URL --- .../example/skins/default/manager.css | 18 ++++++++++ .../example/skins/default/manager.js | 21 ++++++----- .../example/skins/default/manager.tpl | 28 +++++++++++---- .../lib/Lemonldap/NG/Manager.pm | 8 +++++ .../lib/Lemonldap/NG/Manager/Uploader.pm | 36 +++++++++++++++++++ 5 files changed, 96 insertions(+), 15 deletions(-) diff --git a/modules/lemonldap-ng-manager/example/skins/default/manager.css b/modules/lemonldap-ng-manager/example/skins/default/manager.css index 51b63e197..1a1e26679 100644 --- a/modules/lemonldap-ng-manager/example/skins/default/manager.css +++ b/modules/lemonldap-ng-manager/example/skins/default/manager.css @@ -196,3 +196,21 @@ input background:#ddd; font-weight:bold; } + +/* Filearea */ +#content_filearea table tr td +{ + text-align:left; + vertical-align:center; +} +#content_filearea table +{ + margin-left:auto; + margin-right:auto; + padding-left:20px; +} +#content_filearea span.loadimg +{ + display:inline-block; + width:20px; +} diff --git a/modules/lemonldap-ng-manager/example/skins/default/manager.js b/modules/lemonldap-ng-manager/example/skins/default/manager.js index cbbc888fb..03c299be6 100644 --- a/modules/lemonldap-ng-manager/example/skins/default/manager.js +++ b/modules/lemonldap-ng-manager/example/skins/default/manager.js @@ -157,18 +157,19 @@ function setlmtext(id,v){ function setlmdata(id,v){ $('#text_'+id).attr('value',escape(v)); } -function setlmfile(id){ - $("#fileloading") - .ajaxStart(function(){ - $(this).show(); - }) - .ajaxComplete(function(){ - $(this).hide(); - }); +function setlmfile(id,input){ + var inputname=$(input).attr('id'); + $("#"+inputname+"-loadimg") + .ajaxStart(function(){ + $(this).show(); + }) + .ajaxComplete(function(){ + $(this).hide(); + }); $.ajaxFileUpload({ url:scriptname, secureuri:false, - fileElementId:'file', + fileElementId:inputname, dataType:'json', success:function(data,status){ if(typeof(data.errors) != 'undefined' && data.errors != ''){ @@ -184,6 +185,8 @@ function setlmfile(id){ $('#help_content').html('

Request failed

Error code: '+xhr.status+', '+thrownError); } }); + /* Remove global event on loading image */ + $("#"+inputname+"-loadimg").unbind('ajaxStart'); return false; } function setlmsamlassertion(id){ diff --git a/modules/lemonldap-ng-manager/example/skins/default/manager.tpl b/modules/lemonldap-ng-manager/example/skins/default/manager.tpl index 9eba084f8..d84a1ea5d 100644 --- a/modules/lemonldap-ng-manager/example/skins/default/manager.tpl +++ b/modules/lemonldap-ng-manager/example/skins/default/manager.tpl @@ -169,12 +169,28 @@ diff --git a/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm b/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm index b44e4605a..c8c83b175 100644 --- a/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm +++ b/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm @@ -73,6 +73,14 @@ sub new { $self->quit(); } + # URL upload + elsif ( my $rurl = $self->rparam('url') ) { + + require Lemonldap::NG::Manager::Uploader; #inherits + $self->urlUpload('url'); + $self->quit(); + } + # Else load conf require Lemonldap::NG::Manager::Downloader; #inherits $self->{cfgNum} = diff --git a/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Uploader.pm b/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Uploader.pm index 2807295cc..f5f129271 100644 --- a/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Uploader.pm +++ b/modules/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Uploader.pm @@ -10,6 +10,7 @@ use XML::LibXML; use XML::LibXSLT; use MIME::Base64; use JSON; +use LWP::Simple; # TODO use Data::Dumper; @@ -299,6 +300,41 @@ sub fileUpload { $self->quit(); } +## @method public void fileUpload (fieldname) +# Retrieve a file from an URL, and return it. This function is for +# some functionnalities into the SAML2 modules of the manager, accessing +# to data through Ajax requests. +# @param $fieldname The name of the html input field that contains the URL. +sub urlUpload { + my $self = shift; + my $fieldname = shift; + + # Get the URL + my $url = ${$self->rparam($fieldname)}; + + # Get contents from URL + print STDERR "---> " . $url . "\n"; + my $content = get $url; + $content = '' unless(defined $content); + $content =~ s!!>!g; + + # Build JSON reponse + my $json = new JSON(); + $json = $json->allow_nonref(['1']); + $json = $json->utf8(['1']); + my $json_content = $json->encode($content); + my $buf = '{"status":"OK", "content":' . $json_content . '}'; + + # Send JSON response + # text/html is recommended header for JSON data retrieved by JQuery. + print $self->header( + -type => 'text/html', + -Content_Length => length($buf) + ) . $buf; + $self->quit(); +} + ## @method protected array applyTest(void* test,string value) # Apply the test to the value and return the result and an optional message # returned by the test if the sub ref.