<?php
/*
	services_captiveportal_saml_idp.php
	part of m0n0wall (http://m0n0.ch/wall)

	Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
	Copyright (C) 2014 Entr'ouvert <info@entrouvert.com>.
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	1. Redistributions of source code must retain the above copyright notice,
	   this list of conditions and the following disclaimer.

	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/
/*
	pfSense_MODULE:	captiveportal
*/

##|+PRIV
##|*IDENT=page-services-captiveportal-saml-idp
##|*NAME=Services: Captive portal SAML IdP page
##|*DESCR=Allow access to the 'Services: Captive portal SAML IdP' page.
##|*MATCH=services_captiveportal_saml_idp.php*
##|-PRIV

require_once("guiconfig.inc");
require_once("functions.inc");
require_once("filter.inc");
require_once("shaper.inc");
require_once("captiveportal.inc");

if (!is_array($config['captiveportal']))
	$config['captiveportal'] = array();
$a_cp =& $config['captiveportal'];

$a_cert =& $config['cert'];

if (!is_array($config['univnautes']))
	$config['univnautes'] = array();
$a_un =& $config['univnautes'];

if (!is_array($a_un['idp']))
        $a_un['idp'] = array();
$a_idp =& $a_un['idp'];

$pconfig['certref'] = $a_idp['certref'];

$pgtitle = array(gettext("Services"),gettext("Captive portal"), "SAML 2.0 Identity provider");
$shortcut_section = "captiveportal";

if ($_POST) {

	unset($input_errors);
	$pconfig = $_POST;

	/* input validation */
        $reqdfields = array("certref");
        $reqdfieldsn = array(gettext("IdP SAML 2.0 Certificate"));

	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);

        /* if this is an AJAX caller then handle via JSON */
        if (isAjax() && is_array($input_errors)) {
                input_errors2Ajax($input_errors);
                exit;
        }

        if (!$input_errors) {
                $a_idp['certref'] = $pconfig['certref'];
                /* write config.xml */
                write_config();

                /* relaunch IdP */

                /* back to the page */
                pfSenseHeader("services_captiveportal_saml_idp.php");
        }

}
include("head.inc");
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<?php if ($input_errors) print_input_errors($input_errors); ?>
<?php if ($savemsg) print_info_box($savemsg); ?>

<form action="services_captiveportal_saml_idp.php" method="post" enctype="multipart/form-data" name="iform" id="iform">

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr><td class="tabnavtbl">
<?php
	$tab_array = array();
	$tab_array[] = array(gettext("Service provider"), false, "services_captiveportal_saml_sp.php");
	$tab_array[] = array(gettext("Identity provider"), true, "services_captiveportal_saml_idp.php");
	$tab_array[] = array(gettext("Federations"), false, "services_captiveportal_saml_federation.php");
	display_top_tabs($tab_array, true);
?>    </td></tr>
  <tr>
  <td class="tabcont">
  <table width="100%" border="0" cellpadding="6" cellspacing="0">
	<tr>
		<td width="22%" valign="top" class="vncell"><?=gettext("IdP SAML 2.0 Certificate"); ?></td>
		<td width="78%" class="vtable">
			<?php if (count($a_cert)): ?>
			<select name="certref" id="certref" class="formselect">
				<option value="__none__">None</option>
				<?php
					foreach($a_cert as $cert):
						$selected = "";
						if ($pconfig['certref'] == $cert['refid'])
							$selected = "selected";
				?>
				<option value="<?=$cert['refid'];?>"<?=$selected;?>><?=$cert['descr'];?></option>
			<?php endforeach; ?>
			</select>
			<?php else: ?>
				<b><?=gettext("No Certificates defined."); ?></b> <br/>Create one under <a href="system_certmanager.php">System &gt; Cert Manager</a>.
			<?php endif; ?>
		</td>
	</tr>

	<tr>
	  <td width="22%" valign="top">&nbsp;</td>
	  <td width="78%">
		<?php echo "<input name='zone' id='zone' type='hidden' value='" . htmlspecialchars($cpzone) . "'/>"; ?>
		<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onClick="enable_change(true)">
		<a href="services_captiveportal_zones.php"><input name="Cancel" type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onClick="enable_change(true)"></a>
	  </td>
	</tr>
  </table>
  </td>
  </tr>
  </table>
</form>
<script language="JavaScript">
<!--
enable_change(false);
//-->
</script>
<?php include("fend.inc"); ?>
</body>
</html>
