{% extends 'layout2.html' %}
{% load i18n %}
{% load static %}
{% block css_include %}
{% endblock %}
{% block js_include %}
{% endblock %}
{% block content %}
VPN SSL Configuration
';
break;
case "DOWN":
icon = '
';
break;
case "ERROR":
icon = '
';
break;
case "CONNECTING":
icon = ' ';
break;
default:
icon = ' ';
}
return icon + "Service status : " + data ;
}
},
{
sTitle: '{% translate "Tunnels status" %}',
defaultContent: "",
name: "tunnels_status",
mData: "tunnels_status",
aTargets: [2],
bSearchable: false,
mRender: function(data, type, row) {
var cpt = 0;
var result = "";
$.each(data, function(key, value) {
if( cpt > 0 )
result += "";
result += "" + key + ": " + value ;
cpt++;
});
return result;
}
},
{
sTitle: '{% translate "Node" %}',
name: "node", aTargets: [3],
defaultContent: "",
mData: "node",
mRender: function(data, type, row) {
return data;
}
},
{
sTitle: '{% translate "Action" %}',
mData:"id",
aTargets: [4],
defaultContent: "",
mRender: function(data, type, row) {
result = '' +
' ';
if( $('#details_openvpn').is(":hidden") ) {
result += ' ';
} else {
result += ' ';
}
if( row.status === "UP" ) {
result += ' ';
result += ' ';
} else if( row.status === "DOWN" )
result += ' ';
return result;
}
}
];
var openvpn_table = $("#openvpn_list").dataTable({
bServerSide : true,
order : [[1, 'desc']],
iDisplayLength: 10,
bProcessing : true,
bSort : true,
sAjaxSource : '',
sServerMethod : 'POST',
aoColumnDefs: aoColumns,
language: language_datatable,
fnServerData : function(sSource, aoData, fnCallback){
var columns = [];
for (var i in aoColumns){
if( aoColumns[i].bSearchable !== false && aoColumns[i].mData !== null )
columns.push(aoColumns[i].mData);
}
aoData.push({
name: 'columns',
value: JSON.stringify(columns)
});
$.ajax({
type : "POST",
url : sSource,
data : aoData,
success: function(data, callback){
if (!data.status){
notify('error', "{% translate 'Error' %}", data.error);
} else {
fnCallback(data);
}
}
}) // /$.ajax
.fail( function( jqXHR, textStatus ) {
notify('error', "{% translate 'Error' %}", jqXHR.responseText);
}) // /$.fail
.done( function( data ) {
if (!data.status){
notify('error', "{% translate 'Error' %}", data.error);
} else {
fnCallback(data);
}
}); // /$.done
}, // /fnServerData
fnCreatedRow: function(nRow, aData, iDataIndex){
/* Events binding to start a openvpn config */
$(nRow).on('click', '.action', function(e) {
/* Request start of the selected openvpn process */
/* First, retrieve the action to do */
var action = ($(this).hasClass('start') ? "start" : ($(this).hasClass('stop') ? "stop" : ($(this).hasClass('reload') ? "reload" : "")));
$.ajax({
type : "GET",
url : "/services/openvpn/"+action+"/"+aData.id,
}) // /$.ajax
.fail( function( jqXHR, textStatus ) {
new PNotify({
title: 'Unknown error occurred',
text: ''+jqXHR.responseText
+'',
type: 'error',
styling: 'bootstrap3',
width: '500px',
buttons: {
closer: true,
sticker: false
}
});
}) // /$.fail
.done( function( msg ) {
if( msg.status ) {
new PNotify({
title: "Success",
text: ''+msg.message+'',
type: 'success',
styling: 'bootstrap3',
width: '500px',
buttons: {
closer: true,
sticker: false
}
});
} else {
new PNotify({
title: msg.error,
text: ''+msg.error_details+'',
type: 'error',
styling: 'bootstrap3',
width: '500px',
buttons: {
closer: true,
sticker: false
}
});
}
}); // /$.done
e.stopPropagation();
}); // /$(nRow).on('click', '.action'
/* Events binding to edit a openvpn config */
$(nRow).on('click', 'td', function(e) {
if (e.target.tagName !== "TD") return;
const url = "{% url 'services.openvpn.edit' %}" + aData.id
/* Open edition in a new tab with ctrl click */
if (e.ctrlKey || e.metaKey) {
window.open(url, '_blank');
} else {
window.location.href = url;
}
}); // /$(nRow).on('click', 'td'
/* Open edition in a new tab with middle click */
$(nRow).on('mousedown', 'td', function(e){
if (e.target.tagName === "TD" && e.button === 1) {
window.open("{% url 'services.openvpn.edit' %}" + aData.id, '_blank');
}
}); // /$(nRow).on('mousedown', 'td'
/* Events binding to print a openvpn conf */
$(nRow).on('click', '.show-status', function(e) {
$('#details_openvpn').html("");
var conf = aData['statusall'];
$('#details_openvpn').append("
"+conf+""); $('#details_openvpn').show(); e.stopPropagation(); }); $(nRow).on('click', '.hide-status', function(e){ $('#details_openvpn').hide(); e.stopPropagation(); }); }, // fnCreatedRow: function fnDrawCallback: function(settings){ datatableCanRedraw = true; }, // fnDrawCallback: function }); // var openvpn_table = $("#openvpn_list").dataTable /* Reload table data every 5 seconds if previous one answered */ setInterval(function(){ if(datatableCanRedraw == true) { datatableCanRedraw = false; openvpn_table.fnDraw(false); } }, 5000); {% endblock %}