From 1b5626e3a1e89b1bff156151b8ed0e73c2bdd15f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Jul 2021 14:47:02 +0100 Subject: [PATCH 1/8] Chroot option --- epicyon.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/epicyon.py b/epicyon.py index 3d6fe6d1b..65091fb3b 100644 --- a/epicyon.py +++ b/epicyon.py @@ -195,6 +195,12 @@ parser.add_argument('--proxy', dest='proxyPort', type=int, default=None, parser.add_argument('--path', dest='baseDir', type=str, default=os.getcwd(), help='Directory in which to store posts') +parser.add_argument('--chroot', dest='chrootDir', + type=str, default=None, + help='Chroot directory in which to run the system') +parser.add_argument('--setuid', dest='setuid', + type=str, default=None, + help='Set directory permissions uid:gid') parser.add_argument('--ytdomain', dest='YTReplacementDomain', type=str, default=None, help='Domain used to replace youtube.com') @@ -582,6 +588,29 @@ else: if os.path.isfile('debug'): debug = True +if args.chrootDir: + # chroot to a directory + os.chdir(args.chrootDir) + os.chroot(args.chrootDir) + args.baseDir = '' + print('Changed root directory to ' + args.chrootDir) + +if args.setuid: + # set permissions for the directory within which this system will run + import pwd + import grp + if ':' in args.setuid: + setuid = args.setuid.split(':')[0] + setgid = args.setuid.split(':')[1] + else: + setuid = args.setuid + setgid = args.setuid + uid = pwd.getpwnam(setuid) + gid = grp.getgrnam(setgid) + os.setgid(gid) + os.setuid(uid) + print('Setting uid:gid to ' + setuid + ':' + setgid) + if args.tests: runAllTests() sys.exit() From feb61efd6a215a6fb76ac702375b5b1c6b2ccd5d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Jul 2021 16:59:00 +0100 Subject: [PATCH 2/8] Tidying --- tests.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests.py b/tests.py index 9496820ac..c6ac118db 100644 --- a/tests.py +++ b/tests.py @@ -3951,9 +3951,8 @@ def _testSpoofGeolocation() -> None: hourStr = str(hour) if hour < 10: hourStr = '0' + hourStr - currTime = datetime.datetime.strptime("2021-05-" + str(dayNumber) + - " " + hourStr + ":14", - "%Y-%m-%d %H:%M") + dateTimeStr = "2021-05-" + str(dayNumber) + " " + hourStr + ":14" + currTime = datetime.datetime.strptime(dateTimeStr, "%Y-%m-%d %H:%M") coords = spoofGeolocation('', 'new york, usa', currTime, decoySeed, citiesList, nogoList) longitude = coords[1] @@ -3989,9 +3988,8 @@ def _testSpoofGeolocation() -> None: hourStr = str(hour) if hour < 10: hourStr = '0' + hourStr - currTime = datetime.datetime.strptime("2021-05-" + str(dayNumber) + - " " + hourStr + ":14", - "%Y-%m-%d %H:%M") + dateTimeStr = "2021-05-" + str(dayNumber) + " " + hourStr + ":14" + currTime = datetime.datetime.strptime(dateTimeStr, "%Y-%m-%d %H:%M") coords = spoofGeolocation('', 'london, england', currTime, decoySeed, citiesList, nogoList) longitude = coords[1] @@ -4040,9 +4038,8 @@ def _testSpoofGeolocation() -> None: hourStr = str(hour) if hour < 10: hourStr = '0' + hourStr - currTime = datetime.datetime.strptime("2021-05-" + str(dayNumber) + - " " + hourStr + ":14", - "%Y-%m-%d %H:%M") + dateTimeStr = "2021-05-" + str(dayNumber) + " " + hourStr + ":14" + currTime = datetime.datetime.strptime(dateTimeStr, "%Y-%m-%d %H:%M") coords = spoofGeolocation('', 'SAN FRANCISCO, USA', currTime, decoySeed, citiesList, nogoList) longitude = coords[1] @@ -4095,9 +4092,8 @@ def _testSpoofGeolocation() -> None: hourStr = str(hour) if hour < 10: hourStr = '0' + hourStr - currTime = datetime.datetime.strptime("2021-05-" + str(dayNumber) + - " " + hourStr + ":14", - "%Y-%m-%d %H:%M") + dateTimeStr = "2021-05-" + str(dayNumber) + " " + hourStr + ":14" + currTime = datetime.datetime.strptime(dateTimeStr, "%Y-%m-%d %H:%M") coords = spoofGeolocation('', 'SEATTLE, USA', currTime, decoySeed, citiesList, nogoList) longitude = coords[1] From 7b55dfcec151943e8a646ddcc0d921c90eb72ad4 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Jul 2021 17:03:19 +0100 Subject: [PATCH 3/8] Chroot isn't a great idea because there are various dependencies which would also need to be installed --- epicyon.py | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/epicyon.py b/epicyon.py index 65091fb3b..3d6fe6d1b 100644 --- a/epicyon.py +++ b/epicyon.py @@ -195,12 +195,6 @@ parser.add_argument('--proxy', dest='proxyPort', type=int, default=None, parser.add_argument('--path', dest='baseDir', type=str, default=os.getcwd(), help='Directory in which to store posts') -parser.add_argument('--chroot', dest='chrootDir', - type=str, default=None, - help='Chroot directory in which to run the system') -parser.add_argument('--setuid', dest='setuid', - type=str, default=None, - help='Set directory permissions uid:gid') parser.add_argument('--ytdomain', dest='YTReplacementDomain', type=str, default=None, help='Domain used to replace youtube.com') @@ -588,29 +582,6 @@ else: if os.path.isfile('debug'): debug = True -if args.chrootDir: - # chroot to a directory - os.chdir(args.chrootDir) - os.chroot(args.chrootDir) - args.baseDir = '' - print('Changed root directory to ' + args.chrootDir) - -if args.setuid: - # set permissions for the directory within which this system will run - import pwd - import grp - if ':' in args.setuid: - setuid = args.setuid.split(':')[0] - setgid = args.setuid.split(':')[1] - else: - setuid = args.setuid - setgid = args.setuid - uid = pwd.getpwnam(setuid) - gid = grp.getgrnam(setgid) - os.setgid(gid) - os.setuid(uid) - print('Setting uid:gid to ' + setuid + ':' + setgid) - if args.tests: runAllTests() sys.exit() From eb3374765651cd1cce325654705797a0c2017480 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Jul 2021 17:44:07 +0100 Subject: [PATCH 4/8] Tidying --- feeds.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/feeds.py b/feeds.py index 5a5eba61a..310243981 100644 --- a/feeds.py +++ b/feeds.py @@ -9,16 +9,14 @@ __module_group__ = "RSS Feeds" def rss2TagHeader(hashtag: str, httpPrefix: str, domainFull: str) -> str: - rssStr = "" - rssStr += "" - rssStr += '' - rssStr += ' #' + hashtag + '' - rssStr += ' ' + httpPrefix + '://' + domainFull + \ + return \ + "" + \ + "" + \ + '' + \ + ' #' + hashtag + '' + \ + ' ' + httpPrefix + '://' + domainFull + \ '/tags/rss2/' + hashtag + '' - return rssStr def rss2TagFooter() -> str: - rssStr = '' - rssStr += '' - return rssStr + return '' From f7ab9733e9b8f7c0762a7e36735e0b3f38210ea7 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Jul 2021 18:51:58 +0100 Subject: [PATCH 5/8] Tidying --- follow.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/follow.py b/follow.py index 5567dd9bf..0ef1c5ce6 100644 --- a/follow.py +++ b/follow.py @@ -220,18 +220,13 @@ def isFollowerOfPerson(baseDir: str, nickname: str, domain: str, if handle in followersStr: alreadyFollowing = True - elif '://' + followerDomain + \ - '/profile/' + followerNickname in followersStr: - alreadyFollowing = True - elif '://' + followerDomain + \ - '/channel/' + followerNickname in followersStr: - alreadyFollowing = True - elif '://' + followerDomain + \ - '/accounts/' + followerNickname in followersStr: - alreadyFollowing = True - elif '://' + followerDomain + \ - '/u/' + followerNickname in followersStr: - alreadyFollowing = True + else: + paths = ('/profile/', '/channel/', '/accounts/', '/u/') + for userPath in paths: + url = '://' + followerDomain + userPath + followerNickname + if url in followersStr: + alreadyFollowing = True + break return alreadyFollowing From 500e72f0645c59d9a95f37f92f62780160bbcb26 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Jul 2021 19:00:31 +0100 Subject: [PATCH 6/8] Tidying --- happening.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/happening.py b/happening.py index b5606e0e7..2a6b2e842 100644 --- a/happening.py +++ b/happening.py @@ -132,12 +132,10 @@ def saveEventPost(baseDir: str, handle: str, postId: str, calendarNotificationFilename = \ baseDir + '/accounts/' + handle + '/.newCalendar' with open(calendarNotificationFilename, 'w+') as calendarNotificationFile: - calendarNotificationFile.write('/calendar?year=' + - str(eventYear) + - '?month=' + - str(eventMonthNumber) + - '?day=' + - str(eventDayOfMonth)) + notifyStr = \ + '/calendar?year=' + str(eventYear) + '?month=' + \ + str(eventMonthNumber) + '?day=' + str(eventDayOfMonth) + calendarNotificationFile.write(notifyStr) return True From 9194d95b1782978109c1c4b07179e4632dd6af63 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Jul 2021 21:15:34 +0100 Subject: [PATCH 7/8] Tidying --- manualapprove.py | 18 ++++++------------ markdown.py | 33 +++++++++++++-------------------- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/manualapprove.py b/manualapprove.py index 91948a344..c915683ef 100644 --- a/manualapprove.py +++ b/manualapprove.py @@ -111,18 +111,12 @@ def manualApproveFollowRequest(session, baseDir: str, reqNick = approveHandle.split('@')[0] reqDomain = approveHandle.split('@')[1].strip() reqPrefix = httpPrefix + '://' + reqDomain - if reqPrefix + '/profile/' + reqNick in approveFollowsStr: - exists = True - approveHandleFull = reqPrefix + '/profile/' + reqNick - elif reqPrefix + '/channel/' + reqNick in approveFollowsStr: - exists = True - approveHandleFull = reqPrefix + '/channel/' + reqNick - elif reqPrefix + '/accounts/' + reqNick in approveFollowsStr: - exists = True - approveHandleFull = reqPrefix + '/accounts/' + reqNick - elif reqPrefix + '/u/' + reqNick in approveFollowsStr: - exists = True - approveHandleFull = reqPrefix + '/u/' + reqNick + paths = ('/profile/', '/channel/', '/accounts/', '/u/') + for userPath in paths: + if reqPrefix + userPath + reqNick in approveFollowsStr: + exists = True + approveHandleFull = reqPrefix + userPath + reqNick + break if not exists: print('Manual follow accept: ' + approveHandleFull + ' not in requests file "' + diff --git a/markdown.py b/markdown.py index 67d99b426..eb0cbf2d7 100644 --- a/markdown.py +++ b/markdown.py @@ -140,29 +140,22 @@ def markdownToHtml(markdown: str) -> str: linesList = markdown.split('\n') htmlStr = '' ctr = 0 + titles = { + "h5": '#####', + "h4": '####', + "h3": '###', + "h2": '##', + "h1": '#' + } for line in linesList: if ctr > 0: htmlStr += '
' - if line.startswith('#####'): - line = line.replace('#####', '').strip() - line = '
' + line + '
' - ctr = -1 - elif line.startswith('####'): - line = line.replace('####', '').strip() - line = '

' + line + '

' - ctr = -1 - elif line.startswith('###'): - line = line.replace('###', '').strip() - line = '

' + line + '

' - ctr = -1 - elif line.startswith('##'): - line = line.replace('##', '').strip() - line = '

' + line + '

' - ctr = -1 - elif line.startswith('#'): - line = line.replace('#', '').strip() - line = '

' + line + '

' - ctr = -1 + for h, hashes in titles.items(): + if line.startswith(hashes): + line = line.replace(hashes, '').strip() + line = '<' + h + '>' + line + '' + ctr = -1 + break htmlStr += line ctr += 1 return htmlStr From 6f10986407f17183a6a5f18a193b0219788ca38b Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 3 Jul 2021 22:42:26 +0100 Subject: [PATCH 8/8] Lookup actor during migrations --- migrate.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/migrate.py b/migrate.py index b36002a41..bae02eb61 100644 --- a/migrate.py +++ b/migrate.py @@ -13,9 +13,9 @@ from utils import getNicknameFromActor from utils import getDomainFromActor from webfinger import webfingerHandle from blocking import isBlocked -from session import getJson from posts import getUserUrl from follow import unfollowAccount +from person import getActorJson def _moveFollowingHandlesForAccount(baseDir: str, nickname: str, domain: str, @@ -73,22 +73,16 @@ def _updateMovedHandle(baseDir: str, nickname: str, domain: str, print('wfRequest error: ' + str(wfRequest['errors'])) return ctr - profileStr = 'https://www.w3.org/ns/activitystreams' - asHeader = { - 'Accept': 'application/activity+json; profile="' + profileStr + '"' - } if not personUrl: personUrl = getUserUrl(wfRequest, 0, debug) if not personUrl: return ctr - profileStr = 'https://www.w3.org/ns/activitystreams' - asHeader = { - 'Accept': 'application/ld+json; profile="' + profileStr + '"' - } + gnunet = False + if httpPrefix == 'gnunet': + gnunet = True personJson = \ - getJson(session, personUrl, asHeader, None, - debug, __version__, httpPrefix, None) + getActorJson(domain, personUrl, httpPrefix, gnunet, debug) if not personJson: return ctr if not personJson.get('movedTo'):