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