Dos2unix. view exist ssl certs, small change, and bugs
pull/19/head
Aidaho12 2018-05-06 10:45:10 +06:00
parent b9a3a4fc4e
commit ff5fced563
10 changed files with 76 additions and 22 deletions

View File

@ -17,6 +17,7 @@ config_read = ""
configver = ""
stderr = ""
aftersave = ""
error = ""
try:
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
@ -61,7 +62,7 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None:
if master[0] != None:
funct.upload_and_restart(master[0], configver, just_save=save)
stderr = funct.upload_and_restart(serv, configver, just_save=save)
stderr, error = funct.upload_and_restart(serv, configver, just_save=save)
aftersave = 1
@ -79,5 +80,6 @@ output_from_parsed_template = template.render(h2 = 1, title = "Old Versions HAPr
stderr = stderr,
open = form.getvalue('open'),
onclick = "showUploadConfig()",
error = error,
note = 1)
print(output_from_parsed_template)

View File

@ -245,11 +245,18 @@ def upload(serv, path, file, **kwargs):
def upload_and_restart(serv, cfg, **kwargs):
tmp_file = tmp_config_path + "/" + get_data('config') + ".cfg"
error = ""
try:
os.system("dos2unix "+cfg)
except OSError:
error = 'Please install dos2unix'
pass
try:
ssh = ssh_connect(serv)
except:
print('<center><div class="alert alert-danger">Connect fail</div>')
error = 'Connect fail'
sftp = ssh.open_sftp()
sftp.put(cfg, tmp_file)
sftp.close()
@ -272,8 +279,7 @@ def upload_and_restart(serv, cfg, **kwargs):
for command in commands:
stdin, stdout, stderr = ssh.exec_command(command)
return stderr.read().decode(encoding='UTF-8')
return stderr.read().decode(encoding='UTF-8'), error
ssh.close()
def open_port_firewalld(cfg):

View File

@ -18,6 +18,7 @@ config_read = ""
cfg = ""
stderr = ""
aftersave = ""
error = ""
try:
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
@ -71,7 +72,7 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None:
except IOError:
print("Can't read import config file")
stderr = funct.upload_and_restart(serv, cfg, just_save=save, keepalived=1)
stderr, error = funct.upload_and_restart(serv, cfg, just_save=save, keepalived=1)
os.system("/bin/diff -ub %s %s >> %s/config_edit-%s.log" % (oldcfg, cfg, log_path, funct.get_data('logs')))
os.system("/bin/rm -f " + kp_save_configs_dir + "*.old")
@ -87,5 +88,6 @@ output_from_parsed_template = template.render(h2 = 1, title = "Edit Runnig Keepa
cfg = cfg,
selects = servers,
stderr = stderr,
error = error,
keepalived = 1)
print(output_from_parsed_template)

View File

@ -25,8 +25,11 @@ print('Content-type: text/html\n')
if form.getvalue('getcert') is not None and serv is not None:
commands = [ "ls -1t /etc/ssl/certs/ |grep pem" ]
funct.ssh_command(serv, commands, ip="1")
try:
funct.ssh_command(serv, commands, ip="1")
except:
print('<div class="alert alert-danger" style="margin:0">Can not connect to the server</div>')
if form.getvalue('ssh_cert'):
ssh_keys = config.get('ssh', 'ssh_keys')

View File

@ -320,6 +320,27 @@
</div>
<div id="ssl">
<table>
<tr class="overviewHead">
<td class="padding10 first-collumn">View certificates</td>
<td>
Exist certificates
</td>
</tr>
<tr>
<td class="padding10 first-collumn">
<select required name="serv" id="serv5">
<option disabled selected>Choose server</option>
{% for select in selects %}
<option value="{{ select.2 }}">{{ select.1 }}</option>
{% endfor %}
</select>
<a class="ui-button ui-widget ui-corner-all" id="ssl_key_view" title="View certificates">View</a>
</td>
<td>
<span id="ajax-show-ssl"></span>
</td>
</tr>
<table>
<tr class="overviewHead">
<td class="padding10 first-collumn">Upload SSL certificates</td>

View File

@ -94,7 +94,7 @@
{% endif %}
</ul>
</nav>
<div class="copyright-menu">HAproxy-WI v2.5</div>
<div class="copyright-menu">HAproxy-WI v2.5.1</div>
</div>
</div>
<div class="container">
@ -179,10 +179,5 @@
<div id="ajax-compare"></div>
<div id="ajax"></div>
</div>
<center style="margin-left: 8%;">
<h3>
<a class="ui-button ui-widget ui-corner-all" href="#top" title="Move up">UP</a>
</h3><br />
</center>
</body>
</html>

View File

@ -51,16 +51,18 @@
{% endif %}
{% if aftersave %}
<div class="alert alert-info">New config was saved as: {{ cfg }} </div>
<br><a href="viewsttats.py?serv={{ serv }}" target="_blank" title="View stats">Go to view stats</a>
{% if stderr %}
{% if stderr or error %}
<div class="alert alert-danger">
Some errors:
<br>
<br>
{{stderr}}
{{error}}
</div>
{% else %}
<div class="alert alert-success">Config ok</div>
<a href="viewsttats.py?serv={{ serv }}" target="_blank" title="View stats">Go to view stats</a>
<script>window.history.pushState("Map", "Map", cur_url[0])</script>
{% endif %}
{% endif %}
</center>

View File

@ -40,16 +40,19 @@
{% endif %}
{% if aftersave %}
<div class="alert alert-info">Uploaded old config ver: {{ configver }} </div>
<br><a href="viewsttats.py?serv={{ serv }}" target="_blank" title="View stats">Go to view stats</a>
{% if stderr %}
{% if stderr or error %}
<div class="alert alert-danger">
Some errors:
<br>
<br>
{{stderr}}
{{error}}
</div>
{% else %}
<div class="alert alert-success">Config ok</div>
<a href="viewsttats.py?serv={{ serv }}" target="_blank" title="View stats">Go to view stats</a>
<script>window.history.pushState("Map", "Map", cur_url[0])</script>
{% endif %}
{% endif %}
</center>

View File

@ -148,7 +148,7 @@ function showMap() {
type: "GET",
success: function( data ) {
$("#ajax").html(data);
window.history.pushState("Map", "Map", cur_url[0]+"?serv="+$("#serv").val());
//window.history.pushState("Map", "Map", cur_url[0]+"?serv="+$("#serv").val());
}
} );
}
@ -184,7 +184,7 @@ function showCompare() {
type: "GET",
success: function( data ) {
$("#ajax").html(data);
window.history.pushState("Compare", "Compare", cur_url[0]+"?serv="+$("#serv").val()+"&open=open&left="+$("#left").val()+"&right="+$("#right").val());
//window.history.pushState("Compare", "Compare", cur_url[0]+"?serv="+$("#serv").val()+"&open=open&left="+$("#left").val()+"&right="+$("#right").val());
$.getScript(url);
}
} );
@ -200,7 +200,7 @@ function showCompareConfigs() {
type: "GET",
success: function( data ) {
$("#ajax-compare").html(data);
window.history.pushState("Compare", "Compare", cur_url[0]+"?serv="+$("#serv").val()+"&open=open");
//window.history.pushState("Compare", "Compare", cur_url[0]+"?serv="+$("#serv").val()+"&open=open");
$.getScript(url);
}
} );
@ -215,7 +215,7 @@ function showConfig() {
type: "GET",
success: function( data ) {
$("#ajax").html(data);
window.history.pushState("Show config", "Show config", cur_url[0]+"?serv="+$("#serv").val()+"&open=open");
//window.history.pushState("Show config", "Show config", cur_url[0]+"?serv="+$("#serv").val()+"&open=open");
var urlConfigShowJs = '/inc/configshow.js';
$.getScript(urlConfigShowJs);
}
@ -695,4 +695,24 @@ $( function() {
}
} );
});
$('#ssl_key_view').click(function() {
$.ajax( {
url: "options.py",
data: {
serv: $('#serv5').val(),
getcert: "viewcert"
},
type: "GET",
success: function( data ) {
//data = data.replace(/\s+/g,' ');
//data = data.split(" ");
if (data.indexOf('danger') != '-1') {
$("#ajax-show-ssl").html(data);
} else {
$('.alert-danger').remove();
$( "#ajax-show-ssl").html("<b>"+data+"</b>");
}
}
} );
});
});

View File

@ -46,7 +46,7 @@ if [[ $(cat /etc/*-rele* |grep NAME |head -1) != 'NAME="Red Hat Enterprise Linux
yum -y install epel-release
fi
yum -y install git ncat net-tools lshw python34 python34-pip httpd mod_ssl gcc python34-devel
yum -y install git ncat net-tools lshw python34 dos2unix python34-pip httpd mod_ssl gcc python34-devel
if [ $? -eq 1 ]
then