Commit 78148368 authored by Ad Schellevis's avatar Ad Schellevis

(legacy) vpn_openvpn_client.php add duplicate option + some style fixes and...

(legacy) vpn_openvpn_client.php add duplicate option + some style fixes and cleanups. closes https://github.com/opnsense/core/issues/676
parent 2d531c30
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2008 Shrew Soft Inc.
All rights reserved.
......@@ -44,9 +44,13 @@ $a_client = &$config['openvpn']['openvpn-client'];
$vpnid = 0;
$act = null;
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['id']) && is_numericint($_GET['id'])) {
if (isset($_GET['dup']) && isset($a_client[$_GET['dup']])) {
$configId = $_GET['dup'];
} elseif (isset($_GET['id']) && isset($a_client[$_GET['id']])) {
$id = $_GET['id'];
$configId = $id;
}
if (isset($_GET['act'])) {
$act = $_GET['act'];
}
......@@ -60,7 +64,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig['verbosity_level'] = 1; // Default verbosity is 1
// edit existing.
if ($act=="edit" && isset($id) && $a_client[$id]) {
if (isset($configId)) {
// 1 on 1 copy of config attributes
$copy_fields = "auth_user,auth_pass,disable,mode,protocol,interface
,local_port,server_addr,server_port,resolve_retry
......@@ -71,8 +75,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
foreach (explode(",", $copy_fields) as $fieldname) {
$fieldname = trim($fieldname);
if (isset($a_client[$id][$fieldname])) {
$pconfig[$fieldname] = $a_client[$id][$fieldname];
if (isset($a_client[$configId][$fieldname])) {
$pconfig[$fieldname] = $a_client[$configId][$fieldname];
} elseif (!isset($pconfig[$fieldname])) {
// initialize element
$pconfig[$fieldname] = null;
......@@ -80,24 +84,24 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
// load / convert
if (!empty($a_client[$id]['ipaddr'])) {
$pconfig['interface'] = $pconfig['interface'] . '|' . $a_client[$id]['ipaddr'];
if (!empty($a_client[$configId]['ipaddr'])) {
$pconfig['interface'] = $pconfig['interface'] . '|' . $a_client[$configId]['ipaddr'];
}
if (isset($a_client[$id]['tls'])) {
$pconfig['tls'] = base64_decode($a_client[$id]['tls']);
if (isset($a_client[$configId]['tls'])) {
$pconfig['tls'] = base64_decode($a_client[$configId]['tls']);
} else {
$pconfig['tls'] = null;
$pconfig['tlsauth_enable'] = null;
}
if (isset($a_client[$id]['shared_key'])) {
$pconfig['shared_key'] = base64_decode($a_client[$id]['shared_key']);
if (isset($a_client[$configId]['shared_key'])) {
$pconfig['shared_key'] = base64_decode($a_client[$configId]['shared_key']);
} else {
$pconfig['shared_key'] = null ;
}
if (isset($id) && $a_client[$id]) {
if (isset($id)) {
$vpnid = $a_client[$id]['vpnid'];
}
} elseif ($act=="new") {
......@@ -119,7 +123,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
}
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
if (isset($_POST['id']) && isset($a_client[$_POST['id']])) {
$id = $_POST['id'];
}
if (isset($_POST['act'])) {
......@@ -128,7 +132,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if ($act == "del") {
// remove client
if (!isset($id) || !isset($a_client[$id])) {
if (!isset($id)) {
header("Location: vpn_openvpn_client.php");
exit;
}
......@@ -142,7 +146,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = $_POST;
$input_errors = array();
if (isset($id) && $a_client[$id]) {
if (isset($id)) {
$vpnid = $a_client[$id]['vpnid'];
}
if (isset($pconfig['mode']) && $pconfig['mode'] != "p2p_shared_key") {
......@@ -297,7 +301,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$client['shared_key'] = base64_encode($pconfig['shared_key']);
}
if (isset($id) && isset($a_client[$id])) {
if (isset($id)) {
$a_client[$id] = $client;
} else {
$a_client[] = $client;
......@@ -446,21 +450,17 @@ endif; ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php
if (isset($input_errors) && count($input_errors) > 0) {
if (isset($input_errors) && count($input_errors) > 0) {
print_input_errors($input_errors);
}
if (isset($savemsg)) {
}
if (isset($savemsg)) {
print_info_box($savemsg);
}
?>
}?>
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<?php if ($act=="new" || $act=="edit") :
?>
<?php
if ($act=="new" || $act=="edit") :?>
<form action="vpn_openvpn_client.php" method="post" name="iform" id="iform">
<div class="table-responsive">
<table class="table table-striped">
......@@ -488,17 +488,14 @@ if (isset($savemsg)) {
$openvpn_client_modes = array(
'p2p_tls' => gettext("Peer to Peer ( SSL/TLS )"),
'p2p_shared_key' => gettext("Peer to Peer ( Shared Key )") );
foreach ($openvpn_client_modes as $name => $desc) :
foreach ($openvpn_client_modes as $name => $desc) :
$selected = "";
if ($pconfig['mode'] == $name) {
$selected = "selected=\"selected\"";
}
?>
<option value="<?=$name;
?>" <?=$selected;
?>><?=$desc;?></option>
}?>
<option value="<?=$name;?>" <?=$selected;?>><?=$desc;?></option>
<?php
endforeach; ?>
endforeach; ?>
</select>
</td>
</tr>
......@@ -507,17 +504,14 @@ endforeach; ?>
<td>
<select name='protocol' class="form-control">
<?php
foreach (array("UDP", "UDP6", "TCP", "TCP6") as $prot) :
foreach (array("UDP", "UDP6", "TCP", "TCP6") as $prot) :
$selected = "";
if ($pconfig['protocol'] == $prot) {
$selected = "selected=\"selected\"";
}
?>
<option value="<?=$prot;
?>" <?=$selected;
?>><?=$prot;?></option>
}?>
<option value="<?=$prot;?>" <?=$selected;?>><?=$prot;?></option>
<?php
endforeach; ?>
endforeach; ?>
</select>
</td>
</tr>
......@@ -525,16 +519,13 @@ endforeach; ?>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Device mode");?></td>
<td>
<select name='dev_mode' class="form-control" onchange="dev_mode_change()">
<?php
<?php
foreach (array("tun", "tap") as $mode) :
$selected = "";
if ($pconfig['dev_mode'] == $mode) {
$selected = "selected=\"selected\"";
}
?>
<option value="<?=$mode;
?>" <?=$selected;
?>><?=$mode;?></option>
}?>
<option value="<?=$mode;?>" <?=$selected;?>><?=$mode;?></option>
<?php
endforeach; ?>
</select>
......@@ -547,15 +538,15 @@ endforeach; ?>
<?php
$interfaces = get_configured_interface_with_descr();
$carplist = get_configured_carp_interface_list();
foreach ($carplist as $cif => $carpip) {
foreach ($carplist as $cif => $carpip) {
$interfaces[$cif.'|'.$carpip] = $carpip." (".get_vip_descr($carpip).")";
}
}
$aliaslist = get_configured_ip_aliases_list();
foreach ($aliaslist as $aliasip => $aliasif) {
foreach ($aliaslist as $aliasip => $aliasif) {
$interfaces[$aliasif.'|'.$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
}
}
$grouplist = return_gateway_groups_array();
foreach ($grouplist as $name => $group) {
foreach ($grouplist as $name => $group) {
if ($group['ipprotocol'] != inet) {
continue;
}
......@@ -565,20 +556,17 @@ foreach ($grouplist as $name => $group) {
$vipif = $group[0]['int'];
}
$interfaces[$name] = "GW Group {$name}";
}
}
$interfaces['lo0'] = "Localhost";
$interfaces['any'] = "any";
foreach ($interfaces as $iface => $ifacename) :
foreach ($interfaces as $iface => $ifacename) :
$selected = "";
if ($iface == $pconfig['interface']) {
$selected = "selected=\"selected\"";
}
?>
<option value="<?=$iface;
?>" <?=$selected;
?>><?=htmlspecialchars($ifacename);?></option>
}?>
<option value="<?=$iface;?>" <?=$selected;?>><?=htmlspecialchars($ifacename);?></option>
<?php
endforeach; ?>
endforeach; ?>
</select> <br />
</td>
</tr>
......@@ -625,7 +613,7 @@ endforeach; ?>
<option value="basic" <?=$pconfig['proxy_authtype'] == "ntlm" ? "selected=\"selected\"" : "" ?> > <?=gettext("ntlm"); ?></option>
</select>
<div style="display:none" id="proxy_authtype_opts">
<div><?=gettext("Username"); ?> <br/></div
<div><?=gettext("Username"); ?> <br/></div>
<div><input name="proxy_user" id="proxy_user" class="form-control unknown" type="text" size="20" value="<?=$pconfig['proxy_user'];?>" /></div>
<div><?=gettext("Password"); ?> </div>
<div><input name="proxy_passwd" id="proxy_passwd" type="password" class="form-control pwd" size="20" value="<?=$pconfig['proxy_passwd'];?>" /></div>
......@@ -678,15 +666,14 @@ endforeach; ?>
<td>
<input name="tlsauth_enable" id="tlsauth_enable" type="checkbox" value="yes" <?= !empty($pconfig['tlsauth_enable']) ? "checked=\"checked\"" : "";?> onclick="tlsauth_change()" />
<?=gettext("Enable authentication of TLS packets"); ?>.
<?php if (empty($pconfig['tls'])) :
?>
<?php
if (empty($pconfig['tls'])) :?>
<div id="tlsauth_opts">
<input name="autotls_enable" id="autotls_enable" type="checkbox" value="yes"<?= !empty($pconfig['autotls_enable']) ? "checked=\"checked\"" : "";?> onclick="autotls_change()" />
<input name="autotls_enable" id="autotls_enable" type="checkbox" value="yes" <?= !empty($pconfig['autotls_enable']) ? "checked=\"checked\"" : "";?> onclick="autotls_change()" >
<?=gettext("Automatically generate a shared TLS authentication key"); ?>.
</div>
<?php
endif; ?>
<?php
endif; ?>
<div id="autotls_opts">
<textarea name="tls" cols="65" rows="7" class="formpre"><?=isset($pconfig['tls'])?$pconfig['tls']:"";?></textarea>
<p class="text-muted"><em><small><?=gettext("Paste your shared key here"); ?>.</small></em></p>
......@@ -696,37 +683,32 @@ endif; ?>
<tr id="tls_ca">
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Peer Certificate Authority"); ?></td>
<td>
<?php if (isset($config['ca'])) :
?>
<?php
if (isset($config['ca'])) :?>
<select name='caref' class="form-control">
<?php
foreach ($config['ca'] as $ca) :
foreach ($config['ca'] as $ca) :
$selected = "";
if (isset($pconfig['caref']) && $pconfig['caref'] == $ca['refid']) {
$selected = "selected=\"selected\"";
}
?>
<option value="<?=$ca['refid'];
?>" <?=$selected;
?>><?=$ca['descr'];?></option>
}?>
<option value="<?=$ca['refid'];?>" <?=$selected;?>><?=$ca['descr'];?></option>
<?php
endforeach; ?>
endforeach; ?>
</select>
<?php
else :
?>
<b><?=gettext("No Certificate Authorities defined.");
?></b> <br /><?=gettext("Create one under");
?> <a href="system_camanager.php"><?=gettext("System: Certificates");?></a>.
<?php
endif; ?>
<?php
else :?>
<b><?=gettext("No Certificate Authorities defined.");?></b> <br />
<?=gettext("Create one under");?> <a href="system_camanager.php"><?=gettext("System: Certificates");?></a>.
<?php
endif; ?>
</td>
</tr>
<tr id="tls_cert">
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Client Certificate"); ?></td>
<td>
<select name='certref' class="form-control">
<?php
<?php
foreach (isset($config['cert']) ? $config['cert'] : array() as $cert) :
$selected = "";
$caname = "";
......@@ -746,37 +728,31 @@ endif; ?>
}
if (is_cert_revoked($cert)) {
$revoked = " *Revoked";
}
?>
<option value="<?=$cert['refid'];
?>" <?=$selected;
?>><?=$cert['descr'] . $caname . $inuse . $revoked;?></option>
<?php
}?>
<option value="<?=$cert['refid'];?>" <?=$selected;?>><?=$cert['descr'] . $caname . $inuse . $revoked;?></option>
<?php
endforeach; ?>
<option value="" <?=empty($pconfig['certref'])? "selected=\"selected\"" : "";
?>> <?=gettext("None");
?> <?=gettext("(Username and Password required)");?></option>
<option value="" <?=empty($pconfig['certref'])? "selected=\"selected\"" : "";?>>
<?=gettext("None");?> <?=gettext("(Username and Password required)");?>
</option>
</select>
<?php if (!isset($config['cert']) || count($config['cert']) == 0) :
?>
<b><?=gettext("No Certificates defined.");
?></b> <br /><?=gettext("Create one under");
?> <a href="system_certmanager.php"><?=gettext("System: Certificates");
?></a> <?=gettext("if one is required for this connection.");?>
<?php
endif; ?>
if (!isset($config['cert']) || count($config['cert']) == 0) :?>
<b><?=gettext("No Certificates defined.");?></b> <br /><?=gettext("Create one under");?>
<a href="system_certmanager.php"><?=gettext("System: Certificates");?></a> <?=gettext("if one is required for this connection.");?>
<?php
endif; ?>
</td>
</tr>
<tr id="psk">
<td><?=gettext("Shared Key"); ?></td>
<td>
<?php if (empty($pconfig['shared_key'])) :
?>
<?php
if (empty($pconfig['shared_key'])) :?>
<input name="autokey_enable" id="autokey_enable" type="checkbox" value="yes" <?= !empty($pconfig['autokey_enable']) ? "checked=\"checked\"" : "";?> onclick="autokey_change()" />
<?=gettext("Automatically generate a shared key"); ?>.
<?php
endif; ?>
<?php
endif; ?>
<div id="autokey_opts">
<textarea name="shared_key" cols="65" rows="7" class="formpre"><?=isset($pconfig['shared_key']) ? $pconfig['shared_key'] : "";?></textarea>
<em><small><?=gettext("Paste your shared key here"); ?>.</small></em>
......@@ -787,17 +763,15 @@ endif; ?>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Encryption algorithm"); ?></td>
<td>
<select name="crypto" class="form-control">
<?php
<?php
$cipherlist = openvpn_get_cipherlist();
foreach ($cipherlist as $name => $desc) :
$selected = "";
if ($name == $pconfig['crypto']) {
$selected = " selected=\"selected\"";
}
?>
<option value="<?=$name;
?>"<?=$selected?>><?=htmlspecialchars($desc);?></option>
<?php
}?>
<option value="<?=$name;?>"<?=$selected?>><?=htmlspecialchars($desc);?></option>
<?php
endforeach; ?>
</select>
</td>
......@@ -806,17 +780,15 @@ endif; ?>
<td><a id="help_for_digest" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Auth Digest Algorithm"); ?></td>
<td>
<select name="digest" class="form-control">
<?php
<?php
$digestlist = openvpn_get_digestlist();
foreach ($digestlist as $name => $desc) :
$selected = "";
if ($name == $pconfig['digest']) {
$selected = " selected=\"selected\"";
}
?>
<option value="<?=$name;
?>"<?=$selected?>><?=htmlspecialchars($desc);?></option>
<?php
}?>
<option value="<?=$name;?>"<?=$selected?>><?=htmlspecialchars($desc);?></option>
<?php
endforeach; ?>
</select>
<div class="hidden" for="help_for_digest">
......@@ -828,17 +800,15 @@ endif; ?>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Hardware Crypto"); ?></td>
<td>
<select name="engine" class="form-control">
<?php
<?php
$engines = openvpn_get_engines();
foreach ($engines as $name => $desc) :
$selected = "";
if ($name == $pconfig['engine']) {
$selected = " selected=\"selected\"";
}
?>
<option value="<?=$name;
?>"<?=$selected?>><?=htmlspecialchars($desc);?></option>
<?php
}?>
<option value="<?=$name;?>"<?=$selected?>><?=htmlspecialchars($desc);?></option>
<?php
endforeach; ?>
</select>
</td>
......@@ -1016,9 +986,7 @@ endif; ?>
</div>
</td>
</tr>
</table>
<br />
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="icons">
<tr>
......@@ -1026,42 +994,37 @@ endif; ?>
<td width="78%">
<input name="save" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
<input name="act" type="hidden" value="<?=$act;?>" />
<?php if (isset($id) && $a_client[$id]) :
?>
<?php
if (isset($id) && $a_client[$id]) :?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
<?php
endif; ?>
<?php
endif; ?>
</td>
</tr>
</table>
</div>
</form>
<?php
else :
?>
<?php
else:?>
<table class="table table-striped">
<thead>
<tr>
<td width="10%" class="listhdrr"><?=gettext("Disabled"); ?></td>
<td width="10%" class="listhdrr"><?=gettext("Protocol"); ?></td>
<td width="30%" class="listhdrr"><?=gettext("Server"); ?></td>
<td width="40%" class="listhdrr"><?=gettext("Description"); ?></td>
<td width="10%" class="list"></td>
<td><?=gettext("Disabled"); ?></td>
<td><?=gettext("Protocol"); ?></td>
<td><?=gettext("Server"); ?></td>
<td><?=gettext("Description"); ?></td>
<td></td>
</tr>
</thead>
<tbody>
<?php
<?php
$i = 0;
foreach ($a_client as $client) :
$disabled = "NO";
if (isset($client['disable'])) {
$disabled = "YES";
}
$server = "{$client['server_addr']}:{$client['server_port']}";
?>
$server = "{$client['server_addr']}:{$client['server_port']}";?>
<tr ondblclick="document.location='vpn_openvpn_client.php?act=edit&amp;id=<?=$i;?>'">
<td>
<?=$disabled;?>
......@@ -1076,24 +1039,28 @@ else :
<?=htmlspecialchars($client['description']);?>
</td>
<td>
<a href="vpn_openvpn_client.php?act=edit&amp;id=<?=$i;?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
<a id="del_<?=$i;
?>" title="<?=gettext("delete client"); ?>" class="act_delete btn btn-default btn-xs"><span class="fa fa-trash text-muted"></span></a>
<a href="vpn_openvpn_client.php?act=edit&amp;id=<?=$i;?>" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-pencil"></span>
</a>
<a id="del_<?=$i;?>" title="<?=gettext("delete client"); ?>" class="act_delete btn btn-default btn-xs">
<span class="fa fa-trash text-muted"></span>
</a>
<a href="vpn_openvpn_client.php?act=new&dup=<?=$i;?>" class="btn btn-default btn-xs" data-toggle="tooltip" title="<?=gettext("clone rule");?>">
<span class="fa fa-clone text-muted"></span>
</a>
</td>
</tr>
<?php
<?php
$i++;
endforeach;
?>
endforeach;?>
</tbody>
</table>
<?php
endif; ?>
<?php
endif; ?>
</div>
</section>
</div>
</div>
</section>
</section>
<?php include("foot.inc"); ?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment