fix various issues

This commit is contained in:
Izalia Mae 2021-09-17 12:58:41 -04:00
parent 51cddac201
commit 310f1aee17
11 changed files with 60 additions and 40 deletions

View file

@ -21,9 +21,10 @@ setupvenv:
$(PYTHON) -m pip install wheel
$(PYTHON) -m pip install -r requirements.txt
setupdev:
$(PYTHON) -m pip install vulture
$(PYTHON) -m pip install "git+https://git.barkshark.xyz/izaliamae/reload"
$(PYTHON) -m pip install "git+https://git.barkshark.xyz/izaliamae/reload.git"
update-deps:
git reset HEAD --hard

View file

@ -1,5 +1,5 @@
{
"bin": "python3",
"bin": "~/.local/share/venv/uncia/bin/python",
"args": ["-m", "uncia"],
"env": {},
"path": "./uncia",

View file

@ -1,9 +1,10 @@
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-base&subdirectory=base
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-requests-client&subdirectory=requests_client
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-http-server&subdirectory=http_server
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-templates&subdirectory=template
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-password-hasher&subdirectory=hasher
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-http-erver&subdirectory=http_server
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-http-urllib-client&subdirectory=http_urllib_client
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-sql&subdirectory=sql
-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-templates&subdirectory=template
envbash==1.2.0
pyyaml==5.4.1
pg8000=1.21.2
pg8000==1.21.2

View file

@ -1,4 +1,10 @@
from izzylib import logging
from .config import first_start
from .server import app
if first_start:
logging.error(f'Uncia has not been configured yet. Please edit {config.envfile} first.')
app.start()

View file

@ -13,6 +13,8 @@ scriptpath = Path(__file__).resolve.parent
configpath = scriptpath.parent.join('data')
configpath.mkdir()
first_start = False
path = DotDict(
script = scriptpath,
@ -21,12 +23,10 @@ path = DotDict(
envfile = configpath.join('env.production')
)
if not path.envfile.exists:
logging.error(f'Uncia has not been configured yet. Please edit {config.envfile} first.')
write_config()
sys.exit()
load_envbash(path.envfile)
try:
load_envbash(path.envfile)
except FileNotFoundError:
pass
config = DotDict(
@ -67,3 +67,8 @@ UNCIA_DB_PASS={dbconfig.password}
UNCIA_DB_MAXCON={dbconfig.max_connections}
UNCIA_DB_TIMEOUT={dbconfig.timeout}
''')
if not path.envfile.exists:
first_start = True
write_config()

View file

@ -12,8 +12,9 @@ def cmd_actor(self, url):
if not row:
return
self.cache.actor_cache.store(url, row)
return row
data = DotDict(row.data)
self.cache.actor_cache.store(url, data)
return data
def cmd_ban_list(self, types='domain'):
@ -52,10 +53,10 @@ def cmd_config(self, key):
if key not in self.config_defaults:
raise KeyError(f'Invalid config option: {key}')
#cache = self.cache.config.fetch(key)
cache = self.cache.config.fetch(key)
#if cache:
#return cache
if cache:
return cache
row = self.fetch('config', key=key)
@ -63,7 +64,7 @@ def cmd_config(self, key):
return self.config_defaults[key][0]
value = self.config_defaults[key][1](row.value)
#self.cache.config.store(key, value)
self.cache.config.store(key, value)
return value

View file

@ -66,7 +66,7 @@ def cmd_config(self, key, value=None):
else:
self.insert('config', key=key, value=value)
#self.cache.config.store(key, value)
self.cache.config.store(key, value)
return value

View file

@ -25,7 +25,7 @@ def fetch_actor(url):
cached = s.get.actor(url)
if cached:
return cached.data
return cached
try:
data = fetch(url, cache=False)
@ -36,7 +36,7 @@ def fetch_actor(url):
if not data:
data = fetch(url, sign=True, cache=False)
if not data:
if not data or data.get('error'):
return
s.put.actor(url, data)
@ -90,12 +90,12 @@ def get_inbox(actor):
def push_message(inbox, message):
with db.session as s:
response = client.signed_request(
s.get.config('privkey'),
f'https://{config.host}/actor#main-key',
response = client.request(
inbox,
data = message.to_json(),
method = 'post'
body = message.to_json(),
method = 'post',
privkey = s.get.config('privkey'),
keyid = f'https://{config.host}/actor#main-key'
)
if response.status not in [200, 202]:

View file

@ -1,7 +1,9 @@
from izzylib import logging
from izzylib.http_urllib_client import parse_signature, verify_request
from izzylib.http_urllib_client import parse_signature, verify_request, verify_headers
from izzylib.http_server import MiddlewareBase
from izzylib.sql.rows import Row
from .database import db
from .functions import fetch_actor
@ -45,6 +47,7 @@ class AuthCheck(MiddlewareBase):
request.ctx.user = s.fetch('user', id=request.token.id) if request.token else None
request.ctx.signature = parse_signature(request.headers.get('signature'))
request.ctx.instance = None
request.ctx.actor = None
if request.ctx.signature:
if request.ctx.signature.top_domain in blocked_instances:
@ -57,6 +60,9 @@ class AuthCheck(MiddlewareBase):
request.ctx.actor = fetch_actor(request.ctx.signature.actor)
if request.path in ['/inbox', '/actor'] and request.method.lower() == 'post':
if not request.ctx.actor:
return response.text('Could not get actor', status=400)
try:
data = request.data.json
@ -65,7 +71,13 @@ class AuthCheck(MiddlewareBase):
return response.text(f'Invalid data', status=400)
try:
validated = await verify_request(request, actor=request.ctx.actor)
validated = verify_headers(
request.Headers.to_dict(),
request.method,
request.path,
actor = request.ctx.actor,
body = request.body
)
except AssertionError as e:
logging.debug(f'Failed sig check: {e}')

View file

@ -18,17 +18,10 @@ class ProcessData:
self.response = response
self.signature = request.ctx.signature
self.instance = request.ctx.instance
self.actor = request.ctx.actor
self.type = data.type.lower()
self.data = data
try:
self.actor = fetch_actor(self.signature.actor)
except json.decoder.JSONDecodeError:
self.actor = None
#print(self.request.Headers.to_json(4))
#print(self.request.data.json.to_json(4))
if not self.actor:
logging.verbose(f'Failed to fetch actor: {data.actor}')
self.new_response = response.json('Failed to fetch actor.', status=401)
@ -130,3 +123,7 @@ class ProcessData:
else:
logging.verbose(f'Sent "{object.id}" to {instance.domain}')
def cmd_create(self):
return self.cmd_announce()

View file

@ -11,10 +11,7 @@ def template_context(context):
with db.session as s:
config = s.get.config_all()
try:
context['config'] = config
except:
context['config'] = {}
context['config'] = config
return context