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