home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B97.ZIP / NETWORK.CPP < prev    next >
Text File  |  1998-11-13  |  49KB  |  1,938 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. char *stristr(char *string, char *pattern)
  1225. {
  1226.   char *pptr, *sptr, *start;
  1227.   unsigned int slen, plen;
  1228.  
  1229.   for (start = string, pptr = pattern, slen = strlen(string),
  1230.        plen = strlen(pattern); slen >= plen; start++, slen--) {
  1231.     while (toupper(*start) != toupper(*pattern)) {
  1232.       start++;
  1233.       slen--;
  1234.       if (slen < plen)
  1235.         return (NULL);
  1236.     }
  1237.     sptr = start;
  1238.     pptr = pattern;
  1239.     while (toupper(*sptr) == toupper(*pptr)) {
  1240.       sptr++;
  1241.       pptr++;
  1242.       if ('\0' == *pptr)
  1243.         return (start);
  1244.     }
  1245.   }
  1246.   return (NULL);
  1247. }
  1248.  
  1249. int check_encode(char *fn)
  1250. {
  1251.   char s[121], s1[121];
  1252.   int lines, encoded;
  1253.   FILE *fp;
  1254.  
  1255.   if ((fp = fsh_open(fn, "r")) == NULL)
  1256.     return 0;
  1257.  
  1258.   lines = encoded = 0;
  1259.  
  1260.   while ((fgets(s, 120, fp)) && (++lines < 200)) {
  1261.     if (*s == '')
  1262.       strcpy(s1, &s[3]);
  1263.     else
  1264.       strcpy(s1, s);
  1265.     if (strnicmp(s1, "begin 6", 7) == 0) {
  1266.       encoded = 1;
  1267.       break;
  1268.     }
  1269.     if (strnicmp(s1, "Content-Type", 12) == 0) {
  1270.       if (stristr(s1, "text/plain") == 0)
  1271.         encoded = 1;
  1272.     }
  1273.     if (strnicmp(s1, "Content-Transfer-Encoding", 25) == 0) {
  1274.       if (stristr(s1, "8bit")) {
  1275.         encoded = 1;
  1276.         break;
  1277.       }
  1278.     }
  1279.     if (stristr(s1, "This is a multi-part message in MIME format.")) {
  1280.       encoded = 1;
  1281.       break;
  1282.     }
  1283.   }
  1284.  
  1285.   if (fp != NULL)
  1286.     fclose(fp);
  1287.  
  1288.   if (encoded)
  1289.     log_it(MOREINFO, "\n ■ %s appears to contain encoded data.", fn);
  1290.  
  1291.   return encoded;
  1292. }
  1293.  
  1294. void check_unk(void)
  1295. {
  1296.   char s[101], fn[MAXPATH], newfn[MAXPATH];
  1297.   int i, f, f1;
  1298.   long l;
  1299.   struct ffblk ff;
  1300.  
  1301.   sprintf(fn, "%sINBOUND\\UNK-0*.*", net_data);
  1302.   f1 = findfirst(fn, &ff, 0);
  1303.   while (f1 == 0) {
  1304.     sprintf(fn, "%sINBOUND\\%s", net_data, ff.ff_name);
  1305.     f = sh_open1(fn, O_RDONLY | O_BINARY);
  1306.     l = filelength(f);
  1307.     f = sh_close(f);
  1308.     if (l > 32767L) {
  1309.       if (!check_encode(fn)) {
  1310.         sprintf(s, "%s\\PPPUTIL.EXE CHUNK %s %s", maindir, net_data, ff.ff_name);
  1311.         do_spawn(s);
  1312.       } else
  1313.         log_it(MOREINFO, "\n ! %s contains encoded data.", ff.ff_name);
  1314.     } else {
  1315.       i = 0;
  1316.       fnsplit(fn, NULL, NULL, s, NULL);
  1317.       sprintf(newfn, "%sSPOOL\\%s.%03d", net_data, s, ++i);
  1318.       while (exist(newfn))
  1319.         sprintf(newfn, "%sSPOOL\\%s.%03d", net_data, s, ++i);
  1320.       if (copyfile(fn, newfn))
  1321.         unlink(fn);
  1322.     }
  1323.     f1 = findnext(&ff);
  1324.   }
  1325. }
  1326.  
  1327. void check_exp(void)
  1328. {
  1329.   char s[MAXPATH], cmd[201];
  1330.   int ok;
  1331.  
  1332.   cd_to(maindir);
  1333.   sprintf(s, "%s\\EXP.EXE", maindir);
  1334.   if (!exist(s)) {
  1335.     log_it(1, "\n ! EXPort/Import module not found!");
  1336.     return;
  1337.   }
  1338.   ok = 0;
  1339.   sprintf(s, "%sS32767.NET", net_data);
  1340.   if (exist(s))
  1341.     ok = 1;
  1342.   sprintf(s, "%sINBOUND\\SUB*.*", net_data);
  1343.   if (exist(s))
  1344.     ok = 1;
  1345.   sprintf(s, "%sINBOUND\\UNK*.*", net_data);
  1346.   if (exist(s)) {
  1347.     ok = 1;
  1348.     sprintf(s, "%sINBOUND\\UNK-0*.*", net_data);
  1349.     if (exist(s))
  1350.       check_unk();
  1351.   }
  1352.   sprintf(s, "%sSPOOL\\UNK*.*", net_data);
  1353.   if (exist(s))
  1354.     ok = 1;
  1355.  
  1356.   if (ok) {
  1357.     sprintf(cmd, "%s\\EXP.EXE S32767.NET %s %hu %s %s %s", maindir, net_data,
  1358.             net_sysnum, FWDNAME, FWDDOM, net_name);
  1359.     if (do_spawn(cmd)) {
  1360.       log_it(1, "\n ! %s during export!", strings[2]);
  1361.       return;
  1362.     }
  1363.   } else
  1364.     log_it(MOREINFO, "\n ■ No Internet mail or newsgroup posts to process.");
  1365. }
  1366.  
  1367. int check_for_lsl(void)
  1368. {
  1369.   union REGS r;
  1370.   struct SREGS s;
  1371.   char *intstr;
  1372.  
  1373.   for (r.h.ah = 0xc0; r.h.ah != 0; r.h.ah++) {
  1374.     r.h.al = 0;
  1375.     int86x(0x2f, &r, &r, &s);
  1376.     if (r.h.al == 0xff) {
  1377.       intstr = (char *) MK_FP(s.es, r.x.si);
  1378.       if (strncmp(intstr, "LINKSUP$", 8) == 0)
  1379.         return 1;
  1380.     }
  1381.   }
  1382.   return 0;
  1383. }
  1384.  
  1385. #ifndef PACKET
  1386. void klos_ppp(int pppd)
  1387. {
  1388.   char s[160];
  1389.   int i;
  1390.  
  1391.   if (pppd) {
  1392.     cd_to(maindir);
  1393.     if (MOREINFO)
  1394.       sprintf(s, "%s\\EPPPDD.EXE", maindir);
  1395.     else
  1396.       sprintf(s, "%s\\EPPPD.EXE", maindir);
  1397.     if (exist(s)) {
  1398.       output("\n ■ Dialing %s using %s - [Ctrl-C] aborts...\n", DOMAIN, s);
  1399.       i = do_spawn(s);
  1400.     } else
  1401.       log_it(1, "\n ■ %s not in BBS directory!", s);
  1402.   } else {
  1403.     lsl_loaded = check_for_lsl();
  1404.     if (!lsl_loaded) {
  1405.       sprintf(s, "%s\\LSL.COM", maindir);
  1406.       if (exist(s)) {
  1407.         if (MOREINFO)
  1408.           output("\n ■ Loading Link Support Layer and ");
  1409.         do_spawn(s);
  1410.       } else {
  1411.         log_it(1, "\n ■ LSL.COM not in BBS main directory!");
  1412.         do_exit(EXIT_FAILURE);
  1413.       }
  1414.     } else {
  1415.       if (MOREINFO)
  1416.         output("\n ■ LSL already in memory - loading ");
  1417.     }
  1418.     sprintf(s, "%s\\PPP.EXE", maindir);
  1419.     if (exist(s)) {
  1420.       if (MOREINFO)
  1421.         output("PPP packet driver.");
  1422.       do_spawn(s);
  1423.     } else {
  1424.       log_it(1, "\n ■ %s\\PPP.EXE not found!", maindir);
  1425.       do_exit(EXIT_FAILURE);
  1426.     }
  1427.     while (kbhit())
  1428.       getch();
  1429.     sprintf(s, "%s\\PPPSTATE.EXE", maindir);
  1430.     if (exist(s)) {
  1431.       output("\n ■ Dialing %s... timeout %d seconds... ", DOMAIN, TIMEOUT);
  1432.       delay(2000);
  1433.       sprintf(s, "%s\\PPPSTATE.EXE WAIT=%d IP", maindir, TIMEOUT);
  1434.       i = do_spawn(s);
  1435.     } else {
  1436.       log_it(1, "\n ■ %s\\PPPSTATE.EXE not found!", maindir);
  1437.       do_exit(EXIT_FAILURE);
  1438.     }
  1439.   }
  1440.   switch (i) {
  1441.     case 0:
  1442.       if (!pppd)
  1443.         output(" connected!");
  1444.       break;
  1445.     case 1:
  1446.       log_it(1, "\n ■ Unable to establish connection... aborting");
  1447.       sprintf(s, "%s\\PPP U", maindir);
  1448.       do_spawn(s);
  1449.       if (!lsl_loaded) {
  1450.         sprintf(s, "%s\\LSL U", maindir);
  1451.         do_spawn(s);
  1452.       }
  1453.       do_exit(EXIT_FAILURE);
  1454.     case 2:
  1455.       output("\n ■ Unable to find PPP layer... aborting");
  1456.       if (!lsl_loaded) {
  1457.         sprintf(s, "%s\\LSL U", maindir);
  1458.         do_spawn(s);
  1459.       }
  1460.       do_exit(EXIT_FAILURE);
  1461.     default:
  1462.       if (pppd)
  1463.         log_it(1, "no connection.");
  1464.       else {
  1465.         log_it(1, "\n ■ %s PPPState #%d... aborting", strings[2], i);
  1466.         sprintf(s, "%s\\PPP U", maindir);
  1467.         do_spawn(s);
  1468.         if (!lsl_loaded) {
  1469.           sprintf(s, "%s\\LSL U", maindir);
  1470.           do_spawn(s);
  1471.         }
  1472.       }
  1473.       do_exit(EXIT_FAILURE);
  1474.   }
  1475.   if (!pppd) {
  1476.     delay(2000);
  1477.     sprintf(s, "%s\\PPPWAT.EXE", maindir);
  1478.     if (exist(s)) {
  1479.       do_spawn(s);
  1480.     } else {
  1481.       log_it(1, "\n ! %s\\PPPWAT.EXE not found!", maindir);
  1482.       do_exit(EXIT_FAILURE);
  1483.     }
  1484.     sprintf(s, "%s\\IPSTUB.EXE", maindir);
  1485.     if (exist(s)) {
  1486.       do_spawn(s);
  1487.     } else {
  1488.       log_it(1, "\n ■ %s\\IPSTUB.EXE not found!", maindir);
  1489.       do_exit(EXIT_FAILURE);
  1490.     }
  1491.   }
  1492. }
  1493.  
  1494. #endif
  1495.  
  1496. int main(int argc, char *argv[])
  1497. {
  1498.   char *ss, s[201], s1[201], destaddr[101], temp[161], ttotal[21];
  1499.   int i, net_num_max, i1, f, ok, news, totf, send, f1, result;
  1500.   unsigned long sentbytes, recdbytes, rnewsbytes, snewsbytes;
  1501.   unsigned short sy;
  1502.   float dspace;
  1503.   FILE *fp;
  1504.   clock_t starttime, mailtime, newstime;
  1505.   struct tm *time_now;
  1506.   struct ffblk ff;
  1507.   struct diskfree_t df;
  1508.   time_t some;
  1509.  
  1510.   get_dir(maindir, 0);
  1511.  
  1512.   i = i1 = 0;
  1513.   while ((environ[i] != NULL) && (i < 20)) {
  1514.     xenviron[i1++] = environ[i];
  1515.     ++i;
  1516.   }
  1517.   xenviron[i1] = NULL;
  1518.  
  1519.   strcpy(s, "CONFIG.DAT");
  1520.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1521.   if (f < 0) {
  1522.     output("\n ! %s NOT FOUND.", s);
  1523.     return 1;
  1524.   }
  1525.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1526.   sh_close(f);
  1527.  
  1528.   detect_multitask();
  1529.   sprintf(tasker, "%s v%d.%d", t_os_name, t_os_ver[t_os].maj, t_os_ver[t_os].min);
  1530.  
  1531.   ss = getenv("WWIV_INSTANCE");
  1532.   if (ss) {
  1533.     instance = atoi(ss);
  1534.     if ((instance <= 0) || (instance > 999)) {
  1535.       output("\n ! WWIV_INSTANCE must be 1..999!");
  1536.       instance = 1;
  1537.     }
  1538.   } else
  1539.     instance = 1;
  1540.   ss = NULL;
  1541.  
  1542.   strcpy(s, "CONFIG.OVR");
  1543.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1544.   if (f < 0) {
  1545.     output("\n ! %s NOT FOUND.", s);
  1546.     return 1;
  1547.   }
  1548.   sh_lseek(f, (instance - 1) * sizeof(configoverrec), SEEK_SET);
  1549.   sh_read(f, &syscfgovr, sizeof(configoverrec));
  1550.   sh_close(f);
  1551.  
  1552.   sprintf(s, "%sINSTANCE.DAT", syscfg.datadir);
  1553.   if (!exist(s)) {
  1554.     output("\n ! %s NOT FOUND.", s);
  1555.     return 1;
  1556.   }
  1557.   net_num_max = read_networks();
  1558.  
  1559.   news = 0;
  1560.   num_addr = 0;
  1561.   ss = argv[argc - 1];
  1562.   ok = 0;
  1563.   if (_fstrstr((char *) ss, ".") != NULL) {
  1564.     if (atoi(&ss[1]) < net_num_max) {
  1565.       netnum = atoi(&ss[1]);
  1566.       ok = 1;
  1567.     }
  1568.   } else {
  1569.     ss = (getenv("WWIV_NET"));
  1570.     netnum = atoi(ss);
  1571.     if (netnum < net_num_max)
  1572.       ok = 1;
  1573.   }
  1574.   if (!ok) {
  1575.     strcpy(s, "WWIV_NET.DAT");
  1576.     if ((fp = fsh_open(s, "rb")) != NULL) {
  1577.       fgets(s, 3, fp);
  1578.       netnum = atoi(s);
  1579.       if (netnum < net_num_max)
  1580.         ok = 1;
  1581.     }
  1582.     if (fp != NULL)
  1583.       fclose(fp);
  1584.   }
  1585.   ss = argv[1];
  1586.   if (strncmpi(ss, "/N", 2))
  1587.     ok = 0;
  1588.   set_net_num(netnum);
  1589.   sprintf(s, "%sADDRESS.NET", net_data);
  1590.   if (!exist(s)) {
  1591.     sprintf(s, "ADDRESS.1", net_data);
  1592.     if (!exist(s))
  1593.       ok = 0;
  1594.   }
  1595.   if (ok) {
  1596.     *SMTPHOST = *POPHOST = *NEWSHOST = *TIMEHOST = *POPNAME = *POPPASS = *PROXY = 0;
  1597.     *IPADDR = *NETMASK = *DNS = *SDNS = *DOMAIN = *GATEWAY = *FWDNAME = *FWDDOM = 0;
  1598.     PPPD = KEEPSENT = CLEANUP = MOREINFO = NOLISTNAMES = ONECALL = 0;
  1599.     BBSNODE = ALLMAIL = PURGE = 1;
  1600.     TIMEOUT = INACTIVE = 60;
  1601.     SOCK_DELAY = 30;
  1602.     if (parse_net_ini()) {
  1603.       set_net_num(netnum);
  1604.       if (ini_section & INI_NETWORK) {
  1605.         if (!(ini_section & INI_GENERAL)) {
  1606.           output("\n ! [GENERAL] tag missing from NET.INI!");
  1607.           ok = 0;
  1608.         }
  1609.       } else {
  1610.         ok = 0;
  1611.         output("\n ! [NETWORK] tag missing from NET.INI!");
  1612.       }
  1613.     } else {
  1614.       output("\n ! %s NET.INI!", strings[1]);
  1615.       ok = 0;
  1616.     }
  1617.   }
  1618.   if (ok) {
  1619.     if (create_contact_ppp())
  1620.       ok = 0;
  1621.   }
  1622.   if (ok) {
  1623.     log_it(1, "\n\n%s", version);
  1624.     output("\n%s\n", author);
  1625.     time(&some);
  1626.     time_now = localtime(&some);
  1627.     sprintf(s1, "\n ■ Running under %s on instance %d ", tasker, instance);
  1628.     strftime(s, 80, "at %I:%M%p, %d %b %y", time_now);
  1629.     strcat(s1, s);
  1630.     log_it(1, s1);
  1631.     log_it(1, "\n ■ Available memory : %ld bytes/", coreleft());
  1632.     if (net_data[1] == ':')
  1633.       i = net_data[0];
  1634.     else
  1635.       i = maindir[0];
  1636.     i = toupper(i) - 'A' + 1;
  1637.     _dos_getdiskfree(i, &df);
  1638.     dspace = ((float) df.avail_clusters * (float) df.bytes_per_sector *
  1639.               (float) df.sectors_per_cluster);
  1640.     if (dspace < 1024000.00) {
  1641.       log_it(1, "\n ■ Only %.1fK available on drive %c:... aborting!",
  1642.              dspace, i + '@');
  1643.       do_exit(EXIT_FAILURE);
  1644.     } else
  1645.       log_it(1, "Disk space : %c:%.1fM", i + '@', (dspace / 1024000L));
  1646.  
  1647.     set_net_num(netnum);
  1648.     ss = argv[1];
  1649.     sy = atoi(&ss[2]);
  1650.     destaddr[0] = 0;
  1651.     if (sy != 32767)
  1652.       good_addr(destaddr, sy);
  1653.  
  1654.     if ((destaddr[0] == 0) && (sy != 32767)) {
  1655.       output("\n ■ Using direct dial for @%hd.%s\n\n", sy, net_name);
  1656.       ok = 0;
  1657.     } else {
  1658.       ok = 1;
  1659.       if (sy == 32767) {
  1660.         if (ini_section & INI_NEWS)
  1661.           output("\n ■ Initiating newsgroup session...");
  1662.         else {
  1663.           output("\n ■ [NEWS] missing from NET.INI!");
  1664.           do_exit(EXIT_FAILURE);
  1665.         }
  1666.       }
  1667.     }
  1668.   }
  1669.   if (ok) {
  1670.     if (!MOREINFO)
  1671.       freopen(NULL, "w", stdout);
  1672.     if (CLEANUP)
  1673.       process_mail();
  1674.     set_net_num(netnum);
  1675.     sprintf(s, "%sSPOOL", net_data);
  1676.     if ((make_path(s)) < 0) {
  1677.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1678.       do_exit(EXIT_FAILURE);
  1679.     }
  1680.     sprintf(s, "%sMQUEUE", net_data);
  1681.     if ((make_path(s)) < 0) {
  1682.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1683.       do_exit(EXIT_FAILURE);
  1684.     }
  1685.     sprintf(s, "%sMQUEUE\\FAILED", net_data);
  1686.     if ((make_path(s)) < 0) {
  1687.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1688.       do_exit(EXIT_FAILURE);
  1689.     }
  1690.     sprintf(s, "%sMQUEUE\\DIGEST", net_data);
  1691.     if ((make_path(s)) < 0) {
  1692.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1693.       do_exit(EXIT_FAILURE);
  1694.     }
  1695.     sprintf(s, "%sOUTBOUND", net_data);
  1696.     if ((make_path(s)) < 0) {
  1697.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1698.       do_exit(EXIT_FAILURE);
  1699.     }
  1700.     sprintf(s, "%sINBOUND", net_data);
  1701.     if ((make_path(s)) < 0) {
  1702.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1703.       do_exit(EXIT_FAILURE);
  1704.     }
  1705.     sprintf(s, "%sSENT", net_data);
  1706.     if ((make_path(s)) < 0) {
  1707.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1708.       do_exit(EXIT_FAILURE);
  1709.     }
  1710.     if (PURGE) {
  1711.       if ((KEEPSENT) && (sy != 32767)) {
  1712.         log_it(1, "\n ■ Purging sent packets older than %d day%s...", KEEPSENT,
  1713.                KEEPSENT == 1 ? "" : "s");
  1714.         sprintf(s, "%s\\PPPUTIL PURGE %s %d", maindir, net_data, KEEPSENT);
  1715.         do_spawn(s);
  1716.       }
  1717.     }
  1718.     sprintf(s, "%sCHECKNET", net_data);
  1719.     if ((make_path(s)) < 0) {
  1720.       log_it(1, "\n ■ %s \"%s\"", strings[0], s);
  1721.       do_exit(EXIT_FAILURE);
  1722.     }
  1723.     send = 1;
  1724.  
  1725.     check_exp();
  1726.  
  1727.     cd_to(maindir);
  1728.     if ((sy != 32767) || (ONECALL)) {
  1729.       output("\n ■ Preparing outbound packets...");
  1730.       if (!uu_packets()) {
  1731.         sprintf(s, "%sMQUEUE\\*.*", net_data);
  1732.         if (findfirst(s, &ff, 0) == 0) {
  1733.           output(" already in MQUEUE to be sent.");
  1734.         } else {
  1735.           output(" no mail or packets to send.");
  1736.           send = 0;
  1737.         }
  1738.       } else {
  1739.         backline();
  1740.         output(" ■ All packets prepared for transfer.");
  1741.       }
  1742.     }
  1743.     starttime = clock();
  1744.     sentbytes = recdbytes = snewsbytes = rnewsbytes = 0L;
  1745.     cd_to(maindir);
  1746.  
  1747.  
  1748. #ifndef PACKET
  1749.     log_it(0, "\n ■ Memory available : %ld bytes -", coreleft());
  1750.     sprintf(s, "%s%s%d.CFG", net_data, PPPD ? "PPPDRC" : "NET", instance);
  1751.     if (exist(s)) {
  1752.       sprintf(s1, "%s\\%s.CFG", maindir, PPPD ? "PPPDRC" : "NET");
  1753.       unlink(s1);
  1754.       if (!copyfile(s, s1))
  1755.         log_it(1, "\n ■ %s %s from %s.", strings[0], s1, s);
  1756.     }
  1757.     if (!NOWATTCP) {
  1758.       if (create_wattcp_cfg(PPPD))
  1759.         do_exit(EXIT_FAILURE);
  1760.     }
  1761.     klos_ppp(PPPD);
  1762.     log_it(0, "\n ■ Memory available : %ld bytes -", coreleft());
  1763. #endif
  1764.  
  1765.     sprintf(temp_dir, "%sINBOUND\\", net_data);
  1766.  
  1767.     ok = 0;
  1768.     time(&some);
  1769.     time_now = localtime(&some);
  1770.     strftime(s, 80, "\n - SMTP/POP on %A, %B %d, %Y at %H:%M %p",
  1771.              time_now);
  1772.     log_it(0, s);
  1773.     sentbytes = recdbytes = 0L;
  1774.     if ((send) && ((sy != 32767) || (ONECALL))) {
  1775.       totf = 0;
  1776.       sprintf(temp, "%sMQUEUE\\*.*", net_data);
  1777.       f1 = findfirst(temp, &ff, FA_ARCH);
  1778.       while (f1 == 0) {
  1779.         ok = 1;
  1780.         ++totf;
  1781.         sentbytes += ff.ff_fsize;
  1782.         f1 = findnext(&ff);
  1783.       }
  1784.       sprintf(s1, "%sMQUEUE\\", net_data);
  1785.       sprintf(s, "%s\\POP.EXE -send %s %s %s %d %d", maindir, SMTPHOST, DOMAIN,
  1786.               s1, MOREINFO, NOLISTNAMES);
  1787.       do_spawn(s);
  1788.       f1 = findfirst(temp, &ff, FA_ARCH);
  1789.       while (f1 == 0) {
  1790.         --totf;
  1791.         sentbytes -= ff.ff_fsize;
  1792.         f1 = findnext(&ff);
  1793.       }
  1794.       cd_to(maindir);
  1795.       if (ok) {
  1796.         output(" ");
  1797.         backline();
  1798.         log_it(0, "\n");
  1799.         log_it(1, " ■ Outbound mail transfer completed : %d message%s (%ldK).",
  1800.                totf, totf == 1 ? "" : "s", ((sentbytes + 1023) / 1024));
  1801.       }
  1802.     }
  1803.     if ((sy != 32767) || (ONECALL)) {
  1804.       if ((*PRIMENET) && (strnicmp(net_name, PRIMENET, strlen(net_name) != 0))) {
  1805.         if (MOREINFO)
  1806.           output("\n ! Comparing %s (PRIMENET) to %s.", PRIMENET, net_name);
  1807.         output("\n ■ No packet receipt for %s.", net_name);
  1808.       } else {
  1809.         sprintf(s, "%s\\POP -r %s %d %d n%hd",
  1810.                 maindir, temp_dir, ALLMAIL, MOREINFO, net_sysnum);
  1811.         result = do_spawn(s);
  1812.         sprintf(s1, "%s*.*", temp_dir);
  1813.         if ((result == EXIT_SUCCESS) || (exist(s1))) {
  1814.           sprintf(temp, "%s*.*", temp_dir);
  1815.           f1 = findfirst(temp, &ff, FA_ARCH);
  1816.           i = 0;
  1817.           while (f1 == 0) {
  1818.             if ((strncmp(ff.ff_name, "BAD", 3) != 0) && (strncmp(ff.ff_name, "SPM", 3) != 0) &&
  1819.                 (strncmp(ff.ff_name, "SUB", 3) != 0) && (strncmp(ff.ff_name, "DUP", 3) != 0) &&
  1820.                 (strncmp(ff.ff_name, "FIW", 3) != 0) && (ff.ff_fsize)) {
  1821.               recdbytes += ff.ff_fsize;
  1822.               sprintf(s1, "%s%s", temp_dir, ff.ff_name);
  1823.               cd_to(maindir);
  1824.               sprintf(temp, "%s\\UU.EXE -decode %s %s %s", maindir, ff.ff_name,
  1825.                       temp_dir, net_data);
  1826.               if (!do_spawn(temp))
  1827.                 unlink(s1);
  1828.             }
  1829.             f1 = findnext(&ff);
  1830.           }
  1831.         } else
  1832.           output("\n ■ No network packets to process");
  1833.       }
  1834.     }
  1835.     check_exp();
  1836.  
  1837.     mailtime = clock() - starttime;
  1838.     if ((sy == 32767) || (ONECALL)) {
  1839.       time(&some);
  1840.       time_now = localtime(&some);
  1841.       strftime(s, 80, "\n - NEWS session beginning on %A, %B %d, %Y at %H:%M %p",
  1842.                time_now);
  1843.       log_it(0, s);
  1844.       news = 1;
  1845.       starttime = clock();
  1846.       set_net_num(netnum);
  1847.       sprintf(temp, "%sOUTBOUND\\*.*", net_data);
  1848.       f1 = findfirst(temp, &ff, FA_ARCH);
  1849.       while (f1 == 0) {
  1850.         snewsbytes += ff.ff_fsize;
  1851.         f1 = findnext(&ff);
  1852.       }
  1853.       cd_to(maindir);
  1854.       strcpy(s1, net_data);
  1855.       if (LAST(s1) == '\\')
  1856.         LAST(s1) = 0;
  1857.       sprintf(s, "%s\\NEWS.EXE %s %s %hu", maindir, s1, NEWSHOST, net_sysnum);
  1858.       ok = 1;
  1859.       do_spawn(s);
  1860.       set_net_num(netnum);
  1861.       sprintf(temp, "%sP0*.*", net_data);
  1862.       f1 = findfirst(temp, &ff, 0);
  1863.       while (f1 == 0) {
  1864.         rnewsbytes += ff.ff_fsize;
  1865.         f1 = findnext(&ff);
  1866.       }
  1867.     }
  1868.   } else {
  1869.     output("\n");
  1870.     set_net_num(netnum);
  1871.     strcpy(s, "NETWORK0.EXE");
  1872.     for (i = 1; i < argc; i++) {
  1873.       strcat(s, " ");
  1874.       strcat(s, argv[i]);
  1875.     }
  1876.     s[strlen(s) + 1] = '\0';
  1877.     do_it(s);
  1878.     exit(EXIT_SUCCESS);
  1879.   }
  1880.  
  1881.   sprintf(s1, "%s\\NTIME.EXE", maindir);
  1882.   if ((exist(s1)) && (*TIMEHOST)) {
  1883.     output("\n ■ Polling %s...  ", TIMEHOST);
  1884.     sprintf(s, "%s %s", s1, TIMEHOST);
  1885.     do_spawn(s);
  1886.   }
  1887. #ifndef PACKET
  1888.   unload_klos(PPPD);
  1889. #endif
  1890.  
  1891.   output("\n ■ Updating network connection records...");
  1892.  
  1893.   if ((sy != 32767) || ((sy == 32767) && (ONECALL))) {
  1894.     recdbytes = ((recdbytes + 1023) / 1024);
  1895.     sentbytes = ((sentbytes + 1023) / 1024);
  1896.     if (mailtime)
  1897.       sprintf(ttotal, "%3.1f", (mailtime / CLK_TCK / 60));
  1898.     else
  1899.       strcpy(ttotal, "0.1");
  1900.     sprintf(s, "%s\\PPPUTIL.EXE NETLOG %hd %lu %lu %s %s",
  1901.             maindir, sy, sentbytes, recdbytes, ttotal, net_name);
  1902.     if (do_spawn(s))
  1903.       log_it(1, "\n ! %s", strings[4]);
  1904.     if (update_contacts(sy, sentbytes, recdbytes))
  1905.       log_it(1, "\n ■ %s", strings[3]);
  1906.   }
  1907.   if (news) {
  1908.     if ((newstime = clock()) == (clock_t) - 1)
  1909.       log_it(1, "\n ■ NEWS time invalid.");
  1910.     else {
  1911.       newstime -= starttime;
  1912.       if (newstime)
  1913.         sprintf(ttotal, "%3.1f", (newstime / CLK_TCK / 60));
  1914.       else
  1915.         strcpy(ttotal, "0.1");
  1916.       rnewsbytes = ((rnewsbytes + 1023) / 1024);
  1917.       if (rnewsbytes > 9999L)
  1918.         rnewsbytes = 9999L;
  1919.       snewsbytes = ((snewsbytes + 1023) / 1024);
  1920.       if (update_contact(32767, snewsbytes, rnewsbytes, 1))
  1921.         log_it(1, "\n ■ %s", strings[3]);
  1922.       sprintf(s, "%s\\PPPUTIL.EXE NETLOG 32767 %lu %lu %s %s", maindir, snewsbytes, rnewsbytes, ttotal, net_name);
  1923.       if (do_spawn(s))
  1924.         log_it(1, "\n ! %s", strings[4]);
  1925.     }
  1926.   }
  1927.   if (CLEANUP) {
  1928.     process_mail();
  1929.     set_net_num(netnum);
  1930.   }
  1931.   sprintf(s, "%s\\PPPUTIL.EXE TRIM %s NEWS.LOG", maindir, net_data);
  1932.   do_spawn(s);
  1933.   cd_to(maindir);
  1934.   set_net_num(netnum);
  1935.   log_it(1, "\n ■ %s completed!\n\n", version);
  1936.   return 0;
  1937. }
  1938.