| 27 |
#include <errno.h> |
#include <errno.h> |
| 28 |
#include <ctype.h> |
#include <ctype.h> |
| 29 |
#include <string.h> |
#include <string.h> |
|
#include <mysql.h> |
|
| 30 |
#include <regex.h> |
#include <regex.h> |
| 31 |
#include <stdlib.h> |
#include <stdlib.h> |
| 32 |
#include <unistd.h> |
#include <unistd.h> |
| 33 |
|
#include <mysql/mysql.h> |
| 34 |
|
|
| 35 |
int bbs_login(MYSQL *db) |
int bbs_login(MYSQL *db) |
| 36 |
{ |
{ |
| 37 |
char username[BBS_username_max_len + 1]; |
char username[BBS_username_max_len + 1]; |
| 38 |
char password[BBS_password_max_len + 1]; |
char password[BBS_password_max_len + 1]; |
| 39 |
int count = 0; |
int i = 0; |
| 40 |
int ok = 0; |
int ok = 0; |
| 41 |
|
|
| 42 |
for (; !SYS_server_exit && !ok && count < 3; count++) |
for (; !SYS_server_exit && !ok && i < BBS_login_retry_times; i++) |
| 43 |
{ |
{ |
| 44 |
prints("\033[1;33mÇëÊäÈëÕʺÅ\033[m(ÊÔÓÃÇëÊäÈë`\033[1;36mguest\033[m', " |
prints("\033[1;33mÇëÊäÈëÕʺÅ\033[m(ÊÔÓÃÇëÊäÈë`\033[1;36mguest\033[m', " |
| 45 |
"×¢²áÇëÊäÈë`\033[1;31mnew\033[m'): "); |
"×¢²áÇëÊäÈë`\033[1;31mnew\033[m'): "); |
| 85 |
return -1; |
return -1; |
| 86 |
} |
} |
| 87 |
|
|
| 88 |
log_std("User \"%s\"(%ld) login from %s:%d\n", |
log_common("User \"%s\"(%ld) login from %s:%d\n", |
| 89 |
BBS_username, BBS_priv.uid, hostaddr_client, port_client); |
BBS_username, BBS_priv.uid, hostaddr_client, port_client); |
| 90 |
|
|
| 91 |
return 0; |
return 0; |
| 92 |
} |
} |
| 93 |
|
|
| 94 |
int check_user(MYSQL *db, char *username, char *password) |
int check_user(MYSQL *db, const char *username, const char *password) |
| 95 |
{ |
{ |
| 96 |
MYSQL_RES *rs; |
MYSQL_RES *rs; |
| 97 |
MYSQL_ROW row; |
MYSQL_ROW row; |
| 98 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 99 |
int ret; |
int ret; |
| 100 |
long BBS_uid = 0; |
int BBS_uid = 0; |
| 101 |
char client_addr[IP_ADDR_LEN]; |
char client_addr[IP_ADDR_LEN]; |
| 102 |
int i; |
int i; |
| 103 |
int ok = 1; |
int ok = 1; |
| 222 |
} |
} |
| 223 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 224 |
{ |
{ |
| 225 |
BBS_uid = atol(row[0]); |
BBS_uid = atoi(row[0]); |
| 226 |
strncpy(BBS_username, row[1], sizeof(BBS_username) - 1); |
strncpy(BBS_username, row[1], sizeof(BBS_username) - 1); |
| 227 |
BBS_username[sizeof(BBS_username) - 1] = '\0'; |
BBS_username[sizeof(BBS_username) - 1] = '\0'; |
| 228 |
int p_login = atoi(row[2]); |
int p_login = atoi(row[2]); |
| 232 |
// Add user login log |
// Add user login log |
| 233 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 234 |
"INSERT INTO user_login_log(UID, login_dt, login_ip) " |
"INSERT INTO user_login_log(UID, login_dt, login_ip) " |
| 235 |
"VALUES(%ld, NOW(), '%s')", |
"VALUES(%d, NOW(), '%s')", |
| 236 |
BBS_uid, hostaddr_client); |
BBS_uid, hostaddr_client); |
| 237 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 238 |
{ |
{ |
| 308 |
|
|
| 309 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 310 |
"UPDATE user_pubinfo SET visit_count = visit_count + 1, " |
"UPDATE user_pubinfo SET visit_count = visit_count + 1, " |
| 311 |
"last_login_dt = NOW() WHERE UID = %ld", |
"last_login_dt = NOW() WHERE UID = %d", |
| 312 |
BBS_uid); |
BBS_uid); |
| 313 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 314 |
{ |
{ |
| 342 |
return 0; |
return 0; |
| 343 |
} |
} |
| 344 |
|
|
| 345 |
int load_user_info(MYSQL *db, long int BBS_uid) |
int load_user_info(MYSQL *db, int BBS_uid) |
| 346 |
{ |
{ |
| 347 |
MYSQL_RES *rs; |
MYSQL_RES *rs; |
| 348 |
MYSQL_ROW row; |
MYSQL_ROW row; |
| 352 |
|
|
| 353 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 354 |
"SELECT life, UNIX_TIMESTAMP(last_login_dt), user_timezone " |
"SELECT life, UNIX_TIMESTAMP(last_login_dt), user_timezone " |
| 355 |
"FROM user_pubinfo WHERE UID = %ld", |
"FROM user_pubinfo WHERE UID = %d", |
| 356 |
BBS_uid); |
BBS_uid); |
| 357 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 358 |
{ |
{ |
| 424 |
|
|
| 425 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 426 |
"INSERT INTO user_online(SID, UID, ip, login_tm, last_tm) " |
"INSERT INTO user_online(SID, UID, ip, login_tm, last_tm) " |
| 427 |
"VALUES('Telnet_Process_%d', %ld, '%s', NOW(), NOW())", |
"VALUES('Telnet_Process_%d', %d, '%s', NOW(), NOW())", |
| 428 |
getpid(), BBS_priv.uid, hostaddr_client); |
getpid(), BBS_priv.uid, hostaddr_client); |
| 429 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 430 |
{ |
{ |