update
This commit is contained in:
parent
f511b8e44f
commit
111aaa768a
|
|
@ -27,6 +27,9 @@ sys.path.append(web_dir)
|
|||
import core.mw as mw
|
||||
import thisdb
|
||||
|
||||
from admin import setup
|
||||
setup.init()
|
||||
|
||||
g_log_file = mw.getPanelTaskLog()
|
||||
isTask = mw.getMWLogs() + '/panelTask.pl'
|
||||
|
||||
|
|
|
|||
|
|
@ -76,27 +76,7 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
|
|||
# 初始化db
|
||||
# sys_db.init_app(app)
|
||||
# Migrate(app, sys_db)
|
||||
|
||||
|
||||
# 检查数据库是否存在。如果没有就创建它。
|
||||
setup_db_required = False
|
||||
if not os.path.isfile(config.SQLITE_PATH):
|
||||
setup_db_required = True
|
||||
|
||||
# with app.app_context():
|
||||
# sys_db.create_all()
|
||||
|
||||
# with app.app_context():
|
||||
# if setup_db_required:
|
||||
# sys_db.create_all()
|
||||
|
||||
if setup_db_required:
|
||||
# 初始化用户信息
|
||||
thisdb.initPanelData()
|
||||
setup.init_admin_user()
|
||||
setup.init_option()
|
||||
setup.init_cmd()
|
||||
setup.init_db_system()
|
||||
setup.init()
|
||||
|
||||
|
||||
app.config['BASIC_AUTH_OPEN'] = False
|
||||
|
|
|
|||
|
|
@ -9,15 +9,12 @@
|
|||
# ---------------------------------------------------------------------------------
|
||||
|
||||
from .setting import *
|
||||
|
||||
from .temp_login import *
|
||||
from .timezone import *
|
||||
from .secondary_verifiy import *
|
||||
|
||||
from .notify_email import *
|
||||
from .notify_tgbot import *
|
||||
from .app import *
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
# coding:utf-8
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# MW-Linux面板
|
||||
# ---------------------------------------------------------------------------------
|
||||
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
|
||||
# ---------------------------------------------------------------------------------
|
||||
# Author: midoks <midoks@163.com>
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
import re
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
||||
from flask import Blueprint, render_template
|
||||
from flask import request
|
||||
|
||||
from admin import session
|
||||
from admin.user_login_check import panel_login_required
|
||||
|
||||
import core.mw as mw
|
||||
import utils.config as utils_config
|
||||
|
||||
from .setting import blueprint
|
||||
import thisdb
|
||||
|
||||
|
||||
# 获取APP列表
|
||||
@blueprint.route('/get_app_list', endpoint='get_app_list', methods=['POST'])
|
||||
@panel_login_required
|
||||
def get_app_list():
|
||||
limit = request.form.get('limit', '5').strip()
|
||||
page = request.form.get('page', '1').strip()
|
||||
tojs = request.form.get('tojs', '').strip()
|
||||
|
||||
info = thisdb.getAppList(page=int(page),size=int(limit))
|
||||
data = {}
|
||||
data['data'] = info['list']
|
||||
data['page'] = mw.getPage({'count':info['count'],'tojs':tojs,'p':page,'row':limit})
|
||||
return data
|
||||
|
||||
|
||||
# 获取APP列表
|
||||
@blueprint.route('/add_app', endpoint='add_app', methods=['POST'])
|
||||
@panel_login_required
|
||||
def add_app():
|
||||
app_id = request.form.get('app_id', '').strip()
|
||||
app_secret = request.form.get('app_secret', '1').strip()
|
||||
limit_addr = request.form.get('limit_addr', '').strip()
|
||||
|
||||
rid = thisdb.addApp(app_id,app_secret,limit_addr)
|
||||
if rid > 0:
|
||||
return mw.returnData(True, '添加成功!')
|
||||
return mw.returnData(False, '添加失败!')
|
||||
|
|
@ -8,8 +8,24 @@
|
|||
# Author: midoks <midoks@163.com>
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
import os
|
||||
|
||||
from .user import init_admin_user
|
||||
from .option import init_option
|
||||
from .init_db_system import init_db_system
|
||||
from .init_cmd import init_cmd
|
||||
|
||||
|
||||
import thisdb
|
||||
import config
|
||||
|
||||
def init():
|
||||
# 检查数据库是否存在。如果没有就创建它。
|
||||
if not os.path.isfile(config.SQLITE_PATH):
|
||||
# 初始化用户信息
|
||||
thisdb.initPanelData()
|
||||
init_admin_user()
|
||||
init_option()
|
||||
init_cmd()
|
||||
init_db_system()
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ CREATE TABLE IF NOT EXISTS `crontab` (
|
|||
`add_time` TEXT,
|
||||
`update_time` TEXT
|
||||
);
|
||||
CREATE UNIQUE INDEX name_idx ON crontab(name);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `firewall` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
|
@ -46,15 +47,12 @@ CREATE TABLE IF NOT EXISTS `firewall` (
|
|||
`add_time` TEXT,
|
||||
`update_time` TEXT
|
||||
);
|
||||
|
||||
ALTER TABLE `firewall` ADD COLUMN `protocol` TEXT DEFAULT 'tcp';
|
||||
CREATE UNIQUE INDEX port_idx ON firewall(port);
|
||||
|
||||
INSERT INTO `firewall` (`id`, `port`, `protocol`, `ps`, `add_time`, `update_time`) VALUES
|
||||
(1, '80', 'tcp','网站默认端口', '0000-00-00 00:00:00','0000-00-00 00:00:00'),
|
||||
(2, '443', 'tcp/udp', 'HTTPS', '0000-00-00 00:00:00','0000-00-00 00:00:00');
|
||||
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `logs` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`type` TEXT,
|
||||
|
|
@ -77,11 +75,13 @@ CREATE TABLE IF NOT EXISTS `sites` (
|
|||
`add_time` TEXT,
|
||||
`update_time` TEXT
|
||||
);
|
||||
CREATE UNIQUE INDEX name_idx ON sites(name);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `site_types` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`name` TEXT
|
||||
);
|
||||
CREATE UNIQUE INDEX name_idx ON site_types(name);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `domain` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
|
@ -145,6 +145,7 @@ CREATE TABLE IF NOT EXISTS `app` (
|
|||
`add_time` TEXT,
|
||||
`update_time` TEXT
|
||||
);
|
||||
CREATE UNIQUE INDEX app_id_idx ON app(app_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `option` (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
|
@ -152,5 +153,4 @@ CREATE TABLE IF NOT EXISTS `option` (
|
|||
`type` TEXT,
|
||||
`value` TEXT
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX name_idx ON option(name);
|
||||
|
|
|
|||
|
|
@ -1472,3 +1472,155 @@ function setPanelApi(){
|
|||
} ,{icon:rdata.status?1:2}, 1000);
|
||||
},'json');
|
||||
}
|
||||
|
||||
|
||||
function getAppList(page) {
|
||||
if (typeof(page) == 'undefined'){
|
||||
page = 1;
|
||||
}
|
||||
|
||||
$.post('/setting/get_app_list', {page:page}, function(rdata){
|
||||
console.log(rdata);
|
||||
if ( typeof(rdata.status) !='undefined' && !rdata.status){
|
||||
showMsg(rdata.msg,function(){
|
||||
layer.closeAll();
|
||||
},{icon:2}, 2000);
|
||||
return;
|
||||
}
|
||||
|
||||
var tbody = '';
|
||||
for (var i = 0; i < rdata.data.length; i++) {
|
||||
|
||||
tbody += '<tr>';
|
||||
tbody += '<td>' + (rdata.data[i]['login_addr']||'未登陆') +'</td>';
|
||||
|
||||
tbody += '<td>';
|
||||
switch (parseInt(rdata.data[i]['state'])) {
|
||||
case 0:
|
||||
tbody += '<a style="color:green;">待使用</a>';
|
||||
break;
|
||||
case 1:
|
||||
tbody += '<a style="color:brown;">已使用</a>';
|
||||
break;
|
||||
case -1:
|
||||
tbody += '<a>已过期</a>';
|
||||
break;
|
||||
}
|
||||
tbody += '</td>';
|
||||
|
||||
tbody += '<td>' + (getLocalTime(rdata.data[i]['login_time'])||'未登陆') +'</td>';
|
||||
tbody += '<td>' + getLocalTime(rdata.data[i]['expire']) +'</td>';
|
||||
|
||||
tbody += '<td>';
|
||||
|
||||
if (rdata.data[i]['state'] == '1' ){
|
||||
tbody += '<a class="btlink" onclick="getTempAccessLogs(\''+rdata.data[i]['id']+'\')">操作日志</a>';
|
||||
} else{
|
||||
tbody += '<a class="btlink" onclick="removeTempAccess(\''+rdata.data[i]['id']+'\')">删除</a>';
|
||||
}
|
||||
|
||||
tbody += '</td>';
|
||||
|
||||
tbody += '</tr>';
|
||||
}
|
||||
|
||||
$('#temp_login_view_tbody').html(tbody);
|
||||
$('.temp_login_view_page').html(rdata.page);
|
||||
},'json');
|
||||
}
|
||||
|
||||
function addApp(){
|
||||
var msg = '<span style="color:red">注意1:滥用临时授权可能导致安全风险。</br>注意2:请勿在公共场合发布临时授权连接</span></br>即将创建临时授权连接,继续吗?';
|
||||
layer.confirm(msg,{title:'风险提示',closeBtn:1,icon:13,}, function(create_layer) {
|
||||
layer.close(create_layer);
|
||||
layer.open({
|
||||
area: '570px',
|
||||
title: '添加应用',
|
||||
shift: 0,
|
||||
type: 1,
|
||||
content: '<div class="bt-form pd20">\
|
||||
<div class="line">\
|
||||
<span class="tname">应用ID</span>\
|
||||
<div class="info-r">\
|
||||
<input class="bt-input-text mr5" name="app_id" type="text" style="width: 310px;" disabled>\
|
||||
<button class="btn btn-success btn-xs app_id" style="margin-left: -50px;">重置</button>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="line">\
|
||||
<span class="tname">应用密钥</span>\
|
||||
<div class="info-r">\
|
||||
<input class="bt-input-text mr5" name="app_secret" type="text" style="width: 310px;" disabled>\
|
||||
<button class="btn btn-success btn-xs app_secret" style="margin-left: -50px;">重置</button>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class="line">\
|
||||
<span class="tname" style="width: 90px; overflow: initial; height: 20px; line-height: 20px;">IP白名单<br/>(每行1个)</span>\
|
||||
<div class="info-r"><textarea class="bt-input-text" name="api_limit_addr" style="width: 310px; height: 80px; line-height: 20px; padding: 5px 8px;"></textarea></div>\
|
||||
</div>\
|
||||
<div class="line">\
|
||||
<span class="tname"></span>\
|
||||
<div class="info-r"><button class="btn btn-success btn-sm save_app_data">保存配置</button></div>\
|
||||
</div>\
|
||||
<ul class="help-info-text c7">\
|
||||
<li>开启API后,必需在IP白名单列表中的IP才能访问面板API接口</li>\
|
||||
<li style="color: red;">请谨慎在生产环境开启,这可能增加服务器安全风险;</li>\
|
||||
</ul>\
|
||||
</div>',
|
||||
success:function(){
|
||||
$('input[name="app_id"]').val(getRandomString(10));
|
||||
$('input[name="app_secret"]').val(getRandomString(20));
|
||||
|
||||
$('.app_id').click(function(){
|
||||
$('input[name="app_id"]').val(getRandomString(10));
|
||||
});
|
||||
|
||||
$('.app_secret').click(function(){
|
||||
$('input[name="app_secret"]').val(getRandomString(20));
|
||||
});
|
||||
|
||||
$('.save_app_data').click(function(){
|
||||
var app_id = $('input[name="app_id"]').val();
|
||||
var app_secret = $('input[name="app_secret"]').val();
|
||||
var limit_addr = $('textarea[name="api_limit_addr"]').val();
|
||||
$.post('/setting/add_app', {'app_id':app_id,'app_secret':app_secret,'limit_addr':limit_addr},function(rdata){
|
||||
showMsg(rdata.msg, function(){} ,{icon:rdata.status?1:2}, 2000);
|
||||
},'json');
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function appPage(){
|
||||
layer.open({
|
||||
area: ['700px', '380px'],
|
||||
title: 'APP应用管理',
|
||||
closeBtn:1,
|
||||
shift: 0,
|
||||
type: 1,
|
||||
content: "<div class='login_view_table pd20'>\
|
||||
<button class='btn btn-success btn-sm app_add'>添加</button>\
|
||||
<div class='divtable mt10'>\
|
||||
<table class='table table-hover'>\
|
||||
<thead>\
|
||||
<tr>\
|
||||
<th>登录IP</th>\
|
||||
<th>状态</th><th>登录时间</th>\
|
||||
<th>过期时间</th>\
|
||||
<th style='text-align:right;'>操作</th>\
|
||||
</tr>\
|
||||
</thead>\
|
||||
<tbody id='temp_login_view_tbody'></tbody>\
|
||||
</table>\
|
||||
<div class='temp_login_view_page page'></div>\
|
||||
</div>\
|
||||
</div>",
|
||||
success:function(){
|
||||
getAppList();
|
||||
$('.app_add').click(function(){
|
||||
addApp();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@
|
|||
<span class="set-tit text-right" title="API接口" style="float: left;">API接口</span>
|
||||
<input class="btswitch btswitch-ios" id="cfg_panel_api" type="checkbox" {{data['api_token']}}/>
|
||||
<label class="btswitch-btn ml5" for="cfg_panel_api" style="float: left;margin-top:4px;" onclick="setPanelApi()"></label>
|
||||
<button ype="button" class="btn btn-default btn-xs panel_api_btn" style="vertical-align: middle; margin-left: 10px" onclick="showPanelApi();">API接口配置</button>
|
||||
<button ype="button" class="btn btn-default btn-xs panel_api_btn" style="vertical-align: middle; margin-left: 10px" onclick="appPage();">APP应用管理</button>
|
||||
<span class="set-info c7">提供面板API接口访问的支持</span>
|
||||
</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -10,14 +10,15 @@
|
|||
|
||||
import core.mw as mw
|
||||
|
||||
__FIELD = 'id,app_id,app_secret,status,add_time,update_time'
|
||||
__FIELD = 'id,app_id,app_secret,white_list,status,add_time,update_time'
|
||||
|
||||
def addApp(app_id,app_secret):
|
||||
def addApp(app_id,app_secret,white_list):
|
||||
now_time = mw.getDateFromNow()
|
||||
add_data = {
|
||||
'app_id': app_id,
|
||||
'app_secret': app_secret,
|
||||
'status': 1,
|
||||
'white_list':white_list,
|
||||
'add_time': now_time,
|
||||
'update_time': now_time
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue