Add advanced configuration (raw openvpn conf edition)

This commit is contained in:
Julien VAUBOURG
2014-11-20 20:02:43 +01:00
parent a7eac12c27
commit 3aae0029cb
10 changed files with 70 additions and 27 deletions

View File

@@ -45,6 +45,7 @@ function ipv6_compressed($ip) {
dispatch('/', function() {
$ip6_net = moulinette_get('ip6_net');
$ip6_net = ($ip6_net == 'none') ? '' : $ip6_net;
$raw_openvpn = file_get_contents('/etc/openvpn/client.conf.tpl');
set('server_name', moulinette_get('server_name'));
set('server_port', moulinette_get('server_port'));
@@ -56,6 +57,7 @@ dispatch('/', function() {
set('crt_client_key_exists', file_exists('/etc/openvpn/keys/user.key'));
set('crt_server_ca_exists', file_exists('/etc/openvpn/keys/ca-server.crt'));
set('faststatus', service_faststatus() == 0);
set('raw_openvpn', $raw_openvpn);
return render('settings.html.php');
});
@@ -114,7 +116,7 @@ dispatch_put('/settings', function() {
}
} catch(Exception $e) {
flash('error', $e->getMessage().T_(' (configuration not updated).'));
flash('error', $e->getMessage().' ('.T_('configuration not updated').').');
goto redirect;
}
@@ -128,6 +130,8 @@ dispatch_put('/settings', function() {
moulinette_set('ip6_net', $ip6_net);
moulinette_set('ip6_addr', $ip6_addr);
file_put_contents('/etc/openvpn/client.conf.tpl', $_POST['raw_openvpn']);
if($_FILES['crt_client']['error'] == UPLOAD_ERR_OK) {
move_uploaded_file($_FILES['crt_client']['tmp_name'], '/etc/openvpn/keys/user.crt');
} elseif($_POST['crt_client_delete'] == 1) {
@@ -168,16 +172,16 @@ dispatch('/status', function() {
foreach($status_lines AS $status_line) {
if(preg_match('/^\[INFO\]/', $status_line)) {
$status_list .= "<li class='status-info'>${status_line}</li>";
$status_list .= '<li class="status-info">'.htmlspecialchars($status_line).'</li>';
}
elseif(preg_match('/^\[OK\]/', $status_line)) {
$status_list .= "<li class='status-success'>${status_line}</li>";
$status_list .= '<li class="status-success">'.htmlspecialchars($status_line).'</li>';
}
elseif(preg_match('/^\[WARN\]/', $status_line)) {
$status_list .= "<li class='status-warning'>${status_line}</li>";
$status_list .= '<li class="status-warning">'.htmlspecialchars($status_line).'</li>';
}
elseif(preg_match('/^\[ERR\]/', $status_line)) {
$status_list .= "<li class='status-danger'>${status_line}</li>";
$status_list .= '<li class="status-danger">'.htmlspecialchars($status_line).'</li>';
}
}

View File

@@ -6,7 +6,7 @@ li.status-warning {
color: #D9534F;
}
li.status-danger {
li.status-danger, div#raw_openvpn_panel {
color: #D9534F;
}
@@ -69,3 +69,12 @@ div#github {
div#github a {
margin-left: 17px;
}
div#raw_openvpn_panel {
display: none;
}
textarea#raw_openvpn {
height: 300px;
border: 1px solid #D9534F;
}

View File

@@ -50,14 +50,22 @@ $(document).ready(function() {
});
$('#statusbtn').click(function() {
$('#status-loading').show();
if($('#status-loading').is(':hidden')) {
$('#status').hide();
$('#status-loading').show();
$.ajax({
url: '?/status',
}).done(function(data) {
$('#status-loading').hide();
$('#status-text').html('<ul>' + data + '</ul>');
$('#status').show('slow');
});
$.ajax({
url: '?/status',
}).done(function(data) {
$('#status-loading').hide();
$('#status-text').html('<ul>' + data + '</ul>');
$('#status').show('slow');
});
}
});
$('#raw_openvpn_btn').click(function() {
$('#raw_openvpn_btnpanel').hide();
$('#raw_openvpn_panel').show('low');
});
});

View File

@@ -51,6 +51,20 @@
</label>
</div>
</div>
<div class="form-group" id="raw_openvpn_btnpanel">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-9">
<span class="glyphicon glyphicon-cog"></span> <a href="#" id="raw_openvpn_btn" data-toggle="tooltip" data-title="<?= T_('Edit the raw configuration only if you know what you do!') ?>"><?= T_('Advanced') ?></a>
</div>
</div>
<div class="form-group" id="raw_openvpn_panel">
<label for="raw_openvpn" class="col-sm-3 control-label"><?= T_('Advanced') ?></label>
<div class="col-sm-9">
<pre><textarea class="form-control" name="raw_openvpn" id="raw_openvpn"><?= $raw_openvpn ?></textarea></pre>
</div>
</div>
</div>
</div>