home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC20A01.ZIP / NETWORK.CPP < prev    next >
Text File  |  1999-06-27  |  51KB  |  1,984 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 = "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, RETRIES;
  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.     if (curfile == 1) {
  635.       sprintf(fn, "%sADDRESS.1", net_data);
  636.       if (!exist(fn)) {
  637.         sprintf(fn, "%sADDRESS.NET", net_data);
  638.         curfile = 0;
  639.       }
  640.     } else
  641.       sprintf(fn, "%sADDRESS.%d", net_data, curfile);
  642.     if ((fp = fsh_open(fn, "rt")) == NULL)
  643.       curfile = -1;
  644.     while ((curfile >= 0) && (fgets(s, 80, fp) != NULL)) {
  645.       if (s[0] != '@')
  646.         continue;
  647.       ss = strtok(s, " \t\r");
  648.       node = atoi(&ss[1]);
  649.       if (node) {
  650.         ss = strtok(NULL, " \t\r");
  651.         trimstr1(ss);
  652.         curaddr.sysnum = node;
  653.         strcpy(curaddr.address, ss);
  654.         if (ss[0]) {
  655.           fwrite(&curaddr, sizeof(net_address_rec), 1, fc);
  656.           ++num_addr;
  657.         }
  658.       }
  659.     }
  660.     if (fp != NULL)
  661.       fclose(fp);
  662.     ++curfile;
  663.   } while (curfile > 0);
  664.   fseek(fc, 0L, SEEK_SET);
  665.   sprintf(fn, "%sADDRESS.0", net_data);
  666.   if ((fp = fsh_open(fn, "rt")) == NULL) {
  667.     if (fc != NULL)
  668.       fclose(fc);
  669.     return (0);
  670.   }
  671.   while (fgets(s, 80, fp) != NULL) {
  672.     if (s[0] != '@')
  673.       continue;
  674.     ss = strtok(s, " \t\r");
  675.     node = atoi(&ss[1]);
  676.     do {
  677.       ss = strtok(NULL, " \t\r");
  678.       switch (ss[0]) {
  679.         case '-':
  680.           for (i = 0; i < num_addr; i++) {
  681.             fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  682.             fread(&curaddr, sizeof(net_address_rec), 1, fc);
  683.             if (node == curaddr.sysnum) {
  684.               curaddr.sysnum = 0;
  685.               fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  686.               fwrite(&curaddr, sizeof(net_address_rec), 1, fc);
  687.             }
  688.           }
  689.           break;
  690.       }
  691.     } while (ss);
  692.   }
  693.   if (fp != NULL)
  694.     fclose(fp);
  695.   if (fc != NULL)
  696.     fclose(fc);
  697.   return (0);
  698. }
  699.  
  700. void good_addr(char *address, unsigned short sn)
  701. {
  702.   char fn[101];
  703.   int i;
  704.   net_address_rec curaddr;
  705.   FILE *fc;
  706.  
  707.   address[0] = 0;
  708.   sprintf(fn, "%sCONTACT.PPP", net_data);
  709.   if ((fc = fsh_open(fn, "rb+")) == NULL) {
  710.     log_it(1, "\n ■ %s %s!\n", strings[1], fn);
  711.     return;
  712.   }
  713.   for (i = 0; ((i < num_addr) && (!address[0])); i++) {
  714.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  715.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  716.     if (sn == curaddr.sysnum)
  717.       strcpy(address, curaddr.address);
  718.   }
  719.   if (fc != NULL)
  720.     fclose(fc);
  721. }
  722.  
  723. int copyfile(char *infn, char *outfn)
  724. {
  725.   int f1, f2, i;
  726.   char *b;
  727.   struct ftime ft;
  728.  
  729.   if ((strcmp(infn, outfn) != 0) && (exist(infn)) && (!exist(outfn))) {
  730.     if ((b = (char *) farmalloc(16400)) == NULL)
  731.       return 0;
  732.     f1 = sh_open1(infn, O_RDONLY | O_BINARY);
  733.     if (!f1) {
  734.       farfree(b);
  735.       b = NULL;
  736.       return 0;
  737.     }
  738.     getftime(f1, &ft);
  739.     f2 = sh_open(outfn, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  740.     if (!f2) {
  741.       farfree(b);
  742.       b = NULL;
  743.       f1 = sh_close(f1);
  744.       return 0;
  745.     }
  746.     i = sh_read(f1, (char *) b, 16384);
  747.     while (i > 0) {
  748.       sh_write(f2, (char *) b, i);
  749.       i = sh_read(f1, (char *) b, 16384);
  750.     }
  751.     f1 = sh_close(f1);
  752.     setftime(f2, &ft);
  753.     f2 = sh_close(f2);
  754.     farfree(b);
  755.     b = NULL;
  756.   }
  757.   return 1;
  758. }
  759.  
  760. void do_exit(int exitlevel)
  761. {
  762.   delay(2000);
  763.   exit(2 - exitlevel);
  764. }
  765.  
  766. int uu(char *fn, char *pktname, char *dest)
  767. {
  768.   int ok;
  769.   char s[121], s1[201], s2[81];
  770.   FILE *fp;
  771.  
  772.   sprintf(s, "%sMQUEUE\\%s.UUE", net_data, pktname);
  773.   if ((fp = fsh_open(s, "wt")) == NULL) {
  774.     log_it(1, "\n ■ %s %s!", strings[0], s);
  775.     do_exit(EXIT_FAILURE);
  776.   } else {
  777.     if (BBSNODE == 2)
  778.       sprintf(s2, "From: n%hd@filenet.wwiv.net\n", net_sysnum);
  779.     else
  780.       sprintf(s2, "From: %s@%s\n", POPNAME, DOMAIN);
  781.     fprintf(fp, s2);
  782.     sprintf(s2, "To: %s\n", dest);
  783.     fprintf(fp, s2);
  784.     fprintf(fp, "MIME-Version: 1.0\n");
  785.     fprintf(fp, "Content-Type: text/plain; charset=us-ascii\n");
  786.     fprintf(fp, "Content-Transfer-Encoding: x-uue\n");
  787.     sprintf(s2, "Message-ID: <%s-%s@%s>\n", pktname, POPNAME, DOMAIN);
  788.     fprintf(fp, s2);
  789.     sprintf(s2, "Subject: NET PACKET : %s.UUE\n\n", pktname);
  790.     fprintf(fp, s2);
  791.     sprintf(s2, "NET: %s\n\n", net_name);
  792.     fprintf(fp, s2);
  793.  
  794.   }
  795.   if (fp != NULL)
  796.     fclose(fp);
  797.   sprintf(s1, "%s\\UU.EXE -encode %s %s", maindir, fn, s);
  798.   ok = do_spawn(s1);
  799.   if (MOREINFO)
  800.     output("\n");
  801.   return ok;
  802. }
  803.  
  804. int update_contact(unsigned short sy, unsigned long sb, unsigned long rb, int set_time)
  805. {
  806.   char s[101];
  807.   int i, i1, f;
  808.   long cur_time, l;
  809.  
  810.   sprintf(s, "%sCONTACT.NET", net_data);
  811.   f = sh_open1(s, O_RDONLY | O_BINARY);
  812.   if (f >= 0) {
  813.     l = filelength(f);
  814.     netcfg.num_ncn = (int) (l / sizeof(net_contact_rec));
  815.     if ((netcfg.ncn = (net_contact_rec *) farmalloc((netcfg.num_ncn + 2) *
  816.                                         sizeof(net_contact_rec))) == NULL) {
  817.       f = sh_close(f);
  818.       return 1;
  819.     }
  820.     sh_lseek(f, 0L, SEEK_SET);
  821.     sh_read(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
  822.     f = sh_close(f);
  823.   }
  824.   for (i = 0; i < netcfg.num_ncn; i++)
  825.     if (netcfg.ncn[i].systemnumber == sy)
  826.       i1 = i;
  827.   if (set_time) {
  828.     time(&cur_time);
  829.     netcfg.ncn[i1].lasttry = cur_time;
  830.     ++netcfg.ncn[i1].numcontacts;
  831.     if (!netcfg.ncn[i1].firstcontact)
  832.       netcfg.ncn[i1].firstcontact = cur_time;
  833.     netcfg.ncn[i1].lastcontact = cur_time;
  834.     netcfg.ncn[i1].lastcontactsent = cur_time;
  835.   }
  836.   netcfg.ncn[i1].bytes_sent += sb;
  837.   if (rb)
  838.     netcfg.ncn[i1].bytes_received += rb;
  839.   netcfg.ncn[i1].bytes_waiting = 0L;
  840.   sprintf(s, "%sS%hd.net", net_data, sy);
  841.   if (!exist(s))
  842.     sprintf(s, "%sZ%hd.net", net_data, sy);
  843.   f = sh_open1(s, O_RDONLY | O_BINARY);
  844.   if (f > 0) {
  845.     netcfg.ncn[i1].bytes_waiting += (long) filelength(f);
  846.     close(f);
  847.   }
  848.   sprintf(s, "%sCONTACT.NET", net_data);
  849.   f = sh_open1(s, O_RDWR | O_CREAT | O_BINARY);
  850.   if (f > 0) {
  851.     sh_lseek(f, 0L, SEEK_SET);
  852.     sh_write(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
  853.     f = sh_close(f);
  854.   }
  855.   if (netcfg.ncn)
  856.     farfree(netcfg.ncn);
  857.   return 0;
  858. }
  859.  
  860.  
  861. int update_contacts(unsigned short sy, unsigned long sb, unsigned long rb)
  862. {
  863.   int i, i1, rc;
  864.   char fn[101];
  865.   net_address_rec curaddr;
  866.   FILE *fc;
  867.  
  868.   rc = 0;
  869.   sprintf(fn, "%sCONTACT.PPP", net_data);
  870.   if ((fc = fsh_open(fn, "rb+")) == NULL) {
  871.     log_it(1, "\n ■ %s %s!\n", strings[1], fn);
  872.     rc = 1;
  873.     return (rc);
  874.   }
  875.   for (i = 0; i < num_addr; i++) {
  876.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  877.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  878.     if (curaddr.sysnum != 0) {
  879.       if (curaddr.sysnum == sy)
  880.         i1 = update_contact(curaddr.sysnum, sb, rb, 1);
  881.       else
  882.         i1 = update_contact(curaddr.sysnum, 0, 0, 1);
  883.       if (i1)
  884.         rc = 1;
  885.     }
  886.   }
  887.   if (fc != NULL)
  888.     fclose(fc);
  889.   return (rc);
  890. }
  891.  
  892. int uu_packets(void)
  893. {
  894.   char pktname[21], s[121], s1[121], s2[121], s3[121], temp[121];
  895.   int found, sz, f, f1, i;
  896.   unsigned long sbytes, basename;
  897.   net_address_rec curaddr;
  898.   FILE *fc;
  899.  
  900.   num_sys_list = 0;
  901.   found = 0;
  902.   basename = time(NULL);
  903.   sprintf(s, "%sBBSDATA.NET", net_data);
  904.   f = sh_open1(s, O_RDONLY | O_BINARY);
  905.   if (f > 0) {
  906.     num_sys_list = (int) (filelength(f) / sizeof(net_system_list_rec));
  907.     if ((netsys = (net_system_list_rec *) farmalloc((num_sys_list + 2) *
  908.                                     sizeof(net_system_list_rec))) == NULL) {
  909.       log_it(1, "\n ■ Unable to allocate %d bytes of memory for BBSDATA.NET",
  910.              (int) (num_sys_list + 2) * sizeof(net_system_list_rec));
  911.       sh_close(f);
  912.       return 0;
  913.     }
  914.     sh_lseek(f, 0L, SEEK_SET);
  915.     sh_read(f, (void *) netsys, num_sys_list * sizeof(net_system_list_rec));
  916.     sh_close(f);
  917.   } else
  918.     return 0;
  919.  
  920.   sprintf(s1, "%sCONTACT.PPP", net_data);
  921.   if ((fc = fsh_open(s1, "rb+")) == NULL) {
  922.     log_it(1, "\n ■ %s %s!\n", strings[1], s1);
  923.     farfree(netsys);
  924.     return 0;
  925.   }
  926.   for (i = 0; i < num_addr; i++) {
  927.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  928.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  929.     if ((valid_system(curaddr.sysnum)) && (curaddr.sysnum != 32767)) {
  930.       sprintf(s1, "%sS%hd.NET", net_data, curaddr.sysnum);
  931.       if (exist(s1)) {
  932.         sz = 0;
  933.         found = 1;
  934.       } else {
  935.         sprintf(s1, "%sZ%hd.NET", net_data, curaddr.sysnum);
  936.         if (exist(s1)) {
  937.           sz = 1;
  938.           found = 1;
  939.         } else
  940.           continue;
  941.       }
  942.       do {
  943.         sprintf(pktname, "%8.8lx", ++basename);
  944.         sprintf(temp, "%sMQUEUE\\%s.UUE", net_data, pktname);
  945.       } while (exist(temp));
  946.       backline();
  947.       output("\r ■ Encoding %s%hd.NET as %s.UUE -",
  948.              sz ? "Z" : "S", curaddr.sysnum, strupr(pktname));
  949.       if ((uu(s1, pktname, curaddr.address)) != EXIT_SUCCESS) {
  950.         output("\n ■ %s %sMQUEUE\\%s.UUE", strings[0], net_data, pktname);
  951.         if (fc != NULL)
  952.           fclose(fc);
  953.         farfree(netsys);
  954.         do_exit(EXIT_FAILURE);
  955.       } else {
  956.         sprintf(s3, "%sMQUEUE\\%s.UUE", net_data, pktname);
  957.         f1 = sh_open1(s3, O_RDONLY | O_BINARY);
  958.         if (f1 > 0) {
  959.           sbytes = (long) filelength(f1);
  960.           f = sh_close(f1);
  961.         }
  962.         if (KEEPSENT) {
  963.           sprintf(s2, "%sSENT\\%s.SNT", net_data, pktname);
  964.           if (!copyfile(s3, s2))
  965.             output("\n ■ %s %s%hd.NET", strings[0], sz ? "Z" : "S", curaddr.sysnum);
  966.         }
  967.         unlink(s1);
  968.         update_contact(curaddr.sysnum, sbytes, 0, 0);
  969.       }
  970.     }
  971.   }
  972.   if (fc != NULL)
  973.     fclose(fc);
  974.   farfree(netsys);
  975.   return found;
  976. }
  977.  
  978. int parse_net_ini(void)
  979. {
  980.   char cursect, fn[MAXPATH], line[121], vanline[121], *ss;
  981.   FILE *fp;
  982.  
  983.   sprintf(fn, "%s\\NET.INI", maindir);
  984.   if ((fp = fsh_open(fn, "rt")) == NULL) {
  985.     output("\n ! Unable to read %s.", fn);
  986.     return (0);
  987.   }
  988.   while (fgets(line, 80, fp)) {
  989.     strcpy(vanline, line);
  990.     stripspace(line);
  991.     ss = NULL;
  992.     ss = strtok(line, "=");
  993.     if (ss)
  994.       ss = strtok(NULL, "\n");
  995.     if ((line[0] == ';') || (line[0] == '\n') || (strlen(line) == 0))
  996.       continue;
  997.     if ((strnicmp(line, "[FILENET]", 9) == 0) ||
  998.         (strnicmp(line, "[PPPNET]", 8) == 0) ||
  999.         (strnicmp(line, "[NETWORK]", 8) == 0)) {
  1000.       cursect = INI_NETWORK;
  1001.       ini_section |= INI_NETWORK;
  1002.       continue;
  1003.     }
  1004.     if (strnicmp(line, "[GENERAL]", 9) == 0) {
  1005.       cursect = INI_GENERAL;
  1006.       ini_section |= INI_GENERAL;
  1007.       continue;
  1008.     }
  1009.     if (strnicmp(line, "[NEWS]", 6) == 0) {
  1010.       cursect = INI_NEWS;
  1011.       ini_section |= INI_NEWS;
  1012.       continue;
  1013.     }
  1014.     if (cursect & INI_NETWORK) {
  1015.       if (strnicmp(line, "TIMEHOST", 8) == 0) {
  1016.         if (ss)
  1017.           strcpy(TIMEHOST, ss);
  1018.         continue;
  1019.       }
  1020.       if (strnicmp(line, "PRIMENET", 8) == 0) {
  1021.         if (ss)
  1022.           strcpy(PRIMENET, ss);
  1023.         continue;
  1024.       }
  1025.       if (strnicmp(line, "SMTPHOST", 8) == 0) {
  1026.         if (ss)
  1027.           strcpy(SMTPHOST, ss);
  1028.         continue;
  1029.       }
  1030.       if (strnicmp(line, "POPHOST", 7) == 0) {
  1031.         if (ss)
  1032.           strcpy(POPHOST, ss);
  1033.         continue;
  1034.       }
  1035.       if (strnicmp(line, "PROXY", 5) == 0) {
  1036.         if (ss)
  1037.           strcpy(PROXY, ss);
  1038.         continue;
  1039.       }
  1040.       if (strnicmp(line, "POPNAME", 7) == 0) {
  1041.         if (ss)
  1042.           strcpy(POPNAME, ss);
  1043.         continue;
  1044.       }
  1045.       if (strnicmp(line, "POPPASS", 7) == 0) {
  1046.         if (ss)
  1047.           strcpy(POPPASS, ss);
  1048.         continue;
  1049.       }
  1050.     }
  1051.     if (strnicmp(line, "NODEPASS", 8) == 0) {
  1052.       if (ss) {
  1053.         strcpy(NODEPASS, ss);
  1054.         BBSNODE = 2;
  1055.       }
  1056.       continue;
  1057.     }
  1058.     if (cursect & INI_GENERAL) {
  1059.       if (strnicmp(line, "TIMEOUT", 7) == 0) {
  1060.         if (atoi(ss))
  1061.           TIMEOUT = atoi(ss);
  1062.         continue;
  1063.       }
  1064.       if (strnicmp(line, "SOCK_DELAY", 10) == 0) {
  1065.         if (atoi(ss))
  1066.           SOCK_DELAY = atoi(ss);
  1067.         continue;
  1068.       }
  1069.       if ((strnicmp(line, "INACTIVE", 8) == 0) || (strnicmp(line, "SOCK_INACTIVE", 13) == 0)) {
  1070.         if (atoi(ss))
  1071.           INACTIVE = atoi(ss);
  1072.         continue;
  1073.       }
  1074.       if (strnicmp(line, "KEEPSENT", 8) == 0) {
  1075.         if (atoi(ss))
  1076.           KEEPSENT = atoi(ss);
  1077.         continue;
  1078.       }
  1079.       if (strnicmp(line, "RETRIES", 7) == 0) {
  1080.         if (atoi(ss))
  1081.           RETRIES = atoi(ss);
  1082.           if (RETRIES < 1)
  1083.             RETRIES = 1;
  1084.           if (RETRIES > 10)
  1085.             RETRIES = 10;
  1086.         continue;
  1087.       }
  1088.       if (strnicmp(line, "PURGE", 5) == 0) {
  1089.         if (toupper(ss[0]) == 'N')
  1090.           PURGE = 0;
  1091.         continue;
  1092.       }
  1093.       if (strnicmp(line, "DRIVER", 6) == 0) {
  1094.         if (toupper(ss[0]) == 'P')
  1095.           PPPD = 1;
  1096.         continue;
  1097.       }
  1098.       if (strnicmp(line, "ALLMAIL", 7) == 0) {
  1099.         if (toupper(ss[0]) == 'N')
  1100.           ALLMAIL = 0;
  1101.         continue;
  1102.       }
  1103.       if (strnicmp(line, "ONECALL", 7) == 0) {
  1104.         if (toupper(ss[0]) == 'Y')
  1105.           ONECALL = 1;
  1106.         continue;
  1107.       }
  1108.       if (strnicmp(line, "MOREINFO", 8) == 0) {
  1109.         if (toupper(ss[0]) == 'Y')
  1110.           MOREINFO = 1;
  1111.         continue;
  1112.       }
  1113.       if (strnicmp(line, "NOWATTCP", 8) == 0) {
  1114.         if (toupper(ss[0]) == 'Y')
  1115.           NOWATTCP = 1;
  1116.         continue;
  1117.       }
  1118.       if (strnicmp(line, "NOLISTNAMES", 11) == 0) {
  1119.         if (toupper(ss[0]) == 'Y')
  1120.           NOLISTNAMES = 1;
  1121.         continue;
  1122.       }
  1123.       if (strnicmp(line, "CLEANUP", 7) == 0) {
  1124.         if (toupper(ss[0]) == 'Y')
  1125.           CLEANUP = 1;
  1126.         continue;
  1127.       }
  1128.       if (strnicmp(line, "IPADDR", 6) == 0) {
  1129.         if ((ss) && (ss[0] != '0'))
  1130.           strcpy(IPADDR, ss);
  1131.         continue;
  1132.       }
  1133.       if (strnicmp(line, "NETMASK", 7) == 0) {
  1134.         if (ss)
  1135.           strcpy(NETMASK, ss);
  1136.         continue;
  1137.       }
  1138.       if (strnicmp(line, "DNS", 3) == 0) {
  1139.         if (ss)
  1140.           strcpy(DNS, ss);
  1141.         continue;
  1142.       }
  1143.       if (strnicmp(line, "SDNS", 3) == 0) {
  1144.         if (ss)
  1145.           strcpy(SDNS, ss);
  1146.         continue;
  1147.       }
  1148.       if (strnicmp(line, "DOMAIN", 6) == 0) {
  1149.         if (ss)
  1150.           strcpy(DOMAIN, ss);
  1151.         continue;
  1152.       }
  1153.       if (strnicmp(line, "FWDNAME", 7) == 0) {
  1154.         if (ss)
  1155.           strcpy(FWDNAME, ss);
  1156.         continue;
  1157.       }
  1158.       if (strnicmp(line, "FWDDOM", 6) == 0) {
  1159.         if (ss)
  1160.           strcpy(FWDDOM, ss);
  1161.         continue;
  1162.       }
  1163.       if (strnicmp(line, "GATEWAY", 7) == 0) {
  1164.         if ((ss) && (ss[0] != '0'))
  1165.           strcpy(GATEWAY, ss);
  1166.         continue;
  1167.       }
  1168.     }
  1169.     if (cursect & INI_NEWS) {
  1170.       if (strnicmp(line, "NEWSHOST", 8) == 0) {
  1171.         if (ss)
  1172.           strcpy(NEWSHOST, ss);
  1173.         continue;
  1174.       }
  1175.     }
  1176.   }
  1177.   if (!FWDNAME[0])
  1178.     strcpy(FWDNAME, POPNAME);
  1179.   if (!FWDDOM[0])
  1180.     strcpy(FWDDOM, DOMAIN);
  1181.   if (fp != NULL)
  1182.     fclose(fp);
  1183.   return (1);
  1184. }
  1185.  
  1186. int read_networks(void)
  1187. {
  1188.   int f, max;
  1189.   char s[121];
  1190.  
  1191.   sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
  1192.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1193.   max = 0;
  1194.   if (f > 0)
  1195.     max = (int) (filelength(f) / sizeof(net_networks_rec));
  1196.   sh_close(f);
  1197.   return max;
  1198. }
  1199.  
  1200. void do_it(char *cl)
  1201. {
  1202.   int i, i1, l;
  1203.   char *s, *ss[30];
  1204.  
  1205.   s = _fstrdup(cl);
  1206.   ss[0] = s;
  1207.   i = 1;
  1208.   l = strlen(s);
  1209.   for (i1 = 1; i1 < l; i1++)
  1210.     if (s[i1] == 32) {
  1211.       s[i1] = 0;
  1212.       ss[i++] = &(s[i1 + 1]);
  1213.     }
  1214.   ss[i] = NULL;
  1215.   execvpe(ss[0], ss, xenviron);
  1216.   if (s != NULL)
  1217.     farfree(s);
  1218. }
  1219.  
  1220. int create_wattcp_cfg(int pppd)
  1221. {
  1222.   char s1[101], fn[MAXPATH];
  1223.   FILE *fp;
  1224.  
  1225.   if (IPADDR[0] == 0)
  1226.     strcpy(IPADDR, "0.0.0.0");
  1227.  
  1228.   sprintf(fn, "%s\\WATTCP.CFG", maindir);
  1229.   if ((fp = fsh_open(fn, "wt+")) == NULL) {
  1230.     log_it(1, "\n ■ %s %s\\WATTCP.CFG... aborting!", strings[1], maindir);
  1231.     return 1;
  1232.   }
  1233.   if (pppd)
  1234.     fprintf(fp, "my_ip=bootp\n");
  1235.   else {
  1236.     fprintf(fp, "my_ip=%s\n", IPADDR);
  1237.     fprintf(fp, "netmask=%s\n", NETMASK);
  1238.     if (GATEWAY[0] == 0) {
  1239.       strcpy(s1, IPADDR);
  1240.       while (LAST(s1) != '.')
  1241.         LAST(s1) = 0;
  1242.       strcat(s1, "1");
  1243.       strcpy(GATEWAY, s1);
  1244.     }
  1245.     fprintf(fp, "gateway=%s\n", GATEWAY);
  1246.   }
  1247.   fprintf(fp, "nameserver=%s\n", DNS);
  1248.   if (SDNS[0] != 0)
  1249.     fprintf(fp, "nameserver=%s\n", SDNS);
  1250.   fprintf(fp, "domains=\"%s\"\n", DOMAIN);
  1251.   fprintf(fp, "hostname=\"%s\"\n", POPNAME);
  1252.   fprintf(fp, "sockdelay=%d\n", SOCK_DELAY);
  1253.   fprintf(fp, "inactive=%d\n", INACTIVE);
  1254.   fclose(fp);
  1255.   return 0;
  1256. }
  1257.  
  1258. char *stristr(char *string, char *pattern)
  1259. {
  1260.   char *pptr, *sptr, *start;
  1261.   unsigned int slen, plen;
  1262.  
  1263.   for (start = string, pptr = pattern, slen = strlen(string),
  1264.        plen = strlen(pattern); slen >= plen; start++, slen--) {
  1265.     while (toupper(*start) != toupper(*pattern)) {
  1266.       start++;
  1267.       slen--;
  1268.       if (slen < plen)
  1269.         return (NULL);
  1270.     }
  1271.     sptr = start;
  1272.     pptr = pattern;
  1273.     while (toupper(*sptr) == toupper(*pptr)) {
  1274.       sptr++;
  1275.       pptr++;
  1276.       if ('\0' == *pptr)
  1277.         return (start);
  1278.     }
  1279.   }
  1280.   return (NULL);
  1281. }
  1282.  
  1283. int check_encode(char *fn)
  1284. {
  1285.   char s[121], s1[121];
  1286.   int lines, encoded;
  1287.   FILE *fp;
  1288.  
  1289.   if ((fp = fsh_open(fn, "r")) == NULL)
  1290.     return 0;
  1291.  
  1292.   lines = encoded = 0;
  1293.  
  1294.   while ((fgets(s, 120, fp)) && (++lines < 200)) {
  1295.     if (*s == '')
  1296.       strcpy(s1, &s[3]);
  1297.     else
  1298.       strcpy(s1, s);
  1299.     if (strnicmp(s1, "begin 6", 7) == 0) {
  1300.       encoded = 1;
  1301.       break;
  1302.     }
  1303.     if (strnicmp(s1, "Content-Type", 12) == 0) {
  1304.       if (stristr(s1, "text/plain") == 0)
  1305.         encoded = 1;
  1306.     }
  1307.     if (strnicmp(s1, "Content-Transfer-Encoding", 25) == 0) {
  1308.       if (stristr(s1, "8bit")) {
  1309.         encoded = 1;
  1310.         break;
  1311.       }
  1312.     }
  1313.     if (stristr(s1, "This is a multi-part message in MIME format.")) {
  1314.       encoded = 1;
  1315.       break;
  1316.     }
  1317.   }
  1318.  
  1319.   if (fp != NULL)
  1320.     fclose(fp);
  1321.  
  1322.   if (encoded)
  1323.     log_it(MOREINFO, "\n ■ %s appears to contain encoded data.", fn);
  1324.  
  1325.   return encoded;
  1326. }
  1327.  
  1328. void check_unk(void)
  1329. {
  1330.   char s[101], fn[MAXPATH], newfn[MAXPATH];
  1331.   int i, f, f1;
  1332.   long l;
  1333.   struct ffblk ff;
  1334.  
  1335.   sprintf(fn, "%sINBOUND\\UNK-0*.*", net_data);
  1336.   f1 = findfirst(fn, &ff, 0);
  1337.   while (f1 == 0) {
  1338.     sprintf(fn, "%sINBOUND\\%s", net_data, ff.ff_name);
  1339.     f = sh_open1(fn, O_RDONLY | O_BINARY);
  1340.     l = filelength(f);
  1341.     f = sh_close(f);
  1342.     if (l > 32767L) {
  1343.       if (!check_encode(fn)) {
  1344.         sprintf(s, "%s\\PPPUTIL.EXE CHUNK %s %s", maindir, net_data, ff.ff_name);
  1345.         do_spawn(s);
  1346.       } else
  1347.         log_it(MOREINFO, "\n ! %s contains encoded data.", ff.ff_name);
  1348.     } else {
  1349.       i = 0;
  1350.       fnsplit(fn, NULL, NULL, s, NULL);
  1351.       sprintf(newfn, "%sSPOOL\\%s.%03d", net_data, s, ++i);
  1352.       while (exist(newfn))
  1353.         sprintf(newfn, "%sSPOOL\\%s.%03d", net_data, s, ++i);
  1354.       if (copyfile(fn, newfn))
  1355.         unlink(fn);
  1356.     }
  1357.     f1 = findnext(&ff);
  1358.   }
  1359. }
  1360.  
  1361. void check_exp(void)
  1362. {
  1363.   char s[MAXPATH], cmd[201];
  1364.   int ok;
  1365.  
  1366.   cd_to(maindir);
  1367.   sprintf(s, "%s\\EXP.EXE", maindir);
  1368.   if (!exist(s)) {
  1369.     log_it(1, "\n ! EXPort/Import module not found!");
  1370.     return;
  1371.   }
  1372.   ok = 0;
  1373.   sprintf(s, "%sS32767.NET", net_data);
  1374.   if (exist(s))
  1375.     ok = 1;
  1376.   sprintf(s, "%sINBOUND\\SUB*.*", net_data);
  1377.   if (exist(s))
  1378.     ok = 1;
  1379.   sprintf(s, "%sINBOUND\\UNK*.*", net_data);
  1380.   if (exist(s)) {
  1381.     ok = 1;
  1382.     sprintf(s, "%sINBOUND\\UNK-0*.*", net_data);
  1383.     if (exist(s))
  1384.       check_unk();
  1385.   }
  1386.   sprintf(s, "%sSPOOL\\UNK*.*", net_data);
  1387.   if (exist(s))
  1388.     ok = 1;
  1389.  
  1390.   if (ok) {
  1391.     sprintf(cmd, "%s\\EXP.EXE S32767.NET %s %hu %s %s %s", maindir, net_data,
  1392.             net_sysnum, FWDNAME, FWDDOM, net_name);
  1393.     if (do_spawn(cmd)) {
  1394.       log_it(1, "\n ! %s during export!", strings[2]);
  1395.       return;
  1396.     }
  1397.   } else
  1398.     log_it(MOREINFO, "\n ■ No Internet mail or newsgroup posts to process.");
  1399. }
  1400.  
  1401. int check_for_lsl(void)
  1402. {
  1403.   union REGS r;
  1404.   struct SREGS s;
  1405.   char *intstr;
  1406.  
  1407.   for (r.h.ah = 0xc0; r.h.ah != 0; r.h.ah++) {
  1408.     r.h.al = 0;
  1409.     int86x(0x2f, &r, &r, &s);
  1410.     if (r.h.al == 0xff) {
  1411.       intstr = (char *) MK_FP(s.es, r.x.si);
  1412.       if (strncmp(intstr, "LINKSUP$", 8) == 0)
  1413.         return 1;
  1414.     }
  1415.   }
  1416.   return 0;
  1417. }
  1418.  
  1419. #ifndef PACKET
  1420. int klos_ppp(int pppd)
  1421. {
  1422.   char s[160];
  1423.   int i;
  1424.  
  1425.   if (pppd) {
  1426.     cd_to(maindir);
  1427.     if (MOREINFO)
  1428.       sprintf(s, "%s\\EPPPDD.EXE", maindir);
  1429.     else
  1430.       sprintf(s, "%s\\EPPPD.EXE", maindir);
  1431.     if (exist(s)) {
  1432.       output("\n ■ Dialing %s using %s - [Ctrl-C] aborts...\n", DOMAIN, s);
  1433.       i = do_spawn(s);
  1434.     } else
  1435.       log_it(1, "\n ■ %s not in BBS directory!", s);
  1436.   } else {
  1437.     lsl_loaded = check_for_lsl();
  1438.     if (!lsl_loaded) {
  1439.       sprintf(s, "%s\\LSL.COM", maindir);
  1440.       if (exist(s)) {
  1441.         if (MOREINFO)
  1442.           output("\n ■ Loading Link Support Layer and ");
  1443.         do_spawn(s);
  1444.       } else {
  1445.         log_it(1, "\n ■ LSL.COM not in BBS main directory!");
  1446.         exit(EXIT_FAILURE);
  1447.       }
  1448.     } else {
  1449.       if (MOREINFO)
  1450.         output("\n ■ LSL already in memory - loading ");
  1451.     }
  1452.     sprintf(s, "%s\\PPP.EXE", maindir);
  1453.     if (exist(s)) {
  1454.       if (MOREINFO)
  1455.         output("PPP packet driver.");
  1456.       do_spawn(s);
  1457.     } else {
  1458.       log_it(1, "\n ■ %s\\PPP.EXE not found!", maindir);
  1459.       do_exit(EXIT_FAILURE);
  1460.     }
  1461.     while (kbhit())
  1462.       getch();
  1463.     sprintf(s, "%s\\PPPSTATE.EXE", maindir);
  1464.     if (exist(s)) {
  1465.       output("\n ■ Dialing %s... timeout %d seconds... ", DOMAIN, TIMEOUT);
  1466.       delay(2000);
  1467.       sprintf(s, "%s\\PPPSTATE.EXE WAIT=%d IP", maindir, TIMEOUT);
  1468.       i = do_spawn(s);
  1469.     } else {
  1470.       log_it(1, "\n ■ %s\\PPPSTATE.EXE not found!", maindir);
  1471.       do_exit(EXIT_FAILURE);
  1472.     }
  1473.   }
  1474.   switch (i) {
  1475.     case 0:
  1476.       if (!pppd)
  1477.         output(" connected!");
  1478.       break;
  1479.     case 1:
  1480.       log_it(1, "\n ■ Unable to establish connection... aborting");
  1481.       sprintf(s, "%s\\PPP U", maindir);
  1482.       do_spawn(s);
  1483.       if (!lsl_loaded) {
  1484.         sprintf(s, "%s\\LSL U", maindir);
  1485.         do_spawn(s);
  1486.       }
  1487.       return (0);
  1488.     case 2:
  1489.       output("\n ■ Unable to find PPP layer... aborting");
  1490.       if (!lsl_loaded) {
  1491.         sprintf(s, "%s\\LSL U", maindir);
  1492.         do_spawn(s);
  1493.       }
  1494.       do_exit(EXIT_FAILURE);
  1495.     default:
  1496.       if (pppd)
  1497.         log_it(1, "no connection.");
  1498.       else {
  1499.         log_it(1, "\n ■ %s PPPState #%d... aborting", strings[2], i);
  1500.         sprintf(s, "%s\\PPP U", maindir);
  1501.         do_spawn(s);
  1502.         if (!lsl_loaded) {
  1503.           sprintf(s, "%s\\LSL U", maindir);
  1504.           do_spawn(s);
  1505.         }
  1506.       }
  1507.       return (0);
  1508.   }
  1509.   if (!pppd) {
  1510.     delay(2000);
  1511.     sprintf(s, "%s\\PPPWAT.EXE", maindir);
  1512.     if (exist(s)) {
  1513.       do_spawn(s);
  1514.     } else {
  1515.       log_it(1, "\n ! %s\\PPPWAT.EXE not found!", maindir);
  1516.       do_exit(EXIT_FAILURE);
  1517.     }
  1518.     sprintf(s, "%s\\IPSTUB.EXE", maindir);
  1519.     if (exist(s)) {
  1520.       do_spawn(s);
  1521.     } else {
  1522.       log_it(1, "\n ■ %s\\IPSTUB.EXE not found!", maindir);
  1523.       do_exit(EXIT_FAILURE);
  1524.     }
  1525.   }
  1526.   return (1);
  1527. }
  1528.  
  1529. #endif
  1530.  
  1531. int main(int argc, char *argv[])
  1532. {
  1533.   char *ss, s[201], s1[201], destaddr[101], temp[161], ttotal[21];
  1534.   int i, net_num_max, i1, f, ok, news, totf, send, f1, result;
  1535.   unsigned long sentbytes, recdbytes, rnewsbytes, snewsbytes;
  1536.   unsigned short sy;
  1537.   float dspace;
  1538.   FILE *fp;
  1539.   clock_t starttime, mailtime, newstime;
  1540.   struct tm *time_now;
  1541.   struct ffblk ff;
  1542.   struct diskfree_t df;
  1543.   time_t some;
  1544.  
  1545.   get_dir(maindir, 0);
  1546.  
  1547.   i = i1 = 0;
  1548.   while ((environ[i] != NULL) && (i < 20)) {
  1549.     xenviron[i1++] = environ[i];
  1550.     ++i;
  1551.   }
  1552.   xenviron[i1] = NULL;
  1553.  
  1554.   strcpy(s, "CONFIG.DAT");
  1555.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1556.   if (f < 0) {
  1557.     output("\n ! %s NOT FOUND.", s);
  1558.     return 1;
  1559.   }
  1560.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1561.   sh_close(f);
  1562.  
  1563.   detect_multitask();
  1564.   if ((strnicmp(t_os_name, "Windows 98", 10) != 0) && (strnicmp(t_os_name, "Windows 95", 10) != 0) &&
  1565.       (strnicmp(t_os_name, "OS/2 Warp", 9) != 0))
  1566.     sprintf(tasker, "%s v%d.%d", t_os_name, t_os_ver[t_os].maj, t_os_ver[t_os].min);
  1567.   else
  1568.     strcpy(tasker, t_os_name);
  1569.  
  1570.   ss = getenv("WWIV_INSTANCE");
  1571.   if (ss) {
  1572.     instance = atoi(ss);
  1573.     if ((instance <= 0) || (instance > 999)) {
  1574.       output("\n ! WWIV_INSTANCE must be 1..999!");
  1575.       instance = 1;
  1576.     }
  1577.   } else
  1578.     instance = 1;
  1579.   ss = NULL;
  1580.  
  1581.   strcpy(s, "CONFIG.OVR");
  1582.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1583.   if (f < 0) {
  1584.     output("\n ! %s NOT FOUND.", s);
  1585.     return 1;
  1586.   }
  1587.   sh_lseek(f, (instance - 1) * sizeof(configoverrec), SEEK_SET);
  1588.   sh_read(f, &syscfgovr, sizeof(configoverrec));
  1589.   sh_close(f);
  1590.  
  1591.   sprintf(s, "%sINSTANCE.DAT", syscfg.datadir);
  1592.   if (!exist(s)) {
  1593.     output("\n ! %s NOT FOUND.", s);
  1594.     return 1;
  1595.   }
  1596.   net_num_max = read_networks();
  1597.  
  1598.   news = 0;
  1599.   num_addr = 0;
  1600.   ss = argv[argc - 1];
  1601.   ok = 0;
  1602.   if (_fstrstr((char *) ss, ".") != NULL) {
  1603.     if (atoi(&ss[1]) < net_num_max) {
  1604.       netnum = atoi(&ss[1]);
  1605.       ok = 1;
  1606.     }
  1607.   } else {
  1608.     ss = (getenv("WWIV_NET"));
  1609.     netnum = atoi(ss);
  1610.     if (netnum < net_num_max)
  1611.       ok = 1;
  1612.   }
  1613.   if (!ok) {
  1614.     strcpy(s, "WWIV_NET.DAT");
  1615.     if ((fp = fsh_open(s, "rb")) != NULL) {
  1616.       fgets(s, 3, fp);
  1617.       netnum = atoi(s);
  1618.       if (netnum < net_num_max)
  1619.         ok = 1;
  1620.     }
  1621.     if (fp != NULL)
  1622.       fclose(fp);
  1623.   }
  1624.   ss = argv[1];
  1625.   if (strncmpi(ss, "/N", 2))
  1626.     ok = 0;
  1627.   set_net_num(netnum);
  1628.   sprintf(s, "%sADDRESS.NET", net_data);
  1629.   if (!exist(s)) {
  1630.     sprintf(s, "ADDRESS.1", net_data);
  1631.     if (!exist(s))
  1632.       ok = 0;
  1633.   }
  1634.   if (ok) {
  1635.     *SMTPHOST = *POPHOST = *NEWSHOST = *TIMEHOST = *POPNAME = *POPPASS = *PROXY = 0;
  1636.     *IPADDR = *NETMASK = *DNS = *SDNS = *DOMAIN = *GATEWAY = *FWDNAME = *FWDDOM = 0;
  1637.     PPPD = KEEPSENT = CLEANUP = MOREINFO = NOLISTNAMES = ONECALL = NOWATTCP = 0;
  1638.     BBSNODE = ALLMAIL = PURGE = RETRIES = 1;
  1639.     TIMEOUT = INACTIVE = 60;
  1640.     SOCK_DELAY = 30;
  1641.     if (parse_net_ini()) {
  1642.       set_net_num(netnum);
  1643.       if (ini_section & INI_NETWORK) {
  1644.         if (!(ini_section & INI_GENERAL)) {
  1645.           output("\n ! [GENERAL] tag missing from NET.INI!");
  1646.           ok = 0;
  1647.         }
  1648.       } else {
  1649.         ok = 0;
  1650.         output("\n ! [NETWORK] tag missing from NET.INI!");
  1651.       }
  1652.     } else {
  1653.       output("\n ! %s NET.INI!", strings[1]);
  1654.       ok = 0;
  1655.     }
  1656.   }
  1657.   if (ok) {
  1658.     if (create_contact_ppp())
  1659.       ok = 0;
  1660.   }
  1661.   if (ok) {
  1662.     log_it(1, "\n\n%s", version);
  1663.     output("\n%s\n", author);
  1664.     time(&some);
  1665.     time_now = localtime(&some);
  1666.     sprintf(s1, "\n ■ Running under %s on instance %d ", tasker, instance);
  1667.     strftime(s, 80, "at %I:%M%p, %d %b %y", time_now);
  1668.     strcat(s1, s);
  1669.     log_it(1, s1);
  1670.     log_it(1, "\n ■ Available memory : %ld bytes/", coreleft());
  1671.     if (net_data[1] == ':')
  1672.       i = net_data[0];
  1673.     else
  1674.       i = maindir[0];
  1675.     i = toupper(i) - 'A' + 1;
  1676.     _dos_getdiskfree(i, &df);
  1677.     dspace = ((float) df.avail_clusters * (float) df.bytes_per_sector *
  1678.               (float) df.sectors_per_cluster);
  1679.     if (dspace < 1024000.00) {
  1680.       log_it(1, "\n ■ Only %.1fK available on drive %c:... aborting!",
  1681.              dspace, i + '@');
  1682.       do_exit(EXIT_FAILURE);
  1683.     } else
  1684.       log_it(1, "Disk space : %c:%.1fM", i + '@', (dspace / 1024000L));
  1685.  
  1686.     set_net_num(netnum);
  1687.     ss = argv[1];
  1688.     sy = atoi(&ss[2]);
  1689.     destaddr[0] = 0;
  1690.     if (sy != 32767)
  1691.       good_addr(destaddr, sy);
  1692.  
  1693.     if ((destaddr[0] == 0) && (sy != 32767)) {
  1694.       output("\n ■ Using direct dial for @%hd.%s\n\n", sy, net_name);
  1695.       ok = 0;
  1696.     } else {
  1697.       ok = 1;
  1698.       if (sy == 32767) {
  1699.         if (ini_section & INI_NEWS)
  1700.           output("\n ■ Initiating newsgroup session...");
  1701.         else {
  1702.           output("\n ■ [NEWS] missing from NET.INI!");
  1703.           do_exit(EXIT_FAILURE);
  1704.         }
  1705.       }
  1706.     }
  1707.   }
  1708.   if (ok) {
  1709.     if (!MOREINFO)
  1710.       freopen(NULL, "w", stdout);
  1711.     if (CLEANUP)
  1712.       process_mail();
  1713.     set_net_num(netnum);
  1714.     sprintf(s, "%sSPOOL", net_data);
  1715.     if ((make_path(s)) < 0) {
  1716.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1717.       do_exit(EXIT_FAILURE);
  1718.     }
  1719.     sprintf(s, "%sMQUEUE", net_data);
  1720.     if ((make_path(s)) < 0) {
  1721.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1722.       do_exit(EXIT_FAILURE);
  1723.     }
  1724.     sprintf(s, "%sMQUEUE\\FAILED", net_data);
  1725.     if ((make_path(s)) < 0) {
  1726.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1727.       do_exit(EXIT_FAILURE);
  1728.     }
  1729.     sprintf(s, "%sMQUEUE\\DIGEST", net_data);
  1730.     if ((make_path(s)) < 0) {
  1731.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1732.       do_exit(EXIT_FAILURE);
  1733.     }
  1734.     sprintf(s, "%sOUTBOUND", net_data);
  1735.     if ((make_path(s)) < 0) {
  1736.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1737.       do_exit(EXIT_FAILURE);
  1738.     }
  1739.     sprintf(s, "%sINBOUND", net_data);
  1740.     if ((make_path(s)) < 0) {
  1741.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1742.       do_exit(EXIT_FAILURE);
  1743.     }
  1744.     sprintf(s, "%sSENT", net_data);
  1745.     if ((make_path(s)) < 0) {
  1746.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1747.       do_exit(EXIT_FAILURE);
  1748.     }
  1749.     if (PURGE) {
  1750.       if ((KEEPSENT) && (sy != 32767)) {
  1751.         log_it(1, "\n ■ Purging sent packets older than %d day%s...", KEEPSENT,
  1752.                KEEPSENT == 1 ? "" : "s");
  1753.         sprintf(s, "%s\\PPPUTIL PURGE %s %d", maindir, net_data, KEEPSENT);
  1754.         do_spawn(s);
  1755.       }
  1756.     }
  1757.     sprintf(s, "%sCHECKNET", net_data);
  1758.     if ((make_path(s)) < 0) {
  1759.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1760.       do_exit(EXIT_FAILURE);
  1761.     }
  1762.     send = 1;
  1763.  
  1764.     check_exp();
  1765.  
  1766.     cd_to(maindir);
  1767.     if ((sy != 32767) || (ONECALL)) {
  1768.       output("\n ■ Preparing outbound packets...");
  1769.       if (!uu_packets()) {
  1770.         sprintf(s, "%sMQUEUE\\*.*", net_data);
  1771.         if (findfirst(s, &ff, 0) == 0) {
  1772.           output(" already in MQUEUE to be sent.");
  1773.         } else {
  1774.           output(" no mail or packets to send.");
  1775.           send = 0;
  1776.         }
  1777.       } else {
  1778.         backline();
  1779.         output(" ■ All packets prepared for transfer.");
  1780.       }
  1781.     }
  1782.     starttime = clock();
  1783.     sentbytes = recdbytes = snewsbytes = rnewsbytes = 0L;
  1784.     cd_to(maindir);
  1785.  
  1786.  
  1787. #ifndef PACKET
  1788.     log_it(0, "\n ■ Memory available : %ld bytes -", coreleft());
  1789.     sprintf(s, "%s%s%d.CFG", net_data, PPPD ? "PPPDRC" : "NET", instance);
  1790.     if (exist(s)) {
  1791.       sprintf(s1, "%s\\%s.CFG", maindir, PPPD ? "PPPDRC" : "NET");
  1792.       unlink(s1);
  1793.       if (!copyfile(s, s1))
  1794.         log_it(1, "\n ■ %s %s from %s.", strings[0], s1, s);
  1795.     }
  1796.     if (!NOWATTCP) {
  1797.       if (create_wattcp_cfg(PPPD))
  1798.         do_exit(EXIT_FAILURE);
  1799.     }
  1800.     ok = 0;
  1801.     for (i = 0; (i < RETRIES) && (!ok); i++) {
  1802.       if (RETRIES > 1)
  1803.         output("\n ■ Dialing Attempt Number %d of %d", i + 1, RETRIES);
  1804.       ok = klos_ppp(PPPD);
  1805.     }
  1806.     if ((RETRIES > 1) && (!ok))
  1807.       do_exit(EXIT_FAILURE);
  1808.     log_it(0, "\n ■ Memory available : %ld bytes -", coreleft());
  1809. #endif
  1810.  
  1811.     sprintf(temp_dir, "%sINBOUND\\", net_data);
  1812.  
  1813.     ok = 0;
  1814.     time(&some);
  1815.     time_now = localtime(&some);
  1816.     strftime(s, 80, "\n - SMTP/POP on %A, %B %d, %Y at %H:%M %p",
  1817.              time_now);
  1818.     log_it(0, s);
  1819.     sentbytes = recdbytes = 0L;
  1820.     if ((send) && ((sy != 32767) || (ONECALL))) {
  1821.       totf = 0;
  1822.       sprintf(temp, "%sMQUEUE\\*.*", net_data);
  1823.       f1 = findfirst(temp, &ff, FA_ARCH);
  1824.       while (f1 == 0) {
  1825.         ok = 1;
  1826.         ++totf;
  1827.         sentbytes += (long) ff.ff_fsize;
  1828.         f1 = findnext(&ff);
  1829.       }
  1830.       sprintf(s1, "%sMQUEUE\\", net_data);
  1831.       sprintf(s, "%s\\POP.EXE -send %s %s %s %d %d", maindir, SMTPHOST, DOMAIN,
  1832.               s1, MOREINFO, NOLISTNAMES);
  1833.       do_spawn(s);
  1834.       f1 = findfirst(temp, &ff, FA_ARCH);
  1835.       while (f1 == 0) {
  1836.         --totf;
  1837.         sentbytes -= (long) ff.ff_fsize;
  1838.         f1 = findnext(&ff);
  1839.       }
  1840.       cd_to(maindir);
  1841.       if (ok) {
  1842.         output(" ");
  1843.         backline();
  1844.         log_it(0, "\n");
  1845.         log_it(1, " ■ Outbound mail transfer completed : %d message%s (%ldK).",
  1846.                totf, totf == 1 ? "" : "s", ((sentbytes + 1023) / 1024));
  1847.       }
  1848.     }
  1849.     if ((sy != 32767) || (ONECALL)) {
  1850.       if ((*PRIMENET) && (strnicmp(net_name, PRIMENET, strlen(net_name) != 0))) {
  1851.         if (MOREINFO)
  1852.           output("\n ! Comparing %s (PRIMENET) to %s.", PRIMENET, net_name);
  1853.         output("\n ■ No packet receipt for %s.", net_name);
  1854.       } else {
  1855.         sprintf(s, "%s\\POP -r %s %d %d n%hd",
  1856.                 maindir, temp_dir, ALLMAIL, MOREINFO, net_sysnum);
  1857.         result = do_spawn(s);
  1858.         sprintf(s1, "%s*.*", temp_dir);
  1859.         if ((result == EXIT_SUCCESS) || (exist(s1))) {
  1860.           sprintf(temp, "%s*.*", temp_dir);
  1861.           f1 = findfirst(temp, &ff, FA_ARCH);
  1862.           i = 0;
  1863.           while (f1 == 0) {
  1864.             if ((strncmp(ff.ff_name, "BAD", 3) != 0) && (strncmp(ff.ff_name, "SPM", 3) != 0) &&
  1865.                 (strncmp(ff.ff_name, "SUB", 3) != 0) && (strncmp(ff.ff_name, "DUP", 3) != 0) &&
  1866.                 (strncmp(ff.ff_name, "FIW", 3) != 0) && (ff.ff_fsize)) {
  1867.               recdbytes += (long) ff.ff_fsize;
  1868.               sprintf(s1, "%s%s", temp_dir, ff.ff_name);
  1869.               cd_to(maindir);
  1870.               sprintf(temp, "%s\\UU.EXE -decode %s %s %s", maindir, ff.ff_name,
  1871.                       temp_dir, net_data);
  1872.               if (!do_spawn(temp))
  1873.                 unlink(s1);
  1874.             }
  1875.             f1 = findnext(&ff);
  1876.           }
  1877.         } else
  1878.           output("\n ■ No network packets to process");
  1879.       }
  1880.     }
  1881.     check_exp();
  1882.  
  1883.     mailtime = clock() - starttime;
  1884.     if ((sy == 32767) || (ONECALL)) {
  1885.       time(&some);
  1886.       time_now = localtime(&some);
  1887.       strftime(s, 80, "\n - NEWS session beginning on %A, %B %d, %Y at %H:%M %p",
  1888.                time_now);
  1889.       log_it(0, s);
  1890.       news = 1;
  1891.       starttime = clock();
  1892.       set_net_num(netnum);
  1893.       sprintf(temp, "%sOUTBOUND\\*.*", net_data);
  1894.       f1 = findfirst(temp, &ff, FA_ARCH);
  1895.       while (f1 == 0) {
  1896.         snewsbytes += (long) ff.ff_fsize;
  1897.         f1 = findnext(&ff);
  1898.       }
  1899.       cd_to(maindir);
  1900.       strcpy(s1, net_data);
  1901.       if (LAST(s1) == '\\')
  1902.         LAST(s1) = 0;
  1903.       sprintf(s, "%s\\NEWS.EXE %s %s %hu", maindir, s1, NEWSHOST, net_sysnum);
  1904.       ok = 1;
  1905.       do_spawn(s);
  1906.       set_net_num(netnum);
  1907.       sprintf(temp, "%sP0*.*", net_data);
  1908.       f1 = findfirst(temp, &ff, 0);
  1909.       while (f1 == 0) {
  1910.         rnewsbytes += (long) ff.ff_fsize;
  1911.         f1 = findnext(&ff);
  1912.       }
  1913.     }
  1914.   } else {
  1915.     output("\n");
  1916.     set_net_num(netnum);
  1917.     strcpy(s, "NETWORK0.EXE");
  1918.     for (i = 1; i < argc; i++) {
  1919.       strcat(s, " ");
  1920.       strcat(s, argv[i]);
  1921.     }
  1922.     s[strlen(s) + 1] = '\0';
  1923.     do_it(s);
  1924.     exit(EXIT_SUCCESS);
  1925.   }
  1926.  
  1927.   sprintf(s1, "%s\\NTIME.EXE", maindir);
  1928.   if ((exist(s1)) && (*TIMEHOST)) {
  1929.     output("\n ■ Polling %s...  ", TIMEHOST);
  1930.     sprintf(s, "%s %s", s1, TIMEHOST);
  1931.     do_spawn(s);
  1932.   }
  1933. #ifndef PACKET
  1934.   unload_klos(PPPD);
  1935. #endif
  1936.  
  1937.   output("\n ■ Updating network connection records...");
  1938.  
  1939.   if ((sy != 32767) || ((sy == 32767) && (ONECALL))) {
  1940.     if (update_contacts(sy, sentbytes, recdbytes))
  1941.       log_it(1, "\n ■ %s", strings[3]);
  1942.     recdbytes = ((recdbytes + 1023) / 1024);
  1943.     sentbytes = ((sentbytes + 1023) / 1024);
  1944.     if (mailtime)
  1945.       sprintf(ttotal, "%3.1f", (mailtime / CLK_TCK / 60));
  1946.     else
  1947.       strcpy(ttotal, "0.1");
  1948.     sprintf(s, "%s\\PPPUTIL.EXE NETLOG %hd %lu %lu %s %s",
  1949.             maindir, sy, sentbytes, recdbytes, ttotal, net_name);
  1950.     if (do_spawn(s))
  1951.       log_it(1, "\n ! %s", strings[4]);
  1952.   }
  1953.   if (news) {
  1954.     if ((newstime = clock()) == (clock_t) - 1)
  1955.       log_it(1, "\n ■ NEWS time invalid.");
  1956.     else {
  1957.       if (update_contact(32767, snewsbytes, rnewsbytes, 1))
  1958.         log_it(1, "\n ■ %s", strings[3]);
  1959.       newstime -= starttime;
  1960.       if (newstime)
  1961.         sprintf(ttotal, "%3.1f", (newstime / CLK_TCK / 60));
  1962.       else
  1963.         strcpy(ttotal, "0.1");
  1964.       rnewsbytes = ((rnewsbytes + 1023) / 1024);
  1965.       if (rnewsbytes > 9999L)
  1966.         rnewsbytes = 9999L;
  1967.       snewsbytes = ((snewsbytes + 1023) / 1024);
  1968.       sprintf(s, "%s\\PPPUTIL.EXE NETLOG 32767 %lu %lu %s %s", maindir, snewsbytes, rnewsbytes, ttotal, net_name);
  1969.       if (do_spawn(s))
  1970.         log_it(1, "\n ! %s", strings[4]);
  1971.     }
  1972.   }
  1973.   if (CLEANUP) {
  1974.     process_mail();
  1975.     set_net_num(netnum);
  1976.   }
  1977.   sprintf(s, "%s\\PPPUTIL.EXE TRIM %s NEWS.LOG", maindir, net_data);
  1978.   do_spawn(s);
  1979.   cd_to(maindir);
  1980.   set_net_num(netnum);
  1981.   log_it(1, "\n ■ %s completed!\n\n", version);
  1982.   return 0;
  1983. }
  1984.