mirror of https://github.com/tp4a/teleport
1. 调整安装页面,根据用户配置文件显示要操作的数据库;2. 支持重新加载配置文件;3. 调整几个文件名;
parent
233702811e
commit
7e80ab6ed3
|
@ -3,6 +3,7 @@
|
|||
import configparser
|
||||
import os
|
||||
|
||||
import eom_common.eomcore.utils as utils
|
||||
from eom_common.eomcore.logger import log
|
||||
|
||||
__all__ = ['app_cfg']
|
||||
|
@ -187,6 +188,13 @@ class BaseAppConfig(dict):
|
|||
def _on_load(self, cfg_parser):
|
||||
raise RuntimeError('can not create instance for base class.')
|
||||
|
||||
def reload(self):
|
||||
self['_cfg_default'] = {}
|
||||
self['_cfg_loaded'] = {}
|
||||
self['_kvs'] = {'_': self['_kvs']['_']}
|
||||
self._on_init()
|
||||
return self.load(self['_cfg_file'])
|
||||
|
||||
def set_kv(self, key, val):
|
||||
x = key.split('::')
|
||||
if 1 == len(x):
|
||||
|
@ -420,7 +428,7 @@ class AppConfig(BaseAppConfig):
|
|||
self.set_default('database::mysql-db', 'teleport', 'mysql-db=teleport')
|
||||
self.set_default('database::mysql-prefix', 'tp_', 'mysql-prefix=tp_')
|
||||
self.set_default('database::mysql-user', 'teleport', 'mysql-user=teleport')
|
||||
self.set_default('database::mysql-password', None, 'mysql-password=password')
|
||||
self.set_default('database::mysql-password', 'password', 'mysql-password=password')
|
||||
|
||||
def _on_get_save_info(self):
|
||||
return [
|
||||
|
@ -498,6 +506,21 @@ class AppConfig(BaseAppConfig):
|
|||
if _tmp_str is not None:
|
||||
self.set_kv('database::mysql-password', _tmp_str)
|
||||
|
||||
_log_file, ok = self.get_str('common::log-file')
|
||||
if ok:
|
||||
self.log_path = os.path.abspath(os.path.dirname(_log_file))
|
||||
else:
|
||||
_log_file = os.path.join(self.log_path, 'tpweb.log')
|
||||
self.set_default('common::log-file', _log_file)
|
||||
|
||||
if not os.path.exists(self.log_path):
|
||||
utils.make_dir(self.log_path)
|
||||
if not os.path.exists(self.log_path):
|
||||
log.e('Can not create log path:{}\n'.format(self.log_path))
|
||||
return False
|
||||
|
||||
log.set_attribute(filename=_log_file)
|
||||
|
||||
return True
|
||||
|
||||
def update_core(self, conf_data):
|
||||
|
|
|
@ -33,24 +33,25 @@ class WebServerCore:
|
|||
cfg.template_path = os.path.abspath(options['template_path'])
|
||||
cfg.res_path = os.path.abspath(options['res_path'])
|
||||
cfg.cfg_path = os.path.abspath(options['cfg_path'])
|
||||
cfg.log_path = os.path.abspath(options['log_path'])
|
||||
|
||||
_cfg_file = os.path.join(cfg.cfg_path, 'web.ini')
|
||||
if not cfg.load(_cfg_file):
|
||||
return False
|
||||
|
||||
_log_file, ok = cfg.get_str('common::log-file')
|
||||
if ok:
|
||||
cfg.log_path = os.path.abspath(os.path.dirname(_log_file))
|
||||
else:
|
||||
cfg.log_path = os.path.abspath(options['log_path'])
|
||||
_log_file = os.path.join(cfg.log_path, 'tpweb.log')
|
||||
cfg.set_default('common::log-file', _log_file)
|
||||
|
||||
if not os.path.exists(cfg.log_path):
|
||||
utils.make_dir(cfg.log_path)
|
||||
if not os.path.exists(cfg.log_path):
|
||||
log.e('Can not create log path:{}\n'.format(cfg.log_path))
|
||||
return False
|
||||
# _log_file, ok = cfg.get_str('common::log-file')
|
||||
# if ok:
|
||||
# cfg.log_path = os.path.abspath(os.path.dirname(_log_file))
|
||||
# else:
|
||||
# cfg.log_path = os.path.abspath(options['log_path'])
|
||||
# _log_file = os.path.join(cfg.log_path, 'tpweb.log')
|
||||
# cfg.set_default('common::log-file', _log_file)
|
||||
#
|
||||
# if not os.path.exists(cfg.log_path):
|
||||
# utils.make_dir(cfg.log_path)
|
||||
# if not os.path.exists(cfg.log_path):
|
||||
# log.e('Can not create log path:{}\n'.format(cfg.log_path))
|
||||
# return False
|
||||
|
||||
# log.set_attribute(min_level=cfg.common.log_level, filename=cfg.common.log_file)
|
||||
# if cfg.common.debug_mode:
|
||||
|
|
|
@ -181,6 +181,8 @@ class TPDatabase:
|
|||
elif self.db_type == self.DB_TYPE_MYSQL:
|
||||
# select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='dbname' and TABLE_NAME='tablename' ;
|
||||
ret = self.query('SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA="{}" and TABLE_NAME="{}";'.format(self.mysql_db, table_name))
|
||||
if ret is None:
|
||||
return None
|
||||
if len(ret) == 0:
|
||||
return None
|
||||
else:
|
||||
|
|
|
@ -49,7 +49,7 @@ class IndexHandler(TPBaseUserAuthHandler):
|
|||
param['cert_list'] = host.get_cert_list()
|
||||
self.render('host/admin_index.mako', page_param=json.dumps(param))
|
||||
else:
|
||||
self.render('host/common_index.mako', page_param=json.dumps(param))
|
||||
self.render('host/user_index.mako', page_param=json.dumps(param))
|
||||
|
||||
|
||||
class UploadAndImportHandler(TPBaseAdminAuthHandler):
|
||||
|
|
|
@ -19,7 +19,10 @@ class IndexHandler(TPBaseUserAuthHandler):
|
|||
class InstallHandler(TPBaseAdminAuthHandler):
|
||||
def get(self):
|
||||
if get_db().need_create:
|
||||
cfg.reload()
|
||||
|
||||
_db = get_db()
|
||||
_db.init()
|
||||
|
||||
db = {'type': _db.db_type}
|
||||
if _db.db_type == _db.DB_TYPE_SQLITE:
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
<%block name="extend_js">
|
||||
<script type="text/javascript" src="${ static_url('js/ui/teleport.js') }"></script>
|
||||
<script type="text/javascript" src="${ static_url('js/ui/admin_host.js') }"></script>
|
||||
<script type="text/javascript" src="${ static_url('js/ui/host/admin.js') }"></script>
|
||||
</%block>
|
||||
|
||||
<%block name="breadcrumb">
|
||||
|
|
|
@ -1,115 +1,115 @@
|
|||
<%!
|
||||
page_title_ = '主机列表'
|
||||
page_menu_ = ['host']
|
||||
page_id_ = 'host'
|
||||
%>
|
||||
<%inherit file="../page_base.mako"/>
|
||||
|
||||
<%block name="extend_js">
|
||||
<script type="text/javascript" src="${ static_url('js/ui/teleport.js') }"></script>
|
||||
<script type="text/javascript" src="${ static_url('js/ui/common_host.js') }"></script>
|
||||
</%block>
|
||||
|
||||
<%block name="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li><i class="fa fa-server fa-fw"></i> ${self.attr.page_title_}</li>
|
||||
</ol>
|
||||
</%block>
|
||||
|
||||
## Begin Main Body.
|
||||
|
||||
<div class="page-content">
|
||||
|
||||
<!-- begin box -->
|
||||
<div class="box" id="ywl_host_list">
|
||||
|
||||
<!-- begin filter -->
|
||||
<div class="page-filter">
|
||||
<div class="" style="float:right;">
|
||||
<span id="tp-assist-current-version" style="margin-right: 50px"> 助手版本:未知</span>
|
||||
<a href="javascript:;" class="btn btn-sm btn-primary" ywl-filter="reload"><i class="fa fa-repeat fa-fw"></i> 刷新</a>
|
||||
</div>
|
||||
|
||||
<div class="">
|
||||
|
||||
<div class="input-group input-group-sm" style="display:inline-block;margin-right:10px;">
|
||||
<span class="input-group-addon" style="display:inline-block;width:auto; line-height:28px;height:30px;padding:0 10px;font-size:13px;">主机分组</span>
|
||||
<div class="input-group-btn" ywl-filter="host-group" style="display:inline-block;margin-left:-4px;">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span>正在加载</span> <span class="caret"></span></button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>正在加载</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="input-group input-group-sm" style="display:inline-block;margin-right:10px;">
|
||||
<span class="input-group-addon" style="display:inline-block;width:auto; line-height:28px;height:30px;padding:0 10px;font-size:13px;">系统</span>
|
||||
<div class="input-group-btn" ywl-filter="system-type" style="display:inline-block;margin-left:-4px;">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span>正在加载</span> <span class="caret"></span></button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>正在加载</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="input-group input-group-sm" ywl-filter="search" style="display:inline-block;">
|
||||
<input type="text" class="form-control" placeholder="搜索 ID 或 IP" style="display:inline-block;">
|
||||
<span class="input-group-btn" style="display:inline-block;margin-left:-4px;"><button type="button" class="btn btn-default"><i class="fa fa-search fa-fw"></i></button></span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- end filter -->
|
||||
|
||||
|
||||
<table class="table table-striped table-bordered table-hover table-data no-footer dtr-inline" ywl-table="host-list"></table>
|
||||
|
||||
<!-- begin page-nav -->
|
||||
<div class="page-nav" ywl-paging="host-list">
|
||||
|
||||
<div class="" style="float:right;">
|
||||
<nav>
|
||||
<ul class="pagination pagination-sm"></ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div style="float:right;margin-right:30px;">
|
||||
<div class="breadcrumb-container">
|
||||
<ol class="breadcrumb">
|
||||
<li><i class="fa fa-list fa-fw"></i> 记录总数 <strong ywl-field="recorder_total">0</strong></li>
|
||||
<li>页数 <strong><span ywl-field="page_current">1</span>/<span ywl-field="page_total">1</span></strong></li>
|
||||
<li>每页显示
|
||||
<label>
|
||||
<select></select>
|
||||
</label>
|
||||
条记录
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- end page-nav -->
|
||||
|
||||
</div>
|
||||
<!-- end of box -->
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<%block name="extend_content">
|
||||
</%block>
|
||||
|
||||
|
||||
|
||||
<%block name="embed_js">
|
||||
<script type="text/javascript">
|
||||
ywl.add_page_options(${page_param});
|
||||
</script>
|
||||
</%block>
|
||||
<%!
|
||||
page_title_ = '主机列表'
|
||||
page_menu_ = ['host']
|
||||
page_id_ = 'host'
|
||||
%>
|
||||
<%inherit file="../page_base.mako"/>
|
||||
|
||||
<%block name="extend_js">
|
||||
<script type="text/javascript" src="${ static_url('js/ui/teleport.js') }"></script>
|
||||
<script type="text/javascript" src="${ static_url('js/ui/host/user.js') }"></script>
|
||||
</%block>
|
||||
|
||||
<%block name="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li><i class="fa fa-server fa-fw"></i> ${self.attr.page_title_}</li>
|
||||
</ol>
|
||||
</%block>
|
||||
|
||||
## Begin Main Body.
|
||||
|
||||
<div class="page-content">
|
||||
|
||||
<!-- begin box -->
|
||||
<div class="box" id="ywl_host_list">
|
||||
|
||||
<!-- begin filter -->
|
||||
<div class="page-filter">
|
||||
<div class="" style="float:right;">
|
||||
<span id="tp-assist-current-version" style="margin-right: 50px"> 助手版本:未知</span>
|
||||
<a href="javascript:;" class="btn btn-sm btn-primary" ywl-filter="reload"><i class="fa fa-repeat fa-fw"></i> 刷新</a>
|
||||
</div>
|
||||
|
||||
<div class="">
|
||||
|
||||
<div class="input-group input-group-sm" style="display:inline-block;margin-right:10px;">
|
||||
<span class="input-group-addon" style="display:inline-block;width:auto; line-height:28px;height:30px;padding:0 10px;font-size:13px;">主机分组</span>
|
||||
<div class="input-group-btn" ywl-filter="host-group" style="display:inline-block;margin-left:-4px;">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span>正在加载</span> <span class="caret"></span></button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>正在加载</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="input-group input-group-sm" style="display:inline-block;margin-right:10px;">
|
||||
<span class="input-group-addon" style="display:inline-block;width:auto; line-height:28px;height:30px;padding:0 10px;font-size:13px;">系统</span>
|
||||
<div class="input-group-btn" ywl-filter="system-type" style="display:inline-block;margin-left:-4px;">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span>正在加载</span> <span class="caret"></span></button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>正在加载</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="input-group input-group-sm" ywl-filter="search" style="display:inline-block;">
|
||||
<input type="text" class="form-control" placeholder="搜索 ID 或 IP" style="display:inline-block;">
|
||||
<span class="input-group-btn" style="display:inline-block;margin-left:-4px;"><button type="button" class="btn btn-default"><i class="fa fa-search fa-fw"></i></button></span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- end filter -->
|
||||
|
||||
|
||||
<table class="table table-striped table-bordered table-hover table-data no-footer dtr-inline" ywl-table="host-list"></table>
|
||||
|
||||
<!-- begin page-nav -->
|
||||
<div class="page-nav" ywl-paging="host-list">
|
||||
|
||||
<div class="" style="float:right;">
|
||||
<nav>
|
||||
<ul class="pagination pagination-sm"></ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div style="float:right;margin-right:30px;">
|
||||
<div class="breadcrumb-container">
|
||||
<ol class="breadcrumb">
|
||||
<li><i class="fa fa-list fa-fw"></i> 记录总数 <strong ywl-field="recorder_total">0</strong></li>
|
||||
<li>页数 <strong><span ywl-field="page_current">1</span>/<span ywl-field="page_total">1</span></strong></li>
|
||||
<li>每页显示
|
||||
<label>
|
||||
<select></select>
|
||||
</label>
|
||||
条记录
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- end page-nav -->
|
||||
|
||||
</div>
|
||||
<!-- end of box -->
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<%block name="extend_content">
|
||||
</%block>
|
||||
|
||||
|
||||
|
||||
<%block name="embed_js">
|
||||
<script type="text/javascript">
|
||||
ywl.add_page_options(${page_param});
|
||||
</script>
|
||||
</%block>
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
.steps-detail {
|
||||
display: none;
|
||||
margin: 10px;
|
||||
## margin: 10px;
|
||||
padding: 10px;
|
||||
border: 1px solid #b4b4b4;
|
||||
background-color: #dcdcdc;
|
||||
|
@ -44,8 +44,30 @@
|
|||
border: 1px solid #9c2a26;
|
||||
}
|
||||
|
||||
#sqlite-info, #mysql-info {
|
||||
display: none;
|
||||
## #db-info {
|
||||
## }
|
||||
|
||||
.table {
|
||||
width: auto;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.table .key {
|
||||
## width:240px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.table .value {
|
||||
text-align: left;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.notice-box {
|
||||
border:1px solid #e2cab4;
|
||||
background-color: #ffe4cb;
|
||||
padding:15px;
|
||||
color: #000000;
|
||||
margin-bottom:10px;
|
||||
}
|
||||
</style>
|
||||
</%block>
|
||||
|
@ -62,11 +84,11 @@
|
|||
|
||||
<h2>第一步:创建数据表</h2>
|
||||
<div>
|
||||
<p>请选择要使用的数据库类型(暂时仅支持sqlite,其它类型开发中):</p>
|
||||
<input id="db-sqlite" type="radio" checked="checked" name="database" value="sqlite"/> <label for="db-sqlite">SQLite</label><br/>
|
||||
<input id="db-mysql" type="radio" name="database" value="mysql"/> <label for="db-mysql">MySQL(开发中,暂不支持)</label>
|
||||
<div id="sqlite-info"></div>
|
||||
<div id="mysql-info"></div>
|
||||
<p>TELEPORT支持<strong>SQLite</strong>和<strong>MySQL</strong>数据库,根据您的配置,将使用以下信息进行操作:</p>
|
||||
<table id="db-info" class="table"></table>
|
||||
<div class="notice-box">
|
||||
注意:如果以上配置并不是您所期望的,请修改您的配置文件,然后刷新本页面。
|
||||
</div>
|
||||
<div>
|
||||
<button id="btn-create-db" type="button" class="btn btn-primary"><i class="fa fa-wrench fa-fw"></i> 开始创建</button>
|
||||
</div>
|
||||
|
@ -77,7 +99,7 @@
|
|||
<div id="step2" style="display:none;">
|
||||
<hr/>
|
||||
<h2>已完成!</h2>
|
||||
<p>是的,没有第二步了,安装配置已经完成了!刷新页面即可进入Teleport主界面啦~~</p>
|
||||
<p>是的,没有第二步了,安装配置已经完成了!刷新页面即可进入 TELEPORT 主界面啦~~</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -91,20 +113,47 @@
|
|||
"use strict";
|
||||
ywl.add_page_options(${ page_param });
|
||||
|
||||
|
||||
ywl._make_info = function (key, value) {
|
||||
return '<tr><td class="key">' + key + ':</td><td class="value">' + value + '</td></tr>';
|
||||
};
|
||||
|
||||
ywl.on_init = function (cb_stack, cb_args) {
|
||||
ywl.dom = {
|
||||
btn_create_db: $('#btn-create-db'),
|
||||
steps_detail: $('#steps-detail'),
|
||||
sqlite_info: $('#sqlite-info'),
|
||||
mysql_info: $('#mysql-info')
|
||||
db_info: $('#db-info')
|
||||
};
|
||||
|
||||
var html = [];
|
||||
if (ywl.page_options.db.type === DB_TYPE_SQLITE) {
|
||||
html.push(ywl._make_info('数据库类型', 'SQLite'));
|
||||
html.push(ywl._make_info('数据库文件', ywl.page_options.db.sqlite_file));
|
||||
} else if (ywl.page_options.db.type === DB_TYPE_MYSQL) {
|
||||
html.push(ywl._make_info('数据库类型', 'MySQL'));
|
||||
html.push(ywl._make_info('MySQL主机', ywl.page_options.db.mysql_host));
|
||||
html.push(ywl._make_info('MySQL端口', ywl.page_options.db.mysql_port));
|
||||
html.push(ywl._make_info('数据库名称', ywl.page_options.db.mysql_db));
|
||||
html.push(ywl._make_info('用户名', ywl.page_options.db.mysql_user));
|
||||
|
||||
var _t = [];
|
||||
_t.push('<div class="notice-box">');
|
||||
_t.push('注意:请确保您在执行后续创建操作之前,已经在MySQL数据库中创建了数据库"');
|
||||
_t.push(ywl.page_options.db.mysql_db);
|
||||
_t.push('"和用户"');
|
||||
_t.push(ywl.page_options.db.mysql_user);
|
||||
_t.push('",并为用户"');
|
||||
_t.push(ywl.page_options.db.mysql_user);
|
||||
_t.push('"设置了在数据库"');
|
||||
_t.push(ywl.page_options.db.mysql_db);
|
||||
_t.push('"创建表的权限!');
|
||||
_t.push('</div>');
|
||||
ywl.dom.db_info.after(_t.join(''));
|
||||
} else {
|
||||
ywl.show_message('error', '未知的数据库类型,请检查您的配置文件!');
|
||||
ywl.dom.btn_create_db.attr('disabled', 'disabled').hide();
|
||||
}
|
||||
ywl.dom.db_info.append(html.join(''));
|
||||
|
||||
ywl.dom.btn_create_db.click(function () {
|
||||
|
||||
|
@ -145,6 +194,7 @@
|
|||
if (ret.code === TPE_OK) {
|
||||
|
||||
// show step progress.
|
||||
var all_ok = true;
|
||||
var steps = ret.data.steps;
|
||||
ywl.dom.steps_detail.empty();
|
||||
|
||||
|
@ -161,6 +211,7 @@
|
|||
icon_class = 'fa-exclamation-circle';
|
||||
err_class = ' class="error"';
|
||||
steps[i].msg += ' 失败!'
|
||||
all_ok = false;
|
||||
}
|
||||
else {
|
||||
err_class = '';
|
||||
|
@ -178,7 +229,9 @@
|
|||
|
||||
|
||||
if (!ret.data.running) {
|
||||
$('#step2').show('fast');
|
||||
if (all_ok) {
|
||||
$('#step2').show('fast');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue