Pavel Loginov 2020-04-23 23:11:37 +02:00
parent c106b6ffcc
commit d92856067a
5 changed files with 51 additions and 20 deletions

View File

@ -181,7 +181,7 @@ def update_db_v_31(**kwargs):
sql.append("INSERT INTO settings (param, value, section, `desc`) values('server_state_file', '/etc/haproxy/haproxy.state', 'haproxy', 'Path to HAProxy state file');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('server_state_file', '/etc/haproxy/haproxy.state', 'haproxy', 'Path to HAProxy state file');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('haproxy_sock', '/var/run/haproxy.sock', 'haproxy', 'Path to HAProxy sock file');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('haproxy_sock', '/var/run/haproxy.sock', 'haproxy', 'Path to HAProxy sock file');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('haproxy_sock_port', '1999', 'haproxy', 'HAProxy sock port');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('haproxy_sock_port', '1999', 'haproxy', 'HAProxy sock port');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('firewall_enable', '0', 'haproxy', 'If enable this option Haproxy-wi will be configure firewalld based on config port');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('firewall_enable', '0', 'main', 'If enable this option Haproxy-wi will be configure firewalld based on config port');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('apache_log_path', '/var/log/httpd/', 'logs', 'Path to Apache logs');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('apache_log_path', '/var/log/httpd/', 'logs', 'Path to Apache logs');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_enable', '0', 'ldap', 'If 1 ldap enabled');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_enable', '0', 'ldap', 'If 1 ldap enabled');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_server', '', 'ldap', 'IP address ldap server');") sql.append("INSERT INTO settings (param, value, section, `desc`) values('ldap_server', '', 'ldap', 'IP address ldap server');")

View File

@ -1223,25 +1223,30 @@ if form.getvalue('bwlists_save'):
except IOError as e: except IOError as e:
print('<div class="alert alert-danger" style="margin-left:14px">Cat\'n save '+color+' list. %s </div>' % e) print('<div class="alert alert-danger" style="margin-left:14px">Cat\'n save '+color+' list. %s </div>' % e)
servers = sql.get_dick_permit()
path = sql.get_setting('haproxy_dir')+"/"+color path = sql.get_setting('haproxy_dir')+"/"+color
servers = []
for server in servers: servers.append(serv)
funct.ssh_command(server[2], ["sudo mkdir "+path])
funct.ssh_command(server[2], ["sudo chown $(whoami) "+path]) MASTERS = sql.is_master(serv)
error = funct.upload(server[2], path+"/"+bwlists_save, list, dir='fullpath') for master in MASTERS:
if master[0] != None:
servers.append(master[0])
for serv in servers:
funct.ssh_command(serv, ["sudo mkdir "+path])
funct.ssh_command(serv, ["sudo chown $(whoami) "+path])
error = funct.upload(serv, path+"/"+bwlists_save, list, dir='fullpath')
if error: if error:
print('<div class="alert alert-danger">Upload fail: %s</div>' % error) print('<div class="alert alert-danger">Upload fail: %s</div>' % error)
else: else:
print('<div class="alert alert-success" style="margin:10px; margin-left:14px">Edited '+color+' list was uploaded to '+server[1]+'</div>') print('<div class="alert alert-success" style="margin:10px; margin-left:14px">Edited '+color+' list was uploaded to '+serv+'</div>')
try: try:
funct.logging(server[1], 'has edited '+color+' list '+bwlists_save, haproxywi=1, login=1) funct.logging(serv, 'has edited '+color+' list '+bwlists_save, haproxywi=1, login=1)
except: except:
pass pass
if form.getvalue('bwlists_restart') == 'restart': if form.getvalue('bwlists_restart') == 'restart':
funct.ssh_command(server[2], ["sudo systemctl restart haproxy"]) funct.ssh_command(serv, ["sudo systemctl restart haproxy"])
elif form.getvalue('bwlists_restart') == 'reload': elif form.getvalue('bwlists_restart') == 'reload':
funct.ssh_command(server[2], ["sudo systemctl reload haproxy"]) funct.ssh_command(serv, ["sudo systemctl reload haproxy"])
if form.getvalue('get_lists'): if form.getvalue('get_lists'):

View File

@ -750,13 +750,20 @@ h3 {
<div id="lists"> <div id="lists">
<table class="overview"> <table class="overview">
<tr class="overviewHead"> <tr class="overviewHead">
<td class="padding10 first-collumn">New black list</th> <th class="padding10 first-collumn">Server for upload</th>
<td>Exists black lists</th> <th>New black list</th>
<td class="padding10 first-collumn">New white list</th> <th>Exists black lists</th>
<td>Exists white lists</th>
</tr> </tr>
<tr> <tr>
<td class="padding10 first-collumn" style="width: 25%;"> <td class="padding10 first-collumn">
<select required name="serv-black-list" id="serv-black-list">
<option disabled selected>Choose server</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
</select>
</td>
<td style="width: 25%;">
Name: {{ input('new_blacklist_name') }} Name: {{ input('new_blacklist_name') }}
<button onclick="createList('black')">Create</button> <button onclick="createList('black')">Create</button>
</td> </td>
@ -765,7 +772,26 @@ h3 {
<a onclick="editList('{{ list }}', 'black')" style="cursor: pointer;" title="Edit list {{ list }}">{{ list }}</a> <a onclick="editList('{{ list }}', 'black')" style="cursor: pointer;" title="Edit list {{ list }}">{{ list }}</a>
{% endfor %} {% endfor %}
</td> </td>
<td class="padding10 first-collumn" style="width: 25%;">
</tr>
{{ input('group', value=group, type='hidden') }}
</table>
<table>
<tr class="overviewHead">
<th class="padding10 first-collumn">Server for upload</th>
<th>New white list</th>
<th>Exists white lists</th>
</tr>
<tr>
<td class="padding10 first-collumn">
<select required name="serv-white-list" id="serv-white-list">
<option disabled selected>Choose server</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
</select>
</td>
<td style="width: 25%;">
Name: {{ input('new_whitelist_name') }} Name: {{ input('new_whitelist_name') }}
<button onclick="createList( 'white')">Create</button> <button onclick="createList( 'white')">Create</button>
</td> </td>
@ -775,12 +801,11 @@ h3 {
{% endfor %} {% endfor %}
</td> </td>
</tr> </tr>
{{ input('group', value=group, type='hidden') }}
</table> </table>
<div id="ajax"></div>
<div class="add-note addName alert-info" style="width: inherit; margin-right: 15px;"> <div class="add-note addName alert-info" style="width: inherit; margin-right: 15px;">
In this section you can create and edit black and white lists. And after use them in the HAProxy configs or in the "Add proxy" pages In this section you can create and edit black and white lists. And after use them in the HAProxy configs or in the "Add proxy" pages
</div> </div>
<div id="ajax"></div>
<div id="dialog-confirm-cert-edit" title="View certificate " style="display: none;"> <div id="dialog-confirm-cert-edit" title="View certificate " style="display: none;">
<span><b>Note:</b> Each new address must be specified from a new line</span> <span><b>Note:</b> Each new address must be specified from a new line</span>
<textarea id="edit_lists" style="width: 100%" rows=20></textarea> <textarea id="edit_lists" style="width: 100%" rows=20></textarea>

View File

@ -74,7 +74,7 @@ def main(serv, port):
servername = servername.split(",") servername = servername.split(",")
realserver = servername[0] realserver = servername[0]
server = servername[1] server = servername[1]
alert = "Backend: "+realserver[2:]+", server: "+server+" has changed status and is now "+ currentstat[i] + " at " + serv alert = "Backend: "+realserver[2:]+", server: "+server+" has changed status to "+ currentstat[i] + " at " + serv
funct.telegram_send_mess(str(alert), ip=serv) funct.telegram_send_mess(str(alert), ip=serv)
funct.logging("localhost", " "+alert, alerting=1) funct.logging("localhost", " "+alert, alerting=1)
firstrun = False firstrun = False

View File

@ -1212,6 +1212,7 @@ function saveList(action, list, color) {
url: "options.py", url: "options.py",
data: { data: {
bwlists_save: list, bwlists_save: list,
serv: $( "#serv-"+color+"-list option:selected" ).val(),
bwlists_content: $('#edit_lists').val(), bwlists_content: $('#edit_lists').val(),
color: color, color: color,
group: $('#group').val(), group: $('#group').val(),