From d6bcdeb42dbd43e3e80e72527a794be3b23766a6 Mon Sep 17 00:00:00 2001 From: Apex Liu Date: Mon, 11 Dec 2017 01:02:19 +0800 Subject: [PATCH] =?UTF-8?q?rdp=E6=92=AD=E6=94=BE=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=8F=AF=E7=94=A8=EF=BC=88=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=92=AD=E6=94=BEFreeRDP=E7=9A=84=E5=BD=95=E5=83=8F=EF=BC=8C?= =?UTF-8?q?=E4=BD=86=E6=98=AF=E4=B8=8D=E8=83=BD=E6=92=AD=E6=94=BEMSCST?= =?UTF-8?q?=E7=9A=84=E5=BD=95=E5=83=8F=EF=BC=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/tp_assist_win/ts_http_rpc.cpp | 172 +++++++----- client/tp_assist_win/ts_http_rpc.h | 3 +- server/tp_core/core/ts_web_rpc.cpp | 3 + .../teleport/static/js/audit/record-list.js | 244 +++++++++--------- server/www/teleport/static/js/teleport.js | 26 +- .../teleport/static/js/teleport/controls.js | 3 +- server/www/teleport/static/js/tp-assist.js | 45 +++- server/www/teleport/view/audit/record.mako | 1 + .../webroot/app/controller/__init__.py | 3 + .../teleport/webroot/app/controller/audit.py | 79 ++++++ 10 files changed, 359 insertions(+), 220 deletions(-) diff --git a/client/tp_assist_win/ts_http_rpc.cpp b/client/tp_assist_win/ts_http_rpc.cpp index ea0aca1..4827ccc 100644 --- a/client/tp_assist_win/ts_http_rpc.cpp +++ b/client/tp_assist_win/ts_http_rpc.cpp @@ -1174,92 +1174,124 @@ void TsHttpRpc::_rpc_func_rdp_play(const ex_astr& func_args, ex_astr& buf) } // 判断参数是否正确 - if (!jsRoot["host"].isString()) - { - _create_json_ret(buf, TPE_PARAM); - return; - } - if (!jsRoot["port"].isInt()) - { - _create_json_ret(buf, TPE_PARAM); - return; - } - if (!jsRoot["tail"].isString()) +// if (!jsRoot["host"].isString()) +// { +// _create_json_ret(buf, TPE_PARAM); +// return; +// } +// if (!jsRoot["port"].isInt()) +// { +// _create_json_ret(buf, TPE_PARAM); +// return; +// } + + if (!jsRoot["rid"].isInt() + || !jsRoot["web"].isString() + || !jsRoot["sid"].isString() + || !jsRoot["user"].isString() + || !jsRoot["acc"].isString() + || !jsRoot["host"].isString() + || !jsRoot["start"].isString() + ) { _create_json_ret(buf, TPE_PARAM); return; } + + + +// if (!jsRoot["tail"].isString()) +// { +// _create_json_ret(buf, TPE_PARAM); +// return; +// } + + int rid = jsRoot["rid"].asInt(); + ex_astr a_url_base = jsRoot["web"].asCString(); + ex_astr a_sid = jsRoot["sid"].asCString(); + ex_astr a_user = jsRoot["user"].asCString(); + ex_astr a_acc = jsRoot["acc"].asCString(); ex_astr a_host = jsRoot["host"].asCString(); - int port = jsRoot["port"].asInt(); - ex_astr a_tail = jsRoot["tail"].asCString(); - ex_astr server_ip; - if (isIPAddress(a_host.c_str())) - { - server_ip = a_host; - } - else - { - char *ptr, **pptr; - struct hostent *hptr; - char IP[128] = { 0 }; - /* 取得命令后第一个参数,即要解析的域名或主机名 */ - ptr = (char*)a_host.c_str(); - /* 调用gethostbyname()。调用结果都存在hptr中 */ - if ((hptr = gethostbyname(ptr)) == NULL) - { - //printf("gethostbyname error for host:%s/n", ptr); - _create_json_ret(buf, TPE_PARAM); - return; - } - /* 将主机的规范名打出来 */ - //printf("official hostname:%s/n", hptr->h_name); - /* 主机可能有多个别名,将所有别名分别打出来 */ - //for (pptr = hptr->h_aliases; *pptr != NULL; pptr++) - // printf(" alias:%s/n", *pptr); - /* 根据地址类型,将地址打出来 */ - char szbuf[1204] = { 0 }; - switch (hptr->h_addrtype) - { - case AF_INET: - case AF_INET6: - pptr = hptr->h_addr_list; - /* 将刚才得到的所有地址都打出来。其中调用了inet_ntop()函数 */ + ex_astr a_start = jsRoot["start"].asCString(); + //ex_astr a_tail = jsRoot["tail"].asCString(); - for (; *pptr != NULL; pptr++) - inet_ntop(hptr->h_addrtype, *pptr, IP, sizeof(IP)); - server_ip = IP; - break; - default: - printf("unknown address type/n"); - break; - } - } - char szURL[256] = { 0 }; - sprintf_s(szURL, 256, "http://%s:%d/%s", server_ip.c_str(), port, a_tail.c_str()); - ex_astr a_url = szURL; - ex_wstr w_url; - ex_astr2wstr(a_url, w_url); + char cmd_args[1024] = { 0 }; + ex_strformat(cmd_args, 1023, "%d \"%s\" \"%09d-%s-%s-%s-%s\"", rid, a_sid.c_str(), rid, a_user.c_str(), a_acc.c_str(), a_host.c_str(), a_start.c_str()); - char szHost[256] = { 0 }; - sprintf_s(szHost, 256, "%s:%d", a_host.c_str(), port); - a_host = szHost; - ex_wstr w_host; - ex_astr2wstr(a_host, w_host); +// ex_astr a_host = jsRoot["host"].asCString(); +// int port = jsRoot["port"].asInt(); +// ex_astr a_tail = jsRoot["tail"].asCString(); +// ex_astr server_ip; +// if (isIPAddress(a_host.c_str())) +// { +// server_ip = a_host; +// } +// else +// { +// char *ptr, **pptr; +// struct hostent *hptr; +// char IP[128] = { 0 }; +// // 取得命令后第一个参数,即要解析的域名或主机名 +// ptr = (char*)a_host.c_str(); +// // 调用gethostbyname()。调用结果都存在hptr中 +// if ((hptr = gethostbyname(ptr)) == NULL) +// { +// //printf("gethostbyname error for host:%s/n", ptr); +// _create_json_ret(buf, TPE_PARAM); +// return; +// } +// // 将主机的规范名打出来 +// //printf("official hostname:%s/n", hptr->h_name); +// // 主机可能有多个别名,将所有别名分别打出来 +// //for (pptr = hptr->h_aliases; *pptr != NULL; pptr++) +// // printf(" alias:%s/n", *pptr); +// // 根据地址类型,将地址打出来 +// char szbuf[1204] = { 0 }; +// switch (hptr->h_addrtype) +// { +// case AF_INET: +// case AF_INET6: +// pptr = hptr->h_addr_list; +// // 将刚才得到的所有地址都打出来。其中调用了inet_ntop()函数 +// +// for (; *pptr != NULL; pptr++) +// inet_ntop(hptr->h_addrtype, *pptr, IP, sizeof(IP)); +// server_ip = IP; +// break; +// default: +// printf("unknown address type/n"); +// break; +// } +// } + +// char szURL[256] = { 0 }; +// sprintf_s(szURL, 256, "http://%s:%d/%s", server_ip.c_str(), port, a_tail.c_str()); +// ex_astr a_url = szURL; + ex_wstr w_url_base; + ex_astr2wstr(a_url_base, w_url_base); + ex_wstr w_cmd_args; + ex_astr2wstr(cmd_args, w_cmd_args); + +// char szHost[256] = { 0 }; +// sprintf_s(szHost, 256, "%s:%d", a_host.c_str(), port); +// +// a_host = szHost; +// ex_wstr w_host; +// ex_astr2wstr(a_host, w_host); ex_wstr w_exe_path; w_exe_path = _T("\""); w_exe_path += g_env.m_tools_path + _T("\\tprdp\\tprdp-replay.exe\""); - w_exe_path += _T(" "); - w_exe_path += w_url; - - w_exe_path += _T(" "); - w_exe_path += w_host; + w_exe_path += _T(" \""); + w_exe_path += w_url_base; + w_exe_path += _T("\" "); + w_exe_path += w_cmd_args; Json::Value root_ret; ex_astr utf8_path; ex_wstr2astr(w_exe_path, utf8_path, EX_CODEPAGE_UTF8); - root_ret["path"] = utf8_path; + root_ret["cmdline"] = utf8_path; STARTUPINFO si; PROCESS_INFORMATION pi; diff --git a/client/tp_assist_win/ts_http_rpc.h b/client/tp_assist_win/ts_http_rpc.h index a78a723..941327e 100644 --- a/client/tp_assist_win/ts_http_rpc.h +++ b/client/tp_assist_win/ts_http_rpc.h @@ -1,6 +1,8 @@ #ifndef __TS_HTTP_RPC_H__ #define __TS_HTTP_RPC_H__ +#include "../../external/mongoose/mongoose.h" + #include "ts_const.h" #include @@ -10,7 +12,6 @@ #include #include -#include "../../external/mongoose/mongoose.h" /* //================================================================= diff --git a/server/tp_core/core/ts_web_rpc.cpp b/server/tp_core/core/ts_web_rpc.cpp index d12dcae..f50f963 100644 --- a/server/tp_core/core/ts_web_rpc.cpp +++ b/server/tp_core/core/ts_web_rpc.cpp @@ -54,6 +54,9 @@ int ts_web_rpc_get_conn_info(int conn_id, TS_CONNECT_INFO& info) // EXLOGV("\n"); return TPE_NETWORK; } + if (body.length() == 0) { + return TPE_NETWORK; + } Json::Reader jreader; Json::Value jret; diff --git a/server/www/teleport/static/js/audit/record-list.js b/server/www/teleport/static/js/audit/record-list.js index 837649b..025bb59 100644 --- a/server/www/teleport/static/js/audit/record-list.js +++ b/server/www/teleport/static/js/audit/record-list.js @@ -27,21 +27,11 @@ $app.create_controls = function (cb_stack) { dom_id: 'table-record', data_source: { type: 'ajax-post' - ,url: '/audit/get-records' + , url: '/audit/get-records' //exclude: {'state': [TP_SESS_STAT_RUNNING, TP_SESS_STAT_STARTED]} }, column_default: {sort: false, align: 'left'}, columns: [ - // { - // // title: '', - // title: '', - // key: 'chkbox', - // sort: false, - // width: 36, - // align: 'center', - // render: 'make_check_box', - // fields: {id: 'id'} - // }, { title: 'ID', key: 'id', @@ -59,24 +49,17 @@ $app.create_controls = function (cb_stack) { { title: '鐢ㄦ埛', key: 'user', - //sort: true, - //header_render: 'filter_search_host', render: 'user', fields: {user_username: 'user_username', user_surname: 'user_surname'} }, { title: '鏉ユ簮', key: 'client_ip', - //sort: true, - //header_render: 'filter_search_host', - //render: 'host_info', fields: {client_ip: 'client_ip'} }, { title: '杩滅▼杩炴帴', key: 'remote', - //sort: true, - //header_render: 'filter_search_host', render: 'remote', fields: {acc_username: 'acc_username', host_ip: 'host_ip', conn_ip: 'conn_ip', conn_port: 'conn_port'} }, @@ -85,10 +68,6 @@ $app.create_controls = function (cb_stack) { key: 'protocol_type', align: 'center', width: 80, - // align: 'center', - // width: 36, - //sort: true - // header_render: 'filter_os', render: 'protocol', fields: {protocol_type: 'protocol_type', protocol_sub_type: 'protocol_sub_type'} }, @@ -125,12 +104,12 @@ $app.create_controls = function (cb_stack) { render: 'record_action', fields: {id: 'id', state: 'state', time_end: 'time_end', protocol_sub_type: 'protocol_sub_type'} } - ], + ] // 閲嶈浇鍥炶皟鍑芥暟 - on_header_created: $app.on_table_host_header_created, - on_render_created: $app.on_table_host_render_created, - on_cell_created: $app.on_table_host_cell_created + //,on_header_created: $app.on_table_host_header_created + , on_render_created: $app.on_table_host_render_created + , on_cell_created: $app.on_table_host_cell_created }; $app.table_record = $tp.create_table(table_record_options); @@ -141,10 +120,10 @@ $app.create_controls = function (cb_stack) { //------------------------------- // 鐢ㄦ埛鍒楄〃鐩稿叧杩囨护鍣 //------------------------------- - $tp.create_table_header_filter_search($app.table_record, { - name: 'search', - place_holder: '鎼滅储锛氫富鏈篒P/鍚嶇О/鎻忚堪/璧勪骇缂栧彿/绛夌瓑...' - }); + // $tp.create_table_header_filter_search($app.table_record, { + // name: 'search', + // place_holder: '鎼滅储锛氫富鏈篒P/鍚嶇О/鎻忚堪/璧勪骇缂栧彿/绛夌瓑...' + // }); // $app.table_record_role_filter = $tp.create_table_filter_role($app.table_record, $app.role_list); // $tp.create_table_header_filter_state($app.table_record, 'state', $app.obj_states, [TP_STATE_LOCKED]); // 浠巆ookie涓鍙栫敤鎴峰垎椤甸檺鍒剁殑閫夋嫨 @@ -168,11 +147,12 @@ $app.create_controls = function (cb_stack) { }; $app.on_table_host_cell_created = function (tbl, row_id, col_key, cell_obj) { - if (col_key === 'chkbox') { - cell_obj.find('[data-check-box]').click(function () { - $app.check_host_all_selected(); - }); - } else if (col_key === 'action') { + // if (col_key === 'chkbox') { + // cell_obj.find('[data-check-box]').click(function () { + // $app.check_host_all_selected(); + // }); + // } else + if (col_key === 'action') { // 缁戝畾绯荤粺閫夋嫨妗嗕簨浠 cell_obj.find('[data-action]').click(function () { @@ -183,7 +163,8 @@ $app.on_table_host_cell_created = function (tbl, row_id, col_key, cell_obj) { if (action === 'replay') { //$app.dlg_edit_host.show_edit(row_id); if (row_data.protocol_type === TP_PROTOCOL_TYPE_RDP) { - $tp.notify_error('sorry, not impl.'); + // $tp.notify_error('sorry, not impl.'); + $app.do_replay_rdp(row_data.id, row_data.user_username, row_data.acc_username, row_data.host_ip, row_data.time_begin); } else if (row_data.protocol_type === TP_PROTOCOL_TYPE_SSH) { window.open('/audit/replay/' + row_data.protocol_type + '/' + row_data.id); } @@ -206,36 +187,36 @@ $app.on_table_host_cell_created = function (tbl, row_id, col_key, cell_obj) { }; $app.on_table_host_render_created = function (render) { - render.filter_host_state = function (header, title, col) { - var _ret = ['
']; - _ret.push('
'); - _ret.push('
' + title + '
'); + // render.filter_host_state = function (header, title, col) { + // var _ret = ['
']; + // _ret.push('
'); + // _ret.push('
' + title + '
'); + // + // // 琛ㄦ牸鍐呭祵杩囨护鍣ㄧ殑DOM瀹炰綋鍦ㄨ繖鏃剁敓鎴 + // var filter_ctrl = header._table_ctrl.get_filter_ctrl('state'); + // _ret.push(filter_ctrl.render()); + // + // _ret.push('
'); + // + // return _ret.join(''); + // }; + // + // render.filter_search_host = function (header, title, col) { + // var _ret = ['
']; + // _ret.push('
'); + // _ret.push('
' + title + '
'); + // + // // 琛ㄦ牸鍐呭祵杩囨护鍣ㄧ殑DOM瀹炰綋鍦ㄨ繖鏃剁敓鎴 + // var filter_ctrl = header._table_ctrl.get_filter_ctrl('search'); + // _ret.push(filter_ctrl.render()); + // + // _ret.push('
'); + // + // return _ret.join(''); + // }; - // 琛ㄦ牸鍐呭祵杩囨护鍣ㄧ殑DOM瀹炰綋鍦ㄨ繖鏃剁敓鎴 - var filter_ctrl = header._table_ctrl.get_filter_ctrl('state'); - _ret.push(filter_ctrl.render()); - - _ret.push('
'); - - return _ret.join(''); - }; - - render.filter_search_host = function (header, title, col) { - var _ret = ['
']; - _ret.push('
'); - _ret.push('
' + title + '
'); - - // 琛ㄦ牸鍐呭祵杩囨护鍣ㄧ殑DOM瀹炰綋鍦ㄨ繖鏃剁敓鎴 - var filter_ctrl = header._table_ctrl.get_filter_ctrl('search'); - _ret.push(filter_ctrl.render()); - - _ret.push('
'); - - return _ret.join(''); - }; - - render.sid = function(row_id, fields) { - return ''+fields.sid+''; + render.sid = function (row_id, fields) { + return '' + fields.sid + ''; }; render.user = function (row_id, fields) { @@ -270,7 +251,6 @@ $app.on_table_host_render_created = function (render) { }; render.time_begin = function (row_id, fields) { - // return tp_format_datetime(tp_utc2local(fields.time_begin), 'MM-dd HH:mm:ss'); return tp_format_datetime(tp_utc2local(fields.time_begin), 'MM-dd HH:mm:ss'); }; @@ -373,60 +353,84 @@ $app.on_table_host_render_created = function (render) { }; }; -$app.on_table_host_header_created = function (header) { - $('#' + header._table_ctrl.dom_id + ' a[data-reset-filter]').click(function () { - CALLBACK_STACK.create() - .add(header._table_ctrl.load_data) - .add(header._table_ctrl.reset_filters) - .exec(); - }); - - // 琛ㄦ牸鍐呭祵杩囨护鍣ㄧ殑浜嬩欢缁戝畾鍦ㄨ繖鏃惰繘琛岋紙涔熷彲浠ュ欢鏈熷埌鏁翠釜琛ㄦ牸鍒涘缓瀹屾垚鏃惰繘琛岋級 - header._table_ctrl.get_filter_ctrl('search').on_created(); -}; - -$app.get_selected_record = function (tbl) { - var records = []; - var _objs = $('#' + $app.table_record.dom_id + ' tbody tr td input[data-check-box]'); - $.each(_objs, function (i, _obj) { - if ($(_obj).is(':checked')) { - var _row_data = tbl.get_row(_obj); - records.push(_row_data.id); +$app.do_replay_rdp = function (record_id, user_username, acc_username, host_ip, time_begin) { + $assist.do_rdp_replay( + { + rid: record_id + // , web: $tp.web_server // + '/audit/get_rdp_record/' + record_id // 'http://' + ip + ':' + port + '/log/replay/rdp/' + record_id; + // , sid: Cookies.get('_sid') + , user: user_username + , acc: acc_username + , host: host_ip + , start: time_begin//tp_format_datetime(tp_utc2local(time_begin), 'yyyyMMdd-HHmmss') } - }); - return records; + , function () { + // func_success + } + , function (code, message) { + if (code === TPE_NO_ASSIST) + $assist.alert_assist_not_found(); + else + $tp.notify_error('鎾斁RDP鎿嶄綔褰曞儚澶辫触锛' + tp_error_msg(code, message)); + } + ); }; -$app.on_btn_remove_record_click = function () { - // var records = $app.get_selected_record($app.table_record); - // if (records.length === 0) { - // $tp.notify_error('璇烽夋嫨瑕佸垹闄ょ殑浼氳瘽璁板綍锛'); - // return; - // } - // - // var _fn_sure = function (cb_stack, cb_args) { - // $tp.ajax_post_json('/user/remove-user', {users: users}, - // function (ret) { - // if (ret.code === TPE_OK) { - // cb_stack.add($app.check_host_all_selected); - // cb_stack.add($app.table_record.load_data); - // $tp.notify_success('鍒犻櫎鐢ㄦ埛璐﹀彿鎿嶄綔鎴愬姛锛'); - // } else { - // $tp.notify_error('鍒犻櫎鐢ㄦ埛璐﹀彿鎿嶄綔澶辫触锛' + tp_error_msg(ret.code, ret.message)); - // } - // - // cb_stack.exec(); - // }, - // function () { - // $tp.notify_error('缃戠粶鏁呴殰锛屽垹闄ょ敤鎴疯处鍙锋搷浣滃け璐ワ紒'); - // cb_stack.exec(); - // } - // ); - // }; - // - // var cb_stack = CALLBACK_STACK.create(); - // $tp.dlg_confirm(cb_stack, { - // msg: '

娉ㄦ剰锛氬垹闄ゆ搷浣滀笉鍙仮澶嶏紒锛

鍒犻櫎鐢ㄦ埛璐﹀彿灏嗗悓鏃跺皢鍏朵粠鎵鍦ㄧ敤鎴风粍涓Щ闄わ紝骞朵笖鍒犻櫎鎵鏈夊垎閰嶇粰姝ょ敤鎴风殑鎺堟潈锛

濡傛灉鎮ㄥ笇鏈涚姝㈡煇涓敤鎴风櫥褰曟湰绯荤粺锛屽彲瀵瑰叾杩涜鈥滅鐢ㄢ濇搷浣滐紒

鎮ㄧ‘瀹氳绉婚櫎鎵鏈夐夊畾鐨 ' + user_list.length + '涓 鐢ㄦ埛璐﹀彿鍚楋紵

', - // fn_yes: _fn_sure - // }); -}; + +// $app.on_table_host_header_created = function (header) { +// $('#' + header._table_ctrl.dom_id + ' a[data-reset-filter]').click(function () { +// CALLBACK_STACK.create() +// .add(header._table_ctrl.load_data) +// .add(header._table_ctrl.reset_filters) +// .exec(); +// }); +// +// // 琛ㄦ牸鍐呭祵杩囨护鍣ㄧ殑浜嬩欢缁戝畾鍦ㄨ繖鏃惰繘琛岋紙涔熷彲浠ュ欢鏈熷埌鏁翠釜琛ㄦ牸鍒涘缓瀹屾垚鏃惰繘琛岋級 +// header._table_ctrl.get_filter_ctrl('search').on_created(); +// }; + +// $app.get_selected_record = function (tbl) { +// var records = []; +// var _objs = $('#' + $app.table_record.dom_id + ' tbody tr td input[data-check-box]'); +// $.each(_objs, function (i, _obj) { +// if ($(_obj).is(':checked')) { +// var _row_data = tbl.get_row(_obj); +// records.push(_row_data.id); +// } +// }); +// return records; +// }; + +// $app.on_btn_remove_record_click = function () { +// var records = $app.get_selected_record($app.table_record); +// if (records.length === 0) { +// $tp.notify_error('璇烽夋嫨瑕佸垹闄ょ殑浼氳瘽璁板綍锛'); +// return; +// } +// +// var _fn_sure = function (cb_stack, cb_args) { +// $tp.ajax_post_json('/user/remove-user', {users: users}, +// function (ret) { +// if (ret.code === TPE_OK) { +// cb_stack.add($app.check_host_all_selected); +// cb_stack.add($app.table_record.load_data); +// $tp.notify_success('鍒犻櫎鐢ㄦ埛璐﹀彿鎿嶄綔鎴愬姛锛'); +// } else { +// $tp.notify_error('鍒犻櫎鐢ㄦ埛璐﹀彿鎿嶄綔澶辫触锛' + tp_error_msg(ret.code, ret.message)); +// } +// +// cb_stack.exec(); +// }, +// function () { +// $tp.notify_error('缃戠粶鏁呴殰锛屽垹闄ょ敤鎴疯处鍙锋搷浣滃け璐ワ紒'); +// cb_stack.exec(); +// } +// ); +// }; +// +// var cb_stack = CALLBACK_STACK.create(); +// $tp.dlg_confirm(cb_stack, { +// msg: '

娉ㄦ剰锛氬垹闄ゆ搷浣滀笉鍙仮澶嶏紒锛

鍒犻櫎鐢ㄦ埛璐﹀彿灏嗗悓鏃跺皢鍏朵粠鎵鍦ㄧ敤鎴风粍涓Щ闄わ紝骞朵笖鍒犻櫎鎵鏈夊垎閰嶇粰姝ょ敤鎴风殑鎺堟潈锛

濡傛灉鎮ㄥ笇鏈涚姝㈡煇涓敤鎴风櫥褰曟湰绯荤粺锛屽彲瀵瑰叾杩涜鈥滅鐢ㄢ濇搷浣滐紒

鎮ㄧ‘瀹氳绉婚櫎鎵鏈夐夊畾鐨 ' + user_list.length + '涓 鐢ㄦ埛璐﹀彿鍚楋紵

', +// fn_yes: _fn_sure +// }); +// }; diff --git a/server/www/teleport/static/js/teleport.js b/server/www/teleport/static/js/teleport.js index df88d48..5220727 100644 --- a/server/www/teleport/static/js/teleport.js +++ b/server/www/teleport/static/js/teleport.js @@ -53,13 +53,11 @@ var CALLBACK_STACK = { } }; - // console.log(window.location, window.location.protocol+'://'+window.location.host); - // Teleport鏍稿績JS var $tp = { - web_server: window.location.protocol+'://'+window.location.host + web_server: window.location.protocol+'//'+window.location.host // Teleport椤甸潰搴旂敤瀵硅薄锛屾斁缃〉闈㈣嚜韬壒鏈夌殑灞炴у拰鍑芥暟 , app: { @@ -79,28 +77,6 @@ $tp.init = function () { {id: TP_STATE_LOCKED, name: '涓存椂閿佸畾', style: 'warning'} ]; - // $app.user_states = [ - // {id: 1, name: '姝e父', style: 'success'}, - // {id: 2, name: '涓存椂閿佸畾', style: 'warning'}, - // {id: 3, name: '绂佺敤', style: 'danger'} - // ]; - // - // $app.acc_states = [ - // {id: 1, name: '姝e父', style: 'success'}, - // {id: 2, name: '涓存椂閿佸畾', style: 'warning'}, - // {id: 3, name: '绂佺敤', style: 'danger'} - // ]; - // - // $app.host_states = [ - // {id: 1, name: '姝e父', style: 'success'}, - // {id: 2, name: '绂佺敤', style: 'danger'} - // ]; - // - // $app.policy_states = [ - // {id: 1, name: '姝e父', style: 'success'}, - // {id: 2, name: '绂佺敤', style: 'danger'} - // ]; - $app.host_types = [ {id: 1, name: '鐗╃悊涓绘満', style: 'success'}, {id: 2, name: '铏氭嫙涓绘満', style: 'info'}, diff --git a/server/www/teleport/static/js/teleport/controls.js b/server/www/teleport/static/js/teleport/controls.js index 786f7b9..69f769c 100644 --- a/server/www/teleport/static/js/teleport/controls.js +++ b/server/www/teleport/static/js/teleport/controls.js @@ -839,7 +839,8 @@ $tp.create_table_header = function (tbl, on_created) { if (_.isFunction(on_created)) on_created(_tbl_header); - else if (!_.isUndefined(on_created)) + //else if (!_.isUndefined(on_created)) + else if (!_.isNull(on_created)) console.error('create table header, on_created() is not callable.'); cb_stack.exec(); diff --git a/server/www/teleport/static/js/tp-assist.js b/server/www/teleport/static/js/tp-assist.js index f4b5f96..46c3f76 100644 --- a/server/www/teleport/static/js/tp-assist.js +++ b/server/www/teleport/static/js/tp-assist.js @@ -27,7 +27,7 @@ $assist.init = function (cb_stack) { $assist.running = true; $assist.version = ret.version; - if(_.isFunction($tp.assist_checked)) { + if (_.isFunction($tp.assist_checked)) { $tp.assist_checked(); } // if (version_compare()) { @@ -38,7 +38,7 @@ $assist.init = function (cb_stack) { }, error: function () { $assist.running = false; - if(_.isFunction($tp.assist_checked)) { + if (_.isFunction($tp.assist_checked)) { $tp.assist_checked(); } // func_error({}, TPE_NO_ASSIST, '鏃犳硶杩炴帴鍒皌eleport鍔╂墜锛屽彲鑳藉皻鏈惎鍔紒'); @@ -120,7 +120,7 @@ $assist.do_teleport = function (args, func_success, func_error) { jsonp: 'callback', dataType: 'json', success: function (ret) { - if(ret.code === TPE_OK) { + if (ret.code === TPE_OK) { func_success(); } else { func_error(ret.code, ret.message); @@ -144,6 +144,45 @@ $assist.do_teleport = function (args, func_success, func_error) { }); }; +$assist.do_rdp_replay = function (args, func_success, func_error) { + // ================================================== + // args is dict with fields shown below: + // rid: (int) - record-id in database. + // user: (string) - who did the RDP connection. + // acc: (string) - account to login to remote RDP server. + // host: (string) - IP of the remote RDP server. + // start: (string) - when start the RDP connection, should be a UTC timestamp. + // ================================================== + + // now fix the args. + args.web = $tp.web_server; // (string) - teleport server base address, like "http://127.0.0.1:7190", without end-slash. + args.sid = Cookies.get('_sid'); // (string) - current login user's session-id. + args.start = tp_format_datetime(tp_utc2local(args.start), 'yyyyMMdd-HHmmss'); // (string) - convert UTC timestamp to local human-readable string. + + console.log('do-rdp-replay:', args); + + var args_ = encodeURIComponent(JSON.stringify(args)); + $.ajax({ + type: 'GET', + timeout: 6000, + url: $assist.api_url + '/rdp_play/' + args_, + jsonp: 'callback', + dataType: 'json', + success: function (ret) { + console.log('ret', ret); + if (ret.code === TPE_OK) { + func_success(); + } else { + // func_error(ret.code, '鏌ョ湅杩滅▼妗岄潰鎿嶄綔褰曞儚澶辫触锛'); + func_error(ret.code, ret.message); + } + }, + error: function () { + func_error(TPE_NO_ASSIST, '鏃犳硶杩炴帴鍒皌eleport鍔╂墜锛屽彲鑳藉皻鏈惎鍔紒'); + } + }); +}; + /* var version_compare = function () { diff --git a/server/www/teleport/view/audit/record.mako b/server/www/teleport/view/audit/record.mako index 6c1415d..77146e6 100644 --- a/server/www/teleport/view/audit/record.mako +++ b/server/www/teleport/view/audit/record.mako @@ -6,6 +6,7 @@ <%inherit file="../page_base.mako"/> <%block name="extend_js_file"> + diff --git a/server/www/teleport/webroot/app/controller/__init__.py b/server/www/teleport/webroot/app/controller/__init__.py index 23b40b2..8cd61ac 100644 --- a/server/www/teleport/webroot/app/controller/__init__.py +++ b/server/www/teleport/webroot/app/controller/__init__.py @@ -183,6 +183,9 @@ controllers = [ # - [json] 璇诲彇褰曞儚鏁版嵁 (r'/audit/get-record-data', audit.DoGetRecordDataHandler), + # - 璇诲彇褰曞儚鏂囦欢锛堢敤浜嶳DP褰曞儚鍥炴斁锛 + (r'/audit/get-file', audit.DoGetFileHandler), + # (r'/host/export-host', host.ExportHostHandler), # (r'/config/export-database', config.ExportDatabaseHandler), # (r'/config/import-database', config.ImportDatabaseHandler), diff --git a/server/www/teleport/webroot/app/controller/audit.py b/server/www/teleport/webroot/app/controller/audit.py index 1002b0b..445be9d 100644 --- a/server/www/teleport/webroot/app/controller/audit.py +++ b/server/www/teleport/webroot/app/controller/audit.py @@ -274,3 +274,82 @@ class DoGetRecordDataHandler(TPBaseJsonHandler): data_list, data_size, err = record.read_record_data(record_id, offset) self.write_json(err, data={'data_list': data_list, 'data_size': data_size}) + + +class DoGetFileHandler(TPBaseHandler): + @tornado.gen.coroutine + def get(self): + + log.v('--{}\n'.format(self.request.uri)) + + require_privilege = TP_PRIVILEGE_OPS | TP_PRIVILEGE_OPS_AUZ | TP_PRIVILEGE_AUDIT_AUZ | TP_PRIVILEGE_AUDIT_OPS_HISTORY + + # sid = self.get_argument('sid', None) + # if sid is None: + # self.set_status(403) + # return self.write('need login first.') + # + # self._s_id = sid + # _user = self.get_session('user') + # if _user is None: + # self.set_status(403) + # return self.write('need login first.') + # self._user = _user + + if not self._user['_is_login']: + self.set_status(401) # 401=鏈巿鏉, 瑕佹眰韬唤楠岃瘉 + return self.write('need login first.') + if (self._user['privilege'] & require_privilege) == 0: + self.set_status(403) # 403=绂佹 + return self.write('you have no such privilege.') + + act = self.get_argument('act', None) + _type = self.get_argument('type', None) + rid = self.get_argument('rid', None) + filename = self.get_argument('f', None) + offset = int(self.get_argument('offset', '0')) + length = int(self.get_argument('length', '-1')) # -1 means read all content. + if act is None or _type is None or rid is None or filename is None: + self.set_status(400) # 400=閿欒璇锋眰 + return self.write('invalid param, `rid` and `f` must present.') + + if act not in ['size', 'read']: + self.set_status(400) + return self.write('invalid param, `act` should be `size` or `read`.') + if _type not in ['rdp', 'ssh', 'telnet']: + self.set_status(400) + return self.write('invalid param, `type` should be `rdp`, `ssh` or `telnet`.') + + file = os.path.join(get_cfg().core.replay_path, 'rdp', '{:09d}'.format(int(rid)), filename) + if not os.path.exists(file): + self.set_status(404) + return self.write('file does not exists.') + + file_size = os.path.getsize(file) + + if act == 'size': + log.d('--return size:{}\n'.format(file_size)) + return self.write('{}'.format(file_size)) + + if offset >= file_size: + self.set_status(416) # 416=璇锋眰鑼冨洿涓嶇鍚堣姹 + return self.write('no more data.') + + # we read most 4096 bytes one time. + BULK_SIZE = 4096 + total_need = file_size - offset + if length != -1 and length < total_need: + total_need = length + total_read = 0 + with open(file, 'rb') as f: + f.seek(offset) + read_this_time = BULK_SIZE if total_need > BULK_SIZE else total_need + while read_this_time > 0: + self.write(f.read(read_this_time)) + total_read += read_this_time + if total_read >= total_need: + break + read_left = total_need - total_read + read_this_time = BULK_SIZE if read_left > BULK_SIZE else read_left + + # all need data read.