1 |
afb07cf1
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
|
|
<?php
|
3 |
|
|
/*
|
4 |
|
|
vpn_openvpn_srv.php
|
5 |
|
|
|
6 |
|
|
Copyright (C) 2004 Peter Curran (peter@closeconsultants.com).
|
7 |
|
|
Copyright (C) 2005 Peter Allgeyer (allgeyer@web.de).
|
8 |
|
|
All rights reserved.
|
9 |
|
|
|
10 |
|
|
Redistribution and use in source and binary forms, with or without
|
11 |
|
|
modification, are permitted provided that the following conditions are met:
|
12 |
|
|
|
13 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
this list of conditions and the following disclaimer.
|
15 |
|
|
|
16 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
17 |
|
|
notice, this list of conditions and the following disclaimer in the
|
18 |
|
|
documentation and/or other materials provided with the distribution.
|
19 |
|
|
|
20 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
30 |
|
|
*/
|
31 |
|
|
|
32 |
|
|
require("guiconfig.inc");
|
33 |
|
|
require_once("openvpn.inc");
|
34 |
|
|
|
35 |
|
|
if (!is_array($config['ovpn']))
|
36 |
|
|
$config['ovpn'] = array();
|
37 |
|
|
if (!is_array($config['ovpn']['server'])){
|
38 |
|
|
$config['ovpn']['server'] = array();
|
39 |
|
|
$config['ovpn']['server']['tunnel'] = array();
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
$ovpnsrv = &$config['ovpn']['server']['tunnel'];
|
43 |
|
|
|
44 |
|
|
$id = $_GET['id'];
|
45 |
|
|
if (isset($_POST['id']))
|
46 |
|
|
$id = $_POST['id'];
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
if ($_POST['apply']) {
|
50 |
|
|
$retval = 0;
|
51 |
|
|
if (file_exists($d_sysrebootreqd_path)) {
|
52 |
|
|
/* Rewrite interface definitions */
|
53 |
|
|
$retval = ovpn_server_iface();
|
54 |
|
|
} else {
|
55 |
|
|
ovpn_lock();
|
56 |
|
|
$retval = ovpn_server_iface();
|
57 |
|
|
$retval = ovpn_config_server(false);
|
58 |
|
|
ovpn_unlock();
|
59 |
|
|
}
|
60 |
|
|
if (file_exists($d_ovpnsrvdirty_path))
|
61 |
|
|
unlink($d_ovpnsrvdirty_path);
|
62 |
|
|
$savemsg = get_std_save_message($retval);
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
if ($_GET['act'] == "del") {
|
66 |
|
|
if ($ovpnsrv[$id]) {
|
67 |
|
|
$ovpnent = $ovpnsrv[$id];
|
68 |
|
|
unset($ovpnsrv[$id]);
|
69 |
|
|
|
70 |
|
|
/* Kill running processes */
|
71 |
|
|
ovpn_server_kill($ovpnent['tun_iface']);
|
72 |
|
|
|
73 |
|
|
/* Remove old certs & keys */
|
74 |
|
|
ovpn_server_certs_del($ovpnent['tun_iface']);
|
75 |
|
|
|
76 |
|
|
/* Remove interface from list of optional interfaces */
|
77 |
|
|
ovpn_server_iface_del($ovpnent['tun_iface']);
|
78 |
|
|
|
79 |
|
|
write_config();
|
80 |
|
|
//touch($d_sysrebootreqd_path);
|
81 |
|
|
header("Location: vpn_openvpn_srv.php");
|
82 |
|
|
exit;
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
$pgtitle = "VPN: OpenVPN";
|
87 |
|
|
include("head.inc");
|
88 |
|
|
|
89 |
|
|
?>
|
90 |
|
|
|
91 |
|
|
<?php include("fbegin.inc"); ?>
|
92 |
|
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
93 |
|
|
<?php if (file_exists($d_sysrebootreqd_path) && !file_exists($d_ovpnsrvdirty_path)) print_info_box(get_std_save_message(0)); ?>
|
94 |
|
|
<form action="vpn_openvpn_srv.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
|
95 |
|
|
<?php if (file_exists($d_ovpnsrvdirty_path)): ?><p>
|
96 |
|
|
<?php print_info_box_np("The OpenVPN server configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
|
97 |
|
|
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
|
98 |
|
|
<?php endif; ?>
|
99 |
|
|
|
100 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
101 |
|
|
<tr><td>
|
102 |
|
|
<ul id="tabnav">
|
103 |
|
|
<li class="tabact">Server</li>
|
104 |
|
|
<li class="tabinact"><a href="vpn_openvpn_cli.php">Client</a></li>
|
105 |
|
|
<li class="tabinact"><a href="vpn_openvpn_ccd.php">Client-specific Configuration</a></li>
|
106 |
|
|
<li class="tabinact"><a href="vpn_openvpn_crl.php">CRL</a></li>
|
107 |
|
|
</ul>
|
108 |
|
|
</td></tr>
|
109 |
|
|
<tr>
|
110 |
|
|
<td class="tabcont">
|
111 |
|
|
<strong><span class="red">WARNING: This feature is experimental and modifies your optional interface configuration.
|
112 |
|
|
Backup your configuration before using OpenVPN, and restore it before upgrading.<br>
|
113 |
|
|
<br>
|
114 |
|
|
</span></strong>
|
115 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
116 |
|
|
<tr>
|
117 |
|
|
<td width="5%" class="listhdrr">Interface</td>
|
118 |
|
|
<td width="5%" class="listhdrr">Protocol</td>
|
119 |
|
|
<td width="5%" class="listhdrr">Socket</td>
|
120 |
|
|
<td width="25%" class="listhdrr">IP Block</td>
|
121 |
|
|
<td width="15%" class="listhdrr">Crypto</td>
|
122 |
|
|
<td width="35%" class="listhdr">Description</td>
|
123 |
|
|
<td width="10%" class="list"></td>
|
124 |
|
|
</tr>
|
125 |
|
|
|
126 |
|
|
<?php $i = 0; foreach ($ovpnsrv as $server):
|
127 |
|
|
if (!isset($server['enable'])) {
|
128 |
|
|
$spans = "<span class=\"gray\">";
|
129 |
|
|
$spane = "</span>";
|
130 |
|
|
} else {
|
131 |
|
|
$spans = $spane = "";
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
if ($server['bind_iface'] == 'all')
|
135 |
|
|
$ipaddr = "0.0.0.0";
|
136 |
|
|
else
|
137 |
|
|
$ipaddr = ovpn_get_ip($server['bind_iface']);
|
138 |
|
|
?>
|
139 |
|
|
|
140 |
|
|
<tr>
|
141 |
|
|
<td class="listlr"><?=$spans;?>
|
142 |
|
|
<?php if ($interface = ovpn_get_opt_interface($server['tun_iface']))
|
143 |
|
|
$iface = $config['interfaces'][$interface]['descr'];
|
144 |
|
|
else $iface = strtoupper($server['tun_iface']);?>
|
145 |
|
|
<?= $iface;?>
|
146 |
|
|
<?=$spane;?></td>
|
147 |
|
|
<td class="listr"><?=$spans;?>
|
148 |
|
|
<?= strtoupper($server['proto']);?>
|
149 |
|
|
<?=$spane;?></td>
|
150 |
|
|
<td class="listr"><?=$spans;?>
|
151 |
|
|
<?= $ipaddr.":".$server['port'];?>
|
152 |
|
|
<?=$spane;?></td>
|
153 |
|
|
<td nowrap class="listr"><?=$spans;?>
|
154 |
|
|
<?php if ($server['authentication_method'] == "pre_shared_key") {
|
155 |
|
|
if ($server['type'] == "tun") {
|
156 |
|
|
$ipblock = $server['lipaddr'] . " / " . $server['ripaddr'];
|
157 |
|
|
} else {
|
158 |
|
|
$ipblock = $server['lipaddr'] . "/" . $server['netmask'];
|
159 |
|
|
}
|
160 |
|
|
} else if (!$server['bridge'])
|
161 |
|
|
$ipblock = $server['ipblock'] . "/" . $server['prefix'];
|
162 |
|
|
else if ($server['range_from'])
|
163 |
|
|
$ipblock = $server['range_from'] . " - " . $server['range_to'];
|
164 |
|
|
else
|
165 |
|
|
$ipblock = "--";?>
|
166 |
|
|
<?= $ipblock;?>
|
167 |
|
|
<?=$spane;?></td>
|
168 |
|
|
<td class="listr"><?=$spans;?>
|
169 |
|
|
<?= $server['crypto'];?>
|
170 |
|
|
<?=$spane;?></td>
|
171 |
|
|
<td class="listbg"><?=$spans;?>
|
172 |
|
|
<?= htmlspecialchars($server['descr']);?>
|
173 |
|
|
<?=$spane;?></td>
|
174 |
|
|
<td valign="middle" nowrap class="list"> <a href="vpn_openvpn_srv_edit.php?id=<?=$i;?>"><img src="e.gif" title="edit server configuration" width="17" height="17" border="0"></a>
|
175 |
|
|
<a href="vpn_openvpn_srv.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this server configuration?')"><img src="x.gif" title="delete server configuration" width="17" height="17" border="0"></a></td>
|
176 |
|
|
</tr>
|
177 |
|
|
<?php $i++; endforeach; ?>
|
178 |
|
|
<tr>
|
179 |
|
|
<td class="list" colspan="6"> </td>
|
180 |
|
|
<td class="list"> <a href="vpn_openvpn_srv_edit.php"><img src="plus.gif" title="add server configuration" width="17" height="17" border="0"></a></td>
|
181 |
|
|
</tr>
|
182 |
|
|
</table>
|
183 |
|
|
</td>
|
184 |
|
|
</tr>
|
185 |
|
|
</table>
|
186 |
|
|
</form>
|
187 |
|
|
<?php include("fend.inc"); ?>
|