2020-08-23 16:40:54 +00:00
|
|
|
# busby_1st/views/nodeinfo.py
|
2019-08-15 15:46:48 +00:00
|
|
|
#
|
2020-08-23 16:40:54 +00:00
|
|
|
# Part of kepi.
|
|
|
|
# Copyright (c) 2018-2020 Marnanel Thurman.
|
2019-08-15 15:46:48 +00:00
|
|
|
# Licensed under the GNU Public License v2.
|
|
|
|
|
2020-08-23 16:40:54 +00:00
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(name='kepi')
|
|
|
|
|
2019-08-15 15:46:48 +00:00
|
|
|
"""
|
|
|
|
Implements nodeinfo.
|
|
|
|
See [http://nodeinfo.diaspora.software/protocol.html](Diaspora's site)
|
|
|
|
for the full details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import django.views
|
|
|
|
from django.conf import settings
|
|
|
|
from django.shortcuts import render
|
|
|
|
from django.http import HttpResponse
|
2019-11-20 19:10:10 +00:00
|
|
|
from kepi import __version__
|
2019-08-15 15:46:48 +00:00
|
|
|
import re
|
2019-11-20 19:10:10 +00:00
|
|
|
from kepi.bowler_pub.utils import as_json
|
2019-08-15 15:46:48 +00:00
|
|
|
|
|
|
|
class NodeinfoPart1(django.views.View):
|
|
|
|
"""
|
|
|
|
Nodeinfo support.
|
|
|
|
This part must appear at "/.well-known/nodeinfo".
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
|
|
|
|
logger.info('Returning nodeinfo.')
|
|
|
|
|
|
|
|
result = {
|
|
|
|
"links": [
|
|
|
|
{
|
|
|
|
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
|
|
|
"href": request.build_absolute_uri("/nodeinfo.json"),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
return HttpResponse(
|
|
|
|
status = 200,
|
|
|
|
reason = 'Here you go',
|
2019-09-13 22:22:51 +00:00
|
|
|
content = bytes(as_json(result),
|
2019-08-15 15:46:48 +00:00
|
|
|
encoding='utf-8'),
|
|
|
|
content_type='application/json; '+\
|
|
|
|
'profile=http://nodeinfo.diaspora.software/ns/schema/2.0#')
|
|
|
|
|
|
|
|
class NodeinfoPart2(django.views.View):
|
|
|
|
"""
|
|
|
|
Nodeinfo support.
|
|
|
|
|
|
|
|
This should be at "/nodeinfo.json".
|
|
|
|
"""
|
|
|
|
|
|
|
|
def _get_body(self, request):
|
|
|
|
|
|
|
|
result = {
|
|
|
|
"version": "2.0",
|
|
|
|
"software" : {
|
2019-11-20 19:10:10 +00:00
|
|
|
"name": "kepi",
|
2019-08-15 15:46:48 +00:00
|
|
|
"version": __version__,
|
|
|
|
},
|
|
|
|
"protocols": ['activitypub'],
|
|
|
|
"services": {
|
2019-08-15 15:53:26 +00:00
|
|
|
"inbound": [],
|
|
|
|
"outbound": [],
|
2019-08-15 15:46:48 +00:00
|
|
|
},
|
|
|
|
"openRegistrations": False,
|
|
|
|
"usage": {
|
|
|
|
"users": {
|
|
|
|
# When this information is meaningful,
|
|
|
|
# we can implement this more seriously.
|
|
|
|
"total": 1,
|
|
|
|
"activeMonth": 1,
|
|
|
|
},
|
|
|
|
"localPosts": 0,
|
|
|
|
"localComments": 0,
|
|
|
|
},
|
|
|
|
"metadata": {
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return HttpResponse(
|
|
|
|
status = 200,
|
|
|
|
reason = 'Here you go',
|
2019-09-13 22:22:51 +00:00
|
|
|
content = bytes(as_json(result),
|
2019-08-15 15:46:48 +00:00
|
|
|
encoding='utf-8'),
|
|
|
|
content_type='application/json; '+\
|
|
|
|
'profile=http://nodeinfo.diaspora.software/ns/schema/2.0#')
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
result = self._get_body(request)
|
|
|
|
|
|
|
|
result['Access-Control-Allow-Origin'] = '*'
|
|
|
|
return result
|