Skip to content

Commit

Permalink
修正web播放录像时的录像文件路径,避免core服务设置了非默认重放文件路径后web出现找不到文件的问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
apexliu committed Mar 28, 2017
1 parent 349d679 commit 61c1b69
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 714 deletions.
3 changes: 1 addition & 2 deletions build/builder/build-pysrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,14 @@ def _make_base(self):
super()._copy_modules()

def _make_py_ver_file(self):
# 在python.zip尾部追加一个字符串(补零到64字节),指明python动态库的文件名,这样壳在加载时才知道如何加载python动态库
# 指明python动态库的文件名,这样壳在加载时才知道如何加载python动态库
out_file = os.path.join(self.base_path, 'python.ver')
_data = struct.pack('=64s', self._get_py_dll_name().encode())
f = open(out_file, 'wb')
f.write(_data)
f.close()

def _get_py_dll_name(self):
#return 'python{}{}.dll'.format(PY_VER[0], PY_VER[1])
return 'python{}.dll'.format(env.py_ver_str)


Expand Down
2 changes: 0 additions & 2 deletions common/libex/src/ex_ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,6 @@ ExIniSection* ExIniFile::GetSection(const ex_wstr& strName, bool bCreateIfNotExi
if (!bCreateIfNotExists)
return NULL;



ExIniSection* pSec = new ExIniSection(strName);
m_secs.insert(std::make_pair(strName, pSec));
return pSec;
Expand Down
12 changes: 6 additions & 6 deletions server/tp_core/core/ts_http_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include "ts_crypto.h"
#include "ts_web_rpc.h"

//#include <sqlite3.h>


#define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W')
int ts_url_decode(const char *src, int src_len, char *dst, int dst_len, int is_form_url_encoded)
Expand Down Expand Up @@ -130,7 +128,7 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat
ex_astr uri;
uri.assign(hm->uri.p, hm->uri.len);

EXLOGV("got request: %s\n", uri.c_str());
EXLOGD("got request: %s\n", uri.c_str());

if (uri == "/rpc")
{
Expand All @@ -145,7 +143,7 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat
}
else
{
EXLOGV("[core-rpc] got request method `%s`\n", method.c_str());
EXLOGD("[core-rpc] got request method `%s`\n", method.c_str());
_this->_process_request(method, json_param, ret_buf);
}
}
Expand Down Expand Up @@ -198,8 +196,6 @@ ex_rv TsHttpRpc::_parse_request(struct http_message* req, ex_astr& func_cmd, Jso

json_str = &sztmp[0];



Json::Reader jreader;

if (!jreader.parse(json_str.c_str(), json_param))
Expand Down Expand Up @@ -289,6 +285,10 @@ void TsHttpRpc::_rpc_func_get_config(const Json::Value& json_param, ex_astr& buf
{
Json::Value jr_data;

ex_astr _replay_name;
ex_wstr2astr(g_env.m_replay_path, _replay_name);
jr_data["replay-path"] = _replay_name;

ExIniFile& ini = g_env.get_ini();
ex_ini_sections& secs = ini.GetAllSections();
ex_ini_sections::iterator it = secs.begin();
Expand Down
11 changes: 7 additions & 4 deletions server/www/teleport/app/eom_app/app/configs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

import os
import configparser
import os

from eom_common.eomcore.logger import *

Expand All @@ -17,8 +17,7 @@ def __getattr__(self, name):
try:
return self[name]
except KeyError:
# print(self.__class__.__name__)
raise
return None

def __setattr__(self, name, val):
self[name] = val
Expand All @@ -39,7 +38,7 @@ def __init__(self, **kwargs):
self['core']['telnet']['enable'] = False
self['core']['telnet']['port'] = 52389

def load_web(self, cfg_file):
def load(self, cfg_file):
if not os.path.exists(cfg_file):
log.e('configuration file does not exists: [{}]\n'.format(cfg_file))
return False
Expand Down Expand Up @@ -90,6 +89,7 @@ def load_web(self, cfg_file):
def update_core(self, conf_data):
try:
self['core'] = AttrDict()

self['core']['ssh'] = AttrDict()
self['core']['ssh']['enable'] = False
self['core']['ssh']['port'] = 52189
Expand All @@ -110,6 +110,9 @@ def update_core(self, conf_data):
if 'telnet' in conf_data:
self['core']['telnet']['enable'] = conf_data['telnet']['enable']
self['core']['telnet']['port'] = conf_data['telnet']['port']

self['core']['replay_path'] = conf_data['replay-path']

except IndexError:
log.e('invalid core config.\n')
return False
Expand Down
31 changes: 9 additions & 22 deletions server/www/teleport/app/eom_app/app/core.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
# -*- coding: utf-8 -*-

import os
# import sys
import json
import os
import urllib.parse
import urllib.request

import eom_common.eomcore.utils as utils
import tornado.httpserver
import tornado.ioloop
import tornado.netutil
import tornado.process
import tornado.web

# from eom_common.eomcore.eom_mysql import get_mysql_pool
from eom_common.eomcore.eom_sqlite import get_sqlite_pool
import eom_common.eomcore.utils as utils
from eom_common.eomcore.logger import log
from .const import *
from .configs import app_cfg
from .const import *
from .db import get_db
from .session import web_session

Expand All @@ -39,7 +35,7 @@ def init(self, options):
cfg.cfg_path = os.path.abspath(options['cfg_path'])

_cfg_file = os.path.join(cfg.cfg_path, 'web.ini')
if not cfg.load_web(_cfg_file):
if not cfg.load(_cfg_file):
return False

cfg.log_path = os.path.abspath(options['log_path'])
Expand All @@ -61,12 +57,7 @@ def init(self, options):
if not web_session().init():
return False

# TODO: 这里不要初始化数据库接口,需要根据配置文件来决定使用什么数据库(初始安装时还没有配置数据库信息)
# get_mysql_pool().init(cfg.mysql_ip, cfg.mysql_port, cfg.mysql_user, cfg.mysql_pass)
# db_path = os.path.join(cfg.data_path, 'ts_db.db')
get_sqlite_pool().init(cfg.data_path)

# get_db().init_sqlite(os.path.join(cfg.data_path, 'ts_db.db'))
# TODO: 根据配置文件来决定使用什么数据库(初始安装时还没有配置数据库信息)
_db = get_db()
if not _db.init({'type': _db.DB_TYPE_SQLITE, 'file': os.path.join(cfg.data_path, 'ts_db.db')}):
log.e('initialize database interface failed.\n')
Expand Down Expand Up @@ -111,17 +102,13 @@ def run(self):
'autoescape': 'xhtml_escape',

# 'ui_modules': ui_modules,
# 'debug': True,
'debug': False,

# Debug Mode.
'compiled_template_cache': True,
'static_hash_cache': True,
# 不开启模板和静态文件的缓存,这样一旦模板文件和静态文件变化,刷新浏览器即可看到更新。
'compiled_template_cache': False,
'static_hash_cache': False,
}

if cfg.debug:
settings['compiled_template_cache'] = False
settings['static_hash_cache'] = False

from eom_app.controller import controllers
web_app = tornado.web.Application(controllers, **settings)

Expand Down
22 changes: 2 additions & 20 deletions server/www/teleport/app/eom_app/app/database/upgrade.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-

import json
import os
import shutil
import json

from eom_common.eomcore.logger import log

Expand Down Expand Up @@ -75,7 +76,6 @@ def _upgrade_to_v2(self):
return False

# 移除旧的表(暂时改名而不是真的删除)
# str_sql = 'ALTER TABLE ts_sys_user RENAME TO _bak_ts_sys_user;'
_step = self.step_begin(' - 移除不再使用的数据表...')
if not self.db.exec('ALTER TABLE `{}sys_user` RENAME TO `_bak_ts_sys_user`;'.format(self.db.table_prefix)):
self.step_end(_step, 0)
Expand Down Expand Up @@ -108,10 +108,6 @@ def _upgrade_to_v3(self):
return True
self.step_end(_step, 0, '需要升级到v3')

# log.v('upgrade database to version 1.5.217.9 ...\n')
# bak_file = '{}.before-1.5.217.9'.format(db_file)
# if not os.path.exists(bak_file):
# shutil.copy(db_file, bak_file)
if self.db.db_source['type'] == self.db.DB_TYPE_SQLITE:
_step = self.step_begin(' - 备份数据库文件')
_bak_file = '{}.before-v2-to-v3'.format(self.db.db_source['file'])
Expand Down Expand Up @@ -340,12 +336,7 @@ def _upgrade_to_v4(self):
if host_info_alt is not None:
new_host_info.append(host_info_alt)

# print('=====================================')
# for i in range(len(new_host_info)):
# print(new_host_info[i])

# 现在有了新的ts_host_info表,重构ts_auth_info表
# 'SELECT id, host_id, pro_type, auth_mode, user_name, user_pswd, cert_id, encrypt, log_time FROM ts_auth_info;'
if auth_info_ret is not None:
for i in range(len(auth_info_ret)):
auth_info = {}
Expand All @@ -367,9 +358,6 @@ def _upgrade_to_v4(self):
if found:
new_auth_info.append(auth_info)

# for i in range(len(new_auth_info)):
# print(new_auth_info[i])

# 最后重构ts_auth表
if auth_ret is not None:
for i in range(len(auth_ret)):
Expand All @@ -386,9 +374,6 @@ def _upgrade_to_v4(self):
if found:
new_auth.append(auth)

# for i in range(len(new_auth)):
# print(new_auth[i])

self.step_end(_step, 0)
_step = self.step_begin(' - 重新整理认证数据表结构及数据...')

Expand Down Expand Up @@ -450,7 +435,6 @@ def _upgrade_to_v4(self):
new_auth_info[i]['user_name'], new_auth_info[i]['user_pswd'], new_auth_info[i]['user_param'],
new_auth_info[i]['cert_id'], new_auth_info[i]['encrypt'], '1'
)
# print(str_sql)
if not self.db.exec(sql):
self.step_end(_step, -1, '无法调整数据(2)')
return False
Expand Down Expand Up @@ -542,5 +526,3 @@ def _upgrade_to_v5(self):
log.e('failed.\n')
self.step_end(_step, -1)
return False


18 changes: 9 additions & 9 deletions server/www/teleport/app/eom_app/app/db.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# -*- coding: utf-8 -*-

import builtins
import os
import sqlite3
import threading
import datetime

import builtins

from eom_common.eomcore import utils
from eom_common.eomcore.logger import log
from eom_common.eomcore import utils
# from .configs import app_cfg
from .database.create import create_and_init
from .database.upgrade import DatabaseUpgrade

# cfg = app_cfg()

__all__ = ['get_db', 'DbItem']


Expand Down Expand Up @@ -63,14 +59,12 @@ def init(self, db_source):
# 看看数据库中是否存在指定的数据表(如果不存在,可能是一个空数据库文件),则可能是一个新安装的系统
ret = self.is_table_exists('{}group'.format(self._table_prefix))
if ret is None or not ret:
# if ret is None or ret[0][0] == 0:
log.w('database need create.\n')
self.need_create = True
return True

# 尝试从配置表中读取当前数据库版本号(如果不存在,说明是比较旧的版本了)
ret = self.query('SELECT `value` FROM `{}config` WHERE `name`="db_ver";'.format(self._table_prefix))
# log.w(ret)
if ret is None or 0 == len(ret):
self.current_ver = 1
else:
Expand Down Expand Up @@ -124,6 +118,8 @@ def exec(self, sql):
return ret

def create_and_init(self, step_begin, step_end):
log.v('start database create and initialization process.\n')

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):
Expand All @@ -133,17 +129,21 @@ def create_and_init(self, step_begin, step_end):
return False

if create_and_init(self, step_begin, step_end):
log.v('database created.\n')
self.need_create = False
return True
else:
log.e('database create and initialize failed.\n')
return False

def upgrade_database(self, step_begin, step_end):
log.v('start database upgrade process.\n')
if DatabaseUpgrade(self, step_begin, step_end).do_upgrade():
# if upgrade_database(self, step_begin, step_end):
log.v('database upgraded.\n')
self.need_upgrade = False
return True
else:
log.e('database upgrade failed.\n')
return False

def alter_table(self, table_names, field_names=None):
Expand Down
3 changes: 3 additions & 0 deletions server/www/teleport/app/eom_app/controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
(r'/user/list', user.GetListHandler),

# add another path to static-path

# todo: 重放数据路径是动态从core服务的json-rpc接口获取的,因此这里的数据获取方式需要改变
(r"/log/replay/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(cfg.data_path, 'replay')}),

(r'/log/list', record.LogList),
(r'/log/record/(.*)/(.*)', record.RecordHandler),
(r'/log/command-log/(.*)/(.*)', record.ComandLogHandler),
Expand Down
Loading

0 comments on commit 61c1b69

Please sign in to comment.