| 49 |
|
|
| 50 |
enum _bbs_net_constant_t |
enum _bbs_net_constant_t |
| 51 |
{ |
{ |
|
MAX_PROCESS_BAR_LEN = 30, |
|
| 52 |
MAXSTATION = 26 * 2, |
MAXSTATION = 26 * 2, |
| 53 |
STATION_PER_LINE = 4, |
STATION_PER_LINE = 4, |
| 54 |
USERNAME_MAX_LEN = 20, |
USERNAME_MAX_LEN = 20, |
| 55 |
PASSWORD_MAX_LEN = 20, |
PASSWORD_MAX_LEN = 20, |
| 56 |
SSH_CONNECT_TIMEOUT = 5, // seconds |
REMOTE_CONNECT_TIMEOUT = 10, // seconds |
| 57 |
|
SSH_CONNECT_TIMEOUT = 5, // seconds |
| 58 |
|
PROGRESS_BAR_LEN = 30, |
| 59 |
}; |
}; |
| 60 |
|
|
| 61 |
struct _bbsnet_conf |
struct _bbsnet_conf |
| 79 |
MENU_ITEM *p_menu_item; |
MENU_ITEM *p_menu_item; |
| 80 |
MENU_ITEM_ID menu_item_id; |
MENU_ITEM_ID menu_item_id; |
| 81 |
char line[LINE_BUFFER_LEN], *t1, *t2, *t3, *t4, *t5, *t6, *saveptr; |
char line[LINE_BUFFER_LEN], *t1, *t2, *t3, *t4, *t5, *t6, *saveptr; |
| 82 |
int port; |
long port; |
| 83 |
|
char *endptr; |
| 84 |
|
|
| 85 |
unload_bbsnet_conf(); |
unload_bbsnet_conf(); |
| 86 |
|
|
| 126 |
t6 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
t6 = strtok_r(NULL, MENU_CONF_DELIM, &saveptr); |
| 127 |
|
|
| 128 |
if (t1 == NULL || t2 == NULL || t3 == NULL || t4 == NULL || |
if (t1 == NULL || t2 == NULL || t3 == NULL || t4 == NULL || |
| 129 |
t5 == NULL || t6 == NULL || line[0] == '#' || line[0] == '*') |
t5 == NULL || t6 == NULL || t1[0] == '#') |
| 130 |
{ |
{ |
| 131 |
continue; |
continue; |
| 132 |
} |
} |
| 137 |
bbsnet_conf[menu_item_id].org_name[sizeof(bbsnet_conf[menu_item_id].org_name) - 1] = '\0'; |
bbsnet_conf[menu_item_id].org_name[sizeof(bbsnet_conf[menu_item_id].org_name) - 1] = '\0'; |
| 138 |
strncpy(bbsnet_conf[menu_item_id].host_name, t3, sizeof(bbsnet_conf[menu_item_id].host_name) - 1); |
strncpy(bbsnet_conf[menu_item_id].host_name, t3, sizeof(bbsnet_conf[menu_item_id].host_name) - 1); |
| 139 |
bbsnet_conf[menu_item_id].host_name[sizeof(bbsnet_conf[menu_item_id].host_name) - 1] = '\0'; |
bbsnet_conf[menu_item_id].host_name[sizeof(bbsnet_conf[menu_item_id].host_name) - 1] = '\0'; |
| 140 |
port = atoi(t4); |
port = strtol(t4, &endptr, 10); |
| 141 |
if (port <= 0 || port > 65535) |
if (*endptr != '\0' || port <= 0 || port > 65535) |
| 142 |
{ |
{ |
| 143 |
log_error("Invalid port value %d of menu item %d\n", port, menu_item_id); |
log_error("Invalid port value %d of menu item %d\n", port, menu_item_id); |
| 144 |
fclose(fp); |
fclose(fp); |
| 167 |
p_menu_item->priv = 0; |
p_menu_item->priv = 0; |
| 168 |
p_menu_item->level = 0; |
p_menu_item->level = 0; |
| 169 |
p_menu_item->name[0] = |
p_menu_item->name[0] = |
| 170 |
(char)(menu_item_id < MAXSTATION / 2 ? 'A' + menu_item_id : 'a' + menu_item_id); |
(char)(menu_item_id < MAXSTATION / 2 ? 'A' + menu_item_id : 'a' + menu_item_id - MAXSTATION / 2); |
| 171 |
p_menu_item->name[1] = '\0'; |
p_menu_item->name[1] = '\0'; |
| 172 |
snprintf(p_menu_item->text, sizeof(p_menu_item->text), "\033[1;36m%c.\033[m %s", |
snprintf(p_menu_item->text, sizeof(p_menu_item->text), "\033[1;36m%c.\033[m %s", |
| 173 |
p_menu_item->name[0], bbsnet_conf[menu_item_id].site_name); |
p_menu_item->name[0], bbsnet_conf[menu_item_id].site_name); |
| 205 |
} |
} |
| 206 |
} |
} |
| 207 |
|
|
| 208 |
static void process_bar(int n, int len) |
static void progress_bar(int percent, int len) |
| 209 |
{ |
{ |
| 210 |
|
char line[LINE_BUFFER_LEN]; |
| 211 |
char buf[LINE_BUFFER_LEN]; |
char buf[LINE_BUFFER_LEN]; |
| 212 |
char buf2[LINE_BUFFER_LEN]; |
char buf2[LINE_BUFFER_LEN]; |
| 213 |
|
int pos; |
| 214 |
|
|
| 215 |
if (len <= 0) |
if (len <= 0) |
| 216 |
{ |
{ |
| 220 |
{ |
{ |
| 221 |
len = LINE_BUFFER_LEN - 1; |
len = LINE_BUFFER_LEN - 1; |
| 222 |
} |
} |
| 223 |
if (n < 0) |
if (percent < 0) |
| 224 |
{ |
{ |
| 225 |
n = 0; |
percent = 0; |
| 226 |
} |
} |
| 227 |
else if (n > len) |
else if (percent > 100) |
| 228 |
{ |
{ |
| 229 |
n = len; |
percent = 100; |
| 230 |
} |
} |
| 231 |
|
|
| 232 |
|
pos = len * percent / 100; |
| 233 |
|
|
| 234 |
|
line[0] = ' '; |
| 235 |
|
for (int i = 1; i <= len; i++) |
| 236 |
|
{ |
| 237 |
|
line[i] = '-'; |
| 238 |
|
} |
| 239 |
|
line[len + 1] = ' '; |
| 240 |
|
line[len + 2] = '\0'; |
| 241 |
|
|
| 242 |
|
snprintf(buf, sizeof(buf), "%*s%3d%%%*s", |
| 243 |
|
(len - 4) / 2, "", percent, (len - 4 + 1) / 2, ""); |
| 244 |
|
memcpy(buf2, buf, (size_t)pos); |
| 245 |
|
buf2[pos] = '\0'; |
| 246 |
|
|
| 247 |
moveto(4, 1); |
moveto(4, 1); |
| 248 |
prints(" ------------------------------ \r\n"); |
prints("%s\r\n", line); |
| 249 |
snprintf(buf, sizeof(buf), " %3d%% ", n * 100 / len); |
prints("|\033[46m%s\033[44m%s\033[m|\r\n", buf2, buf + pos); |
| 250 |
memcpy(buf2, buf, (size_t)n); |
prints("%s\r\n", line); |
|
buf2[n] = '\0'; |
|
|
prints("|\033[46m%s\033[44m%s\033[m|\r\n", buf2, buf + n); |
|
|
prints(" ------------------------------ \r\n"); |
|
| 251 |
iflush(); |
iflush(); |
| 252 |
} |
} |
| 253 |
|
|
| 254 |
static int bbsnet_connect(int n) |
static int bbsnet_connect(int n) |
| 255 |
{ |
{ |
| 256 |
int sock = -1; |
int sock = -1; |
| 257 |
int ret; |
int ret = 0; |
| 258 |
int loop; |
int loop; |
| 259 |
int error; |
int error; |
| 260 |
int sock_connected = 0; |
int sock_connected = 0; |
| 297 |
char local_addr[INET_ADDRSTRLEN]; |
char local_addr[INET_ADDRSTRLEN]; |
| 298 |
int local_port; |
int local_port; |
| 299 |
socklen_t sock_len; |
socklen_t sock_len; |
| 300 |
time_t t_begin; |
time_t t_begin, t_used; |
| 301 |
time_t t_used = time(NULL); |
struct timespec ts_begin, ts_now; |
| 302 |
struct tm *tm_used; |
int progress, progress_last; |
| 303 |
int ch; |
int ch; |
| 304 |
char remote_user[USERNAME_MAX_LEN + 1]; |
char remote_user[USERNAME_MAX_LEN + 1]; |
| 305 |
char remote_pass[PASSWORD_MAX_LEN + 1]; |
char remote_pass[PASSWORD_MAX_LEN + 1]; |
| 306 |
ssh_session session = NULL; |
ssh_session outbound_session = NULL; |
| 307 |
ssh_channel channel = NULL; |
ssh_channel outbound_channel = NULL; |
| 308 |
int ssh_process_config = 0; |
int ssh_process_config = 0; |
| 309 |
int ssh_log_level = SSH_LOG_NOLOG; |
int ssh_log_level = SSH_LOG_NOLOG; |
| 310 |
|
|
| 366 |
|
|
| 367 |
if ((ret = getaddrinfo(BBS_address, NULL, &hints, &res)) != 0) |
if ((ret = getaddrinfo(BBS_address, NULL, &hints, &res)) != 0) |
| 368 |
{ |
{ |
| 369 |
log_error("getaddrinfo() error (%d)\n", ret); |
log_error("getaddrinfo() error (%d): %s\n", ret, gai_strerror(ret)); |
| 370 |
|
ret = -1; |
| 371 |
goto cleanup; |
goto cleanup; |
| 372 |
} |
} |
| 373 |
|
|
| 374 |
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr), local_addr, sizeof(local_addr)) == NULL) |
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)res->ai_addr)->sin_addr), local_addr, sizeof(local_addr)) == NULL) |
| 375 |
{ |
{ |
| 376 |
log_error("inet_ntop() error (%d)\n", errno); |
log_error("inet_ntop() error (%d)\n", errno); |
| 377 |
|
ret = -1; |
| 378 |
goto cleanup; |
goto cleanup; |
| 379 |
} |
} |
| 380 |
local_port = ntohs(((struct sockaddr_in *)res->ai_addr)->sin_port); |
local_port = ntohs(((struct sockaddr_in *)res->ai_addr)->sin_port); |
| 383 |
if (sock < 0) |
if (sock < 0) |
| 384 |
{ |
{ |
| 385 |
log_error("socket() error (%d)\n", errno); |
log_error("socket() error (%d)\n", errno); |
| 386 |
|
ret = -1; |
| 387 |
goto cleanup; |
goto cleanup; |
| 388 |
} |
} |
| 389 |
|
|
| 390 |
if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) |
if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) |
| 391 |
{ |
{ |
| 392 |
log_error("bind(%s:%u) error (%d)\n", local_addr, local_port, errno); |
log_error("bind(%s:%u) error (%d)\n", local_addr, local_port, errno); |
| 393 |
|
ret = -1; |
| 394 |
goto cleanup; |
goto cleanup; |
| 395 |
} |
} |
| 396 |
|
|
| 405 |
|
|
| 406 |
if ((ret = getaddrinfo(bbsnet_conf[n].host_name, bbsnet_conf[n].port, &hints, &res)) != 0) |
if ((ret = getaddrinfo(bbsnet_conf[n].host_name, bbsnet_conf[n].port, &hints, &res)) != 0) |
| 407 |
{ |
{ |
| 408 |
log_error("getaddrinfo() error (%d)\n", ret); |
log_error("getaddrinfo() error (%d): %s\n", ret, gai_strerror(ret)); |
| 409 |
prints("\033[1;31m查找主机名失败!\033[m\r\n"); |
prints("\033[1;31m查找主机名失败!\033[m\r\n"); |
| 410 |
press_any_key(); |
press_any_key(); |
| 411 |
|
ret = -1; |
| 412 |
goto cleanup; |
goto cleanup; |
| 413 |
} |
} |
| 414 |
|
|
| 415 |
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr), remote_addr, sizeof(remote_addr)) == NULL) |
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)res->ai_addr)->sin_addr), remote_addr, sizeof(remote_addr)) == NULL) |
| 416 |
{ |
{ |
| 417 |
log_error("inet_ntop() error (%d)\n", errno); |
log_error("inet_ntop() error (%d)\n", errno); |
| 418 |
|
ret = -1; |
| 419 |
goto cleanup; |
goto cleanup; |
| 420 |
} |
} |
| 421 |
remote_port = ntohs(((struct sockaddr_in *)res->ai_addr)->sin_port); |
remote_port = ntohs(((struct sockaddr_in *)res->ai_addr)->sin_port); |
| 422 |
|
|
|
prints("\033[1;32m穿梭进度条提示您当前已使用的时间,按\033[1;33mCtrl+C\033[1;32m中断。\033[m\r\n"); |
|
|
process_bar(0, MAX_PROCESS_BAR_LEN); |
|
|
|
|
| 423 |
// Set socket as non-blocking |
// Set socket as non-blocking |
| 424 |
if ((flags_sock = fcntl(sock, F_GETFL, 0)) == -1) |
if ((flags_sock = fcntl(sock, F_GETFL, 0)) == -1) |
| 425 |
{ |
{ |
| 426 |
log_error("fcntl(F_GETFL) error (%d)\n", errno); |
log_error("fcntl(F_GETFL) error (%d)\n", errno); |
| 427 |
|
ret = -1; |
| 428 |
goto cleanup; |
goto cleanup; |
| 429 |
} |
} |
| 430 |
if ((fcntl(sock, F_SETFL, flags_sock | O_NONBLOCK)) == -1) |
if ((fcntl(sock, F_SETFL, flags_sock | O_NONBLOCK)) == -1) |
| 431 |
{ |
{ |
| 432 |
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
| 433 |
|
ret = -1; |
| 434 |
goto cleanup; |
goto cleanup; |
| 435 |
} |
} |
| 436 |
|
|
| 438 |
if ((flags_stdin = fcntl(STDIN_FILENO, F_GETFL, 0)) == -1) |
if ((flags_stdin = fcntl(STDIN_FILENO, F_GETFL, 0)) == -1) |
| 439 |
{ |
{ |
| 440 |
log_error("fcntl(F_GETFL) error (%d)\n", errno); |
log_error("fcntl(F_GETFL) error (%d)\n", errno); |
| 441 |
|
ret = -1; |
| 442 |
goto cleanup; |
goto cleanup; |
| 443 |
} |
} |
| 444 |
if ((flags_stdout = fcntl(STDOUT_FILENO, F_GETFL, 0)) == -1) |
if ((flags_stdout = fcntl(STDOUT_FILENO, F_GETFL, 0)) == -1) |
| 445 |
{ |
{ |
| 446 |
log_error("fcntl(F_GETFL) error (%d)\n", errno); |
log_error("fcntl(F_GETFL) error (%d)\n", errno); |
| 447 |
|
ret = -1; |
| 448 |
goto cleanup; |
goto cleanup; |
| 449 |
} |
} |
| 450 |
if ((fcntl(STDIN_FILENO, F_SETFL, flags_stdin | O_NONBLOCK)) == -1) |
if ((fcntl(STDIN_FILENO, F_SETFL, flags_stdin | O_NONBLOCK)) == -1) |
| 451 |
{ |
{ |
| 452 |
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
| 453 |
|
ret = -1; |
| 454 |
goto cleanup; |
goto cleanup; |
| 455 |
} |
} |
| 456 |
if ((fcntl(STDOUT_FILENO, F_SETFL, flags_stdout | O_NONBLOCK)) == -1) |
if ((fcntl(STDOUT_FILENO, F_SETFL, flags_stdout | O_NONBLOCK)) == -1) |
| 457 |
{ |
{ |
| 458 |
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
| 459 |
|
ret = -1; |
| 460 |
goto cleanup; |
goto cleanup; |
| 461 |
} |
} |
| 462 |
|
|
| 465 |
if (epollfd < 0) |
if (epollfd < 0) |
| 466 |
{ |
{ |
| 467 |
log_error("epoll_create1() error (%d)\n", errno); |
log_error("epoll_create1() error (%d)\n", errno); |
| 468 |
|
ret = -1; |
| 469 |
goto cleanup; |
goto cleanup; |
| 470 |
} |
} |
| 471 |
|
|
| 474 |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev) == -1) |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev) == -1) |
| 475 |
{ |
{ |
| 476 |
log_error("epoll_ctl(socket) error (%d)\n", errno); |
log_error("epoll_ctl(socket) error (%d)\n", errno); |
| 477 |
|
ret = -1; |
| 478 |
goto cleanup; |
goto cleanup; |
| 479 |
} |
} |
| 480 |
|
|
| 483 |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev) == -1) |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDIN_FILENO, &ev) == -1) |
| 484 |
{ |
{ |
| 485 |
log_error("epoll_ctl(STDIN_FILENO) error (%d)\n", errno); |
log_error("epoll_ctl(STDIN_FILENO) error (%d)\n", errno); |
| 486 |
|
ret = -1; |
| 487 |
goto cleanup; |
goto cleanup; |
| 488 |
} |
} |
| 489 |
#endif |
#endif |
| 490 |
|
|
| 491 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 492 |
{ |
{ |
| 493 |
if ((ret = connect(sock, res->ai_addr, res->ai_addrlen)) < 0) |
if ((ret = connect(sock, res->ai_addr, res->ai_addrlen)) == 0) |
| 494 |
|
{ |
| 495 |
|
sock_connected = 1; |
| 496 |
|
break; |
| 497 |
|
} |
| 498 |
|
else if (ret < 0) |
| 499 |
{ |
{ |
| 500 |
if (errno == EAGAIN || errno == EALREADY || errno == EINPROGRESS) |
if (errno == EAGAIN || errno == EALREADY || errno == EINPROGRESS) |
| 501 |
{ |
{ |
| 513 |
log_error("connect(socket) error (%d)\n", errno); |
log_error("connect(socket) error (%d)\n", errno); |
| 514 |
prints("\033[1;31m连接失败!\033[m\r\n"); |
prints("\033[1;31m连接失败!\033[m\r\n"); |
| 515 |
press_any_key(); |
press_any_key(); |
| 516 |
|
ret = -1; |
| 517 |
goto cleanup; |
goto cleanup; |
| 518 |
} |
} |
| 519 |
} |
} |
| 520 |
} |
} |
| 521 |
|
|
| 522 |
for (int j = 0; j < MAX_PROCESS_BAR_LEN && !sock_connected && !SYS_server_exit; j++) |
progress = progress_last = 0; |
| 523 |
|
prints("\033[1;32m连接进行中,按\033[1;33mCtrl+C\033[1;32m中断。\033[m\r\n"); |
| 524 |
|
progress_bar(0, PROGRESS_BAR_LEN); |
| 525 |
|
|
| 526 |
|
if (clock_gettime(CLOCK_REALTIME, &ts_begin) == -1) |
| 527 |
|
{ |
| 528 |
|
log_error("clock_gettime() error (%d)\n", errno); |
| 529 |
|
ret = -1; |
| 530 |
|
goto cleanup; |
| 531 |
|
} |
| 532 |
|
ts_now = ts_begin; |
| 533 |
|
|
| 534 |
|
while ((ts_now.tv_sec - ts_begin.tv_sec) + |
| 535 |
|
(ts_now.tv_nsec - ts_begin.tv_nsec) / 1000 / 1000 / 1000 < |
| 536 |
|
REMOTE_CONNECT_TIMEOUT && |
| 537 |
|
!sock_connected && !SYS_server_exit) |
| 538 |
{ |
{ |
| 539 |
#ifdef HAVE_SYS_EPOLL_H |
#ifdef HAVE_SYS_EPOLL_H |
| 540 |
nfds = epoll_wait(epollfd, events, MAX_EVENTS, 500); // 0.5 second |
nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second |
| 541 |
ret = nfds; |
ret = nfds; |
| 542 |
#else |
#else |
| 543 |
pfds[0].fd = sock; |
pfds[0].fd = sock; |
| 545 |
pfds[1].fd = STDIN_FILENO; |
pfds[1].fd = STDIN_FILENO; |
| 546 |
pfds[1].events = POLLIN; |
pfds[1].events = POLLIN; |
| 547 |
nfds = 2; |
nfds = 2; |
| 548 |
ret = poll(pfds, (nfds_t)nfds, 500); // 0.5 second |
ret = poll(pfds, (nfds_t)nfds, 100); // 0.1 second |
| 549 |
#endif |
#endif |
| 550 |
|
|
| 551 |
if (ret < 0) |
if (ret < 0) |
| 562 |
} |
} |
| 563 |
else if (ret == 0) // timeout |
else if (ret == 0) // timeout |
| 564 |
{ |
{ |
| 565 |
process_bar(j + 1, MAX_PROCESS_BAR_LEN); |
if (clock_gettime(CLOCK_REALTIME, &ts_now) == -1) |
| 566 |
|
{ |
| 567 |
|
log_error("clock_gettime() error (%d)\n", errno); |
| 568 |
|
ret = -1; |
| 569 |
|
goto cleanup; |
| 570 |
|
} |
| 571 |
|
|
| 572 |
|
progress = (int)((ts_now.tv_sec - ts_begin.tv_sec) * 1000 + |
| 573 |
|
(ts_now.tv_nsec - ts_begin.tv_nsec) / 1000 / 1000) / |
| 574 |
|
REMOTE_CONNECT_TIMEOUT / 10 + |
| 575 |
|
1; |
| 576 |
|
|
| 577 |
|
if (progress > progress_last) |
| 578 |
|
{ |
| 579 |
|
progress_last = progress; |
| 580 |
|
progress_bar(progress, PROGRESS_BAR_LEN); |
| 581 |
|
} |
| 582 |
} |
} |
| 583 |
else // ret > 0 |
else // ret > 0 |
| 584 |
{ |
{ |
| 594 |
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0) |
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0) |
| 595 |
{ |
{ |
| 596 |
log_error("getsockopt() error (%d) !\n", errno); |
log_error("getsockopt() error (%d) !\n", errno); |
| 597 |
|
ret = -1; |
| 598 |
goto cleanup; |
goto cleanup; |
| 599 |
} |
} |
| 600 |
if (error == 0) |
if (error == 0) |
| 601 |
{ |
{ |
| 602 |
sock_connected = 1; |
sock_connected = 1; |
| 603 |
|
break; |
| 604 |
} |
} |
| 605 |
} |
} |
| 606 |
#ifdef HAVE_SYS_EPOLL_H |
#ifdef HAVE_SYS_EPOLL_H |
| 615 |
} while (ch == 0); |
} while (ch == 0); |
| 616 |
if (ch == Ctrl('C') || ch == KEY_ESC) |
if (ch == Ctrl('C') || ch == KEY_ESC) |
| 617 |
{ |
{ |
| 618 |
|
ret = 0; |
| 619 |
goto cleanup; |
goto cleanup; |
| 620 |
} |
} |
| 621 |
} |
} |
| 624 |
} |
} |
| 625 |
if (SYS_server_exit) |
if (SYS_server_exit) |
| 626 |
{ |
{ |
| 627 |
|
ret = 0; |
| 628 |
goto cleanup; |
goto cleanup; |
| 629 |
} |
} |
| 630 |
if (!sock_connected) |
if (!sock_connected) |
| 631 |
{ |
{ |
| 632 |
|
progress_bar(100, PROGRESS_BAR_LEN); |
| 633 |
prints("\033[1;31m连接失败!\033[m\r\n"); |
prints("\033[1;31m连接失败!\033[m\r\n"); |
| 634 |
press_any_key(); |
press_any_key(); |
| 635 |
|
ret = -1; |
| 636 |
goto cleanup; |
goto cleanup; |
| 637 |
} |
} |
| 638 |
|
|
| 646 |
if (getsockname(sock, (struct sockaddr *)&sin, &sock_len) < 0) |
if (getsockname(sock, (struct sockaddr *)&sin, &sock_len) < 0) |
| 647 |
{ |
{ |
| 648 |
log_error("getsockname() error: %d", errno); |
log_error("getsockname() error: %d", errno); |
| 649 |
|
ret = -1; |
| 650 |
goto cleanup; |
goto cleanup; |
| 651 |
} |
} |
| 652 |
|
|
| 653 |
strncpy(local_addr, inet_ntoa(sin.sin_addr), sizeof(local_addr) - 1); |
if (inet_ntop(AF_INET, &(sin.sin_addr), local_addr, sizeof(local_addr)) == NULL) |
| 654 |
local_addr[sizeof(local_addr) - 1] = '\0'; |
{ |
| 655 |
|
log_error("inet_ntop() error (%d)\n", errno); |
| 656 |
|
ret = -1; |
| 657 |
|
goto cleanup; |
| 658 |
|
} |
| 659 |
local_port = ntohs(sin.sin_port); |
local_port = ntohs(sin.sin_port); |
| 660 |
|
|
| 661 |
if (bbsnet_conf[n].use_ssh) |
if (bbsnet_conf[n].use_ssh) |
| 662 |
{ |
{ |
| 663 |
session = ssh_new(); |
outbound_session = ssh_new(); |
| 664 |
if (session == NULL) |
if (outbound_session == NULL) |
| 665 |
{ |
{ |
| 666 |
log_error("ssh_new() error\n"); |
log_error("ssh_new() error\n"); |
| 667 |
|
ret = -1; |
| 668 |
goto cleanup; |
goto cleanup; |
| 669 |
} |
} |
| 670 |
|
|
| 671 |
if (ssh_options_set(session, SSH_OPTIONS_FD, &sock) < 0 || |
if (ssh_options_set(outbound_session, SSH_OPTIONS_FD, &sock) < 0 || |
| 672 |
ssh_options_set(session, SSH_OPTIONS_PROCESS_CONFIG, &ssh_process_config) < 0 || |
ssh_options_set(outbound_session, SSH_OPTIONS_PROCESS_CONFIG, &ssh_process_config) < 0 || |
| 673 |
ssh_options_set(session, SSH_OPTIONS_KNOWNHOSTS, SSH_KNOWN_HOSTS_FILE) < 0 || |
ssh_options_set(outbound_session, SSH_OPTIONS_KNOWNHOSTS, SSH_KNOWN_HOSTS_FILE) < 0 || |
| 674 |
ssh_options_set(session, SSH_OPTIONS_HOST, bbsnet_conf[n].host_name) < 0 || |
ssh_options_set(outbound_session, SSH_OPTIONS_HOST, bbsnet_conf[n].host_name) < 0 || |
| 675 |
ssh_options_set(session, SSH_OPTIONS_USER, remote_user) < 0 || |
ssh_options_set(outbound_session, SSH_OPTIONS_USER, remote_user) < 0 || |
| 676 |
ssh_options_set(session, SSH_OPTIONS_HOSTKEYS, "+ssh-rsa") < 0 || |
ssh_options_set(outbound_session, SSH_OPTIONS_HOSTKEYS, "+ssh-ed25519,ecdsa-sha2-nistp256,ssh-rsa") < 0 || |
| 677 |
ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0) |
ssh_options_set(outbound_session, SSH_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0) |
| 678 |
{ |
{ |
| 679 |
log_error("Error setting SSH options: %s\n", ssh_get_error(session)); |
log_error("Error setting SSH options: %s\n", ssh_get_error(outbound_session)); |
| 680 |
|
ret = -1; |
| 681 |
goto cleanup; |
goto cleanup; |
| 682 |
} |
} |
| 683 |
|
|
| 684 |
ssh_set_blocking(session, 0); |
ssh_set_blocking(outbound_session, 0); |
| 685 |
|
|
| 686 |
t_begin = time(NULL); |
t_begin = time(NULL); |
| 687 |
ret = SSH_ERROR; |
ret = SSH_ERROR; |
| 688 |
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 689 |
{ |
{ |
| 690 |
ret = ssh_connect(session); |
ret = ssh_connect(outbound_session); |
| 691 |
if (ret == SSH_OK) |
if (ret == SSH_OK) |
| 692 |
{ |
{ |
| 693 |
break; |
break; |
| 694 |
} |
} |
| 695 |
else if (ret == SSH_AGAIN) |
else if (ret == SSH_AGAIN) |
| 696 |
{ |
{ |
| 697 |
// log_error("ssh_connect() error: SSH_AGAIN\n"); |
// log_debug("ssh_connect() error: SSH_AGAIN\n"); |
| 698 |
} |
} |
| 699 |
else // if (ret == SSH_ERROR) |
else // if (ret == SSH_ERROR) |
| 700 |
{ |
{ |
| 701 |
log_error("ssh_connect() error: SSH_ERROR\n"); |
log_error("ssh_connect() error: SSH_ERROR\n"); |
| 702 |
|
ret = -1; |
| 703 |
goto cleanup; |
goto cleanup; |
| 704 |
} |
} |
| 705 |
} |
} |
| 707 |
{ |
{ |
| 708 |
prints("\033[1;31m连接超时!\033[m\r\n"); |
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 709 |
press_any_key(); |
press_any_key(); |
| 710 |
|
ret = -1; |
| 711 |
goto cleanup; |
goto cleanup; |
| 712 |
} |
} |
| 713 |
|
|
| 714 |
ret = ssh_session_is_known_server(session); |
ret = ssh_session_is_known_server(outbound_session); |
| 715 |
switch (ret) |
switch (ret) |
| 716 |
{ |
{ |
| 717 |
case SSH_KNOWN_HOSTS_NOT_FOUND: |
case SSH_KNOWN_HOSTS_NOT_FOUND: |
| 718 |
case SSH_KNOWN_HOSTS_UNKNOWN: |
case SSH_KNOWN_HOSTS_UNKNOWN: |
| 719 |
if (ssh_session_update_known_hosts(session) != SSH_OK) |
if (ssh_session_update_known_hosts(outbound_session) != SSH_OK) |
| 720 |
{ |
{ |
| 721 |
log_error("ssh_session_update_known_hosts(%s) error\n", bbsnet_conf[n].host_name); |
log_error("ssh_session_update_known_hosts(%s) error\n", bbsnet_conf[n].host_name); |
| 722 |
prints("\033[1;31m无法添加服务器证书\033[m\r\n"); |
prints("\033[1;31m无法添加服务器证书\033[m\r\n"); |
| 723 |
press_any_key(); |
press_any_key(); |
| 724 |
|
ret = -1; |
| 725 |
goto cleanup; |
goto cleanup; |
| 726 |
} |
} |
| 727 |
log_common("SSH key of (%s) is added into %s\n", bbsnet_conf[n].host_name, SSH_KNOWN_HOSTS_FILE); |
log_common("SSH key of (%s) is added into %s\n", bbsnet_conf[n].host_name, SSH_KNOWN_HOSTS_FILE); |
| 732 |
log_error("ssh_session_is_known_server(%s) error: %d\n", bbsnet_conf[n].host_name, ret); |
log_error("ssh_session_is_known_server(%s) error: %d\n", bbsnet_conf[n].host_name, ret); |
| 733 |
prints("\033[1;31m服务器证书已变更\033[m\r\n"); |
prints("\033[1;31m服务器证书已变更\033[m\r\n"); |
| 734 |
press_any_key(); |
press_any_key(); |
| 735 |
|
ret = -1; |
| 736 |
goto cleanup; |
goto cleanup; |
| 737 |
} |
} |
| 738 |
|
|
| 739 |
ret = SSH_AUTH_ERROR; |
ret = SSH_AUTH_ERROR; |
| 740 |
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 741 |
{ |
{ |
| 742 |
ret = ssh_userauth_password(session, NULL, remote_pass); |
ret = ssh_userauth_password(outbound_session, NULL, remote_pass); |
| 743 |
if (ret == SSH_AUTH_SUCCESS) |
if (ret == SSH_AUTH_SUCCESS) |
| 744 |
{ |
{ |
| 745 |
break; |
break; |
| 746 |
} |
} |
| 747 |
else if (ret == SSH_AUTH_AGAIN) |
else if (ret == SSH_AUTH_AGAIN) |
| 748 |
{ |
{ |
| 749 |
// log_error("ssh_userauth_password() error: SSH_AUTH_AGAIN\n"); |
// log_debug("ssh_userauth_password() error: SSH_AUTH_AGAIN\n"); |
| 750 |
} |
} |
| 751 |
else if (ret == SSH_AUTH_ERROR) |
else if (ret == SSH_AUTH_ERROR) |
| 752 |
{ |
{ |
| 753 |
log_error("ssh_userauth_password() error: SSH_AUTH_ERROR\n"); |
log_error("ssh_userauth_password() error: SSH_AUTH_ERROR\n"); |
| 754 |
|
ret = -1; |
| 755 |
goto cleanup; |
goto cleanup; |
| 756 |
} |
} |
| 757 |
else // if (ret == SSH_AUTH_DENIED) |
else // if (ret == SSH_AUTH_DENIED) |
| 759 |
log_error("ssh_userauth_password() error: SSH_AUTH_DENIED\n"); |
log_error("ssh_userauth_password() error: SSH_AUTH_DENIED\n"); |
| 760 |
prints("\033[1;31m身份验证失败!\033[m\r\n"); |
prints("\033[1;31m身份验证失败!\033[m\r\n"); |
| 761 |
press_any_key(); |
press_any_key(); |
| 762 |
|
ret = -1; |
| 763 |
goto cleanup; |
goto cleanup; |
| 764 |
} |
} |
| 765 |
} |
} |
| 767 |
{ |
{ |
| 768 |
prints("\033[1;31m连接超时!\033[m\r\n"); |
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 769 |
press_any_key(); |
press_any_key(); |
| 770 |
|
ret = -1; |
| 771 |
goto cleanup; |
goto cleanup; |
| 772 |
} |
} |
| 773 |
|
|
| 774 |
channel = ssh_channel_new(session); |
outbound_channel = ssh_channel_new(outbound_session); |
| 775 |
if (channel == NULL) |
if (outbound_channel == NULL) |
| 776 |
{ |
{ |
| 777 |
log_error("ssh_channel_new() error\n"); |
log_error("ssh_channel_new() error\n"); |
| 778 |
|
ret = -1; |
| 779 |
goto cleanup; |
goto cleanup; |
| 780 |
} |
} |
| 781 |
|
|
| 782 |
ret = SSH_ERROR; |
ret = SSH_ERROR; |
| 783 |
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 784 |
{ |
{ |
| 785 |
ret = ssh_channel_open_session(channel); |
ret = ssh_channel_open_session(outbound_channel); |
| 786 |
if (ret == SSH_OK) |
if (ret == SSH_OK) |
| 787 |
{ |
{ |
| 788 |
break; |
break; |
| 789 |
} |
} |
| 790 |
else if (ret == SSH_AGAIN) |
else if (ret == SSH_AGAIN) |
| 791 |
{ |
{ |
| 792 |
// log_error("ssh_channel_open_session() error: SSH_AGAIN\n"); |
// log_debug("ssh_channel_open_session() error: SSH_AGAIN\n"); |
| 793 |
} |
} |
| 794 |
else // if (ret == SSH_ERROR) |
else // if (ret == SSH_ERROR) |
| 795 |
{ |
{ |
| 796 |
log_error("ssh_channel_open_session() error: SSH_ERROR\n"); |
log_error("ssh_channel_open_session() error: SSH_ERROR\n"); |
| 797 |
|
ret = -1; |
| 798 |
goto cleanup; |
goto cleanup; |
| 799 |
} |
} |
| 800 |
} |
} |
| 802 |
{ |
{ |
| 803 |
prints("\033[1;31m连接超时!\033[m\r\n"); |
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 804 |
press_any_key(); |
press_any_key(); |
| 805 |
|
ret = -1; |
| 806 |
goto cleanup; |
goto cleanup; |
| 807 |
} |
} |
| 808 |
|
|
| 809 |
ret = SSH_ERROR; |
ret = SSH_ERROR; |
| 810 |
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 811 |
{ |
{ |
| 812 |
ret = ssh_channel_request_pty(channel); |
ret = ssh_channel_request_pty(outbound_channel); |
| 813 |
if (ret == SSH_OK) |
if (ret == SSH_OK) |
| 814 |
{ |
{ |
| 815 |
break; |
break; |
| 816 |
} |
} |
| 817 |
else if (ret == SSH_AGAIN) |
else if (ret == SSH_AGAIN) |
| 818 |
{ |
{ |
| 819 |
// log_error("ssh_channel_request_pty() error: SSH_AGAIN\n"); |
// log_debug("ssh_channel_request_pty() error: SSH_AGAIN\n"); |
| 820 |
} |
} |
| 821 |
else // if (ret == SSH_ERROR) |
else // if (ret == SSH_ERROR) |
| 822 |
{ |
{ |
| 823 |
log_error("ssh_channel_request_pty() error: SSH_ERROR\n"); |
log_error("ssh_channel_request_pty() error: SSH_ERROR\n"); |
| 824 |
|
ret = -1; |
| 825 |
goto cleanup; |
goto cleanup; |
| 826 |
} |
} |
| 827 |
} |
} |
| 829 |
{ |
{ |
| 830 |
prints("\033[1;31m连接超时!\033[m\r\n"); |
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 831 |
press_any_key(); |
press_any_key(); |
| 832 |
|
ret = -1; |
| 833 |
goto cleanup; |
goto cleanup; |
| 834 |
} |
} |
| 835 |
|
|
| 836 |
ret = SSH_ERROR; |
ret = SSH_ERROR; |
| 837 |
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 838 |
{ |
{ |
| 839 |
ret = ssh_channel_request_shell(channel); |
ret = ssh_channel_request_shell(outbound_channel); |
| 840 |
if (ret == SSH_OK) |
if (ret == SSH_OK) |
| 841 |
{ |
{ |
| 842 |
break; |
break; |
| 843 |
} |
} |
| 844 |
else if (ret == SSH_AGAIN) |
else if (ret == SSH_AGAIN) |
| 845 |
{ |
{ |
| 846 |
// log_error("ssh_channel_request_shell() error: SSH_AGAIN\n"); |
// log_debug("ssh_channel_request_shell() error: SSH_AGAIN\n"); |
| 847 |
} |
} |
| 848 |
else // if (ret == SSH_ERROR) |
else // if (ret == SSH_ERROR) |
| 849 |
{ |
{ |
| 850 |
log_error("ssh_channel_request_shell() error: SSH_ERROR\n"); |
log_error("ssh_channel_request_shell() error: SSH_ERROR\n"); |
| 851 |
|
ret = -1; |
| 852 |
goto cleanup; |
goto cleanup; |
| 853 |
} |
} |
| 854 |
} |
} |
| 856 |
{ |
{ |
| 857 |
prints("\033[1;31m连接超时!\033[m\r\n"); |
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 858 |
press_any_key(); |
press_any_key(); |
| 859 |
|
ret = -1; |
| 860 |
goto cleanup; |
goto cleanup; |
| 861 |
} |
} |
| 862 |
} |
} |
| 872 |
if (input_cd == (iconv_t)(-1)) |
if (input_cd == (iconv_t)(-1)) |
| 873 |
{ |
{ |
| 874 |
log_error("iconv_open(%s->%s) error: %d\n", stdio_charset, tocode, errno); |
log_error("iconv_open(%s->%s) error: %d\n", stdio_charset, tocode, errno); |
| 875 |
|
ret = -1; |
| 876 |
goto cleanup; |
goto cleanup; |
| 877 |
} |
} |
| 878 |
|
|
| 882 |
if (output_cd == (iconv_t)(-1)) |
if (output_cd == (iconv_t)(-1)) |
| 883 |
{ |
{ |
| 884 |
log_error("iconv_open(%s->%s) error: %d\n", bbsnet_conf[n].charset, tocode, errno); |
log_error("iconv_open(%s->%s) error: %d\n", bbsnet_conf[n].charset, tocode, errno); |
| 885 |
|
ret = -1; |
| 886 |
goto cleanup; |
goto cleanup; |
| 887 |
} |
} |
| 888 |
|
|
| 892 |
if (epoll_ctl(epollfd, EPOLL_CTL_MOD, sock, &ev) == -1) |
if (epoll_ctl(epollfd, EPOLL_CTL_MOD, sock, &ev) == -1) |
| 893 |
{ |
{ |
| 894 |
log_error("epoll_ctl(socket) error (%d)\n", errno); |
log_error("epoll_ctl(socket) error (%d)\n", errno); |
| 895 |
|
ret = -1; |
| 896 |
goto cleanup; |
goto cleanup; |
| 897 |
} |
} |
| 898 |
|
|
| 901 |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDOUT_FILENO, &ev) == -1) |
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, STDOUT_FILENO, &ev) == -1) |
| 902 |
{ |
{ |
| 903 |
log_error("epoll_ctl(STDOUT_FILENO) error (%d)\n", errno); |
log_error("epoll_ctl(STDOUT_FILENO) error (%d)\n", errno); |
| 904 |
|
ret = -1; |
| 905 |
goto cleanup; |
goto cleanup; |
| 906 |
} |
} |
| 907 |
#endif |
#endif |
| 908 |
|
|
| 909 |
BBS_last_access_tm = t_used = time(NULL); |
BBS_last_access_tm = t_begin = time(NULL); |
| 910 |
loop = 1; |
loop = 1; |
| 911 |
|
|
| 912 |
while (loop && !SYS_server_exit) |
while (loop && !SYS_server_exit) |
| 918 |
break; |
break; |
| 919 |
} |
} |
| 920 |
|
|
| 921 |
if (bbsnet_conf[n].use_ssh && ssh_channel_is_closed(channel)) |
if (bbsnet_conf[n].use_ssh && ssh_channel_is_closed(outbound_channel)) |
| 922 |
{ |
{ |
| 923 |
log_debug("Remote SSH channel is closed\n"); |
log_debug("Outbound channel is closed\n"); |
| 924 |
loop = 0; |
loop = 0; |
| 925 |
break; |
break; |
| 926 |
} |
} |
| 963 |
for (int i = 0; i < nfds; i++) |
for (int i = 0; i < nfds; i++) |
| 964 |
{ |
{ |
| 965 |
#ifdef HAVE_SYS_EPOLL_H |
#ifdef HAVE_SYS_EPOLL_H |
| 966 |
if (events[i].events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) |
if (events[i].events & (EPOLLHUP | EPOLLERR)) |
| 967 |
#else |
#else |
| 968 |
if (pfds[i].revents & (POLLRDHUP | POLLHUP | POLLERR)) |
if (pfds[i].revents & (POLLHUP | POLLERR)) |
| 969 |
#endif |
#endif |
| 970 |
{ |
{ |
| 971 |
#ifdef HAVE_SYS_EPOLL_H |
#ifdef HAVE_SYS_EPOLL_H |
| 1045 |
// Send NO-OP to remote server |
// Send NO-OP to remote server |
| 1046 |
input_buf[input_buf_len] = '\0'; |
input_buf[input_buf_len] = '\0'; |
| 1047 |
input_buf_len++; |
input_buf_len++; |
|
BBS_last_access_tm = time(NULL); |
|
| 1048 |
|
|
| 1049 |
|
BBS_last_access_tm = time(NULL); |
| 1050 |
stdin_read_wait = 0; |
stdin_read_wait = 0; |
| 1051 |
break; // Check whether channel is still open |
break; // Check whether channel is still open |
| 1052 |
} |
} |
| 1128 |
{ |
{ |
| 1129 |
if (bbsnet_conf[n].use_ssh) |
if (bbsnet_conf[n].use_ssh) |
| 1130 |
{ |
{ |
| 1131 |
ret = ssh_channel_write(channel, input_conv + input_conv_offset, (uint32_t)(input_conv_len - input_conv_offset)); |
ret = ssh_channel_write(outbound_channel, input_conv + input_conv_offset, (uint32_t)(input_conv_len - input_conv_offset)); |
| 1132 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 1133 |
{ |
{ |
| 1134 |
log_debug("ssh_channel_write() error: %s\n", ssh_get_error(session)); |
log_debug("ssh_channel_write() error: %s\n", ssh_get_error(outbound_session)); |
| 1135 |
loop = 0; |
loop = 0; |
| 1136 |
break; |
break; |
| 1137 |
} |
} |
| 1185 |
{ |
{ |
| 1186 |
if (bbsnet_conf[n].use_ssh) |
if (bbsnet_conf[n].use_ssh) |
| 1187 |
{ |
{ |
| 1188 |
ret = ssh_channel_read_nonblocking(channel, output_buf + output_buf_len, |
ret = ssh_channel_read_nonblocking(outbound_channel, output_buf + output_buf_len, |
| 1189 |
(uint32_t)(sizeof(output_buf) - (size_t)output_buf_len), 0); |
(uint32_t)(sizeof(output_buf) - (size_t)output_buf_len), 0); |
| 1190 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 1191 |
{ |
{ |
| 1192 |
log_debug("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(session)); |
log_debug("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(outbound_session)); |
| 1193 |
loop = 0; |
loop = 0; |
| 1194 |
break; |
break; |
| 1195 |
} |
} |
| 1310 |
} |
} |
| 1311 |
} |
} |
| 1312 |
|
|
| 1313 |
|
ret = 1; // Normal disconnect |
| 1314 |
|
BBS_last_access_tm = time(NULL); |
| 1315 |
|
t_used = BBS_last_access_tm - t_begin; |
| 1316 |
|
log_common("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", |
| 1317 |
|
t_used / 86400, t_used % 86400 / 3600, t_used % 3600 / 60, t_used % 60); |
| 1318 |
|
|
| 1319 |
cleanup: |
cleanup: |
| 1320 |
|
// Clear sensitive data |
| 1321 |
|
memset(remote_pass, 0, sizeof(remote_pass)); |
| 1322 |
|
memset(remote_user, 0, sizeof(remote_user)); |
| 1323 |
|
|
| 1324 |
if (input_cd != (iconv_t)(-1)) |
if (input_cd != (iconv_t)(-1)) |
| 1325 |
{ |
{ |
| 1326 |
iconv_close(input_cd); |
iconv_close(input_cd); |
| 1339 |
|
|
| 1340 |
if (bbsnet_conf[n].use_ssh) |
if (bbsnet_conf[n].use_ssh) |
| 1341 |
{ |
{ |
| 1342 |
if (channel != NULL) |
if (outbound_channel != NULL) |
| 1343 |
{ |
{ |
| 1344 |
ssh_channel_free(channel); |
ssh_channel_send_eof(outbound_channel); |
| 1345 |
|
ssh_channel_close(outbound_channel); |
| 1346 |
|
ssh_channel_free(outbound_channel); |
| 1347 |
} |
} |
| 1348 |
if (session != NULL) |
if (outbound_session != NULL) |
| 1349 |
{ |
{ |
| 1350 |
ssh_disconnect(session); |
ssh_disconnect(outbound_session); |
| 1351 |
ssh_free(session); |
ssh_free(outbound_session); |
| 1352 |
} |
} |
| 1353 |
} |
} |
| 1354 |
|
|
| 1372 |
freeaddrinfo(res); |
freeaddrinfo(res); |
| 1373 |
} |
} |
| 1374 |
|
|
| 1375 |
t_used = time(NULL) - t_used; |
return ret; |
|
tm_used = gmtime(&t_used); |
|
|
|
|
|
log_common("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", |
|
|
tm_used->tm_yday, tm_used->tm_hour, tm_used->tm_min, tm_used->tm_sec); |
|
|
|
|
|
BBS_last_access_tm = time(NULL); |
|
|
|
|
|
return 0; |
|
| 1376 |
} |
} |
| 1377 |
|
|
| 1378 |
static int bbsnet_refresh() |
static int bbsnet_refresh() |