Add keyholder export

This commit is contained in:
Tobias Kunze 2018-01-18 22:46:07 +01:00
parent 7a0c868161
commit b095cd9988
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,37 @@
from django.db.models import Q
from django.conf import settings
from django.core.management import BaseCommand
from django.template.loader import get_template
from django.utils import timezone
from os import path
class Command(BaseCommand):
def handle(self, *args, **options):
from byro_shackspace.models import ShackProfile
profiles = ShackProfile.objects.filter(
member__memberships__end__isnull=True,
is_keyholder=True,
).order_by('member__number')
for task in ["open", "close"]:
context = {
'task': task,
'profiles': [
{
'name': profile.member.name,
'number': profile.member.number,
'nick': profile.member.profile_profile.nick,
'key': profile.ssh_public_key,
}
for profile in profiles
],
}
content = get_template('shackspace/portal_authorized_keys.txt').render(context)
with open(path.join(settings.BASE_DIR, f'authorized_keys.{task}'), 'w') as f:
f.write(content)

View File

@ -0,0 +1,2 @@
{% for profile in profiles %}command="/opt/Portal-v3/portal/portal.py -a {{ task }} -s {{ profile.number }} -n \"{{ profile.name }}\" --nick \"{{ profile.nick }}\"",no-port-forwarding,no-X11-forwarding,no-agent-forwarding {{ profile.key }}
{% endfor %}