home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / MAINT.C < prev    next >
C/C++ Source or Header  |  2000-07-13  |  5KB  |  196 lines

  1. #include "top.h"
  2.  
  3. /*  Copyright 1993 - 2000 Paul J. Sidorsky
  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, version 2, as
  7.     published by the Free Software Foundation.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17. */
  18.  
  19. void usersec(void);
  20.  
  21. void useredit(void)
  22. {
  23. user_data_typ udat;
  24. XINT res, udel;
  25. char ustr[5];
  26.  
  27. top_output(OUT_SCREEN, "\r\n^pTOP User Deletor");
  28. lookup("\0");
  29.  
  30. top_output(OUT_SCREEN, "^oEnter a user number to delete, S to change a user's security,@cor ENTER to abort.\r\n");
  31. top_output(OUT_SCREEN, "^j---> ^k");
  32.  
  33. od_input_str(ustr, 4, '0', 'z');
  34. if (!stricmp(ustr, "S"))
  35.     {
  36.     usersec();
  37.     od_exit(0, FALSE);
  38.     }
  39. res = 0; udel = (atol(ustr) - 1U);
  40. top_output(OUT_SCREEN, "\r\n");
  41.  
  42. if (udel > 0)
  43.     {
  44.     res = load_user_data(udel, &udat);
  45.     }
  46.  
  47. if (!res)
  48.     {
  49.     top_output(OUT_SCREEN, "^nAborted.");
  50.     }
  51. else
  52.     {
  53.     sprintf(outbuf, "^mDelete ^p%s^m (^p%s^m) (y/N)? ",
  54.             udat.realname, udat.handle);
  55.     top_output(OUT_SCREEN, outbuf);
  56.     res = toupper(od_get_key(TRUE));
  57.     if (res == 'Y')
  58.         {
  59.         memset(&udat, 0, sizeof(user_data_typ));
  60.         save_user_data(udel, &udat);
  61.         top_output(OUT_SCREEN, "^kYes!\r\n\r\n^lDeleted!");
  62.         od_log_write(top_output(OUT_STRING, getlang("LogDelUser"),
  63.                                 udat.handle));
  64.         }
  65.     else
  66.         {
  67.         top_output(OUT_SCREEN, "^kNo!\r\n\r\n^nAborted.");
  68.         }
  69.     }
  70.  
  71. top_output(OUT_SCREEN, "\r\n");
  72.  
  73. od_exit(0, FALSE);
  74.  
  75. return;
  76. }
  77.  
  78. void userpack(void)
  79. {
  80. user_data_typ udat;
  81. XINT uc, udc, unc, res, unewfil, tfil;
  82. char tnam1[256], tnam2[256]; /////////Both dynamic with MAXSTRLEN!
  83. long cashreset = -1, secreset = -1;
  84. top_output(OUT_SCREEN, "\r\n^pPerforming user packing...\r\n");
  85. od_log_write(top_output(OUT_STRING, getlang("LogPacking")));
  86. close(userfil);
  87.  
  88. if (word_str[0])
  89.     {
  90.     secreset = atol(word_str);
  91.     }
  92.  
  93. if (outbuf[0])
  94.     {
  95.     cashreset = atol(outbuf);
  96.     }
  97.  
  98. sprintf(tnam1, "%sUSERS.TOP", cfg.toppath);
  99. sprintf(tnam2, "%sUSERS.OLD", cfg.toppath);
  100.  
  101. if (!access(tnam2, 0))
  102.     {
  103.     sprintf(outbuf, "^nDeleting old file - %s\r\n", tnam2);
  104.     top_output(OUT_SCREEN, outbuf);
  105.     unlink(tnam2);
  106.     }
  107.  
  108. sprintf(outbuf, "^nRenaming %s to %s...", tnam1, tnam2);
  109. top_output(OUT_SCREEN, outbuf);
  110. rename(tnam1, tnam2);
  111.  
  112. top_output(OUT_SCREEN, "^n\r\nOpening new files...");
  113. userfil = sh_open(tnam2, O_RDWR | O_CREAT | O_BINARY, SH_DENYNONE,
  114.                   S_IREAD | S_IWRITE);
  115. unewfil = sh_open(tnam1, O_RDWR | O_CREAT | O_BINARY, SH_DENYNONE,
  116.                   S_IREAD | S_IWRITE);
  117.  
  118. if (userfil == -1 || unewfil == -1)
  119.     {
  120.     close(userfil); close(unewfil);
  121.     top_output(OUT_SCREEN, "^I^mCAN'T DO!!!^A^n\r\n");
  122.     top_output(OUT_SCREEN, "Aborting.\r\n");
  123.     od_exit(0, FALSE);
  124.     }
  125.  
  126. top_output(OUT_SCREEN, "\r\n^nPacking old user file...    0");
  127. for (uc = 0, udc = 0, unc = 0;
  128.      uc < ((long) filelength(userfil) / (long) sizeof(user_data_typ));
  129.      uc++)
  130.      {
  131.      res = load_user_data(uc, &udat);
  132.      if (res && !udat.realname[0])
  133.          {
  134.         udc++;
  135.         }
  136.      if (res && udat.realname[0])
  137.          {
  138.         tfil = userfil; userfil = unewfil;
  139.         if (secreset != -1)
  140.             {
  141.             udat.security = secreset;
  142.             }
  143.         if (cashreset != -1)
  144.             {
  145.             udat.cybercash = cashreset;
  146.             }
  147.         save_user_data(unc, &udat);
  148.         unc++;
  149.         userfil = tfil;
  150.         }
  151.     sprintf(outbuf, "\b\b\b\b\b%5i", uc);
  152.     top_output(OUT_SCREEN, outbuf);
  153.     }
  154.  
  155. close(userfil); close(unewfil);
  156. top_output(OUT_SCREEN, "\b\b\b\b\b^I^kDone!^A^o\r\n\r\n");
  157.  
  158. sprintf(outbuf, "^oRecords processed:  ^l%-5i   ^oRecords deleted:  "
  159.         "^l%-5i   ^oNew user count:  ^l%-5i\r\n", uc, udc, unc);
  160. top_output(OUT_SCREEN, outbuf);
  161.  
  162. od_exit(0, FALSE);
  163.  
  164. return;
  165. }
  166.  
  167. void usersec(void)
  168.     {
  169.     char tstr[10];
  170.     user_data_typ usu;
  171.  
  172.     top_output(OUT_SCREEN, "RECORD NUMBER of user to upgrade to 65535 security (usually will be 0).@c");
  173.     top_output(OUT_SCREEN, "---> ");
  174.  
  175.     od_input_str(tstr, 9, '0', '9');
  176.     if (!tstr[0])
  177.         {
  178.         top_output(OUT_SCREEN, "@c@cAborted.@c@c");
  179.         return;
  180.         }
  181.  
  182.     if (!load_user_data(atoi(tstr), &usu))
  183.         {
  184.         top_output(OUT_SCREEN, "@c@cInvalid user record number!@c@c");
  185.         return;
  186.         }
  187.  
  188.     usu.security = 65535;
  189.  
  190.     save_user_data(atoi(tstr), &usu);
  191.  
  192.     top_output(OUT_SCREEN, "@c@cSecurity for \"@1\" upgraded to 65535.@cThis user can now use the SYSOP SETSEC command.@c@c",
  193.         usu.realname);
  194.  
  195.     }
  196.