From 507ef71766dab111ceda8403152b6835ab2f7d5b Mon Sep 17 00:00:00 2001 From: Apex Liu Date: Mon, 27 Nov 2017 02:28:47 +0800 Subject: [PATCH] =?UTF-8?q?RDP=E5=8A=9F=E8=83=BD=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E5=88=B0v2=E7=9A=84=E7=8A=B6=E6=80=81=E4=BA=86=EF=BC=8C?= =?UTF-8?q?=E5=87=86=E5=A4=87=E5=B0=9D=E8=AF=95=E6=94=AF=E6=8C=81=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=8E=9F=E7=94=9FRDP=E5=AE=A2=E6=88=B7=E7=AB=AF?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/tp_core/common/ts_const.h | 42 ------------------- server/tp_core/protocol/ssh/ssh_recorder.cpp | 2 +- server/tp_core/protocol/ssh/ssh_session.cpp | 31 +++++++------- server/tp_core/protocol/ssh/ssh_session.h | 2 +- .../www/teleport/static/js/ops/remote-list.js | 2 +- 5 files changed, 18 insertions(+), 61 deletions(-) diff --git a/server/tp_core/common/ts_const.h b/server/tp_core/common/ts_const.h index 060bae2..da1fc45 100644 --- a/server/tp_core/common/ts_const.h +++ b/server/tp_core/common/ts_const.h @@ -23,46 +23,4 @@ #define TS_RDP_PROTOCOL_RDSTLS 4 #define TS_RDP_PROTOCOL_HYBRID_EX 8 -// #define TS_AUTH_MODE_NONE 0 -// #define TS_AUTH_MODE_PASSWORD 1 -// #define TS_AUTH_MODE_PRIVATE_KEY 2 -// -// #define TS_PROXY_PROTOCOL_RDP 1 -// #define TS_PROXY_PROTOCOL_SSH 2 -// #define TS_PROXY_PROTOCOL_TELNET 3 - -// #define TSR_OK 0x0000 -// #define TSR_INVALID_DATA 0x0001 -// #define TSR_SEND_ERROR 0x0002 -// #define TSR_NEED_MORE_DATA 0x0005 -// #define TSR_FAILED 0x0006 -// #define TSR_DATA_LEN_ZERO 0x0007 -// -// #define TSR_MAX_CONN_REACHED 0x0010 -// #define TSR_MAX_HOST_REACHED 0x0011 -// -// #define TSR_INVALID_REQUEST 0x1000 -// #define TSR_INVALID_URI 0x1001 -// #define TSR_INVALID_URL_ENCODE 0x1002 -// #define TSR_NO_SUCH_METHOD 0x1003 -// #define TSR_INVALID_JSON_FORMAT 0x1004 -// #define TSR_INVALID_JSON_PARAM 0x1005 -// #define TSR_GETAUTH_INFO_ERROR 0x1006 -// #define TSR_HOST_LOCK_ERROR 0x1007 -// #define TSR_ACCOUNT_LOCK_ERROR 0x1008 - -//================================================ -// #define SESS_STAT_RUNNING 0 // 会话开始了,尚未结束 -// #define SESS_STAT_END 9999 // 会话成功结束 -// #define SESS_STAT_ERR_AUTH_DENIED 1 // 会话结束,因为认证失败 -// #define SESS_STAT_ERR_CONNECT 2 // 会话结束,因为无法连接到远程主机 -// #define SESS_STAT_ERR_BAD_SSH_KEY 3 // 会话结束,因为无法识别SSH私钥 -// #define SESS_STAT_ERR_INTERNAL 4 // 会话结束,因为内部错误 -// #define SESS_STAT_ERR_UNSUPPORT_PROTOCOL 5 // 会话结束,因为协议不支持(RDP) -// #define SESS_STAT_ERR_BAD_PKG 6 // 会话结束,因为收到错误的报文 -// #define SESS_STAT_ERR_RESET 7 // 会话结束,因为teleport核心服务重置了 -// #define SESS_STAT_ERR_IO 8 // 会话结束,因为网络中断 -// #define SESS_STAT_ERR_SESSION 9 // 会话结束,因为无效的会话ID - - #endif // __TS_ERRNO_H__ diff --git a/server/tp_core/protocol/ssh/ssh_recorder.cpp b/server/tp_core/protocol/ssh/ssh_recorder.cpp index a550f1c..0679a7e 100644 --- a/server/tp_core/protocol/ssh/ssh_recorder.cpp +++ b/server/tp_core/protocol/ssh/ssh_recorder.cpp @@ -103,7 +103,7 @@ void TppSshRec::record_win_size_change(int width, int height) record(TS_RECORD_TYPE_SSH_TERM_SIZE, (ex_u8*)&pkg, sizeof(TS_RECORD_WIN_SIZE)); } -// TODO: 为了录像回放和命令历史能够对应(比如点击命令直接跳到录像的对应时点),应该仿照录像数据包的方式记录相对时间偏移,而不是绝对时间。 +// 为了录像回放和命令历史能够对应(比如点击命令直接跳到录像的对应时点),仿照录像数据包的方式记录相对时间偏移,而不是绝对时间。 void TppSshRec::record_command(int flag, const ex_astr& cmd) { char szTime[100] = { 0 }; diff --git a/server/tp_core/protocol/ssh/ssh_session.cpp b/server/tp_core/protocol/ssh/ssh_session.cpp index 6b4a274..4275c74 100644 --- a/server/tp_core/protocol/ssh/ssh_session.cpp +++ b/server/tp_core/protocol/ssh/ssh_session.cpp @@ -11,7 +11,7 @@ TP_SSH_CHANNEL_PAIR::TP_SSH_CHANNEL_PAIR() { cli_channel = NULL; srv_channel = NULL; - retcode = TP_SESS_STAT_RUNNING; + state = TP_SESS_STAT_RUNNING; db_id = 0; channel_id = 0; @@ -127,13 +127,13 @@ void SshSession::_record_end(TP_SSH_CHANNEL_PAIR* cp) { if (cp->db_id > 0) { - //EXLOGD("[ssh] [channel:%d] channel end with code: %d\n", cp->channel_id, cp->retcode); + //EXLOGD("[ssh] [channel:%d] channel end with code: %d\n", cp->channel_id, cp->state); // 如果会话过程中没有发生错误,则将其状态改为结束,否则记录下错误值 - if (cp->retcode == TP_SESS_STAT_RUNNING || cp->retcode == TP_SESS_STAT_STARTED) - cp->retcode = TP_SESS_STAT_END; + if (cp->state == TP_SESS_STAT_RUNNING || cp->state == TP_SESS_STAT_STARTED) + cp->state = TP_SESS_STAT_END; - g_ssh_env.session_end(m_sid.c_str(), cp->db_id, cp->retcode); + g_ssh_env.session_end(m_sid.c_str(), cp->db_id, cp->state); cp->db_id = 0; } @@ -320,7 +320,7 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user, _this->m_sid = user; EXLOGV("[ssh] authenticating, session-id: %s\n", _this->m_sid.c_str()); - int protocol = 0; +// int protocol = 0; //TPP_CONNECT_INFO* sess_info = g_ssh_env.get_connect_info(_this->m_sid.c_str()); _this->m_conn_info = g_ssh_env.get_connect_info(_this->m_sid.c_str()); @@ -336,16 +336,15 @@ int SshSession::_on_auth_password_request(ssh_session session, const char *user, _this->m_auth_type = _this->m_conn_info->auth_type; _this->m_acc_name = _this->m_conn_info->acc_username; _this->m_acc_secret = _this->m_conn_info->acc_secret; - protocol = _this->m_conn_info->protocol_type; + //protocol = _this->m_conn_info->protocol_type; + if (_this->m_conn_info->protocol_type != TP_PROTOCOL_TYPE_SSH) { + EXLOGE("[ssh] session '%s' is not for SSH.\n", _this->m_sid.c_str()); + _this->m_have_error = true; + _this->_session_error(TP_SESS_STAT_ERR_INTERNAL); + return SSH_AUTH_DENIED; + } } - - if (protocol != TP_PROTOCOL_TYPE_SSH) { - EXLOGE("[ssh] session '%s' is not for SSH.\n", _this->m_sid.c_str()); - _this->m_have_error = true; - _this->_session_error(TP_SESS_STAT_ERR_INTERNAL); - return SSH_AUTH_DENIED; - } - + // 现在尝试根据session-id获取得到的信息,连接并登录真正的SSH服务器 EXLOGV("[ssh] try to connect to real SSH server %s:%d\n", _this->m_conn_ip.c_str(), _this->m_conn_port); _this->m_srv_session = ssh_new(); @@ -722,7 +721,7 @@ int SshSession::_on_client_channel_subsystem_request(ssh_session session, ssh_ch // 目前只支持SFTP子系统 if (strcmp(subsystem, "sftp") != 0) { EXLOGE("[ssh] support `sftp` subsystem only, but got `%s`.\n", subsystem); - cp->retcode = TP_SESS_STAT_ERR_UNSUPPORT_PROTOCOL; + cp->state = TP_SESS_STAT_ERR_UNSUPPORT_PROTOCOL; return SSH_ERROR; } diff --git a/server/tp_core/protocol/ssh/ssh_session.h b/server/tp_core/protocol/ssh/ssh_session.h index a7abde0..9797538 100644 --- a/server/tp_core/protocol/ssh/ssh_session.h +++ b/server/tp_core/protocol/ssh/ssh_session.h @@ -37,7 +37,7 @@ private: TppSshRec rec; - int retcode; + int state; int db_id; int channel_id; // for debug only. diff --git a/server/www/teleport/static/js/ops/remote-list.js b/server/www/teleport/static/js/ops/remote-list.js index ddc88af..e002c98 100644 --- a/server/www/teleport/static/js/ops/remote-list.js +++ b/server/www/teleport/static/js/ops/remote-list.js @@ -129,7 +129,7 @@ $app.on_table_host_cell_created = function (tbl, row_id, col_key, cell_obj) { console.log(uni_id, protocol_sub_type); if (action === 'rdp') { - $tp.notify_error('灏氭湭瀹炵幇锛'); + $app.connect_remote(uni_id, TP_PROTOCOL_TYPE_RDP, TP_PROTOCOL_TYPE_RDP_DESKTOP); } else if (action === 'ssh') { $app.connect_remote(uni_id, TP_PROTOCOL_TYPE_SSH, protocol_sub_type); } else if (action === 'telnet') {