ssh except

pull/19/head
Aidaho12 2018-02-06 12:36:43 +06:00
parent 5d12901a5b
commit dbe2ff7374
3 changed files with 30 additions and 445 deletions

View File

@ -93,8 +93,8 @@ def links():
'<li><a href=/ title="Home Page" style="size:5">Home Page</a></li>'
'<li><a href="#" title="Statistics, monitoring and logs">Stats</a>'
'<ul>'
'<li><a href=/cgi-bin/overview.py title="Server and service status"">Overview</a> </li>'
'<li><a href=/cgi-bin/viewsttats.py title="View Stats"">Stats</a> </li>'
'<li><a href=/cgi-bin/overview.py title="Server and service status">Overview</a> </li>'
'<li><a href=/cgi-bin/viewsttats.py title="View Stats">Stats</a> </li>'
'<li><a href="http://172.28.5.106:3000/d/000000002/haproxy?refresh=1m&orgId=1" title="Mon" target="_blanck">Monitoring</a> </li>'
'<li><a href=/cgi-bin/logs.py title="View logs">Logs</a></li>'
'</ul>'
@ -149,29 +149,45 @@ def footer():
'</center>'
'</center></div>'
'<div class="footer">'
'<div class="footer-link">')
#links()
'<div class="footer-link">'
'<span class="LogoText">HAproxy-WI</span>')
print('</div></div></body></html>')
def ssh_connect(serv):
ssh = SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
if config.get('ssh', 'ssh_keys_enable') == "1":
k = paramiko.RSAKey.from_private_key_file(ssh_keys)
ssh.connect(hostname = serv, username = ssh_user_name, pkey = k )
else:
ssh.connect(hostname = serv, username = ssh_user_name, password = config.get('ssh', 'ssh_pass'))
return ssh
except paramiko.AuthenticationException:
print("Authentication failed, please verify your credentials: %s")
except paramiko.SSHException as sshException:
print("Unable to establish SSH connection: %s" % sshException)
except paramiko.BadHostKeyException as badHostKeyException:
print("Unable to verify server's host key: %s" % badHostKeyException)
except Exception as e:
print(e.args)
if config.get('ssh', 'ssh_keys_enable') == "1":
k = paramiko.RSAKey.from_private_key_file(ssh_keys)
ssh.connect(hostname = serv, username = ssh_user_name, pkey = k )
else:
ssh.connect(hostname = serv, username = ssh_user_name, password = config.get('ssh', 'ssh_pass'))
return ssh
def get_config(serv, cfg):
os.chdir(hap_configs_dir)
ssh = ssh_connect(serv)
sftp = ssh.open_sftp()
sftp.get(haproxy_config_path, cfg)
sftp.close()
ssh.close()
try:
sftp = ssh.open_sftp()
sftp.get(haproxy_config_path, cfg)
sftp.close()
ssh.close()
except IOError as e:
flash(str(e)+" IOERROR")
return ["IOERROR: " + str(e),0,0]
except Exception as e:
flash(str(e)+" OTHER EXCEPTION")
return ["Error: " + str(e),0,0]
def show_config(cfg):
print('</center><div class="configShow">')

View File

@ -1,30 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>HAProxy web manager</title>
<link href="/favicon.ico" rel="icon" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link href="style.css" rel="stylesheet">
</head>
<body>
<center>
<div class="conteinerIndex">
<h2>Welcome! HAproxy Web Interface</h2>
<h3>Choose your destiny!</h3>
<a href=/cgi-bin/overview.py title="Server and service status"">Overview</a> <br />
<a href="cgi-bin/viewsttats.py" title="View stats">View stats</a> <br />
<a href="cgi-bin/logs.py" title="View logs">Logs</a> <br />
<a href="cgi-bin/edit.py" title="Edit settings">Edit settings</a> <br />
<a href="cgi-bin/diff.py" title="Compare Configs">Compare</a> <br />
<a href="cgi-bin/configshow.py" title="Show Config">Show</a> <br />
<a href=/cgi-bin/add.py title="Add single listen/frontend/backend">Add</a> <br />
<a href="cgi-bin/config.py" title="Edit settings">Edit config</a> <br />
<a href="cgi-bin/configver.py" title="Upload old config">Upload old config</a> <br />
<a href="cgi-bin/delver.py" title="Upload old config">Delete old config</a> <br />
<div class="copyright">
HAproxy Web Interface v1.6.1
</div>
</div>
</body>
</html>

401
style.css
View File

@ -1,401 +0,0 @@
html {
font-size: 10px;
}
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.42857143;
color: #000;
background-color: #eee;
margin: 0;
padding: 0;
}
h2 {
border: 1px solid #aaa;
padding: 10px;
border-radius: 5px;
background: #aaa;
padding-left: 3%;
}
.top-menu {
background-color: #222;
min-height: 50px;
margin-bottom: 20px;
top: 0;
position: fixed;
right: 0;
left: 0;
z-index: 1000;
}
.logoText {
color: #fff;
font-size: 30px;
float: left;
margin-left: 50px;
margin-top: 3px;
font-style: italic;
font-weight: bold;
}
.top-menu img {
max-width: 125px;
float: left;
padding-left: 20px;
}
.top-menu a, .footer a {
padding: 10px;
margin-top: 10px;
padding-left: 7px;
padding-right: 7px;
}
.top-link {
margin-top: 15px;
}
.top-link, .footer-link {
margin-left: 30%;
}
.conteiner {
clear: both;
margin-top: 65px;
min-height: calc(100vh - 115px);
max-width: 50%;
min-width: 40%;
background-color: #fff;
margin-left: 25%;
}
.configShow, .diff {
margin-left: 16%;
height: 70%;
overflow: auto;
width: 70%;
border: 1px solid #DCDCDC;
border-radius: 5px;
}
.diffHead {
background-color: #F5F5F5;
padding: 10px;
}
.lineDog {
background-color: #dbedff;
margin-bottom: 10px;
}
.lineDiffMinus, .lineDiffPlus {
padding-left: 5px;
}
.lineDiffMinus {
background-color: #ffdce0;
}
.lineDiffPlus {
background-color: #cdffd8;
}
.lineDiff {
padding-left: 5px;
}
.param {
font-weight: bold;
background-color: #DCDCDC;
padding-left: 13px;
}
.numRow {
padding-left: 10px;
padding-right: 20px;
}
.paramInSec {
font-weight: bold;
}
.conteinerIndex {
width: 20%;
background-color: #fff;
padding: 20px;
border-radius: 10px;
margin-top: 2%;
}
.conteinerIndex img {
max-width: 250px;
}
.copyright {
color: #23527c;
margin-left: 15px;
}
.line {
background-color: #eee;
border: 1px solid #000;
}
.line, .line3 {
padding-top:5px;
padding-bottom: 5px;
padding-left: 10px;
padding-right: 10px;
}
.comment {
color: #aaa;
}
.addName {
background-color: #eee;
width: 120px;
}
.addOption, .addName {
border: 1px solid #ddd;
padding: 15px;
}
.addButton {
padding-top: 15px;
}
.addSuc {
padding-left: 20px;
padding-top: 20px;
color: #23527c;
}
.tooltip {
font-size: 12px;
padding-bottom: 10px;
}
.tooltipTop {
margin-bottom: -20px;
padding-top: 10px;
}
.footer {
background-color: #222;
min-height: 50px;
top: 0;
right: 0;
left: 0;
}
.overview {
width: 100%;
}
.overview tr{
border: 1px solid #ddd;
border-radius: 5px;
}
.overviewTd {
padding-left: 5%;
padding-top: 20px;
border-color: #ddd;
}
.overviewTr {
margin: 0;
background-color: #eee;
padding-left: 15px;
font-size: 15px;
}
.footer-link {
padding-top: 15px;
}
.ro {
border: none;
}
.menu {
margin-left: 13%;
font-weight: bold;
font-style: italic;
margin-top: -10px;
}
.menu ul li{
padding: 10px;
}
.menu ul > li:hover{
background-color: #333;
}
.menu ul ul > li:hover{
background-color: #69e;
}
.menu ul li, .menu ul{
display: inline-block;
}
.menu ul{
position: relative;
margin: 0;
padding: 0;
background-color: #222222;
}
.menu ul ul{
display: none;
position: absolute;
background-color: #007FFF;
margin-top: 10px;
margin-left: -10px;
}
.menu ul a{
color: #fff;
text-decoration: none;
}
.menu ul ul a{
color: #fff;
text-decoration: none;
}
.menu li:hover ul{
display: block;
}
.menu li:hover li{
display: block;
}
a {
background-color: transparent;
}
a:active,
a:hover {
outline: 0;
}
abbr[title] {
border-bottom: 1px dotted;
}
b,
strong {
font-weight: bold;
}
button,
input,
optgroup,
select,
textarea {
margin: 0;
font: inherit;
color: inherit;
//background-color: #ccc;
border-radius: 7px;
padding: 5px;
}
button {
overflow: visible;
}
button,
select {
text-transform: none;
//background-color: #eee;
}
select {
color: #000;
}
button {
background-color: #337ab7;
border-color: #2e6da4;
color: #fff;
}
button,
html input[type="button"],
input[type="reset"],
input[type="submit"] {
-webkit-appearance: button;
cursor: pointer;
}
button[disabled],
html input[disabled] {
cursor: default;
}
button::-moz-focus-inner,
input::-moz-focus-inner {
padding: 0;
border: 0;
}
input {
line-height: normal;
border-radius: 4px;
padding: 4px;
}
fieldset {
padding: .35em .625em .75em;
margin: 0 2px;
border: 1px solid #c0c0c0;
}
legend {
padding: 0;
border: 0;
}
optgroup {
font-weight: bold;
}
table {
border-spacing: 0;
border-collapse: collapse;
}
td,
th {
padding: 0;
}
a,
a:visited {
text-decoration: underline;
}
#a[href]:after {
# content: " (" attr(href) ")";
# }
#abbr[title]:after {
# content: " (" attr(title) ")";
# }
#a[href^="#"]:after,
#a[href^="javascript:"]:after {
# content: "";
# }
a {
#color: #337ab7;
color: #9d9d9d;
text-decoration: none;
}
a:hover,
a:focus {
color: #23527c;
text-decoration: underline;
}
a:focus {
outline: 5px auto -webkit-focus-ring-color;
outline-offset: -2px;
}
.container {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
.container-fluid {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
.row {
margin-right: -15px;
margin-left: -15px;
}
table {
background-color: transparent;
}
caption {
padding-top: 8px;
padding-bottom: 8px;
color: #777;
text-align: left;
}
th {
text-align: left;
}
fieldset {
min-width: 0;
padding: 0;
margin: 0;
border: 0;
}
legend {
display: block;
width: 100%;
padding: 0;
margin-bottom: 20px;
font-size: 21px;
line-height: inherit;
color: #333;
border: 0;
border-bottom: 1px solid #e5e5e5;
}
label {
display: inline-block;
max-width: 100%;
margin-bottom: 5px;
font-weight: bold;
}