Project

General

Profile

Download (15.1 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	vpn_openvpn.php
6

    
7
	Copyright (C) 2004 Peter Curran (peter@closeconsultants.com).
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']['tun_iface'] = "tun0";
40
	$config['ovpn']['server']['psh_options'] = array();
41
	/* Initialise with some sensible defaults */
42
	$config['ovpn']['server']['port'] = 5000;
43
	$config['ovpn']['server']['proto'] = 'UDP';
44
	$config['ovpn']['server']['maxcli'] = 25;
45
	$config['ovpn']['server']['crypto'] = 'BF-CBC';
46
	$config['ovpn']['server']['dupcn'] = true;
47
	$config['ovpn']['server']['verb'] = 1;
48
}
49

    
50
if ($_POST) {
51

    
52
	unset($input_errors);
53

    
54
	/* input validation */
55
	if ($_POST['enable']) {
56
		$reqdfields = explode(" ", "tun_iface bind_iface ipblock");
57
		$reqdfieldsn = explode(",", "Tunnel type,Interface binding,IP address block start");
58

    
59
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
60

    
61
	}
62

    
63
	/* need a test here to make sure prefix and max_clients are coherent */
64

    
65
	/* Sort out the cert+key files */
66
	if (is_null($_POST['ca_cert']))
67
		$input_errors[] = "You must provide a CA certificate file";
68
	elseif (!strstr($_POST['ca_cert'], "BEGIN CERTIFICATE") || !strstr($_POST['ca_cert'], "END CERTIFICATE"))
69
		$input_errors[] = "The CA certificate does not appear to be valid.";
70

    
71
	if (is_null($_POST['srv_cert']))
72
		$input_errors[] = "You must provide a server certificate file";
73
	elseif (!strstr($_POST['srv_cert'], "BEGIN CERTIFICATE") || !strstr($_POST['srv_cert'], "END CERTIFICATE"))
74
		$input_errors[] = "The server certificate does not appear to be valid.";
75

    
76
	if (is_null($_POST['srv_key']))
77
		$input_errors[] = "You must provide a server key file";
78
	elseif (!strstr($_POST['srv_key'], "BEGIN RSA PRIVATE KEY") || !strstr($_POST['srv_key'], "END RSA PRIVATE KEY"))
79
		$input_errors[] = "The server key does not appear to be valid.";
80

    
81
	if (is_null($_POST['dh_param']))
82
		$input_errors[] = "You must provide a DH parameters file";
83
	elseif (!strstr($_POST['dh_param'], "BEGIN DH PARAMETERS") || !strstr($_POST['dh_param'], "END DH PARAMETERS"))
84
		$input_errors[] = "The DH parameters do not appear to be valid.";
85

    
86
	if (!$input_errors) {
87
		$server =& $config['ovpn']['server'];
88
		$server['enable'] = $_POST['enable'] ? true : false;
89

    
90
		/* Make sure that the tunnel interface type has not changed */
91
		if ($server['tun_iface'] != $_POST['tun_iface']){
92
			$server['tun_iface'] = $_POST['tun_iface'];
93
			touch($d_sysrebootreqd_path);
94
		}
95

    
96
		$server['bind_iface'] = $_POST['bind_iface'];
97
		$server['port'] = $_POST['port'];
98
		$server['proto'] = $_POST['proto'];
99

    
100
		/* Make sure the IP address and/or prefix have not changed */
101
		if ($server['ipblock'] != $_POST['ipblock']){
102
			$server['ipblock'] = $_POST['ipblock'];
103
			touch($d_sysrebootreqd_path);
104
		}
105
		if ($server['prefix'] != $_POST['prefix']){
106
			$server['prefix'] = $_POST['prefix'];
107
			touch($d_sysrebootreqd_path);
108
		}
109

    
110
		$server['maxcli'] = $_POST['maxcli'];
111
		$server['crypto'] = $_POST['crypto'];
112
		$server['cli2cli'] = $_POST['cli2cli'] ? true : false;
113
		$server['dupcn'] = $_POST['dupcn'] ? true : false;
114
		$server['psh_options']['redir'] = $_POST['psh_redir'] ? true : false;
115
		$server['psh_options']['redir_loc'] = $_POST['psh_redir_loc'] ? true : false;
116
		if ($_POST['psh_rtedelay'])
117
			$server['psh_options']['rtedelay'] = $_POST['psh_rtedelay_int'];
118
		if ($_POST['psh_ping'])
119
			$server['psh_options']['ping'] = $_POST['psh_ping_int'];
120
		if ($_POST['psh_pingexit'])
121
			$server['psh_options']['pingexit'] = $_POST['psh_pingexit_int'];
122
		if ($_POST['psh_pingrst'])
123
			$server['psh_options']['pingrst'] = $_POST['psh_pingrst_int'];
124
		if ($_POST['inact'])
125
			$server['psh_options']['inact'] = $_POST['psh_inact_int'];
126
		$server['ca_cert'] = base64_encode($_POST['ca_cert']);
127
		$server['srv_cert'] = base64_encode($_POST['srv_cert']);
128
		$server['srv_key'] = base64_encode($_POST['srv_key']);
129
		$server['dh_param'] = base64_encode($_POST['dh_param']);
130

    
131
		write_config();
132

    
133
		$retval = 0;
134
		if (file_exists($d_sysrebootreqd_path)) {
135
			/* Rewrite interface definitions */
136
			$retval = ovpn_server_iface();
137
		}
138
		else{
139
			ovpn_lock();
140
			$retval = ovpn_config_server();
141
			ovpn_unlock();
142
		}
143
		$savemsg = get_std_save_message($retval);
144
	}
145
}
146

    
147
/* Simply take a copy of the array */
148
$pconfig = $config['ovpn']['server'];
149

    
150
?>
151
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
152
<html>
153
<head>
154
<title><?=gentitle("VPN: OpenVPN");?></title>
155
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
156
<link href="gui.css" rel="stylesheet" type="text/css">
157
</head>
158

    
159
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
160
<?php include("fbegin.inc"); ?>
161
<p class="pgtitle">VPN: OpenVPN</p>
162
<?php if ($input_errors) print_input_errors($input_errors); ?>
163
<?php if (file_exists($d_sysrebootreqd_path)) print_info_box(get_std_save_message(0)); ?>
164

    
165
<form action="vpn_openvpn.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
166
<table width="100%" border="0" cellpadding="0" cellspacing="0">
167
  <tr><td>
168
  <ul id="tabnav">
169
	<li class="tabact">Server</li>
170
	<li class="tabinact"><a href="vpn_openvpn_cli.php">Client</a></li>
171
  </ul>
172
  </td></tr>
173
  <tr>
174
  <td class="tabcont">
175
    <strong><span class="red">WARNING: This feature is experimental and modifies your optional interface configuration.
176
  Backup your configuration before using OpenVPN, and restore it before upgrading.<br>
177
&nbsp;  <br>
178
    </span></strong><table width="100%" border="0" cellpadding="6" cellspacing="0">
179
  <tr>
180
    <td width="22%" valign="top" class="vtable">&nbsp;</td>
181
    <td width="78%" class="vtable">
182
      <input name="enable" type="checkbox" value="yes" <?php if (isset($pconfig['enable'])) echo "checked"; ?>>
183
      <strong>Enable OpenVPN server </strong></td>
184
   </tr>
185

    
186
   <tr>
187
     <td width="22%" valign="top" class="vncellreq">Tunnel type</td>
188
     <td width="78%" class="vtable">
189
       <input type="radio" name="tun_iface" class="formfld" value="tun0" <?php if ($pconfig['tun_iface'] == 'tun0') echo "checked"; ?>>
190
          TUN&nbsp;
191
       <input type="radio" name="tun_iface" class="formfld" value="tap0" <?php if ($pconfig['tun_iface'] == 'tap0') echo "checked"; ?>>
192
          TAP
193
      </td>
194
    </tr>
195

    
196
    <tr>
197
      <td width="22%" valign="top" class="vncell">OpenVPN protocol/port</td>
198
      <td width="78%" class="vtable">
199
	<input type="radio" name="proto" class="formfld" value="UDP" <?php if ($pconfig['proto'] == 'UDP') echo "checked"; ?>>
200
           UDP&nbsp;
201
        <input type="radio" name="proto" class="formfld" value="TCP" <?php if ($pconfig['proto'] == 'TCP') echo "checked"; ?>>
202
           TCP<br><br>
203
        Port:
204
        <input name="port" type="text" class="formfld" size="5" maxlength="5" value="<?= $pconfig['port']; ?>"><br>
205
        Enter the port number to use for the server (default is 5000).</td>
206
    </tr>
207

    
208
    <tr>
209
      <td width="22%" valign="top" class="vncellreq">Interface binding</td>
210
      <td width="78%" class="vtable">
211
	<select name="bind_iface" class="formfld">
212
        <?php
213
	$interfaces = ovpn_real_interface_list();
214
	foreach ($interfaces as $key => $iface):
215
        ?>
216
	<option value="<?=$key;?>" <?php if ($key == $pconfig['bind_iface']) echo "selected"; ?>> <?= $iface;?>
217
        </option>
218
        <?php endforeach;?>
219
        </select>
220
        <span class="vexpl"><br>
221
        Choose an interface for the OpenVPN server to listen on.</span></td>
222
    </tr>
223

    
224
    <tr>
225
      <td width="22%" valign="top" class="vncellreq">IP address block</td>
226
      <td width="78%" class="vtable">
227
        <input name="ipblock" type="text" class="formfld" size="20" value="<?=htmlspecialchars($pconfig['ipblock']);?>">
228
        /
229
        <select name="prefix" class="formfld">
230
          <?php for ($i = 29; $i > 19; $i--): ?>
231
          <option value="<?=$i;?>" <?php if ($i == $pconfig['prefix']) echo "selected"; ?>>
232
            <?=$i;?>
233
          </option>
234
          <?php endfor; ?>
235
        </select>
236
        <br>
237
        Enter the IP address block for the OpenVPN server and clients to use.<br>
238
        <br>
239
	Maximum number of simultaneous clients:
240
	<input name="maxcli" type="text" class="formfld" size="3" maxlength="3" value="<?=htmlspecialchars($pconfig['maxcli']);?>">
241
	</td>
242
    </tr>
243

    
244
    <tr>
245
      <td width="22%" valign="top" class="vncellreq">CA certificate</td>
246
      <td width="78%" class="vtable">
247
      <textarea name="ca_cert" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['ca_cert']));?></textarea>
248
      <br>
249
      Paste a CA certificate in X.509 PEM format here. <a target="_new" href='vpn_openvpn_create_certs.php'>Create</a> all certificates.</td>
250
    </tr>
251

    
252
    <tr>
253
      <td width="22%" valign="top" class="vncellreq">Server certificate</td>
254
      <td width="78%" class="vtable">
255
        <textarea name="srv_cert" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['srv_cert']));?></textarea>
256
        <br>
257
        Paste a server certificate in X.509 PEM format here.</td>
258
     </tr>
259

    
260
     <tr>
261
       <td width="22%" valign="top" class="vncellreq">Server key</td>
262
       <td width="78%" class="vtable">
263
         <textarea name="srv_key" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['srv_key']));?></textarea>
264
         <br>Paste the server RSA private key here.</td>
265
      </tr>
266

    
267
      <tr>
268
        <td width="22%" valign="top" class="vncellreq">DH parameters</td>
269
        <td width="78%" class="vtable">
270
	  <textarea name="dh_param" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['dh_param']));?></textarea>
271
          <br>
272
          Paste the Diffie-Hellman parameters in PEM format here.</td>
273
      </tr>
274

    
275
      <tr>
276
        <td width="22%" valign="top" class="vncell">Crypto</td>
277
        <td width="78%" class="vtable">
278
          <select name="crypto" class="formfld">
279
	    <?php $cipher_list = ovpn_get_cipher_list();
280
	    foreach($cipher_list as $key => $value){
281
	    ?>
282
	      <option value="<?= $key ?>" <?php if ($pconfig['crypto'] == $key) echo "selected"; ?>>
283
	        <?= $value ?>
284
	      </option>
285
	    <?php
286
	    }
287
	    ?>
288
	  </select>
289
	  <br>
290
	  Select a data channel encryption cipher.</td>
291
      </tr>
292

    
293
      <tr>
294
        <td width="22%" valign="top" class="vncell">Internal routing mode</td>
295
        <td width="78%" class="vtable">
296
	  <input name="cli2cli" type="checkbox" value="yes" <?php if (isset($pconfig['cli2cli'])) echo "checked"; ?>>
297
          <strong>Enable client-to-client routing</strong><br>
298
          If this option is on,  clients are allowed to talk to each other.</td>
299
      </tr>
300

    
301
      <tr>
302
        <td width="22%" valign="top" class="vncell">Client authentication</td>
303
        <td width="78%" class="vtable">
304
	  <input name="dupcn" type="checkbox" value="yes" <?php if (isset($pconfig['dupcn'])) echo "checked"; ?>>
305
          <strong>Permit duplicate client certificates</strong><br>
306
	  If this option is on, clients with duplicate certificates will not be disconnected.</td>
307
      </tr>
308

    
309
      <tr>
310
        <td width="22%" valign="top" class="vncell">Client-push options</td>
311
        <td width="78%" class="vtable">
312
	      <table border="0" cellspacing="0" cellpadding="0">
313
	        <tr>
314
              <td><input type="checkbox" name="psh_redir" value="yes" <?php if (isset($pconfig['psh_options']['redir'])) echo "checked"; ?>>
315
              Redirect-gateway</td>
316
              <td>&nbsp;</td>
317
              <td><input type="checkbox" name="psh_redir_loc" value="yes" <?php if (isset($pconfig['psh_options']['redir_loc'])) echo "checked"; ?>>
318
                Local</td>
319
	          </tr>
320
            <tr>
321
              <td><input type="checkbox" name="psh_rtedelay" value="yes" <?php if (isset($pconfig['psh_options']['rtedelay'])) echo "checked"; ?>> Route-delay</td>
322
              <td width="16">&nbsp;</td>
323
              <td><input type="text" name="psh_rtedelay_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['rtedelay']?>"> seconds</td>
324
            </tr>
325
            <tr>
326
              <td><input type="checkbox" name="psh_inact" value="yes" <?php if (isset($pconfig['psh_options']['inact'])) echo "checked"; ?>>
327
    Inactive</td>
328
              <td>&nbsp;</td>
329
              <td><input type="text" name="psh_inact_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['inact']?>">
330
    seconds</td>
331
            </tr>
332
            <tr>
333
              <td><input type="checkbox" name="psh_ping" value="yes" <?php if (isset($pconfig['psh_options']['ping'])) echo "checked"; ?>> Ping</td>
334
              <td>&nbsp;</td>
335
              <td>Interval: <input type="text" name="psh_ping_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['ping']?>"> seconds</td>
336
            </tr>
337
            <tr>
338
              <td><input type="checkbox" name="psh_pingexit" value="yes" <?php if (isset($pconfig['psh_options']['pingexit'])) echo "checked"; ?>> Ping-exit</td>
339
              <td>&nbsp;</td>
340
              <td>Interval: <input type="text" name="psh_pingexit_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['pingexit']?>"> seconds</td>
341
            </tr>
342
            <tr>
343
              <td><input type="checkbox" name="psh_pingrst" value="yes" <?php if (isset($pconfig['psh_options']['pingrst'])) echo "checked"; ?>> Ping-restart</td>
344
              <td>&nbsp;</td>
345
              <td>Interval: <input type="text" name="psh_pingrst_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['pingrst']?>"> seconds</td>
346
            </tr>
347
          </table></td>
348
      </tr>
349
      <tr>
350
        <td width="22%" valign="top">&nbsp;</td>
351
        <td width="78%">
352
          <input name="Submit" type="submit" class="formbtn" value="Save">
353
        </td>
354
      </tr>
355
      <tr>
356
        <td width="22%" valign="top">&nbsp;</td>
357
        <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
358
          </strong></span>Changing any settings on this page will disconnect all clients!</span>
359
	</td>
360
      </tr>
361
    </table>  </td>
362
</tr>
363
</table>
364
</form>
365
<?php include("fend.inc"); ?>
366
</body>
367
</html>
(101-101/109)