fix logins

This commit is contained in:
Izalia Mae 2020-02-06 12:33:37 -05:00
parent bd6833f2f1
commit 705f35f7a6
7 changed files with 39 additions and 39 deletions

View file

@ -169,6 +169,10 @@ While it isn't necessary, I highly recommend turning on authorized fetches (v3.0
AUTHORIZED_FETCH=true
```
## Usage
Start the server with `./server.py`. If you want to edit the config, just run `./server.py edit`.
## WebUI usage
If your account is an admin account according to Mastodon, you can manage the PAWS whitelist at {domain}/paws. Instances in this whitelist will have their fetches signed if they don't sign them themselves.

View file

@ -1,29 +1,4 @@
#!/usr/bin/env python3
import sys
import os
import stat
from os import environ as env
from .routes import main
if 'install' in sys.argv:
from .config import mastodir, logging
script = f'{mastodir}/paws.sh'
start_script = f'''#!/bin/sh
export MASTODIR={mastodir}
(cd MASTODIR && python -m paws)'''
with open(script, 'w') as sh:
sh.write(start_script)
if os.path.isfile(script):
os.chmod(script, 492)
logging.info(f'Startup script saved as {script}')
else:
logging.info(f'Failed to write script as {script}')
else:
main()
main()

View file

@ -9,7 +9,7 @@ from envbash import load_envbash
from .functions import bool_check
VERSION = '0.2.1'
VERSION = '0.2.2'
full_path = abspath(sys.executable) if getattr(sys, 'frozen', False) else abspath(__file__)
script_path = getattr(sys, '_MEIPASS', dirname(abspath(__file__)))
@ -46,20 +46,24 @@ logging.addHandler(console)
if not isfile(f'{stor_path}/production.env'):
logging.error(f'PAWS environment file doesn\'t exist: {stor_path}/production.env')
logging.error('Creating a new config file. Be sure to edit it and restart PAWS')
logging.info('Creating a new config file. Be sure to edit it and restart PAWS')
new_config = '''
PAWS_HOST=127.0.0.1
PAWS_PORT=3001
### Uncomment and adjust any values as necessary
#PAWS_HOST=127.0.0.1
#PAWS_PORT=3001
PAWS_DOMAIN=bappypaws.example.com
#PAWS_DOMAIN=bappypaws.example.com
MASTOPATH=/home/mastodon/glitch-soc
#MASTOPATH=/home/mastodon/glitch-soc
#MASTOHOST=localhost:3000
'''
with open(f'{stor_path}/production.env', 'w') as pawsconf:
pawsconf.write(new_config)
logging.info(f'Created new config at {stor_path}/production.env')
else:
load_envbash(f'{stor_path}/production.env')

View file

@ -95,8 +95,8 @@ async def http_filter(app, handler):
# add logged in user data to the request for the frontend
request['user'] = user_data
if request.path not in ['/paws/actor', '/paws/inbox', '/.well-known/webfinger'] and request.host == paws_host:
return aiohttp.web.HTTPFound(f'http://{masto_host}{request.path}?{distill_query(request.query)}')
if request.path in ['/paws/actor', '/paws/inbox', '/.well-known/webfinger'] and request.host != paws_host:
return aiohttp.web.HTTPFound(f'http://{masto_host}/paws')
# try to find the domain for the request
if not domain:
@ -151,6 +151,9 @@ async def http_filter(app, handler):
if user_ban_check(user.lower(), (user_data['handle'].lower(), user_data['instance'])) or user_domain_ban_check(user.lower(), user_data['instance']):
return http_error(request, 403, 'Access Denied')
if signature and wl_check(domain):
logging.warning(f'{domain} has started signing requests and can be removed from the whitelist')
if not signature and real_ip == ua_ip and wl_check(domain) and request.method == 'GET':
logging.info(f'Signing fetch for whitelisted instance: {domain}')

View file

@ -8,7 +8,6 @@ import traceback
import http.client as http
from urllib.parse import urlencode, urlparse
from mastodon import Mastodon
from .config import PAWSCONFIG, MASTOCONFIG, VERSION, stor_path

View file

@ -72,7 +72,9 @@ async def get_login(request):
token = request.cookies.get('paws_token')
numid = random.randint(1*1000000, 10*1000000-1)
if pawsdb.users.get(query.token == token):
logging.warning(token)
if token and pawsdb.users.get(query.token == token):
return aiohttp.web.HTTPFound(f'https://{masto_host}/paws')
return render('pages/login.html', request, {'redir': redir, 'numid': numid})
@ -129,8 +131,10 @@ async def get_auth(request):
if None in [numid, code]:
return http_error(request, 500, 'Missing temporary userid or auth code')
if redir in ['', None]:
redir = '/about'
logging.warning(redir)
if redir in ['', 'None', None]:
redir = '/paws'
user = pawsdb.users.get(query.handle == str(numid))
token, userinfo = login(user, code)
@ -156,7 +160,7 @@ async def get_logout(request):
with trans(pawsdb.users) as tr:
tr.remove(where('token') == token)
response = render('pages/login.html', request, {'msg': 'Logged out'})
response = aiohttp.web.HTTPFound('/paws/login')
response.del_cookie('token')
return response

View file

@ -1,5 +1,16 @@
#!/usr/bin/env python3
import sys, os
from paws.routes import main
if __name__ == '__main__':
if 'edit' in sys.argv:
from paws.config import stor_path
print(f'Opening {stor_path}/production.env in a text editor')
editor = os.popen(f'$EDITOR {stor_path}/production.env', 'r')
editor.read()
editor.close()
sys.exit()
main()