修复调整路径带来的小bug。

pull/32/merge
apexliu 2017-03-27 05:11:47 +08:00
parent d3c581a857
commit a592da9626
12 changed files with 110 additions and 159 deletions

View File

@ -85,7 +85,7 @@ class BuilderWin(BuilderBase):
utils.make_zip(self.path_tmp, self._final_file)
utils.remove(self.base_tmp)
# utils.remove(self.base_tmp)
class BuilderLinux(BuilderBase):

View File

@ -274,9 +274,9 @@ class InstallerBase:
cnt = len(l)
for i in range(cnt):
if int(l[i] < r[i]):
if int(l[i]) < int(r[i]):
return -1
elif int(l[i] > r[i]):
elif int(l[i]) > int(r[i]):
return 1
return 0
@ -396,7 +396,10 @@ class InstallerWin(InstallerBase):
utils.remove(self._log_path)
# only remove the installation path when it empty.
os.rmdir(self._install_path)
try:
os.rmdir(self._install_path)
except OSError:
pass
def _install_service(self):
cc.o(' - install teleport core service ... ', end='')
@ -430,8 +433,7 @@ class InstallerWin(InstallerBase):
raise RuntimeError('Can not start core service.')
cc.o(' - start teleport web service ...', end='')
_err, _o = utils.sys_exec(r'sc start "{}"'.format(self._web_service_name))
# print('start web', _err, _o)
_err, _ = utils.sys_exec(r'sc start "{}"'.format(self._web_service_name))
if _err == 0:
cc.i('[done]')
else:
@ -439,55 +441,47 @@ class InstallerWin(InstallerBase):
raise RuntimeError('Can not start web service.')
def _stop_service(self):
cc.o(' - stop teleport core service ... ', end='')
_err, _o = utils.sys_exec(r'sc stop "{}"'.format(self._core_service_name))
# print('stop core', _err, _o)
if _err == 1060 or _err == 1062 or _err == 0:
cc.i('[done]')
else:
cc.e('[failed]')
raise RuntimeError('can not stop core service.')
_check_service_name = [self._old_core_service_name, self._old_web_service_name, self._core_service_name,
self._web_service_name]
cc.o(' - stop teleport web service ... ', end='')
_err, _o = utils.sys_exec(r'sc stop "{}"'.format(self._web_service_name))
# print('stop web', _err, _o)
if _err == 1060 or _err == 1062 or _err == 0:
cc.i('[done]')
else:
cc.e('[failed]')
raise RuntimeError('can not stop web service.')
for _service_name in _check_service_name:
cc.o(' - stop service [{}] ... '.format(_service_name), end='')
_err, _ = utils.sys_exec(r'sc stop "{}"'.format(_service_name))
if _err == 1060 or _err == 1062 or _err == 0:
cc.i('[done]')
elif _err == 1072:
cc.e('[failed]')
raise RuntimeError('can not stop service [{}]. please close Service Manager and try again.'.format(_service_name))
else:
cc.e('[failed]')
raise RuntimeError('can not stop service [{}].'.format(_service_name))
def _uninstall_service(self):
cc.o(' - delete teleport core service ... ', end='')
_err, _o = utils.sys_exec(r'sc delete "{}"'.format(self._core_service_name))
# print('del core', _err, _o)
if _err == 1060 or _err == 0:
cc.i('[done]')
else:
cc.e('[failed]')
raise RuntimeError('Can not uninstall core service.')
_check_service_name = [self._old_core_service_name, self._old_web_service_name, self._core_service_name,
self._web_service_name]
cc.o(' - delete teleport web service ... ', end='')
_err, _o = utils.sys_exec(r'sc delete "{}"'.format(self._web_service_name))
# print('del web', _err, _o)
if _err == 1060 or _err == 0:
cc.i('[done]')
else:
cc.e('[failed]')
raise RuntimeError('Can not uninstall web service.')
for _service_name in _check_service_name:
cc.o(' - remove service [{}] ... '.format(_service_name), end='')
_err, _ = utils.sys_exec(r'sc delete "{}"'.format(_service_name))
if _err == 1060 or _err == 0:
cc.i('[done]')
elif _err == 1072:
cc.e('[failed]')
raise RuntimeError('can not remove service [{}]. please close Service Manager and try again.'.format(_service_name))
else:
cc.e('[failed]')
raise RuntimeError('can not remove service [{}].'.format(_service_name))
def _check_service(self):
cc.o(' - check teleport core service status ... ', end='')
_err, _o = utils.sys_exec(r'sc query "{}"'.format(self._core_service_name))
# print('chk core', _err, _o)
if _err == 1060 or _err == 0:
cc.i('[running]')
else:
cc.e('[not running]')
cc.o(' - check teleport web service status ... ', end='')
_err, _o = utils.sys_exec(r'sc delete "{}"'.format(self._web_service_name))
# print('chk web', _err, _o)
_err, _o = utils.sys_exec(r'sc query "{}"'.format(self._web_service_name))
if _err == 1060 or _err == 0:
cc.i('[running]')
else:

View File

@ -1,88 +0,0 @@
CREATE TABLE `ts_account` (
`account_id` integer PRIMARY KEY AUTOINCREMENT,
`account_type` int(11) DEFAULT 0,
`account_name` varchar(32) DEFAULT NULL,
`account_pwd` varchar(32) DEFAULT NULL,
`account_status` int(11) DEFAULT 0,
`account_lock` int(11) DEFAULT 0,
`account_desc` varchar(255)
);
INSERT INTO `main`.`ts_account` VALUES (1, 100, 'admin', '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918', 0, 0, '超级管理员');
CREATE TABLE `ts_auth`(
`auth_id` INTEGER PRIMARY KEY AUTOINCREMENT,
`account_name` varchar(256),
`host_id` INTEGER,
`host_auth_id` int(11) NOT NULL
);
CREATE TABLE `ts_cert` (
`cert_id` integer PRIMARY KEY AUTOINCREMENT,
`cert_name` varchar(256),
`cert_pub` varchar(2048) DEFAULT '',
`cert_pri` varchar(4096) DEFAULT '',
`cert_desc` varchar(256)
);
CREATE TABLE `ts_config` (
`name` varchar(256) NOT NULL,
`value` varchar(256),
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_rpc_port', 52080);
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_telnet_port', 52389);
INSERT INTO `main`.`ts_config` VALUES ('ts_server_rpc_ip', '127.0.0.1');
CREATE TABLE `ts_group` (
`group_id` integer PRIMARY KEY AUTOINCREMENT,
`group_name` varchar(255) DEFAULT''
);
CREATE TABLE `ts_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 ''
);
CREATE TABLE `ts_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)
);
CREATE TABLE `ts_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)
);

View File

@ -121,12 +121,6 @@ int _app_main(int argc, wchar_t** argv)
if (!_process_cmd_line(argc, argv))
return 1;
if (!g_env.init())
{
EXLOGE("[core] env init failed.\n");
return 1;
}
#ifdef EX_DEBUG
EXLOG_LEVEL(EX_LOG_LEVEL_DEBUG);
#endif
@ -134,14 +128,32 @@ int _app_main(int argc, wchar_t** argv)
#ifdef EX_OS_WIN32
if (g_run_type == RUN_INSTALL_SRV)
{
if (!g_env.init(false))
{
EXLOGE("[core] env init failed.\n");
return 1;
}
return service_install();
}
else if (g_run_type == RUN_UNINST_SRV)
{
if (!g_env.init(false))
{
EXLOGE("[core] env init failed.\n");
return 1;
}
return service_uninstall();
}
#endif
if (!g_env.init(true))
{
EXLOGE("[core] env init failed.\n");
return 1;
}
if (!g_is_debug)
{
if (!_run_daemon())

View File

@ -9,7 +9,7 @@ TsEnv::TsEnv()
TsEnv::~TsEnv()
{}
bool TsEnv::init(void)
bool TsEnv::init(bool run_core)
{
EXLOG_LEVEL(EX_LOG_LEVEL_INFO);
@ -18,6 +18,8 @@ bool TsEnv::init(void)
m_exec_path = m_exec_file;
ex_dirname(m_exec_path);
if(!run_core)
return true;
// 定位 log, etc 路径
// 默认情况下,以上三个目录均位于本可执行程序的 ../ 相对位置,

View File

@ -9,7 +9,7 @@ public:
TsEnv();
~TsEnv();
bool init(void);
bool init(bool run_core);
ExIniFile& get_ini(void) { return m_ini; }

View File

@ -259,12 +259,6 @@ int _app_main(int argc, wchar_t** argv)
return _main_loop();
}
if (!g_env.init(true))
{
EXLOGE("[tpweb] env init failed.\n");
return 1;
}
#ifdef EX_DEBUG
EXLOG_LEVEL(EX_LOG_LEVEL_DEBUG);
#endif
@ -272,14 +266,30 @@ int _app_main(int argc, wchar_t** argv)
#ifdef EX_OS_WIN32
if (g_run_type == RUN_INSTALL_SRV)
{
if (!g_env.init(false))
{
EXLOGE("[tpweb] env init failed.\n");
return 1;
}
return service_install();
}
else if(g_run_type == RUN_UNINST_SRV)
{
if (!g_env.init(false))
{
EXLOGE("[tpweb] env init failed.\n");
return 1;
}
return service_uninstall();
}
#endif
if (!g_env.init(true))
{
EXLOGE("[tpweb] env init failed.\n");
return 1;
}
if (!g_is_debug)
{
if (!_run_daemon())

View File

@ -44,7 +44,7 @@ bool TsEnv::init(bool for_web)
base_path = m_exec_path;
ex_path_join(base_path, true, L"..", NULL);
#ifdef EX_OS_WIN
#ifdef EX_OS_WIN32
conf_file = base_path;
ex_path_join(conf_file, false, L"etc", L"web.ini", NULL);
log_path = base_path;
@ -88,7 +88,7 @@ bool TsEnv::init(bool for_web)
if (!ex_is_file_exists(conf_file.c_str()))
{
EXLOGE("[tpweb] web.ini not found.\n");
EXLOGE(L"[tpweb] `%s` not found.\n", conf_file.c_str());
return false;
}

View File

@ -6,6 +6,7 @@ import sqlite3
import threading
import datetime
from eom_common.eomcore import utils
from eom_common.eomcore.logger import log
# from .configs import app_cfg
from .database.create import create_and_init
@ -123,6 +124,14 @@ class TPDatabase:
return ret
def create_and_init(self, step_begin, step_end):
if self.db_source['type'] == self.DB_TYPE_SQLITE:
db_path = os.path.dirname(self.db_source['file'])
if not os.path.exists(db_path):
utils.make_dir(db_path)
if not os.path.exists(db_path):
log.e('can not create folder `{}` to store database file.\n'.format(db_path))
return False
if create_and_init(self, step_begin, step_end):
self.need_create = False
return True

View File

@ -267,6 +267,9 @@ def get_group_list():
field_a = ['group_id', 'group_name']
sql = 'SELECT {} FROM `{}group` AS a; '.format(','.join(['`a`.`{}`'.format(i) for i in field_a]), db.table_prefix)
db_ret = db.query(sql)
if db_ret is None:
return list()
ret = list()
for item in db_ret:
x = DbItem()
@ -369,7 +372,7 @@ def add_host(args, must_not_exists=True):
group_id, host_sys_type, host_ip,
host_port, protocol, host_lock, host_desc)
ret = db.query(sql)
ret = db.exec(sql)
if not ret:
return -101

View File

@ -113,7 +113,7 @@
<button type="button" id="btn-batch-add-host" class="btn btn-sm btn-primary"><i class="fa fa-plus-square fa-fw"></i> 批量添加主机</button>
<button type="button" id="btn-delete-host" class="btn btn-sm btn-danger"><i class="fa fa-trash fa-fw"></i> 批量移除主机</button>
<button type="button" id="btn-apply-group" class="btn btn-sm btn-primary"><i class="fa fa-cubes fa-fw"></i> 批量设置分组</button>
<button type="button" id="btn-batch-export-host" class="btn btn-sm btn-primary"><i class="fa fa-exchange fa-fw"></i> 批量导出主机</button>
<button type="button" id="btn-batch-export-host" class="btn btn-sm btn-primary"><i class="fa fa-exchange fa-fw"></i> 备份所有主机及登录信息</button>
</div>
<div>
<hr/>

View File

@ -23,22 +23,25 @@
h2 {
font-size: 160%;
}
.steps-detail {
display: none;
margin:10px;
padding:10px;
border:1px solid #b4b4b4;
margin: 10px;
padding: 10px;
border: 1px solid #b4b4b4;
background-color: #dcdcdc;
}
.steps-detail p {
padding-left:5px;
margin:2px 0 2px 1px;
padding-left: 5px;
margin: 2px 0 2px 1px;
}
.steps-detail p.error {
color:#ffffff;
margin:2px 0 2px 0;
color: #ffffff;
margin: 2px 0 2px 0;
background-color: #cc3632;
border:1px solid #9c2a26;
border: 1px solid #9c2a26;
}
</style>
</%block>
@ -127,15 +130,21 @@
var html = [];
var icon_class = '';
var err_class = '';
for(var i = 0; i < steps.length; ++i) {
if(steps[i].stat == 0)
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)
if (steps[i].code != 0) {
icon_class = 'fa-exclamation-circle';
err_class = ' class="error"';
else
steps[i].msg += ' 失败!'
}
else {
err_class = '';
}
html.push('<p');
html.push(err_class);
html.push('><i class="fa ');