diff --git a/admin/dashboard.py b/admin/dashboard.py index a4f354f..2a5c9dd 100644 --- a/admin/dashboard.py +++ b/admin/dashboard.py @@ -214,6 +214,18 @@ def pastafari2_add_server_task(): error=0 data={} ssh_user=config_task.remote_user + ssh_port=config_task.port + + try: + + tmp_port=int(request.form.get('ssh_port', '22')) + + ssh_port=tmp_port + + except: + pass + + #make ping to server @@ -242,7 +254,7 @@ def pastafari2_add_server_task(): data={'ssh_user': ssh_user, 'pub_key': public_key, 'url_stats': config.domain_url+url_for('monit_app.monit_get_data', api_key=config.monit_api_key), 'hostname': server_host, 'ip': ip, 'group_id': group_id, 'group_name': group_name} - with SSHTask(server_host, db, remote_user=server_username, remote_password=server_password, private_key=private_key, remote_path=remote_path, task_id=task_id, data=data) as ssh_task: + with SSHTask(server_host, db, remote_user=server_username, remote_password=server_password, private_key=private_key, remote_path=remote_path, task_id=task_id, data=data, port=ssh_port) as ssh_task: if not ssh_task.prepare_connection(): error=1 txt_error=I18n.lang('pastafari2', 'error_connection', 'Error: cannot connect to server') @@ -257,7 +269,7 @@ def pastafari2_add_server_task(): path_task='modules.pastafari2.tasks.system.task' - if not task.run_task(ip, path_task, 'Add new server', 'add_new_server', 'Task for add a new server', user=server_username, password=server_password, where_sql_server='', url='', data=data, send_task=True): + if not task.run_task(ip, path_task, 'Add new server', 'add_new_server', 'Task for add a new server', user=server_username, password=server_password, where_sql_server='', url='', data=data, send_task=True, ssh_port=ssh_port): error=1 error_form['#server_host_error']=I18n.lang('pastafari2', 'error_exec_task', 'Error: cannot execute the task '+task.txt_error) diff --git a/libraries/task.py b/libraries/task.py index 27c0b42..5517e30 100644 --- a/libraries/task.py +++ b/libraries/task.py @@ -13,7 +13,7 @@ class Task: #($server='', $ssh_user='root', $ssh_key_priv='./ssh/id_rsa', $ssh_key_password='', $ssh_path='leviathan', $mysql_conn=false) - def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={}): + def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={}, port=22): self.config=config_task @@ -29,6 +29,8 @@ class Task: self.os_server='' + self.port=port + self.files=[] # Format first array element is command with the interpreter, the task is agnostic, the files in os directory. The commands are setted with 750 permission. @@ -135,7 +137,7 @@ class Task: try: - self.ssh.connect(self.server, port=self.config.port, username=self.remote_user, password=self.remote_password, pkey=rsa, key_filename=None, timeout=None, allow_agent=True, look_for_keys=True, compress=False, sock=None, gss_auth=False, gss_kex=False, gss_deleg_creds=True, gss_host=None, banner_timeout=None) + self.ssh.connect(self.server, port=self.port, username=self.remote_user, password=self.remote_password, pkey=rsa, key_filename=None, timeout=None, allow_agent=True, look_for_keys=True, compress=False, sock=None, gss_auth=False, gss_kex=False, gss_deleg_creds=True, gss_host=None, banner_timeout=None) if add_host: host_key.save(self.config.ssh_directory+'/known_hosts') diff --git a/models/pastafari2.py b/models/pastafari2.py index c8c1ba2..94b6bfc 100644 --- a/models/pastafari2.py +++ b/models/pastafari2.py @@ -31,6 +31,7 @@ class ServerDbTask(Server): super().__init__(connection) self.fields['group'].required=False self.register(corefields.ForeignKeyField('group_id', ServerGroup(connection), 11, False, 'id', 'group', select_fields=[])) + self.register(corefields.IntegerField('ssh_port')) class UpdateServerScripts(WebModel): diff --git a/models/tasks.py b/models/tasks.py index 3652891..882026c 100644 --- a/models/tasks.py +++ b/models/tasks.py @@ -42,6 +42,7 @@ class Task(WebModel): self.register(corefields.CharField('ssh_key_pub')) self.register(corefields.CharField('ssh_key_priv')) self.register(corefields.CharField('ssh_key_password')) + self.register(corefields.IntegerField('ssh_port')) data_field=corefields.CharField('') @@ -57,7 +58,7 @@ class Task(WebModel): self.txt_error='' self.error=False - def run_task(self, server, path, name_task, codename_task, description_task, data={}, user='', password='', where_sql_server='', url='', ssh_key_priv='', ssh_key_password='', send_task=True): + def run_task(self, server, path, name_task, codename_task, description_task, data={}, user='', password='', where_sql_server='', url='', ssh_key_priv='', ssh_key_password='', send_task=True, ssh_port=22): logtask=LogTask(self.connection) #servers=Server(self.connection) @@ -77,7 +78,7 @@ class Task(WebModel): if where_sql_server!='': yes_parent=1 - if self.insert({'name_task': name_task,'description_task': description_task, 'url_return': url, 'server': server, 'where_sql_server': where_sql_server, 'data': data , 'user': user, 'password': password, 'path': path, 'where_sql_server' : where_sql_server, 'ssh_key_priv': ssh_key_priv, 'ssh_key_password': ssh_key_password, 'is_parent': yes_parent}): + if self.insert({'name_task': name_task,'description_task': description_task, 'url_return': url, 'server': server, 'where_sql_server': where_sql_server, 'data': data , 'user': user, 'password': password, 'path': path, 'where_sql_server' : where_sql_server, 'ssh_key_priv': ssh_key_priv, 'ssh_key_password': ssh_key_password, 'is_parent': yes_parent, 'ssh_port': ssh_port}): task_id=self.insert_id() parent_id=task_id diff --git a/scripts/servers/databases/mariadb/install_mariadb.py b/scripts/servers/databases/mariadb/install_mariadb.py index 3a63ae3..05a8983 100644 --- a/scripts/servers/databases/mariadb/install_mariadb.py +++ b/scripts/servers/databases/mariadb/install_mariadb.py @@ -89,7 +89,7 @@ elif linux_distro=='arch': print('Error, cannot start mariadb') sys.exit(1) -elif linux_distro=='rocky' or linux_distro=='alma' or linux_distro=='fedora': +elif linux_distro=='rocky' or linux_distro=='almalinux' or linux_distro=='fedora': if subprocess.call("sudo dnf install -y mariadb-server expect", shell=True) > 0: print('Error, cannot install MariaDB...') diff --git a/scripts/system/install_git.py b/scripts/system/install_git.py index 98144dc..b05b39c 100644 --- a/scripts/system/install_git.py +++ b/scripts/system/install_git.py @@ -24,7 +24,7 @@ elif linux_distro=='debian' or linux_distro=='ubuntu': if call('sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y git', shell=True) > 0: print('Error, cannot install git...') exit(1) -elif linux_distro=='rocky' or linux_distro=='fedora': +elif linux_distro=='rocky' or linux_distro=='fedora' or linux_distro=='almalinux': if call("sudo dnf install -y git", shell=True) > 0: print('Error, cannot install git...') exit(1) diff --git a/scripts/system/install_php.py b/scripts/system/install_php.py index 65a25e8..da1ede6 100644 --- a/scripts/system/install_php.py +++ b/scripts/system/install_php.py @@ -23,9 +23,9 @@ elif linux_distro=='debian' or linux_distro=='ubuntu': if call('sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y php-fpm php-gd php-json php-mysql php-curl php-mbstring php-intl php-imagick php-xml php-zip php-redis unzip', shell=True) > 0: print('Error, cannot install php...') exit(1) -elif linux_distro=='rocky' or linux_distro=='fedora': +elif linux_distro=='rocky' or linux_distro=='fedora' or linux_distro=='almalinux': - if linux_distro=='rocky': + if linux_distro=='rocky' or linux_distro=='almalinux': if call("sudo dnf install -y php php-gd php-mysqlnd php-fpm php-zip", shell=True) > 0: print('Error, cannot install php...') diff --git a/scripts/system/install_python.sh b/scripts/system/install_python.sh index 18184f1..50ab943 100644 --- a/scripts/system/install_python.sh +++ b/scripts/system/install_python.sh @@ -22,7 +22,7 @@ elif [[ $DISTRO =~ ^NAME=\"Arch ]]; then sudo pacman -S --noconfirm python python-pip sudo augeas python-virtualenv -elif [[ $DISTRO =~ ^NAME=\"Rocky ]] || [[ $DISTRO =~ ^NAME=\"Alma ]]; then +elif [[ $DISTRO =~ ^NAME=\"Rocky ]] || [[ $DISTRO =~ ^Alma ]]; then dnf install -y sudo @@ -46,7 +46,7 @@ elif [[ $DISTRO =~ ^Fedora ]]; then else - echo "Sorry, Linux distro not supported" + echo '{"error": 1, "status": 1, "progress": 100, "no_progress":0, "message": "Error, cannot install python in your distro..."}' exit 1; fi diff --git a/servers/launcher.py b/servers/launcher.py index 542daff..b9d82d9 100644 --- a/servers/launcher.py +++ b/servers/launcher.py @@ -40,6 +40,8 @@ def start(cli_args=None): arr_task=task_model.select_a_row(task_id) + default_port=22 + if arr_task: if (arr_task['user']!='' or arr_task['password']!='') and arr_task['path']!='': @@ -55,6 +57,9 @@ def start(cli_args=None): task_model.update({'password': ''}) + if arr_task['ssh_port']!='': + default_port=int(arr_task['ssh_port']) + """ if not commands_to_execute: print('Error: no task files') @@ -73,7 +78,7 @@ def start(cli_args=None): taskmod=importlib.import_module(arr_task.get('path', '')) - ssh_task=taskmod.ServerTask(arr_task['server'], conn, remote_user=remote_user, remote_password=remote_password, private_key=private_key, password_key=password_key, remote_path='pastafari2', task_id=task_id, data=json.loads(arr_task['data'])) + ssh_task=taskmod.ServerTask(arr_task['server'], conn, remote_user=remote_user, remote_password=remote_password, private_key=private_key, password_key=password_key, remote_path='pastafari2', task_id=task_id, data=json.loads(arr_task['data']), port=default_port) ssh_task.exec() diff --git a/tasks/system/task.py b/tasks/system/task.py index 6ee8627..d7d8bcc 100644 --- a/tasks/system/task.py +++ b/tasks/system/task.py @@ -3,9 +3,9 @@ from modules.pastafari2.models.pastafari2 import ServerDbTask class ServerTask(Task): - def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={}): + def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={}, ssh_port=22): - super().__init__(server, conn, remote_user, remote_password, private_key, password_key, remote_path, task_id, data) + super().__init__(server, conn, remote_user, remote_password, private_key, password_key, remote_path, task_id, data, ssh_port) #self.files=[['modules/pastafari2/scripts/system/alive.sh', 0o755]] @@ -37,6 +37,6 @@ class ServerTask(Task): #'subdomain_id': self.data['subdomain_id'] - server.insert({'hostname': self.data['hostname'], 'ip': self.data['ip'], 'group_id': self.data['group_id']}) + server.insert({'hostname': self.data['hostname'], 'ip': self.data['ip'], 'group_id': self.data['group_id'], 'ssh_port': self.port}) return True diff --git a/templates/admin/add_server.phtml b/templates/admin/add_server.phtml index 151e9e7..78470e9 100644 --- a/templates/admin/add_server.phtml +++ b/templates/admin/add_server.phtml @@ -11,6 +11,7 @@

+