Added task for change password
This commit is contained in:
parent
04ddeb761e
commit
f08b057cd1
2 changed files with 74 additions and 0 deletions
21
scripts/system/change_user_password.py
Normal file
21
scripts/system/change_user_password.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#!/usr/bin/python3 -u
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
from pastafariutils.unix import add_user, del_user, change_password
|
||||||
|
from pathlib import Path
|
||||||
|
from subprocess import call, DEVNULL
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
import shutil
|
||||||
|
import pwd
|
||||||
|
import distro
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
parser=argparse.ArgumentParser(prog='change_password_user.py', description='A tool for change passwords')
|
||||||
|
|
||||||
|
parser.add_argument('--password', help='The password of the unix user', required=True)
|
||||||
|
|
||||||
|
args=parser.parse_args()
|
||||||
|
|
||||||
53
tasks/system/change_password_user.py
Normal file
53
tasks/system/change_password_user.py
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
from modules.pastafari2.libraries.task import Task
|
||||||
|
from modules.pastafari2.models.pastafari2 import ServerDbTask
|
||||||
|
import os
|
||||||
|
|
||||||
|
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={}):
|
||||||
|
|
||||||
|
super().__init__(server, conn, remote_user, remote_password, private_key, password_key, remote_path, task_id, data)
|
||||||
|
|
||||||
|
#self.files=[['modules/pastafari2/scripts/system/alive.sh', 0o755]]
|
||||||
|
|
||||||
|
self.files=[['modules/pastafari2/scripts/system/change_password.py', 0o755]]
|
||||||
|
|
||||||
|
#self.files.append([self.data['ssh_pub_key'], 0o600])
|
||||||
|
|
||||||
|
self.commands_to_execute=[]
|
||||||
|
|
||||||
|
#self.commands_to_execute.append(['modules/pastafari2/scripts/system/alive.sh', ''])
|
||||||
|
|
||||||
|
#self.commands_to_execute.append(['modules/pastafari2/scripts/system/install_pzoo_stats.py', '--user='+self.data['ssh_user']+' --pub_key='+self.data['pub_key']+' --url_stats='+self.data['url_stats']+' --group="'+self.data['group_name']+'" --path='+remote_path])
|
||||||
|
|
||||||
|
def pre_task(self):
|
||||||
|
|
||||||
|
ssh_pub_key_file=''
|
||||||
|
|
||||||
|
final_ssh_pub=''
|
||||||
|
|
||||||
|
if self.data['ssh_pub_key']!='':
|
||||||
|
with open('./modules/webservers/scripts/files/id_rsa.pub', 'w') as f:
|
||||||
|
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])
|
||||||
|
|
||||||
|
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'])
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
"""
|
||||||
|
def post_task(self):
|
||||||
|
|
||||||
|
if os.path.isfile('./modules/webservers/scripts/files/id_rsa.pub'):
|
||||||
|
|
||||||
|
|
||||||
|
return True
|
||||||
|
"""
|
||||||
Loading…
Add table
Add a link
Reference in a new issue