Project

General

Profile

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

    
6
	Copyright (C) 2004 Peter Curran (peter@closeconsultants.com).
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
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

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

    
64
	/* 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

    
70
	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

    
75
	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

    
80
	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

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

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

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

    
99
		/* 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

    
109
		$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
		$server['dh_param'] = base64_encode($_POST['dh_param']);
129

    
130
		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
  <ul id="tabnav">
168
	<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

    
185
   <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

    
195
    <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
        Port:
203
        <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

    
207
    <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
        <?php
212
	$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

    
223
    <tr>
224
      <td width="22%" valign="top" class="vncellreq">IP address block</td>
225
      <td width="78%" class="vtable">
226
        <input name="ipblock" type="text" class="formfld" size="20" value="<?=htmlspecialchars($pconfig['ipblock']);?>">
227
        /
228
        <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
	Maximum number of simultaneous clients:
239
	<input name="maxcli" type="text" class="formfld" size="3" maxlength="3" value="<?=htmlspecialchars($pconfig['maxcli']);?>">
240
	</td>
241
    </tr>
242

    
243
    <tr>
244
      <td width="22%" valign="top" class="vncellreq">CA certificate</td>
245
      <td width="78%" class="vtable">
246
      <textarea name="ca_cert" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['ca_cert']));?></textarea>
247
      <br>
248
      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
    </tr>
250

    
251
    <tr>
252
      <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

    
259
     <tr>
260
       <td width="22%" valign="top" class="vncellreq">Server key</td>
261
       <td width="78%" class="vtable">
262
         <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

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

    
274
      <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

    
292
      <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

    
300
      <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

    
308
      <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>
(99-99/106)