Skip to content

Commit c3ace56

Browse files
author
lizenghai
committed
first commit for RustDeskApiServer
0 parents  commit c3ace56

File tree

315 files changed

+64478
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

315 files changed

+64478
-0
lines changed

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Python
2+
*.pyc
3+
*.pyo
4+
*.spec
5+
*.c
6+
*.pyd
7+
*.so
8+
test.py
9+
__pycache__
10+
11+
# Documents
12+
test
13+
14+
15+
# Files
16+
*.bat
17+
server.ico
18+
19+
# Build
20+
build
21+
dist

README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
## Rustdesk Api接口介绍
2+
<p align="center">
3+
<img src ="https://img.shields.io/badge/version-1.0.0-blueviolet.svg"/>
4+
<img src ="https://img.shields.io/badge/platform-windows|linux-green.svg"/>
5+
<img src ="https://img.shields.io/badge/python-3.7|3.8|3.9|3.10|3.11-blue.svg" />
6+
<img src ="https://img.shields.io/badge/Django-3.2+|4.x-yelow.svg" />
7+
</p>
8+
9+
### 缘起
10+
看了市面上各类RustDesk WEB API版本,或多或少的存在一些问题,比如说,需要通过url注册、新版客户端某些接口不支持、无法方便的修改密码等不足,因此博采众长,撸一个自己喜欢的版本来用。在此要感谢论坛及github的各位朋友写的接口,省去了我抓包找接口的时间。
11+
![主页面](/images/front_main.png)
12+
13+
### 功能特点
14+
- 支持前台网页自主注册和登录。
15+
- 注册页与登录页:
16+
17+
<img src="images/front_reg.png" width="45%" />
18+
<img src="images/front_login.png" width="45%" />
19+
20+
- 支持前台展示设备信息,分为管理员版、用户版。
21+
- 支持自定义别名(备注)。
22+
- 支持后台管理。
23+
- 支持彩色标签。
24+
25+
<img src="images/rust_books.png" width="45%" />
26+
27+
- 支持设备在线统计。
28+
- 支持设备密码保存。
29+
- 利用心跳接口自动管理token并保活。
30+
- 支持分享设备给其他用户(本功能暂未实现)。
31+
32+
后台主页:
33+
<img src="images/admin_main.png" width="60%" />
34+
35+
### 管理员设置
36+
当数据库中不存在账户时,第一个注册的账户直接获取超级管理员权限,之后注册账户为普通账户。
37+
38+
### 其他说明
39+
设备信息
40+
经测试,客户端会在非绿色版模式下,安装为服务的模式中,定时发送设备信息到api接口,
41+
所以如果想要设备信息,需要安装rustdesk客户端并启动服务。
42+
43+
### 连接速度慢
44+
新版本Key模式链接速度慢,可以在服务端启动服务时,不要带参数的-k,此时,客户端也不能配置key
45+
46+
47+
48+
### 获取方法
49+
50+
#### 开箱即用版
51+
52+
Window独立打包版,无需安装环境,直接运行`启动.bat`即可。请前往release下载。仅支持windows
53+
独立版截图:![window独立绿色版](/images/windows_run.png =60x)
54+
55+
56+
57+
#### 代码版本
58+
59+
将代码克隆到本地后,请先安装依赖:
60+
`pip install -r requirements.txt`
61+
62+
确保依赖安装正确后,执行:
63+
`python manage.py runserver 0.0.0.0:21114` 端口号请自行修改。
64+
65+
此时即可使用`http://本机IP:端口`的形式来访问啦。
66+
67+
支持Django3及Django4+
68+
注意,如果cengtos配置时,Django4会因为系统的sqlite3版本过低而出问题,请修改依赖库中的文件,路径:
69+
`xxxx/Lib/site-packages/django/db/backends/sqlite3/base.py` (这是例子,根据情况自行查找包所在地址)
70+
71+
72+
修改内容:
73+
```
74+
# from sqlite3 import dbapi2 as Database #(注释掉这行)
75+
from pysqlite3 import dbapi2 as Database # 启用pysqlite3
76+
```
77+
78+
79+
### 计划开发
80+
81+
1、分享设备给其他已注册用户
82+
83+
说明:类似网盘url分享,url激活后可以获得某个或某组或某个标签下的设备
84+
备注:其实web api作为中间件,可做的不多,更多功能还是需要修改客户端来实现,就不太值当了。

api/__init__.py

Whitespace-only changes.

api/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .admin_user import *

api/admin_user.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# cython:language_level=3
2+
from django.contrib import admin
3+
from api import models
4+
from django import forms
5+
from django.contrib.auth.models import Group
6+
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
7+
from django.contrib.auth.forms import ReadOnlyPasswordHashField
8+
9+
10+
11+
class UserCreationForm(forms.ModelForm):
12+
"""A form for creating new users. Includes all the required
13+
fields, plus a repeated password."""
14+
password1 = forms.CharField(label='密码', widget=forms.PasswordInput)
15+
password2 = forms.CharField(label='再次输入密码', widget=forms.PasswordInput)
16+
17+
class Meta:
18+
model = models.UserProfile
19+
fields = ('username','is_active','is_admin')
20+
21+
def clean_password2(self):
22+
# Check that the two password entries match
23+
password1 = self.cleaned_data.get("password1")
24+
password2 = self.cleaned_data.get("password2")
25+
if password1 and password2 and password1 != password2:
26+
raise forms.ValidationError("密码校验失败,两次密码不一致。")
27+
return password2
28+
29+
30+
def save(self, commit=True):
31+
# Save the provided password in hashed format
32+
user = super(UserCreationForm, self).save(commit=False)
33+
user.set_password(self.cleaned_data["password1"])
34+
if commit:
35+
user.save()
36+
return user
37+
38+
39+
class UserChangeForm(forms.ModelForm):
40+
"""A form for updating users. Includes all the fields on
41+
the user, but replaces the password field with admin's
42+
password hash display field.
43+
"""
44+
password = ReadOnlyPasswordHashField(label=("密码Hash值"), help_text=("<a href=\"../password/\">点击修改密码</a>."))
45+
class Meta:
46+
model = models.UserProfile
47+
fields = ('username', 'is_active', 'is_admin')
48+
49+
def clean_password(self):
50+
# Regardless of what the user provides, return the initial value.
51+
# This is done here, rather than on the field, because the
52+
# field does not have access to the initial value
53+
return self.initial["password"]
54+
#return self.initial["password"]
55+
56+
def save(self, commit=True):
57+
# Save the provided password in hashed format
58+
user = super(UserChangeForm, self).save(commit=False)
59+
60+
if commit:
61+
user.save()
62+
return user
63+
64+
class UserAdmin(BaseUserAdmin):
65+
# The forms to add and change user instances
66+
form = UserChangeForm
67+
add_form = UserCreationForm
68+
password = ReadOnlyPasswordHashField(label=("密码Hash值"), help_text=("<a href=\"../password/\">点击修改密码</a>."))
69+
# The fields to be used in displaying the User model.
70+
# These override the definitions on the base UserAdmin
71+
# that reference specific fields on auth.User.
72+
list_display = ('username', 'rid')
73+
list_filter = ('is_admin', 'is_active')
74+
fieldsets = (
75+
('基本信息', {'fields': ('username', 'password', 'is_active', 'is_admin', 'rid', 'uuid', 'deviceInfo',)}),
76+
77+
)
78+
readonly_fields = ( 'rid', 'uuid')
79+
add_fieldsets = (
80+
(None, {
81+
'classes': ('wide',),
82+
'fields': ('username', 'is_active', 'is_admin', 'password1', 'password2', )}
83+
),
84+
)
85+
86+
search_fields = ('username', )
87+
ordering = ('username',)
88+
filter_horizontal = ()
89+
90+
91+
admin.site.register(models.UserProfile, UserAdmin)
92+
admin.site.register(models.RustDeskToken, models.RustDeskTokenAdmin)
93+
admin.site.register(models.RustDeskTag, models.RustDeskTagAdmin)
94+
admin.site.register(models.RustDeskPeer, models.RustDeskPeerAdmin)
95+
admin.site.register(models.RustDesDevice, models.RustDesDeviceAdmin)
96+
admin.site.unregister(Group)
97+
admin.site.site_header = 'RustDesk自建Web'
98+
admin.site.site_title = '未定义'

api/apps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class ApiConfig(AppConfig):
5+
name = 'api'

0 commit comments

Comments
 (0)