XMerge branch 'main' of gitlab.com:bashrc2/epicyon

merge-requests/30/head
Bob Mottram 2022-05-11 23:33:03 +01:00
commit 8fd4ae2610
15 changed files with 603 additions and 239 deletions

View File

@ -8,38 +8,49 @@ __status__ = "Production"
__module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def get_briar_address(actor_json: {}) -> str:
"""Returns briar address for the given actor
"""
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('briar'):
if not name_value.lower().startswith('briar'):
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, prop_value = \
get_attachment_property_value(property_value)
if not prop_value:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = property_value['value'].strip()
if len(property_value['value']) < 50:
property_value[prop_value_name] = prop_value.strip()
if len(property_value[prop_value_name]) < 50:
continue
if not property_value['value'].startswith('briar://'):
if not property_value[prop_value_name].startswith('briar://'):
continue
if property_value['value'].lower() != property_value['value']:
if property_value[prop_value_name].lower() != \
property_value[prop_value_name]:
continue
if '"' in property_value['value']:
if '"' in property_value[prop_value_name]:
continue
if ' ' in property_value['value']:
if ' ' in property_value[prop_value_name]:
continue
if ',' in property_value['value']:
if ',' in property_value[prop_value_name]:
continue
if '.' in property_value['value']:
if '.' in property_value[prop_value_name]:
continue
return property_value['value']
return property_value[prop_value_name]
return ''
@ -71,11 +82,16 @@ def set_briar_address(actor_json: {}, briar_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('briar'):
if not name_value.lower().startswith('briar'):
continue
property_found = property_value
break
@ -85,15 +101,24 @@ def set_briar_address(actor_json: {}, briar_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('briar'):
if not name_value.lower().startswith('briar'):
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = briar_address
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = briar_address
return
new_briar_address = {

View File

@ -8,6 +8,7 @@ __status__ = "Production"
__module_group__ = "Profile Metadata"
import re
from utils import get_attachment_property_value
def get_cwtch_address(actor_json: {}) -> str:
@ -16,28 +17,36 @@ def get_cwtch_address(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('cwtch'):
if not name_value.lower().startswith('cwtch'):
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, prop_value = \
get_attachment_property_value(property_value)
if not prop_value:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = property_value['value'].strip()
if len(property_value['value']) < 2:
property_value[prop_value_name] = \
property_value[prop_value_name].strip()
if len(property_value[prop_value_name]) < 2:
continue
if '"' in property_value['value']:
if '"' in property_value[prop_value_name]:
continue
if ' ' in property_value['value']:
if ' ' in property_value[prop_value_name]:
continue
if ',' in property_value['value']:
if ',' in property_value[prop_value_name]:
continue
if '.' in property_value['value']:
if '.' in property_value[prop_value_name]:
continue
return property_value['value']
return property_value[prop_value_name]
return ''
@ -59,11 +68,16 @@ def set_cwtch_address(actor_json: {}, cwtch_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('cwtch'):
if not name_value.lower().startswith('cwtch'):
continue
property_found = property_value
break
@ -73,15 +87,24 @@ def set_cwtch_address(actor_json: {}, cwtch_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('cwtch'):
if not name_value.lower().startswith('cwtch'):
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = cwtch_address
prop_value_name, prop_value = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = cwtch_address
return
new_cwtch_address = {

View File

@ -8,6 +8,9 @@ __status__ = "Production"
__module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def _get_donation_types() -> []:
return ('patreon', 'paypal', 'gofundme', 'liberapay',
'kickstarter', 'indiegogo', 'crowdsupply',
@ -25,19 +28,26 @@ def get_donation_url(actor_json: {}) -> str:
return ''
donation_type = _get_donation_types()
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if property_value['name'].lower() not in donation_type:
if name_value.lower() not in donation_type:
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, prop_value = \
get_attachment_property_value(property_value)
if not prop_value:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
if '<a href="' not in property_value['value']:
if '<a href="' not in property_value[prop_value_name]:
continue
donate_url = property_value['value'].split('<a href="')[1]
donate_url = property_value[prop_value_name].split('<a href="')[1]
if '"' in donate_url:
return donate_url.split('"')[0]
return ''
@ -51,17 +61,24 @@ def get_website(actor_json: {}, translate: {}) -> str:
match_strings = _get_website_strings()
match_strings.append(translate['Website'].lower())
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if property_value['name'].lower() not in match_strings:
if name_value.lower() not in match_strings:
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
return property_value['value']
return property_value[prop_value_name]
return ''
@ -92,11 +109,16 @@ def set_donation_url(actor_json: {}, donate_url: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower() != donate_name:
if not name_value.lower() != donate_name:
continue
property_found = property_value
break
@ -111,15 +133,24 @@ def set_donation_url(actor_json: {}, donate_url: str) -> None:
donate_url + '</a>'
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if property_value['name'].lower() != donate_name:
if name_value.lower() != donate_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = donate_value
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = donate_value
return
new_donate = {

View File

@ -8,23 +8,33 @@ __status__ = "Production"
__module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def get_enigma_pub_key(actor_json: {}) -> str:
"""Returns Enigma public key for the given actor
"""
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('enigma'):
if not name_value.lower().startswith('enigma'):
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
return property_value['value']
return property_value[prop_value_name]
return ''
@ -41,11 +51,16 @@ def set_enigma_pub_key(actor_json: {}, enigma_pub_key: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('enigma'):
if not name_value.lower().startswith('enigma'):
continue
property_found = property_value
break
@ -55,15 +70,24 @@ def set_enigma_pub_key(actor_json: {}, enigma_pub_key: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('enigma'):
if not name_value.lower().startswith('enigma'):
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = enigma_pub_key
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = enigma_pub_key
return
new_enigma_pub_key = {

View File

@ -73,11 +73,16 @@ def set_actor_languages(base_dir: str, actor_json: {},
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('languages'):
if not name_value.lower().startswith('languages'):
continue
property_found = property_value
break

View File

@ -8,31 +8,41 @@ __status__ = "Production"
__module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def get_matrix_address(actor_json: {}) -> str:
"""Returns matrix address for the given actor
"""
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('matrix'):
if not name_value.lower().startswith('matrix'):
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
if '@' not in property_value['value']:
if '@' not in property_value[prop_value_name]:
continue
if not property_value['value'].startswith('@'):
if not property_value[prop_value_name].startswith('@'):
continue
if ':' not in property_value['value']:
if ':' not in property_value[prop_value_name]:
continue
if '"' in property_value['value']:
if '"' in property_value[prop_value_name]:
continue
return property_value['value']
return property_value[prop_value_name]
return ''
@ -45,11 +55,16 @@ def set_matrix_address(actor_json: {}, matrix_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('matrix'):
if not name_value.lower().startswith('matrix'):
continue
property_found = property_value
break
@ -70,15 +85,24 @@ def set_matrix_address(actor_json: {}, matrix_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('matrix'):
if not name_value.lower().startswith('matrix'):
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = matrix_address
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = matrix_address
return
new_matrix_address = {

View File

@ -15,6 +15,7 @@ from posts import outbox_message_create_wrap
from posts import save_post_to_box
from posts import send_to_followers_thread
from posts import send_to_named_addresses_thread
from utils import get_attachment_property_value
from utils import get_account_timezone
from utils import has_object_string_type
from utils import get_base_content_from_post
@ -130,38 +131,51 @@ def _person_receive_update_outbox(recent_posts_cache: {},
# update fields within actor
if 'attachment' in updated_actor_json:
for new_property_value in updated_actor_json['attachment']:
if not new_property_value.get('name'):
name_value = None
if new_property_value.get('name'):
name_value = new_property_value['name']
elif new_property_value.get('schema:name'):
name_value = new_property_value['schema:name']
if not name_value:
continue
if new_property_value['name'] not in updatable_attachments:
if name_value not in updatable_attachments:
continue
if not new_property_value.get('type'):
continue
if not new_property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(new_property_value)
if not prop_value_name:
continue
if new_property_value['type'] != 'PropertyValue':
if not new_property_value['type'].endswith('PropertyValue'):
continue
if 'attachment' not in actor_json:
continue
found = False
for attach_idx, _ in enumerate(actor_json['attachment']):
if actor_json['attachment'][attach_idx]['type'] != \
'PropertyValue':
attach_type = actor_json['attachment'][attach_idx]['type']
if not attach_type.endswith('PropertyValue'):
continue
if actor_json['attachment'][attach_idx]['name'] != \
new_property_value['name']:
attach_name = ''
if actor_json['attachment'][attach_idx].get('name'):
attach_name = \
actor_json['attachment'][attach_idx]['name']
elif actor_json['attachment'][attach_idx].get('schema:name'):
attach_name = \
actor_json['attachment'][attach_idx]['schema:name']
if attach_name != name_value:
continue
if actor_json['attachment'][attach_idx]['value'] != \
new_property_value['value']:
actor_json['attachment'][attach_idx]['value'] = \
new_property_value['value']
if actor_json['attachment'][attach_idx][prop_value_name] != \
new_property_value[prop_value_name]:
actor_json['attachment'][attach_idx][prop_value_name] = \
new_property_value[prop_value_name]
actor_changed = True
found = True
break
if not found:
actor_json['attachment'].append({
"name": new_property_value['name'],
"name": name_value,
"type": "PropertyValue",
"value": new_property_value['value']
"value": new_property_value[prop_value_name]
})
actor_changed = True
# save actor to file

View File

@ -38,6 +38,7 @@ from roles import set_role
from roles import set_rolesFromList
from roles import get_actor_roles_list
from media import process_meta_data
from utils import get_attachment_property_value
from utils import get_nickname_from_actor
from utils import remove_html
from utils import contains_invalid_chars
@ -232,7 +233,7 @@ def get_actor_update_json(actor_json: {}) -> {}:
"@id": "as:movedTo",
"@type": "@id"
},
"schema": "http://schema.org#",
"schema": "http://schema.org/",
"PropertyValue": "schema:PropertyValue",
"value": "schema:value",
"IdentityProof": "toot:IdentityProof",
@ -338,7 +339,7 @@ def get_default_person_context() -> str:
'messageType': 'toot:messageType',
'movedTo': {'@id': 'as:movedTo', '@type': '@id'},
'publicKeyBase64': 'toot:publicKeyBase64',
'schema': 'http://schema.org#',
'schema': 'http://schema.org/',
'suspended': 'toot:suspended',
'toot': 'http://joinmastodon.org/ns#',
'value': 'schema:value',
@ -1789,10 +1790,14 @@ def valid_sending_actor(session, base_dir: str,
continue
if isinstance(tag['name'], str):
bio_str += ' ' + tag['name']
if tag.get('value'):
prop_value_name, _ = \
get_attachment_property_value(tag)
if not prop_value_name:
continue
if isinstance(tag['value'], str):
bio_str += ' ' + tag['value']
if tag.get(prop_value_name):
continue
if isinstance(tag[prop_value_name], str):
bio_str += ' ' + tag[prop_value_name]
if actor_json.get('name'):
bio_str += ' ' + remove_html(actor_json['name'])
@ -1814,19 +1819,20 @@ def valid_sending_actor(session, base_dir: str,
for tag in actor_json['attachment']:
if not isinstance(tag, dict):
continue
if not tag.get('name'):
if not tag.get('name') and not tag.get('schema:name'):
continue
no_of_tags += 1
if not tag.get('value'):
prop_value_name, _ = get_attachment_property_value(tag)
if not prop_value_name:
tags_without_value += 1
continue
if not isinstance(tag['value'], str):
if not isinstance(tag[prop_value_name], str):
tags_without_value += 1
continue
if not tag['value'].strip():
if not tag[prop_value_name].strip():
tags_without_value += 1
continue
if len(tag['value']) < 2:
if len(tag[prop_value_name]) < 2:
tags_without_value += 1
continue
if no_of_tags > 0:

149
pgp.py
View File

@ -30,27 +30,37 @@ from cwtch import get_cwtch_address
from blog import get_blog_address
from utils import get_attachment_property_value
def get_email_address(actor_json: {}) -> str:
"""Returns the email address for the given actor
"""
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('email'):
if not name_value.lower().startswith('email'):
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
if '@' not in property_value['value']:
if '@' not in property_value[prop_value_name]:
continue
if '.' not in property_value['value']:
if '.' not in property_value[prop_value_name]:
continue
return property_value['value']
return property_value[prop_value_name]
return ''
@ -60,19 +70,26 @@ def get_pgp_pub_key(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('pgp'):
if not name_value.lower().startswith('pgp'):
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
if not contains_pgp_public_key(property_value['value']):
if not contains_pgp_public_key(property_value[prop_value_name]):
continue
return property_value['value']
return property_value[prop_value_name]
return ''
@ -82,19 +99,26 @@ def get_pgp_fingerprint(actor_json: {}) -> str:
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('openpgp'):
if not name_value.lower().startswith('openpgp'):
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
if len(property_value['value']) < 10:
if len(property_value[prop_value_name]) < 10:
continue
return property_value['value']
return property_value[prop_value_name]
return ''
@ -117,11 +141,16 @@ def set_email_address(actor_json: {}, email_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('email'):
if not name_value.lower().startswith('email'):
continue
property_found = property_value
break
@ -131,15 +160,24 @@ def set_email_address(actor_json: {}, email_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('email'):
if not name_value.lower().startswith('email'):
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = email_address
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = email_address
return
new_email_address = {
@ -168,11 +206,16 @@ def set_pgp_pub_key(actor_json: {}, pgp_pub_key: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('pgp'):
if not name_value.lower().startswith('pgp'):
continue
property_found = property_value
break
@ -182,15 +225,24 @@ def set_pgp_pub_key(actor_json: {}, pgp_pub_key: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('pgp'):
if not name_value.lower().startswith('pgp'):
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = pgp_pub_key
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = pgp_pub_key
return
newpgp_pub_key = {
@ -217,11 +269,16 @@ def set_pgp_fingerprint(actor_json: {}, fingerprint: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('openpgp'):
if not name_value.lower().startswith('openpgp'):
continue
property_found = property_value
break
@ -231,15 +288,24 @@ def set_pgp_fingerprint(actor_json: {}, fingerprint: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('openpgp'):
if not name_value.lower().startswith('openpgp'):
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = fingerprint.strip()
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = fingerprint.strip()
return
newpgp_fingerprint = {
@ -451,12 +517,13 @@ def _get_pgp_public_key_from_actor(signing_priv_key_pem: str,
for tag in actor_json['attachment']:
if not isinstance(tag, dict):
continue
if not tag.get('value'):
prop_value_name, _ = get_attachment_property_value(tag)
if not prop_value_name:
continue
if not isinstance(tag['value'], str):
if not isinstance(tag[prop_value_name], str):
continue
if contains_pgp_public_key(tag['value']):
return tag['value']
if contains_pgp_public_key(tag[prop_value_name]):
return tag[prop_value_name]
return None

59
ssb.py
View File

@ -8,34 +8,45 @@ __status__ = "Production"
__module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def get_ssb_address(actor_json: {}) -> str:
"""Returns ssb address for the given actor
"""
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('ssb'):
if not name_value.lower().startswith('ssb'):
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = property_value['value'].strip()
if not property_value['value'].startswith('@'):
property_value[prop_value_name] = \
property_value[prop_value_name].strip()
if not property_value[prop_value_name].startswith('@'):
continue
if '=.' not in property_value['value']:
if '=.' not in property_value[prop_value_name]:
continue
if '"' in property_value['value']:
if '"' in property_value[prop_value_name]:
continue
if ' ' in property_value['value']:
if ' ' in property_value[prop_value_name]:
continue
if ',' in property_value['value']:
if ',' in property_value[prop_value_name]:
continue
return property_value['value']
return property_value[prop_value_name]
return ''
@ -62,11 +73,16 @@ def set_ssb_address(actor_json: {}, ssb_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('ssb'):
if not name_value.lower().startswith('ssb'):
continue
property_found = property_value
break
@ -76,15 +92,24 @@ def set_ssb_address(actor_json: {}, ssb_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('ssb'):
if not name_value.lower().startswith('ssb'):
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = ssb_address
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = ssb_address
return
new_ssb_address = {

62
tox.py
View File

@ -8,36 +8,48 @@ __status__ = "Production"
__module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def get_tox_address(actor_json: {}) -> str:
"""Returns tox address for the given actor
"""
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('tox'):
if not name_value.lower().startswith('tox'):
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = property_value['value'].strip()
if len(property_value['value']) != 76:
property_value[prop_value_name] = \
property_value[prop_value_name].strip()
if len(property_value[prop_value_name]) != 76:
continue
if property_value['value'].upper() != property_value['value']:
if property_value[prop_value_name].upper() != \
property_value[prop_value_name]:
continue
if '"' in property_value['value']:
if '"' in property_value[prop_value_name]:
continue
if ' ' in property_value['value']:
if ' ' in property_value[prop_value_name]:
continue
if ',' in property_value['value']:
if ',' in property_value[prop_value_name]:
continue
if '.' in property_value['value']:
if '.' in property_value[prop_value_name]:
continue
return property_value['value']
return property_value[prop_value_name]
return ''
@ -67,11 +79,16 @@ def set_tox_address(actor_json: {}, tox_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('tox'):
if not name_value.lower().startswith('tox'):
continue
property_found = property_value
break
@ -81,15 +98,24 @@ def set_tox_address(actor_json: {}, tox_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith('tox'):
if not name_value.lower().startswith('tox'):
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = tox_address
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = tox_address
return
new_tox_address = {

View File

@ -52,22 +52,29 @@ def get_actor_languages_list(actor_json: {}) -> []:
if not actor_json.get('attachment'):
return []
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith('languages'):
if not name_value.lower().startswith('languages'):
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
if isinstance(property_value['value'], list):
lang_list = property_value['value']
if isinstance(property_value[prop_value_name], list):
lang_list = property_value[prop_value_name]
lang_list.sort()
return lang_list
if isinstance(property_value['value'], str):
lang_str = property_value['value']
if isinstance(property_value[prop_value_name], str):
lang_str = property_value[prop_value_name]
lang_list_temp = []
if ',' in lang_str:
lang_list_temp = lang_str.split(',')
@ -1099,14 +1106,22 @@ def get_gender_from_bio(base_dir: str, actor: str, person_cache: {},
for tag in tags_list:
if not isinstance(tag, dict):
continue
if not tag.get('name') or not tag.get('value'):
name_value = None
if tag.get('name'):
name_value = tag['name']
if tag.get('schema:name'):
name_value = tag['schema:name']
if not name_value:
continue
if tag['name'].lower() == \
prop_value_name, _ = get_attachment_property_value(tag)
if not prop_value_name:
continue
if name_value.lower() == \
translate['gender'].lower():
bio_found = tag['value']
bio_found = tag[prop_value_name]
break
if tag['name'].lower().startswith(pronoun_str):
bio_found = tag['value']
if name_value.lower().startswith(pronoun_str):
bio_found = tag[prop_value_name]
break
# the field name could be anything,
# just look at the value
@ -1114,9 +1129,13 @@ def get_gender_from_bio(base_dir: str, actor: str, person_cache: {},
for tag in tags_list:
if not isinstance(tag, dict):
continue
if not tag.get('name') or not tag.get('value'):
if not tag.get('name') and not tag.get('schema:name'):
continue
gender = _gender_from_string(translate, tag['value'])
prop_value_name, _ = get_attachment_property_value(tag)
if not prop_value_name:
continue
gender = \
_gender_from_string(translate, tag[prop_value_name])
if gender:
return gender
# if not then use the bio
@ -3113,32 +3132,39 @@ def get_actor_property_url(actor_json: {}, property_name: str) -> str:
return ''
property_name = property_name.lower()
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value['name'].lower().startswith(property_name):
if not name_value.lower().startswith(property_name):
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = property_value['value'].strip()
property_value['value'] = property_value[prop_value_name].strip()
prefixes = get_protocol_prefixes()
prefix_found = False
for prefix in prefixes:
if property_value['value'].startswith(prefix):
if property_value[prop_value_name].startswith(prefix):
prefix_found = True
break
if not prefix_found:
continue
if '.' not in property_value['value']:
if '.' not in property_value[prop_value_name]:
continue
if ' ' in property_value['value']:
if ' ' in property_value[prop_value_name]:
continue
if ',' in property_value['value']:
if ',' in property_value[prop_value_name]:
continue
return property_value['value']
return property_value[prop_value_name]
return ''
@ -3652,3 +3678,20 @@ def disallow_reply(content: str) -> bool:
if diss in content:
return True
return False
def get_attachment_property_value(property_value: {}) -> (str, str):
"""Returns the fieldname and value for an attachment property
"""
prop_value = None
prop_value_name = None
if property_value.get('value'):
prop_value = property_value['value']
prop_value_name = 'value'
elif property_value.get('http://schema.org#value'):
prop_value_name = 'http://schema.org#value'
prop_value = property_value[prop_value_name]
elif property_value.get('https://schema.org#value'):
prop_value_name = 'https://schema.org#value'
prop_value = property_value[prop_value_name]
return prop_value_name, prop_value

View File

@ -11,6 +11,7 @@ import os
from shutil import copyfile
from collections import OrderedDict
from session import get_json
from utils import get_attachment_property_value
from utils import is_account_dir
from utils import remove_html
from utils import get_protocol_prefixes
@ -183,11 +184,16 @@ def _set_actor_property_url(actor_json: {},
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith(property_name_lower):
if not name_value.lower().startswith(property_name_lower):
continue
property_found = property_value
break
@ -210,15 +216,24 @@ def _set_actor_property_url(actor_json: {},
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not property_value['name'].lower().startswith(property_name_lower):
if not name_value.lower().startswith(property_name_lower):
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = url
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = url
return
new_address = {
@ -787,11 +802,16 @@ def html_header_with_person_markup(css_filename: str, instance_title: str,
)
for attach_json in actor_json['attachment']:
if not attach_json.get('name'):
if not attach_json.get('schema:name'):
continue
prop_value_name, _ = get_attachment_property_value(attach_json)
if not prop_value_name:
continue
if not attach_json.get('value'):
continue
name = attach_json['name'].lower()
value = attach_json['value']
if attach_json.get('name'):
name = attach_json['name'].lower()
else:
name = attach_json['schema:name'].lower()
value = attach_json[prop_value_name]
for og_tag in og_tags:
if name != og_tag:
continue

View File

@ -12,6 +12,7 @@ import urllib.parse
from session import get_json
from cache import store_webfinger_in_cache
from cache import get_webfinger_from_cache
from utils import get_attachment_property_value
from utils import get_full_domain
from utils import load_json
from utils import load_json_onionify
@ -414,9 +415,14 @@ def _webfinger_updateFromProfile(wf_json: {}, actor_json: {}) -> bool:
aliases_not_found.append(alias)
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
property_name = property_value['name'].lower()
property_name = name_value.lower()
found = False
for name, alias in webfinger_property_name.items():
if name == property_name:
@ -428,12 +434,14 @@ def _webfinger_updateFromProfile(wf_json: {}, actor_json: {}) -> bool:
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
new_value = property_value['value'].strip()
new_value = property_value[prop_value_name].strip()
if '://' in new_value:
new_value = new_value.split('://')[1]

59
xmpp.py
View File

@ -8,29 +8,38 @@ __status__ = "Production"
__module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
def get_xmpp_address(actor_json: {}) -> str:
"""Returns xmpp address for the given actor
"""
if not actor_json.get('attachment'):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name'].lower()
elif property_value.get('schema:name'):
name_value = property_value['schema:name'].lower()
if not name_value:
continue
name_lower = property_value['name'].lower()
if not (name_lower.startswith('xmpp') or
name_lower.startswith('jabber')):
if not (name_value.startswith('xmpp') or
name_value.startswith('jabber')):
continue
if not property_value.get('type'):
continue
if not property_value.get('value'):
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
if '@' not in property_value['value']:
if '@' not in property_value[prop_value_name]:
continue
if '"' in property_value['value']:
if '"' in property_value[prop_value_name]:
continue
return property_value['value']
return property_value[prop_value_name]
return ''
@ -53,12 +62,17 @@ def set_xmpp_address(actor_json: {}, xmpp_address: str) -> None:
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
if not (property_value['name'].lower().startswith('xmpp') or
property_value['name'].lower().startswith('jabber')):
if not (name_value.lower().startswith('xmpp') or
name_value.lower().startswith('jabber')):
continue
property_found = property_value
break
@ -68,17 +82,26 @@ def set_xmpp_address(actor_json: {}, xmpp_address: str) -> None:
return
for property_value in actor_json['attachment']:
if not property_value.get('name'):
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
name_lower = property_value['name'].lower()
if not (name_lower.startswith('xmpp') or
name_lower.startswith('jabber')):
name_value = name_value.lower()
if not (name_value.startswith('xmpp') or
name_value.startswith('jabber')):
continue
if property_value['type'] != 'PropertyValue':
if not property_value['type'].endswith('PropertyValue'):
continue
property_value['value'] = xmpp_address
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = xmpp_address
return
new_xmpp_address = {