/[LeafOK_CVS]/lbbs/src/login.c
ViewVC logotype

Diff of /lbbs/src/login.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.54 by sysadm, Wed Oct 1 02:21:15 2025 UTC Revision 1.64 by sysadm, Tue Nov 4 11:20:16 2025 UTC
# Line 30  Line 30 
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    static const int BBS_username_min_len = 3; // common len = 5, special len = 3
36    static const int BBS_password_min_len = 5; // legacy len = 5, current len = 6
37    
38  int bbs_login(void)  int bbs_login(void)
39  {  {
# Line 113  int check_user(const char *username, con Line 117  int check_user(const char *username, con
117          // Verify format          // Verify format
118          for (i = 0; ok && username[i] != '\0'; i++)          for (i = 0; ok && username[i] != '\0'; i++)
119          {          {
120                  if (!(isalpha(username[i]) || (i > 0 && isdigit(username[i]))))                  if (!(isalpha(username[i]) || (i > 0 && (isdigit(username[i]) || username[i] == '_'))))
121                  {                  {
122                          ok = 0;                          ok = 0;
123                  }                  }
124          }          }
125          if (ok && (i < 3 || i > 12))          if (ok && (i < BBS_username_min_len || i > BBS_username_max_len))
126          {          {
127                  ok = 0;                  ok = 0;
128          }          }
# Line 129  int check_user(const char *username, con Line 133  int check_user(const char *username, con
133                          ok = 0;                          ok = 0;
134                  }                  }
135          }          }
136          if (ok && (i < 5 || i > 12))          if (ok && (i < BBS_password_min_len || i > BBS_password_max_len))
137          {          {
138                  ok = 0;                  ok = 0;
139          }          }
# Line 487  int user_online_add(MYSQL *db) Line 491  int user_online_add(MYSQL *db)
491  {  {
492          char sql[SQL_BUFFER_LEN];          char sql[SQL_BUFFER_LEN];
493    
494          if (user_online_del(db) != 0)          snprintf(sql, sizeof(sql),
495                             "INSERT INTO visit_log(dt, IP) VALUES(NOW(), '%s')",
496                             hostaddr_client);
497            if (mysql_query(db, sql) != 0)
498          {          {
499                    log_error("Add visit log error: %s\n", mysql_error(db));
500                  return -1;                  return -1;
501          }          }
502    
503            if (user_online_del(db) != 0)
504            {
505                    return -2;
506            }
507    
508          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
509                           "INSERT INTO user_online(SID, UID, ip, login_tm, last_tm) "                           "INSERT INTO user_online(SID, UID, ip, current_action, login_tm, last_tm) "
510                           "VALUES('Telnet_Process_%d', %d, '%s', NOW(), NOW())",                           "VALUES('Telnet_Process_%d', %d, '%s', 'LOGIN', NOW(), NOW())",
511                           getpid(), BBS_priv.uid, hostaddr_client);                           getpid(), BBS_priv.uid, hostaddr_client);
512          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
513          {          {
514                  log_error("Add user_online error: %s\n", mysql_error(db));                  log_error("Add user_online error: %s\n", mysql_error(db));
515                  return -1;                  return -3;
516          }          }
517    
518          return 0;          return 0;
# Line 521  int user_online_del(MYSQL *db) Line 534  int user_online_del(MYSQL *db)
534          return 0;          return 0;
535  }  }
536    
537    int user_online_exp(MYSQL *db)
538    {
539            char sql[SQL_BUFFER_LEN];
540    
541            // +1 exp for every 5 minutes online since last logout
542            // but at most 24 hours worth of exp can be gained in Telnet session
543            snprintf(sql, sizeof(sql),
544                             "UPDATE user_pubinfo SET exp = exp + FLOOR(LEAST(TIMESTAMPDIFF("
545                             "SECOND, GREATEST(last_login_dt, IF(last_logout_dt IS NULL, last_login_dt, last_logout_dt)), NOW()"
546                             ") / 60 / 5, 12 * 24)), last_logout_dt = NOW() "
547                             "WHERE UID = %d",
548                             BBS_priv.uid);
549            if (mysql_query(db, sql) != 0)
550            {
551                    log_error("Update user_pubinfo error: %s\n", mysql_error(db));
552                    return -1;
553            }
554    
555            return 0;
556    }
557    
558  int user_online_update(const char *action)  int user_online_update(const char *action)
559  {  {
560          MYSQL *db = NULL;          MYSQL *db = NULL;
561          char sql[SQL_BUFFER_LEN];          char sql[SQL_BUFFER_LEN];
562    
563          if (strcmp(BBS_current_action, action) == 0 &&          if ((action == NULL || strcmp(BBS_current_action, action) == 0) &&
564                  time(NULL) - BBS_current_action_tm < BBS_current_action_refresh_interval) // No change                  time(NULL) - BBS_current_action_tm < BBS_current_action_refresh_interval) // No change
565          {          {
566                  return 0;                  return 0;
567          }          }
568    
569          strncpy(BBS_current_action, action, sizeof(BBS_current_action) - 1);          if (action != NULL)
570          BBS_current_action[sizeof(BBS_current_action) - 1] = '\0';          {
571                    strncpy(BBS_current_action, action, sizeof(BBS_current_action) - 1);
572                    BBS_current_action[sizeof(BBS_current_action) - 1] = '\0';
573            }
574    
575          BBS_current_action_tm = time(NULL);          BBS_current_action_tm = time(NULL);
576    
577          db = db_open();          db = db_open();
# Line 544  int user_online_update(const char *actio Line 582  int user_online_update(const char *actio
582          }          }
583    
584          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
585                           "UPDATE user_online SET current_action = '%s', last_tm=NOW() "                           "UPDATE user_online SET current_action = '%s', last_tm = NOW() "
586                           "WHERE SID = 'Telnet_Process_%d'",                           "WHERE SID = 'Telnet_Process_%d'",
587                           BBS_current_action, getpid());                           BBS_current_action, getpid());
588          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1