| 54 |
STATION_PER_LINE = 4, |
STATION_PER_LINE = 4, |
| 55 |
USERNAME_MAX_LEN = 20, |
USERNAME_MAX_LEN = 20, |
| 56 |
PASSWORD_MAX_LEN = 20, |
PASSWORD_MAX_LEN = 20, |
| 57 |
|
SSH_CONNECT_TIMEOUT = 5, // seconds |
| 58 |
}; |
}; |
| 59 |
|
|
| 60 |
struct _bbsnet_conf |
struct _bbsnet_conf |
| 62 |
char org_name[40]; |
char org_name[40]; |
| 63 |
char site_name[40]; |
char site_name[40]; |
| 64 |
char host_name[IP_ADDR_LEN]; |
char host_name[IP_ADDR_LEN]; |
| 65 |
in_port_t port; |
char port[6]; |
| 66 |
int8_t use_ssh; |
int8_t use_ssh; |
| 67 |
char charset[CHARSET_MAX_LEN + 1]; |
char charset[CHARSET_MAX_LEN + 1]; |
| 68 |
} bbsnet_conf[MAXSTATION]; |
} bbsnet_conf[MAXSTATION]; |
| 69 |
|
|
| 70 |
static MENU_SET bbsnet_menu; |
static MENU_SET bbsnet_menu; |
| 71 |
|
|
| 72 |
|
static void unload_bbsnet_conf(void); |
| 73 |
|
|
| 74 |
static int load_bbsnet_conf(const char *file_config) |
static int load_bbsnet_conf(const char *file_config) |
| 75 |
{ |
{ |
| 76 |
FILE *fp; |
FILE *fp; |
| 78 |
MENU_ITEM *p_menu_item; |
MENU_ITEM *p_menu_item; |
| 79 |
MENU_ITEM_ID menu_item_id; |
MENU_ITEM_ID menu_item_id; |
| 80 |
char line[LINE_BUFFER_LEN], *t1, *t2, *t3, *t4, *t5, *t6, *saveptr; |
char line[LINE_BUFFER_LEN], *t1, *t2, *t3, *t4, *t5, *t6, *saveptr; |
| 81 |
|
int port; |
| 82 |
|
|
| 83 |
fp = fopen(file_config, "r"); |
unload_bbsnet_conf(); |
|
if (fp == NULL) |
|
|
{ |
|
|
return -1; |
|
|
} |
|
| 84 |
|
|
| 85 |
bbsnet_menu.p_menu_pool = calloc(1, sizeof(MENU)); |
bbsnet_menu.p_menu_pool = calloc(1, sizeof(MENU)); |
| 86 |
if (bbsnet_menu.p_menu_pool == NULL) |
if (bbsnet_menu.p_menu_pool == NULL) |
| 87 |
{ |
{ |
| 88 |
log_error("calloc(p_menu_pool) error\n"); |
log_error("calloc(p_menu_pool) error\n"); |
| 89 |
return -3; |
return -1; |
| 90 |
} |
} |
| 91 |
bbsnet_menu.menu_count = 1; |
bbsnet_menu.menu_count = 1; |
| 92 |
|
|
| 94 |
if (bbsnet_menu.p_menu_item_pool == NULL) |
if (bbsnet_menu.p_menu_item_pool == NULL) |
| 95 |
{ |
{ |
| 96 |
log_error("calloc(p_menu_item_pool) error\n"); |
log_error("calloc(p_menu_item_pool) error\n"); |
| 97 |
return -3; |
unload_bbsnet_conf(); |
| 98 |
|
return -1; |
| 99 |
} |
} |
| 100 |
bbsnet_menu.menu_item_count = MAXSTATION; |
bbsnet_menu.menu_item_count = MAXSTATION; |
| 101 |
|
|
| 106 |
p_menu->title.show = 0; |
p_menu->title.show = 0; |
| 107 |
p_menu->screen_show = 0; |
p_menu->screen_show = 0; |
| 108 |
|
|
| 109 |
|
fp = fopen(file_config, "r"); |
| 110 |
|
if (fp == NULL) |
| 111 |
|
{ |
| 112 |
|
unload_bbsnet_conf(); |
| 113 |
|
return -2; |
| 114 |
|
} |
| 115 |
|
|
| 116 |
menu_item_id = 0; |
menu_item_id = 0; |
| 117 |
while (fgets(line, sizeof(line), fp) && menu_item_id < MAXSTATION) |
while (fgets(line, sizeof(line), fp) && menu_item_id < MAXSTATION) |
| 118 |
{ |
{ |
| 135 |
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'; |
| 136 |
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); |
| 137 |
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'; |
| 138 |
bbsnet_conf[menu_item_id].port = (in_port_t)(t4 ? atoi(t4) : 23); |
port = atoi(t4); |
| 139 |
|
if (port <= 0 || port > 65535) |
| 140 |
|
{ |
| 141 |
|
log_error("Invalid port value %d of menu item %d\n", port, menu_item_id); |
| 142 |
|
fclose(fp); |
| 143 |
|
unload_bbsnet_conf(); |
| 144 |
|
return -3; |
| 145 |
|
} |
| 146 |
|
strncpy(bbsnet_conf[menu_item_id].port, t4, sizeof(bbsnet_conf[menu_item_id].port) - 1); |
| 147 |
|
bbsnet_conf[menu_item_id].port[sizeof(bbsnet_conf[menu_item_id].port) - 1] = '\0'; |
| 148 |
bbsnet_conf[menu_item_id].use_ssh = (toupper(t5[0]) == 'Y'); |
bbsnet_conf[menu_item_id].use_ssh = (toupper(t5[0]) == 'Y'); |
| 149 |
strncpy(bbsnet_conf[menu_item_id].charset, t6, sizeof(bbsnet_conf[menu_item_id].charset) - 1); |
strncpy(bbsnet_conf[menu_item_id].charset, t6, sizeof(bbsnet_conf[menu_item_id].charset) - 1); |
| 150 |
bbsnet_conf[menu_item_id].charset[sizeof(bbsnet_conf[menu_item_id].charset) - 1] = '\0'; |
bbsnet_conf[menu_item_id].charset[sizeof(bbsnet_conf[menu_item_id].charset) - 1] = '\0'; |
| 153 |
if (p_menu_item == NULL) |
if (p_menu_item == NULL) |
| 154 |
{ |
{ |
| 155 |
log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); |
log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id); |
| 156 |
return -1; |
fclose(fp); |
| 157 |
|
unload_bbsnet_conf(); |
| 158 |
|
return -3; |
| 159 |
} |
} |
| 160 |
|
|
| 161 |
p_menu_item->row = (int16_t)(2 + menu_item_id / STATION_PER_LINE); |
p_menu_item->row = (int16_t)(2 + menu_item_id / STATION_PER_LINE); |
| 167 |
p_menu_item->name[0] = |
p_menu_item->name[0] = |
| 168 |
(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); |
| 169 |
p_menu_item->name[1] = '\0'; |
p_menu_item->name[1] = '\0'; |
| 170 |
snprintf(p_menu_item->text, sizeof(p_menu_item->text), "[1;36m%c.[m %s", |
snprintf(p_menu_item->text, sizeof(p_menu_item->text), "\033[1;36m%c.\033[m %s", |
| 171 |
p_menu_item->name[0], bbsnet_conf[menu_item_id].site_name); |
p_menu_item->name[0], bbsnet_conf[menu_item_id].site_name); |
| 172 |
|
|
| 173 |
p_menu->items[p_menu->item_count] = menu_item_id; |
p_menu->items[p_menu->item_count] = menu_item_id; |
| 190 |
bbsnet_menu.menu_count = 0; |
bbsnet_menu.menu_count = 0; |
| 191 |
bbsnet_menu.menu_item_count = 0; |
bbsnet_menu.menu_item_count = 0; |
| 192 |
|
|
| 193 |
free(bbsnet_menu.p_menu_pool); |
if (bbsnet_menu.p_menu_pool) |
| 194 |
bbsnet_menu.p_menu_pool = NULL; |
{ |
| 195 |
free(bbsnet_menu.p_menu_item_pool); |
free(bbsnet_menu.p_menu_pool); |
| 196 |
bbsnet_menu.p_menu_item_pool = NULL; |
bbsnet_menu.p_menu_pool = NULL; |
| 197 |
|
} |
| 198 |
|
|
| 199 |
|
if (bbsnet_menu.p_menu_item_pool) |
| 200 |
|
{ |
| 201 |
|
free(bbsnet_menu.p_menu_item_pool); |
| 202 |
|
bbsnet_menu.p_menu_item_pool = NULL; |
| 203 |
|
} |
| 204 |
} |
} |
| 205 |
|
|
| 206 |
static void process_bar(int n, int len) |
static void process_bar(int n, int len) |
| 208 |
char buf[LINE_BUFFER_LEN]; |
char buf[LINE_BUFFER_LEN]; |
| 209 |
char buf2[LINE_BUFFER_LEN]; |
char buf2[LINE_BUFFER_LEN]; |
| 210 |
|
|
| 211 |
if (len > LINE_BUFFER_LEN) |
if (len <= 0) |
| 212 |
|
{ |
| 213 |
|
len = 1; |
| 214 |
|
} |
| 215 |
|
else if (len > LINE_BUFFER_LEN) |
| 216 |
{ |
{ |
| 217 |
len = LINE_BUFFER_LEN - 1; |
len = LINE_BUFFER_LEN - 1; |
| 218 |
} |
} |
| 237 |
|
|
| 238 |
static int bbsnet_connect(int n) |
static int bbsnet_connect(int n) |
| 239 |
{ |
{ |
| 240 |
int sock, ret, loop, error; |
int sock = -1; |
| 241 |
|
int ret; |
| 242 |
|
int loop; |
| 243 |
|
int error; |
| 244 |
int sock_connected = 0; |
int sock_connected = 0; |
| 245 |
int flags_sock; |
int flags_sock = -1; |
| 246 |
int flags_stdin; |
int flags_stdin = -1; |
| 247 |
int flags_stdout; |
int flags_stdout = -1; |
|
int len; |
|
| 248 |
struct sockaddr_in sin; |
struct sockaddr_in sin; |
| 249 |
char input_buf[LINE_BUFFER_LEN]; |
char input_buf[LINE_BUFFER_LEN]; |
| 250 |
char output_buf[LINE_BUFFER_LEN]; |
char output_buf[LINE_BUFFER_LEN]; |
| 258 |
int output_conv_len = 0; |
int output_conv_len = 0; |
| 259 |
int input_conv_offset = 0; |
int input_conv_offset = 0; |
| 260 |
int output_conv_offset = 0; |
int output_conv_offset = 0; |
| 261 |
iconv_t input_cd = NULL; |
iconv_t input_cd = (iconv_t)(-1); |
| 262 |
iconv_t output_cd = NULL; |
iconv_t output_cd = (iconv_t)(-1); |
| 263 |
char tocode[32]; |
char tocode[CHARSET_MAX_LEN + 20]; |
| 264 |
|
|
| 265 |
#ifdef HAVE_SYS_EPOLL_H |
#ifdef HAVE_SYS_EPOLL_H |
| 266 |
struct epoll_event ev, events[MAX_EVENTS]; |
struct epoll_event ev, events[MAX_EVENTS]; |
| 267 |
int epollfd; |
int epollfd = -1; |
| 268 |
#else |
#else |
| 269 |
struct pollfd pfds[3]; |
struct pollfd pfds[3]; |
| 270 |
#endif |
#endif |
| 274 |
int stdout_write_wait = 0; |
int stdout_write_wait = 0; |
| 275 |
int sock_read_wait = 0; |
int sock_read_wait = 0; |
| 276 |
int sock_write_wait = 0; |
int sock_write_wait = 0; |
| 277 |
struct hostent *p_host = NULL; |
struct addrinfo hints, *res = NULL; |
| 278 |
int tos; |
int tos; |
| 279 |
char remote_addr[IP_ADDR_LEN]; |
char remote_addr[INET_ADDRSTRLEN]; |
| 280 |
int remote_port; |
int remote_port; |
| 281 |
char local_addr[IP_ADDR_LEN]; |
char local_addr[INET_ADDRSTRLEN]; |
| 282 |
int local_port; |
int local_port; |
| 283 |
socklen_t sock_len; |
socklen_t sock_len; |
| 284 |
|
time_t t_begin; |
| 285 |
time_t t_used = time(NULL); |
time_t t_used = time(NULL); |
| 286 |
struct tm *tm_used; |
struct tm *tm_used; |
| 287 |
int ch; |
int ch; |
| 290 |
ssh_session session = NULL; |
ssh_session session = NULL; |
| 291 |
ssh_channel channel = NULL; |
ssh_channel channel = NULL; |
| 292 |
int ssh_process_config = 0; |
int ssh_process_config = 0; |
| 293 |
int ssh_log_level = SSH_LOG_PROTOCOL; |
int ssh_log_level = SSH_LOG_NOLOG; |
| 294 |
|
|
| 295 |
if (user_online_update("BBS_NET") < 0) |
if (user_online_update("BBS_NET") < 0) |
| 296 |
{ |
{ |
| 343 |
bbsnet_conf[n].site_name, bbsnet_conf[n].host_name); |
bbsnet_conf[n].site_name, bbsnet_conf[n].host_name); |
| 344 |
iflush(); |
iflush(); |
| 345 |
|
|
| 346 |
p_host = gethostbyname(bbsnet_conf[n].host_name); |
memset(&hints, 0, sizeof(hints)); |
| 347 |
|
hints.ai_family = AF_INET; |
| 348 |
|
hints.ai_socktype = SOCK_STREAM; |
| 349 |
|
hints.ai_protocol = IPPROTO_TCP; |
| 350 |
|
|
| 351 |
if (p_host == NULL) |
if ((ret = getaddrinfo(BBS_address, NULL, &hints, &res)) != 0) |
| 352 |
{ |
{ |
| 353 |
prints("\033[1;31m查找主机名失败!\033[m\r\n"); |
log_error("getaddrinfo() error (%d)\n", ret); |
| 354 |
press_any_key(); |
goto cleanup; |
|
return -1; |
|
| 355 |
} |
} |
| 356 |
|
|
| 357 |
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr), local_addr, sizeof(local_addr)) == NULL) |
| 358 |
|
{ |
| 359 |
|
log_error("inet_ntop() error (%d)\n", errno); |
| 360 |
|
goto cleanup; |
| 361 |
|
} |
| 362 |
|
local_port = ntohs(((struct sockaddr_in *)res->ai_addr)->sin_port); |
| 363 |
|
|
| 364 |
|
sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); |
| 365 |
if (sock < 0) |
if (sock < 0) |
| 366 |
{ |
{ |
| 367 |
prints("\033[1;31m无法创建socket!\033[m\r\n"); |
log_error("socket() error (%d)\n", errno); |
| 368 |
press_any_key(); |
goto cleanup; |
|
return -1; |
|
| 369 |
} |
} |
| 370 |
|
|
| 371 |
sin.sin_family = AF_INET; |
if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) |
| 372 |
sin.sin_addr.s_addr = (BBS_address[0] != '\0' ? inet_addr(BBS_address) : INADDR_ANY); |
{ |
| 373 |
sin.sin_port = 0; |
log_error("bind(%s:%u) error (%d)\n", local_addr, local_port, errno); |
| 374 |
|
goto cleanup; |
| 375 |
|
} |
| 376 |
|
|
| 377 |
|
freeaddrinfo(res); |
| 378 |
|
res = NULL; |
| 379 |
|
|
| 380 |
|
memset(&hints, 0, sizeof(hints)); |
| 381 |
|
hints.ai_family = AF_INET; |
| 382 |
|
hints.ai_flags = AI_NUMERICSERV; |
| 383 |
|
hints.ai_socktype = SOCK_STREAM; |
| 384 |
|
hints.ai_protocol = IPPROTO_TCP; |
| 385 |
|
|
| 386 |
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) |
if ((ret = getaddrinfo(bbsnet_conf[n].host_name, bbsnet_conf[n].port, &hints, &res)) != 0) |
| 387 |
{ |
{ |
| 388 |
log_error("Bind address %s:%u failed (%d)\n", |
log_error("getaddrinfo() error (%d)\n", ret); |
| 389 |
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), errno); |
prints("\033[1;31m查找主机名失败!\033[m\r\n"); |
| 390 |
return -2; |
press_any_key(); |
| 391 |
|
goto cleanup; |
| 392 |
} |
} |
| 393 |
|
|
| 394 |
memset(&sin, 0, sizeof(sin)); |
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr), remote_addr, sizeof(remote_addr)) == NULL) |
| 395 |
sin.sin_family = AF_INET; |
{ |
| 396 |
sin.sin_addr = *(struct in_addr *)p_host->h_addr_list[0]; |
log_error("inet_ntop() error (%d)\n", errno); |
| 397 |
sin.sin_port = htons(bbsnet_conf[n].port); |
goto cleanup; |
| 398 |
|
} |
| 399 |
strncpy(remote_addr, inet_ntoa(sin.sin_addr), sizeof(remote_addr) - 1); |
remote_port = ntohs(((struct sockaddr_in *)res->ai_addr)->sin_port); |
|
remote_addr[sizeof(remote_addr) - 1] = '\0'; |
|
|
remote_port = ntohs(sin.sin_port); |
|
| 400 |
|
|
| 401 |
prints("\033[1;32m穿梭进度条提示您当前已使用的时间,按\033[1;33mCtrl+C\033[1;32m中断。\033[m\r\n"); |
prints("\033[1;32m穿梭进度条提示您当前已使用的时间,按\033[1;33mCtrl+C\033[1;32m中断。\033[m\r\n"); |
| 402 |
process_bar(0, MAX_PROCESS_BAR_LEN); |
process_bar(0, MAX_PROCESS_BAR_LEN); |
| 403 |
|
|
| 404 |
// Set socket as non-blocking |
// Set socket as non-blocking |
| 405 |
flags_sock = fcntl(sock, F_GETFL, 0); |
if ((flags_sock = fcntl(sock, F_GETFL, 0)) == -1) |
| 406 |
fcntl(sock, F_SETFL, flags_sock | O_NONBLOCK); |
{ |
| 407 |
|
log_error("fcntl(F_GETFL) error (%d)\n", errno); |
| 408 |
|
goto cleanup; |
| 409 |
|
} |
| 410 |
|
if ((fcntl(sock, F_SETFL, flags_sock | O_NONBLOCK)) == -1) |
| 411 |
|
{ |
| 412 |
|
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
| 413 |
|
goto cleanup; |
| 414 |
|
} |
| 415 |
|
|
| 416 |
// Set STDIN/STDOUT as non-blocking |
// Set STDIN/STDOUT as non-blocking |
| 417 |
flags_stdin = fcntl(STDIN_FILENO, F_GETFL, 0); |
if ((flags_stdin = fcntl(STDIN_FILENO, F_GETFL, 0)) == -1) |
| 418 |
flags_stdout = fcntl(STDOUT_FILENO, F_GETFL, 0); |
{ |
| 419 |
fcntl(STDIN_FILENO, F_SETFL, flags_stdin | O_NONBLOCK); |
log_error("fcntl(F_GETFL) error (%d)\n", errno); |
| 420 |
fcntl(STDOUT_FILENO, F_SETFL, flags_stdout | O_NONBLOCK); |
goto cleanup; |
| 421 |
|
} |
| 422 |
|
if ((flags_stdout = fcntl(STDOUT_FILENO, F_GETFL, 0)) == -1) |
| 423 |
|
{ |
| 424 |
|
log_error("fcntl(F_GETFL) error (%d)\n", errno); |
| 425 |
|
goto cleanup; |
| 426 |
|
} |
| 427 |
|
if ((fcntl(STDIN_FILENO, F_SETFL, flags_stdin | O_NONBLOCK)) == -1) |
| 428 |
|
{ |
| 429 |
|
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
| 430 |
|
goto cleanup; |
| 431 |
|
} |
| 432 |
|
if ((fcntl(STDOUT_FILENO, F_SETFL, flags_stdout | O_NONBLOCK)) == -1) |
| 433 |
|
{ |
| 434 |
|
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
| 435 |
|
goto cleanup; |
| 436 |
|
} |
| 437 |
|
|
| 438 |
#ifdef HAVE_SYS_EPOLL_H |
#ifdef HAVE_SYS_EPOLL_H |
| 439 |
epollfd = epoll_create1(0); |
epollfd = epoll_create1(0); |
| 440 |
if (epollfd < 0) |
if (epollfd < 0) |
| 441 |
{ |
{ |
| 442 |
log_error("epoll_create1() error (%d)\n", errno); |
log_error("epoll_create1() error (%d)\n", errno); |
| 443 |
return -1; |
goto cleanup; |
| 444 |
} |
} |
| 445 |
|
|
| 446 |
ev.events = EPOLLOUT | EPOLLET; |
ev.events = EPOLLOUT | EPOLLET; |
| 462 |
|
|
| 463 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 464 |
{ |
{ |
| 465 |
if ((ret = connect(sock, (struct sockaddr *)&sin, sizeof(sin))) < 0) |
if ((ret = connect(sock, res->ai_addr, res->ai_addrlen)) < 0) |
| 466 |
{ |
{ |
| 467 |
if (errno == EAGAIN || errno == EALREADY || errno == EINPROGRESS) |
if (errno == EAGAIN || errno == EALREADY || errno == EINPROGRESS) |
| 468 |
{ |
{ |
| 478 |
else |
else |
| 479 |
{ |
{ |
| 480 |
log_error("connect(socket) error (%d)\n", errno); |
log_error("connect(socket) error (%d)\n", errno); |
|
|
|
| 481 |
prints("\033[1;31m连接失败!\033[m\r\n"); |
prints("\033[1;31m连接失败!\033[m\r\n"); |
| 482 |
press_any_key(); |
press_any_key(); |
|
|
|
| 483 |
goto cleanup; |
goto cleanup; |
| 484 |
} |
} |
| 485 |
} |
} |
| 525 |
if (pfds[i].fd == sock && (pfds[i].revents & POLLOUT)) |
if (pfds[i].fd == sock && (pfds[i].revents & POLLOUT)) |
| 526 |
#endif |
#endif |
| 527 |
{ |
{ |
| 528 |
len = sizeof(error); |
socklen_t len = sizeof(error); |
| 529 |
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, (socklen_t *)&len) < 0) |
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0) |
| 530 |
{ |
{ |
| 531 |
log_error("getsockopt() error (%d) !\n", error); |
log_error("getsockopt() error (%d) !\n", errno); |
| 532 |
goto cleanup; |
goto cleanup; |
| 533 |
} |
} |
| 534 |
if (error == 0) |
if (error == 0) |
| 562 |
{ |
{ |
| 563 |
prints("\033[1;31m连接失败!\033[m\r\n"); |
prints("\033[1;31m连接失败!\033[m\r\n"); |
| 564 |
press_any_key(); |
press_any_key(); |
|
|
|
| 565 |
goto cleanup; |
goto cleanup; |
| 566 |
} |
} |
| 567 |
|
|
| 605 |
|
|
| 606 |
ssh_set_blocking(session, 0); |
ssh_set_blocking(session, 0); |
| 607 |
|
|
| 608 |
while (!SYS_server_exit) |
t_begin = time(NULL); |
| 609 |
|
ret = SSH_ERROR; |
| 610 |
|
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 611 |
{ |
{ |
| 612 |
ret = ssh_connect(session); |
ret = ssh_connect(session); |
| 613 |
if (ret == SSH_OK) |
if (ret == SSH_OK) |
| 614 |
{ |
{ |
| 615 |
break; |
break; |
| 616 |
} |
} |
| 617 |
else if (ret == SSH_ERROR) |
else if (ret == SSH_AGAIN) |
| 618 |
{ |
{ |
| 619 |
log_error("ssh_connect() error\n"); |
// log_error("ssh_connect() error: SSH_AGAIN\n"); |
| 620 |
|
} |
| 621 |
|
else // if (ret == SSH_ERROR) |
| 622 |
|
{ |
| 623 |
|
log_error("ssh_connect() error: SSH_ERROR\n"); |
| 624 |
goto cleanup; |
goto cleanup; |
| 625 |
} |
} |
| 626 |
} |
} |
| 627 |
|
if (ret != SSH_OK) |
| 628 |
|
{ |
| 629 |
|
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 630 |
|
press_any_key(); |
| 631 |
|
goto cleanup; |
| 632 |
|
} |
| 633 |
|
|
| 634 |
ret = ssh_session_is_known_server(session); |
ret = ssh_session_is_known_server(session); |
| 635 |
switch (ret) |
switch (ret) |
| 639 |
if (ssh_session_update_known_hosts(session) != SSH_OK) |
if (ssh_session_update_known_hosts(session) != SSH_OK) |
| 640 |
{ |
{ |
| 641 |
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); |
| 642 |
prints("\033[1;31m无法添加服务器证书\033[m"); |
prints("\033[1;31m无法添加服务器证书\033[m\r\n"); |
| 643 |
press_any_key(); |
press_any_key(); |
| 644 |
goto cleanup; |
goto cleanup; |
| 645 |
} |
} |
| 649 |
case SSH_KNOWN_HOSTS_CHANGED: |
case SSH_KNOWN_HOSTS_CHANGED: |
| 650 |
case SSH_KNOWN_HOSTS_OTHER: |
case SSH_KNOWN_HOSTS_OTHER: |
| 651 |
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); |
| 652 |
prints("\033[1;31m服务器证书已变更\033[m"); |
prints("\033[1;31m服务器证书已变更\033[m\r\n"); |
| 653 |
press_any_key(); |
press_any_key(); |
| 654 |
goto cleanup; |
goto cleanup; |
| 655 |
} |
} |
| 656 |
|
|
| 657 |
for (int i = 0; !SYS_server_exit;) |
ret = SSH_AUTH_ERROR; |
| 658 |
|
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 659 |
{ |
{ |
| 660 |
ret = ssh_userauth_password(session, NULL, remote_pass); |
ret = ssh_userauth_password(session, NULL, remote_pass); |
| 661 |
if (ret == SSH_AUTH_SUCCESS) |
if (ret == SSH_AUTH_SUCCESS) |
| 664 |
} |
} |
| 665 |
else if (ret == SSH_AUTH_AGAIN) |
else if (ret == SSH_AUTH_AGAIN) |
| 666 |
{ |
{ |
| 667 |
#ifdef _DEBUG |
// log_error("ssh_userauth_password() error: SSH_AUTH_AGAIN\n"); |
|
log_error("ssh_userauth_password() error: SSH_AUTH_AGAIN\n"); |
|
|
#endif |
|
| 668 |
} |
} |
| 669 |
else if (ret == SSH_AUTH_ERROR) |
else if (ret == SSH_AUTH_ERROR) |
| 670 |
{ |
{ |
| 671 |
log_error("ssh_userauth_password() error: %d\n", ret); |
log_error("ssh_userauth_password() error: SSH_AUTH_ERROR\n"); |
| 672 |
goto cleanup; |
goto cleanup; |
| 673 |
} |
} |
| 674 |
else // if (ret == SSH_AUTH_DENIED) |
else // if (ret == SSH_AUTH_DENIED) |
| 675 |
{ |
{ |
| 676 |
|
log_error("ssh_userauth_password() error: SSH_AUTH_DENIED\n"); |
| 677 |
prints("\033[1;31m身份验证失败!\033[m\r\n"); |
prints("\033[1;31m身份验证失败!\033[m\r\n"); |
| 678 |
i++; |
press_any_key(); |
| 679 |
if (i < BBS_login_retry_times) |
goto cleanup; |
|
{ |
|
|
prints("请输入密码: "); |
|
|
iflush(); |
|
|
if (str_input(remote_pass, sizeof(remote_pass), NOECHO) < 0) |
|
|
{ |
|
|
goto cleanup; |
|
|
} |
|
|
if (remote_pass[0] == '\0') |
|
|
{ |
|
|
goto cleanup; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
goto cleanup; |
|
|
} |
|
| 680 |
} |
} |
| 681 |
} |
} |
| 682 |
|
if (ret != SSH_AUTH_SUCCESS) |
| 683 |
|
{ |
| 684 |
|
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 685 |
|
press_any_key(); |
| 686 |
|
goto cleanup; |
| 687 |
|
} |
| 688 |
|
|
| 689 |
channel = ssh_channel_new(session); |
channel = ssh_channel_new(session); |
| 690 |
if (channel == NULL) |
if (channel == NULL) |
| 693 |
goto cleanup; |
goto cleanup; |
| 694 |
} |
} |
| 695 |
|
|
| 696 |
while (!SYS_server_exit) |
ret = SSH_ERROR; |
| 697 |
|
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 698 |
{ |
{ |
| 699 |
ret = ssh_channel_open_session(channel); |
ret = ssh_channel_open_session(channel); |
| 700 |
if (ret == SSH_OK) |
if (ret == SSH_OK) |
| 701 |
{ |
{ |
| 702 |
break; |
break; |
| 703 |
} |
} |
| 704 |
else if (ret == SSH_ERROR) |
else if (ret == SSH_AGAIN) |
| 705 |
|
{ |
| 706 |
|
// log_error("ssh_channel_open_session() error: SSH_AGAIN\n"); |
| 707 |
|
} |
| 708 |
|
else // if (ret == SSH_ERROR) |
| 709 |
{ |
{ |
| 710 |
log_error("ssh_channel_open_session() error\n"); |
log_error("ssh_channel_open_session() error: SSH_ERROR\n"); |
| 711 |
goto cleanup; |
goto cleanup; |
| 712 |
} |
} |
| 713 |
} |
} |
| 714 |
|
if (ret != SSH_OK) |
| 715 |
|
{ |
| 716 |
|
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 717 |
|
press_any_key(); |
| 718 |
|
goto cleanup; |
| 719 |
|
} |
| 720 |
|
|
| 721 |
while (!SYS_server_exit) |
ret = SSH_ERROR; |
| 722 |
|
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 723 |
{ |
{ |
| 724 |
ret = ssh_channel_request_pty(channel); |
ret = ssh_channel_request_pty(channel); |
| 725 |
if (ret == SSH_OK) |
if (ret == SSH_OK) |
| 726 |
{ |
{ |
| 727 |
break; |
break; |
| 728 |
} |
} |
| 729 |
else if (ret == SSH_ERROR) |
else if (ret == SSH_AGAIN) |
| 730 |
{ |
{ |
| 731 |
log_error("ssh_channel_request_pty() error\n"); |
// log_error("ssh_channel_request_pty() error: SSH_AGAIN\n"); |
| 732 |
|
} |
| 733 |
|
else // if (ret == SSH_ERROR) |
| 734 |
|
{ |
| 735 |
|
log_error("ssh_channel_request_pty() error: SSH_ERROR\n"); |
| 736 |
goto cleanup; |
goto cleanup; |
| 737 |
} |
} |
| 738 |
} |
} |
| 739 |
|
if (ret != SSH_OK) |
| 740 |
|
{ |
| 741 |
|
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 742 |
|
press_any_key(); |
| 743 |
|
goto cleanup; |
| 744 |
|
} |
| 745 |
|
|
| 746 |
while (!SYS_server_exit) |
ret = SSH_ERROR; |
| 747 |
|
while (!SYS_server_exit && time(NULL) - t_begin < SSH_CONNECT_TIMEOUT) |
| 748 |
{ |
{ |
| 749 |
ret = ssh_channel_request_shell(channel); |
ret = ssh_channel_request_shell(channel); |
| 750 |
if (ret == SSH_OK) |
if (ret == SSH_OK) |
| 751 |
{ |
{ |
| 752 |
break; |
break; |
| 753 |
} |
} |
| 754 |
else if (ret == SSH_ERROR) |
else if (ret == SSH_AGAIN) |
| 755 |
|
{ |
| 756 |
|
// log_error("ssh_channel_request_shell() error: SSH_AGAIN\n"); |
| 757 |
|
} |
| 758 |
|
else // if (ret == SSH_ERROR) |
| 759 |
{ |
{ |
| 760 |
log_error("ssh_channel_request_shell() error\n"); |
log_error("ssh_channel_request_shell() error: SSH_ERROR\n"); |
| 761 |
goto cleanup; |
goto cleanup; |
| 762 |
} |
} |
| 763 |
} |
} |
| 764 |
|
if (ret != SSH_OK) |
| 765 |
|
{ |
| 766 |
|
prints("\033[1;31m连接超时!\033[m\r\n"); |
| 767 |
|
press_any_key(); |
| 768 |
|
goto cleanup; |
| 769 |
|
} |
| 770 |
} |
} |
| 771 |
|
|
| 772 |
prints("\033[1;31m连接成功!\033[m\r\n"); |
prints("\033[1;31m连接成功!\033[m\r\n"); |
| 789 |
if (output_cd == (iconv_t)(-1)) |
if (output_cd == (iconv_t)(-1)) |
| 790 |
{ |
{ |
| 791 |
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); |
|
iconv_close(input_cd); |
|
| 792 |
goto cleanup; |
goto cleanup; |
| 793 |
} |
} |
| 794 |
|
|
| 817 |
{ |
{ |
| 818 |
if (SSH_v2 && ssh_channel_is_closed(SSH_channel)) |
if (SSH_v2 && ssh_channel_is_closed(SSH_channel)) |
| 819 |
{ |
{ |
| 820 |
log_error("SSH channel is closed\n"); |
log_debug("SSH channel is closed\n"); |
| 821 |
loop = 0; |
loop = 0; |
| 822 |
break; |
break; |
| 823 |
} |
} |
| 824 |
|
|
| 825 |
if (bbsnet_conf[n].use_ssh && ssh_channel_is_closed(channel)) |
if (bbsnet_conf[n].use_ssh && ssh_channel_is_closed(channel)) |
| 826 |
{ |
{ |
| 827 |
log_error("Remote SSH channel is closed\n"); |
log_debug("Remote SSH channel is closed\n"); |
| 828 |
loop = 0; |
loop = 0; |
| 829 |
break; |
break; |
| 830 |
} |
} |
| 867 |
for (int i = 0; i < nfds; i++) |
for (int i = 0; i < nfds; i++) |
| 868 |
{ |
{ |
| 869 |
#ifdef HAVE_SYS_EPOLL_H |
#ifdef HAVE_SYS_EPOLL_H |
| 870 |
if (events[i].data.fd == STDIN_FILENO) |
if (events[i].events & (EPOLLHUP | EPOLLERR)) |
| 871 |
|
#else |
| 872 |
|
if (pfds[i].revents & (POLLHUP | POLLERR)) |
| 873 |
|
#endif |
| 874 |
|
{ |
| 875 |
|
#ifdef HAVE_SYS_EPOLL_H |
| 876 |
|
log_debug("FD (%d) error events (%d)\n", events[i].data.fd, events[i].events); |
| 877 |
|
#else |
| 878 |
|
log_debug("FD (%d) error events (%d)\n", pfds[i].fd, pfds[i].revents); |
| 879 |
|
#endif |
| 880 |
|
loop = 0; |
| 881 |
|
break; |
| 882 |
|
} |
| 883 |
|
|
| 884 |
|
#ifdef HAVE_SYS_EPOLL_H |
| 885 |
|
if (events[i].data.fd == STDIN_FILENO && (events[i].events & EPOLLIN)) |
| 886 |
#else |
#else |
| 887 |
if (pfds[i].fd == STDIN_FILENO && (pfds[i].revents & POLLIN)) |
if (pfds[i].fd == STDIN_FILENO && (pfds[i].revents & POLLIN)) |
| 888 |
#endif |
#endif |
| 916 |
} |
} |
| 917 |
|
|
| 918 |
#ifdef HAVE_SYS_EPOLL_H |
#ifdef HAVE_SYS_EPOLL_H |
| 919 |
if (events[i].data.fd == STDOUT_FILENO) |
if (events[i].data.fd == STDOUT_FILENO && (events[i].events & EPOLLOUT)) |
| 920 |
#else |
#else |
| 921 |
if (pfds[i].fd == STDOUT_FILENO && (pfds[i].revents & POLLOUT)) |
if (pfds[i].fd == STDOUT_FILENO && (pfds[i].revents & POLLOUT)) |
| 922 |
#endif |
#endif |
| 934 |
ret = ssh_channel_read_nonblocking(SSH_channel, input_buf + input_buf_len, sizeof(input_buf) - (uint32_t)input_buf_len, 0); |
ret = ssh_channel_read_nonblocking(SSH_channel, input_buf + input_buf_len, sizeof(input_buf) - (uint32_t)input_buf_len, 0); |
| 935 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 936 |
{ |
{ |
| 937 |
log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session)); |
log_debug("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(SSH_session)); |
| 938 |
loop = 0; |
loop = 0; |
| 939 |
break; |
break; |
| 940 |
} |
} |
| 979 |
} |
} |
| 980 |
else if (ret == 0) // broken pipe |
else if (ret == 0) // broken pipe |
| 981 |
{ |
{ |
| 982 |
#ifdef _DEBUG |
log_debug("read(STDIN) EOF\n"); |
|
log_error("read(STDIN) EOF\n"); |
|
|
#endif |
|
| 983 |
stdin_read_wait = 0; |
stdin_read_wait = 0; |
| 984 |
loop = 0; |
loop = 0; |
| 985 |
break; |
break; |
| 1008 |
#ifdef _DEBUG |
#ifdef _DEBUG |
| 1009 |
for (int j = input_buf_offset; j < input_buf_len; j++) |
for (int j = input_buf_offset; j < input_buf_len; j++) |
| 1010 |
{ |
{ |
| 1011 |
log_error("Debug input: <--[%u]\n", (input_buf[j] + 256) % 256); |
log_debug("input: <--[%u]\n", (input_buf[j] + 256) % 256); |
| 1012 |
} |
} |
| 1013 |
#endif |
#endif |
| 1014 |
|
|
| 1023 |
#ifdef _DEBUG |
#ifdef _DEBUG |
| 1024 |
for (int j = input_conv_offset; j < input_conv_len; j++) |
for (int j = input_conv_offset; j < input_conv_len; j++) |
| 1025 |
{ |
{ |
| 1026 |
log_error("Debug input_conv: <--[%u]\n", (input_conv[j] + 256) % 256); |
log_debug("input_conv: <--[%u]\n", (input_conv[j] + 256) % 256); |
| 1027 |
} |
} |
| 1028 |
#endif |
#endif |
| 1029 |
} |
} |
| 1035 |
ret = ssh_channel_write(channel, input_conv + input_conv_offset, (uint32_t)(input_conv_len - input_conv_offset)); |
ret = ssh_channel_write(channel, input_conv + input_conv_offset, (uint32_t)(input_conv_len - input_conv_offset)); |
| 1036 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 1037 |
{ |
{ |
| 1038 |
log_error("ssh_channel_write() error: %s\n", ssh_get_error(session)); |
log_debug("ssh_channel_write() error: %s\n", ssh_get_error(session)); |
| 1039 |
loop = 0; |
loop = 0; |
| 1040 |
break; |
break; |
| 1041 |
} |
} |
| 1057 |
} |
} |
| 1058 |
else |
else |
| 1059 |
{ |
{ |
| 1060 |
log_error("write(socket) error (%d)\n", errno); |
log_debug("write(socket) error (%d)\n", errno); |
| 1061 |
loop = 0; |
loop = 0; |
| 1062 |
break; |
break; |
| 1063 |
} |
} |
| 1064 |
} |
} |
| 1065 |
else if (ret == 0) // broken pipe |
else if (ret == 0) // broken pipe |
| 1066 |
{ |
{ |
| 1067 |
#ifdef _DEBUG |
log_debug("write(socket) EOF\n"); |
|
log_error("write(socket) EOF\n"); |
|
|
#endif |
|
| 1068 |
sock_write_wait = 0; |
sock_write_wait = 0; |
| 1069 |
loop = 0; |
loop = 0; |
| 1070 |
break; |
break; |
| 1093 |
(uint32_t)(sizeof(output_buf) - (size_t)output_buf_len), 0); |
(uint32_t)(sizeof(output_buf) - (size_t)output_buf_len), 0); |
| 1094 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 1095 |
{ |
{ |
| 1096 |
log_error("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(session)); |
log_debug("ssh_channel_read_nonblocking() error: %s\n", ssh_get_error(session)); |
| 1097 |
loop = 0; |
loop = 0; |
| 1098 |
break; |
break; |
| 1099 |
} |
} |
| 1126 |
} |
} |
| 1127 |
else |
else |
| 1128 |
{ |
{ |
| 1129 |
log_error("read(socket) error (%d)\n", errno); |
log_debug("read(socket) error (%d)\n", errno); |
| 1130 |
loop = 0; |
loop = 0; |
| 1131 |
break; |
break; |
| 1132 |
} |
} |
| 1133 |
} |
} |
| 1134 |
else if (ret == 0) // broken pipe |
else if (ret == 0) // broken pipe |
| 1135 |
{ |
{ |
| 1136 |
#ifdef _DEBUG |
log_debug("read(socket) EOF\n"); |
|
log_error("read(socket) EOF\n"); |
|
|
#endif |
|
| 1137 |
sock_read_wait = 0; |
sock_read_wait = 0; |
| 1138 |
loop = 0; |
loop = 0; |
| 1139 |
break; |
break; |
| 1165 |
ret = ssh_channel_write(SSH_channel, output_conv + output_conv_offset, (uint32_t)(output_conv_len - output_conv_offset)); |
ret = ssh_channel_write(SSH_channel, output_conv + output_conv_offset, (uint32_t)(output_conv_len - output_conv_offset)); |
| 1166 |
if (ret == SSH_ERROR) |
if (ret == SSH_ERROR) |
| 1167 |
{ |
{ |
| 1168 |
log_error("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session)); |
log_debug("ssh_channel_write() error: %s\n", ssh_get_error(SSH_session)); |
| 1169 |
loop = 0; |
loop = 0; |
| 1170 |
break; |
break; |
| 1171 |
} |
} |
| 1187 |
} |
} |
| 1188 |
else |
else |
| 1189 |
{ |
{ |
| 1190 |
log_error("write(STDOUT) error (%d)\n", errno); |
log_debug("write(STDOUT) error (%d)\n", errno); |
| 1191 |
loop = 0; |
loop = 0; |
| 1192 |
break; |
break; |
| 1193 |
} |
} |
| 1194 |
} |
} |
| 1195 |
else if (ret == 0) // broken pipe |
else if (ret == 0) // broken pipe |
| 1196 |
{ |
{ |
| 1197 |
#ifdef _DEBUG |
log_debug("write(STDOUT) EOF\n"); |
|
log_error("write(STDOUT) EOF\n"); |
|
|
#endif |
|
| 1198 |
stdout_write_wait = 0; |
stdout_write_wait = 0; |
| 1199 |
loop = 0; |
loop = 0; |
| 1200 |
break; |
break; |
| 1214 |
} |
} |
| 1215 |
} |
} |
| 1216 |
|
|
|
iconv_close(input_cd); |
|
|
iconv_close(output_cd); |
|
|
|
|
| 1217 |
cleanup: |
cleanup: |
| 1218 |
|
if (input_cd != (iconv_t)(-1)) |
| 1219 |
|
{ |
| 1220 |
|
iconv_close(input_cd); |
| 1221 |
|
} |
| 1222 |
|
if (output_cd != (iconv_t)(-1)) |
| 1223 |
|
{ |
| 1224 |
|
iconv_close(output_cd); |
| 1225 |
|
} |
| 1226 |
|
|
| 1227 |
#ifdef HAVE_SYS_EPOLL_H |
#ifdef HAVE_SYS_EPOLL_H |
| 1228 |
if (close(epollfd) < 0) |
if (epollfd != -1 && close(epollfd) < 0) |
| 1229 |
{ |
{ |
| 1230 |
log_error("close(epoll) error (%d)\n"); |
log_error("close(epoll) error (%d)\n"); |
| 1231 |
} |
} |
| 1233 |
|
|
| 1234 |
if (bbsnet_conf[n].use_ssh) |
if (bbsnet_conf[n].use_ssh) |
| 1235 |
{ |
{ |
| 1236 |
ssh_channel_free(channel); |
if (channel != NULL) |
| 1237 |
ssh_disconnect(session); |
{ |
| 1238 |
ssh_free(session); |
ssh_channel_free(channel); |
| 1239 |
|
} |
| 1240 |
|
if (session != NULL) |
| 1241 |
|
{ |
| 1242 |
|
ssh_disconnect(session); |
| 1243 |
|
ssh_free(session); |
| 1244 |
|
} |
| 1245 |
} |
} |
| 1246 |
|
|
| 1247 |
// Restore STDIN/STDOUT flags |
// Restore STDIN/STDOUT flags |
| 1248 |
fcntl(STDIN_FILENO, F_SETFL, flags_stdin); |
if (flags_stdin != -1 && fcntl(STDIN_FILENO, F_SETFL, flags_stdin) == -1) |
| 1249 |
fcntl(STDOUT_FILENO, F_SETFL, flags_stdout); |
{ |
| 1250 |
|
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
| 1251 |
|
} |
| 1252 |
|
if (flags_stdout != -1 && fcntl(STDOUT_FILENO, F_SETFL, flags_stdout) == -1) |
| 1253 |
|
{ |
| 1254 |
|
log_error("fcntl(F_SETFL) error (%d)\n", errno); |
| 1255 |
|
} |
| 1256 |
|
|
| 1257 |
if (close(sock) == -1) |
if (sock != -1 && close(sock) == -1) |
| 1258 |
{ |
{ |
| 1259 |
log_error("Close socket failed\n"); |
log_error("Close socket failed\n"); |
| 1260 |
} |
} |
| 1261 |
|
|
| 1262 |
|
if (res) |
| 1263 |
|
{ |
| 1264 |
|
freeaddrinfo(res); |
| 1265 |
|
} |
| 1266 |
|
|
| 1267 |
t_used = time(NULL) - t_used; |
t_used = time(NULL) - t_used; |
| 1268 |
tm_used = gmtime(&t_used); |
tm_used = gmtime(&t_used); |
| 1269 |
|
|
| 1270 |
log_common("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", |
log_common("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", |
| 1271 |
tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, |
tm_used->tm_yday, tm_used->tm_hour, tm_used->tm_min, tm_used->tm_sec); |
|
tm_used->tm_sec); |
|
| 1272 |
|
|
| 1273 |
BBS_last_access_tm = time(NULL); |
BBS_last_access_tm = time(NULL); |
| 1274 |
|
|
| 1306 |
|
|
| 1307 |
moveto(20, 1); |
moveto(20, 1); |
| 1308 |
clrtoeol(); |
clrtoeol(); |
| 1309 |
prints("|\033[1m单位: \033[1;33m%s\033[m%*s 站名: \033[1;33m%s\033[m", |
prints("|\033[1m单位: \033[1;33m%s\033[m%*s 站名: \033[1;33m%s\033[m%*s 类型: \033[1;33m%s\033[m", |
| 1310 |
bbsnet_conf[i].org_name, 20 - str_length(bbsnet_conf[i].org_name, 1), "", bbsnet_conf[i].site_name); |
bbsnet_conf[i].org_name, 20 - str_length(bbsnet_conf[i].org_name, 1), "", |
| 1311 |
|
bbsnet_conf[i].site_name, 20 - str_length(bbsnet_conf[i].site_name, 1), "", |
| 1312 |
|
(bbsnet_conf[i].use_ssh ? "SSH" : "Telnet")); |
| 1313 |
moveto(20, 80); |
moveto(20, 80); |
| 1314 |
prints("|"); |
prints("|"); |
| 1315 |
moveto(21, 1); |
moveto(21, 1); |
| 1316 |
clrtoeol(); |
clrtoeol(); |
| 1317 |
prints("|\033[1m连往: \033[1;33m%-20s\033[m 端口: \033[1;33m%-5d\033[m 类型: \033[1;33m%s\033[m", |
prints("|\033[1m连往: \033[1;33m%-20s\033[m 端口: \033[1;33m%-5s\033[m 编码: \033[1;33m%s\033[m", |
| 1318 |
bbsnet_conf[i].host_name, bbsnet_conf[i].port, (bbsnet_conf[i].use_ssh ? "SSH" : "Telnet")); |
bbsnet_conf[i].host_name, bbsnet_conf[i].port, bbsnet_conf[i].charset); |
| 1319 |
moveto(21, 80); |
moveto(21, 80); |
| 1320 |
prints("|"); |
prints("|"); |
| 1321 |
iflush(); |
iflush(); |
| 1327 |
{ |
{ |
| 1328 |
int ch, i; |
int ch, i; |
| 1329 |
|
|
| 1330 |
load_bbsnet_conf(CONF_BBSNET); |
if (load_bbsnet_conf(CONF_BBSNET) < 0) |
| 1331 |
|
{ |
| 1332 |
|
clearscr(); |
| 1333 |
|
moveto(1, 1); |
| 1334 |
|
prints("加载穿梭配置失败!"); |
| 1335 |
|
press_any_key(); |
| 1336 |
|
return -1; |
| 1337 |
|
} |
| 1338 |
|
|
| 1339 |
bbsnet_refresh(); |
bbsnet_refresh(); |
| 1340 |
display_menu(&bbsnet_menu); |
display_menu(&bbsnet_menu); |
| 1352 |
switch (ch) |
switch (ch) |
| 1353 |
{ |
{ |
| 1354 |
case KEY_NULL: // broken pipe |
case KEY_NULL: // broken pipe |
| 1355 |
log_error("KEY_NULL\n"); |
log_debug("KEY_NULL\n"); |
| 1356 |
goto cleanup; |
goto cleanup; |
| 1357 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 1358 |
if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) |
if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) |