Skip to content

Commit

Permalink
V1.2 增加创建分享链接功能
Browse files Browse the repository at this point in the history
  • Loading branch information
kingmo888 committed Dec 14, 2023
1 parent 0f11646 commit 66a65b7
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 62 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p align="center">
<i>一个 python 实现的 Rustdesk API 接口,支持 WebUI 管理</i>
<br/>
<img src ="https://img.shields.io/badge/Version-1.1-blueviolet.svg"/>
<img src ="https://img.shields.io/badge/Version-1.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 Expand Up @@ -137,7 +137,7 @@ services:
## 开发计划
- [ ] 分享设备给其他已注册用户
- [-] 分享设备给其他已注册用户
> 说明:类似网盘url分享,url激活后可以获得某个或某组或某个标签下的设备
> 备注:其实web api作为中间件,可做的不多,更多功能还是需要修改客户端来实现,就不太值当了。
Expand Down
1 change: 1 addition & 0 deletions api/admin_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class UserAdmin(BaseUserAdmin):
admin.site.register(models.RustDeskTag, models.RustDeskTagAdmin)
admin.site.register(models.RustDeskPeer, models.RustDeskPeerAdmin)
admin.site.register(models.RustDesDevice, models.RustDesDeviceAdmin)
admin.site.register(models.ShareLink, models.ShareLinkAdmin)
admin.site.unregister(Group)
admin.site.site_header = 'RustDesk自建Web'
admin.site.site_title = '未定义'
30 changes: 29 additions & 1 deletion api/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.7 on 2023-12-04 21:05
# Generated by Django 4.2.7 on 2023-12-14 12:08

from django.db import migrations, models

Expand Down Expand Up @@ -138,6 +138,34 @@ class Migration(migrations.Migration):
"ordering": ("-username",),
},
),
migrations.CreateModel(
name="ShareLink",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("uid", models.CharField(max_length=16, verbose_name="用户ID")),
("shash", models.CharField(max_length=60, verbose_name="链接Key")),
("peers", models.CharField(max_length=20, verbose_name="机器ID列表")),
("is_used", models.BooleanField(default=False, verbose_name="是否使用")),
("is_expired", models.BooleanField(default=False, verbose_name="是否过期")),
(
"create_time",
models.DateTimeField(auto_now_add=True, verbose_name="生成时间"),
),
],
options={
"verbose_name": "分享链接",
"verbose_name_plural": "链接列表",
"ordering": ("-create_time",),
},
),
migrations.CreateModel(
name="UserProfile",
fields=[
Expand Down
26 changes: 25 additions & 1 deletion api/models_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,28 @@ class RustDesDeviceAdmin(admin.ModelAdmin):
list_display = ('rid', 'hostname', 'memory', 'uuid', 'version', 'create_time', 'update_time')
search_fields = ('hostname', 'memory')
list_filter = ('rid', )




class ShareLink(models.Model):
''' 分享链接
'''
uid = models.CharField(verbose_name='用户ID', max_length=16)
shash = models.CharField(verbose_name='链接Key', max_length=60)
peers = models.CharField(verbose_name='机器ID列表', max_length=20)
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 = "链接列表"


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' )
44 changes: 44 additions & 0 deletions api/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% load static %}<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{% block title %}{% endblock %}</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="{% static 'layui/css/layui.css' %}">
{% block link %}{% endblock %}
</head>
<body>
<script src={% static "layui/layui.js" %}></script>
<script>
layui.use('element', function(){
var element = layui.element; //导航的hover效果二级菜单等功能需要依赖element模块

//监听导航点击
element.on('nav(demo)', function(elem){
//console.log(elem)
layer.msg(elem.text());
});
});
</script>

<ul class="layui-nav">
<li class="layui-nav-item"><a href="/">首页</a></li>
<li class="layui-nav-item"><a href="/api/share">分享</a></li>

{% if u.is_admin %}
<li class="layui-nav-item"><a href="/admin">管理后台</a>
</li>
{% endif %}

</ul>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
<legend>{% block legend_name %}{% endblock %}</legend>
</fieldset>

{% block content %}{% endblock %}

</body>
</html>
12 changes: 12 additions & 0 deletions api/templates/msg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% block title %}{{title}}{% endblock %}
{% block legend_name %}信息{% endblock %}
{% block content %}
<div style="padding: 20px; background-color: #F2F2F2;">
<div class="layui-row layui-col-space15">
{% autoescape off %}
{{msg}}
{% endautoescape %}
</div></div>

{% endblock %}
105 changes: 105 additions & 0 deletions api/templates/share.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@

{% extends "base.html" %}{% load static %}
{% block title %}分享机器{% endblock %}
{% block link %}<link rel="stylesheet" href="{% static 'layui/css/style.css' %}">{% endblock %}
{% block legend_name %}分享机器给其他用户{% endblock %}
{% block content %}


<div class="layui-container">
<div class="layui-card layui-col-md3-offset2">
<div class="layui-card-header">请将要分享的机器调整到右侧</div>
<div id="showdevice"></div>
<button id="create" type="button" class="layui-btn padding-5" lay-on="getData">生成分享链接</button>
</div>
<div class="layui-card">1链接有效期为15分钟切勿随意分享给他人</div>
<div class="layui-card">2所分享的机器被分享人享有相同的权限如果机器设置了保存密码被分享人也可以直接连接</div>
<div class="layui-card">3为保障安全链接有效期为15分钟链接仅有效1次链接一旦被非分享人的登录用户访问分享生效后续访问链接失效</div>

<div class="layui-card layui-col-md6-offset1">
<table class="layui-table">
<colgroup>
<col width="30">
<col width="100">
<col width="300">
<col>
</colgroup>
<thead>
<tr>
<th>链接地址</th>
<th>创建时间</th>
<th>ID列表</th>
</tr>
</thead>
<tbody>

{% for one in sharelinks %}
<tr>
<td>{{one.shash}} </td>
<td>{{one.create_time}} </td>
<td>{{one.peers}} </td>

</tr>
{% endfor %}
</tbody>
</table>
</div>


</div>

<script>
layui.use(['transfer', 'jquery', 'layer'], function(){
var transfer = layui.transfer;
var $ = layui.jquery;
var layer = layui.layer;

//渲染
transfer.render({
elem: '#showdevice' //绑定元素
,title: ['我的机器', '分享机器'] //自定义标题
//,width: 500 //定义宽度
//,height: 300 //定义高度
,data: [//定义数据源
{%for peer in peers %}
{"value": "{{peer.id}}", "title": "{{peer.name}}"},
{%endfor%}

] //disabled 是否禁用 checked 是否选中
,id: 'device' //定义索引 重新加载reload或者获取右侧数据时可以用到
});
$("#create_bak").click(function(){

var getData = transfer.getData('device');
alert(JSON.stringify(getData));

});
$("#create").click(function(){
var getData = transfer.getData('device');
$.ajax({
url:'/api/share',
type:'post',
dataType:'json',
data:{
data:JSON.stringify(getData),
},
success:function(data){
if (data.code == 1) {
// var myMsg = layer.msg('处理中', {
// shade: 0.4,
// time:false //取消自动关闭
// });
//layer.msg('注册成功,请前往登录页登录。');
layer.alert('成功!如需分享,请复制以下链接给其他人:<br>'+ window.location + '/' +data.shash, function (index) {
location.reload();});
}else {
layer.msg(data.msg);
}
}
});

});

});
</script>
{% endblock %}
50 changes: 5 additions & 45 deletions api/templates/show_work.html
Original file line number Diff line number Diff line change
@@ -1,46 +1,7 @@
{% load static %}<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>RustDesk WebUI</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="{% static 'layui/css/layui.css' %}">

</head>
<body>
<script src={% static "layui/layui.js" %}></script>
<script>
layui.use('element', function(){
var element = layui.element; //导航的hover效果二级菜单等功能需要依赖element模块

//监听导航点击
element.on('nav(demo)', function(elem){
//console.log(elem)
layer.msg(elem.text());
});
});
</script>

<ul class="layui-nav">
<li class="layui-nav-item"><a href="/">首页</a></li>





{% if u.is_admin %}
<li class="layui-nav-item"><a href="/admin">管理后台</a>
</li>
{% endif %}

</ul>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
<legend>综合屏</legend>
</fieldset>

{% extends "base.html" %}
{% block title %}RustDesk WebUI{% endblock %}
{% block legend_name %}综合屏{% endblock %}
{% block content %}
<div style="padding: 20px; background-color: #F2F2F2;">
<div class="layui-row layui-col-space15">
<div class="layui-col-md15">
Expand Down Expand Up @@ -154,5 +115,4 @@

</div></div>

</body>
</html>
{% endblock %}
1 change: 1 addition & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
#url(r'^register',views.register),
url(r'^user_action',views.user_action), # 前端
url(r'^work',views.work), # 前端
url(r'^share',views.share), # 前端
]
12 changes: 1 addition & 11 deletions api/views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@
import copy
from .views_front import *

salt = 'xiaomo'
EFFECTIVE_SECONDS = 7200

def getStrMd5(s):
if not isinstance(s, (str,)):
s = str(s)

myHash = hashlib.md5()
myHash.update(s.encode())

return myHash.hexdigest()

def login(request):
result = {}
Expand All @@ -45,7 +35,7 @@ def login(request):
user.rid = rid
user.uuid = uuid
user.autoLogin = autoLogin
user.rtype = rtype
user.rtype = rtype
user.deviceInfo = json.dumps(deviceInfo)
user.save()

Expand Down
Loading

0 comments on commit 66a65b7

Please sign in to comment.