From bee0d99ce6b92dd2f2f1def5c2e3cac1e4a70078 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 9 Jun 2020 12:51:51 +0100 Subject: [PATCH] Support for gnunet --- content.py | 7 +++++++ epicyon.py | 12 ++++++++++++ inbox.py | 1 + session.py | 6 +++++- utils.py | 4 ++++ webfinger.py | 1 + webinterface.py | 5 +++++ 7 files changed, 35 insertions(+), 1 deletion(-) diff --git a/content.py b/content.py index b825722e..214f46ba 100644 --- a/content.py +++ b/content.py @@ -137,6 +137,7 @@ def addWebLinks(content: str) -> str: if w.startswith('https://') or \ w.startswith('http://') or \ w.startswith('i2p://') or \ + w.startswith('gnunet://') or \ w.startswith('gemini://') or \ w.startswith('gopher://') or \ w.startswith('hyper://') or \ @@ -151,6 +152,8 @@ def addWebLinks(content: str) -> str: markup += '' elif w.startswith('i2p://'): markup += '' + elif w.startswith('gnunet://'): + markup += '' elif w.startswith('dat://'): markup += '' elif w.startswith('hyper://'): @@ -161,6 +164,7 @@ def addWebLinks(content: str) -> str: markup += '' linkText = w.replace('https://', '').replace('http://', '') linkText = linkText.replace('dat://', '').replace('i2p://', '') + linkText = linkText.replace('gnunet://', '') linkText = linkText.replace('hyper://', '') linkText = linkText.replace('gemini://', '') linkText = linkText.replace('gopher://', '') @@ -421,6 +425,8 @@ def removeLongWords(content: str, maxWordLength: int, continue elif 'i2p:' in wordStr: continue + elif 'gnunet:' in wordStr: + continue elif 'dat:' in wordStr: continue elif 'hyper:' in wordStr: @@ -552,6 +558,7 @@ def getMentionsFromHtml(htmlText: str, continue actorStr = mentionStr.split('"')[0] if actorStr.startswith('http') or \ + actorStr.startswith('gnunet') or \ actorStr.startswith('i2p') or \ actorStr.startswith('hyper') or \ actorStr.startswith('dat:'): diff --git a/epicyon.py b/epicyon.py index 5ade0993..a8e0a4ea 100644 --- a/epicyon.py +++ b/epicyon.py @@ -172,6 +172,9 @@ parser.add_argument("--instanceOnlySkillsSearch", type=str2bool, nargs='?', parser.add_argument("--http", type=str2bool, nargs='?', const=True, default=False, help="Use http only") +parser.add_argument("--gnunet", type=str2bool, nargs='?', + const=True, default=False, + help="Use gnunet protocol only") parser.add_argument("--dat", type=str2bool, nargs='?', const=True, default=False, help="Use dat protocol only") @@ -391,6 +394,8 @@ if args.posts: proxyType = 'tor' elif args.i2p or domain.endswith('.i2p'): proxyType = 'i2p' + elif args.gnunet: + proxyType = 'gnunet' getPublicPostsOfPerson(baseDir, nickname, domain, False, True, proxyType, args.port, httpPrefix, debug, __version__) @@ -409,6 +414,8 @@ if args.postsraw: proxyType = 'tor' elif args.i2p or domain.endswith('.i2p'): proxyType = 'i2p' + elif args.gnunet: + proxyType = 'gnunet' getPublicPostsOfPerson(baseDir, nickname, domain, False, False, proxyType, args.port, httpPrefix, debug, __version__) @@ -603,6 +610,8 @@ if args.tor or domain.endswith('.onion'): proxyType = 'tor' elif args.i2p or domain.endswith('.i2p'): proxyType = 'i2p' +elif args.gnunet: + proxyType = 'gnunet' if args.approve: if not args.nickname: @@ -1012,6 +1021,8 @@ if args.proxyPort: ocapAlways = False if args.ocap: ocapAlways = args.ocap +if args.gnunet: + httpPrefix = 'gnunet' if args.dat: httpPrefix = 'dat' if args.hyper: @@ -1028,6 +1039,7 @@ if args.actor: # format: https://domain/@nick args.actor = args.actor.replace('https://', '') args.actor = args.actor.replace('http://', '') + args.actor = args.actor.replace('gnunet://', '') args.actor = args.actor.replace('dat://', '') args.actor = args.actor.replace('hyper://', '') args.actor = args.actor.replace('i2p://', '') diff --git a/inbox.py b/inbox.py index 2a7f4170..9a247ef7 100644 --- a/inbox.py +++ b/inbox.py @@ -1364,6 +1364,7 @@ def receiveAnnounce(recentPostsCache: {}, messageJson['object'].replace('https://', '') objectDomain = objectDomain.replace('http://', '') objectDomain = objectDomain.replace('i2p://', '') + objectDomain = objectDomain.replace('gnunet://', '') objectDomain = objectDomain.replace('dat://', '') objectDomain = objectDomain.replace('hyper://', '') if '/' in objectDomain: diff --git a/session.py b/session.py index 20f4a771..31de91ac 100644 --- a/session.py +++ b/session.py @@ -31,6 +31,10 @@ def createSession(proxyType: str): session.proxies = {} session.proxies['http'] = 'socks5h://localhost:4447' session.proxies['https'] = 'socks5h://localhost:4447' + elif proxyType == 'gnunet': + session.proxies = {} + session.proxies['http'] = 'socks5h://localhost:7777' + session.proxies['https'] = 'socks5h://localhost:7777' return session @@ -59,7 +63,7 @@ def getJson(session, url: str, headers: {}, params: {}, except Exception as e: print('ERROR: getJson failed\nurl: ' + str(url) + '\n' + 'headers: ' + str(sessionHeaders) + '\n' + - 'params: ' + str(sessionParams)) + 'params: ' + str(sessionParams) + '\n') print(e) return None diff --git a/utils.py b/utils.py index a7974d48..e51cf49d 100644 --- a/utils.py +++ b/utils.py @@ -232,22 +232,26 @@ def getDomainFromActor(actor: str) -> (str, int): domain = actor.split('/profile/')[0].replace('https://', '') domain = domain.replace('http://', '').replace('i2p://', '') domain = domain.replace('dat://', '').replace('hyper://', '') + domain = domain.replace('gnunet://', '') else: if '/channel/' in actor: domain = actor.split('/channel/')[0].replace('https://', '') domain = domain.replace('http://', '').replace('i2p://', '') domain = domain.replace('dat://', '').replace('hyper://', '') + domain = domain.replace('gnunet://', '') else: if '/users/' not in actor: domain = actor.replace('https://', '').replace('http://', '') domain = domain.replace('i2p://', '') domain = domain.replace('dat://', '').replace('hyper://', '') + domain = domain.replace('gnunet://', '') if '/' in actor: domain = domain.split('/')[0] else: domain = actor.split('/users/')[0].replace('https://', '') domain = domain.replace('http://', '').replace('i2p://', '') domain = domain.replace('dat://', '').replace('hyper://', '') + domain = domain.replace('gnunet://', '') if ':' in domain: portStr = domain.split(':')[1] if not portStr.isdigit(): diff --git a/webfinger.py b/webfinger.py index 02310a3a..02976fab 100644 --- a/webfinger.py +++ b/webfinger.py @@ -29,6 +29,7 @@ def parseHandle(handle: str) -> (str, str): handleStr = handle.replace('https://', '').replace('http://', '') handleStr = handleStr.replace('dat://', '').replace('hyper://', '') handleStr = handleStr.replace('i2p://', '') + handleStr = handleStr.replace('gnunet://', '') if '/@' in handle: domain, nickname = handleStr.split('/@') else: diff --git a/webinterface.py b/webinterface.py index 32d77880..e6081603 100644 --- a/webinterface.py +++ b/webinterface.py @@ -102,6 +102,7 @@ def getBlogAddress(actorJson: {}) -> str: propertyValue['value'] = propertyValue['value'].strip() if not (propertyValue['value'].startswith('https://') or propertyValue['value'].startswith('http://') or + propertyValue['value'].startswith('gnunet://') or propertyValue['value'].startswith('dat://') or propertyValue['value'].startswith('hyper://') or propertyValue['value'].startswith('i2p://')): @@ -138,6 +139,7 @@ def setBlogAddress(actorJson: {}, blogAddress: str) -> None: if not (blogAddress.startswith('https://') or blogAddress.startswith('http://') or + blogAddress.startswith('gnunet://') or blogAddress.startswith('dat://') or blogAddress.startswith('hyper://') or blogAddress.startswith('i2p://')): @@ -2800,6 +2802,7 @@ def addEmbeddedAudio(translate: {}, content: str) -> str: if not (w.startswith('http') or w.startswith('dat:') or w.startswith('hyper:') or w.startswith('i2p:') or + w.startswith('gnunet:') or '/' in w): continue url = w @@ -2846,6 +2849,7 @@ def addEmbeddedVideo(translate: {}, content: str, continue if not (w.startswith('http') or w.startswith('dat:') or w.startswith('hyper:') or w.startswith('i2p:') or + w.startswith('gnunet:') or '/' in w): continue url = w @@ -3992,6 +3996,7 @@ def individualPostAsHtml(recentPostsCache: {}, maxRecentPosts: int, postDomain = postDomain.replace('https://', '') postDomain = postDomain.replace('http://', '') postDomain = postDomain.replace('hyper://', '') + postDomain = postDomain.replace('gnunet://', '') postDomain = postDomain.replace('dat://', '') postDomain = postDomain.replace('i2p://', '') if '/' in postDomain: