Projet

Général

Profil

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

univnautes / usr / local / www / vpn_l2tp_users_edit.php @ e5d6b608

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
if (!is_array($config['l2tp']['user'])) {
58
	$config['l2tp']['user'] = array();
59
}
60
$a_secret = &$config['l2tp']['user'];
61

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

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

    
72
if ($_POST) {
73

    
74
	unset($input_errors);
75
	$pconfig = $_POST;
76

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

    
86
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
87

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

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

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

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

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

    
117
	if (!$input_errors) {
118

    
119
		if (isset($id) && $a_secret[$id])
120
			$secretent = $a_secret[$id];
121

    
122
		$secretent['name'] = $_POST['usernamefld'];
123
		$secretent['ip'] = $_POST['ip'];
124

    
125
		if ($_POST['passwordfld'])
126
			$secretent['password'] = $_POST['passwordfld'];
127

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

    
134
		write_config();
135

    
136
		$retval = vpn_l2tp_configure();
137

    
138
		pfSenseHeader("vpn_l2tp_users.php");
139

    
140
		exit;
141
	}
142
}
143

    
144
include("head.inc");
145
?>
146

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

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

    
190
<?php include("fend.inc"); ?>
191
</body>
192
</html>
(244-244/254)