home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
PPPBCKP
/
SRC
/
SRC15B92.ZIP
/
NETWORK.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1998-10-09
|
48KB
|
1,885 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"
#undef MAXPATH
#define MAXPATH 160
#define NUL '\0'
#define LAST(s) s[strlen(s)-1]
#define SHARE_LEVEL 10
#define WAIT_TIME 10
#define TRIES 100
struct ts_os_ver {
int maj;
int min;
};
#define DOS 0
#define OS2 1
#define DV 2
#define WINS 3
#define WIN3 4
#define MT_DOS 0x01
#define MT_OS2 0x02
#define MT_DV 0x04
#define MT_WINS 0x08
#define MT_WIN3 0x10
struct ts_os_ver t_os_ver[5];
int t_os_type;
int t_os;
char t_os_name[41];
#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 " VERSION " (" __DATE__ ")";
char *author = "Contact Frank Reid at edare@home.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 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, netnum;
int instance, lsl_loaded;
char SMTPHOST[40], POPHOST[40], NEWSHOST[40], POPNAME[40], POPPASS[40], PROXY[40];
char IPADDR[18], NETMASK[18], FWDNAME[20], FWDDOM[40], TIMEHOST[40], DNS[16];
char PRIMENET[25], NODEPASS[20], SDNS[16], DOMAIN[40], GATEWAY[16], temp_dir[MAXPATH];
unsigned int KEEPSENT, ALLMAIL, CLEANUP, MOREINFO, NOLISTNAMES, NOWATTCP;
unsigned int TIMEOUT, SOCK_DELAY, INACTIVE;
unsigned int ONECALL, PURGE, BBSNODE, PPPD;
char *xenviron[20];
int detect_multitask(void)
{
union REGS t_regs;
t_os_type = 0;
t_os = 0;
if (_osmajor < 10) {
t_os_ver[DOS].maj = _osmajor;
t_os_ver[DOS].min = _osminor;
t_os_type = t_os_type | MT_DOS;
strcpy(t_os_name, "DOS");
} else {
t_os_type = t_os_type | MT_OS2;
t_os_ver[OS2].maj = _osmajor / 10;
t_os_ver[OS2].min = _osminor;
if (t_os_ver[OS2].maj == 3) {
strcpy(t_os_name, "OS/2 Warp");
} else {
strcpy(t_os_name, "OS/2");
}
}
t_regs.x.ax = 0x4680;
int86(0x2F, &t_regs, &t_regs);
if (t_regs.x.ax == 0x0000) {
t_os_ver[WINS].maj = 3;
t_os_ver[WINS].min = 0;
t_os_type = t_os_type | MT_WINS;
} else {
t_regs.x.ax = 0x1600;
int86(0x2F, &t_regs, &t_regs);
switch (t_regs.h.al) {
case 0x00:
case 0x80:
case 0x01:
case 0xFF:
break;
default:
t_os_type = t_os_type | MT_WIN3;
t_os_ver[WIN3].maj = t_regs.h.al;
t_os_ver[WIN3].min = t_regs.h.ah;
if (t_os_ver[WIN3].maj == 4) {
strcpy(t_os_name, "Windows 95");
t_os_ver[WIN3].maj = t_os_ver[WIN3].maj - 3;
} else {
strcpy(t_os_name, "Windows");
}
break;
}
}
t_regs.x.cx = 0x4445;
t_regs.x.dx = 0x5351;
t_regs.x.ax = 0x2B01;
intdos(&t_regs, &t_regs);
if (t_regs.h.al != 0xFF) {
t_os_type = t_os_type | MT_DV;
t_os_ver[DV].maj = t_regs.h.bh;
t_os_ver[DV].min = t_regs.h.bl;
strcpy(t_os_name, "DESQview");
}
if (t_os_type & MT_DOS)
t_os = DOS;
if (t_os_type & MT_DV)
t_os = DV;
if (t_os_type & MT_WINS)
t_os = WINS;
if (t_os_type & MT_WIN3)
t_os = WIN3;
if (t_os_type & MT_OS2)
t_os = OS2;
return (t_os - 1);
}
void giveup_timeslice(void)
{
union REGS t_regs;
switch (t_os) {
case DOS:
break;
case OS2:
case WIN3:
case WINS:
t_regs.x.ax = 0x1680;
int86(0x2f, &t_regs, &t_regs);
break;
case DV:
t_regs.x.ax = 0x1000;
int86(0x15, &t_regs, &t_regs);
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);
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[30];
ss1 = strdup(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)
free(ss1);
ss1 = NULL;
return i;
}
#ifndef PACKET
void unload_klos(int pppd)
{
char s[160];
char far *ss;
int i;
if (pppd) {
for (i = 0x60; i < 0x80; i++) {
ss = (char far *) getvect(i);
if (memcmp(&(ss[3]), "PKT DRVR", 8) == 0)
break;
}
sprintf(s, "%s\\TERMIN.COM 0x%02X", maindir, i);
do_spawn(s);
} else {
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, "\\");
}
}
unsigned char *trimstr1(unsigned 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);
fprintf(fp, "MIME-Version: 1.0\n");
fprintf(fp, "Content-Type: text/plain; charset=us-ascii\n");
fprintf(fp, "Content-Transfer-Encoding: x-uue\n");
sprintf(s2, "Message-ID: <%s-%s@%s>\n", pktname, POPNAME, DOMAIN);
fprintf(fp, s2);
sprintf(s2, "Subject: NET PACKET : %s.UUE\n\n", pktname);
fprintf(fp, s2);
sprintf(s2, "NET: %s\n\n", net_name);
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, int set_time)
{
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;
if (set_time) {
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, 1);
else
i1 = update_contact(curaddr.sysnum, 0, 0, 1);
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));
sh_close(f);
return 0;
}
sh_lseek(f, 0L, SEEK_SET);
sh_read(f, (void *) netsys, num_sys_list * sizeof(net_system_list_rec));
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, 0);
}
}
}
if (fc != NULL)
fclose(fc);
farfree(netsys);
return found;
}
int parse_net_ini(void)
{
char cursect, fn[MAXPATH], line[121], vanline[121], *ss;
FILE *fp;
sprintf(fn, "%s\\NET.INI", maindir);
if ((fp = fsh_open(fn, "rt")) == NULL) {
output("\n ! Unable to read %s.", fn);
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) ||
(strnicmp(line, "[NETWORK]", 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, "PRIMENET", 8) == 0) {
if (ss)
strcpy(PRIMENET, 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, "PROXY", 5) == 0) {
if (ss)
strcpy(PROXY, 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, "DRIVER", 6) == 0) {
if (toupper(ss[0]) == 'P')
PPPD = 1;
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, "NOWATTCP", 8) == 0) {
if (toupper(ss[0]) == 'Y')
NOWATTCP = 1;
continue;
}
if (strnicmp(line, "NOLISTNAMES", 11) == 0) {
if (toupper(ss[0]) == 'Y')
NOLISTNAMES = 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);
}
int read_networks(void)
{
int f, max;
char s[121];
sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
f = sh_open1(s, O_RDONLY | O_BINARY);
max = 0;
if (f > 0)
max = (int) (filelength(f) / sizeof(net_networks_rec));
sh_close(f);
return max;
}
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(int pppd)
{
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;
}
if (pppd)
fprintf(fp, "my_ip=bootp\n");
else {
fprintf(fp, "my_ip=%s\n", IPADDR);
fprintf(fp, "netmask=%s\n", NETMASK);
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, "nameserver=%s\n", DNS);
if (SDNS[0] != 0)
fprintf(fp, "nameserver=%s\n", SDNS);
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) {
if (strnicmp(&s[14], "text", 4) != 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(int pppd)
{
char s[160];
int i;
if (pppd) {
cd_to(maindir);
if (MOREINFO)
sprintf(s, "%s\\EPPPDD.EXE", maindir);
else
sprintf(s, "%s\\EPPPD.EXE", maindir);
if (exist(s)) {
output("\n ■ Dialing %s using %s - [Ctrl-C] aborts...\n", DOMAIN, s);
i = do_spawn(s);
} else
log_it(1, "\n ■ %s not in BBS directory!", s);
} else {
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);
} else {
log_it(1, "\n ■ %s\\PPPSTATE.EXE not found!", maindir);
do_exit(EXIT_FAILURE);
}
}
switch (i) {
case 0:
if (!pppd)
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:
if (pppd)
log_it(1, "no connection.");
else {
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);
}
if (!pppd) {
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[201], s1[201], destaddr[101], temp[161], ttotal[21];
int i, net_num_max, i1, 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;
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));
sh_close(f);
detect_multitask();
sprintf(tasker, "%s v%d.%d", t_os_name, t_os_ver[t_os].maj, t_os_ver[t_os].min);
ss = getenv("WWIV_INSTANCE");
if (ss) {
instance = atoi(ss);
if ((instance <= 0) || (instance > 999)) {
output("\n ! WWIV_INSTANCE must be 1..999!");
instance = 1;
}
} else
instance = 1;
ss = NULL;
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));
sh_close(f);
sprintf(s, "%sINSTANCE.DAT", syscfg.datadir);
if (!exist(s)) {
output("\n ! %s NOT FOUND.", s);
return 1;
}
net_num_max = 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 (netnum < net_num_max)
ok = 1;
}
if (fp != NULL)
fclose(fp);
}
ss = argv[1];
if (strncmpi(ss, "/N", 2))
ok = 0;
set_net_num(netnum);
sprintf(s, "%sADDRESS.NET", net_data);
if (!exist(s)) {
sprintf(s, "ADDRESSS.1", net_data);
if (!exist(s))
ok = 0;
}
if (ok) {
*SMTPHOST = *POPHOST = *NEWSHOST = *TIMEHOST = *POPNAME = *POPPASS = *PROXY = 0;
*IPADDR = *NETMASK = *DNS = *SDNS = *DOMAIN = *GATEWAY = *FWDNAME = *FWDDOM = 0;
PPPD = KEEPSENT = CLEANUP = MOREINFO = NOLISTNAMES = ONECALL = 0;
BBSNODE = ALLMAIL = PURGE = 1;
TIMEOUT = INACTIVE = 60;
SOCK_DELAY = 30;
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 ! [NETWORK] 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 ■ Available memory : %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, "%sMQUEUE\\FAILED", net_data);
if ((make_path(s)) < 0) {
log_it(1, "\n ■ %s \"%s\"", strings[0], s);
do_exit(EXIT_FAILURE);
}
sprintf(s, "%sMQUEUE\\DIGEST", 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 %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);
#ifndef PACKET
log_it(0, "\n ■ Memory available : %ld bytes -", coreleft());
sprintf(s, "%s%s%d.CFG", net_data, PPPD ? "PPPDRC" : "NET", instance);
if (exist(s)) {
sprintf(s1, "%s\\%s.CFG", maindir, PPPD ? "PPPDRC" : "NET");
unlink(s1);
if (!copyfile(s, s1))
log_it(1, "\n ■ %s %s from %s.", strings[0], s1, s);
}
if (!NOWATTCP) {
if (create_wattcp_cfg(PPPD))
do_exit(EXIT_FAILURE);
}
klos_ppp(PPPD);
log_it(0, "\n ■ Memory available : %ld bytes -", coreleft());
#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.EXE -send %s %s %s %d %d", maindir, SMTPHOST, DOMAIN,
s1, MOREINFO, NOLISTNAMES);
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)) {
if ((*PRIMENET) && (strnicmp(net_name, PRIMENET, strlen(net_name) != 0))) {
output("\n ■ No packet receipt for %s.", net_name);
} else {
sprintf(s, "%s\\POP -r %s %d %d n%hd",
maindir, temp_dir, ALLMAIL, MOREINFO, net_sysnum);
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) &&
(strncmp(ff.ff_name, "FIW", 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");
}
}
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(PPPD);
#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, 1))
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;
}