Browse Source

v1.4.2

add Telegram messages
pull/19/head
Aidaho12 7 years ago
parent
commit
bc9bb95b28
  1. 1
      README.md
  2. 47
      cgi-bin/funct.py
  3. 20
      haproxy-webintarface.config

1
README.md

@ -20,6 +20,7 @@ For install just dowload archive and untar somewhere:
$ cd /opt
$ unzip master.zip
$ mv haproxy-web-interface-master/ haproxy
$ cd /opt/haproxy
$ pip3 install -r requirements.txt
$ chmod +x server.py
$ chmod +x -R cgi-bin/

47
cgi-bin/funct.py

@ -44,6 +44,19 @@ def logging(serv, action):
log.write(mess)
log.close
if config.get('telegram', 'enable') == "1": telegram_send_mess(mess)
def telegram_send_mess(mess):
import telegram
token_bot = config.get('telegram', 'token')
channel_name = config.get('telegram', 'channel_name')
proxy = config.get('telegram', 'proxy')
if proxy is not None:
pp = telegram.utils.request.Request(proxy_url=proxy)
bot = telegram.Bot(token=token_bot, request=pp)
bot.send_message(chat_id=channel_name, text=mess)
def check_login(ref):
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
login = cookie.get('login')
@ -111,15 +124,22 @@ def footer():
'<div class="footer-link">')
links()
print('</div></div></body></html>')
def get_config(serv, cfg):
os.chdir(hap_configs_dir)
def ssh_connect(serv):
ssh = SSHClient()
ssh.load_system_host_keys()
k = paramiko.RSAKey.from_private_key_file(ssh_keys)
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname = serv, username = ssh_user_name, pkey = k )
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()
@ -167,13 +187,7 @@ def upload_and_restart(serv, cfg):
now_utc = datetime.now(timezone(config.get('main', 'time_zone')))
tmp_file = tmp_config_path + "/" + now_utc.strftime(fmt) + ".cfg"
ssh = SSHClient()
ssh.load_system_host_keys()
k = paramiko.RSAKey.from_private_key_file(ssh_keys)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print("connecting<br />")
ssh.connect( hostname = serv, username = ssh_user_name, pkey = k )
ssh = ssh_connect(serv)
print("connected<br />")
sftp = ssh.open_sftp()
sftp.put(cfg, tmp_file)
@ -250,12 +264,7 @@ def show_ip(stdout):
print(line)
def ssh_command(serv, commands, **kwargs):
ssh = SSHClient()
ssh.load_system_host_keys()
k = paramiko.RSAKey.from_private_key_file(ssh_keys)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect( hostname = serv, username = ssh_user_name, pkey = k )
ssh = ssh_connect(serv)
ip = 0
compare_funct = 0

20
haproxy-webintarface.config

@ -3,7 +3,6 @@
fullpath = /opt/haproxy/
server_bind_ip = 0.0.0.0
server_port = 8000
#Log for server.py
log_path = %(fullpath)s/log/
time_zone = UTC
#Enable logo on top menu. Default disable
@ -17,16 +16,28 @@ haproxy_configs_server = localhost
haproxy_save_configs_dir = /opt/haproxy/cgi-bin/hap_config/
[ssh]
#If ssh connect disable entare password for ssh connect. Default enable
ssh_keys_enable = 1
#SSH keys to connect without password to HAproxy servers
ssh_keys = /opt/haproxy/cgi-bin/id_rsa.pem
#Username for connect ssh
ssh_user_name = root
ssh_pass =
[logs]
#Logs save localy, disable by default
#Logs save locally, disable by default
local_path_logs = /var/log/haproxy.log
#If exist syslog server for HAproxy logs
syslog_server_enable = enable
syslog_server = 172.28.5.112
syslog_server =
[telegram]
#Send log message to telegram channel
#Default bot send message disable
enable = 0
token =
channel_name =
proxy =
[haproxy]
#Command for restart HAproxy service
@ -36,10 +47,7 @@ user = admin
password = password
stats_port = 8085
haproxy_config_path = /etc/haproxy/haproxy.cfg
<<<<<<< HEAD
#Temp store configs, for haproxy check
tmp_config_path = /tmp
#Time in seconds for auto refresh view stats_port
refresh_time = 120

Loading…
Cancel
Save