From 5621dd6c340db87f4d6e3e1367d7a47e6f8e4a14 Mon Sep 17 00:00:00 2001 From: absurdo Date: Sun, 28 May 2023 19:42:14 +0200 Subject: [PATCH] Dekleted password option for website users --- tasks/system/change_password_user.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tasks/system/change_password_user.py b/tasks/system/change_password_user.py index eb4cf22..46b4497 100644 --- a/tasks/system/change_password_user.py +++ b/tasks/system/change_password_user.py @@ -1,6 +1,7 @@ from modules.pastafari2.libraries.task import Task from modules.pastafari2.models.pastafari2 import ServerDbTask import os +from subprocess import call class ServerTask(Task): @@ -31,23 +32,37 @@ class ServerTask(Task): f.write(self.data['ssh_pub_key']) ssh_pub_key_file='./modules/webservers/scripts/files/id_rsa.pub' self.files.append([ssh_pub_key_file, 0o600]) + + # ssh-keygen -l -f id_rsa.pub + + if call("ssh-keygen -l -f {}".format(ssh_pub_key_file), shell=True) > 0: + self.logtask.insert({'status':1, 'progress': 100, 'error': 1, 'task_id': self.id, 'server': self.server, 'message': 'INVALID PUB KEY %s' % "{}".format(ssh_pub_key_file)}) + #os.unlink(ssh_pub_key_file) + return False + + else: + self.logtask.insert({'status':1, 'progress': 100, 'error': 1, 'task_id': self.task_id, 'server': self.server, 'message': 'No exists ssh pub key'}) + return False final_ssh_pub='--ssh_pub_key_file="'+ssh_pub_key_file+'"' - + """ final_password='' if self.data['password']!='': final_password='--password=%s' % self.data['password'] + """ - self.commands_to_execute.append(['modules/pastafari2/scripts/system/change_password.py', '--user=%s %s %s' % (self.data['user'], final_password, final_ssh_pub), 'sudo']) + self.commands_to_execute.append(['modules/pastafari2/scripts/system/change_password.py', '--user=%s %s' % (self.data['user'], final_ssh_pub), 'sudo']) return True - """ + def post_task(self): - if os.path.isfile('./modules/webservers/scripts/files/id_rsa.pub'): - + ssh_pub_key_file='./modules/webservers/scripts/files/id_rsa.pub' + + if os.path.isfile(ssh_pub_key_file): + os.unlink(ssh_pub_key_file) return True - """ +