-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
daemon_get_profile.py
566 lines (548 loc) · 24.7 KB
/
daemon_get_profile.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
__filename__ = "daemon_get_profile.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.5.0"
__maintainer__ = "Bob Mottram"
__email__ = "[email protected]"
__status__ = "Production"
__module_group__ = "Core GET"
import os
import json
from roles import get_actor_roles_list
from skills import no_of_actor_skills
from skills import get_skills_from_list
from utils import get_nickname_from_actor
from utils import load_json
from utils import get_json_content_from_accept
from utils import get_occupation_skills
from utils import get_instance_url
from utils import acct_dir
from utils import convert_domains
from httpcodes import write2
from httpcodes import http_404
from person import person_lookup
from person import add_alternate_domains
from httprequests import request_http
from httpheaders import redirect_headers
from httpheaders import set_headers
from session import establish_session
from city import get_spoofed_city
from webapp_profile import html_profile
from webapp_profile import html_edit_profile
from fitnessFunctions import fitness_performance
from securemode import secure_mode
def show_person_profile(self, authorized: bool,
calling_domain: str,
referer_domain: str, path: str,
base_dir: str, http_prefix: str,
domain: str,
onion_domain: str, i2p_domain: str,
getreq_start_time,
proxy_type: str, cookie: str,
debug: str,
curr_session,
access_keys: {},
key_shortcuts: {}, city: str,
account_timezone: {},
bold_reading_nicknames: {},
max_shares_on_profile: int,
sites_unavailable: [],
fitness: {},
signing_priv_key_pem: str,
rss_icon_at_top: bool,
icons_as_buttons: bool,
default_timeline: str,
recent_posts_cache: {},
max_recent_posts: int,
translate: {},
project_version: str,
cached_webfingers: {},
person_cache: {},
yt_replace_domain: str,
twitter_replacement_domain: str,
show_published_date_only: bool,
newswire: {},
theme_name: str,
dormant_months: int,
peertube_instances: [],
allow_local_network_access: bool,
text_mode_banner: str,
system_language: str,
max_like_count: int,
shared_items_federated_domains: [],
cw_lists: [],
lists_enabled: {},
content_license_url: str,
buy_sites: [],
no_of_books: int,
auto_cw_cache: {}) -> bool:
"""Shows the profile for a person
"""
# look up a person
actor_json = person_lookup(domain, path, base_dir)
if not actor_json:
return False
add_alternate_domains(actor_json, domain, onion_domain, i2p_domain)
if request_http(self.headers, debug):
curr_session = \
establish_session("showPersonProfile",
curr_session, proxy_type,
self.server)
if not curr_session:
http_404(self, 86)
return True
city = None
timezone = None
if '/users/' in path:
nickname = path.split('/users/')[1]
if '/' in nickname:
nickname = nickname.split('/')[0]
if key_shortcuts.get(nickname):
access_keys = key_shortcuts[nickname]
city = get_spoofed_city(city, base_dir, nickname, domain)
if account_timezone.get(nickname):
timezone = account_timezone.get(nickname)
bold_reading = False
if bold_reading_nicknames.get(nickname):
bold_reading = True
msg = \
html_profile(signing_priv_key_pem,
rss_icon_at_top,
icons_as_buttons,
default_timeline,
recent_posts_cache,
max_recent_posts,
translate,
project_version,
base_dir, http_prefix, authorized,
actor_json, 'posts', curr_session,
cached_webfingers,
person_cache,
yt_replace_domain,
twitter_replacement_domain,
show_published_date_only,
newswire,
theme_name,
dormant_months,
peertube_instances,
allow_local_network_access,
text_mode_banner,
debug,
access_keys, city,
system_language,
max_like_count,
shared_items_federated_domains,
None, None, None,
cw_lists,
lists_enabled,
content_license_url,
timezone, bold_reading,
buy_sites,
None,
max_shares_on_profile,
sites_unavailable,
no_of_books,
auto_cw_cache).encode('utf-8')
msglen = len(msg)
set_headers(self, 'text/html', msglen,
cookie, calling_domain, False)
write2(self, msg)
fitness_performance(getreq_start_time, fitness,
'_GET', '_show_person_profile',
debug)
if debug:
print('DEBUG: html actor sent')
else:
if secure_mode(curr_session, proxy_type, False,
self.server, self.headers, self.path):
accept_str = self.headers['Accept']
msg_str = json.dumps(actor_json, ensure_ascii=False)
msg_str = convert_domains(calling_domain,
referer_domain,
msg_str, http_prefix,
domain,
onion_domain,
i2p_domain)
msg = msg_str.encode('utf-8')
msglen = len(msg)
if 'application/ld+json' in accept_str:
set_headers(self, 'application/ld+json', msglen,
cookie, calling_domain, False)
elif 'application/jrd+json' in accept_str:
set_headers(self, 'application/jrd+json', msglen,
cookie, calling_domain, False)
else:
set_headers(self, 'application/activity+json', msglen,
cookie, calling_domain, False)
write2(self, msg)
fitness_performance(getreq_start_time, fitness,
'_GET', '_show_person_profile json',
debug)
if debug:
print('DEBUG: json actor sent')
else:
http_404(self, 87)
return True
def show_roles(self, calling_domain: str, referer_domain: str,
path: str, base_dir: str, http_prefix: str,
domain: str, getreq_start_time,
proxy_type: str, cookie: str, debug: str,
curr_session, default_timeline: str,
recent_posts_cache: {},
cached_webfingers: {},
yt_replace_domain: str,
twitter_replacement_domain: str,
icons_as_buttons: bool,
access_keys: {},
key_shortcuts: {}, city: str,
signing_priv_key_pem: str,
rss_icon_at_top: bool,
shared_items_federated_domains: [],
account_timezone: {},
bold_reading_nicknames: {},
max_recent_posts: int,
translate: {},
project_version: str,
person_cache: {},
show_published_date_only: bool,
newswire: {},
theme_name: str,
dormant_months: int,
peertube_instances: [],
allow_local_network_access: bool,
text_mode_banner: str,
system_language: str,
max_like_count: int,
cw_lists: {},
lists_enabled: {},
content_license_url: str,
buy_sites: {},
max_shares_on_profile: int,
sites_unavailable: [],
no_of_books: int,
auto_cw_cache: {},
fitness: {},
onion_domain: str,
i2p_domain: str) -> bool:
"""Show roles within profile screen
"""
named_status = path.split('/users/')[1]
if '/' not in named_status:
return False
post_sections = named_status.split('/')
nickname = post_sections[0]
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if not os.path.isfile(actor_filename):
return False
actor_json = load_json(actor_filename)
if not actor_json:
return False
if actor_json.get('hasOccupation'):
if request_http(self.headers, debug):
get_person = \
person_lookup(domain, path.replace('/roles', ''),
base_dir)
if get_person:
if key_shortcuts.get(nickname):
access_keys = key_shortcuts[nickname]
roles_list = get_actor_roles_list(actor_json)
city = get_spoofed_city(city, base_dir, nickname, domain)
timezone = None
if account_timezone.get(nickname):
timezone = account_timezone.get(nickname)
bold_reading = False
if bold_reading_nicknames.get(nickname):
bold_reading = True
msg = \
html_profile(signing_priv_key_pem,
rss_icon_at_top,
icons_as_buttons,
default_timeline,
recent_posts_cache,
max_recent_posts,
translate,
project_version,
base_dir, http_prefix, True,
get_person, 'roles',
curr_session,
cached_webfingers,
person_cache,
yt_replace_domain,
twitter_replacement_domain,
show_published_date_only,
newswire,
theme_name,
dormant_months,
peertube_instances,
allow_local_network_access,
text_mode_banner,
debug,
access_keys, city,
system_language,
max_like_count,
shared_items_federated_domains,
roles_list,
None, None, cw_lists,
lists_enabled,
content_license_url,
timezone, bold_reading,
buy_sites, None,
max_shares_on_profile,
sites_unavailable,
no_of_books,
auto_cw_cache)
msg = msg.encode('utf-8')
msglen = len(msg)
set_headers(self, 'text/html', msglen,
cookie, calling_domain, False)
write2(self, msg)
fitness_performance(getreq_start_time, fitness,
'_GET', '_show_roles', debug)
else:
if secure_mode(curr_session, proxy_type, False,
self.server, self.headers, path):
roles_list = get_actor_roles_list(actor_json)
msg_str = json.dumps(roles_list, ensure_ascii=False)
msg_str = convert_domains(calling_domain,
referer_domain,
msg_str, http_prefix,
domain,
onion_domain,
i2p_domain)
msg = msg_str.encode('utf-8')
msglen = len(msg)
protocol_str = \
get_json_content_from_accept(self.headers['Accept'])
set_headers(self, protocol_str, msglen,
None, calling_domain, False)
write2(self, msg)
fitness_performance(getreq_start_time, fitness,
'_GET', '_show_roles json', debug)
else:
http_404(self, 65)
return True
return False
def show_skills(self, calling_domain: str, referer_domain: str,
path: str, base_dir: str, http_prefix: str,
domain: str, getreq_start_time, proxy_type: str,
cookie: str, debug: str, curr_session,
default_timeline: str,
recent_posts_cache: {},
cached_webfingers: {},
yt_replace_domain: str,
twitter_replacement_domain: str,
show_published_date_only: bool,
icons_as_buttons: bool,
allow_local_network_access: bool,
access_keys: {},
key_shortcuts: {},
shared_items_federated_domains: [],
signing_priv_key_pem: str,
content_license_url: str,
peertube_instances: [], city: str,
account_timezone: {},
bold_reading_nicknames: {},
max_shares_on_profile: int,
rss_icon_at_top: bool,
max_recent_posts: int,
translate: {},
project_version: str,
person_cache: {},
newswire: {},
theme_name: str,
dormant_months: int,
text_mode_banner: str,
system_language: str,
max_like_count: int,
cw_lists: {},
lists_enabled: {},
buy_sites: [],
sites_unavailable: [],
no_of_books: int,
auto_cw_cache: {},
fitness: {},
domain_full: str,
onion_domain: str,
i2p_domain: str) -> bool:
"""Show skills on the profile screen
"""
named_status = path.split('/users/')[1]
if '/' in named_status:
post_sections = named_status.split('/')
nickname = post_sections[0]
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
if os.path.isfile(actor_filename):
actor_json = load_json(actor_filename)
if actor_json:
if no_of_actor_skills(actor_json) > 0:
if request_http(self.headers, debug):
get_person = \
person_lookup(domain,
path.replace('/skills', ''),
base_dir)
if get_person:
if key_shortcuts.get(nickname):
access_keys = key_shortcuts[nickname]
actor_skills_list = \
get_occupation_skills(actor_json)
skills = \
get_skills_from_list(actor_skills_list)
city = get_spoofed_city(city, base_dir,
nickname, domain)
shared_items_fed_domains = \
shared_items_federated_domains
timezone = None
nick = nickname
if account_timezone.get(nick):
timezone = account_timezone.get(nick)
bold_reading = False
if bold_reading_nicknames.get(nick):
bold_reading = True
msg = \
html_profile(signing_priv_key_pem,
rss_icon_at_top,
icons_as_buttons,
default_timeline,
recent_posts_cache,
max_recent_posts,
translate,
project_version,
base_dir, http_prefix, True,
get_person, 'skills',
curr_session,
cached_webfingers,
person_cache,
yt_replace_domain,
twitter_replacement_domain,
show_published_date_only,
newswire,
theme_name,
dormant_months,
peertube_instances,
allow_local_network_access,
text_mode_banner,
debug,
access_keys, city,
system_language,
max_like_count,
shared_items_fed_domains,
skills,
None, None,
cw_lists,
lists_enabled,
content_license_url,
timezone, bold_reading,
buy_sites,
None,
max_shares_on_profile,
sites_unavailable,
no_of_books,
auto_cw_cache)
msg = msg.encode('utf-8')
msglen = len(msg)
set_headers(self, 'text/html', msglen,
cookie, calling_domain,
False)
write2(self, msg)
fitness_performance(getreq_start_time, fitness,
'_GET', '_show_skills',
debug)
else:
if secure_mode(curr_session,
proxy_type, False,
self.server,
self.headers,
path):
actor_skills_list = \
get_occupation_skills(actor_json)
skills = \
get_skills_from_list(actor_skills_list)
msg_str = json.dumps(skills,
ensure_ascii=False)
msg_str = convert_domains(calling_domain,
referer_domain,
msg_str,
http_prefix,
domain,
onion_domain,
i2p_domain)
msg = msg_str.encode('utf-8')
msglen = len(msg)
accept_str = self.headers['Accept']
protocol_str = \
get_json_content_from_accept(accept_str)
set_headers(self, protocol_str, msglen, None,
calling_domain, False)
write2(self, msg)
fitness_performance(getreq_start_time, fitness,
'_GET',
'_show_skills json',
debug)
else:
http_404(self, 66)
return True
actor = path.replace('/skills', '')
actor_absolute = \
get_instance_url(calling_domain, http_prefix, domain_full,
onion_domain, i2p_domain) + \
actor
redirect_headers(self, actor_absolute, cookie, calling_domain, 303)
return True
def edit_profile2(self, calling_domain: str, path: str,
translate: {}, base_dir: str,
domain: str, port: int,
cookie: str,
peertube_instances: [],
access_keys: {},
key_shortcuts: {},
default_reply_interval_hrs: int,
default_timeline: str,
theme_name: str,
text_mode_banner: str,
user_agents_blocked: [],
crawlers_allowed: [],
cw_lists: {},
lists_enabled: {},
system_language: str,
min_images_for_accounts: [],
max_recent_posts: int,
reverse_sequence: bool,
buy_sites: [],
block_military: bool,
block_federated_endpoints: []) -> bool:
"""Show the edit profile screen
"""
if '/users/' in path and path.endswith('/editprofile'):
nickname = get_nickname_from_actor(path)
if '/users/' in path:
if key_shortcuts.get(nickname):
access_keys = key_shortcuts[nickname]
msg = html_edit_profile(self.server, translate,
base_dir, path, domain, port,
default_timeline,
theme_name,
peertube_instances,
text_mode_banner,
user_agents_blocked,
crawlers_allowed,
access_keys,
default_reply_interval_hrs,
cw_lists,
lists_enabled,
system_language,
min_images_for_accounts,
max_recent_posts,
reverse_sequence,
buy_sites,
block_military,
block_federated_endpoints)
if msg:
msg = msg.encode('utf-8')
msglen = len(msg)
set_headers(self, 'text/html', msglen,
cookie, calling_domain, False)
write2(self, msg)
else:
http_404(self, 105)
return True
return False