pull/105/head
Apex Liu 2017-10-30 18:14:48 +08:00
parent a49590705d
commit 65f2d1ceae
7 changed files with 57 additions and 131 deletions

View File

@ -29,7 +29,7 @@ class BuilderWin(BuilderBase):
def build_exe(self): def build_exe(self):
cc.i('build tp_assist...') cc.i('build tp_assist...')
sln_file = os.path.join(env.root_path, 'client', 'tp_assist', 'tp_assist.vs2015.sln') sln_file = os.path.join(env.root_path, 'client', 'tp_assist_win', 'tp_assist.vs2015.sln')
out_file = os.path.join(env.root_path, 'out', 'client', ctx.bits_path, ctx.target_path, 'tp_assist.exe') out_file = os.path.join(env.root_path, 'out', 'client', ctx.bits_path, ctx.target_path, 'tp_assist.exe')
if os.path.exists(out_file): if os.path.exists(out_file):
utils.remove(out_file) utils.remove(out_file)

View File

@ -839,7 +839,7 @@ void TsHttpRpc::_rpc_func_run_client(const ex_astr& func_args, ex_astr& buf)
// SSH // SSH
//============================================== //==============================================
if (pro_sub == TP_PROTOCOL_SUB_TYPE_SSH) if (pro_sub == TP_PROTOCOL_TYPE_SSH_SHELL)
{ {
w_exe_path = _T("\""); w_exe_path = _T("\"");
w_exe_path += g_cfg.ssh_app + _T("\" "); w_exe_path += g_cfg.ssh_app + _T("\" ");

View File

@ -9,8 +9,6 @@ TppRecBase::TppRecBase()
{ {
m_cache.reserve(MAX_SIZE_PER_FILE); m_cache.reserve(MAX_SIZE_PER_FILE);
m_start_time = 0; m_start_time = 0;
m_last_time = 0;
//m_protocol =
} }
TppRecBase::~TppRecBase() TppRecBase::~TppRecBase()

View File

@ -92,13 +92,10 @@ protected:
virtual bool _on_end() = 0; virtual bool _on_end() = 0;
protected: protected:
//int m_protocol;
ex_wstr m_base_path; // 录像文件基础路径,例如 /usr/local/eom/teleport/data/replay/ssh/123数字编号是内部附加的作为本次会话录像文件的目录名称 ex_wstr m_base_path; // 录像文件基础路径,例如 /usr/local/eom/teleport/data/replay/ssh/123数字编号是内部附加的作为本次会话录像文件的目录名称
ex_wstr m_base_fname; // 录像文件的文件名,不含扩展名部分,内部会以此为基础合成文件全名,并将录像文件存放在 m_base_path 指向的目录中 ex_wstr m_base_fname; // 录像文件的文件名,不含扩展名部分,内部会以此为基础合成文件全名,并将录像文件存放在 m_base_path 指向的目录中
ex_u64 m_start_time; ex_u64 m_start_time;
ex_u64 m_last_time;
MemBuffer m_cache; MemBuffer m_cache;
}; };

View File

@ -10,12 +10,13 @@ TppSshRec::TppSshRec()
memset(&m_head, 0, sizeof(TS_RECORD_HEADER)); memset(&m_head, 0, sizeof(TS_RECORD_HEADER));
memcpy((ex_u8*)(&m_head.info.magic), TPP_RECORD_MAGIC, sizeof(ex_u32)); memcpy((ex_u8*)(&m_head.info.magic), TPP_RECORD_MAGIC, sizeof(ex_u32));
m_head.info.ver = 0x03; m_head.info.ver = 0x03;
m_header_changed = false;
m_save_full_header = false;
m_file_info = NULL; m_file_info = NULL;
m_file_data = NULL; m_file_data = NULL;
m_file_cmd = NULL; m_file_cmd = NULL;
m_save_full_header = false;
} }
TppSshRec::~TppSshRec() TppSshRec::~TppSshRec()
@ -44,29 +45,7 @@ bool TppSshRec::_on_begin(const TPP_CONNECT_INFO* info)
bool TppSshRec::_on_end() bool TppSshRec::_on_end()
{ {
// 如果还有剩下未写入的数据,写入文件中。 // 如果还有剩下未写入的数据,写入文件中。
if (m_cache.size() > 0) save_record();
_save_to_data_file();
if (m_cmd_cache.size() > 0)
_save_to_cmd_file();
// // ¸üÐÂÍ·ÐÅÏ¢
// //m_head.timestamp = m_start_time;
// m_head.info.time_ms = (ex_u32)(m_last_time - m_start_time);
//
// ex_wstr fname = m_base_path;
// ex_path_join(fname, false, m_base_fname.c_str(), NULL);
// fname += L".tpr";
//
// FILE* f = ex_fopen(fname, L"wb");
// if (NULL == f)
// {
// EXLOGE("[ssh] can not open record file for write.\n");
// return false;
// }
//
// fwrite(&m_head, sizeof(TS_RECORD_HEADER), 1, f);
// fflush(f);
// fclose(f);
if(m_file_info != NULL) if(m_file_info != NULL)
fclose(m_file_info); fclose(m_file_info);
@ -79,9 +58,7 @@ bool TppSshRec::_on_end()
} }
void TppSshRec::save_record() { void TppSshRec::save_record() {
if (m_cache.size() > 0)
_save_to_data_file(); _save_to_data_file();
if (m_cmd_cache.size() > 0)
_save_to_cmd_file(); _save_to_cmd_file();
} }
@ -90,7 +67,7 @@ void TppSshRec::record(ex_u8 type, const ex_u8* data, size_t size)
if (data == NULL || 0 == size) if (data == NULL || 0 == size)
return; return;
if (sizeof(TS_RECORD_PKG) + size + m_cache.size() > m_cache.buffer_size()) if (sizeof(TS_RECORD_PKG) + size + m_cache.size() > MAX_SIZE_PER_FILE)
_save_to_data_file(); _save_to_data_file();
TS_RECORD_PKG pkg = {0}; TS_RECORD_PKG pkg = {0};
@ -100,16 +77,15 @@ void TppSshRec::record(ex_u8 type, const ex_u8* data, size_t size)
if (m_start_time > 0) if (m_start_time > 0)
{ {
m_last_time = ex_get_tick_count(); pkg.time_ms = (ex_u32)(ex_get_tick_count() - m_start_time);
pkg.time_ms = (ex_u32)(m_last_time - m_start_time);
m_head.info.time_ms = pkg.time_ms; m_head.info.time_ms = pkg.time_ms;
} }
m_head.info.packages++;
m_cache.append((ex_u8*)&pkg, sizeof(TS_RECORD_PKG)); m_cache.append((ex_u8*)&pkg, sizeof(TS_RECORD_PKG));
m_cache.append(data, size); m_cache.append(data, size);
m_head.info.packages++;
m_header_changed = true;
} }
void TppSshRec::record_win_size_startup(int width, int height) void TppSshRec::record_win_size_startup(int width, int height)
@ -146,15 +122,17 @@ void TppSshRec::record_command(const ex_astr& cmd)
size_t lenTime = strlen(szTime); size_t lenTime = strlen(szTime);
if (m_cmd_cache.size() + cmd.length() + lenTime > m_cache.buffer_size()) if (m_cmd_cache.size() + cmd.length() + lenTime > MAX_SIZE_PER_FILE)
_save_to_cmd_file(); _save_to_cmd_file();
m_cmd_cache.append((ex_u8*)szTime, lenTime); m_cmd_cache.append((ex_u8*)szTime, lenTime);
m_cmd_cache.append((ex_u8*)cmd.c_str(), cmd.length()); m_cmd_cache.append((ex_u8*)cmd.c_str(), cmd.length());
} }
bool TppSshRec::_save_to_data_file() bool TppSshRec::_save_to_info_file() {
{ if (!m_header_changed)
return true;
if(m_file_info == NULL) { if(m_file_info == NULL) {
ex_wstr fname = m_base_path; ex_wstr fname = m_base_path;
ex_path_join(fname, false, m_base_fname.c_str(), NULL); ex_path_join(fname, false, m_base_fname.c_str(), NULL);
@ -171,6 +149,25 @@ bool TppSshRec::_save_to_data_file()
m_save_full_header = true; m_save_full_header = true;
} }
fseek(m_file_info, 0L, SEEK_SET);
if (m_save_full_header) {
fwrite(&m_head, ts_record_header_size, 1, m_file_info);
fflush(m_file_info);
m_save_full_header = false;
}
else {
fwrite(&m_head.info, ts_record_header_info_size, 1, m_file_info);
fflush(m_file_info);
}
return true;
}
bool TppSshRec::_save_to_data_file()
{
if (m_cache.size() == 0)
return true;
if(m_file_data == NULL) { if(m_file_data == NULL) {
ex_wstr fname = m_base_path; ex_wstr fname = m_base_path;
ex_path_join(fname, false, m_base_fname.c_str(), NULL); ex_path_join(fname, false, m_base_fname.c_str(), NULL);
@ -182,47 +179,22 @@ bool TppSshRec::_save_to_data_file()
EXLOGE("[ssh] can not open record data-file for write.\n"); EXLOGE("[ssh] can not open record data-file for write.\n");
return false; return false;
} }
m_header_changed = true;
} }
// wchar_t _str_file_id[24] = { 0 };
// ex_wcsformat(_str_file_id, 24, L".%03d", 0);// m_head.file_count);
//
// ex_wstr fname = m_base_path;
// ex_path_join(fname, false, m_base_fname.c_str(), NULL);
// fname += _str_file_id;
//
// FILE* f = ex_fopen(fname, L"wb");
//
// if (NULL == f)
// {
// EXLOGE("[ssh] can not open record data-file for write.\n");
// m_cache.empty();
// return false;
// }
if(m_cache.size() > 0) {
fwrite(m_cache.data(), m_cache.size(), 1, m_file_data); fwrite(m_cache.data(), m_cache.size(), 1, m_file_data);
fflush(m_file_data); fflush(m_file_data);
}
fseek(m_file_info, 0L, SEEK_SET);
if(m_save_full_header) {
fwrite(&m_head, ts_record_header_size, 1, m_file_info);
fflush(m_file_info);
m_save_full_header = false;
} else {
fwrite(&m_head.info, ts_record_header_info_size, 1, m_file_info);
fflush(m_file_info);
}
m_cache.empty(); m_cache.empty();
return true;
return _save_to_info_file();
} }
bool TppSshRec::_save_to_cmd_file() bool TppSshRec::_save_to_cmd_file()
{ {
if (m_cmd_cache.size() == 0)
return true;
if(NULL == m_file_cmd) { if(NULL == m_file_cmd) {
ex_wstr fname = m_base_path; ex_wstr fname = m_base_path;
ex_path_join(fname, false, m_base_fname.c_str(), NULL); ex_path_join(fname, false, m_base_fname.c_str(), NULL);
@ -233,26 +205,13 @@ bool TppSshRec::_save_to_cmd_file()
EXLOGE("[ssh] can not open record cmd-file for write.\n"); EXLOGE("[ssh] can not open record cmd-file for write.\n");
return false; return false;
} }
m_header_changed = true;
} }
// ex_wstr fname = m_base_path;
// ex_path_join(fname, false, m_base_fname.c_str(), NULL);
// fname += L"-cmd.txt";
//
// FILE* f = ex_fopen(fname, L"ab");
// if (NULL == f)
// {
// m_cmd_cache.empty();
// return false;
// }
fwrite(m_cmd_cache.data(), m_cmd_cache.size(), 1, m_file_cmd); fwrite(m_cmd_cache.data(), m_cmd_cache.size(), 1, m_file_cmd);
fflush(m_file_cmd); fflush(m_file_cmd);
// fclose(f);
m_cmd_cache.empty(); m_cmd_cache.empty();
return true; return _save_to_info_file();
} }

View File

@ -8,34 +8,6 @@
#pragma pack(push,1) #pragma pack(push,1)
// 录像文件头
// typedef struct TS_RECORD_HEADER
// {
// ex_u32 magic; // "TPPR" 标志 TelePort Protocol Record
// ex_u64 timestamp; // 本次录像的起始时间UTC时间戳
// ex_u32 packages; // 总包数
// ex_u32 time_ms; // 总耗时(毫秒)
// ex_u16 width; // 初始屏幕尺寸:宽
// ex_u16 height; // 初始屏幕尺寸:高
// ex_u16 file_count; // 数据文件总数
// ex_u32 file_size; // 所有数据文件的总大小不包括每个数据文件的头即4字节的每文件大小
// char account[16]; // teleport账号
// char username[16]; // 远程主机用户名
// char ip[18];
// ex_u16 port;
//
// ex_u8 reserve[128 - 4 - 8 - 4 - 4 - 2 - 2 - 2 - 4 - 16 - 16 - 18 - 2]; // 保留
// }TS_RECORD_HEADER;
//
// // 一个数据包的头
// typedef struct TS_RECORD_PKG
// {
// ex_u8 type; // 包的数据类型
// ex_u32 size; // 这个包的总大小(不含包头)
// ex_u32 time_ms; // 这个包距起始时间的时间差毫秒意味着一个连接不能持续超过49天
// ex_u8 reserve[3]; // 保留
// }TS_RECORD_PKG;
// 记录窗口大小改变的数据包 // 记录窗口大小改变的数据包
typedef struct TS_RECORD_WIN_SIZE typedef struct TS_RECORD_WIN_SIZE
{ {
@ -62,11 +34,13 @@ protected:
bool _on_begin(const TPP_CONNECT_INFO* info); bool _on_begin(const TPP_CONNECT_INFO* info);
bool _on_end(); bool _on_end();
bool _save_to_info_file();
bool _save_to_data_file(); bool _save_to_data_file();
bool _save_to_cmd_file(); bool _save_to_cmd_file();
protected: protected:
TS_RECORD_HEADER m_head; TS_RECORD_HEADER m_head;
bool m_header_changed;
MemBuffer m_cmd_cache; MemBuffer m_cmd_cache;

View File

@ -297,13 +297,9 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
if (_this->m_auth_type != TP_AUTH_TYPE_NONE) if (_this->m_auth_type != TP_AUTH_TYPE_NONE)
ssh_options_set(_this->m_srv_session, SSH_OPTIONS_USER, _this->m_acc_name.c_str()); ssh_options_set(_this->m_srv_session, SSH_OPTIONS_USER, _this->m_acc_name.c_str());
//#ifdef EX_DEBUG // default timeout is 10 seconds.
// // int _timeout_us = 500000000; // 5 sec. int _timeout = 30; // 30 sec.
// // ssh_options_set(_this->m_srv_session, SSH_OPTIONS_TIMEOUT_USEC, &_timeout_us); ssh_options_set(_this->m_srv_session, SSH_OPTIONS_TIMEOUT, &_timeout);
//#else
// int _timeout_us = 10000000; // 10 sec.
// ssh_options_set(_this->m_srv_session, SSH_OPTIONS_TIMEOUT_USEC, &_timeout_us);
//#endif
int rc = 0; int rc = 0;
rc = ssh_connect(_this->m_srv_session); rc = ssh_connect(_this->m_srv_session);
@ -321,6 +317,7 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
} }
// // 检查服务端支持的认证协议 // // 检查服务端支持的认证协议
ssh_userauth_none(_this->m_srv_session, NULL);
// rc = ssh_userauth_none(_this->m_srv_session, NULL); // rc = ssh_userauth_none(_this->m_srv_session, NULL);
// if (rc == SSH_AUTH_ERROR) { // if (rc == SSH_AUTH_ERROR) {
// EXLOGE("[ssh] invalid password for password mode to login to real SSH server %s:%d.\n", _this->m_server_ip.c_str(), _this->m_server_port); // EXLOGE("[ssh] invalid password for password mode to login to real SSH server %s:%d.\n", _this->m_server_ip.c_str(), _this->m_server_port);
@ -344,6 +341,7 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
retry_count += 1; retry_count += 1;
if (retry_count >= 5) if (retry_count >= 5)
break; break;
ex_sleep_ms(500);
rc = ssh_userauth_kbdint(_this->m_srv_session, NULL, NULL); rc = ssh_userauth_kbdint(_this->m_srv_session, NULL, NULL);
continue; continue;
} }
@ -394,7 +392,7 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user,
EXLOGD("[ssh] failed to login with password mode, got %d.\n", rc); EXLOGD("[ssh] failed to login with password mode, got %d.\n", rc);
} }
EXLOGE("[ssh] can not use password mode or interactive mode ot login to real SSH server %s:%d.\n", _this->m_conn_ip.c_str(), _this->m_conn_port); EXLOGE("[ssh] can not use password mode or interactive mode to login to real SSH server %s:%d.\n", _this->m_conn_ip.c_str(), _this->m_conn_port);
_this->m_have_error = true; _this->m_have_error = true;
_this->m_retcode = TP_SESS_STAT_ERR_AUTH_DENIED; _this->m_retcode = TP_SESS_STAT_ERR_AUTH_DENIED;
return SSH_AUTH_ERROR; return SSH_AUTH_ERROR;