Projet

Général

Profil

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

univnautes / usr / local / www / vpn_pptp_users_edit.php @ bca63487

1
<?php
2
/*
3
	vpn_pptp_users_edit.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5

    
6
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
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-vpnpptp-user-edit
33
##|*NAME=VPN: VPN PPTP: User: Edit page
34
##|*DESCR=Allow access to the 'VPN: VPN PPTP: User: Edit' page.
35
##|*MATCH=vpn_pptp_users_edit.php*
36
##|-PRIV
37

    
38
function pptpusercmp($a, $b) {
39
	return strcasecmp($a['name'], $b['name']);
40
}
41

    
42
function pptpd_users_sort() {
43
        global $config;
44

    
45
        if (!is_array($config['ppptpd']['user']))
46
                return;
47

    
48
        usort($config['pptpd']['user'], "pptpusercmp");
49
}
50

    
51
require("guiconfig.inc");
52
require_once("vpn.inc");
53

    
54
if (!is_array($config['pptpd']['user'])) {
55
	$config['pptpd']['user'] = array();
56
}
57
$a_secret = &$config['pptpd']['user'];
58

    
59
if (is_numericint($_GET['id']))
60
	$id = $_GET['id'];
61
if (isset($_POST['id']) && is_numericint($_POST['id']))
62
	$id = $_POST['id'];
63

    
64
if (isset($id) && $a_secret[$id]) {
65
	$pconfig['username'] = $a_secret[$id]['name'];
66
	$pconfig['ip'] = $a_secret[$id]['ip'];
67
}
68

    
69
if ($_POST) {
70

    
71
	unset($input_errors);
72
	$pconfig = $_POST;
73

    
74
	/* input validation */
75
	if (isset($id) && ($a_secret[$id])) {
76
		$reqdfields = explode(" ", "username");
77
		$reqdfieldsn = array(gettext("Username"));
78
	} else {
79
		$reqdfields = explode(" ", "username password");
80
		$reqdfieldsn = array(gettext("Username"),gettext("Password"));
81
	}
82

    
83
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
84

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

    
88
	if (preg_match("/^!/", $_POST['password']))
89
		$input_errors[] = gettext("The password cannot start with '!'.");
90

    
91
	if (!preg_match("/^[\x20-\x7E]*$/", $_POST['password']))
92
		$input_errors[] = gettext("The password contains invalid characters.");
93

    
94
	if (($_POST['password']) && ($_POST['password'] != $_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['username']) {
105
				$input_errors[] = gettext("Another entry with the same username already exists.");
106
				break;
107
			}
108
		}
109
	}
110

    
111
	if (!$input_errors) {
112

    
113
		if (isset($id) && $a_secret[$id])
114
			$secretent = $a_secret[$id];
115

    
116
		$secretent['name'] = $_POST['username'];
117
		$secretent['ip'] = $_POST['ip'];
118

    
119
		if ($_POST['password'])
120
			$secretent['password'] = $_POST['password'];
121

    
122
		if (isset($id) && $a_secret[$id])
123
			$a_secret[$id] = $secretent;
124
		else
125
			$a_secret[] = $secretent;
126
		pptpd_users_sort();
127

    
128
		write_config();
129
		mark_subsystem_dirty('pptpusers');
130

    
131
		header("Location: vpn_pptp_users.php");
132
		exit;
133
	}
134
}
135

    
136
$pgtitle = array(gettext("VPN"),gettext("VPN PPTP"),gettext("User"),gettext("Edit"));
137
$shortcut_section = "pptps";
138
include("head.inc");
139

    
140
?>
141
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
142
<?php include("fbegin.inc"); ?>
143
<?php if ($input_errors) print_input_errors($input_errors); ?>
144
            <form action="vpn_pptp_users_edit.php" method="post" name="iform" id="iform">
145
              <div id="mainarea">
146
	      <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="vpn pptp users edit">
147
                <tr>
148
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Username");?></td>
149
                  <td width="78%" class="vtable">
150
					<?=$mandfldhtml;?><input name="username" type="text" class="formfld user" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>" />
151
                  </td>
152
                </tr>
153
                <tr>
154
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Password");?></td>
155
                  <td width="78%" class="vtable">
156
                    <?=$mandfldhtml;?><input name="password" type="password" class="formfld pwd" id="password" size="20" />
157
                    <br /><?=$mandfldhtml;?><input name="password2" type="password" class="formfld pwd" id="password2" size="20" />
158
                    &nbsp;(<?=gettext("confirmation");?>)<?php if (isset($id) && $a_secret[$id]): ?><br />
159
                    <span class="vexpl"><?=gettext("If you want to change the users' password, ".
160
                    "enter it here twice.");?></span><?php endif; ?></td>
161
                </tr>
162
                <tr>
163
                  <td width="22%" valign="top" class="vncell"><?=gettext("IP address");?></td>
164
                  <td width="78%" class="vtable">
165
                    <input name="ip" type="text" class="formfld unknown" id="ip" size="20" value="<?=htmlspecialchars($pconfig['ip']);?>" />
166
                    <br /><span class="vexpl"><?=gettext("If you want the user to be assigned a specific IP address, enter it here.");?></span></td>
167
                </tr>
168
                <tr>
169
                  <td class="vncell" width="22%" valign="top">&nbsp;</td>
170
                  <td class="vncell" width="78%">
171
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
172
                    <?php if (isset($id) && $a_secret[$id]): ?>
173
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
174
                    <?php endif; ?>
175
                  </td>
176
                </tr>
177
              </table>
178
	      </div>
179
</form>
180
<?php include("fend.inc"); ?>
181
</body>
182
</html>
(252-252/254)