2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2001-11-04 16:41:54 +00:00
|
|
|
* $Id$
|
2001-08-17 05:46:24 +00:00
|
|
|
* Purpose ...............: File forward to a node
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2004-02-21 17:22:00 +00:00
|
|
|
* Copyright (C) 1997-2004
|
2001-08-17 05:46:24 +00:00
|
|
|
*
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
* Beekmansbos 10
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
* the Netherlands
|
|
|
|
*
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
*
|
|
|
|
* This BBS is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* MBSE BBS is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
2003-08-15 20:05:34 +00:00
|
|
|
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
2001-08-17 05:46:24 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../config.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbselib.h"
|
2002-01-07 19:16:03 +00:00
|
|
|
#include "../lib/users.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbsedb.h"
|
2002-04-03 20:29:12 +00:00
|
|
|
#include "../lib/diesel.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "tic.h"
|
|
|
|
#include "sendmail.h"
|
|
|
|
#include "rollover.h"
|
2002-04-03 20:29:12 +00:00
|
|
|
#include "mgrutil.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "forward.h"
|
|
|
|
|
|
|
|
|
2002-02-10 15:57:05 +00:00
|
|
|
|
2001-08-17 05:46:24 +00:00
|
|
|
void ForwardFile(fidoaddr Node, fa_list *sbl)
|
|
|
|
{
|
2004-03-06 21:48:41 +00:00
|
|
|
char *subject = NULL, *fwdfile = NULL, *queuedir, *listfile, *ticfile = NULL, *ticname, flavor;
|
2002-08-05 20:43:29 +00:00
|
|
|
FILE *fp, *fi, *fl, *net;
|
2002-08-03 22:12:37 +00:00
|
|
|
faddr *dest, *routeto, *Fa, *Temp, *ba;
|
|
|
|
int i, z, n;
|
|
|
|
time_t now, ftime;
|
|
|
|
fa_list *tmp;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-03 22:12:37 +00:00
|
|
|
if (!SearchNode(Node)) {
|
|
|
|
WriteError("TIC forward in %s, node %s not in setup but defined in area setup", TIC.TicIn.Area, aka2str(Node));
|
|
|
|
return;
|
|
|
|
}
|
2003-02-21 20:01:25 +00:00
|
|
|
Syslog('+', "Forward file to %s %s netmail", aka2str(Node), nodes.Message?"with":"without");
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-05 20:43:29 +00:00
|
|
|
fwdfile = calloc(PATH_MAX, sizeof(char));
|
|
|
|
queuedir = calloc(PATH_MAX, sizeof(char));
|
|
|
|
listfile = calloc(PATH_MAX, sizeof(char));
|
|
|
|
sprintf(queuedir, "%s/%d.%d.%d.%d", CFG.out_queue, Node.zone, Node.net, Node.node, Node.point);
|
|
|
|
sprintf(listfile, "%s/.filelist", queuedir);
|
|
|
|
mkdirs(listfile, 0750);
|
|
|
|
if ((fl = fopen(listfile, "a+")) == NULL) {
|
|
|
|
WriteError("$Can't open %s", listfile);
|
|
|
|
free(fwdfile);
|
|
|
|
free(listfile);
|
|
|
|
free(queuedir);
|
|
|
|
return;
|
|
|
|
}
|
2002-08-03 22:12:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the full filename
|
|
|
|
*/
|
2002-11-23 18:52:46 +00:00
|
|
|
if (TIC.PassThru || TIC.SendOrg) {
|
2002-11-26 20:35:50 +00:00
|
|
|
sprintf(fwdfile, "%s/%s", TIC.Inbound, TIC.TicIn.File);
|
|
|
|
subject = xstrcpy(TIC.TicIn.File);
|
2002-08-03 22:12:37 +00:00
|
|
|
} else {
|
2002-11-23 18:52:46 +00:00
|
|
|
/*
|
|
|
|
* Make sure the file attach is the 8.3 filename
|
|
|
|
*/
|
2002-11-26 20:35:50 +00:00
|
|
|
sprintf(fwdfile, "%s/%s", TIC.BBSpath, TIC.NewFile);
|
|
|
|
subject = xstrcpy(TIC.NewFile);
|
2002-08-03 22:12:37 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-03 22:12:37 +00:00
|
|
|
flavor = 'f';
|
|
|
|
if (nodes.Crash)
|
|
|
|
flavor = 'c';
|
|
|
|
if (nodes.Hold)
|
|
|
|
flavor = 'h';
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2004-07-16 11:09:04 +00:00
|
|
|
fprintf(fl, "%c LEAVE FDN %s\n", flavor, fwdfile);
|
2002-08-05 20:43:29 +00:00
|
|
|
|
2002-08-03 22:12:37 +00:00
|
|
|
if (nodes.RouteVia.zone)
|
|
|
|
routeto = fido2faddr(nodes.RouteVia);
|
|
|
|
else
|
|
|
|
routeto = fido2faddr(Node);
|
|
|
|
dest = fido2faddr(Node);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-03 22:12:37 +00:00
|
|
|
ticfile = calloc(PATH_MAX, sizeof(char));
|
|
|
|
ticname = calloc(15, sizeof(char));
|
|
|
|
if (nodes.Tic) {
|
|
|
|
sprintf(ticname, "%08lx.tic", sequencer());
|
|
|
|
subject = xstrcat(subject, (char *)" ");
|
|
|
|
subject = xstrcat(subject, ticname);
|
2002-08-05 20:43:29 +00:00
|
|
|
sprintf(ticfile, "%s/%s", CFG.ticout, ticname);
|
2002-08-03 22:12:37 +00:00
|
|
|
}
|
|
|
|
free(ticname);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send netmail message if the node has it turned on.
|
|
|
|
*/
|
|
|
|
if (nodes.Message) {
|
|
|
|
Temp = fido2faddr(Node);
|
|
|
|
if ((net = SendMgrMail(Temp, CFG.ct_KeepMgr, TRUE, (char *)"Filemgr", subject, NULL)) != NULL) {
|
|
|
|
if ((fi = OpenMacro("forward.tic", nodes.Language, FALSE)) != NULL) {
|
|
|
|
ftime = TIC.FileDate;
|
|
|
|
MacroVars("a", "s", TIC.TicIn.Area);
|
|
|
|
MacroVars("b", "s", tic.Comment);
|
|
|
|
MacroVars("c", "d", TIC.FileCost);
|
|
|
|
MacroVars("d", "s", fgroup.Comment);
|
2002-11-26 20:35:50 +00:00
|
|
|
if (TIC.PassThru || TIC.SendOrg)
|
|
|
|
MacroVars("f", "s", TIC.TicIn.FullName);
|
|
|
|
else
|
|
|
|
MacroVars("f", "s", TIC.NewFullName);
|
2002-08-03 22:12:37 +00:00
|
|
|
MacroVars("g", "d", TIC.FileSize);
|
|
|
|
MacroVars("h", "d", (TIC.FileSize / 1024));
|
|
|
|
MacroVars("i", "s", TIC.TicIn.Crc);
|
|
|
|
MacroVars("j", "s", TIC.TicIn.Origin);
|
|
|
|
MacroVars("m", "s", rfcdate(ftime));
|
|
|
|
MacroVars("n", "s", TIC.TicIn.Desc);
|
|
|
|
MacroVars("s", "s", nodes.Sysop);
|
2002-11-26 20:35:50 +00:00
|
|
|
if (TIC.PassThru || TIC.SendOrg)
|
|
|
|
MacroVars("e", "s", TIC.TicIn.File);
|
2002-08-03 22:12:37 +00:00
|
|
|
else
|
2002-11-26 20:35:50 +00:00
|
|
|
MacroVars("e", "s", TIC.NewFile);
|
2002-08-03 22:12:37 +00:00
|
|
|
if (strlen(TIC.TicIn.Magic))
|
|
|
|
MacroVars("k", "s", TIC.TicIn.Magic);
|
|
|
|
if (strlen(TIC.TicIn.Replace))
|
|
|
|
MacroVars("l", "s", TIC.TicIn.Replace);
|
|
|
|
MacroRead(fi, net);
|
|
|
|
fprintf(net, "%s\r", TearLine());
|
|
|
|
CloseMail(net, Temp);
|
2002-04-03 20:29:12 +00:00
|
|
|
}
|
2002-08-03 22:12:37 +00:00
|
|
|
} else {
|
|
|
|
WriteError("$Can't create netmail");
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-08-03 22:12:37 +00:00
|
|
|
tidy_faddr(Temp);
|
|
|
|
}
|
|
|
|
free(subject);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-03 22:12:37 +00:00
|
|
|
/*
|
|
|
|
* If we need a .TIC file, start creating it.
|
|
|
|
*/
|
|
|
|
if (nodes.Tic) {
|
|
|
|
mkdirs(ticfile, 0770);
|
|
|
|
if ((fp = fopen(ticfile, "a+")) != NULL) {
|
|
|
|
fprintf(fp, "Area %s\r\n", TIC.TicIn.Area);
|
|
|
|
fprintf(fp, "Origin %s\r\n", TIC.TicIn.Origin);
|
|
|
|
Fa = fido2faddr(tic.Aka);
|
|
|
|
fprintf(fp, "From %s\r\n", ascfnode(Fa, 0x0f));
|
|
|
|
free(Fa);
|
|
|
|
if (strlen(TIC.TicIn.Replace))
|
|
|
|
fprintf(fp, "Replaces %s\r\n", TIC.TicIn.Replace);
|
|
|
|
if (strlen(TIC.TicIn.Magic))
|
|
|
|
fprintf(fp, "Magic %s\r\n", TIC.TicIn.Magic);
|
2001-12-13 19:54:55 +00:00
|
|
|
|
2002-11-26 20:35:50 +00:00
|
|
|
if ((TIC.PassThru) || (TIC.SendOrg)) {
|
|
|
|
fprintf(fp, "File %s\r\n", TIC.TicIn.File);
|
|
|
|
if (strlen(TIC.TicIn.FullName))
|
|
|
|
fprintf(fp, "Fullname %s\r\n", TIC.TicIn.FullName);
|
|
|
|
} else {
|
|
|
|
fprintf(fp, "File %s\r\n", TIC.NewFile);
|
|
|
|
if (strlen(TIC.NewFullName))
|
|
|
|
fprintf(fp, "Fullname %s\r\n", TIC.NewFullName);
|
|
|
|
}
|
2002-08-03 22:12:37 +00:00
|
|
|
fprintf(fp, "Size %ld\r\n", (long)(TIC.FileSize));
|
|
|
|
fprintf(fp, "Desc %s\r\n", TIC.TicIn.Desc);
|
|
|
|
fprintf(fp, "Crc %s\r\n", TIC.TicIn.Crc);
|
2002-12-01 16:25:32 +00:00
|
|
|
if (nodes.TIC_To) {
|
2002-08-03 22:12:37 +00:00
|
|
|
fprintf(fp, "To %s, %s\r\n", nodes.Sysop, ascfnode(dest, 0x1f));
|
2002-12-01 16:25:32 +00:00
|
|
|
}
|
|
|
|
if (nodes.AdvTic) {
|
2002-08-03 22:12:37 +00:00
|
|
|
fprintf(fp, "Areadesc %s\r\n", tic.Comment);
|
|
|
|
fprintf(fp, "Fdn %s\r\n", fgroup.Comment);
|
|
|
|
if (TIC.TicIn.TotLDesc)
|
|
|
|
for (i = 0; i < TIC.TicIn.TotLDesc; i++)
|
|
|
|
fprintf(fp, "LDesc %s\r\n", TIC.TicIn.LDesc[i]);
|
|
|
|
}
|
|
|
|
fprintf(fp, "Created by MBSE BBS %s %s\r\n", VERSION, SHORTRIGHT);
|
|
|
|
if (TIC.TicIn.TotPath)
|
|
|
|
for (i = 0; i < TIC.TicIn.TotPath; i++)
|
|
|
|
fprintf(fp, "Path %s\r\n", TIC.TicIn.Path[i]);
|
|
|
|
/*
|
|
|
|
* Add our system to the path
|
|
|
|
*/
|
|
|
|
now = time(NULL);
|
|
|
|
subject = ctime(&now);
|
|
|
|
Striplf(subject);
|
|
|
|
ba = bestaka_s(dest);
|
2004-12-29 15:09:38 +00:00
|
|
|
fprintf(fp, "Path %s %lu %s %s\r\n", ascfnode(ba, 0x1f), (long)mktime(localtime(&now)), subject, tzname[0]);
|
2002-08-03 22:12:37 +00:00
|
|
|
tidy_faddr(ba);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-12-01 16:25:32 +00:00
|
|
|
if (nodes.TIC_AdvSB) {
|
2002-08-03 22:12:37 +00:00
|
|
|
/*
|
|
|
|
* In advanced TIC mode we send multiple seenby
|
|
|
|
* addresses on one line in stead of one line
|
|
|
|
* per system.
|
|
|
|
*/
|
|
|
|
z = 0;
|
|
|
|
n = 0;
|
|
|
|
subject = xstrcpy((char *)"Seenby");
|
|
|
|
for (tmp = sbl; tmp; tmp = tmp->next) {
|
|
|
|
if (strlen(subject) > 70) {
|
|
|
|
fprintf(fp, "%s\r\n", subject);
|
|
|
|
z = 0;
|
|
|
|
n = 0;
|
|
|
|
free(subject);
|
|
|
|
subject = xstrcpy((char *)"Seenby ");
|
|
|
|
} else {
|
|
|
|
subject = xstrcat(subject, (char *)" ");
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-08-03 22:12:37 +00:00
|
|
|
if (z != tmp->addr->zone) {
|
|
|
|
subject = xstrcat(subject, ascfnode(tmp->addr, 0x0e));
|
|
|
|
z = tmp->addr->zone;
|
|
|
|
} else {
|
|
|
|
if (n != tmp->addr->net) {
|
|
|
|
subject = xstrcat(subject, ascfnode(tmp->addr, 0x06));
|
|
|
|
n = tmp->addr->net;
|
2001-08-17 05:46:24 +00:00
|
|
|
} else {
|
2002-08-03 22:12:37 +00:00
|
|
|
subject = xstrcat(subject, ascfnode(tmp->addr, 0x02));
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-08-03 22:12:37 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-08-03 22:12:37 +00:00
|
|
|
if (strlen(subject) > 7) {
|
|
|
|
fprintf(fp, "%s\r\n", subject);
|
|
|
|
free(subject);
|
|
|
|
}
|
|
|
|
} else {
|
2001-08-17 05:46:24 +00:00
|
|
|
/*
|
2002-08-03 22:12:37 +00:00
|
|
|
* Old style seenby lines
|
2001-08-17 05:46:24 +00:00
|
|
|
*/
|
2002-08-03 22:12:37 +00:00
|
|
|
for (tmp = sbl; tmp; tmp = tmp->next) {
|
|
|
|
fprintf(fp, "Seenby %s\r\n", ascfnode(tmp->addr, 0x0f));
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-08-03 22:12:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now append all passthru ticlines
|
|
|
|
*/
|
|
|
|
if (TIC.TicIn.Unknowns)
|
|
|
|
for (i = 0; i < TIC.TicIn.Unknowns; i++)
|
|
|
|
fprintf(fp, "%s\r\n", TIC.TicIn.Unknown[i]);
|
|
|
|
|
|
|
|
fprintf(fp, "Pw %s\r\n", nodes.Fpasswd);
|
|
|
|
fclose(fp);
|
2004-07-16 11:09:04 +00:00
|
|
|
fprintf(fl, "%c KFS NOR %s\n", flavor, ticfile);
|
2002-08-03 22:12:37 +00:00
|
|
|
} else {
|
|
|
|
WriteError("$Can't create %s", ticfile);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2002-08-03 22:12:37 +00:00
|
|
|
}
|
2002-08-05 20:43:29 +00:00
|
|
|
fsync(fileno(fl));
|
|
|
|
fclose(fl);
|
|
|
|
|
2002-08-03 22:12:37 +00:00
|
|
|
/*
|
|
|
|
* Update the nodes statistic counters
|
|
|
|
*/
|
|
|
|
StatAdd(&nodes.FilesSent, 1L);
|
|
|
|
StatAdd(&nodes.F_KbSent, T_File.SizeKb);
|
|
|
|
UpdateNode();
|
|
|
|
SearchNode(Node);
|
|
|
|
free(ticfile);
|
|
|
|
free(fwdfile);
|
2002-08-05 20:43:29 +00:00
|
|
|
free(queuedir);
|
|
|
|
free(listfile);
|
2002-08-03 22:12:37 +00:00
|
|
|
tidy_faddr(routeto);
|
2005-08-12 14:20:33 +00:00
|
|
|
Syslog('f', "forward done");
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|