mirror of https://github.com/Aidaho12/haproxy-wi
parent
05e3009d86
commit
81e2505422
|
@ -2145,3 +2145,62 @@ if form.getvalue('lets_domain'):
|
|||
print('success: Certificate has been created')
|
||||
|
||||
os.system("rm -f %s" % script)
|
||||
|
||||
if form.getvalue('uploadovpn'):
|
||||
name = form.getvalue('ovpnname')
|
||||
|
||||
ovpn_file = os.path.dirname('/tmp/') + "/" + name + '.ovpn'
|
||||
|
||||
try:
|
||||
with open(ovpn_file, "w") as conf:
|
||||
conf.write(form.getvalue('uploadovpn'))
|
||||
except IOError as e:
|
||||
print(str(e))
|
||||
print('error: Can\'t save ovpn file')
|
||||
else:
|
||||
print('success: ovpn file has been saved </div>')
|
||||
|
||||
try:
|
||||
cmd = 'sudo openvpn3 config-import --config %s --persistent' % ovpn_file
|
||||
funct.subprocess_execute(cmd)
|
||||
except IOError as e:
|
||||
funct.logging('localhost', e.args[0], haproxywi=1)
|
||||
|
||||
try:
|
||||
cmd = 'sudo cp %s /etc/openvpn3/%s.conf' % (ovpn_file, name)
|
||||
funct.subprocess_execute(cmd)
|
||||
except IOError as e:
|
||||
funct.logging('localhost', e.args[0], haproxywi=1)
|
||||
|
||||
funct.logging("localhost", " has been uploaded a new ovpn file %s" % ovpn_file, haproxywi=1, login=1)
|
||||
|
||||
if form.getvalue('openvpndel') is not None:
|
||||
openvpndel = form.getvalue('openvpndel')
|
||||
|
||||
cmd = 'sudo openvpn3 config-remove --config /tmp/%s.ovpn --force' % openvpndel
|
||||
try:
|
||||
funct.subprocess_execute(cmd)
|
||||
print("Ok")
|
||||
funct.logging(openvpndel, ' has deleted the ovpn file ', haproxywi=1, login=1)
|
||||
except IOError as e:
|
||||
print(e.args[0])
|
||||
funct.logging('localhost', e.args[0], haproxywi=1)
|
||||
|
||||
if form.getvalue('actionvpn') is not None:
|
||||
openvpn = form.getvalue('openvpnprofile')
|
||||
action = form.getvalue('actionvpn')
|
||||
|
||||
if action == 'start':
|
||||
cmd = 'sudo openvpn3 session-start --config /tmp/%s.ovpn' % openvpn
|
||||
elif action == 'restart':
|
||||
cmd = 'sudo openvpn3 session-manage --config /tmp/%s.ovpn --restart' % openvpn
|
||||
elif action == 'disconnect':
|
||||
cmd = 'sudo openvpn3 session-manage --config /tmp/%s.ovpn --disconnect' % openvpn
|
||||
try:
|
||||
funct.subprocess_execute(cmd)
|
||||
print("success: The " + openvpn + " has been " + action + "ed")
|
||||
funct.logging(openvpn, ' has ' + action + ' the ovpn session ', haproxywi=1, login=1)
|
||||
except IOError as e:
|
||||
print(e.args[0])
|
||||
funct.logging('localhost', e.args[0], haproxywi=1)
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<li><a href="#servers" title="Admin area: Manage servers - HAProxy-WI">Servers</a></li>
|
||||
<li><a href="#ssh" title="Admin area: Manage SSH credentials - HAProxy-WI">SSH credentials</a></li>
|
||||
<li><a href="#checker" title="Admin area: Manage checker - HAProxy-WI">Checker</a></li>
|
||||
<li><a href="#openvpn" title="Admin area: OpenVPN - HAProxy-WI">OpenVPN</a></li>
|
||||
<li><a href="#settings" title="Admin area: Manage HAProxy-WI settings - HAProxy-WI">Settings</a></li>
|
||||
<li><a href="#services" title="Admin area: Manage HAProxy-WI services - HAProxy-WI">Services</a></li>
|
||||
<li><a href="#updatehapwi" title="Admin area: Update HAProxy-WI - HAProxy-WI">Update</a></li>
|
||||
|
@ -83,6 +84,98 @@
|
|||
{% include 'include/admin_telegram.html' %}
|
||||
</div>
|
||||
|
||||
<div id="openvpn">
|
||||
{% if openvpn != 'package openvpn3-client is not installed' %}
|
||||
<table id="openvpn_table" class="overview">
|
||||
<caption><h3>OpenVPN profiles</h3></caption>
|
||||
<tr class="overviewHead">
|
||||
<td class="padding10 first-collumn" style="width: 25%;">
|
||||
Profile name
|
||||
</td>
|
||||
<td class="padding10 first-collumn" style="width: 35%;">
|
||||
Time of creation
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% for c in openvpn_configs %}
|
||||
<tr class="{{ loop.cycle('odd', 'even') }}" id="{{c.split('/')[-1].split('.')[0]}}">
|
||||
<td class="padding10 first-collumn">
|
||||
{{c.split('/')[-1]}}
|
||||
</td>
|
||||
<td style="width: 100%">
|
||||
{{c.split('/')[0]}}
|
||||
</td>
|
||||
<td>
|
||||
<a class="service-start" onclick="OpenVpnSess('{{c.split('/')[-1].split('.')[0]}}', 'start')" title="Start OpenVPN with profile {{c.split('/')[-1]}}"></a>
|
||||
</td>
|
||||
<td>
|
||||
<a class="delete" onclick="confirmDeleteOpenVpnProfile('{{c.split('/')[-1].split('.')[0]}}')" title="Delete OpenVPN profile {{c.split('/')[-1]}}" style="cursor: pointer;"></a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<br />
|
||||
<table id="openvpn_table" class="overview">
|
||||
<caption><h3>OpenVPN sessions</h3></caption>
|
||||
<tr class="overviewHead">
|
||||
<td class="padding10 first-collumn" style="width: 25%;">
|
||||
Session name
|
||||
</td>
|
||||
<td class="padding10 first-collumn" style="width: 35%;">
|
||||
Status
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% for c in openvpn_sess %}
|
||||
<tr class="{{ loop.cycle('odd', 'even') }}">
|
||||
<td class="padding10 first-collumn">
|
||||
{{c.split(' ')[0]}}
|
||||
</td>
|
||||
<td style="width: 100%">
|
||||
{{c.split(' ')[4]}}
|
||||
</td>
|
||||
<td>
|
||||
<a class="service-reload" onclick="OpenVpnSess('{{c.split(' ')[0]}}', 'restart')" title="Restart OpenVPN with profile {{c.split('/')[0]}}"></a>
|
||||
</td>
|
||||
<td>
|
||||
<a class="delete" onclick="OpenVpnSess('{{c.split(' ')[0]}}', 'disconnect')" title="Disconnect OpenVPN profile {{c.split('/')[2]}}" style="cursor: pointer;"></a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<br />
|
||||
<table id="openvpn_upload_table" class="overview">
|
||||
<caption><h3>Uploading ovpn files</h3></caption>
|
||||
<tr class="overviewHead" style="width: 50%;">
|
||||
<td class="padding10 first-collumn" style="width: 25%;">Ovpn file name</td>
|
||||
<td>
|
||||
<span title="Ovpn file must be with an auto-login profile">Upload ovpn file (?)</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr style="width: 50%;">
|
||||
<td class="first-collumn" valign="top" style="padding-top: 15px;">
|
||||
{{ input('ovpn_upload_name', size='30') }}
|
||||
</td>
|
||||
<td style="padding-top: 15px;">
|
||||
<textarea id="ovpn_upload_file" cols="50" rows="5"></textarea><br /><br />
|
||||
<a class="ui-button ui-widget ui-corner-all" id="ovpn_upload" title="Upload ovpn file" onclick="uploadOvpn()">Upload</a>
|
||||
<br /><br />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
{% else %}
|
||||
<center>
|
||||
<br />
|
||||
<h3>You do not have installed OpenVPN client.
|
||||
Read <a href="https://haproxy-wi.org/services.py?service=openvpn" title="OpenVPN" style="color: #5d9ceb;" target="_blank">hear</a>
|
||||
how to install OpenVPN client</h3>
|
||||
</center>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div id="settings">
|
||||
{% include 'include/admin_settings.html' %}
|
||||
</div>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<table>
|
||||
{% if page == 'users.py' %}
|
||||
<caption><h3>Install Grafana and Prometheus servers</h3></caption>
|
||||
<caption><h3>Installing Grafana and Prometheus servers</h3></caption>
|
||||
<tr class="overviewHead">
|
||||
<td class="padding10 first-collumn">Current instalation</td>
|
||||
<td class="padding10 first-collumn">Current installation</td>
|
||||
<td class="padding10 first-collumn" style="width: 30%;">Available Versions</td>
|
||||
<td class="padding10 first-collumn" style="width: 30%;">Note</td>
|
||||
<td></td>
|
||||
|
|
15
app/users.py
15
app/users.py
|
@ -11,12 +11,14 @@ print('Content-type: text/html\n')
|
|||
|
||||
funct.check_login()
|
||||
funct.page_for_admin()
|
||||
|
||||
try:
|
||||
user, user_id, role, token, servers = funct.get_users_params()
|
||||
users = sql.select_users()
|
||||
settings = sql.get_setting('', all=1)
|
||||
ldap_enable = sql.get_setting('ldap_enable')
|
||||
grafana, stderr = funct.subprocess_execute("service grafana-server status |grep Active |awk '{print $1}'")
|
||||
|
||||
services = []
|
||||
services_name = {'checker_haproxy': 'Master backends checker service',
|
||||
'keep_alive': 'Auto start service',
|
||||
|
@ -35,6 +37,16 @@ try:
|
|||
cmd = "rpm --query haproxy-wi-"+service_name+"-* |awk -F\""+service_name + "\" '{print $2}' |awk -F\".noa\" '{print $1}' |sed 's/-//1' |sed 's/-/./'"
|
||||
service_ver, stderr = funct.subprocess_execute(cmd)
|
||||
services.append([s, status, v, service_ver[0]])
|
||||
|
||||
openvpn, stderr = funct.subprocess_execute("rpm --query openvpn3-client")
|
||||
if openvpn[0] != 'package openvpn3-client is not installed':
|
||||
cmd = "sudo openvpn3 configs-list |grep -E 'ovpn|(^|[^0-9])[0-9]{4}($|[^0-9])' |grep -v net|awk -F\" \" '{print $1}'|awk 'ORS=NR%2?\" \":\"\\n\"'"
|
||||
openvpn_configs, stderr = funct.subprocess_execute(cmd)
|
||||
cmd = "sudo openvpn3 sessions-list|grep -E 'Config|Status'|awk -F\":\" '{print $2}'|awk 'ORS=NR%2?\" \":\"\\n\"'| sed 's/^ //g'"
|
||||
openvpn_sess, stderr = funct.subprocess_execute(cmd)
|
||||
else:
|
||||
openvpn_configs = ''
|
||||
openvpn_sess = ''
|
||||
except:
|
||||
pass
|
||||
|
||||
|
@ -55,6 +67,9 @@ template = template.render(title = "Admin area: Manage users",
|
|||
smon_ver=funct.check_new_version(service='smon'),
|
||||
metrics_ver=funct.check_new_version(service='metrics'),
|
||||
keep_ver=funct.check_new_version(service='keep'),
|
||||
openvpn=openvpn[0],
|
||||
openvpn_configs=openvpn_configs,
|
||||
openvpn_sess=openvpn_sess,
|
||||
settings=settings,
|
||||
backups=sql.select_backups(),
|
||||
services=services,
|
||||
|
|
90
inc/users.js
90
inc/users.js
|
@ -1957,3 +1957,93 @@ function updateService(service) {
|
|||
}
|
||||
} );
|
||||
}
|
||||
function confirmDeleteOpenVpnProfile(id) {
|
||||
$( "#dialog-confirm" ).dialog({
|
||||
resizable: false,
|
||||
height: "auto",
|
||||
width: 400,
|
||||
modal: true,
|
||||
title: "Are you sure you want to delete profile " +id+ "?",
|
||||
buttons: {
|
||||
"Delete": function() {
|
||||
$( this ).dialog( "close" );
|
||||
removeOpenVpnProfile(id);
|
||||
},
|
||||
Cancel: function() {
|
||||
$( this ).dialog( "close" );
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function removeOpenVpnProfile(id) {
|
||||
console.log(id)
|
||||
$("#"+id).css("background-color", "#f2dede");
|
||||
$.ajax( {
|
||||
url: "options.py",
|
||||
data: {
|
||||
openvpndel: id,
|
||||
token: $('#token').val()
|
||||
},
|
||||
type: "POST",
|
||||
success: function( data ) {
|
||||
data = data.replace(/\s+/g,' ');
|
||||
if(data == "Ok ") {
|
||||
$("#"+id).remove();
|
||||
} else if (data.indexOf('error:') != '-1' || data.indexOf('unique') != '-1') {
|
||||
toastr.error(data);
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
function uploadOvpn() {
|
||||
toastr.clear();
|
||||
if ($( "#ovpn_upload_name" ).val() == '' || $('#ovpn_upload_file').val() == '') {
|
||||
toastr.error('All fields must be completed');
|
||||
} else {
|
||||
$.ajax( {
|
||||
url: "options.py",
|
||||
data: {
|
||||
uploadovpn: $('#ovpn_upload_file').val(),
|
||||
ovpnname: $('#ovpn_upload_name').val(),
|
||||
token: $('#token').val()
|
||||
},
|
||||
type: "POST",
|
||||
success: function( data ) {
|
||||
data = data.replace(/\s+/g,' ');
|
||||
if (data.indexOf('danger') != '-1' || data.indexOf('unique') != '-1' || data.indexOf('error:') != '-1') {
|
||||
toastr.error(data);
|
||||
} else if (data.indexOf('success') != '-1') {
|
||||
toastr.clear();
|
||||
toastr.success(data)
|
||||
location.reload()
|
||||
} else {
|
||||
toastr.error('Something wrong, check and try again');
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
function OpenVpnSess(id, action) {
|
||||
$.ajax({
|
||||
url: "options.py",
|
||||
data: {
|
||||
actionvpn: action,
|
||||
openvpnprofile: id,
|
||||
token: $('#token').val()
|
||||
},
|
||||
type: "POST",
|
||||
success: function (data) {
|
||||
data = data.replace(/\s+/g, ' ');
|
||||
if (data.indexOf('danger') != '-1' || data.indexOf('unique') != '-1' || data.indexOf('error:') != '-1') {
|
||||
toastr.error(data);
|
||||
} else if (data.indexOf('success') != '-1') {
|
||||
toastr.clear();
|
||||
toastr.success(data)
|
||||
location.reload()
|
||||
} else {
|
||||
toastr.error('Something wrong, check and try again');
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
Loading…
Reference in New Issue