mirror of https://gitlab.com/bashrc2/epicyon
Snake case
parent
cb9165afa1
commit
3a2a24baa4
125
daemon.py
125
daemon.py
|
@ -1885,12 +1885,18 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
moderation_text = \
|
moderation_text = \
|
||||||
urllib.parse.unquote_plus(mod_text.strip())
|
urllib.parse.unquote_plus(mod_text.strip())
|
||||||
elif moderation_str.startswith('submitInfo'):
|
elif moderation_str.startswith('submitInfo'):
|
||||||
|
if '=' in moderation_str:
|
||||||
|
moderation_text = \
|
||||||
|
moderation_str.split('=')[1].strip()
|
||||||
|
mod_text = moderation_text.replace('+', ' ')
|
||||||
|
moderation_text = \
|
||||||
|
urllib.parse.unquote_plus(mod_text.strip())
|
||||||
search_handle = moderation_text
|
search_handle = moderation_text
|
||||||
if search_handle:
|
if search_handle:
|
||||||
if '/@' in search_handle:
|
if '/@' in search_handle:
|
||||||
search_nickname = \
|
search_nickname = \
|
||||||
get_nickname_from_actor(search_handle)
|
get_nickname_from_actor(search_handle)
|
||||||
search_domain, search_port = \
|
search_domain, _ = \
|
||||||
get_domain_from_actor(search_handle)
|
get_domain_from_actor(search_handle)
|
||||||
search_handle = \
|
search_handle = \
|
||||||
search_nickname + '@' + search_domain
|
search_nickname + '@' + search_domain
|
||||||
|
@ -1898,17 +1904,17 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if search_handle.startswith('http'):
|
if search_handle.startswith('http'):
|
||||||
search_nickname = \
|
search_nickname = \
|
||||||
get_nickname_from_actor(search_handle)
|
get_nickname_from_actor(search_handle)
|
||||||
search_domain, search_port = \
|
search_domain, _ = \
|
||||||
get_domain_from_actor(search_handle)
|
get_domain_from_actor(search_handle)
|
||||||
search_handle = \
|
search_handle = \
|
||||||
search_nickname + '@' + search_domain
|
search_nickname + '@' + search_domain
|
||||||
if '@' not in search_handle:
|
if '@' not in search_handle:
|
||||||
# is this a local nickname on this instance?
|
# is this a local nickname on this instance?
|
||||||
localHandle = \
|
local_handle = \
|
||||||
search_handle + '@' + self.server.domain
|
search_handle + '@' + self.server.domain
|
||||||
if os.path.isdir(self.server.base_dir +
|
if os.path.isdir(self.server.base_dir +
|
||||||
'/accounts/' + localHandle):
|
'/accounts/' + local_handle):
|
||||||
search_handle = localHandle
|
search_handle = local_handle
|
||||||
else:
|
else:
|
||||||
search_handle = None
|
search_handle = None
|
||||||
if search_handle:
|
if search_handle:
|
||||||
|
@ -3737,38 +3743,38 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
length = int(self.headers['Content-length'])
|
length = int(self.headers['Content-length'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
questionParams = self.rfile.read(length).decode('utf-8')
|
question_params = self.rfile.read(length).decode('utf-8')
|
||||||
except SocketError as ex:
|
except SocketError as ex:
|
||||||
if ex.errno == errno.ECONNRESET:
|
if ex.errno == errno.ECONNRESET:
|
||||||
print('WARN: POST questionParams connection was reset')
|
print('WARN: POST question_params connection was reset')
|
||||||
else:
|
else:
|
||||||
print('WARN: POST questionParams socket error')
|
print('WARN: POST question_params socket error')
|
||||||
self.send_response(400)
|
self.send_response(400)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.server.postreq_busy = False
|
self.server.postreq_busy = False
|
||||||
return
|
return
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
print('ERROR: POST questionParams rfile.read failed, ' + str(ex))
|
print('ERROR: POST question_params rfile.read failed, ' + str(ex))
|
||||||
self.send_response(400)
|
self.send_response(400)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.server.postreq_busy = False
|
self.server.postreq_busy = False
|
||||||
return
|
return
|
||||||
|
|
||||||
questionParams = questionParams.replace('+', ' ')
|
question_params = question_params.replace('+', ' ')
|
||||||
questionParams = questionParams.replace('%3F', '')
|
question_params = question_params.replace('%3F', '')
|
||||||
questionParams = \
|
question_params = \
|
||||||
urllib.parse.unquote_plus(questionParams.strip())
|
urllib.parse.unquote_plus(question_params.strip())
|
||||||
|
|
||||||
# post being voted on
|
# post being voted on
|
||||||
message_id = None
|
message_id = None
|
||||||
if 'messageId=' in questionParams:
|
if 'messageId=' in question_params:
|
||||||
message_id = questionParams.split('messageId=')[1]
|
message_id = question_params.split('messageId=')[1]
|
||||||
if '&' in message_id:
|
if '&' in message_id:
|
||||||
message_id = message_id.split('&')[0]
|
message_id = message_id.split('&')[0]
|
||||||
|
|
||||||
answer = None
|
answer = None
|
||||||
if 'answer=' in questionParams:
|
if 'answer=' in question_params:
|
||||||
answer = questionParams.split('answer=')[1]
|
answer = question_params.split('answer=')[1]
|
||||||
if '&' in answer:
|
if '&' in answer:
|
||||||
answer = answer.split('&')[0]
|
answer = answer.split('&')[0]
|
||||||
|
|
||||||
|
@ -3794,7 +3800,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
debug: bool) -> None:
|
debug: bool) -> None:
|
||||||
"""Receives an image via POST
|
"""Receives an image via POST
|
||||||
"""
|
"""
|
||||||
if not self.outboxAuthenticated:
|
if not self.outbox_authenticated:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: unauthenticated attempt to ' +
|
print('DEBUG: unauthenticated attempt to ' +
|
||||||
'post image to outbox')
|
'post image to outbox')
|
||||||
|
@ -3900,11 +3906,12 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
item_id = remove_share_confirm_params.split('itemID=')[1]
|
item_id = remove_share_confirm_params.split('itemID=')[1]
|
||||||
if '&' in item_id:
|
if '&' in item_id:
|
||||||
item_id = item_id.split('&')[0]
|
item_id = item_id.split('&')[0]
|
||||||
shareNickname = get_nickname_from_actor(share_actor)
|
share_nickname = get_nickname_from_actor(share_actor)
|
||||||
if shareNickname:
|
if share_nickname:
|
||||||
shareDomain, sharePort = get_domain_from_actor(share_actor)
|
share_domain, _ = \
|
||||||
|
get_domain_from_actor(share_actor)
|
||||||
remove_shared_item(base_dir,
|
remove_shared_item(base_dir,
|
||||||
shareNickname, shareDomain, item_id,
|
share_nickname, share_domain, item_id,
|
||||||
http_prefix, domain_full, 'shares')
|
http_prefix, domain_full, 'shares')
|
||||||
|
|
||||||
if calling_domain.endswith('.onion') and onion_domain:
|
if calling_domain.endswith('.onion') and onion_domain:
|
||||||
|
@ -3967,11 +3974,12 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
item_id = remove_share_confirm_params.split('itemID=')[1]
|
item_id = remove_share_confirm_params.split('itemID=')[1]
|
||||||
if '&' in item_id:
|
if '&' in item_id:
|
||||||
item_id = item_id.split('&')[0]
|
item_id = item_id.split('&')[0]
|
||||||
shareNickname = get_nickname_from_actor(share_actor)
|
share_nickname = get_nickname_from_actor(share_actor)
|
||||||
if shareNickname:
|
if share_nickname:
|
||||||
shareDomain, sharePort = get_domain_from_actor(share_actor)
|
share_domain, _ = \
|
||||||
|
get_domain_from_actor(share_actor)
|
||||||
remove_shared_item(base_dir,
|
remove_shared_item(base_dir,
|
||||||
shareNickname, shareDomain, item_id,
|
share_nickname, share_domain, item_id,
|
||||||
http_prefix, domain_full, 'wanted')
|
http_prefix, domain_full, 'wanted')
|
||||||
|
|
||||||
if calling_domain.endswith('.onion') and onion_domain:
|
if calling_domain.endswith('.onion') and onion_domain:
|
||||||
|
@ -4043,20 +4051,20 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if '&' in month_str:
|
if '&' in month_str:
|
||||||
month_str = month_str.split('&')[0]
|
month_str = month_str.split('&')[0]
|
||||||
if '/statuses/' in remove_message_id:
|
if '/statuses/' in remove_message_id:
|
||||||
removePostActor = remove_message_id.split('/statuses/')[0]
|
remove_post_actor = remove_message_id.split('/statuses/')[0]
|
||||||
if origin_path_str in removePostActor:
|
if origin_path_str in remove_post_actor:
|
||||||
toList = ['https://www.w3.org/ns/activitystreams#Public',
|
toList = ['https://www.w3.org/ns/activitystreams#Public',
|
||||||
removePostActor]
|
remove_post_actor]
|
||||||
delete_json = {
|
delete_json = {
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
'actor': removePostActor,
|
'actor': remove_post_actor,
|
||||||
'object': remove_message_id,
|
'object': remove_message_id,
|
||||||
'to': toList,
|
'to': toList,
|
||||||
'cc': [removePostActor + '/followers'],
|
'cc': [remove_post_actor + '/followers'],
|
||||||
'type': 'Delete'
|
'type': 'Delete'
|
||||||
}
|
}
|
||||||
self.post_to_nickname = \
|
self.post_to_nickname = \
|
||||||
get_nickname_from_actor(removePostActor)
|
get_nickname_from_actor(remove_post_actor)
|
||||||
if self.post_to_nickname:
|
if self.post_to_nickname:
|
||||||
if month_str and year_str:
|
if month_str and year_str:
|
||||||
if month_str.isdigit() and year_str.isdigit():
|
if month_str.isdigit() and year_str.isdigit():
|
||||||
|
@ -4146,7 +4154,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
links_filename = base_dir + '/accounts/links.txt'
|
links_filename = base_dir + '/accounts/links.txt'
|
||||||
about_filename = base_dir + '/accounts/about.md'
|
about_filename = base_dir + '/accounts/about.md'
|
||||||
TOS_filename = base_dir + '/accounts/tos.md'
|
tos_filename = base_dir + '/accounts/tos.md'
|
||||||
|
|
||||||
# extract all of the text fields into a dict
|
# extract all of the text fields into a dict
|
||||||
fields = \
|
fields = \
|
||||||
|
@ -4209,17 +4217,17 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if not dangerous_markup(tos_str,
|
if not dangerous_markup(tos_str,
|
||||||
allow_local_network_access):
|
allow_local_network_access):
|
||||||
try:
|
try:
|
||||||
with open(TOS_filename, 'w+') as tosfile:
|
with open(tos_filename, 'w+') as tosfile:
|
||||||
tosfile.write(tos_str)
|
tosfile.write(tos_str)
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: unable to write TOS ' + TOS_filename)
|
print('EX: unable to write TOS ' + tos_filename)
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(TOS_filename):
|
if os.path.isfile(tos_filename):
|
||||||
try:
|
try:
|
||||||
os.remove(TOS_filename)
|
os.remove(tos_filename)
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: _links_update unable to delete ' +
|
print('EX: _links_update unable to delete ' +
|
||||||
TOS_filename)
|
tos_filename)
|
||||||
|
|
||||||
# redirect back to the default timeline
|
# redirect back to the default timeline
|
||||||
self._redirect_headers(actor_str + '/' + default_timeline,
|
self._redirect_headers(actor_str + '/' + default_timeline,
|
||||||
|
@ -4592,10 +4600,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
# get the nickname
|
# get the nickname
|
||||||
nickname = get_nickname_from_actor(actor_str)
|
nickname = get_nickname_from_actor(actor_str)
|
||||||
editorRole = None
|
editor_role = None
|
||||||
if nickname:
|
if nickname:
|
||||||
editorRole = is_editor(base_dir, nickname)
|
editor_role = is_editor(base_dir, nickname)
|
||||||
if not nickname or not editorRole:
|
if not nickname or not editor_role:
|
||||||
if not nickname:
|
if not nickname:
|
||||||
print('WARN: nickname not found in ' + actor_str)
|
print('WARN: nickname not found in ' + actor_str)
|
||||||
else:
|
else:
|
||||||
|
@ -5204,16 +5212,16 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.twitter_replacement_domain = None
|
self.server.twitter_replacement_domain = None
|
||||||
|
|
||||||
# change custom post submit button text
|
# change custom post submit button text
|
||||||
currCustomSubmitText = \
|
curr_custom_submit_text = \
|
||||||
get_config_param(base_dir, 'customSubmitText')
|
get_config_param(base_dir, 'customSubmitText')
|
||||||
if fields.get('customSubmitText'):
|
if fields.get('customSubmitText'):
|
||||||
if fields['customSubmitText'] != \
|
if fields['customSubmitText'] != \
|
||||||
currCustomSubmitText:
|
curr_custom_submit_text:
|
||||||
customText = fields['customSubmitText']
|
customText = fields['customSubmitText']
|
||||||
set_config_param(base_dir, 'customSubmitText',
|
set_config_param(base_dir, 'customSubmitText',
|
||||||
customText)
|
customText)
|
||||||
else:
|
else:
|
||||||
if currCustomSubmitText:
|
if curr_custom_submit_text:
|
||||||
set_config_param(base_dir, 'customSubmitText',
|
set_config_param(base_dir, 'customSubmitText',
|
||||||
'')
|
'')
|
||||||
|
|
||||||
|
@ -5276,10 +5284,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if fields.get('instanceDescriptionShort'):
|
if fields.get('instanceDescriptionShort'):
|
||||||
if fields['instanceDescriptionShort'] != \
|
if fields['instanceDescriptionShort'] != \
|
||||||
curr_instance_description_short:
|
curr_instance_description_short:
|
||||||
iDesc = fields['instanceDescriptionShort']
|
idesc = fields['instanceDescriptionShort']
|
||||||
set_config_param(base_dir,
|
set_config_param(base_dir,
|
||||||
'instanceDescriptionShort',
|
'instanceDescriptionShort',
|
||||||
iDesc)
|
idesc)
|
||||||
else:
|
else:
|
||||||
if curr_instance_description_short:
|
if curr_instance_description_short:
|
||||||
set_config_param(base_dir,
|
set_config_param(base_dir,
|
||||||
|
@ -5687,10 +5695,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'w+') as modfile:
|
'w+') as modfile:
|
||||||
for mod_nick in mods:
|
for mod_nick in mods:
|
||||||
mod_nick = mod_nick.strip()
|
mod_nick = mod_nick.strip()
|
||||||
modDir = base_dir + \
|
mod_dir = base_dir + \
|
||||||
'/accounts/' + mod_nick + \
|
'/accounts/' + mod_nick + \
|
||||||
'@' + domain
|
'@' + domain
|
||||||
if os.path.isdir(modDir):
|
if os.path.isdir(mod_dir):
|
||||||
modfile.write(mod_nick +
|
modfile.write(mod_nick +
|
||||||
'\n')
|
'\n')
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -5700,10 +5708,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
for mod_nick in mods:
|
for mod_nick in mods:
|
||||||
mod_nick = mod_nick.strip()
|
mod_nick = mod_nick.strip()
|
||||||
modDir = base_dir + \
|
mod_dir = base_dir + \
|
||||||
'/accounts/' + mod_nick + \
|
'/accounts/' + mod_nick + \
|
||||||
'@' + domain
|
'@' + domain
|
||||||
if os.path.isdir(modDir):
|
if os.path.isdir(mod_dir):
|
||||||
set_role(base_dir,
|
set_role(base_dir,
|
||||||
mod_nick, domain,
|
mod_nick, domain,
|
||||||
'moderator')
|
'moderator')
|
||||||
|
@ -5715,11 +5723,11 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'w+') as modfile:
|
'w+') as modfile:
|
||||||
for mod_nick in mods:
|
for mod_nick in mods:
|
||||||
mod_nick = mod_nick.strip()
|
mod_nick = mod_nick.strip()
|
||||||
modDir = \
|
mod_dir = \
|
||||||
base_dir + \
|
base_dir + \
|
||||||
'/accounts/' + mod_nick + \
|
'/accounts/' + mod_nick + \
|
||||||
'@' + domain
|
'@' + domain
|
||||||
if os.path.isdir(modDir):
|
if os.path.isdir(mod_dir):
|
||||||
modfile.write(mod_nick +
|
modfile.write(mod_nick +
|
||||||
'\n')
|
'\n')
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -5729,12 +5737,12 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
for mod_nick in mods:
|
for mod_nick in mods:
|
||||||
mod_nick = mod_nick.strip()
|
mod_nick = mod_nick.strip()
|
||||||
modDir = \
|
mod_dir = \
|
||||||
base_dir + \
|
base_dir + \
|
||||||
'/accounts/' + \
|
'/accounts/' + \
|
||||||
mod_nick + '@' + \
|
mod_nick + '@' + \
|
||||||
domain
|
domain
|
||||||
if os.path.isdir(modDir):
|
if os.path.isdir(mod_dir):
|
||||||
set_role(base_dir,
|
set_role(base_dir,
|
||||||
mod_nick, domain,
|
mod_nick, domain,
|
||||||
'moderator')
|
'moderator')
|
||||||
|
@ -6554,7 +6562,6 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
actor_json['id'].replace('/', '#') + '.json'
|
actor_json['id'].replace('/', '#') + '.json'
|
||||||
save_json(actor_json, actor_cache_filename)
|
save_json(actor_json, actor_cache_filename)
|
||||||
# send profile update to followers
|
# send profile update to followers
|
||||||
pub_number, pub_date = get_status_number()
|
|
||||||
update_actor_json = get_actor_update_json(actor_json)
|
update_actor_json = get_actor_update_json(actor_json)
|
||||||
print('Sending actor update: ' +
|
print('Sending actor update: ' +
|
||||||
str(update_actor_json))
|
str(update_actor_json))
|
||||||
|
@ -17702,7 +17709,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return
|
return
|
||||||
|
|
||||||
# if this is a POST to the outbox then check authentication
|
# if this is a POST to the outbox then check authentication
|
||||||
self.outboxAuthenticated = False
|
self.outbox_authenticated = False
|
||||||
self.post_to_nickname = None
|
self.post_to_nickname = None
|
||||||
|
|
||||||
fitness_performance(postreq_start_time, self.server.fitness,
|
fitness_performance(postreq_start_time, self.server.fitness,
|
||||||
|
@ -18216,10 +18223,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.path.endswith('/shares'):
|
self.path.endswith('/shares'):
|
||||||
if users_in_path:
|
if users_in_path:
|
||||||
if authorized:
|
if authorized:
|
||||||
self.outboxAuthenticated = True
|
self.outbox_authenticated = True
|
||||||
path_users_section = self.path.split('/users/')[1]
|
path_users_section = self.path.split('/users/')[1]
|
||||||
self.post_to_nickname = path_users_section.split('/')[0]
|
self.post_to_nickname = path_users_section.split('/')[0]
|
||||||
if not self.outboxAuthenticated:
|
if not self.outbox_authenticated:
|
||||||
self.send_response(405)
|
self.send_response(405)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.server.postreq_busy = False
|
self.server.postreq_busy = False
|
||||||
|
@ -18378,7 +18385,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.debug)
|
self.server.debug)
|
||||||
|
|
||||||
# https://www.w3.org/TR/activitypub/#object-without-create
|
# https://www.w3.org/TR/activitypub/#object-without-create
|
||||||
if self.outboxAuthenticated:
|
if self.outbox_authenticated:
|
||||||
if self._post_to_outbox(message_json,
|
if self._post_to_outbox(message_json,
|
||||||
self.server.project_version, None):
|
self.server.project_version, None):
|
||||||
if message_json.get('id'):
|
if message_json.get('id'):
|
||||||
|
|
Loading…
Reference in New Issue