Projet

Général

Profil

Télécharger (12,8 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / services_captiveportal_saml_federation.php @ 2e70388a

1
<?php
2
/*
3
    borrowed from services_captiveportal_saml_federation.php
4

    
5
    Copyright (C) 2008 Shrew Soft Inc.
6
    All rights reserved.
7

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

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

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

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

    
33
##|+PRIV
34
##|*IDENT=page-services-captiveportal-saml-federation
35
##|*NAME=Service: Captive portal SAML federation manager
36
##|*DESCR=Allow access to the 'Service: Captive portal SAML federation manager' page.
37
##|*MATCH=services_captiveportal_saml_federation.php*
38
##|-PRIV
39

    
40
require("guiconfig.inc");
41
require_once("certs.inc");
42

    
43
$pgtitle = array(gettext("Service"), gettext("Captive portal"),"SAML 2.0 Federations");
44
$shortcut_section = "captiveportal";
45

    
46

    
47
if (is_numericint($_GET['id']))
48
	$id = $_GET['id'];
49
if (isset($_POST['id']) && is_numericint($_POST['id']))
50
	$id = $_POST['id'];
51

    
52
if (!is_array($config['ca']))
53
	$config['ca'] = array();
54

    
55
$a_ca =& $config['ca'];
56

    
57
if (!is_array($config['cert']))
58
	$config['cert'] = array();
59

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

    
62
$act = $_GET['act'];
63
if ($_POST['act'])
64
	$act = $_POST['act'];
65

    
66
if (!is_array($config['univnautes']))
67
        $config['univnautes'] = array();
68
$a_univnautes =& $config['univnautes'];
69

    
70
if (!is_array($a_univnautes['federations']))
71
        $a_univnautes['federations'] = array();
72
$federations =& $a_univnautes['federations'];
73

    
74
if (!is_array($federations['federation']))
75
        $federations['federation'] = array();
76
$a_federation =& $federations['federation'];
77

    
78

    
79
if ($act == "del") {
80

    
81
	if (!isset($a_federation[$id])) {
82
		pfSenseHeader("services_captiveportal_saml_federation.php");
83
		exit;
84
	}
85

    
86
	$name = $a_federation[$id]['descr'];
87
	unset($a_federation[$id]);
88
	write_config();
89

    
90
	/* reload federation (and geoinfos) */
91
	mwexec_bg("/usr/local/univnautes/sp/rc.sh syncdata");
92

    
93
	$savemsg = sprintf(gettext("Federation %s successfully deleted"), $name) . "<br/>";
94
	pfSenseHeader("services_captiveportal_saml_federation.php");
95
	exit;
96
}
97

    
98
if ($act == "edit") {
99
	if (!$a_federation[$id]) {
100
		pfSenseHeader("services_captiveportal_saml_federation.php");
101
		exit;
102
	}
103
	$pconfig['enable'] = isset($a_federation[$id]['enable']);
104
	$pconfig['refid'] = $a_federation[$id]['refid'];
105
	$pconfig['codename'] = $a_federation[$id]['codename'];
106
	$pconfig['descr'] = $a_federation[$id]['descr'];
107
	$pconfig['url'] = $a_federation[$id]['url'];
108
	$pconfig['certref'] = $a_federation[$id]['certref'];
109
}
110

    
111
if ($act == "new") {
112
	$pconfig['enable'] = true;
113
}
114

    
115
if ($_POST) {
116

    
117
	unset($input_errors);
118
	$input_errors = array();
119
	$pconfig = $_POST;
120

    
121
	/* input validation */
122
	$reqdfields = explode(" ", "codename descr url certref");
123
	$reqdfieldsn = array(
124
			gettext("Codename"),
125
			gettext("Description"),
126
			gettext("URL"),
127
			gettext("Metadata Certificate"),
128
			gettext("HTTPS CA Certificate"));
129

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

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

    
138
	if (preg_match('/[^A-Za-z0-9_]/', $_POST['codename'])) {
139
		$input_errors[] = gettext("The codename can only contain letters, digits, and underscores (_).");
140
	}
141

    
142
	/* save modifications */
143
	if (!$input_errors) {
144

    
145
		$federation = array();
146
		if (!isset($pconfig['refid']) || empty($pconfig['refid']))
147
			$federation['refid'] = uniqid('fed_');
148
		else
149
			$federation['refid'] = $pconfig['refid'];
150

    
151
		if (isset($id) && $a_federation[$id])
152
			$federation = $a_federation[$id];
153

    
154
		$federation['codename'] = $pconfig['codename'];
155
		$federation['descr'] = $pconfig['descr'];
156
		$federation['url'] = $pconfig['url'];
157
		$federation['certref'] = $pconfig['certref'];
158

    
159
		if ($_POST['enable'])
160
			$federation['enable'] = true;
161
		else
162
			unset($federation['enable']);
163

    
164
		if (isset($id) && $a_federation[$id])
165
			$a_federation[$id] = $federation;
166
		else
167
			$a_federation[] = $federation;
168

    
169
                /* echo "<pre>";
170
                #print_r($config);
171
                print_r($id);
172
                print_r($a_federation);
173
                print_r($federation);
174
                exit; */
175

    
176
		write_config();
177

    
178
		/* reload federation (and geoinfos) */
179
		mwexec_bg("/usr/local/univnautes/sp/rc.sh syncdata");
180

    
181
		pfSenseHeader("services_captiveportal_saml_federation.php");
182
	}
183
}
184

    
185
include("head.inc");
186
?>
187

    
188
<body link="#000000" vlink="#000000" alink="#000000" onload="<?= $jsevents["body"]["onload"] ?>">
189
<?php include("fbegin.inc"); ?>
190

    
191
<?php
192
	if ($input_errors)
193
		print_input_errors($input_errors);
194
	if ($savemsg)
195
		print_info_box($savemsg);
196
?>
197

    
198
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="CA manager">
199
	<tr>
200
		<td>
201
		<?php
202
			$tab_array = array();
203
			$tab_array[] = array(gettext("Service provider"), false, "services_captiveportal_saml_sp.php");
204
			# $tab_array[] = array(gettext("Identity provider"), false, "services_captiveportal_saml_idp.php");
205
			$tab_array[] = array(gettext("Federations"), true, "services_captiveportal_saml_federation.php");
206
			$tab_array[] = array(gettext("Whitelists"), false, "services_captiveportal_saml_whitelist.php");
207
			display_top_tabs($tab_array);
208
		?>
209
		</td>
210
	</tr>
211
	<tr>
212
		<td id="mainarea">
213
			<div class="tabcont">
214

    
215
				<?php if ($act == "new" || $act == "edit" || $act == gettext("Save") || $input_errors): ?>
216

    
217
				<form action="" method="post" name="iform" id="iform">
218
					<?php if ($act == "edit"): ?>
219
					<input type="hidden" name="edit" value="edit" id="edit" />
220
					<input type="hidden" name="id" value="<?php echo htmlspecialchars($id); ?>" id="id" />
221
					<input type="hidden" name="refid" value="<?php echo $pconfig['refid']; ?>" id="refid" />
222
					<?php endif; ?>
223
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
224
						<tr>
225
                                                        <td width="22%" valign="top" class="vncellreq"><?=gettext("Code
226
 name");?></td>
227
                                                        <td width="78%" class="vtable">
228
                                                        <?php
229
                                                        if ($act == 'new') {
230
                                                        ?>
231
                                                        <input name="codename" type="text" class="formfld unknown" id="codename" size="20" value="<?=htmlspecialchars($pconfig['codename']);?>" placeholder="codename" />
232
                                                        <br/>Can not be changed after. The codename can only contain letters, digits, and underscores (_).
233
                                                        <?php } else { ?>
234
                                                        <input name="codename" type="hidden" value="<?=htmlspecialchars($pconfig['codename']);?>" /><?=$pconfig['codename'];?>
235
                                                        <?php }; ?>
236
                                                        </td>
237
                                                </tr>
238
						<tr>
239
							<td width="22%" valign="top" class="vtable">&nbsp;</td>
240
							<td width="78%" class="vtable">
241
							<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?>><strong><?=gettext("Enable this federation"); ?> </strong></td>
242
						</tr>
243
						<tr>
244
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Description");?></td>
245
							<td width="78%" class="vtable">
246
								<input name="descr" type="text" class="formfld unknown" id="descr" size="65" value="<?=htmlspecialchars($pconfig['descr']);?>" />
247
							</td>
248
						</tr>
249
					</table>
250

    
251
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing" summary="existing">
252
						<tr>
253
							<td colspan="2" class="list" height="12"></td>
254
						</tr>
255
						<tr>
256
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Federation");?></td>
257
						</tr>
258
						<tr>
259
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Metadata URL");?></td>
260
							<td width="78%" class="vtable">
261
								<input name="url" type="text" class="formfld url" id="url" size="65" value="<?=htmlspecialchars($pconfig['url']);?>" placeholder="https://..." />
262
								<br/><?=gettext("");?>
263
							</td>
264
						</tr>
265
						<tr>
266
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Metadata certificate"); ?></td>
267
							<td width="78%" class="vtable">
268
								<?php if (count($a_cert)): ?>
269
								<select name="certref" id="certref" class="formselect">
270
									<option value="__none__">None</option>
271
									<?php
272
										foreach($a_cert as $cert):
273
											$selected = "";
274
											if ($pconfig['certref'] == $cert['refid'])
275
												$selected = "selected";
276
									?>
277
									<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['descr'];?></option>
278
									<?php endforeach; ?>
279
								</select>
280
                                                                <br/><?=gettext("If None, metadata signature will not be checked."); ?>
281
								<?php else: ?>
282
									<b><?=gettext("No Certificates defined."); ?></b> <br/>Create one under <a href="system_certmanager.php">System &gt; Cert Manager</a>.
283
								<?php endif; ?>
284
							</td>
285
						</tr>
286

    
287
					</table>
288

    
289
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="save">
290
						<tr>
291
							<td width="22%" valign="top">&nbsp;</td>
292
							<td width="78%">
293
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
294
								<?php if (isset($id) && $a_ca[$id]): ?>
295
								<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
296
								<?php endif;?>
297
							</td>
298
						</tr>
299

    
300

    
301
					</table>
302
				</form>
303

    
304
				<?php else: ?>
305

    
306
				<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
307
					<tr>
308
						<td width="10%" class="listhdrr"><?=gettext("Active");?></td>
309
						<td width="15%" class="listhdrr"><?=gettext("Codename");?></td>
310
						<td width="20%" class="listhdrr"><?=gettext("Description");?></td>
311
						<td width="50%" class="listhdrr"><?=gettext("URL");?></td>
312
					</tr>
313
					<?php
314
						$i = 0;
315
						foreach($a_federation as $federation):
316
							$name = htmlspecialchars($federation['codename']);
317
							$descr = htmlspecialchars($federation['descr']);
318
							$url = htmlspecialchars($federation['url']);
319

    
320
					?>
321
					<tr>
322
						<td class="listlr"><?php
323
							if (isset($federation['enable'])) echo 'x';
324
						?></td>
325
						<td class="listr"><?=$name;?></td>
326
						<td class="listr"><em><?=$descr;?></em></td>
327
						<td class="listr"><?=$url;?>&nbsp;</td>
328
						<td valign="middle" nowrap class="list">
329
							<a href="services_captiveportal_saml_federation.php?act=edit&amp;id=<?=$i;?>">
330
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit");?>" alt="<?=gettext("edit");?>" width="17" height="17" border="0" />
331
							</a>
332
							<a href="services_captiveportal_saml_federation.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this Federation?");?>')">
333
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete");?>" alt="<?=gettext("delete"); ?>" width="17" height="17" border="0" />
334
							</a>
335
						</td>
336
					</tr>
337
					<?php
338
							$i++;
339
						endforeach;
340
					?>
341
					<tr>
342
						<td class="list" colspan="5"></td>
343
						<td class="list">
344
							<a href="services_captiveportal_saml_federation.php?act=new">
345
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_plus.gif" title="<?=gettext("add or import ca");?>" alt="<?=gettext("add ca");?>" width="17" height="17" border="0" />
346
							</a>
347
						</td>
348
					</tr>
349
					<tr>
350
						<td colspan="5">
351
							<p>
352
								<?=gettext("Additional Federations can be added here.");?>
353
							</p>
354
						</td>
355
					</tr>
356
				</table>
357

    
358
				<?php endif; ?>
359

    
360
			</div>
361
		</td>
362
	</tr>
363
</table>
364
<?php include("fend.inc");?>
365
<script type="text/javascript">
366
//<![CDATA[
367

    
368
method_change();
369

    
370
//]]>
371
</script>
372

    
373
</body>
374
</html>
(144-144/250)