home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
PPPBCKP
/
SRC15B42.ZIP
/
NETWORK.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-09-26
|
47KB
|
1,882 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 <mem.h>
#include <conio.h>
#include <io.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"
#define NUL '\0'
#define LAST(s) s[strlen(s)-1]
#define MAX_PATH 79
#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 VIDEO 0x10
#define INI_NETWORK 0x01
#define INI_GENERAL 0x02
#define INI_NEWS 0x04
char *version = "Freeware PPP Net Packet Engine " VERSION " (" __DATE__ ")";
char *author = "Contact Frank Reid at edare@ix.netcom.com or 1@8213.WWIVnet for support";
extern unsigned _stklen = 10240;
typedef struct {
unsigned short sysnum;
char address[60];
} net_address_rec;
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], maindir[121];
char net_name[16], net_data[121];
unsigned short net_sysnum;
int num_sys_list, net_num, net_num_max, netnum;
static int lsl_loaded;
char SMTPHOST[60], POPHOST[60], NEWSHOST[60], POPNAME[60], POPPASS[25];
char IPADDR[21], NETMASK[21], FWDNAME[60], FWDDOM[60];
char DNS[21], DOMAIN[60], GATEWAY[60], temp_dir[MAXPATH];
unsigned int KEEPSENT = 0, ALLMAIL = 1, CLEANUP = 0, MOREINFO = 0, TIMEOUT = 60, SOCK_DELAY = 30, INACTIVE = 60;
unsigned int ONECALL = 0, PURGE = 1;
int instance;
char *xenviron[50];
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 *) strchr(fmode, 'w')) != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT | O_TRUNC;
} else
if (((char *) strchr(fmode, 'a')) != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT;
} else {
md = O_RDONLY;
}
if (((char *) strchr(fmode, 'b')) != NULL) {
md |= O_BINARY;
}
if (((char *) strchr(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 *) strchr(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);
}
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 *s, *ss[50];
s = strdup(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;
if (MOREINFO)
output("\n");
i = (spawnvpe(P_WAIT, ss[0], ss, xenviron) & 0x00ff);
free(s);
return (i);
}
void unload_klos(void)
{
char s[101];
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);
}
}
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 = (int) strlen(s);
while ((i > 0) && ((char *) strchr(whitespace, s[i - 1]) != NULL))
--i;
while ((i > 0) && ((char *) strchr(whitespace, *s) != NULL)) {
memmove(s, s + 1, --i);
}
s[i] = NUL;
return (s);
}
char *make_abs_path(unsigned 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, 0);
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[MAX_PATH], current_drive, *p, *flp;
union REGS r;
p = flp = strdup(s);
_getdcwd(0, current_path, MAX_PATH);
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[121];
sprintf(s, "%s\\FLINK.EXE", maindir);
if (exist(s))
do_spawn(s);
sprintf(s, "%s\\LINKER.EXE", maindir);
if (exist(s))
do_spawn(s);
}
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 ■ Unable to create %s!\n", 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) {
output("\n ■ Unable to read %s!\n", 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 *input, char *output)
{
int f1, f2, i;
char *b;
struct ftime ft;
if ((strcmp(input, output) != 0) && (exist(input)) && (!exist(output))) {
if ((b = (char *) malloc(16400)) == NULL)
return 0;
f1 = sh_open1(input, O_RDONLY | O_BINARY);
if (!f1) {
free(b);
b = NULL;
return 0;
}
getftime(f1, &ft);
f2 = sh_open(output, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
if (!f2) {
free(b);
b = NULL;
sh_close(f1);
return 0;
}
i = read(f1, (void *) b, 16384);
while (i > 0) {
sh_write(f2, (void *) b, i);
i = read(f1, (void *) b, 16384);
}
f1 = sh_close(f1);
setftime(f2, &ft);
f2 = sh_close(f2);
free(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[121], s2[81];
FILE *fp;
sprintf(s, "%sMQUEUE\\%s.UUE", net_data, pktname);
if ((fp = fsh_open(s, "wt")) == NULL) {
output("\n ■ Unable to open %s for write operations!", s);
do_exit(EXIT_FAILURE);
} else {
sprintf(s2, "from: %s@%s\n", POPNAME, DOMAIN);
fprintf(fp, s2);
sprintf(s2, "to: %s\n", dest);
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 -encode %s %s", maindir, fn, s);
ok = do_spawn(s1);
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) {
output("\n ■ Unable to allocate %d bytes of memory to update CONTACT.NET",
(int) (netcfg.num_ncn + 2) * sizeof(net_contact_rec));
sh_close(f);
return 1;
}
sh_lseek(f, 0L, SEEK_SET);
sh_read(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
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));
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) {
output("\n ■ Unable to read %s!\n", 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;
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) {
output("\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) {
output("\n ■ Unable to read %s!\n", 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;
else {
sprintf(s1, "%sZ%hd.NET", net_data, curaddr.sysnum);
if (exist(s1))
sz = 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 ■ Error creating %sMQUEUE\\%s.UUE", net_data, pktname);
if (fc != NULL)
fclose(fc);
farfree(netsys);
do_exit(EXIT_FAILURE);
} else {
found = 1;
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);
sh_close(f1);
}
if (!copyfile(s3, s2))
output("\n ■ Error moving %s%hd.NET", sz ? "Z" : "S", curaddr.sysnum);
}
unlink(s1);
update_contact(curaddr.sysnum, sbytes, 0);
}
}
}
if (fc != NULL)
fclose(fc);
farfree(netsys);
return found;
}
int purge_sent(void)
{
char s[121];
int f1, howmany = 0;
long age;
struct ffblk ff;
struct stat fileinfo;
sprintf(s, "%sSENT\\*.*", net_data);
f1 = findfirst(s, &ff, 0);
while (f1 == 0) {
sprintf(s, "%sSENT\\%s", net_data, ff.ff_name);
if (stat(s, &fileinfo) == 0) {
age = (time(NULL) - fileinfo.st_atime);
if (age > (86400L * KEEPSENT)) {
++howmany;
unlink(s);
}
}
f1 = findnext(&ff);
}
return howmany;
}
int parse_net_ini(void)
{
char cursect;
char line[121], *ss;
FILE *fp;
if ((fp = fsh_open("NET.INI", "rt")) == NULL)
return (0);
while (fgets(line, 80, fp)) {
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, "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 (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, "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 count_lines(char *s)
{
FILE *fp;
char fn[121];
unsigned int nl = 0;
const int NEWLINE = '\n';
int c;
strcpy(fn, s);
if ((fp = fsh_open(fn, "rt")) == NULL) {
printf("\n ■ Cannot open %s", fn);
return 0;
}
while ((c = getc(fp)) != EOF) {
if (c == NEWLINE)
++nl;
}
if (fp != NULL)
fclose(fp);
return nl;
}
typedef struct {
char line[81];
} nlines;
nlines *NETLOG;
int write_netlog(int sn, long sent, long recd, char *tmused)
{
FILE *fp;
int i = 0;
unsigned int lines;
char s[81], s1[81], s2[81], fn[121];
struct tm *time_now;
time_t some;
sprintf(fn, "%sNET.LOG", syscfg.gfilesdir);
lines = 0;
lines = count_lines(fn);
if ((NETLOG = ((nlines *) farmalloc((lines + 2) * 81))) == NULL) {
output("\n ■ Unable to allocate %d bytes for NET.LOG entry",
(lines + 2) * 81);
return 1;
}
if ((fp = fsh_open(fn, "r")) == NULL) {
farfree(NETLOG);
return 1;
}
while (fgets(s, 80, fp)) {
strtok(s, "\n");
strcpy(NETLOG[i++].line, s);
}
if (fp != NULL)
fclose(fp);
time(&some);
time_now = localtime(&some);
strftime(s1, 35, "%m/%d/%y %H:%M:%S", time_now);
if ((sent) || (recd)) {
if ((recd) && (!sent))
sprintf(s2, " , R:%4ldk,", recd);
else {
if ((recd) && (sent))
sprintf(s2, "S:%4ldk, R:%4ldk,", sent, recd);
else
sprintf(s2, "S:%4ldk, ", sent);
}
} else
strcpy(s2, " ");
if ((fp = fsh_open(fn, "wt+")) != NULL) {
fprintf(fp, "%s To %5d, %s %4s min %s\n", s1, sn, s2,
tmused, net_name);
for (i = 0; i < lines; i++)
fprintf(fp, "%s\n", NETLOG[i].line);
fclose(fp);
}
farfree(NETLOG);
return 0;
}
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));
sh_close(f);
}
}
void init(void)
{
char s[81], s1[81], *ss;
int i, i1, dv, f;
struct tm *time_now;
time_t some;
output("\n%s\n%s\n\n", version, author);
get_dir(maindir, 0);
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;
}
detect_multitask();
switch (multitasker) {
case 1:
dv = get_dv_version();
sprintf(s1, "DesqView %d.%02d", dv / 256, dv % 256);
break;
case 2:
dv = get_win_version();
if (dv == 4)
strcpy(s1, "Windows 95");
else
sprintf(s1, "Windows %d.%02d", dv % 256, dv / 256);
break;
case 3:
dv = get_dv_version();
sprintf(s1, "Windows and DesqView %d.%02d", dv / 256, dv % 256);
break;
case 4:
case 5:
case 6:
case 7:
if ((_osmajor / 10 == 2) && (_osminor >= 30))
strcpy(s1, "OS/2 Warp");
else
sprintf(s1, "OS/2 %d.%2.2d", _osmajor / 10, _osminor);
break;
case 8:
sprintf(s1, "NETBIOS network");
multitasker = 1;
break;
default:
strcpy(s1, "DOS");
break;
}
strcpy(s, "CONFIG.DAT");
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f < 0) {
output("\n ■ %s NOT FOUND.", s);
return;
}
sh_read(f, (void *) (&syscfg), sizeof(configrec));
sh_close(f);
output(" ■ Running under %s on instance %d ", s1, instance);
time(&some);
time_now = localtime(&some);
strftime(s, 80, "at %I:%M%p, %d %b %y", time_now);
printf(s);
strcpy(s, "CONFIG.OVR");
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f < 0) {
output("\n ■ %s NOT FOUND.", s);
return;
}
sh_lseek(f, (instance - 1) * sizeof(configoverrec), SEEK_SET);
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;
}
read_networks();
i = i1 = 0;
while (environ[i] != NULL) {
xenviron[i1++] = environ[i];
++i;
}
xenviron[i1] = NULL;
}
long getfctime(char *s)
{
struct stat statbuf;
if (stat(s, &statbuf) < 0)
return (0L);
else
return (statbuf.st_atime);
}
int process_bbsdata(void)
{
char s[101];
unsigned long bbslist_ctime, connect_ctime, callout_ctime, bbsdata_ctime;
int tf, n, net3;
net3 = 0;
sprintf(s, "%sBBSLIST.NET", net_data);
bbslist_ctime = getfctime(s);
sprintf(s, "%sCONNECT.NET", net_data);
connect_ctime = getfctime(s);
sprintf(s, "%sCALLOUT.NET", net_data);
callout_ctime = getfctime(s);
sprintf(s, "%sBBSDATA.NET", net_data);
bbsdata_ctime = getfctime(s);
sprintf(s, "%sBBSLIST.UPD", net_data);
bbslist_ctime = getfctime(s);
sprintf(s, "%sCONNECT.UPD", net_data);
connect_ctime = getfctime(s);
n = 0;
tf = ((bbslist_ctime > bbsdata_ctime) || (connect_ctime > bbsdata_ctime));
if (tf)
n = 1;
tf = (tf || (callout_ctime > bbsdata_ctime));
if (tf) {
sprintf(s, "NETWORK3 .%d", netnum);
if (n) {
sprintf(s, "NETWORK3 .%d Y", netnum);
net3 = 1;
}
do_spawn(s);
}
return (net3);
}
void do_it(char *cl)
{
int i, i1, l;
char *s, *ss[30];
s = strdup(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);
}
int create_wattcp_cfg(void)
{
char s[MAXPATH], s1[41];
FILE *fp;
sprintf(s, "%s\\WATTCP.CFG", maindir);
if ((fp = fsh_open(s, "wt")) == NULL) {
output("\n ■ Can't open %s for output!", s);
return 1;
}
fseek(fp, 0L, SEEK_SET);
sprintf(s, "my_ip=%s\n", IPADDR);
fprintf(fp, s);
fprintf(fp, "netmask=%s\n", NETMASK);
fprintf(fp, "nameserver=%s\n", DNS);
if (GATEWAY[0] == 0) {
strcpy(s1, IPADDR);
while (LAST(s1) != '.')
LAST(s1) = 0;
strcat(s1, "1");
strcpy(GATEWAY, s1);
}
sprintf(s, "gateway=%s\n", GATEWAY);
fprintf(fp, s);
fprintf(fp, "domainslist=\"%s\"\n", DOMAIN);
fprintf(fp, "hostname=\"%s\"\n", POPNAME);
fprintf(fp, "sockdelay=%d\n", SOCK_DELAY);
fprintf(fp, "inactive=%d\n", INACTIVE);
if (fp != NULL)
fclose(fp);
return 0;
}
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;
}
void klos_ppp(void)
{
char s[121], fn[MAXPATH], *ss;
int i;
FILE *fp;
lsl_loaded = check_for_lsl();
if (!lsl_loaded) {
sprintf(s, "%s\\LSL.COM", maindir);
if (exist(s)) {
output("\n ■ Loading Link Support Layer and ");
do_spawn(s);
} else {
output("\n ■ LSL.COM not in BBS main directory!");
do_exit(EXIT_FAILURE);
}
} else
output("\n ■ LSL already in memory - loading ");
sprintf(s, "%s\\PPP.EXE", maindir);
if (exist(s)) {
output("PPP packet driver.");
do_spawn(s);
} else {
output("\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);
sprintf(s, "%s\\PPPSTATE.EXE WAIT=%d IP", maindir, TIMEOUT);
i = do_spawn(s);
switch (i) {
case 0:
output(" connected!");
break;
case 1:
output("\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:
output("\n ■ Unknown PPPState Error #%d... aborting", 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 {
output("\n ■ %s\\PPPSTATE.EXE not found!", maindir);
do_exit(EXIT_FAILURE);
}
if (!IPADDR[0]) {
sprintf(s, "%s\\PPPWAT.EXE", maindir);
if (exist(s)) {
do_spawn(s);
} else {
output("\n ■ %s\\PPPWAT.EXE not found!", maindir);
unload_klos();
do_exit(EXIT_FAILURE);
}
sprintf(fn, "%s\\WATTCP.CFG", maindir);
if ((fp = fsh_open(fn, "rt")) == NULL) {
output("\n ■ Unable to read %s\\WATTCP.CFG... aborting!", maindir);
unload_klos();
do_exit(EXIT_FAILURE);
} else {
while (fgets(s, 100, fp) != NULL) {
if (strnicmp(s, "my_ip", 5) == 0) {
ss = strtok(s, "=");
ss = strtok(NULL, "\r");
trimstr1(ss);
strcpy(IPADDR, ss);
break;
}
}
}
if (fp != NULL)
fclose(fp);
}
if (IPADDR) {
output("\n ■ Session IP address is %s... ", IPADDR);
if (create_wattcp_cfg()) {
unload_klos();
do_exit(EXIT_FAILURE);
}
} else {
output("\n ■ Could not find IP Address... aborting!");
unload_klos();
do_exit(EXIT_FAILURE);
}
sprintf(s, "%s\\IPSTUB.EXE", maindir);
if (exist(s)) {
do_spawn(s);
} else {
output("\n ■ %s\\IPSTUB.EXE not found!", maindir);
do_exit(EXIT_FAILURE);
}
output("establishing socket ");
for (i = 5; i >= 0; i--) {
output("\b\b\b\b%d...", i);
delay(1000);
}
output("\b\b\b\b\b... ready!");
}
double freek(int dr)
{
float d;
struct dfree df;
getdfree(dr, &df);
d = (float) df.df_avail;
d *= ((float) df.df_bsec);
d *= ((float) df.df_sclus);
d /= 1024.0;
if (df.df_sclus == 0xffff)
d = -1.0;
return (d);
}
int main(int argc, char *argv[])
{
int i, ok, news, totf, send, f1;
unsigned short sy;
double dspace;
char *ss, s[121], s1[MAXPATH], destaddr[121], temp[121];
char ttotal[21];
clock_t starttime, mailtime, newstime;
unsigned long sentbytes, recdbytes, rnewsbytes, snewsbytes;
FILE *fp;
struct ffblk ff;
init();
news = 0;
num_addr = 0;
ss = argv[argc - 1];
ok = 0;
if (strstr((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[0] = 0;
POPHOST[0] = 0;
NEWSHOST[0] = 0;
POPNAME[0] = 0;
POPPASS[0] = 0;
IPADDR[0] = 0;
NETMASK[0] = 0;
DNS[0] = 0;
DOMAIN[0] = 0;
GATEWAY[0] = 0;
FWDNAME[0] = 0;
FWDDOM[0] = 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 ■ Could not open file NET.INI!");
ok = 0;
}
}
if (ok)
if (create_contact_ppp())
ok = 0;
if (ok) {
output("\n ■ Memory available : %ld bytes -", coreleft());
if (net_data[1] == ':')
i = net_data[0];
else
i = maindir[0];
i = toupper(i) - 'A' + 1;
dspace = freek(i);
if (dspace < 1024.0) {
output("\n ■ Only %.1fK available on drive %c:... aborting!",
dspace, i + '@');
do_exit(EXIT_FAILURE);
} else {
output(" Disk space ");
if (dspace < 10000.0)
output(": %c:%.1fK", i + '@', dspace);
else
output(": %c:%.1fM", i + '@', dspace / 1024.0);
}
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 retrieval session...");
news = 1;
} else {
output("\n ■ [NEWS] tag 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) {
output("\n ■ Unable to create \"%s\"", s);
do_exit(EXIT_FAILURE);
}
sprintf(s, "%sMQUEUE", net_data);
if ((make_path(s)) < 0) {
output("\n ■ Unable to create \"%s\"", s);
do_exit(EXIT_FAILURE);
}
sprintf(s, "%sOUTBOUND", net_data);
if ((make_path(s)) < 0) {
output("\n ■ Unable to create \"%s\"", s);
do_exit(EXIT_FAILURE);
}
sprintf(s, "%sINBOUND", net_data);
if ((make_path(s)) < 0) {
output("\n ■ Unable to create \"%s\"", s);
do_exit(EXIT_FAILURE);
}
sprintf(s, "%sSENT", net_data);
if ((make_path(s)) < 0) {
output("\n ■ Unable to create \"%s\"", s);
do_exit(EXIT_FAILURE);
}
if (PURGE) {
if ((KEEPSENT) && (sy != 32767)) {
output("\n ■ Purging sent packets older than %d day%s...", KEEPSENT,
KEEPSENT == 1 ? "" : "s");
i = purge_sent();
output(" %d packet%s deleted.", i, i == 1 ? "" : "s");
}
}
sprintf(s, "%sCHECKNET", net_data);
if ((make_path(s)) < 0) {
output("\n ■ Unable to create \"%s\"", s);
do_exit(EXIT_FAILURE);
}
send = 1;
cd_to(maindir);
sprintf(s, "%s\\EXP.EXE", maindir);
if (!exist(s)) {
output("\n ■ Export module EXP.EXE not found!");
} else {
sprintf(s, "%sS32767.NET", net_data);
sprintf(s1, "%sSPOOL\\UNK*.*", net_data);
if ((exist(s)) || (exist(s1))) {
sprintf(s, "EXP.EXE S32767.NET %s %hu %s %s %s",
net_data, net_sysnum, FWDNAME, FWDDOM, net_name);
if (do_spawn(s))
output("\n ■ Unknown error during export.");
} else
output("\n ■ No Internet mail or newsgroup articles to export.");
}
cd_to(maindir);
if ((sy != 32767) || (ONECALL)) {
output("\n ■ Preparing outbound mail for transmission...");
if (!uu_packets()) {
sprintf(s, "%sMQUEUE\\*.*", net_data);
if (findfirst(s, &ff, 0) == 0) {
output(" outbound packets in MQUEUE.");
} else {
output(" no mail or packets to send.");
send = 0;
}
} else {
backline();
output("\r ■ All packets prepared for transmission.");
}
}
sprintf(s, "%sNET%d.CFG", net_data, instance);
if (exist(s)) {
sprintf(s1, "%s\\NET.CFG", maindir);
unlink(s1);
if (!copyfile(s, s1))
output("\n ■ Unable to copy %s to %s", s, s1);
}
starttime = clock();
sentbytes = recdbytes = snewsbytes = rnewsbytes = 0L;
cd_to(maindir);
klos_ppp();
sprintf(temp_dir, "%sINBOUND\\", net_data);
if ((send) && ((sy != 32767) || (ONECALL))) {
totf = 0;
sprintf(temp, "%sMQUEUE\\*.*", net_data);
f1 = findfirst(temp, &ff, FA_ARCH);
if (f1 == 0)
output("\n");
while (f1 == 0) {
sprintf(s1, "%sMQUEUE\\%s", net_data, ff.ff_name);
sprintf(s, "%s\\POP -send %s %s %s %d", maindir, SMTPHOST, DOMAIN, s1, MOREINFO);
backline();
output("\r ■ SND : %s ", ff.ff_name);
if (do_spawn(s) == EXIT_SUCCESS) {
unlink(s1);
sentbytes += ff.ff_fsize;
++totf;
} else
output("\n ■ Unsuccessful! %s remains in MQUEUE.", ff.ff_name);
f1 = findnext(&ff);
}
sprintf(temp, "%sMQUEUE\\*.*", net_data);
f1 = findfirst(temp, &ff, FA_ARCH);
while (f1 == 0) {
sprintf(s1, "%sMQUEUE\\%s", net_data, ff.ff_name);
sprintf(s, "%s\\POP -send %s %s %s %d", maindir, SMTPHOST, DOMAIN, s1, MOREINFO);
backline();
output("\r ■ SND : %s ", ff.ff_name);
if (do_spawn(s) == EXIT_SUCCESS) {
unlink(s1);
sentbytes += ff.ff_fsize;
++totf;
} else
output("\n ■ Unsuccessful! %s remains in MQUEUE.", ff.ff_name);
f1 = findnext(&ff);
}
backline();
output("\r ■ Outbound mail transfer completed - %d file%s (%ldK).",
totf, totf == 1 ? "" : "s", ((sentbytes + 1023) / 1024));
send = 0;
}
if ((sy != 32767) || (ONECALL)) {
sprintf(s, "%s\\POP -receive %s %s %s %s %d %s %d", maindir, POPHOST, POPNAME, POPPASS,
temp_dir, ALLMAIL, DOMAIN, MOREINFO);
output("\n ■ Checking %s for inbound mail - ", POPHOST);
sprintf(s1, "%s*.*", temp_dir);
if ((do_spawn(s) == EXIT_SUCCESS) || (exist(s1))) {
sprintf(temp, "%s*.*", temp_dir);
f1 = findfirst(temp, &ff, FA_ARCH);
i = 0;
send = 0;
while (f1 == 0) {
if ((strncmp(ff.ff_name, "BAD", 3) != 0) && (ff.ff_fsize)) {
recdbytes += ff.ff_fsize;
sprintf(s1, "%s%s", temp_dir, ff.ff_name);
sprintf(temp, "%s\\UU -decode %s %s %s", maindir, ff.ff_name,
temp_dir, net_data);
if (!do_spawn(temp)) {
send = 1;
unlink(s1);
}
}
f1 = findnext(&ff);
}
} else
output("\n ■ No network packets to process");
if ((send) && (CLEANUP)) {
output("\n ■ Running FLINK/Linker on received packets... please wait.");
process_mail();
set_net_num(netnum);
process_bbsdata();
}
}
sprintf(s, "%sSPOOL\\UNK*.*", net_data);
if (exist(s)) {
sprintf(s, "EXP.EXE S32767.NET %s %hu %s %s %s",
net_data, net_sysnum, FWDNAME, FWDDOM, net_name);
if (do_spawn(s))
output("\n ■ Unknown error during export");
}
mailtime = clock() - starttime;
if ((sy == 32767) || (ONECALL)) {
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;
if (do_spawn(s) != EXIT_SUCCESS)
output("\n ■ Unsuccessful news retrieval session...");
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);
}
unload_klos();
newstime = clock() - starttime;
output("\n ■ Updating network connection records...");
if (ONECALL) {
recdbytes = ((recdbytes + 1023) / 1024);
sentbytes = ((sentbytes + 1023) / 1024);
if (mailtime)
sprintf(ttotal, "%2.1f", (mailtime / CLK_TCK / 60));
else
strcpy(ttotal, "0.1");
if (update_contacts(sy, sentbytes, recdbytes))
output("\n ■ Unable to access CONTACT.NET!");
if (write_netlog(sy, sentbytes, recdbytes, ttotal))
output("\n ■ Unable to access NET.LOG!");
if (newstime)
sprintf(ttotal, "%2.1f", (newstime / CLK_TCK / 60));
else
strcpy(ttotal, "0.1");
rnewsbytes = ((rnewsbytes + 1023) / 1024);
snewsbytes = ((snewsbytes + 1023) / 1024);
if (update_contact(32767, snewsbytes, rnewsbytes))
output("\n ■ Unable to access CONTACT.NET!");
if (write_netlog(32767, snewsbytes, rnewsbytes, ttotal))
output("\n ■ Unable to access NET.LOG!");
} else {
if (news) {
if (newstime)
sprintf(ttotal, "%2.1f", (newstime / CLK_TCK / 60));
else
strcpy(ttotal, "0.1");
rnewsbytes = ((rnewsbytes + 1023) / 1024);
snewsbytes = ((snewsbytes + 1023) / 1024);
if (update_contact(32767, snewsbytes, rnewsbytes))
output("\n ■ Unable to access CONTACT.NET!");
if (write_netlog(32767, snewsbytes, rnewsbytes, ttotal))
output("\n ■ Unable to access NET.LOG!");
} else {
recdbytes = ((recdbytes + 1023) / 1024);
sentbytes = ((sentbytes + 1023) / 1024);
if (mailtime)
sprintf(ttotal, "%2.1f", (mailtime / CLK_TCK / 60));
else
strcpy(ttotal, "0.1");
if (update_contacts(sy, sentbytes, recdbytes))
output("\n ■ Unable to access CONTACT.NET!");
if (write_netlog(sy, sentbytes, recdbytes, ttotal))
output("\n ■ Unable to access NET.LOG!");
}
}
cd_to(maindir);
set_net_num(netnum);
output("\n ■ %s completed!\n\n", version);
return 0;
}