SSH port
pull/42/head
Aidaho12 2018-09-01 16:43:25 +06:00
parent f0564e4744
commit ca1d564294
11 changed files with 98 additions and 475 deletions

View File

@ -84,6 +84,12 @@ def create_table(**kwargs):
`hostname` VARCHAR ( 64 ) UNIQUE, `hostname` VARCHAR ( 64 ) UNIQUE,
`ip` VARCHAR ( 64 ) UNIQUE, `ip` VARCHAR ( 64 ) UNIQUE,
`groups` VARCHAR ( 64 ), `groups` VARCHAR ( 64 ),
type_ip INTEGER NOT NULL DEFAULT 0,
enable INTEGER NOT NULL DEFAULT 1,
master INTEGER NOT NULL DEFAULT 0,
cred INTEGER NOT NULL DEFAULT 1,
alert INTEGER NOT NULL DEFAULT 0,
metrics INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY(`id`) PRIMARY KEY(`id`)
); );
CREATE TABLE IF NOT EXISTS `roles_users` ( CREATE TABLE IF NOT EXISTS `roles_users` (
@ -109,36 +115,35 @@ def create_table(**kwargs):
PRIMARY KEY(`id`) PRIMARY KEY(`id`)
); );
INSERT INTO `groups` (name, description) VALUES ('All','All servers enter in this group'); INSERT INTO `groups` (name, description) VALUES ('All','All servers enter in this group');
CREATE TABLE IF NOT EXISTS `servers` (
`id` INTEGER NOT NULL,
`hostname` VARCHAR ( 64 ) UNIQUE,
`ip` VARCHAR ( 64 ) UNIQUE,
`groups` VARCHAR ( 64 ),
PRIMARY KEY(`id`)
);
CREATE TABLE IF NOT EXISTS `uuid` ( CREATE TABLE IF NOT EXISTS `uuid` (
`user_id` INTEGER NOT NULL, `user_id` INTEGER NOT NULL,
`uuid` varchar ( 64 ) `uuid` varchar ( 64 )
); );
CREATE TABLE IF NOT EXISTS `cred` ( CREATE TABLE IF NOT EXISTS `cred` (
`id` integer primary key autoincrement, `id` integer primary key autoincrement,
`name` VARCHAR ( 64 ) UNIQUE,
`enable` INTEGER NOT NULL DEFAULT 1, `enable` INTEGER NOT NULL DEFAULT 1,
`username` VARCHAR ( 64 ) NOT NULL, `username` VARCHAR ( 64 ) NOT NULL,
`password` VARCHAR ( 64 ) NOT NULL `password` VARCHAR ( 64 ) NOT NULL,
groups INTEGER NOT NULL DEFAULT 1
); );
CREATE TABLE IF NOT EXISTS `token` ( CREATE TABLE IF NOT EXISTS `token` (
`user_id` INTEGER, `user_id` INTEGER,
`token` varchar(64), `token` varchar(64),
`exp` DATETIME default '0000-00-00 00:00:00' `exp` DATETIME default '0000-00-00 00:00:00'
); );
CREATE TABLE IF NOT EXISTS `uuid` (`user_id` INTEGER NOT NULL, `uuid` varchar ( 64 ),`exp` timestamp default '0000-00-00 00:00:00');
CREATE TABLE IF NOT EXISTS `token` (`user_id` INTEGER, `token` varchar(64), `exp` timestamp default '0000-00-00 00:00:00');
CREATE TABLE IF NOT EXISTS `telegram` (`id` integer primary key autoincrement, `token` VARCHAR ( 64 ), `chanel_name` INTEGER NOT NULL DEFAULT 1, `groups` INTEGER NOT NULL DEFAULT 1);
CREATE TABLE IF NOT EXISTS `metrics` (`serv` varchar(64), curr_con INTEGER, cur_ssl_con INTEGER, sess_rate INTEGER, max_sess_rate INTEGER,`date` timestamp default '0000-00-00 00:00:00');
CREATE TABLE IF NOT EXISTS `settings` (`param` varchar(64) UNIQUE, value varchar(64), section varchar(64), `desc` varchar(100));
""" """
try: try:
cur.executescript(sql) cur.executescript(sql)
except sqltool.Error as e: except sqltool.Error as e:
if kwargs.get('silent') != 1: if kwargs.get('silent') != 1:
if e.args[0] == 'column email is not unique' or e == "1060 (42S21): column email is not unique' ": if e.args[0] == 'column email is not unique' or e == "1060 (42S21): column email is not unique' ":
print('Updating... go to version 2.0.1<br />') print('Updating... go to version 3.0<br />')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
return False return False
@ -158,377 +163,9 @@ def create_table(**kwargs):
cur.close() cur.close()
con.close() con.close()
def update_db_v_2_0_1(**kwargs):
con, cur = get_cur()
sql = """
ALTER TABLE `servers` ADD COLUMN type_ip INTEGER NOT NULL DEFAULT 0;
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: type_ip' or e == " 1060 (42S21): Duplicate column name 'type_ip' ":
print('Updating... go to version 2.0.1.1<br />')
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 2.0.1<br />")
return True
cur.close()
con.close()
def update_db_v_2_0_1_1(**kwargs):
con, cur = get_cur()
sql = """
ALTER TABLE `servers` ADD COLUMN enable INTEGER NOT NULL DEFAULT 1;
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: enable' or e == "1060 (42S21): Duplicate column name 'enable' ":
print('Updating... go to version 2.0.5<br />')
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 2.0.1.1<br />")
return True
cur.close()
con.close()
def update_db_v_2_0_5(**kwargs):
con, cur = get_cur()
sql = """
ALTER TABLE `servers` ADD COLUMN master INTEGER NOT NULL DEFAULT 0;
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: master' or e == "1060 (42S21): Duplicate column name 'master' ":
print('Updating... go to version 2.4<br />')
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 2.0.5<br />")
return True
cur.close()
con.close()
def update_db_v_2_4(**kwargs):
con, cur = get_cur()
sql = """
CREATE TABLE IF NOT EXISTS `uuid` (`user_id` INTEGER NOT NULL, `uuid` varchar ( 64 ) );
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
print(kwargs.get('silent'))
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: user_id' or e == "1060 (42S21): Duplicate column name 'user_id' ":
print('Updating... go to version 2.5.3')
else:
print("An error occurred:", e)
return False
else:
if kwargs.get('silent') != 1:
print("DB was update to 2.4 <br />")
return True
cur.close()
con.close()
def update_db_v_2_5_6(**kwargs):
con, cur = get_cur()
if mysql_enable == '1':
sql = """
ALTER TABLE `uuid` ADD COLUMN `exp` timestamp default '0000-00-00 00:00:00';
"""
else:
sql = """
ALTER TABLE `uuid` ADD COLUMN `exp` DATETIME default '0000-00-00 00:00:00';
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: exp' or e == " 1060 (42S21): Duplicate column name 'exp' ":
print('Updating... go to version 2.5.6.1')
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 2.5.6.1<br />")
return True
cur.close()
con.close()
def update_db_v_2_5_6_1(**kwargs):
con, cur = get_cur()
if mysql_enable == '1':
sql = """
CREATE TABLE IF NOT EXISTS `token` (`user_id` INTEGER, `token` varchar(64), `exp` timestamp default '0000-00-00 00:00:00');
"""
else:
sql = """
CREATE TABLE IF NOT EXISTS `token` (`user_id` INTEGER, `token` varchar(64), `exp` DATETIME default '0000-00-00 00:00:00');
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: token' or e == "1060 (42S21): Duplicate column name 'token' ":
print('Updating... go to version 2.6')
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 2.5.6.1<br />")
return True
cur.close()
con.close()
def update_db_v_2_6(**kwargs):
con, cur = get_cur()
sql = """ select name from cred limit 1 """
try:
cur.execute(sql)
except sqltool.Error as e:
if mysql_enable == '0':
sql = """ CREATE TABLE IF NOT EXISTS `cred_id` (
`id` integer primary key autoincrement,
`name` VARCHAR ( 64 ) UNIQUE,
`enable` INTEGER NOT NULL DEFAULT 1,
`username` VARCHAR ( 64 ) NOT NULL,
`password` VARCHAR ( 64 ) NOT NULL
);
INSERT INTO cred_id (id, enable, username, password) select id, enable, username, password from cred;
drop table cred;
ALTER TABLE cred_id RENAME to cred;
"""
try:
cur.executescript(sql)
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: name' or e == "1060 (42S21): Duplicate column name 'name' ":
pass
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 2.6<br />")
return True
else:
sql = [ "CREATE TABLE IF NOT EXISTS cred_id(`id` integer primary key AUTO_INCREMENT, `name` VARCHAR ( 64 ) UNIQUE, `enable` INTEGER NOT NULL DEFAULT 1, `username` VARCHAR ( 64 ) NOT NULL, `password` VARCHAR ( 64 ) NOT NULL ); ",
"INSERT INTO cred_id (enable, username, password) select enable, username, password from cred;",
"drop table cred;",
"ALTER TABLE cred_id RENAME to cred;" ]
try:
for i in sql:
cur.execute(i)
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: id' or e == "1060 (42S21): Duplicate column name 'id' ":
print('DB was updated. No more run')
else:
print("An error occurred:", e)
return False
else:
pass
return True
cur.close()
con.close()
def update_db_v_2_61(**kwargs):
con, cur = get_cur()
sql = """
ALTER TABLE `servers` ADD COLUMN cred INTEGER NOT NULL DEFAULT 1;
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: cred' or e == "1060 (42S21): Duplicate column name 'cred' ":
print('Updating... go to version 2.6.1')
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 2.6<br />")
return True
cur.close()
con.close()
def update_db_v_2_6_1(**kwargs):
con, cur = get_cur()
sql = """
ALTER TABLE `cred` ADD COLUMN groups INTEGER NOT NULL DEFAULT 1;
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: groups' or e == "1060 (42S21): Duplicate column name 'groups' ":
print('Updating... go to version 2.7')
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 2.6.1<br />")
return True
cur.close()
con.close()
def update_db_v_2_7(**kwargs):
con, cur = get_cur()
sql = """
ALTER TABLE `servers` ADD COLUMN alert INTEGER NOT NULL DEFAULT 0;
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: alert' or e == "1060 (42S21): Duplicate column name 'groups' ":
print('Updating... go to version 2.7.2')
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 2.7.2<br />")
return True
cur.close()
con.close()
def update_db_v_2_7_2(**kwargs):
con, cur = get_cur()
if mysql_enable == '0':
sql = """ CREATE TABLE IF NOT EXISTS `telegram` (`id` integer primary key autoincrement, `token` VARCHAR ( 64 ), `chanel_name` INTEGER NOT NULL DEFAULT 1, `groups` INTEGER NOT NULL DEFAULT 1); """
else:
sql = """ CREATE TABLE IF NOT EXISTS `telegram` (`id` integer primary key auto_increment, `token` VARCHAR ( 64 ), `chanel_name` INTEGER NOT NULL DEFAULT 1, `groups` INTEGER NOT NULL DEFAULT 1); """
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: telegram' or e == "1060 (42S21): Duplicate column name 'telegram' ":
print("Update finished. No run more")
else:
print("An error occurred:", e)
return False
else:
return True
cur.close()
con.close()
def update_db_v_2_8(**kwargs):
con, cur = get_cur()
sql = """CREATE TABLE IF NOT EXISTS `metrics` (`serv` varchar(64), curr_con INTEGER, cur_ssl_con INTEGER, sess_rate INTEGER, max_sess_rate INTEGER,`date` DATETIME default '0000-00-00 00:00:00'); """
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: token' or e == "1060 (42S21): Duplicate column name 'token' ":
print('Updating... go to version 2.6')
else:
print("An error occurred:", e.args[0])
return False
else:
return True
cur.close()
con.close()
def update_db_v_2_8_2(**kwargs):
con, cur = get_cur()
sql = """ ALTER TABLE `servers` ADD COLUMN metrics INTEGER NOT NULL DEFAULT 0 """
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: metrics' or e == "1060 (42S21): Duplicate column name 'metrics' ":
print('DB was update to 2.8')
else:
print("An error occurred:", e)
return False
else:
#print("DB was update to 2.8<br />")
return True
cur.close()
con.close()
def update_db_v_2_9(**kwargs):
con, cur = get_cur()
sql = """CREATE TABLE IF NOT EXISTS `settings` (`param` varchar(64) UNIQUE, value varchar(64)); """
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: token' or e == "1060 (42S21): Duplicate column name 'token' ":
print('Updating... go to version 2.10')
else:
print("An error occurred:", e.args[0])
return False
else:
return True
cur.close()
con.close()
def update_db_v_2_91(**kwargs):
con, cur = get_cur()
sql = """
insert into `settings` (param, value) values ('lists_path', 'lists');
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'column param is not unique' or e == "1062 (23000): Duplicate entry 'lists_path' for key 'param'":
print('Updating... go to version 3.0')
else:
print("An error occurred:", e)
return False
else:
print("Updating... go to version 3.0<br />")
return True
cur.close()
con.close()
def update_db_v_3(**kwargs):
con, cur = get_cur()
sql = """
ALTER TABLE `settings` ADD COLUMN section varchar(64);
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: section' or e == " 1060 (42S21): Duplicate column name 'section' ":
print('Updating... go to version 3.1')
else:
print("An error occurred:", e)
return False
cur.close()
con.close()
def update_db_v_31(**kwargs): def update_db_v_31(**kwargs):
con, cur = get_cur() con, cur = get_cur()
sql = [ "ALTER TABLE `settings` ADD COLUMN `desc` varchar(100); ", sql = [ "INSERT INTO settings (param, value, section, `desc`) values('time_zone', 'UTC', 'main', 'Time Zone');",
"INSERT INTO settings (param, value, section, `desc`) values('time_zone', 'UTC', 'main', 'Time Zone');",
"INSERT INTO settings (param, value, section, `desc`) values('proxy', '', 'main', 'Proxy server. Use proto://ip:port');", "INSERT INTO settings (param, value, section, `desc`) values('proxy', '', 'main', 'Proxy server. Use proto://ip:port');",
"INSERT INTO settings (param, value, section, `desc`) values('session_ttl', '5', 'main', 'Time to live users sessions. In days');", "INSERT INTO settings (param, value, section, `desc`) values('session_ttl', '5', 'main', 'Time to live users sessions. In days');",
"INSERT INTO settings (param, value, section, `desc`) values('token_ttl', '5', 'main', 'Time to live users tokens. In days');", "INSERT INTO settings (param, value, section, `desc`) values('token_ttl', '5', 'main', 'Time to live users tokens. In days');",
@ -550,7 +187,8 @@ def update_db_v_31(**kwargs):
"INSERT INTO settings (param, value, section, `desc`) values('tmp_config_path', '/tmp/', 'haproxy', 'Temp store configs, for haproxy check');", "INSERT INTO settings (param, value, section, `desc`) values('tmp_config_path', '/tmp/', 'haproxy', 'Temp store configs, for haproxy check');",
"INSERT INTO settings (param, value, section, `desc`) values('cert_path', '/etc/ssl/certs/', 'haproxy', 'Path to SSL dir');", "INSERT INTO settings (param, value, section, `desc`) values('cert_path', '/etc/ssl/certs/', 'haproxy', 'Path to SSL dir');",
"INSERT INTO settings (param, value, section, `desc`) values('firewall_enable', '0', 'haproxy', 'If enable this option Haproxy-wi will be configure firewalld based on config port');", "INSERT INTO settings (param, value, section, `desc`) values('firewall_enable', '0', 'haproxy', 'If enable this option Haproxy-wi will be configure firewalld based on config port');",
"update settings set `section` = 'main', `desc` = 'Path to black/white lists' where param = 'lists_path' "] "INSERT INTO settings (param, value, section, `desc`) values('lists_path', 'lists', 'main', 'Path to black/white lists', 'lists_path');",
"INSERT INTO settings (param, value, section, `desc`) values ('apache_log_path', '/var/log/httpd/', 'logs', 'Path to Apache logs');" ]
try: try:
for i in sql: for i in sql:
cur.execute(i) cur.execute(i)
@ -604,68 +242,40 @@ def update_db_v_3_21(**kwargs):
cur.close() cur.close()
con.close() con.close()
def update_db_v_3_2_1(**kwargs): def update_db_v_3_2_3(**kwargs):
con, cur = get_cur() con, cur = get_cur()
sql = """ sql = """
insert into `settings` (param, value, section, `desc`) values ('apache_log_path', '/var/log/httpd/', 'logs', 'Path to Apache logs'); ALTER TABLE `servers` ADD COLUMN port INTEGER NOT NULL DEFAULT 22;
""" """
try: try:
cur.execute(sql) cur.execute(sql)
con.commit() con.commit()
except sqltool.Error as e: except sqltool.Error as e:
if kwargs.get('silent') != 1: if kwargs.get('silent') != 1:
if e.args[0] == 'column param is not unique' or e == "1062 (23000): Duplicate entry 'lists_path' for key 'param'": if e.args[0] == 'duplicate column name: port' or e == " 1060 (42S21): Duplicate column name 'port' ":
print('DB was update') print('DB was update<br />')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
return False return False
else: else:
print("Updating... go to version 3.0<br />") print("DB was update to 3.2.3<br />")
return True return True
cur.close() cur.close()
con.close() con.close()
def update_all(): def update_all():
update_db_v_2_0_1()
update_db_v_2_0_1_1()
update_db_v_2_0_5()
update_db_v_2_4()
update_db_v_2_5_6()
update_db_v_2_5_6_1()
update_db_v_2_6()
update_db_v_2_61()
update_db_v_2_6_1()
update_db_v_2_7()
update_db_v_2_7_2()
update_db_v_2_8()
update_db_v_2_8_2()
update_db_v_2_9()
update_db_v_2_91()
update_db_v_3()
update_db_v_31() update_db_v_31()
update_db_v_3_2() update_db_v_3_2()
update_db_v_3_21() update_db_v_3_21()
update_db_v_3_2_1() update_db_v_3_2_3()
def update_all_silent(): def update_all_silent():
update_db_v_2_0_1(silent=1)
update_db_v_2_0_1_1(silent=1)
update_db_v_2_0_5(silent=1)
update_db_v_2_4(silent=1)
update_db_v_2_5_6(silent=1)
update_db_v_2_5_6_1(silent=1)
update_db_v_2_6(silent=1)
update_db_v_2_61(silent=1)
update_db_v_2_6_1(silent=1)
update_db_v_2_7(silent=1)
update_db_v_2_7_2(silent=1)
update_db_v_2_8(silent=1)
update_db_v_2_8_2(silent=1)
update_db_v_2_9(silent=1)
update_db_v_2_91(silent=1)
update_db_v_3(silent=1)
update_db_v_31(silent=1) update_db_v_31(silent=1)
update_db_v_3_2(silent=1) update_db_v_3_2(silent=1)
update_db_v_3_21(silent=1) update_db_v_3_21(silent=1)
update_db_v_3_2_1(silent=1) update_db_v_3_2_3(silent=1)
if __name__ == "__main__":
create_table()
update_all()

View File

@ -159,15 +159,19 @@ def ssh_connect(serv, **kwargs):
ssh_user_name = sshs[4] ssh_user_name = sshs[4]
ssh_user_password = sshs[5] ssh_user_password = sshs[5]
ssh_key_name = fullpath+'/keys/%s.pem' % sshs[2] ssh_key_name = fullpath+'/keys/%s.pem' % sshs[2]
servers = sql.select_servers(server=serv)
for server in servers:
ssh_port = server[10]
ssh = SSHClient() ssh = SSHClient()
ssh.load_system_host_keys() ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try: try:
if ssh_enable == 1: if ssh_enable == 1:
k = paramiko.RSAKey.from_private_key_file(ssh_key_name) k = paramiko.RSAKey.from_private_key_file(ssh_key_name)
ssh.connect(hostname = serv, username = ssh_user_name, pkey = k ) ssh.connect(hostname = serv, port = ssh_port, username = ssh_user_name, pkey = k)
else: else:
ssh.connect(hostname = serv, username = ssh_user_name, password = ssh_user_password) ssh.connect(hostname = serv, port = ssh_port, username = ssh_user_name, password = ssh_user_password)
if kwargs.get('check'): if kwargs.get('check'):
return True return True
else: else:
@ -196,9 +200,9 @@ def ssh_connect(serv, **kwargs):
except Exception as e: except Exception as e:
if e == "No such file or directory": if e == "No such file or directory":
if kwargs.get('check'): if kwargs.get('check'):
print('<div class="alert alert-danger">{}. Check ssh key</div>'.format(e)) print('<div class="alert alert-danger">%s. Check ssh key</div>') % e
else: else:
return '{}. Check ssh key'.format(e) return '%s. Check ssh key' % e
pass pass
elif e == "Invalid argument": elif e == "Invalid argument":
if kwargs.get('check'): if kwargs.get('check'):
@ -208,7 +212,7 @@ def ssh_connect(serv, **kwargs):
pass pass
else: else:
if kwargs.get('check'): if kwargs.get('check'):
print('<div class="alert alert-danger">{}</div>'.format(e)) print('<div class="alert alert-danger">%s</div>') % e
else: else:
error = e error = e
pass pass
@ -232,7 +236,7 @@ def get_config(serv, cfg, **kwargs):
sftp.close() sftp.close()
ssh.close() ssh.close()
except Exception as e: except Exception as e:
ssh += str(e) ssh = str(e)
return ssh return ssh
def diff_config(oldcfg, cfg): def diff_config(oldcfg, cfg):
@ -465,6 +469,7 @@ def ssh_command(serv, commands, **kwargs):
try: try:
ssh.close() ssh.close()
except: except:
ssh = str(ssh)
print("<div class='alert alert-danger'>"+ssh+"</div>") print("<div class='alert alert-danger'>"+ssh+"</div>")
pass pass

View File

@ -2,7 +2,7 @@ CREATE TABLE IF NOT EXISTS `user` (`id` INTEGER NOT NULL AUTO_INCREMENT,`usernam
INSERT INTO `user` (username, email, password, role, groups) VALUES ('admin','admin@localhost','admin','admin','1'); INSERT INTO `user` (username, email, password, role, groups) VALUES ('admin','admin@localhost','admin','admin','1');
INSERT INTO `user` (username, email, password, role, groups) VALUES ('editor','editor@localhost','editor','editor','1'); INSERT INTO `user` (username, email, password, role, groups) VALUES ('editor','editor@localhost','editor','editor','1');
INSERT INTO `user` (username, email, password, role, groups) VALUES ('guest','guest@localhost','guest','guest','1'); INSERT INTO `user` (username, email, password, role, groups) VALUES ('guest','guest@localhost','guest','guest','1');
CREATE TABLE IF NOT EXISTS `servers` (`id` INTEGER NOT NULL AUTO_INCREMENT,`hostname` VARCHAR ( 64 ) UNIQUE,`ip` VARCHAR ( 64 ) UNIQUE,`groups` VARCHAR ( 64 ),PRIMARY KEY(`id`) ); CREATE TABLE IF NOT EXISTS `servers` (`id` INTEGER NOT NULL AUTO_INCREMENT,`hostname` VARCHAR ( 64 ) UNIQUE,`ip` VARCHAR ( 64 ) UNIQUE,`groups` VARCHAR ( 64 ), type_ip INTEGER NOT NULL DEFAULT 0, enable INTEGER NOT NULL DEFAULT 1, master INTEGER NOT NULL DEFAULT 0, cred INTEGER NOT NULL DEFAULT 1, alert INTEGER NOT NULL DEFAULT 0, metrics INTEGER NOT NULL DEFAULT 0PRIMARY KEY(`id`) );
CREATE TABLE IF NOT EXISTS `role` (`id` INTEGER NOT NULL AUTO_INCREMENT,`name` VARCHAR ( 80 ) UNIQUE,`description` VARCHAR ( 255 ),PRIMARY KEY(`id`) ); CREATE TABLE IF NOT EXISTS `role` (`id` INTEGER NOT NULL AUTO_INCREMENT,`name` VARCHAR ( 80 ) UNIQUE,`description` VARCHAR ( 255 ),PRIMARY KEY(`id`) );
INSERT INTO `role` (name, description) VALUES ('admin','Can do everything'); INSERT INTO `role` (name, description) VALUES ('admin','Can do everything');
INSERT INTO `role` (name, description) VALUES ('editor','Can edit configs'); INSERT INTO `role` (name, description) VALUES ('editor','Can edit configs');
@ -10,7 +10,10 @@ INSERT INTO `role` (name, description) VALUES ('guest','Read only access');
CREATE TABLE IF NOT EXISTS `groups` (`id` INTEGER NOT NULL AUTO_INCREMENT,`name` VARCHAR ( 80 ) UNIQUE,`description` VARCHAR ( 255 ),PRIMARY KEY(`id`)); CREATE TABLE IF NOT EXISTS `groups` (`id` INTEGER NOT NULL AUTO_INCREMENT,`name` VARCHAR ( 80 ) UNIQUE,`description` VARCHAR ( 255 ),PRIMARY KEY(`id`));
INSERT INTO `groups` (name, description) VALUES ('All','All servers enter in this group'); INSERT INTO `groups` (name, description) VALUES ('All','All servers enter in this group');
CREATE TABLE IF NOT EXISTS `servers` (`id` INTEGER NOT NULL AUTO_INCREMENT,`hostname` VARCHAR ( 64 ) UNIQUE,`ip` VARCHAR ( 64 ) UNIQUE,`groups` VARCHAR ( 64 ), PRIMARY KEY(`id`)); CREATE TABLE IF NOT EXISTS `servers` (`id` INTEGER NOT NULL AUTO_INCREMENT,`hostname` VARCHAR ( 64 ) UNIQUE,`ip` VARCHAR ( 64 ) UNIQUE,`groups` VARCHAR ( 64 ), PRIMARY KEY(`id`));
CREATE TABLE IF NOT EXISTS `uuid` (`user_id` INTEGER NOT NULL, `uuid` varchar ( 64 ) ); CREATE TABLE IF NOT EXISTS `uuid` (`user_id` INTEGER NOT NULL, `uuid` varchar ( 64 ),`exp` DATETIME default '0000-00-00 00:00:00');
CREATE TABLE IF NOT EXISTS `cred` (`id` integer primary key AUTO_INCREMENT,`enable` INTEGER NOT NULL DEFAULT 1, `username` VARCHAR ( 64 ) NOT NULL, `password` VARCHAR ( 64 ) NOT NULL ); CREATE TABLE IF NOT EXISTS `cred` (`id` integer primary key AUTO_INCREMENT,`enable` INTEGER NOT NULL DEFAULT 1, `username` VARCHAR ( 64 ) NOT NULL, `password` VARCHAR ( 64 ) NOT NULL );
insert into cred('enable','username','password') values ('1', 'root','password');
CREATE TABLE IF NOT EXISTS `token` (`user_id` INTEGER, `token` varchar(64), `exp` timestamp default '0000-00-00 00:00:00'); CREATE TABLE IF NOT EXISTS `token` (`user_id` INTEGER, `token` varchar(64), `exp` timestamp default '0000-00-00 00:00:00');
CREATE TABLE IF NOT EXISTS `cred` (`id` integer primary key AUTO_INCREMENT, `name` VARCHAR ( 64 ) UNIQUE, `enable` INTEGER NOT NULL DEFAULT 1, `username` VARCHAR ( 64 ) NOT NULL, `password` VARCHAR ( 64 ) NOT NULL, groups INTEGER NOT NULL DEFAULT 1 );
CREATE TABLE IF NOT EXISTS `telegram` (`id` integer primary key auto_increment, `token` VARCHAR ( 64 ), `chanel_name` INTEGER NOT NULL DEFAULT 1, `groups` INTEGER NOT NULL DEFAULT 1);
CREATE TABLE IF NOT EXISTS `metrics` (`serv` varchar(64), curr_con INTEGER, cur_ssl_con INTEGER, sess_rate INTEGER, max_sess_rate INTEGER,`date` DATETIME default '0000-00-00 00:00:00');
CREATE TABLE IF NOT EXISTS `settings` (`param` varchar(64) UNIQUE, value varchar(64), section varchar(64), `desc` varchar(100));

View File

@ -143,7 +143,7 @@ def delete_server(id):
cur.close() cur.close()
con.close() con.close()
def update_server(hostname, ip, group, typeip, enable, master, id, cred, alert, metrics): def update_server(hostname, ip, group, typeip, enable, master, id, cred, alert, metrics, port):
con, cur = create_db.get_cur() con, cur = create_db.get_cur()
sql = """update servers set sql = """update servers set
hostname = '%s', hostname = '%s',
@ -154,8 +154,9 @@ def update_server(hostname, ip, group, typeip, enable, master, id, cred, alert,
master = '%s', master = '%s',
cred = '%s', cred = '%s',
alert = '%s', alert = '%s',
metrics = '%s' metrics = '%s',
where id = '%s'""" % (hostname, ip, group, typeip, enable, master, cred, alert, metrics, id) port = '%s'
where id = '%s'""" % (hostname, ip, group, typeip, enable, master, cred, alert, metrics, port, id)
try: try:
cur.execute(sql) cur.execute(sql)
con.commit() con.commit()
@ -1199,12 +1200,13 @@ if form.getvalue('updateserver') is not None:
cred = form.getvalue('cred') cred = form.getvalue('cred')
alert = form.getvalue('alert_en') alert = form.getvalue('alert_en')
metrics = form.getvalue('metrics') metrics = form.getvalue('metrics')
port = form.getvalue('port')
print('Content-type: text/html\n') print('Content-type: text/html\n')
if name is None or ip is None: if name is None or ip is None:
print(error_mess) print(error_mess)
else: else:
#if funct.ssh_connect(ip, check=1): #if funct.ssh_connect(ip, check=1):
update_server(name, ip, group, typeip, enable, master, id, cred, alert, metrics) update_server(name, ip, group, typeip, enable, master, id, cred, alert, metrics, port)
#else: #else:
# print('<span class="alert alert-danger" id="error"><a title="Close" id="errorMess"><b>X</b></a></span>') # print('<span class="alert alert-danger" id="error"><a title="Close" id="errorMess"><b>X</b></a></span>')

View File

@ -161,6 +161,7 @@
<tr class="overviewHead"> <tr class="overviewHead">
<td class="padding10 first-collumn">Hostname</td> <td class="padding10 first-collumn">Hostname</td>
<td>IP</td> <td>IP</td>
<td><span title="SSH port">Port(?)</span></td></td>
<td>Group</td> <td>Group</td>
<td>Enable</td> <td>Enable</td>
<td><span title="Vitrual IP, something like VRRP">Virt(?)</span></td> <td><span title="Vitrual IP, something like VRRP">Virt(?)</span></td>
@ -179,6 +180,9 @@
<td> <td>
<input type="text" id="ip-{{server.0}}" value="{{server.2}}" class="form-control"> <input type="text" id="ip-{{server.0}}" value="{{server.2}}" class="form-control">
</td> </td>
<td>
<input type="text" id="port-{{server.0}}" value="{{server.10}}" size="1" class="form-control">
</td>
<td> <td>
<select id="servergroup-{{server.0}}" name="servergroup-{{server.0}}"> <select id="servergroup-{{server.0}}" name="servergroup-{{server.0}}">
<option disabled selected>Choose group</option> <option disabled selected>Choose group</option>
@ -255,6 +259,7 @@
<tr class="overviewHead"> <tr class="overviewHead">
<td class="padding10 first-collumn">New hostname</td> <td class="padding10 first-collumn">New hostname</td>
<td>IP</td> <td>IP</td>
<td><span title="SSH port">Port(?)</span></td></td>
<td>Group</td> <td>Group</td>
<td>Enable</td> <td>Enable</td>
<td><span title="Vitrual IP, something like VRRP">Virt(?)</span></td> <td><span title="Vitrual IP, something like VRRP">Virt(?)</span></td>
@ -271,6 +276,9 @@
<td> <td>
<input type="text" name="new-ip" id="new-ip" class="form-control"> <input type="text" name="new-ip" id="new-ip" class="form-control">
</td> </td>
<td>
<input type="text" name="new-port" id="new-port" size=1 class="form-control" value="22">
</td>
<td> <td>
<select id="new-server-group-add" name="new-server-group-add"> <select id="new-server-group-add" name="new-server-group-add">
<option disabled selected value="0">Choose group</option> <option disabled selected value="0">Choose group</option>

View File

@ -9,6 +9,9 @@
<input type="hidden" id="servergroup-{{server.0}}" name="servergroup-{{server.0}}" value="{{ ssh_group.0 }}" > <input type="hidden" id="servergroup-{{server.0}}" name="servergroup-{{server.0}}" value="{{ ssh_group.0 }}" >
{% endif %} {% endif %}
</td> </td>
<td>
<input type="text" id="port-{{server.0}}" value="{{server.10}}" size="1" class="form-control">
</td>
{% if page != "servers.py" %} {% if page != "servers.py" %}
<td> <td>
<select id="servergroup-{{server.0}}" name="servergroup-{{server.0}}"> <select id="servergroup-{{server.0}}" name="servergroup-{{server.0}}">

View File

@ -101,7 +101,7 @@
</ul> </ul>
</nav> </nav>
<div class="copyright-menu"> <div class="copyright-menu">
HAproxy-WI v3.2.3 HAproxy-WI v3.2.4
<br> <br>
<a href="https://www.patreon.com/haproxy_wi" title="Donate" target="_blank" style="color: #fff; margin-left: 30px; color: red;" class="patreon"> Patreon</a> <a href="https://www.patreon.com/haproxy_wi" title="Donate" target="_blank" style="color: #fff; margin-left: 30px; color: red;" class="patreon"> Patreon</a>
</div> </div>

View File

@ -21,6 +21,7 @@
<tr class="overviewHead"> <tr class="overviewHead">
<td class="padding10 first-collumn">Hostname</td> <td class="padding10 first-collumn">Hostname</td>
<td>IP</td> <td>IP</td>
<td><span title="SSH port">Port(?)</span></td></td>
<td>Enable</td> <td>Enable</td>
<td><span title="Vitrual IP, something like VRRP">Virt(?)</span></td> <td><span title="Vitrual IP, something like VRRP">Virt(?)</span></td>
<td><span title="Alert if backend change status. Before enable add Telgram chanel at Checker tab">Alert(?)</span></td> <td><span title="Alert if backend change status. Before enable add Telgram chanel at Checker tab">Alert(?)</span></td>
@ -41,6 +42,9 @@
<input type="hidden" id="new-server-group-add" name="servergroup-{{server.0}}" value="{{ group }}" > <input type="hidden" id="new-server-group-add" name="servergroup-{{server.0}}" value="{{ group }}" >
<input type="hidden" id="servergroup-{{server.0}}" name="servergroup-{{server.0}}" value="{{ group }}" > <input type="hidden" id="servergroup-{{server.0}}" name="servergroup-{{server.0}}" value="{{ group }}" >
</td> </td>
<td>
<input type="text" id="port-{{server.0}}" value="{{server.10}}" size="1" class="form-control">
</td>
<td> <td>
{% if server.5 == 1 %} {% if server.5 == 1 %}
<label for="enable-{{server.0}}"></label><input type="checkbox" id="enable-{{server.0}}" checked> <label for="enable-{{server.0}}"></label><input type="checkbox" id="enable-{{server.0}}" checked>
@ -107,6 +111,7 @@
<tr class="overviewHead"> <tr class="overviewHead">
<td class="padding10 first-collumn">New hostname</td> <td class="padding10 first-collumn">New hostname</td>
<td>IP</td> <td>IP</td>
<td><span title="SSH port">Port(?)</span></td></td>
<td>Enable</td> <td>Enable</td>
<td><span title="Vitrual IP, something like VRRP">Virt(?)</span></td> <td><span title="Vitrual IP, something like VRRP">Virt(?)</span></td>
<td><span title="Alert if backend change status">Alert(?)</span></td> <td><span title="Alert if backend change status">Alert(?)</span></td>
@ -123,6 +128,9 @@
<input type="text" name="new-ip" id="new-ip" class="form-control"> <input type="text" name="new-ip" id="new-ip" class="form-control">
<input type="hidden" id="new-sshgroup" name="new-sshgroup" value="{{ group }}" > <input type="hidden" id="new-sshgroup" name="new-sshgroup" value="{{ group }}" >
</td> </td>
<td>
<input type="text" name="new-port" id="new-port" size=1 class="form-control" value="22">
</td>
<td> <td>
<label for="enable"></label><input type="checkbox" id="enable" checked> <label for="enable"></label><input type="checkbox" id="enable" checked>
</td> </td>

View File

@ -1,16 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-"
import create_db
import funct
mysql_enable = funct.get_config_var('mysql', 'enable')
if mysql_enable == '1':
from mysql.connector import errorcode
import mysql.connector as sqltool
else:
db = "haproxy-wi.db"
import sqlite3 as sqltool
create_db.create_table()
create_db.update_all()

View File

@ -419,7 +419,7 @@ sudo sudo chmod +x /var/www/$HOME_HAPROXY_WI/app/*.py
sudo chmod +x /var/www/$HOME_HAPROXY_WI/app/tools/*.py sudo chmod +x /var/www/$HOME_HAPROXY_WI/app/tools/*.py
cd /var/www/$HOME_HAPROXY_WI/app cd /var/www/$HOME_HAPROXY_WI/app
./update_db.py ./create_db.py
if hash apt-get 2>/dev/null; then if hash apt-get 2>/dev/null; then
sudo chown -R www-data:www-data /var/www/$HOME_HAPROXY_WI/ sudo chown -R www-data:www-data /var/www/$HOME_HAPROXY_WI/
sudo chown -R www-data:www-data /var/log/apache2/ sudo chown -R www-data:www-data /var/log/apache2/

View File

@ -17,7 +17,7 @@ else
fi fi
cd app/ cd app/
./update_db.py ./create_db.py
pip3 install -r ../requirements.txt pip3 install -r ../requirements.txt