Pavel Loginov 3 years ago
parent
commit
d1e931d8d1
  1. 2
      app/funct.py
  2. 42
      app/scripts/ansible/roles/grafana.yml
  3. 32
      app/sql.py
  4. 50
      app/templates/add.html
  5. 4
      app/templates/include/add_backup.html
  6. 6
      app/templates/include/mon_installation.html
  7. 2
      app/templates/include/select.html
  8. 12
      app/templates/nettools.html
  9. 10
      app/templates/runtimeapi.html
  10. 6
      app/templates/servers.html
  11. 2
      app/templates/viewstats.html
  12. 6
      app/templates/waf.html
  13. 4
      config_other/fail2ban/filter.d/roxy-wi.conf
  14. 9
      config_other/fail2ban/jail.d/haproxy-wi.conf
  15. 9
      config_other/fail2ban/jail.d/roxy-wi.conf
  16. 2
      inc/add.js

2
app/funct.py

@ -866,7 +866,7 @@ def open_port_firewalld(cfg, serv, **kwargs):
pass
firewalld_commands += 'sudo firewall-cmd --reload -q'
logging(serv, ' Next ports have been opened: ' + ports + ' has opened ')
logging(serv, ' Next ports have been opened: ' + ports)
return firewalld_commands

42
app/scripts/ansible/roles/grafana.yml

@ -50,12 +50,48 @@
debugger: never
when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and ansible_facts.services["firewalld.service"]['state'] == "running"
with_items: [ "3000", "9090" ]
- name: Open stat port for iptables
iptables:
chain: INPUT
destination_port: "{{ item }}"
jump: ACCEPT
protocol: tcp
ignore_errors: yes
with_items: [ "3000", "9090" ]
ignore_errors: yes
with_items: [ "3000", "9090" ]
- name: Ensure group "grafana" exists
ansible.builtin.group:
name: grafana
state: present
- name: Add the Grafana user
user:
name: grafana
shell: /sbin/nologin
groups: grafana
append: yes
- name: Create a directory if it does not exist
file:
path: "{{ item }}"
state: directory
mode: '0755'
owner: grafana
with_items:
- /var/lib/grafana
- /var/log/grafana
- /etc/grafana
- name: Create grafana.ini
file:
path: /etc/grafana/grafana.ini
owner: grafana
group: grafana
mode: '0644'
state: touch
- name: Restart service Grafana, in all cases
service:
name: grafana-server
state: restarted

32
app/sql.py

@ -553,16 +553,11 @@ def delete_uuid(uuid):
def delete_old_uuid():
cursor = conn.cursor()
if mysql_enable == '1':
sql = """ delete from uuid where exp < now() or exp is NULL """
sql1 = """ delete from token where exp < now() or exp is NULL """
else:
sql = """ delete from uuid where exp < datetime('now') or exp is NULL"""
sql1 = """ delete from token where exp < datetime('now') or exp is NULL"""
query = UUID.delete().where((UUID.exp < funct.get_data('regular')) | (UUID.exp.is_null(True)) )
query1 = Token.delete().where((Token.exp < funct.get_data('regular')) | (Token.exp.is_null(True)) )
try:
cursor.execute(sql)
cursor.execute(sql1)
query.execute()
query1.execute()
except Exception as e:
funct.out_error(e)
@ -1110,25 +1105,28 @@ def select_waf_servers_metrics_for_master():
def select_waf_servers_metrics(uuid):
cursor = conn.cursor()
try:
user_group = User.get(User.username == get_user_name_by_uuid(uuid))
except Exception as e:
funct.out_error(e)
else:
if user_group.groups == '1':
sql = """ select servers.ip from servers left join waf as waf on waf.server_id = servers.id
where servers.enable = 1 and waf.metrics = '1' """
query = Waf.select(Server.ip).join(Server, on=(Waf.server_id == Server.server_id)).where(
(Server.enable == 1) &
(Waf.metrics == 1)
)
else:
sql = """ select servers.ip from servers left join waf as waf on waf.server_id = servers.id
where servers.enable = 1 and waf.metrics = '1' and servers.groups like '%{group}%' """.format(group=user_group.groups)
query = Waf.select(Server.ip).join(Server, on=(Waf.server_id == Server.server_id)).where(
(Server.enable == 1) &
(Waf.metrics == 1) &
(Server.groups == user_group.groups)
)
try:
cursor.execute(sql)
query_res = query.execute()
except Exception as e:
funct.out_error(e)
else:
return cursor.fetchall()
return query_res
def select_waf_metrics(serv, **kwargs):

50
app/templates/add.html

@ -6,7 +6,7 @@
'rdp-cookie':'rdp-cookie', 'uri':'uri', 'uri whole':'uri whole', 'static-rr': 'static-rr',
'url_param userid':'url_param userid'} %}
{% set checks = dict() %}
{% set checks = {'':'Choose custom health check','option tcp-check':'Check a TCP Port',
{% set checks = {'':'Choose a custom health check','option tcp-check':'Check a TCP Port',
'option ssl-hello-chk':'Check a SSL Port','option httpchk':'Check a HTTP service',
'option ldap-check':'Check a LDAP service', 'option mysql-check':'Check a MySql Service',
'option pgsql-check':'Check a PgSQL Service', 'option redis-check': 'Check a Redis Service',
@ -40,15 +40,15 @@
<table class="add-table">
<caption><h3>Add listen</h3></caption>
<tr>
<td class="addName">Select server: </td>
<td class="addName">Select a server: </td>
<td class="addOption">
<select required name="serv" id="serv">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
</select>
<div class="tooltip tooltipTop"><b>Note:</b> If you re-configure the master server, the slave server will re-configured automatically</div>
<div class="tooltip tooltipTop"><b>Note:</b> If you re-configure the master server, the slave server will be re-configured automatically</div>
</td>
<td rowspan="5" class="add-note addName alert-info">
A "listen" section defines a complete proxy with its frontend and backend parts combined in one section. It is generally useful for TCP-only traffic.
@ -73,7 +73,7 @@
{{ input('ip', placeholder="Any", size='15') }}<b>:</b>
{{ input('listen-port', name='port', type="number", title="Port for bind listen", placeholder="8080", size='5', required='required') }}
<div class="tooltip tooltipTop">
The IP address for the bind listener, <b>if empty, will be assigned to all IP addresses</b>. <br />
If the IP-address for the listener is empty, it will listen on all IP addresses. <br />
Start typing IP or press down button. If you are using <b>VRRP, leave the IP field blank</b>. If you assign a VRRP IP, the slave server will not start
</div>
</td>
@ -289,15 +289,15 @@
<table>
<caption><h3>Add frontend</h3></caption>
<tr>
<td class="addName">Select server: </td>
<td class="addName">Select a server: </td>
<td class="addOption">
<select required name="serv" id="serv2">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
</select>
<div class="tooltip tooltipTop"><b>Note:</b> If you re-configure the master server, the slave server will re-configured automatically</div>
<div class="tooltip tooltipTop"><b>Note:</b> If you re-configure the master server, the slave server will be re-configured automatically</div>
</td>
<td rowspan="5" class="add-note addName alert-info">
A "frontend" section describes a set of listening sockets accepting client connections.
@ -322,7 +322,7 @@
<input type="text" name="ip" id="ip1" size="15" placeholder="Any" class="form-control"><b>:</b>
<input type="number" name="port" required title="Port for bind frontend" placeholder="8080" class="form-control">
<div class="tooltip tooltipTop">
The IP address for the bind listener, <b>if empty, will be assigned to all IP addresses</b>. <br />
If the IP-address for the frontend is empty, it will listen on all IP addresses. <br />
Start typing IP or press down button. If you are using <b>VRRP, leave the IP field blank</b>. If you assign a VRRP IP, the slave server will not start
</div>
</td>
@ -465,15 +465,15 @@
<table>
<caption><h3>Add backend</h3></caption>
<tr>
<td class="addName">Select server: </td>
<td class="addName">Select a server: </td>
<td class="addOption">
<select required name="serv" id="serv3">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
</select>
<div class="tooltip tooltipTop"><b>Note:</b> If you re-configure the master server, the slave server will reconfigured automatically</div>
<div class="tooltip tooltipTop"><b>Note:</b> If you re-configure the master server, the slave server will be re-configured automatically</div>
</td>
<td rowspan="4" class="add-note addName alert-info">
A "backend" section describes a set of servers to which the proxy will connect to forward incoming connections.
@ -678,7 +678,7 @@
<tr>
<td class="padding10 first-collumn">
<select required name="serv" id="serv5">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -701,7 +701,7 @@
<tr style="width: 50%;">
<td class="first-collumn" valign="top" style="padding-top: 15px;">
<select required id="serv4">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -733,7 +733,7 @@
<tr>
<td class="padding10 first-collumn">
<select required id="serv_for_lets">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -866,15 +866,15 @@
<table>
<caption><h3>Add Userlist</h3></caption>
<tr>
<td class="addName">Select server: </td>
<td class="addName">Select a server: </td>
<td class="addOption">
<select required name="serv" id="userlist_serv">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
</select>
<div class="tooltip tooltipTop"><b>Note:</b> If you reconfigure Master server, Slave will reconfigured automatically</div>
<div class="tooltip tooltipTop"><b>Note:</b> If you reconfigure Master server, Slave will be re-configured automatically</div>
</td>
<td rowspan="4" class="add-note addName alert-info">
It is possible to control access to frontend/backend/listen sections or to
@ -928,15 +928,15 @@
<table>
<caption><h3>Existing UserList</h3></caption>
<tr>
<td class="addName">Select server: </td>
<td class="addName">Select a server: </td>
<td class="addOption">
<select required name="serv" id="existing_userlist_serv">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
</select>
<div class="tooltip tooltipTop"><b>Note:</b> If you reconfigure Master server, Slave will reconfigured automatically</div>
<div class="tooltip tooltipTop"><b>Note:</b> If you reconfigure Master server, Slave will be re-configured automatically</div>
</td>
<td>
<a class="ui-button ui-widget ui-corner-all" title="Add Userlist" onclick="showUserlists()">Show Userlist</a>
@ -965,12 +965,12 @@
<td class="addName">Select server: </td>
<td class="addOption">
<select required name="serv" id="peers_serv">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
</select>
<div class="tooltip tooltipTop"><b>Note:</b> If you reconfigure Master server, Slave will reconfigured automatically</div>
<div class="tooltip tooltipTop"><b>Note:</b> If you re-configure Master server, Slave will be re-configured automatically</div>
</td>
<td rowspan="4" class="add-note addName alert-info">
The peers section enables the replication of stick table data between two or more HAProxy instances.
@ -1038,7 +1038,7 @@
</td>
<td class="padding10 first-collumn">
<select required name="serv-black-list" id="serv-black-list">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
<option value="all">ALL</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
@ -1067,7 +1067,7 @@
</td>
<td class="padding10 first-collumn">
<select required name="serv-white-list" id="serv-white-list">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
<option value="all">ALL</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>

4
app/templates/include/add_backup.html

@ -1,11 +1,11 @@
<tr>
<td class="padding20" style="width: 40%;">
Choose server for backup
Select a server for backup
<span class="need-field">*</span>
</td>
<td>
<select autofocus required name="backup-server" id="backup-server">
<option disabled>Choose server</option>
<option disabled>------</option>
{% for s in servers %}}
<option value="{{ s.2 }}">{{ s.1 }}</option>
{% endfor %}

6
app/templates/include/mon_installation.html

@ -48,7 +48,7 @@
</td>
<td class="padding10 first-collumn">
<select autofocus required name="haproxy_exp_addserv" id="haproxy_exp_addserv">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in servers %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -78,7 +78,7 @@
</td>
<td class="padding10 first-collumn">
<select autofocus required name="nginx_exp_addserv" id="nginx_exp_addserv">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in servers %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -108,7 +108,7 @@
</td>
<td class="padding10 first-collumn">
<select autofocus required name="node_exp_addserv" id="node_exp_addserv">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in servers %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}

2
app/templates/include/select.html

@ -1,5 +1,5 @@
<select autofocus required name="serv" id="{{ select_id }}">
<option disabled>Choose server</option>
<option disabled>------</option>
{% for select in selects %}
{% if select.2 == serv %}
<option value="{{ select.2 }}" selected>{{ select.1 }}</option>

12
app/templates/nettools.html

@ -31,7 +31,7 @@
<tr>
<td class="padding10 first-collumn">
<select autofocus required name="nettools_icmp_server_from" id="nettools_icmp_server_from">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
<option value="localhost">Roxy-WI</option>
{% for server in servers %}
<option value="{{ server.2 }}">{{ server.1 }}</option>
@ -63,7 +63,7 @@
<tr>
<td class="padding10 first-collumn">
<select autofocus required name="nettools_telnet_server_from" id="nettools_telnet_server_from">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
<option value="localhost">Roxy-WI</option>
{% for server in servers %}
<option value="{{ server.2 }}">{{ server.1 }}</option>
@ -95,7 +95,7 @@
<tr>
<td class="padding10 first-collumn">
<select autofocus required name="nettools_nslookup_server_from" id="nettools_nslookup_server_from">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
<option value="localhost">Roxy-WI</option>
{% for server in servers %}
<option value="{{ server.2 }}">{{ server.1 }}</option>
@ -126,7 +126,7 @@
$( "#nettools_telnet_form" ).on("click", ":submit", function(e){
$('#ajax-nettools').html('');
var frm = $('#nettools_telnet_form');
if($('#nettools_telnet_server_from option:selected').val() == 'Choose server') {
if($('#nettools_telnet_server_from option:selected').val() == '------') {
toastr.warning('Choose a server From');
return false;
}
@ -161,7 +161,7 @@
$( "#nettools_nslookup_form" ).on("click", ":submit", function(e){
$('#ajax-nettools').html('');
var frm = $('#nettools_nslookup_form');
if($('#nettools_nslookup_server_from option:selected').val() == 'Choose server') {
if($('#nettools_nslookup_server_from option:selected').val() == '------') {
toastr.warning('Choose a server From');
return false;
}
@ -189,7 +189,7 @@
$( "#nettools_icmp_form" ).on("click", ":submit", function(e){
$('#ajax-nettools').html('');
var frm = $('#nettools_icmp_form');
if($('#nettools_icmp_server_from option:selected').val() == 'Choose server') {
if($('#nettools_icmp_server_from option:selected').val() == '------') {
toastr.warning('Choose a server From');
return false;
}

10
app/templates/runtimeapi.html

@ -90,7 +90,7 @@
<td class="padding10 first-collumn" style="width: 25%;">
<form action="" method="post" id="maxconnform">
<select autofocus required name="serv" id="maxconn_select">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -129,7 +129,7 @@
<td class="padding10 first-collumn" style="width: 25%;">
<form action="" method="post" id="runtimeapiip">
<select autofocus required name="ip_select" id="ip_select">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -171,7 +171,7 @@
<td class="padding10 first-collumn" style="width: 25%;">
<form action="" method="post" id="runtimeapitable">
<select autofocus required name="table_serv_select" id="table_serv_select">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -203,7 +203,7 @@
<td class="padding10 first-collumn" style="width: 25%;">
<form action="" method="post" id="runtimeapilist">
<select autofocus required name="list_serv_select" id="list_serv_select">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -234,7 +234,7 @@
<td class="padding10 first-collumn" style="width: 25%;">
<form action="" method="post" id="runtimeapisessions">
<select autofocus required name="sessions_serv_select" id="sessions_serv_select">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}

6
app/templates/servers.html

@ -63,7 +63,7 @@
</td>
<td class="padding10 first-collumn">
<select autofocus required name="haproxyaddserv" id="haproxyaddserv">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in servers %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -94,7 +94,7 @@
</td>
<td class="padding10 first-collumn">
<select autofocus required name="nginxaddserv" id="nginxaddserv">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in servers %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
@ -128,7 +128,7 @@
<tr>
<td class="padding10 first-collumn">
<select autofocus required name="geoipserv" id="geoipserv">
<option disabled selected>Choose server</option>
<option disabled selected>------</option>
{% for select in servers %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}

2
app/templates/viewstats.html

@ -11,7 +11,7 @@
<form style="padding-left: 5px;" action="viewsttats.py" method="post">
<input type="hidden" id="service" value="{{service}}" />
<select autofocus required name="serv" id="serv">
<option disabled>Choose server</option>
<option disabled>------</option>
{% for select in selects %}
{% if select.2 == serv %}
<option value="{{ select.2 }}" selected>{{ select.1 }}</option>

6
app/templates/waf.html

@ -91,7 +91,7 @@
</div>
{% for s in servers %}
<div class="chart-container">
<canvas id="s_{{s.0}}" role="img"></canvas>
<canvas id="s_{{s.ip}}" role="img"></canvas>
</div>
{% endfor %}
<div id="dialog-confirm" style="display: none;">
@ -100,7 +100,7 @@
<script>
function showWafMetrics() {
{% for s in servers %}
getWafChartData('{{s.0}}');
getWafChartData('{{s.ip}}');
{% endfor %}
}
showWafMetrics();
@ -111,7 +111,7 @@
let metrics = new Promise(
(resolve, reject) => {
{% for s in servers %}
getWafChartData('{{s.0}}')
getWafChartData('{{s.ip}}')
{% endfor %}
});
metrics.then();

4
config_other/fail2ban/filter.d/haproxy-wi.conf → config_other/fail2ban/filter.d/roxy-wi.conf

@ -1,4 +1,4 @@
# Fail2Ban haproxy-wi filter
# Fail2Ban roxy-wi filter
#
[Definition]
@ -13,5 +13,5 @@ failregex = from <HOST> user: .* failed log in for: .*
ignoreregex =
# Author: Pavel Loginov
# For project: haproxy-wi.org
# For project: roxy-wi.org

9
config_other/fail2ban/jail.d/haproxy-wi.conf

@ -1,9 +0,0 @@
[haproxy-wi]
enabled = true
filter = haproxy-wi
port = http,https
action = iptables[name=haproxy-wi, port=https, protocol=tcp]
logpath = /var/www/haproxy-wi/log/haproxy-wi-*.log
findtime = 600
bantime = 600
maxretry = 2

9
config_other/fail2ban/jail.d/roxy-wi.conf

@ -0,0 +1,9 @@
[roxy-wi]
enabled = true
filter = roxy-wi
port = http,https
action = iptables[name=roxy-wi, port=https, protocol=tcp]
logpath = /var/www/haproxy-wi/log/roxy-wi-*.log
findtime = 600
bantime = 600
maxretry = 2

2
inc/add.js

@ -1001,7 +1001,7 @@ $( function() {
$('#add-userlist-group').click(function() {
$('#userlist-groups').append(add_userlist_group_var);
});
var add_peer_var = '<br /><input name="servers_name" required title="Peer name" size=14 placeholder="haproxyN" class="form-control">' +
var add_peer_var = '<br /><input name="servers_name" required title="Peer name" size=14 placeholder="haproxyN" class="form-control">: ' +
'<input name="servers" title="Backend IP" size=14 placeholder="xxx.xxx.xxx.xxx" class="form-control second-server">: ' +
'<input name="server_port" required title="Backend port" size=3 placeholder="yyy" class="form-control second-server add_server_number" type="number">'
$('[name=add-peer-input]').click(function() {

Loading…
Cancel
Save