Пример #1
0
def ssh(request, admin_site):
    """Show information and manipulate with SSH key."""
    # Check whether we can generate SSH key
    can_generate = can_generate_key()

    # Grab action type
    action = request.POST.get('action')

    # Generate key if it does not exist yet
    if can_generate and action == 'generate':
        generate_ssh_key(request)

    # Read key data if it exists
    key = get_key_data()

    # Add host key
    if action == 'add-host':
        add_host_key(request)

    context = admin_site.each_context(request)
    context['public_key'] = key
    context['can_generate'] = can_generate
    context['host_keys'] = get_host_keys()

    return render(
        request,
        "admin/ssh.html",
        context,
    )
Пример #2
0
def ssh(request):
    """
    Show information and manipulate with SSH key.
    """
    # Check whether we can generate SSH key
    can_generate = can_generate_key()

    # Grab action type
    action = request.POST.get('action', None)

    # Generate key if it does not exist yet
    if can_generate and action == 'generate':
        generate_ssh_key(request)

    # Read key data if it exists
    key = get_key_data()

    # Add host key
    if action == 'add-host':
        add_host_key(request)

    return render(
        request, "admin/ssh.html", {
            'public_key': key,
            'can_generate': can_generate,
            'host_keys': get_host_keys(),
            'ssh_docs': weblate.get_doc_url('admin/projects', 'private'),
        })
Пример #3
0
def ssh(request):
    """
    Show information and manipulate with SSH key.
    """
    # Check whether we can generate SSH key
    can_generate = can_generate_key()

    # Grab action type
    action = request.POST.get('action', None)

    # Generate key if it does not exist yet
    if can_generate and action == 'generate':
        generate_ssh_key(request)

    # Read key data if it exists
    key = get_key_data()

    # Add host key
    if action == 'add-host':
        add_host_key(request)

    context = admin_context(request)
    context['public_key'] = key
    context['can_generate'] = can_generate
    context['host_keys'] = get_host_keys()
    context['ssh_docs'] = weblate.get_doc_url('admin/projects', 'private')

    return render(
        request,
        "admin/ssh.html",
        context,
    )
Пример #4
0
def ssh(request):
    """
    Show information and manipulate with SSH key.
    """
    # Check whether we can generate SSH key
    can_generate = can_generate_key()

    if not is_home_writable():
        can_generate = False
        messages.error(
            request,
            _('Can not write to home directory, please check documentation.'))

    # Grab action type
    action = request.POST.get('action', None)

    # Generate key if it does not exist yet
    if can_generate and action == 'generate':
        generate_ssh_key(request)

    # Read key data if it exists
    key = get_key_data()

    # Add host key
    if action == 'add-host':
        add_host_key(request)

    return render(
        request, "admin/ssh.html", {
            'public_key': key,
            'can_generate': can_generate,
            'host_keys': get_host_keys(),
            'ssh_docs': weblate.get_doc_url('admin/projects', 'private'),
        })
Пример #5
0
def ssh(request):
    """
    Show information and manipulate with SSH key.
    """
    # Check whether we can generate SSH key
    can_generate = can_generate_key()

    # Grab action type
    action = request.POST.get("action", None)

    # Generate key if it does not exist yet
    if can_generate and action == "generate":
        generate_ssh_key(request)

    # Read key data if it exists
    key = get_key_data()

    # Add host key
    if action == "add-host":
        add_host_key(request)

    return render(
        request,
        "admin/ssh.html",
        {
            "public_key": key,
            "can_generate": can_generate,
            "host_keys": get_host_keys(),
            "ssh_docs": weblate.get_doc_url("admin/projects", "private"),
        },
    )
Пример #6
0
 def test_parse(self):
     try:
         backup_dir = appsettings.DATA_DIR
         tempdir = os.path.join(self._tempdir, 'ssh')
         os.makedirs(tempdir)
         shutil.copy(TEST_HOSTS, tempdir)
         appsettings.DATA_DIR = self._tempdir
         hosts = get_host_keys()
         self.assertEqual(len(hosts), 50)
     finally:
         appsettings.DATA_DIR = backup_dir
Пример #7
0
 def test_parse(self):
     try:
         backup_dir = appsettings.DATA_DIR
         tempdir = os.path.join(self._tempdir, 'ssh')
         os.makedirs(tempdir)
         shutil.copy(TEST_HOSTS, tempdir)
         appsettings.DATA_DIR = self._tempdir
         hosts = get_host_keys()
         self.assertEqual(len(hosts), 50)
     finally:
         appsettings.DATA_DIR = backup_dir
Пример #8
0
def ssh(request):
    """
    Show information and manipulate with SSH key.
    """
    # Check whether we can generate SSH key
    can_generate = can_generate_key()

    if not is_home_writable():
        can_generate = False
        messages.error(
            request,
            _('Can not write to home directory, please check documentation.')
        )

    # Grab action type
    action = request.POST.get('action', None)

    # Generate key if it does not exist yet
    if can_generate and action == 'generate':
        generate_ssh_key(request)

    # Read key data if it exists
    key = get_key_data()

    # Add host key
    if action == 'add-host':
        add_host_key(request)

    return render(
        request,
        "admin/ssh.html",
        {
            'public_key': key,
            'can_generate': can_generate,
            'host_keys': get_host_keys(),
            'ssh_docs': weblate.get_doc_url('admin/projects', 'private'),
        }
    )
Пример #9
0
 def test_parse(self):
     check_data_writable()
     shutil.copy(TEST_HOSTS, os.path.join(settings.DATA_DIR, 'ssh'))
     hosts = get_host_keys()
     self.assertEqual(len(hosts), 50)
Пример #10
0
 def test_parse(self):
     tempdir = os.path.join(appsettings.DATA_DIR, 'ssh')
     os.makedirs(tempdir)
     shutil.copy(TEST_HOSTS, tempdir)
     hosts = get_host_keys()
     self.assertEqual(len(hosts), 50)
Пример #11
0
 def test_parse(self):
     tempdir = os.path.join(appsettings.DATA_DIR, 'ssh')
     os.makedirs(tempdir)
     shutil.copy(TEST_HOSTS, tempdir)
     hosts = get_host_keys()
     self.assertEqual(len(hosts), 50)
Пример #12
0
 def test_parse(self):
     check_data_writable()
     shutil.copy(TEST_HOSTS, os.path.join(appsettings.DATA_DIR, 'ssh'))
     hosts = get_host_keys()
     self.assertEqual(len(hosts), 50)