diff --git a/ChangeLog b/ChangeLog index 46cd83b8..2e5bac93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4723,6 +4723,7 @@ v0.33.20 10-Feb-2002 of being plain passed. Auto file area create implemented, it can use plain tagfiles or filegate.zxx formatted files. + The mbfido web command now uses macro templates. mbfile: The mbfile index command now creates the html pages using the diff --git a/examples/templates.tar b/examples/templates.tar index 736b70be..c1d221f1 100644 Binary files a/examples/templates.tar and b/examples/templates.tar differ diff --git a/mbfido/Makefile b/mbfido/Makefile index 476efad4..40cf5ec2 100644 --- a/mbfido/Makefile +++ b/mbfido/Makefile @@ -166,7 +166,7 @@ utic.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/co announce.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/msgtext.h ../lib/diesel.h grlist.h msgutil.h announce.h fflist.o: ../lib/libs.h ../lib/clcomm.h ../lib/msg.h fflist.h ftn2rfc.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/dbftn.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/common.h ../lib/clcomm.h rollover.h aliasdb.h postemail.h backalias.h ftn2rfc.h -makestat.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/diesel.h makestat.h +makestat.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/diesel.h mgrutil.h makestat.h mbindex.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/dbftn.h mbindex.h msgutil.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/dbcfg.h ../lib/msg.h ../lib/msgtext.h ../lib/diesel.h msgutil.h postecho.o: ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h ../lib/msgtext.h ../lib/dbcfg.h ../lib/dbnode.h ../lib/dbmsgs.h ../lib/dbdupe.h ../lib/dbuser.h ../lib/dbftn.h ftn2rfc.h postecho.h storeecho.h addpkt.h rollover.h diff --git a/mbfido/makestat.c b/mbfido/makestat.c index 8fb8b42a..290c2253 100644 --- a/mbfido/makestat.c +++ b/mbfido/makestat.c @@ -35,62 +35,56 @@ #include "../lib/common.h" #include "../lib/clcomm.h" #include "../lib/diesel.h" +#include "mgrutil.h" #include "makestat.h" -FILE *newpage(char *, char *); -FILE *newpage(char *Name, char *Title) +FILE *newpage(char *, FILE *); +FILE *newpage(char *Name, FILE *fi) { - char linebuf[1024], outbuf[1024]; - static FILE* fa; - time_t later; + char *temp; + static FILE* fa; + time_t later; - later = time(NULL) + 86400; - sprintf(linebuf, "%s/stat/%s.temp", CFG.www_root, Name); - mkdirs(linebuf, 0755); + later = time(NULL) + 86400; + temp = calloc(PATH_MAX, sizeof(char)); + sprintf(temp, "%s/stat/%s.temp", CFG.www_root, Name); + mkdirs(temp, 0755); - if ((fa = fopen(linebuf, "w")) == NULL) { - WriteError("$Can't create %s", linebuf); - } else { - sprintf(linebuf, "%s", Title); - html_massage(linebuf, outbuf); - fprintf(fa, "\n"); - fprintf(fa, "\n", rfcdate(later)); - fprintf(fa, "\n"); - fprintf(fa, "\n", CFG.www_charset); - fprintf(fa, "\n", CFG.www_author, outbuf); - fprintf(fa, "\n%s\n", outbuf); - fprintf(fa, "\n", CFG.www_url, CFG.www_link2ftp); - fprintf(fa, "\n\n\n\n"); - fprintf(fa, "

%s

\n", Title); - fprintf(fa, "\n"); - return fa; - } - return NULL; + if ((fa = fopen(temp, "w")) == NULL) { + WriteError("$Can't create %s", temp); + } else { + MacroVars("a", "s", rfcdate(later)); + MacroRead(fi, fa); + free(temp); + return fa; + } + + free(temp); + return NULL; } -void closepage(FILE *, char *); -void closepage(FILE *fa, char *Name) +void closepage(FILE *, char *, FILE *); +void closepage(FILE *fa, char *Name, FILE *fi) { - char temp1[81], temp2[81]; + char *temp1, *temp2; - if (fa == NULL) - return; + if (fa == NULL) + return; - fprintf(fa, "

\n"); - fprintf(fa, "

\n"); - fprintf(fa, "Top of page   Statistic index\n"); - fprintf(fa, "
\n\n\n"); - fclose(fa); - sprintf(temp1, "%s/stat/%s.html", CFG.www_root, Name); - sprintf(temp2, "%s/stat/%s.temp", CFG.www_root, Name); - rename(temp2, temp1); - fa = NULL; + temp1 = calloc(PATH_MAX, sizeof(char)); + temp2 = calloc(PATH_MAX, sizeof(char)); + MacroRead(fi, fa); + fclose(fa); + sprintf(temp1, "%s/stat/%s.html", CFG.www_root, Name); + sprintf(temp2, "%s/stat/%s.temp", CFG.www_root, Name); + rename(temp2, temp1); + chmod(temp1, 0644); + fa = NULL; } @@ -115,195 +109,233 @@ char *adate(time_t now) void MakeStat(void) { - FILE *fg, *fw; - char *name, *p; - int i, Total, Lm, Area; - struct _history hist; + FILE *fi, *fg, *fw; + char *name, *p, *q; + int i, Total, Lm, Area; + struct _history hist; + long fileptr = 0; - if (!strlen(CFG.www_root)) - return; + if (!strlen(CFG.www_root)) { + Syslog('!', "Warning, WWW root not defined, skip statistical html creation"); + return; + } - Syslog('+', "Start making statistic HTML pages"); - name = calloc(128, sizeof(char)); - if (Miy == 0) - Lm = 11; - else - Lm = Miy -1; + Syslog('+', "Start making statistic HTML pages"); + name = calloc(128, sizeof(char)); + if (Miy == 0) + Lm = 11; + else + Lm = Miy -1; - sprintf(name, "%s/etc/mgroups.data", getenv("MBSE_ROOT")); - if ((fg = fopen(name, "r")) == NULL) { - WriteError("Can't open %s", name); + sprintf(name, "%s/etc/mgroups.data", getenv("MBSE_ROOT")); + if ((fg = fopen(name, "r")) == NULL) { + WriteError("Can't open %s", name); + } else { + fread(&mgrouphdr, sizeof(mgrouphdr), 1, fg); + + if ((fi = OpenMacro("html.egroups", 'E', TRUE)) == NULL) { + Syslog('+', "Can't open macro file, skipping html pages creation"); } else { - if ((fw = newpage((char *)"mgroups", (char *)"Message groups statistics")) != NULL) { - fprintf(fw, "Message group statisticsReceived lastSent last\n"); - fprintf(fw, "GroupCommentAkaLast dateweekmonthweekmonth\n"); - fread(&mgrouphdr, sizeof(mgrouphdr), 1, fg); - while ((fread(&mgroup, mgrouphdr.recsize, 1, fg)) == 1) { - if (mgroup.Active) { - fprintf(fw, "%s%s%s%s%ld%ld%ld%ld\n", - mgroup.Name, mgroup.Comment, aka2str(mgroup.UseAka), adate(mgroup.LastDate), - mgroup.MsgsRcvd.lweek, mgroup.MsgsRcvd.month[Lm], - mgroup.MsgsSent.lweek, mgroup.MsgsSent.month[Lm]); - } - } - fprintf(fw, "\n"); - closepage(fw, (char *)"mgroups"); - } else { - WriteError("Can't create mgroups.html"); + if ((fw = newpage((char *)"mgroups", fi)) != NULL) { + fileptr = ftell(fi); + while ((fread(&mgroup, mgrouphdr.recsize, 1, fg)) == 1) { + if (mgroup.Active) { + fseek(fi, fileptr, SEEK_SET); + MacroVars("bcdefghi", "ssssdddd", mgroup.Name, mgroup.Comment, aka2str(mgroup.UseAka), + adate(mgroup.LastDate), mgroup.MsgsRcvd.lweek, mgroup.MsgsRcvd.month[Lm], + mgroup.MsgsSent.lweek, mgroup.MsgsSent.month[Lm]); + MacroRead(fi, fw); + } } - fclose(fg); + closepage(fw, (char *)"mgroups", fi); + } else { + WriteError("Can't create mgroups.html"); + } + fclose(fi); + MacroClear(); } + fclose(fg); + } - sprintf(name, "%s/etc/mareas.data", getenv("MBSE_ROOT")); - if ((fg = fopen(name, "r")) == NULL) { - WriteError("$Can't open %s", name); + sprintf(name, "%s/etc/mareas.data", getenv("MBSE_ROOT")); + if ((fg = fopen(name, "r")) == NULL) { + WriteError("$Can't open %s", name); + } else { + if ((fi = OpenMacro("html.mareas", 'E', TRUE)) == NULL) { + Syslog('+', "Can't open macro file, skipping html pages creation"); } else { - if ((fw = newpage((char *)"mareas", (char *)"Message areas statistics")) != NULL) { - fprintf(fw, "Message areas statisticsReceived lastPosts last\n"); - fprintf(fw, "NrAreaTagGroupLast dateweekmonthweekmonth\n"); - fread(&msgshdr, sizeof(msgshdr), 1, fg); - Area = 0; - while ((fread(&msgs, msgshdr.recsize, 1, fg)) == 1) { - Area++; - if (msgs.Active) { - fprintf(fw, "%d%s%s %s %s%ld%ld%ld%ld\n", - Area, msgs.Name, msgs.Tag, msgs.Group, adate(msgs.LastRcvd), - msgs.Received.lweek, msgs.Received.month[Lm], - msgs.Posted.lweek, msgs.Posted.month[Lm]); - } - fseek(fg, msgshdr.syssize, SEEK_CUR); - } - fprintf(fw, "\n"); - closepage(fw, (char *)"mareas"); - } else { - WriteError("Can't create mareas.html"); + if ((fw = newpage((char *)"mareas", fi)) != NULL) { + fileptr = ftell(fi); + fread(&msgshdr, sizeof(msgshdr), 1, fg); + Area = 0; + while ((fread(&msgs, msgshdr.recsize, 1, fg)) == 1) { + Area++; + if (msgs.Active) { + fseek(fi, fileptr, SEEK_SET); + MacroVars("bcdefghij", "dssssdddd", Area, msgs.Name, msgs.Tag, msgs.Group, adate(msgs.LastRcvd), + msgs.Received.lweek, msgs.Received.month[Lm], msgs.Posted.lweek, msgs.Posted.month[Lm]); + MacroRead(fi, fw); + } + fseek(fg, msgshdr.syssize, SEEK_CUR); } - fclose(fg); + closepage(fw, (char *)"mareas", fi); + } else { + WriteError("Can't create mareas.html"); + } + fclose(fi); + MacroClear(); } + fclose(fg); + } - sprintf(name, "%s/etc/fgroups.data", getenv("MBSE_ROOT")); - if ((fg = fopen(name, "r")) == NULL) { - WriteError("$Can't open %s", name); + sprintf(name, "%s/etc/fgroups.data", getenv("MBSE_ROOT")); + if ((fg = fopen(name, "r")) == NULL) { + WriteError("$Can't open %s", name); + } else { + fread(&fgrouphdr, sizeof(fgrouphdr), 1, fg); + if ((fi = OpenMacro("html.fgroups", 'E', TRUE)) == NULL) { + Syslog('+', "Can't open macro file, skipping html pages creation"); } else { - if ((fw = newpage((char *)"fgroups", (char *)"TIC file groups statistics")) != NULL) { - fprintf(fw, "TIC file group statisticsLast weekLast month\n"); - fprintf(fw, "GroupCommentAkaLast datefilesKBytesfilesKBytes\n"); - fread(&fgrouphdr, sizeof(fgrouphdr), 1, fg); - while ((fread(&fgroup, fgrouphdr.recsize, 1, fg)) == 1) { - if (fgroup.Active) { - fprintf(fw, "%s%s%s%s%ld%ld%ld%ld\n", - fgroup.Name, fgroup.Comment, aka2str(fgroup.UseAka), adate(fgroup.LastDate), - fgroup.Files.lweek, fgroup.KBytes.lweek, - fgroup.Files.month[Lm], fgroup.KBytes.month[Lm]); - } - } - fprintf(fw, "\n"); - closepage(fw, (char *)"fgroups"); - } else { - WriteError("Can't create fgroups.html"); + if ((fw = newpage((char *)"fgroups", fi)) != NULL) { + fileptr = ftell(fi); + while ((fread(&fgroup, fgrouphdr.recsize, 1, fg)) == 1) { + if (fgroup.Active) { + fseek(fi, fileptr, SEEK_SET); + MacroVars("bcdefghi", "ssssdddd", fgroup.Name, fgroup.Comment, aka2str(fgroup.UseAka), adate(fgroup.LastDate), + fgroup.Files.lweek, fgroup.KBytes.lweek, fgroup.Files.month[Lm], fgroup.KBytes.month[Lm]); + MacroRead(fi, fw); + } } - fclose(fg); + closepage(fw, (char *)"fgroups", fi); + } else { + WriteError("Can't create fgroups.html"); + } + fclose(fi); + MacroClear(); } + fclose(fg); + } - sprintf(name, "%s/etc/tic.data", getenv("MBSE_ROOT")); - if ((fg = fopen(name, "r")) == NULL) { - WriteError("$Can't open %s", name); + sprintf(name, "%s/etc/tic.data", getenv("MBSE_ROOT")); + if ((fg = fopen(name, "r")) == NULL) { + WriteError("$Can't open %s", name); + } else { + fread(&tichdr, sizeof(tichdr), 1, fg); + if ((fi = OpenMacro("html.tic", 'E', TRUE)) == NULL) { + Syslog('+', "Can't open macro file, skipping html pages creation"); } else { - if ((fw = newpage((char *)"tic", (char *)"TIC file areas statistics")) != NULL) { - fprintf(fw, "TIC file areas statisticsLast weekLast month\n"); - fprintf(fw, "AreaTagGroupLast datefilesKBytesfilesKBytes\n"); - fread(&tichdr, sizeof(tichdr), 1, fg); - while ((fread(&tic, tichdr.recsize, 1, fg)) == 1) { - if (tic.Active) { - fprintf(fw, "%s%s %s %s%ld%ld%ld%ld\n", - tic.Comment, tic.Name, tic.Group, adate(tic.LastAction), - tic.Files.lweek, tic.KBytes.lweek, - tic.Files.month[Lm], tic.KBytes.month[Lm]); - } - fseek(fg, tichdr.syssize, SEEK_CUR); - } - fprintf(fw, "\n"); - closepage(fw, (char *)"tic"); - } else { - WriteError("Can't create tic.html"); + if ((fw = newpage((char *)"tic", fi)) != NULL) { + fileptr = ftell(fi); + while ((fread(&tic, tichdr.recsize, 1, fg)) == 1) { + if (tic.Active) { + fseek(fi, fileptr, SEEK_SET); + MacroVars("bcdefghi", "ssssdddd", tic.Comment, tic.Name, tic.Group, adate(tic.LastAction), + tic.Files.lweek, tic.KBytes.lweek, tic.Files.month[Lm], tic.KBytes.month[Lm]); + MacroRead(fi, fw); + } + fseek(fg, tichdr.syssize, SEEK_CUR); } - fclose(fg); + closepage(fw, (char *)"tic", fi); + } else { + WriteError("Can't create tic.html"); + } + fclose(fi); + MacroClear(); } + fclose(fg); + } - sprintf(name, "%s/etc/nodes.data", getenv("MBSE_ROOT")); - if ((fg = fopen(name, "r")) == NULL) { - WriteError("$Can't open %s", name); - } else { - if ((fw = newpage((char *)"nodes", (char *)"Nodes statistics")) != NULL) { - fprintf(fw, "Nodes statistics\n"); - fprintf(fw, "NodeSysopStatusStart DateLast dateCreditDebet\n"); - fread(&nodeshdr, sizeof(nodeshdr), 1, fg); - while ((fread(&nodes, nodeshdr.recsize, 1, fg)) == 1) { - fseek(fg, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR); - p = xstrcpy(adate(nodes.StartDate)); - fprintf(fw, "%s%s%s %s%s%s%ld%ld\n", - aka2str(nodes.Aka[0]), nodes.Sysop, nodes.Crash?"Crash":"", nodes.Hold?"Hold":"", - p, adate(nodes.LastDate), nodes.Credit, nodes.Debet); - free(p); - } - fprintf(fw, "\n"); - closepage(fw, (char *)"nodes"); - } else { - WriteError("Can't create nodes.html"); - } - fclose(fg); - } - - sprintf(name, "%s/var/mailer.hist", getenv("MBSE_ROOT")); - if ((fg = fopen(name, "r")) == NULL) { - WriteError("$Can't open %s", name); + sprintf(name, "%s/etc/nodes.data", getenv("MBSE_ROOT")); + if ((fg = fopen(name, "r")) == NULL) { + WriteError("$Can't open %s", name); + } else { + fread(&nodeshdr, sizeof(nodeshdr), 1, fg); + if ((fi = OpenMacro("html.nodes", 'E', TRUE)) == NULL) { + Syslog('+', "Can't open macro file, skipping html pages creation"); } else { - if ((fw = newpage((char *)"mailhistory", (char *)"Mailer history")) != NULL) { - fseek(fg, 0, SEEK_END); - Total = (ftell(fg) / sizeof(hist)) -1; - fseek(fg, 0, SEEK_SET); - fread(&hist, sizeof(hist), 1, fg); - fprintf(fw, "Mailer history since %s\n", adate(hist.online)); - fprintf(fw, "AkaSystemLocationTimeElapsedSentReceivedMode\n"); + if ((fw = newpage((char *)"nodes", fi)) != NULL) { + fileptr = ftell(fi); + while ((fread(&nodes, nodeshdr.recsize, 1, fg)) == 1) { + fseek(fg, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR); + p = xstrcpy(adate(nodes.StartDate)); + fseek(fi, fileptr, SEEK_SET); + if (nodes.Crash) + q = xstrcpy((char *)"Crash"); + else if (nodes.Hold) + q = xstrcpy((char *)"Hold"); + else + q = xstrcpy((char *)"Normal"); + MacroVars("bcdefgh", "sssssdd", aka2str(nodes.Aka[0]), nodes.Sysop, q, p, + adate(nodes.LastDate), nodes.Credit, nodes.Debet); + MacroRead(fi, fw); + free(p); + free(q); + } + closepage(fw, (char *)"nodes", fi); + } else { + WriteError("Can't create nodes.html"); + } + fclose(fi); + MacroClear(); + } + fclose(fg); + } - for (i = Total; i > 0; i--) { - fseek(fg, i * sizeof(hist), SEEK_SET); - fread(&hist, sizeof(hist), 1, fg); - fprintf(fw, "%s%s%s%s%s%lu%lu%s", - aka2str(hist.aka), hist.system_name, hist.location, + sprintf(name, "%s/var/mailer.hist", getenv("MBSE_ROOT")); + if ((fg = fopen(name, "r")) == NULL) { + WriteError("$Can't open %s", name); + } else { + if ((fi = OpenMacro("html.mailer", 'E', TRUE)) == NULL) { + Syslog('+', "Can't open macro file, skipping html pages creation"); + } else { + fseek(fg, 0, SEEK_END); + Total = (ftell(fg) / sizeof(hist)) -1; + fseek(fg, 0, SEEK_SET); + fread(&hist, sizeof(hist), 1, fg); + MacroVars("b", "s", adate(hist.online)); + if ((fw = newpage((char *)"mailhistory", fi)) != NULL) { + fileptr = ftell(fi); + for (i = Total; i > 0; i--) { + fseek(fg, i * sizeof(hist), SEEK_SET); + fread(&hist, sizeof(hist), 1, fg); + fseek(fi, fileptr, SEEK_SET); + MacroVars("cdefghij", "sssssdds", aka2str(hist.aka), hist.system_name, hist.location, adate(hist.online), t_elapsed(hist.online, hist.offline), hist.sent_bytes, hist.rcvd_bytes, hist.inbound ? "In":"Out"); - } - - fprintf(fw, "\n"); - closepage(fw, (char *)"mailhistory"); - } else { - WriteError("Can't create tic.html"); + MacroRead(fi, fw); } - fclose(fg); + closepage(fw, (char *)"mailhistory", fi); + } else { + WriteError("Can't create tic.html"); + } + fclose(fi); + MacroClear(); } + fclose(fg); + } - sprintf(name, "%s/etc/sysinfo.data", getenv("MBSE_ROOT")); - if ((fg = fopen(name, "r")) != NULL ) { - fread(&SYSINFO, sizeof(SYSINFO), 1, fg); - if ((fw = newpage((char *)"sysinfo", (char *)"BBS system information")) != NULL) { - fprintf(fw, "BBS system info\n"); - fprintf(fw, "Total calls%lu\n", SYSINFO.SystemCalls); - fprintf(fw, "Pots calls%lu\n", SYSINFO.Pots); - fprintf(fw, "ISDN calls%lu\n", SYSINFO.ISDN); - fprintf(fw, "Network calls%lu\n", SYSINFO.Network); - fprintf(fw, "Local calls%lu\n", SYSINFO.Local); - fprintf(fw, "Start date%s\n", adate(SYSINFO.StartDate)); - fprintf(fw, "Last caller%s\n", SYSINFO.LastCaller); - fprintf(fw, "\n"); - closepage(fw, (char *)"sysinfo"); - } - fclose(fg); + sprintf(name, "%s/etc/sysinfo.data", getenv("MBSE_ROOT")); + if ((fg = fopen(name, "r")) != NULL ) { + if ((fi = OpenMacro("html.sysinfo", 'E', TRUE)) == NULL) { + Syslog('+', "Can't open macro file, skipping html pages creation"); + } else { + fread(&SYSINFO, sizeof(SYSINFO), 1, fg); + MacroVars("bcdefgh", "dddddss", SYSINFO.SystemCalls, SYSINFO.Pots, SYSINFO.ISDN, SYSINFO.Network, + SYSINFO.Local, adate(SYSINFO.StartDate), SYSINFO.LastCaller); + if ((fw = newpage((char *)"sysinfo", fi)) != NULL) { + closepage(fw, (char *)"sysinfo", fi); + } else { + WriteError("Can't create sysinfo.html"); + } + fclose(fi); + MacroClear(); } + fclose(fg); + } - free(name); - Syslog('+', "Finished making statistic HTML pages"); + free(name); + Syslog('+', "Finished making statistic HTML pages"); }