From 55a1030ceb09ce21899872056bf1cb54ca6bf074 Mon Sep 17 00:00:00 2001 From: Jaime Perez Crespo <jaime.perez@uninett.no> Date: Tue, 3 Nov 2015 13:46:07 +0100 Subject: [PATCH] Reformat and enhance the metadata converter page. --- templates/metadata-converter.php | 84 ++++++++++++++++------------ www/admin/metadata-converter.php | 96 ++++++++++++++------------------ 2 files changed, 90 insertions(+), 90 deletions(-) diff --git a/templates/metadata-converter.php b/templates/metadata-converter.php index 6dd148c13..907fc9bc7 100644 --- a/templates/metadata-converter.php +++ b/templates/metadata-converter.php @@ -2,45 +2,57 @@ $this->data['header'] = $this->t('metaconv_title'); $this->includeAtTemplateBase('includes/header.php'); ?> - - - -<h2><?php echo $this->t('metaconv_title'); ?></h2> - -<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> -</form> - + <h2><?php echo $this->t('metaconv_title'); ?></h2> + <form action="?" method="post" enctype="multipart/form-data"> + <p><?php echo($this->t('{admin:metaconv_xmlmetadata}')); ?></p> + <p> + <textarea rows="20" style="width: 100%" + 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'); ?>" class="btn"/> + </p> + </form> <?php - $output = $this->data['output']; -if($output !== NULL) { - - echo('<h2>' . $this->t('metaconv_converted') . '</h2>' . "\n"); - - foreach($output as $type => $text) { - if($text === '') { - continue; - } - - echo('<h3>' . htmlspecialchars($type) . '</h3>' . "\n"); - echo('<pre class="metadatabox">' . htmlspecialchars($text) . '</pre>' . "\n"); - } -} - +if (!empty($output)) { ?> - + <h2><?php echo $this->t('metaconv_converted'); ?></h2> <?php + $i = 1; + foreach ($output as $type => $text) { + if ($text === '') { + continue; + } +?> + <h3><?php echo htmlspecialchars($type); ?></h3> + <div class="metadatabox"> + <button data-clipboard-target="#metadata<?php echo $i; ?>" id="btn<?php echo $i; ?>" + class="btn topright" style="margin-right: 0.5em;"> + <img src="<?php echo $this->data['baseurlpath'].'/resources/icons/clipboard.svg'; ?>" + alt="Copy to clipboard"> + </button> + <pre id="metadata<?php echo $i; ?>"><?php + echo htmlspecialchars($text); + ?></pre> + </div> +<?php + $i++; + } +?> + <script type="text/javascript"> +<?php + for ($j = 1; $j <= $i; $j++) { +?> + var clipboard<?php echo $j; ?> = new Clipboard('#btn<?php echo $j; ?>'); +<?php + } + ?> + </script> +<?php +} $this->includeAtTemplateBase('includes/footer.php'); diff --git a/www/admin/metadata-converter.php b/www/admin/metadata-converter.php index a7223745c..e59fc9be9 100644 --- a/www/admin/metadata-converter.php +++ b/www/admin/metadata-converter.php @@ -1,70 +1,58 @@ <?php - require_once('../_include.php'); -/* Make sure that the user has admin access rights. */ +// make sure that the user has admin access rights SimpleSAML\Utils\Auth::requireAdmin(); $config = SimpleSAML_Configuration::getInstance(); -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($_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); - - /* Get all metadata for the entities. */ - foreach($entities as &$entity) { - $entity = array( - 'shib13-sp-remote' => $entity->getMetadata1xSP(), - 'shib13-idp-remote' => $entity->getMetadata1xIdP(), - 'saml20-sp-remote' => $entity->getMetadata20SP(), - 'saml20-idp-remote' => $entity->getMetadata20IdP(), - ); - - } - - /* Transpose from $entities[entityid][type] to $output[type][entityid]. */ - $output = SimpleSAML\Utils\Arrays::transpose($entities); - - /* Merge all metadata of each type to a single string which should be - * added to the corresponding file. - */ - foreach($output as $type => &$entities) { - - $text = ''; - - foreach($entities as $entityId => $entityMetadata) { - - if($entityMetadata === NULL) { - continue; - } - - /* Remove the entityDescriptor element because it is unused, and only - * makes the output harder to read. - */ - unset($entityMetadata['entityDescriptor']); - - $text .= '$metadata[' . var_export($entityId, TRUE) . '] = ' . - var_export($entityMetadata, TRUE) . ";\n"; - } - - $entities = $text; - } - +if (!empty($xmldata)) { + \SimpleSAML\Utils\XML::checkSAMLMessage($xmldata, 'saml-meta'); + $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsString($xmldata); + + // get all metadata for the entities + foreach ($entities as &$entity) { + $entity = array( + 'shib13-sp-remote' => $entity->getMetadata1xSP(), + 'shib13-idp-remote' => $entity->getMetadata1xIdP(), + 'saml20-sp-remote' => $entity->getMetadata20SP(), + 'saml20-idp-remote' => $entity->getMetadata20IdP(), + ); + } + + // transpose from $entities[entityid][type] to $output[type][entityid] + $output = SimpleSAML\Utils\Arrays::transpose($entities); + + // merge all metadata of each type to a single string which should be added to the corresponding file + foreach ($output as $type => &$entities) { + $text = ''; + foreach ($entities as $entityId => $entityMetadata) { + + if ($entityMetadata === null) { + continue; + } + + // remove the entityDescriptor element because it is unused, and only makes the output harder to read + unset($entityMetadata['entityDescriptor']); + + $text .= '$metadata['.var_export($entityId, true).'] = '. + var_export($entityMetadata, true).";\n"; + } + $entities = $text; + } } else { - $xmldata = ''; - $output = array(); + $xmldata = ''; + $output = array(); } - $template = new SimpleSAML_XHTML_Template($config, 'metadata-converter.php', 'admin'); - +$template->data['clipboard.js'] = true; $template->data['xmldata'] = $xmldata; $template->data['output'] = $output; - $template->show(); -- GitLab