-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvpn.php
453 lines (392 loc) · 18.9 KB
/
vpn.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<?php
/*
* vpn.php
*
* Copyright (C) 2013-2024 by Erland Hedman <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
include 'cgi-bin/common.php';
//if (count($_POST)) {echo "<pre>"; print_r($_POST); echo "</pre>";exit;}
if (count($_POST) && $_POST["POST_ACTION"] == "OK") {
if (! function_exists('pcntl_fork')) die('PCNTL functions not available on this PHP installation');
$pid = pcntl_fork();
if ($pid == -1) {
echo("<pre>pcntl_fork: failed - check the extension for pcntl.so\n");
print_r(error_get_last());
echo "</pre>\n"; exit;
} else if (!$pid) {
// We are the child
$i=1;
while (isset($_POST['vpn_'.$i.'_secr'])) { // simple hiding of passwords
if ($_POST['vpn_'.$i.'_sts'] == '2') {
$i++;
continue;
}
$_POST['vpn_'.$i.'_secr'] = base64_decode($_POST['vpn_'.$i.'_secr']);
$i++;
}
$ns1=g_srvstat("named")? g_ip(g_lan()):"8.8.8.8";
do_ddns($_POST['ddns_enabled'], $_POST['ddns_domain'], $_POST['ddns_account'], $_POST['ddns_pw1'], $_POST['provider'], g_lan());
do_vpn(g_lan()." ".VPNET." ".$ns1." ".implode(" ", $_POST));
} else {
//header('Location: http://'. $_SERVER["SERVER_ADDR"]. '/wait.php?seconds=24&loc='.$_SERVER['SCRIPT_NAME']);
header('Location: http://'. $_SERVER["SERVER_ADDR"]. '/wait.php?seconds=20&loc='.$_SERVER['SCRIPT_NAME']);
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="/css/bridge.css">
<title><?php p_title(); ?></title>
<script>
function do_timeout()
{
self.location.href="/logout.php";
}
<?php setTimeout(); ?>
<?php include 'inc/general.js.php' ?>
function initPage()
{
var f = getObj("form");
f.ddns_pw2.value = f.ddns_pw1.value = "<?php echo trim(@exec("grep password= /etc/ddclient.conf | awk -F\' '{printf \"%s\", \$2}'")); ?>";
f.ddns_account.value = "<?php echo trim(@exec("grep login= /etc/ddclient.conf | awk -F= '{printf \"%s\", \$2}'")); ?>";
f.ddns_domain.value = "<?php echo trim(@exec("tail -1 /etc/ddclient.conf")); ?>";
f.ddns_enable.checked = <?php echo g_srvstat("ddclient")? "true":"false"; ?>;
f.vpn_enable.checked = <?php echo g_srvstat("pptpd")? "true":"false"; ?>;
f.vpn_type.options.selectedIndex = "<?php echo trim(@exec("grep type= /etc/ppp/pptpd-options | awk -F= '{printf \"%s\", \$2}'")); ?>";
f.provider.options.selectedIndex = "<?php echo trim(@exec("grep provider= /etc/ddclient.conf | awk -F= '{printf \"%s\", \$2}'")); ?>";
}
function addUser()
{
var f=getObj("form");
var table = getObj("vpn-users");
var rowIndx = table.getElementsByTagName("tbody")[0].getElementsByTagName("tr").length;
if (isFieldBlank(f.vpn_user.value) == true) {
f.vpn_user.select();
alert("User Login field is blank");
return false;
}
if (isFieldAscii(f.vpn_user.value) == false) {
f.vpn_user.select();
alert("Illegal characters in User Login field");
return false;
}
if (isFieldBlank(f.vpn_pw1.value) == true) {
f.vpn_pw1.select();
alert("Password field is blank");
return false;
}
if (isFieldAscii(f.vpn_pw1.value) == false) {
f.vpn_pw1.select();
alert("Illegal characters in Password field");
return false;
}
if (f.vpn_pw1.value.length < 6) {
f.vpn_pw1.select();
alert("Password field is too short");
return false;
}
if (f.vpn_pw1.value != f.vpn_pw2.value) {
alert("The New Password and the Confirmation Password are not matched");
f.vpn_pw1.select();
return false;
}
for( var i=1; i < rowIndx; i++ ) {
if (f.vpn_user.value == getObj('vpn_'+i+'_user').value) {
f.vpn_user.select();
alert("Duplicate Name field");
return false;
}
}
var row = table.insertRow(rowIndx);
var user = row.insertCell(0);
var secr = row.insertCell(1);
var del = row.insertCell(2);
user.innerHTML='<input readonly style="width:98%" name="vpn_'+rowIndx+'_user" id="vpn_'+rowIndx+'_user" value="'+f.vpn_user.value+'" maxlength="60" type="text">';
secr.innerHTML='<input readonly style="width:98%" name="vpn_'+rowIndx+'_secr" id="vpn_'+rowIndx+'_secr" value="'+f.vpn_pw1.value+'" maxlength="40" type="text">';
del.innerHTML='<input id="vpn_'+rowIndx+'_del" type="checkbox" onchange="setStatus('+rowIndx+');"><input id="vpn_'+rowIndx+'_sts" name="vpn_'+rowIndx+'_sts" value="2" type="hidden">';
restartTimeout();
return true;
}
function setStatus(itm)
{
getObj('vpn_'+itm+'_sts').value = getObj('vpn_'+itm+'_del').checked? "0":"1"
return true;
}
function checkPage()
{
var f=getObj("form");
if (isFieldBlank(f.ddns_domain.value) == true) {
f.ddns_domain.select();
alert("Domain is blank for DDNS");
return false;
}
if (isFieldAscii(f.ddns_domain.value) == false) {
f.ddns_domain.select();
alert("Illegal characters in Domain field for DDNS");
return false;
}
if (isFieldBlank(f.ddns_account.value) == true) {
f.ddns_account.select();
alert("Account login is blank for DDNS");
return false;
}
if (isFieldAscii(f.ddns_account.value) == false) {
f.ddns_account.select();
alert("Illegal characters in Account login field for DDNS");
return false;
}
if (isFieldBlank(f.ddns_pw1.value) == true) {
f.ddns_pw1.select();
alert("Password is blank for DDNS");
return false;
}
if (isFieldAscii(f.ddns_pw1.value) == false) {
f.ddns_pw1.select();
alert("Illegal characters in Password field for DDNS");
return false;
}
if (f.ddns_pw1.value.length < 6) {
f.ddns_pw1.select();
alert("Password is too short for DDNS");
return false;
}
if (f.ddns_pw1.value != f.ddns_pw2.value) {
alert("The New Password and the Confirmation Password are not matched for DDNS.");
f.ddns_pw1.select();
return false;
}
if (isDecimal(f.vpn_connections.value) == false) {
alert("Invalid value for Max Connections "+f.vpn_connections.value);
f.vpn_connection.select();
return false;
}
if (f.vpn_connections.value >100 || f.vpn_connections.value < 1) {
alert("Invalid value ("+f.vpn_connections.value+") for Max Connections. Range is 1-100.");
f.vpn_connections.select();
return false;
}
f.ddns_enabled.value = f.ddns_enable.checked? "1":"0";
f.vpn_enabled.value = f.vpn_enable.checked? "1":"0";
f.POST_ACTION.value = "OK";
f.submit();
return true;
}
function showPass(id)
{
var obj = document.getElementById(id);
if (obj.type === "password") {
obj.type = "text";
} else {
obj.type = "password";
}
}
</script>
</head>
<body onload="initPage();"><script>onbody();</script>
<form name="form" id="form" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>" onsubmit="return checkPage();">
<input name="POST_ACTION" value="0" type="hidden">
<input name="ddns_enabled" value="0" id="ddns_enabled" type="hidden">
<input name="vpn_enabled" value="0" id="vpn_enabled" type="hidden">
<table id="topContainer">
<tr>
<td class="laCN">Project Page : <a href="<?php p_productHome(); ?>" target=_blank><?php p_serverName(); ?></a></td>
<td class="raCN">Version : <?php p_firmware("-ro");?> </td>
</tr>
</table>
<table id="topTable">
<tr>
<td id="topBarLeft"><a id="logo" href="<?php p_productHome(); ?>"></a></td>
<td id="topBarRight"></td>
</tr>
</table>
<table id="topMenuTable">
<tr>
<td class="ledPanel">
<img class="led" alt="fwstat" title="Firewall" src="/img/<?php echo g_srvstat("shorewall")? "on":"off" ?>.png">
<img class="led" alt="dnsstat" title="DNS" src="/img/<?php echo g_srvstat("named")? "on":"off" ?>.png">
<img class="led" alt="dhcpstat" title="DHCP" src="/img/<?php echo g_srvstat("dhcpd")? "on":"off" ?>.png">
</td>
<td class="topMenuLink"><a href="/network.php">Setup</a></td>
<td class="topMenuLink"><a href="/advanced.php">Advanced</a></td>
<td class="topMenuThis"><a href="/admin.php">MAINTENANCE</a></td>
<td class="topMenuLink"><a href="/status.php">Status</a></td>
<td class="topMenuLink"><a href="/logout.php"><span id="timer"></span></a></td>
</tr>
</table>
<table id="mainContentTable">
<tr style="vertical-align: top;">
<td class="leftMenyContatiner">
<div class="leftNavLink">
<ul style="width: 100%">
<li><div class="leftnavLink"><a href="/firewall.php">Security</a></div></li>
<li><div class="leftnavLink"><a href="/virtual.php">Virtual Server</a></div></li>
<li><div id="left" class="navThis">Inbound Acces</div></li>
<li><div class="leftnavLink"><a href="/blacklist.php">URL Blacklist</a></div></li>
<li><div class="leftnavLink"><a href="/logfw.php">Firewall Log</a></div></li>
</ul>
</div>
</td>
<td id="contentHeading">
<div id="contentBox">
<h1>Inbound Access</h1>
Here you can setup your network for secure inbound acces using a Virtual Private Network (VPN).<br>
In order to conveniently access the VPN from the Internet by a Domain Name, you need to set up
a DDNS (Dynamic Name Resolution) service from a provider of such services for example www.dyn.com.<br>
If you have a fixed I.P address bound to your own registered domain, this DDNS service is not needed.
<br><br>
<?php if (g_srvstat("shorewall") == true && stat("/etc/shorewall/tunnels") != false) {?>
<input value="Save Settings" type="submit">
<input value="Don't Save Settings" onclick="cancelSettings()" type="button">
<?php } else {?>
Enable VPN in the "Security" menu to see the Save button.
<input value="Don't Save Settings" onclick="cancelSettings()" type="button">
<?php }?>
</div><br>
<div class="actionBox">
<h2 class="actionHeader">DDNS</h2>
DDNS is a dynamic DNS updating service that provides a corresponding domain
name for devices using dynamic IP addresses.<br><br>
<table>
<tr>
<td class="raCB" style="width:40%; height:25px">Enable DDNS :</td>
<td>
<input type="checkbox" id="ddns_enable" checked="checked">
</td>
</tr>
<tr>
<td class="raCN" style="width:40%"><b>Service Provider :</b></td>
<td>
<select id="provider" name="provider">
<option value="0">www.dyn.com</option>
<option value="1">www.easydns.com</option>
<option value="2">www.dslreports.com</option>
<option value="3">www.zoneedit.com</option>
</select>
</td>
</tr>
<tr>
<td class="raCN"><b>Domain :</b></td>
<td> <input style="width:50%" type="text" name="ddns_domain" maxlength="60" value=""></td>
</tr>
<tr>
<td class="raCN"><b>Account Login :</b></td>
<td>
<input style="width:50%" type="password" name="ddns_account" id="ddns_account" maxlength="60" value="">
<input type="checkbox" style="width: 20px;" onclick="showPass('ddns_account');">Show
</td>
</tr>
<tr>
<td class="raCN"><b>Password :</b></td>
<td>
<input style="width:50%" type="password" name="ddns_pw1" id="ddns_pw1" maxlength="40" onFocus="this.select();">
<input type="checkbox" style="width: 20px;" onclick="showPass('ddns_pw1');">Show
</td>
</tr>
<tr>
<td class="raCN"><b>Verify Password :</b></td>
<td> <input style="width:50%" type="password" name="ddns_pw2" maxlength="40" onFocus="this.select();"></td>
</tr>
</table>
</div><div class="vbr"></div>
<div class="actionBox">
<h2 class="actionHeader">VPN</h2>
A virtual private network (VPN) extends your local network across a public network,
such as the Internet. It enables a remote computer to send and receive data across the Inetnet
as if it is directly connected to your local network<br><br>
<table>
<tr>
<td class="raCB" style="width:40%; height:25px">Enable VPN :</td>
<td colspan="2">
<input type="checkbox" id="vpn_enable" checked="checked">
</td>
</tr>
<tr>
<td class="raCN" style="width:40%"><b>Type :</b></td>
<td colspan="2">
<select id="vpn_type" name="vpn_type">
<option title="no encryption" value="0">PPTP</option>
<option title="MPPE-128 encryption" value="1">PPTP-MPPE</option>
</select>
</td>
</tr>
<tr>
<td class="raCN"><b>Max Connections :</b></td>
<td colspan="2"> <input style="width:10%" type="text" name="vpn_connections" maxlength="3" value="10"></td>
</tr>
<tr>
<td class="raCN"><b>New User Login :</b></td>
<td colspan="2"> <input type="text" id="vpn_user" maxlength="60" value=""></td>
</tr>
<tr>
<td class="raCN"><b>Password :</b></td>
<td colspan="2"> <input type="text" id="vpn_pw1" maxlength="40"></td>
</tr>
<tr>
<td class="raCN"><b>Verify Password :</b></td>
<td> <input type="text" id="vpn_pw2" maxlength="40"></td>
<td> <input type="button" value="Add User" onclick="addUser();"></td>
</tr>
</table>
<div class="vbr"></div>
<h2 class="actionHeader">VPN Users</h2><div class="vbr"></div>
<div style="overflow-y:auto;max-height:250px;">
<table id="vpn-users">
<tbody>
<tr>
<td style="width:40%">User</td>
<td style="width:40%">Secret</td>
<td style="width:20%">Delete</td>
</tr>
<?php
if (($fd = fopen("/etc/ppp/chap-secrets", "r")) == NULL)
die("bummer");
$record=1;
while (!feof($fd)) {
$str=trim(fgets($fd));
if ($str == "" || $str[0] == "#") continue;
$a=explode("\t", $str);
$user=$a[0]; $secr=$a[2]
?>
<tr>
<td><input readonly style="width:98%" id="vpn_<?php echo $record;?>_user" name="vpn_<?php echo $record;?>_user" value="<?php echo $user;?>" type="text"></td>
<td><input readonly style="width:98%" id="vpn_<?php echo $record;?>_secr" name="vpn_<?php echo $record;?>_secr" value="<?php echo base64_encode($secr);?>" type="password"></td>
<td>
<input id="vpn_<?php echo $record;?>_del" type="checkbox" onchange="setStatus(<?php echo $record;?>);">
<input id="vpn_<?php echo $record;?>_sts" name="vpn_<?php echo $record;?>_sts" value="1" type="hidden">
</td>
</tr>
<?php
$record++;
}
@fclose($fd);
?>
</tbody>
</table>
</div>
</div>
</td>
<td id="quickHelpContent"><strong>Help...</strong><br>
<br>
<strong>NOTE!</strong> Please note that some service providers do not allow inbound access to home premises,
typically if the WAN side is through a 3G/4G modem.<br>Presumably they can be asked to
enable inbound access for your mobile subscription.<br><br>
<strong>NOTE!</strong> This service will not work if any downstream firewalls (your external modem) is active without having this <?php p_mode(); ?> in a DMZ zone.<br><br>
</td>
</tr>
<tr>
<td colspan="3" id="footer">
Copyright © <?php p_copyRight(); ?>
</td>
</tr>
</table>
</form>
</body>
</html>