Skip to content

Commit

Permalink
add ip_address for model resolves #137, resolves #15
Browse files Browse the repository at this point in the history
  • Loading branch information
kingmo888 committed Sep 9, 2024
1 parent 3978cf6 commit 7b8951d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<p align="center">
<i>一个 python 实现的 Rustdesk API 接口,支持 WebUI 管理</i>
<br/>
<img src ="https://img.shields.io/badge/Version-1.5.1-blueviolet.svg"/>
<img src ="https://img.shields.io/badge/Version-1.5.2-blueviolet.svg"/>
<img src ="https://img.shields.io/badge/Python-3.7|3.8|3.9|3.10|3.11-blue.svg" />
<img src ="https://img.shields.io/badge/Django-3.2+|4.x-yelow.svg" />
<br/>
Expand Down
18 changes: 18 additions & 0 deletions api/migrations/0008_rustdesdevice_ip_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2024-09-09 10:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0007_alter_rustdesdevice_options_and_more'),
]

operations = [
migrations.AddField(
model_name='rustdesdevice',
name='ip_address',
field=models.CharField(blank=True, max_length=60, verbose_name='IP'),
),
]
51 changes: 30 additions & 21 deletions api/models_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.contrib import admin
from django.utils.translation import gettext as _


class RustDeskToken(models.Model):
''' Token
'''
Expand All @@ -12,35 +13,38 @@ class RustDeskToken(models.Model):
uuid = models.CharField(verbose_name=_('uuid'), max_length=60)
access_token = models.CharField(verbose_name=_('access_token'), max_length=60, blank=True)
create_time = models.DateTimeField(verbose_name=_('登录时间'), auto_now_add=True)
#expire_time = models.DateTimeField(verbose_name='过期时间')
# expire_time = models.DateTimeField(verbose_name='过期时间')

class Meta:
ordering = ('-username',)
verbose_name = "Token"
verbose_name_plural = _("Token列表")
verbose_name_plural = _("Token列表")


class RustDeskTokenAdmin(admin.ModelAdmin):
list_display = ('username', 'uid')
search_fields = ('username', 'uid')
list_filter = ('create_time', ) #过滤器
list_filter = ('create_time', ) # 过滤器


class RustDeskTag(models.Model):
''' Tags
'''
uid = models.CharField(verbose_name=_('所属用户ID'), max_length=16)
tag_name = models.CharField(verbose_name=_('标签名称'), max_length=60)
tag_color = models.CharField(verbose_name=_('标签颜色'), max_length=60, blank=True)

class Meta:
ordering = ('-uid',)
verbose_name = "Tags"
verbose_name_plural = _("Tags列表")


class RustDeskTagAdmin(admin.ModelAdmin):
list_display = ('tag_name', 'uid', 'tag_color')
search_fields = ('tag_name', 'uid')
list_filter = ('uid', )


class RustDeskPeer(models.Model):
''' Pees
Expand All @@ -53,19 +57,19 @@ class RustDeskPeer(models.Model):
platform = models.CharField(verbose_name=_('平台'), max_length=30)
tags = models.CharField(verbose_name=_('标签'), max_length=30)
rhash = models.CharField(verbose_name=_('设备链接密码'), max_length=60)

class Meta:
ordering = ('-username',)
verbose_name = "Peers"
verbose_name_plural = _("Peers列表" )
verbose_name_plural = _("Peers列表")


class RustDeskPeerAdmin(admin.ModelAdmin):
list_display = ('rid', 'uid', 'username', 'hostname', 'platform', 'alias', 'tags')
search_fields = ('deviceid', 'alias')
list_filter = ('rid', 'uid', )


class RustDesDevice(models.Model):
rid = models.CharField(verbose_name=_('客户端ID'), max_length=60, blank=True)
cpu = models.CharField(verbose_name='CPU', max_length=100)
Expand All @@ -75,21 +79,24 @@ class RustDesDevice(models.Model):
uuid = models.CharField(verbose_name='uuid', max_length=100)
username = models.CharField(verbose_name=_('系统用户名'), max_length=100, blank=True)
version = models.CharField(verbose_name=_('客户端版本'), max_length=100)
ip_address = models.CharField(verbose_name=_('IP'), max_length=60, blank=True)
create_time = models.DateTimeField(verbose_name=_('设备注册时间'), auto_now_add=True)
update_time = models.DateTimeField(verbose_name=('设备更新时间'), auto_now=True, blank=True)

class Meta:
ordering = ('-rid',)
verbose_name = _("设备")
verbose_name_plural = _("设备列表" )

verbose_name_plural = _("设备列表")


class RustDesDeviceAdmin(admin.ModelAdmin):
list_display = ('rid', 'hostname', 'memory', 'uuid', 'version', 'create_time', 'update_time')
search_fields = ('hostname', 'memory')
list_filter = ('rid', )


class ConnLog(models.Model):
id = models.IntegerField(verbose_name='ID',primary_key=True)
id = models.IntegerField(verbose_name='ID', primary_key=True)
action = models.CharField(verbose_name='Action', max_length=20, null=True)
conn_id = models.CharField(verbose_name='Connection ID', max_length=10, null=True)
from_ip = models.CharField(verbose_name='From IP', max_length=30, null=True)
Expand All @@ -100,13 +107,15 @@ class ConnLog(models.Model):
session_id = models.CharField(verbose_name='Session ID', max_length=60, null=True)
uuid = models.CharField(verbose_name='uuid', max_length=60, null=True)


class ConnLogAdmin(admin.ModelAdmin):
list_display = ('id', 'action', 'conn_id', 'from_ip', 'from_id', 'rid', 'conn_start', 'conn_end', 'session_id', 'uuid')
search_fields = ('from_ip', 'rid')
list_filter = ('id', 'from_ip', 'from_id', 'rid', 'conn_start', 'conn_end')


class FileLog(models.Model):
id = models.IntegerField(verbose_name='ID',primary_key=True)
id = models.IntegerField(verbose_name='ID', primary_key=True)
file = models.CharField(verbose_name='Path', max_length=500)
remote_id = models.CharField(verbose_name='Remote ID', max_length=20, default='0')
user_id = models.CharField(verbose_name='User ID', max_length=20, default='0')
Expand All @@ -115,11 +124,13 @@ class FileLog(models.Model):
direction = models.IntegerField(verbose_name='Direction', default=0)
logged_at = models.DateTimeField(verbose_name='Logged At', null=True)


class FileLogAdmin(admin.ModelAdmin):
list_display = ('id', 'file', 'remote_id', 'user_id', 'user_ip', 'filesize', 'direction', 'logged_at')
search_fields = ('file', 'remote_id', 'user_id', 'user_ip')
list_filter = ('id', 'file', 'remote_id', 'user_id', 'user_ip', 'filesize', 'direction', 'logged_at')


class ShareLink(models.Model):
''' 分享链接
'''
Expand All @@ -129,16 +140,14 @@ class ShareLink(models.Model):
is_used = models.BooleanField(verbose_name=_('是否使用'), default=False)
is_expired = models.BooleanField(verbose_name=_('是否过期'), default=False)
create_time = models.DateTimeField(verbose_name=_('生成时间'), auto_now_add=True)



class Meta:
ordering = ('-create_time',)
verbose_name = _("分享链接")
verbose_name_plural = _("链接列表" )
verbose_name_plural = _("链接列表")


class ShareLinkAdmin(admin.ModelAdmin):
list_display = ('shash', 'uid', 'peers', 'is_used', 'is_expired', 'create_time')
search_fields = ('peers', )
list_filter = ('is_used', 'uid', 'is_expired' )
list_filter = ('is_used', 'uid', 'is_expired')
14 changes: 9 additions & 5 deletions api/templates/show_work.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<th>{{ "系统" | translate }}</th>
<th>{{ "CPU" | translate }}</th>
<th>{{ "内存" | translate }}</th>
<th>{{ "IP" | translate }}</th>
<th>{{ "注册时间" | translate }}</th>
<th>{{ "更新时间" | translate }}</th>
<th>{{ "状态" | translate }}</th>
Expand All @@ -41,6 +42,7 @@
<td>{{one.os}}</td>
<td>{{one.cpu}}</td>
<td>{{one.memory}}</td>
<td>{{one.ip_address}}</td>
<td>{{one.create_time}}</td>
<td>{{one.update_time}}</td>
<td>{{one.status}} </td>
Expand All @@ -67,10 +69,10 @@
<button class="layui-btn" ><a href="?page={{ page_obj.paginator.num_pages }}">{{ "尾页" | translate }} &raquo;</a></button>
{% endif %}
</span>
</div>
</div>
{% endif %}


{% if u.is_admin and show_all %}
<div class="layui-col-md15">
<div class="layui-card">
Expand All @@ -89,6 +91,7 @@
<th>{{ "系统" | translate }}</th>
<th>{{ "CPU" | translate }}</th>
<th>{{ "内存" | translate }}</th>
<th>{{ "IP" | translate }}</th>
<th>{{ "注册日期" | translate }}</th>
<th>{{ "更新时间" | translate }}</th>
<th>{{ "状态" | translate }}</th>
Expand All @@ -106,6 +109,7 @@
<td>{{one.os}} </td>
<td>{{one.cpu}} </td>
<td>{{one.memory}} </td>
<td>{{one.ip_address}}</td>
<td>{{one.create_time}} </td>
<td>{{one.update_time}} </td>
<td>{{one.status}} </td>
Expand All @@ -132,11 +136,11 @@
<button class="layui-btn" ><a href="?show_type=admin&page={{ page_obj.paginator.num_pages }}">{{ "尾页" | translate }} &raquo;</a></button>
{% endif %}
</span>
</div>
</div>
{% endif %}




</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion api/views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def sysinfo(request):
if request.method == 'GET':
result['error'] = _('错误的提交方式!')
return JsonResponse(result)

client_ip = request.META.get('REMOTE_ADDR')
postdata = json.loads(request.body)
device = RustDesDevice.objects.filter(Q(rid=postdata['id']) & Q(uuid=postdata['uuid'])).first()
if not device:
Expand All @@ -239,6 +239,7 @@ def sysinfo(request):
username=postdata.get('username', '-'),
uuid=postdata['uuid'],
version=postdata['version'],
ip_address=client_ip
)
device.save()
else:
Expand All @@ -254,6 +255,8 @@ def heartbeat(request):
postdata = json.loads(request.body)
device = RustDesDevice.objects.filter(Q(rid=postdata['id']) & Q(uuid=postdata['uuid'])).first()
if device:
client_ip = request.META.get('REMOTE_ADDR')
device.ip_address = client_ip
device.save()
# token保活
create_time = datetime.datetime.now() + datetime.timedelta(seconds=EFFECTIVE_SECONDS)
Expand Down
Binary file modified db/db.sqlite3
Binary file not shown.

0 comments on commit 7b8951d

Please sign in to comment.