mirror of https://github.com/jumpserver/jumpserver
				
				
				
			[Update] 修改授权api, windows资产只有rdp协议,linux只有ssh协议
							parent
							
								
									91863107d7
								
							
						
					
					
						commit
						f886e7c2f5
					
				| 
						 | 
				
			
			@ -15,7 +15,7 @@ class AssetCreateForm(forms.ModelForm):
 | 
			
		|||
        model = Asset
 | 
			
		||||
        fields = [
 | 
			
		||||
            'hostname', 'ip', 'public_ip', 'port',  'comment',
 | 
			
		||||
            'nodes', 'is_active', 'admin_user', 'labels',
 | 
			
		||||
            'nodes', 'is_active', 'admin_user', 'labels', 'platform',
 | 
			
		||||
 | 
			
		||||
        ]
 | 
			
		||||
        widgets = {
 | 
			
		||||
| 
						 | 
				
			
			@ -44,7 +44,7 @@ class AssetUpdateForm(forms.ModelForm):
 | 
			
		|||
    class Meta:
 | 
			
		||||
        model = Asset
 | 
			
		||||
        fields = [
 | 
			
		||||
            'hostname', 'ip', 'port', 'nodes',  'is_active',
 | 
			
		||||
            'hostname', 'ip', 'port', 'nodes',  'is_active', 'platform',
 | 
			
		||||
            'public_ip', 'number', 'comment', 'admin_user', 'labels',
 | 
			
		||||
        ]
 | 
			
		||||
        widgets = {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,6 +38,14 @@ def default_node():
 | 
			
		|||
 | 
			
		||||
class Asset(models.Model):
 | 
			
		||||
    # Important
 | 
			
		||||
    PLATFORM_CHOICES = (
 | 
			
		||||
        ('Linux', 'Linux'),
 | 
			
		||||
        ('Unix', 'Unix'),
 | 
			
		||||
        ('MacOS', 'MacOS'),
 | 
			
		||||
        ('BSD', 'BSD'),
 | 
			
		||||
        ('Windows', 'Windows'),
 | 
			
		||||
        ('Other', 'Other'),
 | 
			
		||||
    )
 | 
			
		||||
    id = models.UUIDField(default=uuid.uuid4, primary_key=True)
 | 
			
		||||
    ip = models.GenericIPAddressField(max_length=32, verbose_name=_('IP'), db_index=True)
 | 
			
		||||
    hostname = models.CharField(max_length=128, unique=True, verbose_name=_('Hostname'))
 | 
			
		||||
| 
						 | 
				
			
			@ -64,7 +72,7 @@ class Asset(models.Model):
 | 
			
		|||
    disk_total = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('Disk total'))
 | 
			
		||||
    disk_info = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('Disk info'))
 | 
			
		||||
 | 
			
		||||
    platform = models.CharField(max_length=128, null=True, blank=True, verbose_name=_('Platform'))
 | 
			
		||||
    platform = models.CharField(max_length=128, choices=PLATFORM_CHOICES, default='Linux', verbose_name=_('Platform'))
 | 
			
		||||
    os = models.CharField(max_length=128, null=True, blank=True, verbose_name=_('OS'))
 | 
			
		||||
    os_version = models.CharField(max_length=16, null=True, blank=True, verbose_name=_('OS version'))
 | 
			
		||||
    os_arch = models.CharField(max_length=16, blank=True, null=True, verbose_name=_('OS arch'))
 | 
			
		||||
| 
						 | 
				
			
			@ -87,6 +95,12 @@ class Asset(models.Model):
 | 
			
		|||
            return True, ''
 | 
			
		||||
        return False, warning
 | 
			
		||||
 | 
			
		||||
    def is_unixlike(self):
 | 
			
		||||
        if self.platform not in ("Windows", "Other"):
 | 
			
		||||
            return True
 | 
			
		||||
        else:
 | 
			
		||||
            return False
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def hardware_info(self):
 | 
			
		||||
        if self.cpu_count:
 | 
			
		||||
| 
						 | 
				
			
			@ -99,6 +113,8 @@ class Asset(models.Model):
 | 
			
		|||
 | 
			
		||||
    @property
 | 
			
		||||
    def is_connective(self):
 | 
			
		||||
        if not self.is_unixlike():
 | 
			
		||||
            return True
 | 
			
		||||
        val = cache.get(ASSET_ADMIN_CONN_CACHE_KEY.format(self.hostname))
 | 
			
		||||
        if val == 1:
 | 
			
		||||
            return True
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@
 | 
			
		|||
    {% bootstrap_field form.hostname layout="horizontal" %}
 | 
			
		||||
    {% bootstrap_field form.ip layout="horizontal" %}
 | 
			
		||||
    {% bootstrap_field form.port layout="horizontal" %}
 | 
			
		||||
    {% bootstrap_field form.platform layout="horizontal" %}
 | 
			
		||||
    {% bootstrap_field form.public_ip layout="horizontal" %}
 | 
			
		||||
 | 
			
		||||
    <div class="hr-line-dashed"></div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,6 +22,7 @@
 | 
			
		|||
    {% bootstrap_field form.hostname layout="horizontal" %}
 | 
			
		||||
    {% bootstrap_field form.ip layout="horizontal" %}
 | 
			
		||||
    {% bootstrap_field form.port layout="horizontal" %}
 | 
			
		||||
    {% bootstrap_field form.platform layout="horizontal" %}
 | 
			
		||||
    {% bootstrap_field form.public_ip layout="horizontal" %}
 | 
			
		||||
 | 
			
		||||
    <div class="hr-line-dashed"></div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -54,7 +54,11 @@ class UserGrantedAssetsApi(ListAPIView):
 | 
			
		|||
            user = self.request.user
 | 
			
		||||
 | 
			
		||||
        for k, v in NodePermissionUtil.get_user_assets(user).items():
 | 
			
		||||
            k.system_users_granted = v
 | 
			
		||||
            if k.is_unixlike():
 | 
			
		||||
                system_users_granted = [s for s in v if s.protocol == 'ssh']
 | 
			
		||||
            else:
 | 
			
		||||
                system_users_granted = [s for s in v if s.protocol == 'rdp']
 | 
			
		||||
            k.system_users_granted = system_users_granted
 | 
			
		||||
            queryset.append(k)
 | 
			
		||||
        return queryset
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -118,9 +122,16 @@ class UserGrantedNodesWithAssetsApi(ListAPIView):
 | 
			
		|||
            user = get_object_or_404(User, id=user_id)
 | 
			
		||||
 | 
			
		||||
        nodes = NodePermissionUtil.get_user_nodes_with_assets(user)
 | 
			
		||||
        assets = {}
 | 
			
		||||
        for k, v in NodePermissionUtil.get_user_assets(user).items():
 | 
			
		||||
            if k.is_unixlike():
 | 
			
		||||
                system_users_granted = [s for s in v if s.protocol == 'ssh']
 | 
			
		||||
            else:
 | 
			
		||||
                system_users_granted = [s for s in v if s.protocol == 'rdp']
 | 
			
		||||
            assets[k] = system_users_granted
 | 
			
		||||
        for node, v in nodes.items():
 | 
			
		||||
            for asset in v['assets']:
 | 
			
		||||
                asset.system_users_granted = v['system_users']
 | 
			
		||||
                asset.system_users_granted = assets[asset]
 | 
			
		||||
            node.assets_granted = v['assets']
 | 
			
		||||
            queryset.append(node)
 | 
			
		||||
        return queryset
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -223,7 +223,7 @@ $(document).ready(function(){
 | 
			
		|||
        current_node = nodes[0];
 | 
			
		||||
        url += "?node=" + current_node.id;
 | 
			
		||||
    }
 | 
			
		||||
    window.open(url);
 | 
			
		||||
    window.open(url, '_self');
 | 
			
		||||
})
 | 
			
		||||
.on('click', '.btn-del', function () {
 | 
			
		||||
    var $this = $(this);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@ import uuid
 | 
			
		|||
 | 
			
		||||
from django.db import models
 | 
			
		||||
from django.utils.translation import ugettext_lazy as _
 | 
			
		||||
from django.utils import timezone
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
 | 
			
		||||
from users.models import User
 | 
			
		||||
| 
						 | 
				
			
			@ -127,6 +128,7 @@ class Session(models.Model):
 | 
			
		|||
    has_replay = models.BooleanField(default=False, verbose_name=_("Replay"))
 | 
			
		||||
    has_command = models.BooleanField(default=False, verbose_name=_("Command"))
 | 
			
		||||
    terminal = models.ForeignKey(Terminal, null=True, on_delete=models.CASCADE)
 | 
			
		||||
    date_last_active = models.DateTimeField(verbose_name=_("Date last active"), default=timezone.now)
 | 
			
		||||
    date_start = models.DateTimeField(verbose_name=_("Date start"))
 | 
			
		||||
    date_end = models.DateTimeField(verbose_name=_("Date end"), null=True)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,17 +1,27 @@
 | 
			
		|||
# -*- coding: utf-8 -*-
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
import datetime
 | 
			
		||||
 | 
			
		||||
from celery import shared_task
 | 
			
		||||
from django.utils import timezone
 | 
			
		||||
 | 
			
		||||
from common.celery import register_as_period_task, after_app_ready_start, \
 | 
			
		||||
    after_app_shutdown_clean
 | 
			
		||||
from .models import Status
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
CACHE_REFRESH_INTERVAL = 10
 | 
			
		||||
RUNNING = False
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Todo: 定期清理上报history
 | 
			
		||||
@shared_task
 | 
			
		||||
def clean_terminal_history():
 | 
			
		||||
    pass
 | 
			
		||||
@register_as_period_task(interval=3600)
 | 
			
		||||
@after_app_ready_start
 | 
			
		||||
@after_app_shutdown_clean
 | 
			
		||||
def delete_terminal_status_period():
 | 
			
		||||
    yesterday = timezone.now() - datetime.timedelta(days=1)
 | 
			
		||||
    Status.objects.filter(date_created__lt=yesterday).delete()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -75,6 +75,7 @@
 | 
			
		|||
    <th class="text-center">{% trans 'Terminal' %}</th>
 | 
			
		||||
    <th class="text-center">{% trans 'Command' %}</th>
 | 
			
		||||
    <th class="text-center">{% trans 'Date start' %}</th>
 | 
			
		||||
{#    <th class="text-center">{% trans 'Date last active' %}</th>#}
 | 
			
		||||
    <th class="text-center">{% trans 'Duration' %}</th>
 | 
			
		||||
    <th class="text-center">{% trans 'Action' %}</th>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
| 
						 | 
				
			
			@ -94,6 +95,7 @@
 | 
			
		|||
            <td class="text-center">{{ session.id | get_session_command_amount }}</td>
 | 
			
		||||
 | 
			
		||||
            <td class="text-center">{{ session.date_start }}</td>
 | 
			
		||||
{#            <td class="text-center">{{ session.date_last_active }}</td>#}
 | 
			
		||||
            <td class="text-center">{{ session.date_start|time_util_with_seconds:session.date_end }}</td>
 | 
			
		||||
            <td>
 | 
			
		||||
                {% if session.is_finished %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue