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 is_float
|
||||
from flags import is_right_to_left_text
|
||||
from utils import string_starts_with
|
||||
from utils import replace_strings
|
||||
from utils import data_dir
|
||||
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:
|
||||
"""Handle DOI scientific references
|
||||
"""
|
||||
if not wrd.startswith('doi:') and \
|
||||
not wrd.startswith('DOI:'):
|
||||
if not string_starts_with(wrd, ('doi:', 'DOI:')):
|
||||
return False
|
||||
|
||||
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:
|
||||
"""Handle arxiv scientific references
|
||||
"""
|
||||
if not wrd.startswith('arXiv:') and \
|
||||
not wrd.startswith('arx:') and \
|
||||
not wrd.startswith('arxiv:'):
|
||||
if not string_starts_with(wrd, ('arXiv:', 'arx:', 'arxiv:')):
|
||||
return False
|
||||
|
||||
arxiv_ref_str = wrd.split(':', 1)[1].lower()
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ from flags import is_artist
|
|||
from flags import is_blog_post
|
||||
from timeFunctions import date_utcnow
|
||||
from timeFunctions import get_current_time_int
|
||||
from utils import string_starts_with
|
||||
from utils import is_yggdrasil_address
|
||||
from utils import replace_strings
|
||||
from utils import contains_invalid_chars
|
||||
|
|
@ -318,8 +319,9 @@ def daemon_http_get(self) -> None:
|
|||
|
||||
# accounts directory should not be accessible
|
||||
if self.path.startswith('/accounts/'):
|
||||
if not self.path.startswith('/accounts/avatars') and \
|
||||
not self.path.startswith('/accounts/headers'):
|
||||
if not string_starts_with(self.path,
|
||||
('/accounts/avatars',
|
||||
'/accounts/headers')):
|
||||
print('GET HTTP Attempt to get accounts file ' + self.path)
|
||||
http_404(self, 145)
|
||||
return
|
||||
|
|
@ -2706,9 +2708,8 @@ def daemon_http_get(self) -> None:
|
|||
self.server.debug)
|
||||
|
||||
# image on login screen or qrcode
|
||||
if (is_image_file(self.path) and
|
||||
(self.path.startswith('/login.') or
|
||||
self.path.startswith('/qrcode.png'))):
|
||||
if is_image_file(self.path) and \
|
||||
(string_starts_with(self.path, ('/login.', '/qrcode.png'))):
|
||||
icon_filename = data_dir(self.server.base_dir) + self.path
|
||||
if os.path.isfile(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 write2
|
||||
from httpheaders import set_headers
|
||||
from utils import string_starts_with
|
||||
from utils import convert_domains
|
||||
from utils import get_instance_url
|
||||
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'):
|
||||
http_400(self)
|
||||
return True
|
||||
if not path.startswith('/nodeinfo/2.') and \
|
||||
not path.startswith('/.well-known/host-meta') and \
|
||||
not path.startswith('/.well-known/nodeinfo') and \
|
||||
not path.startswith('/.well-known/x-nodeinfo'):
|
||||
if not string_starts_with(path,
|
||||
('/nodeinfo/2.',
|
||||
'/.well-known/host-meta',
|
||||
'/.well-known/nodeinfo',
|
||||
'/.well-known/x-nodeinfo')):
|
||||
return False
|
||||
if not referer_domain:
|
||||
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_meta
|
||||
from webfinger import wellknown_protocol_handler
|
||||
from utils import string_starts_with
|
||||
from utils import get_json_content_from_accept
|
||||
from utils import convert_domains
|
||||
from utils import is_yggdrasil_address
|
||||
|
|
@ -60,11 +61,10 @@ def get_webfinger(self, calling_domain: str, referer_domain: str,
|
|||
return True
|
||||
http_404(self, 6)
|
||||
return True
|
||||
if path.startswith('/api/statusnet') or \
|
||||
path.startswith('/api/gnusocial') or \
|
||||
path.startswith('/siteinfo') or \
|
||||
path.startswith('/poco') or \
|
||||
path.startswith('/friendi'):
|
||||
if string_starts_with(path, ('/api/statusnet',
|
||||
'/api/gnusocial',
|
||||
'/siteinfo',
|
||||
'/poco', '/friendi')):
|
||||
http_404(self, 7)
|
||||
return True
|
||||
# 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)
|
||||
return True
|
||||
# nodeinfo
|
||||
if path.startswith('/.well-known/nodeinfo') or \
|
||||
path.startswith('/.well-known/x-nodeinfo'):
|
||||
if string_starts_with(path, ('/.well-known/nodeinfo',
|
||||
'/.well-known/x-nodeinfo')):
|
||||
if calling_domain.endswith('.onion') and onion_domain:
|
||||
wf_result = \
|
||||
webfinger_node_info('http', onion_domain)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import errno
|
|||
import json
|
||||
from socket import error as SocketError
|
||||
from flags import is_corporate
|
||||
from utils import string_starts_with
|
||||
from utils import is_yggdrasil_address
|
||||
from utils import replace_strings
|
||||
from utils import string_ends_with
|
||||
|
|
@ -205,8 +206,9 @@ def daemon_http_post(self) -> None:
|
|||
|
||||
# accounts directory should not be accessible
|
||||
if self.path.startswith('/accounts/'):
|
||||
if not self.path.startswith('/accounts/avatars') and \
|
||||
not self.path.startswith('/accounts/headers'):
|
||||
if not string_starts_with(self.path,
|
||||
('/accounts/avatars',
|
||||
'/accounts/headers')):
|
||||
print('POST HTTP Attempt to post accounts file ' + self.path)
|
||||
http_404(self, 146)
|
||||
return
|
||||
|
|
@ -1134,9 +1136,8 @@ def daemon_http_post(self) -> None:
|
|||
return
|
||||
|
||||
is_media_content = False
|
||||
if self.headers['Content-type'].startswith('image/') or \
|
||||
self.headers['Content-type'].startswith('video/') or \
|
||||
self.headers['Content-type'].startswith('audio/'):
|
||||
if string_starts_with(self.headers['Content-type'],
|
||||
('image/', 'video/', 'audio/')):
|
||||
is_media_content = True
|
||||
|
||||
# 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
|
||||
content_type_str = self.headers['Content-type']
|
||||
if not content_type_str.startswith('application/json') and \
|
||||
not content_type_str.startswith('application/activity+json') and \
|
||||
not content_type_str.startswith('application/ld+json'):
|
||||
if not string_starts_with(content_type_str,
|
||||
('application/json',
|
||||
'application/activity+json',
|
||||
'application/ld+json')):
|
||||
print("POST is not json: " + self.headers['Content-type'])
|
||||
if self.server.debug:
|
||||
print(str(self.headers).replace('\n', ' '))
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import os
|
|||
import errno
|
||||
import urllib.parse
|
||||
from socket import error as SocketError
|
||||
from utils import string_starts_with
|
||||
from utils import data_dir
|
||||
from utils import delete_post
|
||||
from utils import locate_post
|
||||
|
|
@ -131,9 +132,8 @@ def moderator_actions(self, path: str, calling_domain: str, cookie: str,
|
|||
search_handle = ''
|
||||
if '@' not in search_handle or \
|
||||
'/@/' in search_handle:
|
||||
if search_handle.startswith('http') or \
|
||||
search_handle.startswith('ipfs') or \
|
||||
search_handle.startswith('ipns'):
|
||||
if string_starts_with(search_handle,
|
||||
('http', 'ipfs', 'ipns')):
|
||||
search_nickname = \
|
||||
get_nickname_from_actor(search_handle)
|
||||
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_text: ' + moderation_text)
|
||||
nickname = moderation_text
|
||||
if nickname.startswith('http') or \
|
||||
nickname.startswith('ipfs') or \
|
||||
nickname.startswith('ipns') or \
|
||||
nickname.startswith('hyper'):
|
||||
if string_starts_with(nickname,
|
||||
('http', 'ipfs', 'ipns', 'hyper')):
|
||||
nickname = get_nickname_from_actor(nickname)
|
||||
if '@' in nickname:
|
||||
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]
|
||||
else:
|
||||
moderation_domain = moderation_text
|
||||
if moderation_domain.startswith('http') or \
|
||||
moderation_domain.startswith('ipfs') or \
|
||||
moderation_domain.startswith('ipns') or \
|
||||
moderation_domain.startswith('hyper'):
|
||||
if string_starts_with(moderation_domain,
|
||||
('http', 'ipfs', 'ipns', 'hyper')):
|
||||
# https://domain
|
||||
block_domain, block_port = \
|
||||
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]
|
||||
else:
|
||||
moderation_domain = moderation_text
|
||||
if moderation_domain.startswith('http') or \
|
||||
moderation_domain.startswith('ipfs') or \
|
||||
moderation_domain.startswith('ipns') or \
|
||||
moderation_domain.startswith('hyper'):
|
||||
if string_starts_with(moderation_domain,
|
||||
('http', 'ipfs', 'ipns', 'hyper')):
|
||||
# https://domain
|
||||
block_domain, block_port = \
|
||||
get_domain_from_actor(moderation_domain)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import urllib.parse
|
|||
from pathlib import Path
|
||||
from random import randint
|
||||
from flags import is_pgp_encrypted
|
||||
from utils import string_starts_with
|
||||
from utils import replace_strings
|
||||
from utils import get_post_attachments
|
||||
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,
|
||||
screenreader, system_language, espeak,
|
||||
page_number)
|
||||
elif (command_str.startswith('show sen') or
|
||||
command_str.startswith('show out')):
|
||||
elif string_starts_with(command_str,
|
||||
('show sen', 'show out')):
|
||||
page_number = 1
|
||||
prev_timeline_first_id = ''
|
||||
curr_timeline = 'outbox'
|
||||
|
|
@ -1896,8 +1897,8 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
translate,
|
||||
screenreader, system_language, espeak,
|
||||
page_number)
|
||||
elif (command_str.startswith('read ') or
|
||||
command_str.startswith('show ') or
|
||||
elif (string_starts_with(command_str,
|
||||
('read ', 'show ')) or
|
||||
command_str == 'read' or
|
||||
command_str == '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)
|
||||
refresh_timeline = True
|
||||
print('')
|
||||
elif (command_str == 'post' or command_str == 'p' or
|
||||
command_str == 'send' or
|
||||
command_str.startswith('dm ') or
|
||||
command_str.startswith('direct message ') or
|
||||
command_str.startswith('post ') or
|
||||
command_str.startswith('send ')):
|
||||
elif (command_str in ('post', 'p', 'send') or
|
||||
string_starts_with(command_str,
|
||||
('dm ', 'direct message ',
|
||||
'post ', 'send '))):
|
||||
session_post = create_session(proxy_type)
|
||||
if command_str.startswith('dm ') or \
|
||||
command_str.startswith('direct message ') or \
|
||||
command_str.startswith('post ') or \
|
||||
command_str.startswith('send '):
|
||||
if string_starts_with(command_str,
|
||||
('dm ', 'direct message ',
|
||||
'post ', 'send ')):
|
||||
replacements = {
|
||||
' to ': ' ',
|
||||
' dm ': ' ',
|
||||
|
|
@ -2143,19 +2141,20 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
mitm_servers)
|
||||
refresh_timeline = True
|
||||
print('')
|
||||
elif (command_str == 'undo mute' or
|
||||
command_str == 'undo ignore' or
|
||||
command_str == 'remove mute' or
|
||||
command_str == 'rm mute' or
|
||||
command_str == 'unmute' or
|
||||
command_str == 'unignore' or
|
||||
command_str == 'mute undo' or
|
||||
command_str.startswith('undo mute ') or
|
||||
command_str.startswith('undo ignore ') or
|
||||
command_str.startswith('remove mute ') or
|
||||
command_str.startswith('remove ignore ') or
|
||||
command_str.startswith('unignore ') or
|
||||
command_str.startswith('unmute ')):
|
||||
elif (command_str in ('undo mute',
|
||||
'undo ignore',
|
||||
'remove mute',
|
||||
'rm mute',
|
||||
'unmute',
|
||||
'unignore',
|
||||
'mute undo') or
|
||||
string_starts_with(command_str,
|
||||
('undo mute ',
|
||||
'undo ignore ',
|
||||
'remove mute ',
|
||||
'remove ignore ',
|
||||
'unignore ',
|
||||
'unmute '))):
|
||||
curr_index = 0
|
||||
if ' ' in command_str:
|
||||
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)
|
||||
refresh_timeline = True
|
||||
print('')
|
||||
elif (command_str == 'mute' or
|
||||
command_str == 'ignore' or
|
||||
command_str.startswith('mute ') or
|
||||
command_str.startswith('ignore ')):
|
||||
elif (command_str in ('mute', 'ignore') or
|
||||
string_starts_with(command_str,
|
||||
('mute ', 'ignore '))):
|
||||
curr_index = 0
|
||||
if ' ' in command_str:
|
||||
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)
|
||||
refresh_timeline = True
|
||||
print('')
|
||||
elif (command_str == 'undo bookmark' or
|
||||
command_str == 'remove bookmark' or
|
||||
command_str == 'rm bookmark' or
|
||||
command_str == 'undo bm' or
|
||||
command_str == 'rm bm' or
|
||||
command_str == 'remove bm' or
|
||||
command_str == 'unbookmark' or
|
||||
command_str == 'bookmark undo' or
|
||||
command_str == 'bm undo ' or
|
||||
command_str.startswith('undo bm ') or
|
||||
command_str.startswith('remove bm ') or
|
||||
command_str.startswith('undo bookmark ') or
|
||||
command_str.startswith('remove bookmark ') or
|
||||
command_str.startswith('unbookmark ') or
|
||||
command_str.startswith('unbm ')):
|
||||
elif (command_str in ('undo bookmark',
|
||||
'remove bookmark',
|
||||
'rm bookmark',
|
||||
'undo bm',
|
||||
'rm bm',
|
||||
'remove bm',
|
||||
'unbookmark',
|
||||
'bookmark undo',
|
||||
'bm undo ') or
|
||||
string_starts_with(command_str,
|
||||
('undo bm ',
|
||||
'remove bm ',
|
||||
'undo bookmark ',
|
||||
'remove bookmark ',
|
||||
'unbookmark ',
|
||||
'unbm '))):
|
||||
curr_index = 0
|
||||
if ' ' in command_str:
|
||||
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)
|
||||
refresh_timeline = True
|
||||
print('')
|
||||
elif (command_str == 'bookmark' or
|
||||
command_str == 'bm' or
|
||||
command_str.startswith('bookmark ') or
|
||||
command_str.startswith('bm ')):
|
||||
elif (command_str in ('bookmark', 'bm') or
|
||||
string_starts_with(command_str,
|
||||
('bookmark ', 'bm '))):
|
||||
curr_index = 0
|
||||
if ' ' in command_str:
|
||||
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)
|
||||
refresh_timeline = True
|
||||
print('')
|
||||
elif (command_str.startswith('undo block ') or
|
||||
command_str.startswith('remove block ') or
|
||||
command_str.startswith('rm block ') or
|
||||
command_str.startswith('unblock ')):
|
||||
elif string_starts_with(command_str,
|
||||
('undo block ',
|
||||
'remove block ',
|
||||
'rm block ',
|
||||
'unblock ')):
|
||||
curr_index = 0
|
||||
if ' ' in command_str:
|
||||
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)
|
||||
refresh_timeline = True
|
||||
print('')
|
||||
elif (command_str.startswith('announce') or
|
||||
command_str.startswith('boost') or
|
||||
command_str.startswith('retweet')):
|
||||
elif string_starts_with(command_str,
|
||||
('announce', 'boost', 'retweet')):
|
||||
curr_index = 0
|
||||
if ' ' in command_str:
|
||||
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)
|
||||
refresh_timeline = True
|
||||
print('')
|
||||
elif (command_str.startswith('unannounce') or
|
||||
command_str.startswith('undo announce') or
|
||||
command_str.startswith('unboost') or
|
||||
command_str.startswith('undo boost') or
|
||||
command_str.startswith('undo retweet')):
|
||||
elif string_starts_with(command_str,
|
||||
('unannounce',
|
||||
'undo announce',
|
||||
'unboost',
|
||||
'undo boost',
|
||||
'undo retweet')):
|
||||
curr_index = 0
|
||||
if ' ' in command_str:
|
||||
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,
|
||||
screenreader, system_language, espeak)
|
||||
print('')
|
||||
elif (command_str.startswith('unfollow ') or
|
||||
command_str.startswith('stop following ')):
|
||||
elif string_starts_with(command_str,
|
||||
('unfollow ',
|
||||
'stop following ')):
|
||||
follow_handle = command_str.replace('unfollow ', '').strip()
|
||||
follow_handle = follow_handle.replace('stop following ', '')
|
||||
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,
|
||||
system_language, espeak)
|
||||
print('')
|
||||
elif (command_str.startswith('pgp') or
|
||||
command_str.startswith('gpg')):
|
||||
elif string_starts_with(command_str, ('pgp', 'gpg')):
|
||||
if not has_local_pg_pkey():
|
||||
print('No PGP public key was found')
|
||||
else:
|
||||
|
|
@ -2901,10 +2900,8 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
input()
|
||||
prev_timeline_first_id = ''
|
||||
refresh_timeline = True
|
||||
elif (command_str == 'delete' or
|
||||
command_str == 'rm' or
|
||||
command_str.startswith('delete ') or
|
||||
command_str.startswith('rm ')):
|
||||
elif (command_str in ('delete', 'rm') or
|
||||
string_starts_with(command_str, ('delete ', 'rm '))):
|
||||
curr_index = 0
|
||||
if ' ' in command_str:
|
||||
post_index = command_str.split(' ')[-1].strip()
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ from tests import test_update_actor
|
|||
from tests import run_all_tests
|
||||
from auth import store_basic_credentials
|
||||
from auth import create_password
|
||||
from utils import string_starts_with
|
||||
from utils import is_yggdrasil_url
|
||||
from utils import is_yggdrasil_address
|
||||
from utils import get_event_categories
|
||||
|
|
@ -3110,10 +3111,8 @@ def _command_options() -> None:
|
|||
original_actor = argb.followers
|
||||
if '/@' in argb.followers or \
|
||||
'/users/' in argb.followers or \
|
||||
argb.followers.startswith('http') or \
|
||||
argb.followers.startswith('ipfs') or \
|
||||
argb.followers.startswith('ipns') or \
|
||||
argb.followers.startswith('hyper'):
|
||||
string_starts_with(argb.followers,
|
||||
('http', 'ipfs', 'ipns', 'hyper')):
|
||||
# format: https://domain/@nick
|
||||
prefixes = get_protocol_prefixes()
|
||||
for prefix in prefixes:
|
||||
|
|
|
|||
13
follow.py
13
follow.py
|
|
@ -10,6 +10,7 @@ __module_group__ = "ActivityPub"
|
|||
import os
|
||||
from pprint import pprint
|
||||
from flags import has_group_type
|
||||
from utils import string_starts_with
|
||||
from utils import is_yggdrasil_address
|
||||
from utils import is_yggdrasil_url
|
||||
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 \
|
||||
not line.startswith('http'):
|
||||
ctr += 1
|
||||
elif ((line.startswith('http') or
|
||||
line.startswith('ipfs') or
|
||||
line.startswith('ipns') or
|
||||
line.startswith('hyper')) and
|
||||
elif (string_starts_with(line,
|
||||
('http', 'ipfs', 'ipns', 'hyper')) and
|
||||
has_users_path(line)):
|
||||
ctr += 1
|
||||
return ctr
|
||||
|
|
@ -569,10 +568,8 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str,
|
|||
# group actor
|
||||
url = http_prefix + '://' + dom + '/c/' + nick
|
||||
following['orderedItems'].append(url)
|
||||
elif ((line.startswith('http') or
|
||||
line.startswith('ipfs') or
|
||||
line.startswith('ipns') or
|
||||
line.startswith('hyper')) and
|
||||
elif (string_starts_with(line,
|
||||
('http', 'ipfs', 'ipns', 'hyper')) and
|
||||
has_users_path(line)):
|
||||
# https://domain/users/nickname
|
||||
page_ctr += 1
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ from media import process_meta_data
|
|||
from flags import is_image_file
|
||||
from timeFunctions import date_utcnow
|
||||
from timeFunctions import get_current_time_int
|
||||
from utils import string_starts_with
|
||||
from utils import is_yggdrasil_address
|
||||
from utils import get_person_icon
|
||||
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)
|
||||
if '/@' in handle or \
|
||||
detected_users_path in handle or \
|
||||
handle.startswith('http') or \
|
||||
handle.startswith('ipfs') or \
|
||||
handle.startswith('ipns') or \
|
||||
handle.startswith('hyper'):
|
||||
string_starts_with(handle, ('http', 'ipfs', 'ipns', 'hyper')):
|
||||
group_paths = get_group_paths()
|
||||
if detected_users_path in group_paths:
|
||||
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_epoch
|
||||
from timeFunctions import valid_post_date
|
||||
from utils import string_starts_with
|
||||
from utils import is_yggdrasil_address
|
||||
from utils import resembles_url
|
||||
from utils import get_person_icon
|
||||
|
|
@ -2913,10 +2914,8 @@ def create_report_post(base_dir: str,
|
|||
if moderator_actor not in moderators_list:
|
||||
moderators_list.append(moderator_actor)
|
||||
continue
|
||||
if line.startswith('http') or \
|
||||
line.startswith('ipfs') or \
|
||||
line.startswith('ipns') or \
|
||||
line.startswith('hyper'):
|
||||
if string_starts_with(line,
|
||||
('http', 'ipfs', 'ipns', 'hyper')):
|
||||
# must be a local address - no remote moderators
|
||||
if '://' + domain_full + '/' in line:
|
||||
if line not in moderators_list:
|
||||
|
|
@ -4663,9 +4662,8 @@ def is_image_media(session, base_dir: str, http_prefix: str,
|
|||
return False
|
||||
for attach in post_attachments:
|
||||
if attach.get('mediaType') and attach.get('url'):
|
||||
if attach['mediaType'].startswith('image/') or \
|
||||
attach['mediaType'].startswith('audio/') or \
|
||||
attach['mediaType'].startswith('video/'):
|
||||
if string_starts_with(attach['mediaType'],
|
||||
('image/', 'audio/', 'video/')):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import ssl
|
|||
import socket
|
||||
from urllib.parse import urlparse
|
||||
from utils import data_dir
|
||||
from utils import string_starts_with
|
||||
|
||||
|
||||
class Result:
|
||||
|
|
@ -105,9 +106,7 @@ def site_is_active(url: str, timeout: int,
|
|||
url = url.replace('<>', '')
|
||||
if '<' in url:
|
||||
url = url.split('<')[0]
|
||||
if not url.startswith('http') and \
|
||||
not url.startswith('ipfs') and \
|
||||
not url.startswith('ipns'):
|
||||
if not string_starts_with(url, ('http', 'ipfs', 'ipns')):
|
||||
return False
|
||||
if '.onion/' in url or '.i2p/' in url 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:
|
||||
"""Returns true if the given host is on the local network
|
||||
"""
|
||||
if host.startswith('localhost') or \
|
||||
host.startswith('192.') or \
|
||||
host.startswith('127.') or \
|
||||
host.startswith('10.'):
|
||||
if string_starts_with(host, ('localhost', '192.', '127.', '10.')):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
@ -847,9 +844,7 @@ def get_followers_of_person(base_dir: str,
|
|||
for account in dirs:
|
||||
filename = os.path.join(subdir, account) + '/' + follow_file
|
||||
if account == handle or \
|
||||
account.startswith('inbox@') or \
|
||||
account.startswith('Actor@') or \
|
||||
account.startswith('news@'):
|
||||
string_starts_with(account, ('inbox@', 'Actor@', 'news@')):
|
||||
continue
|
||||
if not os.path.isfile(filename):
|
||||
continue
|
||||
|
|
@ -2858,9 +2853,8 @@ def permitted_dir(path: str) -> bool:
|
|||
"""These are special paths which should not be accessible
|
||||
directly via GET or POST
|
||||
"""
|
||||
if path.startswith('/wfendpoints') or \
|
||||
path.startswith('/keys') or \
|
||||
path.startswith('/accounts'):
|
||||
if string_starts_with(path,
|
||||
('/wfendpoints', '/keys', '/accounts')):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -3911,8 +3905,8 @@ def get_media_url_from_torrent(post_json_object: {}) -> (str, str, str,
|
|||
if not tag_link.get('href'):
|
||||
continue
|
||||
if tag_link['mediaType'] == 'application/x-bittorrent' or \
|
||||
tag_link['mediaType'].startswith('magnet:') or \
|
||||
tag_link['mediaType'].startswith('bencoded:'):
|
||||
string_starts_with(tag_link['mediaType'],
|
||||
('magnet:', 'bencoded:')):
|
||||
if tag_link['mediaType'].startswith('magnet:'):
|
||||
media_magnet = remove_html(media_link['href'])
|
||||
elif tag_link['mediaType'].startswith('bencoded:'):
|
||||
|
|
@ -4078,7 +4072,7 @@ def check_bad_path(path: str):
|
|||
# allow /.well-known/...
|
||||
if '/.' in path_lower:
|
||||
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')
|
||||
|
||||
if path_lower.startswith('/wp-'):
|
||||
|
|
@ -4128,7 +4122,7 @@ def set_premium_account(base_dir: str, nickname: str, domain: str,
|
|||
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
|
||||
"""
|
||||
for start_str in possible_begin:
|
||||
|
|
|
|||
|
|
@ -276,8 +276,11 @@ def get_show_map_button(post_id: str, translate: {},
|
|||
map_content: str) -> str:
|
||||
"""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">' + \
|
||||
translate['Show Map'] + '</summary>' + \
|
||||
show_map_str + '</summary>' + \
|
||||
'<div id="' + post_id + '">' + map_content + \
|
||||
'</div></details>\n'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue