merge-requests/30/head
Bob Mottram 2022-06-15 15:46:41 +01:00
parent 7e690f35a4
commit 21df473662
2 changed files with 69 additions and 141 deletions

199
daemon.py
View File

@ -500,7 +500,6 @@ class PubServer(BaseHTTPRequestHandler):
def handle_error(self, request, client_address):
print('ERROR: http server error: ' + str(request) + ', ' +
str(client_address))
pass
def _send_reply_to_question(self, nickname: str, message_id: str,
answer: str,
@ -2439,10 +2438,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
return
def _key_shortcuts(self, path: str,
calling_domain: str, cookie: str,
def _key_shortcuts(self, calling_domain: str, cookie: str,
base_dir: str, http_prefix: str, nickname: str,
domain: str, domain_full: str, port: int,
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str,
debug: bool, access_keys: {},
default_timeline: str) -> None:
@ -2529,12 +2527,10 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
return
def _theme_designer_edit(self, path: str,
calling_domain: str, cookie: str,
def _theme_designer_edit(self, calling_domain: str, cookie: str,
base_dir: str, http_prefix: str, nickname: str,
domain: str, domain_full: str, port: int,
onion_domain: str, i2p_domain: str,
debug: bool, access_keys: {},
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str, debug: bool,
default_timeline: str, theme_name: str,
allow_local_network_access: bool,
system_language: str,
@ -3347,8 +3343,7 @@ class PubServer(BaseHTTPRequestHandler):
return
def _unfollow_confirm(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
path: str, base_dir: str, http_prefix: str,
domain: str, domain_full: str, port: int,
onion_domain: str, i2p_domain: str,
debug: bool,
@ -3430,8 +3425,7 @@ class PubServer(BaseHTTPRequestHandler):
}
path_users_section = path.split('/users/')[1]
self.post_to_nickname = path_users_section.split('/')[0]
group_account = has_group_type(self.server.base_dir,
following_actor,
group_account = has_group_type(base_dir, following_actor,
self.server.person_cache)
unfollow_account(self.server.base_dir, self.post_to_nickname,
self.server.domain,
@ -3448,8 +3442,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
def _follow_confirm(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
path: str, base_dir: str, http_prefix: str,
domain: str, domain_full: str, port: int,
onion_domain: str, i2p_domain: str,
debug: bool,
@ -3621,8 +3614,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
def _block_confirm(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
path: str, base_dir: str, http_prefix: str,
domain: str, domain_full: str, port: int,
onion_domain: str, i2p_domain: str,
debug: bool,
@ -3711,8 +3703,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
def _unblock_confirm(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
path: str, base_dir: str, http_prefix: str,
domain: str, domain_full: str, port: int,
onion_domain: str, i2p_domain: str,
debug: bool) -> None:
@ -3805,8 +3796,7 @@ class PubServer(BaseHTTPRequestHandler):
domain: str, domain_full: str,
port: int, search_for_emoji: bool,
onion_domain: str, i2p_domain: str,
getreq_start_time, getreq_timings: {},
debug: bool,
getreq_start_time, debug: bool,
curr_session, proxy_type: str) -> None:
"""Receive a search query
"""
@ -4338,11 +4328,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
def _receive_vote(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str,
debug: bool,
path: str, http_prefix: str, domain_full: str,
onion_domain: str, i2p_domain: str, debug: bool,
curr_session, proxy_type: str) -> None:
"""Receive a vote via POST
"""
@ -4425,13 +4412,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
return
def _receive_image(self, length: int,
calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str,
debug: bool) -> None:
def _receive_image(self, length: int, path: str, base_dir: str,
domain: str, debug: bool) -> None:
"""Receives an image via POST
"""
if not self.outbox_authenticated:
@ -4491,8 +4473,7 @@ class PubServer(BaseHTTPRequestHandler):
def _remove_share(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str,
domain_full: str, onion_domain: str, i2p_domain: str,
debug: bool) -> None:
"""Removes a shared item
"""
@ -4564,8 +4545,7 @@ class PubServer(BaseHTTPRequestHandler):
def _remove_wanted(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str,
domain_full: str, onion_domain: str, i2p_domain: str,
debug: bool) -> None:
"""Removes a wanted item
"""
@ -4635,8 +4615,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
def _receive_remove_post(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
path: str, base_dir: str, http_prefix: str,
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str,
debug: bool,
@ -4743,10 +4722,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
def _links_update(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str, debug: bool,
path: str, base_dir: str, debug: bool,
default_timeline: str,
allow_local_network_access: bool) -> None:
"""Updates the left links column of the timeline
@ -4890,12 +4866,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
def _set_hashtag_category(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str, debug: bool,
default_timeline: str,
allow_local_network_access: bool) -> None:
path: str, base_dir: str,
domain: str, debug: bool) -> None:
"""On the screen after selecting a hashtag from the swarm, this sets
the category for that tag
"""
@ -4993,10 +4965,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
def _newswire_update(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str, debug: bool,
path: str, base_dir: str,
domain: str, debug: bool,
default_timeline: str) -> None:
"""Updates the right newswire column of the timeline
"""
@ -5153,11 +5123,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
def _citations_update(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str, debug: bool,
default_timeline: str,
path: str, base_dir: str,
domain: str, debug: bool,
newswire: {}) -> None:
"""Updates the citations for a blog post after hitting
update button on the citations screen
@ -5247,11 +5214,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
def _news_post_edit(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str, debug: bool,
default_timeline: str) -> None:
path: str, base_dir: str,
domain: str, debug: bool) -> None:
"""edits a news post after receiving POST
"""
users_path = path.replace('/newseditdata', '')
@ -5384,8 +5348,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.postreq_busy = False
def _profile_edit(self, calling_domain: str, cookie: str,
authorized: bool, path: str,
base_dir: str, http_prefix: str,
path: str, base_dir: str, http_prefix: str,
domain: str, domain_full: str,
onion_domain: str, i2p_domain: str,
debug: bool, allow_local_network_access: bool,
@ -5884,9 +5847,9 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('customSubmitText'):
if fields['customSubmitText'] != \
curr_custom_submit_text:
customText = fields['customSubmitText']
custom_text = fields['customSubmitText']
set_config_param(base_dir, 'customSubmitText',
customText)
custom_text)
else:
if curr_custom_submit_text:
set_config_param(base_dir, 'customSubmitText',
@ -7305,7 +7268,7 @@ class PubServer(BaseHTTPRequestHandler):
save_json(actor_json, actor_filename)
webfinger_update(base_dir,
nickname, domain,
onion_domain,
onion_domain, i2p_domain,
self.server.cached_webfingers)
# also copy to the actors cache and
# person_cache in memory
@ -7597,8 +7560,7 @@ class PubServer(BaseHTTPRequestHandler):
None, calling_domain, False)
self._write(msg)
def _get_exported_theme(self, calling_domain: str, path: str,
base_dir: str, domain_full: str,
def _get_exported_theme(self, path: str, base_dir: str, domain_full: str,
debug: bool) -> None:
"""Returns an exported theme zip file
"""
@ -7684,8 +7646,7 @@ class PubServer(BaseHTTPRequestHandler):
print('font not found: ' + path + ' ' + calling_domain)
self._404()
def _get_rss2feed(self, authorized: bool,
calling_domain: str, path: str,
def _get_rss2feed(self, calling_domain: str, path: str,
base_dir: str, http_prefix: str,
domain: str, port: int, proxy_type: str,
getreq_start_time,
@ -7734,8 +7695,7 @@ class PubServer(BaseHTTPRequestHandler):
path + ' ' + calling_domain)
self._404()
def _get_rss2site(self, authorized: bool,
calling_domain: str, path: str,
def _get_rss2site(self, calling_domain: str, path: str,
base_dir: str, http_prefix: str,
domain_full: str, port: int, proxy_type: str,
translate: {},
@ -7792,8 +7752,7 @@ class PubServer(BaseHTTPRequestHandler):
path + ' ' + calling_domain)
self._404()
def _get_newswire_feed(self, authorized: bool,
calling_domain: str, path: str,
def _get_newswire_feed(self, calling_domain: str, path: str,
base_dir: str, http_prefix: str,
domain: str, port: int, proxy_type: str,
getreq_start_time,
@ -15595,7 +15554,7 @@ class PubServer(BaseHTTPRequestHandler):
return
if authorized and '/exports/' in self.path:
self._get_exported_theme(calling_domain, self.path,
self._get_exported_theme(self.path,
self.server.base_dir,
self.server.domain_full,
self.server.debug)
@ -15641,8 +15600,7 @@ class PubServer(BaseHTTPRequestHandler):
return
if self.path == '/newswire.xml':
self._get_newswire_feed(authorized,
calling_domain, self.path,
self._get_newswire_feed(calling_domain, self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
@ -15657,8 +15615,7 @@ class PubServer(BaseHTTPRequestHandler):
if self.path.startswith('/blog/') and \
self.path.endswith('/rss.xml'):
if not self.path == '/blog/rss.xml':
self._get_rss2feed(authorized,
calling_domain, self.path,
self._get_rss2feed(calling_domain, self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
@ -15668,8 +15625,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.debug,
curr_session)
else:
self._get_rss2site(authorized,
calling_domain, self.path,
self._get_rss2site(calling_domain, self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain_full,
@ -19966,23 +19922,17 @@ class PubServer(BaseHTTPRequestHandler):
if authorized and self.path.endswith('/sethashtagcategory'):
self._set_hashtag_category(calling_domain, cookie,
authorized, self.path,
self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
self.server.domain_full,
self.server.onion_domain,
self.server.i2p_domain,
self.server.debug,
self.server.default_timeline,
self.server.allow_local_network_access)
self.server.debug)
self.server.postreq_busy = False
return
# update of profile/avatar from web interface,
# after selecting Edit button then Submit
if authorized and self.path.endswith('/profiledata'):
self._profile_edit(calling_domain, cookie, authorized, self.path,
self._profile_edit(calling_domain, cookie, self.path,
self.server.base_dir, self.server.http_prefix,
self.server.domain,
self.server.domain_full,
@ -19997,12 +19947,8 @@ class PubServer(BaseHTTPRequestHandler):
return
if authorized and self.path.endswith('/linksdata'):
self._links_update(calling_domain, cookie, authorized, self.path,
self.server.base_dir, self.server.http_prefix,
self.server.domain,
self.server.domain_full,
self.server.onion_domain,
self.server.i2p_domain, self.server.debug,
self._links_update(calling_domain, cookie, self.path,
self.server.base_dir, self.server.debug,
self.server.default_timeline,
self.server.allow_local_network_access)
self.server.postreq_busy = False
@ -20010,39 +19956,28 @@ class PubServer(BaseHTTPRequestHandler):
if authorized and self.path.endswith('/newswiredata'):
self._newswire_update(calling_domain, cookie,
authorized, self.path,
self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
self.server.domain_full,
self.server.onion_domain,
self.server.i2p_domain, self.server.debug,
self.server.domain, self.server.debug,
self.server.default_timeline)
self.server.postreq_busy = False
return
if authorized and self.path.endswith('/citationsdata'):
self._citations_update(calling_domain, cookie,
authorized, self.path,
self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
self.server.domain_full,
self.server.onion_domain,
self.server.i2p_domain, self.server.debug,
self.server.default_timeline,
self.server.debug,
self.server.newswire)
self.server.postreq_busy = False
return
if authorized and self.path.endswith('/newseditdata'):
self._news_post_edit(calling_domain, cookie, authorized, self.path,
self.server.base_dir, self.server.http_prefix,
self._news_post_edit(calling_domain, cookie, self.path,
self.server.base_dir,
self.server.domain,
self.server.domain_full,
self.server.onion_domain,
self.server.i2p_domain, self.server.debug,
self.server.default_timeline)
self.server.debug)
self.server.postreq_busy = False
return
@ -20123,10 +20058,8 @@ class PubServer(BaseHTTPRequestHandler):
if self.path.endswith('/question') or \
'/question?page=' in self.path:
self._receive_vote(calling_domain, cookie,
authorized, self.path,
self.server.base_dir,
self.path,
self.server.http_prefix,
self.server.domain,
self.server.domain_full,
self.server.onion_domain,
self.server.i2p_domain,
@ -20142,7 +20075,6 @@ class PubServer(BaseHTTPRequestHandler):
authorized, self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
self.server.domain_full,
self.server.onion_domain,
self.server.i2p_domain,
@ -20156,7 +20088,6 @@ class PubServer(BaseHTTPRequestHandler):
authorized, self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
self.server.domain_full,
self.server.onion_domain,
self.server.i2p_domain,
@ -20178,7 +20109,7 @@ class PubServer(BaseHTTPRequestHandler):
return
if self.path.endswith('/rmpost'):
self._receive_remove_post(calling_domain, cookie,
authorized, self.path,
self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
@ -20197,7 +20128,7 @@ class PubServer(BaseHTTPRequestHandler):
# decision to follow in the web interface is confirmed
if self.path.endswith('/followconfirm'):
self._follow_confirm(calling_domain, cookie,
authorized, self.path,
self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
@ -20218,7 +20149,7 @@ class PubServer(BaseHTTPRequestHandler):
# decision to unfollow in the web interface is confirmed
if self.path.endswith('/unfollowconfirm'):
self._unfollow_confirm(calling_domain, cookie,
authorized, self.path,
self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
@ -20238,7 +20169,7 @@ class PubServer(BaseHTTPRequestHandler):
# decision to unblock in the web interface is confirmed
if self.path.endswith('/unblockconfirm'):
self._unblock_confirm(calling_domain, cookie,
authorized, self.path,
self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
@ -20257,7 +20188,7 @@ class PubServer(BaseHTTPRequestHandler):
# decision to block in the web interface is confirmed
if self.path.endswith('/blockconfirm'):
self._block_confirm(calling_domain, cookie,
authorized, self.path,
self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
@ -20305,14 +20236,12 @@ class PubServer(BaseHTTPRequestHandler):
self.server.key_shortcuts[nickname] = access_keys.copy()
access_keys = self.server.key_shortcuts[nickname]
self._key_shortcuts(self.path,
calling_domain, cookie,
self._key_shortcuts(calling_domain, cookie,
self.server.base_dir,
self.server.http_prefix,
nickname,
self.server.domain,
self.server.domain_full,
self.server.port,
self.server.onion_domain,
self.server.i2p_domain,
self.server.debug,
@ -20335,18 +20264,15 @@ class PubServer(BaseHTTPRequestHandler):
allow_local_network_access = \
self.server.allow_local_network_access
self._theme_designer_edit(self.path,
calling_domain, cookie,
self._theme_designer_edit(calling_domain, cookie,
self.server.base_dir,
self.server.http_prefix,
nickname,
self.server.domain,
self.server.domain_full,
self.server.port,
self.server.onion_domain,
self.server.i2p_domain,
self.server.debug,
access_keys,
self.server.default_timeline,
self.server.theme_name,
allow_local_network_access,
@ -20520,14 +20446,9 @@ class PubServer(BaseHTTPRequestHandler):
# receive images to the outbox
if self.headers['Content-type'].startswith('image/') and \
users_in_path:
self._receive_image(length, calling_domain, cookie,
authorized, self.path,
self._receive_image(length, self.path,
self.server.base_dir,
self.server.http_prefix,
self.server.domain,
self.server.domain_full,
self.server.onion_domain,
self.server.i2p_domain,
self.server.debug)
self.server.postreq_busy = False
return

View File

@ -490,7 +490,7 @@ def _webfinger_updateFromProfile(wf_json: {}, actor_json: {}) -> bool:
def webfinger_update(base_dir: str, nickname: str, domain: str,
onion_domain: str,
onion_domain: str, i2p_domain: str,
cached_webfingers: {}) -> None:
"""Regenerates stored webfinger
"""
@ -505,8 +505,15 @@ def webfinger_update(base_dir: str, nickname: str, domain: str,
if onion_domain in handle:
handle = handle.replace(onion_domain, domain)
onionify = True
elif i2p_domain:
if i2p_domain in handle:
handle = handle.replace(i2p_domain, domain)
i2pify = True
if not onionify:
wf_json = load_json(filename)
if not i2pify:
wf_json = load_json(filename)
else:
wf_json = load_json_onionify(filename, domain, i2p_domain)
else:
wf_json = load_json_onionify(filename, domain, onion_domain)
if not wf_json: