epicyon.py 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. __filename__ = "epicyon.py"
  2. __author__ = "Bob Mottram"
  3. __license__ = "AGPL3+"
  4. __version__ = "1.0.0"
  5. __maintainer__ = "Bob Mottram"
  6. __email__ = "bob@freedombone.net"
  7. __status__ = "Production"
  8. from person import createPerson
  9. from person import createSharedInbox
  10. from person import createCapabilitiesInbox
  11. from person import setDisplayNickname
  12. from person import setBio
  13. from person import setProfileImage
  14. from person import removeAccount
  15. from skills import setSkillLevel
  16. from roles import setRole
  17. from person import setOrganizationScheme
  18. from webfinger import webfingerHandle
  19. from posts import getPosts
  20. from posts import createPublicPost
  21. from posts import deleteAllPosts
  22. from posts import createOutbox
  23. from posts import archivePosts
  24. from posts import sendPostViaServer
  25. from posts import getPublicPostsOfPerson
  26. from posts import getUserUrl
  27. from posts import archivePosts
  28. from session import createSession
  29. from session import getJson
  30. from blocking import addBlock
  31. from blocking import removeBlock
  32. from filters import addFilter
  33. from filters import removeFilter
  34. import json
  35. import os
  36. import shutil
  37. import sys
  38. import requests
  39. import time
  40. from pprint import pprint
  41. from tests import testHttpsig
  42. from daemon import runDaemon
  43. import socket
  44. from follow import clearFollows
  45. from follow import clearFollowers
  46. from follow import followerOfPerson
  47. from follow import unfollowPerson
  48. from follow import unfollowerOfPerson
  49. from follow import getFollowersOfPerson
  50. from tests import testPostMessageBetweenServers
  51. from tests import testFollowBetweenServers
  52. from tests import testClientToServer
  53. from tests import runAllTests
  54. from config import setConfigParam
  55. from config import getConfigParam
  56. from auth import storeBasicCredentials
  57. from auth import removePassword
  58. from auth import createPassword
  59. from utils import getDomainFromActor
  60. from utils import getNicknameFromActor
  61. from utils import followPerson
  62. from utils import validNickname
  63. from media import archiveMedia
  64. from media import getAttachmentMediaType
  65. from delete import sendDeleteViaServer
  66. from like import sendLikeViaServer
  67. from like import sendUndoLikeViaServer
  68. from blocking import sendBlockViaServer
  69. from blocking import sendUndoBlockViaServer
  70. from roles import sendRoleViaServer
  71. from skills import sendSkillViaServer
  72. from availability import setAvailability
  73. from availability import sendAvailabilityViaServer
  74. from manualapprove import manualDenyFollowRequest
  75. from manualapprove import manualApproveFollowRequest
  76. from shares import sendShareViaServer
  77. from shares import sendUndoShareViaServer
  78. from shares import addShare
  79. import argparse
  80. def str2bool(v):
  81. if isinstance(v, bool):
  82. return v
  83. if v.lower() in ('yes', 'true', 't', 'y', '1'):
  84. return True
  85. elif v.lower() in ('no', 'false', 'f', 'n', '0'):
  86. return False
  87. else:
  88. raise argparse.ArgumentTypeError('Boolean value expected.')
  89. parser = argparse.ArgumentParser(description='ActivityPub Server')
  90. parser.add_argument('-n','--nickname', dest='nickname', type=str,default=None, \
  91. help='Nickname of the account to use')
  92. parser.add_argument('--fol','--follow', dest='follow', type=str,default=None, \
  93. help='Handle of account to follow. eg. nickname@domain')
  94. parser.add_argument('--unfol','--unfollow', dest='unfollow', type=str,default=None, \
  95. help='Handle of account stop following. eg. nickname@domain')
  96. parser.add_argument('-d','--domain', dest='domain', type=str,default=None, \
  97. help='Domain name of the server')
  98. parser.add_argument('-p','--port', dest='port', type=int,default=None, \
  99. help='Port number to run on')
  100. parser.add_argument('--proxy', dest='proxyPort', type=int,default=None, \
  101. help='Proxy port number to run on')
  102. parser.add_argument('--path', dest='baseDir', \
  103. type=str,default=os.getcwd(), \
  104. help='Directory in which to store posts')
  105. parser.add_argument('-a','--addaccount', dest='addaccount', \
  106. type=str,default=None, \
  107. help='Adds a new account')
  108. parser.add_argument('-r','--rmaccount', dest='rmaccount', \
  109. type=str,default=None, \
  110. help='Remove an account')
  111. parser.add_argument('--pass','--password', dest='password', \
  112. type=str,default=None, \
  113. help='Set a password for an account')
  114. parser.add_argument('--chpass','--changepassword', \
  115. nargs='+',dest='changepassword', \
  116. help='Change the password for an account')
  117. parser.add_argument('--actor', dest='actor', type=str,default=None, \
  118. help='Show the json actor the given handle')
  119. parser.add_argument('--posts', dest='posts', type=str,default=None, \
  120. help='Show posts for the given handle')
  121. parser.add_argument('--postsraw', dest='postsraw', type=str,default=None, \
  122. help='Show raw json of posts for the given handle')
  123. parser.add_argument('--json', dest='json', type=str,default=None, \
  124. help='Show the json for a given activitypub url')
  125. parser.add_argument('-f','--federate', nargs='+',dest='federationList', \
  126. help='Specify federation list separated by spaces')
  127. parser.add_argument("--debug", type=str2bool, nargs='?', \
  128. const=True, default=False, \
  129. help="Show debug messages")
  130. parser.add_argument("--instanceOnlySkillsSearch", type=str2bool, nargs='?', \
  131. const=True, default=False, \
  132. help="Skills searches only return results from this instance")
  133. parser.add_argument("--http", type=str2bool, nargs='?', \
  134. const=True, default=False, \
  135. help="Use http only")
  136. parser.add_argument("--dat", type=str2bool, nargs='?', \
  137. const=True, default=False, \
  138. help="Use dat protocol only")
  139. parser.add_argument("--tor", type=str2bool, nargs='?', \
  140. const=True, default=False, \
  141. help="Route via Tor")
  142. parser.add_argument("--tests", type=str2bool, nargs='?', \
  143. const=True, default=False, \
  144. help="Run unit tests")
  145. parser.add_argument("--testsnetwork", type=str2bool, nargs='?', \
  146. const=True, default=False, \
  147. help="Run network unit tests")
  148. parser.add_argument("--testdata", type=str2bool, nargs='?', \
  149. const=True, default=False, \
  150. help="Generate some data for testing purposes")
  151. parser.add_argument("--ocap", type=str2bool, nargs='?', \
  152. const=True, default=False, \
  153. help="Always strictly enforce object capabilities")
  154. parser.add_argument("--noreply", type=str2bool, nargs='?', \
  155. const=True, default=False, \
  156. help="Default capabilities don't allow replies on posts")
  157. parser.add_argument("--nolike", type=str2bool, nargs='?', \
  158. const=True, default=False, \
  159. help="Default capabilities don't allow likes/favourites on posts")
  160. parser.add_argument("--nopics", type=str2bool, nargs='?', \
  161. const=True, default=False, \
  162. help="Default capabilities don't allow attached pictures")
  163. parser.add_argument("--noannounce","--norepeat", type=str2bool, nargs='?', \
  164. const=True, default=False, \
  165. help="Default capabilities don't allow announce/repeat")
  166. parser.add_argument("--cw", type=str2bool, nargs='?', \
  167. const=True, default=False, \
  168. help="Default capabilities don't allow posts without content warnings")
  169. parser.add_argument('--icon','--avatar', dest='avatar', type=str,default=None, \
  170. help='Set the avatar filename for an account')
  171. parser.add_argument('--image','--background', dest='backgroundImage', type=str,default=None, \
  172. help='Set the profile background image for an account')
  173. parser.add_argument('--archive', dest='archive', type=str,default=None, \
  174. help='Archive old files to the given directory')
  175. parser.add_argument('--archiveweeks', dest='archiveWeeks', type=str,default=None, \
  176. help='Specify the number of weeks after which data will be archived')
  177. parser.add_argument('--maxposts', dest='archiveMaxPosts', type=str,default=None, \
  178. help='Maximum number of posts in in/outbox')
  179. parser.add_argument('--message', dest='message', type=str,default=None, \
  180. help='Message content')
  181. parser.add_argument('--delete', dest='delete', type=str,default=None, \
  182. help='Delete a specified post')
  183. parser.add_argument("--allowdeletion", type=str2bool, nargs='?', \
  184. const=True, default=False, \
  185. help="Do not allow deletions")
  186. parser.add_argument('--repeat','--announce', dest='announce', type=str,default=None, \
  187. help='Announce/repeat a url')
  188. parser.add_argument('--favorite','--like', dest='like', type=str,default=None, \
  189. help='Like a url')
  190. parser.add_argument('--undolike','--unlike', dest='undolike', type=str,default=None, \
  191. help='Undo a like of a url')
  192. parser.add_argument('--sendto', dest='sendto', type=str,default=None, \
  193. help='Address to send a post to')
  194. parser.add_argument('--attach', dest='attach', type=str,default=None, \
  195. help='File to attach to a post')
  196. parser.add_argument('--imagedescription', dest='imageDescription', type=str,default=None, \
  197. help='Description of an attached image')
  198. parser.add_argument("--blurhash", type=str2bool, nargs='?', \
  199. const=True, default=False, \
  200. help="Create blurhash for an image")
  201. parser.add_argument('--warning','--warn','--cwsubject','--subject', dest='subject', type=str,default=None, \
  202. help='Subject of content warning')
  203. parser.add_argument('--reply','--replyto', dest='replyto', type=str,default=None, \
  204. help='Url of post to reply to')
  205. parser.add_argument("--followersonly", type=str2bool, nargs='?', \
  206. const=True, default=True, \
  207. help="Send to followers only")
  208. parser.add_argument("--followerspending", type=str2bool, nargs='?', \
  209. const=True, default=False, \
  210. help="Show a list of followers pending")
  211. parser.add_argument('--approve', dest='approve', type=str,default=None, \
  212. help='Approve a follow request')
  213. parser.add_argument('--deny', dest='deny', type=str,default=None, \
  214. help='Deny a follow request')
  215. parser.add_argument("-c","--client", type=str2bool, nargs='?', \
  216. const=True, default=False, \
  217. help="Use as an ActivityPub client")
  218. parser.add_argument('--maxreplies', dest='maxReplies', type=int,default=64, \
  219. help='Maximum number of replies to a post')
  220. parser.add_argument('--role', dest='role', type=str,default=None, \
  221. help='Set a role for a person')
  222. parser.add_argument('--organization','--project', dest='project', type=str,default=None, \
  223. help='Set a project for a person')
  224. parser.add_argument('--skill', dest='skill', type=str,default=None, \
  225. help='Set a skill for a person')
  226. parser.add_argument('--level', dest='skillLevelPercent', type=int,default=None, \
  227. help='Set a skill level for a person as a percentage, or zero to remove')
  228. parser.add_argument('--status','--availability', dest='availability', type=str,default=None, \
  229. help='Set an availability status')
  230. parser.add_argument('--block', dest='block', type=str,default=None, \
  231. help='Block a particular address')
  232. parser.add_argument('--unblock', dest='unblock', type=str,default=None, \
  233. help='Remove a block on a particular address')
  234. parser.add_argument('--delegate', dest='delegate', type=str,default=None, \
  235. help='Address of an account to delegate a role to')
  236. parser.add_argument('--undodelegate','--undelegate', dest='undelegate', type=str,default=None, \
  237. help='Removes a delegated role for the given address')
  238. parser.add_argument('--filter', dest='filterStr', type=str,default=None, \
  239. help='Adds a word or phrase which if present will cause a message to be ignored')
  240. parser.add_argument('--unfilter', dest='unfilterStr', type=str,default=None, \
  241. help='Remove a filter on a particular word or phrase')
  242. parser.add_argument('--domainmax', dest='domainMaxPostsPerDay', type=int,default=8640, \
  243. help='Maximum number of received posts from a domain per day')
  244. parser.add_argument('--accountmax', dest='accountMaxPostsPerDay', type=int,default=8640, \
  245. help='Maximum number of received posts from an account per day')
  246. parser.add_argument('--itemName', dest='itemName', type=str,default=None, \
  247. help='Name of an item being shared')
  248. parser.add_argument('--undoItemName', dest='undoItemName', type=str,default=None, \
  249. help='Name of an shared item to remove')
  250. parser.add_argument('--summary', dest='summary', type=str,default=None, \
  251. help='Description of an item being shared')
  252. parser.add_argument('--itemImage', dest='itemImage', type=str,default=None, \
  253. help='Filename of an image for an item being shared')
  254. parser.add_argument('--itemType', dest='itemType', type=str,default=None, \
  255. help='Type of item being shared')
  256. parser.add_argument('--itemCategory', dest='itemCategory', type=str,default=None, \
  257. help='Category of item being shared')
  258. parser.add_argument('--location', dest='location', type=str,default=None, \
  259. help='Location/City of item being shared')
  260. parser.add_argument('--duration', dest='duration', type=str,default=None, \
  261. help='Duration for which to share an item')
  262. parser.add_argument('--registration', dest='registration', type=str,default=None, \
  263. help='Whether new registrations are open or closed')
  264. parser.add_argument('--maxregistrations', dest='maxRegistrations', type=int,default=None, \
  265. help='The maximum number of new registrations')
  266. parser.add_argument("--resetregistrations", type=str2bool, nargs='?', \
  267. const=True, default=False, \
  268. help="Reset the number of remaining registrations")
  269. args = parser.parse_args()
  270. debug=False
  271. if args.debug:
  272. debug=True
  273. if args.tests:
  274. runAllTests()
  275. sys.exit()
  276. if args.testsnetwork:
  277. print('Network Tests')
  278. testPostMessageBetweenServers()
  279. testFollowBetweenServers()
  280. testClientToServer()
  281. print('All tests succeeded')
  282. sys.exit()
  283. httpPrefix='https'
  284. if args.http:
  285. httpPrefix='http'
  286. baseDir=args.baseDir
  287. if baseDir.endswith('/'):
  288. print("--path option should not end with '/'")
  289. sys.exit()
  290. if args.posts:
  291. if '@' not in args.posts:
  292. print('Syntax: --posts nickname@domain')
  293. sys.exit()
  294. if not args.http:
  295. args.port=443
  296. nickname=args.posts.split('@')[0]
  297. domain=args.posts.split('@')[1]
  298. getPublicPostsOfPerson(baseDir,nickname,domain,False,True, \
  299. args.tor,args.port,httpPrefix,debug, \
  300. __version__)
  301. sys.exit()
  302. if args.postsraw:
  303. if '@' not in args.postsraw:
  304. print('Syntax: --postsraw nickname@domain')
  305. sys.exit()
  306. if not args.http:
  307. args.port=443
  308. nickname=args.postsraw.split('@')[0]
  309. domain=args.postsraw.split('@')[1]
  310. getPublicPostsOfPerson(baseDir,nickname,domain,False,False, \
  311. args.tor,args.port,httpPrefix,debug, \
  312. __version__)
  313. sys.exit()
  314. # create cache for actors
  315. if not os.path.isdir(baseDir+'/cache'):
  316. os.mkdir(baseDir+'/cache')
  317. if not os.path.isdir(baseDir+'/cache/actors'):
  318. print('Creating actors cache')
  319. os.mkdir(baseDir+'/cache/actors')
  320. if not os.path.isdir(baseDir+'/cache/announce'):
  321. print('Creating announce cache')
  322. os.mkdir(baseDir+'/cache/announce')
  323. if args.domain:
  324. domain=args.domain
  325. setConfigParam(baseDir,'domain',domain)
  326. # maximum number of new registrations
  327. if not args.maxRegistrations:
  328. maxRegistrations=getConfigParam(baseDir,'maxRegistrations')
  329. if not maxRegistrations:
  330. maxRegistrations=10
  331. setConfigParam(baseDir,'maxRegistrations',str(maxRegistrations))
  332. else:
  333. maxRegistrations=int(maxRegistrations)
  334. else:
  335. maxRegistrations=args.maxRegistrations
  336. setConfigParam(baseDir,'maxRegistrations',str(maxRegistrations))
  337. # if this is the initial run then allow new registrations
  338. if not getConfigParam(baseDir,'registration'):
  339. setConfigParam(baseDir,'registration','open')
  340. setConfigParam(baseDir,'maxRegistrations',str(maxRegistrations))
  341. setConfigParam(baseDir,'registrationsRemaining',str(maxRegistrations))
  342. if args.resetregistrations:
  343. setConfigParam(baseDir,'registrationsRemaining',str(maxRegistrations))
  344. print('Number of new registrations reset to '+str(maxRegistrations))
  345. # whether new registrations are open or closed
  346. if args.registration:
  347. if args.registration.lower()=='open':
  348. registration=getConfigParam(baseDir,'registration')
  349. if not registration:
  350. setConfigParam(baseDir,'registrationsRemaining',str(maxRegistrations))
  351. else:
  352. if registration!='open':
  353. setConfigParam(baseDir,'registrationsRemaining',str(maxRegistrations))
  354. setConfigParam(baseDir,'registration','open')
  355. print('New registrations open')
  356. else:
  357. setConfigParam(baseDir,'registration','closed')
  358. print('New registrations closed')
  359. # unique ID for the instance
  360. instanceId=getConfigParam(baseDir,'instanceId')
  361. if not instanceId:
  362. instanceId=createPassword(32)
  363. setConfigParam(baseDir,'instanceId',instanceId)
  364. print('Instance ID: '+instanceId)
  365. # get domain name from configuration
  366. configDomain=getConfigParam(baseDir,'domain')
  367. if configDomain:
  368. domain=configDomain
  369. else:
  370. domain='localhost'
  371. # get port number from configuration
  372. configPort=getConfigParam(baseDir,'port')
  373. if configPort:
  374. port=configPort
  375. else:
  376. port=8085
  377. configProxyPort=getConfigParam(baseDir,'proxyPort')
  378. if configProxyPort:
  379. proxyPort=configProxyPort
  380. else:
  381. proxyPort=port
  382. nickname=None
  383. if args.nickname:
  384. nickname=nickname
  385. federationList=[]
  386. if args.federationList:
  387. if len(args.federationList)==1:
  388. if not (args.federationList[0].lower()=='any' or \
  389. args.federationList[0].lower()=='all' or \
  390. args.federationList[0].lower()=='*'):
  391. for federationDomain in args.federationList:
  392. if '@' in federationDomain:
  393. print(federationDomain+': Federate with domains, not individual accounts')
  394. sys.exit()
  395. federationList=args.federationList.copy()
  396. setConfigParam(baseDir,'federationList',federationList)
  397. else:
  398. configFederationList=getConfigParam(baseDir,'federationList')
  399. if configFederationList:
  400. federationList=configFederationList
  401. useTor=args.tor
  402. if domain.endswith('.onion'):
  403. useTor=True
  404. if args.approve:
  405. if not args.nickname:
  406. print('Specify a nickname with the --nickname option')
  407. sys.exit()
  408. if '@' not in args.approve:
  409. print('syntax: --approve nick@domain')
  410. sys.exit()
  411. session = createSession(domain,port,useTor)
  412. sendThreads=[]
  413. postLog=[]
  414. cachedWebfingers={}
  415. personCache={}
  416. acceptedCaps=[]
  417. manualApproveFollowRequest(session,baseDir, \
  418. httpPrefix,
  419. args.nickname,domain,port, \
  420. args.approve, \
  421. federationList, \
  422. sendThreads,postLog, \
  423. cachedWebfingers,personCache, \
  424. acceptedCaps, \
  425. debug,__version__)
  426. sys.exit()
  427. if args.deny:
  428. if not args.nickname:
  429. print('Specify a nickname with the --nickname option')
  430. sys.exit()
  431. if '@' not in args.deny:
  432. print('syntax: --deny nick@domain')
  433. sys.exit()
  434. session = createSession(domain,port,useTor)
  435. sendThreads=[]
  436. postLog=[]
  437. cachedWebfingers={}
  438. personCache={}
  439. manualDenyFollowRequest(session,baseDir, \
  440. httpPrefix,
  441. args.nickname,domain,port, \
  442. args.deny, \
  443. federationList, \
  444. sendThreads,postLog, \
  445. cachedWebfingers,personCache, \
  446. debug,__version__)
  447. sys.exit()
  448. if args.followerspending:
  449. if not args.nickname:
  450. print('Specify a nickname with the --nickname option')
  451. sys.exit()
  452. accountsDir=baseDir+'/accounts/'+args.nickname+'@'+domain
  453. approveFollowsFilename=accountsDir+'/followrequests.txt'
  454. approveCtr=0
  455. if os.path.isfile(approveFollowsFilename):
  456. with open(approveFollowsFilename, 'r') as approvefile:
  457. for approve in approvefile:
  458. print(approve.replace('\n',''))
  459. approveCtr+=1
  460. if approveCtr==0:
  461. print('There are no follow requests pending approval.')
  462. sys.exit()
  463. if args.message:
  464. if not args.nickname:
  465. print('Specify a nickname with the --nickname option')
  466. sys.exit()
  467. if not args.password:
  468. print('Specify a password with the --password option')
  469. sys.exit()
  470. session = createSession(domain,port,useTor)
  471. if not args.sendto:
  472. print('Specify an account to sent to: --sendto [nickname@domain]')
  473. sys.exit()
  474. if '@' not in args.sendto and \
  475. not args.sendto.lower().endswith('public') and \
  476. not args.sendto.lower().endswith('followers'):
  477. print('syntax: --sendto [nickname@domain]')
  478. print(' --sendto public')
  479. print(' --sendto followers')
  480. sys.exit()
  481. if '@' in args.sendto:
  482. toNickname=args.sendto.split('@')[0]
  483. toDomain=args.sendto.split('@')[1].replace('\n','')
  484. toPort=443
  485. if ':' in toDomain:
  486. toPort=toDomain.split(':')[1]
  487. toDomain=toDomain.split(':')[0]
  488. else:
  489. if args.sendto.endswith('followers'):
  490. toNickname=None
  491. toDomain='followers'
  492. toPort=port
  493. else:
  494. toNickname=None
  495. toDomain='public'
  496. toPort=port
  497. #ccUrl=httpPrefix+'://'+domain+'/users/'+nickname+'/followers'
  498. ccUrl=None
  499. sendMessage=args.message
  500. followersOnly=args.followersonly
  501. clientToServer=args.client
  502. attachedImageDescription=args.imageDescription
  503. useBlurhash=args.blurhash
  504. sendThreads = []
  505. postLog = []
  506. personCache={}
  507. cachedWebfingers={}
  508. subject=args.subject
  509. attach=args.attach
  510. mediaType=None
  511. if attach:
  512. mediaType=getAttachmentMediaType(attach)
  513. replyTo=args.replyto
  514. followersOnly=False
  515. print('Sending post to '+args.sendto)
  516. sendPostViaServer(__version__, \
  517. baseDir,session,args.nickname,args.password, \
  518. domain,port, \
  519. toNickname,toDomain,toPort,ccUrl, \
  520. httpPrefix,sendMessage,followersOnly, \
  521. attach,mediaType, \
  522. attachedImageDescription,useBlurhash, \
  523. cachedWebfingers,personCache, \
  524. args.debug,replyTo,replyTo,subject)
  525. for i in range(10):
  526. # TODO detect send success/fail
  527. time.sleep(1)
  528. sys.exit()
  529. if args.announce:
  530. if not args.nickname:
  531. print('Specify a nickname with the --nickname option')
  532. sys.exit()
  533. if not args.password:
  534. print('Specify a password with the --password option')
  535. sys.exit()
  536. session = createSession(domain,port,useTor)
  537. personCache={}
  538. cachedWebfingers={}
  539. print('Sending announce/repeat of '+args.announce)
  540. sendAnnounceViaServer(baseDir,session,args.nickname,args.password,
  541. domain,port, \
  542. httpPrefix,args.announce, \
  543. cachedWebfingers,personCache, \
  544. True,__version__)
  545. for i in range(10):
  546. # TODO detect send success/fail
  547. time.sleep(1)
  548. sys.exit()
  549. if args.itemName:
  550. if not args.password:
  551. print('Specify a password with the --password option')
  552. sys.exit()
  553. if not args.nickname:
  554. print('Specify a nickname with the --nickname option')
  555. sys.exit()
  556. if not args.summary:
  557. print('Specify a description for your shared item with the --summary option')
  558. sys.exit()
  559. if not args.itemType:
  560. print('Specify a type of shared item with the --itemType option')
  561. sys.exit()
  562. if not args.itemCategory:
  563. print('Specify a category of shared item with the --itemCategory option')
  564. sys.exit()
  565. if not args.location:
  566. print('Specify a location or city where theshared item resides with the --location option')
  567. sys.exit()
  568. if not args.duration:
  569. print('Specify a duration to share the object with the --duration option')
  570. sys.exit()
  571. session = createSession(domain,port,useTor)
  572. personCache={}
  573. cachedWebfingers={}
  574. print('Sending shared item: '+args.itemName)
  575. sendShareViaServer(baseDir,session, \
  576. args.nickname,args.password, \
  577. domain,port, \
  578. httpPrefix, \
  579. args.itemName, \
  580. args.summary, \
  581. args.itemImage, \
  582. args.itemType, \
  583. args.itemCategory, \
  584. args.location, \
  585. args.duration, \
  586. cachedWebfingers,personCache, \
  587. debug,__version__)
  588. for i in range(10):
  589. # TODO detect send success/fail
  590. time.sleep(1)
  591. sys.exit()
  592. if args.undoItemName:
  593. if not args.password:
  594. print('Specify a password with the --password option')
  595. sys.exit()
  596. if not args.nickname:
  597. print('Specify a nickname with the --nickname option')
  598. sys.exit()
  599. session = createSession(domain,port,useTor)
  600. personCache={}
  601. cachedWebfingers={}
  602. print('Sending undo of shared item: '+args.undoItemName)
  603. sendUndoShareViaServer(session, \
  604. args.nickname,args.password, \
  605. domain,port, \
  606. httpPrefix, \
  607. args.undoItemName, \
  608. cachedWebfingers,personCache, \
  609. debug,__version__)
  610. for i in range(10):
  611. # TODO detect send success/fail
  612. time.sleep(1)
  613. sys.exit()
  614. if args.like:
  615. if not args.nickname:
  616. print('Specify a nickname with the --nickname option')
  617. sys.exit()
  618. if not args.password:
  619. print('Specify a password with the --password option')
  620. sys.exit()
  621. session = createSession(domain,port,useTor)
  622. personCache={}
  623. cachedWebfingers={}
  624. print('Sending like of '+args.like)
  625. sendLikeViaServer(baseDir,session, \
  626. args.nickname,args.password, \
  627. domain,port, \
  628. httpPrefix,args.like, \
  629. cachedWebfingers,personCache, \
  630. True,__version__)
  631. for i in range(10):
  632. # TODO detect send success/fail
  633. time.sleep(1)
  634. sys.exit()
  635. if args.undolike:
  636. if not args.nickname:
  637. print('Specify a nickname with the --nickname option')
  638. sys.exit()
  639. if not args.password:
  640. print('Specify a password with the --password option')
  641. sys.exit()
  642. session = createSession(domain,port,useTor)
  643. personCache={}
  644. cachedWebfingers={}
  645. print('Sending undo like of '+args.undolike)
  646. sendUndoLikeViaServer(baseDir,session, \
  647. args.nickname,args.password, \
  648. domain,port, \
  649. httpPrefix,args.undolike, \
  650. cachedWebfingers,personCache, \
  651. True,__version__)
  652. for i in range(10):
  653. # TODO detect send success/fail
  654. time.sleep(1)
  655. sys.exit()
  656. if args.delete:
  657. if not args.nickname:
  658. print('Specify a nickname with the --nickname option')
  659. sys.exit()
  660. if not args.password:
  661. print('Specify a password with the --password option')
  662. sys.exit()
  663. session = createSession(domain,port,useTor)
  664. personCache={}
  665. cachedWebfingers={}
  666. print('Sending delete request of '+args.delete)
  667. sendDeleteViaServer(baseDir,session, \
  668. args.nickname,args.password, \
  669. domain,port, \
  670. httpPrefix,args.delete, \
  671. cachedWebfingers,personCache, \
  672. True,__version__)
  673. for i in range(10):
  674. # TODO detect send success/fail
  675. time.sleep(1)
  676. sys.exit()
  677. if args.follow:
  678. # follow via c2s protocol
  679. if '.' not in args.follow:
  680. print("This doesn't look like a fediverse handle")
  681. sys.exit()
  682. if not args.nickname:
  683. print('Please specify the nickname for the account with --nickname')
  684. sys.exit()
  685. if not args.password:
  686. print('Please specify the password for '+args.nickname+' on '+domain)
  687. sys.exit()
  688. followNickname=getNicknameFromActor(args.follow)
  689. if not followNickname:
  690. print('Unable to find nickname in '+args.follow)
  691. sys.exit()
  692. followDomain,followPort=getDomainFromActor(args.follow)
  693. session = createSession(domain,port,useTor)
  694. personCache={}
  695. cachedWebfingers={}
  696. followHttpPrefix=httpPrefix
  697. if args.follow.startswith('https'):
  698. followHttpPrefix='https'
  699. sendFollowRequestViaServer(baseDir,session, \
  700. args.nickname,args.password, \
  701. domain,port, \
  702. followNickname,followDomain,followPort, \
  703. httpPrefix, \
  704. cachedWebfingers,personCache, \
  705. debug,__version__)
  706. for t in range(20):
  707. time.sleep(1)
  708. # TODO some method to know if it worked
  709. print('Ok')
  710. sys.exit()
  711. if args.unfollow:
  712. # unfollow via c2s protocol
  713. if '.' not in args.follow:
  714. print("This doesn't look like a fediverse handle")
  715. sys.exit()
  716. if not args.nickname:
  717. print('Please specify the nickname for the account with --nickname')
  718. sys.exit()
  719. if not args.password:
  720. print('Please specify the password for '+args.nickname+' on '+domain)
  721. sys.exit()
  722. followNickname=getNicknameFromActor(args.unfollow)
  723. if not followNickname:
  724. print('WARN: unable to find nickname in '+args.unfollow)
  725. sys.exit()
  726. followDomain,followPort=getDomainFromActor(args.unfollow)
  727. session = createSession(domain,port,useTor)
  728. personCache={}
  729. cachedWebfingers={}
  730. followHttpPrefix=httpPrefix
  731. if args.follow.startswith('https'):
  732. followHttpPrefix='https'
  733. sendUnfollowRequestViaServer(baseDir,session, \
  734. args.nickname,args.password, \
  735. domain,port, \
  736. followNickname,followDomain,followPort, \
  737. httpPrefix, \
  738. cachedWebfingers,personCache, \
  739. debug,__version__)
  740. for t in range(20):
  741. time.sleep(1)
  742. # TODO some method to know if it worked
  743. print('Ok')
  744. sys.exit()
  745. nickname='admin'
  746. if args.domain:
  747. domain=args.domain
  748. setConfigParam(baseDir,'domain',domain)
  749. if args.port:
  750. port=args.port
  751. setConfigParam(baseDir,'port',port)
  752. if args.proxyPort:
  753. proxyPort=args.proxyPort
  754. setConfigParam(baseDir,'proxyPort',proxyPort)
  755. ocapAlways=False
  756. if args.ocap:
  757. ocapAlways=args.ocap
  758. if args.dat:
  759. httpPrefix='dat'
  760. if args.actor:
  761. if '/@' in args.actor or '/users/' in args.actor or args.actor.startswith('http') or args.actor.startswith('dat'):
  762. # format: https://domain/@nick
  763. args.actor=args.actor.replace('https://','').replace('http://','').replace('dat://','').replace('/@','/users/')
  764. if '/users/' not in args.actor and '/profile/' not in args.actor:
  765. print('Expected actor format: https://domain/@nick or https://domain/users/nick')
  766. sys.exit()
  767. if '/users/' in args.actor:
  768. nickname=args.actor.split('/users/')[1].replace('\n','')
  769. domain=args.actor.split('/users/')[0]
  770. else:
  771. nickname=args.actor.split('/profile/')[1].replace('\n','')
  772. domain=args.actor.split('/profile/')[0]
  773. else:
  774. # format: @nick@domain
  775. if '@' not in args.actor:
  776. print('Syntax: --actor nickname@domain')
  777. sys.exit()
  778. if args.actor.startswith('@'):
  779. args.actor=args.actor[1:]
  780. if '@' not in args.actor:
  781. print('Syntax: --actor nickname@domain')
  782. sys.exit()
  783. nickname=args.actor.split('@')[0]
  784. domain=args.actor.split('@')[1].replace('\n','')
  785. wfCache={}
  786. if args.http or domain.endswith('.onion'):
  787. httpPrefix='http'
  788. port=80
  789. else:
  790. httpPrefix='https'
  791. port=443
  792. session=createSession(domain,port,useTor)
  793. if nickname=='inbox':
  794. nickname=domain
  795. wfRequest=webfingerHandle(session,nickname+'@'+domain,httpPrefix,wfCache, \
  796. None,__version__)
  797. if not wfRequest:
  798. print('Unable to webfinger '+nickname+'@'+domain)
  799. sys.exit()
  800. asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'}
  801. personUrl = getUserUrl(wfRequest)
  802. if nickname==domain:
  803. personUrl=personUrl.replace('/users/','/actor/')
  804. #print('personUrl: '+personUrl)
  805. personJson = getJson(session,personUrl,asHeader,None,__version__,httpPrefix,None)
  806. if personJson:
  807. pprint(personJson)
  808. else:
  809. print('Failed to get '+personUrl)
  810. sys.exit()
  811. if args.json:
  812. session = createSession(domain,port,True)
  813. asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
  814. testJson = getJson(session,args.json,asHeader,None,__version__,httpPrefix,None)
  815. pprint(testJson)
  816. sys.exit()
  817. if args.addaccount:
  818. if '@' in args.addaccount:
  819. nickname=args.addaccount.split('@')[0]
  820. domain=args.addaccount.split('@')[1]
  821. else:
  822. nickname=args.addaccount
  823. if not args.domain or not getConfigParam(baseDir,'domain'):
  824. print('Use the --domain option to set the domain name')
  825. sys.exit()
  826. if not validNickname(domain,nickname):
  827. print(nickname+' is a reserved name. Use something different.')
  828. sys.exit()
  829. if not args.password:
  830. print('Use the --password option to set the password for '+nickname)
  831. sys.exit()
  832. if len(args.password.strip())<8:
  833. print('Password should be at least 8 characters')
  834. sys.exit()
  835. if os.path.isdir(baseDir+'/accounts/'+nickname+'@'+domain):
  836. print('Account already exists')
  837. sys.exit()
  838. createPerson(baseDir,nickname,domain,port,httpPrefix,True,args.password.strip())
  839. if os.path.isdir(baseDir+'/accounts/'+nickname+'@'+domain):
  840. print('Account created for '+nickname+'@'+domain)
  841. else:
  842. print('Account creation failed')
  843. sys.exit()
  844. if args.rmaccount:
  845. if '@' in args.rmaccount:
  846. nickname=args.rmaccount.split('@')[0]
  847. domain=args.rmaccount.split('@')[1]
  848. else:
  849. nickname=args.rmaccount
  850. if not args.domain or not getConfigParam(baseDir,'domain'):
  851. print('Use the --domain option to set the domain name')
  852. sys.exit()
  853. if removeAccount(baseDir,nickname,domain,port):
  854. print('Account for '+handle+' was removed')
  855. sys.exit()
  856. if args.changepassword:
  857. if len(args.changepassword)!=2:
  858. print('--changepassword [nickname] [new password]')
  859. sys.exit()
  860. if '@' in args.changepassword[0]:
  861. nickname=args.changepassword[0].split('@')[0]
  862. domain=args.changepassword[0].split('@')[1]
  863. else:
  864. nickname=args.changepassword[0]
  865. if not args.domain or not getConfigParam(baseDir,'domain'):
  866. print('Use the --domain option to set the domain name')
  867. sys.exit()
  868. newPassword=args.changepassword[1]
  869. if len(newPassword)<8:
  870. print('Password should be at least 8 characters')
  871. sys.exit()
  872. if not os.path.isdir(baseDir+'/accounts/'+nickname+'@'+domain):
  873. print('Account '+nickname+'@'+domain+' not found')
  874. sys.exit()
  875. passwordFile=baseDir+'/accounts/passwords'
  876. if os.path.isfile(passwordFile):
  877. if nickname+':' in open(passwordFile).read():
  878. storeBasicCredentials(baseDir,nickname,newPassword)
  879. print('Password for '+nickname+' was changed')
  880. else:
  881. print(nickname+' is not in the passwords file')
  882. else:
  883. print('Passwords file not found')
  884. sys.exit()
  885. archiveWeeks=4
  886. if args.archiveWeeks:
  887. archiveWeeks=args.archiveWeeks
  888. archiveMaxPosts=256
  889. if args.archiveMaxPosts:
  890. archiveMaxPosts=args.archiveMaxPosts
  891. if args.archive:
  892. if args.archive.lower().endswith('null') or \
  893. args.archive.lower().endswith('delete') or \
  894. args.archive.lower().endswith('none'):
  895. args.archive=None
  896. print('Archiving with deletion of old posts...')
  897. else:
  898. print('Archiving to '+args.archive+'...')
  899. archiveMedia(baseDir,args.archive,archiveWeeks)
  900. archivePosts(baseDir,httpPrefix,args.archive,archiveMaxPosts)
  901. print('Archiving complete')
  902. sys.exit()
  903. if not args.domain and not domain:
  904. print('Specify a domain with --domain [name]')
  905. sys.exit()
  906. if args.avatar:
  907. if not os.path.isfile(args.avatar):
  908. print(args.avatar+' is not an image filename')
  909. sys.exit()
  910. if not args.nickname:
  911. print('Specify a nickname with --nickname [name]')
  912. sys.exit()
  913. if setProfileImage(baseDir,httpPrefix,args.nickname,domain, \
  914. port,args.avatar,'avatar','128x128'):
  915. print('Avatar added for '+args.nickname)
  916. else:
  917. print('Avatar was not added for '+args.nickname)
  918. sys.exit()
  919. if args.backgroundImage:
  920. if not os.path.isfile(args.backgroundImage):
  921. print(args.backgroundImage+' is not an image filename')
  922. sys.exit()
  923. if not args.nickname:
  924. print('Specify a nickname with --nickname [name]')
  925. sys.exit()
  926. if setProfileImage(baseDir,httpPrefix,args.nickname,domain, \
  927. port,args.backgroundImage,'background','256x256'):
  928. print('Background image added for '+args.nickname)
  929. else:
  930. print('Background image was not added for '+args.nickname)
  931. sys.exit()
  932. if args.project:
  933. if not args.delegate and not args.undelegate:
  934. if not nickname:
  935. print('No nickname given')
  936. sys.exit()
  937. if args.role.lower()=='none' or \
  938. args.role.lower()=='remove' or \
  939. args.role.lower()=='delete':
  940. args.role=None
  941. if args.role:
  942. if setRole(baseDir,nickname,domain,args.project,args.role):
  943. print('Role within '+args.project+' set to '+args.role)
  944. else:
  945. if setRole(baseDir,nickname,domain,args.project,None):
  946. print('Left '+args.project)
  947. sys.exit()
  948. if args.skill:
  949. if not nickname:
  950. print('Specify a nickname with the --nickname option')
  951. sys.exit()
  952. if not args.password:
  953. print('Specify a password with the --password option')
  954. sys.exit()
  955. if not args.skillLevelPercent:
  956. print('Specify a skill level in the range 0-100')
  957. sys.exit()
  958. if int(args.skillLevelPercent)<0 or int(args.skillLevelPercent)>100:
  959. print('Skill level should be a percentage in the range 0-100')
  960. sys.exit()
  961. session = createSession(domain,port,useTor)
  962. personCache={}
  963. cachedWebfingers={}
  964. print('Sending '+args.skill+' skill level '+str(args.skillLevelPercent)+' for '+nickname)
  965. sendSkillViaServer(baseDir,session, \
  966. nickname,args.password, \
  967. domain,port, \
  968. httpPrefix, \
  969. args.skill,args.skillLevelPercent, \
  970. cachedWebfingers,personCache, \
  971. True,__version__)
  972. for i in range(10):
  973. # TODO detect send success/fail
  974. time.sleep(1)
  975. sys.exit()
  976. if args.availability:
  977. if not nickname:
  978. print('Specify a nickname with the --nickname option')
  979. sys.exit()
  980. if not args.password:
  981. print('Specify a password with the --password option')
  982. sys.exit()
  983. session = createSession(domain,port,useTor)
  984. personCache={}
  985. cachedWebfingers={}
  986. print('Sending availability status of '+nickname+' as '+args.availability)
  987. sendAvailabilityViaServer(baseDir,session,nickname,args.password,
  988. domain,port, \
  989. httpPrefix, \
  990. args.availability, \
  991. cachedWebfingers,personCache, \
  992. True,__version__)
  993. for i in range(10):
  994. # TODO detect send success/fail
  995. time.sleep(1)
  996. sys.exit()
  997. if federationList:
  998. print('Federating with: '+str(federationList))
  999. #if not os.path.isdir(baseDir+'/accounts/'+nickname+'@'+domain):
  1000. # print('Creating default admin account '+nickname+'@'+domain)
  1001. # print('See config.json for the password. You can remove the password from config.json after moving it elsewhere.')
  1002. # adminPassword=createPassword(10)
  1003. # setConfigParam(baseDir,'adminPassword',adminPassword)
  1004. # createPerson(baseDir,nickname,domain,port,httpPrefix,True,adminPassword)
  1005. if args.block:
  1006. if not nickname:
  1007. print('Specify a nickname with the --nickname option')
  1008. sys.exit()
  1009. if not args.password:
  1010. print('Specify a password with the --password option')
  1011. sys.exit()
  1012. if '@' in args.block:
  1013. blockedDomain=args.block.split('@')[1].replace('\n','')
  1014. blockedNickname=args.block.split('@')[0]
  1015. blockedActor=httpPrefix+'://'+blockedDomain+'/users/'+blockedNickname
  1016. args.block=blockedActor
  1017. else:
  1018. if '/users/' not in args.block:
  1019. print(args.block+' does not look like an actor url')
  1020. sys.exit()
  1021. session = createSession(domain,port,useTor)
  1022. personCache={}
  1023. cachedWebfingers={}
  1024. print('Sending block of '+args.block)
  1025. sendBlockViaServer(baseDir,session,nickname,args.password,
  1026. domain,port, \
  1027. httpPrefix,args.block, \
  1028. cachedWebfingers,personCache, \
  1029. True,__version__)
  1030. for i in range(10):
  1031. # TODO detect send success/fail
  1032. time.sleep(1)
  1033. sys.exit()
  1034. if args.delegate:
  1035. if not nickname:
  1036. print('Specify a nickname with the --nickname option')
  1037. sys.exit()
  1038. if not args.password:
  1039. print('Specify a password with the --password option')
  1040. sys.exit()
  1041. if not args.project:
  1042. print('Specify a project with the --project option')
  1043. sys.exit()
  1044. if not args.role:
  1045. print('Specify a role with the --role option')
  1046. sys.exit()
  1047. if '@' in args.delegate:
  1048. delegatedNickname=args.delegate.split('@')[0]
  1049. args.delegate=blockedActor
  1050. session = createSession(domain,port,useTor)
  1051. personCache={}
  1052. cachedWebfingers={}
  1053. print('Sending delegation for '+args.delegate+' with role '+args.role+' in project '+args.project)
  1054. sendRoleViaServer(baseDir,session, \
  1055. nickname,args.password, \
  1056. domain,port, \
  1057. httpPrefix,args.delegate, \
  1058. args.project,args.role, \
  1059. cachedWebfingers,personCache, \
  1060. True,__version__)
  1061. for i in range(10):
  1062. # TODO detect send success/fail
  1063. time.sleep(1)
  1064. sys.exit()
  1065. if args.undelegate:
  1066. if not nickname:
  1067. print('Specify a nickname with the --nickname option')
  1068. sys.exit()
  1069. if not args.password:
  1070. print('Specify a password with the --password option')
  1071. sys.exit()
  1072. if not args.project:
  1073. print('Specify a project with the --project option')
  1074. sys.exit()
  1075. if '@' in args.undelegate:
  1076. delegatedNickname=args.undelegate.split('@')[0]
  1077. args.undelegate=blockedActor
  1078. session = createSession(domain,port,useTor)
  1079. personCache={}
  1080. cachedWebfingers={}
  1081. print('Sending delegation removal for '+args.undelegate+' from role '+args.role+' in project '+args.project)
  1082. sendRoleViaServer(baseDir,session, \
  1083. nickname,args.password, \
  1084. domain,port, \
  1085. httpPrefix,args.delegate, \
  1086. args.project,None, \
  1087. cachedWebfingers,personCache, \
  1088. True,__version__)
  1089. for i in range(10):
  1090. # TODO detect send success/fail
  1091. time.sleep(1)
  1092. sys.exit()
  1093. if args.unblock:
  1094. if not nickname:
  1095. print('Specify a nickname with the --nickname option')
  1096. sys.exit()
  1097. if not args.password:
  1098. print('Specify a password with the --password option')
  1099. sys.exit()
  1100. if '@' in args.unblock:
  1101. blockedDomain=args.unblock.split('@')[1].replace('\n','')
  1102. blockedNickname=args.unblock.split('@')[0]
  1103. blockedActor=httpPrefix+'://'+blockedDomain+'/users/'+blockedNickname
  1104. args.unblock=blockedActor
  1105. else:
  1106. if '/users/' not in args.unblock:
  1107. print(args.unblock+' does not look like an actor url')
  1108. sys.exit()
  1109. session = createSession(domain,port,useTor)
  1110. personCache={}
  1111. cachedWebfingers={}
  1112. print('Sending undo block of '+args.unblock)
  1113. sendUndoBlockViaServer(baseDir,session,nickname,args.password,
  1114. domain,port, \
  1115. httpPrefix,args.unblock, \
  1116. cachedWebfingers,personCache, \
  1117. True,__version__)
  1118. for i in range(10):
  1119. # TODO detect send success/fail
  1120. time.sleep(1)
  1121. sys.exit()
  1122. if args.filterStr:
  1123. if not args.nickname:
  1124. print('Please specify a nickname')
  1125. sys.exit()
  1126. if addFilter(baseDir,args.nickname,domain,args.filterStr):
  1127. print('Filter added to '+args.nickname+': '+args.filterStr)
  1128. sys.exit()
  1129. if args.unfilterStr:
  1130. if not args.nickname:
  1131. print('Please specify a nickname')
  1132. sys.exit()
  1133. if removeFilter(baseDir,args.nickname,domain,args.unfilterStr):
  1134. print('Filter removed from '+args.nickname+': '+args.unfilterStr)
  1135. sys.exit()
  1136. if args.testdata:
  1137. useBlurhash=False
  1138. nickname='testuser567'
  1139. password='boringpassword'
  1140. print('Generating some test data for user: '+nickname)
  1141. if os.path.isdir(baseDir+'/tags'):
  1142. shutil.rmtree(baseDir+'/tags')
  1143. if os.path.isdir(baseDir+'/accounts'):
  1144. shutil.rmtree(baseDir+'/accounts')
  1145. if os.path.isdir(baseDir+'/keys'):
  1146. shutil.rmtree(baseDir+'/keys')
  1147. if os.path.isdir(baseDir+'/media'):
  1148. shutil.rmtree(baseDir+'/media')
  1149. if os.path.isdir(baseDir+'/sharefiles'):
  1150. shutil.rmtree(baseDir+'/sharefiles')
  1151. if os.path.isdir(baseDir+'/wfendpoints'):
  1152. shutil.rmtree(baseDir+'/wfendpoints')
  1153. setConfigParam(baseDir,'registrationsRemaining',str(maxRegistrations))
  1154. createPerson(baseDir,'maxboardroom',domain,port,httpPrefix,True,password)
  1155. createPerson(baseDir,'ultrapancake',domain,port,httpPrefix,True,password)
  1156. createPerson(baseDir,'drokk',domain,port,httpPrefix,True,password)
  1157. createPerson(baseDir,'sausagedog',domain,port,httpPrefix,True,password)
  1158. createPerson(baseDir,nickname,domain,port,httpPrefix,True,'likewhateveryouwantscoob')
  1159. setSkillLevel(baseDir,nickname,domain,'testing',60)
  1160. setSkillLevel(baseDir,nickname,domain,'typing',50)
  1161. setRole(baseDir,nickname,domain,'instance','admin')
  1162. setRole(baseDir,nickname,domain,'epicyon','hacker')
  1163. setRole(baseDir,nickname,domain,'someproject','assistant')
  1164. setAvailability(baseDir,nickname,domain,'busy')
  1165. addShare(baseDir, \
  1166. httpPrefix,nickname,domain,port, \
  1167. "spanner", \
  1168. "It's a spanner", \
  1169. "img/shares1.png", \
  1170. "tool", \
  1171. "mechanical", \
  1172. "City", \
  1173. "2 months",
  1174. debug)
  1175. addShare(baseDir, \
  1176. httpPrefix,nickname,domain,port, \
  1177. "witch hat", \
  1178. "Spooky", \
  1179. "img/shares2.png", \
  1180. "hat", \
  1181. "clothing", \
  1182. "City", \
  1183. "3 months",
  1184. debug)
  1185. deleteAllPosts(baseDir,nickname,domain,'inbox')
  1186. deleteAllPosts(baseDir,nickname,domain,'outbox')
  1187. createPublicPost(baseDir,nickname,domain,port,httpPrefix,"like, this is totally just a #test, man",False,True,False,None,None,useBlurhash)
  1188. createPublicPost(baseDir,nickname,domain,port,httpPrefix,"Zoiks!!!",False,True,False,None,None,useBlurhash)
  1189. createPublicPost(baseDir,nickname,domain,port,httpPrefix,"Hey scoob we need like a hundred more #milkshakes",False,True,False,None,None,useBlurhash)
  1190. createPublicPost(baseDir,nickname,domain,port,httpPrefix,"Getting kinda spooky around here",False,True,False,None,None,useBlurhash,'someone')
  1191. createPublicPost(baseDir,nickname,domain,port,httpPrefix,"And they would have gotten away with it too if it wasn't for those pesky hackers",False,True,False,'img/logo.png','Description of image',useBlurhash)
  1192. createPublicPost(baseDir,nickname,domain,port,httpPrefix,"man, these centralized sites are, like, the worst!",False,True,False,None,None,useBlurhash)
  1193. createPublicPost(baseDir,nickname,domain,port,httpPrefix,"another mystery solved #test",False,True,False,None,None,useBlurhash)
  1194. createPublicPost(baseDir,nickname,domain,port,httpPrefix,"let's go bowling",False,True,False,None,None,useBlurhash)
  1195. domainFull=domain+':'+str(port)
  1196. clearFollows(baseDir,nickname,domain)
  1197. followPerson(baseDir,nickname,domain,'maxboardroom',domainFull,federationList,False)
  1198. followPerson(baseDir,nickname,domain,'ultrapancake',domainFull,federationList,False)
  1199. followPerson(baseDir,nickname,domain,'sausagedog',domainFull,federationList,False)
  1200. followPerson(baseDir,nickname,domain,'drokk',domainFull,federationList,False)
  1201. followerOfPerson(baseDir,nickname,domain,'drokk',domainFull,federationList,False)
  1202. followerOfPerson(baseDir,nickname,domain,'maxboardroom',domainFull,federationList,False)
  1203. setConfigParam(baseDir,'admin',nickname)
  1204. runDaemon(__version__, \
  1205. instanceId,args.client,baseDir, \
  1206. domain,port,proxyPort,httpPrefix, \
  1207. federationList, \
  1208. args.noreply,args.nolike,args.nopics, \
  1209. args.noannounce,args.cw,ocapAlways, \
  1210. useTor,args.maxReplies, \
  1211. args.domainMaxPostsPerDay,args.accountMaxPostsPerDay, \
  1212. args.allowdeletion,debug,False, \
  1213. args.instanceOnlySkillsSearch)