mirror of https://github.com/tp4a/teleport
temp.
parent
65f2d1ceae
commit
2d0ce5da20
|
@ -609,7 +609,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)
|
||||||
{
|
{
|
||||||
char szCmd[1024] = {0};
|
char szCmd[1024] = {0};
|
||||||
ex_strformat(szCmd, 1023, "ssh %s@%s -p %d", sid.c_str(), teleport_ip.c_str(), teleport_port);
|
ex_strformat(szCmd, 1023, "ssh %s@%s -p %d", sid.c_str(), teleport_ip.c_str(), teleport_port);
|
||||||
|
|
|
@ -85,7 +85,6 @@ bool tpp_session_begin(const TPP_CONNECT_INFO* info, int* db_id)
|
||||||
sinfo.conn_port = info->conn_port;
|
sinfo.conn_port = info->conn_port;
|
||||||
sinfo.protocol_type = info->protocol_type;
|
sinfo.protocol_type = info->protocol_type;
|
||||||
sinfo.protocol_sub_type = info->protocol_sub_type;
|
sinfo.protocol_sub_type = info->protocol_sub_type;
|
||||||
//sinfo.protocol_flag = info->protocol_flag;
|
|
||||||
sinfo.auth_type = info->auth_type;
|
sinfo.auth_type = info->auth_type;
|
||||||
|
|
||||||
return ts_web_rpc_session_begin(sinfo, *db_id);
|
return ts_web_rpc_session_begin(sinfo, *db_id);
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
|
|
||||||
typedef struct TS_CONNECT_INFO
|
typedef struct TS_CONNECT_INFO
|
||||||
{
|
{
|
||||||
|
// TODO:
|
||||||
|
//TPP_CONNECT_INFO conn;
|
||||||
|
|
||||||
ex_astr sid;
|
ex_astr sid;
|
||||||
|
|
||||||
// 与此连接信息相关的三个要素的ID
|
// 与此连接信息相关的三个要素的ID
|
||||||
|
@ -36,7 +39,7 @@ typedef struct TS_CONNECT_INFO
|
||||||
ex_u64 ticket_start;// 此连接信息的创建时间(用于超时未使用就销毁的功能)
|
ex_u64 ticket_start;// 此连接信息的创建时间(用于超时未使用就销毁的功能)
|
||||||
}TS_CONNECT_INFO;
|
}TS_CONNECT_INFO;
|
||||||
|
|
||||||
typedef std::map<ex_astr, TS_CONNECT_INFO*> ts_connections;
|
typedef std::map<ex_astr, TS_CONNECT_INFO*> ts_connections; // sid -> TS_CONNECT_INFO
|
||||||
|
|
||||||
class TsSessionManager : public ExThreadBase
|
class TsSessionManager : public ExThreadBase
|
||||||
{
|
{
|
||||||
|
@ -44,8 +47,21 @@ public:
|
||||||
TsSessionManager();
|
TsSessionManager();
|
||||||
~TsSessionManager();
|
~TsSessionManager();
|
||||||
|
|
||||||
|
// generate a sid for connection info.
|
||||||
bool request_session(ex_astr& sid, TS_CONNECT_INFO* info);
|
bool request_session(ex_astr& sid, TS_CONNECT_INFO* info);
|
||||||
|
|
||||||
|
// +ref for connection-info.
|
||||||
|
bool session_connect(const ex_astr& sid, TPP_CONNECT_INFO** info);
|
||||||
|
|
||||||
|
// free connection-info created by session_connect().
|
||||||
|
bool free_connect_info(TPP_CONNECT_INFO* info);
|
||||||
|
|
||||||
|
// -ref for connecton-info, and release it when ref is 0.
|
||||||
|
bool session_end(const ex_astr& sid);
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
void timer();
|
||||||
|
|
||||||
// 根据sid得到session信息
|
// 根据sid得到session信息
|
||||||
bool get_connect_info(const ex_astr& sid, TS_CONNECT_INFO& info);
|
bool get_connect_info(const ex_astr& sid, TS_CONNECT_INFO& info);
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ SshProxy::~SshProxy()
|
||||||
m_sftp_sessions.clear();
|
m_sftp_sessions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SshProxy::init(void)
|
bool SshProxy::init()
|
||||||
{
|
{
|
||||||
m_host_ip = g_ssh_env.bind_ip;
|
m_host_ip = g_ssh_env.bind_ip;
|
||||||
m_host_port = g_ssh_env.bind_port;
|
m_host_port = g_ssh_env.bind_port;
|
||||||
|
@ -69,9 +69,8 @@ bool SshProxy::init(void)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SshProxy::timer(void) {
|
void SshProxy::timer() {
|
||||||
// be called per one second.
|
// be called per one second.
|
||||||
// EXLOGV("[ssh] on-timer.\n");
|
|
||||||
m_timer_counter++;
|
m_timer_counter++;
|
||||||
if(m_timer_counter < 5)
|
if(m_timer_counter < 5)
|
||||||
return;
|
return;
|
||||||
|
@ -86,14 +85,14 @@ void SshProxy::timer(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SshProxy::_thread_loop(void)
|
void SshProxy::_thread_loop()
|
||||||
{
|
{
|
||||||
EXLOGV("[ssh] TeleportServer-SSH ready on %s:%d\n", m_host_ip.c_str(), m_host_port);
|
EXLOGV("[ssh] TeleportServer-SSH ready on %s:%d\n", m_host_ip.c_str(), m_host_port);
|
||||||
_run();
|
_run();
|
||||||
EXLOGV("[ssh] main-loop end.\n");
|
EXLOGV("[ssh] main-loop end.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SshProxy::_set_stop_flag(void)
|
void SshProxy::_set_stop_flag()
|
||||||
{
|
{
|
||||||
m_stop_flag = true;
|
m_stop_flag = true;
|
||||||
|
|
||||||
|
@ -108,8 +107,8 @@ void SshProxy::_set_stop_flag(void)
|
||||||
ssh_options_set(_session, SSH_OPTIONS_HOST, host_ip.c_str());
|
ssh_options_set(_session, SSH_OPTIONS_HOST, host_ip.c_str());
|
||||||
ssh_options_set(_session, SSH_OPTIONS_PORT, &m_host_port);
|
ssh_options_set(_session, SSH_OPTIONS_PORT, &m_host_port);
|
||||||
|
|
||||||
int _timeout_us = 100000;
|
int _timeout_us = 10;
|
||||||
ssh_options_set(_session, SSH_OPTIONS_TIMEOUT_USEC, &_timeout_us);
|
ssh_options_set(_session, SSH_OPTIONS_TIMEOUT, &_timeout_us);
|
||||||
ssh_connect(_session);
|
ssh_connect(_session);
|
||||||
ssh_free(_session);
|
ssh_free(_session);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +116,7 @@ void SshProxy::_set_stop_flag(void)
|
||||||
m_thread_mgr.stop_all();
|
m_thread_mgr.stop_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SshProxy::_run(void)
|
void SshProxy::_run()
|
||||||
{
|
{
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
@ -172,7 +171,7 @@ void SshProxy::_run(void)
|
||||||
m_thread_mgr.stop_all();
|
m_thread_mgr.stop_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SshProxy::_dump_sftp_sessions(void)
|
void SshProxy::_dump_sftp_sessions()
|
||||||
{
|
{
|
||||||
ts_sftp_sessions::iterator it = m_sftp_sessions.begin();
|
ts_sftp_sessions::iterator it = m_sftp_sessions.begin();
|
||||||
for (; it != m_sftp_sessions.end(); ++it)
|
for (; it != m_sftp_sessions.end(); ++it)
|
||||||
|
|
|
@ -25,8 +25,8 @@ public:
|
||||||
SshProxy();
|
SshProxy();
|
||||||
~SshProxy();
|
~SshProxy();
|
||||||
|
|
||||||
bool init(void);
|
bool init();
|
||||||
void timer(void);
|
void timer();
|
||||||
|
|
||||||
void add_sftp_session_info(
|
void add_sftp_session_info(
|
||||||
const ex_astr& sid,
|
const ex_astr& sid,
|
||||||
|
@ -42,13 +42,13 @@ public:
|
||||||
void session_finished(SshSession* sess);
|
void session_finished(SshSession* sess);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _thread_loop(void);
|
void _thread_loop();
|
||||||
void _set_stop_flag(void);
|
void _set_stop_flag();
|
||||||
|
|
||||||
void _run(void);
|
void _run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _dump_sftp_sessions(void);
|
void _dump_sftp_sessions();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ssh_bind m_bind;
|
ssh_bind m_bind;
|
||||||
|
|
Loading…
Reference in New Issue