| 30 |
#include <regex.h> |
#include <regex.h> |
| 31 |
#include <unistd.h> |
#include <unistd.h> |
| 32 |
#include <mysql/mysql.h> |
#include <mysql/mysql.h> |
| 33 |
|
#include <sys/param.h> |
| 34 |
|
|
| 35 |
int bbs_login(void) |
int bbs_login(void) |
| 36 |
{ |
{ |
| 214 |
} |
} |
| 215 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 216 |
{ |
{ |
| 217 |
if (atoi(row[0]) >= 3) |
if (atoi(row[0]) >= BBS_allowed_login_failures_per_account) |
| 218 |
{ |
{ |
| 219 |
prints("\033[1;31m账户存在多次失败登陆尝试,请使用Web方式登录解锁\033[m\r\n"); |
prints("\033[1;31m账户存在多次失败登陆尝试,请使用Web方式登录解锁\033[m\r\n"); |
| 220 |
ret = 1; |
ret = 1; |
| 488 |
{ |
{ |
| 489 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 490 |
|
|
| 491 |
if (user_online_del(db) != 0) |
snprintf(sql, sizeof(sql), |
| 492 |
|
"INSERT INTO visit_log(dt, IP) VALUES(NOW(), '%s')", |
| 493 |
|
hostaddr_client); |
| 494 |
|
if (mysql_query(db, sql) != 0) |
| 495 |
{ |
{ |
| 496 |
|
log_error("Add visit log error: %s\n", mysql_error(db)); |
| 497 |
return -1; |
return -1; |
| 498 |
} |
} |
| 499 |
|
|
| 500 |
|
if (user_online_del(db) != 0) |
| 501 |
|
{ |
| 502 |
|
return -2; |
| 503 |
|
} |
| 504 |
|
|
| 505 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 506 |
"INSERT INTO user_online(SID, UID, ip, login_tm, last_tm) " |
"INSERT INTO user_online(SID, UID, ip, current_action, login_tm, last_tm) " |
| 507 |
"VALUES('Telnet_Process_%d', %d, '%s', NOW(), NOW())", |
"VALUES('Telnet_Process_%d', %d, '%s', 'LOGIN', NOW(), NOW())", |
| 508 |
getpid(), BBS_priv.uid, hostaddr_client); |
getpid(), BBS_priv.uid, hostaddr_client); |
| 509 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 510 |
{ |
{ |
| 511 |
log_error("Add user_online error: %s\n", mysql_error(db)); |
log_error("Add user_online error: %s\n", mysql_error(db)); |
| 512 |
return -1; |
return -3; |
| 513 |
} |
} |
| 514 |
|
|
| 515 |
return 0; |
return 0; |
| 531 |
return 0; |
return 0; |
| 532 |
} |
} |
| 533 |
|
|
| 534 |
|
int user_online_exp(MYSQL *db) |
| 535 |
|
{ |
| 536 |
|
char sql[SQL_BUFFER_LEN]; |
| 537 |
|
|
| 538 |
|
// +1 exp for every 5 minutes online since last logout |
| 539 |
|
// but at most 24 hours worth of exp can be gained in Telnet session |
| 540 |
|
snprintf(sql, sizeof(sql), |
| 541 |
|
"UPDATE user_pubinfo SET exp = exp + FLOOR(LEAST(TIMESTAMPDIFF(" |
| 542 |
|
"SECOND, GREATEST(last_login_dt, IF(last_logout_dt IS NULL, last_login_dt, last_logout_dt)), NOW()" |
| 543 |
|
") / 60 / 5, 12 * 24)), last_logout_dt = NOW() " |
| 544 |
|
"WHERE UID = %d", |
| 545 |
|
BBS_priv.uid); |
| 546 |
|
if (mysql_query(db, sql) != 0) |
| 547 |
|
{ |
| 548 |
|
log_error("Update user_pubinfo error: %s\n", mysql_error(db)); |
| 549 |
|
return -1; |
| 550 |
|
} |
| 551 |
|
|
| 552 |
|
return 0; |
| 553 |
|
} |
| 554 |
|
|
| 555 |
int user_online_update(const char *action) |
int user_online_update(const char *action) |
| 556 |
{ |
{ |
| 557 |
MYSQL *db = NULL; |
MYSQL *db = NULL; |
| 558 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 559 |
|
|
| 560 |
if (strcmp(BBS_current_action, action) == 0) // No change |
if ((action == NULL || strcmp(BBS_current_action, action) == 0) && |
| 561 |
|
time(NULL) - BBS_current_action_tm < BBS_current_action_refresh_interval) // No change |
| 562 |
{ |
{ |
| 563 |
return 0; |
return 0; |
| 564 |
} |
} |
| 565 |
|
|
| 566 |
strncpy(BBS_current_action, action, sizeof(BBS_current_action) - 1); |
if (action != NULL) |
| 567 |
BBS_current_action[sizeof(BBS_current_action) - 1] = '\0'; |
{ |
| 568 |
|
strncpy(BBS_current_action, action, sizeof(BBS_current_action) - 1); |
| 569 |
|
BBS_current_action[sizeof(BBS_current_action) - 1] = '\0'; |
| 570 |
|
} |
| 571 |
|
|
| 572 |
|
BBS_current_action_tm = time(NULL); |
| 573 |
|
|
| 574 |
db = db_open(); |
db = db_open(); |
| 575 |
if (db == NULL) |
if (db == NULL) |