mirror of https://gitlab.com/bashrc2/epicyon
Tidying
parent
2f5f10e897
commit
f1d9fc2ed7
|
|
@ -20,6 +20,7 @@ from flags import is_pgp_encrypted
|
||||||
from flags import contains_pgp_public_key
|
from flags import contains_pgp_public_key
|
||||||
from flags import is_float
|
from flags import is_float
|
||||||
from flags import is_right_to_left_text
|
from flags import is_right_to_left_text
|
||||||
|
from utils import string_starts_with
|
||||||
from utils import replace_strings
|
from utils import replace_strings
|
||||||
from utils import data_dir
|
from utils import data_dir
|
||||||
from utils import remove_link_tracking
|
from utils import remove_link_tracking
|
||||||
|
|
@ -638,8 +639,7 @@ def _shorten_linked_urls(content: str) -> str:
|
||||||
def _contains_doi_reference(wrd: str, replace_dict: {}) -> bool:
|
def _contains_doi_reference(wrd: str, replace_dict: {}) -> bool:
|
||||||
"""Handle DOI scientific references
|
"""Handle DOI scientific references
|
||||||
"""
|
"""
|
||||||
if not wrd.startswith('doi:') and \
|
if not string_starts_with(wrd, ('doi:', 'DOI:')):
|
||||||
not wrd.startswith('DOI:'):
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
doi_ref_str = wrd.split(':', 1)[1]
|
doi_ref_str = wrd.split(':', 1)[1]
|
||||||
|
|
@ -657,9 +657,7 @@ def _contains_doi_reference(wrd: str, replace_dict: {}) -> bool:
|
||||||
def _contains_arxiv_reference(wrd: str, replace_dict: {}) -> bool:
|
def _contains_arxiv_reference(wrd: str, replace_dict: {}) -> bool:
|
||||||
"""Handle arxiv scientific references
|
"""Handle arxiv scientific references
|
||||||
"""
|
"""
|
||||||
if not wrd.startswith('arXiv:') and \
|
if not string_starts_with(wrd, ('arXiv:', 'arx:', 'arxiv:')):
|
||||||
not wrd.startswith('arx:') and \
|
|
||||||
not wrd.startswith('arxiv:'):
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
arxiv_ref_str = wrd.split(':', 1)[1].lower()
|
arxiv_ref_str = wrd.split(':', 1)[1].lower()
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ from flags import is_artist
|
||||||
from flags import is_blog_post
|
from flags import is_blog_post
|
||||||
from timeFunctions import date_utcnow
|
from timeFunctions import date_utcnow
|
||||||
from timeFunctions import get_current_time_int
|
from timeFunctions import get_current_time_int
|
||||||
|
from utils import string_starts_with
|
||||||
from utils import is_yggdrasil_address
|
from utils import is_yggdrasil_address
|
||||||
from utils import replace_strings
|
from utils import replace_strings
|
||||||
from utils import contains_invalid_chars
|
from utils import contains_invalid_chars
|
||||||
|
|
@ -318,8 +319,9 @@ def daemon_http_get(self) -> None:
|
||||||
|
|
||||||
# accounts directory should not be accessible
|
# accounts directory should not be accessible
|
||||||
if self.path.startswith('/accounts/'):
|
if self.path.startswith('/accounts/'):
|
||||||
if not self.path.startswith('/accounts/avatars') and \
|
if not string_starts_with(self.path,
|
||||||
not self.path.startswith('/accounts/headers'):
|
('/accounts/avatars',
|
||||||
|
'/accounts/headers')):
|
||||||
print('GET HTTP Attempt to get accounts file ' + self.path)
|
print('GET HTTP Attempt to get accounts file ' + self.path)
|
||||||
http_404(self, 145)
|
http_404(self, 145)
|
||||||
return
|
return
|
||||||
|
|
@ -2706,9 +2708,8 @@ def daemon_http_get(self) -> None:
|
||||||
self.server.debug)
|
self.server.debug)
|
||||||
|
|
||||||
# image on login screen or qrcode
|
# image on login screen or qrcode
|
||||||
if (is_image_file(self.path) and
|
if is_image_file(self.path) and \
|
||||||
(self.path.startswith('/login.') or
|
(string_starts_with(self.path, ('/login.', '/qrcode.png'))):
|
||||||
self.path.startswith('/qrcode.png'))):
|
|
||||||
icon_filename = data_dir(self.server.base_dir) + self.path
|
icon_filename = data_dir(self.server.base_dir) + self.path
|
||||||
if os.path.isfile(icon_filename):
|
if os.path.isfile(icon_filename):
|
||||||
if etag_exists(self, icon_filename):
|
if etag_exists(self, icon_filename):
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ from httpcodes import http_404
|
||||||
from httpcodes import http_503
|
from httpcodes import http_503
|
||||||
from httpcodes import write2
|
from httpcodes import write2
|
||||||
from httpheaders import set_headers
|
from httpheaders import set_headers
|
||||||
|
from utils import string_starts_with
|
||||||
from utils import convert_domains
|
from utils import convert_domains
|
||||||
from utils import get_instance_url
|
from utils import get_instance_url
|
||||||
from utils import local_network_host
|
from utils import local_network_host
|
||||||
|
|
@ -46,10 +47,11 @@ def get_nodeinfo(self, ua_str: str, calling_domain: str,
|
||||||
if path.startswith('/nodeinfo/1.0'):
|
if path.startswith('/nodeinfo/1.0'):
|
||||||
http_400(self)
|
http_400(self)
|
||||||
return True
|
return True
|
||||||
if not path.startswith('/nodeinfo/2.') and \
|
if not string_starts_with(path,
|
||||||
not path.startswith('/.well-known/host-meta') and \
|
('/nodeinfo/2.',
|
||||||
not path.startswith('/.well-known/nodeinfo') and \
|
'/.well-known/host-meta',
|
||||||
not path.startswith('/.well-known/x-nodeinfo'):
|
'/.well-known/nodeinfo',
|
||||||
|
'/.well-known/x-nodeinfo')):
|
||||||
return False
|
return False
|
||||||
if not referer_domain:
|
if not referer_domain:
|
||||||
if not debug and not unit_test:
|
if not debug and not unit_test:
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ from webfinger import webfinger_lookup
|
||||||
from webfinger import webfinger_node_info
|
from webfinger import webfinger_node_info
|
||||||
from webfinger import webfinger_meta
|
from webfinger import webfinger_meta
|
||||||
from webfinger import wellknown_protocol_handler
|
from webfinger import wellknown_protocol_handler
|
||||||
|
from utils import string_starts_with
|
||||||
from utils import get_json_content_from_accept
|
from utils import get_json_content_from_accept
|
||||||
from utils import convert_domains
|
from utils import convert_domains
|
||||||
from utils import is_yggdrasil_address
|
from utils import is_yggdrasil_address
|
||||||
|
|
@ -60,11 +61,10 @@ def get_webfinger(self, calling_domain: str, referer_domain: str,
|
||||||
return True
|
return True
|
||||||
http_404(self, 6)
|
http_404(self, 6)
|
||||||
return True
|
return True
|
||||||
if path.startswith('/api/statusnet') or \
|
if string_starts_with(path, ('/api/statusnet',
|
||||||
path.startswith('/api/gnusocial') or \
|
'/api/gnusocial',
|
||||||
path.startswith('/siteinfo') or \
|
'/siteinfo',
|
||||||
path.startswith('/poco') or \
|
'/poco', '/friendi')):
|
||||||
path.startswith('/friendi'):
|
|
||||||
http_404(self, 7)
|
http_404(self, 7)
|
||||||
return True
|
return True
|
||||||
# protocol handler. See https://fedi-to.github.io/protocol-handler.html
|
# protocol handler. See https://fedi-to.github.io/protocol-handler.html
|
||||||
|
|
@ -88,8 +88,8 @@ def get_webfinger(self, calling_domain: str, referer_domain: str,
|
||||||
http_404(self, 8)
|
http_404(self, 8)
|
||||||
return True
|
return True
|
||||||
# nodeinfo
|
# nodeinfo
|
||||||
if path.startswith('/.well-known/nodeinfo') or \
|
if string_starts_with(path, ('/.well-known/nodeinfo',
|
||||||
path.startswith('/.well-known/x-nodeinfo'):
|
'/.well-known/x-nodeinfo')):
|
||||||
if calling_domain.endswith('.onion') and onion_domain:
|
if calling_domain.endswith('.onion') and onion_domain:
|
||||||
wf_result = \
|
wf_result = \
|
||||||
webfinger_node_info('http', onion_domain)
|
webfinger_node_info('http', onion_domain)
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import errno
|
||||||
import json
|
import json
|
||||||
from socket import error as SocketError
|
from socket import error as SocketError
|
||||||
from flags import is_corporate
|
from flags import is_corporate
|
||||||
|
from utils import string_starts_with
|
||||||
from utils import is_yggdrasil_address
|
from utils import is_yggdrasil_address
|
||||||
from utils import replace_strings
|
from utils import replace_strings
|
||||||
from utils import string_ends_with
|
from utils import string_ends_with
|
||||||
|
|
@ -205,8 +206,9 @@ def daemon_http_post(self) -> None:
|
||||||
|
|
||||||
# accounts directory should not be accessible
|
# accounts directory should not be accessible
|
||||||
if self.path.startswith('/accounts/'):
|
if self.path.startswith('/accounts/'):
|
||||||
if not self.path.startswith('/accounts/avatars') and \
|
if not string_starts_with(self.path,
|
||||||
not self.path.startswith('/accounts/headers'):
|
('/accounts/avatars',
|
||||||
|
'/accounts/headers')):
|
||||||
print('POST HTTP Attempt to post accounts file ' + self.path)
|
print('POST HTTP Attempt to post accounts file ' + self.path)
|
||||||
http_404(self, 146)
|
http_404(self, 146)
|
||||||
return
|
return
|
||||||
|
|
@ -1134,9 +1136,8 @@ def daemon_http_post(self) -> None:
|
||||||
return
|
return
|
||||||
|
|
||||||
is_media_content = False
|
is_media_content = False
|
||||||
if self.headers['Content-type'].startswith('image/') or \
|
if string_starts_with(self.headers['Content-type'],
|
||||||
self.headers['Content-type'].startswith('video/') or \
|
('image/', 'video/', 'audio/')):
|
||||||
self.headers['Content-type'].startswith('audio/'):
|
|
||||||
is_media_content = True
|
is_media_content = True
|
||||||
|
|
||||||
# check that the content length string is not too long
|
# check that the content length string is not too long
|
||||||
|
|
@ -1180,9 +1181,10 @@ def daemon_http_post(self) -> None:
|
||||||
|
|
||||||
# refuse to receive non-json content
|
# refuse to receive non-json content
|
||||||
content_type_str = self.headers['Content-type']
|
content_type_str = self.headers['Content-type']
|
||||||
if not content_type_str.startswith('application/json') and \
|
if not string_starts_with(content_type_str,
|
||||||
not content_type_str.startswith('application/activity+json') and \
|
('application/json',
|
||||||
not content_type_str.startswith('application/ld+json'):
|
'application/activity+json',
|
||||||
|
'application/ld+json')):
|
||||||
print("POST is not json: " + self.headers['Content-type'])
|
print("POST is not json: " + self.headers['Content-type'])
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
print(str(self.headers).replace('\n', ' '))
|
print(str(self.headers).replace('\n', ' '))
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import os
|
||||||
import errno
|
import errno
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from socket import error as SocketError
|
from socket import error as SocketError
|
||||||
|
from utils import string_starts_with
|
||||||
from utils import data_dir
|
from utils import data_dir
|
||||||
from utils import delete_post
|
from utils import delete_post
|
||||||
from utils import locate_post
|
from utils import locate_post
|
||||||
|
|
@ -131,9 +132,8 @@ def moderator_actions(self, path: str, calling_domain: str, cookie: str,
|
||||||
search_handle = ''
|
search_handle = ''
|
||||||
if '@' not in search_handle or \
|
if '@' not in search_handle or \
|
||||||
'/@/' in search_handle:
|
'/@/' in search_handle:
|
||||||
if search_handle.startswith('http') or \
|
if string_starts_with(search_handle,
|
||||||
search_handle.startswith('ipfs') or \
|
('http', 'ipfs', 'ipns')):
|
||||||
search_handle.startswith('ipns'):
|
|
||||||
search_nickname = \
|
search_nickname = \
|
||||||
get_nickname_from_actor(search_handle)
|
get_nickname_from_actor(search_handle)
|
||||||
if search_nickname:
|
if search_nickname:
|
||||||
|
|
@ -207,10 +207,8 @@ def moderator_actions(self, path: str, calling_domain: str, cookie: str,
|
||||||
print('moderation_button: ' + moderation_button)
|
print('moderation_button: ' + moderation_button)
|
||||||
print('moderation_text: ' + moderation_text)
|
print('moderation_text: ' + moderation_text)
|
||||||
nickname = moderation_text
|
nickname = moderation_text
|
||||||
if nickname.startswith('http') or \
|
if string_starts_with(nickname,
|
||||||
nickname.startswith('ipfs') or \
|
('http', 'ipfs', 'ipns', 'hyper')):
|
||||||
nickname.startswith('ipns') or \
|
|
||||||
nickname.startswith('hyper'):
|
|
||||||
nickname = get_nickname_from_actor(nickname)
|
nickname = get_nickname_from_actor(nickname)
|
||||||
if '@' in nickname:
|
if '@' in nickname:
|
||||||
nickname = nickname.split('@')[0]
|
nickname = nickname.split('@')[0]
|
||||||
|
|
@ -234,10 +232,8 @@ def moderator_actions(self, path: str, calling_domain: str, cookie: str,
|
||||||
moderation_reason = moderation_text.split(' ', 1)[1]
|
moderation_reason = moderation_text.split(' ', 1)[1]
|
||||||
else:
|
else:
|
||||||
moderation_domain = moderation_text
|
moderation_domain = moderation_text
|
||||||
if moderation_domain.startswith('http') or \
|
if string_starts_with(moderation_domain,
|
||||||
moderation_domain.startswith('ipfs') or \
|
('http', 'ipfs', 'ipns', 'hyper')):
|
||||||
moderation_domain.startswith('ipns') or \
|
|
||||||
moderation_domain.startswith('hyper'):
|
|
||||||
# https://domain
|
# https://domain
|
||||||
block_domain, block_port = \
|
block_domain, block_port = \
|
||||||
get_domain_from_actor(moderation_domain)
|
get_domain_from_actor(moderation_domain)
|
||||||
|
|
@ -272,10 +268,8 @@ def moderator_actions(self, path: str, calling_domain: str, cookie: str,
|
||||||
moderation_domain = moderation_text.split(' ', 1)[0]
|
moderation_domain = moderation_text.split(' ', 1)[0]
|
||||||
else:
|
else:
|
||||||
moderation_domain = moderation_text
|
moderation_domain = moderation_text
|
||||||
if moderation_domain.startswith('http') or \
|
if string_starts_with(moderation_domain,
|
||||||
moderation_domain.startswith('ipfs') or \
|
('http', 'ipfs', 'ipns', 'hyper')):
|
||||||
moderation_domain.startswith('ipns') or \
|
|
||||||
moderation_domain.startswith('hyper'):
|
|
||||||
# https://domain
|
# https://domain
|
||||||
block_domain, block_port = \
|
block_domain, block_port = \
|
||||||
get_domain_from_actor(moderation_domain)
|
get_domain_from_actor(moderation_domain)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import urllib.parse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from random import randint
|
from random import randint
|
||||||
from flags import is_pgp_encrypted
|
from flags import is_pgp_encrypted
|
||||||
|
from utils import string_starts_with
|
||||||
from utils import replace_strings
|
from utils import replace_strings
|
||||||
from utils import get_post_attachments
|
from utils import get_post_attachments
|
||||||
from utils import get_url_from_post
|
from utils import get_url_from_post
|
||||||
|
|
@ -1855,8 +1856,8 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
translate,
|
translate,
|
||||||
screenreader, system_language, espeak,
|
screenreader, system_language, espeak,
|
||||||
page_number)
|
page_number)
|
||||||
elif (command_str.startswith('show sen') or
|
elif string_starts_with(command_str,
|
||||||
command_str.startswith('show out')):
|
('show sen', 'show out')):
|
||||||
page_number = 1
|
page_number = 1
|
||||||
prev_timeline_first_id = ''
|
prev_timeline_first_id = ''
|
||||||
curr_timeline = 'outbox'
|
curr_timeline = 'outbox'
|
||||||
|
|
@ -1896,8 +1897,8 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
translate,
|
translate,
|
||||||
screenreader, system_language, espeak,
|
screenreader, system_language, espeak,
|
||||||
page_number)
|
page_number)
|
||||||
elif (command_str.startswith('read ') or
|
elif (string_starts_with(command_str,
|
||||||
command_str.startswith('show ') or
|
('read ', 'show ')) or
|
||||||
command_str == 'read' or
|
command_str == 'read' or
|
||||||
command_str == 'show'):
|
command_str == 'show'):
|
||||||
if command_str in ('read', 'show'):
|
if command_str in ('read', 'show'):
|
||||||
|
|
@ -2051,17 +2052,14 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
mitm_servers)
|
mitm_servers)
|
||||||
refresh_timeline = True
|
refresh_timeline = True
|
||||||
print('')
|
print('')
|
||||||
elif (command_str == 'post' or command_str == 'p' or
|
elif (command_str in ('post', 'p', 'send') or
|
||||||
command_str == 'send' or
|
string_starts_with(command_str,
|
||||||
command_str.startswith('dm ') or
|
('dm ', 'direct message ',
|
||||||
command_str.startswith('direct message ') or
|
'post ', 'send '))):
|
||||||
command_str.startswith('post ') or
|
|
||||||
command_str.startswith('send ')):
|
|
||||||
session_post = create_session(proxy_type)
|
session_post = create_session(proxy_type)
|
||||||
if command_str.startswith('dm ') or \
|
if string_starts_with(command_str,
|
||||||
command_str.startswith('direct message ') or \
|
('dm ', 'direct message ',
|
||||||
command_str.startswith('post ') or \
|
'post ', 'send ')):
|
||||||
command_str.startswith('send '):
|
|
||||||
replacements = {
|
replacements = {
|
||||||
' to ': ' ',
|
' to ': ' ',
|
||||||
' dm ': ' ',
|
' dm ': ' ',
|
||||||
|
|
@ -2143,19 +2141,20 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
mitm_servers)
|
mitm_servers)
|
||||||
refresh_timeline = True
|
refresh_timeline = True
|
||||||
print('')
|
print('')
|
||||||
elif (command_str == 'undo mute' or
|
elif (command_str in ('undo mute',
|
||||||
command_str == 'undo ignore' or
|
'undo ignore',
|
||||||
command_str == 'remove mute' or
|
'remove mute',
|
||||||
command_str == 'rm mute' or
|
'rm mute',
|
||||||
command_str == 'unmute' or
|
'unmute',
|
||||||
command_str == 'unignore' or
|
'unignore',
|
||||||
command_str == 'mute undo' or
|
'mute undo') or
|
||||||
command_str.startswith('undo mute ') or
|
string_starts_with(command_str,
|
||||||
command_str.startswith('undo ignore ') or
|
('undo mute ',
|
||||||
command_str.startswith('remove mute ') or
|
'undo ignore ',
|
||||||
command_str.startswith('remove ignore ') or
|
'remove mute ',
|
||||||
command_str.startswith('unignore ') or
|
'remove ignore ',
|
||||||
command_str.startswith('unmute ')):
|
'unignore ',
|
||||||
|
'unmute '))):
|
||||||
curr_index = 0
|
curr_index = 0
|
||||||
if ' ' in command_str:
|
if ' ' in command_str:
|
||||||
post_index = command_str.split(' ')[-1].strip()
|
post_index = command_str.split(' ')[-1].strip()
|
||||||
|
|
@ -2191,10 +2190,9 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
mitm_servers)
|
mitm_servers)
|
||||||
refresh_timeline = True
|
refresh_timeline = True
|
||||||
print('')
|
print('')
|
||||||
elif (command_str == 'mute' or
|
elif (command_str in ('mute', 'ignore') or
|
||||||
command_str == 'ignore' or
|
string_starts_with(command_str,
|
||||||
command_str.startswith('mute ') or
|
('mute ', 'ignore '))):
|
||||||
command_str.startswith('ignore ')):
|
|
||||||
curr_index = 0
|
curr_index = 0
|
||||||
if ' ' in command_str:
|
if ' ' in command_str:
|
||||||
post_index = command_str.split(' ')[-1].strip()
|
post_index = command_str.split(' ')[-1].strip()
|
||||||
|
|
@ -2230,21 +2228,22 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
mitm_servers)
|
mitm_servers)
|
||||||
refresh_timeline = True
|
refresh_timeline = True
|
||||||
print('')
|
print('')
|
||||||
elif (command_str == 'undo bookmark' or
|
elif (command_str in ('undo bookmark',
|
||||||
command_str == 'remove bookmark' or
|
'remove bookmark',
|
||||||
command_str == 'rm bookmark' or
|
'rm bookmark',
|
||||||
command_str == 'undo bm' or
|
'undo bm',
|
||||||
command_str == 'rm bm' or
|
'rm bm',
|
||||||
command_str == 'remove bm' or
|
'remove bm',
|
||||||
command_str == 'unbookmark' or
|
'unbookmark',
|
||||||
command_str == 'bookmark undo' or
|
'bookmark undo',
|
||||||
command_str == 'bm undo ' or
|
'bm undo ') or
|
||||||
command_str.startswith('undo bm ') or
|
string_starts_with(command_str,
|
||||||
command_str.startswith('remove bm ') or
|
('undo bm ',
|
||||||
command_str.startswith('undo bookmark ') or
|
'remove bm ',
|
||||||
command_str.startswith('remove bookmark ') or
|
'undo bookmark ',
|
||||||
command_str.startswith('unbookmark ') or
|
'remove bookmark ',
|
||||||
command_str.startswith('unbm ')):
|
'unbookmark ',
|
||||||
|
'unbm '))):
|
||||||
curr_index = 0
|
curr_index = 0
|
||||||
if ' ' in command_str:
|
if ' ' in command_str:
|
||||||
post_index = command_str.split(' ')[-1].strip()
|
post_index = command_str.split(' ')[-1].strip()
|
||||||
|
|
@ -2281,10 +2280,9 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
mitm_servers)
|
mitm_servers)
|
||||||
refresh_timeline = True
|
refresh_timeline = True
|
||||||
print('')
|
print('')
|
||||||
elif (command_str == 'bookmark' or
|
elif (command_str in ('bookmark', 'bm') or
|
||||||
command_str == 'bm' or
|
string_starts_with(command_str,
|
||||||
command_str.startswith('bookmark ') or
|
('bookmark ', 'bm '))):
|
||||||
command_str.startswith('bm ')):
|
|
||||||
curr_index = 0
|
curr_index = 0
|
||||||
if ' ' in command_str:
|
if ' ' in command_str:
|
||||||
post_index = command_str.split(' ')[-1].strip()
|
post_index = command_str.split(' ')[-1].strip()
|
||||||
|
|
@ -2319,10 +2317,11 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
mitm_servers)
|
mitm_servers)
|
||||||
refresh_timeline = True
|
refresh_timeline = True
|
||||||
print('')
|
print('')
|
||||||
elif (command_str.startswith('undo block ') or
|
elif string_starts_with(command_str,
|
||||||
command_str.startswith('remove block ') or
|
('undo block ',
|
||||||
command_str.startswith('rm block ') or
|
'remove block ',
|
||||||
command_str.startswith('unblock ')):
|
'rm block ',
|
||||||
|
'unblock ')):
|
||||||
curr_index = 0
|
curr_index = 0
|
||||||
if ' ' in command_str:
|
if ' ' in command_str:
|
||||||
post_index = command_str.split(' ')[-1].strip()
|
post_index = command_str.split(' ')[-1].strip()
|
||||||
|
|
@ -2457,9 +2456,8 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
mitm_servers)
|
mitm_servers)
|
||||||
refresh_timeline = True
|
refresh_timeline = True
|
||||||
print('')
|
print('')
|
||||||
elif (command_str.startswith('announce') or
|
elif string_starts_with(command_str,
|
||||||
command_str.startswith('boost') or
|
('announce', 'boost', 'retweet')):
|
||||||
command_str.startswith('retweet')):
|
|
||||||
curr_index = 0
|
curr_index = 0
|
||||||
if ' ' in command_str:
|
if ' ' in command_str:
|
||||||
post_index = command_str.split(' ')[-1].strip()
|
post_index = command_str.split(' ')[-1].strip()
|
||||||
|
|
@ -2510,11 +2508,12 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
mitm_servers)
|
mitm_servers)
|
||||||
refresh_timeline = True
|
refresh_timeline = True
|
||||||
print('')
|
print('')
|
||||||
elif (command_str.startswith('unannounce') or
|
elif string_starts_with(command_str,
|
||||||
command_str.startswith('undo announce') or
|
('unannounce',
|
||||||
command_str.startswith('unboost') or
|
'undo announce',
|
||||||
command_str.startswith('undo boost') or
|
'unboost',
|
||||||
command_str.startswith('undo retweet')):
|
'undo boost',
|
||||||
|
'undo retweet')):
|
||||||
curr_index = 0
|
curr_index = 0
|
||||||
if ' ' in command_str:
|
if ' ' in command_str:
|
||||||
post_index = command_str.split(' ')[-1].strip()
|
post_index = command_str.split(' ')[-1].strip()
|
||||||
|
|
@ -2664,8 +2663,9 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
_say_command(say_str,
|
_say_command(say_str,
|
||||||
screenreader, system_language, espeak)
|
screenreader, system_language, espeak)
|
||||||
print('')
|
print('')
|
||||||
elif (command_str.startswith('unfollow ') or
|
elif string_starts_with(command_str,
|
||||||
command_str.startswith('stop following ')):
|
('unfollow ',
|
||||||
|
'stop following ')):
|
||||||
follow_handle = command_str.replace('unfollow ', '').strip()
|
follow_handle = command_str.replace('unfollow ', '').strip()
|
||||||
follow_handle = follow_handle.replace('stop following ', '')
|
follow_handle = follow_handle.replace('stop following ', '')
|
||||||
if follow_handle.startswith('@'):
|
if follow_handle.startswith('@'):
|
||||||
|
|
@ -2885,8 +2885,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
_say_command(say_str, say_str, original_screen_reader,
|
_say_command(say_str, say_str, original_screen_reader,
|
||||||
system_language, espeak)
|
system_language, espeak)
|
||||||
print('')
|
print('')
|
||||||
elif (command_str.startswith('pgp') or
|
elif string_starts_with(command_str, ('pgp', 'gpg')):
|
||||||
command_str.startswith('gpg')):
|
|
||||||
if not has_local_pg_pkey():
|
if not has_local_pg_pkey():
|
||||||
print('No PGP public key was found')
|
print('No PGP public key was found')
|
||||||
else:
|
else:
|
||||||
|
|
@ -2901,10 +2900,8 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
||||||
input()
|
input()
|
||||||
prev_timeline_first_id = ''
|
prev_timeline_first_id = ''
|
||||||
refresh_timeline = True
|
refresh_timeline = True
|
||||||
elif (command_str == 'delete' or
|
elif (command_str in ('delete', 'rm') or
|
||||||
command_str == 'rm' or
|
string_starts_with(command_str, ('delete ', 'rm '))):
|
||||||
command_str.startswith('delete ') or
|
|
||||||
command_str.startswith('rm ')):
|
|
||||||
curr_index = 0
|
curr_index = 0
|
||||||
if ' ' in command_str:
|
if ' ' in command_str:
|
||||||
post_index = command_str.split(' ')[-1].strip()
|
post_index = command_str.split(' ')[-1].strip()
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ from tests import test_update_actor
|
||||||
from tests import run_all_tests
|
from tests import run_all_tests
|
||||||
from auth import store_basic_credentials
|
from auth import store_basic_credentials
|
||||||
from auth import create_password
|
from auth import create_password
|
||||||
|
from utils import string_starts_with
|
||||||
from utils import is_yggdrasil_url
|
from utils import is_yggdrasil_url
|
||||||
from utils import is_yggdrasil_address
|
from utils import is_yggdrasil_address
|
||||||
from utils import get_event_categories
|
from utils import get_event_categories
|
||||||
|
|
@ -3110,10 +3111,8 @@ def _command_options() -> None:
|
||||||
original_actor = argb.followers
|
original_actor = argb.followers
|
||||||
if '/@' in argb.followers or \
|
if '/@' in argb.followers or \
|
||||||
'/users/' in argb.followers or \
|
'/users/' in argb.followers or \
|
||||||
argb.followers.startswith('http') or \
|
string_starts_with(argb.followers,
|
||||||
argb.followers.startswith('ipfs') or \
|
('http', 'ipfs', 'ipns', 'hyper')):
|
||||||
argb.followers.startswith('ipns') or \
|
|
||||||
argb.followers.startswith('hyper'):
|
|
||||||
# format: https://domain/@nick
|
# format: https://domain/@nick
|
||||||
prefixes = get_protocol_prefixes()
|
prefixes = get_protocol_prefixes()
|
||||||
for prefix in prefixes:
|
for prefix in prefixes:
|
||||||
|
|
|
||||||
13
follow.py
13
follow.py
|
|
@ -10,6 +10,7 @@ __module_group__ = "ActivityPub"
|
||||||
import os
|
import os
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from flags import has_group_type
|
from flags import has_group_type
|
||||||
|
from utils import string_starts_with
|
||||||
from utils import is_yggdrasil_address
|
from utils import is_yggdrasil_address
|
||||||
from utils import is_yggdrasil_url
|
from utils import is_yggdrasil_url
|
||||||
from utils import get_user_paths
|
from utils import get_user_paths
|
||||||
|
|
@ -435,10 +436,8 @@ def _get_no_of_follows(base_dir: str, nickname: str, domain: str,
|
||||||
('.' in line or is_yggdrasil_url(line)) and \
|
('.' in line or is_yggdrasil_url(line)) and \
|
||||||
not line.startswith('http'):
|
not line.startswith('http'):
|
||||||
ctr += 1
|
ctr += 1
|
||||||
elif ((line.startswith('http') or
|
elif (string_starts_with(line,
|
||||||
line.startswith('ipfs') or
|
('http', 'ipfs', 'ipns', 'hyper')) and
|
||||||
line.startswith('ipns') or
|
|
||||||
line.startswith('hyper')) and
|
|
||||||
has_users_path(line)):
|
has_users_path(line)):
|
||||||
ctr += 1
|
ctr += 1
|
||||||
return ctr
|
return ctr
|
||||||
|
|
@ -569,10 +568,8 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str,
|
||||||
# group actor
|
# group actor
|
||||||
url = http_prefix + '://' + dom + '/c/' + nick
|
url = http_prefix + '://' + dom + '/c/' + nick
|
||||||
following['orderedItems'].append(url)
|
following['orderedItems'].append(url)
|
||||||
elif ((line.startswith('http') or
|
elif (string_starts_with(line,
|
||||||
line.startswith('ipfs') or
|
('http', 'ipfs', 'ipns', 'hyper')) and
|
||||||
line.startswith('ipns') or
|
|
||||||
line.startswith('hyper')) and
|
|
||||||
has_users_path(line)):
|
has_users_path(line)):
|
||||||
# https://domain/users/nickname
|
# https://domain/users/nickname
|
||||||
page_ctr += 1
|
page_ctr += 1
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ from media import process_meta_data
|
||||||
from flags import is_image_file
|
from flags import is_image_file
|
||||||
from timeFunctions import date_utcnow
|
from timeFunctions import date_utcnow
|
||||||
from timeFunctions import get_current_time_int
|
from timeFunctions import get_current_time_int
|
||||||
|
from utils import string_starts_with
|
||||||
from utils import is_yggdrasil_address
|
from utils import is_yggdrasil_address
|
||||||
from utils import get_person_icon
|
from utils import get_person_icon
|
||||||
from utils import account_is_indexable
|
from utils import account_is_indexable
|
||||||
|
|
@ -1882,10 +1883,7 @@ def get_actor_json(host_domain: str, handle: str, http: bool, gnunet: bool,
|
||||||
detected_users_path = _detect_users_path(handle)
|
detected_users_path = _detect_users_path(handle)
|
||||||
if '/@' in handle or \
|
if '/@' in handle or \
|
||||||
detected_users_path in handle or \
|
detected_users_path in handle or \
|
||||||
handle.startswith('http') or \
|
string_starts_with(handle, ('http', 'ipfs', 'ipns', 'hyper')):
|
||||||
handle.startswith('ipfs') or \
|
|
||||||
handle.startswith('ipns') or \
|
|
||||||
handle.startswith('hyper'):
|
|
||||||
group_paths = get_group_paths()
|
group_paths = get_group_paths()
|
||||||
if detected_users_path in group_paths:
|
if detected_users_path in group_paths:
|
||||||
group_account = True
|
group_account = True
|
||||||
|
|
|
||||||
12
posts.py
12
posts.py
|
|
@ -45,6 +45,7 @@ from timeFunctions import date_utcnow
|
||||||
from timeFunctions import date_from_string_format
|
from timeFunctions import date_from_string_format
|
||||||
from timeFunctions import date_epoch
|
from timeFunctions import date_epoch
|
||||||
from timeFunctions import valid_post_date
|
from timeFunctions import valid_post_date
|
||||||
|
from utils import string_starts_with
|
||||||
from utils import is_yggdrasil_address
|
from utils import is_yggdrasil_address
|
||||||
from utils import resembles_url
|
from utils import resembles_url
|
||||||
from utils import get_person_icon
|
from utils import get_person_icon
|
||||||
|
|
@ -2913,10 +2914,8 @@ def create_report_post(base_dir: str,
|
||||||
if moderator_actor not in moderators_list:
|
if moderator_actor not in moderators_list:
|
||||||
moderators_list.append(moderator_actor)
|
moderators_list.append(moderator_actor)
|
||||||
continue
|
continue
|
||||||
if line.startswith('http') or \
|
if string_starts_with(line,
|
||||||
line.startswith('ipfs') or \
|
('http', 'ipfs', 'ipns', 'hyper')):
|
||||||
line.startswith('ipns') or \
|
|
||||||
line.startswith('hyper'):
|
|
||||||
# must be a local address - no remote moderators
|
# must be a local address - no remote moderators
|
||||||
if '://' + domain_full + '/' in line:
|
if '://' + domain_full + '/' in line:
|
||||||
if line not in moderators_list:
|
if line not in moderators_list:
|
||||||
|
|
@ -4663,9 +4662,8 @@ def is_image_media(session, base_dir: str, http_prefix: str,
|
||||||
return False
|
return False
|
||||||
for attach in post_attachments:
|
for attach in post_attachments:
|
||||||
if attach.get('mediaType') and attach.get('url'):
|
if attach.get('mediaType') and attach.get('url'):
|
||||||
if attach['mediaType'].startswith('image/') or \
|
if string_starts_with(attach['mediaType'],
|
||||||
attach['mediaType'].startswith('audio/') or \
|
('image/', 'audio/', 'video/')):
|
||||||
attach['mediaType'].startswith('video/'):
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import ssl
|
||||||
import socket
|
import socket
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from utils import data_dir
|
from utils import data_dir
|
||||||
|
from utils import string_starts_with
|
||||||
|
|
||||||
|
|
||||||
class Result:
|
class Result:
|
||||||
|
|
@ -105,9 +106,7 @@ def site_is_active(url: str, timeout: int,
|
||||||
url = url.replace('<>', '')
|
url = url.replace('<>', '')
|
||||||
if '<' in url:
|
if '<' in url:
|
||||||
url = url.split('<')[0]
|
url = url.split('<')[0]
|
||||||
if not url.startswith('http') and \
|
if not string_starts_with(url, ('http', 'ipfs', 'ipns')):
|
||||||
not url.startswith('ipfs') and \
|
|
||||||
not url.startswith('ipns'):
|
|
||||||
return False
|
return False
|
||||||
if '.onion/' in url or '.i2p/' in url or \
|
if '.onion/' in url or '.i2p/' in url or \
|
||||||
url.endswith('.onion') or \
|
url.endswith('.onion') or \
|
||||||
|
|
|
||||||
22
utils.py
22
utils.py
|
|
@ -563,10 +563,7 @@ def get_sha_512(msg: str):
|
||||||
def local_network_host(host: str) -> bool:
|
def local_network_host(host: str) -> bool:
|
||||||
"""Returns true if the given host is on the local network
|
"""Returns true if the given host is on the local network
|
||||||
"""
|
"""
|
||||||
if host.startswith('localhost') or \
|
if string_starts_with(host, ('localhost', '192.', '127.', '10.')):
|
||||||
host.startswith('192.') or \
|
|
||||||
host.startswith('127.') or \
|
|
||||||
host.startswith('10.'):
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -847,9 +844,7 @@ def get_followers_of_person(base_dir: str,
|
||||||
for account in dirs:
|
for account in dirs:
|
||||||
filename = os.path.join(subdir, account) + '/' + follow_file
|
filename = os.path.join(subdir, account) + '/' + follow_file
|
||||||
if account == handle or \
|
if account == handle or \
|
||||||
account.startswith('inbox@') or \
|
string_starts_with(account, ('inbox@', 'Actor@', 'news@')):
|
||||||
account.startswith('Actor@') or \
|
|
||||||
account.startswith('news@'):
|
|
||||||
continue
|
continue
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
continue
|
continue
|
||||||
|
|
@ -2858,9 +2853,8 @@ def permitted_dir(path: str) -> bool:
|
||||||
"""These are special paths which should not be accessible
|
"""These are special paths which should not be accessible
|
||||||
directly via GET or POST
|
directly via GET or POST
|
||||||
"""
|
"""
|
||||||
if path.startswith('/wfendpoints') or \
|
if string_starts_with(path,
|
||||||
path.startswith('/keys') or \
|
('/wfendpoints', '/keys', '/accounts')):
|
||||||
path.startswith('/accounts'):
|
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -3911,8 +3905,8 @@ def get_media_url_from_torrent(post_json_object: {}) -> (str, str, str,
|
||||||
if not tag_link.get('href'):
|
if not tag_link.get('href'):
|
||||||
continue
|
continue
|
||||||
if tag_link['mediaType'] == 'application/x-bittorrent' or \
|
if tag_link['mediaType'] == 'application/x-bittorrent' or \
|
||||||
tag_link['mediaType'].startswith('magnet:') or \
|
string_starts_with(tag_link['mediaType'],
|
||||||
tag_link['mediaType'].startswith('bencoded:'):
|
('magnet:', 'bencoded:')):
|
||||||
if tag_link['mediaType'].startswith('magnet:'):
|
if tag_link['mediaType'].startswith('magnet:'):
|
||||||
media_magnet = remove_html(media_link['href'])
|
media_magnet = remove_html(media_link['href'])
|
||||||
elif tag_link['mediaType'].startswith('bencoded:'):
|
elif tag_link['mediaType'].startswith('bencoded:'):
|
||||||
|
|
@ -4078,7 +4072,7 @@ def check_bad_path(path: str):
|
||||||
# allow /.well-known/...
|
# allow /.well-known/...
|
||||||
if '/.' in path_lower:
|
if '/.' in path_lower:
|
||||||
good_starts = ('/.well-known/', '/users/.well-known/')
|
good_starts = ('/.well-known/', '/users/.well-known/')
|
||||||
if _string_starts_with(path_lower, good_starts):
|
if string_starts_with(path_lower, good_starts):
|
||||||
bad_strings = ('..', '%2e%2e', '%252e%252e')
|
bad_strings = ('..', '%2e%2e', '%252e%252e')
|
||||||
|
|
||||||
if path_lower.startswith('/wp-'):
|
if path_lower.startswith('/wp-'):
|
||||||
|
|
@ -4128,7 +4122,7 @@ def set_premium_account(base_dir: str, nickname: str, domain: str,
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _string_starts_with(text: str, possible_begin: []) -> bool:
|
def string_starts_with(text: str, possible_begin: []) -> bool:
|
||||||
""" Does the given text start with at least one of the beginnings
|
""" Does the given text start with at least one of the beginnings
|
||||||
"""
|
"""
|
||||||
for start_str in possible_begin:
|
for start_str in possible_begin:
|
||||||
|
|
|
||||||
|
|
@ -276,8 +276,11 @@ def get_show_map_button(post_id: str, translate: {},
|
||||||
map_content: str) -> str:
|
map_content: str) -> str:
|
||||||
"""Returns the markup for a "show map" button
|
"""Returns the markup for a "show map" button
|
||||||
"""
|
"""
|
||||||
|
show_map_str = 'Show Map'
|
||||||
|
if translate.get('Show Map'):
|
||||||
|
show_map_str = translate['Show Map']
|
||||||
return ' <details><summary class="cw" tabindex="10">' + \
|
return ' <details><summary class="cw" tabindex="10">' + \
|
||||||
translate['Show Map'] + '</summary>' + \
|
show_map_str + '</summary>' + \
|
||||||
'<div id="' + post_id + '">' + map_content + \
|
'<div id="' + post_id + '">' + map_content + \
|
||||||
'</div></details>\n'
|
'</div></details>\n'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue