1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
vpn_openvpn_cli.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']['client'])){
|
37
|
$config['ovpn']['client'] = array();
|
38
|
$config['ovpn']['client']['tunnel'] = array();
|
39
|
}
|
40
|
|
41
|
$ovpncli =& $config['ovpn']['client']['tunnel'];
|
42
|
|
43
|
if ($_POST['apply']) {
|
44
|
$retval = 0;
|
45
|
ovpn_lock();
|
46
|
$retval = ovpn_config_client();
|
47
|
ovpn_unlock();
|
48
|
if (file_exists($d_ovpnclidirty_path))
|
49
|
unlink($d_ovpnclidirty_path);
|
50
|
$savemsg = get_std_save_message($retval);
|
51
|
}
|
52
|
|
53
|
if ($_GET['act'] == "del") {
|
54
|
if ($ovpncli[$_GET['id']]) {
|
55
|
unset($ovpncli[$_GET['id']]);
|
56
|
write_config();
|
57
|
ovpn_client_kill($_GET['id']);
|
58
|
touch($d_ovpnclidirty_path);
|
59
|
header("Location: vpn_openvpn_cli.php");
|
60
|
exit;
|
61
|
}
|
62
|
}
|
63
|
|
64
|
$pgtitle = "VPN: OpenVPN: Client";
|
65
|
include("head.inc");
|
66
|
|
67
|
?>
|
68
|
|
69
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
70
|
<?php include("fbegin.inc"); ?>
|
71
|
<p class="pgtitle"><?=$pgtitle?></p>
|
72
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
73
|
<?php if (file_exists($d_sysrebootreqd_path) && !file_exists($d_ovpnclidirty_path)) print_info_box(get_std_save_message(0)); ?>
|
74
|
<form action="vpn_openvpn_cli.php" method="post" enctype="multipart/form-data" name="iform" id="iform">
|
75
|
<?php if (file_exists($d_ovpnclidirty_path)): ?><p>
|
76
|
<?php print_info_box_np("The OpenVPN client configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
|
77
|
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
|
78
|
<?php endif; ?>
|
79
|
|
80
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
81
|
<tr><td>
|
82
|
<ul id="tabnav">
|
83
|
<li class="tabinact1"><a href="vpn_openvpn.php">Server</a></li>
|
84
|
<li class="tabact">Client</li>
|
85
|
</ul>
|
86
|
</td></tr>
|
87
|
<tr>
|
88
|
<td class="tabcont">
|
89
|
<strong><span class="red">WARNING: This feature is experimental and modifies your optional interface configuration.
|
90
|
Backup your configuration before using OpenVPN, and restore it before upgrading.<br>
|
91
|
<br>
|
92
|
</span></strong>
|
93
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
94
|
<tr>
|
95
|
<td width="10%" class="listhdrr">Interface</td>
|
96
|
<td width="30%" class="listhdrr">Server address</td>
|
97
|
<td width="10%" class="listhdrr" align="middle">Version</td>
|
98
|
<td width="40%" class="listhdr">Description</td>
|
99
|
<td width="10%" class="list"></td>
|
100
|
</tr>
|
101
|
|
102
|
<?php $i = 0; foreach ($ovpncli as $client):
|
103
|
if (!isset($client['enable'])) {
|
104
|
$spans = "<span class=\"gray\">";
|
105
|
$spane = "</span>";
|
106
|
} else {
|
107
|
$spans = $spane = "";
|
108
|
}
|
109
|
?>
|
110
|
|
111
|
<tr>
|
112
|
<td class="listlr"><?=$spans;?>
|
113
|
<?= $client['if'].":".$client['cport'];?>
|
114
|
<?=$spane;?></td>
|
115
|
<td class="listr"><?=$spans;?>
|
116
|
<?= $client['saddr'].":".$client['sport'];?>
|
117
|
<?=$spane;?></td>
|
118
|
<td align="middle" class="listr"><?=$spans;?>
|
119
|
<?= $client['ver'];?>
|
120
|
<?=$spane;?></td>
|
121
|
<td class="listbg"><?=$spans;?>
|
122
|
<?= $client['descr'];?>
|
123
|
<?=$spane;?></td>
|
124
|
<td valign="middle" nowrap class="list"> <a href="vpn_openvpn_cli_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit client configuration" width="17" height="17" border="0"></a>
|
125
|
<a href="vpn_openvpn_cli.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this client configuration?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete client configuration" width="17" height="17" border="0"></a></td>
|
126
|
</tr>
|
127
|
<?php $i++; endforeach; ?>
|
128
|
<tr>
|
129
|
<td class="list" colspan="4"> </td>
|
130
|
<td class="list"> <a href="vpn_openvpn_cli_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add client configuration" width="17" height="17" border="0"></a></td>
|
131
|
</tr>
|
132
|
</table>
|
133
|
</td>
|
134
|
</tr>
|
135
|
</table>
|
136
|
</form>
|
137
|
<?php include("fend.inc"); ?>
|