From 2963568837330fb9374014f9e8f20531664591c3 Mon Sep 17 00:00:00 2001 From: Thijs Kinkhorst <thijs@kinkhorst.com> Date: Wed, 27 May 2015 15:18:07 +0000 Subject: [PATCH] Support file uploads in metadata converter. Closes #17 --- dictionaries/admin.definition.json | 3 +++ templates/metadata-converter.php | 6 +++++- www/admin/metadata-converter.php | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/dictionaries/admin.definition.json b/dictionaries/admin.definition.json index f9e3b2097..c899f9b32 100644 --- a/dictionaries/admin.definition.json +++ b/dictionaries/admin.definition.json @@ -83,6 +83,9 @@ "metaconv_title": { "en": "Metadata parser" }, + "metaconv_selectfile": { + "en": "or select a file:" + }, "metaconv_parse": { "en": "Parse" }, diff --git a/templates/metadata-converter.php b/templates/metadata-converter.php index ae95982b2..6dd148c13 100644 --- a/templates/metadata-converter.php +++ b/templates/metadata-converter.php @@ -7,12 +7,16 @@ $this->includeAtTemplateBase('includes/header.php'); <h2><?php echo $this->t('metaconv_title'); ?></h2> -<form action="?" method="post"> +<form action="?" method="post" enctype="multipart/form-data"> <p><?php echo($this->t('{admin:metaconv_xmlmetadata}')); ?></p> <p> <textarea rows="20" cols="120" name="xmldata"><?php echo htmlspecialchars($this->data['xmldata']); ?></textarea> </p> +<p> +<?php echo $this->t('metaconv_selectfile'); ?> +<input type="file" name="xmlfile" /></p> + <p> <input type="submit" value="<?php echo $this->t('metaconv_parse'); ?>" /> </p> diff --git a/www/admin/metadata-converter.php b/www/admin/metadata-converter.php index 828d2ce8d..a7223745c 100644 --- a/www/admin/metadata-converter.php +++ b/www/admin/metadata-converter.php @@ -7,9 +7,13 @@ SimpleSAML\Utils\Auth::requireAdmin(); $config = SimpleSAML_Configuration::getInstance(); -if(array_key_exists('xmldata', $_POST)) { +if ( !empty($_FILES['xmlfile']['tmp_name']) ) { + $xmldata = file_get_contents($_FILES['xmlfile']['tmp_name']); +} elseif ( array_key_exists('xmldata', $_POST) ) { $xmldata = $_POST['xmldata']; +} +if ( !empty($xmldata) ) { \SimpleSAML\Utils\XML::checkSAMLMessage($xmldata, 'saml-meta'); $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsString($xmldata); -- GitLab