Project

General

Profile

Download (14.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/*
3
	vpn_openvpn.php
4

    
5
	Copyright (C) 2004 Peter Curran (peter@closeconsultants.com).
6
	All rights reserved.
7
	
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10
	
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13
	
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17
	
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29

    
30
require("guiconfig.inc");
31
require_once("openvpn.inc");
32

    
33
if (!is_array($config['ovpn']))
34
	$config['ovpn'] = array();
35
if (!is_array($config['ovpn']['server'])){
36
	$config['ovpn']['server'] =  array();
37
	$config['ovpn']['server']['tun_iface'] = "tun0";
38
	$config['ovpn']['server']['psh_options'] = array();
39
	/* Initialise with some sensible defaults */
40
	$config['ovpn']['server']['port'] = 5000;
41
	$config['ovpn']['server']['proto'] = 'UDP';
42
	$config['ovpn']['server']['maxcli'] = 25;
43
	$config['ovpn']['server']['crypto'] = 'BF-CBC';
44
	$config['ovpn']['server']['dupcn'] = true;
45
	$config['ovpn']['server']['verb'] = 1;
46
}
47

    
48
if ($_POST) {
49

    
50
	unset($input_errors);
51

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

    
57
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
58

    
59
	}
60
	
61
	/* need a test here to make sure prefix and max_clients are coherent */
62
		
63
	/* Sort out the cert+key files */
64
	if (is_null($_POST['ca_cert']))
65
		$input_errors[] = "You must provide a CA certificate file";
66
	elseif (!strstr($_POST['ca_cert'], "BEGIN CERTIFICATE") || !strstr($_POST['ca_cert'], "END CERTIFICATE"))
67
		$input_errors[] = "The CA certificate does not appear to be valid.";
68
		
69
	if (is_null($_POST['srv_cert']))
70
		$input_errors[] = "You must provide a server certificate file";
71
	elseif (!strstr($_POST['srv_cert'], "BEGIN CERTIFICATE") || !strstr($_POST['srv_cert'], "END CERTIFICATE"))
72
		$input_errors[] = "The server certificate does not appear to be valid.";
73
		
74
	if (is_null($_POST['srv_key']))
75
		$input_errors[] = "You must provide a server key file";
76
	elseif (!strstr($_POST['srv_key'], "BEGIN RSA PRIVATE KEY") || !strstr($_POST['srv_key'], "END RSA PRIVATE KEY"))
77
		$input_errors[] = "The server key does not appear to be valid.";
78
		
79
	if (is_null($_POST['dh_param']))
80
		$input_errors[] = "You must provide a DH parameters file";
81
	elseif (!strstr($_POST['dh_param'], "BEGIN DH PARAMETERS") || !strstr($_POST['dh_param'], "END DH PARAMETERS"))
82
		$input_errors[] = "The DH parameters do not appear to be valid.";
83
				
84
	if (!$input_errors) {
85
		$server =& $config['ovpn']['server'];
86
		$server['enable'] = $_POST['enable'] ? true : false;
87
		/* Make sure that the tunnel interface type has not changed */
88
		if ($server['tun_iface'] != $_POST['tun_iface']){ 
89
			$server['tun_iface'] = $_POST['tun_iface'];
90

    
91
		}
92
		
93
		$server['bind_iface'] = $_POST['bind_iface'];
94
		$server['port'] = $_POST['port'];
95
		$server['proto'] = $_POST['proto'];
96
		
97
		/* Make sure the IP address and/or prefix have not changed */
98
		if ($server['ipblock'] != $_POST['ipblock']){
99
			$server['ipblock'] = $_POST['ipblock'];
100
		}
101
		if ($server['prefix'] != $_POST['prefix']){
102
			$server['prefix'] = $_POST['prefix'];
103
		}
104
		
105
		$server['maxcli'] = $_POST['maxcli'];
106
		$server['crypto'] = $_POST['crypto'];
107
		$server['cli2cli'] = $_POST['cli2cli'] ? true : false;
108
		$server['dupcn'] = $_POST['dupcn'] ? true : false;
109
		$server['psh_options']['redir'] = $_POST['psh_redir'] ? true : false;
110
		$server['psh_options']['redir_loc'] = $_POST['psh_redir_loc'] ? true : false;
111
		if ($_POST['psh_rtedelay'])
112
			$server['psh_options']['rtedelay'] = $_POST['psh_rtedelay_int'];
113
		if ($_POST['psh_ping'])
114
			$server['psh_options']['ping'] = $_POST['psh_ping_int'];
115
		if ($_POST['psh_pingexit'])
116
			$server['psh_options']['pingexit'] = $_POST['psh_pingexit_int'];
117
		if ($_POST['psh_pingrst'])
118
			$server['psh_options']['pingrst'] = $_POST['psh_pingrst_int'];
119
		if ($_POST['inact'])
120
			$server['psh_options']['inact'] = $_POST['psh_inact_int'];
121
		$server['ca_cert'] = base64_encode($_POST['ca_cert']);
122
		$server['srv_cert'] = base64_encode($_POST['srv_cert']);
123
		$server['srv_key'] = base64_encode($_POST['srv_key']);
124
		$server['dh_param'] = base64_encode($_POST['dh_param']);	
125
			
126
		write_config();
127

    
128
		$retval = 0;
129
		if (file_exists($d_sysrebootreqd_path)) {
130
			/* Rewrite interface definitions */
131
			$retval = ovpn_server_iface();
132
		}
133
		else{
134
			ovpn_lock();
135
			$retval = ovpn_config_server($server['enable']);
136
			ovpn_unlock();
137
		}
138
		$savemsg = get_std_save_message($retval);
139
	}
140
}
141

    
142
/* Simply take a copy of the array */
143
$pconfig = $config['ovpn']['server'];
144

    
145
$pgtitle = array("VPN","OpenVPN");
146
include("head.inc");
147

    
148
?>
149

    
150
<?php include("fbegin.inc"); ?>
151
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
152
<?php if ($input_errors) print_input_errors($input_errors); ?>
153

    
154
<form action="vpn_openvpn.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
155
<table width="100%" border="0" cellpadding="0" cellspacing="0">
156
  <tr><td>
157
<?php
158
        $tab_array = array();
159
        $tab_array[] = array("Server", true, "vpn_openvpn.php");
160
        $tab_array[] = array("Client", false, "vpn_openvpn_cli.php");
161
        display_top_tabs($tab_array);
162
?>
163
  </td></tr>
164
  <tr>
165
  <td>
166
    <div id="mainarea">
167
    <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
168
  <tr>
169
  <td colspan="2">
170
    <strong><span class="red">WARNING: This feature is experimental and modifies your optional interface configuration.
171
  Backup your configuration before using OpenVPN, and restore it before upgrading.<br>
172
&nbsp;  <br>
173
    </span></strong>
174
  </td></tr>
175
  <tr>
176
    <td width="22%" valign="top" class="vtable">&nbsp;</td>
177
    <td width="78%" class="vtable">
178
      <input name="enable" type="checkbox" value="yes" <?php if (isset($pconfig['enable'])) echo "checked"; ?>>
179
      <strong>Enable OpenVPN server </strong></td>
180
   </tr>
181
   
182
   <tr>
183
     <td width="22%" valign="top" class="vncellreq">Tunnel type</td>
184
     <td width="78%" class="vtable">
185
       <input type="radio" name="tun_iface" class="formfld" value="tun0" <?php if ($pconfig['tun_iface'] == 'tun0') echo "checked"; ?>>
186
          TUN&nbsp;
187
       <input type="radio" name="tun_iface" class="formfld" value="tap0" <?php if ($pconfig['tun_iface'] == 'tap0') echo "checked"; ?>>
188
          TAP
189
      </td>
190
    </tr>
191
    
192
    <tr>
193
      <td width="22%" valign="top" class="vncell">OpenVPN protocol/port</td>
194
      <td width="78%" class="vtable">
195
	<input type="radio" name="proto" class="formfld" value="UDP" <?php if ($pconfig['proto'] == 'UDP') echo "checked"; ?>>
196
           UDP&nbsp;
197
        <input type="radio" name="proto" class="formfld" value="TCP" <?php if ($pconfig['proto'] == 'TCP') echo "checked"; ?>>
198
           TCP<br><br>
199
        Port: 
200
        <input name="port" type="text" class="formfld" size="5" maxlength="5" value="<?= $pconfig['port']; ?>"><br>
201
        Enter the port number to use for the server (default is 5000).</td>
202
    </tr>
203
    
204
    <tr>
205
      <td width="22%" valign="top" class="vncellreq">Interface binding</td>
206
      <td width="78%" class="vtable">
207
	<select name="bind_iface" class="formfld">
208
        <?php 
209
	$interfaces = ovpn_real_interface_list();
210
	foreach ($interfaces as $key => $iface):
211
        ?>
212
	<option value="<?=$key;?>" <?php if ($key == $pconfig['bind_iface']) echo "selected"; ?>> <?= $iface;?>
213
        </option>
214
        <?php endforeach;?>
215
        </select>
216
        <span class="vexpl"><br>
217
        Choose an interface for the OpenVPN server to listen on.</span></td>
218
    </tr>
219
		
220
    <tr> 
221
      <td width="22%" valign="top" class="vncellreq">IP address block</td>
222
      <td width="78%" class="vtable"> 
223
        <input name="ipblock" type="text" class="formfld" size="20" value="<?=htmlspecialchars($pconfig['ipblock']);?>">
224
        / 
225
        <select name="prefix" class="formfld">
226
          <?php for ($i = 29; $i > 19; $i--): ?>
227
          <option value="<?=$i;?>" <?php if ($i == $pconfig['prefix']) echo "selected"; ?>>
228
            <?=$i;?>
229
          </option>
230
          <?php endfor; ?>
231
        </select>
232
        <br>
233
        Enter the IP address block for the OpenVPN server and clients to use.<br>
234
        <br>
235
	Maximum number of simultaneous clients: 
236
	<input name="maxcli" type="text" class="formfld" size="3" maxlength="3" value="<?=htmlspecialchars($pconfig['maxcli']);?>">
237
	</td>
238
    </tr>
239
    
240
    <tr> 
241
      <td width="22%" valign="top" class="vncellreq">CA certificate</td>
242
      <td width="78%" class="vtable"> 
243
      <textarea name="ca_cert" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['ca_cert']));?></textarea>
244
      <br>
245
      Paste a CA certificate in X.509 PEM format here.</td>
246
    </tr>
247
		
248
    <tr> 
249
      <td width="22%" valign="top" class="vncellreq">Server certificate</td>
250
      <td width="78%" class="vtable">
251
        <textarea name="srv_cert" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['srv_cert']));?></textarea>
252
        <br>
253
        Paste a server certificate in X.509 PEM format here.</td>
254
     </tr>
255
     
256
     <tr> 
257
       <td width="22%" valign="top" class="vncellreq">Server key</td>
258
       <td width="78%" class="vtable"> 
259
         <textarea name="srv_key" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['srv_key']));?></textarea>
260
         <br>Paste the server RSA private key here.</td>
261
      </tr>
262
      
263
      <tr> 
264
        <td width="22%" valign="top" class="vncellreq">DH parameters</td>
265
        <td width="78%" class="vtable"> 
266
	  <textarea name="dh_param" cols="65" rows="4" class="formpre"><?=htmlspecialchars(base64_decode($pconfig['dh_param']));?></textarea>
267
          <br>          
268
          Paste the Diffie-Hellman parameters in PEM format here.</td>
269
      </tr>
270
      
271
      <tr>
272
        <td width="22%" valign="top" class="vncell">Crypto</td>
273
        <td width="78%" class="vtable">
274
          <select name="crypto" class="formfld">
275
	    <?php $cipher_list = ovpn_get_cipher_list();
276
	    foreach($cipher_list as $key => $value){
277
	    ?>
278
	      <option value="<?= $key ?>" <?php if ($pconfig['crypto'] == $key) echo "selected"; ?>>
279
	        <?= $value ?>
280
	      </option>
281
	    <?php
282
	    }
283
	    ?>
284
	  </select>
285
	  <br>
286
	  Select a data channel encryption cipher.</td>
287
      </tr>
288
      
289
      <tr>
290
        <td width="22%" valign="top" class="vncell">Internal routing mode</td>
291
        <td width="78%" class="vtable">
292
	  <input name="cli2cli" type="checkbox" value="yes" <?php if (isset($pconfig['cli2cli'])) echo "checked"; ?>>
293
          <strong>Enable client-to-client routing</strong><br>
294
          If this option is on,  clients are allowed to talk to each other.</td>
295
      </tr>
296
      
297
      <tr>
298
        <td width="22%" valign="top" class="vncell">Client authentication</td>
299
        <td width="78%" class="vtable">
300
	  <input name="dupcn" type="checkbox" value="yes" <?php if (isset($pconfig['dupcn'])) echo "checked"; ?>>
301
          <strong>Permit duplicate client certificates</strong><br>
302
	  If this option is on, clients with duplicate certificates will not be disconnected.</td>
303
      </tr>
304
	 
305
      <tr>
306
        <td width="22%" valign="top" class="vncell">Client-push options</td>
307
        <td width="78%" class="vtable">
308
	      <table border="0" cellspacing="0" cellpadding="0">
309
	        <tr>
310
              <td><input type="checkbox" name="psh_redir" value="yes" <?php if (isset($pconfig['psh_options']['redir'])) echo "checked"; ?>>
311
              Redirect-gateway</td>
312
              <td>&nbsp;</td>
313
              <td><input type="checkbox" name="psh_redir_loc" value="yes" <?php if (isset($pconfig['psh_options']['redir_loc'])) echo "checked"; ?>>
314
                Local</td>
315
	          </tr>
316
            <tr>
317
              <td><input type="checkbox" name="psh_rtedelay" value="yes" <?php if (isset($pconfig['psh_options']['rtedelay'])) echo "checked"; ?>> Route-delay</td>
318
              <td width="16">&nbsp;</td>
319
              <td><input type="text" name="psh_rtedelay_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['rtedelay']?>"> seconds</td>
320
            </tr>
321
            <tr>
322
              <td><input type="checkbox" name="psh_inact" value="yes" <?php if (isset($pconfig['psh_options']['inact'])) echo "checked"; ?>>
323
    Inactive</td>
324
              <td>&nbsp;</td>
325
              <td><input type="text" name="psh_inact_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['inact']?>">
326
    seconds</td>
327
            </tr>
328
            <tr>
329
              <td><input type="checkbox" name="psh_ping" value="yes" <?php if (isset($pconfig['psh_options']['ping'])) echo "checked"; ?>> Ping</td>
330
              <td>&nbsp;</td>
331
              <td>Interval: <input type="text" name="psh_ping_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['ping']?>"> seconds</td>
332
            </tr>
333
            <tr>
334
              <td><input type="checkbox" name="psh_pingexit" value="yes" <?php if (isset($pconfig['psh_options']['pingexit'])) echo "checked"; ?>> Ping-exit</td>
335
              <td>&nbsp;</td>
336
              <td>Interval: <input type="text" name="psh_pingexit_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['pingexit']?>"> seconds</td>
337
            </tr>
338
            <tr>
339
              <td><input type="checkbox" name="psh_pingrst" value="yes" <?php if (isset($pconfig['psh_options']['pingrst'])) echo "checked"; ?>> Ping-restart</td>
340
              <td>&nbsp;</td>
341
              <td>Interval: <input type="text" name="psh_pingrst_int" class="formfld" size="4" value="<?= $pconfig['psh_options']['pingrst']?>"> seconds</td>
342
            </tr>
343
          </table></td>
344
      </tr>
345
      <tr>
346
        <td width="22%" valign="top">&nbsp;</td>
347
        <td width="78%">
348
          <input name="Submit" type="submit" class="formbtn" value="Save">
349
        </td>
350
      </tr>
351
      <tr>
352
        <td width="22%" valign="top">&nbsp;</td>
353
        <td width="78%"><span class="vexpl"><span class="red"><strong>Note:<br>
354
          </strong></span>Changing any settings on this page will disconnect all clients!</span>
355
	</td>
356
      </tr>
357
    </table>
358
    </div>
359
</td>
360
</tr>
361
</table>
362
</form>
363
<?php include("fend.inc"); ?>
(177-177/197)