From d01e97f32ce37d0e32d95d91175719d3d871af65 Mon Sep 17 00:00:00 2001 From: Cp0204 Date: Fri, 22 Dec 2023 22:44:27 +0800 Subject: [PATCH 1/5] =?UTF-8?q?docker=E6=94=AF=E6=8C=81=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E7=AB=AF=E8=87=AA=E5=AE=9A=E4=B9=89ID=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 5 ++--- README.md | 40 ++++++++++++++++++++------------- rustdesk_server_api/settings.py | 17 ++++++++------ webui/views.py | 5 ++--- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index c5da823..37984c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,8 @@ RUN set -ex \ && rm -rf /var/cache/apk/* \ && cp -r ./db ./db_bak -ENV HOST=0.0.0.0 -ENV TZ=Asia/Shanghai -ENV CSRF_TRUSTED_ORIGINS="" +ENV HOST="0.0.0.0" +ENV TZ="Asia/Shanghai" EXPOSE 21114/tcp EXPOSE 21114/udp diff --git a/README.md b/README.md index 531f538..349693c 100644 --- a/README.md +++ b/README.md @@ -89,9 +89,8 @@ docker run 命令: docker run -d \ --name rustdesk-api-server \ -p 21114:21114 \ - -e HOST=0.0.0.0 \ - -e TZ=Asia/Shanghai \ - -e CSRF_TRUSTED_ORIGINS=http://yourdomain.com:21114 \ #修改CSRF_TRUSTED_ORIGINS为你的访问地址,SSL以https开头 + -e CSRF_TRUSTED_ORIGINS=http://yourdomain.com:21114 \ #防跨域信任来源,可选 + -e ID_SERVER=yourdomain.com \ #Web控制端使用的ID服务器 -v /yourpath/db:/rustdesk-api-server/db \ #修改/yourpath/db为你宿主机数据库挂载目录 -v /etc/timezone:/etc/timezone:ro \ -v /etc/localtime:/etc/localtime:ro \ @@ -109,9 +108,8 @@ services: container_name: rustdesk-api-server image: ghcr.io/kingmo888/rustdesk-api-server:latest environment: - - HOST=0.0.0.0 - - TZ=Asia/Shanghai - - CSRF_TRUSTED_ORIGINS=http://yourdomain.com:21114 #修改CSRF_TRUSTED_ORIGINS为你的访问地址,SSL以https开头 + - CSRF_TRUSTED_ORIGINS=http://yourdomain.com:21114 #防跨域信任来源,可选 + - ID_SERVER=yourdomain.com #Web控制端使用的ID服务器 volumes: - /yourpath/db:/rustdesk-api-server/db #修改/yourpath/db为你宿主机数据库挂载目录 - /etc/timezone:/etc/timezone:ro @@ -121,6 +119,18 @@ services: - "21114:21114" restart: unless-stopped ``` + +## 环境变量 + +| 变量名 | 参考值 | 备注 | +| ---- | ------- | ----------- | +| `HOST` | 默认 `0.0.0.0` | 绑定服务的IP | +| `TZ` | 默认 `Asia/Shanghai`,可选 | 时区 | +| `SECRET_KEY` | 可选,自定义一串随机字符 | 程序加密秘钥 | +| `CSRF_TRUSTED_ORIGINS` | 可选,默认关闭验证;如需开启填写你的访问地址 `http://yourdomain.com:21114`。 **如需关闭验证请删除此变量,而不是留空** | 防跨域信任来源 | +| `ID_SERVER` | 可选,默认为和API服务器同主机。可自定义如 `yourdomain.com` | Web控制端使用的ID服务器 | +| `DEBUG` | 可选,默认 `False` | 调试模式 | + ## 使用问题 - 管理员设置 @@ -134,7 +144,7 @@ services: - 连接速度慢 新版本Key模式链接速度慢,可以在服务端启动服务时,不要带参数的-k,此时,客户端也不能配置key。 - + - Web控制端启用 修改rustdesk_server_api/settings.py文件中ID_SERVER配置项,将ID服务器/中继服务器IP或域名填上。 @@ -142,26 +152,26 @@ services: - Web控制端一直转圈 web控制端目前仅支持非SSL模式,若webui为https访问,请将s去掉,否则ws连不上一直转圈。如:https://domain.com/webui,改为http://domain.com/webui - + - 后台操作登录或登出时:CSRF验证失败. 请求被中断. 这种操作大概率是docker配置+nginx反代+SSL的组合,要注意修改CSRF_TRUSTED_ORIGINS,如果是ssl那就是https开头,否则就是http。 -## [x] 开发计划 +## 开发计划 -- [x] 分享设备给其他已注册用户(v1.3) +- [x] 分享设备给其他已注册用户(v1.3+) > 说明:类似网盘url分享,url激活后可以获得某个或某组或某个标签下的设备 > 备注:其实web api作为中间件,可做的不多,更多功能还是需要修改客户端来实现,就不太值当了。 -- [x] 集成Web客户端形式 +- [x] 集成Web客户端形式(v1.4+) - > 将大神的web客户端集成进来,已集成。 [来源](https://www.52pojie.cn/thread-1708319-1-1.html) + > 将大神的web客户端集成进来,已集成。 [来源](https://www.52pojie.cn/thread-1708319-1-1.html) ## 其他相关工具 -[可以修改客户端ID的CMD脚本](https://github.com/abdullah-erturk/RustDesk-ID-Changer) +- [可以修改客户端ID的CMD脚本](https://github.com/abdullah-erturk/RustDesk-ID-Changer) -[rustdesk](https://github.com/rustdesk/rustdesk) +- [rustdesk](https://github.com/rustdesk/rustdesk) -[rustdesk-server](https://github.com/rustdesk/rustdesk-server) \ No newline at end of file +- [rustdesk-server](https://github.com/rustdesk/rustdesk-server) \ No newline at end of file diff --git a/rustdesk_server_api/settings.py b/rustdesk_server_api/settings.py index de53bed..3cfaf95 100644 --- a/rustdesk_server_api/settings.py +++ b/rustdesk_server_api/settings.py @@ -14,17 +14,20 @@ from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent -CSRF_TRUSTED_ORIGINS = [os.environ.get("CSRF_TRUSTED_ORIGINS", "http://www.baidu.com")] -SECURE_CROSS_ORIGIN_OPENER_POLICY = 'None' +if "CSRF_TRUSTED_ORIGINS" in os.environ: + CSRF_TRUSTED_ORIGINS = [os.environ["CSRF_TRUSTED_ORIGINS"]] +else: + CSRF_TRUSTED_ORIGINS = ["http://127.0.0.1:21114"] + SECURE_CROSS_ORIGIN_OPENER_POLICY = 'None' # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'j%7yjvygpih=6b%qf!q%&ixpn+27dngzdu-i3xh-^3xgy3^nnc' +SECRET_KEY = os.environ.get("SECRET_KEY", 'j%7yjvygpih=6b%qf!q%&ixpn+27dngzdu-i3xh-^3xgy3^nnc') # ID服务器IP或域名,一般与中继服务器,用于web client -ID_SERVER = '127.0.0.1' +ID_SERVER = os.environ.get("ID_SERVER", '') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = os.environ.get("DEBUG", False) DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' ALLOWED_HOSTS = ["*"] AUTH_USER_MODEL = 'api.UserProfile' #AppName.自定义user @@ -125,8 +128,8 @@ STATIC_URL = 'static/' if DEBUG: STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] - + else: - + STATIC_ROOT = os.path.join(BASE_DIR, 'static') # 新增 diff --git a/webui/views.py b/webui/views.py index 34f49ba..a201941 100644 --- a/webui/views.py +++ b/webui/views.py @@ -7,7 +7,6 @@ from django.conf import settings as _settings @login_required(login_url='/api/user_action?action=login') def index(request): - if _settings.ID_SERVER == '127.0.0.1': - html = "网站未配置ID_SERVER选项, 无法使用web client!
" + '返回' - return HttpResponse(html) + if _settings.ID_SERVER == '': + _settings.ID_SERVER = request.get_host().split(":")[0] return render(request, 'webui.html') From e6a4a0025031eca10405bd15e4ef9e32749733e8 Mon Sep 17 00:00:00 2001 From: Cp0204 Date: Sat, 23 Dec 2023 00:21:29 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=92=8C=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=9C=A8=E6=96=B0=E7=AA=97=E5=8F=A3=E6=89=93=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/templates/base.html | 70 +++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/api/templates/base.html b/api/templates/base.html index d39baa5..f28ab30 100644 --- a/api/templates/base.html +++ b/api/templates/base.html @@ -1,45 +1,47 @@ -{% load static %} +{% load static %} + + - -{% block title %}{% endblock %} - - - - -{% block link %}{% endblock %} + + {% block title %}{% endblock %} + + + + + {% block link %}{% endblock %} + - - + + //监听导航点击 + element.on('nav(demo)', function (elem) { + //console.log(elem) + layer.msg(elem.text()); + }); + }); + - +
+ {% block legend_name %}{% endblock %} +
+ {% block content %}{% endblock %} + \ No newline at end of file From 1549495b39e887fd3addbffc2f6ac6befd14c324 Mon Sep 17 00:00:00 2001 From: Cp0204 Date: Sat, 23 Dec 2023 00:21:59 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/templates/show_work.html | 173 +++++++++++++++-------------------- 1 file changed, 76 insertions(+), 97 deletions(-) diff --git a/api/templates/show_work.html b/api/templates/show_work.html index 992480f..074a873 100644 --- a/api/templates/show_work.html +++ b/api/templates/show_work.html @@ -1,118 +1,97 @@ {% extends "base.html" %} {% block title %}RustDesk WebUI{% endblock %} {% block legend_name %}综合屏{% endblock %} -{% block content %} +{% block content %}
-
+
设备统计 - 【用户名:{{u.username}}】
- - - - - - - - - - - - - - - - - - - - - - - - - - - {% for one in single_info %} - - - - - - - - - - - - - - - - - - {% endfor %} - -
客户端ID版本连接密码系统用户名计算机名别名平台系统CPU内存注册时间更新时间
{{one.rid}} {{one.version}} {{one.has_rhash}} {{one.username}} {{one.hostname}} {{one.alias}} {{one.platform}} {{one.os}} {{one.cpu}} {{one.memory}} {{one.create_time}} {{one.update_time}}
+ + + + + + + + + + + + + + + + + + + {% for one in single_info %} + + + + + + + + + + + + + + + {% endfor %} + +
客户端ID版本连接密码系统用户名计算机名别名平台系统CPU内存注册时间更新时间
{{one.rid}} {{one.version}}{{one.has_rhash}}{{one.username}}{{one.hostname}}{{one.alias}}{{one.platform}}{{one.os}}{{one.cpu}}{{one.memory}}{{one.create_time}}{{one.update_time}}
- - -{% if u.is_admin %} -
+ + {% if u.is_admin %} +
全部用户
- - - - - - - - - - - - - - - - - - - +
客户端ID所属用户版本系统用户名计算机名系统CPU内存注册时间更新时间
+ + + + + + + + + + + + + + + - - - - - {% for one in all_info %} - - - - - - - - - - - - - - - - {% endfor %} - -
客户端ID所属用户版本系统用户名计算机名系统CPU内存注册时间更新时间
{{one.rid}} {{one.rust_user}} {{one.version}} {{one.username}} {{one.hostname}} {{one.os}} {{one.cpu}} {{one.memory}} {{one.create_time}} {{one.update_time}}
+ {% for one in all_info %} + + {{one.rid}} + {{one.rust_user}} + {{one.version}} + {{one.username}} + {{one.hostname}} + {{one.os}} + {{one.cpu}} + {{one.memory}} + {{one.create_time}} + {{one.update_time}} + + {% endfor %} + +
-{% endif %} + {% endif %} -
+
+
{% endblock %} \ No newline at end of file From 98fb7c8511ac8fc95e0464a90cf4e53363658b53 Mon Sep 17 00:00:00 2001 From: Cp0204 Date: Sat, 23 Dec 2023 00:23:32 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E6=89=80=E5=B1=9E?= =?UTF-8?q?=E7=94=A8=E6=88=B7=20=E4=B8=8D=E6=98=BE=E7=A4=BA=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/views_front.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/api/views_front.py b/api/views_front.py index 3f48324..73441fd 100644 --- a/api/views_front.py +++ b/api/views_front.py @@ -65,7 +65,7 @@ def model_to_dict2(instance, fields=None, exclude=None, replace=None, default=No # 如果exclude 传递了,要进行判断 if exclude and f.name in exclude: continue - + key = f.name # 获取字段对应的数据 if type(f) == DateTimeField: @@ -122,7 +122,7 @@ def user_login(request): password = request.POST.get('password', '') if not username or not password: return JsonResponse({'code':0, 'msg':'出了点问题。'}) - + user = auth.authenticate(username=username,password=password) if user: auth.login(request, user) @@ -146,7 +146,7 @@ def user_register(request): info = '用户名不得小于3位' result['msg'] = info return JsonResponse(result) - + if len(password1)<8 or len(password1)>20: info = '密码长度不符合要求, 应在8~20位。' result['msg'] = info @@ -188,7 +188,7 @@ def get_single_info(uid): for rid in peers.keys(): peers[rid]['has_rhash'] = '是' if len(peers[rid]['rhash'])>1 else '否' - + return [v for k,v in peers.items()] def get_all_info(): @@ -199,7 +199,7 @@ def get_all_info(): user = UserProfile.objects.filter(Q(id=peer.uid)).first() device = devices.get(peer.rid, None) if device: - devices['rust_user'] = user.username + devices[peer.rid]['rust_user'] = user.username return [v for k,v in devices.items()] @login_required(login_url='/api/user_action?action=login') @@ -225,14 +225,14 @@ def check_sharelink_expired(sharelink): sharelink.is_expired = True sharelink.save() return True - + @login_required(login_url='/api/user_action?action=login') def share(request): peers = RustDeskPeer.objects.filter(Q(uid=request.user.id)) sharelinks = ShareLink.objects.filter(Q(uid=request.user.id) & Q(is_used=False) & Q(is_expired=False)) - - + + # 省资源:处理已过期请求,不主动定时任务轮询请求,在任意地方请求时,检查是否过期,过期则保存。 now = datetime.datetime.now() for sl in sharelinks: @@ -240,7 +240,7 @@ def share(request): sharelinks = ShareLink.objects.filter(Q(uid=request.user.id) & Q(is_used=False) & Q(is_expired=False)) peers = [{'id':ix+1, 'name':f'{p.rid}|{p.alias}'} for ix, p in enumerate(peers)] sharelinks = [{'shash':s.shash, 'is_used':s.is_used, 'is_expired':s.is_expired, 'create_time':s.create_time, 'peers':s.peers} for ix, s in enumerate(sharelinks)] - + if request.method == 'GET': url = request.build_absolute_uri() if url.endswith('share'): @@ -267,7 +267,7 @@ def share(request): peers_self_ids = [x.rid for x in RustDeskPeer.objects.filter(Q(uid=request.user.id))] peers_share = RustDeskPeer.objects.filter(rid__in=peers) peers_share_ids = [x.rid for x in peers_share] - + for peer in peers_share: if peer.rid in peers_self_ids: continue @@ -276,9 +276,9 @@ def share(request): peer.uid = request.user.id peer.save() msg += f"{peer.rid}," - + msg += '已被成功获取。' - + return render(request, 'msg.html', {'title':msg, 'msg':msg}) else: data = request.POST.get('data', '[]') @@ -296,4 +296,4 @@ def share(request): sharelink.save() return JsonResponse({'code':1, 'shash':sharelink.shash}) - + From 74f9a17c05d59fc40bf7a30f9e73586c812714c5 Mon Sep 17 00:00:00 2001 From: Cp0204 Date: Sat, 23 Dec 2023 00:24:18 +0800 Subject: [PATCH 5/5] Update README.md --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 349693c..dfa489b 100644 --- a/README.md +++ b/README.md @@ -127,8 +127,8 @@ services: | `HOST` | 默认 `0.0.0.0` | 绑定服务的IP | | `TZ` | 默认 `Asia/Shanghai`,可选 | 时区 | | `SECRET_KEY` | 可选,自定义一串随机字符 | 程序加密秘钥 | -| `CSRF_TRUSTED_ORIGINS` | 可选,默认关闭验证;如需开启填写你的访问地址 `http://yourdomain.com:21114`。 **如需关闭验证请删除此变量,而不是留空** | 防跨域信任来源 | -| `ID_SERVER` | 可选,默认为和API服务器同主机。可自定义如 `yourdomain.com` | Web控制端使用的ID服务器 | +| `CSRF_TRUSTED_ORIGINS` | 可选,默认关闭验证;
如需开启填写你的访问地址 `http://yourdomain.com:21114`
**如需关闭验证请删除此变量,而不是留空** | 防跨域信任来源 | +| `ID_SERVER` | 可选,默认为和API服务器同主机。
可自定义如 `yourdomain.com` | Web控制端使用的ID服务器 | | `DEBUG` | 可选,默认 `False` | 调试模式 | ## 使用问题 @@ -145,13 +145,15 @@ services: 新版本Key模式链接速度慢,可以在服务端启动服务时,不要带参数的-k,此时,客户端也不能配置key。 -- Web控制端启用 +- Web控制端配置 - 修改rustdesk_server_api/settings.py文件中ID_SERVER配置项,将ID服务器/中继服务器IP或域名填上。 + - 设置ID_SERVER环境变量,或修改rustdesk_server_api/settings.py文件中ID_SERVER配置项,将ID服务器/中继服务器IP或域名填上。 - Web控制端一直转圈 - web控制端目前仅支持非SSL模式,若webui为https访问,请将s去掉,否则ws连不上一直转圈。如:https://domain.com/webui,改为http://domain.com/webui + - 检查ID服务器填写是否正确 + + - Web控制端目前仅支持非SSL模式,若webui为https访问,请将s去掉,否则ws连不上一直转圈。如:https://domain.com/webui,改为http://domain.com/webui - 后台操作登录或登出时:CSRF验证失败. 请求被中断.