Projet

Général

Profil

Télécharger (11,5 ko) Statistiques
| Branche: | Tag: | Révision:

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

1
<?php
2
/*
3
    borrowed from services_captiveportal_saml_whitelist.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-whitelist
35
##|*NAME=Service: Captive portal SAML whitelist manager
36
##|*DESCR=Allow access to the 'Service: Captive portal SAML whitelist manager' page.
37
##|*MATCH=services_captiveportal_saml_whitelist.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 Whitelists");
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['whitelists']))
71
        $a_univnautes['whitelists'] = array();
72
$whitelists =& $a_univnautes['whitelists'];
73

    
74
if (!is_array($whitelists['whitelist']))
75
        $whitelists['whitelist'] = array();
76
$a_whitelist =& $whitelists['whitelist'];
77

    
78

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

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

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

    
90
        /* reload whitelists */
91
        mwexec_bg("/usr/local/univnautes/sp/rc.sh syncwl");
92

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

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

    
110
if ($act == "new") {
111
	# $pconfig['descr'] = "New whitelist";
112
}
113

    
114
if ($_POST) {
115

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

    
120
	$reqdfields = explode(" ", "codename");
121
	$reqdfieldsn = array(gettext("Codename"));
122

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

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

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

    
135
	/* save modifications */
136
	if (!$input_errors) {
137

    
138
		$whitelist = array();
139
		if (!isset($pconfig['refid']) || empty($pconfig['refid']))
140
			$whitelist['refid'] = uniqid('whitelist_');
141
		else
142
			$whitelist['refid'] = $pconfig['refid'];
143

    
144
		if (isset($id) && $a_whitelist[$id])
145
			$whitelist = $a_whitelist[$id];
146

    
147
		$whitelist['codename'] = $pconfig['codename'];
148
		$whitelist['descr'] = $pconfig['descr'];
149
		$whitelist['url'] = $pconfig['url'];
150
		$whitelist['caref'] = $pconfig['caref'];
151

    
152
		if (isset($id) && $a_whitelist[$id])
153
			$a_whitelist[$id] = $whitelist;
154
		else
155
			$a_whitelist[] = $whitelist;
156

    
157
		/*
158
		echo "<pre>";
159
                print_r($config);
160
                print_r($id);
161
                print_r($a_whitelist);
162
                print_r($whitelist);
163
		echo "</pre>";
164
		exit;
165
		*/
166

    
167
		write_config();
168

    
169
		/* reload whitelists */
170
		mwexec_bg("/usr/local/univnautes/sp/rc.sh syncwl");
171

    
172
		pfSenseHeader("services_captiveportal_saml_whitelist.php");
173
	}
174
}
175

    
176
include("head.inc");
177
?>
178

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

    
182
<?php
183
	if ($input_errors)
184
		print_input_errors($input_errors);
185
	if ($savemsg)
186
		print_info_box($savemsg);
187
?>
188

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

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

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

    
236
					<table width="100%" border="0" cellpadding="6" cellspacing="0" id="existing" summary="existing">
237
						<tr>
238
							<td colspan="2" class="list" height="12"></td>
239
						</tr>
240
						<tr>
241
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Whitelist Download");?></td>
242
						</tr>
243

    
244
						<tr>
245
							<td width="22%" valign="top" class="vncellreq"><?=gettext("Metadata URL");?></td>
246
							<td width="78%" class="vtable">
247
								<input name="url" type="text" class="formfld url" id="url" size="65" value="<?=htmlspecialchars($pconfig['url']);?>" placeholder="https://..." />
248
								<br/><?=gettext("");?>
249
							</td>
250
						</tr>
251

    
252
						<tr>
253
							<td width="22%" valign="top" class="vncellreq"><?=gettext("HTTPS CA certificate"); ?></td>
254
							<td width="78%" class="vtable">
255
								<?php if (count($a_ca)): ?>
256
								<select name="caref" id="caref" class="formselect">
257
									<option value="__none__">None</option>
258
									<?php
259
										foreach($a_ca as $ca):
260
											$selected = "";
261
											if ($pconfig['caref'] == $ca['refid'])
262
												$selected = "selected";
263
									?>
264
									<option value="<?=$ca['refid'];?>" <?=$selected;?>><?=$ca['descr'];?></option>
265
									<?php endforeach; ?>
266
								</select>
267
                                                                <br/><?=gettext("If None, the HTTPS server certificate will not be checked."); ?>
268
								<?php else: ?>
269
									<b><?=gettext("No CA defined."); ?></b> <br/>Create one under <a href="system_certmanager.php">System &gt; Cert Manager</a>.
270
								<?php endif; ?>
271
							</td>
272
						</tr>
273

    
274
					</table>
275

    
276
					<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="save">
277
						<tr>
278
							<td width="22%" valign="top">&nbsp;</td>
279
							<td width="78%">
280
								<input id="submit" name="save" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
281
								<?php if (isset($id) && $a_ca[$id]): ?>
282
								<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
283
								<?php endif;?>
284
							</td>
285
						</tr>
286

    
287

    
288
					</table>
289
				</form>
290

    
291
				<?php else: ?>
292

    
293
				<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
294
					<tr>
295
						<td width="15%" class="listhdrr"><?=gettext("Name");?></td>
296
						<td width="20%" class="listhdrr"><?=gettext("Description");?></td>
297
						<td width="60%" class="listhdrr"><?=gettext("URL");?></td>
298
					</tr>
299
					<?php
300
						$i = 0;
301
						foreach($a_whitelist as $whitelist):
302
							$name = htmlspecialchars($whitelist['codename']);
303
							$descr = htmlspecialchars($whitelist['descr']);
304
							$url = htmlspecialchars($whitelist['url']);
305

    
306
					?>
307
					<tr>
308
						<td class="listlr">
309
							<?=$name;?><br />
310
						</td>
311
						<td class="listr">
312
							<em><?=$descr;?></em>
313
						</td>
314
						<td class="listr"><?=$url;?>&nbsp;</td>
315
						<td valign="middle" nowrap class="list">
316
							<a href="services_captiveportal_saml_whitelist.php?act=edit&amp;id=<?=$i;?>">
317
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_e.gif" title="<?=gettext("edit");?>" alt="<?=gettext("edit");?>" width="17" height="17" border="0" />
318
							</a>
319
							<a href="services_captiveportal_saml_whitelist.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this Whitelist?");?>')">
320
								<img src="/themes/<?= $g['theme'];?>/images/icons/icon_x.gif" title="<?=gettext("delete");?>" alt="<?=gettext("delete"); ?>" width="17" height="17" border="0" />
321
							</a>
322
						</td>
323
					</tr>
324
					<?php
325
							$i++;
326
						endforeach;
327
					?>
328
					<tr>
329
						<td class="list" colspan="5"></td>
330
						<td class="list">
331
							<a href="services_captiveportal_saml_whitelist.php?act=new">
332
								<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" />
333
							</a>
334
						</td>
335
					</tr>
336
					<tr>
337
						<td colspan="5">
338
							<p>
339
								<?=gettext("Additional IP Whitelists can be added here.");?>
340
							</p>
341
						</td>
342
					</tr>
343
				</table>
344

    
345
				<?php endif; ?>
346

    
347
			</div>
348
		</td>
349
	</tr>
350
</table>
351
<?php include("fend.inc");?>
352
<script type="text/javascript">
353
//<![CDATA[
354

    
355
method_change();
356

    
357
//]]>
358
</script>
359

    
360
</body>
361
</html>
(147-147/250)