Project

General

Profile

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

    
5
	Copyright (C) 2004 Peter Curran (peter@closeconsultants.com).
6
	Copyright (C) 2005 Peter Allgeyer (allgeyer@web.de).
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']['tunnel'] =  array();
39
}
40

    
41
$ovpnsrv = &$config['ovpn']['server']['tunnel'];
42

    
43
$id = $_GET['id'];
44
if (isset($_POST['id']))
45
        $id = $_POST['id'];
46

    
47

    
48
if ($_POST['apply']) {
49
		$retval = 0;
50
		if (file_exists($d_sysrebootreqd_path)) {
51
			/* Rewrite interface definitions */
52
			$retval = ovpn_server_iface();
53
		} else {
54
			ovpn_lock();
55
			$retval = ovpn_server_iface();
56
			$retval = ovpn_config_server(false);
57
			ovpn_unlock();
58
		}
59
		if (file_exists($d_ovpnsrvdirty_path))
60
			unlink($d_ovpnsrvdirty_path);
61
		$savemsg = get_std_save_message($retval);	
62
}
63

    
64
if ($_GET['act'] == "del") {
65
	if ($ovpnsrv[$id]) {
66
		$ovpnent = $ovpnsrv[$id];
67
		unset($ovpnsrv[$id]);
68
									      
69
		/* Kill running processes */
70
		ovpn_server_kill($ovpnent['tun_iface']);
71

    
72
		/* Remove old certs & keys */
73
		ovpn_server_certs_del($ovpnent['tun_iface']);
74

    
75
		/* Remove interface from list of optional interfaces */
76
		ovpn_server_iface_del($ovpnent['tun_iface']);
77

    
78
		write_config();
79
		//touch($d_sysrebootreqd_path);
80
		header("Location: vpn_openvpn_srv.php");
81
		exit;
82
	}
83
}
84

    
85
$pgtitle = "VPN: OpenVPN";
86
include("head.inc");
87

    
88
?>
89
<?php include("fbegin.inc"); ?>
90
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
91
<p class="pgtitle"><?=$pgtitle?></p>
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

    
95
<form action="vpn_openvpn_srv.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
96
<?php if (file_exists($d_ovpnsrvdirty_path)): ?><p>
97
<?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.");?>
98
</p>
99
<?php endif; ?>
100

    
101
<table width="100%" border="0" cellpadding="0" cellspacing="0">
102
  <tr><td>
103
<?php
104
	$tab_array = array();
105
	$tab_array[] = array("Server", true, "vpn_openvpn_srv.php");
106
	$tab_array[] = array("Client", false, "vpn_openvpn_cli.php");
107
	$tab_array[] = array("Client-specific Configuration", false, "vpn_openvpn_ccd.php");
108
	$tab_array[] = array("CRL", false, "vpn_openvpn_crl.php");
109
	display_top_tabs($tab_array);
110
?>
111
  </td></tr>
112
  
113
  <tr> 
114
    <td>
115
	<div id="mainarea">
116
        <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
117
                <tr> 
118
                  <td class="vtable">
119
				    <strong><span class="red">WARNING: This feature is experimental and modifies your optional interface configuration.
120
					Backup your configuration before using OpenVPN, and restore it before upgrading.
121
				    </span></strong>
122
				  </td>
123
				</tr>
124
        </table>
125
		
126
    <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
127
	<tr>
128
	  <td width="5%" class="listhdrr">Interface</td>
129
	  <td width="5%" class="listhdrr">Protocol</td>
130
	  <td width="5%" class="listhdrr">Socket</td>
131
	  <td width="25%" class="listhdrr">IP Block</td>
132
	  <td width="15%" class="listhdrr">Crypto</td>
133
	  <td width="35%" class="listhdr">Description</td>
134
	  <td width="10%" class="list"></td>
135
	</tr>
136
	
137
	<?php $i = 0; foreach ($ovpnsrv as $server):
138
					if (!isset($server['enable'])) {
139
						$spans = "<span class=\"gray\">";
140
						$spane = "</span>";
141
					} else {
142
						$spans = $spane = "";
143
					}
144
					
145
		if ($server['bind_iface'] == 'all')
146
			$ipaddr = "0.0.0.0";
147
		else
148
			$ipaddr = ovpn_get_ip($server['bind_iface']);
149
	?>
150
	
151
	<tr>
152
	  <td class="listlr"><?=$spans;?>
153
		<?php	if ($interface = ovpn_get_opt_interface($server['tun_iface']))
154
				$iface = $config['interfaces'][$interface]['descr'];
155
			else $iface = strtoupper($server['tun_iface']);?>
156
		<?= $iface;?>
157
	  <?=$spane;?></td>
158
	  <td class="listr"><?=$spans;?>
159
		<?= strtoupper($server['proto']);?>	
160
	  <?=$spane;?></td>
161
	  <td class="listr"><?=$spans;?>
162
		<?= $ipaddr.":".$server['port'];?>
163
	  <?=$spane;?></td>
164
	  <td nowrap class="listr"><?=$spans;?>
165
		<?php	if ($server['authentication_method'] == "pre_shared_key") {
166
				if ($server['type'] == "tun") {
167
					$ipblock = $server['lipaddr'] . " / " . $server['ripaddr'];
168
				} else {
169
					$ipblock = $server['lipaddr'] . "/" . $server['netmask'];
170
				}
171
			} else if (!$server['bridge'])
172
				$ipblock = $server['ipblock'] . "/" . $server['prefix'];
173
			else if ($server['range_from'])
174
				$ipblock = $server['range_from'] . " - " . $server['range_to'];
175
			else
176
				$ipblock = "--";?>
177
		<?= $ipblock;?>	
178
	  <?=$spane;?></td>
179
	  <td class="listr"><?=$spans;?>
180
		<?= $server['crypto'];?>	
181
	  <?=$spane;?></td>
182
	   <td class="listbg"><?=$spans;?>
183
	  	<?= htmlspecialchars($server['descr']);?>&nbsp;
184
	  <?=$spane;?></td>
185
	  <td valign="middle" nowrap class="list"> <a href="vpn_openvpn_srv_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit server configuration" width="17" height="17" border="0"></a>
186
		 &nbsp;<a href="vpn_openvpn_srv.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this server configuration?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete server configuration" width="17" height="17" border="0"></a></td>
187
	</tr>
188
  	<?php $i++; endforeach; ?>
189
	<tr> 
190
	  <td class="list" colspan="6">&nbsp;</td>
191
	  <td class="list"> <a href="vpn_openvpn_srv_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add server configuration" width="17" height="17" border="0"></a></td>
192
	</tr>
193
    </table>
194
  </td>
195
</tr>
196
</table>
197
</form>
198
<?php include("fend.inc"); ?>
(165-165/174)