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