Skip to content

Commit

Permalink
修复了版本显示错误的问题,并完善了关于页用于显示版本信息。
Browse files Browse the repository at this point in the history
  • Loading branch information
llody55 committed Jul 4, 2024
1 parent 8cba660 commit 734a643
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Dockerfile_amd
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ WORKDIR /app
COPY . /app

# 初始化数据库
RUN python manage.py migrate
RUN echo "from apps.models import CustomUser; CustomUser.objects.create_superuser('[email protected]','llody', '1qaz2wsx')" | python manage.py shell
RUN echo "from apps.models import Registries; registry = Registries(registries_name='DockerHub', registries_url='docker.io', registries_auth=False, registries_remarks='DockerHub'); registry.save()" | python manage.py shell
# RUN python manage.py migrate
# RUN echo "from apps.models import CustomUser; CustomUser.objects.create_superuser('[email protected]','llody', '1qaz2wsx')" | python manage.py shell
# RUN echo "from apps.models import Registries; registry = Registries(registries_name='DockerHub', registries_url='docker.io', registries_auth=False, registries_remarks='DockerHub'); registry.save()" | python manage.py shell

RUN chmod +x start.sh

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ docker run --privileged -itd --name udocker -p 8000:8000 -p 9002:9002 -v /var/ru
mkdir /opt/udocke_db
docker run --privileged -itd --name udocker -p 8000:8000 -p 9002:9002 -v /var/run/docker.sock:/var/run/docker.sock -v /opt/udocke_db:/app/db swr.cn-southwest-2.myhuaweicloud.com/llody/udocker:latest
```
### docker-compose方式(推荐)
```yaml
version: '3'

services:
udocker:
image: swr.cn-southwest-2.myhuaweicloud.com/llody/udocker:latest
container_name: udocker
privileged: true
ports:
- "8000:8000"
- "9002:9002"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /opt/udocke_db:/app/db
restart: always
```
> 启动方式:docker-compose up -d <br>
> 更新方式:docker-compose pull && docker-compose up -d --remove-orphans
### 账户密码
> 默认账户:llody 密码:1qaz2wsx
Expand Down
2 changes: 2 additions & 0 deletions apps/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@
re_path("webssh_update_file_api/",views.webssh_update_file_api,name="webssh_update_file_api"), # 上传API
re_path("webssh_download_file_api/",views.webssh_download_file_api,name="webssh_download_file_api"), # 下载方法API
re_path("webssh_delete_file_api/",views.webssh_delete_file_api,name="webssh_delete_file_api"), # 删除文件方法API

re_path("about/",views.about,name="about"),
]
14 changes: 10 additions & 4 deletions apps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,21 @@ def user_login(request):
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(request, username=username, password=password)
print("当前用户:", user)
#print("当前用户:", user)
if user is not None:
# 获取用户所属的所有角色
roles = user.roles.all()
for role in roles:
# 获取用户所属的所有角色,并存入session
request.session['user_roles'] = role.name
print(f"当前用户所在角色: {role.name}")
#print(f"当前用户所在角色: {role.name}")
# 获取当前角色的所有权限
role_permissions = role.permissions.all()
for perm in role_permissions:
print(f"当前角色所有权限: {perm.name}")
# 检查用户是否有某个具体的权限(需要提供app_label)
has_edit_permission = user.has_perm('edit_permission')
print("是否有编辑权限:", has_edit_permission)
#print("是否有编辑权限:", has_edit_permission)
login(request, user)
return redirect('index')
else:
Expand Down Expand Up @@ -178,6 +178,8 @@ def password_reset_request(request):
# 如果当前密码验证失败,返回错误信息
return JsonResponse({'error': '当前密码不正确,请重试','code':'1'})


# 容器列表页
@csrf_exempt
@login_required
def docker_container(request):
Expand Down Expand Up @@ -2132,4 +2134,8 @@ def webssh_delete_file_api(request):
result = {'msg': msg, "code": code}
return JsonResponse(result)
finally:
sftp.close()
sftp.close()

@login_required
def about(request):
return render(request, 'about.html')
1 change: 1 addition & 0 deletions static/sweetalert2/sweetalert2.min.css

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions static/sweetalert2/sweetalert2.min.js

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions templates/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% extends 'docker_base.html' %}
{% block title %}关于{% endblock %}
{% block item-9 %}layui-nav-itemed{% endblock %}
{% load i18n %}
{% block head_style %}
<style>
body {
margin: 10px;
}

/* 标题样式 */
.layui-card-header {
background-color: #f2f2f2;
/* 修改标题背景颜色 */
color: #333;
/* 修改标题文字颜色 */
font-size: 16px;
/* 修改标题文字大小 */
border-bottom: 1px solid #e6e6e6;
/* 在标题下方添加边框线 */
line-height: 36px;
/* 调整行高 */
}
/* 底部内边距样式*/
#fixed {
padding-bottom: 40px; /* 底部填充,值应大于或等于提交按钮的高度加上一些额外空间 */
}
</style>
{% endblock %}
{% block context %}
<span class="layui-breadcrumb">
<a href="#">首页</a>
<a><cite>关于</cite></a>
</span>
<hr>
<div class="layui-card">
<div class="layui-card-body">
<div class="layui-bg-gray" style="padding: 16px;">
<div class="layui-row layui-col-space15">
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-header">版本</div>
<div class="layui-card-body">
当前版本:<span style="color: #1e9fff;">{{ version }} </span><br>
最新版本:{% if version == latest_version %}
已经是最新版了
{% else %}
<span style="color: #16b777;">{{ latest_version }}</span> <a href="https://github.com/llody55/udocker" target="_blank"><span style="color: #16b777;"> 查看版本差异 </span></a>
{% endif %}
</div>
</div>
</div>

</div>
</div>
</div>
</div>

{% endblock %}
{% block custom_js %}
JS
{% endblock %}

20 changes: 17 additions & 3 deletions templates/docker_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<!-- <link href="http://pt.llody.top:1080/7.jpg" type="image/x-icon" rel="shortcut icon" /> -->
<link href="/static/layui/css/layui.css" rel="stylesheet" /> <!-- 注意路劲 -->
<link href="/static/xterm/xterm.css" rel="stylesheet" type="text/css" />
<link href="/static/sweetalert2/sweetalert2.min.css" rel="stylesheet" type="text/css" />
<link href="//at.alicdn.com/t/c/font_4111199_zcutv4ow13q.css" rel="stylesheet" /> <!-- 文件夹图标矢量图-->

<style>
Expand Down Expand Up @@ -165,7 +166,7 @@
<dd><a href="" style="color: black;">{% translate "基本资料" %}</a></dd>
<dd><a href="" style="color: black;">{% translate "安全设置" %}</a></dd>
<hr>
<dd><a href="{% url 'logout' %}" style="color: black;">{% translate "退出" %}</a></dd>
<dd><a href="{% url 'logout' %}" id="logoutLink" style="color: black;">{% translate "退出" %}</a></dd>
</dl>
</li>
{% else %}
Expand Down Expand Up @@ -213,7 +214,7 @@

</li>
<li class="layui-nav-item {% block item-9 %}{% endblock %}">
<a href="#"><i class="layui-icon layui-icon-about">&nbsp;&nbsp;<span>{% translate "关于" %}</span></i></a>
<a href="{% url 'about' %}"><i class="layui-icon layui-icon-about">&nbsp;&nbsp;<span>{% translate "关于" %}</span></i></a>
</li>
</ul>
</div>
Expand All @@ -230,12 +231,13 @@

<div class="layui-footer" style="text-align: center">
<!-- 底部固定区域 -->
<a href="https://github.com/llody55/udocker"> {% translate "Udocker 控制台" %}</a> ©2024 llody version {{version}} &nbsp;&nbsp;&nbsp; <img alt="欢迎关注" src="https://static.llody.top/images/favicon.ico">
<a href="https://github.com/llody55/udocker"> {% translate "Udocker 控制台" %}</a> ©2024 llody version: v{{version}} &nbsp;&nbsp;&nbsp; <img alt="欢迎关注" src="https://static.llody.top/images/favicon.ico">
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.8/clipboard.min.js"></script>
<script src="/static/layui/layui.js"></script>
<script src="/static/xterm/xterm.js"></script>
<script src="/static/sweetalert2/sweetalert2.min.js"></script>
{% block custom_js %}{% endblock %}
<script>
//JS
Expand Down Expand Up @@ -358,6 +360,18 @@
$('#message').on('click', function () {
layer.msg("开发中。。。。",{ icon: 6 } )
})

// 登出链接点击事件
document.getElementById('logoutLink').addEventListener('click', function(event) {
event.preventDefault(); // 阻止默认的链接跳转行为

// 清除 localStorage 中的 versionUpdateShown 项
localStorage.removeItem('versionUpdateShown');

// 执行登出操作
window.location.href = "{% url 'logout' %}";
});

});
</script>
</body>
Expand Down
52 changes: 52 additions & 0 deletions templates/docker_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,56 @@
largeImage.style.display = "none";
};
</script>
<script>
layui.use(['element', 'layer', 'util'], function () {
var element = layui.element
var layer = layui.layer
var util = layui.util
var $ = layui.$;

$(document).ready(function() {
var currentVersion = "{{ version }}";
var latestVersion = "{{ latest_version }}";
var showNotification = "{{ show_notification }}";

if (currentVersion !== latestVersion ) {
// 检查是否已经显示过更新提示
if (!localStorage.getItem('versionUpdateShown')) {
Swal.fire({
title: '检测到新版本!',
html: '当前最新的版本是:<span style="color: #1e9fff;">v' + latestVersion + '</span>,点击前往升级。',
icon: 'info',
timer: 5000,
timerProgressBar: true,
showCancelButton: true,
confirmButtonText: '前往升级',
cancelButtonText: '暂不升级',
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
width: 300, // 设置弹出框的宽度
height: 100,
padding: '2em', // 设置弹出框的内边距
customClass: {
popup: 'swal2-popup swal2-modal swal2-icon-info swal2-show',
confirmButton: 'swal2-confirm',
cancelButton: 'swal2-cancel'
},
position: 'bottom-start'
}).then((result) => {
if (result.isConfirmed) {
window.location.href = 'https://github.com/llody55/udocker';
}
});

// 设置标志,表示已经显示过更新提示
//localStorage.setItem('versionUpdateShown', 'true');

}else{
console.log("已弹出,开始静默")
}

}
});
})
</script>
{% endblock %}
28 changes: 27 additions & 1 deletion udockers/contexts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
import requests
from django.core.cache import cache
from udockers.settings import VERSION_STR

def version(request):
return {'version': VERSION_STR}
return {'version': VERSION_STR}

# 检查GitHub中版本
def get_latest_github_version(owner, repo):
url = f'https://api.github.com/repos/{owner}/{repo}/tags'
response = requests.get(url)
if response.status_code == 200:
tags = response.json()
if tags:
latest_tag = tags[0]['name']
# 去掉前缀 'v'
if latest_tag.startswith('v'):
latest_tag = latest_tag[1:]
return latest_tag
return None

def latest_version(request):
cache_key = 'latest_github_version'
latest_version = cache.get(cache_key)
if not latest_version:
latest_version = get_latest_github_version('llody55', 'udocker')
if latest_version:
cache.set(cache_key, latest_version, 3600)
show_notification = not request.session.get('update_notified', False)
return {'latest_version': latest_version,'show_notification':show_notification}
3 changes: 2 additions & 1 deletion udockers/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#CSRF_TRUSTED_ORIGINS = ['https://add.llody.top']

# Application definition
VERSION = (1, 1, 1)
VERSION = (1, 1, 3)

VERSION_STR = '.'.join(map(str, VERSION))

Expand Down Expand Up @@ -84,6 +84,7 @@
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'udockers.contexts.version',
'udockers.contexts.latest_version',
],
},
},
Expand Down

0 comments on commit 734a643

Please sign in to comment.