Pavel Loginov 2020-11-06 10:39:44 +06:00
parent 92103b2e37
commit 5d591fdf7f
3 changed files with 33 additions and 32 deletions

View File

@ -2,7 +2,7 @@
import os import os
import funct import funct
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/'), autoescape=True,extensions=['jinja2.ext.loopcontrols']) env = Environment(loader=FileSystemLoader('templates/'), autoescape=True, extensions=['jinja2.ext.loopcontrols'])
template = env.get_template('sections.html') template = env.get_template('sections.html')
print('Content-type: text/html\n') print('Content-type: text/html\n')
@ -22,7 +22,7 @@ end_line = ""
try: try:
user, user_id, role, token, servers = funct.get_users_params() user, user_id, role, token, servers = funct.get_users_params()
except: except Exception:
pass pass
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
@ -32,11 +32,11 @@ if serv is not None and open is not None:
error = funct.get_config(serv, cfg) error = funct.get_config(serv, cfg)
sections = funct.get_sections(cfg) sections = funct.get_sections(cfg)
if serv is not None and section is not None : if serv is not None and section is not None:
try: try:
funct.logging(serv, "sections.py open config") funct.logging(serv, "sections.py open config")
except: except Exception:
pass pass
start_line, end_line, config_read = funct.get_section_from_config(cfg, section) start_line, end_line, config_read = funct.get_section_from_config(cfg, section)
@ -46,7 +46,7 @@ if serv is not None and section is not None :
if serv is not None and form.getvalue('config') is not None: if serv is not None and form.getvalue('config') is not None:
try: try:
funct.logging(serv, "config.py edited config") funct.logging(serv, "config.py edited config")
except: except Exception:
pass pass
config = form.getvalue('config') config = form.getvalue('config')
@ -71,23 +71,22 @@ if serv is not None and form.getvalue('config') is not None:
os.system("/bin/rm -f " + hap_configs_dir + "*.old") os.system("/bin/rm -f " + hap_configs_dir + "*.old")
template = template.render(h2 = 1, title = "Working with HAProxy configs", template = template.render(h2=1, title="Working with HAProxy configs",
role = role, role=role,
action = "sections.py", action="sections.py",
user = user, user=user,
select_id = "serv", select_id="serv",
serv = serv, serv=serv,
aftersave = aftersave, aftersave=aftersave,
config = config_read, config=config_read,
cfg = cfg, cfg=cfg,
selects = servers, selects=servers,
stderr = stderr, stderr=stderr,
error = error, error=error,
start_line = start_line, start_line=start_line,
end_line = end_line, end_line=end_line,
section = section, section=section,
sections = sections, sections=sections,
note = 1, versions=funct.versions(),
versions = funct.versions(), token=token)
token = token)
print(template) print(template)

View File

@ -70,7 +70,7 @@
</p> </p>
</form> </form>
{% if note %} {% if note %}
<div class="alert alert-info"><b>Note:</b> If you reconfigure Master server, Slave will reconfigured automatically</div> <div class="alert alert-info"><b>Note:</b> When reconfiguring the master server, the slave will be reconfigured automatically</div>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endif %} {% endif %}
@ -80,7 +80,7 @@
{% include 'include/errors.html' %} {% include 'include/errors.html' %}
{% else %} {% else %}
<div class="alert alert-success">Config is ok</div> <div class="alert alert-success">Config is ok</div>
<a href="viewsttats.py?serv={{ serv }}" target="_blank" title="View stats">Go to view stats</a> <a href="viewsttats.py?serv={{ serv }}" target="_blank" title="View stats">Go to stats</a>
{% endif %} {% endif %}
{% endif %} {% endif %}
</center> </center>

View File

@ -26,7 +26,7 @@
{% if config %} {% if config %}
{% if role <= 3 %} {% if role <= 3 %}
<div id="config"> <div id="config">
<h4>You are editting "{{section}}" from server {{ serv }}</h4> <h4>You are editing "{{section}}" section from server {{ serv }}</h4>
</center> </center>
<form action="{{ action }}" name="saveconfig" method="post"> <form action="{{ action }}" name="saveconfig" method="post">
<input type="hidden" value="{{ serv }}" name="serv"> <input type="hidden" value="{{ serv }}" name="serv">
@ -44,9 +44,11 @@
<button type="submit" value="reload" name="save" class="btn btn-default">Save and reload</button> <button type="submit" value="reload" name="save" class="btn btn-default">Save and reload</button>
</p> </p>
</form> </form>
{% if note %} <div class="alert alert-info">
<div class="alert alert-info"><b>Note:</b> If you reconfigure Master server, Slave will reconfigured automatically</div> <p><b>Note:</b></p>
{% endif %} <p>When reconfiguring the master server, the slave will be reconfigured automatically</p>
<p>Unable to delete entire section</p>
</div>
<script> <script>
var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("config_text_area"), {mode: "haproxy", lineNumbers: true}); var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("config_text_area"), {mode: "haproxy", lineNumbers: true});
</script> </script>
@ -68,8 +70,8 @@
{% include 'include/errors.html' %} {% include 'include/errors.html' %}
{% else %} {% else %}
<div class="alert alert-success">Config is ok</div> <div class="alert alert-success">Config is ok</div>
<a href="config.py?serv={{ serv }}" title="Working with HAProxy configs">Configs</a> | <a href="config.py?serv={{ serv }}" title="Working with HAProxy config">Config</a> |
<a href="viewsttats.py?serv={{ serv }}" target="_blank" title="View stats">Go to view stats</a> <a href="viewsttats.py?serv={{ serv }}" target="_blank" title="View stats">Go to stats</a>
{% endif %} {% endif %}
<script>window.history.pushState("Config", "Config", cur_url[0])</script> <script>window.history.pushState("Config", "Config", cur_url[0])</script>
{% endif %} {% endif %}