Pavel Loginov 2022-05-25 21:40:55 +03:00
parent 64509d1fd4
commit 27024cc58a
3 changed files with 66 additions and 52 deletions

View File

@ -169,11 +169,11 @@ def logging(server_ip, action, **kwargs):
log = open(log_path + "/roxy-wi-" + get_data('logs') + ".log", "a")
elif kwargs.get('provisioning') == 1:
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")
else:
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")
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':
config_path = "/etc/keepalived/keepalived.conf"
elif (
kwargs.get("nginx") or kwargs.get("service") == 'nginx'
or kwargs.get("apache") or kwargs.get("service") == 'apache'
kwargs.get("nginx") or kwargs.get("service") == 'nginx'
or kwargs.get("apache") or kwargs.get("service") == 'apache'
):
config_path = kwargs.get('config_file_name')
elif kwargs.get("waf") or kwargs.get("service") == 'waf':
@ -527,8 +527,8 @@ def get_sections(config, **kwargs):
return_config.append(find_ip[0])
else:
if line.startswith((
'global', 'listen', 'frontend', 'backend', 'cache', 'defaults', '#HideBlockStart',
'#HideBlockEnd', 'peers', 'resolvers', 'userlist', 'http-errors'
'global', 'listen', 'frontend', 'backend', 'cache', 'defaults', '#HideBlockStart',
'#HideBlockEnd', 'peers', 'resolvers', 'userlist', 'http-errors'
)):
line = line.strip()
return_config.append(line)
@ -550,8 +550,8 @@ def get_section_from_config(config, section):
continue
if record:
if line.startswith((
'global', 'listen', 'frontend', 'backend', 'cache', 'defaults', '#HideBlockStart',
'#HideBlockEnd', 'peers', 'resolvers', 'userlist', 'http-errors'
'global', 'listen', 'frontend', 'backend', 'cache', 'defaults', '#HideBlockStart',
'#HideBlockEnd', 'peers', 'resolvers', 'userlist', 'http-errors'
)):
record = False
end_line = index
@ -663,7 +663,7 @@ def show_installation_output(error, output, service):
for line in output:
if "UNREACHABLE" in line:
print(line + '<br />')
if ("Traceback", "FAILED", "error", "ERROR") in line:
if any(s in line for s in ("Traceback", "FAILED", "error", "ERROR")):
try:
print(line)
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:
if (
'nginx' not in return_path
and 'haproxy' not in return_path
and 'apache2' not in return_path
and 'httpd' not in return_path
'nginx' not in return_path
and 'haproxy' not in return_path
and 'apache2' 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'
if return_path[-1] != '/':

View File

@ -1302,10 +1302,12 @@ if form.getvalue('master'):
os.system("cp scripts/%s ." % script)
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port +
" ETH=" + ETH + " IP=" + str(IP) + " MASTER=MASTER" + " RETURN_TO_MASTER=" + return_to_master +
" SYN_FLOOD=" + syn_flood + " HOST=" + str(master) +
" USER=" + str(ssh_user_name) + " PASS='" + str(ssh_user_password) + "' KEY=" + str(ssh_key_name)]
commands = [
"chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port
+ " ETH=" + ETH + " IP=" + str(IP) + " MASTER=MASTER" + " RETURN_TO_MASTER=" + return_to_master
+ " 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])
@ -1316,7 +1318,7 @@ if form.getvalue('master'):
group_id = sql.get_group_id_by_server_ip(master)
cred_id = sql.get_cred_id_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'):
master = form.getvalue('master_slave')
@ -1343,9 +1345,11 @@ if form.getvalue('master_slave'):
os.system("cp scripts/%s ." % script)
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port +
" ETH=" + ETH + " IP=" + IP + " MASTER=BACKUP" + " HOST=" + str(slave) +
" USER=" + str(ssh_user_name) + " PASS='" + str(ssh_user_password) + "' KEY=" + str(ssh_key_name)]
commands = [
"chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port
+ " 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])
@ -1381,10 +1385,12 @@ if form.getvalue('masteradd'):
for server in servers:
ssh_port = str(server[10])
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv +
" SSH_PORT=" + ssh_port + " ETH=" + ETH + " RETURN_TO_MASTER=" + return_to_master +
" 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)]
commands = [
"chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv
+ " SSH_PORT=" + ssh_port + " ETH=" + ETH + " RETURN_TO_MASTER=" + return_to_master
+ " 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])
@ -1415,10 +1421,12 @@ if form.getvalue('masteradd_slave'):
for server in servers:
ssh_port = str(server[10])
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv +
" SSH_PORT=" + ssh_port + " ETH=" + ETH +
" 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)]
commands = [
"chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv
+ " SSH_PORT=" + ssh_port + " ETH=" + ETH
+ " 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])
@ -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>')
else:
for line in output:
if ("Traceback", "FAILED") in line:
if any(s in line for s in ("Traceback", "FAILED")):
try:
print(line)
break
@ -1644,7 +1652,7 @@ if form.getvalue('backup') or form.getvalue('deljob') or form.getvalue('backupup
output, error = funct.subprocess_execute(commands[0])
for line in output:
if ("Traceback", "FAILED") in line:
if any(s in line for s in ("Traceback", "FAILED")):
try:
print('error: ' + line)
break
@ -1721,7 +1729,7 @@ if form.getvalue('git_backup'):
output, error = funct.subprocess_execute(commands[0])
for line in output:
if ("Traceback", "FAILED") in line:
if any(s in line for s in ("Traceback", "FAILED")):
try:
print('error: ' + line)
break
@ -1956,7 +1964,7 @@ if form.getvalue('get_nginx_v'):
if is_dockerized == '1':
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:
cmd = ['sudo /usr/sbin/nginx -v']
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'
l = ldap.initialize('{}://{}:{}/'.format(ldap_proto, server, port))
ldap_bind = ldap.initialize('{}://{}:{}/'.format(ldap_proto, server, port))
try:
l.protocol_version = ldap.VERSION3
l.set_option(ldap.OPT_REFERRALS, 0)
ldap_bind.protocol_version = ldap.VERSION3
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 + "))"
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)]
try:
@ -2867,7 +2875,7 @@ if form.getvalue('lets_domain'):
print(error)
else:
for line in output:
if "msg" in line or "FAILED" in line:
if any(s in line for s in ("msg", "FAILED")):
try:
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)
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={} ' \
'AWS_SECRET_KEY={} firewall={} public_ip={} ssh_name={} delete_on_termination={} volume_type={} ' \
'cloud=aws"'.format(
region, group, size, oss, floating_ip, volume_size, awsvars, aws_key, aws_secret,
firewall, public_ip, ssh_name, delete_on_termination, volume_type
)
'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={} ' \
'cloud=aws"'.format(
region, group, size, oss, floating_ip, volume_size, awsvars, aws_key, aws_secret,
firewall, public_ip, ssh_name, delete_on_termination, volume_type
)
output, stderr = funct.subprocess_execute(cmd)
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={} ' \
'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,
privet_net, firewall, floating_ip, ssh_name
)

View File

@ -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):
try:
Backup.insert(server=server, rhost=rserver, rpath=rpath, backup_type=backup_type, time=time,
cred=cred, description=description).execute()
Backup.insert(
server=server, rhost=rserver, rpath=rpath, backup_type=backup_type, time=time,
cred=cred, description=description
).execute()
except Exception as e:
out_error(e)
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):
try:
PortScannerPorts.insert(serv=serv, port=port, user_group_id=user_group_id, service_name=service_name,
date=funct.get_data('regular')).execute()
PortScannerPorts.insert(
serv=serv, port=port, user_group_id=user_group_id, service_name=service_name,
date=funct.get_data('regular')
).execute()
except Exception as e:
out_error(e)
@ -2547,8 +2551,9 @@ def select_port_name(serv, port):
def select_count_opened_ports(serv):
query = PortScannerPorts.select(PortScannerPorts.date,
fn.Count(PortScannerPorts.port).alias('count')).where(PortScannerPorts.serv == serv)
query = PortScannerPorts.select(
PortScannerPorts.date, fn.Count(PortScannerPorts.port).alias('count')
).where(PortScannerPorts.serv == serv)
try:
query_res = query.execute()
except Exception as e: