Fixes for support change port and changes for no install monit for default

This commit is contained in:
absurdo 2023-08-02 01:11:21 +02:00
parent 2ebe22f79e
commit 7c1b903d44
11 changed files with 38 additions and 16 deletions

View file

@ -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)

View file

@ -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')

View file

@ -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):

View file

@ -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

View file

@ -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...')

View file

@ -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)

View file

@ -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...')

View file

@ -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

View file

@ -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()

View file

@ -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

View file

@ -11,6 +11,7 @@
<p><label>${lang('pastafari2', 'server_username', 'Server username')} <span class="pastafari2_error error" id="server_username_error"></span></label> <input type="text" name="server_username" value=""></p>
<p><label>${lang('pastafari2', 'server_password', 'Server password.')} <span class="pastafari2_error error" id="server_password_error"></span></label> <input type="password" name="server_password" value=""></p>
<p><label>${lang('pastafari2', 'repeat_server_password', 'Repeat server password')} <span class="pastafari2_error error" id="repeat_server_password_error"></span></label> <input type="password" name="repeat_server_password" value=""></p>
<p><label>${lang('pastafari2', 'ssh_port', 'SSH port')}* <span class="pastafari2_error error" id="ssh_port_error"></span></label> <input type="number" name="ssh_port" value="22"></p>
<p><input type="submit" value="${lang('pastafari2', 'send', 'Send')}"/></p>
</form>
</div>