epicyon/epicyon.py

136 lines
4.4 KiB
Python
Raw Normal View History

2019-06-28 18:55:29 +00:00
__filename__ = "epicyon.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "0.0.1"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
from person import createPerson
2019-07-03 09:40:27 +00:00
from person import setPreferredNickname
2019-06-28 20:00:25 +00:00
from person import setBio
2019-06-28 18:55:29 +00:00
from webfinger import webfingerHandle
2019-07-02 09:25:29 +00:00
from posts import getPosts
2019-06-29 10:08:59 +00:00
from posts import createPublicPost
2019-06-29 11:47:33 +00:00
from posts import deleteAllPosts
2019-06-29 13:17:02 +00:00
from posts import createOutbox
2019-06-29 13:44:21 +00:00
from posts import archivePosts
2019-06-30 10:14:02 +00:00
from posts import sendPost
2019-07-03 10:31:02 +00:00
from posts import getPublicPostsOfPerson
2019-06-28 18:55:29 +00:00
from session import createSession
2019-06-29 16:47:37 +00:00
from session import getJson
2019-06-28 18:55:29 +00:00
import json
2019-06-30 22:56:37 +00:00
import os
2019-06-28 18:55:29 +00:00
import sys
import requests
from pprint import pprint
2019-06-30 20:14:03 +00:00
from tests import testHttpsig
2019-06-28 18:55:29 +00:00
from daemon import runDaemon
2019-06-28 19:52:35 +00:00
import socket
2019-06-29 18:23:13 +00:00
from follow import clearFollows
2019-06-29 20:21:37 +00:00
from follow import clearFollowers
2019-06-29 18:23:13 +00:00
from follow import followPerson
from follow import followerOfPerson
from follow import unfollowPerson
from follow import unfollowerOfPerson
2019-06-30 21:20:02 +00:00
from tests import testPostMessageBetweenServers
from tests import runAllTests
2019-07-03 09:24:55 +00:00
import argparse
2019-06-30 21:20:02 +00:00
2019-07-03 09:24:55 +00:00
def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')
2019-07-03 10:31:02 +00:00
2019-07-03 09:24:55 +00:00
parser = argparse.ArgumentParser(description='ActivityPub Server')
2019-07-03 12:24:54 +00:00
parser.add_argument('-d','--domain', dest='domain', type=str,default='localhost',
2019-07-03 09:24:55 +00:00
help='Domain name of the server')
2019-07-03 10:31:02 +00:00
parser.add_argument('-p','--port', dest='port', type=int,default=8085,
2019-07-03 09:24:55 +00:00
help='Port number to run on')
parser.add_argument('--path', dest='baseDir', type=str,default=os.getcwd(),
help='Directory in which to store posts')
2019-07-03 10:31:02 +00:00
parser.add_argument('--posts', dest='posts', type=str,default=None,
help='Show posts for the given handle')
2019-07-03 11:24:38 +00:00
parser.add_argument('--postsraw', dest='postsraw', type=str,default=None,
help='Show raw json of posts for the given handle')
2019-07-03 09:24:55 +00:00
parser.add_argument('-f','--federate', nargs='+',dest='federationList',
help='Specify federation list separated by spaces')
2019-07-03 16:14:45 +00:00
parser.add_argument("--debug", type=str2bool, nargs='?',
const=True, default=False,
help="Show debug messages")
2019-07-03 12:24:54 +00:00
parser.add_argument("--http", type=str2bool, nargs='?',
2019-07-03 09:24:55 +00:00
const=True, default=False,
2019-07-03 12:24:54 +00:00
help="Use http only")
2019-07-03 19:00:03 +00:00
parser.add_argument("--dat", type=str2bool, nargs='?',
const=True, default=False,
help="Use dat protocol only")
2019-07-03 09:24:55 +00:00
parser.add_argument("--tor", type=str2bool, nargs='?',
const=True, default=False,
help="Route via Tor")
parser.add_argument("--tests", type=str2bool, nargs='?',
const=True, default=False,
help="Run unit tests")
2019-07-03 10:31:02 +00:00
parser.add_argument("--testsnetwork", type=str2bool, nargs='?',
const=True, default=False,
help="Run network unit tests")
2019-07-03 09:24:55 +00:00
args = parser.parse_args()
2019-07-03 10:31:02 +00:00
2019-07-03 16:14:45 +00:00
debug=False
if args.debug:
debug=True
2019-07-03 09:24:55 +00:00
if args.tests:
runAllTests()
sys.exit()
2019-07-03 10:31:02 +00:00
if args.testsnetwork:
print('Network Tests')
testPostMessageBetweenServers()
sys.exit()
2019-07-03 10:33:55 +00:00
if args.posts:
nickname=args.posts.split('@')[0]
domain=args.posts.split('@')[1]
2019-07-03 11:24:38 +00:00
getPublicPostsOfPerson(nickname,domain,False,True)
sys.exit()
if args.postsraw:
nickname=args.postsraw.split('@')[0]
domain=args.postsraw.split('@')[1]
getPublicPostsOfPerson(nickname,domain,True,False)
2019-07-03 10:33:55 +00:00
sys.exit()
2019-07-03 10:31:02 +00:00
if not args.domain:
print('Specify a domain with --domain [name]')
sys.exit()
2019-07-03 16:14:45 +00:00
2019-07-03 09:40:27 +00:00
nickname='admin'
2019-07-03 09:24:55 +00:00
domain=args.domain
port=args.port
2019-07-03 19:00:03 +00:00
httpPrefix='https'
2019-07-03 12:24:54 +00:00
if args.http:
2019-07-03 19:00:03 +00:00
httpPrefix='http'
if args.dat:
httpPrefix='dat'
2019-07-03 09:24:55 +00:00
useTor=args.tor
baseDir=args.baseDir
if baseDir.endswith('/'):
print("--path option should not end with '/'")
sys.exit()
federationList=[]
if args.federationList:
federationList=args.federationList.copy()
2019-07-03 16:16:36 +00:00
print('Federating with: '+str(federationList))
2019-06-28 18:55:29 +00:00
2019-07-03 12:24:54 +00:00
if not os.path.isdir(baseDir+'/accounts/'+nickname+'@'+domain):
2019-07-03 12:25:42 +00:00
print('Creating default admin account '+nickname+'@'+domain)
2019-07-03 19:00:03 +00:00
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(baseDir,nickname,domain,port,httpPrefix,True)
2019-07-03 12:24:54 +00:00
2019-07-04 14:36:29 +00:00
runDaemon(baseDir,domain,port,httpPrefix,federationList,useTor,debug)