Merge branch 'main' of gitlab.com:bashrc2/epicyon
97
blocking.py
|
@ -432,6 +432,103 @@ def is_blocked(base_dir: str, nickname: str, domain: str,
|
|||
return False
|
||||
|
||||
|
||||
def allowed_announce(base_dir: str, nickname: str, domain: str,
|
||||
block_nickname: str, block_domain: str,
|
||||
announce_blocked_cache: [] = None) -> bool:
|
||||
"""Is the given nickname allowed to send announces?
|
||||
"""
|
||||
block_handle = None
|
||||
if block_nickname and block_domain:
|
||||
block_handle = block_nickname + '@' + block_domain
|
||||
|
||||
# cached announce blocks
|
||||
if announce_blocked_cache:
|
||||
for blocked_str in announce_blocked_cache:
|
||||
if '*@' + domain in blocked_str:
|
||||
return False
|
||||
if block_handle:
|
||||
if blocked_str == block_handle:
|
||||
return False
|
||||
|
||||
# non-cached instance level announce blocks
|
||||
global_announce_blocks_filename = \
|
||||
base_dir + '/accounts/noannounce.txt'
|
||||
if os.path.isfile(global_announce_blocks_filename):
|
||||
if text_in_file('*@' + block_domain,
|
||||
global_announce_blocks_filename):
|
||||
return False
|
||||
if block_handle:
|
||||
block_str = block_handle + '\n'
|
||||
if text_in_file(block_str,
|
||||
global_announce_blocks_filename):
|
||||
return False
|
||||
|
||||
# non-cached account level announce blocks
|
||||
account_dir = acct_dir(base_dir, nickname, domain)
|
||||
blocking_filename = account_dir + '/noannounce.txt'
|
||||
if os.path.isfile(blocking_filename):
|
||||
if text_in_file('*@' + block_domain + '\n', blocking_filename):
|
||||
return False
|
||||
if block_handle:
|
||||
if text_in_file(block_handle + '\n', blocking_filename):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def allowed_announce_add(base_dir: str, nickname: str, domain: str,
|
||||
following_nickname: str,
|
||||
following_domain: str) -> None:
|
||||
"""Allow announces for a handle
|
||||
"""
|
||||
account_dir = acct_dir(base_dir, nickname, domain)
|
||||
blocking_filename = account_dir + '/noannounce.txt'
|
||||
handle = following_nickname + '@' + following_domain
|
||||
if text_in_file(handle + '\n', blocking_filename):
|
||||
file_text = ''
|
||||
try:
|
||||
with open(blocking_filename, 'r',
|
||||
encoding='utf-8') as fp_noannounce:
|
||||
file_text = fp_noannounce.read()
|
||||
file_text = file_text.replace(handle + '\n', '')
|
||||
except OSError:
|
||||
print('EX: unable to read noannounce: ' +
|
||||
blocking_filename + ' ' + handle)
|
||||
try:
|
||||
with open(blocking_filename, 'w+',
|
||||
encoding='utf-8') as fp_noannounce:
|
||||
fp_noannounce.write(file_text)
|
||||
except OSError:
|
||||
print('EX: unable to write noannounce: ' +
|
||||
blocking_filename + ' ' + handle)
|
||||
|
||||
|
||||
def allowed_announce_remove(base_dir: str, nickname: str, domain: str,
|
||||
following_nickname: str,
|
||||
following_domain: str) -> None:
|
||||
"""Don't allow announces from a handle
|
||||
"""
|
||||
account_dir = acct_dir(base_dir, nickname, domain)
|
||||
blocking_filename = account_dir + '/noannounce.txt'
|
||||
handle = following_nickname + '@' + following_domain
|
||||
file_text = ''
|
||||
if not text_in_file(handle + '\n', blocking_filename):
|
||||
try:
|
||||
with open(blocking_filename, 'r',
|
||||
encoding='utf-8') as fp_noannounce:
|
||||
file_text = fp_noannounce.read()
|
||||
except OSError:
|
||||
print('EX: unable to read noannounce: ' +
|
||||
blocking_filename + ' ' + handle)
|
||||
file_text += handle + '\n'
|
||||
try:
|
||||
with open(blocking_filename, 'w+',
|
||||
encoding='utf-8') as fp_noannounce:
|
||||
fp_noannounce.write(file_text)
|
||||
except OSError:
|
||||
print('EX: unable to write noannounce: ' +
|
||||
blocking_filename + ' ' + handle)
|
||||
|
||||
|
||||
def outbox_block(base_dir: str, nickname: str, domain: str,
|
||||
message_json: {}, debug: bool) -> bool:
|
||||
""" When a block request is received by the outbox from c2s
|
||||
|
|
|
@ -1815,8 +1815,12 @@ def import_emoji(base_dir: str, import_filename: str, session) -> None:
|
|||
with open(import_filename, "r", encoding='utf-8') as fp_emoji:
|
||||
lines = fp_emoji.readlines()
|
||||
for line in lines:
|
||||
if ', ' not in line:
|
||||
continue
|
||||
url = line.split(', ')[0]
|
||||
tag = line.split(', ')[1].strip()
|
||||
if ':' not in tag:
|
||||
continue
|
||||
tag = tag.split(':')[1]
|
||||
if emoji_dict.get(tag):
|
||||
continue
|
||||
|
|
31
daemon.py
|
@ -154,6 +154,8 @@ from blocking import remove_global_block
|
|||
from blocking import is_blocked_hashtag
|
||||
from blocking import is_blocked_domain
|
||||
from blocking import get_domain_blocklist
|
||||
from blocking import allowed_announce_add
|
||||
from blocking import allowed_announce_remove
|
||||
from roles import set_roles_from_list
|
||||
from roles import get_actor_roles_list
|
||||
from blog import path_contains_blog_link
|
||||
|
@ -3046,6 +3048,35 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.postreq_busy = False
|
||||
return
|
||||
|
||||
# person options screen, allow announces checkbox
|
||||
# See html_person_options
|
||||
if '&submitAllowAnnounce=' in options_confirm_params:
|
||||
allow_announce = None
|
||||
if 'allowAnnounce=' in options_confirm_params:
|
||||
allow_announce = \
|
||||
options_confirm_params.split('allowAnnounce=')[1]
|
||||
if '&' in allow_announce:
|
||||
allow_announce = allow_announce.split('&')[0]
|
||||
if allow_announce == 'on':
|
||||
allowed_announce_add(base_dir,
|
||||
chooser_nickname,
|
||||
domain,
|
||||
options_nickname,
|
||||
options_domain_full)
|
||||
else:
|
||||
allowed_announce_remove(base_dir,
|
||||
chooser_nickname,
|
||||
domain,
|
||||
options_nickname,
|
||||
options_domain_full)
|
||||
users_path_str = \
|
||||
users_path + '/' + self.server.default_timeline + \
|
||||
'?page=' + str(page_number)
|
||||
self._redirect_headers(users_path_str, cookie,
|
||||
calling_domain)
|
||||
self.server.postreq_busy = False
|
||||
return
|
||||
|
||||
# person options screen, on notify checkbox
|
||||
# See html_person_options
|
||||
if '&submitNotifyOnPost=' in options_confirm_params:
|
||||
|
|
After Width: | Height: | Size: 6.1 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 7.8 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 9.8 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 9.9 KiB |
After Width: | Height: | Size: 51 KiB |
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 6.9 KiB |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 264 B |
After Width: | Height: | Size: 426 B |
After Width: | Height: | Size: 795 B |
After Width: | Height: | Size: 5.5 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 975 B |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 5.4 KiB |
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 978 B |
After Width: | Height: | Size: 615 B |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 389 B |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 7.3 KiB |
After Width: | Height: | Size: 954 B |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 5.1 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 220 B |
After Width: | Height: | Size: 233 B |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 212 B |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.5 KiB |