Add keyholder export
This commit is contained in:
parent
7a0c868161
commit
b095cd9988
37
byro_shackspace/management/commands/export_keyholder.py
Normal file
37
byro_shackspace/management/commands/export_keyholder.py
Normal 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)
|
||||
|
@ -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 %}
|
Loading…
Reference in New Issue
Block a user