diff --git a/apps/assets/models/asset.py b/apps/assets/models/asset.py index 068f41aa2..1e6540586 100644 --- a/apps/assets/models/asset.py +++ b/apps/assets/models/asset.py @@ -112,7 +112,12 @@ class Asset(models.Model): 'groups': [group.name for group in self.groups.all()], 'username': self.admin_user.username if self.admin_user else '', 'password': self.admin_user.password if self.admin_user else '', - 'private_key': self.admin_user.private_key if self.admin_user else None, + 'private_key': self.admin_user.private_key_file if self.admin_user else None, + 'become': { + 'method': self.admin_user.become_method, + 'user': self.admin_user.become_user, + 'pass': self.admin_user.become_pass, + } if self.admin_user.become else {}, } class Meta: diff --git a/apps/assets/models/user.py b/apps/assets/models/user.py index ee2a156ab..48d0f4029 100644 --- a/apps/assets/models/user.py +++ b/apps/assets/models/user.py @@ -3,12 +3,14 @@ # from __future__ import unicode_literals - +import os import logging +from hashlib import md5 from django.core.exceptions import ValidationError from django.db import models from django.utils.translation import ugettext_lazy as _ +from django.conf import settings from common.utils import signer, validate_ssh_private_key, ssh_key_string_to_obj @@ -38,7 +40,7 @@ class AdminUser(models.Model): become = models.BooleanField(default=True) become_method = models.CharField(choices=BECOME_METHOD_CHOICES, default='sudo', max_length=4) become_user = models.CharField(default='root', max_length=64) - become_password = models.CharField(default='', max_length=128) + become_pass = models.CharField(default='', max_length=128) _public_key = models.CharField( max_length=4096, blank=True, verbose_name=_('SSH public key')) comment = models.TextField(blank=True, verbose_name=_('Comment')) @@ -74,6 +76,18 @@ class AdminUser(models.Model): def private_key(self, private_key_raw): self._private_key = signer.sign(private_key_raw) + @property + def private_key_file(self): + if not self.private_key: + return None + project_dir = settings.PROJECT_DIR + tmp_dir = os.path.join(project_dir, 'tmp') + key_name = md5(self._private_key).hexdigest() + key_path = os.path.join(tmp_dir, key_name) + if not os.path.exists(key_path): + self.private_key.write_private_key_file(key_path) + return key_path + @property def public_key(self): return signer.unsign(self._public_key) diff --git a/apps/audits/templates/audits/proxy_log_list.html b/apps/audits/templates/audits/proxy_log_offline_list.html similarity index 100% rename from apps/audits/templates/audits/proxy_log_list.html rename to apps/audits/templates/audits/proxy_log_offline_list.html diff --git a/apps/audits/templates/audits/proxy_log_online_list.html b/apps/audits/templates/audits/proxy_log_online_list.html new file mode 100644 index 000000000..6a3c815b0 --- /dev/null +++ b/apps/audits/templates/audits/proxy_log_online_list.html @@ -0,0 +1,173 @@ +{% extends '_base_list.html' %} +{% load i18n %} +{% load static %} +{% block content_left_head %} + + +{% endblock %} + + +{% block table_search %} +
+{% endblock %} + +{% block table_head %} +