diff --git a/announce.py b/announce.py index f39732979..814728c15 100644 --- a/announce.py +++ b/announce.py @@ -7,7 +7,7 @@ __email__ = "bob@freedombone.net" __status__ = "Production" __module_group__ = "ActivityPub" -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import hasObjectDict from utils import removeIdEnding from utils import hasUsersPath diff --git a/availability.py b/availability.py index 3cedea24a..32e63481b 100644 --- a/availability.py +++ b/availability.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Core" +__module_group__ = "Profile Metadata" import os from webfinger import webfingerHandle diff --git a/blocking.py b/blocking.py index 0c81fcd8a..128209aaa 100644 --- a/blocking.py +++ b/blocking.py @@ -11,7 +11,7 @@ import os import json import time from datetime import datetime -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import hasObjectDict from utils import isAccountDir from utils import getCachedPostFilename diff --git a/blog.py b/blog.py index cbb2574c8..ef8aed4c5 100644 --- a/blog.py +++ b/blog.py @@ -26,6 +26,7 @@ from utils import getDomainFromActor from utils import locatePost from utils import loadJson from utils import firstParagraphFromString +from utils import getActorPropertyUrl from posts import createBlogsTimeline from newswire import rss2Header from newswire import rss2Footer @@ -884,3 +885,9 @@ def pathContainsBlogLink(baseDir: str, messageId = httpPrefix + '://' + domainFull + \ '/users/' + nickname + '/statuses/' + userEnding2[1] return locatePost(baseDir, nickname, domain, messageId), nickname + + +def getBlogAddress(actorJson: {}) -> str: + """Returns blog address for the given actor + """ + return getActorPropertyUrl(actorJson, 'Blog') diff --git a/bookmarks.py b/bookmarks.py index 414f748bd..5cee25bc1 100644 --- a/bookmarks.py +++ b/bookmarks.py @@ -11,7 +11,7 @@ import os from pprint import pprint from webfinger import webfingerHandle from auth import createBasicAuthHeader -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import hasUsersPath from utils import getFullDomain from utils import removeIdEnding diff --git a/cache.py b/cache.py index 96608524e..8d6291316 100644 --- a/cache.py +++ b/cache.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "ActivityPub" +__module_group__ = "Core" import os import datetime diff --git a/city.py b/city.py index 1726966d3..8a31a7801 100644 --- a/city.py +++ b/city.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Spoofing" +__module_group__ = "Metadata" import os import datetime diff --git a/content.py b/content.py index be1eec89d..85f233767 100644 --- a/content.py +++ b/content.py @@ -11,7 +11,7 @@ import os import email.parser import urllib.parse from shutil import copyfile -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import isValidLanguage from utils import getImageExtensions from utils import loadJson diff --git a/daemon.py b/daemon.py index e180512bf..69795fab2 100644 --- a/daemon.py +++ b/daemon.py @@ -140,13 +140,13 @@ from blog import htmlBlogView from blog import htmlBlogPage from blog import htmlBlogPost from blog import htmlEditBlog +from blog import getBlogAddress from webapp_minimalbutton import setMinimal from webapp_minimalbutton import isMinimal from webapp_utils import getAvatarImageUrl from webapp_utils import htmlHashtagBlocked from webapp_utils import htmlFollowingList from webapp_utils import setBlogAddress -from webapp_utils import getBlogAddress from webapp_calendar import htmlCalendarDeleteConfirm from webapp_calendar import htmlCalendar from webapp_about import htmlAbout diff --git a/delete.py b/delete.py index b51d5c7a0..834e8c46e 100644 --- a/delete.py +++ b/delete.py @@ -9,7 +9,7 @@ __module_group__ = "ActivityPub" import os from datetime import datetime -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import hasUsersPath from utils import getFullDomain from utils import removeIdEnding diff --git a/devices.py b/devices.py index 0f0ef44a9..0ec994cd5 100644 --- a/devices.py +++ b/devices.py @@ -5,6 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" +__module_group__ = "Security" # REST API overview # diff --git a/domainhandler.py b/domainhandler.py deleted file mode 100644 index b7875b32a..000000000 --- a/domainhandler.py +++ /dev/null @@ -1,32 +0,0 @@ -__filename__ = "domainhandler.py" -__author__ = "Bob Mottram" -__license__ = "AGPL3+" -__version__ = "1.2.0" -__maintainer__ = "Bob Mottram" -__email__ = "bob@freedombone.net" -__status__ = "Production" -__module_group__ = "Core" - - -def removeDomainPort(domain: str) -> str: - """If the domain has a port appended then remove it - eg. mydomain.com:80 becomes mydomain.com - """ - if ':' in domain: - if domain.startswith('did:'): - return domain - domain = domain.split(':')[0] - return domain - - -def getPortFromDomain(domain: str) -> int: - """If the domain has a port number appended then return it - eg. mydomain.com:80 returns 80 - """ - if ':' in domain: - if domain.startswith('did:'): - return None - portStr = domain.split(':')[1] - if portStr.isdigit(): - return int(portStr) - return None diff --git a/epicyon.py b/epicyon.py index 6e4abafdb..aa3966cea 100644 --- a/epicyon.py +++ b/epicyon.py @@ -61,8 +61,8 @@ from tests import testUpdateActor from tests import runAllTests from auth import storeBasicCredentials from auth import createPassword -from domainhandler import removeDomainPort -from domainhandler import getPortFromDomain +from utils import removeDomainPort +from utils import getPortFromDomain from utils import hasUsersPath from utils import getFullDomain from utils import setConfigParam diff --git a/filters.py b/filters.py index 67ca4d98d..fef1ed171 100644 --- a/filters.py +++ b/filters.py @@ -5,6 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" +__module_group__ = "Moderation" import os diff --git a/follow.py b/follow.py index 2745c8ec5..096394dd4 100644 --- a/follow.py +++ b/follow.py @@ -9,7 +9,7 @@ __module_group__ = "ActivityPub" from pprint import pprint import os -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import hasObjectDict from utils import hasUsersPath from utils import getFullDomain diff --git a/followingCalendar.py b/followingCalendar.py index 68bef2973..af38b10b0 100644 --- a/followingCalendar.py +++ b/followingCalendar.py @@ -8,7 +8,18 @@ __status__ = "Production" __module_group__ = "Calendar" import os -from domainhandler import removeDomainPort + + +def _portDomainRemove(domain: str) -> str: + """If the domain has a port appended then remove it + eg. mydomain.com:80 becomes mydomain.com + same as removeDomainPort in utils.py + """ + if ':' in domain: + if domain.startswith('did:'): + return domain + domain = domain.split(':')[0] + return domain def receivingCalendarEvents(baseDir: str, nickname: str, domain: str, @@ -44,7 +55,7 @@ def _receiveCalendarEvents(baseDir: str, nickname: str, domain: str, indicating whether to receive calendar events from that account """ # check that a following file exists - domain = removeDomainPort(domain) + domain = _portDomainRemove(domain) followingFilename = baseDir + '/accounts/' + \ nickname + '@' + domain + '/following.txt' if not os.path.isfile(followingFilename): diff --git a/git.py b/git.py index 2dcea4d31..d198d4c93 100644 --- a/git.py +++ b/git.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Core" +__module_group__ = "Profile Metadata" import os import html diff --git a/inbox.py b/inbox.py index 1f5c86e18..cbc5f2da6 100644 --- a/inbox.py +++ b/inbox.py @@ -13,8 +13,8 @@ import datetime import time import random from linked_data_sig import verifyJsonSignature -from domainhandler import removeDomainPort -from domainhandler import getPortFromDomain +from utils import removeDomainPort +from utils import getPortFromDomain from utils import hasObjectDict from utils import dmAllowedFromDomain from utils import isRecentPost diff --git a/like.py b/like.py index ee42afead..ad0bff5da 100644 --- a/like.py +++ b/like.py @@ -7,7 +7,7 @@ __email__ = "bob@freedombone.net" __status__ = "Production" __module_group__ = "ActivityPub" -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import hasObjectDict from utils import hasUsersPath from utils import getFullDomain diff --git a/manualapprove.py b/manualapprove.py index 91c78ffac..91948a344 100644 --- a/manualapprove.py +++ b/manualapprove.py @@ -12,8 +12,8 @@ from follow import followedAccountAccepts from follow import followedAccountRejects from follow import removeFromFollowRequests from utils import loadJson -from domainhandler import removeDomainPort -from domainhandler import getPortFromDomain +from utils import removeDomainPort +from utils import getPortFromDomain def manualDenyFollowRequest(session, baseDir: str, diff --git a/mastoapiv1.py b/mastoapiv1.py index 51d6da9cb..bd0d9c131 100644 --- a/mastoapiv1.py +++ b/mastoapiv1.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Core" +__module_group__ = "API" import os from utils import loadJson diff --git a/newsdaemon.py b/newsdaemon.py index 79431c794..fda1debc6 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "RSS Feeds" +__module_group__ = "Web Interface Columns" # Example hashtag logic: # diff --git a/newswire.py b/newswire.py index 12daecf28..57b37eb69 100644 --- a/newswire.py +++ b/newswire.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "RSS Feeds" +__module_group__ = "Web Interface Columns" import os import json diff --git a/person.py b/person.py index e148397e2..2f5b357c2 100644 --- a/person.py +++ b/person.py @@ -38,7 +38,7 @@ from roles import setRole from roles import setRolesFromList from roles import getActorRolesList from media import processMetaData -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import getStatusNumber from utils import getFullDomain from utils import validNickname diff --git a/petnames.py b/petnames.py index 21c46095a..2378c9047 100644 --- a/petnames.py +++ b/petnames.py @@ -5,6 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" +__module_group__ = "Core" import os diff --git a/posts.py b/posts.py index 41713a7cc..230b7d72f 100644 --- a/posts.py +++ b/posts.py @@ -32,8 +32,8 @@ from session import postImage from webfinger import webfingerHandle from httpsig import createSignedHeader from siteactive import siteIsActive -from domainhandler import removeDomainPort -from domainhandler import getPortFromDomain +from utils import removeDomainPort +from utils import getPortFromDomain from utils import hasObjectDict from utils import rejectPostId from utils import removeInvalidChars diff --git a/pyjsonld.py b/pyjsonld.py index 042f199ac..18bfbcd79 100644 --- a/pyjsonld.py +++ b/pyjsonld.py @@ -15,7 +15,7 @@ JSON-LD. __copyright__ = 'Copyright (c) 2011-2014 Digital Bazaar, Inc.' __license__ = 'New BSD license' __version__ = '0.6.8' -__module_group__ = "ActivityPub" +__module_group__ = "Security" __all__ = [ 'compact', 'expand', 'flatten', 'frame', 'link', 'from_rdf', 'to_rdf', diff --git a/roles.py b/roles.py index 121dcf7b8..7fb00e38a 100644 --- a/roles.py +++ b/roles.py @@ -5,12 +5,13 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" +__module_group__ = "Profile Metadata" import os from utils import loadJson from utils import saveJson from utils import getStatusNumber -from domainhandler import removeDomainPort +from utils import removeDomainPort def _clearRoleStatus(baseDir: str, role: str) -> None: diff --git a/shares.py b/shares.py index 488a276fb..2a2261c7c 100644 --- a/shares.py +++ b/shares.py @@ -20,7 +20,7 @@ from utils import loadJson from utils import saveJson from utils import getImageExtensions from utils import hasObjectDict -from domainhandler import removeDomainPort +from utils import removeDomainPort from media import processMetaData diff --git a/siteactive.py b/siteactive.py index ca530bf49..c5e96f821 100644 --- a/siteactive.py +++ b/siteactive.py @@ -6,6 +6,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" +__module_group__ = "Core" import http.client from urllib.parse import urlparse diff --git a/skills.py b/skills.py index dae7d567b..3d5d3f92b 100644 --- a/skills.py +++ b/skills.py @@ -5,6 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" +__module_group__ = "Profile Metadata" import os from webfinger import webfingerHandle diff --git a/socnet.py b/socnet.py index 30450c1ff..4ae5d3e1c 100644 --- a/socnet.py +++ b/socnet.py @@ -5,6 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" +__module_group__ = "Moderation" from session import createSession from webfinger import webfingerHandle diff --git a/speaker.py b/speaker.py index dc77f0207..2d8d788d1 100644 --- a/speaker.py +++ b/speaker.py @@ -5,6 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" +__module_group__ = "Accessibility" import os import html diff --git a/tests.py b/tests.py index 40098610f..72b6cb741 100644 --- a/tests.py +++ b/tests.py @@ -2890,6 +2890,91 @@ def _functionArgsMatch(callArgs: [], funcArgs: []): return callArgsCtr >= funcArgsCtr +def _moduleInGroups(modName: str, includeGroups: [], modGroups: {}) -> bool: + """Is the given module within the included groups list? + """ + for groupName in includeGroups: + if modName in modGroups[groupName]: + return True + return False + + +def _diagramGroups(includeGroups: [], + excludeExtraModules: [], + modules: {}, modGroups: {}, + maxModuleCalls: int) -> None: + """Draws a dot diagram containing only the given module groups + """ + callGraphStr = 'digraph EpicyonGroups {\n\n' + callGraphStr += ' graph [fontsize=10 fontname="Verdana" compound=true];\n' + callGraphStr += ' node [fontsize=10 fontname="Verdana"];\n\n' + excludeModulesFromDiagram = [ + 'setup', 'tests', '__init__', 'pyjsonld' + ] + excludeModulesFromDiagram += excludeExtraModules + # colors of modules nodes + for modName, modProperties in modules.items(): + if modName in excludeModulesFromDiagram: + continue + if not _moduleInGroups(modName, includeGroups, modGroups): + continue + if not modProperties.get('calls'): + callGraphStr += ' "' + modName + \ + '" [fillcolor=yellow style=filled];\n' + continue + if len(modProperties['calls']) <= int(maxModuleCalls / 8): + callGraphStr += ' "' + modName + \ + '" [fillcolor=green style=filled];\n' + elif len(modProperties['calls']) < int(maxModuleCalls / 4): + callGraphStr += ' "' + modName + \ + '" [fillcolor=orange style=filled];\n' + else: + callGraphStr += ' "' + modName + \ + '" [fillcolor=red style=filled];\n' + callGraphStr += '\n' + # connections between modules + for modName, modProperties in modules.items(): + if modName in excludeModulesFromDiagram: + continue + if not _moduleInGroups(modName, includeGroups, modGroups): + continue + if not modProperties.get('calls'): + continue + for modCall in modProperties['calls']: + if modCall in excludeModulesFromDiagram: + continue + if not _moduleInGroups(modCall, includeGroups, modGroups): + continue + callGraphStr += ' "' + modName + '" -> "' + modCall + '";\n' + # module groups/clusters + clusterCtr = 1 + for groupName, groupModules in modGroups.items(): + if groupName not in includeGroups: + continue + callGraphStr += '\n' + callGraphStr += \ + ' subgraph cluster_' + str(clusterCtr) + ' {\n' + callGraphStr += ' node [style=filled];\n' + for modName in groupModules: + if modName not in excludeModulesFromDiagram: + callGraphStr += ' ' + modName + ';\n' + callGraphStr += ' label = "' + groupName + '";\n' + callGraphStr += ' color = blue;\n' + callGraphStr += ' }\n' + clusterCtr += 1 + callGraphStr += '\n}\n' + filename = 'epicyon_groups' + for groupName in includeGroups: + filename += '_' + groupName.replace(' ', '-') + filename += '.dot' + with open(filename, 'w+') as fp: + fp.write(callGraphStr) + print('Graph saved to ' + filename) + print('Plot using: ' + + 'sfdp -x -Goverlap=false -Goverlap_scaling=2 ' + + '-Gsep=+100 -Tx11 epicyon_modules.dot') + + def _testFunctions(): print('testFunctions') function = {} @@ -3139,51 +3224,29 @@ def _testFunctions(): else: modules[modName]['calls'] = [modCall] lineCtr += 1 - callGraphStr = 'digraph EpicyonModules {\n\n' - callGraphStr += ' graph [fontsize=10 fontname="Verdana" compound=true];\n' - callGraphStr += ' node [shape=record fontsize=10 fontname="Verdana"];\n\n' - # colors of modules nodes - for modName, modProperties in modules.items(): - if not modProperties.get('calls'): - callGraphStr += ' "' + modName + \ - '" [fillcolor=yellow style=filled];\n' - continue - if len(modProperties['calls']) <= int(maxModuleCalls / 8): - callGraphStr += ' "' + modName + \ - '" [fillcolor=green style=filled];\n' - elif len(modProperties['calls']) < int(maxModuleCalls / 4): - callGraphStr += ' "' + modName + \ - '" [fillcolor=orange style=filled];\n' - else: - callGraphStr += ' "' + modName + \ - '" [fillcolor=red style=filled];\n' - callGraphStr += '\n' - # connections between modules - for modName, modProperties in modules.items(): - if not modProperties.get('calls'): - continue - for modCall in modProperties['calls']: - callGraphStr += ' "' + modName + '" -> "' + modCall + '";\n' - # module groups/clusters - clusterCtr = 1 - for groupName, groupModules in modGroups.items(): - callGraphStr += '\n' - callGraphStr += \ - ' subgraph cluster_' + str(clusterCtr) + ' {\n' - callGraphStr += ' node [style=filled];\n' - for modName in groupModules: - callGraphStr += ' ' + modName + ';\n' - callGraphStr += ' label = "' + groupName + '";\n' - callGraphStr += ' color = blue;\n' - callGraphStr += ' }\n' - clusterCtr += 1 - callGraphStr += '\n}\n' - with open('epicyon_modules.dot', 'w+') as fp: - fp.write(callGraphStr) - print('Modules call graph saved to epicyon_modules.dot') - print('Plot using: ' + - 'sfdp -x -Goverlap=false -Goverlap_scaling=2 ' + - '-Gsep=+100 -Tx11 epicyon_modules.dot') + + _diagramGroups(['Commandline Interface', 'ActivityPub'], ['utils'], + modules, modGroups, maxModuleCalls) + _diagramGroups(['Commandline Interface', 'Core'], ['utils'], + modules, modGroups, maxModuleCalls) + _diagramGroups(['Timeline', 'Core'], ['utils'], + modules, modGroups, maxModuleCalls) + _diagramGroups(['Web Interface', 'Core'], ['utils'], + modules, modGroups, maxModuleCalls) + _diagramGroups(['Web Interface Columns', 'Core'], ['utils'], + modules, modGroups, maxModuleCalls) + _diagramGroups(['Core'], [], + modules, modGroups, maxModuleCalls) + _diagramGroups(['ActivityPub'], [], + modules, modGroups, maxModuleCalls) + _diagramGroups(['ActivityPub', 'Core'], ['utils'], + modules, modGroups, maxModuleCalls) + _diagramGroups(['ActivityPub', 'Security'], ['utils'], + modules, modGroups, maxModuleCalls) + _diagramGroups(['Core', 'Security'], ['utils'], + modules, modGroups, maxModuleCalls) + _diagramGroups(['Timeline', 'Security'], ['utils'], + modules, modGroups, maxModuleCalls) callGraphStr = 'digraph Epicyon {\n\n' callGraphStr += ' size="8,6"; ratio=fill;\n' diff --git a/theme.py b/theme.py index 4223bb121..a700d9706 100644 --- a/theme.py +++ b/theme.py @@ -5,6 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" +__module_group__ = "Web Interface" import os from utils import isAccountDir diff --git a/threads.py b/threads.py index c07de0821..0c734c485 100644 --- a/threads.py +++ b/threads.py @@ -5,6 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" +__module_group__ = "Core" import threading import sys diff --git a/utils.py b/utils.py index 33454cf14..c2a79642f 100644 --- a/utils.py +++ b/utils.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "ActivityPu" +__module_group__ = "Core" import os import re @@ -16,8 +16,6 @@ import json import idna import locale from pprint import pprint -from domainhandler import removeDomainPort -from domainhandler import getPortFromDomain from followingCalendar import addPersonToCalendar from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import hashes @@ -2403,3 +2401,77 @@ def hasObjectDict(postJsonObject: {}) -> bool: if isinstance(postJsonObject['object'], dict): return True return False + + +def getAltPath(actor: str, domainFull: str, callingDomain: str) -> str: + """Returns alternate path from the actor + eg. https://clearnetdomain/path becomes http://oniondomain/path + """ + postActor = actor + if callingDomain not in actor and domainFull in actor: + if callingDomain.endswith('.onion') or \ + callingDomain.endswith('.i2p'): + postActor = \ + 'http://' + callingDomain + actor.split(domainFull)[1] + print('Changed POST domain from ' + actor + ' to ' + postActor) + return postActor + + +def getActorPropertyUrl(actorJson: {}, propertyName: str) -> str: + """Returns a url property from an actor + """ + if not actorJson.get('attachment'): + return '' + propertyName = propertyName.lower() + for propertyValue in actorJson['attachment']: + if not propertyValue.get('name'): + continue + if not propertyValue['name'].lower().startswith(propertyName): + continue + if not propertyValue.get('type'): + continue + if not propertyValue.get('value'): + continue + if propertyValue['type'] != 'PropertyValue': + continue + propertyValue['value'] = propertyValue['value'].strip() + prefixes = getProtocolPrefixes() + prefixFound = False + for prefix in prefixes: + if propertyValue['value'].startswith(prefix): + prefixFound = True + break + if not prefixFound: + continue + if '.' not in propertyValue['value']: + continue + if ' ' in propertyValue['value']: + continue + if ',' in propertyValue['value']: + continue + return propertyValue['value'] + return '' + + +def removeDomainPort(domain: str) -> str: + """If the domain has a port appended then remove it + eg. mydomain.com:80 becomes mydomain.com + """ + if ':' in domain: + if domain.startswith('did:'): + return domain + domain = domain.split(':')[0] + return domain + + +def getPortFromDomain(domain: str) -> int: + """If the domain has a port number appended then return it + eg. mydomain.com:80 returns 80 + """ + if ':' in domain: + if domain.startswith('did:'): + return None + portStr = domain.split(':')[1] + if portStr.isdigit(): + return int(portStr) + return None diff --git a/webapp_accesskeys.py b/webapp_accesskeys.py index 9813a5d46..c901a59c1 100644 --- a/webapp_accesskeys.py +++ b/webapp_accesskeys.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Web Interface" +__module_group__ = "Accessibility" import os from utils import isAccountDir diff --git a/webapp_calendar.py b/webapp_calendar.py index 740cf514c..65cdb7de0 100644 --- a/webapp_calendar.py +++ b/webapp_calendar.py @@ -18,12 +18,12 @@ from utils import getDomainFromActor from utils import locatePost from utils import loadJson from utils import weekDayOfMonthStart -from domainhandler import removeDomainPort +from utils import getAltPath +from utils import removeDomainPort from happening import getTodaysEvents from happening import getCalendarEvents from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter -from webapp_utils import getAltPath from webapp_utils import htmlHideFromScreenReader from webapp_utils import htmlKeyboardNavigation diff --git a/webapp_column_left.py b/webapp_column_left.py index 6a63126db..eea4ace02 100644 --- a/webapp_column_left.py +++ b/webapp_column_left.py @@ -5,13 +5,13 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Web Interface" +__module_group__ = "Web Interface Columns" import os from utils import getConfigParam from utils import getNicknameFromActor from utils import isEditor -from domainhandler import removeDomainPort +from utils import removeDomainPort from webapp_utils import sharesTimelineJson from webapp_utils import htmlPostSeparator from webapp_utils import getLeftImageFile diff --git a/webapp_column_right.py b/webapp_column_right.py index 15c95c40a..3ea61e1c9 100644 --- a/webapp_column_right.py +++ b/webapp_column_right.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Web Interface" +__module_group__ = "Web Interface Columns" import os from datetime import datetime @@ -17,7 +17,7 @@ from utils import votesOnNewswireItem from utils import getNicknameFromActor from utils import isEditor from utils import getConfigParam -from domainhandler import removeDomainPort +from utils import removeDomainPort from posts import isModerator from webapp_utils import getRightImageFile from webapp_utils import htmlHeaderWithExternalStyle diff --git a/webapp_confirm.py b/webapp_confirm.py index 9d9847dfb..69f0cc576 100644 --- a/webapp_confirm.py +++ b/webapp_confirm.py @@ -15,7 +15,7 @@ from utils import getDomainFromActor from utils import locatePost from utils import loadJson from utils import getConfigParam -from webapp_utils import getAltPath +from utils import getAltPath from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter from webapp_post import individualPostAsHtml diff --git a/webapp_frontscreen.py b/webapp_frontscreen.py index d6e397d10..585489077 100644 --- a/webapp_frontscreen.py +++ b/webapp_frontscreen.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Web Interface" +__module_group__ = "Timeline" import os from utils import isSystemAccount diff --git a/webapp_headerbuttons.py b/webapp_headerbuttons.py index 825dcc302..99ab01290 100644 --- a/webapp_headerbuttons.py +++ b/webapp_headerbuttons.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Web Interface" +__module_group__ = "Timeline" import os diff --git a/webapp_media.py b/webapp_media.py index fe6217041..4d5ff6366 100644 --- a/webapp_media.py +++ b/webapp_media.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Web Interface" +__module_group__ = "Timeline" import os diff --git a/webapp_minimalbutton.py b/webapp_minimalbutton.py index 3b1815f36..3c293528a 100644 --- a/webapp_minimalbutton.py +++ b/webapp_minimalbutton.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Web Interface" +__module_group__ = "Timeline" import os diff --git a/webapp_moderation.py b/webapp_moderation.py index 01bddd2ad..7a2c696e7 100644 --- a/webapp_moderation.py +++ b/webapp_moderation.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Web Interface" +__module_group__ = "Moderation" import os from utils import isAccountDir diff --git a/webapp_profile.py b/webapp_profile.py index 4b47bbe36..ca6d6e9fb 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -52,7 +52,7 @@ from webapp_utils import htmlFooter from webapp_utils import addEmojiToDisplayName from webapp_utils import getBannerFile from webapp_utils import htmlPostSeparator -from webapp_utils import getBlogAddress +from blog import getBlogAddress from webapp_post import individualPostAsHtml from webapp_timeline import htmlIndividualShare diff --git a/webapp_search.py b/webapp_search.py index 22221ea1c..892e3f52d 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -22,13 +22,13 @@ from utils import locatePost from utils import isPublicPost from utils import firstParagraphFromString from utils import searchBoxPosts +from utils import getAltPath from skills import noOfActorSkills from skills import getSkillsFromList from categories import getHashtagCategory from feeds import rss2TagHeader from feeds import rss2TagFooter from webapp_utils import htmlKeyboardNavigation -from webapp_utils import getAltPath from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter from webapp_utils import getSearchBannerFile diff --git a/webapp_utils.py b/webapp_utils.py index 22d6fb787..5bf49b8ce 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -150,20 +150,6 @@ def headerButtonsFrontScreen(translate: {}, return headerStr -def getAltPath(actor: str, domainFull: str, callingDomain: str) -> str: - """Returns alternate path from the actor - eg. https://clearnetdomain/path becomes http://oniondomain/path - """ - postActor = actor - if callingDomain not in actor and domainFull in actor: - if callingDomain.endswith('.onion') or \ - callingDomain.endswith('.i2p'): - postActor = \ - 'http://' + callingDomain + actor.split(domainFull)[1] - print('Changed POST domain from ' + actor + ' to ' + postActor) - return postActor - - def getContentWarningButton(postID: str, translate: {}, content: str) -> str: """Returns the markup for a content warning button @@ -174,48 +160,6 @@ def getContentWarningButton(postID: str, translate: {}, '\n' -def _getActorPropertyUrl(actorJson: {}, propertyName: str) -> str: - """Returns a url property from an actor - """ - if not actorJson.get('attachment'): - return '' - propertyName = propertyName.lower() - for propertyValue in actorJson['attachment']: - if not propertyValue.get('name'): - continue - if not propertyValue['name'].lower().startswith(propertyName): - continue - if not propertyValue.get('type'): - continue - if not propertyValue.get('value'): - continue - if propertyValue['type'] != 'PropertyValue': - continue - propertyValue['value'] = propertyValue['value'].strip() - prefixes = getProtocolPrefixes() - prefixFound = False - for prefix in prefixes: - if propertyValue['value'].startswith(prefix): - prefixFound = True - break - if not prefixFound: - continue - if '.' not in propertyValue['value']: - continue - if ' ' in propertyValue['value']: - continue - if ',' in propertyValue['value']: - continue - return propertyValue['value'] - return '' - - -def getBlogAddress(actorJson: {}) -> str: - """Returns blog address for the given actor - """ - return _getActorPropertyUrl(actorJson, 'Blog') - - def _setActorPropertyUrl(actorJson: {}, propertyName: str, url: str) -> None: """Sets a url for the given actor property """ diff --git a/webapp_welcome.py b/webapp_welcome.py index c1e804a82..0e970fc5b 100644 --- a/webapp_welcome.py +++ b/webapp_welcome.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Web Interface" +__module_group__ = "Onboarding" import os from shutil import copyfile diff --git a/webapp_welcome_final.py b/webapp_welcome_final.py index 01349aa28..0b6491c47 100644 --- a/webapp_welcome_final.py +++ b/webapp_welcome_final.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Web Interface" +__module_group__ = "Onboarding" import os from shutil import copyfile diff --git a/webapp_welcome_profile.py b/webapp_welcome_profile.py index 990c88fe2..1362aa344 100644 --- a/webapp_welcome_profile.py +++ b/webapp_welcome_profile.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Web Interface" +__module_group__ = "Onboarding" import os from shutil import copyfile diff --git a/webfinger.py b/webfinger.py index c774a0c85..c82a5199c 100644 --- a/webfinger.py +++ b/webfinger.py @@ -17,7 +17,7 @@ from utils import loadJson from utils import loadJsonOnionify from utils import saveJson from utils import getProtocolPrefixes -from domainhandler import removeDomainPort +from utils import removeDomainPort def _parseHandle(handle: str) -> (str, str):