-
Notifications
You must be signed in to change notification settings - Fork 31
/
jimi_cli.py
107 lines (100 loc) · 3.89 KB
/
jimi_cli.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import sys
import os
import json
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--reset_root',action='store_true', help='Reset root password')
parser.add_argument('--update_conduct_acl', action='store_true', help='Update conduct ACLs')
parser.add_argument('--conduct', help='Conduct ID')
parser.add_argument('--acl', help='ACL ID')
parser.add_argument('--read', action='store_true', help='Set read to true')
parser.add_argument('--write', action='store_true', help='Set write to true')
parser.add_argument('--delete', action='store_true', help='Set delete to true')
args = parser.parse_args()
if args.reset_root:
from core import auth
from system import install
rootUser = auth._user().getAsClass(query={ "username" : "root" })
if len(rootUser) == 1:
rootUser = rootUser[0]
rootPass = install.randomString(30)
rootUser.setAttribute("passwordHash",rootPass)
rootUser.update(["passwordHash"])
print("Root password reset! Password: {0}".format(rootPass))
elif args.update_conduct_acl:
conductID = args.conduct
aclString = {"accessID":args.acl,"read":False,"write":False,"delete":False}
if args.read:
aclString["read"] = True
if args.write:
aclString["write"] = True
if args.delete:
aclString["delete"] = True
import jimi
counter = 0
conductObj = jimi.conduct._conduct().getAsClass(id=conductID)[0]
webObjects = jimi.webui._modelUI().getAsClass(query={"conductID" : conductID})
#Add ACL to conduct
tempACL = []
added = False
for acl in conductObj.acl["ids"]:
if acl["accessID"] == aclString["accessID"]:
tempACL.append(aclString)
added = True
else:
tempACL.append(acl)
if added == False:
tempACL.append(aclString)
conductObj.acl["ids"] = tempACL
conductObj.update(["acl"])
for jimiObject in conductObj.flow:
counter += 1
if "triggerID" in jimiObject:
#Update trigger object ACL
triggerObject = jimi.trigger._trigger().getAsClass(id=jimiObject["triggerID"])[0]
tempACL = []
added = False
for acl in triggerObject.acl["ids"]:
if acl["accessID"] == aclString["accessID"]:
tempACL.append(aclString)
added = True
else:
tempACL.append(acl)
if added == False:
tempACL.append(aclString)
triggerObject.acl["ids"] = tempACL
triggerObject.update(["acl"])
elif "actionID" in jimiObject:
#Update action object ACL
actionObject = jimi.action._action().getAsClass(id=jimiObject["actionID"])[0]
tempACL = []
added = False
for acl in actionObject.acl["ids"]:
if acl["accessID"] == aclString["accessID"]:
tempACL.append(aclString)
added = True
else:
tempACL.append(acl)
if added == False:
tempACL.append(aclString)
actionObject.acl["ids"] = tempACL
actionObject.update(["acl"])
#Update UI ACL
webObject = [x for x in webObjects if jimiObject["flowID"] == x.flowID][0]
tempACL = []
added = False
for acl in webObject.acl["ids"]:
if acl["accessID"] == aclString["accessID"]:
tempACL.append(aclString)
added = True
else:
tempACL.append(acl)
if added == False:
tempACL.append(aclString)
webObject.acl["ids"] = tempACL
webObject.update(["acl"])
print(f"Updated {counter}/{len(conductObj.flow)} objects with new ACL",end="\r")
print(f"Updated {counter}/{len(conductObj.flow)} objects with new ACL")
else:
from screens import mainScreen
screen = mainScreen.mainScreen()