1
1
import asyncio
2
2
import json
3
3
import re
4
+ import secrets
5
+ import string
4
6
import traceback
5
7
from typing import TYPE_CHECKING , Any
6
8
7
9
import websockets
8
10
9
11
from accounts .utils import is_superuser
10
12
from tacticalrmm .constants import TRMM_WS_MAX_SIZE
11
- from tacticalrmm .helpers import make_random_password
12
13
from tacticalrmm .logger import logger
13
14
14
15
if TYPE_CHECKING :
@@ -40,6 +41,14 @@ def has_mesh_perms(*, user: "User") -> bool:
40
41
return user .role and getattr (user .role , "can_use_mesh" )
41
42
42
43
44
+ def make_mesh_password () -> str :
45
+ alpha = string .ascii_letters + string .digits
46
+ nonalpha = "!@#$"
47
+ passwd = [secrets .choice (alpha ) for _ in range (29 )] + [secrets .choice (nonalpha )]
48
+ secrets .SystemRandom ().shuffle (passwd )
49
+ return "" .join (passwd )
50
+
51
+
43
52
def transform_trmm (obj ):
44
53
ret = []
45
54
try :
@@ -128,7 +137,7 @@ def add_users_to_node(self, *, node_id: str, user_ids: list[str]):
128
137
"action" : "adddeviceuser" ,
129
138
"nodeid" : node_id ,
130
139
"usernames" : [s .replace ("user//" , "" ) for s in user_ids ],
131
- "rights" : 72 ,
140
+ "rights" : 3563736 ,
132
141
"remove" : False ,
133
142
}
134
143
self .mesh_action (payload = payload , wait = False )
@@ -156,7 +165,7 @@ def add_user_to_mesh(self, *, user_info: dict[str, Any]) -> None:
156
165
"action" : "adduser" ,
157
166
"username" : user_info ["username" ],
158
167
"email" : user_info ["email" ],
159
- "pass" : make_random_password ( len = 30 ),
168
+ "pass" : make_mesh_password ( ),
160
169
"resetNextLogin" : False ,
161
170
"randomPassword" : False ,
162
171
"removeEvents" : False ,
@@ -172,23 +181,3 @@ def delete_user_from_mesh(self, *, mesh_user_id: str) -> None:
172
181
"userid" : mesh_user_id ,
173
182
}
174
183
self .mesh_action (payload = payload , wait = False )
175
-
176
- def add_agent_to_user (self , * , user_id : str , node_id : str ) -> None :
177
- payload = {
178
- "action" : "adddeviceuser" ,
179
- "nodeid" : node_id ,
180
- "userids" : [user_id ],
181
- "rights" : 72 ,
182
- "remove" : False ,
183
- }
184
- self .mesh_action (payload = payload , wait = False )
185
-
186
- def remove_agent_from_user (self , * , user_id : str , node_id : str ) -> None :
187
- payload = {
188
- "action" : "adddeviceuser" ,
189
- "nodeid" : node_id ,
190
- "userids" : [user_id ],
191
- "rights" : 0 ,
192
- "remove" : True ,
193
- }
194
- self .mesh_action (payload = payload , wait = False )
0 commit comments