home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
PPPBCKP
/
SRC
/
SRC15B83.ZIP
/
NETWORK.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1998-01-03
|
45KB
|
1,815 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <dos.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <ctype.h>
#include <io.h>
#include <conio.h>
#include <share.h>
#include <errno.h>
#include <malloc.h>
#include <dir.h>
#include <time.h>
#include <process.h>
#include <direct.h>
#include "vardec.h"
#include "net.h"
#include "version.h"
#include "retcode.h"
extern unsigned _stklen = (8 * 1024);
#define NUL '\0'
#define LAST(s) s[strlen(s)-1]
#define SHARE_LEVEL 10
#define WAIT_TIME 10
#define TRIES 100
#define MT_DESQVIEW 0x01
#define MT_WINDOWS 0x02
#define MT_OS2 0x04
#define MT_NB 0x40
#define INI_NETWORK 0x01
#define INI_GENERAL 0x02
#define INI_NEWS 0x04
typedef struct {
unsigned short sysnum;
char address[60];
} net_address_rec;
char *version = "Freeware PPP Project Net Packet Engine " VERSION " (" __DATE__ ")";
char *author = "Contact Frank Reid at edare@ix.netcom.com or 1@8213.WWIVnet for support";
char *strings[] = {
"Unable to create",
"Unable to read",
"Unknown error",
"Unable to write CONTACT.NET!",
"Unable to write NET.LOG!",
0L,
};
configrec syscfg;
configoverrec syscfgovr;
net_networks_rec netcfg;
net_system_list_rec *netsys;
int multitasker = 0, ini_section = 0, num_addr;
char wwiv_net_no[20], tasker[40], maindir[MAXPATH];
char net_name[16], net_data[MAXPATH];
unsigned short net_sysnum;
int num_sys_list, net_num, net_num_max, netnum;
int instance, lsl_loaded;
char SMTPHOST[40], POPHOST[40], NEWSHOST[40], POPNAME[20], POPPASS[20];
char IPADDR[18], NETMASK[18], FWDNAME[20], FWDDOM[40], TIMEHOST[40], DNS[16];
char NODEPASS[20], SDNS[16], DOMAIN[40], GATEWAY[16], temp_dir[MAXPATH];
unsigned int KEEPSENT = 0, ALLMAIL = 1, CLEANUP = 0, MOREINFO = 0;
unsigned int TIMEOUT = 60, SOCK_DELAY = 30, INACTIVE = 60;
unsigned int ONECALL = 0, PURGE = 1, BBSNODE = 1;
char *xenviron[20];
void dv_pause(void)
{
__emit__(0xb8, 0x1a, 0x10, 0xcd, 0x15);
__emit__(0xb8, 0x00, 0x10, 0xcd, 0x15);
__emit__(0xb8, 0x25, 0x10, 0xcd, 0x15);
}
void win_pause(void)
{
__emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
}
int get_dos_version(void)
{
_AX = 0x3000;
geninterrupt(0x21);
if (_AX % 256 >= 10) {
multitasker |= MT_OS2;
}
return (_AX);
}
int get_dv_version(void)
{
int v;
if (multitasker & MT_OS2)
return 0;
_AX = 0x2b01;
_CX = 0x4445;
_DX = 0x5351;
geninterrupt(0x21);
if (_AL == 0xff) {
return 0;
} else {
v = _BX;
multitasker |= MT_DESQVIEW;
return v;
}
}
int get_win_version(void)
{
int v = 0;
__emit__(0x55, 0x06, 0x53);
_AX = 0x352f;
geninterrupt(0x21);
_AX = _ES;
if (_AX | _BX) {
_AX = 0x1600;
geninterrupt(0x2f);
v = _AX;
if (v % 256 <= 1)
v = 0;
}
__emit__(0x5b, 0x07, 0x5d);
if (v != 0)
multitasker |= MT_WINDOWS;
return (v);
}
int get_nb_version(void)
{
_AX = 0;
geninterrupt(0x2A);
return (_AH);
}
void detect_multitask(void)
{
get_dos_version();
get_win_version();
get_dv_version();
if (multitasker < 2)
if (get_nb_version())
multitasker = MT_NB;
}
void giveup_timeslice(void)
{
if (multitasker) {
switch (multitasker) {
case 1:
case 3:
dv_pause();
break;
case 2:
case 4:
case 5:
case 6:
case 7:
win_pause();
break;
default:
break;
}
}
}
char *stripspace(char *str)
{
char *obuf, *nbuf;
if (str) {
for (obuf = str, nbuf = str; *obuf; ++obuf) {
if (!isspace(*obuf))
*nbuf++ = *obuf;
}
*nbuf = NULL;
}
return (str);
}
int sh_write(int handle, void *buffer, unsigned long len)
{
if (handle == -1) {
return (-1);
}
return (write(handle, buffer, (unsigned) len));
}
int sh_open(char *path, int file_access, unsigned fmode)
{
int handle, count, share;
char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
share = SH_DENYRW;
} else {
share = SH_DENYWR;
}
handle = open(path, file_access | share, fmode);
if (handle < 0) {
count = 1;
fnsplit(path, drive, dir, file, ext);
if (access(path, 0) != -1) {
delay(WAIT_TIME);
handle = open(path, file_access | share, fmode);
while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
if (count % 2)
delay(WAIT_TIME);
else
giveup_timeslice();
count++;
handle = open(path, file_access | share, fmode);
}
}
}
return (handle);
}
int sh_open1(char *path, int access)
{
unsigned fmode;
fmode = 0;
if ((access & O_RDWR) || (access & O_WRONLY))
fmode |= S_IWRITE;
if ((access & O_RDWR) || (access & O_RDONLY))
fmode |= S_IREAD;
return (sh_open(path, access, fmode));
}
int sh_close(int f)
{
if (f != -1)
close(f);
return (-1);
}
int sh_read(int handle, void *buf, unsigned len)
{
if (handle == -1) {
return (-1);
}
return (read(handle, buf, len));
}
long sh_lseek(int handle, long offset, int fromwhere)
{
if (handle == -1) {
return (-1L);
}
return (lseek(handle, offset, fromwhere));
}
FILE *fsh_open(char *path, char *fmode)
{
FILE *f;
int count, share, md, fd;
char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
share = SH_DENYWR;
md = 0;
if (((char *) _fstrchr(fmode, 'w')) != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT | O_TRUNC;
} else
if (((char *) _fstrchr(fmode, 'a')) != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT;
} else {
md = O_RDONLY;
}
if (((char *) _fstrchr(fmode, 'b')) != NULL) {
md |= O_BINARY;
}
if (((char *) _fstrchr(fmode, '+')) != NULL) {
md &= ~O_RDONLY;
md |= O_RDWR;
share = SH_DENYRD;
}
fd = open(path, md | share, S_IREAD | S_IWRITE);
if (fd < 0) {
count = 1;
fnsplit(path, drive, dir, file, ext);
if ((access(path, 0)) != -1) {
delay(WAIT_TIME);
fd = open(path, md | share, S_IREAD | S_IWRITE);
while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
delay(WAIT_TIME);
count++;
fd = open(path, md | share, S_IREAD | S_IWRITE);
}
}
}
if (fd > 0) {
if (((char *) _fstrchr(fmode, 'a')) != NULL)
sh_lseek(fd, 0L, SEEK_END);
f = fdopen(fd, fmode);
if (!f) {
close(fd);
}
} else
f = NULL;
return (f);
}
void output(char *fmt,...)
{
va_list v;
char s[255];
va_start(v, fmt);
vsprintf(s, fmt, v);
va_end(v);
fputs(s, stderr);
}
int log_it(int display, char *fmt,...)
{
va_list v;
char s[255], fn[MAXPATH];
FILE *fp;
va_start(v, fmt);
vsprintf(s, fmt, v);
va_end(v);
sprintf(fn, "%sNEWS.LOG", net_data);
if ((fp = fsh_open(fn, "at")) == NULL) {
output("\n ! Error accessing %s.", fn);
output("\n ! String = \"%s\".", s);
return 1;
}
fputs(s, fp);
if (fp != NULL)
fclose(fp);
if (display)
fputs(s, stderr);
return 0;
}
void backline(void)
{
int i;
output(" ");
for (i = wherex(); i > 0; i--)
output("\b \b");
}
int do_spawn(char *cl)
{
int i, i1, l;
char *ss1, *ss[10];
ss1 = _fstrdup(cl);
ss[0] = ss1;
i = 1;
l = strlen(ss1);
for (i1 = 1; i1 < l; i1++)
if (ss1[i1] == 32) {
ss1[i1] = 0;
ss[i++] = &(ss1[i1 + 1]);
}
ss[i] = NULL;
i = (spawnvpe(P_WAIT, ss[0], ss, xenviron) & 0x00ff);
if (ss1 != NULL)
farfree(ss1);
return i;
}
#ifndef PACKET
void unload_klos(void)
{
char s[160];
sprintf(s, "%s\\IPSTUB U", maindir);
do_spawn(s);
sprintf(s, "%s\\PPP U", maindir);
do_spawn(s);
if (!lsl_loaded) {
sprintf(s, "%s\\LSL U", maindir);
do_spawn(s);
}
}
#endif
void cd_to(char *s)
{
char *s1;
int i, db;
s1 = s;
i = strlen(s1) - 1;
db = (s1[i] == '\\');
if (i == 0)
db = 0;
if ((i == 2) && (s1[1] == ':'))
db = 0;
if (db)
s1[i] = 0;
chdir(s1);
if (s[1] == ':')
setdisk(s[0] - 'A');
}
void get_dir(char *s, int be)
{
strcpy(s, "X:\\");
s[0] = 'A' + getdisk();
getcurdir(0, s + 3);
if (be) {
if (s[strlen(s) - 1] != '\\')
strcat(s, "\\");
}
}
char *trimstr1(char *s)
{
int i;
static char *whitespace = " \r\n\t";
i = strlen(s);
if (i) {
while ((i > 0) && (_fstrchr(whitespace, s[i - 1])))
--i;
while ((i > 0) && (_fstrchr(whitespace, *s))) {
memmove(s, s + 1, --i);
}
s[i] = NUL;
}
return (s);
}
char *make_abs_path(char *checkdir)
{
char newdir[121];
if ((strlen(checkdir) < 3) || (checkdir[1] != ':') || (checkdir[2] != '\\')) {
cd_to(maindir);
cd_to(checkdir);
if (LAST(checkdir) == '\\')
get_dir(newdir, 1);
else
get_dir(newdir, 0);
cd_to(maindir);
strcpy(checkdir, newdir);
}
return checkdir;
}
int exist(char *s)
{
int i;
struct ffblk ff;
i = findfirst(s, &ff, FA_HIDDEN);
if (i)
return 0;
else
return 1;
}
void set_net_num(int n)
{
char s[121];
int f;
sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f < 0)
return;
lseek(f, ((long) (n)) * sizeof(net_networks_rec), SEEK_SET);
sh_read(f, &netcfg, sizeof(net_networks_rec));
close(f);
net_num = n;
net_sysnum = netcfg.sysnum;
strcpy(net_name, netcfg.name);
strcpy(net_data, make_abs_path(netcfg.dir));
if (LAST(net_data) != '\\')
strcat(net_data, "\\");
sprintf(wwiv_net_no, "WWIV_NET=%d", net_num);
}
int make_path(char *s)
{
unsigned int i;
char drive, current_path[MAXPATH], current_drive, *p, *flp;
union REGS r;
p = flp = strdup(s);
_getdcwd(0, current_path, MAXPATH);
current_drive = *current_path - '@';
if (LAST(s) == '\\')
LAST(s) = 0;
if (p[1] == ':') {
drive = toupper(p[0]) - 'A' + 1;
if ((_osmajor == 3 && _osminor >= 1) || (_osmajor > 3)) {
r.x.ax = 0x4409;
r.h.bl = drive;
int86(0x21, &r, &r);
if (r.x.cflag)
return -3;
}
if (_chdrive(drive)) {
chdir(current_path);
_dos_setdrive(current_drive, &i);
return -2;
}
p += 2;
}
if (*p == '\\') {
chdir("\\");
p++;
}
for (; (p = strtok(p, "\\")) != 0; p = 0) {
if (chdir(p)) {
if (mkdir(p)) {
chdir(current_path);
_dos_setdrive(current_drive, &i);
return -1;
}
chdir(p);
}
}
chdir(current_path);
if (flp)
free(flp);
return 0;
}
void process_mail(void)
{
char s[201];
output("\n ■ Network clean-up... please wait... ");
sprintf(s, "%s\\FLINK.EXE", maindir);
if (exist(s))
do_spawn(s);
sprintf(s, "%s\\LINKER.EXE", maindir);
if (exist(s))
do_spawn(s);
output("done.");
}
int valid_system(unsigned int ts)
{
int i;
for (i = 0; i < num_sys_list; i++) {
if (netsys[i].sysnum == ts) {
if (netsys[i].numhops == 1)
return (1);
else
return (0);
}
}
return (0);
}
int create_contact_ppp(void)
{
char *ss, fn[101], s[81];
unsigned short node;
int curfile, i;
net_address_rec curaddr;
FILE *fp, *fc;
sprintf(fn, "%sCONTACT.PPP", net_data);
if ((fc = fsh_open(fn, "wb+")) == NULL) {
output("\n ! %s %s!\n", strings[0], fn);
return 1;
}
curfile = 1;
num_addr = 0;
do {
sprintf(fn, "%sADDRESS.%d", net_data, curfile);
if ((fp = fsh_open(fn, "rt")) == NULL)
curfile = -1;
while ((curfile > 0) && (fgets(s, 80, fp) != NULL)) {
if (s[0] != '@')
continue;
ss = strtok(s, " \t\r");
node = atoi(&ss[1]);
if (node) {
ss = strtok(NULL, " \t\r");
trimstr1(ss);
curaddr.sysnum = node;
strcpy(curaddr.address, ss);
if (ss[0]) {
fwrite(&curaddr, sizeof(net_address_rec), 1, fc);
++num_addr;
}
}
}
if (fp != NULL)
fclose(fp);
++curfile;
} while (curfile > 0);
fseek(fc, 0L, SEEK_SET);
sprintf(fn, "%sADDRESS.0", net_data);
if ((fp = fsh_open(fn, "rt")) == NULL) {
if (fc != NULL)
fclose(fc);
return (0);
}
while (fgets(s, 80, fp) != NULL) {
if (s[0] != '@')
continue;
ss = strtok(s, " \t\r");
node = atoi(&ss[1]);
do {
ss = strtok(NULL, " \t\r");
switch (ss[0]) {
case '-':
for (i = 0; i < num_addr; i++) {
fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
fread(&curaddr, sizeof(net_address_rec), 1, fc);
if (node == curaddr.sysnum) {
curaddr.sysnum = 0;
fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
fwrite(&curaddr, sizeof(net_address_rec), 1, fc);
}
}
break;
}
} while (ss);
}
if (fp != NULL)
fclose(fp);
if (fc != NULL)
fclose(fc);
return (0);
}
void good_addr(char *address, unsigned short sn)
{
char fn[101];
int i;
net_address_rec curaddr;
FILE *fc;
address[0] = 0;
sprintf(fn, "%sCONTACT.PPP", net_data);
if ((fc = fsh_open(fn, "rb+")) == NULL) {
log_it(1, "\n ■ %s %s!\n", strings[1], fn);
return;
}
for (i = 0; ((i < num_addr) && (!address[0])); i++) {
fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
fread(&curaddr, sizeof(net_address_rec), 1, fc);
if (sn == curaddr.sysnum)
strcpy(address, curaddr.address);
}
if (fc != NULL)
fclose(fc);
}
int copyfile(char *infn, char *outfn)
{
int f1, f2, i;
char *b;
struct ftime ft;
if ((strcmp(infn, outfn) != 0) && (exist(infn)) && (!exist(outfn))) {
if ((b = (char *) farmalloc(16400)) == NULL)
return 0;
f1 = sh_open1(infn, O_RDONLY | O_BINARY);
if (!f1) {
farfree(b);
b = NULL;
return 0;
}
getftime(f1, &ft);
f2 = sh_open(outfn, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
if (!f2) {
farfree(b);
b = NULL;
f1 = sh_close(f1);
return 0;
}
i = sh_read(f1, (char *) b, 16384);
while (i > 0) {
sh_write(f2, (char *) b, i);
i = sh_read(f1, (char *) b, 16384);
}
f1 = sh_close(f1);
setftime(f2, &ft);
f2 = sh_close(f2);
farfree(b);
b = NULL;
}
return 1;
}
void do_exit(int exitlevel)
{
delay(2000);
exit(2 - exitlevel);
}
int uu(char *fn, char *pktname, char *dest)
{
int ok;
char s[121], s1[201], s2[81];
FILE *fp;
sprintf(s, "%sMQUEUE\\%s.UUE", net_data, pktname);
if ((fp = fsh_open(s, "wt")) == NULL) {
log_it(1, "\n ■ %s %s!", strings[0], s);
do_exit(EXIT_FAILURE);
} else {
if (BBSNODE == 2)
sprintf(s2, "From: n%hd@filenet.ml.org\n", net_sysnum);
else
sprintf(s2, "From: %s@%s\n", POPNAME, DOMAIN);
fprintf(fp, s2);
sprintf(s2, "To: %s\n", dest);
fprintf(fp, s2);
sprintf(s2, "Message-ID: <%s-%s@%s>\n", pktname, POPNAME, DOMAIN);
fprintf(fp, s2);
sprintf(s2, "Subject: @%s NET PACKET : %s.UUE\n\n", net_name, pktname);
fprintf(fp, s2);
}
if (fp != NULL)
fclose(fp);
sprintf(s1, "%s\\UU.EXE -encode %s %s", maindir, fn, s);
ok = do_spawn(s1);
if (MOREINFO)
output("\n");
return ok;
}
int update_contact(unsigned short sy, unsigned long sb, unsigned long rb)
{
char s[101];
int i, i1, f;
long cur_time, l;
sprintf(s, "%sCONTACT.NET", net_data);
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f >= 0) {
l = filelength(f);
netcfg.num_ncn = (int) (l / sizeof(net_contact_rec));
if ((netcfg.ncn = (net_contact_rec *) farmalloc((netcfg.num_ncn + 2) *
sizeof(net_contact_rec))) == NULL) {
f = sh_close(f);
return 1;
}
sh_lseek(f, 0L, SEEK_SET);
sh_read(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
f = sh_close(f);
}
for (i = 0; i < netcfg.num_ncn; i++)
if (netcfg.ncn[i].systemnumber == sy)
i1 = i;
time(&cur_time);
netcfg.ncn[i1].lasttry = cur_time;
++netcfg.ncn[i1].numcontacts;
if (!netcfg.ncn[i1].firstcontact)
netcfg.ncn[i1].firstcontact = cur_time;
netcfg.ncn[i1].lastcontact = cur_time;
netcfg.ncn[i1].lastcontactsent = cur_time;
netcfg.ncn[i1].bytes_sent += sb;
if (rb)
netcfg.ncn[i1].bytes_received += rb;
netcfg.ncn[i1].bytes_waiting = 0L;
sprintf(s, "%sS%hd.net", net_data, sy);
if (!exist(s))
sprintf(s, "%sZ%hd.net", net_data, sy);
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f > 0) {
netcfg.ncn[i1].bytes_waiting += filelength(f);
close(f);
}
sprintf(s, "%sCONTACT.NET", net_data);
f = sh_open1(s, O_RDWR | O_CREAT | O_BINARY);
if (f > 0) {
sh_lseek(f, 0L, SEEK_SET);
sh_write(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
f = sh_close(f);
}
if (netcfg.ncn)
farfree(netcfg.ncn);
return 0;
}
int update_contacts(unsigned short sy, unsigned long sb, unsigned long rb)
{
int i, i1, rc;
char fn[101];
net_address_rec curaddr;
FILE *fc;
rc = 0;
sprintf(fn, "%sCONTACT.PPP", net_data);
if ((fc = fsh_open(fn, "rb+")) == NULL) {
log_it(1, "\n ■ %s %s!\n", strings[1], fn);
rc = 1;
return (rc);
}
for (i = 0; i < num_addr; i++) {
fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
fread(&curaddr, sizeof(net_address_rec), 1, fc);
if (curaddr.sysnum != 0) {
if (curaddr.sysnum == sy)
i1 = update_contact(curaddr.sysnum, sb, rb);
else
i1 = update_contact(curaddr.sysnum, 0, 0);
if (i1)
rc = 1;
}
}
if (fc != NULL)
fclose(fc);
return (rc);
}
int uu_packets(void)
{
char pktname[21], s[121], s1[121], s2[121], s3[121], temp[121];
int found, sz, f, f1, i;
unsigned long sbytes, basename;
net_address_rec curaddr;
FILE *fc;
num_sys_list = 0;
found = 0;
basename = time(NULL);
sprintf(s, "%sBBSDATA.NET", net_data);
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f > 0) {
num_sys_list = (int) (filelength(f) / sizeof(net_system_list_rec));
if ((netsys = (net_system_list_rec *) farmalloc((num_sys_list + 2) *
sizeof(net_system_list_rec))) == NULL) {
log_it(1, "\n ■ Unable to allocate %d bytes of memory for BBSDATA.NET",
(int) (num_sys_list + 2) * sizeof(net_system_list_rec));
f = sh_close(f);
return 0;
}
sh_lseek(f, 0L, SEEK_SET);
sh_read(f, (void *) netsys, num_sys_list * sizeof(net_system_list_rec));
f = sh_close(f);
} else
return 0;
sprintf(s1, "%sCONTACT.PPP", net_data);
if ((fc = fsh_open(s1, "rb+")) == NULL) {
log_it(1, "\n ■ %s %s!\n", strings[1], s1);
farfree(netsys);
return 0;
}
for (i = 0; i < num_addr; i++) {
fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
fread(&curaddr, sizeof(net_address_rec), 1, fc);
if ((valid_system(curaddr.sysnum)) && (curaddr.sysnum != 32767)) {
sprintf(s1, "%sS%hd.NET", net_data, curaddr.sysnum);
if (exist(s1)) {
sz = 0;
found = 1;
} else {
sprintf(s1, "%sZ%hd.NET", net_data, curaddr.sysnum);
if (exist(s1)) {
sz = 1;
found = 1;
} else
continue;
}
do {
sprintf(pktname, "%8.8lx", ++basename);
sprintf(temp, "%sMQUEUE\\%s.UUE", net_data, pktname);
} while (exist(temp));
backline();
output("\r ■ Encoding %s%hd.NET as %s.UUE -",
sz ? "Z" : "S", curaddr.sysnum, strupr(pktname));
if ((uu(s1, pktname, curaddr.address)) != EXIT_SUCCESS) {
output("\n ■ %s %sMQUEUE\\%s.UUE", strings[0], net_data, pktname);
if (fc != NULL)
fclose(fc);
farfree(netsys);
do_exit(EXIT_FAILURE);
} else {
if (KEEPSENT) {
sprintf(s3, "%sMQUEUE\\%s.UUE", net_data, pktname);
sprintf(s2, "%sSENT\\%s.SNT", net_data, pktname);
f1 = sh_open1(s3, O_RDONLY | O_BINARY);
if (f1 > 0) {
sbytes = filelength(f1);
f = sh_close(f1);
}
if (!copyfile(s3, s2))
output("\n ■ %s %s%hd.NET", strings[0], sz ? "Z" : "S", curaddr.sysnum);
}
unlink(s1);
update_contact(curaddr.sysnum, sbytes, 0);
}
}
}
if (fc != NULL)
fclose(fc);
farfree(netsys);
return found;
}
int parse_net_ini(void)
{
char cursect, line[121], vanline[121], *ss;
FILE *fp;
if ((fp = fsh_open("NET.INI", "rt")) == NULL)
return (0);
while (fgets(line, 80, fp)) {
strcpy(vanline, line);
stripspace(line);
ss = NULL;
ss = strtok(line, "=");
if (ss)
ss = strtok(NULL, "\n");
if ((line[0] == ';') || (line[0] == '\n') || (strlen(line) == 0))
continue;
if ((strnicmp(line, "[FILENET]", 9) == 0) ||
(strnicmp(line, "[PPPNET]", 8) == 0)) {
cursect = INI_NETWORK;
ini_section |= INI_NETWORK;
continue;
}
if (strnicmp(line, "[GENERAL]", 9) == 0) {
cursect = INI_GENERAL;
ini_section |= INI_GENERAL;
continue;
}
if (strnicmp(line, "[NEWS]", 6) == 0) {
cursect = INI_NEWS;
ini_section |= INI_NEWS;
continue;
}
if (cursect & INI_NETWORK) {
if (strnicmp(line, "TIMEHOST", 8) == 0) {
if (ss)
strcpy(TIMEHOST, ss);
continue;
}
if (strnicmp(line, "SMTPHOST", 8) == 0) {
if (ss)
strcpy(SMTPHOST, ss);
continue;
}
if (strnicmp(line, "POPHOST", 7) == 0) {
if (ss)
strcpy(POPHOST, ss);
continue;
}
if (strnicmp(line, "POPNAME", 7) == 0) {
if (ss)
strcpy(POPNAME, ss);
continue;
}
if (strnicmp(line, "POPPASS", 7) == 0) {
if (ss)
strcpy(POPPASS, ss);
continue;
}
}
if (strnicmp(line, "NODEPASS", 7) == 0) {
if (ss) {
strcpy(NODEPASS, ss);
BBSNODE = 2;
}
continue;
}
if (cursect & INI_GENERAL) {
if (strnicmp(line, "TIMEOUT", 7) == 0) {
if (atoi(ss))
TIMEOUT = atoi(ss);
continue;
}
if (strnicmp(line, "SOCK_DELAY", 10) == 0) {
if (atoi(ss))
SOCK_DELAY = atoi(ss);
continue;
}
if ((strnicmp(line, "INACTIVE", 8) == 0) || (strnicmp(line, "SOCK_INACTIVE", 13) == 0)) {
if (atoi(ss))
INACTIVE = atoi(ss);
continue;
}
if (strnicmp(line, "KEEPSENT", 8) == 0) {
if (atoi(ss))
KEEPSENT = atoi(ss);
continue;
}
if (strnicmp(line, "PURGE", 5) == 0) {
if (toupper(ss[0]) == 'N')
PURGE = 0;
continue;
}
if (strnicmp(line, "ALLMAIL", 7) == 0) {
if (toupper(ss[0]) == 'N')
ALLMAIL = 0;
continue;
}
if (strnicmp(line, "ONECALL", 7) == 0) {
if (toupper(ss[0]) == 'Y')
ONECALL = 1;
continue;
}
if (strnicmp(line, "MOREINFO", 8) == 0) {
if (toupper(ss[0]) == 'Y')
MOREINFO = 1;
continue;
}
if (strnicmp(line, "CLEANUP", 7) == 0) {
if (toupper(ss[0]) == 'Y')
CLEANUP = 1;
continue;
}
if (strnicmp(line, "IPADDR", 6) == 0) {
if ((ss) && (ss[0] != '0'))
strcpy(IPADDR, ss);
continue;
}
if (strnicmp(line, "NETMASK", 7) == 0) {
if (ss)
strcpy(NETMASK, ss);
continue;
}
if (strnicmp(line, "DNS", 3) == 0) {
if (ss)
strcpy(DNS, ss);
continue;
}
if (strnicmp(line, "SDNS", 3) == 0) {
if (ss)
strcpy(SDNS, ss);
continue;
}
if (strnicmp(line, "DOMAIN", 6) == 0) {
if (ss)
strcpy(DOMAIN, ss);
continue;
}
if (strnicmp(line, "FWDNAME", 7) == 0) {
if (ss)
strcpy(FWDNAME, ss);
continue;
}
if (strnicmp(line, "FWDDOM", 6) == 0) {
if (ss)
strcpy(FWDDOM, ss);
continue;
}
if (strnicmp(line, "GATEWAY", 7) == 0) {
if ((ss) && (ss[0] != '0'))
strcpy(GATEWAY, ss);
continue;
}
}
if (cursect & INI_NEWS) {
if (strnicmp(line, "NEWSHOST", 8) == 0) {
if (ss)
strcpy(NEWSHOST, ss);
continue;
}
}
}
if (!FWDNAME[0])
strcpy(FWDNAME, POPNAME);
if (!FWDDOM[0])
strcpy(FWDDOM, DOMAIN);
if (fp != NULL)
fclose(fp);
return (1);
}
void read_networks(void)
{
int f;
char s[121];
sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
f = sh_open1(s, O_RDONLY | O_BINARY);
net_num_max = 0;
if (f > 0) {
net_num_max = (int) (filelength(f) / sizeof(net_networks_rec));
f = sh_close(f);
}
}
void do_it(char *cl)
{
int i, i1, l;
char *s, *ss[30];
s = _fstrdup(cl);
ss[0] = s;
i = 1;
l = strlen(s);
for (i1 = 1; i1 < l; i1++)
if (s[i1] == 32) {
s[i1] = 0;
ss[i++] = &(s[i1 + 1]);
}
ss[i] = NULL;
execvpe(ss[0], ss, xenviron);
if (s != NULL)
farfree(s);
}
int create_wattcp_cfg(void)
{
char s1[101], fn[MAXPATH];
FILE *fp;
if (IPADDR[0] == 0)
strcpy(IPADDR, "0.0.0.0");
sprintf(fn, "%s\\WATTCP.CFG", maindir);
if ((fp = fsh_open(fn, "wt+")) == NULL) {
log_it(1, "\n ■ %s %s\\WATTCP.CFG... aborting!", strings[1], maindir);
return 1;
}
fprintf(fp, "my_ip=%s\n", IPADDR);
fprintf(fp, "netmask=%s\n", NETMASK);
fprintf(fp, "nameserver=%s\n", DNS);
if (SDNS[0] != 0)
fprintf(fp, "nameserver=%s\n", SDNS);
if (GATEWAY[0] == 0) {
strcpy(s1, IPADDR);
while (LAST(s1) != '.')
LAST(s1) = 0;
strcat(s1, "1");
strcpy(GATEWAY, s1);
}
fprintf(fp, "gateway=%s\n", GATEWAY);
fprintf(fp, "domains=\"%s\"\n", DOMAIN);
fprintf(fp, "hostname=\"%s\"\n", POPNAME);
fprintf(fp, "sockdelay=%d\n", SOCK_DELAY);
fprintf(fp, "inactive=%d\n", INACTIVE);
fclose(fp);
return 0;
}
int check_encode(char *fn)
{
char s[121];
int lines, encoded;
FILE *fp;
if ((fp = fsh_open(fn, "r")) == NULL)
return 0;
lines = encoded = 0;
while ((fgets(s, 120, fp)) && (++lines < 1000) && (!encoded)) {
if (strnicmp(s, "begin 6", 7) == 0) {
encoded = 1;
break;
}
if (strnicmp(s, "Content-Type:", 13) == 0) {
encoded = 1;
break;
}
}
if (fp != NULL)
fclose(fp);
if (encoded) {
log_it(MOREINFO, "\n ■ %s appears to contain encoded data.", fn);
return 1;
}
return 0;
}
void check_unk(void)
{
char s[101], fn[MAXPATH];
int f, f1;
long l;
struct ffblk ff;
sprintf(fn, "%sSPOOL\\UNK-0*.*", net_data);
f1 = findfirst(fn, &ff, 0);
while (f1 == 0) {
sprintf(fn, "%sINBOUND\\%s", net_data, ff.ff_name);
f = sh_open1(fn, O_RDONLY | O_BINARY);
l = filelength(f);
f = sh_close(f);
if (l > 32767L) {
if (!check_encode(fn)) {
sprintf(s, "%s\\PPPUTIL.EXE CHUNK %s %s", maindir, net_data, ff.ff_name);
do_spawn(s);
}
}
f1 = findnext(&ff);
}
}
void check_exp(void)
{
char s[MAXPATH], cmd[201];
int ok;
cd_to(maindir);
sprintf(s, "%s\\EXP.EXE", maindir);
if (!exist(s)) {
log_it(1, "\n ! EXPort/Import module not found!");
return;
}
ok = 0;
sprintf(s, "%sS32767.NET", net_data);
if (exist(s))
ok = 1;
sprintf(s, "%sINBOUND\\SUB*.*", net_data);
if (exist(s))
ok = 1;
sprintf(s, "%sSPOOL\\UNK*.*", net_data);
if (exist(s)) {
ok = 1;
sprintf(s, "%sSPOOL\\UNK-0*.*", net_data);
if (exist(s))
check_unk();
}
if (ok) {
sprintf(cmd, "%s\\EXP.EXE S32767.NET %s %hu %s %s %s", maindir, net_data,
net_sysnum, FWDNAME, FWDDOM, net_name);
if (do_spawn(cmd)) {
log_it(1, "\n ! %s during export!", strings[2]);
return;
}
} else
log_it(MOREINFO, "\n ■ No Internet mail or newsgroup posts to process.");
}
int check_for_lsl(void)
{
union REGS r;
struct SREGS s;
char *intstr;
for (r.h.ah = 0xc0; r.h.ah != 0; r.h.ah++) {
r.h.al = 0;
int86x(0x2f, &r, &r, &s);
if (r.h.al == 0xff) {
intstr = (char *) MK_FP(s.es, r.x.si);
if (strncmp(intstr, "LINKSUP$", 8) == 0)
return 1;
}
}
return 0;
}
#ifndef PACKET
void klos_ppp(void)
{
char s[160];
int i;
lsl_loaded = check_for_lsl();
if (!lsl_loaded) {
sprintf(s, "%s\\LSL.COM", maindir);
if (exist(s)) {
if (MOREINFO)
output("\n ■ Loading Link Support Layer and ");
do_spawn(s);
} else {
log_it(1, "\n ■ LSL.COM not in BBS main directory!");
do_exit(EXIT_FAILURE);
}
} else {
if (MOREINFO)
output("\n ■ LSL already in memory - loading ");
}
sprintf(s, "%s\\PPP.EXE", maindir);
if (exist(s)) {
if (MOREINFO)
output("PPP packet driver.");
do_spawn(s);
} else {
log_it(1, "\n ■ %s\\PPP.EXE not found!", maindir);
do_exit(EXIT_FAILURE);
}
while (kbhit())
getch();
sprintf(s, "%s\\PPPSTATE.EXE", maindir);
if (exist(s)) {
output("\n ■ Dialing %s... timeout %d seconds... ", DOMAIN, TIMEOUT);
delay(2000);
sprintf(s, "%s\\PPPSTATE.EXE WAIT=%d IP", maindir, TIMEOUT);
i = do_spawn(s);
switch (i) {
case 0:
output(" connected!");
break;
case 1:
log_it(1, "\n ■ Unable to establish connection... aborting");
sprintf(s, "%s\\PPP U", maindir);
do_spawn(s);
if (!lsl_loaded) {
sprintf(s, "%s\\LSL U", maindir);
do_spawn(s);
}
do_exit(EXIT_FAILURE);
case 2:
output("\n ■ Unable to find PPP layer... aborting");
if (!lsl_loaded) {
sprintf(s, "%s\\LSL U", maindir);
do_spawn(s);
}
do_exit(EXIT_FAILURE);
default:
log_it(1, "\n ■ %s PPPState #%d... aborting", strings[2], i);
sprintf(s, "%s\\PPP U", maindir);
do_spawn(s);
if (!lsl_loaded) {
sprintf(s, "%s\\LSL U", maindir);
do_spawn(s);
}
do_exit(EXIT_FAILURE);
}
} else {
log_it(1, "\n ■ %s\\PPPSTATE.EXE not found!", maindir);
do_exit(EXIT_FAILURE);
}
delay(2000);
sprintf(s, "%s\\PPPWAT.EXE", maindir);
if (exist(s)) {
do_spawn(s);
} else {
log_it(1, "\n ! %s\\PPPWAT.EXE not found!", maindir);
do_exit(EXIT_FAILURE);
}
sprintf(s, "%s\\IPSTUB.EXE", maindir);
if (exist(s)) {
do_spawn(s);
} else {
log_it(1, "\n ■ %s\\IPSTUB.EXE not found!", maindir);
do_exit(EXIT_FAILURE);
}
}
#endif
int main(int argc, char *argv[])
{
char *ss, s[160], s1[MAXPATH], destaddr[101], temp[160], ttotal[21];
int i, i1, dv, f, ok, news, totf, send, f1, result;
unsigned long sentbytes, recdbytes, rnewsbytes, snewsbytes;
unsigned short sy;
float dspace;
FILE *fp;
clock_t starttime, mailtime, newstime;
struct tm *time_now;
struct ffblk ff;
struct diskfree_t df;
time_t some;
get_dir(maindir, 0);
i = i1 = 0;
while ((environ[i] != NULL) && (i < 20)) {
xenviron[i1++] = environ[i];
++i;
}
xenviron[i1] = NULL;
ss = getenv("WWIV_INSTANCE");
if (ss) {
instance = atoi(ss);
if ((instance <= 0) || (instance > 999)) {
output("\n ! WWIV_INSTANCE can only be 1..999!");
instance = 1;
}
} else {
instance = 1;
}
ss = NULL;
strcpy(s, "CONFIG.DAT");
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f < 0) {
output("\n ! %s NOT FOUND.", s);
return 1;
}
sh_read(f, (void *) (&syscfg), sizeof(configrec));
f = sh_close(f);
detect_multitask();
switch (multitasker) {
case 1:
dv = get_dv_version();
sprintf(tasker, "DesqView %d.%02d", dv / 256, dv % 256);
break;
case 2:
dv = get_win_version();
if (dv >= 4)
strcpy(tasker, "Windows 95");
else
sprintf(tasker, "Windows %d.%02d", dv % 256, dv / 256);
break;
case 3:
dv = get_dv_version();
sprintf(tasker, "Windows and DesqView %d.%02d", dv / 256, dv % 256);
break;
case 4:
sprintf(tasker, "NETBIOS network");
multitasker = 1;
break;
case 5:
case 6:
case 7:
if ((_osmajor / 10 == 2) && (_osminor >= 30))
strcpy(tasker, "OS/2 Warp");
else
sprintf(tasker, "OS/2 %d.%2.2d", _osmajor / 10, _osminor);
break;
case 8:
sprintf(tasker, "NETBIOS network");
multitasker = 1;
break;
default:
strcpy(tasker, "DOS");
break;
}
strcpy(s, "CONFIG.OVR");
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f < 0) {
output("\n ! %s NOT FOUND.", s);
return 1;
}
sh_lseek(f, (instance - 1) * sizeof(configoverrec), SEEK_SET);
sh_read(f, &syscfgovr, sizeof(configoverrec));
f = sh_close(f);
sprintf(s, "%sINSTANCE.DAT", syscfg.datadir);
if (!exist(s)) {
output("\n ! %s NOT FOUND.", s);
return 1;
}
read_networks();
news = 0;
num_addr = 0;
ss = argv[argc - 1];
ok = 0;
if (_fstrstr((char *) ss, ".") != NULL) {
if (atoi(&ss[1]) < net_num_max) {
netnum = atoi(&ss[1]);
ok = 1;
}
} else {
ss = (getenv("WWIV_NET"));
netnum = atoi(ss);
if (netnum < net_num_max)
ok = 1;
}
if (!ok) {
strcpy(s, "WWIV_NET.DAT");
if ((fp = fsh_open(s, "rb")) != NULL) {
fgets(s, 3, fp);
netnum = atoi(s);
if (fp != NULL)
fclose(fp);
if (netnum < net_num_max)
ok = 1;
}
}
ss = argv[1];
if (strncmpi(ss, "/N", 2))
ok = 0;
set_net_num(netnum);
sprintf(s, "%sADDRESS.1", net_data);
if (!exist(s))
ok = 0;
if (ok) {
*SMTPHOST = *POPHOST = *NEWSHOST = *TIMEHOST = *POPNAME = *POPPASS = 0;
*IPADDR = *NETMASK = *DNS = *SDNS = *DOMAIN = *GATEWAY = *FWDNAME = *FWDDOM = 0;
if (parse_net_ini()) {
set_net_num(netnum);
if (ini_section & INI_NETWORK) {
if (!(ini_section & INI_GENERAL)) {
output("\n ! [GENERAL] tag missing from NET.INI!");
ok = 0;
}
} else {
ok = 0;
output("\n ! [FILENET] tag missing from NET.INI!");
}
} else {
output("\n ! %s NET.INI!", strings[1]);
ok = 0;
}
}
if (ok)
if (create_contact_ppp())
ok = 0;
if (ok) {
log_it(1, "\n\n%s", version);
output("\n%s\n", author);
time(&some);
time_now = localtime(&some);
sprintf(s1, "\n ■ Running under %s on instance %d ", tasker, instance);
strftime(s, 80, "at %I:%M%p, %d %b %y", time_now);
strcat(s1, s);
log_it(1, s1);
log_it(1, "\n ■ Memory available : %ld bytes -", coreleft());
if (net_data[1] == ':')
i = net_data[0];
else
i = maindir[0];
i = toupper(i) - 'A' + 1;
_dos_getdiskfree(i, &df);
dspace = ((float)df.avail_clusters * (float)df.bytes_per_sector *
(float)df.sectors_per_cluster);
if (dspace < 1024000.00) {
log_it(1, "\n ■ Only %.1fK available on drive %c:... aborting!",
dspace, i + '@');
do_exit(EXIT_FAILURE);
} else
log_it(1, " Disk space : %c:%.1fM", i + '@', (dspace / 1024000L));
set_net_num(netnum);
ss = argv[1];
sy = atoi(&ss[2]);
destaddr[0] = 0;
if (sy != 32767)
good_addr(destaddr, sy);
if ((destaddr[0] == 0) && (sy != 32767)) {
output("\n ■ Using direct dial for @%hd.%s\n\n", sy, net_name);
ok = 0;
} else {
ok = 1;
if (sy == 32767) {
if (ini_section & INI_NEWS)
output("\n ■ Initiating newsgroup session...");
else {
output("\n ■ [NEWS] missing from NET.INI!");
do_exit(EXIT_FAILURE);
}
}
}
}
if (ok) {
if (!MOREINFO)
freopen(NULL, "w", stdout);
if (CLEANUP)
process_mail();
set_net_num(netnum);
sprintf(s, "%sSPOOL", net_data);
if ((make_path(s)) < 0) {
log_it(1, "\n ■ %s \"%s\"", strings[0], s);
do_exit(EXIT_FAILURE);
}
sprintf(s, "%sMQUEUE", net_data);
if ((make_path(s)) < 0) {
log_it(1, "\n ■ %s \"%s\"", strings[0], s);
do_exit(EXIT_FAILURE);
}
sprintf(s, "%sOUTBOUND", net_data);
if ((make_path(s)) < 0) {
log_it(1, "\n ■ %s \"%s\"", strings[0], s);
do_exit(EXIT_FAILURE);
}
sprintf(s, "%sINBOUND", net_data);
if ((make_path(s)) < 0) {
log_it(1, "\n ■ %s \"%s\"", strings[0], s);
do_exit(EXIT_FAILURE);
}
sprintf(s, "%sSENT", net_data);
if ((make_path(s)) < 0) {
log_it(1, "\n ■ %s \"%s\"", strings[0], s);
do_exit(EXIT_FAILURE);
}
if (PURGE) {
if ((KEEPSENT) && (sy != 32767)) {
log_it(1, "\n ■ Purging sent packets older than %d day%s...", KEEPSENT,
KEEPSENT == 1 ? "" : "s");
sprintf(s, "%s\\PPPUTIL PURGE %s\\SENT\\ %d", maindir, net_data, KEEPSENT);
do_spawn(s);
}
}
sprintf(s, "%sCHECKNET", net_data);
if ((make_path(s)) < 0) {
log_it(1, "\n ■ %s \"%s\"", strings[0], s);
do_exit(EXIT_FAILURE);
}
send = 1;
check_exp();
cd_to(maindir);
if ((sy != 32767) || (ONECALL)) {
output("\n ■ Preparing outbound packets...");
if (!uu_packets()) {
sprintf(s, "%sMQUEUE\\*.*", net_data);
if (findfirst(s, &ff, 0) == 0) {
output(" already in MQUEUE to be sent.");
} else {
output(" no mail or packets to send.");
send = 0;
}
} else {
backline();
output(" ■ All packets prepared for transfer.");
}
}
starttime = clock();
sentbytes = recdbytes = snewsbytes = rnewsbytes = 0L;
cd_to(maindir);
if (create_wattcp_cfg())
do_exit(EXIT_FAILURE);
#ifndef PACKET
sprintf(s, "%sNET%d.CFG", net_data, instance);
if (exist(s)) {
sprintf(s1, "%s\\NET.CFG", maindir);
unlink(s1);
if (!copyfile(s, s1))
log_it(1, "\n ■ %s %s from %s.", strings[0], s1, s);
}
klos_ppp();
#endif
sprintf(temp_dir, "%sINBOUND\\", net_data);
ok = 0;
time(&some);
time_now = localtime(&some);
strftime(s, 80, "\n - SMTP/POP on %A, %B %d, %Y at %H:%M %p",
time_now);
log_it(0, s);
sentbytes = recdbytes = 0L;
if ((send) && ((sy != 32767) || (ONECALL))) {
totf = 0;
sprintf(temp, "%sMQUEUE\\*.*", net_data);
f1 = findfirst(temp, &ff, FA_ARCH);
while (f1 == 0) {
ok = 1;
++totf;
sentbytes += ff.ff_fsize;
f1 = findnext(&ff);
}
sprintf(s1, "%sMQUEUE\\", net_data);
sprintf(s, "%s\\POP -send %s %s %s %d", maindir, SMTPHOST, DOMAIN, s1, MOREINFO);
do_spawn(s);
f1 = findfirst(temp, &ff, FA_ARCH);
while (f1 == 0) {
--totf;
sentbytes -= ff.ff_fsize;
f1 = findnext(&ff);
}
cd_to(maindir);
if (ok) {
backline();
log_it(0, "\n");
log_it(1, " ■ Outbound mail transfer completed : %d message%s (%ldK).",
totf, totf == 1 ? "" : "s", ((sentbytes + 1023) / 1024));
}
}
if ((sy != 32767) || (ONECALL)) {
do {
if (BBSNODE == 2)
sprintf(s, "%s\\POP.EXE -receive filenet.ml.org n%hd %s %s 1 filenet.ml.org %d",
maindir, net_sysnum, NODEPASS, temp_dir, MOREINFO);
else
sprintf(s, "%s\\POP.EXE -receive %s %s %s %s %d %s %d",
maindir, POPHOST, POPNAME, POPPASS,
temp_dir, ALLMAIL, DOMAIN, MOREINFO);
result = do_spawn(s);
sprintf(s1, "%s*.*", temp_dir);
if ((result == EXIT_SUCCESS) || (exist(s1))) {
sprintf(temp, "%s*.*", temp_dir);
f1 = findfirst(temp, &ff, FA_ARCH);
i = 0;
while (f1 == 0) {
if ((strncmp(ff.ff_name, "BAD", 3) != 0) && (strncmp(ff.ff_name, "SPM", 3) != 0) &&
(strncmp(ff.ff_name, "SUB", 3) != 0) && (strncmp(ff.ff_name, "DUP", 3) != 0) &&
(ff.ff_fsize)) {
recdbytes += ff.ff_fsize;
sprintf(s1, "%s%s", temp_dir, ff.ff_name);
cd_to(maindir);
sprintf(temp, "%s\\UU.EXE -decode %s %s %s", maindir, ff.ff_name,
temp_dir, net_data);
if (!do_spawn(temp))
unlink(s1);
}
f1 = findnext(&ff);
}
} else
output("\n ■ No network packets to process");
--BBSNODE;
} while (BBSNODE);
}
check_exp();
mailtime = clock() - starttime;
if ((sy == 32767) || (ONECALL)) {
time(&some);
time_now = localtime(&some);
strftime(s, 80, "\n - NEWS session beginning on %A, %B %d, %Y at %H:%M %p",
time_now);
log_it(0, s);
news = 1;
starttime = clock();
set_net_num(netnum);
sprintf(temp, "%sOUTBOUND\\*.*", net_data);
f1 = findfirst(temp, &ff, FA_ARCH);
while (f1 == 0) {
snewsbytes += ff.ff_fsize;
f1 = findnext(&ff);
}
cd_to(maindir);
strcpy(s1, net_data);
if (LAST(s1) == '\\')
LAST(s1) = 0;
sprintf(s, "%s\\NEWS.EXE %s %s %hu", maindir, s1, NEWSHOST, net_sysnum);
ok = 1;
do_spawn(s);
set_net_num(netnum);
sprintf(temp, "%sP0*.*", net_data);
f1 = findfirst(temp, &ff, 0);
while (f1 == 0) {
rnewsbytes += ff.ff_fsize;
f1 = findnext(&ff);
}
}
} else {
output("\n");
set_net_num(netnum);
strcpy(s, "NETWORK0.EXE");
for (i = 1; i < argc; i++) {
strcat(s, " ");
strcat(s, argv[i]);
}
s[strlen(s) + 1] = '\0';
do_it(s);
exit(EXIT_SUCCESS);
}
sprintf(s1, "%s\\NTIME.EXE", maindir);
if ((exist(s1)) && (*TIMEHOST)) {
output("\n ■ Polling %s... ", TIMEHOST);
sprintf(s, "%s %s", s1, TIMEHOST);
do_spawn(s);
}
#ifndef PACKET
unload_klos();
#endif
output("\n ■ Updating network connection records...");
if ((sy != 32767) || ((sy == 32767) && (ONECALL))) {
recdbytes = ((recdbytes + 1023) / 1024);
sentbytes = ((sentbytes + 1023) / 1024);
if (mailtime)
sprintf(ttotal, "%3.1f", (mailtime / CLK_TCK / 60));
else
strcpy(ttotal, "0.1");
sprintf(s, "%s\\PPPUTIL.EXE NETLOG %hd %lu %lu %s %s",
maindir, sy, sentbytes, recdbytes, ttotal, net_name);
if (do_spawn(s))
log_it(1, "\n ! %s", strings[4]);
if (update_contacts(sy, sentbytes, recdbytes))
log_it(1, "\n ■ %s", strings[3]);
}
if (news) {
if ((newstime = clock()) == (clock_t) - 1)
log_it(1, "\n ■ NEWS time invalid.");
else {
newstime -= starttime;
if (newstime)
sprintf(ttotal, "%3.1f", (newstime / CLK_TCK / 60));
else
strcpy(ttotal, "0.1");
rnewsbytes = ((rnewsbytes + 1023) / 1024);
if (rnewsbytes > 9999L)
rnewsbytes = 9999L;
snewsbytes = ((snewsbytes + 1023) / 1024);
if (update_contact(32767, snewsbytes, rnewsbytes))
log_it(1, "\n ■ %s", strings[3]);
sprintf(s, "%s\\PPPUTIL.EXE NETLOG 32767 %lu %lu %s %s", maindir, snewsbytes, rnewsbytes, ttotal, net_name);
if (do_spawn(s))
log_it(1, "\n ! %s", strings[4]);
}
}
if (CLEANUP) {
process_mail();
set_net_num(netnum);
}
sprintf(s, "%s\\PPPUTIL.EXE TRIM %s NEWS.LOG", maindir, net_data);
do_spawn(s);
cd_to(maindir);
set_net_num(netnum);
log_it(1, "\n ■ %s completed!\n\n", version);
return 0;
}