home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B87.ZIP / NETWORK.CPP < prev    next >
C/C++ Source or Header  |  1998-01-18  |  46KB  |  1,868 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdarg.h>
  5. #include <dos.h>
  6. #include <fcntl.h>
  7. #include <sys/stat.h>
  8. #include <ctype.h>
  9. #include <io.h>
  10. #include <conio.h>
  11. #include <share.h>
  12. #include <errno.h>
  13. #include <malloc.h>
  14. #include <dir.h>
  15. #include <time.h>
  16. #include <process.h>
  17. #include <direct.h>
  18. #include "vardec.h"
  19. #include "net.h"
  20. #include "version.h"
  21. #include "retcode.h"
  22.  
  23. extern unsigned _stklen = 15000U;
  24.  
  25. #define NUL '\0'
  26. #define LAST(s) s[strlen(s)-1]
  27.  
  28. #define SHARE_LEVEL 10
  29. #define WAIT_TIME 10
  30. #define TRIES 100
  31.  
  32. #define MT_DESQVIEW 0x01
  33. #define MT_WINDOWS  0x02
  34. #define MT_OS2      0x04
  35. #define MT_NB       0x40
  36.  
  37. #define INI_NETWORK   0x01
  38. #define INI_GENERAL   0x02
  39. #define INI_NEWS      0x04
  40.  
  41. typedef struct {
  42.   unsigned short sysnum;
  43.   char address[60];
  44. } net_address_rec;
  45.  
  46. char *version = "Freeware PPP Project Net Packet Engine " VERSION " (" __DATE__ ")";
  47. char *author = "Contact Frank Reid at edare@ix.netcom.com or 1@8213.WWIVnet for support";
  48.  
  49. char *strings[] = {
  50.   "Unable to create",
  51.   "Unable to read",
  52.   "Unknown error",
  53.   "Unable to write CONTACT.NET!",
  54.   "Unable to write NET.LOG!",
  55.   0L,
  56. };
  57.  
  58. configrec syscfg;
  59. configoverrec syscfgovr;
  60. net_networks_rec netcfg;
  61. net_system_list_rec *netsys;
  62. int multitasker = 0, ini_section = 0, num_addr;
  63. char wwiv_net_no[20], tasker[40], maindir[MAXPATH];
  64. char net_name[16], net_data[MAXPATH];
  65. unsigned short net_sysnum;
  66. int num_sys_list, net_num, netnum;
  67. int instance, lsl_loaded;
  68.  
  69. char SMTPHOST[40], POPHOST[40], NEWSHOST[40], POPNAME[20], POPPASS[20];
  70. char IPADDR[18], NETMASK[18], FWDNAME[20], FWDDOM[40], TIMEHOST[40], DNS[16];
  71. char NODEPASS[20], SDNS[16], DOMAIN[40], GATEWAY[16], temp_dir[MAXPATH];
  72. unsigned int KEEPSENT, ALLMAIL, CLEANUP, MOREINFO, NOLISTNAMES;
  73. unsigned int TIMEOUT, SOCK_DELAY, INACTIVE;
  74. unsigned int ONECALL, PURGE, BBSNODE, PPPD;
  75.  
  76. char *xenviron[20];
  77.  
  78. void dv_pause(void)
  79. {
  80.   __emit__(0xb8, 0x1a, 0x10, 0xcd, 0x15);
  81.   __emit__(0xb8, 0x00, 0x10, 0xcd, 0x15);
  82.   __emit__(0xb8, 0x25, 0x10, 0xcd, 0x15);
  83. }
  84.  
  85. void win_pause(void)
  86. {
  87.   __emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
  88. }
  89.  
  90. int get_dos_version(void)
  91. {
  92.   _AX = 0x3000;
  93.   geninterrupt(0x21);
  94.   if (_AX % 256 >= 10) {
  95.     multitasker |= MT_OS2;
  96.   }
  97.   return (_AX);
  98. }
  99.  
  100. int get_dv_version(void)
  101. {
  102.   int v;
  103.  
  104.   if (multitasker & MT_OS2)
  105.     return 0;
  106.   _AX = 0x2b01;
  107.   _CX = 0x4445;
  108.   _DX = 0x5351;
  109.   geninterrupt(0x21);
  110.   if (_AL == 0xff) {
  111.     return 0;
  112.   } else {
  113.     v = _BX;
  114.     multitasker |= MT_DESQVIEW;
  115.     return v;
  116.   }
  117. }
  118.  
  119. int get_win_version(void)
  120. {
  121.   int v = 0;
  122.  
  123.   __emit__(0x55, 0x06, 0x53);
  124.   _AX = 0x352f;
  125.   geninterrupt(0x21);
  126.   _AX = _ES;
  127.   if (_AX | _BX) {
  128.     _AX = 0x1600;
  129.     geninterrupt(0x2f);
  130.     v = _AX;
  131.     if (v % 256 <= 1)
  132.       v = 0;
  133.   }
  134.   __emit__(0x5b, 0x07, 0x5d);
  135.   if (v != 0)
  136.     multitasker |= MT_WINDOWS;
  137.   return (v);
  138. }
  139.  
  140. int get_nb_version(void)
  141. {
  142.   _AX = 0;
  143.   geninterrupt(0x2A);
  144.   return (_AH);
  145. }
  146.  
  147. void detect_multitask(void)
  148. {
  149.   get_dos_version();
  150.   get_win_version();
  151.   get_dv_version();
  152.   if (multitasker < 2)
  153.     if (get_nb_version())
  154.       multitasker = MT_NB;
  155. }
  156.  
  157. void giveup_timeslice(void)
  158. {
  159.   if (multitasker) {
  160.     switch (multitasker) {
  161.       case 1:
  162.       case 3:
  163.         dv_pause();
  164.         break;
  165.       case 2:
  166.       case 4:
  167.       case 5:
  168.       case 6:
  169.       case 7:
  170.         win_pause();
  171.         break;
  172.       default:
  173.         break;
  174.     }
  175.   }
  176. }
  177.  
  178. char *stripspace(char *str)
  179. {
  180.   char *obuf, *nbuf;
  181.  
  182.   if (str) {
  183.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  184.       if (!isspace(*obuf))
  185.         *nbuf++ = *obuf;
  186.     }
  187.     *nbuf = NULL;
  188.   }
  189.   return (str);
  190. }
  191.  
  192. int sh_write(int handle, void *buffer, unsigned long len)
  193. {
  194.   if (handle == -1) {
  195.     return (-1);
  196.   }
  197.   return (write(handle, buffer, (unsigned) len));
  198. }
  199.  
  200. int sh_open(char *path, int file_access, unsigned fmode)
  201. {
  202.   int handle, count, share;
  203.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  204.  
  205.   if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
  206.     share = SH_DENYRW;
  207.   } else {
  208.     share = SH_DENYWR;
  209.   }
  210.   handle = open(path, file_access | share, fmode);
  211.   if (handle < 0) {
  212.     count = 1;
  213.     fnsplit(path, drive, dir, file, ext);
  214.     if (access(path, 0) != -1) {
  215.       delay(WAIT_TIME);
  216.       handle = open(path, file_access | share, fmode);
  217.       while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
  218.         if (count % 2)
  219.           delay(WAIT_TIME);
  220.         else
  221.           giveup_timeslice();
  222.         count++;
  223.         handle = open(path, file_access | share, fmode);
  224.       }
  225.     }
  226.   }
  227.   return (handle);
  228. }
  229.  
  230. int sh_open1(char *path, int access)
  231. {
  232.   unsigned fmode;
  233.  
  234.   fmode = 0;
  235.   if ((access & O_RDWR) || (access & O_WRONLY))
  236.     fmode |= S_IWRITE;
  237.   if ((access & O_RDWR) || (access & O_RDONLY))
  238.     fmode |= S_IREAD;
  239.   return (sh_open(path, access, fmode));
  240. }
  241.  
  242. int sh_close(int f)
  243. {
  244.   if (f != -1)
  245.     close(f);
  246.   return (-1);
  247. }
  248.  
  249. int sh_read(int handle, void *buf, unsigned len)
  250. {
  251.   if (handle == -1) {
  252.     return (-1);
  253.   }
  254.   return (read(handle, buf, len));
  255. }
  256.  
  257. long sh_lseek(int handle, long offset, int fromwhere)
  258. {
  259.   if (handle == -1) {
  260.     return (-1L);
  261.   }
  262.   return (lseek(handle, offset, fromwhere));
  263. }
  264.  
  265. FILE *fsh_open(char *path, char *fmode)
  266. {
  267.   FILE *f;
  268.   int count, share, md, fd;
  269.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  270.  
  271.   share = SH_DENYWR;
  272.   md = 0;
  273.   if (((char *) _fstrchr(fmode, 'w')) != NULL) {
  274.     share = SH_DENYRD;
  275.     md = O_RDWR | O_CREAT | O_TRUNC;
  276.   } else
  277.     if (((char *) _fstrchr(fmode, 'a')) != NULL) {
  278.     share = SH_DENYRD;
  279.     md = O_RDWR | O_CREAT;
  280.   } else {
  281.     md = O_RDONLY;
  282.   }
  283.   if (((char *) _fstrchr(fmode, 'b')) != NULL) {
  284.     md |= O_BINARY;
  285.   }
  286.   if (((char *) _fstrchr(fmode, '+')) != NULL) {
  287.     md &= ~O_RDONLY;
  288.     md |= O_RDWR;
  289.     share = SH_DENYRD;
  290.   }
  291.   fd = open(path, md | share, S_IREAD | S_IWRITE);
  292.   if (fd < 0) {
  293.     count = 1;
  294.     fnsplit(path, drive, dir, file, ext);
  295.     if ((access(path, 0)) != -1) {
  296.       delay(WAIT_TIME);
  297.       fd = open(path, md | share, S_IREAD | S_IWRITE);
  298.       while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
  299.         delay(WAIT_TIME);
  300.         count++;
  301.         fd = open(path, md | share, S_IREAD | S_IWRITE);
  302.       }
  303.     }
  304.   }
  305.   if (fd > 0) {
  306.     if (((char *) _fstrchr(fmode, 'a')) != NULL)
  307.       sh_lseek(fd, 0L, SEEK_END);
  308.     f = fdopen(fd, fmode);
  309.     if (!f) {
  310.       close(fd);
  311.     }
  312.   } else
  313.     f = NULL;
  314.   return (f);
  315. }
  316.  
  317. void output(char *fmt,...)
  318. {
  319.   va_list v;
  320.   char s[255];
  321.  
  322.   va_start(v, fmt);
  323.   vsprintf(s, fmt, v);
  324.   va_end(v);
  325.   fputs(s, stderr);
  326. }
  327.  
  328. int log_it(int display, char *fmt,...)
  329. {
  330.   va_list v;
  331.   char s[255], fn[MAXPATH];
  332.   FILE *fp;
  333.  
  334.   va_start(v, fmt);
  335.   vsprintf(s, fmt, v);
  336.   va_end(v);
  337.   sprintf(fn, "%sNEWS.LOG", net_data);
  338.   if ((fp = fsh_open(fn, "at")) == NULL) {
  339.     output("\n ! Error accessing %s.", fn);
  340.     return 1;
  341.   }
  342.   fputs(s, fp);
  343.   if (fp != NULL)
  344.     fclose(fp);
  345.   if (display)
  346.     fputs(s, stderr);
  347.   return 0;
  348. }
  349.  
  350. void backline(void)
  351. {
  352.   int i;
  353.  
  354.   output(" ");
  355.   for (i = wherex(); i > 0; i--)
  356.     output("\b \b");
  357. }
  358.  
  359.  
  360. int do_spawn(char *cl)
  361. {
  362.   int i, i1, l;
  363.   char *ss1, *ss[30];
  364.  
  365.   ss1 = strdup(cl);
  366.   ss[0] = ss1;
  367.   i = 1;
  368.   l = strlen(ss1);
  369.   for (i1 = 1; i1 < l; i1++) {
  370.     if (ss1[i1] == 32) {
  371.       ss1[i1] = 0;
  372.       ss[i++] = &(ss1[i1 + 1]);
  373.     }
  374.   }
  375.   ss[i] = NULL;
  376.   i = (spawnvpe(P_WAIT, ss[0], ss, xenviron) & 0x00ff);
  377.   if (ss1 != NULL)
  378.     free(ss1);
  379.   ss1 = NULL;
  380.   return i;
  381. }
  382.  
  383. #ifndef PACKET
  384. void unload_klos(int pppd)
  385. {
  386.   char s[160];
  387.   char far *ss;
  388.   int i;
  389.  
  390.   if (pppd) {
  391.     for (i = 0x60; i < 0x80; i++) {
  392.       ss = (char far *)getvect(i);
  393.       if (memcmp(&(ss[3]), "PKT DRVR", 8) == 0)
  394.         break;
  395.     }
  396.     sprintf(s, "%s\\TERMIN.COM 0x%02X", maindir, i);
  397.     do_spawn(s);
  398.   } else {
  399.     sprintf(s, "%s\\IPSTUB U", maindir);
  400.     do_spawn(s);
  401.     sprintf(s, "%s\\PPP U", maindir);
  402.     do_spawn(s);
  403.     if (!lsl_loaded) {
  404.       sprintf(s, "%s\\LSL U", maindir);
  405.       do_spawn(s);
  406.     }
  407.   }
  408. }
  409.  
  410. #endif
  411.  
  412. void cd_to(char *s)
  413. {
  414.   char *s1;
  415.   int i, db;
  416.  
  417.   s1 = s;
  418.   i = strlen(s1) - 1;
  419.   db = (s1[i] == '\\');
  420.   if (i == 0)
  421.     db = 0;
  422.   if ((i == 2) && (s1[1] == ':'))
  423.     db = 0;
  424.   if (db)
  425.     s1[i] = 0;
  426.   chdir(s1);
  427.   if (s[1] == ':')
  428.     setdisk(s[0] - 'A');
  429. }
  430.  
  431. void get_dir(char *s, int be)
  432. {
  433.   strcpy(s, "X:\\");
  434.   s[0] = 'A' + getdisk();
  435.   getcurdir(0, s + 3);
  436.   if (be) {
  437.     if (s[strlen(s) - 1] != '\\')
  438.       strcat(s, "\\");
  439.   }
  440. }
  441.  
  442. unsigned char *trimstr1(unsigned char *s)
  443. {
  444.   int i;
  445.   static char *whitespace = " \r\n\t";
  446.  
  447.   i = strlen(s);
  448.   if (i) {
  449.     while ((i > 0) && (_fstrchr(whitespace, s[i - 1])))
  450.       --i;
  451.     while ((i > 0) && (_fstrchr(whitespace, *s))) {
  452.       memmove(s, s + 1, --i);
  453.     }
  454.     s[i] = NUL;
  455.   }
  456.   return (s);
  457. }
  458.  
  459. char *make_abs_path(char *checkdir)
  460. {
  461.   char newdir[121];
  462.  
  463.   if ((strlen(checkdir) < 3) || (checkdir[1] != ':') || (checkdir[2] != '\\')) {
  464.     cd_to(maindir);
  465.     cd_to(checkdir);
  466.     if (LAST(checkdir) == '\\')
  467.       get_dir(newdir, 1);
  468.     else
  469.       get_dir(newdir, 0);
  470.     cd_to(maindir);
  471.     strcpy(checkdir, newdir);
  472.   }
  473.   return checkdir;
  474. }
  475.  
  476. int exist(char *s)
  477. {
  478.   int i;
  479.   struct ffblk ff;
  480.  
  481.   i = findfirst(s, &ff, FA_HIDDEN);
  482.   if (i)
  483.     return 0;
  484.   else
  485.     return 1;
  486. }
  487.  
  488. void set_net_num(int n)
  489. {
  490.   char s[121];
  491.   int f;
  492.  
  493.   sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
  494.   f = sh_open1(s, O_RDONLY | O_BINARY);
  495.   if (f < 0)
  496.     return;
  497.   lseek(f, ((long) (n)) * sizeof(net_networks_rec), SEEK_SET);
  498.   sh_read(f, &netcfg, sizeof(net_networks_rec));
  499.   close(f);
  500.   net_num = n;
  501.   net_sysnum = netcfg.sysnum;
  502.   strcpy(net_name, netcfg.name);
  503.   strcpy(net_data, make_abs_path(netcfg.dir));
  504.   if (LAST(net_data) != '\\')
  505.     strcat(net_data, "\\");
  506.   sprintf(wwiv_net_no, "WWIV_NET=%d", net_num);
  507. }
  508.  
  509. int make_path(char *s)
  510. {
  511.   unsigned int i;
  512.   char drive, current_path[MAXPATH], current_drive, *p, *flp;
  513.   union REGS r;
  514.  
  515.   p = flp = strdup(s);
  516.   _getdcwd(0, current_path, MAXPATH);
  517.   current_drive = *current_path - '@';
  518.   if (LAST(s) == '\\')
  519.     LAST(s) = 0;
  520.   if (p[1] == ':') {
  521.     drive = toupper(p[0]) - 'A' + 1;
  522.     if ((_osmajor == 3 && _osminor >= 1) || (_osmajor > 3)) {
  523.       r.x.ax = 0x4409;
  524.       r.h.bl = drive;
  525.       int86(0x21, &r, &r);
  526.       if (r.x.cflag)
  527.         return -3;
  528.     }
  529.     if (_chdrive(drive)) {
  530.       chdir(current_path);
  531.       _dos_setdrive(current_drive, &i);
  532.       return -2;
  533.     }
  534.     p += 2;
  535.   }
  536.   if (*p == '\\') {
  537.     chdir("\\");
  538.     p++;
  539.   }
  540.   for (; (p = strtok(p, "\\")) != 0; p = 0) {
  541.     if (chdir(p)) {
  542.       if (mkdir(p)) {
  543.         chdir(current_path);
  544.         _dos_setdrive(current_drive, &i);
  545.         return -1;
  546.       }
  547.       chdir(p);
  548.     }
  549.   }
  550.   chdir(current_path);
  551.   if (flp)
  552.     free(flp);
  553.   return 0;
  554. }
  555.  
  556. void process_mail(void)
  557. {
  558.   char s[201];
  559.  
  560.   output("\n ■ Network clean-up... please wait... ");
  561.   sprintf(s, "%s\\FLINK.EXE", maindir);
  562.   if (exist(s))
  563.     do_spawn(s);
  564.   sprintf(s, "%s\\LINKER.EXE", maindir);
  565.   if (exist(s))
  566.     do_spawn(s);
  567.   output("done.");
  568. }
  569.  
  570. int valid_system(unsigned int ts)
  571. {
  572.   int i;
  573.  
  574.   for (i = 0; i < num_sys_list; i++) {
  575.     if (netsys[i].sysnum == ts) {
  576.       if (netsys[i].numhops == 1)
  577.         return (1);
  578.       else
  579.         return (0);
  580.     }
  581.   }
  582.   return (0);
  583. }
  584.  
  585. int create_contact_ppp(void)
  586. {
  587.   char *ss, fn[101], s[81];
  588.   unsigned short node;
  589.   int curfile, i;
  590.   net_address_rec curaddr;
  591.   FILE *fp, *fc;
  592.  
  593.   sprintf(fn, "%sCONTACT.PPP", net_data);
  594.   if ((fc = fsh_open(fn, "wb+")) == NULL) {
  595.     output("\n ! %s %s!\n", strings[0], fn);
  596.     return 1;
  597.   }
  598.   curfile = 1;
  599.   num_addr = 0;
  600.   do {
  601.     sprintf(fn, "%sADDRESS.%d", net_data, curfile);
  602.     if ((fp = fsh_open(fn, "rt")) == NULL)
  603.       curfile = -1;
  604.     while ((curfile > 0) && (fgets(s, 80, fp) != NULL)) {
  605.       if (s[0] != '@')
  606.         continue;
  607.       ss = strtok(s, " \t\r");
  608.       node = atoi(&ss[1]);
  609.       if (node) {
  610.         ss = strtok(NULL, " \t\r");
  611.         trimstr1(ss);
  612.         curaddr.sysnum = node;
  613.         strcpy(curaddr.address, ss);
  614.         if (ss[0]) {
  615.           fwrite(&curaddr, sizeof(net_address_rec), 1, fc);
  616.           ++num_addr;
  617.         }
  618.       }
  619.     }
  620.     if (fp != NULL)
  621.       fclose(fp);
  622.     ++curfile;
  623.   } while (curfile > 0);
  624.   fseek(fc, 0L, SEEK_SET);
  625.   sprintf(fn, "%sADDRESS.0", net_data);
  626.   if ((fp = fsh_open(fn, "rt")) == NULL) {
  627.     if (fc != NULL)
  628.       fclose(fc);
  629.     return (0);
  630.   }
  631.   while (fgets(s, 80, fp) != NULL) {
  632.     if (s[0] != '@')
  633.       continue;
  634.     ss = strtok(s, " \t\r");
  635.     node = atoi(&ss[1]);
  636.     do {
  637.       ss = strtok(NULL, " \t\r");
  638.       switch (ss[0]) {
  639.         case '-':
  640.           for (i = 0; i < num_addr; i++) {
  641.             fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  642.             fread(&curaddr, sizeof(net_address_rec), 1, fc);
  643.             if (node == curaddr.sysnum) {
  644.               curaddr.sysnum = 0;
  645.               fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  646.               fwrite(&curaddr, sizeof(net_address_rec), 1, fc);
  647.             }
  648.           }
  649.           break;
  650.       }
  651.     } while (ss);
  652.   }
  653.   if (fp != NULL)
  654.     fclose(fp);
  655.   if (fc != NULL)
  656.     fclose(fc);
  657.   return (0);
  658. }
  659.  
  660. void good_addr(char *address, unsigned short sn)
  661. {
  662.   char fn[101];
  663.   int i;
  664.   net_address_rec curaddr;
  665.   FILE *fc;
  666.  
  667.   address[0] = 0;
  668.   sprintf(fn, "%sCONTACT.PPP", net_data);
  669.   if ((fc = fsh_open(fn, "rb+")) == NULL) {
  670.     log_it(1, "\n ■ %s %s!\n", strings[1], fn);
  671.     return;
  672.   }
  673.   for (i = 0; ((i < num_addr) && (!address[0])); i++) {
  674.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  675.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  676.     if (sn == curaddr.sysnum)
  677.       strcpy(address, curaddr.address);
  678.   }
  679.   if (fc != NULL)
  680.     fclose(fc);
  681. }
  682.  
  683. int copyfile(char *infn, char *outfn)
  684. {
  685.   int f1, f2, i;
  686.   char *b;
  687.   struct ftime ft;
  688.  
  689.   if ((strcmp(infn, outfn) != 0) && (exist(infn)) && (!exist(outfn))) {
  690.     if ((b = (char *) farmalloc(16400)) == NULL)
  691.       return 0;
  692.     f1 = sh_open1(infn, O_RDONLY | O_BINARY);
  693.     if (!f1) {
  694.       farfree(b);
  695.       b = NULL;
  696.       return 0;
  697.     }
  698.     getftime(f1, &ft);
  699.     f2 = sh_open(outfn, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  700.     if (!f2) {
  701.       farfree(b);
  702.       b = NULL;
  703.       f1 = sh_close(f1);
  704.       return 0;
  705.     }
  706.     i = sh_read(f1, (char *) b, 16384);
  707.     while (i > 0) {
  708.       sh_write(f2, (char *) b, i);
  709.       i = sh_read(f1, (char *) b, 16384);
  710.     }
  711.     f1 = sh_close(f1);
  712.     setftime(f2, &ft);
  713.     f2 = sh_close(f2);
  714.     farfree(b);
  715.     b = NULL;
  716.   }
  717.   return 1;
  718. }
  719.  
  720. void do_exit(int exitlevel)
  721. {
  722.   delay(2000);
  723.   exit(2 - exitlevel);
  724. }
  725.  
  726. int uu(char *fn, char *pktname, char *dest)
  727. {
  728.   int ok;
  729.   char s[121], s1[201], s2[81];
  730.   FILE *fp;
  731.  
  732.   sprintf(s, "%sMQUEUE\\%s.UUE", net_data, pktname);
  733.   if ((fp = fsh_open(s, "wt")) == NULL) {
  734.     log_it(1, "\n ■ %s %s!", strings[0], s);
  735.     do_exit(EXIT_FAILURE);
  736.   } else {
  737.     if (BBSNODE == 2)
  738.       sprintf(s2, "From: n%hd@filenet.ml.org\n", net_sysnum);
  739.     else
  740.       sprintf(s2, "From: %s@%s\n", POPNAME, DOMAIN);
  741.     fprintf(fp, s2);
  742.     sprintf(s2, "To: %s\n", dest);
  743.     fprintf(fp, s2);
  744.     sprintf(s2, "Message-ID: <%s-%s@%s>\n", pktname, POPNAME, DOMAIN);
  745.     fprintf(fp, s2);
  746.     sprintf(s2, "Subject: @%s NET PACKET : %s.UUE\n\n", net_name, pktname);
  747.     fprintf(fp, s2);
  748.   }
  749.   if (fp != NULL)
  750.     fclose(fp);
  751.   sprintf(s1, "%s\\UU.EXE -encode %s %s", maindir, fn, s);
  752.   ok = do_spawn(s1);
  753.   if (MOREINFO)
  754.     output("\n");
  755.   return ok;
  756. }
  757.  
  758. int update_contact(unsigned short sy, unsigned long sb, unsigned long rb)
  759. {
  760.   char s[101];
  761.   int i, i1, f;
  762.   long cur_time, l;
  763.  
  764.   sprintf(s, "%sCONTACT.NET", net_data);
  765.   f = sh_open1(s, O_RDONLY | O_BINARY);
  766.   if (f >= 0) {
  767.     l = filelength(f);
  768.     netcfg.num_ncn = (int) (l / sizeof(net_contact_rec));
  769.     if ((netcfg.ncn = (net_contact_rec *) farmalloc((netcfg.num_ncn + 2) *
  770.                                         sizeof(net_contact_rec))) == NULL) {
  771.       f = sh_close(f);
  772.       return 1;
  773.     }
  774.     sh_lseek(f, 0L, SEEK_SET);
  775.     sh_read(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
  776.     f = sh_close(f);
  777.   }
  778.   for (i = 0; i < netcfg.num_ncn; i++)
  779.     if (netcfg.ncn[i].systemnumber == sy)
  780.       i1 = i;
  781.   time(&cur_time);
  782.   netcfg.ncn[i1].lasttry = cur_time;
  783.   ++netcfg.ncn[i1].numcontacts;
  784.   if (!netcfg.ncn[i1].firstcontact)
  785.     netcfg.ncn[i1].firstcontact = cur_time;
  786.   netcfg.ncn[i1].lastcontact = cur_time;
  787.   netcfg.ncn[i1].lastcontactsent = cur_time;
  788.   netcfg.ncn[i1].bytes_sent += sb;
  789.   if (rb)
  790.     netcfg.ncn[i1].bytes_received += rb;
  791.   netcfg.ncn[i1].bytes_waiting = 0L;
  792.   sprintf(s, "%sS%hd.net", net_data, sy);
  793.   if (!exist(s))
  794.     sprintf(s, "%sZ%hd.net", net_data, sy);
  795.   f = sh_open1(s, O_RDONLY | O_BINARY);
  796.   if (f > 0) {
  797.     netcfg.ncn[i1].bytes_waiting += filelength(f);
  798.     close(f);
  799.   }
  800.   sprintf(s, "%sCONTACT.NET", net_data);
  801.   f = sh_open1(s, O_RDWR | O_CREAT | O_BINARY);
  802.   if (f > 0) {
  803.     sh_lseek(f, 0L, SEEK_SET);
  804.     sh_write(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
  805.     f = sh_close(f);
  806.   }
  807.   if (netcfg.ncn)
  808.     farfree(netcfg.ncn);
  809.   return 0;
  810. }
  811.  
  812.  
  813. int update_contacts(unsigned short sy, unsigned long sb, unsigned long rb)
  814. {
  815.   int i, i1, rc;
  816.   char fn[101];
  817.   net_address_rec curaddr;
  818.   FILE *fc;
  819.  
  820.   rc = 0;
  821.   sprintf(fn, "%sCONTACT.PPP", net_data);
  822.   if ((fc = fsh_open(fn, "rb+")) == NULL) {
  823.     log_it(1, "\n ■ %s %s!\n", strings[1], fn);
  824.     rc = 1;
  825.     return (rc);
  826.   }
  827.   for (i = 0; i < num_addr; i++) {
  828.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  829.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  830.     if (curaddr.sysnum != 0) {
  831.       if (curaddr.sysnum == sy)
  832.         i1 = update_contact(curaddr.sysnum, sb, rb);
  833.       else
  834.         i1 = update_contact(curaddr.sysnum, 0, 0);
  835.       if (i1)
  836.         rc = 1;
  837.     }
  838.   }
  839.   if (fc != NULL)
  840.     fclose(fc);
  841.   return (rc);
  842. }
  843.  
  844. int uu_packets(void)
  845. {
  846.   char pktname[21], s[121], s1[121], s2[121], s3[121], temp[121];
  847.   int found, sz, f, f1, i;
  848.   unsigned long sbytes, basename;
  849.   net_address_rec curaddr;
  850.   FILE *fc;
  851.  
  852.   num_sys_list = 0;
  853.   found = 0;
  854.   basename = time(NULL);
  855.   sprintf(s, "%sBBSDATA.NET", net_data);
  856.   f = sh_open1(s, O_RDONLY | O_BINARY);
  857.   if (f > 0) {
  858.     num_sys_list = (int) (filelength(f) / sizeof(net_system_list_rec));
  859.     if ((netsys = (net_system_list_rec *) farmalloc((num_sys_list + 2) *
  860.                                     sizeof(net_system_list_rec))) == NULL) {
  861.       log_it(1, "\n ■ Unable to allocate %d bytes of memory for BBSDATA.NET",
  862.              (int) (num_sys_list + 2) * sizeof(net_system_list_rec));
  863.       sh_close(f);
  864.       return 0;
  865.     }
  866.     sh_lseek(f, 0L, SEEK_SET);
  867.     sh_read(f, (void *) netsys, num_sys_list * sizeof(net_system_list_rec));
  868.     sh_close(f);
  869.   } else
  870.     return 0;
  871.  
  872.   sprintf(s1, "%sCONTACT.PPP", net_data);
  873.   if ((fc = fsh_open(s1, "rb+")) == NULL) {
  874.     log_it(1, "\n ■ %s %s!\n", strings[1], s1);
  875.     farfree(netsys);
  876.     return 0;
  877.   }
  878.   for (i = 0; i < num_addr; i++) {
  879.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  880.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  881.     if ((valid_system(curaddr.sysnum)) && (curaddr.sysnum != 32767)) {
  882.       sprintf(s1, "%sS%hd.NET", net_data, curaddr.sysnum);
  883.       if (exist(s1)) {
  884.         sz = 0;
  885.         found = 1;
  886.       } else {
  887.         sprintf(s1, "%sZ%hd.NET", net_data, curaddr.sysnum);
  888.         if (exist(s1)) {
  889.           sz = 1;
  890.           found = 1;
  891.         } else
  892.           continue;
  893.       }
  894.       do {
  895.         sprintf(pktname, "%8.8lx", ++basename);
  896.         sprintf(temp, "%sMQUEUE\\%s.UUE", net_data, pktname);
  897.       } while (exist(temp));
  898.       backline();
  899.       output("\r ■ Encoding %s%hd.NET as %s.UUE -",
  900.              sz ? "Z" : "S", curaddr.sysnum, strupr(pktname));
  901.       if ((uu(s1, pktname, curaddr.address)) != EXIT_SUCCESS) {
  902.         output("\n ■ %s %sMQUEUE\\%s.UUE", strings[0], net_data, pktname);
  903.         if (fc != NULL)
  904.           fclose(fc);
  905.         farfree(netsys);
  906.         do_exit(EXIT_FAILURE);
  907.       } else {
  908.         if (KEEPSENT) {
  909.           sprintf(s3, "%sMQUEUE\\%s.UUE", net_data, pktname);
  910.           sprintf(s2, "%sSENT\\%s.SNT", net_data, pktname);
  911.           f1 = sh_open1(s3, O_RDONLY | O_BINARY);
  912.           if (f1 > 0) {
  913.             sbytes = filelength(f1);
  914.             f = sh_close(f1);
  915.           }
  916.           if (!copyfile(s3, s2))
  917.             output("\n ■ %s %s%hd.NET", strings[0], sz ? "Z" : "S", curaddr.sysnum);
  918.         }
  919.         unlink(s1);
  920.         update_contact(curaddr.sysnum, sbytes, 0);
  921.       }
  922.     }
  923.   }
  924.   if (fc != NULL)
  925.     fclose(fc);
  926.   farfree(netsys);
  927.   return found;
  928. }
  929.  
  930. int parse_net_ini(void)
  931. {
  932.   char cursect, fn[MAXPATH], line[121], vanline[121], *ss;
  933.   FILE *fp;
  934.  
  935.   sprintf(fn, "%s\\NET.INI", maindir);
  936.   if ((fp = fsh_open(fn, "rt")) == NULL) {
  937.     output("\n ! Unable to read %s.", fn);
  938.     return (0);
  939.   }
  940.   while (fgets(line, 80, fp)) {
  941.     strcpy(vanline, line);
  942.     stripspace(line);
  943.     ss = NULL;
  944.     ss = strtok(line, "=");
  945.     if (ss)
  946.       ss = strtok(NULL, "\n");
  947.     if ((line[0] == ';') || (line[0] == '\n') || (strlen(line) == 0))
  948.       continue;
  949.     if ((strnicmp(line, "[FILENET]", 9) == 0) ||
  950.         (strnicmp(line, "[PPPNET]", 8) == 0)) {
  951.       cursect = INI_NETWORK;
  952.       ini_section |= INI_NETWORK;
  953.       continue;
  954.     }
  955.     if (strnicmp(line, "[GENERAL]", 9) == 0) {
  956.       cursect = INI_GENERAL;
  957.       ini_section |= INI_GENERAL;
  958.       continue;
  959.     }
  960.     if (strnicmp(line, "[NEWS]", 6) == 0) {
  961.       cursect = INI_NEWS;
  962.       ini_section |= INI_NEWS;
  963.       continue;
  964.     }
  965.     if (cursect & INI_NETWORK) {
  966.       if (strnicmp(line, "TIMEHOST", 8) == 0) {
  967.         if (ss)
  968.           strcpy(TIMEHOST, ss);
  969.         continue;
  970.       }
  971.       if (strnicmp(line, "SMTPHOST", 8) == 0) {
  972.         if (ss)
  973.           strcpy(SMTPHOST, ss);
  974.         continue;
  975.       }
  976.       if (strnicmp(line, "POPHOST", 7) == 0) {
  977.         if (ss)
  978.           strcpy(POPHOST, ss);
  979.         continue;
  980.       }
  981.       if (strnicmp(line, "POPNAME", 7) == 0) {
  982.         if (ss)
  983.           strcpy(POPNAME, ss);
  984.         continue;
  985.       }
  986.       if (strnicmp(line, "POPPASS", 7) == 0) {
  987.         if (ss)
  988.           strcpy(POPPASS, ss);
  989.         continue;
  990.       }
  991.     }
  992.     if (strnicmp(line, "NODEPASS", 7) == 0) {
  993.       if (ss) {
  994.         strcpy(NODEPASS, ss);
  995.         BBSNODE = 2;
  996.       }
  997.       continue;
  998.     }
  999.     if (cursect & INI_GENERAL) {
  1000.       if (strnicmp(line, "TIMEOUT", 7) == 0) {
  1001.         if (atoi(ss))
  1002.           TIMEOUT = atoi(ss);
  1003.         continue;
  1004.       }
  1005.       if (strnicmp(line, "SOCK_DELAY", 10) == 0) {
  1006.         if (atoi(ss))
  1007.           SOCK_DELAY = atoi(ss);
  1008.         continue;
  1009.       }
  1010.       if ((strnicmp(line, "INACTIVE", 8) == 0) || (strnicmp(line, "SOCK_INACTIVE", 13) == 0)) {
  1011.         if (atoi(ss))
  1012.           INACTIVE = atoi(ss);
  1013.         continue;
  1014.       }
  1015.       if (strnicmp(line, "KEEPSENT", 8) == 0) {
  1016.         if (atoi(ss))
  1017.           KEEPSENT = atoi(ss);
  1018.         continue;
  1019.       }
  1020.       if (strnicmp(line, "PURGE", 5) == 0) {
  1021.         if (toupper(ss[0]) == 'N')
  1022.           PURGE = 0;
  1023.         continue;
  1024.       }
  1025.       if (strnicmp(line, "DRIVER", 6) == 0) {
  1026.         if (toupper(ss[0]) == 'P')
  1027.           PPPD = 1;
  1028.         continue;
  1029.       }
  1030.       if (strnicmp(line, "ALLMAIL", 7) == 0) {
  1031.         if (toupper(ss[0]) == 'N')
  1032.           ALLMAIL = 0;
  1033.         continue;
  1034.       }
  1035.       if (strnicmp(line, "ONECALL", 7) == 0) {
  1036.         if (toupper(ss[0]) == 'Y')
  1037.           ONECALL = 1;
  1038.         continue;
  1039.       }
  1040.       if (strnicmp(line, "MOREINFO", 8) == 0) {
  1041.         if (toupper(ss[0]) == 'Y')
  1042.           MOREINFO = 1;
  1043.         continue;
  1044.       }
  1045.       if (strnicmp(line, "NOLISTNAMES", 11) == 0) {
  1046.         if (toupper(ss[0]) == 'Y')
  1047.           NOLISTNAMES = 1;
  1048.         continue;
  1049.       }
  1050.       if (strnicmp(line, "CLEANUP", 7) == 0) {
  1051.         if (toupper(ss[0]) == 'Y')
  1052.           CLEANUP = 1;
  1053.         continue;
  1054.       }
  1055.       if (strnicmp(line, "IPADDR", 6) == 0) {
  1056.         if ((ss) && (ss[0] != '0'))
  1057.           strcpy(IPADDR, ss);
  1058.         continue;
  1059.       }
  1060.       if (strnicmp(line, "NETMASK", 7) == 0) {
  1061.         if (ss)
  1062.           strcpy(NETMASK, ss);
  1063.         continue;
  1064.       }
  1065.       if (strnicmp(line, "DNS", 3) == 0) {
  1066.         if (ss)
  1067.           strcpy(DNS, ss);
  1068.         continue;
  1069.       }
  1070.       if (strnicmp(line, "SDNS", 3) == 0) {
  1071.         if (ss)
  1072.           strcpy(SDNS, ss);
  1073.         continue;
  1074.       }
  1075.       if (strnicmp(line, "DOMAIN", 6) == 0) {
  1076.         if (ss)
  1077.           strcpy(DOMAIN, ss);
  1078.         continue;
  1079.       }
  1080.       if (strnicmp(line, "FWDNAME", 7) == 0) {
  1081.         if (ss)
  1082.           strcpy(FWDNAME, ss);
  1083.         continue;
  1084.       }
  1085.       if (strnicmp(line, "FWDDOM", 6) == 0) {
  1086.         if (ss)
  1087.           strcpy(FWDDOM, ss);
  1088.         continue;
  1089.       }
  1090.       if (strnicmp(line, "GATEWAY", 7) == 0) {
  1091.         if ((ss) && (ss[0] != '0'))
  1092.           strcpy(GATEWAY, ss);
  1093.         continue;
  1094.       }
  1095.     }
  1096.     if (cursect & INI_NEWS) {
  1097.       if (strnicmp(line, "NEWSHOST", 8) == 0) {
  1098.         if (ss)
  1099.           strcpy(NEWSHOST, ss);
  1100.         continue;
  1101.       }
  1102.     }
  1103.   }
  1104.   if (!FWDNAME[0])
  1105.     strcpy(FWDNAME, POPNAME);
  1106.   if (!FWDDOM[0])
  1107.     strcpy(FWDDOM, DOMAIN);
  1108.   if (fp != NULL)
  1109.     fclose(fp);
  1110.   return (1);
  1111. }
  1112.  
  1113. int read_networks(void)
  1114. {
  1115.   int f, max;
  1116.   char s[121];
  1117.  
  1118.   sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
  1119.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1120.   max = 0;
  1121.   if (f > 0)
  1122.     max = (int) (filelength(f) / sizeof(net_networks_rec));
  1123.   sh_close(f);
  1124.   return max;
  1125. }
  1126.  
  1127. void do_it(char *cl)
  1128. {
  1129.   int i, i1, l;
  1130.   char *s, *ss[30];
  1131.  
  1132.   s = _fstrdup(cl);
  1133.   ss[0] = s;
  1134.   i = 1;
  1135.   l = strlen(s);
  1136.   for (i1 = 1; i1 < l; i1++)
  1137.     if (s[i1] == 32) {
  1138.       s[i1] = 0;
  1139.       ss[i++] = &(s[i1 + 1]);
  1140.     }
  1141.   ss[i] = NULL;
  1142.   execvpe(ss[0], ss, xenviron);
  1143.   if (s != NULL)
  1144.     farfree(s);
  1145. }
  1146.  
  1147. int create_wattcp_cfg(int pppd)
  1148. {
  1149.   char s1[101], fn[MAXPATH];
  1150.   FILE *fp;
  1151.  
  1152.   if (IPADDR[0] == 0)
  1153.     strcpy(IPADDR, "0.0.0.0");
  1154.  
  1155.   sprintf(fn, "%s\\WATTCP.CFG", maindir);
  1156.   if ((fp = fsh_open(fn, "wt+")) == NULL) {
  1157.     log_it(1, "\n ■ %s %s\\WATTCP.CFG... aborting!", strings[1], maindir);
  1158.     return 1;
  1159.   }
  1160.   if (pppd)
  1161.     fprintf(fp, "my_ip=bootp\n");
  1162.   else {
  1163.     fprintf(fp, "my_ip=%s\n", IPADDR);
  1164.     fprintf(fp, "netmask=%s\n", NETMASK);
  1165.     fprintf(fp, "gateway=%s\n", GATEWAY);
  1166.   }
  1167.   fprintf(fp, "nameserver=%s\n", DNS);
  1168.   if (SDNS[0] != 0)
  1169.     fprintf(fp, "nameserver=%s\n", SDNS);
  1170.   if ((GATEWAY[0] == 0) && (!pppd)) {
  1171.     strcpy(s1, IPADDR);
  1172.     while (LAST(s1) != '.')
  1173.       LAST(s1) = 0;
  1174.     strcat(s1, "1");
  1175.     strcpy(GATEWAY, s1);
  1176.   }
  1177.   fprintf(fp, "domains=\"%s\"\n", DOMAIN);
  1178.   fprintf(fp, "hostname=\"%s\"\n", POPNAME);
  1179.   fprintf(fp, "sockdelay=%d\n", SOCK_DELAY);
  1180.   fprintf(fp, "inactive=%d\n", INACTIVE);
  1181.   fclose(fp);
  1182.   return 0;
  1183. }
  1184.  
  1185. int check_encode(char *fn)
  1186. {
  1187.   char s[121];
  1188.   int lines, encoded;
  1189.   FILE *fp;
  1190.  
  1191.   if ((fp = fsh_open(fn, "r")) == NULL)
  1192.     return 0;
  1193.  
  1194.   lines = encoded = 0;
  1195.  
  1196.   while ((fgets(s, 120, fp)) && (++lines < 1000) && (!encoded)) {
  1197.     if (strnicmp(s, "begin 6", 7) == 0) {
  1198.       encoded = 1;
  1199.       break;
  1200.     }
  1201.     if (strnicmp(s, "Content-Type:", 13) == 0) {
  1202.       encoded = 1;
  1203.       break;
  1204.     }
  1205.   }
  1206.  
  1207.   if (fp != NULL)
  1208.     fclose(fp);
  1209.  
  1210.   if (encoded) {
  1211.     log_it(MOREINFO, "\n ■ %s appears to contain encoded data.", fn);
  1212.     return 1;
  1213.   }
  1214.   return 0;
  1215. }
  1216.  
  1217. void check_unk(void)
  1218. {
  1219.   char s[101], fn[MAXPATH];
  1220.   int f, f1;
  1221.   long l;
  1222.   struct ffblk ff;
  1223.  
  1224.   sprintf(fn, "%sSPOOL\\UNK-0*.*", net_data);
  1225.   f1 = findfirst(fn, &ff, 0);
  1226.   while (f1 == 0) {
  1227.     sprintf(fn, "%sINBOUND\\%s", net_data, ff.ff_name);
  1228.     f = sh_open1(fn, O_RDONLY | O_BINARY);
  1229.     l = filelength(f);
  1230.     f = sh_close(f);
  1231.     if (l > 32767L) {
  1232.       if (!check_encode(fn)) {
  1233.         sprintf(s, "%s\\PPPUTIL.EXE CHUNK %s %s", maindir, net_data, ff.ff_name);
  1234.         do_spawn(s);
  1235.       }
  1236.     }
  1237.     f1 = findnext(&ff);
  1238.   }
  1239. }
  1240.  
  1241. void check_exp(void)
  1242. {
  1243.   char s[MAXPATH], cmd[201];
  1244.   int ok;
  1245.  
  1246.   cd_to(maindir);
  1247.   sprintf(s, "%s\\EXP.EXE", maindir);
  1248.   if (!exist(s)) {
  1249.     log_it(1, "\n ! EXPort/Import module not found!");
  1250.     return;
  1251.   }
  1252.   ok = 0;
  1253.   sprintf(s, "%sS32767.NET", net_data);
  1254.   if (exist(s))
  1255.     ok = 1;
  1256.   sprintf(s, "%sINBOUND\\SUB*.*", net_data);
  1257.   if (exist(s))
  1258.     ok = 1;
  1259.   sprintf(s, "%sSPOOL\\UNK*.*", net_data);
  1260.   if (exist(s)) {
  1261.     ok = 1;
  1262.     sprintf(s, "%sSPOOL\\UNK-0*.*", net_data);
  1263.     if (exist(s))
  1264.       check_unk();
  1265.   }
  1266.   if (ok) {
  1267.     sprintf(cmd, "%s\\EXP.EXE S32767.NET %s %hu %s %s %s", maindir, net_data,
  1268.             net_sysnum, FWDNAME, FWDDOM, net_name);
  1269.     if (do_spawn(cmd)) {
  1270.       log_it(1, "\n ! %s during export!", strings[2]);
  1271.       return;
  1272.     }
  1273.   } else
  1274.     log_it(MOREINFO, "\n ■ No Internet mail or newsgroup posts to process.");
  1275. }
  1276.  
  1277. int check_for_lsl(void)
  1278. {
  1279.   union REGS r;
  1280.   struct SREGS s;
  1281.   char *intstr;
  1282.  
  1283.   for (r.h.ah = 0xc0; r.h.ah != 0; r.h.ah++) {
  1284.     r.h.al = 0;
  1285.     int86x(0x2f, &r, &r, &s);
  1286.     if (r.h.al == 0xff) {
  1287.       intstr = (char *) MK_FP(s.es, r.x.si);
  1288.       if (strncmp(intstr, "LINKSUP$", 8) == 0)
  1289.         return 1;
  1290.     }
  1291.   }
  1292.   return 0;
  1293. }
  1294.  
  1295. #ifndef PACKET
  1296. void klos_ppp(int pppd)
  1297. {
  1298.   char s[160];
  1299.   int i;
  1300.  
  1301.   if (pppd) {
  1302.     cd_to(maindir);
  1303.     if (MOREINFO)
  1304.       sprintf(s, "%s\\EPPPDD.EXE", maindir);
  1305.     else
  1306.       sprintf(s, "%s\\EPPPD.EXE", maindir);
  1307.     if (exist(s)) {
  1308.       output("\n ■ Dialing %s using %s... <Ctrl>-C to abort\n", DOMAIN, s);
  1309.       i = do_spawn(s);
  1310.     } else
  1311.       log_it(1, "\n ■ %s not in BBS directory!", s);
  1312.   } else {
  1313.     lsl_loaded = check_for_lsl();
  1314.     if (!lsl_loaded) {
  1315.       sprintf(s, "%s\\LSL.COM", maindir);
  1316.       if (exist(s)) {
  1317.         if (MOREINFO)
  1318.           output("\n ■ Loading Link Support Layer and ");
  1319.         do_spawn(s);
  1320.       } else {
  1321.         log_it(1, "\n ■ LSL.COM not in BBS main directory!");
  1322.         do_exit(EXIT_FAILURE);
  1323.       }
  1324.     } else {
  1325.       if (MOREINFO)
  1326.         output("\n ■ LSL already in memory - loading ");
  1327.     }
  1328.     sprintf(s, "%s\\PPP.EXE", maindir);
  1329.     if (exist(s)) {
  1330.       if (MOREINFO)
  1331.         output("PPP packet driver.");
  1332.       do_spawn(s);
  1333.     } else {
  1334.       log_it(1, "\n ■ %s\\PPP.EXE not found!", maindir);
  1335.       do_exit(EXIT_FAILURE);
  1336.     }
  1337.     while (kbhit())
  1338.       getch();
  1339.     sprintf(s, "%s\\PPPSTATE.EXE", maindir);
  1340.     if (exist(s)) {
  1341.       output("\n ■ Dialing %s... timeout %d seconds... ", DOMAIN, TIMEOUT);
  1342.       delay(2000);
  1343.       sprintf(s, "%s\\PPPSTATE.EXE WAIT=%d IP", maindir, TIMEOUT);
  1344.       i = do_spawn(s);
  1345.     } else {
  1346.       log_it(1, "\n ■ %s\\PPPSTATE.EXE not found!", maindir);
  1347.       do_exit(EXIT_FAILURE);
  1348.     }
  1349.   }
  1350.   switch (i) {
  1351.     case 0:
  1352.       if (!pppd)
  1353.         output(" connected!");
  1354.       break;
  1355.     case 1:
  1356.       log_it(1, "\n ■ Unable to establish connection... aborting");
  1357.       sprintf(s, "%s\\PPP U", maindir);
  1358.       do_spawn(s);
  1359.       if (!lsl_loaded) {
  1360.         sprintf(s, "%s\\LSL U", maindir);
  1361.         do_spawn(s);
  1362.       }
  1363.       do_exit(EXIT_FAILURE);
  1364.     case 2:
  1365.       output("\n ■ Unable to find PPP layer... aborting");
  1366.       if (!lsl_loaded) {
  1367.         sprintf(s, "%s\\LSL U", maindir);
  1368.         do_spawn(s);
  1369.       }
  1370.       do_exit(EXIT_FAILURE);
  1371.     default:
  1372.       if (pppd)
  1373.         log_it(1, "no connection.");
  1374.       else {
  1375.         log_it(1, "\n ■ %s PPPState #%d... aborting", strings[2], i);
  1376.         sprintf(s, "%s\\PPP U", maindir);
  1377.         do_spawn(s);
  1378.         if (!lsl_loaded) {
  1379.           sprintf(s, "%s\\LSL U", maindir);
  1380.           do_spawn(s);
  1381.         }
  1382.       }
  1383.       do_exit(EXIT_FAILURE);
  1384.   }
  1385.   if (!pppd) {
  1386.     delay(2000);
  1387.     sprintf(s, "%s\\PPPWAT.EXE", maindir);
  1388.     if (exist(s)) {
  1389.       do_spawn(s);
  1390.     } else {
  1391.       log_it(1, "\n ! %s\\PPPWAT.EXE not found!", maindir);
  1392.       do_exit(EXIT_FAILURE);
  1393.     }
  1394.     sprintf(s, "%s\\IPSTUB.EXE", maindir);
  1395.     if (exist(s)) {
  1396.       do_spawn(s);
  1397.     } else {
  1398.       log_it(1, "\n ■ %s\\IPSTUB.EXE not found!", maindir);
  1399.       do_exit(EXIT_FAILURE);
  1400.     }
  1401.   }
  1402. }
  1403.  
  1404. #endif
  1405.  
  1406. int main(int argc, char *argv[])
  1407. {
  1408.   char *ss, s[161], s1[MAXPATH], destaddr[101], temp[160], ttotal[21];
  1409.   int i, net_num_max, i1, dv, f, ok, news, totf, send, f1, result;
  1410.   unsigned long sentbytes, recdbytes, rnewsbytes, snewsbytes;
  1411.   unsigned short sy;
  1412.   float dspace;
  1413.   FILE *fp;
  1414.   clock_t starttime, mailtime, newstime;
  1415.   struct tm *time_now;
  1416.   struct ffblk ff;
  1417.   struct diskfree_t df;
  1418.   time_t some;
  1419.  
  1420.   get_dir(maindir, 0);
  1421.  
  1422.   i = i1 = 0;
  1423.   while ((environ[i] != NULL) && (i < 20)) {
  1424.     xenviron[i1++] = environ[i];
  1425.     ++i;
  1426.   }
  1427.   xenviron[i1] = NULL;
  1428.  
  1429.   strcpy(s, "CONFIG.DAT");
  1430.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1431.   if (f < 0) {
  1432.     output("\n ! %s NOT FOUND.", s);
  1433.     return 1;
  1434.   }
  1435.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1436.   sh_close(f);
  1437.  
  1438.   detect_multitask();
  1439.  
  1440.   switch (multitasker) {
  1441.     case 1:
  1442.       dv = get_dv_version();
  1443.       sprintf(tasker, "DesqView %d.%02d", dv / 256, dv % 256);
  1444.       break;
  1445.     case 2:
  1446.       dv = get_win_version();
  1447.       if (dv >= 4)
  1448.         strcpy(tasker, "Windows 95");
  1449.       else
  1450.         sprintf(tasker, "Windows %d.%02d", dv % 256, dv / 256);
  1451.       break;
  1452.     case 3:
  1453.       dv = get_dv_version();
  1454.       sprintf(tasker, "Windows and DesqView %d.%02d", dv / 256, dv % 256);
  1455.       break;
  1456.     case 4:
  1457.     case 5:
  1458.     case 6:
  1459.     case 7:
  1460.       if ((_osmajor / 10 == 2) && (_osminor >= 30))
  1461.         strcpy(tasker, "OS/2 Warp");
  1462.       else
  1463.         sprintf(tasker, "OS/2 %d.%2.2d", _osmajor / 10, _osminor);
  1464.       break;
  1465.     case 8:
  1466.       sprintf(tasker, "NETBIOS network");
  1467.       multitasker = 1;
  1468.       break;
  1469.     default:
  1470.       strcpy(tasker, "DOS");
  1471.       break;
  1472.   }
  1473.  
  1474.   ss = getenv("WWIV_INSTANCE");
  1475.   if (ss) {
  1476.     instance = atoi(ss);
  1477.     if ((instance <= 0) || (instance > 999)) {
  1478.       output("\n ! WWIV_INSTANCE must be 1..999!");
  1479.       instance = 1;
  1480.     }
  1481.   } else
  1482.     instance = 1;
  1483.   ss = NULL;
  1484.  
  1485.   strcpy(s, "CONFIG.OVR");
  1486.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1487.   if (f < 0) {
  1488.     output("\n ! %s NOT FOUND.", s);
  1489.     return 1;
  1490.   }
  1491.   sh_lseek(f, (instance - 1) * sizeof(configoverrec), SEEK_SET);
  1492.   sh_read(f, &syscfgovr, sizeof(configoverrec));
  1493.   sh_close(f);
  1494.  
  1495.   sprintf(s, "%sINSTANCE.DAT", syscfg.datadir);
  1496.   if (!exist(s)) {
  1497.     output("\n ! %s NOT FOUND.", s);
  1498.     return 1;
  1499.   }
  1500.  
  1501.   net_num_max = read_networks();
  1502.  
  1503.   news = 0;
  1504.   num_addr = 0;
  1505.   ss = argv[argc - 1];
  1506.   ok = 0;
  1507.   if (_fstrstr((char *) ss, ".") != NULL) {
  1508.     if (atoi(&ss[1]) < net_num_max) {
  1509.       netnum = atoi(&ss[1]);
  1510.       ok = 1;
  1511.     }
  1512.   } else {
  1513.     ss = (getenv("WWIV_NET"));
  1514.     netnum = atoi(ss);
  1515.     if (netnum < net_num_max)
  1516.       ok = 1;
  1517.   }
  1518.   if (!ok) {
  1519.     strcpy(s, "WWIV_NET.DAT");
  1520.     if ((fp = fsh_open(s, "rb")) != NULL) {
  1521.       fgets(s, 3, fp);
  1522.       netnum = atoi(s);
  1523.       if (netnum < net_num_max)
  1524.         ok = 1;
  1525.     }
  1526.     if (fp != NULL)
  1527.       fclose(fp);
  1528.   }
  1529.  
  1530.   ss = argv[1];
  1531.   if (strncmpi(ss, "/N", 2))
  1532.     ok = 0;
  1533.   set_net_num(netnum);
  1534.   sprintf(s, "%sADDRESS.1", net_data);
  1535.   if (!exist(s))
  1536.     ok = 0;
  1537.   if (ok) {
  1538.     *SMTPHOST = *POPHOST = *NEWSHOST = *TIMEHOST = *POPNAME = *POPPASS = 0;
  1539.     *IPADDR = *NETMASK = *DNS = *SDNS = *DOMAIN = *GATEWAY = *FWDNAME = *FWDDOM = 0;
  1540.     PPPD = KEEPSENT = CLEANUP = MOREINFO = NOLISTNAMES = ONECALL = 0;
  1541.     BBSNODE = ALLMAIL = PURGE = 1;
  1542.     TIMEOUT = INACTIVE = 60;
  1543.     SOCK_DELAY = 30;
  1544.     if (parse_net_ini()) {
  1545.       set_net_num(netnum);
  1546.       if (ini_section & INI_NETWORK) {
  1547.         if (!(ini_section & INI_GENERAL)) {
  1548.           output("\n ! [GENERAL] tag missing from NET.INI!");
  1549.           ok = 0;
  1550.         }
  1551.       } else {
  1552.         ok = 0;
  1553.         output("\n ! [FILENET] tag missing from NET.INI!");
  1554.       }
  1555.     } else {
  1556.       output("\n ! %s NET.INI!", strings[1]);
  1557.       ok = 0;
  1558.     }
  1559.   }
  1560.  
  1561.   if (ok) {
  1562.     if (create_contact_ppp())
  1563.       ok = 0;
  1564.   }
  1565.  
  1566.   if (ok) {
  1567.     log_it(1, "\n\n%s", version);
  1568.     output("\n%s\n", author);
  1569.     time(&some);
  1570.     time_now = localtime(&some);
  1571.     sprintf(s1, "\n ■ Running under %s on instance %d ", tasker, instance);
  1572.     strftime(s, 80, "at %I:%M%p, %d %b %y", time_now);
  1573.     strcat(s1, s);
  1574.     log_it(1, s1);
  1575.     log_it(1, "\n ■ Memory available : %ld bytes -", coreleft());
  1576.     if (net_data[1] == ':')
  1577.       i = net_data[0];
  1578.     else
  1579.       i = maindir[0];
  1580.     i = toupper(i) - 'A' + 1;
  1581.     _dos_getdiskfree(i, &df);
  1582.     dspace = ((float)df.avail_clusters * (float)df.bytes_per_sector *
  1583.              (float)df.sectors_per_cluster);
  1584.     if (dspace < 1024000.00) {
  1585.       log_it(1, "\n ■ Only %.1fK available on drive %c:... aborting!",
  1586.              dspace, i + '@');
  1587.       do_exit(EXIT_FAILURE);
  1588.     } else
  1589.       log_it(1, " Disk space : %c:%.1fM", i + '@', (dspace / 1024000L));
  1590.  
  1591.     set_net_num(netnum);
  1592.     ss = argv[1];
  1593.     sy = atoi(&ss[2]);
  1594.     destaddr[0] = 0;
  1595.     if (sy != 32767)
  1596.       good_addr(destaddr, sy);
  1597.  
  1598.     if ((destaddr[0] == 0) && (sy != 32767)) {
  1599.       output("\n ■ Using direct dial for @%hd.%s\n\n", sy, net_name);
  1600.       ok = 0;
  1601.     } else {
  1602.       ok = 1;
  1603.       if (sy == 32767) {
  1604.         if (ini_section & INI_NEWS)
  1605.           output("\n ■ Initiating newsgroup session...");
  1606.         else {
  1607.           output("\n ■ [NEWS] missing from NET.INI!");
  1608.           do_exit(EXIT_FAILURE);
  1609.         }
  1610.       }
  1611.     }
  1612.   }
  1613.   if (ok) {
  1614.     if (!MOREINFO)
  1615.       freopen(NULL, "w", stdout);
  1616.     if (CLEANUP)
  1617.       process_mail();
  1618.     set_net_num(netnum);
  1619.     sprintf(s, "%sSPOOL", net_data);
  1620.     if ((make_path(s)) < 0) {
  1621.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1622.       do_exit(EXIT_FAILURE);
  1623.     }
  1624.     sprintf(s, "%sMQUEUE", net_data);
  1625.     if ((make_path(s)) < 0) {
  1626.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1627.       do_exit(EXIT_FAILURE);
  1628.     }
  1629.     sprintf(s, "%sOUTBOUND", net_data);
  1630.     if ((make_path(s)) < 0) {
  1631.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1632.       do_exit(EXIT_FAILURE);
  1633.     }
  1634.     sprintf(s, "%sINBOUND", net_data);
  1635.     if ((make_path(s)) < 0) {
  1636.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1637.       do_exit(EXIT_FAILURE);
  1638.     }
  1639.     sprintf(s, "%sSENT", net_data);
  1640.     if ((make_path(s)) < 0) {
  1641.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1642.       do_exit(EXIT_FAILURE);
  1643.     }
  1644.     if (PURGE) {
  1645.       if ((KEEPSENT) && (sy != 32767)) {
  1646.         log_it(1, "\n ■ Purging sent packets older than %d day%s...", KEEPSENT,
  1647.                KEEPSENT == 1 ? "" : "s");
  1648.         sprintf(s, "%s\\PPPUTIL PURGE %s %d", maindir, net_data, KEEPSENT);
  1649.         do_spawn(s);
  1650.       }
  1651.     }
  1652.     sprintf(s, "%sCHECKNET", net_data);
  1653.     if ((make_path(s)) < 0) {
  1654.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1655.       do_exit(EXIT_FAILURE);
  1656.     }
  1657.     send = 1;
  1658.  
  1659.     check_exp();
  1660.  
  1661.     cd_to(maindir);
  1662.     if ((sy != 32767) || (ONECALL)) {
  1663.       output("\n ■ Preparing outbound packets...");
  1664.       if (!uu_packets()) {
  1665.         sprintf(s, "%sMQUEUE\\*.*", net_data);
  1666.         if (findfirst(s, &ff, 0) == 0) {
  1667.           output(" already in MQUEUE to be sent.");
  1668.         } else {
  1669.           output(" no mail or packets to send.");
  1670.           send = 0;
  1671.         }
  1672.       } else {
  1673.         backline();
  1674.         output(" ■ All packets prepared for transfer.");
  1675.       }
  1676.     }
  1677.     starttime = clock();
  1678.     sentbytes = recdbytes = snewsbytes = rnewsbytes = 0L;
  1679.     cd_to(maindir);
  1680.  
  1681.  
  1682. #ifndef PACKET
  1683.     sprintf(s, "%s%s%d.CFG", net_data, PPPD ? "PPPDRC" : "NET", instance);
  1684.     if (exist(s)) {
  1685.       sprintf(s1, "%s\\%s.CFG", maindir, PPPD ? "PPPDRC" : "NET");
  1686.       unlink(s1);
  1687.       if (!copyfile(s, s1))
  1688.         log_it(1, "\n ■ %s %s from %s.", strings[0], s1, s);
  1689.     }
  1690.  
  1691.     if (create_wattcp_cfg(PPPD))
  1692.         do_exit(EXIT_FAILURE);
  1693.  
  1694.     klos_ppp(PPPD);
  1695. #endif
  1696.  
  1697.     sprintf(temp_dir, "%sINBOUND\\", net_data);
  1698.  
  1699.     ok = 0;
  1700.     time(&some);
  1701.     time_now = localtime(&some);
  1702.     strftime(s, 80, "\n - SMTP/POP on %A, %B %d, %Y at %H:%M %p",
  1703.              time_now);
  1704.     log_it(0, s);
  1705.     sentbytes = recdbytes = 0L;
  1706.     if ((send) && ((sy != 32767) || (ONECALL))) {
  1707.       totf = 0;
  1708.       sprintf(temp, "%sMQUEUE\\*.*", net_data);
  1709.       f1 = findfirst(temp, &ff, FA_ARCH);
  1710.       while (f1 == 0) {
  1711.         ok = 1;
  1712.         ++totf;
  1713.         sentbytes += ff.ff_fsize;
  1714.         f1 = findnext(&ff);
  1715.       }
  1716.       sprintf(s1, "%sMQUEUE\\", net_data);
  1717.       sprintf(s, "%s\\POP.EXE -send %s %s %s %d %d", maindir, SMTPHOST, DOMAIN,
  1718.                 s1, MOREINFO, NOLISTNAMES);
  1719.       do_spawn(s);
  1720.       f1 = findfirst(temp, &ff, FA_ARCH);
  1721.       while (f1 == 0) {
  1722.         --totf;
  1723.         sentbytes -= ff.ff_fsize;
  1724.         f1 = findnext(&ff);
  1725.       }
  1726.       cd_to(maindir);
  1727.       if (ok) {
  1728.         backline();
  1729.         log_it(0, "\n");
  1730.         log_it(1, " ■ Outbound mail transfer completed : %d message%s (%ldK).",
  1731.                totf, totf == 1 ? "" : "s", ((sentbytes + 1023) / 1024));
  1732.       }
  1733.     }
  1734.     if ((sy != 32767) || (ONECALL)) {
  1735.       sprintf(s, "%s\\POP.EXE -receive %s %s %s %s %d %s %d %s n%hd",
  1736.               maindir, POPHOST, POPNAME, POPPASS,
  1737.               temp_dir, ALLMAIL, DOMAIN, MOREINFO,
  1738.               BBSNODE == 2 ? NODEPASS : "none",
  1739.               net_sysnum);
  1740.       result = do_spawn(s);
  1741.       sprintf(s1, "%s*.*", temp_dir);
  1742.       if ((result == EXIT_SUCCESS) || (exist(s1))) {
  1743.         sprintf(temp, "%s*.*", temp_dir);
  1744.         f1 = findfirst(temp, &ff, FA_ARCH);
  1745.         i = 0;
  1746.         while (f1 == 0) {
  1747.           if ((strncmp(ff.ff_name, "BAD", 3) != 0) && (strncmp(ff.ff_name, "SPM", 3) != 0) &&
  1748.               (strncmp(ff.ff_name, "SUB", 3) != 0) && (strncmp(ff.ff_name, "DUP", 3) != 0) &&
  1749.               (ff.ff_fsize)) {
  1750.             recdbytes += ff.ff_fsize;
  1751.             sprintf(s1, "%s%s", temp_dir, ff.ff_name);
  1752.             cd_to(maindir);
  1753.             sprintf(temp, "%s\\UU.EXE -decode %s %s %s", maindir, ff.ff_name,
  1754.                     temp_dir, net_data);
  1755.             if (!do_spawn(temp))
  1756.               unlink(s1);
  1757.           }
  1758.           f1 = findnext(&ff);
  1759.         }
  1760.       } else
  1761.         output("\n ■ No network packets to process");
  1762.     }
  1763.  
  1764.     check_exp();
  1765.  
  1766.     mailtime = clock() - starttime;
  1767.     if ((sy == 32767) || (ONECALL)) {
  1768.       time(&some);
  1769.       time_now = localtime(&some);
  1770.       strftime(s, 80, "\n - NEWS session beginning on %A, %B %d, %Y at %H:%M %p",
  1771.                time_now);
  1772.       log_it(0, s);
  1773.       news = 1;
  1774.       starttime = clock();
  1775.       set_net_num(netnum);
  1776.       sprintf(temp, "%sOUTBOUND\\*.*", net_data);
  1777.       f1 = findfirst(temp, &ff, FA_ARCH);
  1778.       while (f1 == 0) {
  1779.         snewsbytes += ff.ff_fsize;
  1780.         f1 = findnext(&ff);
  1781.       }
  1782.       cd_to(maindir);
  1783.       strcpy(s1, net_data);
  1784.       if (LAST(s1) == '\\')
  1785.         LAST(s1) = 0;
  1786.       sprintf(s, "%s\\NEWS.EXE %s %s %hu", maindir, s1, NEWSHOST, net_sysnum);
  1787.       ok = 1;
  1788.       do_spawn(s);
  1789.       set_net_num(netnum);
  1790.       sprintf(temp, "%sP0*.*", net_data);
  1791.       f1 = findfirst(temp, &ff, 0);
  1792.       while (f1 == 0) {
  1793.         rnewsbytes += ff.ff_fsize;
  1794.         f1 = findnext(&ff);
  1795.       }
  1796.     }
  1797.   } else {
  1798.     output("\n");
  1799.     set_net_num(netnum);
  1800.     strcpy(s, "NETWORK0.EXE");
  1801.     for (i = 1; i < argc; i++) {
  1802.       strcat(s, " ");
  1803.       strcat(s, argv[i]);
  1804.     }
  1805.     s[strlen(s) + 1] = '\0';
  1806.     do_it(s);
  1807.     exit(EXIT_SUCCESS);
  1808.   }
  1809.  
  1810.   sprintf(s1, "%s\\NTIME.EXE", maindir);
  1811.   if ((exist(s1)) && (*TIMEHOST)) {
  1812.     output("\n ■ Polling %s...  ", TIMEHOST);
  1813.     sprintf(s, "%s %s", s1, TIMEHOST);
  1814.     do_spawn(s);
  1815.   }
  1816.  
  1817. #ifndef PACKET
  1818.   unload_klos(PPPD);
  1819. #endif
  1820.  
  1821.   output("\n ■ Updating network connection records...");
  1822.  
  1823.   if ((sy != 32767) || ((sy == 32767) && (ONECALL))) {
  1824.     recdbytes = ((recdbytes + 1023) / 1024);
  1825.     sentbytes = ((sentbytes + 1023) / 1024);
  1826.     if (mailtime)
  1827.       sprintf(ttotal, "%3.1f", (mailtime / CLK_TCK / 60));
  1828.     else
  1829.       strcpy(ttotal, "0.1");
  1830.     sprintf(s, "%s\\PPPUTIL.EXE NETLOG %hd %lu %lu %s %s",
  1831.         maindir, sy, sentbytes, recdbytes, ttotal, net_name);
  1832.     if (do_spawn(s))
  1833.       log_it(1, "\n ! %s", strings[4]);
  1834.     if (update_contacts(sy, sentbytes, recdbytes))
  1835.       log_it(1, "\n ■ %s", strings[3]);
  1836.   }
  1837.   if (news) {
  1838.     if ((newstime = clock()) == (clock_t) - 1)
  1839.       log_it(1, "\n ■ NEWS time invalid.");
  1840.     else {
  1841.       newstime -= starttime;
  1842.       if (newstime)
  1843.         sprintf(ttotal, "%3.1f", (newstime / CLK_TCK / 60));
  1844.       else
  1845.         strcpy(ttotal, "0.1");
  1846.       rnewsbytes = ((rnewsbytes + 1023) / 1024);
  1847.       if (rnewsbytes > 9999L)
  1848.         rnewsbytes = 9999L;
  1849.       snewsbytes = ((snewsbytes + 1023) / 1024);
  1850.       if (update_contact(32767, snewsbytes, rnewsbytes))
  1851.         log_it(1, "\n ■ %s", strings[3]);
  1852.       sprintf(s, "%s\\PPPUTIL.EXE NETLOG 32767 %lu %lu %s %s", maindir, snewsbytes, rnewsbytes, ttotal, net_name);
  1853.       if (do_spawn(s))
  1854.         log_it(1, "\n ! %s", strings[4]);
  1855.     }
  1856.   }
  1857.   if (CLEANUP) {
  1858.     process_mail();
  1859.     set_net_num(netnum);
  1860.   }
  1861.   sprintf(s, "%s\\PPPUTIL.EXE TRIM %s NEWS.LOG", maindir, net_data);
  1862.   do_spawn(s);
  1863.   cd_to(maindir);
  1864.   set_net_num(netnum);
  1865.   log_it(1, "\n ■ %s completed!\n\n", version);
  1866.   return 0;
  1867. }
  1868.