From d71217d50fb068470bef2cb6d458e241ffa86acc Mon Sep 17 00:00:00 2001 From: Apex Liu Date: Fri, 14 Apr 2017 18:40:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=BD=95=E5=83=8F=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=A0=BC=E5=BC=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/tp_core/common/base_record.h | 152 ++++--------------- server/tp_core/protocol/ssh/ssh_recorder.cpp | 4 +- server/tp_core/protocol/ssh/ssh_recorder.h | 52 +++---- 3 files changed, 60 insertions(+), 148 deletions(-) diff --git a/server/tp_core/common/base_record.h b/server/tp_core/common/base_record.h index e2619d0..8306a59 100644 --- a/server/tp_core/common/base_record.h +++ b/server/tp_core/common/base_record.h @@ -8,133 +8,43 @@ #include #define MAX_SIZE_PER_FILE 4194304 // 4M = 1024*1024*4 -//#define MAX_SIZE_PER_FILE 40*1024 -// #define SSH_DATA 1 -// #define SSH_WINDOWS_SIZE 2 -#if 0 #pragma pack(push,1) -struct ts_replay_data_header +// 录像文件头 +typedef struct TS_RECORD_HEADER { - ex_u8 action; - ex_u32 time; - ex_u32 size; - //char* buf; -}; -struct ts_replay_header + ex_u32 magic; // "TPPR" 标志 TelePort Protocol Record + ex_u16 ver; // 录像文件版本,目前为2 + ex_u16 protocol; // 协议:1=RDP, 2=SSH, 3=Telnet + 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; + + // RDP专有 + ex_u8 rdp_security; // 0 = RDP, 1 = TLS + + ex_u8 reserve[128 - 4 - 2 - 2 - 8 - 4 - 4 - 2 - 2 - 2 - 4 - 16 - 16 - 18 - 2 - 1]; // 保留 +}TS_RECORD_HEADER; + +// 一个数据包的头 +typedef struct TS_RECORD_PKG { - char ID[16]; - char version[16]; - ex_u8 total_size; - ex_u8 total_file_count; - ex_u32 total_time; - //数组,每个数组元素的内容是每个文件的播放时长 -}; -struct ssh_terms_data_header -{ - char ID[16]; - char version[16]; - ex_u32 term_count; - //数组,每个数组元素的内容是每个文件的播放时长 -}; -struct ssh_terms_data { - //char term[16]; - ex_u32 time; - ex_u32 w; - ex_u32 h; - //ex_u32 px; - //ex_u32 py; -}; + ex_u8 type; // 包的数据类型 + ex_u32 size; // 这个包的总大小(不含包头) + ex_u32 time_ms; // 这个包距起始时间的时间差(毫秒,意味着一个连接不能持续超过49天) + ex_u8 reserve[3]; // 保留 +}TS_RECORD_PKG; + #pragma pack(pop) -typedef std::vector file_time_list; - -typedef std::vector windows_size_list; - -class base_record -{ -public: - base_record(); - ~base_record(); -public: - void begin(int record_id, int record_type); - void record(unsigned char* buf, int len, int cmd); - void windows_size(ssh_terms_data size_info); - void end(); - ex_astr get_replay_path() { - return m_current_path; - } -protected: - bool open_next_file(); - bool cached_buffer(ts_replay_data_header* header, unsigned char* buf,int len); - bool save_buffer_to_file(int internal_time); - bool save_to_file(int internal_time, ts_replay_data_header* header, unsigned char* buf, int len); -protected: - ex_u64 m_begin_time; - ex_u64 m_last_time; - - int m_file_current_index; - - ex_astr m_current_path; - FILE* m_current_file; - unsigned char* m_buf; - int m_buf_offset; - - file_time_list m_timelist; - windows_size_list m_windows_size_list; - - int m_totol_size; - //Json::Value m_ts_replay; - -}; -#endif - -//==================================================== -// NEW INTERFACE -//==================================================== - -// #define TS_RECORD_TYPE_RDP_CURSOR_POS 0x10 // 鼠标坐标位置改变,用于绘制虚拟鼠标 -// #define TS_RECORD_TYPE_RDP_SERVER_PKG 0x11 // 服务端返回的数据包,用于展示 - -// #pragma pack(push,1) -// -// // 录像文件头 -// typedef struct TS_RECORD_HEADER -// { -// ex_u32 magic; // "TPPR" 标志 TelePort Protocol Record -// ex_u32 timestamp; // 本次录像的起始时间(UTC时间戳) -// ex_u32 packages; // 总包数 -// ex_u32 time_ms; // 总耗时(毫秒) -// ex_u16 width; // 初始屏幕尺寸:宽 -// ex_u16 height; // 初始屏幕尺寸:高 -// ex_u8 security; // 0 = RDP, 1 = SSL -// 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 - 20 - 1 - 2 - 4 - 16 - 16 - 18 - 2]; // 保留 -// }TS_RECORD_HEADER; -// -// // 一个数据包的头 -// typedef struct TS_RECORD_PKG -// { -// ex_u8 type; // 包的数据类型(目前暂时保留未使用,必须为0) -// ex_u32 size; // 这个包的总大小 -// ex_u32 time_ms; // 这个包距起始时间的时间差(毫秒,意味着一个连接不能持续超过49天) -// ex_u8 reserve[3]; // 保留 -// }TS_RECORD_PKG; -// -// RDP鼠标移动 -// typedef struct TS_RECORD_RDP_MOUSE_POS -// { -// ex_u16 x; -// ex_u16 y; -// }TS_RECORD_RDP_MOUSE_POS; - -// #pragma pack(pop) class TppRecBase { diff --git a/server/tp_core/protocol/ssh/ssh_recorder.cpp b/server/tp_core/protocol/ssh/ssh_recorder.cpp index 74cb654..7d4fc07 100644 --- a/server/tp_core/protocol/ssh/ssh_recorder.cpp +++ b/server/tp_core/protocol/ssh/ssh_recorder.cpp @@ -1,6 +1,6 @@ #include "ssh_recorder.h" -static ex_u8 TPP_RECORD_MAGIC[4] = { 'T', 'P', 'R', 'R' }; +static ex_u8 TPP_RECORD_MAGIC[4] = { 'T', 'P', 'P', 'R' }; TppSshRec::TppSshRec() { @@ -8,6 +8,8 @@ TppSshRec::TppSshRec() memset(&m_head, 0, sizeof(TS_RECORD_HEADER)); memcpy((ex_u8*)(&m_head.magic), TPP_RECORD_MAGIC, sizeof(ex_u32)); + m_head.ver = 0x02; + m_head.protocol = TS_PROXY_PROTOCOL_SSH; } TppSshRec::~TppSshRec() diff --git a/server/tp_core/protocol/ssh/ssh_recorder.h b/server/tp_core/protocol/ssh/ssh_recorder.h index a4f5a6c..08d52a8 100644 --- a/server/tp_core/protocol/ssh/ssh_recorder.h +++ b/server/tp_core/protocol/ssh/ssh_recorder.h @@ -9,32 +9,32 @@ #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_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