mirror of https://github.com/Aidaho12/haproxy-wi
parent
64509d1fd4
commit
27024cc58a
26
app/funct.py
26
app/funct.py
|
@ -169,11 +169,11 @@ def logging(server_ip, action, **kwargs):
|
||||||
log = open(log_path + "/roxy-wi-" + get_data('logs') + ".log", "a")
|
log = open(log_path + "/roxy-wi-" + get_data('logs') + ".log", "a")
|
||||||
elif kwargs.get('provisioning') == 1:
|
elif kwargs.get('provisioning') == 1:
|
||||||
mess = get_data('date_in_log') + " from " + ip + " user: " + login + ", group: " + user_group + ", " + \
|
mess = get_data('date_in_log') + " from " + ip + " user: " + login + ", group: " + user_group + ", " + \
|
||||||
action + "\n"
|
action + "\n"
|
||||||
log = open(log_path + "/provisioning-" + get_data('logs') + ".log", "a")
|
log = open(log_path + "/provisioning-" + get_data('logs') + ".log", "a")
|
||||||
else:
|
else:
|
||||||
mess = get_data('date_in_log') + " from " + ip + " user: " + login + ", group: " + user_group + ", " + \
|
mess = get_data('date_in_log') + " from " + ip + " user: " + login + ", group: " + user_group + ", " + \
|
||||||
action + " for: " + server_ip + "\n"
|
action + " for: " + server_ip + "\n"
|
||||||
log = open(log_path + "/config_edit-" + get_data('logs') + ".log", "a")
|
log = open(log_path + "/config_edit-" + get_data('logs') + ".log", "a")
|
||||||
|
|
||||||
if kwargs.get('keep_history'):
|
if kwargs.get('keep_history'):
|
||||||
|
@ -424,8 +424,8 @@ def get_config(server_ip, cfg, **kwargs):
|
||||||
if kwargs.get("keepalived") or kwargs.get("service") == 'keepalived':
|
if kwargs.get("keepalived") or kwargs.get("service") == 'keepalived':
|
||||||
config_path = "/etc/keepalived/keepalived.conf"
|
config_path = "/etc/keepalived/keepalived.conf"
|
||||||
elif (
|
elif (
|
||||||
kwargs.get("nginx") or kwargs.get("service") == 'nginx'
|
kwargs.get("nginx") or kwargs.get("service") == 'nginx'
|
||||||
or kwargs.get("apache") or kwargs.get("service") == 'apache'
|
or kwargs.get("apache") or kwargs.get("service") == 'apache'
|
||||||
):
|
):
|
||||||
config_path = kwargs.get('config_file_name')
|
config_path = kwargs.get('config_file_name')
|
||||||
elif kwargs.get("waf") or kwargs.get("service") == 'waf':
|
elif kwargs.get("waf") or kwargs.get("service") == 'waf':
|
||||||
|
@ -527,8 +527,8 @@ def get_sections(config, **kwargs):
|
||||||
return_config.append(find_ip[0])
|
return_config.append(find_ip[0])
|
||||||
else:
|
else:
|
||||||
if line.startswith((
|
if line.startswith((
|
||||||
'global', 'listen', 'frontend', 'backend', 'cache', 'defaults', '#HideBlockStart',
|
'global', 'listen', 'frontend', 'backend', 'cache', 'defaults', '#HideBlockStart',
|
||||||
'#HideBlockEnd', 'peers', 'resolvers', 'userlist', 'http-errors'
|
'#HideBlockEnd', 'peers', 'resolvers', 'userlist', 'http-errors'
|
||||||
)):
|
)):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
return_config.append(line)
|
return_config.append(line)
|
||||||
|
@ -550,8 +550,8 @@ def get_section_from_config(config, section):
|
||||||
continue
|
continue
|
||||||
if record:
|
if record:
|
||||||
if line.startswith((
|
if line.startswith((
|
||||||
'global', 'listen', 'frontend', 'backend', 'cache', 'defaults', '#HideBlockStart',
|
'global', 'listen', 'frontend', 'backend', 'cache', 'defaults', '#HideBlockStart',
|
||||||
'#HideBlockEnd', 'peers', 'resolvers', 'userlist', 'http-errors'
|
'#HideBlockEnd', 'peers', 'resolvers', 'userlist', 'http-errors'
|
||||||
)):
|
)):
|
||||||
record = False
|
record = False
|
||||||
end_line = index
|
end_line = index
|
||||||
|
@ -663,7 +663,7 @@ def show_installation_output(error, output, service):
|
||||||
for line in output:
|
for line in output:
|
||||||
if "UNREACHABLE" in line:
|
if "UNREACHABLE" in line:
|
||||||
print(line + '<br />')
|
print(line + '<br />')
|
||||||
if ("Traceback", "FAILED", "error", "ERROR") in line:
|
if any(s in line for s in ("Traceback", "FAILED", "error", "ERROR")):
|
||||||
try:
|
try:
|
||||||
print(line)
|
print(line)
|
||||||
break
|
break
|
||||||
|
@ -1461,10 +1461,10 @@ def get_remote_files(server_ip: str, config_dir: str, file_format: str):
|
||||||
|
|
||||||
def return_nice_path(return_path: str) -> str:
|
def return_nice_path(return_path: str) -> str:
|
||||||
if (
|
if (
|
||||||
'nginx' not in return_path
|
'nginx' not in return_path
|
||||||
and 'haproxy' not in return_path
|
and 'haproxy' not in return_path
|
||||||
and 'apache2' not in return_path
|
and 'apache2' not in return_path
|
||||||
and 'httpd' not in return_path
|
and 'httpd' not in return_path
|
||||||
):
|
):
|
||||||
return 'error: The path must contain the name of the service. Check it in Roxy-WI settings'
|
return 'error: The path must contain the name of the service. Check it in Roxy-WI settings'
|
||||||
if return_path[-1] != '/':
|
if return_path[-1] != '/':
|
||||||
|
|
|
@ -1302,10 +1302,12 @@ if form.getvalue('master'):
|
||||||
|
|
||||||
os.system("cp scripts/%s ." % script)
|
os.system("cp scripts/%s ." % script)
|
||||||
|
|
||||||
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port +
|
commands = [
|
||||||
" ETH=" + ETH + " IP=" + str(IP) + " MASTER=MASTER" + " RETURN_TO_MASTER=" + return_to_master +
|
"chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port
|
||||||
" SYN_FLOOD=" + syn_flood + " HOST=" + str(master) +
|
+ " ETH=" + ETH + " IP=" + str(IP) + " MASTER=MASTER" + " RETURN_TO_MASTER=" + return_to_master
|
||||||
" USER=" + str(ssh_user_name) + " PASS='" + str(ssh_user_password) + "' KEY=" + str(ssh_key_name)]
|
+ " SYN_FLOOD=" + syn_flood + " HOST=" + str(master)
|
||||||
|
+ " USER=" + str(ssh_user_name) + " PASS='" + str(ssh_user_password) + "' KEY=" + str(ssh_key_name)
|
||||||
|
]
|
||||||
|
|
||||||
output, error = funct.subprocess_execute(commands[0])
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
|
@ -1316,7 +1318,7 @@ if form.getvalue('master'):
|
||||||
group_id = sql.get_group_id_by_server_ip(master)
|
group_id = sql.get_group_id_by_server_ip(master)
|
||||||
cred_id = sql.get_cred_id_by_server_ip(master)
|
cred_id = sql.get_cred_id_by_server_ip(master)
|
||||||
hostname = sql.get_hostname_by_server_ip(master)
|
hostname = sql.get_hostname_by_server_ip(master)
|
||||||
sql.add_server(hostname + '-VIP', IP, group_id, '1', '1', '0', cred_id, ssh_port, 'VRRP IP for '+master, haproxy, nginx, '0')
|
sql.add_server(hostname + '-VIP', IP, group_id, '1', '1', '0', cred_id, ssh_port, 'VRRP IP for ' + master, haproxy, nginx, '0')
|
||||||
|
|
||||||
if form.getvalue('master_slave'):
|
if form.getvalue('master_slave'):
|
||||||
master = form.getvalue('master_slave')
|
master = form.getvalue('master_slave')
|
||||||
|
@ -1343,9 +1345,11 @@ if form.getvalue('master_slave'):
|
||||||
|
|
||||||
os.system("cp scripts/%s ." % script)
|
os.system("cp scripts/%s ." % script)
|
||||||
|
|
||||||
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port +
|
commands = [
|
||||||
" ETH=" + ETH + " IP=" + IP + " MASTER=BACKUP" + " HOST=" + str(slave) +
|
"chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port
|
||||||
" USER=" + str(ssh_user_name) + " PASS='" + str(ssh_user_password) + "' KEY=" + str(ssh_key_name)]
|
+ " ETH=" + ETH + " IP=" + IP + " MASTER=BACKUP" + " HOST=" + str(slave)
|
||||||
|
+ " USER=" + str(ssh_user_name) + " PASS='" + str(ssh_user_password) + "' KEY=" + str(ssh_key_name)
|
||||||
|
]
|
||||||
|
|
||||||
output, error = funct.subprocess_execute(commands[0])
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
|
@ -1381,10 +1385,12 @@ if form.getvalue('masteradd'):
|
||||||
for server in servers:
|
for server in servers:
|
||||||
ssh_port = str(server[10])
|
ssh_port = str(server[10])
|
||||||
|
|
||||||
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv +
|
commands = [
|
||||||
" SSH_PORT=" + ssh_port + " ETH=" + ETH + " RETURN_TO_MASTER=" + return_to_master +
|
"chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv
|
||||||
" IP=" + str(IP) + " MASTER=MASTER" + " RESTART=" + kp + " ADD_VRRP=1 HOST=" + str(master) +
|
+ " SSH_PORT=" + ssh_port + " ETH=" + ETH + " RETURN_TO_MASTER=" + return_to_master
|
||||||
" USER=" + str(ssh_user_name) + " PASS='" + str(ssh_user_password) + "' KEY=" + str(ssh_key_name)]
|
+ " IP=" + str(IP) + " MASTER=MASTER" + " RESTART=" + kp + " ADD_VRRP=1 HOST=" + str(master)
|
||||||
|
+ " USER=" + str(ssh_user_name) + " PASS='" + str(ssh_user_password) + "' KEY=" + str(ssh_key_name)
|
||||||
|
]
|
||||||
|
|
||||||
output, error = funct.subprocess_execute(commands[0])
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
|
@ -1415,10 +1421,12 @@ if form.getvalue('masteradd_slave'):
|
||||||
for server in servers:
|
for server in servers:
|
||||||
ssh_port = str(server[10])
|
ssh_port = str(server[10])
|
||||||
|
|
||||||
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv +
|
commands = [
|
||||||
" SSH_PORT=" + ssh_port + " ETH=" + ETH +
|
"chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv
|
||||||
" IP=" + str(IP) + " MASTER=BACKUP" + " RESTART=" + kp + " ADD_VRRP=1 HOST=" + str(slave) +
|
+ " SSH_PORT=" + ssh_port + " ETH=" + ETH
|
||||||
" USER=" + str(ssh_user_name) + " PASS='" + str(ssh_user_password) + "' KEY=" + str(ssh_key_name)]
|
+ " IP=" + str(IP) + " MASTER=BACKUP" + " RESTART=" + kp + " ADD_VRRP=1 HOST=" + str(slave)
|
||||||
|
+ " USER=" + str(ssh_user_name) + " PASS='" + str(ssh_user_password) + "' KEY=" + str(ssh_key_name)
|
||||||
|
]
|
||||||
|
|
||||||
output, error = funct.subprocess_execute(commands[0])
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
|
@ -1471,7 +1479,7 @@ if form.getvalue('install_grafana'):
|
||||||
'success: Grafana and Prometheus servers were installed. You can find Grafana on http://' + socket.gethostname() + ':3000<br>')
|
'success: Grafana and Prometheus servers were installed. You can find Grafana on http://' + socket.gethostname() + ':3000<br>')
|
||||||
else:
|
else:
|
||||||
for line in output:
|
for line in output:
|
||||||
if ("Traceback", "FAILED") in line:
|
if any(s in line for s in ("Traceback", "FAILED")):
|
||||||
try:
|
try:
|
||||||
print(line)
|
print(line)
|
||||||
break
|
break
|
||||||
|
@ -1644,7 +1652,7 @@ if form.getvalue('backup') or form.getvalue('deljob') or form.getvalue('backupup
|
||||||
output, error = funct.subprocess_execute(commands[0])
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
for line in output:
|
for line in output:
|
||||||
if ("Traceback", "FAILED") in line:
|
if any(s in line for s in ("Traceback", "FAILED")):
|
||||||
try:
|
try:
|
||||||
print('error: ' + line)
|
print('error: ' + line)
|
||||||
break
|
break
|
||||||
|
@ -1721,7 +1729,7 @@ if form.getvalue('git_backup'):
|
||||||
output, error = funct.subprocess_execute(commands[0])
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
for line in output:
|
for line in output:
|
||||||
if ("Traceback", "FAILED") in line:
|
if any(s in line for s in ("Traceback", "FAILED")):
|
||||||
try:
|
try:
|
||||||
print('error: ' + line)
|
print('error: ' + line)
|
||||||
break
|
break
|
||||||
|
@ -1956,7 +1964,7 @@ if form.getvalue('get_nginx_v'):
|
||||||
|
|
||||||
if is_dockerized == '1':
|
if is_dockerized == '1':
|
||||||
container_name = sql.get_setting('nginx_container_name')
|
container_name = sql.get_setting('nginx_container_name')
|
||||||
cmd = ["docker exec -it "+container_name+" /usr/sbin/nginx -v 2>&1|awk '{print $3}'"]
|
cmd = ["docker exec -it " + container_name + " /usr/sbin/nginx -v 2>&1|awk '{print $3}'"]
|
||||||
else:
|
else:
|
||||||
cmd = ['sudo /usr/sbin/nginx -v']
|
cmd = ['sudo /usr/sbin/nginx -v']
|
||||||
print(funct.ssh_command(serv, cmd))
|
print(funct.ssh_command(serv, cmd))
|
||||||
|
@ -2103,17 +2111,17 @@ if form.getvalue('get_ldap_email'):
|
||||||
|
|
||||||
ldap_proto = 'ldap' if ldap_type == "0" else 'ldaps'
|
ldap_proto = 'ldap' if ldap_type == "0" else 'ldaps'
|
||||||
|
|
||||||
l = ldap.initialize('{}://{}:{}/'.format(ldap_proto, server, port))
|
ldap_bind = ldap.initialize('{}://{}:{}/'.format(ldap_proto, server, port))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
l.protocol_version = ldap.VERSION3
|
ldap_bind.protocol_version = ldap.VERSION3
|
||||||
l.set_option(ldap.OPT_REFERRALS, 0)
|
ldap_bind.set_option(ldap.OPT_REFERRALS, 0)
|
||||||
|
|
||||||
bind = l.simple_bind_s(user, password)
|
bind = ldap_bind.simple_bind_s(user, password)
|
||||||
|
|
||||||
criteria = "(&(objectClass=" + ldap_class_search + ")(" + ldap_user_attribute + "=" + username + "))"
|
criteria = "(&(objectClass=" + ldap_class_search + ")(" + ldap_user_attribute + "=" + username + "))"
|
||||||
attributes = [ldap_search_field]
|
attributes = [ldap_search_field]
|
||||||
result = l.search_s(ldap_base, ldap.SCOPE_SUBTREE, criteria, attributes)
|
result = ldap_bind.search_s(ldap_base, ldap.SCOPE_SUBTREE, criteria, attributes)
|
||||||
|
|
||||||
results = [entry for dn, entry in result if isinstance(entry, dict)]
|
results = [entry for dn, entry in result if isinstance(entry, dict)]
|
||||||
try:
|
try:
|
||||||
|
@ -2867,7 +2875,7 @@ if form.getvalue('lets_domain'):
|
||||||
print(error)
|
print(error)
|
||||||
else:
|
else:
|
||||||
for line in output:
|
for line in output:
|
||||||
if "msg" in line or "FAILED" in line:
|
if any(s in line for s in ("msg", "FAILED")):
|
||||||
try:
|
try:
|
||||||
line = line.split(':')[1]
|
line = line.split(':')[1]
|
||||||
line = line.split('"')[1]
|
line = line.split('"')[1]
|
||||||
|
@ -3278,12 +3286,12 @@ if form.getvalue('awsvars') or form.getvalue('awseditvars'):
|
||||||
aws_key, aws_secret = sql.select_aws_provider(provider)
|
aws_key, aws_secret = sql.select_aws_provider(provider)
|
||||||
|
|
||||||
cmd = 'cd scripts/terraform/ && sudo ansible-playbook var_generator.yml -i inventory -e "region={} ' \
|
cmd = 'cd scripts/terraform/ && sudo ansible-playbook var_generator.yml -i inventory -e "region={} ' \
|
||||||
'group={} size={} os={} floating_ip={} volume_size={} server_name={} AWS_ACCESS_KEY={} ' \
|
'group={} size={} os={} floating_ip={} volume_size={} server_name={} AWS_ACCESS_KEY={} ' \
|
||||||
'AWS_SECRET_KEY={} firewall={} public_ip={} ssh_name={} delete_on_termination={} volume_type={} ' \
|
'AWS_SECRET_KEY={} firewall={} public_ip={} ssh_name={} delete_on_termination={} volume_type={} ' \
|
||||||
'cloud=aws"'.format(
|
'cloud=aws"'.format(
|
||||||
region, group, size, oss, floating_ip, volume_size, awsvars, aws_key, aws_secret,
|
region, group, size, oss, floating_ip, volume_size, awsvars, aws_key, aws_secret,
|
||||||
firewall, public_ip, ssh_name, delete_on_termination, volume_type
|
firewall, public_ip, ssh_name, delete_on_termination, volume_type
|
||||||
)
|
)
|
||||||
|
|
||||||
output, stderr = funct.subprocess_execute(cmd)
|
output, stderr = funct.subprocess_execute(cmd)
|
||||||
if stderr != '':
|
if stderr != '':
|
||||||
|
@ -3325,7 +3333,8 @@ if form.getvalue('dovars') or form.getvalue('doeditvars'):
|
||||||
|
|
||||||
cmd = 'cd scripts/terraform/ && sudo ansible-playbook var_generator.yml -i inventory -e "region={} ' \
|
cmd = 'cd scripts/terraform/ && sudo ansible-playbook var_generator.yml -i inventory -e "region={} ' \
|
||||||
'group={} size={} os={} floating_ip={} ssh_ids={} server_name={} token={} backup={} monitoring={} ' \
|
'group={} size={} os={} floating_ip={} ssh_ids={} server_name={} token={} backup={} monitoring={} ' \
|
||||||
'privet_net={} firewall={} floating_ip={} ssh_name={} cloud=do"'.format(
|
'privet_net={} firewall={} floating_ip={} ssh_name={} ' \
|
||||||
|
'cloud=do"'.format(
|
||||||
region, group, size, oss, floating_ip, ssh_ids, dovars, token, backup, monitoring,
|
region, group, size, oss, floating_ip, ssh_ids, dovars, token, backup, monitoring,
|
||||||
privet_net, firewall, floating_ip, ssh_name
|
privet_net, firewall, floating_ip, ssh_name
|
||||||
)
|
)
|
||||||
|
|
17
app/sql.py
17
app/sql.py
|
@ -942,8 +942,10 @@ def update_ssh(cred_id, name, enable, group, username, password):
|
||||||
|
|
||||||
def insert_backup_job(server, rserver, rpath, backup_type, time, cred, description):
|
def insert_backup_job(server, rserver, rpath, backup_type, time, cred, description):
|
||||||
try:
|
try:
|
||||||
Backup.insert(server=server, rhost=rserver, rpath=rpath, backup_type=backup_type, time=time,
|
Backup.insert(
|
||||||
cred=cred, description=description).execute()
|
server=server, rhost=rserver, rpath=rpath, backup_type=backup_type, time=time,
|
||||||
|
cred=cred, description=description
|
||||||
|
).execute()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
out_error(e)
|
out_error(e)
|
||||||
return False
|
return False
|
||||||
|
@ -2516,8 +2518,10 @@ def delete_port_scanner_settings(server_id):
|
||||||
|
|
||||||
def insert_port_scanner_port(serv, user_group_id, port, service_name):
|
def insert_port_scanner_port(serv, user_group_id, port, service_name):
|
||||||
try:
|
try:
|
||||||
PortScannerPorts.insert(serv=serv, port=port, user_group_id=user_group_id, service_name=service_name,
|
PortScannerPorts.insert(
|
||||||
date=funct.get_data('regular')).execute()
|
serv=serv, port=port, user_group_id=user_group_id, service_name=service_name,
|
||||||
|
date=funct.get_data('regular')
|
||||||
|
).execute()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
out_error(e)
|
out_error(e)
|
||||||
|
|
||||||
|
@ -2547,8 +2551,9 @@ def select_port_name(serv, port):
|
||||||
|
|
||||||
|
|
||||||
def select_count_opened_ports(serv):
|
def select_count_opened_ports(serv):
|
||||||
query = PortScannerPorts.select(PortScannerPorts.date,
|
query = PortScannerPorts.select(
|
||||||
fn.Count(PortScannerPorts.port).alias('count')).where(PortScannerPorts.serv == serv)
|
PortScannerPorts.date, fn.Count(PortScannerPorts.port).alias('count')
|
||||||
|
).where(PortScannerPorts.serv == serv)
|
||||||
try:
|
try:
|
||||||
query_res = query.execute()
|
query_res = query.execute()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in New Issue