diff --git a/byro_shackspace/management/commands/export_keyholder.py b/byro_shackspace/management/commands/export_keyholder.py new file mode 100644 index 0000000..c24059f --- /dev/null +++ b/byro_shackspace/management/commands/export_keyholder.py @@ -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) + diff --git a/byro_shackspace/templates/shackspace/portal_authorized_keys.txt b/byro_shackspace/templates/shackspace/portal_authorized_keys.txt new file mode 100644 index 0000000..e1d3db9 --- /dev/null +++ b/byro_shackspace/templates/shackspace/portal_authorized_keys.txt @@ -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 %}