Created new mbutils source directory

This commit is contained in:
Michiel Broek
2004-11-05 20:41:08 +00:00
parent c22e9948e1
commit f32015b7cf
15 changed files with 106 additions and 46 deletions

1
mbutils/.cvsignore Normal file
View File

@@ -0,0 +1 @@
filelist mball mbchat mblang mbstat mbtoberep mbuser

92
mbutils/Makefile Normal file
View File

@@ -0,0 +1,92 @@
# Makefile for MBSE BBS under Linux
# Copyright (c) 1998, 2004 by M. Broek.
# $Id$
include ../Makefile.global
SRCS = mball.c mblang.c mbstat.c mbtoberep.c mbuser.c
HDRS = mball.h mbstat.h mbuser.h
MBALL_OBJS = mball.o
MBALL_LIBS = ../lib/libmbse.a ../lib/libdbase.a
MBLANG_OBJS = mblang.o
MBLANG_LIBS = ../lib/libmbse.a ../lib/libdbase.a
MBSTAT_OBJS = mbstat.o
MBSTAT_LIBS = ../lib/libmbse.a ../lib/libdbase.a
MBTOBE_OBJS = mbtoberep.o
MBTOBE_LIBS = ../lib/libmbse.a ../lib/libdbase.a
MBUSER_OBJS = mbuser.o
MBUSER_LIBS = ../lib/libmbse.a ../lib/libdbase.a
OTHER = Makefile
TARGET = mball mblang mbstat mbtoberep mbuser
#############################################################################################################
.c.o:
${CC} ${CFLAGS} ${INCLUDES} ${DEFINES} -c $<
all: ${TARGET}
clean:
rm -f ${TARGET} *.o *.h~ *.c~ core filelist Makefile.bak
mball: ${MBALL_OBJS} ${MBALL_LIBS}
${CC} -o mball ${MBALL_OBJS} ${LDFLAGS} ${LIBS} ${MBALL_LIBS}
mblang: ${MBLANG_OBJS} ${MBLANG_LIBS}
${CC} -o mblang ${MBLANG_OBJS} ${LDFLAGS} ${LIBS} ${MBLANG_LIBS}
mbstat: ${MBSTAT_OBJS} ${MBSTAT_LIBS}
${CC} -o mbstat ${MBSTAT_OBJS} ${LDFLAGS} ${LIBS} ${MBSTAT_LIBS}
mbtoberep: ${MBTOBE_OBJS} ${MBTOBE_LIBS}
${CC} -o mbtoberep ${MBTOBE_OBJS} ${LDFLAGS} ${LIBS} ${MBTOBE_LIBS}
mbuser: ${MBUSER_OBJS} ${MBUSER_LIBS}
${CC} -o mbuser ${MBUSER_OBJS} ${LDFLAGS} ${LIBS} ${MBUSER_LIBS}
install: all
@if [ "`id -un`" != "root" ] ; then \
echo; echo " Must be root to install!"; echo; exit 3; \
fi
${INSTALL} -c -s -o ${OWNER} -g ${GROUP} -m 0700 mball ${BINDIR}
${INSTALL} -c -s -o ${OWNER} -g ${GROUP} -m 0700 mblang ${BINDIR}
${INSTALL} -c -s -o ${OWNER} -g ${GROUP} -m 0750 mbstat ${BINDIR}
${INSTALL} -c -s -o ${OWNER} -g ${GROUP} -m 0700 mbtoberep ${BINDIR}
${INSTALL} -c -s -o ${ROWNER} -g ${RGROUP} -m 6711 mbuser ${BINDIR}
@rm -f mbchat
filelist: Makefile
BASE=`pwd`; \
BASE=`basename $${BASE}`; \
(for f in ${SRCS} ${HDRS} ${OTHER} ; do echo ${PACKAGE}-${VERSION}/$${BASE}/$$f; done) >filelist
depend:
@rm -f Makefile.bak; \
mv Makefile Makefile.bak; \
sed -e '/^# DO NOT DELETE/,$$d' Makefile.bak >Makefile; \
${ECHO} '# DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT' \
>>Makefile; \
${ECHO} '# Dependencies generated by make depend' >>Makefile; \
for f in ${SRCS}; \
do \
${ECHO} "Dependencies for $$f:\c"; \
${ECHO} "`basename $$f .c`.o:\c" >>Makefile; \
for h in `sed -n -e \
's/^#[ ]*include[ ]*"\([^"]*\)".*/\1/p' $$f`; \
do \
${ECHO} " $$h\c"; \
${ECHO} " $$h\c" >>Makefile; \
done; \
${ECHO} " done."; \
${ECHO} "" >>Makefile; \
done; \
${ECHO} '# End of generated dependencies' >>Makefile
# DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT
# Dependencies generated by make depend
mball.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbsedb.h mball.h
mblang.o: ../config.h ../lib/mbselib.h
mbstat.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbstat.h
mbtoberep.o: ../config.h ../lib/mbselib.h
mbuser.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbuser.h
# End of generated dependencies

512
mbutils/mball.c Normal file
View File

@@ -0,0 +1,512 @@
/*****************************************************************************
*
* $Id$
* Purpose ...............: Creates allfiles listings
*
*****************************************************************************
* Copyright (C) 1997-2004
*
* 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
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*****************************************************************************/
#include "../config.h"
#include "../lib/mbselib.h"
#include "../lib/mbse.h"
#include "../lib/users.h"
#include "../lib/mbsedb.h"
#include "mball.h"
extern int do_quiet; /* Suppress screen output */
int do_zip = FALSE; /* Create ZIP archives */
int do_list = FALSE; /* Create filelist */
extern int e_pid; /* Pid of child */
extern int show_log; /* Show logging */
time_t t_start; /* Start time */
time_t t_end; /* End time */
struct tm *l_date; /* Structure for Date */
void ProgName()
{
if (do_quiet)
return;
mbse_colour(15, 0);
printf("\nMBALL: MBSE BBS %s Allfiles Listing Creator\n", VERSION);
mbse_colour(14, 0);
printf(" %s\n", COPYRIGHT);
}
void die(int onsig)
{
/*
* First check if a child is running, if so, kill it.
*/
if (e_pid) {
if ((kill(e_pid, SIGTERM)) == 0)
Syslog('+', "SIGTERM to pid %d succeeded", e_pid);
else {
if ((kill(e_pid, SIGKILL)) == 0)
Syslog('+', "SIGKILL to pid %d succeded", e_pid);
else
WriteError("$Failed to kill pid %d", e_pid);
}
/*
* In case the child had the tty in raw mode...
*/
execute_pth((char *)"stty", (char *)"sane", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
}
signal(onsig, SIG_IGN);
if (onsig) {
if (onsig <= NSIG)
WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
else
WriteError("Terminated with error %d", onsig);
}
ulockprogram((char *)"mball");
t_end = time(NULL);
Syslog(' ', "MBALL finished in %s", t_elapsed(t_start, t_end));
if (!do_quiet) {
mbse_colour(7, 0);
printf("\n");
}
ExitClient(onsig);
}
void Help()
{
do_quiet = FALSE;
ProgName();
mbse_colour(11, 0);
printf("\nUsage: mball [command] <options>\n\n");
mbse_colour(9, 0);
printf(" Commands are:\n\n");
mbse_colour(3, 0);
printf(" l list Create allfiles and newfiles lists\n");
mbse_colour(9, 0);
printf("\n Options are:\n\n");
mbse_colour(3, 0);
printf(" -q -quiet Quiet mode\n");
printf(" -z -zip Create .zip archives\n");
mbse_colour(7, 0);
printf("\n");
die(MBERR_COMMANDLINE);
}
int main(int argc, char **argv)
{
int i;
char *cmd;
struct passwd *pw;
InitConfig();
mbse_TermInit(1, 80, 24);
t_start = time(NULL);
umask(000);
/*
* Catch all signals we can, and ignore the rest.
*/
for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
signal(i, (void (*))die);
else if (i == SIGCHLD)
signal(i, SIG_DFL);
else if ((i != SIGKILL) && (i != SIGSTOP))
signal(i, SIG_IGN);
}
if (argc < 2)
Help();
cmd = xstrcpy((char *)"Command line: mball");
for (i = 1; i < argc; i++) {
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
if (!strncasecmp(argv[i], "l", 1))
do_list = TRUE;
if (!strncasecmp(argv[i], "-q", 2))
do_quiet = TRUE;
if (!strncasecmp(argv[i], "-z", 2))
do_zip = TRUE;
}
if (!do_list)
Help();
ProgName();
pw = getpwuid(getuid());
InitClient(pw->pw_name, (char *)"mball", CFG.location, CFG.logfile,
CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
Syslog(' ', " ");
Syslog(' ', "MBALL v%s", VERSION);
Syslog(' ', cmd);
free(cmd);
if (!do_quiet) {
mbse_colour(3, 0);
printf("\n");
}
if (lockprogram((char *)"mball")) {
if (!do_quiet)
printf("Can't lock mball, abort.\n");
die(MBERR_NO_PROGLOCK);
}
if (do_list) {
Masterlist();
if (do_zip)
MakeArc();
CreateSema((char *)"mailin");
}
if (!do_quiet)
printf("Done!\n");
die(MBERR_OK);
return 0;
}
void MidLine(char *txt, FILE *fp, int doit)
{
char temp[81];
int x, y, z;
if (!doit)
return;
z = strlen(txt);
x = 77 - z;
x /= 2;
strcpy(temp, "");
for (y = 0; y < x; y++)
strcat(temp, " ");
strcat(temp, txt);
z = strlen(temp);
x = 77 - z;
for (y = 0; y < x; y++)
strcat(temp, " ");
fprintf(fp, "%c", 179);
fprintf(fp, "%s", temp);
fprintf(fp, "%c\r\n", 179);
}
void TopBox(FILE *fp, int doit)
{
int y;
if (!doit)
return;
fprintf(fp, "\r\n%c", 213);
for(y = 0; y < 77; y++)
fprintf(fp, "%c", 205);
fprintf(fp, "%c\r\n", 184);
}
void BotBox(FILE *fp, int doit)
{
int y;
if (!doit)
return;
fprintf(fp, "%c", 212);
for (y = 0; y < 77; y++)
fprintf(fp, "%c", 205);
fprintf(fp, "%c\r\n\r\n", 190);
}
void Masterlist()
{
FILE *fp, *np, *pAreas, *pHeader;
int AreaNr = 0, z, x = 0, New;
unsigned long AllFiles = 0, AllKBytes = 0, NewFiles = 0, NewKBytes = 0;
unsigned long AllAreaFiles, AllAreaBytes, popdown, down;
unsigned long NewAreaFiles, NewAreaBytes;
char *sAreas;
char temp[81], pop[81];
struct _fdbarea *fdb_area = NULL;
sAreas = calloc(PATH_MAX, sizeof(char));
IsDoing("Create Allfiles list");
sprintf(sAreas, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
if(( pAreas = fopen (sAreas, "r")) == NULL) {
WriteError("Can't open File Areas File: %s", sAreas);
mbse_colour(7,0);
die(MBERR_GENERAL);
}
fread(&areahdr, sizeof(areahdr), 1, pAreas);
if (!do_quiet)
printf("Processing file areas\n");
if ((fp = fopen("allfiles.tmp", "a+")) == NULL) {
WriteError("$Can't open allfiles.tmp");
die(MBERR_GENERAL);
}
if ((np = fopen("newfiles.tmp", "a+")) == NULL) {
WriteError("$Can't open newfiles.tmp");
fclose(fp);
die(MBERR_GENERAL);
}
TopBox(fp, TRUE);
TopBox(np, TRUE);
sprintf(temp, "All available files at %s", CFG.bbs_name);
MidLine(temp, fp, TRUE);
sprintf(temp, "New available files since %d days at %s", CFG.newdays, CFG.bbs_name);
MidLine(temp, np, TRUE);
BotBox(fp, TRUE);
BotBox(np, TRUE);
sprintf(temp, "%s/etc/header.txt", getenv("MBSE_ROOT"));
if (( pHeader = fopen(temp, "r")) != NULL) {
Syslog('+', "Inserting %s", temp);
while( fgets(temp, 80 ,pHeader) != NULL) {
Striplf(temp);
fprintf(fp, "%s\r\n", temp);
fprintf(np, "%s\r\n", temp);
}
fclose(pHeader);
}
while (fread(&area, areahdr.recsize, 1, pAreas) == 1) {
AreaNr++;
AllAreaFiles = 0;
AllAreaBytes = 0;
NewAreaFiles = 0;
NewAreaBytes = 0;
if (area.Available && (area.LTSec.level <= CFG.security.level)) {
Nopper();
if ((fdb_area = mbsedb_OpenFDB(AreaNr, 30)) == 0) {
WriteError("$Can't open Area %d (%s)! Skipping ...", AreaNr, area.Name);
} else {
popdown = 0;
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
if (!fdb.Deleted) {
/*
* The next is to reduce system load.
*/
x++;
if (CFG.slow_util && do_quiet && ((x % 3) == 0))
msleep(1);
AllFiles++;
AllAreaFiles++;
AllAreaBytes += fdb.Size;
down = fdb.TimesDL;
if (down > popdown) {
popdown = down;
sprintf(pop, "%s", fdb.Name);
}
if (((t_start - fdb.UploadDate) / 84400) <= CFG.newdays) {
NewFiles++;
NewAreaFiles++;
NewAreaBytes += fdb.Size;
}
}
}
AllKBytes += AllAreaBytes / 1024;
NewKBytes += NewAreaBytes / 1024;
/*
* If there are files to report do it.
*/
if (AllAreaFiles) {
TopBox(fp, TRUE);
TopBox(np, NewAreaFiles);
sprintf(temp, "Area %d - %s", AreaNr, area.Name);
MidLine(temp, fp, TRUE);
MidLine(temp, np, NewAreaFiles);
sprintf(temp, "File Requests allowed");
MidLine(temp, fp, area.FileReq);
MidLine(temp, np, area.FileReq && NewAreaFiles);
sprintf(temp, "%ld KBytes in %ld files", AllAreaBytes / 1024, AllAreaFiles);
MidLine(temp, fp, TRUE);
sprintf(temp, "%ld KBytes in %ld files", NewAreaBytes / 1024, NewAreaFiles);
MidLine(temp, np, NewAreaFiles);
if (popdown) {
sprintf(temp, "Most popular file is %s", pop);
MidLine(temp, fp, TRUE);
}
BotBox(fp, TRUE);
BotBox(np, NewAreaFiles);
fseek(fdb_area->fp, fdbhdr.hdrsize, SEEK_SET);
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
if (!fdb.Deleted) {
New = (((t_start - fdb.UploadDate) / 84400) <= CFG.newdays);
sprintf(temp, "%-12s%10lu K %s [%04ld] Uploader: %s",
fdb.Name, (long)(fdb.Size / 1024), StrDateDMY(fdb.UploadDate), fdb.TimesDL,
strlen(fdb.Uploader)?fdb.Uploader:"");
fprintf(fp, "%s\r\n", temp);
if (New)
fprintf(np, "%s\r\n", temp);
for (z = 0; z < 25; z++) {
if (strlen(fdb.Desc[z])) {
if ((fdb.Desc[z][0] == '@') && (fdb.Desc[z][1] == 'X')) {
fprintf(fp, " %s\r\n",fdb.Desc[z]+4);
if (New)
fprintf(np, " %s\r\n",fdb.Desc[z]+4);
} else {
fprintf(fp, " %s\r\n",fdb.Desc[z]);
if (New)
fprintf(np, " %s\r\n",fdb.Desc[z]);
}
}
}
if (strlen(fdb.Magic)) {
fprintf(fp, " Magic filerequest: %s\r\n", fdb.Magic);
if (New)
fprintf(np, " Magic filerequest: %s\r\n", fdb.Magic);
}
}
}
}
mbsedb_CloseFDB(fdb_area);
}
}
} /* End of While Loop Checking for Areas Done */
fclose(pAreas);
TopBox(fp, TRUE);
TopBox(np, TRUE);
sprintf(temp, "Total %ld files, %ld KBytes", AllFiles, AllKBytes);
MidLine(temp, fp, TRUE);
sprintf(temp, "Total %ld files, %ld KBytes", NewFiles, NewKBytes);
MidLine(temp, np, TRUE);
MidLine((char *)"", fp, TRUE);
MidLine((char *)"", np, TRUE);
sprintf(temp, "Created by MBSE BBS v%s (%s-%s) at %s", VERSION, OsName(), OsCPU(), StrDateDMY(t_start));
MidLine(temp, fp, TRUE);
MidLine(temp, np, TRUE);
BotBox(fp, TRUE);
BotBox(np, TRUE);
sprintf(temp, "%s/etc/footer.txt", getenv("MBSE_ROOT"));
if(( pHeader = fopen(temp, "r")) != NULL) {
Syslog('+', "Inserting %s", temp);
while( fgets(temp, 80 ,pHeader) != NULL) {
Striplf(temp);
fprintf(fp, "%s\r\n", temp);
fprintf(np, "%s\r\n", temp);
}
fclose(pHeader);
}
fclose(fp);
fclose(np);
if ((rename("allfiles.tmp", "allfiles.txt")) == 0)
unlink("allfiles.tmp");
if ((rename("newfiles.tmp", "newfiles.txt")) == 0)
unlink("newfiles.tmp");
Syslog('+', "Allfiles: %ld, %ld MBytes", AllFiles, AllKBytes / 1024);
Syslog('+', "Newfiles: %ld, %ld MBytes", NewFiles, NewKBytes / 1024);
free(sAreas);
}
void MakeArc()
{
char *cmd;
if (!getarchiver((char *)"ZIP")) {
WriteError("ZIP Archiver not available");
return;
}
cmd = xstrcpy(archiver.farc);
if (cmd == NULL) {
WriteError("ZIP archive command not available");
return;
}
Nopper();
if (!do_quiet)
printf("Creating allfiles.zip\n");
if (!execute_str(cmd, (char *)"allfiles.zip allfiles.txt", (char *)NULL, (char *)"/dev/null",
(char *)"/dev/null", (char *)"/dev/null") == 0)
WriteError("Create allfiles.zip failed");
Nopper();
if (!do_quiet)
printf("Creating newfiles.zip\n");
if (!execute_str(cmd, (char *)"newfiles.zip newfiles.txt", (char *)NULL, (char *)"/dev/null",
(char *)"/dev/null", (char *)"/dev/null") == 0)
WriteError("Create newfiles.zip failed");
free(cmd);
cmd = NULL;
}

17
mbutils/mball.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef _MBALL_H
#define _MBALL_H
void ProgName(void);
void die(int);
void Help(void);
void MakeIndex(void);
void MidLine(char *, FILE *, int);
void TopBox(FILE *, int);
void BotBox(FILE *, int);
void Masterlist(void);
void MakeArc(void);
#endif

113
mbutils/mblang.c Normal file
View File

@@ -0,0 +1,113 @@
/*****************************************************************************
*
* $Id$
* Purpose ...............: Language Compiler
*
*****************************************************************************
* Copyright (C) 1997-2004
*
* 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
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*****************************************************************************/
#include "../config.h"
#include "../lib/mbselib.h"
int main(int argc, char **argv)
{
FILE *fp, *fp1;
int i, j, lines;
char *temp, *temp1;
temp = calloc(PATH_MAX, sizeof(char));
temp1 = calloc(PATH_MAX, sizeof(char));
printf("\nMBLANG: MBSE BBS %s Quick Language Data File Creator\n", VERSION);
printf(" %s\n", COPYRIGHT);
if (argc < 3) {
printf("\nUsage: %s [language data file] [language text file]\n\n", *(argv));
exit(MBERR_COMMANDLINE);
}
sprintf(temp1, "%s", *(argv + 1));
unlink(temp1);
sprintf(temp, "%s", *(argv + 2));
if ((fp1 = fopen(temp, "r")) == NULL) {
printf("\nUnable to open %s\n", temp);
exit(MBERR_COMMANDLINE);
}
sprintf(temp1, "%s", *(argv + 1));
if ((fp = fopen(temp1, "a+")) == NULL) {
printf("\nUnable to open %s\n", temp1);
exit(MBERR_COMMANDLINE);
}
lines = 0;
while (fgets(temp, 115, fp1) != NULL) {
memset(&ldata, 0, sizeof(ldata));
/*
* Take the response keys part
*/
for(i = 0; i < strlen(temp); i++) {
if(temp[i] == '|')
break;
ldata.sKey[i] = temp[i];
}
if (i > 29) {
printf("\nKey part in line %d too long (%d chars)", lines, i);
exit(MBERR_GENERAL);
}
/*
* Take the prompt string part
*/
j = 0;
for (i = i+1; i < strlen(temp); i++) {
if (temp[i] == '\n')
break;
ldata.sString[j] = temp[i];
j++;
}
if (j > 84) {
printf("\nLanguage string in line %d too long (%d chars)", lines, j);
exit(MBERR_GENERAL);
}
fwrite(&ldata, sizeof(ldata), 1, fp);
lines++;
}
fclose(fp);
fclose(fp1);
free(temp);
free(temp1);
printf("\nCompiled %d language lines\n", lines);
return 0;
}

274
mbutils/mbstat.c Normal file
View File

@@ -0,0 +1,274 @@
/*****************************************************************************
*
* $Id$
* Purpose ...............: Change BBS status
*
*****************************************************************************
* Copyright (C) 1997-2004
*
* 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
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*****************************************************************************/
#include "../config.h"
#include "../lib/mbselib.h"
#include "../lib/users.h"
#include "../lib/mbsedb.h"
#include "mbstat.h"
extern int do_quiet;
time_t t_start, t_end;
void Help(void)
{
do_quiet = FALSE;
ProgName();
mbse_colour(11, 0);
printf("\nUsage: mbstat [command] <options>\n\n");
mbse_colour(9, 0);
printf(" Commands are:\n\n");
mbse_colour(3, 0);
printf(" c close Close the BBS for users\n");
printf(" o open Open the BBS for users\n");
printf(" s set semafore Set named semafore\n");
printf(" w wait Wait until the BBS is free\n\n");
mbse_colour(9,0);
printf(" Options are:\n\n");
mbse_colour(3, 0);
printf(" -q -quiet Quiet, no screen output\n");
mbse_colour(7, 0);
die(MBERR_COMMANDLINE);
}
void ProgName(void)
{
if (do_quiet)
return;
mbse_colour(15, 0);
printf("\nMBSTAT: MBSE BBS %s Status Changer\n", VERSION);
mbse_colour(14, 0);
printf(" %s\n", COPYRIGHT);
mbse_colour(3, 0);
}
void die(int onsig)
{
signal(onsig, SIG_IGN);
if (onsig)
WriteError("Terminated on signal %d", onsig);
if (!do_quiet) {
mbse_colour(7, 0);
printf("\n");
}
t_end = time(NULL);
Syslog(' ', "MBSTAT finished in %s", t_elapsed(t_start, t_end));
ExitClient(onsig);
}
int main(int argc, char **argv)
{
int i;
char *cmd, *semafore = NULL;
int do_open = FALSE;
int do_close = FALSE;
int do_wait = FALSE;
int do_sema = FALSE;
struct passwd *pw;
InitConfig();
mbse_TermInit(1, 80, 24);
t_start = time(NULL);
/*
* Catch or ignore signals
*/
for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
signal(i, (void (*))die);
else if ((i != SIGKILL) && (i != SIGSTOP))
signal(i, SIG_IGN);
}
cmd = xstrcpy((char *)"Command line: mbstat");
for (i = 1; i < argc; i++) {
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, tl(argv[i]));
if (!strncmp(tl(argv[i]), "w", 1))
do_wait = TRUE;
if (!strncmp(tl(argv[i]), "o", 1))
do_open = TRUE;
if (!strncmp(tl(argv[i]), "c", 1))
do_close = TRUE;
if (!strncmp(tl(argv[i]), "s", 1)) {
do_sema = TRUE;
i++;
semafore = xstrcpy(tl(argv[i]));
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, tl(argv[i]));
}
if (!strncmp(tl(argv[i]), "-q", 2))
do_quiet = TRUE;
}
ProgName();
pw = getpwuid(getuid());
InitClient(pw->pw_name, (char *)"mbstat", CFG.location, CFG.logfile,
CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
Syslog(' ', " ");
Syslog(' ', "MBSTAT v%s", VERSION);
Syslog(' ', cmd);
free(cmd);
if (!do_quiet) {
mbse_colour(3, 0);
printf("\n");
}
if (do_close)
do_open = FALSE;
if (do_open) {
Open();
do_close = FALSE;
do_wait = FALSE;
}
if (do_close)
Close();
if (do_wait)
Wait();
if (do_sema)
Semafore(semafore);
if (!(do_open || do_close || do_wait || do_sema))
Help();
die(MBERR_OK);
return 0;
}
int Semafore(char *semafore)
{
char buf[81];
strcpy(buf, SockR("SECR:1,%s;", semafore));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "Semafore \"%s\" is set", semafore);
if (!do_quiet)
printf("Semafore \"%s\" is set\n", semafore);
return TRUE;
} else {
Syslog('+', "Failed to set \"%s\" semafore", semafore);
printf("Failed to set \"%s\" semafore\n", semafore);
return FALSE;
}
}
int Close(void)
{
char buf[81];
strcpy(buf, SockR("SCLO:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "The BBS is closed");
if (!do_quiet)
printf("The BBS is closed\n");
return TRUE;
} else {
printf("Failed to close the BBS\n");
return FALSE;
}
}
int Open(void)
{
char buf[81];
strcpy(buf, SockR("SOPE:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "The BBS is open");
if (!do_quiet)
printf("The BBS is open\n");
return TRUE;
} else {
printf("Failed to open the BBS\n");
return FALSE;
}
}
int Wait(void)
{
int Waiting = 3600;
char buf[PATH_MAX];
if (IsSema((char *)"upsdown"))
Waiting = 30;
Syslog('+', "Waiting for the BBS to become free, timeout %d seconds", Waiting);
while (Waiting) {
strcpy(buf, SockR("SFRE:0;"));
if (strncmp(buf, "100:0;", 6) == 0) {
Syslog('+', "The BBS is free");
if (!do_quiet)
printf("The BBS is free. \n");
return TRUE;
}
if (!do_quiet) {
buf[strlen(buf) -1] = '\0';
printf("\r%s\r", buf+6);
fflush(stdout);
}
sleep(1);
Waiting--;
}
WriteError("Wait for BBS free timeout, aborting");
return FALSE;
}

14
mbutils/mbstat.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef _MBSTAT_H
#define _MBSTAT_H
void Help(void);
void ProgName(void);
void die(int);
int Semafore(char *);
int Open(void);
int Close(void);
int Wait(void);
#endif

90
mbutils/mbtoberep.c Normal file
View File

@@ -0,0 +1,90 @@
/*****************************************************************************
*
* $Id$
* Purpose ...............: Show contents of toberep.data
*
*****************************************************************************
* Copyright (C) 1997-2004
*
* 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
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*****************************************************************************/
#include "../config.h"
#include "../lib/mbselib.h"
int main(int argc, char **argv)
{
char *BBSpath;
char *temp;
FILE *fp;
struct _filerecord rep;
int i;
if ((BBSpath = getenv("MBSE_ROOT")) == NULL) {
printf("MBSE_ROOT variable not set\n");
exit(MBERR_INIT_ERROR);
}
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/etc/toberep.data", BBSpath);
if ((fp = fopen(temp, "r")) == NULL) {
printf("File %s not found\n", temp);
free(temp);
exit(MBERR_INIT_ERROR);
}
while (fread(&rep, sizeof(rep), 1, fp) == 1) {
printf("File echo %s\n", rep.Echo);
printf("Comment %s\n", rep.Comment);
printf("Group %s\n", rep.Group);
printf("Short name %s\n", rep.Name);
printf("Long name %s\n", rep.LName);
printf("File size %lu\n", (long)(rep.Size));
printf("File size Kb %lu\n", rep.SizeKb);
printf("File date %s", ctime(&rep.Fdate));
printf("File CRC %s\n", rep.Crc);
printf("Origin system %s\n", rep.Origin);
printf("From system %s\n", rep.From);
printf("Replace %s\n", rep.Replace);
printf("Magic %s\n", rep.Magic);
printf("Announce ");
if (rep.Announce)
printf("yes\n");
else
printf("no\n");
printf("Description %s\n", rep.Desc);
for (i = 0; i < rep.TotLdesc; i++) {
printf(" %2d %s\n", (int)strlen(rep.LDesc[i]), rep.LDesc[i]);
}
printf("\n\n");
}
fclose(fp);
chmod(temp, 0640);
free(temp);
return 0;
}

397
mbutils/mbuser.c Normal file
View File

@@ -0,0 +1,397 @@
/*****************************************************************************
*
* $Id$
* Purpose ...............: User Pack Util
*
*****************************************************************************
* Copyright (C) 1997-2004
*
* 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
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*****************************************************************************/
#include "../config.h"
#include "../lib/mbselib.h"
#include "../lib/users.h"
#include "../lib/mbsedb.h"
#include "mbuser.h"
extern int e_pid; /* External pid */
extern int do_quiet; /* Quiet flag */
time_t t_start; /* Start time */
time_t t_end; /* End time */
int Days, Level; /* Kill days and up to level */
struct userhdr usrhdr; /* Database header */
struct userrec usr; /* Database record */
mode_t oldmask; /* Old umask value */
int main(int argc, char **argv)
{
int i, pack = FALSE;
char *cmd;
struct passwd *pw;
InitConfig();
mbse_TermInit(1, 80, 24);
Days = 0;
Level = 0;
t_start = time(NULL);
if (argc < 2)
Help();
cmd = xstrcpy((char *)"Command line:");
for (i = 1; i < argc; i++) {
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, tl(argv[i]));
if (strncasecmp(tl(argv[i]), "-q", 2) == 0)
do_quiet = TRUE;
if (strncasecmp(tl(argv[i]), "p", 1) == 0)
pack = TRUE;
if (strncasecmp(tl(argv[i]), "k", 1) == 0) {
if (argc <= (i + 2))
Help();
i++;
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
Days = atoi(argv[i]);
i++;
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
Level = atoi(argv[i]);
if ((Days == 0) || (Level == 0))
Help();
}
}
if ((Days + Level + pack) == 0)
Help();
ProgName();
pw = getpwuid(getuid());
InitClient(pw->pw_name, (char *)"mbuser", CFG.location, CFG.logfile,
CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
Syslog(' ', " ");
Syslog(' ', "MBUSER v%s", VERSION);
Syslog(' ', cmd);
free(cmd);
if (enoughspace(CFG.freespace) == 0)
ExitClient(MBERR_DISK_FULL);
if (lockprogram((char *)"mbuser")) {
if (!do_quiet)
printf("Can't lock mbuser, abort.\n");
ExitClient(MBERR_NO_PROGLOCK);
}
oldmask = umask(027);
if (!do_quiet)
mbse_colour(3, 0);
UserPack(Days, Level, pack);
umask(oldmask);
ulockprogram((char *)"mbuser");
t_end = time(NULL);
Syslog(' ', "MBUSER finished in %s", t_elapsed(t_start, t_end));
if (!do_quiet)
mbse_colour(7, 0);
ExitClient(MBERR_OK);
return 0;
}
/*
* Program header
*/
void ProgName(void)
{
if (do_quiet)
return;
mbse_colour(15, 0);
printf("\nMBUSER: MBSE BBS %s - User maintenance utility\n", VERSION);
mbse_colour(14, 0);
printf(" %s\n\n", COPYRIGHT);
mbse_colour(7, 0);
}
void Help(void)
{
do_quiet = FALSE;
ProgName();
mbse_colour(11, 0);
printf("\nUsage: mbuser [commands] <options>\n\n");
mbse_colour(9, 0);
printf(" Commands are:\n\n");
mbse_colour(3, 0);
printf(" kill [n] [l] Kill users not called in \"n\" days below level \"l\"\n");
printf(" pack Pack the userbase\n");
mbse_colour(9, 0);
printf("\n Options are:\n\n");
mbse_colour(3, 0);
printf(" -quiet Quiet mode, (no screen output)\n\n");
mbse_colour(7, 0);
printf("\n");
ExitClient(MBERR_COMMANDLINE);
}
/*
* Userpack routine
*/
void UserPack(int days, int level, int pack)
{
FILE *fin, *fout;
char *fnin, *fnout;
long oldsize, curpos;
int updated, delete = 0, rc, highest = 0, record = 0, sysop = FALSE;
time_t Last;
char *cmd;
fnin = calloc(PATH_MAX, sizeof(char));
fnout = calloc(PATH_MAX, sizeof(char));
sprintf(fnin, "%s/etc/users.data", getenv("MBSE_ROOT"));
sprintf(fnout, "%s/etc/users.temp", getenv("MBSE_ROOT"));
/*
* First copy the users database, all packing will be done
* on a the copy.
*/
if ((fin = fopen(fnin, "r")) == NULL) {
WriteError("Can't open %s", fnin);
free(fnin);
free(fnout);
return;
}
if ((fout = fopen(fnout, "w+")) == NULL) {
WriteError("Can't create %s", fnout);
fclose(fin);
free(fnin);
free(fnout);
return;
}
fread(&usrhdr, sizeof(usrhdr), 1, fin);
oldsize = usrhdr.recsize;
updated = FALSE;
/*
* First count records and blanks at the end. Check if the sysop name
* in the main configuration exists in the userdatabase.
*/
while (fread(&usr, oldsize, 1,fin) == 1) {
delete++;
if (!usr.Deleted && strlen(usr.sUserName)) {
highest = (ftell(fin) / oldsize);
if (!strcmp(usr.sUserName, CFG.sysop_name) && !strcmp(usr.Name, CFG.sysop))
sysop = TRUE;
}
}
if (highest != delete) {
Syslog('+', "Blank records at the end, truncating userbase");
updated = TRUE;
}
if (!sysop)
WriteError("No valid Sysop Fidoname and/or Unixname found in userbase, check setup!");
fseek(fin, usrhdr.hdrsize, SEEK_SET);
if (oldsize != sizeof(usr)) {
updated = TRUE;
Syslog('+', "Userbase recordsize is changed, making update");
}
usrhdr.hdrsize = sizeof(usrhdr);
usrhdr.recsize = sizeof(usr);
fwrite(&usrhdr, sizeof(usrhdr), 1, fout);
/*
* The datarecord is filled with zero's before each read
* so that if the record format changed, the new fields will
* be empty by default. The blank records at the end of the
* database are dropped.
*/
memset(&usr, 0, sizeof(usr));
while (fread(&usr, oldsize, 1,fin) == 1) {
record++;
fwrite(&usr, sizeof(usr), 1, fout);
memset(&usr, 0, sizeof(usr));
if (CFG.slow_util && do_quiet)
msleep(1);
Nopper();
}
fclose(fin);
delete = 0;
/*
* Handle packing for days below level
*/
if ((days) && (level)) {
fseek(fout, sizeof(usrhdr), SEEK_SET);
curpos = sizeof(usrhdr);
while (fread(&usr, sizeof(usr), 1, fout) == 1) {
/*
* New users don't have the last login date set yet,
* use the registration date instead.
*/
if (usr.iTotalCalls == 0)
Last = usr.tFirstLoginDate;
else
Last = usr.tLastLoginDate;
/*
* Wow, killing on the second exact!. Don't kill
* the guest accounts.
*/
if ((((t_start - Last) / 86400) > days) &&
(usr.Security.level < level) && (!usr.Guest) &&
(usr.sUserName[0] != '\0') && (!usr.NeverDelete)) {
Syslog('+', "Mark user %s", usr.sUserName);
if (!do_quiet) {
printf("Mark user %s\n", usr.sUserName);
fflush(stdout);
}
delete++;
updated = TRUE;
fseek(fout, - sizeof(usr), SEEK_CUR);
/*
* Just mark for deletion
*/
usr.Deleted = TRUE;
fwrite(&usr, sizeof(usr), 1, fout);
}
if (CFG.slow_util && do_quiet)
msleep(1);
}
Syslog('+', "Marked %d users to delete", delete);
}
/*
* Pack the userbase if told so
*/
if (pack) {
Syslog('+', "Packing userbase");
delete = 0;
fseek(fout, sizeof(usrhdr), SEEK_SET);
while (fread(&usr, sizeof(usr), 1, fout) == 1) {
if (CFG.slow_util && do_quiet)
msleep(1);
Nopper();
if (usr.Deleted) {
if (!do_quiet) {
printf("Delete user %s\n", usr.Name);
fflush(stdout);
}
if (usr.Name[0] != '\0') {
if ((setuid(0) == -1) || (setgid(0) == -1)) {
WriteError("Cannot setuid(root) or setgid(root)");
WriteError("Cannot delete unix account %s", usr.Name);
} else {
#ifndef __FreeBSD__
rc = execute_str((char *)"/usr/sbin/userdel ", usr.Name, NULL,
(char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
#else
rc = execute_str((char *)"/usr/sbin/pw userdel ", usr.Name, NULL,
(char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
#endif
#ifdef _VPOPMAIL_PATH
cmd = xstrcpy((char *)_VPOPMAIL_PATH);
cmd = xstrcat(cmd, (char *)"/vdeluser ");
rc = execute_str(cmd, usr.Name, NULL,
(char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
free(cmd);
#endif
if (chdir(CFG.bbs_usersdir) == 0) {
cmd = xstrcpy((char *)"-Rf ");
cmd = xstrcat(cmd, usr.Name);
rc = execute_pth((char *)"rm", cmd,
(char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
free(cmd);
}
}
}
fseek(fout, - sizeof(usr), SEEK_CUR);
/*
* Blank the deleted records for reuse.
*/
memset(&usr, 0, sizeof(usr));
fwrite(&usr, sizeof(usr), 1, fout);
delete++;
updated = TRUE;
}
}
Syslog('+', "Deleted %d records", delete);
}
if (updated) {
/*
* Copy file back to the original file, truncate any
* deleted records at the end.
*/
fseek(fout, 0, SEEK_SET);
if ((fin = fopen(fnin, "w")) == NULL) {
WriteError("Can't open %s", fnin);
free(fnin);
free(fnout);
return;
}
fread(&usrhdr, sizeof(usrhdr), 1, fout);
fwrite(&usrhdr, sizeof(usrhdr), 1, fin);
record = 0;
while (fread(&usr, sizeof(usr), 1,fout) == 1) {
Nopper();
record++;
fwrite(&usr, sizeof(usr), 1, fin);
if (record >= highest)
break;
}
fclose(fin);
fclose(fout);
chmod(fnin, 0660);
Syslog('+', "Userbase is updated, written %d records", record);
} else {
fclose(fout);
}
unlink(fnout);
free(fnin);
free(fnout);
}

9
mbutils/mbuser.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef _MBUSER_H
#define _MBUSER_H
void ProgName(void);
void Help(void);
void UserPack(int, int, int);
#endif