Projet

Général

Profil

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

univnautes / usr / local / www / services_captiveportal_saml_federation.php @ 326238ce

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
	$savemsg = sprintf(gettext("Federation %s successfully deleted"), $name) . "<br/>";
90
	pfSenseHeader("services_captiveportal_saml_federation.php");
91
	exit;
92
}
93

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

    
107
if ($act == "new") {
108
	$pconfig['enable'] = true;
109
}
110

    
111
if ($_POST) {
112

    
113
	unset($input_errors);
114
	$input_errors = array();
115
	$pconfig = $_POST;
116

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

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

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

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

    
138
	/* save modifications */
139
	if (!$input_errors) {
140

    
141
		$federation = array();
142
		if (!isset($pconfig['refid']) || empty($pconfig['refid']))
143
			$federation['refid'] = uniqid('fed_');
144
		else
145
			$federation['refid'] = $pconfig['refid'];
146

    
147
		if (isset($id) && $a_federation[$id])
148
			$federation = $a_federation[$id];
149

    
150
		$federation['codename'] = $pconfig['codename'];
151
		$federation['descr'] = $pconfig['descr'];
152
		$federation['url'] = $pconfig['url'];
153
		$federation['certref'] = $pconfig['certref'];
154

    
155
		if ($_POST['enable'])
156
			$federation['enable'] = true;
157
		else
158
			unset($federation['enable']);
159

    
160
		if (isset($id) && $a_federation[$id])
161
			$a_federation[$id] = $federation;
162
		else
163
			$a_federation[] = $federation;
164

    
165
                /* echo "<pre>";
166
                #print_r($config);
167
                print_r($id);
168
                print_r($a_federation);
169
                print_r($federation);
170
                exit; */
171

    
172
		write_config();
173

    
174
		/* reload federation (and geoinfos) */
175
 		mwexec_bg("/usr/local/univnautes/sp/rc.sh syncdata");
176

    
177
		pfSenseHeader("services_captiveportal_saml_federation.php");
178
	}
179
}
180

    
181
include("head.inc");
182
?>
183

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

    
187
<?php
188
	if ($input_errors)
189
		print_input_errors($input_errors);
190
	if ($savemsg)
191
		print_info_box($savemsg);
192
?>
193

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

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

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

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

    
283
					</table>
284

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

    
296

    
297
					</table>
298
				</form>
299

    
300
				<?php else: ?>
301

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

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

    
354
				<?php endif; ?>
355

    
356
			</div>
357
		</td>
358
	</tr>
359
</table>
360
<?php include("fend.inc");?>
361
<script type="text/javascript">
362
//<![CDATA[
363

    
364
method_change();
365

    
366
//]]>
367
</script>
368

    
369
</body>
370
</html>
(144-144/250)