整理代码。

pull/105/head
Apex Liu 2017-08-22 17:31:35 +08:00
parent eef2ce4460
commit be59d1a612
9 changed files with 151 additions and 347 deletions

View File

@ -20,12 +20,12 @@ bool TppEnvBase::init(TPP_INIT_ARGS* args)
etc_path = args->etc_path;
replay_path = args->replay_path;
get_session = args->func_get_connect_info;
free_session = args->func_free_connect_info;
get_connect_info = args->func_get_connect_info;
free_connect_info = args->func_free_connect_info;
session_begin = args->func_session_begin;
session_end = args->func_session_end;
if (NULL == get_session || NULL == free_session || NULL == session_begin || NULL == session_end)
if (NULL == get_connect_info || NULL == free_connect_info || NULL == session_begin || NULL == session_end)
{
EXLOGE("invalid init args(2).\n");
return false;

View File

@ -16,8 +16,8 @@ public:
ex_wstr etc_path; // 配置文件、SSH服务器的私钥文件的存放路径
ex_wstr replay_path;
TPP_GET_CONNNECT_INFO_FUNC get_session;
TPP_FREE_CONNECT_INFO_FUNC free_session;
TPP_GET_CONNNECT_INFO_FUNC get_connect_info;
TPP_FREE_CONNECT_INFO_FUNC free_connect_info;
TPP_SESSION_BEGIN_FUNC session_begin;
TPP_SESSION_END_FUNC session_end;

View File

@ -32,15 +32,14 @@ typedef struct TPP_CONNECT_INFO
char* account_name; // 远程主机的账号
char* account_secret; // 远程主机账号的密码(或者私钥)
char* account_param;
//char* account_param;
char* username_prompt; // for telnet
char* password_prompt; // for telnet
int protocol_type;
int protocol_sub_type;
int auth_type;
int sys_type;
// int ref_count; // 这个连接信息的引用计数如果创建的连接信息从来未被使用则超过60秒后自动销毁
// ex_u64 ticket_start; // 此连接信息的创建时间(用于超时未使用就销毁的功能)
int connect_flag;
}TPP_CONNECT_INFO;
typedef TPP_CONNECT_INFO* (*TPP_GET_CONNNECT_INFO_FUNC)(const char* sid);

View File

@ -59,7 +59,7 @@ void TsHttpRpc::_thread_loop(void)
{
EXLOGV("[core] TeleportServer-RPC ready on %s:%d\n", m_host_ip.c_str(), m_host_port);
while(!m_stop_flag)
while (!m_stop_flag)
{
mg_mgr_poll(&m_mg_mgr, 500);
}
@ -80,10 +80,10 @@ bool TsHttpRpc::init(void)
m_host_port = g_env.rpc_bind_port;
char addr[128] = { 0 };
// if (0 == strcmp(m_host_ip.c_str(), "127.0.0.1") || 0 == strcmp(m_host_ip.c_str(), "localhost"))
// ex_strformat(addr, 128, ":%d", m_host_port);
// else
// ex_strformat(addr, 128, "%s:%d", m_host_ip.c_str(), m_host_port);
// if (0 == strcmp(m_host_ip.c_str(), "127.0.0.1") || 0 == strcmp(m_host_ip.c_str(), "localhost"))
// ex_strformat(addr, 128, ":%d", m_host_port);
// else
// ex_strformat(addr, 128, "%s:%d", m_host_ip.c_str(), m_host_port);
if (0 == strcmp(m_host_ip.c_str(), "0.0.0.0"))
ex_strformat(addr, 128, ":%d", m_host_port);
else
@ -153,11 +153,11 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat
EXLOGE("[core] rpc got invalid request: not `rpc` uri.\n");
_this->_create_json_ret(ret_buf, TPE_PARAM, "not a `rpc` request.");
}
mg_printf(nc, "HTTP/1.0 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: %d\r\nContent-Type: application/json\r\n\r\n%s", (int)ret_buf.size() - 1, &ret_buf[0]);
nc->flags |= MG_F_SEND_AND_CLOSE;
}
break;
break;
default:
break;
}
@ -335,21 +335,6 @@ void TsHttpRpc::_rpc_func_request_session(const Json::Value& json_param, ex_astr
int conn_id = 0;
ex_rv rv = TPE_OK;
ex_astr host_ip;
int host_port = 0;
int sys_type = 0;
ex_astr user_name;
ex_astr user_auth;
ex_astr user_param;
ex_astr account_name;
bool account_lock = true;
int auth_mode = 0;
int protocol = 0;
int is_enc = 1;
// 如果authid为正整数这是一个长期保留的认证ID如果是负整数这是一个临时的认证ID用于连接测试如果为0则报错
if (json_param["conn_id"].isNull())
{
_create_json_ret(buf, TPE_PARAM);
@ -368,63 +353,20 @@ void TsHttpRpc::_rpc_func_request_session(const Json::Value& json_param, ex_astr
return;
}
Json::Value jret;
if ((rv = ts_web_rpc_get_conn_info(conn_id, jret)) != TPE_OK)
TS_CONNECT_INFO* info = new TS_CONNECT_INFO;
if ((rv = ts_web_rpc_get_conn_info(conn_id, *info)) != TPE_OK)
{
_create_json_ret(buf, rv);
return;
}
Json::Value& _jret = jret["data"];
host_ip = _jret["host_ip"].asString();
host_port = _jret["host_port"].asInt();
//host_lock = 0;
sys_type = 1;// _jret["sys_type"].asInt();
protocol = _jret["protocol_type"].asInt();
is_enc = _jret["_enc"].asInt() == 0 ? false : true;
auth_mode = _jret["auth_type"].asInt();
//account_lock = _jret["account_lock"].asInt() == 0 ? true : false;
user_name = _jret["user_name"].asString();
user_auth = _jret["secret"].asString();
user_param = "";// _jret["user_param"].asString();
account_name = _jret["account_name"].asString();
// 进一步判断参数是否合法
if (host_ip.length() == 0 || host_port >= 65535 || account_name.length() == 0
|| !(auth_mode == TP_AUTH_TYPE_NONE || auth_mode == TP_AUTH_TYPE_PASSWORD || auth_mode == TP_AUTH_TYPE_PRIVATE_KEY)
|| !(protocol == TP_PROTOCOL_TYPE_RDP || protocol == TP_PROTOCOL_TYPE_SSH || protocol == TP_PROTOCOL_TYPE_TELNET)
//|| !(is_enc == 0 || is_enc == 1)
)
{
_create_json_ret(buf, TPE_PARAM);
return;
}
// TODO: 解密操作应该延迟到使用密码/密钥时才进行,尽量减少明文出现的时间。
if(is_enc)
{
if (user_auth.length() > 0)
{
ex_astr _auth;
if (!ts_db_field_decrypt(user_auth, _auth))
{
_create_json_ret(buf, TPE_FAILED);
return;
}
user_auth = _auth;
}
}
info->ref_count = 0;
info->ticket_start = ex_get_tick_count();
// 生成一个session-id内部会避免重复
ex_astr sid;
if((rv = g_session_mgr.request_session(sid, account_name, conn_id,
host_ip, host_port, sys_type, protocol,
user_name, user_auth, user_param, auth_mode)) != TPE_OK)
{
_create_json_ret(buf, rv);
ex_astr sid;
if (!g_session_mgr.request_session(sid, info)) {
_create_json_ret(buf, TPE_FAILED);
return;
}
@ -436,173 +378,6 @@ void TsHttpRpc::_rpc_func_request_session(const Json::Value& json_param, ex_astr
_create_json_ret(buf, TPE_OK, jr_data);
}
// void TsHttpRpc::_rpc_func_request_session(const ex_astr& func_args, ex_astr& buf)
// {
// // 申请一个会话ID
// // 入参: 两种模式
// // MODE A: 已知目标服务器信息及认证信息
// // 示例: {"ip":"192.168.5.11","port":22,"uname":"root","uauth":"abcdefg","authmode":1,"protocol":2,"enc":0}
// // ip: 目标服务器IP地址
// // port: 目标服务器端口
// // uname: 目标服务器认证所用的用户名
// // uauth: 目标服务器认证所用的密码或私钥
// // authmode: 1=password, 2=private-key
// // protocol: 1=rdp, 2=ssh
// // enc: 1=uauth中的内容是加密的0=uauth中的内容是明文仅用于开发测试阶段
// // MODE B: 认证ID需要根据这个ID到数据库中取得目标服务器信息及认证信息
// // 示例: {"authid":123456}
// // 返回:
// // SSH返回 {"code":0, "data":{"sid":"0123abcde"}}
// // RDP返回 {"code":0, "data":{"sid":"0123abcde0A"}}
// // 错误返回: {"code":1234}
//
// Json::Reader jreader;
// Json::Value jsRoot;
//
// if (!jreader.parse(func_args.c_str(), jsRoot))
// {
// _create_json_ret(buf, TSR_INVALID_JSON_FORMAT);
// return;
// }
// if (jsRoot.isArray())
// {
// _create_json_ret(buf, TSR_INVALID_JSON_PARAM);
// return;
// }
//
// ex_astr host_ip;
// int host_port = 0;
// int sys_type = 0;
// ex_astr user_name;
// ex_astr user_auth;
// ex_astr user_param;
//
// ex_astr account_name;
// int auth_mode = 0;
// int protocol = 0;
// int is_enc = 1;
// int auth_id = 0;
// // 入参模式
// if (!jsRoot["auth_id"].isNull())
// {
// // 使用认证ID的方式申请SID
// if (!jsRoot["auth_id"].isNumeric())
// {
// _create_json_ret(buf, TSR_INVALID_JSON_PARAM);
// return;
// }
// auth_id = jsRoot["auth_id"].asUInt();
// TS_DB_AUTH_INFO ts_auth_info;
// if (!g_db.get_auth_info(auth_id, ts_auth_info))
// {
// _create_json_ret(buf, TSR_GETAUTH_INFO_ERROR);
// return;
// }
// if (ts_auth_info.host_lock !=0 )
// {
// _create_json_ret(buf, TSR_HOST_LOCK_ERROR);
// return;
// }
// if (ts_auth_info.account_lock != 0)
// {
// _create_json_ret(buf, TSR_ACCOUNT_LOCK_ERROR);
// return;
// }
// host_ip = ts_auth_info.host_ip;
// host_port = ts_auth_info.host_port;
// sys_type = ts_auth_info.sys_type;
// user_name = ts_auth_info.user_name;
// user_auth = ts_auth_info.user_auth;
// user_param = ts_auth_info.user_param;
// auth_mode = ts_auth_info.auth_mode;
// protocol = ts_auth_info.protocol;
// is_enc = ts_auth_info.is_encrypt;
// account_name = ts_auth_info.account_name;
// }
// else
// {
// // 判断参数是否正确
// if (jsRoot["ip"].isNull() || !jsRoot["ip"].isString()
// || jsRoot["port"].isNull() || !jsRoot["port"].isNumeric()
// || jsRoot["systype"].isNull() || !jsRoot["systype"].isNumeric()
// || jsRoot["account"].isNull() || !jsRoot["account"].isString()
// || jsRoot["uname"].isNull() || !jsRoot["uname"].isString()
// || jsRoot["uauth"].isNull() || !jsRoot["uauth"].isString()
// || jsRoot["authmode"].isNull() || !jsRoot["authmode"].isNumeric()
// || jsRoot["protocol"].isNull() || !jsRoot["protocol"].isNumeric()
// || jsRoot["enc"].isNull() || !jsRoot["enc"].isNumeric()
// )
// {
// _create_json_ret(buf, TSR_INVALID_JSON_PARAM);
// return;
// }
//
// host_ip = jsRoot["ip"].asCString();
// host_port = jsRoot["port"].asUInt();
// sys_type = jsRoot["systype"].asUInt();
// account_name = jsRoot["account"].asCString();
// user_name = jsRoot["uname"].asCString();
// user_auth = jsRoot["uauth"].asCString();
// if (jsRoot["uparam"].isNull())
// {
// user_param = "";
// }
// else
// {
// user_param = jsRoot["uparam"].asCString();
// }
//
// auth_mode = jsRoot["authmode"].asUInt();
// protocol = jsRoot["protocol"].asUInt();
// is_enc = jsRoot["enc"].asUInt();
// }
//
// // 进一步判断参数是否合法
// if (host_ip.length() == 0 || host_port >= 65535 || account_name.length() == 0
// || !(auth_mode == TS_AUTH_MODE_NONE || auth_mode == TS_AUTH_MODE_PASSWORD || auth_mode == TS_AUTH_MODE_PRIVATE_KEY)
// || !(protocol == TS_PROXY_PROTOCOL_RDP || protocol == TS_PROXY_PROTOCOL_SSH || protocol == TS_PROXY_PROTOCOL_TELNET)
// || !(is_enc == 0 || is_enc == 1)
// )
// {
// _create_json_ret(buf, TSR_INVALID_JSON_PARAM);
// return;
// }
//
// if(is_enc)
// {
// if (user_auth.length() > 0)
// {
// ex_astr _auth;
// if (!ts_db_field_decrypt(user_auth, _auth))
// {
// _create_json_ret(buf, TSR_FAILED);
// return;
// }
//
// user_auth = _auth;
// }
// }
//
// // 生成一个session-id内部会避免重复
// ex_astr sid;
// ex_rv rv = g_session_mgr.request_session(sid, account_name, auth_id,
// host_ip, host_port, sys_type, protocol,
// user_name, user_auth, user_param, auth_mode);
// if (rv != TSR_OK)
// {
// _create_json_ret(buf, rv);
// return;
// }
//
// EXLOGD("[core] rpc new session-id: %s\n", sid.c_str());
//
// Json::Value jr_root;
// jr_root["code"] = TSR_OK;
// jr_root["data"]["sid"] = sid;
//
// _create_json_ret(buf, jr_root);
// }
void TsHttpRpc::_rpc_func_enc(const Json::Value& json_param, ex_astr& buf)
{
// https://github.com/eomsoft/teleport/wiki/TELEPORT-CORE-JSON-RPC#enc

View File

@ -32,8 +32,10 @@ TPP_CONNECT_INFO* tpp_get_connect_info(const char* sid)
ex_strcpy(info->account_name, sinfo.account_name.length() + 1, sinfo.account_name.c_str());
info->account_secret = (char*)calloc(1, sinfo.account_secret.length() + 1);
ex_strcpy(info->account_secret, sinfo.account_secret.length() + 1, sinfo.account_secret.c_str());
info->account_param = (char*)calloc(1, sinfo.account_param.length() + 1);
ex_strcpy(info->account_param, sinfo.account_param.length() + 1, sinfo.account_param.c_str());
info->username_prompt = (char*)calloc(1, sinfo.username_prompt.length() + 1);
ex_strcpy(info->username_prompt, sinfo.username_prompt.length() + 1, sinfo.username_prompt.c_str());
info->password_prompt = (char*)calloc(1, sinfo.password_prompt.length() + 1);
ex_strcpy(info->password_prompt, sinfo.password_prompt.length() + 1, sinfo.password_prompt.c_str());
info->user_id = sinfo.user_id;
info->host_id = sinfo.host_id;
@ -42,7 +44,7 @@ TPP_CONNECT_INFO* tpp_get_connect_info(const char* sid)
info->protocol_type = sinfo.protocol_type;
info->protocol_sub_type = sinfo.protocol_sub_type;
info->auth_type= sinfo.auth_type;
info->sys_type = sinfo.sys_type;
info->connect_flag = sinfo.connect_flag;
return info;
}
@ -59,7 +61,8 @@ void tpp_free_connect_info(TPP_CONNECT_INFO* info)
free(info->client_ip);
free(info->account_name);
free(info->account_secret);
free(info->account_param);
free(info->username_prompt);
free(info->password_prompt);
free(info);
}
@ -80,7 +83,7 @@ bool tpp_session_begin(const TPP_CONNECT_INFO* info, int* db_id)
sinfo.protocol_type = info->protocol_type;
sinfo.protocol_sub_type = info->protocol_sub_type;
sinfo.auth_type = info->auth_type;
sinfo.sys_type = info->sys_type;
//sinfo.connect_flag = info->connect_flag;
return ts_web_rpc_session_begin(sinfo, *db_id);
}

View File

@ -65,46 +65,6 @@ void TsSessionManager::_check_connect_info(void)
}
}
ex_rv TsSessionManager::request_session(
ex_astr& sid, // 返回的session-id
ex_astr account_name,
int auth_id,
const ex_astr& host_ip, // 要连接的主机IP
int host_port, // 要连接的主机端口
int sys_type,
int protocol, // 要使用的协议1=rdp, 2=ssh
const ex_astr& user_name, // 认证信息中的用户名
const ex_astr& user_auth, // 认证信息,密码或私钥
const ex_astr& user_param, //
int auth_mode // 认证方式1=password2=private-key
)
{
TS_SESSION_INFO* info = new TS_SESSION_INFO;
info->account_name = account_name;
info->auth_id = auth_id;
info->host_ip = host_ip;
info->host_port = host_port;
info->sys_type = sys_type;
info->protocol = protocol;
info->user_name = user_name;
info->user_auth = user_auth;
info->auth_mode = auth_mode;
info->user_param = user_param;
if (protocol == TP_PROTOCOL_TYPE_RDP)
info->ref_count = 2;
else
info->ref_count = 1;
info->ticket_start = ex_get_tick_count();
EXLOGD("[core] request session: user-name: [%s], protocol: [%d], auth-mode: [%d]\n", info->user_name.c_str(), info->protocol, info->auth_mode);
if (_add_connect_info(sid, info))
return EXRV_OK;
delete info;
return EXRV_FAILED;
}
bool TsSessionManager::get_connect_info(const ex_astr& sid, TS_CONNECT_INFO& info)
{
ExThreadSmartLock locker(m_lock);
@ -114,35 +74,34 @@ bool TsSessionManager::get_connect_info(const ex_astr& sid, TS_CONNECT_INFO& inf
return false;
info.sid = it->second->sid;
info.account_name = it->second->account_name;
info.auth_id = it->second->auth_id;
info.host_ip = it->second->host_ip;
info.host_port = it->second->host_port;
info.protocol = it->second->protocol;
info.user_id = it->second->user_id;
info.host_id = it->second->host_id;
info.account_id = it->second->account_id;
info.user_name = it->second->user_name;
info.user_auth = it->second->user_auth;
info.user_param = it->second->user_param;
info.auth_mode = it->second->auth_mode;
info.sys_type = it->second->sys_type;
info.ref_count = it->second->ref_count;
info.ticket_start = it->second->ticket_start;
info.real_remote_host_ip = it->second->real_remote_host_ip;
info.remote_host_ip = it->second->remote_host_ip;
info.remote_host_port = it->second->remote_host_port;
info.client_ip = it->second->client_ip;
info.account_name = it->second->account_name;
info.account_secret = it->second->account_secret;
info.username_prompt = it->second->username_prompt;
info.password_prompt = it->second->password_prompt;
info.connect_flag = it->second->connect_flag;
info.protocol_type = it->second->protocol_type;
info.protocol_sub_type = it->second->protocol_sub_type;
info.auth_type = it->second->auth_type;
it->second->ref_count++;
// if (it->second->ref_count <= 0)
// {
// delete it->second;
// m_sessions.erase(it);
// }
return true;
}
bool TsSessionManager::_add_connect_info(ex_astr& sid, TS_CONNECT_INFO* info)
bool TsSessionManager::request_session(ex_astr& sid, TS_CONNECT_INFO* info)
{
ExThreadSmartLock locker(m_lock);
EXLOGD("[core] request session: account: [%s], protocol: [%d], auth-mode: [%d]\n", info->account_name.c_str(), info->protocol_type, info->auth_type);
ex_astr _sid;
int retried = 0;
ts_connections::iterator it;

View File

@ -23,14 +23,16 @@ typedef struct TS_CONNECT_INFO
ex_astr client_ip;
ex_astr account_name; // 远程主机的账号
ex_astr account_secret;// 远程主机账号的密码(或者私钥)
ex_astr account_param;
ex_astr account_secret; // 远程主机账号的密码(或者私钥)
ex_astr username_prompt;// for telnet
ex_astr password_prompt;// for telnet
int protocol_type;
int protocol_sub_type;
int auth_type;
int sys_type;
int connect_flag;
//int sys_type;
int ref_count;// 这个连接信息的引用计数如果创建的连接信息从来未被使用则超过30秒后自动销毁
ex_u64 ticket_start;// 此连接信息的创建时间(用于超时未使用就销毁的功能)
}TS_CONNECT_INFO;
@ -43,20 +45,7 @@ public:
TsSessionManager();
~TsSessionManager();
// 申请一个session-id。
ex_rv request_session(
ex_astr& sid, // 返回的session-id
ex_astr account_name,
int auth_id,
const ex_astr& host_ip, // 要连接的主机IP
int host_port, // 要连接的主机端口
int sys_type, // 主机操作系统类型
int protocol, // 要使用的协议1=rdp, 2=ssh
const ex_astr& user_name, // 认证信息中的用户名
const ex_astr& user_auth, // 认证信息,密码或私钥
const ex_astr& user_param, //
int auth_mode // 认证方式1=password2=private-key
);
bool request_session(ex_astr& sid, TS_CONNECT_INFO* info);
// 根据sid得到session信息
bool get_connect_info(const ex_astr& sid, TS_CONNECT_INFO& info);
@ -69,7 +58,6 @@ protected:
private:
void _gen_session_id(ex_astr& sid, const TS_CONNECT_INFO* info, int len);
bool _add_connect_info(ex_astr& sid, TS_CONNECT_INFO* info);
void _check_connect_info(void);
private:

View File

@ -1,5 +1,6 @@
#include "ts_web_rpc.h"
#include "ts_env.h"
#include "ts_crypto.h"
#include "ts_http_client.h"
#include "../common/ts_const.h"
@ -28,7 +29,7 @@ bool ts_web_rpc_register_core()
return ts_http_get(url, body);
}
int ts_web_rpc_get_conn_info(int conn_id, Json::Value& jret)
int ts_web_rpc_get_conn_info(int conn_id, TS_CONNECT_INFO& info)
{
Json::FastWriter json_writer;
Json::Value jreq;
@ -55,6 +56,7 @@ int ts_web_rpc_get_conn_info(int conn_id, Json::Value& jret)
}
Json::Reader jreader;
Json::Value jret;
if (!jreader.parse(body.c_str(), jret))
return TPE_PARAM;
@ -66,28 +68,106 @@ int ts_web_rpc_get_conn_info(int conn_id, Json::Value& jret)
Json::Value& _jret = jret["data"];
if (
!_jret["host_ip"].isString()
|| !_jret["host_port"].isInt()
// || !_jret["sys_type"].isInt()
!_jret["user_id"].isInt()
|| !_jret["host_id"].isInt()
|| !_jret["account_id"].isInt()
|| !_jret["remote_host_port"].isInt()
|| !_jret["protocol_type"].isInt()
|| !_jret["protocol_sub_type"].isInt()
|| !_jret["auth_type"].isInt()
|| !_jret["account_name"].isString()
|| !_jret["secret"].isString()
// || !_jret["user_param"].isString()
// || !_jret["conn_param"].isInt()
|| !_jret["connect_flag"].isInt()
|| !_jret["_enc"].isInt()
|| !_jret["user_name"].isString()
|| !_jret["real_remote_host_ip"].isString()
|| !_jret["remote_host_ip"].isString()
|| !_jret["client_ip"].isString()
|| !_jret["_enc"].isInt()
|| !_jret["_test"].isInt()
|| !_jret["account_name"].isString()
|| !_jret["account_secret"].isString()
|| !_jret["username_prompt"].isString()
|| !_jret["password_prompt"].isString()
)
{
EXLOGE("got connection info from web-server, but not all info valid.\n");
return TPE_PARAM;
}
int user_id;
int host_id;
int account_id;
ex_astr user_name;// 申请本次连接的用户名
ex_astr real_remote_host_ip;// 真正的远程主机IP如果是直接连接模式则与remote_host_ip相同
ex_astr remote_host_ip;// 要连接的远程主机的IP如果是端口映射模式则为路由主机的IP
int remote_host_port;// 要连接的远程主机的端口(如果是端口映射模式,则为路由主机的端口)
ex_astr client_ip;
ex_astr account_name; // 远程主机的账号
ex_astr account_secret;// 远程主机账号的密码(或者私钥)
ex_astr username_prompt;
ex_astr password_prompt;
int protocol_type;
int protocol_sub_type;
int auth_type;
int connect_flag;
bool _enc;
user_id = _jret["user_id"].asInt();
host_id = _jret["host_id"].asInt();
account_id = _jret["account_id"].asInt();
user_name = _jret["user_name"].asString();
real_remote_host_ip = _jret["real_remote_host_ip"].asString();
remote_host_ip = _jret["remote_host_ip"].asString();
remote_host_port = _jret["remote_host_port"].asInt();
client_ip = _jret["client_ip"].asString();
account_name = _jret["account_name"].asString();
account_secret = _jret["account_secret"].asString();
username_prompt = _jret["username_prompt"].asString();
password_prompt = _jret["password_prompt"].asString();
protocol_type = _jret["protocol_type"].asInt();
protocol_sub_type = _jret["protocol_sub_type"].asInt();
connect_flag = _jret["connect_flag"].asInt();
auth_type = _jret["auth_type"].asInt();
_enc = _jret["_enc"].asBool();
// 进一步判断参数是否合法
// 注意account_id可以为-1表示这是一次测试连接。
if (user_id <= 0 || host_id <= 0
|| user_name.length() == 0
|| real_remote_host_ip.length() == 0 || remote_host_ip.length() == 0 || client_ip.length() == 0
|| remote_host_port <= 0 || remote_host_port >= 65535
|| account_name.length() == 0 || account_secret.length() == 0
|| connect_flag == 0
|| !(protocol_type == TP_PROTOCOL_TYPE_RDP || protocol_type == TP_PROTOCOL_TYPE_SSH || protocol_type == TP_PROTOCOL_TYPE_TELNET)
|| !(auth_type == TP_AUTH_TYPE_NONE || auth_type == TP_AUTH_TYPE_PASSWORD || auth_type == TP_AUTH_TYPE_PRIVATE_KEY)
)
{
return TPE_PARAM;
}
if (_enc) {
ex_astr _auth;
if (!ts_db_field_decrypt(account_secret, _auth))
return TPE_FAILED;
account_secret = _auth;
}
info.user_id = user_id;
info.host_id = host_id;
info.account_id = account_id;
info.user_name = user_name;
info.real_remote_host_ip = real_remote_host_ip;
info.remote_host_ip = remote_host_ip;
info.remote_host_port = remote_host_port;
info.client_ip = client_ip;
info.account_name = account_name;
info.account_secret = account_secret;
info.username_prompt = username_prompt;
info.password_prompt = password_prompt;
info.protocol_type = protocol_type;
info.protocol_sub_type = protocol_sub_type;
info.auth_type = auth_type;
info.connect_flag = connect_flag;
return TPE_OK;
}
@ -104,7 +184,7 @@ bool ts_web_rpc_session_begin(TS_CONNECT_INFO& info, int& record_id)
jreq["param"]["real_remote_host_ip"] = info.real_remote_host_ip.c_str();
jreq["param"]["remote_host_ip"] = info.remote_host_ip.c_str();
jreq["param"]["client_ip"] = info.client_ip.c_str();
jreq["param"]["sys_type"] = info.sys_type;
//jreq["param"]["sys_type"] = info.sys_type;
jreq["param"]["remote_host_port"] = info.remote_host_port;
jreq["param"]["auth_type"] = info.auth_type;
jreq["param"]["protocol_type"] = info.protocol_type;

View File

@ -9,7 +9,7 @@
bool ts_web_rpc_register_core();
// 根据连接ID获取远程连接信息包括服务器IP、端口用户名、密码或私钥、协议如RDP或SSH等等
int ts_web_rpc_get_conn_info(int conn_id, Json::Value& jret);
int ts_web_rpc_get_conn_info(int conn_id, TS_CONNECT_INFO& info);
// 记录会话的开始
bool ts_web_rpc_session_begin(TS_CONNECT_INFO& info, int& record_id);