1. 设定服务端版本为2.2.8.1,准备发布;2. 为docker发布调整默认数据目录路径(安装目录下的data目录),包括配置文件、日志文件、录像文件、数据库文件等;

pull/32/head
Apex Liu 2017-05-24 17:28:28 +08:00
parent 7e80ab6ed3
commit 9ab930bd55
26 changed files with 584 additions and 575 deletions

5
.gitignore vendored
View File

@ -57,10 +57,9 @@ __pycache__
/server/share/etc/core.ini
/server/share/etc/web.ini
/server/share/data
/server/share/db
/server/share/log
/server/www/teleport/.idea/vcs.xml
/server/www/packages/packages-windows/x64
/server/share/replay
# for generated files.

View File

@ -1,3 +1,3 @@
# -*- coding: utf8 -*-
VER_TELEPORT_SERVER = "2.2.7.3"
VER_TELEPORT_ASSIST = "2.2.5.1"
# -*- coding: utf8 -*-
VER_TELEPORT_SERVER = "2.2.8.1"
VER_TELEPORT_ASSIST = "2.2.6.1"

Binary file not shown.

View File

@ -1,6 +1,6 @@
#ifndef __TS_ASSIST_VER_H__
#define __TS_ASSIST_VER_H__
#define TP_ASSIST_VER L"2.2.5.1"
#endif // __TS_ASSIST_VER_H__
#ifndef __TS_ASSIST_VER_H__
#define __TS_ASSIST_VER_H__
#define TP_ASSIST_VER L"2.2.6.1"
#endif // __TS_ASSIST_VER_H__

View File

@ -1,241 +1,241 @@
#include <ex/ex_thread.h>
#include <ex/ex_log.h>
//=========================================================
//
//=========================================================
#ifdef EX_OS_WIN32
unsigned int WINAPI ExThreadBase::_thread_func(LPVOID pParam)
#else
void* ExThreadBase::_thread_func(void* pParam)
#endif
{
ExThreadBase* p = (ExThreadBase*)pParam;
ex_astr thread_name = p->m_thread_name;
p->m_is_running = true;
p->_thread_loop();
p->m_is_running = false;
// if(!p->m_stop_by_request)
// p->m_thread_manager->_remove_thread(p);
EXLOGV(" # thread [%s] end.\n", thread_name.c_str());
return 0;
}
ExThreadBase::ExThreadBase(const char* thread_name) :
m_handle(0),
m_is_running(false),
m_stop_flag(false)
{
m_thread_name = thread_name;
}
ExThreadBase::~ExThreadBase()
{
}
bool ExThreadBase::start(void)
{
EXLOGV(" . thread [%s] starting.\n", m_thread_name.c_str());
#ifdef WIN32
HANDLE h = (HANDLE)_beginthreadex(NULL, 0, _thread_func, (void*)this, 0, NULL);
if (NULL == h)
{
return false;
}
m_handle = h;
#else
pthread_t ptid = 0;
int ret = pthread_create(&ptid, NULL, _thread_func, (void*)this);
if (ret != 0)
{
return false;
}
m_handle = ptid;
#endif
return true;
}
bool ExThreadBase::stop(void)
{
EXLOGV("[thread] try to stop thread [%s].\n", m_thread_name.c_str());
_set_stop_flag();
EXLOGV("[thread] wait thread [%s] end.\n", m_thread_name.c_str());
#ifdef EX_OS_WIN32
if (WaitForSingleObject(m_handle, INFINITE) != WAIT_OBJECT_0)
{
return false;
}
#else
if (pthread_join(m_handle, NULL) != 0)
{
return false;
}
#endif
return true;
}
bool ExThreadBase::terminate(void)
{
#ifdef EX_OS_WIN32
return TerminateThread(m_handle, 1) ? true : false;
#else
return pthread_cancel(m_handle) == 0 ? true : false;
#endif
}
//=========================================================
//
//=========================================================
ExThreadManager::ExThreadManager()
{}
ExThreadManager::~ExThreadManager()
{
if (m_threads.size() > 0)
{
EXLOGE("[ERROR] when destroy thread manager, there are %d thread not exit.\n", m_threads.size());
stop_all();
}
}
void ExThreadManager::stop_all(void)
{
ExThreadSmartLock locker(m_lock);
ex_threads::iterator it = m_threads.begin();
for (; it != m_threads.end(); ++it)
{
(*it)->stop();
}
m_threads.clear();
}
void ExThreadManager::add(ExThreadBase* tb)
{
ExThreadSmartLock locker(m_lock);
ex_threads::iterator it = m_threads.begin();
for (; it != m_threads.end(); ++it)
{
if ((*it) == tb)
{
EXLOGE("[ERROR] when add thread to manager, it already exist.\n");
return;
}
}
m_threads.push_back(tb);
}
void ExThreadManager::remove(ExThreadBase* tb)
{
ExThreadSmartLock locker(m_lock);
ex_threads::iterator it = m_threads.begin();
for (; it != m_threads.end(); ++it)
{
if ((*it) == tb)
{
//delete (*it);
m_threads.erase(it);
return;
}
}
EXLOGE("[ERROR] when remove thread from manager, it not exist.\n");
}
//=========================================================
//
//=========================================================
ExThreadLock::ExThreadLock()
{
#ifdef EX_OS_WIN32
InitializeCriticalSection(&m_locker);
#else
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&m_locker, &attr);
pthread_mutexattr_destroy(&attr);
#endif
}
ExThreadLock::~ExThreadLock()
{
#ifdef EX_OS_WIN32
DeleteCriticalSection(&m_locker);
#else
pthread_mutex_destroy(&m_locker);
#endif
}
void ExThreadLock::lock(void)
{
#ifdef EX_OS_WIN32
EnterCriticalSection(&m_locker);
#else
pthread_mutex_lock(&m_locker);
#endif
}
void ExThreadLock::unlock(void)
{
#ifdef EX_OS_WIN32
LeaveCriticalSection(&m_locker);
#else
pthread_mutex_unlock(&m_locker);
#endif
}
//=========================================================
//
//=========================================================
int ex_atomic_add(volatile int* pt, int t)
{
#ifdef EX_OS_WIN32
return (int)InterlockedExchangeAdd((long*)pt, (long)t);
#else
return __sync_add_and_fetch(pt, t);
#endif
}
int ex_atomic_inc(volatile int* pt)
{
#ifdef EX_OS_WIN32
return (int)InterlockedIncrement((long*)pt);
#else
return __sync_add_and_fetch(pt, 1);
#endif
}
int ex_atomic_dec(volatile int* pt)
{
#ifdef EX_OS_WIN32
return (int)InterlockedDecrement((long*)pt);
#else
return __sync_add_and_fetch(pt, -1);
#endif
}
ex_u64 ex_get_thread_id(void)
{
#ifdef EX_OS_WIN32
return GetCurrentThreadId();
#else
return pthread_self();
#endif
}
#include <ex/ex_thread.h>
#include <ex/ex_log.h>
//=========================================================
//
//=========================================================
#ifdef EX_OS_WIN32
unsigned int WINAPI ExThreadBase::_thread_func(LPVOID pParam)
#else
void* ExThreadBase::_thread_func(void* pParam)
#endif
{
ExThreadBase* p = (ExThreadBase*)pParam;
ex_astr thread_name = p->m_thread_name;
p->m_is_running = true;
p->_thread_loop();
p->m_is_running = false;
// if(!p->m_stop_by_request)
// p->m_thread_manager->_remove_thread(p);
EXLOGV(" # thread [%s] end.\n", thread_name.c_str());
return 0;
}
ExThreadBase::ExThreadBase(const char* thread_name) :
m_handle(0),
m_is_running(false),
m_stop_flag(false)
{
m_thread_name = thread_name;
}
ExThreadBase::~ExThreadBase()
{
}
bool ExThreadBase::start(void)
{
EXLOGV(" . thread [%s] starting.\n", m_thread_name.c_str());
#ifdef WIN32
HANDLE h = (HANDLE)_beginthreadex(NULL, 0, _thread_func, (void*)this, 0, NULL);
if (NULL == h)
{
return false;
}
m_handle = h;
#else
pthread_t ptid = 0;
int ret = pthread_create(&ptid, NULL, _thread_func, (void*)this);
if (ret != 0)
{
return false;
}
m_handle = ptid;
#endif
return true;
}
bool ExThreadBase::stop(void)
{
EXLOGV("[thread] try to stop thread [%s].\n", m_thread_name.c_str());
_set_stop_flag();
EXLOGV("[thread] wait thread [%s] end.\n", m_thread_name.c_str());
#ifdef EX_OS_WIN32
if (WaitForSingleObject(m_handle, INFINITE) != WAIT_OBJECT_0)
{
return false;
}
#else
if (pthread_join(m_handle, NULL) != 0)
{
return false;
}
#endif
return true;
}
bool ExThreadBase::terminate(void)
{
#ifdef EX_OS_WIN32
return TerminateThread(m_handle, 1) ? true : false;
#else
return pthread_cancel(m_handle) == 0 ? true : false;
#endif
}
//=========================================================
//
//=========================================================
ExThreadManager::ExThreadManager()
{}
ExThreadManager::~ExThreadManager()
{
if (m_threads.size() > 0)
{
EXLOGE("when destroy thread manager, there are %d thread not exit.\n", m_threads.size());
stop_all();
}
}
void ExThreadManager::stop_all(void)
{
ExThreadSmartLock locker(m_lock);
ex_threads::iterator it = m_threads.begin();
for (; it != m_threads.end(); ++it)
{
(*it)->stop();
}
m_threads.clear();
}
void ExThreadManager::add(ExThreadBase* tb)
{
ExThreadSmartLock locker(m_lock);
ex_threads::iterator it = m_threads.begin();
for (; it != m_threads.end(); ++it)
{
if ((*it) == tb)
{
EXLOGE("when add thread to manager, it already exist.\n");
return;
}
}
m_threads.push_back(tb);
}
void ExThreadManager::remove(ExThreadBase* tb)
{
ExThreadSmartLock locker(m_lock);
ex_threads::iterator it = m_threads.begin();
for (; it != m_threads.end(); ++it)
{
if ((*it) == tb)
{
//delete (*it);
m_threads.erase(it);
return;
}
}
EXLOGE("when remove thread from manager, it not exist.\n");
}
//=========================================================
//
//=========================================================
ExThreadLock::ExThreadLock()
{
#ifdef EX_OS_WIN32
InitializeCriticalSection(&m_locker);
#else
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&m_locker, &attr);
pthread_mutexattr_destroy(&attr);
#endif
}
ExThreadLock::~ExThreadLock()
{
#ifdef EX_OS_WIN32
DeleteCriticalSection(&m_locker);
#else
pthread_mutex_destroy(&m_locker);
#endif
}
void ExThreadLock::lock(void)
{
#ifdef EX_OS_WIN32
EnterCriticalSection(&m_locker);
#else
pthread_mutex_lock(&m_locker);
#endif
}
void ExThreadLock::unlock(void)
{
#ifdef EX_OS_WIN32
LeaveCriticalSection(&m_locker);
#else
pthread_mutex_unlock(&m_locker);
#endif
}
//=========================================================
//
//=========================================================
int ex_atomic_add(volatile int* pt, int t)
{
#ifdef EX_OS_WIN32
return (int)InterlockedExchangeAdd((long*)pt, (long)t);
#else
return __sync_add_and_fetch(pt, t);
#endif
}
int ex_atomic_inc(volatile int* pt)
{
#ifdef EX_OS_WIN32
return (int)InterlockedIncrement((long*)pt);
#else
return __sync_add_and_fetch(pt, 1);
#endif
}
int ex_atomic_dec(volatile int* pt)
{
#ifdef EX_OS_WIN32
return (int)InterlockedDecrement((long*)pt);
#else
return __sync_add_and_fetch(pt, -1);
#endif
}
ex_u64 ex_get_thread_id(void)
{
#ifdef EX_OS_WIN32
return GetCurrentThreadId();
#else
return pthread_self();
#endif
}

Binary file not shown.

View File

@ -376,9 +376,9 @@ class InstallerWin(InstallerBase):
return
def _fix_path(self):
self._config_path = os.path.join(self._install_path, 'etc')
self._data_path = os.path.join(self._install_path, 'data')
self._log_path = os.path.join(self._install_path, 'log')
self._config_path = os.path.join(self._data_path, 'etc')
self._log_path = os.path.join(self._data_path, 'log')
def _copy_files(self):
utils.copy_ex(os.path.join(env.src_path, 'bin'), os.path.join(self._install_path, 'bin'))
@ -392,8 +392,8 @@ class InstallerWin(InstallerBase):
utils.remove(os.path.join(self._install_path, 'www'))
if del_settings:
utils.remove(self._data_path)
utils.remove(self._config_path)
utils.remove(self._log_path)
# utils.remove(self._config_path)
# utils.remove(self._log_path)
# only remove the installation path when it empty.
try:
@ -516,9 +516,12 @@ class InstallerLinux(InstallerBase):
return
def _fix_path(self):
self._config_path = '/etc/teleport'
self._data_path = os.path.join('/var/lib/teleport')
self._log_path = os.path.join('/var/log/teleport')
# self._config_path = '/etc/teleport'
# self._data_path = os.path.join('/var/lib/teleport')
# self._log_path = os.path.join('/var/log/teleport')
self._data_path = os.path.join(self._install_path, 'data')
self._config_path = os.path.join(self._data_path, 'etc')
self._log_path = os.path.join(self._data_path, 'log')
def _copy_files(self):
utils.copy_ex(os.path.join(env.src_path, 'bin'), os.path.join(self._install_path, 'bin'))
@ -543,8 +546,8 @@ class InstallerLinux(InstallerBase):
if del_settings:
utils.remove(self._data_path)
utils.remove(self._config_path)
utils.remove(self._log_path)
# utils.remove(self._config_path)
# utils.remove(self._log_path)
def _install_service(self):
daemon_files = [

View File

@ -38,7 +38,7 @@ void TppRecBase::end()
#ifdef EX_DEBUG
if (m_cache.size() > 0)
{
EXLOGE("[ssh] not all record data saved.\n");
EXLOGE("not all record data saved.\n");
}
#endif
}

Binary file not shown.

View File

@ -1,180 +1,180 @@
#include "ts_crypto.h"
#include <mbedtls/aes.h>
#include <mbedtls/base64.h>
/* 加密方案:
AES-CBC
1616AES-CBC
*/
static ex_u8 g_db_field_aes_key[32] = {
0xd6, 0xb6, 0x6e, 0x3b, 0x41, 0xc4, 0x33, 0x13, 0xaa, 0x61, 0xc9, 0x47, 0x82, 0xfc, 0x84, 0x50,
0x85, 0x53, 0x3a, 0x01, 0x97, 0x2d, 0xca, 0xba, 0x87, 0xbc, 0x27, 0x20, 0x29, 0xde, 0x87, 0x67,
};
bool ts_db_field_encrypt(const ex_astr& str_dec, ex_astr& str_enc)
{
ex_bin bin_dec;
bin_dec.resize(str_dec.length());
memset(&bin_dec[0], 0, bin_dec.size());
memcpy(&bin_dec[0], str_dec.c_str(), bin_dec.size());
return ts_db_field_encrypt(bin_dec, str_enc);
}
bool ts_db_field_decrypt(const ex_astr& str_enc, ex_astr& str_dec)
{
ex_bin bin_dec;
if (!ts_db_field_decrypt(str_enc, bin_dec))
return false;
if (bin_dec[bin_dec.size() - 1] != 0)
{
bin_dec.resize(bin_dec.size() + 1);
bin_dec[bin_dec.size() - 1] = 0;
}
str_dec = (char*)&bin_dec[0];
return true;
}
bool ts_db_field_encrypt(const ex_bin& bin_dec, ex_astr& str_enc)
{
int i = 0;
int offset = 0;
// 随机数种子发生器(注意多线程的问题)
ex_u64 _tick = ex_get_tick_count();
ex_u64 _seed_tmp = ex_get_thread_id() + _tick;
ex_u32 _seed = ((ex_u32*)&_seed_tmp)[0] + ((ex_u32*)&_seed_tmp)[1];
srand(_seed);
// 计算密文大小
int pad = 16 - bin_dec.size() % 16;
int enc_size = bin_dec.size() + pad + 16; // 追加16字节是为了额外填充的随机数
// 准备被加密数据16字节随机数+明文+补齐填充)
ex_bin bin_be_enc;
bin_be_enc.resize(enc_size);
memset(&bin_be_enc[0], 0, bin_be_enc.size());
offset = 0;
for (i = 0; i < 16; ++i)
{
bin_be_enc[offset] = (unsigned char)(rand() % 0xFF);
offset++;
}
memcpy(&bin_be_enc[offset], &bin_dec[0], bin_dec.size());
offset += bin_dec.size();
for (i = 0; i < pad; ++i)
{
bin_be_enc[offset] = (unsigned char)pad;
offset++;
}
// 准备密文缓冲区
ex_bin bin_enc;
bin_enc.resize(enc_size);
memset(&bin_enc[0], 0, bin_enc.size());
// 准备加密算法
mbedtls_aes_context ctx;
mbedtls_aes_init(&ctx);
if (0 != mbedtls_aes_setkey_enc(&ctx, g_db_field_aes_key, 256))
{
EXLOGE("invalid AES key.\n");
return false;
}
// 加密
unsigned char iv[16] = { 0 };
memset(iv, 0, 16);
if (0 != mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, enc_size, iv, &bin_be_enc[0], &bin_enc[0]))
{
EXLOGE("AES-CBC encrypt failed.\n");
mbedtls_aes_free(&ctx);
return false;
}
mbedtls_aes_free(&ctx);
// 将加密结果进行base64编码
ex_bin enc_b64;
enc_b64.resize(enc_size * 2);
memset(&enc_b64[0], 0, enc_size * 2);
size_t olen = 0;
if (0 != mbedtls_base64_encode(&enc_b64[0], enc_size * 2, &olen, &bin_enc[0], enc_size))
{
EXLOGE("BASE64 encode failed.\n");
return false;
}
enc_b64[olen] = 0;
str_enc = (char*)&enc_b64[0];
return true;
}
bool ts_db_field_decrypt(const ex_astr& str_enc, ex_bin& bin_dec)
{
ex_bin bin_enc;
bin_enc.resize(str_enc.length());
memset(&bin_enc[0], 0, bin_enc.size());
// base64解码
size_t enc_size = 0;
if (0 != mbedtls_base64_decode(&bin_enc[0], bin_enc.size(), &enc_size, (const unsigned char*)str_enc.c_str(), str_enc.length()))
{
EXLOGE("BASE64 decode failed.\n");
return false;
}
bin_enc.resize(enc_size);
if (bin_enc.size() % 16 != 0)
{
EXLOGE("invalid cipher-data.\n");
return false;
}
// 准备明文缓冲区
ex_bin bin_tmp;
bin_tmp.resize(enc_size);
memset(&bin_tmp[0], 0, bin_tmp.size());
// 准备解密算法
mbedtls_aes_context ctx;
mbedtls_aes_init(&ctx);
if (0 != mbedtls_aes_setkey_dec(&ctx, g_db_field_aes_key, 256))
{
EXLOGE("invalid AES key.\n");
return false;
}
// 解密
unsigned char iv[16] = { 0 };
memset(iv, 0, 16);
if (0 != mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, enc_size, iv, &bin_enc[0], &bin_tmp[0]))
{
EXLOGE("AES-CBC decrypt failed.\n");
mbedtls_aes_free(&ctx);
return false;
}
mbedtls_aes_free(&ctx);
// 去除padding
unsigned char pad = bin_tmp[bin_tmp.size() - 1];
if (pad == 0 || pad > 16)
{
EXLOGE("invalid padding.\n");
return false;
}
bin_tmp.resize(bin_tmp.size() - pad);
if (bin_tmp.size() < 16)
{
EXLOGE("invalid decrypted data.\n");
return false;
}
// 将最终结果复制到返回缓冲区需要抛弃前面的16字节随机数
bin_dec.resize(bin_tmp.size() - 16);
memcpy(&bin_dec[0], &bin_tmp[16], bin_dec.size());
return true;
}
#include "ts_crypto.h"
#include <mbedtls/aes.h>
#include <mbedtls/base64.h>
/* 加密方案:
AES-CBC
1616AES-CBC
*/
static ex_u8 g_db_field_aes_key[32] = {
0xd6, 0xb6, 0x6e, 0x3b, 0x41, 0xc4, 0x33, 0x13, 0xaa, 0x61, 0xc9, 0x47, 0x82, 0xfc, 0x84, 0x50,
0x85, 0x53, 0x3a, 0x01, 0x97, 0x2d, 0xca, 0xba, 0x87, 0xbc, 0x27, 0x20, 0x29, 0xde, 0x87, 0x67,
};
bool ts_db_field_encrypt(const ex_astr& str_dec, ex_astr& str_enc)
{
ex_bin bin_dec;
bin_dec.resize(str_dec.length());
memset(&bin_dec[0], 0, bin_dec.size());
memcpy(&bin_dec[0], str_dec.c_str(), bin_dec.size());
return ts_db_field_encrypt(bin_dec, str_enc);
}
bool ts_db_field_decrypt(const ex_astr& str_enc, ex_astr& str_dec)
{
ex_bin bin_dec;
if (!ts_db_field_decrypt(str_enc, bin_dec))
return false;
if (bin_dec[bin_dec.size() - 1] != 0)
{
bin_dec.resize(bin_dec.size() + 1);
bin_dec[bin_dec.size() - 1] = 0;
}
str_dec = (char*)&bin_dec[0];
return true;
}
bool ts_db_field_encrypt(const ex_bin& bin_dec, ex_astr& str_enc)
{
int i = 0;
int offset = 0;
// 随机数种子发生器(注意多线程的问题)
ex_u64 _tick = ex_get_tick_count();
ex_u64 _seed_tmp = ex_get_thread_id() + _tick;
ex_u32 _seed = ((ex_u32*)&_seed_tmp)[0] + ((ex_u32*)&_seed_tmp)[1];
srand(_seed);
// 计算密文大小
int pad = 16 - bin_dec.size() % 16;
int enc_size = bin_dec.size() + pad + 16; // 追加16字节是为了额外填充的随机数
// 准备被加密数据16字节随机数+明文+补齐填充)
ex_bin bin_be_enc;
bin_be_enc.resize(enc_size);
memset(&bin_be_enc[0], 0, bin_be_enc.size());
offset = 0;
for (i = 0; i < 16; ++i)
{
bin_be_enc[offset] = (unsigned char)(rand() % 0xFF);
offset++;
}
memcpy(&bin_be_enc[offset], &bin_dec[0], bin_dec.size());
offset += bin_dec.size();
for (i = 0; i < pad; ++i)
{
bin_be_enc[offset] = (unsigned char)pad;
offset++;
}
// 准备密文缓冲区
ex_bin bin_enc;
bin_enc.resize(enc_size);
memset(&bin_enc[0], 0, bin_enc.size());
// 准备加密算法
mbedtls_aes_context ctx;
mbedtls_aes_init(&ctx);
if (0 != mbedtls_aes_setkey_enc(&ctx, g_db_field_aes_key, 256))
{
EXLOGE("[core] invalid AES key.\n");
return false;
}
// 加密
unsigned char iv[16] = { 0 };
memset(iv, 0, 16);
if (0 != mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, enc_size, iv, &bin_be_enc[0], &bin_enc[0]))
{
EXLOGE("[core] AES-CBC encrypt failed.\n");
mbedtls_aes_free(&ctx);
return false;
}
mbedtls_aes_free(&ctx);
// 将加密结果进行base64编码
ex_bin enc_b64;
enc_b64.resize(enc_size * 2);
memset(&enc_b64[0], 0, enc_size * 2);
size_t olen = 0;
if (0 != mbedtls_base64_encode(&enc_b64[0], enc_size * 2, &olen, &bin_enc[0], enc_size))
{
EXLOGE("[core] BASE64 encode failed.\n");
return false;
}
enc_b64[olen] = 0;
str_enc = (char*)&enc_b64[0];
return true;
}
bool ts_db_field_decrypt(const ex_astr& str_enc, ex_bin& bin_dec)
{
ex_bin bin_enc;
bin_enc.resize(str_enc.length());
memset(&bin_enc[0], 0, bin_enc.size());
// base64解码
size_t enc_size = 0;
if (0 != mbedtls_base64_decode(&bin_enc[0], bin_enc.size(), &enc_size, (const unsigned char*)str_enc.c_str(), str_enc.length()))
{
EXLOGE("[core] BASE64 decode failed.\n");
return false;
}
bin_enc.resize(enc_size);
if (bin_enc.size() % 16 != 0)
{
EXLOGE("[core] invalid cipher-data.\n");
return false;
}
// 准备明文缓冲区
ex_bin bin_tmp;
bin_tmp.resize(enc_size);
memset(&bin_tmp[0], 0, bin_tmp.size());
// 准备解密算法
mbedtls_aes_context ctx;
mbedtls_aes_init(&ctx);
if (0 != mbedtls_aes_setkey_dec(&ctx, g_db_field_aes_key, 256))
{
EXLOGE("[core] invalid AES key.\n");
return false;
}
// 解密
unsigned char iv[16] = { 0 };
memset(iv, 0, 16);
if (0 != mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, enc_size, iv, &bin_enc[0], &bin_tmp[0]))
{
EXLOGE("[core] AES-CBC decrypt failed.\n");
mbedtls_aes_free(&ctx);
return false;
}
mbedtls_aes_free(&ctx);
// 去除padding
unsigned char pad = bin_tmp[bin_tmp.size() - 1];
if (pad == 0 || pad > 16)
{
EXLOGE("[core] invalid padding.\n");
return false;
}
bin_tmp.resize(bin_tmp.size() - pad);
if (bin_tmp.size() < 16)
{
EXLOGE("[core] invalid decrypted data.\n");
return false;
}
// 将最终结果复制到返回缓冲区需要抛弃前面的16字节随机数
bin_dec.resize(bin_tmp.size() - 16);
memcpy(&bin_dec[0], &bin_tmp[16], bin_dec.size());
return true;
}

View File

@ -42,30 +42,41 @@ bool TsEnv::init(bool load_config)
ex_path_join(conf_file, false, L"core.ini", NULL);
m_replay_path = base_path;
ex_path_join(m_replay_path, false, L"share", L"data", L"replay", NULL);
ex_path_join(m_replay_path, false, L"share", L"replay", NULL);
log_path = base_path;
ex_path_join(log_path, false, L"share", L"log", NULL);
}
else // not in development mode
{
#ifdef EX_OS_WIN32
// #ifdef EX_OS_WIN32
// base_path = m_exec_path;
// ex_path_join(base_path, true, L"..", NULL);
// m_etc_path = base_path;
// ex_path_join(m_etc_path, false, L"etc", NULL);
// conf_file = m_etc_path;
// ex_path_join(conf_file, false, L"core.ini", NULL);
// m_replay_path = base_path;
// ex_path_join(m_replay_path, false, L"data", L"replay", NULL);
// log_path = base_path;
// ex_path_join(log_path, false, L"log", NULL);
// #else
// m_etc_path = L"/etc/teleport";
// conf_file = L"/etc/teleport/core.ini";
// m_replay_path = L"/var/lib/teleport/replay";
// log_path = L"/var/log/teleport";
// #endif
base_path = m_exec_path;
ex_path_join(base_path, true, L"..", NULL);
ex_path_join(base_path, true, L"..", L"data", NULL);
m_etc_path = base_path;
ex_path_join(m_etc_path, false, L"etc", NULL);
conf_file = m_etc_path;
ex_path_join(conf_file, false, L"core.ini", NULL);
m_replay_path = base_path;
ex_path_join(m_replay_path, false, L"data", L"replay", NULL);
ex_path_join(m_replay_path, false, L"replay", NULL);
log_path = base_path;
ex_path_join(log_path, false, L"log", NULL);
#else
m_etc_path = L"/etc/teleport";
conf_file = L"/etc/teleport/core.ini";
m_replay_path = L"/var/lib/teleport/replay";
log_path = L"/var/log/teleport";
#endif
}
//EXLOGW(L"[core] load config file: %ls.\n", conf_file.c_str());
@ -112,7 +123,7 @@ bool TsEnv::init(bool load_config)
}
int debug_mode = 0;
ps->GetInt(L"debug", debug_mode, 0);
ps->GetInt(L"debug-mode", debug_mode, 0);
if (debug_mode == 1)
EXLOG_DEBUG(true);

View File

@ -55,14 +55,14 @@ TsHttpRpc::~TsHttpRpc()
void TsHttpRpc::_thread_loop(void)
{
EXLOGV("[core-rpc] TeleportServer-HTTP-RPC ready on %s:%d\n", m_host_ip.c_str(), m_host_port);
EXLOGV("[core] rpc TeleportServer-HTTP-RPC ready on %s:%d\n", m_host_ip.c_str(), m_host_port);
while(!m_stop_flag)
{
mg_mgr_poll(&m_mg_mgr, 500);
}
EXLOGV("[core-rpc] main loop end.\n");
EXLOGV("[core] rpc main loop end.\n");
}
void TsHttpRpc::_set_stop_flag(void)
@ -90,7 +90,7 @@ bool TsHttpRpc::init(void)
nc = mg_bind(&m_mg_mgr, addr, _mg_event_handler);
if (NULL == nc)
{
EXLOGE("[core-rpc] listener failed to bind at %s.\n", addr);
EXLOGE("[core] rpc listener failed to bind at %s.\n", addr);
return false;
}
@ -114,7 +114,7 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat
TsHttpRpc* _this = (TsHttpRpc*)nc->user_data;
if (NULL == _this)
{
EXLOGE("[core-rpc] invalid http request.\n");
EXLOGE("[core] rpc invalid http request.\n");
return;
}
@ -127,7 +127,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);
EXLOGD("got request: %s\n", uri.c_str());
EXLOGD("[core] rpc got request: %s\n", uri.c_str());
if (uri == "/rpc")
{
@ -137,18 +137,18 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat
ex_rv rv = _this->_parse_request(hm, method, json_param);
if (TSR_OK != rv)
{
EXLOGE("[core-rpc] got invalid request.\n");
EXLOGE("[core] rpc got invalid request.\n");
_this->_create_json_ret(ret_buf, rv);
}
else
{
EXLOGD("[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);
}
}
else
{
EXLOGE("[core-rpc] got invalid request: not `rpc` uri.\n");
EXLOGE("[core] rpc got invalid request: not `rpc` uri.\n");
_this->_create_json_ret(ret_buf, TSR_INVALID_REQUEST, "not a `rpc` request.");
}
@ -267,7 +267,7 @@ void TsHttpRpc::_process_request(const ex_astr& func_cmd, const Json::Value& jso
}
else
{
EXLOGE("[core-rpc] got unknown command: %s\n", func_cmd.c_str());
EXLOGE("[core] rpc got unknown command: %s\n", func_cmd.c_str());
_create_json_ret(buf, TSR_NO_SUCH_METHOD);
}
}
@ -428,7 +428,7 @@ void TsHttpRpc::_rpc_func_request_session(const Json::Value& json_param, ex_astr
return;
}
EXLOGD("[core-rpc] new session-id: %s\n", sid.c_str());
EXLOGD("[core] rpc new session-id: %s\n", sid.c_str());
Json::Value jr_data;
jr_data["sid"] = sid;
@ -594,7 +594,7 @@ void TsHttpRpc::_rpc_func_request_session(const Json::Value& json_param, ex_astr
// return;
// }
//
// EXLOGD("[core-rpc] new session-id: %s\n", sid.c_str());
// EXLOGD("[core] rpc new session-id: %s\n", sid.c_str());
//
// Json::Value jr_root;
// jr_root["code"] = TSR_OK;

View File

@ -53,7 +53,7 @@ void TsSessionManager::_check_sessions(void)
if (_now - it->second->ticket_start >= 10000)
#endif
{
EXLOGV("remove session: %s\n", it->first.c_str());
EXLOGV("[core] remove session: %s\n", it->first.c_str());
delete it->second;
m_sessions.erase(it++);
}

View File

@ -1,6 +1,6 @@
#ifndef __TS_SERVER_VER_H__
#define __TS_SERVER_VER_H__
#define TP_SERVER_VER L"2.2.7.3"
#endif // __TS_SERVER_VER_H__
#ifndef __TS_SERVER_VER_H__
#define __TS_SERVER_VER_H__
#define TP_SERVER_VER L"2.2.8.1"
#endif // __TS_SERVER_VER_H__

View File

@ -202,7 +202,7 @@ bool SshProxy::get_sftp_session_info(const ex_astr& sid, TS_SFTP_SESSION_INFO& i
ts_sftp_sessions::iterator it = m_sftp_sessions.find(sid);
if (it == m_sftp_sessions.end())
{
EXLOGD("sftp-session '%s' not exists.\n", sid.c_str());
EXLOGD("[ssh] sftp-session '%s' not exists.\n", sid.c_str());
return false;
}

View File

@ -51,7 +51,7 @@ void TppSshRec::_on_end(void)
FILE* f = ex_fopen(fname, L"wb");
if (NULL == f)
{
EXLOGE("[record] can not open file for write.\n");
EXLOGE("[ssh] can not open record file for write.\n");
return;
}
@ -137,7 +137,7 @@ bool TppSshRec::_save_to_data_file(void)
if (NULL == f)
{
EXLOGE("[record] can not open data-file for write.\n");
EXLOGE("[ssh] can not open record data-file for write.\n");
m_cache.empty();
return false;
}

Binary file not shown.

View File

@ -44,16 +44,16 @@ bool TsEnv::init(bool load_config)
base_path = m_exec_path;
ex_path_join(base_path, true, L"..", NULL);
#ifdef EX_OS_WIN32
// #ifdef EX_OS_WIN32
conf_file = base_path;
ex_path_join(conf_file, false, L"etc", L"web.ini", NULL);
ex_path_join(conf_file, false, L"data", L"etc", L"web.ini", NULL);
log_path = base_path;
ex_path_join(log_path, false, L"log", NULL);
#else
conf_file = L"/etc/teleport/web.ini";
log_path = L"/var/log/teleport";
#endif
ex_path_join(log_path, false, L"data", L"log", NULL);
// #else
// conf_file = L"/etc/teleport/web.ini";
// log_path = L"/var/log/teleport";
//
// #endif
}
m_www_path = base_path;
@ -74,7 +74,7 @@ bool TsEnv::init(bool load_config)
ex_wstr log_file;
ExIniSection* ps = cfg.GetDumySection();
if (!ps->GetStr(L"log_file", log_file))
if (!ps->GetStr(L"log-file", log_file))
{
EXLOG_FILE(L"tpweb.log", log_path.c_str());
}
@ -95,11 +95,22 @@ bool TsEnv::init(bool load_config)
}
int log_level = EX_LOG_LEVEL_INFO;
if (ps->GetInt(L"log_level", log_level))
if (ps->GetInt(L"log-level", log_level))
{
EXLOGV("[tpweb] log-level: %d\n", log_level);
EXLOG_LEVEL(log_level);
}
int debug_mode = 0;
if (ps->GetInt(L"debug-mode", debug_mode))
{
EXLOGV("[tpweb] debug-mode: %d\n", debug_mode);
// EXLOG_LEVEL(log_level);
}
if (1 == debug_mode) {
EXLOG_LEVEL(EX_LOG_LEVEL_DEBUG);
}
return true;
}

View File

@ -1,6 +1,6 @@
#ifndef __TS_SERVER_VER_H__
#define __TS_SERVER_VER_H__
#define TP_SERVER_VER L"2.2.7.3"
#endif // __TS_SERVER_VER_H__
#ifndef __TS_SERVER_VER_H__
#define __TS_SERVER_VER_H__
#define TP_SERVER_VER L"2.2.8.1"
#endif // __TS_SERVER_VER_H__

View File

@ -29,34 +29,19 @@ class WebServerCore:
cfg.app_path = os.path.abspath(options['app_path'])
cfg.static_path = os.path.abspath(options['static_path'])
cfg.data_path = os.path.abspath(options['data_path'])
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.data_path = os.path.abspath(options['data_path'])
# cfg.cfg_path = os.path.abspath(options['cfg_path'])
# cfg.log_path = os.path.abspath(options['log_path'])
cfg.cfg_path = os.path.join(cfg.data_path, 'etc')
cfg.log_path = os.path.join(cfg.data_path, 'log')
_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.set_attribute(min_level=cfg.common.log_level, filename=cfg.common.log_file)
# if cfg.common.debug_mode:
# log.set_attribute(min_level=log.LOG_DEBUG, trace_error=log.TRACE_ERROR_FULL)
return True
def _get_core_server_config(self):

View File

@ -53,7 +53,7 @@ class TPDatabase:
cfg = app_cfg()
if 'sqlite' == cfg.database.type:
if cfg.database.sqlite_file is None:
cfg.set_default('database::sqlite-file', os.path.join(cfg.data_path, 'ts_db.db'))
cfg.set_default('database::sqlite-file', os.path.join(cfg.data_path, 'db', 'ts_db.db'))
if not self._init_sqlite(cfg.database.sqlite_file):
return False
elif 'mysql' == cfg.database.type:

View File

@ -14,10 +14,10 @@ import os
import platform
import sys
__all__ = ['PATH_APP_ROOT', 'PATH_LOG', 'PATH_CONF', 'PATH_DATA']
__all__ = ['PATH_APP_ROOT', 'PATH_DATA']
PATH_LOG = ''
PATH_CONF = ''
# PATH_LOG = ''
# PATH_CONF = ''
PATH_DATA = ''
# 将Python安装的扩展库移除避免开发调试与正式发布所依赖的库文件不一致导致发布的版本无法运行
@ -54,17 +54,17 @@ if _ext_path not in sys.path:
# 确定一些路径
if os.path.exists(os.path.join(os.path.dirname(sys.executable), 'dev_mode')):
# 开发调试模式
PATH_LOG = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'share', 'log'))
PATH_CONF = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'share', 'etc'))
PATH_DATA = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'share', 'data'))
PATH_DATA = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'share'))
# PATH_LOG = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'share', 'log'))
# PATH_CONF = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'share', 'etc'))
else:
PATH_LOG = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'log'))
PATH_CONF = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'etc'))
PATH_DATA = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'data'))
# PATH_LOG = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'data', 'log'))
# PATH_CONF = os.path.abspath(os.path.join(PATH_APP_ROOT, '..', '..', 'data', 'etc'))
if PLATFORM == 'linux':
# 根据Linux目录规范建议设置各个必要的路径
PATH_LOG = '/var/log/teleport'
PATH_CONF = '/etc/teleport'
PATH_DATA = '/var/lib/teleport'
# if PLATFORM == 'linux':
# # 根据Linux目录规范建议设置各个必要的路径
# PATH_LOG = '/var/log/teleport'
# PATH_CONF = '/etc/teleport'
# PATH_DATA = '/var/lib/teleport'

View File

@ -1,37 +1,37 @@
# -*- coding: utf-8 -*-
import os
import sys
from eom_env import *
import eom_app.app as app
def main():
options = {
# app_path 网站程序根路径(应该是本文件所在目录的上一级目录)
'app_path': PATH_APP_ROOT,
# cfg_path 网站配置文件路径
'cfg_path': PATH_CONF,
# log_path 网站运行时日志文件路径
'log_path': PATH_LOG,
# static_path 网站静态文件路径
'static_path': os.path.join(PATH_APP_ROOT, 'static'),
# data_path 网站数据文件路径
'data_path': PATH_DATA,
# template_path 网站模板文件路径
'template_path': os.path.join(PATH_APP_ROOT, 'view'),
# res_path 网站资源文件路径
'res_path': os.path.join(PATH_APP_ROOT, 'res')
}
return app.run(options)
if __name__ == '__main__':
sys.exit(main())
# -*- coding: utf-8 -*-
import os
import sys
from eom_env import *
import eom_app.app as app
def main():
options = {
# app_path 网站程序根路径(应该是本文件所在目录的上一级目录)
'app_path': PATH_APP_ROOT,
# cfg_path 网站配置文件路径
# 'cfg_path': PATH_CONF,
# log_path 网站运行时日志文件路径
# 'log_path': PATH_LOG,
# static_path 网站静态文件路径
'static_path': os.path.join(PATH_APP_ROOT, 'static'),
# data_path 网站数据文件路径
'data_path': PATH_DATA,
# template_path 网站模板文件路径
'template_path': os.path.join(PATH_APP_ROOT, 'view'),
# res_path 网站资源文件路径
'res_path': os.path.join(PATH_APP_ROOT, 'res')
}
return app.run(options)
if __name__ == '__main__':
sys.exit(main())

View File

@ -1,4 +1,4 @@
# -*- coding: utf8 -*-
TS_VER = "2.2.7.3"
TP_ASSIST_LAST_VER = "2.2.5.1"
TP_ASSIST_REQUIRE = "2.0.0.1"
# -*- coding: utf8 -*-
TS_VER = "2.2.8.1"
TP_ASSIST_LAST_VER = "2.2.6.1"
TP_ASSIST_REQUIRE = "2.0.0.1"

View File

@ -59,13 +59,6 @@
## }
## ]
## },
{
'require_type': 100,
'id': 'config',
'link': '/config',
'name': '配置管理',
'icon': 'fa-cogs',
},
{
'require_type': 100,
'id': 'log',
@ -73,6 +66,13 @@
'name': '日志查询',
'icon': 'fa-database',
},
{
'require_type': 100,
'id': 'config',
'link': '/config',
'name': '配置管理',
'icon': 'fa-cogs',
},
{
'separator': true,
'require_type': 1,

View File

@ -14,6 +14,6 @@ Build 构建号。构建号用于表明此版本发布之前进行了多少
TELEPORT_SERVER 2.2.7.3
TELEPORT_SERVER 2.2.8.1
TELEPORT_ASSIST 2.2.6.1
TELEPORT_ASSIST_REQUIRE 2.0.0.1