From 051ea1e504a871b7f19e0c9971f3a7e466bf8115 Mon Sep 17 00:00:00 2001
From: kingmo888 <17401091+kingmo888@users.noreply.github.com>
Date: Wed, 6 Mar 2024 21:31:57 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=A6=BB=E7=AE=A1=E7=90=86=E5=91=98?=
=?UTF-8?q?=E8=AE=BE=E5=A4=87=E9=A1=B5=E9=9D=A2=E3=80=81=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E5=88=86=E9=A1=B5=E3=80=81=E5=A2=9E=E5=8A=A0excel=E5=AF=BC?=
=?UTF-8?q?=E5=87=BA=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 4 ++-
README.md | 8 +++---
api/templates/base.html | 4 +++
api/templates/show_work.html | 50 ++++++++++++++++++++++++++++++++---
api/urls.py | 5 ++--
api/views_front.py | 45 ++++++++++++++++++++++++++-----
db/db.sqlite3 | Bin 155648 -> 155648 bytes
7 files changed, 100 insertions(+), 16 deletions(-)
diff --git a/.gitignore b/.gitignore
index 3a6cd5f..7478fcd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,4 +23,6 @@ dist
dist-
dist_py38
-LICENSE.rst
\ No newline at end of file
+LICENSE.rst
+
+db/test_db.sqlite3
\ No newline at end of file
diff --git a/README.md b/README.md
index 144a40d..659479d 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
一个 python 实现的 Rustdesk API 接口,支持 WebUI 管理
-
+
@@ -175,9 +175,11 @@ services:
> 通过配置方式,对过期超过指定时间的设备清理或过滤。
-- [ ] 首屏拆分为用户列表页与管理员列表页并增加分页。
+- [x] 首屏拆分为用户列表页与管理员列表页并增加分页。
-- [ ] 支持信息导出到为xlsx文件。
+- [x] 支持信息导出到为xlsx文件。
+
+ > 支持管理员在【所有设备】页面导出所有设备信息。
## 其他相关工具
diff --git a/api/templates/base.html b/api/templates/base.html
index 755f198..96f5ae8 100644
--- a/api/templates/base.html
+++ b/api/templates/base.html
@@ -28,6 +28,10 @@
- 首页
+ {% if u.is_admin %}
+ - 所有设备
+
+ {% endif %}
- 分享
- 网页控制
diff --git a/api/templates/show_work.html b/api/templates/show_work.html
index 074a873..d7dd16d 100644
--- a/api/templates/show_work.html
+++ b/api/templates/show_work.html
@@ -4,6 +4,7 @@
{% block content %}
+ {% if not show_all %}
@@ -26,7 +27,7 @@
- {% for one in single_info %}
+ {% for one in page_obj %}
| {{one.rid}} |
{{one.version}} |
@@ -47,11 +48,32 @@
+
+
+ {% if page_obj.has_previous %}
+
+
+ {% endif %}
+ {% if page_obj.paginator.num_pages > 1 %}
+
+ 页码 {{ page_obj.number }} / {{ page_obj.paginator.num_pages }}
+
+ {% endif %}
+ {% if page_obj.has_next %}
+
+
+ {% endif %}
+
+
+ {% endif %}
- {% if u.is_admin %}
+
+ {% if u.is_admin and show_all %}
-
+
@@ -70,7 +92,7 @@
- {% for one in all_info %}
+ {% for one in page_obj %}
| {{one.rid}} |
{{one.rust_user}} |
@@ -89,8 +111,28 @@
+
+
+ {% if page_obj.has_previous %}
+
+
+ {% endif %}
+ {% if page_obj.paginator.num_pages > 1 %}
+
+ 页码 {{ page_obj.number }} / {{ page_obj.paginator.num_pages }}
+
+ {% endif %}
+ {% if page_obj.has_next %}
+
+
+ {% endif %}
+
+
{% endif %}
+
+
+
diff --git a/api/urls.py b/api/urls.py
index f432aca..bb4cee3 100644
--- a/api/urls.py
+++ b/api/urls.py
@@ -18,6 +18,7 @@ urlpatterns = [
url(r'^heartbeat',views.heartbeat),
#url(r'^register',views.register),
url(r'^user_action',views.user_action), # 前端
- url(r'^work',views.work), # 前端
- url(r'^share',views.share), # 前端
+ url(r'^work',views.work), # 前端
+ url(r'^down_peers$',views.down_peers), # 前端
+ url(r'^share',views.share), # 前端
]
diff --git a/api/views_front.py b/api/views_front.py
index 0d1e754..93f0bb5 100644
--- a/api/views_front.py
+++ b/api/views_front.py
@@ -8,6 +8,8 @@ from django.contrib.auth.decorators import login_required
from django.contrib import auth
from api.models import RustDeskPeer, RustDesDevice, UserProfile, ShareLink
from django.forms.models import model_to_dict
+from django.core.paginator import Paginator
+from django.http import HttpResponse
from itertools import chain
from django.db.models.fields import DateTimeField, DateField, CharField, TextField
@@ -18,6 +20,9 @@ import time
import hashlib
import sys
+from io import BytesIO
+import xlwt
+
salt = 'xiaomo'
EFFECTIVE_SECONDS = 7200
@@ -213,17 +218,45 @@ def get_all_info():
@login_required(login_url='/api/user_action?action=login')
def work(request):
-
username = request.user
u = UserProfile.objects.get(username=username)
- single_info = get_single_info(u.id)
+
+ show_type = request.GET.get('show_type', '')
+ show_all = True if show_type == 'admin' and u.is_admin else False
+ paginator = Paginator(get_all_info(), 15) if show_type == 'admin' and u.is_admin else Paginator(get_single_info(u.id), 15)
+ page_number = request.GET.get('page')
+ page_obj = paginator.get_page(page_number)
+ return render(request, 'show_work.html', {'u':u, 'show_all':show_all, 'page_obj':page_obj})
+@login_required(login_url='/api/user_action?action=login')
+def down_peers(request):
+ username = request.user
+ u = UserProfile.objects.get(username=username)
+
+ if not u.is_admin:
+ print(u.is_admin)
+ return HttpResponseRedirect('/api/work')
+
all_info = get_all_info()
- print(all_info)
-
- return render(request, 'show_work.html', {'single_info':single_info, 'all_info':all_info, 'u':u})
-
+ f = xlwt.Workbook(encoding='utf-8')
+ sheet1 = f.add_sheet(u'设备信息表', cell_overwrite_ok=True)
+ all_fields = [x.name for x in RustDesDevice._meta.get_fields()]
+ all_fields.append('rust_user')
+ for i, one in enumerate(all_info):
+ for j, name in enumerate(all_fields):
+ if i == 0:
+ # 写入列名
+ sheet1.write(i, j, name)
+ sheet1.write(i+1, j, one.get(name, '-'))
+ sio = BytesIO()
+ f.save(sio)
+ sio.seek(0)
+ response = HttpResponse(sio.getvalue(), content_type='application/vnd.ms-excel')
+ response['Content-Disposition'] = 'attachment; filename=DeviceInfo.xls'
+ response.write(sio.getvalue())
+ return response
+
def check_sharelink_expired(sharelink):
now = datetime.datetime.now()
if sharelink.create_time > now:
diff --git a/db/db.sqlite3 b/db/db.sqlite3
index 87c8699a67ce37926d808659b01a2be8d7968a24..7576dcb3384218712617bb04139cd641f5e839e4 100644
GIT binary patch
delta 568
zcmaKouTBIp5QmpbR-6Hn<3e(G`^SLWGHs{r^c3e11Vae&vI%ArxFA3g!Ucgv%md)S
z@&Y8M@K_!K#RE`zt)O-N`pwL5maG19)qnpU?dS$je0)JQ?(jrII9I!%BfNu>B}
z>;|!c;W&O7!$bV8j0S_SooBmyv-aYuTL6HZcZ=?(YcCZjY#=tIK~Gw2<=G$@*WLgB
zL3kZ59&P5?@O;+Z^2wx$h6dp@5F$TML;|dqo`An5GD-u&09eVx!X|7KwOXU;>m3
zIf35_p8#+gL#f~5U>%?r-h~|-b|oZ$yhLmHu8gJ)h9j+|;*U}$hDC?UbFYfV4F)jkt-eHW_yHT^PGaR#>)Ax~03<}OdrR^fE>w;sf^ti|q
h14ROh-WR@cxHBMtq94V6BE;u{*vImz+;}b9hre4?escf-