Fixes in tasks

This commit is contained in:
absurdo 2023-09-01 00:52:51 +02:00
parent 0839729105
commit 12116ce3c5
2 changed files with 36 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import subprocess
import argparse
import platform
import distro
import os
pyv=platform.python_version_tuple()
@ -30,19 +31,50 @@ except:
exit(1)
print('Changing ssh port...')
#sudo su -s /bin/bash -c ' echo "Port=%i" > /etc/ssh/sshd_config.d/port.conf' % ssh_port
#if subprocess.call('sudo echo "Port=%i" > /etc/ssh/sshd_config.d/port.conf' % ssh_port, shell=True) > 0:
if os.path.isfile('/etc/sshd_config.d/port.conf'):
if subprocess.call("sudo cp /etc/sshd_config.d/port.conf /etc/sshd_config.d/port.conf.bak", shell=True) > 0:
print('Error: cannot save the old sshd configuration')
sys.exit(1)
if subprocess.call("sudo su -s /bin/bash -c ' echo \"Port=%i\" > /etc/ssh/sshd_config.d/port.conf'" % ssh_port, shell=True) > 0:
#print('{"error": 1, "status": 1, "progress": 100, "no_progress":0, "message": "Error: cannot save the new sshd configuration'+('sudo echo "Port=%i" > /etc/ssh/sshd_config.d/port.conf' % ssh_port)+'"}')
print('Error: cannot save the new sshd configuration sudo echo "Port=%i" > /etc/ssh/sshd_config.d/port.conf\n' % ssh_port)
sys.exit(1)
if linux_distro=='fedora' or linux_distro=='centos' or linux_distro=='almalinux' or linux_distro=='rocky':
if subprocess.call("sudo getenforce", shell=True)==0:
if subprocess.call("sudo semanage port -a -t ssh_port_t -p tcp %s" % ssh_port, shell=True) > 0:
print('WARNING: probably the port is open for ssh in selinux\n')
#sys.exit(1)
if subprocess.call("sudo systemctl status firewalld", shell=True)==0:
if subprocess.call("sudo firewall-cmd --add-port=%s/tcp --permanent && sudo firewall-cmd --reload" % ssh_port, shell=True) > 0:
print('Error, cannot set firewall services for sshd...\n')
exit(1)
if subprocess.call("sudo systemctl restart sshd", shell=True) > 0:
#Fallout to
#print('{"error": 1, "status": 1, "progress": 100, "no_progress":0, "message": "Error: cannot save the new sshd configuration'+('sudo echo "Port=%i" > /etc/ssh/sshd_config.d/port.conf' % ssh_port)+'"}')
print('Error: cannot restart new sshd configuration!, dangerous!')
sys.exit(1)
print('{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Done: changed the ssh port value..., if the port is not 22, you need change the port access in command line or ssh configuration"}')
print('Error: cannot restart new sshd configuration!, dangerous!\n')
print('Restarting sshd with old value...')
if os.path.isfile('/etc/sshd_config.d/port.conf.bak'):
if subprocess.call("sudo cp /etc/sshd_config.d/port.conf.bak /etc/sshd_config.d/port.conf", shell=True) > 0:
print('Error: cannot get the old sshd configuration for restaure old port!, deleting old configuration and opening port 22!\n')
sys.exit(1)
if subprocess.call("sudo rm -f /etc/sshd_config.d/port.conf && sudo systemctl restart sshd", shell=True) > 0:
print('Error: cannot delete configuration and restart sshd!!\n')
sys.exit(1)
print('{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Done: changed the ssh port value..."}')

View file

@ -51,7 +51,7 @@ def execute_script(task_id, executable='launcher.py'):
return_value=proc.returncode
if return_value>0:
if return_value!=0:
connection=WebModel.connection()
if executable=='launcher.py':