home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / lora299s.zip / LUSER.CPP < prev    next >
C/C++ Source or Header  |  1998-05-12  |  4KB  |  124 lines

  1.  
  2. // LoraBBS Version 2.99 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include "_ldefs.h"
  20. #include "lora_api.h"
  21.  
  22. VOID PurgeUsers (USHORT Days, USHORT Level)
  23. {
  24.    USHORT i;
  25.    CHAR Temp[64];
  26.    ULONG Today;
  27.    struct tm *ltm;
  28.    class TUser *User;
  29.  
  30.    printf (" * Purging Users\n");
  31.    Today = time (NULL);
  32.  
  33.    if ((User = new TUser ("users")) != NULL) {
  34.       if (User->First () == TRUE)
  35.          do {
  36.             if (Level == 0 || User->Level < Level) {
  37.                i = (USHORT)((Today - User->LastCall) / 86400L);
  38.                if (i >= Days) {
  39.                   ltm = localtime ((time_t *)&User->LastCall);
  40.                   strcpy (Temp, asctime (ltm));
  41.                   Temp[strlen (Temp) - 1] = '\0';
  42.                   printf (" +-- %-30.30s Last: %s (%u days)\n", User->Name, Temp, i);
  43.                   User->Delete ();
  44.                }
  45.             }
  46.          } while (User->Next () == TRUE);
  47.       delete User;
  48.    }
  49. }
  50.  
  51. VOID PackUsers (VOID)
  52. {
  53.    class TUser *User;
  54.  
  55.    printf (" * Pack (Compressing) Users\n");
  56.  
  57.    if ((User = new TUser ("users")) != NULL) {
  58.       User->Pack ();
  59.       delete User;
  60.    }
  61. }
  62.  
  63. void main (int argc, char *argv[])
  64. {
  65.    int i;
  66.    USHORT Pack, Purge, Level;
  67.  
  68.    Pack = FALSE;
  69.    Purge = Level = 0;
  70.  
  71.    printf ("\nLUSER; %s v%s - User maintenance utility\n", NAME, VERSION);
  72.    printf ("       Copyright (c) 1991-96 by Marco Maccaferri. All Rights Reserved.\n\n");
  73.  
  74. /*
  75.    if (ValidateKey ("bbs", NULL, NULL) == KEY_UNREGISTERED) {
  76.       printf ("* * *     WARNING: No license key found    * * *\n");
  77.       if ((i = CheckExpiration ()) == 0) {
  78.          printf ("* * *   This evaluation copy has expired   * * *\n\a\n");
  79.           exit (0);
  80.       }
  81.       else
  82.          printf ("* * * You have %2d days left for evaluation * * * \n\a\n", i);
  83.    }
  84. */
  85.  
  86.    if (argc <= 1) {
  87.       printf (" * Command-line parameters:\n\n");
  88.  
  89.       printf ("        -P        Pack (compress) user file\n");
  90.       printf ("        -D[n]     Delete users who haven't called in [n] days\n");
  91.       printf ("        -M[s]     Only purge users with security level less than [s]\n");
  92.  
  93.       printf ("\n * Please refer to the documentation for a more complete command summary\n\n");
  94.    }
  95.    else {
  96.       for (i = 1; i < argc; i++) {
  97.          if (argv[i][0] == '-' || argv[i][0] == '/') {
  98.             switch (toupper (argv[i][1])) {
  99.                case 'D':
  100.                   Purge = (USHORT)atoi (&argv[i][2]);
  101.                   break;
  102.                case 'M':
  103.                   Level = (USHORT)atoi (&argv[i][2]);
  104.                   break;
  105.                case 'P':
  106.                   Pack = TRUE;
  107.                   break;
  108.             }
  109.          }
  110.       }
  111.  
  112.       if (Purge != 0)
  113.          PurgeUsers (Purge, Level);
  114.       if (Pack == TRUE)
  115.          PackUsers ();
  116.  
  117.       if (Purge != 0 || Pack == TRUE)
  118.          printf (" * Done\n\n");
  119.       else
  120.          printf (" * Nothing to do\n\n");
  121.    }
  122. }
  123.  
  124.