-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
daemon_post_profile.py
3420 lines (3083 loc) · 137 KB
/
daemon_post_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
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
__filename__ = "daemon_post_profile.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.6.0"
__maintainer__ = "Bob Mottram"
__email__ = "[email protected]"
__status__ = "Production"
__module_group__ = "Daemon POST"
import os
import errno
from webfinger import webfinger_update
from socket import error as SocketError
from blocking import save_blocked_military
from blocking import save_blocked_government
from blocking import save_blocked_bluesky
from blocking import save_blocked_nostr
from httpheaders import redirect_headers
from httpheaders import clear_login_details
from flags import is_artist
from flags import is_memorial_account
from flags import is_premium_account
from utils import data_dir
from utils import set_premium_account
from utils import remove_avatar_from_cache
from utils import save_json
from utils import save_reverse_timeline
from utils import set_minimize_all_images
from utils import set_account_timezone
from utils import get_account_timezone
from utils import set_memorials
from utils import get_memorials
from utils import license_link_from_name
from utils import resembles_url
from utils import set_config_param
from utils import set_reply_interval_hours
from utils import valid_password
from utils import remove_eol
from utils import remove_html
from utils import get_url_from_post
from utils import load_json
from utils import acct_dir
from utils import get_config_param
from utils import get_instance_url
from utils import get_nickname_from_actor
from utils import get_occupation_name
from auth import store_basic_credentials
from filters import is_filtered
from content import add_name_emojis_to_tags
from content import add_html_tags
from content import extract_text_fields_in_post
from content import extract_media_in_form_post
from content import save_media_in_form_post
from theme import enable_grayscale
from theme import disable_grayscale
from theme import get_theme
from theme import is_news_theme_name
from theme import set_news_avatar
from theme import get_text_mode_banner
from theme import set_theme
from theme import export_theme
from theme import import_theme
from city import get_spoofed_city
from media import convert_image_to_low_bandwidth
from media import process_meta_data
from webapp_welcome import welcome_screen_is_complete
from skills import no_of_actor_skills
from skills import actor_has_skill
from skills import actor_skill_value
from skills import set_actor_skill_level
from categories import set_hashtag_category
from person import deactivate_account
from person import get_actor_move_json
from person import get_actor_update_json
from person import add_actor_update_timestamp
from person import randomize_actor_images
from person import get_default_person_context
from person import update_memorial_flags
from pgp import set_pgp_pub_key
from pgp import get_pgp_pub_key
from pgp import get_email_address
from pgp import set_email_address
from pgp import set_pgp_fingerprint
from pgp import get_pgp_fingerprint
from pronouns import get_pronouns
from pronouns import set_pronouns
from discord import get_discord
from discord import set_discord
from music import get_music_site_url
from music import set_music_site_url
from art import get_art_site_url
from art import set_art_site_url
from youtube import get_youtube
from youtube import set_youtube
from pixelfed import get_pixelfed
from pixelfed import set_pixelfed
from peertube import get_peertube
from peertube import set_peertube
from xmpp import get_xmpp_address
from xmpp import set_xmpp_address
from matrix import get_matrix_address
from matrix import set_matrix_address
from ssb import get_ssb_address
from ssb import set_ssb_address
from utils import set_occupation_name
from blog import get_blog_address
from webapp_utils import set_blog_address
from session import site_is_verified
from languages import set_actor_languages
from languages import get_actor_languages
from posts import is_moderator
from posts import set_post_expiry_keep_dms
from posts import get_post_expiry_keep_dms
from posts import set_post_expiry_days
from posts import get_post_expiry_days
from posts import set_max_profile_posts
from posts import get_max_profile_posts
from tox import get_tox_address
from tox import set_tox_address
from briar import get_briar_address
from briar import set_briar_address
from cwtch import get_cwtch_address
from cwtch import set_cwtch_address
from enigma import get_enigma_pub_key
from enigma import set_enigma_pub_key
from website import get_website
from website import set_website
from website import get_gemini_link
from website import set_gemini_link
from donate import get_donation_url
from donate import set_donation_url
from person import get_featured_hashtags
from person import set_featured_hashtags
from blocking import save_block_federated_endpoints
from blocking import import_blocking_file
from blocking import add_account_blocks
from blocking import set_broch_mode
from shares import merge_shared_item_tokens
from roles import set_roles_from_list
from schedule import remove_scheduled_posts
from cwlists import get_cw_list_variable
from cache import store_person_in_cache
from daemon_utils import post_to_outbox
def _profile_post_deactivate_account(base_dir: str, nickname: str, domain: str,
calling_domain: str,
fields: {}, self) -> bool:
""" HTTP POST deactivate the account
"""
deactivated = False
if fields.get('deactivateThisAccount'):
if fields['deactivateThisAccount'] == 'on':
deactivate_account(base_dir, nickname, domain)
clear_login_details(self, nickname, calling_domain)
self.server.postreq_busy = False
deactivated = True
return deactivated
def _profile_post_save_actor(base_dir: str, http_prefix: str,
nickname: str, domain: str, port: int,
actor_json: {}, actor_filename: str,
onion_domain: str, i2p_domain: str,
curr_session, proxy_type: str,
send_move_activity: bool,
self, cached_webfingers: {},
person_cache: {}, project_version: str) -> None:
""" HTTP POST save actor json file within accounts
"""
add_name_emojis_to_tags(base_dir, http_prefix,
domain, port,
actor_json)
# update the context for the actor
actor_json['@context'] = [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
get_default_person_context()
]
if actor_json.get('nomadicLocations'):
del actor_json['nomadicLocations']
if not actor_json.get('featured'):
actor_json['featured'] = actor_json['id'] + '/collections/featured'
if not actor_json.get('featuredTags'):
actor_json['featuredTags'] = actor_json['id'] + '/collections/tags'
randomize_actor_images(actor_json)
add_actor_update_timestamp(actor_json)
# save the actor
save_json(actor_json, actor_filename)
webfinger_update(base_dir, nickname, domain,
onion_domain, i2p_domain,
cached_webfingers)
# also copy to the actors cache and
# person_cache in memory
store_person_in_cache(base_dir, actor_json['id'], actor_json,
person_cache, True)
# clear any cached images for this actor
id_str = actor_json['id'].replace('/', '-')
remove_avatar_from_cache(base_dir, id_str)
# save the actor to the cache
actor_cache_filename = \
base_dir + '/cache/actors/' + \
actor_json['id'].replace('/', '#') + '.json'
save_json(actor_json, actor_cache_filename)
# send profile update to followers
update_actor_json = get_actor_update_json(actor_json)
print('Sending actor update: ' + str(update_actor_json))
post_to_outbox(self, update_actor_json,
project_version, nickname,
curr_session, proxy_type)
# send move activity if necessary
if send_move_activity:
move_actor_json = get_actor_move_json(actor_json)
print('Sending Move activity: ' + str(move_actor_json))
post_to_outbox(self, move_actor_json,
project_version,
nickname,
curr_session, proxy_type)
def _profile_post_memorial(base_dir: str, nickname: str,
actor_json: {},
actor_changed: bool) -> bool:
""" HTTP POST change memorial status
"""
if is_memorial_account(base_dir, nickname):
if not actor_json.get('memorial'):
actor_json['memorial'] = True
actor_changed = True
elif actor_json.get('memorial'):
actor_json['memorial'] = False
actor_changed = True
return actor_changed
def _profile_post_git_projects(base_dir: str, nickname: str, domain: str,
fields: {}) -> None:
""" HTTP POST save git project names list
"""
git_projects_filename = \
acct_dir(base_dir, nickname, domain) + '/gitprojects.txt'
if fields.get('gitProjects'):
try:
with open(git_projects_filename, 'w+',
encoding='utf-8') as fp_git:
fp_git.write(fields['gitProjects'].lower())
except OSError:
print('EX: unable to write git ' + git_projects_filename)
else:
if os.path.isfile(git_projects_filename):
try:
os.remove(git_projects_filename)
except OSError:
print('EX: _profile_edit unable to delete ' +
git_projects_filename)
def _profile_post_peertube_instances(base_dir: str, fields: {}, self,
peertube_instances: []) -> None:
""" HTTP POST save peertube instances list
"""
peertube_instances_file = data_dir(base_dir) + '/peertube.txt'
if fields.get('ptInstances'):
peertube_instances.clear()
try:
with open(peertube_instances_file, 'w+',
encoding='utf-8') as fp_peertube:
fp_peertube.write(fields['ptInstances'])
except OSError:
print('EX: unable to write peertube ' +
peertube_instances_file)
pt_instances_list = fields['ptInstances'].split('\n')
if pt_instances_list:
for url in pt_instances_list:
url = url.strip()
if not url:
continue
if url in peertube_instances:
continue
peertube_instances.append(url)
else:
if os.path.isfile(peertube_instances_file):
try:
os.remove(peertube_instances_file)
except OSError:
print('EX: _profile_edit unable to delete ' +
peertube_instances_file)
peertube_instances.clear()
def _profile_post_block_federated(base_dir: str, fields: {}, self) -> None:
""" HTTP POST save blocking API endpoints
"""
block_ep_new: list[str] = []
if fields.get('blockFederated'):
block_federated_str = fields['blockFederated']
block_ep_new = block_federated_str.split('\n')
if str(self.server.block_federated_endpoints) != str(block_ep_new):
self.server.block_federated_endpoints = \
save_block_federated_endpoints(base_dir,
block_ep_new)
if not block_ep_new:
self.server.block_federated = []
def _profile_post_robots_txt(base_dir: str, fields: {}, self) -> None:
""" HTTP POST save robots.txt file
"""
new_robots_txt = ''
if fields.get('robotsTxt'):
new_robots_txt = fields['robotsTxt']
if str(self.server.robots_txt) != str(new_robots_txt):
robots_txt_filename = data_dir(base_dir) + '/robots.txt'
if not new_robots_txt:
self.server.robots_txt = ''
if os.path.isfile(robots_txt_filename):
try:
os.remove(robots_txt_filename)
except OSError:
print('EX: _profile_post_robots_txt' +
' unable to delete ' +
robots_txt_filename)
else:
try:
with open(robots_txt_filename, 'w+',
encoding='utf-8') as fp_robots:
fp_robots.write(new_robots_txt)
except OSError:
print('EX: _profile_post_robots_txt unable to save ' +
robots_txt_filename)
self.server.robots_txt = new_robots_txt
def _profile_post_buy_domains(base_dir: str, fields: {}, self) -> None:
""" HTTP POST save allowed buy domains
"""
buy_sites = {}
if fields.get('buySitesStr'):
buy_sites_str = fields['buySitesStr']
buy_sites_list = buy_sites_str.split('\n')
for site_url in buy_sites_list:
if ' ' in site_url:
site_url = site_url.split(' ')[-1]
buy_icon_text = site_url.replace(site_url, '').strip()
if not buy_icon_text:
buy_icon_text = site_url
else:
buy_icon_text = site_url
if buy_sites.get(buy_icon_text):
continue
if '<' in site_url:
continue
if not site_url.strip():
continue
buy_sites[buy_icon_text] = site_url.strip()
if str(self.server.buy_sites) != str(buy_sites):
self.server.buy_sites = buy_sites
buy_sites_filename = data_dir(base_dir) + '/buy_sites.json'
if buy_sites:
save_json(buy_sites, buy_sites_filename)
else:
if os.path.isfile(buy_sites_filename):
try:
os.remove(buy_sites_filename)
except OSError:
print('EX: unable to delete ' +
buy_sites_filename)
def _profile_post_crawlers_allowed(base_dir: str, fields: {}, self) -> None:
""" HTTP POST save allowed web crawlers
"""
crawlers_allowed: list[str] = []
if fields.get('crawlersAllowedStr'):
crawlers_allowed_str = fields['crawlersAllowedStr']
crawlers_allowed_list = crawlers_allowed_str.split('\n')
for uagent in crawlers_allowed_list:
if uagent in crawlers_allowed:
continue
crawlers_allowed.append(uagent.strip())
if str(self.server.crawlers_allowed) != str(crawlers_allowed):
self.server.crawlers_allowed = crawlers_allowed
crawlers_allowed_str = ''
for uagent in crawlers_allowed:
if crawlers_allowed_str:
crawlers_allowed_str += ','
crawlers_allowed_str += uagent
set_config_param(base_dir, 'crawlersAllowed',
crawlers_allowed_str)
def _profile_post_blocked_user_agents(base_dir: str, fields: {}, self) -> None:
""" HTTP POST save blocked user agents
"""
user_agents_blocked: list[str] = []
if fields.get('userAgentsBlockedStr'):
user_agents_blocked_str = fields['userAgentsBlockedStr']
user_agents_blocked_list = user_agents_blocked_str.split('\n')
for uagent in user_agents_blocked_list:
if uagent in user_agents_blocked:
continue
user_agents_blocked.append(uagent.strip())
if str(self.server.user_agents_blocked) != str(user_agents_blocked):
self.server.user_agents_blocked = user_agents_blocked
user_agents_blocked_str = ''
for uagent in user_agents_blocked:
if user_agents_blocked_str:
user_agents_blocked_str += ','
user_agents_blocked_str += uagent
set_config_param(base_dir, 'userAgentsBlocked',
user_agents_blocked_str)
def _profile_post_cw_lists(fields: {}, self) -> None:
""" HTTP POST set selected content warning lists
"""
new_lists_enabled = ''
for name, _ in self.server.cw_lists.items():
list_var_name = get_cw_list_variable(name)
if fields.get(list_var_name):
if fields[list_var_name] == 'on':
if new_lists_enabled:
new_lists_enabled += ', ' + name
else:
new_lists_enabled += name
if new_lists_enabled != self.server.lists_enabled:
self.server.lists_enabled = new_lists_enabled
set_config_param(self.server.base_dir,
"listsEnabled", new_lists_enabled)
def _profile_post_allowed_instances(base_dir: str, nickname: str, domain: str,
fields: {}) -> None:
""" HTTP POST save allowed instances list
This is the account level allow list
"""
allowed_instances_filename = \
acct_dir(base_dir, nickname, domain) + '/allowedinstances.txt'
if fields.get('allowedInstances'):
inst_filename = allowed_instances_filename
try:
with open(inst_filename, 'w+',
encoding='utf-8') as fp_inst:
fp_inst.write(fields['allowedInstances'])
except OSError:
print('EX: unable to write allowed instances ' +
allowed_instances_filename)
else:
if os.path.isfile(allowed_instances_filename):
try:
os.remove(allowed_instances_filename)
except OSError:
print('EX: _profile_edit ' +
'unable to delete ' +
allowed_instances_filename)
def _profile_post_dm_instances(base_dir: str, nickname: str, domain: str,
fields: {}) -> None:
""" HTTP POST Save DM allowed instances list.
The allow list for incoming DMs,
if the .followDMs flag file exists
"""
dm_allowed_instances_filename = \
acct_dir(base_dir, nickname, domain) + '/dmAllowedInstances.txt'
if fields.get('dmAllowedInstances'):
try:
with open(dm_allowed_instances_filename, 'w+',
encoding='utf-8') as fp_dm:
fp_dm.write(fields['dmAllowedInstances'])
except OSError:
print('EX: unable to write allowed DM instances ' +
dm_allowed_instances_filename)
else:
if os.path.isfile(dm_allowed_instances_filename):
try:
os.remove(dm_allowed_instances_filename)
except OSError:
print('EX: _profile_edit ' +
'unable to delete ' +
dm_allowed_instances_filename)
def _profile_post_import_theme(base_dir: str, nickname: str,
admin_nickname: str, fields: {}) -> None:
""" HTTP POST import theme from file
"""
if fields.get('importTheme'):
if not os.path.isdir(base_dir + '/imports'):
os.mkdir(base_dir + '/imports')
filename_base = base_dir + '/imports/newtheme.zip'
if os.path.isfile(filename_base):
try:
os.remove(filename_base)
except OSError:
print('EX: _profile_edit unable to delete ' +
filename_base)
if nickname == admin_nickname or is_artist(base_dir, nickname):
if import_theme(base_dir, filename_base):
print(nickname + ' uploaded a theme')
else:
print('Only admin or artist can import a theme')
def _profile_post_import_follows(base_dir: str, nickname: str, domain: str,
fields: {}) -> None:
""" HTTP POST import following from file
"""
if fields.get('importFollows'):
filename_base = \
acct_dir(base_dir, nickname, domain) + '/import_following.csv'
follows_str = fields['importFollows']
while follows_str.startswith('\n'):
follows_str = follows_str[1:]
try:
with open(filename_base, 'w+',
encoding='utf-8') as fp_foll:
fp_foll.write(follows_str)
except OSError:
print('EX: unable to write imported follows ' +
filename_base)
def _profile_post_import_blocks_csv(base_dir: str, nickname: str, domain: str,
fields: {}) -> None:
""" HTTP POST import blocks from csv file
"""
if fields.get('importBlocks'):
blocks_str = fields['importBlocks']
while blocks_str.startswith('\n'):
blocks_str = blocks_str[1:]
blocks_lines = blocks_str.split('\n')
if import_blocking_file(base_dir, nickname, domain,
blocks_lines):
print('blocks imported for ' + nickname)
else:
print('blocks not imported for ' + nickname)
def _profile_post_auto_cw(base_dir: str, nickname: str, domain: str,
fields: {}, self) -> None:
""" HTTP POST autogenerated content warnings
"""
auto_cw_filename = \
acct_dir(base_dir, nickname, domain) + '/autocw.txt'
if fields.get('autoCW'):
try:
with open(auto_cw_filename, 'w+',
encoding='utf-8') as fp_auto_cw:
fp_auto_cw.write(fields['autoCW'])
except OSError:
print('EX: unable to write auto CW ' +
auto_cw_filename)
self.server.auto_cw_cache[nickname] = fields['autoCW'].split('\n')
else:
if os.path.isfile(auto_cw_filename):
try:
os.remove(auto_cw_filename)
except OSError:
print('EX: _profile_edit ' +
'unable to delete ' +
auto_cw_filename)
self.server.auto_cw_cache[nickname]: list[str] = []
def _profile_post_autogenerated_tags(base_dir: str,
nickname: str, domain: str,
fields: {}) -> None:
""" HTTP POST autogenerated tags
"""
auto_tags_filename = \
acct_dir(base_dir, nickname, domain) + '/autotags.txt'
if fields.get('autoTags'):
try:
with open(auto_tags_filename, 'w+',
encoding='utf-8') as fp_auto:
fp_auto.write(fields['autoTags'])
except OSError:
print('EX: unable to write auto tags ' +
auto_tags_filename)
else:
if os.path.isfile(auto_tags_filename):
try:
os.remove(auto_tags_filename)
except OSError:
print('EX: _profile_edit unable to delete ' +
auto_tags_filename)
def _profile_post_word_replacements(base_dir: str,
nickname: str, domain: str,
fields: {}) -> None:
""" HTTP POST word replacements
"""
switch_filename = \
acct_dir(base_dir, nickname, domain) + '/replacewords.txt'
if fields.get('switchwords'):
try:
with open(switch_filename, 'w+',
encoding='utf-8') as fp_switch:
fp_switch.write(fields['switchwords'])
except OSError:
print('EX: unable to write switches ' +
switch_filename)
else:
if os.path.isfile(switch_filename):
try:
os.remove(switch_filename)
except OSError:
print('EX: _profile_edit ' +
'unable to delete ' +
switch_filename)
def _profile_post_filtered_words_within_bio(base_dir: str,
nickname: str, domain: str,
fields: {}) -> None:
""" HTTP POST save filtered words within bio list
"""
filter_bio_filename = \
acct_dir(base_dir, nickname, domain) + '/filters_bio.txt'
if fields.get('filteredWordsBio'):
try:
with open(filter_bio_filename, 'w+',
encoding='utf-8') as fp_filter:
fp_filter.write(fields['filteredWordsBio'])
except OSError:
print('EX: unable to write bio filter ' +
filter_bio_filename)
else:
if os.path.isfile(filter_bio_filename):
try:
os.remove(filter_bio_filename)
except OSError:
print('EX: _profile_edit ' +
'unable to delete bio filter ' +
filter_bio_filename)
def _profile_post_filtered_words(base_dir: str, nickname: str, domain: str,
fields: {}) -> None:
""" HTTP POST save filtered words list
"""
filter_filename = acct_dir(base_dir, nickname, domain) + '/filters.txt'
if fields.get('filteredWords'):
try:
with open(filter_filename, 'w+',
encoding='utf-8') as fp_filter:
fp_filter.write(fields['filteredWords'])
except OSError:
print('EX: unable to write filter ' +
filter_filename)
else:
if os.path.isfile(filter_filename):
try:
os.remove(filter_filename)
except OSError:
print('EX: _profile_edit ' +
'unable to delete filter ' +
filter_filename)
def _profile_post_low_bandwidth(base_dir: str, path: str,
nickname: str, admin_nickname: str,
fields: {}, self) -> None:
""" HTTP POST low bandwidth images checkbox
"""
if path.startswith('/users/' + admin_nickname + '/') or \
is_artist(base_dir, nickname):
curr_low_bandwidth = \
get_config_param(base_dir, 'lowBandwidth')
low_bandwidth = False
if fields.get('lowBandwidth'):
if fields['lowBandwidth'] == 'on':
low_bandwidth = True
if curr_low_bandwidth != low_bandwidth:
set_config_param(base_dir, 'lowBandwidth',
low_bandwidth)
self.server.low_bandwidth = low_bandwidth
def _profile_post_dyslexic_font(base_dir: str, path: str,
nickname: str, admin_nickname: str,
fields: {}, self,
theme_name: str,
domain: str,
allow_local_network_access: bool,
system_language: str) -> None:
""" HTTP POST dyslexic font
"""
if path.startswith('/users/' + admin_nickname + '/') or \
is_artist(base_dir, nickname):
dyslexic_font2 = False
if fields.get('dyslexicFont'):
if fields['dyslexicFont'] == 'on':
dyslexic_font2 = True
if dyslexic_font2 != self.server.dyslexic_font:
self.server.dyslexic_font = dyslexic_font2
set_config_param(base_dir, 'dyslexicFont',
self.server.dyslexic_font)
set_theme(base_dir, theme_name, domain,
allow_local_network_access,
system_language,
self.server.dyslexic_font, False)
def _profile_post_grayscale_theme(base_dir: str, path: str,
nickname: str, admin_nickname: str,
fields: {}) -> None:
""" HTTP POST grayscale theme
"""
if path.startswith('/users/' + admin_nickname + '/') or \
is_artist(base_dir, nickname):
grayscale = False
if fields.get('grayscale'):
if fields['grayscale'] == 'on':
grayscale = True
if grayscale:
enable_grayscale(base_dir)
else:
disable_grayscale(base_dir)
def _profile_post_account_type(path: str, actor_json: {}, fields: {},
admin_nickname: str,
actor_changed: bool) -> bool:
""" HTTP POST Changes the type of account Bot/Group/Person
"""
if fields.get('isBot'):
if fields['isBot'] == 'on' and actor_json.get('type'):
if actor_json['type'] != 'Service':
actor_json['type'] = 'Service'
actor_changed = True
else:
# this account is a group
if fields.get('isGroup'):
if fields['isGroup'] == 'on' and actor_json.get('type'):
if actor_json['type'] != 'Group':
# only allow admin to create groups
if path.startswith('/users/' +
admin_nickname + '/'):
actor_json['type'] = 'Group'
actor_changed = True
else:
# this account is a person (default)
if actor_json.get('type'):
if actor_json['type'] != 'Person':
actor_json['type'] = 'Person'
actor_changed = True
return actor_changed
def _profile_post_notify_reactions(base_dir: str,
nickname: str, domain: str,
on_final_welcome_screen: bool,
hide_reaction_button_active: bool,
fields: {}, actor_changed: bool) -> bool:
""" HTTP POST notify about new Reactions
"""
notify_reactions_filename = \
acct_dir(base_dir, nickname, domain) + '/.notifyReactions'
if on_final_welcome_screen:
# default setting from welcome screen
notify_react_filename = notify_reactions_filename
try:
with open(notify_react_filename, 'w+',
encoding='utf-8') as fp_notify:
fp_notify.write('\n')
except OSError:
print('EX: unable to write notify reactions ' +
notify_reactions_filename)
actor_changed = True
else:
notify_reactions_active = False
if fields.get('notifyReactions'):
if fields['notifyReactions'] == 'on' and \
not hide_reaction_button_active:
notify_reactions_active = True
try:
with open(notify_reactions_filename, 'w+',
encoding='utf-8') as fp_notify:
fp_notify.write('\n')
except OSError:
print('EX: unable to write ' +
'notify reactions ' +
notify_reactions_filename)
if not notify_reactions_active:
if os.path.isfile(notify_reactions_filename):
try:
os.remove(notify_reactions_filename)
except OSError:
print('EX: _profile_edit ' +
'unable to delete ' +
notify_reactions_filename)
return actor_changed
def _profile_post_notify_likes(on_final_welcome_screen: bool,
notify_likes_filename: str,
actor_changed: bool,
fields: {},
hide_like_button_active: bool) -> bool:
""" HTTP POST notify about new Likes
"""
if on_final_welcome_screen:
# default setting from welcome screen
try:
with open(notify_likes_filename, 'w+',
encoding='utf-8') as fp_notify:
fp_notify.write('\n')
except OSError:
print('EX: unable to write notify likes ' +
notify_likes_filename)
actor_changed = True
else:
notify_likes_active = False
if fields.get('notifyLikes'):
if fields['notifyLikes'] == 'on' and \
not hide_like_button_active:
notify_likes_active = True
try:
with open(notify_likes_filename, 'w+',
encoding='utf-8') as fp_notify:
fp_notify.write('\n')
except OSError:
print('EX: unable to write notify likes ' +
notify_likes_filename)
if not notify_likes_active:
if os.path.isfile(notify_likes_filename):
try:
os.remove(notify_likes_filename)
except OSError:
print('EX: _profile_edit ' +
'unable to delete ' +
notify_likes_filename)
return actor_changed
def _profile_post_block_military(nickname: str, fields: {}, self) -> None:
""" HTTP POST block military instances
"""
block_mil_instances = False
if fields.get('blockMilitary'):
if fields['blockMilitary'] == 'on':
block_mil_instances = True
if block_mil_instances:
if not self.server.block_military.get(nickname):
self.server.block_military[nickname] = True
save_blocked_military(self.server.base_dir,
self.server.block_military)
else:
if self.server.block_military.get(nickname):
del self.server.block_military[nickname]
save_blocked_military(self.server.base_dir,
self.server.block_military)
def _profile_post_block_government(nickname: str, fields: {}, self) -> None:
""" HTTP POST block government instances
"""
block_gov_instances = False
if fields.get('blockGovernment'):
if fields['blockGovernment'] == 'on':
block_gov_instances = True
if block_gov_instances:
if not self.server.block_government.get(nickname):
self.server.block_government[nickname] = True
save_blocked_government(self.server.base_dir,
self.server.block_government)
else:
if self.server.block_government.get(nickname):
del self.server.block_government[nickname]
save_blocked_government(self.server.base_dir,
self.server.block_government)
def _profile_post_block_bluesky(nickname: str, fields: {}, self) -> None:
""" HTTP POST block bluesky bridges
"""
block_bsky_instances = False
if fields.get('blockBlueSky'):
if fields['blockBlueSky'] == 'on':
block_bsky_instances = True
if block_bsky_instances:
if not self.server.block_bluesky.get(nickname):
self.server.block_bluesky[nickname] = True
save_blocked_bluesky(self.server.base_dir,
self.server.block_bluesky)
else:
if self.server.block_bluesky.get(nickname):
del self.server.block_bluesky[nickname]
save_blocked_bluesky(self.server.base_dir,
self.server.block_bluesky)
def _profile_post_block_nostr(nickname: str, fields: {}, self) -> None:
""" HTTP POST block nostr bridges
"""
block_nostr_instances = False
if fields.get('blockNostr'):
if fields['blockNostr'] == 'on':
block_nostr_instances = True
if block_nostr_instances:
if not self.server.block_nostr.get(nickname):
self.server.block_nostr[nickname] = True
save_blocked_nostr(self.server.base_dir,
self.server.block_nostr)
else:
if self.server.block_nostr.get(nickname):
del self.server.block_nostr[nickname]
save_blocked_nostr(self.server.base_dir,
self.server.block_nostr)
def _profile_post_no_reply_boosts(base_dir: str, nickname: str, domain: str,
fields: {}) -> bool:
""" HTTP POST disallow boosts of replies in inbox
"""
no_reply_boosts_filename = \
acct_dir(base_dir, nickname, domain) + '/.noReplyBoosts'
no_reply_boosts = False
if fields.get('noReplyBoosts'):
if fields['noReplyBoosts'] == 'on':
no_reply_boosts = True
if no_reply_boosts:
if not os.path.isfile(no_reply_boosts_filename):
try:
with open(no_reply_boosts_filename, 'w+',
encoding='utf-8') as fp_reply:
fp_reply.write('\n')
except OSError:
print('EX: unable to write noReplyBoosts ' +
no_reply_boosts_filename)
if not no_reply_boosts:
if os.path.isfile(no_reply_boosts_filename):
try:
os.remove(no_reply_boosts_filename)
except OSError:
print('EX: _profile_edit ' +
'unable to delete ' +
no_reply_boosts_filename)
def _profile_post_no_seen_posts(base_dir: str, nickname: str, domain: str,
fields: {}) -> bool:
""" HTTP POST disallow seen posts in timelines
"""
no_seen_posts_filename = \
acct_dir(base_dir, nickname, domain) + '/.noSeenPosts'
no_seen_posts = False
if fields.get('noSeenPosts'):
if fields['noSeenPosts'] == 'on':
no_seen_posts = True
if no_seen_posts:
if not os.path.isfile(no_seen_posts_filename):
try:
with open(no_seen_posts_filename, 'w+',
encoding='utf-8') as fp_seen:
fp_seen.write('\n')
except OSError:
print('EX: unable to write noSeenPosts ' +
no_seen_posts_filename)
if not no_seen_posts:
if os.path.isfile(no_seen_posts_filename):
try:
os.remove(no_seen_posts_filename)
except OSError:
print('EX: _profile_edit ' +
'unable to delete ' +
no_seen_posts_filename)
def _profile_post_watermark_enabled(base_dir: str,
nickname: str, domain: str,
fields: {}) -> bool:
""" HTTP POST apply watermark to image attachments
"""
watermark_enabled_filename = \
acct_dir(base_dir, nickname, domain) + '/.watermarkEnabled'
watermark_enabled = False
if fields.get('watermarkEnabled'):
if fields['watermarkEnabled'] == 'on':
watermark_enabled = True
if watermark_enabled:
if not os.path.isfile(watermark_enabled_filename):
try:
with open(watermark_enabled_filename, 'w+',
encoding='utf-8') as fp_wm:
fp_wm.write('\n')
except OSError:
print('EX: unable to write watermarkEnabled ' +
watermark_enabled_filename)
if not watermark_enabled:
if os.path.isfile(watermark_enabled_filename):
try:
os.remove(watermark_enabled_filename)
except OSError:
print('EX: _profile_edit ' +
'unable to delete ' +