Projet

Général

Profil

Télécharger (6,96 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / vpn_l2tp_users_edit.php @ 62424bdb

1
<?php
2
/*
3
	vpn_l2tp_users_edit.php
4
	part of pfSense
5

    
6
	Copyright (C) 2006 Scott Ullrich (sullrich@gmail.com)
7
	All rights reserved.
8

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

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

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

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

    
31
##|+PRIV
32
##|*IDENT=page-vpn-vpnl2tp-users-edit
33
##|*NAME=VPN: VPN L2TP : Users : Edit page
34
##|*DESCR=Allow access to the 'VPN: VPN L2TP : Users : Edit' page.
35
##|*MATCH=vpn_l2tp_users_edit.php*
36
##|-PRIV
37

    
38
$pgtitle = array(gettext("VPN"),gettext("L2TP"),gettext("User"),gettext("Edit"));
39
$shortcut_section = "l2tps";
40

    
41
function  l2tpusercmp($a,  $b)  {
42
	return  strcasecmp($a['name'],  $b['name']);
43
}
44

    
45
function  l2tp_users_sort()  {
46
        global  $config;
47

    
48
        if (!is_array($config['l2tp']['user']))
49
                return;
50

    
51
        usort($config['l2tp']['user'],  "l2tpusercmp");
52
}
53

    
54
require("guiconfig.inc");
55
require_once("vpn.inc");
56

    
57
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/vpn_l2tp_users.php');
58

    
59
if (!is_array($config['l2tp']['user'])) {
60
	$config['l2tp']['user'] = array();
61
}
62
$a_secret = &$config['l2tp']['user'];
63

    
64
if (is_numericint($_GET['id']))
65
	$id = $_GET['id'];
66
if (isset($_POST['id']) && is_numericint($_POST['id']))
67
	$id = $_POST['id'];
68

    
69
if (isset($id) && $a_secret[$id]) {
70
	$pconfig['usernamefld'] = $a_secret[$id]['name'];
71
	$pconfig['ip'] = $a_secret[$id]['ip'];
72
}
73

    
74
if ($_POST) {
75

    
76
	unset($input_errors);
77
	$pconfig = $_POST;
78

    
79
	/* input validation */
80
	if (isset($id) && ($a_secret[$id])) {
81
		$reqdfields = explode(" ", "usernamefld");
82
		$reqdfieldsn = array(gettext("Username"));
83
	} else {
84
		$reqdfields = explode(" ", "usernamefld passwordfld");
85
		$reqdfieldsn = array(gettext("Username"),gettext("Password"));
86
	}
87

    
88
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
89

    
90
	if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['usernamefld']))
91
		$input_errors[] = gettext("The username contains invalid characters.");
92

    
93
	if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['passwordfld']))
94
		$input_errors[] = gettext("The password contains invalid characters.");
95

    
96
	if (($_POST['passwordfld']) && ($_POST['passwordfld'] != $_POST['password2'])) {
97
		$input_errors[] = gettext("The passwords do not match.");
98
	}
99
	if (($_POST['ip'] && !is_ipaddr($_POST['ip']))) {
100
		$input_errors[] = gettext("The IP address entered is not valid.");
101
	}
102

    
103
	if (!$input_errors && !(isset($id) && $a_secret[$id])) {
104
		/* make sure there are no dupes */
105
		foreach ($a_secret as $secretent) {
106
			if ($secretent['name'] == $_POST['usernamefld']) {
107
				$input_errors[] = gettext("Another entry with the same username already exists.");
108
				break;
109
			}
110
		}
111
	}
112

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

    
119
	if (!$input_errors) {
120

    
121
		if (isset($id) && $a_secret[$id])
122
			$secretent = $a_secret[$id];
123

    
124
		$secretent['name'] = $_POST['usernamefld'];
125
		$secretent['ip'] = $_POST['ip'];
126

    
127
		if ($_POST['passwordfld'])
128
			$secretent['password'] = $_POST['passwordfld'];
129

    
130
		if (isset($id) && $a_secret[$id])
131
			$a_secret[$id] = $secretent;
132
		else
133
			$a_secret[] = $secretent;
134
		l2tp_users_sort();
135

    
136
		write_config();
137

    
138
		$retval = vpn_l2tp_configure();
139

    
140
		pfSenseHeader("vpn_l2tp_users.php");
141

    
142
		exit;
143
	}
144
}
145

    
146
include("head.inc");
147
?>
148

    
149
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
150
<?php include("fbegin.inc"); ?>
151

    
152
<?php if ($input_errors) print_input_errors($input_errors); ?>
153
			<div id="inputerrors"></div>
154
            <form action="vpn_l2tp_users_edit.php" method="post" name="iform" id="iform">
155
              <div id="mainarea">
156
	          <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="vpn l2tp users edit">
157
                <tr>
158
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Username");?></td>
159
                  <td width="78%" class="vtable">
160
					<?=$mandfldhtml;?><input name="usernamefld" type="text" class="formfld user" id="usernamefld" size="20" value="<?=htmlspecialchars($pconfig['usernamefld']);?>" />
161
                  </td>
162
                </tr>
163
                <tr>
164
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Password");?></td>
165
                  <td width="78%" class="vtable">
166
                    <?=$mandfldhtml;?><input name="passwordfld" type="password" class="formfld pwd" id="passwordfld" size="20" />
167
                    <br /><?=$mandfldhtml;?><input name="password2" type="password" class="formfld pwd" id="password2" size="20" />
168
                    &nbsp;(<?=gettext("confirmation");?>)<?php if (isset($id) && $a_secret[$id]): ?><br />
169
                    <span class="vexpl"><?=gettext("If you want to change the users password, enter it here twice.");?></span>
170
                    <?php endif; ?></td>
171
                </tr>
172
                <tr>
173
                  <td width="22%" valign="top" class="vncell"><?=gettext("IP address");?></td>
174
                  <td width="78%" class="vtable">
175
                    <input name="ip" type="text" class="formfld unknown" id="ip" size="20" value="<?=htmlspecialchars($pconfig['ip']);?>" />
176
                    <br /><span class="vexpl"><?=gettext("If you want the user to be assigned a specific IP address, enter it here.");?></span></td>
177
                </tr>
178
                <tr>
179
                  <td width="22%" valign="top">&nbsp;</td>
180
                  <td width="78%">
181
                    <input id="submit" name="Submit" type="submit" class="formbtn" value="<?=gettext('Save');?>" />
182
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
183
                    <?php if (isset($id) && $a_secret[$id]): ?>
184
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
185
                    <?php endif; ?>
186
                  </td>
187
                </tr>
188
              </table>
189
	      </div>
190
</form>
191

    
192
<?php include("fend.inc"); ?>
193
</body>
194
</html>
(246-246/256)