Project

General

Profile

Download (15.1 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 fb03ee88 Scott Ullrich
<?php
3 5b237745 Scott Ullrich
/*
4
	vpn_openvpn.php
5
6
	Copyright (C) 2004 Peter Curran (peter@closeconsultants.com).
7
	All rights reserved.
8 fb03ee88 Scott Ullrich
9 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11 fb03ee88 Scott Ullrich
12 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14 fb03ee88 Scott Ullrich
15 5b237745 Scott Ullrich
	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 fb03ee88 Scott Ullrich
19 5b237745 Scott Ullrich
	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
require("guiconfig.inc");
32
require_once("openvpn.inc");
33
34
if (!is_array($config['ovpn']))
35
	$config['ovpn'] = array();
36
if (!is_array($config['ovpn']['server'])){
37
	$config['ovpn']['server'] =  array();
38
	$config['ovpn']['server']['tun_iface'] = "tun0";
39
	$config['ovpn']['server']['psh_options'] = array();
40
	/* Initialise with some sensible defaults */
41
	$config['ovpn']['server']['port'] = 5000;
42
	$config['ovpn']['server']['proto'] = 'UDP';
43
	$config['ovpn']['server']['maxcli'] = 25;
44
	$config['ovpn']['server']['crypto'] = 'BF-CBC';
45
	$config['ovpn']['server']['dupcn'] = true;
46
	$config['ovpn']['server']['verb'] = 1;
47
}
48
49
if ($_POST) {
50
51
	unset($input_errors);
52
53
	/* input validation */
54
	if ($_POST['enable']) {
55
		$reqdfields = explode(" ", "tun_iface bind_iface ipblock");
56
		$reqdfieldsn = explode(",", "Tunnel type,Interface binding,IP address block start");
57
58
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
59
60
	}
61 fb03ee88 Scott Ullrich
62 5b237745 Scott Ullrich
	/* need a test here to make sure prefix and max_clients are coherent */
63 fb03ee88 Scott Ullrich
64 5b237745 Scott Ullrich
	/* Sort out the cert+key files */
65
	if (is_null($_POST['ca_cert']))
66
		$input_errors[] = "You must provide a CA certificate file";
67
	elseif (!strstr($_POST['ca_cert'], "BEGIN CERTIFICATE") || !strstr($_POST['ca_cert'], "END CERTIFICATE"))
68
		$input_errors[] = "The CA certificate does not appear to be valid.";
69 fb03ee88 Scott Ullrich
70 5b237745 Scott Ullrich
	if (is_null($_POST['srv_cert']))
71
		$input_errors[] = "You must provide a server certificate file";
72
	elseif (!strstr($_POST['srv_cert'], "BEGIN CERTIFICATE") || !strstr($_POST['srv_cert'], "END CERTIFICATE"))
73
		$input_errors[] = "The server certificate does not appear to be valid.";
74 fb03ee88 Scott Ullrich
75 5b237745 Scott Ullrich
	if (is_null($_POST['srv_key']))
76
		$input_errors[] = "You must provide a server key file";
77
	elseif (!strstr($_POST['srv_key'], "BEGIN RSA PRIVATE KEY") || !strstr($_POST['srv_key'], "END RSA PRIVATE KEY"))
78
		$input_errors[] = "The server key does not appear to be valid.";
79 fb03ee88 Scott Ullrich
80 5b237745 Scott Ullrich
	if (is_null($_POST['dh_param']))
81
		$input_errors[] = "You must provide a DH parameters file";
82
	elseif (!strstr($_POST['dh_param'], "BEGIN DH PARAMETERS") || !strstr($_POST['dh_param'], "END DH PARAMETERS"))
83
		$input_errors[] = "The DH parameters do not appear to be valid.";
84 fb03ee88 Scott Ullrich
85 5b237745 Scott Ullrich
	if (!$input_errors) {
86
		$server =& $config['ovpn']['server'];
87
		$server['enable'] = $_POST['enable'] ? true : false;
88 fb03ee88 Scott Ullrich
89 5b237745 Scott Ullrich
		/* Make sure that the tunnel interface type has not changed */
90 fb03ee88 Scott Ullrich
		if ($server['tun_iface'] != $_POST['tun_iface']){
91 5b237745 Scott Ullrich
			$server['tun_iface'] = $_POST['tun_iface'];
92
			touch($d_sysrebootreqd_path);
93
		}
94 fb03ee88 Scott Ullrich
95 5b237745 Scott Ullrich
		$server['bind_iface'] = $_POST['bind_iface'];
96
		$server['port'] = $_POST['port'];
97
		$server['proto'] = $_POST['proto'];
98 fb03ee88 Scott Ullrich
99 5b237745 Scott Ullrich
		/* Make sure the IP address and/or prefix have not changed */
100
		if ($server['ipblock'] != $_POST['ipblock']){
101
			$server['ipblock'] = $_POST['ipblock'];
102
			touch($d_sysrebootreqd_path);
103
		}
104
		if ($server['prefix'] != $_POST['prefix']){
105
			$server['prefix'] = $_POST['prefix'];
106
			touch($d_sysrebootreqd_path);
107
		}
108 fb03ee88 Scott Ullrich
109 5b237745 Scott Ullrich
		$server['maxcli'] = $_POST['maxcli'];
110
		$server['crypto'] = $_POST['crypto'];
111
		$server['cli2cli'] = $_POST['cli2cli'] ? true : false;
112
		$server['dupcn'] = $_POST['dupcn'] ? true : false;
113
		$server['psh_options']['redir'] = $_POST['psh_redir'] ? true : false;
114
		$server['psh_options']['redir_loc'] = $_POST['psh_redir_loc'] ? true : false;
115
		if ($_POST['psh_rtedelay'])
116
			$server['psh_options']['rtedelay'] = $_POST['psh_rtedelay_int'];
117
		if ($_POST['psh_ping'])
118
			$server['psh_options']['ping'] = $_POST['psh_ping_int'];
119
		if ($_POST['psh_pingexit'])
120
			$server['psh_options']['pingexit'] = $_POST['psh_pingexit_int'];
121
		if ($_POST['psh_pingrst'])
122
			$server['psh_options']['pingrst'] = $_POST['psh_pingrst_int'];
123
		if ($_POST['inact'])
124
			$server['psh_options']['inact'] = $_POST['psh_inact_int'];
125
		$server['ca_cert'] = base64_encode($_POST['ca_cert']);
126
		$server['srv_cert'] = base64_encode($_POST['srv_cert']);
127
		$server['srv_key'] = base64_encode($_POST['srv_key']);
128 fb03ee88 Scott Ullrich
		$server['dh_param'] = base64_encode($_POST['dh_param']);
129
130 5b237745 Scott Ullrich
		write_config();
131
132
		$retval = 0;
133
		if (file_exists($d_sysrebootreqd_path)) {
134
			/* Rewrite interface definitions */
135
			$retval = ovpn_server_iface();
136
		}
137
		else{
138
			ovpn_lock();
139
			$retval = ovpn_config_server();
140
			ovpn_unlock();
141
		}
142
		$savemsg = get_std_save_message($retval);
143
	}
144
}
145
146
/* Simply take a copy of the array */
147
$pconfig = $config['ovpn']['server'];
148
149
?>
150
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
151
<html>
152
<head>
153
<title><?=gentitle("VPN: OpenVPN");?></title>
154
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
155
<link href="gui.css" rel="stylesheet" type="text/css">
156
</head>
157
158
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
159
<?php include("fbegin.inc"); ?>
160
<p class="pgtitle">VPN: OpenVPN</p>
161
<?php if ($input_errors) print_input_errors($input_errors); ?>
162
<?php if (file_exists($d_sysrebootreqd_path)) print_info_box(get_std_save_message(0)); ?>
163
164
<form action="vpn_openvpn.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
165
<table width="100%" border="0" cellpadding="0" cellspacing="0">
166
  <tr><td>
167 fb03ee88 Scott Ullrich
  <ul id="tabnav">
168 5b237745 Scott Ullrich
	<li class="tabact">Server</li>
169
	<li class="tabinact"><a href="vpn_openvpn_cli.php">Client</a></li>
170
  </ul>
171
  </td></tr>
172
  <tr>
173
  <td class="tabcont">
174
    <strong><span class="red">WARNING: This feature is experimental and modifies your optional interface configuration.
175
  Backup your configuration before using OpenVPN, and restore it before upgrading.<br>
176
&nbsp;  <br>
177
    </span></strong><table width="100%" border="0" cellpadding="6" cellspacing="0">
178
  <tr>
179
    <td width="22%" valign="top" class="vtable">&nbsp;</td>
180
    <td width="78%" class="vtable">
181
      <input name="enable" type="checkbox" value="yes" <?php if (isset($pconfig['enable'])) echo "checked"; ?>>
182
      <strong>Enable OpenVPN server </strong></td>
183
   </tr>
184 fb03ee88 Scott Ullrich
185 5b237745 Scott Ullrich
   <tr>
186
     <td width="22%" valign="top" class="vncellreq">Tunnel type</td>
187
     <td width="78%" class="vtable">
188
       <input type="radio" name="tun_iface" class="formfld" value="tun0" <?php if ($pconfig['tun_iface'] == 'tun0') echo "checked"; ?>>
189
          TUN&nbsp;
190
       <input type="radio" name="tun_iface" class="formfld" value="tap0" <?php if ($pconfig['tun_iface'] == 'tap0') echo "checked"; ?>>
191
          TAP
192
      </td>
193
    </tr>
194 fb03ee88 Scott Ullrich
195 5b237745 Scott Ullrich
    <tr>
196
      <td width="22%" valign="top" class="vncell">OpenVPN protocol/port</td>
197
      <td width="78%" class="vtable">
198
	<input type="radio" name="proto" class="formfld" value="UDP" <?php if ($pconfig['proto'] == 'UDP') echo "checked"; ?>>
199
           UDP&nbsp;
200
        <input type="radio" name="proto" class="formfld" value="TCP" <?php if ($pconfig['proto'] == 'TCP') echo "checked"; ?>>
201
           TCP<br><br>
202 fb03ee88 Scott Ullrich
        Port:
203 5b237745 Scott Ullrich
        <input name="port" type="text" class="formfld" size="5" maxlength="5" value="<?= $pconfig['port']; ?>"><br>
204
        Enter the port number to use for the server (default is 5000).</td>
205
    </tr>
206 fb03ee88 Scott Ullrich
207 5b237745 Scott Ullrich
    <tr>
208
      <td width="22%" valign="top" class="vncellreq">Interface binding</td>
209
      <td width="78%" class="vtable">
210
	<select name="bind_iface" class="formfld">
211 fb03ee88 Scott Ullrich
        <?php
212 5b237745 Scott Ullrich
	$interfaces = ovpn_real_interface_list();
213
	foreach ($interfaces as $key => $iface):
214
        ?>
215
	<option value="<?=$key;?>" <?php if ($key == $pconfig['bind_iface']) echo "selected"; ?>> <?= $iface;?>
216
        </option>
217
        <?php endforeach;?>
218
        </select>
219
        <span class="vexpl"><br>
220
        Choose an interface for the OpenVPN server to listen on.</span></td>
221
    </tr>
222 fb03ee88 Scott Ullrich
223
    <tr>
224 5b237745 Scott Ullrich
      <td width="22%" valign="top" class="vncellreq">IP address block</td>
225 fb03ee88 Scott Ullrich
      <td width="78%" class="vtable">
226 5b237745 Scott Ullrich
        <input name="ipblock" type="text" class="formfld" size="20" value="<?=htmlspecialchars($pconfig['ipblock']);?>">
227 fb03ee88 Scott Ullrich
        /
228 5b237745 Scott Ullrich
        <select name="prefix" class="formfld">
229
          <?php for ($i = 29; $i > 19; $i--): ?>
230
          <option value="<?=$i;?>" <?php if ($i == $pconfig['prefix']) echo "selected"; ?>>
231
            <?=$i;?>
232
          </option>
233
          <?php endfor; ?>
234
        </select>
235
        <br>
236
        Enter the IP address block for the OpenVPN server and clients to use.<br>
237
        <br>
238 fb03ee88 Scott Ullrich
	Maximum number of simultaneous clients:
239 5b237745 Scott Ullrich
	<input name="maxcli" type="text" class="formfld" size="3" maxlength="3" value="<?=htmlspecialchars($pconfig['maxcli']);?>">
240
	</td>
241
    </tr>
242 fb03ee88 Scott Ullrich
243
    <tr>
244 5b237745 Scott Ullrich
      <td width="22%" valign="top" class="vncellreq">CA certificate</td>
245 fb03ee88 Scott Ullrich
      <td width="78%" class="vtable">
246 5b237745 Scott Ullrich
      <textarea name="ca_cert" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['ca_cert']));?></textarea>
247
      <br>
248 fb03ee88 Scott Ullrich
      Paste a CA certificate in X.509 PEM format here. <a target="_new" href='vpn_openvpn_create_certs.php'>Create</a> all certificates.</td>
249 5b237745 Scott Ullrich
    </tr>
250 fb03ee88 Scott Ullrich
251
    <tr>
252 5b237745 Scott Ullrich
      <td width="22%" valign="top" class="vncellreq">Server certificate</td>
253
      <td width="78%" class="vtable">
254
        <textarea name="srv_cert" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['srv_cert']));?></textarea>
255
        <br>
256
        Paste a server certificate in X.509 PEM format here.</td>
257
     </tr>
258 fb03ee88 Scott Ullrich
259
     <tr>
260 5b237745 Scott Ullrich
       <td width="22%" valign="top" class="vncellreq">Server key</td>
261 fb03ee88 Scott Ullrich
       <td width="78%" class="vtable">
262 5b237745 Scott Ullrich
         <textarea name="srv_key" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['srv_key']));?></textarea>
263
         <br>Paste the server RSA private key here.</td>
264
      </tr>
265 fb03ee88 Scott Ullrich
266
      <tr>
267 5b237745 Scott Ullrich
        <td width="22%" valign="top" class="vncellreq">DH parameters</td>
268 fb03ee88 Scott Ullrich
        <td width="78%" class="vtable">
269 5b237745 Scott Ullrich
	  <textarea name="dh_param" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['dh_param']));?></textarea>
270 fb03ee88 Scott Ullrich
          <br>
271 5b237745 Scott Ullrich
          Paste the Diffie-Hellman parameters in PEM format here.</td>
272
      </tr>
273 fb03ee88 Scott Ullrich
274 5b237745 Scott Ullrich
      <tr>
275
        <td width="22%" valign="top" class="vncell">Crypto</td>
276
        <td width="78%" class="vtable">
277
          <select name="crypto" class="formfld">
278
	    <?php $cipher_list = ovpn_get_cipher_list();
279
	    foreach($cipher_list as $key => $value){
280
	    ?>
281
	      <option value="<?= $key ?>" <?php if ($pconfig['crypto'] == $key) echo "selected"; ?>>
282
	        <?= $value ?>
283
	      </option>
284
	    <?php
285
	    }
286
	    ?>
287
	  </select>
288
	  <br>
289
	  Select a data channel encryption cipher.</td>
290
      </tr>
291 fb03ee88 Scott Ullrich
292 5b237745 Scott Ullrich
      <tr>
293
        <td width="22%" valign="top" class="vncell">Internal routing mode</td>
294
        <td width="78%" class="vtable">
295
	  <input name="cli2cli" type="checkbox" value="yes" <?php if (isset($pconfig['cli2cli'])) echo "checked"; ?>>
296
          <strong>Enable client-to-client routing</strong><br>
297
          If this option is on,  clients are allowed to talk to each other.</td>
298
      </tr>
299 fb03ee88 Scott Ullrich
300 5b237745 Scott Ullrich
      <tr>
301
        <td width="22%" valign="top" class="vncell">Client authentication</td>
302
        <td width="78%" class="vtable">
303
	  <input name="dupcn" type="checkbox" value="yes" <?php if (isset($pconfig['dupcn'])) echo "checked"; ?>>
304
          <strong>Permit duplicate client certificates</strong><br>
305
	  If this option is on, clients with duplicate certificates will not be disconnected.</td>
306
      </tr>
307 fb03ee88 Scott Ullrich
308 5b237745 Scott Ullrich
      <tr>
309
        <td width="22%" valign="top" class="vncell">Client-push options</td>
310
        <td width="78%" class="vtable">
311
	      <table border="0" cellspacing="0" cellpadding="0">
312
	        <tr>
313
              <td><input type="checkbox" name="psh_redir" value="yes" <?php if (isset($pconfig['psh_options']['redir'])) echo "checked"; ?>>
314
              Redirect-gateway</td>
315
              <td>&nbsp;</td>
316
              <td><input type="checkbox" name="psh_redir_loc" value="yes" <?php if (isset($pconfig['psh_options']['redir_loc'])) echo "checked"; ?>>
317
                Local</td>
318
	          </tr>
319
            <tr>
320
              <td><input type="checkbox" name="psh_rtedelay" value="yes" <?php if (isset($pconfig['psh_options']['rtedelay'])) echo "checked"; ?>> Route-delay</td>
321
              <td width="16">&nbsp;</td>
322
              <td><input type="text" name="psh_rtedelay_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['rtedelay']?>"> seconds</td>
323
            </tr>
324
            <tr>
325
              <td><input type="checkbox" name="psh_inact" value="yes" <?php if (isset($pconfig['psh_options']['inact'])) echo "checked"; ?>>
326
    Inactive</td>
327
              <td>&nbsp;</td>
328
              <td><input type="text" name="psh_inact_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['inact']?>">
329
    seconds</td>
330
            </tr>
331
            <tr>
332
              <td><input type="checkbox" name="psh_ping" value="yes" <?php if (isset($pconfig['psh_options']['ping'])) echo "checked"; ?>> Ping</td>
333
              <td>&nbsp;</td>
334
              <td>Interval: <input type="text" name="psh_ping_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['ping']?>"> seconds</td>
335
            </tr>
336
            <tr>
337
              <td><input type="checkbox" name="psh_pingexit" value="yes" <?php if (isset($pconfig['psh_options']['pingexit'])) echo "checked"; ?>> Ping-exit</td>
338
              <td>&nbsp;</td>
339
              <td>Interval: <input type="text" name="psh_pingexit_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['pingexit']?>"> seconds</td>
340
            </tr>
341
            <tr>
342
              <td><input type="checkbox" name="psh_pingrst" value="yes" <?php if (isset($pconfig['psh_options']['pingrst'])) echo "checked"; ?>> Ping-restart</td>
343
              <td>&nbsp;</td>
344
              <td>Interval: <input type="text" name="psh_pingrst_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['pingrst']?>"> seconds</td>
345
            </tr>
346
          </table></td>
347
      </tr>
348
      <tr>
349
        <td width="22%" valign="top">&nbsp;</td>
350
        <td width="78%">
351
          <input name="Submit" type="submit" class="formbtn" value="Save">
352
        </td>
353
      </tr>
354
      <tr>
355
        <td width="22%" valign="top">&nbsp;</td>
356
        <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
357
          </strong></span>Changing any settings on this page will disconnect all clients!</span>
358
	</td>
359
      </tr>
360
    </table>  </td>
361
</tr>
362
</table>
363
</form>
364
<?php include("fend.inc"); ?>
365
</body>
366
</html>