From d09a96ec8474e0dde910255f46fbda338f247166 Mon Sep 17 00:00:00 2001
From: Mr Chen
Date: Wed, 10 Jan 2024 00:02:04 +0800
Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E5=8C=BA=E8=AE=BE=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
class/core/config_api.py | 23 +++++++++++++
route/static/app/config.js | 52 +++++++++++++++++++++++++++++
route/templates/default/config.html | 7 ++++
3 files changed, 82 insertions(+)
diff --git a/class/core/config_api.py b/class/core/config_api.py
index 1002d8840..1ff175f7e 100755
--- a/class/core/config_api.py
+++ b/class/core/config_api.py
@@ -20,6 +20,7 @@ import mw
import re
import json
import pwd
+import pytz
from flask import session
from flask import request
@@ -911,6 +912,21 @@ class config_api:
data['status_code_msg'] = "默认-安全入口错误提示"
return data
+
+ def getTimezoneListApi(self):
+ # 获取时区列表
+ # pytz.all_timezones | 所有
+ # pytz.common_timezones
+ return pytz.all_timezones
+
+ def setTimezoneApi(self):
+ # 设置时区列表
+ timezone = request.form.get('timezone', '').strip()
+ cmd = 'timedatectl set-timezone "'+timezone+'"'
+ mw.execShell(cmd)
+ return mw.returnJson(True, '设置成功!')
+
+
def get(self):
data = {}
@@ -920,6 +936,13 @@ class config_api:
sformat = 'date +"%Y-%m-%d %H:%M:%S %Z %z"'
data['systemdate'] = mw.execShell(sformat)[0].strip()
+ # 获取时区
+ import datetime
+ import pytz
+ now = datetime.datetime.now()
+ tz_name = now.astimezone().tzinfo
+ data['systemdatezone'] = tz_name
+
data['port'] = mw.getHostPort()
data['ip'] = mw.getHostAddr()
diff --git a/route/static/app/config.js b/route/static/app/config.js
index d8d906e00..521ab65d8 100755
--- a/route/static/app/config.js
+++ b/route/static/app/config.js
@@ -348,6 +348,58 @@ function syncDate(){
},'json');
}
+function setTimezone(){
+ layer.open({
+ type: 1,
+ area: ["400px","200px"],
+ title: '设置服务器时区',
+ closeBtn: 1,
+ shift: 5,
+ shadeClose: false,
+ btn:["确定","取消"],
+ content: "",
+ success:function(){
+
+ var tbody = '';
+ $.post('/config/get_timezone_list', {}, function (rdata) {
+
+ for (var i = 0; i < rdata.length; i++) {
+ tbody += '';
+ }
+ $('select[name="timezone"]').append(tbody);
+
+ },'json');
+
+ // for(i in msg_list){
+ // if (msg_list[i]['code'] == ''){
+ // tbody += '';
+ // } else{
+ // tbody += '';
+ // }
+ // }
+
+ },
+ yes:function(index){
+ var loadT = layer.msg("正在设置时区...", { icon: 16, time: 0, shade: [0.3, '#000'] });
+ var timezone = $('select[name="timezone"]').val();
+ $.post('/config/set_timezone', { timezone: timezone }, function (rdata) {
+ showMsg(rdata.msg, function(){
+ layer.close(index);
+ layer.close(loadT);
+ location.reload();
+ },{ icon: rdata.status ? 1 : 2 }, 2000);
+ },'json');
+ }
+ })
+}
+
function setIPv6() {
var loadT = layer.msg('正在配置,请稍候...', { icon: 16, time: 0, shade: [0.3, '#000'] });
diff --git a/route/templates/default/config.html b/route/templates/default/config.html
index b01374e69..aa24edf59 100755
--- a/route/templates/default/config.html
+++ b/route/templates/default/config.html
@@ -86,6 +86,13 @@
同步当前服务器时间
+
+
+ 服务器时区
+
+
+ 设置当前服务器时区
+
面板用户