mirror of https://github.com/tp4a/teleport
WEB方式安装向导功能完成,可以从零架设TELEPORT服务了。下一步是升级向导。
parent
054deb839e
commit
8a04467e2a
|
@ -9,37 +9,37 @@ CREATE TABLE `ts_account` (
|
||||||
`account_desc` varchar(255)
|
`account_desc` varchar(255)
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO "main"."ts_account" VALUES (1, 100, 'admin', '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918', 0, 0, '超级管理员');
|
INSERT INTO `main`.`ts_account` VALUES (1, 100, 'admin', '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918', 0, 0, '超级管理员');
|
||||||
|
|
||||||
CREATE TABLE "ts_auth"(
|
CREATE TABLE `ts_auth`(
|
||||||
"auth_id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
`auth_id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
"account_name" varchar(256),
|
`account_name` varchar(256),
|
||||||
"host_id" INTEGER,
|
`host_id` INTEGER,
|
||||||
"host_auth_id" int(11) NOT NULL
|
`host_auth_id` int(11) NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE "ts_cert" (
|
CREATE TABLE `ts_cert` (
|
||||||
"cert_id" integer PRIMARY KEY AUTOINCREMENT,
|
`cert_id` integer PRIMARY KEY AUTOINCREMENT,
|
||||||
"cert_name" varchar(256),
|
`cert_name` varchar(256),
|
||||||
"cert_pub" varchar(2048) DEFAULT '',
|
`cert_pub` varchar(2048) DEFAULT '',
|
||||||
"cert_pri" varchar(4096) DEFAULT '',
|
`cert_pri` varchar(4096) DEFAULT '',
|
||||||
"cert_desc" varchar(256)
|
`cert_desc` varchar(256)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE "ts_config" (
|
CREATE TABLE `ts_config` (
|
||||||
"name" varchar(256) NOT NULL,
|
`name` varchar(256) NOT NULL,
|
||||||
"value" varchar(256),
|
`value` varchar(256),
|
||||||
PRIMARY KEY ("name" ASC)
|
PRIMARY KEY (`name` ASC)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO "main"."ts_config" VALUES ('ts_server_ip', '127.0.0.1');
|
INSERT INTO `main`.`ts_config` VALUES ('ts_server_ip', '127.0.0.1');
|
||||||
INSERT INTO "main"."ts_config" VALUES ('ts_server_rpc_port', 52080);
|
INSERT INTO `main`.`ts_config` VALUES ('ts_server_rpc_port', 52080);
|
||||||
INSERT INTO "main"."ts_config" VALUES ('ts_server_rdp_port', 52089);
|
INSERT INTO `main`.`ts_config` VALUES ('ts_server_rdp_port', 52089);
|
||||||
INSERT INTO "main"."ts_config" VALUES ('ts_server_ssh_port', 52189);
|
INSERT INTO `main`.`ts_config` VALUES ('ts_server_ssh_port', 52189);
|
||||||
INSERT INTO "main"."ts_config" VALUES ('ts_server_telnet_port', 52389);
|
INSERT INTO `main`.`ts_config` VALUES ('ts_server_telnet_port', 52389);
|
||||||
INSERT INTO "main"."ts_config" VALUES ('ts_server_rpc_ip', '127.0.0.1');
|
INSERT INTO `main`.`ts_config` VALUES ('ts_server_rpc_ip', '127.0.0.1');
|
||||||
|
|
||||||
CREATE TABLE `ts_group` (
|
CREATE TABLE `ts_group` (
|
||||||
`group_id` integer PRIMARY KEY AUTOINCREMENT,
|
`group_id` integer PRIMARY KEY AUTOINCREMENT,
|
||||||
|
@ -47,42 +47,42 @@ CREATE TABLE `ts_group` (
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE "ts_host_info"(
|
CREATE TABLE `ts_host_info`(
|
||||||
"host_id" integer PRIMARY KEY AUTOINCREMENT,
|
`host_id` integer PRIMARY KEY AUTOINCREMENT,
|
||||||
"group_id" int(11) DEFAULT 0,
|
`group_id` int(11) DEFAULT 0,
|
||||||
"host_sys_type" int(11) DEFAULT 1,
|
`host_sys_type` int(11) DEFAULT 1,
|
||||||
"host_ip" varchar(32) DEFAULT '',
|
`host_ip` varchar(32) DEFAULT '',
|
||||||
"host_port" int(11) DEFAULT 0,
|
`host_port` int(11) DEFAULT 0,
|
||||||
"protocol" int(11) DEFAULT 0,
|
`protocol` int(11) DEFAULT 0,
|
||||||
"host_lock" int(11) DEFAULT 0,
|
`host_lock` int(11) DEFAULT 0,
|
||||||
"host_desc" DEFAULT ''
|
`host_desc` DEFAULT ''
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE "ts_auth_info"(
|
CREATE TABLE `ts_auth_info`(
|
||||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
"host_id" INTEGER,
|
`host_id` INTEGER,
|
||||||
"auth_mode" INTEGER,
|
`auth_mode` INTEGER,
|
||||||
"user_name" varchar(256),
|
`user_name` varchar(256),
|
||||||
"user_pswd" varchar(256),
|
`user_pswd` varchar(256),
|
||||||
"user_param" varchar(256),
|
`user_param` varchar(256),
|
||||||
"cert_id" INTEGER,
|
`cert_id` INTEGER,
|
||||||
"encrypt" INTEGER,
|
`encrypt` INTEGER,
|
||||||
"log_time" varchar(60)
|
`log_time` varchar(60)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE "ts_log" (
|
CREATE TABLE `ts_log` (
|
||||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
"session_id" varchar(32),
|
`session_id` varchar(32),
|
||||||
"account_name" varchar(64),
|
`account_name` varchar(64),
|
||||||
"host_ip" varchar(32),
|
`host_ip` varchar(32),
|
||||||
"host_port" INTEGER,
|
`host_port` INTEGER,
|
||||||
"sys_type" INTEGER DEFAULT 0,
|
`sys_type` INTEGER DEFAULT 0,
|
||||||
"auth_type" INTEGER,
|
`auth_type` INTEGER,
|
||||||
"protocol" INTEGER,
|
`protocol` INTEGER,
|
||||||
"user_name" varchar(64),
|
`user_name` varchar(64),
|
||||||
"ret_code" INTEGER,
|
`ret_code` INTEGER,
|
||||||
"begin_time" INTEGER,
|
`begin_time` INTEGER,
|
||||||
"end_time" INTEGER,
|
`end_time` INTEGER,
|
||||||
"log_time" varchar(64)
|
`log_time` varchar(64)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,18 +1,26 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from eom_common.eomcore.logger import log
|
|
||||||
from eom_app.app.util import sec_generate_password
|
from eom_app.app.util import sec_generate_password
|
||||||
|
from eom_common.eomcore.logger import log
|
||||||
|
|
||||||
# 升级数据表结构时必须升级此版本号,并编写响应的升级SQL
|
# 升级数据表结构时必须升级此版本号,并编写响应的升级SQL
|
||||||
TELEPORT_DATABASE_VERSION = 10
|
TELEPORT_DATABASE_VERSION = 10
|
||||||
|
|
||||||
|
|
||||||
|
def _db_exec(db, step_begin, step_end, msg, sql):
|
||||||
|
_step = step_begin(msg)
|
||||||
|
|
||||||
|
ret = db.exec(sql)
|
||||||
|
if not ret:
|
||||||
|
step_end(_step, -1)
|
||||||
|
raise RuntimeError('[FAILED] {}'.format(sql))
|
||||||
|
else:
|
||||||
|
step_end(_step, 0)
|
||||||
|
|
||||||
|
|
||||||
def create_and_init(db, step_begin, step_end):
|
def create_and_init(db, step_begin, step_end):
|
||||||
_admin_sec_password = sec_generate_password('admin')
|
try:
|
||||||
|
_db_exec(db, step_begin, step_end, '创建表 account', """CREATE TABLE `{}account` (
|
||||||
_step = step_begin('创建表 account')
|
|
||||||
|
|
||||||
ret = db.exec("""CREATE TABLE `{}account` (
|
|
||||||
`account_id` integer PRIMARY KEY AUTOINCREMENT,
|
`account_id` integer PRIMARY KEY AUTOINCREMENT,
|
||||||
`account_type` int(11) DEFAULT 0,
|
`account_type` int(11) DEFAULT 0,
|
||||||
`account_name` varchar(32) DEFAULT NULL,
|
`account_name` varchar(32) DEFAULT NULL,
|
||||||
|
@ -21,10 +29,88 @@ def create_and_init(db, step_begin, step_end):
|
||||||
`account_lock` int(11) DEFAULT 0,
|
`account_lock` int(11) DEFAULT 0,
|
||||||
`account_desc` varchar(255)
|
`account_desc` varchar(255)
|
||||||
);""".format(db.table_prefix))
|
);""".format(db.table_prefix))
|
||||||
if not ret:
|
|
||||||
log.e('create table `account` failed.')
|
_db_exec(db, step_begin, step_end, '创建表 auth', """CREATE TABLE `{}auth`(
|
||||||
step_end(_step, -1)
|
`auth_id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
return
|
`account_name` varchar(256),
|
||||||
else:
|
`host_id` INTEGER,
|
||||||
log.i('create table `account` ok.')
|
`host_auth_id` int(11) NOT NULL
|
||||||
step_end(_step, 0)
|
);""".format(db.table_prefix))
|
||||||
|
|
||||||
|
# 注意,这个key表原名为cert,考虑到其中存放的是ssh密钥对,与证书无关,因此改名为key
|
||||||
|
# 这也是升级到数据库版本10的标志!
|
||||||
|
_db_exec(db, step_begin, step_end, '创建表 key', """CREATE TABLE `{}key` (
|
||||||
|
`cert_id` integer PRIMARY KEY AUTOINCREMENT,
|
||||||
|
`cert_name` varchar(256),
|
||||||
|
`cert_pub` varchar(2048) DEFAULT '',
|
||||||
|
`cert_pri` varchar(4096) DEFAULT '',
|
||||||
|
`cert_desc` varchar(256)
|
||||||
|
);
|
||||||
|
""".format(db.table_prefix))
|
||||||
|
|
||||||
|
_db_exec(db, step_begin, step_end, '创建表 config', """CREATE TABLE `{}config` (
|
||||||
|
`name` varchar(256) NOT NULL,
|
||||||
|
`value` varchar(256),
|
||||||
|
PRIMARY KEY (`name` ASC)
|
||||||
|
);""".format(db.table_prefix))
|
||||||
|
|
||||||
|
_db_exec(db, step_begin, step_end, '创建表 group', """CREATE TABLE `{}group` (
|
||||||
|
`group_id` integer PRIMARY KEY AUTOINCREMENT,
|
||||||
|
`group_name` varchar(255) DEFAULT''
|
||||||
|
);""".format(db.table_prefix))
|
||||||
|
|
||||||
|
_db_exec(db, step_begin, step_end, '创建表 host_info', """CREATE TABLE `{}host_info`(
|
||||||
|
`host_id` integer PRIMARY KEY AUTOINCREMENT,
|
||||||
|
`group_id` int(11) DEFAULT 0,
|
||||||
|
`host_sys_type` int(11) DEFAULT 1,
|
||||||
|
`host_ip` varchar(32) DEFAULT '',
|
||||||
|
`host_port` int(11) DEFAULT 0,
|
||||||
|
`protocol` int(11) DEFAULT 0,
|
||||||
|
`host_lock` int(11) DEFAULT 0,
|
||||||
|
`host_desc` DEFAULT ''
|
||||||
|
);""".format(db.table_prefix))
|
||||||
|
|
||||||
|
_db_exec(db, step_begin, step_end, '创建表 auth_info', """CREATE TABLE `{}auth_info`(
|
||||||
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
`host_id` INTEGER,
|
||||||
|
`auth_mode` INTEGER,
|
||||||
|
`user_name` varchar(256),
|
||||||
|
`user_pswd` varchar(256),
|
||||||
|
`user_param` varchar(256),
|
||||||
|
`cert_id` INTEGER,
|
||||||
|
`encrypt` INTEGER,
|
||||||
|
`log_time` varchar(60)
|
||||||
|
);""".format(db.table_prefix))
|
||||||
|
|
||||||
|
_db_exec(db, step_begin, step_end, '创建表 key', """CREATE TABLE `{}log` (
|
||||||
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
`session_id` varchar(32),
|
||||||
|
`account_name` varchar(64),
|
||||||
|
`host_ip` varchar(32),
|
||||||
|
`host_port` INTEGER,
|
||||||
|
`sys_type` INTEGER DEFAULT 0,
|
||||||
|
`auth_type` INTEGER,
|
||||||
|
`protocol` INTEGER,
|
||||||
|
`user_name` varchar(64),
|
||||||
|
`ret_code` INTEGER,
|
||||||
|
`begin_time` INTEGER,
|
||||||
|
`end_time` INTEGER,
|
||||||
|
`log_time` varchar(64)
|
||||||
|
);""".format(db.table_prefix))
|
||||||
|
|
||||||
|
_admin_sec_password = sec_generate_password('admin')
|
||||||
|
|
||||||
|
_db_exec(db, step_begin, step_end,
|
||||||
|
'建立管理员账号',
|
||||||
|
'INSERT INTO `{}account` VALUES (1, 100, "admin", "{}", 0, 0, "超级管理员");'.format(db.table_prefix, _admin_sec_password)
|
||||||
|
)
|
||||||
|
|
||||||
|
_db_exec(db, step_begin, step_end,
|
||||||
|
'设定数据库版本',
|
||||||
|
'INSERT INTO `{}config` VALUES ("db_ver", "{}");'.format(db.table_prefix, TELEPORT_DATABASE_VERSION)
|
||||||
|
)
|
||||||
|
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
log.e('ERROR')
|
||||||
|
return False
|
||||||
|
|
|
@ -13,6 +13,7 @@ cfg = app_cfg()
|
||||||
|
|
||||||
__all__ = ['get_db']
|
__all__ = ['get_db']
|
||||||
|
|
||||||
|
|
||||||
# 注意,每次调整数据库结构,必须增加版本号,并且在升级接口中编写对应的升级操作
|
# 注意,每次调整数据库结构,必须增加版本号,并且在升级接口中编写对应的升级操作
|
||||||
# TELEPORT_DATABASE_VERSION = 2
|
# TELEPORT_DATABASE_VERSION = 2
|
||||||
|
|
||||||
|
@ -46,15 +47,15 @@ class TPDatabase:
|
||||||
return
|
return
|
||||||
|
|
||||||
# 看看数据库中是否存在用户表(如果不存在,可能是一个空数据库文件),则可能是一个新安装的系统
|
# 看看数据库中是否存在用户表(如果不存在,可能是一个空数据库文件),则可能是一个新安装的系统
|
||||||
ret = self.query('SELECT COUNT(*) FROM sqlite_master where type="table" and name="ts_account";')
|
ret = self.query('SELECT COUNT(*) FROM `sqlite_master` WHERE `type`="table" AND `name`="{}account";'.format(self._table_prefix))
|
||||||
if ret[0][0] == 0:
|
if ret is None or ret[0][0] == 0:
|
||||||
log.w('database need create.\n')
|
log.w('database need create.\n')
|
||||||
self.need_create = True
|
self.need_create = True
|
||||||
return
|
return
|
||||||
|
|
||||||
# 尝试从配置表中读取当前数据库版本号(如果不存在,说明是比较旧的版本了,则置为0)
|
# 尝试从配置表中读取当前数据库版本号(如果不存在,说明是比较旧的版本了,则置为0)
|
||||||
ret = self.query('SELECT value FROM ts_config where name="db_ver";')
|
ret = self.query('SELECT `value` FROM {}config WHERE `name`="db_ver";'.format(self._table_prefix))
|
||||||
if 0 == len(ret):
|
if ret is None or 0 == len(ret):
|
||||||
log.w('database need upgrade.\n')
|
log.w('database need upgrade.\n')
|
||||||
self.need_upgrade = True
|
self.need_upgrade = True
|
||||||
|
|
||||||
|
@ -64,10 +65,13 @@ class TPDatabase:
|
||||||
def exec(self, sql):
|
def exec(self, sql):
|
||||||
return self._conn_pool.exec(sql)
|
return self._conn_pool.exec(sql)
|
||||||
|
|
||||||
|
|
||||||
def create_and_init(self, step_begin, step_end):
|
def create_and_init(self, step_begin, step_end):
|
||||||
step_begin('准备创建数据表')
|
step_begin('准备创建数据表')
|
||||||
create_and_init(self, step_begin, step_end)
|
if create_and_init(self, step_begin, step_end):
|
||||||
|
self.need_create = False
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class TPDatabasePool:
|
class TPDatabasePool:
|
||||||
|
|
|
@ -69,7 +69,6 @@ def async_enc(data):
|
||||||
|
|
||||||
|
|
||||||
_captcha_chars = 'AaCDdEeFfHJjKkLMmNnPpQRTtVvWwXxYy34679'
|
_captcha_chars = 'AaCDdEeFfHJjKkLMmNnPpQRTtVvWwXxYy34679'
|
||||||
# _font_dir = os.path.join(cfg.res_path, 'fonts')
|
|
||||||
|
|
||||||
|
|
||||||
def gen_captcha():
|
def gen_captcha():
|
||||||
|
@ -86,7 +85,7 @@ def gen_captcha():
|
||||||
os.path.join(cfg.res_path, 'fonts', '001.ttf')
|
os.path.join(cfg.res_path, 'fonts', '001.ttf')
|
||||||
],
|
],
|
||||||
# font_sizes=(28, 34, 36, 32),
|
# font_sizes=(28, 34, 36, 32),
|
||||||
font_sizes=(34, 38, 32),
|
font_sizes=(34, 40, 32, 36),
|
||||||
color='#63a8f5',
|
color='#63a8f5',
|
||||||
# squeeze_factor=1.2,
|
# squeeze_factor=1.2,
|
||||||
squeeze_factor=0.9,
|
squeeze_factor=0.9,
|
||||||
|
@ -135,7 +134,6 @@ def sec_generate_password(password):
|
||||||
|
|
||||||
ret = '{}:{}:{}'.format(_hash_type, _salt, _val)
|
ret = '{}:{}:{}'.format(_hash_type, _salt, _val)
|
||||||
|
|
||||||
print(ret, len(ret))
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,11 @@ from urllib.parse import quote
|
||||||
import mako.lookup
|
import mako.lookup
|
||||||
import mako.template
|
import mako.template
|
||||||
import tornado.web
|
import tornado.web
|
||||||
from tornado.escape import json_encode
|
|
||||||
|
|
||||||
from eom_app.app.const import *
|
|
||||||
from eom_app.app.session import web_session, SESSION_EXPIRE
|
|
||||||
from eom_app.app.configs import app_cfg
|
from eom_app.app.configs import app_cfg
|
||||||
|
from eom_app.app.const import *
|
||||||
from eom_app.app.db import get_db
|
from eom_app.app.db import get_db
|
||||||
|
from eom_app.app.session import web_session, SESSION_EXPIRE
|
||||||
|
from tornado.escape import json_encode
|
||||||
|
|
||||||
cfg = app_cfg()
|
cfg = app_cfg()
|
||||||
|
|
||||||
|
@ -26,14 +25,11 @@ class TPBaseHandler(tornado.web.RequestHandler):
|
||||||
MODE_HTTP = 0
|
MODE_HTTP = 0
|
||||||
MODE_JSON = 1
|
MODE_JSON = 1
|
||||||
|
|
||||||
# MODE_JSONP = 2
|
|
||||||
|
|
||||||
def __init__(self, application, request, **kwargs):
|
def __init__(self, application, request, **kwargs):
|
||||||
super().__init__(application, request, **kwargs)
|
super().__init__(application, request, **kwargs)
|
||||||
|
|
||||||
self._s_id = None
|
self._s_id = None
|
||||||
self._mode = self.MODE_HTTP
|
self._mode = self.MODE_HTTP
|
||||||
# self._jsonp_callback = ''
|
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
template_path = self.get_template_path()
|
template_path = self.get_template_path()
|
||||||
|
@ -125,25 +121,6 @@ class TPBaseHandler(tornado.web.RequestHandler):
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
# class TPBaseAppHandler(TPBaseHandler):
|
|
||||||
# """
|
|
||||||
# 权限控制:如果处于维护模式,只有管理员登录后方可操作,其他用户均显示维护页面
|
|
||||||
# """
|
|
||||||
# def __init__(self, application, request, **kwargs):
|
|
||||||
# super().__init__(application, request, **kwargs)
|
|
||||||
#
|
|
||||||
# def prepare(self):
|
|
||||||
# super().prepare()
|
|
||||||
# if self._finished:
|
|
||||||
# return
|
|
||||||
#
|
|
||||||
# if cfg.app_mode == APP_MODE_NORMAL:
|
|
||||||
# return
|
|
||||||
#
|
|
||||||
# # self.redirect('/maintenance')
|
|
||||||
# self.render('maintenance/index.mako')
|
|
||||||
|
|
||||||
|
|
||||||
class TPBaseJsonHandler(TPBaseHandler):
|
class TPBaseJsonHandler(TPBaseHandler):
|
||||||
"""
|
"""
|
||||||
所有返回JSON数据的控制器均从本类集成,返回的数据格式一律包含三个字段:code/msg/data
|
所有返回JSON数据的控制器均从本类集成,返回的数据格式一律包含三个字段:code/msg/data
|
||||||
|
@ -167,7 +144,6 @@ class TPBaseUserAuthHandler(TPBaseHandler):
|
||||||
return
|
return
|
||||||
|
|
||||||
reference = self.request.uri
|
reference = self.request.uri
|
||||||
print(reference)
|
|
||||||
|
|
||||||
user = self.get_current_user()
|
user = self.get_current_user()
|
||||||
if not user['is_login']:
|
if not user['is_login']:
|
||||||
|
@ -177,10 +153,6 @@ class TPBaseUserAuthHandler(TPBaseHandler):
|
||||||
else:
|
else:
|
||||||
self.redirect('/auth/login')
|
self.redirect('/auth/login')
|
||||||
else:
|
else:
|
||||||
# if cfg.app_mode == APP_MODE_MAINTENANCE and user['type'] != 100:
|
|
||||||
# self.render('maintenance/index.mako')
|
|
||||||
# else:
|
|
||||||
# pass
|
|
||||||
if cfg.app_mode == APP_MODE_MAINTENANCE:
|
if cfg.app_mode == APP_MODE_MAINTENANCE:
|
||||||
if user['type'] != 100:
|
if user['type'] != 100:
|
||||||
self.render('maintenance/index.mako')
|
self.render('maintenance/index.mako')
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import time
|
|
||||||
import threading
|
import threading
|
||||||
from .base import TPBaseUserAuthHandler, TPBaseAdminAuthHandler, TPBaseAdminAuthJsonHandler
|
import time
|
||||||
|
|
||||||
|
from eom_app.app.configs import app_cfg
|
||||||
|
from eom_app.app.const import *
|
||||||
from eom_app.app.db import get_db
|
from eom_app.app.db import get_db
|
||||||
from eom_app.app.util import sec_generate_password, sec_verify_password
|
from .base import TPBaseUserAuthHandler, TPBaseAdminAuthHandler, TPBaseAdminAuthJsonHandler
|
||||||
|
|
||||||
|
cfg = app_cfg()
|
||||||
|
|
||||||
|
# from eom_app.app.util import sec_generate_password, sec_verify_password
|
||||||
|
|
||||||
|
|
||||||
class IndexHandler(TPBaseUserAuthHandler):
|
class IndexHandler(TPBaseUserAuthHandler):
|
||||||
|
@ -15,18 +21,22 @@ class IndexHandler(TPBaseUserAuthHandler):
|
||||||
|
|
||||||
class InstallHandler(TPBaseAdminAuthHandler):
|
class InstallHandler(TPBaseAdminAuthHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
if get_db().need_upgrade:
|
if get_db().need_create:
|
||||||
|
self.render('maintenance/install.mako')
|
||||||
|
elif get_db().need_upgrade:
|
||||||
return self.redirect('/maintenance/upgrade')
|
return self.redirect('/maintenance/upgrade')
|
||||||
|
else:
|
||||||
self.render('maintenance/install.mako')
|
self.redirect('/')
|
||||||
|
|
||||||
|
|
||||||
class UpgradeHandler(TPBaseAdminAuthHandler):
|
class UpgradeHandler(TPBaseAdminAuthHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
if get_db().need_create:
|
if get_db().need_create:
|
||||||
return self.redirect('/maintenance/install')
|
return self.redirect('/maintenance/install')
|
||||||
|
elif get_db().need_upgrade:
|
||||||
self.render('maintenance/upgrade.mako')
|
self.render('maintenance/upgrade.mako')
|
||||||
|
else:
|
||||||
|
self.redirect('/')
|
||||||
|
|
||||||
|
|
||||||
class RpcThreadManage:
|
class RpcThreadManage:
|
||||||
|
@ -86,7 +96,8 @@ class RpcThreadManage:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
# self._add_step_result(tid, 0, '正在初始化 1...')
|
# self._add_step_result(tid, 0, '正在初始化 1...')
|
||||||
|
|
||||||
get_db().create_and_init(_step_begin, _step_end)
|
if get_db().create_and_init(_step_begin, _step_end):
|
||||||
|
cfg.app_mode = APP_MODE_NORMAL
|
||||||
|
|
||||||
self._step_begin(tid, '操作已完成')
|
self._step_begin(tid, '操作已完成')
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
from eom_app.app.const import *
|
from eom_app.app.const import *
|
||||||
from eom_app.app.configs import app_cfg
|
from eom_app.app.configs import app_cfg
|
||||||
|
from eom_app.app.db import get_db
|
||||||
|
from eom_app.app.util import sec_generate_password, sec_verify_password
|
||||||
|
|
||||||
from .common import *
|
from .common import *
|
||||||
|
|
||||||
|
@ -10,12 +12,10 @@ cfg = app_cfg()
|
||||||
|
|
||||||
|
|
||||||
def verify_user(name, password):
|
def verify_user(name, password):
|
||||||
_password = hashlib.sha256(password.encode()).hexdigest()
|
db = get_db()
|
||||||
string_sql = 'select account_id, account_type, ' \
|
|
||||||
'account_name FROM ts_account WHERE account_name =\'{}\' AND account_pwd = \'{}\''.format(name, _password)
|
|
||||||
|
|
||||||
sql_exec = get_db_con()
|
sql = 'SELECT `account_id`, `account_type`, `account_name`, `account_pwd` FROM `{}account` WHERE `account_name`="{}";'.format(db.table_prefix, name)
|
||||||
db_ret = sql_exec.ExecProcQuery(string_sql)
|
db_ret = db.query(sql)
|
||||||
if db_ret is None:
|
if db_ret is None:
|
||||||
# 特别地,如果无法取得数据库连接,有可能是新安装的系统,尚未建立数据库,此时应该处于维护模式
|
# 特别地,如果无法取得数据库连接,有可能是新安装的系统,尚未建立数据库,此时应该处于维护模式
|
||||||
# 因此可以特别地处理用户验证:用户名admin,密码admin可以登录为管理员
|
# 因此可以特别地处理用户验证:用户名admin,密码admin可以登录为管理员
|
||||||
|
@ -26,25 +26,57 @@ def verify_user(name, password):
|
||||||
|
|
||||||
if len(db_ret) != 1:
|
if len(db_ret) != 1:
|
||||||
return 0, 0, ''
|
return 0, 0, ''
|
||||||
user_id, account_type, name = db_ret[0]
|
|
||||||
|
user_id = db_ret[0][0]
|
||||||
|
account_type = db_ret[0][1]
|
||||||
|
name = db_ret[0][2]
|
||||||
|
if not sec_verify_password(password, db_ret[0][3]):
|
||||||
|
# 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下
|
||||||
|
if db_ret[0][3] != hashlib.sha256(password.encode()).hexdigest():
|
||||||
|
return 0, 0, ''
|
||||||
|
else:
|
||||||
|
# 发现此用户的密码散列格式还是旧的,更新成新的吧!
|
||||||
|
_new_sec_password = sec_generate_password(password)
|
||||||
|
sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={}'.format(db.table_prefix, _new_sec_password, int(user_id))
|
||||||
|
db.exec(sql)
|
||||||
|
|
||||||
return user_id, account_type, name
|
return user_id, account_type, name
|
||||||
|
|
||||||
|
|
||||||
def modify_pwd(old_pwd, new_pwd, user_id):
|
def modify_pwd(old_pwd, new_pwd, user_id):
|
||||||
sql_exec = get_db_con()
|
db = get_db()
|
||||||
new_pwd = hashlib.sha256(new_pwd.encode()).hexdigest()
|
sql = 'SELECT `account_pwd` FROM `{}account` WHERE `account_id`={};'.format(db.table_prefix, int(user_id))
|
||||||
old_pwd = hashlib.sha256(old_pwd.encode()).hexdigest()
|
db_ret = db.query(sql)
|
||||||
|
if db_ret is None or len(db_ret) != 1:
|
||||||
string_sql = 'SELECT account_id FROM ts_account WHERE account_pwd = \'{}\' AND account_id = {};'.format(old_pwd, int(user_id))
|
|
||||||
db_ret = sql_exec.ExecProcQuery(string_sql)
|
|
||||||
if len(db_ret) != 1:
|
|
||||||
return -2
|
return -2
|
||||||
string_sql = 'UPDATE ts_account SET account_pwd = \'{}\' WHERE account_pwd = \'{}\' AND account_id = {}'.format(new_pwd, old_pwd, int(user_id))
|
|
||||||
|
|
||||||
ret = sql_exec.ExecProcNonQuery(string_sql)
|
if not sec_verify_password(old_pwd, db_ret[0][0]):
|
||||||
if ret:
|
# 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下
|
||||||
|
if db_ret[0][0] != hashlib.sha256(old_pwd.encode()).hexdigest():
|
||||||
|
return -2
|
||||||
|
|
||||||
|
_new_sec_password = sec_generate_password(new_pwd)
|
||||||
|
sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={}'.format(db.table_prefix, _new_sec_password, int(user_id))
|
||||||
|
db_ret = db.exec(sql)
|
||||||
|
if db_ret:
|
||||||
return 0
|
return 0
|
||||||
return -3
|
else:
|
||||||
|
return -3
|
||||||
|
|
||||||
|
# sql_exec = get_db_con()
|
||||||
|
# new_pwd = hashlib.sha256(new_pwd.encode()).hexdigest()
|
||||||
|
# old_pwd = hashlib.sha256(old_pwd.encode()).hexdigest()
|
||||||
|
|
||||||
|
# string_sql = 'SELECT account_id FROM ts_account WHERE account_pwd = \'{}\' AND account_id = {};'.format(old_pwd, int(user_id))
|
||||||
|
# db_ret = sql_exec.ExecProcQuery(string_sql)
|
||||||
|
# if len(db_ret) != 1:
|
||||||
|
# return -2
|
||||||
|
# string_sql = 'UPDATE ts_account SET account_pwd = \'{}\' WHERE account_pwd = \'{}\' AND account_id = {}'.format(new_pwd, old_pwd, int(user_id))
|
||||||
|
#
|
||||||
|
# ret = sql_exec.ExecProcNonQuery(string_sql)
|
||||||
|
# if ret:
|
||||||
|
# return 0
|
||||||
|
# return -3
|
||||||
|
|
||||||
|
|
||||||
def get_user_list():
|
def get_user_list():
|
||||||
|
@ -72,7 +104,7 @@ def get_user_list():
|
||||||
def delete_user(user_id):
|
def delete_user(user_id):
|
||||||
sql_exec = get_db_con()
|
sql_exec = get_db_con()
|
||||||
#
|
#
|
||||||
str_sql = 'DELETE FROM ts_account WHERE account_id = {} '.format(user_id)
|
str_sql = 'DELETE FROM ts_account WHERE account_id={};'.format(user_id)
|
||||||
ret = sql_exec.ExecProcNonQuery(str_sql)
|
ret = sql_exec.ExecProcNonQuery(str_sql)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -80,27 +112,32 @@ def delete_user(user_id):
|
||||||
def lock_user(user_id, lock_status):
|
def lock_user(user_id, lock_status):
|
||||||
sql_exec = get_db_con()
|
sql_exec = get_db_con()
|
||||||
#
|
#
|
||||||
str_sql = 'UPDATE ts_account SET account_lock = {} ' \
|
str_sql = 'UPDATE ts_account SET account_lock={} ' \
|
||||||
' WHERE account_id = {}'.format(lock_status, user_id)
|
'WHERE account_id={};'.format(lock_status, user_id)
|
||||||
ret = sql_exec.ExecProcNonQuery(str_sql)
|
ret = sql_exec.ExecProcNonQuery(str_sql)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def reset_user(user_id):
|
def reset_user(user_id):
|
||||||
sql_exec = get_db_con()
|
# sql_exec = get_db_con()
|
||||||
#
|
#
|
||||||
user_pwd = hashlib.sha256("123456".encode()).hexdigest()
|
# user_pwd = hashlib.sha256("123456".encode()).hexdigest()
|
||||||
str_sql = 'UPDATE ts_account SET account_pwd = "{}" ' \
|
# str_sql = 'UPDATE ts_account SET account_pwd = "{}" ' \
|
||||||
' WHERE account_id = {}'.format(user_pwd, user_id)
|
# ' WHERE account_id = {}'.format(user_pwd, user_id)
|
||||||
ret = sql_exec.ExecProcNonQuery(str_sql)
|
# ret = sql_exec.ExecProcNonQuery(str_sql)
|
||||||
|
|
||||||
|
db = get_db()
|
||||||
|
_new_sec_password = sec_generate_password('123456')
|
||||||
|
sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={};'.format(db.table_prefix, _new_sec_password, int(user_id))
|
||||||
|
ret = db.exec(sql)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def modify_user(user_id, user_desc):
|
def modify_user(user_id, user_desc):
|
||||||
sql_exec = get_db_con()
|
sql_exec = get_db_con()
|
||||||
#
|
#
|
||||||
str_sql = 'UPDATE ts_account SET account_desc = \'{}\' ' \
|
str_sql = 'UPDATE ts_account SET account_desc="{}" ' \
|
||||||
' WHERE account_id = {}'.format(user_desc, user_id)
|
'WHERE account_id={};'.format(user_desc, user_id)
|
||||||
ret = sql_exec.ExecProcNonQuery(str_sql)
|
ret = sql_exec.ExecProcNonQuery(str_sql)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,23 @@
|
||||||
h2 {
|
h2 {
|
||||||
font-size: 160%;
|
font-size: 160%;
|
||||||
}
|
}
|
||||||
|
.steps-detail {
|
||||||
|
display: none;
|
||||||
|
margin:10px;
|
||||||
|
padding:10px;
|
||||||
|
border:1px solid #b4b4b4;
|
||||||
|
background-color: #dcdcdc;
|
||||||
|
}
|
||||||
|
.steps-detail p {
|
||||||
|
padding-left:5px;
|
||||||
|
margin:2px 0 2px 1px;
|
||||||
|
}
|
||||||
|
.steps-detail p.error {
|
||||||
|
color:#ffffff;
|
||||||
|
margin:2px 0 2px 0;
|
||||||
|
background-color: #cc3632;
|
||||||
|
border:1px solid #9c2a26;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</%block>
|
</%block>
|
||||||
|
|
||||||
|
@ -45,9 +62,7 @@
|
||||||
<button id="btn-create-db" type="button" class="btn btn-primary"><i class="fa fa-wrench fa-fw"></i> 开始创建</button>
|
<button id="btn-create-db" type="button" class="btn btn-primary"><i class="fa fa-wrench fa-fw"></i> 开始创建</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="step-detail">
|
<div id="steps-detail" class="steps-detail"></div>
|
||||||
<i class="fa fa-cog fa-spin"></i> 正在创建用户表...
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,11 +79,13 @@
|
||||||
ywl.on_init = function (cb_stack, cb_args) {
|
ywl.on_init = function (cb_stack, cb_args) {
|
||||||
ywl.dom = {
|
ywl.dom = {
|
||||||
btn_create_db: $('#btn-create-db'),
|
btn_create_db: $('#btn-create-db'),
|
||||||
|
steps_detail: $('#steps-detail')
|
||||||
};
|
};
|
||||||
|
|
||||||
ywl.dom.btn_create_db.click(function () {
|
ywl.dom.btn_create_db.click(function () {
|
||||||
|
|
||||||
ywl.dom.btn_create_db.attr('disabled', 'disabled');
|
ywl.dom.btn_create_db.attr('disabled', 'disabled').hide();
|
||||||
|
ywl.dom.steps_detail.show();
|
||||||
|
|
||||||
console.log('create-db-click');
|
console.log('create-db-click');
|
||||||
ywl.ajax_post_json('/maintenance/rpc', {cmd: 'create_db'},
|
ywl.ajax_post_json('/maintenance/rpc', {cmd: 'create_db'},
|
||||||
|
@ -81,9 +98,7 @@
|
||||||
.add(ywl.get_task_ret, {task_id: ret.data.task_id})
|
.add(ywl.get_task_ret, {task_id: ret.data.task_id})
|
||||||
.add(ywl.delay_exec, {delay_ms: 500})
|
.add(ywl.delay_exec, {delay_ms: 500})
|
||||||
.exec();
|
.exec();
|
||||||
|
}
|
||||||
## ywl.get_task_ret(ret.data.task_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
function () {
|
function () {
|
||||||
|
@ -104,7 +119,35 @@
|
||||||
function (ret) {
|
function (ret) {
|
||||||
console.log('get_task_ret:', ret);
|
console.log('get_task_ret:', ret);
|
||||||
if (ret.code == 0) {
|
if (ret.code == 0) {
|
||||||
if(!ret.data.running) {
|
|
||||||
|
// show step progress.
|
||||||
|
var steps = ret.data.steps;
|
||||||
|
ywl.dom.steps_detail.empty();
|
||||||
|
|
||||||
|
var html = [];
|
||||||
|
var icon_class = '';
|
||||||
|
var err_class = '';
|
||||||
|
for(var i = 0; i < steps.length; ++i) {
|
||||||
|
if(steps[i].stat == 0)
|
||||||
|
icon_class = 'fa-check';
|
||||||
|
else
|
||||||
|
icon_class = 'fa-cog fa-spin';
|
||||||
|
if(steps[i].code != 0)
|
||||||
|
err_class = ' class="error"';
|
||||||
|
else
|
||||||
|
err_class = '';
|
||||||
|
html.push('<p');
|
||||||
|
html.push(err_class);
|
||||||
|
html.push('><i class="fa ');
|
||||||
|
html.push(icon_class);
|
||||||
|
html.push('"></i> ');
|
||||||
|
html.push(steps[i].msg);
|
||||||
|
html.push('</p>')
|
||||||
|
}
|
||||||
|
ywl.dom.steps_detail.html(html.join(''));
|
||||||
|
|
||||||
|
|
||||||
|
if (!ret.data.running) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue