-
Notifications
You must be signed in to change notification settings - Fork 3
/
update_user_pass.py
27 lines (22 loc) · 978 Bytes
/
update_user_pass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import argparse, json, hashlib
def update_user_password(config_json, user=u"admin", password=u"admin"):
config_json['admin']['username'] = user
config_json['admin']['password'] = password
return config_json
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file', help='Path to config JSON file')
parser.add_argument('-u', '--user', help='User name')
parser.add_argument('-p', '--password', help='Password file')
args = parser.parse_args()
with open(args.password, 'r') as f:
args.password = hashlib.md5(f.read()).hexdigest()
print(args.file)
print(args.user)
print(args.password)
config_json = json.loads(open(args.file).read())
output_json = update_user_password(config_json,
user=args.user,
password=args.password)
with open(args.file, 'w') as f:
json.dump(output_json, f)