mirror of https://github.com/Aidaho12/haproxy-wi
parent
7e9781aa12
commit
7d428fe0f6
|
@ -76,6 +76,7 @@ if serv is not None and form.getvalue('open') is not None:
|
|||
os.system("/bin/mv %s %s.old" % (cfg, cfg))
|
||||
|
||||
if serv is not None and form.getvalue('config') is not None:
|
||||
import sys
|
||||
funct.check_is_server_in_group(serv)
|
||||
try:
|
||||
funct.logging(serv, "config.py edited config")
|
||||
|
@ -85,12 +86,12 @@ if serv is not None and form.getvalue('config') is not None:
|
|||
config = form.getvalue('config')
|
||||
oldcfg = form.getvalue('oldconfig')
|
||||
save = form.getvalue('save')
|
||||
aftersave = 1
|
||||
|
||||
try:
|
||||
with open(cfg, "a") as conf:
|
||||
conf.write(config)
|
||||
except IOError:
|
||||
error = "Can't read import config file"
|
||||
print("error: Cannot read import config file")
|
||||
|
||||
if service == 'keepalived':
|
||||
stderr = funct.upload_and_restart(serv, cfg, just_save=save, keepalived=1)
|
||||
|
@ -103,6 +104,14 @@ if serv is not None and form.getvalue('config') is not None:
|
|||
|
||||
os.system("/bin/rm -f " + configs_dir + "*.old")
|
||||
|
||||
if stderr:
|
||||
print(stderr)
|
||||
else:
|
||||
if save == 'test':
|
||||
print('Config is ok')
|
||||
else:
|
||||
print('Config is ok <br /> Config has been updated')
|
||||
sys.exit()
|
||||
|
||||
template = template.render(h2=1, title=title,
|
||||
role=role,
|
||||
|
|
|
@ -29,7 +29,7 @@ try:
|
|||
for s in servers:
|
||||
i += 1
|
||||
if i != servers_len:
|
||||
servers_for_grep += s[2]+'|'
|
||||
servers_for_grep += s[2]+'\|'
|
||||
else:
|
||||
servers_for_grep += s[2]
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<script src="/inc/codemirror/codemirror.js"></script>
|
||||
<script src="/inc/codemirror/nginx.js"></script>
|
||||
<script src="/inc/codemirror/haproxy.js"></script>
|
||||
<script src="/inc/configshow.js"></script>
|
||||
<center>
|
||||
{% if selects|length == 0 %}
|
||||
{% include 'include/getstarted.html' %}
|
||||
|
@ -42,45 +43,36 @@
|
|||
</form>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if not aftersave %}
|
||||
{% if stderr or error %}
|
||||
{% include 'include/errors.html' %}
|
||||
{% endif %}
|
||||
|
||||
{% if stderr or error %}
|
||||
{% include 'include/errors.html' %}
|
||||
{% endif %}
|
||||
|
||||
{% if config %}
|
||||
{% if role <= 3 %}
|
||||
<h4>Config from {{ serv }}</h4>
|
||||
</center>
|
||||
<form action="{{ action }}" name="saveconfig" id="saveconfig" method="post">
|
||||
<input type="hidden" value="{{ serv }}" name="serv">
|
||||
<input type="hidden" value="{{ cfg }}.old" name="oldconfig">
|
||||
<div style="margin-left: 23%;width: 60%;">
|
||||
<textarea name="config" id="config_text_area" class="config" rows="35" cols="100">{{ config }}</textarea>
|
||||
</div>
|
||||
<p>
|
||||
<center>
|
||||
{% if service == 'haproxy' %}
|
||||
<button type="submit" value="test" name="save" class="btn btn-default">Just test</button>
|
||||
{% endif %}
|
||||
<button type="submit" value="save" name="save" class="btn btn-default">Just save</button>
|
||||
<button type="submit" value="" name="" class="btn btn-default">Save and restart</button>
|
||||
{% if service != 'keepalived' %}
|
||||
<button type="submit" value="reload" name="save" class="btn btn-default">Save and reload</button>
|
||||
{% endif %}
|
||||
</p>
|
||||
</form>
|
||||
{% if note %}
|
||||
<div class="alert alert-info"><b>Note:</b> When reconfiguring the master server, the slave will be reconfigured automatically</div>
|
||||
<h4>Config from {{ serv }}</h4>
|
||||
</center>
|
||||
<form action="config.py" name="saveconfig" id="saveconfig" method="post">
|
||||
<input type="hidden" value="{{ serv }}" name="serv">
|
||||
<input type="hidden" value="{{ cfg }}.old" name="oldconfig">
|
||||
<input type="hidden" value="{{ token }}" name="token">
|
||||
<input type="hidden" value="{{ service }}" name="service">
|
||||
<div style="margin-left: 23%;width: 60%;">
|
||||
<textarea name="config" id="config_text_area" class="config" rows="35" cols="100">{{ config }}</textarea>
|
||||
</div>
|
||||
<p>
|
||||
<center>
|
||||
{% if service == 'haproxy' %}
|
||||
<button type="submit" value="test" name="save" class="btn btn-default">Just test</button>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if aftersave %}
|
||||
<div class="alert alert-info">New config was saved as: {{ cfg }} </div>
|
||||
{% if stderr or error %}
|
||||
{% include 'include/errors.html' %}
|
||||
{% else %}
|
||||
<div class="alert alert-success">Config is ok</div>
|
||||
<a href="viewsttats.py?serv={{ serv }}" target="_blank" title="View stats">Go to stats</a>
|
||||
<button type="submit" value="save" name="save" class="btn btn-default">Just save</button>
|
||||
<button type="submit" value="" name="" class="btn btn-default">Save and restart</button>
|
||||
{% if service != 'keepalived' %}
|
||||
<button type="submit" value="reload" name="save" class="btn btn-default">Save and reload</button>
|
||||
{% endif %}
|
||||
</p>
|
||||
</form>
|
||||
<div class="alert alert-info"><b>Note:</b> When reconfiguring the master server, the slave will be reconfigured automatically</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</center>
|
||||
|
|
|
@ -52,4 +52,25 @@ $( function() {
|
|||
event.preventDefault();
|
||||
});
|
||||
|
||||
$( "#saveconfig" ).on("click", ":submit", function(e){
|
||||
var frm = $('#saveconfig');
|
||||
myCodeMirror.save();
|
||||
$.ajax({
|
||||
url: frm.attr('action'),
|
||||
data: frm.serialize() + "&save=" + $(this).val(),
|
||||
type: frm.attr('method'),
|
||||
success: function( data ) {
|
||||
data = data.replace('\n', '<br>');
|
||||
if (data.indexOf('error: ') != '-1' || data.indexOf('Fatal') != '-1') {
|
||||
toastr.clear();
|
||||
toastr.error(data);
|
||||
} else {
|
||||
toastr.clear();
|
||||
toastr.success(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
})
|
Loading…
Reference in New Issue