Converted from CVS
This commit is contained in:
1
mbutils/.cvsignore
Normal file
1
mbutils/.cvsignore
Normal file
@@ -0,0 +1 @@
|
||||
filelist mball mbchat mblang mbstat mbsnmp mbtoberep mbuser mbbw
|
107
mbutils/Makefile
Normal file
107
mbutils/Makefile
Normal file
@@ -0,0 +1,107 @@
|
||||
# Makefile for MBSE BBS under Linux
|
||||
# Copyright (c) 1998, 2004 by M. Broek.
|
||||
# $Id: Makefile,v 1.8 2008/02/10 20:07:16 mbse Exp $
|
||||
|
||||
include ../Makefile.global
|
||||
|
||||
SRCS = mball.c dlcount.c mblang.c mbstat.c mbsnmp.c mbtoberep.c mbuser.c mbbw.c
|
||||
HDRS = mball.h dlcount.h mbstat.h mbsnmp.h mbuser.h
|
||||
MBALL_OBJS = mball.o dlcount.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
|
||||
MBSNMP_OBJS = mbsnmp.o
|
||||
MBSNMP_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
|
||||
MBBW_OBJS = mbbw.o
|
||||
MBBW_LIBS = ../lib/libmbse.a ../lib/libdbase.a
|
||||
OTHER = Makefile
|
||||
TARGET = mball mblang mbstat mbsnmp mbtoberep mbuser mbbw
|
||||
|
||||
#############################################################################################################
|
||||
|
||||
.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}
|
||||
|
||||
mbsnmp: ${MBSNMP_OBJS} ${MBSNMP_LIBS}
|
||||
${CC} -o mbsnmp ${MBSNMP_OBJS} ${LDFLAGS} ${LIBS} ${MBSNMP_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}
|
||||
|
||||
mbbw: ${MBBW_OBJS} ${MBBW_LIBS}
|
||||
${CC} -o mbbw ${MBBW_OBJS} ${LDFLAGS} ${LIBS} ${MBBW_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 4750 mbsnmp ${BINDIR}
|
||||
${INSTALL} -c -s -o ${OWNER} -g ${GROUP} -m 0700 mbtoberep ${BINDIR}
|
||||
${INSTALL} -c -s -o ${ROWNER} -g ${RGROUP} -m 6711 mbuser ${BINDIR}
|
||||
${INSTALL} -c -s -o ${OWNER} -g ${GROUP} -m 0750 mbbw ${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 dlcount.h mball.h
|
||||
dlcount.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h dlcount.h
|
||||
mblang.o: ../config.h ../lib/mbselib.h
|
||||
mbstat.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbstat.h
|
||||
mbsnmp.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbsnmp.h
|
||||
mbtoberep.o: ../config.h ../lib/mbselib.h
|
||||
mbuser.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbuser.h
|
||||
mbbw.o: ../config.h ../lib/mbselib.h ../lib/bluewave.h
|
||||
# End of generated dependencies
|
275
mbutils/dlcount.c
Normal file
275
mbutils/dlcount.c
Normal file
@@ -0,0 +1,275 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id: dlcount.c,v 1.7 2007/10/16 14:29:29 mbse Exp $
|
||||
* Purpose ...............: Count WWW and FTP downloads
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2007
|
||||
*
|
||||
* 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 "dlcount.h"
|
||||
|
||||
static char *months[]={(char *)"Jan",(char *)"Feb",(char *)"Mar",
|
||||
(char *)"Apr",(char *)"May",(char *)"Jun",
|
||||
(char *)"Jul",(char *)"Aug",(char *)"Sep",
|
||||
(char *)"Oct",(char *)"Nov",(char *)"Dec"};
|
||||
|
||||
void count_download(char *, time_t, off_t, char *);
|
||||
|
||||
extern int do_quiet;
|
||||
|
||||
|
||||
void dlcount(void)
|
||||
{
|
||||
char *temp, *p, *q = NULL, *date, *file, *base, month[20];
|
||||
FILE *fp;
|
||||
int i, date_ok, file_ok, result, filesize;
|
||||
time_t filedate = (time_t)0, lastcheck;
|
||||
struct tm tm;
|
||||
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
|
||||
/*
|
||||
* Check if we have a mark when we did this the last time.
|
||||
* If not, create one and don't do anything. Run the next time.
|
||||
*/
|
||||
snprintf(temp, PATH_MAX, "%s/var/dlcount.stat", getenv("MBSE_ROOT"));
|
||||
if ((lastcheck = file_time(temp)) == -1) {
|
||||
Syslog('+', "Checking WWW downloads never done before, creating timestamp");
|
||||
if ((fp = fopen(temp, "a"))) {
|
||||
fclose(fp);
|
||||
}
|
||||
free(temp);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Refresh timestamp
|
||||
*/
|
||||
unlink(temp);
|
||||
if ((fp = fopen(temp, "a"))) {
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
date = calloc(81, sizeof(char));
|
||||
file = calloc(PATH_MAX, sizeof(char));
|
||||
base = calloc(PATH_MAX, sizeof(char));
|
||||
|
||||
if (strlen(CFG.www_logfile) && (fp = fopen(CFG.www_logfile, "r"))) {
|
||||
|
||||
/*
|
||||
* Check apache logfile
|
||||
*/
|
||||
if (!do_quiet)
|
||||
printf("Checking WWW downloads\n");
|
||||
Syslog('+', "Checking WWW downloads");
|
||||
|
||||
while (fgets(temp, PATH_MAX-1, fp)) {
|
||||
date_ok = file_ok = FALSE;
|
||||
memset(date, 0, 80);
|
||||
memset(file, 0, PATH_MAX);
|
||||
memset(base, 0, PATH_MAX);
|
||||
Striplf(temp);
|
||||
|
||||
/*
|
||||
* Parse logline, be aware for lots of garbage created by systems
|
||||
* that try to compromise the webserver.
|
||||
*/
|
||||
// Syslog('f', "%s", printable(temp, 100));
|
||||
p = strchr(temp, '[');
|
||||
if (p) {
|
||||
q = strchr(p, ']');
|
||||
if (q && ((q-p) < 40)) {
|
||||
strncpy(date, p+1, q - p - 1);
|
||||
tm.tm_mday = atoi(strtok(date, "/\0"));
|
||||
snprintf(month, 20, "%s", strtok(NULL, "/\0"));
|
||||
for (i = 0; i < 12; i++)
|
||||
if (strncasecmp(months[i], month, 3) == 0)
|
||||
break;
|
||||
tm.tm_mon = i;
|
||||
tm.tm_year = atoi(strtok(NULL, ":\0")) - 1900;
|
||||
tm.tm_hour = atoi(strtok(NULL, ":\0"));
|
||||
tm.tm_min = atoi(strtok(NULL, ":\0"));
|
||||
tm.tm_sec = atoi(strtok(NULL, ":\0"));
|
||||
filedate = mktime(&tm);
|
||||
if (filedate > lastcheck)
|
||||
date_ok = TRUE;
|
||||
}
|
||||
}
|
||||
if (date_ok && (p = strchr(temp, '"'))) {
|
||||
q = strchr(p+1, '"');
|
||||
if (q && ((q-p) < 128)) {
|
||||
strncpy(file, p+1, q - p - 1);
|
||||
if (strncmp(file, "GET ", 4) == 0) {
|
||||
if ((p = strstr(file, CFG.www_link2ftp))) {
|
||||
snprintf(base, PATH_MAX, "%s%s", CFG.ftp_base, p + strlen(CFG.www_link2ftp));
|
||||
for (i = strlen(base); i; i--) {
|
||||
if (base[i] == ' ') {
|
||||
base[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
file_ok = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (file_ok) {
|
||||
p = strtok(q, (char *)" \0");
|
||||
result = atoi(strtok(NULL, (char *)" \0"));
|
||||
filesize = atoi(strtok(NULL, (char *)" \0"));
|
||||
if (result == 200) {
|
||||
/*
|
||||
* So far it seems that the file is possible downloaded from the bbs.
|
||||
* Now search the download area and filerecord.
|
||||
*/
|
||||
Syslog('f', "%s %s %d", rfcdate(filedate), base, filesize);
|
||||
count_download(base, filedate, filesize, (char *)"WWW");
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
if (strlen(CFG.ftp_logfile) && (fp = fopen(CFG.ftp_logfile, "r"))) {
|
||||
|
||||
/*
|
||||
* Check ftp logfile
|
||||
*/
|
||||
if (!do_quiet)
|
||||
printf("Checking FTP downloads\n");
|
||||
Syslog('+', "Checking FTP downloads");
|
||||
|
||||
while (fgets(temp, PATH_MAX-1, fp)) {
|
||||
date_ok = file_ok = FALSE;
|
||||
memset(date, 0, 80);
|
||||
memset(file, 0, PATH_MAX);
|
||||
memset(base, 0, PATH_MAX);
|
||||
Striplf(temp);
|
||||
|
||||
/*
|
||||
* Parse logline.
|
||||
*/
|
||||
// Syslog('f', "%s", printable(temp, 100));
|
||||
p = strtok(temp, " \0"); /* Day of week */
|
||||
p = strtok(NULL, " \0"); /* Month */
|
||||
for (i = 0; i < 12; i++)
|
||||
if (strncasecmp(months[i], p, 3) == 0)
|
||||
break;
|
||||
tm.tm_mon = i;
|
||||
tm.tm_mday = atoi(strtok(NULL, " \0")); /* Day in month */
|
||||
tm.tm_hour = atoi(strtok(NULL, ":\0")); /* Hour */
|
||||
tm.tm_min = atoi(strtok(NULL, ":\0")); /* Minute */
|
||||
tm.tm_sec = atoi(strtok(NULL, " \0")); /* Seconds */
|
||||
tm.tm_year = atoi(strtok(NULL, " \0")) - 1900; /* Year */
|
||||
filedate = mktime(&tm);
|
||||
if (filedate > lastcheck)
|
||||
date_ok = TRUE;
|
||||
p = strtok(NULL, " \0"); /* 0 */
|
||||
p = strtok(NULL, " \0"); /* Remote host */
|
||||
filesize = atoi(strtok(NULL, " \0")); /* Filesize */
|
||||
p = strtok(NULL, " \0"); /* Filename */
|
||||
if (p == NULL)
|
||||
break;
|
||||
|
||||
snprintf(base, PATH_MAX, "%s", p);
|
||||
if (date_ok) {
|
||||
/*
|
||||
* So far it seems that the file is possible downloaded from the bbs.
|
||||
* Now search the download area and filerecord.
|
||||
*/
|
||||
Syslog('f', "%s %s %d", rfcdate(filedate), base, filesize);
|
||||
count_download(base, filedate, filesize, (char *)"FTP");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(base);
|
||||
free(file);
|
||||
free(date);
|
||||
free(temp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Count download if file is present in the FDB.
|
||||
*/
|
||||
void count_download(char *filename, time_t filedate, off_t filesize, char *dltype)
|
||||
{
|
||||
char *temp;
|
||||
FILE *dfp;
|
||||
int i, j;
|
||||
struct _fdbarea *fdb_area = NULL;
|
||||
struct FILE_record frec;
|
||||
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
snprintf(temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
|
||||
|
||||
if ((dfp = fopen(temp, "r"))) {
|
||||
|
||||
fread(&areahdr, sizeof(areahdr), 1, dfp);
|
||||
snprintf(temp, PATH_MAX, "%s", filename);
|
||||
for (j = strlen(temp); j; j--)
|
||||
if (temp[j] == '/') {
|
||||
temp[j] = '\0';
|
||||
break;
|
||||
}
|
||||
i = 0;
|
||||
|
||||
while (fread(&area, areahdr.recsize, 1, dfp) == 1) {
|
||||
i++;
|
||||
if (area.Available && (strcmp(temp, area.Path) == 0)) {
|
||||
snprintf(temp, PATH_MAX, "%s", basename(filename));
|
||||
|
||||
if ((fdb_area = mbsedb_OpenFDB(i, 30))) {
|
||||
while (fread(&frec, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
|
||||
if (((strcasecmp(frec.Name, temp) == 0) || (strcasecmp(frec.LName, temp) == 0)) &&
|
||||
(frec.Size == filesize)) {
|
||||
Syslog('+', "%s download %s from area %d", dltype, temp, i);
|
||||
frec.LastDL = filedate;
|
||||
frec.TimesDL++;
|
||||
if (mbsedb_LockFDB(fdb_area, 30)) {
|
||||
fseek(fdb_area->fp, 0 - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&frec, fdbhdr.recsize, 1, fdb_area->fp);
|
||||
mbsedb_UnlockFDB(fdb_area);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
mbsedb_CloseFDB(fdb_area);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(dfp);
|
||||
}
|
||||
|
||||
free(temp);
|
||||
}
|
||||
|
8
mbutils/dlcount.h
Normal file
8
mbutils/dlcount.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _DLCOUNT_H
|
||||
#define _DLCOUNT_H
|
||||
|
||||
/* $Id: dlcount.h,v 1.1 2005/08/11 15:14:27 mbse Exp $ */
|
||||
|
||||
void dlcount(void);
|
||||
|
||||
#endif
|
555
mbutils/mball.c
Normal file
555
mbutils/mball.c
Normal file
@@ -0,0 +1,555 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id: mball.c,v 1.9 2007/09/02 11:17:33 mbse Exp $
|
||||
* Purpose ...............: Creates allfiles listings
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2007
|
||||
*
|
||||
* 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 "dlcount.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(WHITE, BLACK);
|
||||
printf("\nMBALL: MBSE BBS %s Allfiles Listing Creator\n", VERSION);
|
||||
mbse_colour(YELLOW, BLACK);
|
||||
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(LIGHTGRAY, BLACK);
|
||||
printf("\n");
|
||||
}
|
||||
ExitClient(onsig);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Help()
|
||||
{
|
||||
do_quiet = FALSE;
|
||||
ProgName();
|
||||
|
||||
mbse_colour(LIGHTCYAN, BLACK);
|
||||
printf("\nUsage: mball [command] <options>\n\n");
|
||||
mbse_colour(LIGHTBLUE, BLACK);
|
||||
printf(" Commands are:\n\n");
|
||||
mbse_colour(CYAN, BLACK);
|
||||
printf(" l list Create allfiles and newfiles lists\n");
|
||||
mbse_colour(LIGHTBLUE, BLACK);
|
||||
printf("\n Options are:\n\n");
|
||||
mbse_colour(CYAN, BLACK);
|
||||
printf(" -q -quiet Quiet mode\n");
|
||||
printf(" -z -zip Create .zip archives\n");
|
||||
mbse_colour(LIGHTGRAY, BLACK);
|
||||
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) || (i == SIGIOT))
|
||||
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(CYAN, BLACK);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (lockprogram((char *)"mball")) {
|
||||
if (!do_quiet)
|
||||
printf("Can't lock mball, abort.\n");
|
||||
die(MBERR_NO_PROGLOCK);
|
||||
}
|
||||
|
||||
if (do_list) {
|
||||
dlcount();
|
||||
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, FILE *up, int doit)
|
||||
{
|
||||
char temp[256];
|
||||
int x, y, z;
|
||||
|
||||
if (!doit)
|
||||
return;
|
||||
|
||||
z = strlen(txt);
|
||||
x = 77 - z;
|
||||
x /= 2;
|
||||
strcpy(temp, "\xB3");
|
||||
|
||||
for (y = 0; y < x; y++)
|
||||
strcat(temp, " ");
|
||||
|
||||
strncat(temp, txt, 255);
|
||||
|
||||
for (y = strlen(temp); y < 78; y++)
|
||||
strncat(temp, " ", 255);
|
||||
|
||||
strncat(temp, "\xB3\r\n", 255);
|
||||
fprintf(fp, temp);
|
||||
fprintf(up, chartran(temp));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TopBox(FILE *fp, FILE *up, int doit)
|
||||
{
|
||||
int y;
|
||||
char temp[256];
|
||||
|
||||
if (!doit)
|
||||
return;
|
||||
|
||||
strcpy(temp, "\r\n\xDA");
|
||||
for(y = 0; y < 77; y++)
|
||||
strncat(temp, "\xC4", 255);
|
||||
strncat(temp, "\xBF\r\n", 255);
|
||||
fprintf(fp, temp);
|
||||
fprintf(up, chartran(temp));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BotBox(FILE *fp, FILE *up, int doit)
|
||||
{
|
||||
int y;
|
||||
char temp[256];
|
||||
|
||||
if (!doit)
|
||||
return;
|
||||
|
||||
strcpy(temp, "\xC0");
|
||||
for (y = 0; y < 77; y++)
|
||||
strncat(temp, "\xC4", 255);
|
||||
strncat(temp, "\xD9\r\n\r\n", 255);
|
||||
fprintf(fp, temp);
|
||||
fprintf(up, chartran(temp));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WriteFiles(FILE *fp, FILE *fu, FILE *np, FILE *nu, int New, char *temp)
|
||||
{
|
||||
fprintf(fp, "%s\r\n", temp);
|
||||
fprintf(fu, "%s\r\n", chartran(temp));
|
||||
if (New) {
|
||||
fprintf(np, "%s\r\n", temp);
|
||||
fprintf(nu, "%s\r\n", chartran(temp));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Masterlist()
|
||||
{
|
||||
FILE *fp, *np, *fu, *nu, *pAreas, *pHeader;
|
||||
int AreaNr = 0, z, x = 0, New;
|
||||
unsigned int AllFiles = 0, AllKBytes = 0, NewFiles = 0, NewKBytes = 0;
|
||||
unsigned int AllAreaFiles, AllAreaBytes, popdown, down, NewAreaFiles, NewAreaBytes;
|
||||
char *sAreas, temp[PATH_MAX], pop[81];
|
||||
struct _fdbarea *fdb_area = NULL;
|
||||
|
||||
sAreas = calloc(PATH_MAX, sizeof(char));
|
||||
|
||||
IsDoing("Create Allfiles list");
|
||||
|
||||
snprintf(sAreas, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
|
||||
|
||||
if(( pAreas = fopen (sAreas, "r")) == NULL) {
|
||||
WriteError("Can't open File Areas File: %s", sAreas);
|
||||
mbse_colour(LIGHTGRAY, BLACK);
|
||||
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);
|
||||
}
|
||||
if ((fu = fopen("allfiles.ump", "a+")) == NULL) {
|
||||
WriteError("$Can't open allfiles.ump");
|
||||
fclose(fp);
|
||||
fclose(np);
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
if ((nu = fopen("newfiles.ump", "a+")) == NULL) {
|
||||
WriteError("$Can't open newfiles.ump");
|
||||
fclose(fp);
|
||||
fclose(np);
|
||||
fclose(fu);
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
|
||||
chartran_init((char *)"CP437", (char *)"UTF-8", 'B');
|
||||
|
||||
TopBox(fp, fu, TRUE);
|
||||
TopBox(np, nu, TRUE);
|
||||
snprintf(temp, 81, "All available files at %s", CFG.bbs_name);
|
||||
MidLine(temp, fp, fu, TRUE);
|
||||
snprintf(temp, 81, "New available files since %d days at %s", CFG.newdays, CFG.bbs_name);
|
||||
MidLine(temp, np, nu, TRUE);
|
||||
BotBox(fp, fu, TRUE);
|
||||
BotBox(np, nu, TRUE);
|
||||
|
||||
snprintf(temp, PATH_MAX, "%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);
|
||||
fprintf(fu, "%s\r\n", chartran(temp));
|
||||
fprintf(nu, "%s\r\n", chartran(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;
|
||||
snprintf(pop, 81, "%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, fu, TRUE);
|
||||
TopBox(np, nu, NewAreaFiles);
|
||||
|
||||
snprintf(temp, 81, "Area %d - %s", AreaNr, area.Name);
|
||||
MidLine(temp, fp, fu, TRUE);
|
||||
MidLine(temp, np, nu, NewAreaFiles);
|
||||
|
||||
snprintf(temp, 81, "File Requests allowed");
|
||||
MidLine(temp, fp, fu, area.FileReq);
|
||||
MidLine(temp, np, nu, area.FileReq && NewAreaFiles);
|
||||
|
||||
snprintf(temp, 81, "%d KBytes in %d files", AllAreaBytes / 1024, AllAreaFiles);
|
||||
MidLine(temp, fp, fu, TRUE);
|
||||
snprintf(temp, 81, "%d KBytes in %d files", NewAreaBytes / 1024, NewAreaFiles);
|
||||
MidLine(temp, np, nu, NewAreaFiles);
|
||||
if (popdown) {
|
||||
snprintf(temp, 81, "Most popular file is %s", pop);
|
||||
MidLine(temp, fp, fu, TRUE);
|
||||
}
|
||||
|
||||
BotBox(fp, fu, TRUE);
|
||||
BotBox(np, nu, 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);
|
||||
|
||||
snprintf(temp, 81, "%s", fdb.LName);
|
||||
WriteFiles(fp, fu, np, nu, New, temp);
|
||||
|
||||
snprintf(temp, 81, "%-12s%10u K %s [%04d] Uploader: %s",
|
||||
fdb.Name, (int)(fdb.Size / 1024), StrDateDMY(fdb.UploadDate), fdb.TimesDL,
|
||||
strlen(fdb.Uploader)?fdb.Uploader:"");
|
||||
WriteFiles(fp, fu, np, nu, New, temp);
|
||||
|
||||
for (z = 0; z < 25; z++) {
|
||||
if (strlen(fdb.Desc[z])) {
|
||||
if ((fdb.Desc[z][0] == '@') && (fdb.Desc[z][1] == 'X')) {
|
||||
snprintf(temp, 81, " %s", fdb.Desc[z]+4);
|
||||
} else {
|
||||
snprintf(temp, 81, " %s", fdb.Desc[z]);
|
||||
}
|
||||
WriteFiles(fp, fu, np, nu, New, temp);
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(fdb.Magic)) {
|
||||
snprintf(temp, 81, " Magic filerequest: %s", fdb.Magic);
|
||||
WriteFiles(fp, fu, np, nu, New, temp);
|
||||
}
|
||||
WriteFiles(fp, fu, np, nu, New, (char *)"");
|
||||
}
|
||||
}
|
||||
}
|
||||
mbsedb_CloseFDB(fdb_area);
|
||||
}
|
||||
}
|
||||
} /* End of While Loop Checking for Areas Done */
|
||||
|
||||
fclose(pAreas);
|
||||
|
||||
TopBox(fp, fu, TRUE);
|
||||
TopBox(np, nu, TRUE);
|
||||
snprintf(temp, 81, "Total %d files, %d KBytes", AllFiles, AllKBytes);
|
||||
MidLine(temp, fp, fu, TRUE);
|
||||
snprintf(temp, 81, "Total %d files, %d KBytes", NewFiles, NewKBytes);
|
||||
MidLine(temp, np, nu, TRUE);
|
||||
|
||||
MidLine((char *)"", fp, fu, TRUE);
|
||||
MidLine((char *)"", np, nu, TRUE);
|
||||
|
||||
snprintf(temp, 81, "Created by MBSE BBS v%s (%s-%s) at %s", VERSION, OsName(), OsCPU(), StrDateDMY(t_start));
|
||||
MidLine(temp, fp, fu, TRUE);
|
||||
MidLine(temp, np, nu, TRUE);
|
||||
|
||||
BotBox(fp, fu, TRUE);
|
||||
BotBox(np, nu, TRUE);
|
||||
|
||||
snprintf(temp, PATH_MAX, "%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);
|
||||
fprintf(fu, "%s\r\n", chartran(temp));
|
||||
fprintf(nu, "%s\r\n", chartran(temp));
|
||||
}
|
||||
fclose(pHeader);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
fclose(np);
|
||||
fclose(fu);
|
||||
fclose(nu);
|
||||
chartran_close();
|
||||
|
||||
if ((rename("allfiles.tmp", "allfiles.txt")) == 0)
|
||||
unlink("allfiles.tmp");
|
||||
if ((rename("newfiles.tmp", "newfiles.txt")) == 0)
|
||||
unlink("newfiles.tmp");
|
||||
if ((rename("allfiles.ump", "allfiles.utf")) == 0)
|
||||
unlink("allfiles.ump");
|
||||
if ((rename("newfiles.ump", "newfiles.utf")) == 0)
|
||||
unlink("newfiles.ump");
|
||||
|
||||
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 allfiles.utf", (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 newfiles.utf", (char *)NULL, (char *)"/dev/null",
|
||||
(char *)"/dev/null", (char *)"/dev/null") == 0)
|
||||
WriteError("Create newfiles.zip failed");
|
||||
|
||||
free(cmd);
|
||||
cmd = NULL;
|
||||
}
|
||||
|
||||
|
18
mbutils/mball.h
Normal file
18
mbutils/mball.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _MBALL_H
|
||||
#define _MBALL_H
|
||||
|
||||
|
||||
void ProgName(void);
|
||||
void die(int);
|
||||
void Help(void);
|
||||
void MakeIndex(void);
|
||||
void MidLine(char *, FILE *, FILE *, int);
|
||||
void TopBox(FILE *, FILE *, int);
|
||||
void BotBox(FILE *, FILE *, int);
|
||||
void WriteFiles(FILE *, FILE *, FILE *, FILE *, int, char *);
|
||||
void Masterlist(void);
|
||||
void MakeArc(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
176
mbutils/mbbw.c
Normal file
176
mbutils/mbbw.c
Normal file
@@ -0,0 +1,176 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id: mbbw.c,v 1.4 2007/08/25 18:32:09 mbse Exp $
|
||||
* Purpose ...............: Dump Bluewave packets
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2007
|
||||
*
|
||||
* 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/bluewave.h"
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *bwname, *temp;
|
||||
FILE *fp;
|
||||
INF_HEADER Inf;
|
||||
INF_AREA_INFO AreaInf;
|
||||
MIX_REC Mix;
|
||||
FTI_REC Fti;
|
||||
int i, pos;
|
||||
|
||||
printf("\nMBBW: MBSE BBS %s Bluewave Dump\n", VERSION);
|
||||
printf(" %s\n\n", COPYRIGHT);
|
||||
|
||||
if (argc != 2) {
|
||||
printf("Usage: mbbw [packetname]\n\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bwname = xstrcpy(argv[1]);
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
snprintf(temp, PATH_MAX, "%s.INF", bwname);
|
||||
|
||||
if ((fp = fopen(temp, "r"))) {
|
||||
printf("---- %s.INF -------------------------------------------------------\n", bwname);
|
||||
if (fread(&Inf, sizeof(INF_HEADER), 1, fp) == 1) {
|
||||
printf("\n");
|
||||
printf("Packet version %d\n", Inf.ver);
|
||||
for (i = 0; i < 5; i++)
|
||||
if (strlen((char *)Inf.readerfiles[i]))
|
||||
printf("Display file %d %s\n", i+1, Inf.readerfiles[i]);
|
||||
printf("Registration number %s\n", Inf.regnum);
|
||||
printf("Login name %s\n", Inf.loginname);
|
||||
printf("Aliasname %s\n", Inf.aliasname);
|
||||
printf("Password type %d\n", Inf.passtype);
|
||||
printf("Network address %d:%d/%d.%d\n", Inf.zone, Inf.net, Inf.node, Inf.point);
|
||||
printf("Sysop %s\n", Inf.sysop);
|
||||
printf("Control %sConfig %sFreq\n", (Inf.ctrl_flags & INF_NO_CONFIG) ? "No":"",
|
||||
(Inf.ctrl_flags & INF_NO_FREQ) ? "No":"");
|
||||
printf("System name %s\n", Inf.systemname);
|
||||
printf("Max freqs %d\n", Inf.maxfreqs);
|
||||
printf("Is QWK %s\n", Inf.is_QWK ? "Yes":"No");
|
||||
printf("User flags %s%s%s%s%s%s\n", (Inf.uflags & INF_HOTKEYS) ? "Hotkeys ":"",
|
||||
(Inf.uflags & INF_XPERT) ? "Expert ":"",
|
||||
(Inf.uflags & INF_GRAPHICS) ? "ANSI ":"",
|
||||
(Inf.uflags & INF_NOT_MY_MAIL) ? "Not-my-mail ":"",
|
||||
(Inf.uflags & INF_EXT_INFO) ? "Ext-info ":"",
|
||||
(Inf.uflags & INF_NUMERIC_EXT) ? "Numeric-ext":"");
|
||||
for (i = 0; i < 10; i++)
|
||||
if (strlen((char *)Inf.keywords[i]))
|
||||
printf("Keywords %2d %s\n", i+1, Inf.keywords[i]);
|
||||
for (i = 0; i < 10; i++)
|
||||
if (strlen((char *)Inf.filters[i]))
|
||||
printf("Filters %2d %s\n", i+1, Inf.filters[i]);
|
||||
for (i = 0; i < 3; i++)
|
||||
if (strlen((char *)Inf.macros[i]))
|
||||
printf("Macro %d %s\n", i+1, Inf.macros[i]);
|
||||
printf("Netmail flags %s%s%s%s%s%s%s\n", (Inf.netmail_flags & INF_CAN_CRASH) ? "Crash ":"",
|
||||
(Inf.netmail_flags & INF_CAN_ATTACH) ? "Attach ":"",
|
||||
(Inf.netmail_flags & INF_CAN_KSENT) ? "KSent ":"",
|
||||
(Inf.netmail_flags & INF_CAN_HOLD) ? "Hold ":"",
|
||||
(Inf.netmail_flags & INF_CAN_IMM) ? "Immediate ":"",
|
||||
(Inf.netmail_flags & INF_CAN_FREQ) ? "Freq ":"",
|
||||
(Inf.netmail_flags & INF_CAN_DIRECT) ? "Direct ":"");
|
||||
printf("Credits %d\n", Inf.credits);
|
||||
printf("Debits %d\n", Inf.debits);
|
||||
printf("Can forward %s\n", Inf.can_forward ? "Yes":"No");
|
||||
printf("INF header length (1230) %d\n", Inf.inf_header_len);
|
||||
printf("INF areainfo len (80) %d\n", Inf.inf_areainfo_len);
|
||||
printf("MIX structlen (14) %d\n", Inf.mix_structlen);
|
||||
printf("FTI structlen (186) %d\n", Inf.fti_structlen);
|
||||
printf("Uses UPL file %s\n", Inf.uses_upl_file ? "Yes":"No");
|
||||
printf("From/To length %d\n", Inf.from_to_len);
|
||||
printf("Subject length %d\n", Inf.subject_len);
|
||||
printf("Packet ID %s\n", Inf.packet_id);
|
||||
printf("File list type %d\n", Inf.file_list_type);
|
||||
printf("Max packet size %d\n", Inf.max_packet_size);
|
||||
|
||||
fseek(fp, (long)Inf.inf_header_len, SEEK_SET);
|
||||
while (fread(&AreaInf, sizeof(INF_AREA_INFO), 1, fp)) {
|
||||
printf("\n");
|
||||
printf("Area number %s\n", AreaInf.areanum);
|
||||
printf("Area tag %s\n", AreaInf.echotag);
|
||||
printf("Area title %s\n", AreaInf.title);
|
||||
printf("Area flags %s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
|
||||
(AreaInf.area_flags & INF_SCANNING) ? "Active ":"",
|
||||
(AreaInf.area_flags & INF_ALIAS_NAME) ? "Aliases ":"",
|
||||
(AreaInf.area_flags & INF_ANY_NAME) ? "Any-name ":"",
|
||||
(AreaInf.area_flags & INF_ECHO) ? "Echo ":"",
|
||||
(AreaInf.area_flags & INF_NETMAIL) ? "Netmail ":"",
|
||||
(AreaInf.area_flags & INF_POST) ? "Post ":"",
|
||||
(AreaInf.area_flags & INF_NO_PRIVATE) ? "No-private ":"",
|
||||
(AreaInf.area_flags & INF_NO_PUBLIC) ? "No-public ":"",
|
||||
(AreaInf.area_flags & INF_NO_TAGLINE) ? "No-tagline ":"",
|
||||
(AreaInf.area_flags & INF_NO_HIGHBIT) ? "No-highbit ":"",
|
||||
(AreaInf.area_flags & INF_NOECHO) ? "No-echo ":"",
|
||||
(AreaInf.area_flags & INF_HASFILE) ? "Hasfile ":"",
|
||||
(AreaInf.area_flags & INF_PERSONAL) ? "Personal ":"",
|
||||
(AreaInf.area_flags & INF_TO_ALL) ? "To-all ":"");
|
||||
printf("Network type %s\n", AreaInf.network_type ? "Internet":"Fidonet");
|
||||
}
|
||||
printf("\n");
|
||||
} else {
|
||||
printf("Cannot read info header\n");
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
snprintf(temp, PATH_MAX, "%s.MIX", bwname);
|
||||
if ((fp = fopen(temp, "r"))) {
|
||||
printf("---- %s.MIX -------------------------------------------------------\n\n", bwname);
|
||||
printf(" Area Total Pers. FTI ptr\n");
|
||||
printf("------ ------ ------ ---------\n");
|
||||
while (fread(&Mix, ORIGINAL_MIX_STRUCT_LEN, 1, fp)) {
|
||||
printf("%6s %6d %6d %9d\n", Mix.areanum, Mix.totmsgs, Mix.numpers, Mix.msghptr);
|
||||
}
|
||||
printf("\n");
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
snprintf(temp, PATH_MAX, "%s.FTI", bwname);
|
||||
pos = 0;
|
||||
if ((fp = fopen(temp, "r"))) {
|
||||
printf("---- %s.FTI -------------------------------------------------------\n\n", bwname);
|
||||
printf(" Pos From Date Msgnum Replto Replat Ptr Length\n");
|
||||
printf("------ ------------------------------------- ------------------- ------ ------ ------ ------ ------\n");
|
||||
while (fread(&Fti, ORIGINAL_FTI_STRUCT_LEN, 1, fp)) {
|
||||
printf("%6d %-36s %20s %6d %6d %6d %6d %6d\n", pos, Fti.from, Fti.date, Fti.msgnum, Fti.replyto, Fti.replyat,
|
||||
Fti.msgptr, Fti.msglength);
|
||||
|
||||
pos += ORIGINAL_FTI_STRUCT_LEN;
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
free(bwname);
|
||||
free(temp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
113
mbutils/mblang.c
Normal file
113
mbutils/mblang.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id: mblang.c,v 1.2 2005/08/30 17:45:31 mbse Exp $
|
||||
* Purpose ...............: Language Compiler
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2005
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
|
||||
snprintf(temp1, PATH_MAX, "%s", *(argv + 1));
|
||||
unlink(temp1);
|
||||
|
||||
snprintf(temp, PATH_MAX, "%s", *(argv + 2));
|
||||
if ((fp1 = fopen(temp, "r")) == NULL) {
|
||||
printf("\nUnable to open %s\n", temp);
|
||||
exit(MBERR_COMMANDLINE);
|
||||
}
|
||||
snprintf(temp1, PATH_MAX, "%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;
|
||||
}
|
||||
|
||||
|
212
mbutils/mbsnmp.c
Normal file
212
mbutils/mbsnmp.c
Normal file
@@ -0,0 +1,212 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id: mbsnmp.c,v 1.3 2008/02/23 21:42:17 mbse Exp $
|
||||
* Purpose ...............: SNMP passthru support.
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2008
|
||||
*
|
||||
* 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 "mbsnmp.h"
|
||||
|
||||
|
||||
|
||||
// mbsnmp [-n|-g] .1.3.6.1.4.1.2021.256.group.item
|
||||
// mbsnmp <base oid> <request type> <requested oid>
|
||||
// <base oid> Base oid for this tree.
|
||||
// <request type> -n for SNMP getNext, or -g for SNMP get.
|
||||
// <request oid> Requested OID
|
||||
// outputs: "new oid\n" . "integer\n" . data . "\n"
|
||||
|
||||
|
||||
/*
|
||||
* group command reply
|
||||
* ----- ------- ----------------------------------------------------------------------------------------------
|
||||
* 0 MGMS:0; 100:12,kbrcvd,kbsent,sessin,sessout,sess_sec,sess_unseq,sess_bad,ftsc,yoohoo,emsi,binkp,freqs;
|
||||
* 1 MGTN:0; 100:3,in,out,bad;
|
||||
* 2 MGTI:0; 100:3,in,out,bad;
|
||||
* 3 MGTE:0; 100:4,in,out,bad,dupe;
|
||||
* 4 MGTR:0; 100:4,in,out,bad,dupe;
|
||||
* 5 MGTT:0; 100:4,in,out,bad,dupe;
|
||||
* 6 MGTF:0; 100:6,in,out,bad,dupe,magics,hatched;
|
||||
* 7 MGBB:0; 100:9,sessions,minutes,posted,uploads,kbupload,downloads,kbdownload,chats,chatminutes;
|
||||
* 8 MGOB:0; 100:1,size;
|
||||
*/
|
||||
|
||||
|
||||
void usage(void);
|
||||
void die(int);
|
||||
|
||||
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
fprintf(stderr, "\nMBSNMP: MBSE BBS %s SNMP subagent\n", VERSION);
|
||||
fprintf(stderr, " %s\n", COPYRIGHT);
|
||||
fprintf(stderr, "\nUsage: mbsnmp <base oid> <request type> <request oid>\n\n");
|
||||
exit(MBERR_COMMANDLINE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void die(int onsig)
|
||||
{
|
||||
signal(onsig, SIG_IGN);
|
||||
|
||||
if (onsig)
|
||||
Syslog('+', "Terminated on signal %d", onsig);
|
||||
|
||||
ExitClient(onsig);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, getnext = FALSE, group = 0, sub = 0, params, val = 0;
|
||||
char *t1, *t2, *saveptr1 = NULL, *saveptr2 = NULL, *token1, *token2;
|
||||
char *base_save, *req_save, *envptr = NULL, *req_oid, *base_oid, *resp, *type;
|
||||
struct passwd *pw;
|
||||
|
||||
/*
|
||||
* First, check the syntax and parameters.
|
||||
*/
|
||||
if (argc != 4)
|
||||
usage();
|
||||
if (strcmp(argv[2],"-n") && strcmp(argv[2],"-g"))
|
||||
usage();
|
||||
base_oid = argv[1];
|
||||
req_oid = argv[3];
|
||||
getnext = strcmp(argv[2], "-g");
|
||||
if (strncmp(base_oid, req_oid, strlen(base_oid)))
|
||||
usage();
|
||||
|
||||
/*
|
||||
* The next trick is to supply a fake environment variable
|
||||
* MBSE_ROOT because most likely we are started from snmpd.
|
||||
* This will setup the variable so InitConfig() will work.
|
||||
* The /etc/passwd must point to the correct homedirectory.
|
||||
*/
|
||||
pw = getpwnam((char *)"mbse");
|
||||
if (getenv("MBSE_ROOT") == NULL) {
|
||||
envptr = xstrcpy((char *)"MBSE_ROOT=");
|
||||
envptr = xstrcat(envptr, pw->pw_dir);
|
||||
putenv(envptr);
|
||||
}
|
||||
|
||||
InitConfig();
|
||||
|
||||
/*
|
||||
* Catch or ignore signals
|
||||
*/
|
||||
for (i = 0; i < NSIG; i++) {
|
||||
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || (i == SIGIOT))
|
||||
signal(i, (void (*))die);
|
||||
else if ((i != SIGKILL) && (i != SIGSTOP))
|
||||
signal(i, SIG_IGN);
|
||||
}
|
||||
|
||||
pw = getpwuid(getuid());
|
||||
InitClient(pw->pw_name, (char *)"mbsnmp", CFG.location, CFG.logfile,
|
||||
CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
|
||||
|
||||
base_save = xstrcpy(base_oid);
|
||||
req_save = xstrcpy(req_oid);
|
||||
for (i = 1, t1 = base_oid, t2 = req_oid; ; i++, t1 = NULL, t2 = NULL) {
|
||||
token1 = strtok_r(t1, ".", &saveptr1);
|
||||
token2 = strtok_r(t2, ".", &saveptr2);
|
||||
if ((token1 == NULL) || (token2 == NULL))
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Complete the requested OID if needed.
|
||||
*/
|
||||
if (token2) {
|
||||
group = atoi(token2);
|
||||
t2 = NULL;
|
||||
token2 = strtok_r(t2, ".", &saveptr2);
|
||||
if (token2) {
|
||||
sub = atoi(token2);
|
||||
}
|
||||
}
|
||||
|
||||
if ((group < 0) || (group > 8)) {
|
||||
die(MBERR_OK);
|
||||
}
|
||||
|
||||
switch (group) {
|
||||
case 0: resp = SockR("MGMS:0;"); break;
|
||||
case 1: resp = SockR("MGTN:0;"); break;
|
||||
case 2: resp = SockR("MGTI:0;"); break;
|
||||
case 3: resp = SockR("MGTE:0;"); break;
|
||||
case 4: resp = SockR("MGTR:0;"); break;
|
||||
case 5: resp = SockR("MGTT:0;"); break;
|
||||
case 6: resp = SockR("MGTF:0;"); break;
|
||||
case 7: resp = SockR("MGBB:0;"); break;
|
||||
case 8: resp = SockR("MGOB:0;"); break;
|
||||
default: resp = (char *)"200:0;";
|
||||
}
|
||||
|
||||
t1 = strtok(resp, ":");
|
||||
t1 = strtok(NULL, ",");
|
||||
params = atoi(t1);
|
||||
|
||||
for (i = 0; i < params; i++) {
|
||||
t1 = strtok(NULL, ",;");
|
||||
val = atoi(t1);
|
||||
if (i == sub)
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* The value type defaults to counter.
|
||||
*/
|
||||
type = (char *)"counter";
|
||||
if ((group == 8) && (sub == 0))
|
||||
type = (char *)"gauge";
|
||||
|
||||
if ((group < 9) && (sub < params)) {
|
||||
if (getnext) {
|
||||
sub++;
|
||||
if ((sub >= params) && (group < 8)) {
|
||||
sub = 0;
|
||||
group++;
|
||||
}
|
||||
}
|
||||
printf("%s.%d.%d\n", base_save, group, sub);
|
||||
printf("%s\n", type);
|
||||
printf("%d\n", val);
|
||||
}
|
||||
|
||||
die(MBERR_OK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
8
mbutils/mbsnmp.h
Normal file
8
mbutils/mbsnmp.h
Normal file
@@ -0,0 +1,8 @@
|
||||
/* $Id: mbsnmp.h,v 1.1 2008/02/10 20:07:16 mbse Exp $ */
|
||||
|
||||
#ifndef _MBSNMP_H
|
||||
#define _MBSNMP_H
|
||||
|
||||
|
||||
|
||||
#endif
|
279
mbutils/mbstat.c
Normal file
279
mbutils/mbstat.c
Normal file
@@ -0,0 +1,279 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id: mbstat.c,v 1.5 2007/09/02 11:17:33 mbse Exp $
|
||||
* Purpose ...............: Change BBS status
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2007
|
||||
*
|
||||
* 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(LIGHTCYAN, BLACK);
|
||||
printf("\nUsage: mbstat [command] <options>\n\n");
|
||||
mbse_colour(LIGHTBLUE, BLACK);
|
||||
printf(" Commands are:\n\n");
|
||||
mbse_colour(CYAN, BLACK);
|
||||
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(LIGHTBLUE, BLACK);
|
||||
printf(" Semafore's are:\n\n");
|
||||
mbse_colour(CYAN, BLACK);
|
||||
printf(" mailout mailin mbindex newnews msglink\n");
|
||||
printf(" reqindex upsalarm upsdown do_inet\n\n");
|
||||
mbse_colour(LIGHTBLUE, BLACK);
|
||||
printf(" Options are:\n\n");
|
||||
mbse_colour(CYAN, BLACK);
|
||||
printf(" -q -quiet Quiet, no screen output\n");
|
||||
mbse_colour(LIGHTGRAY, BLACK);
|
||||
die(MBERR_COMMANDLINE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ProgName(void)
|
||||
{
|
||||
if (do_quiet)
|
||||
return;
|
||||
|
||||
mbse_colour(WHITE, BLACK);
|
||||
printf("\nMBSTAT: MBSE BBS %s Status Changer\n", VERSION);
|
||||
mbse_colour(YELLOW, BLACK);
|
||||
printf(" %s\n", COPYRIGHT);
|
||||
mbse_colour(CYAN, BLACK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void die(int onsig)
|
||||
{
|
||||
signal(onsig, SIG_IGN);
|
||||
|
||||
if (onsig)
|
||||
Syslog('+', "Terminated on signal %d", onsig);
|
||||
|
||||
if (!do_quiet) {
|
||||
mbse_colour(LIGHTGRAY, BLACK);
|
||||
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) || (i == SIGIOT))
|
||||
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(CYAN, BLACK);
|
||||
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
14
mbutils/mbstat.h
Normal 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
|
||||
|
92
mbutils/mbtoberep.c
Normal file
92
mbutils/mbtoberep.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id: mbtoberep.c,v 1.3 2005/10/11 20:49:49 mbse Exp $
|
||||
* Purpose ...............: Show contents of toberep.data
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2005
|
||||
*
|
||||
* 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;
|
||||
time_t tt;
|
||||
|
||||
if ((BBSpath = getenv("MBSE_ROOT")) == NULL) {
|
||||
printf("MBSE_ROOT variable not set\n");
|
||||
exit(MBERR_INIT_ERROR);
|
||||
}
|
||||
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
snprintf(temp, PATH_MAX, "%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 %u\n", (int)rep.Size);
|
||||
printf("File size Kb %u\n", rep.SizeKb);
|
||||
tt = (time_t)rep.Fdate;
|
||||
printf("File date %s", ctime(&tt));
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
396
mbutils/mbuser.c
Normal file
396
mbutils/mbuser.c
Normal file
@@ -0,0 +1,396 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id: mbuser.c,v 1.5 2007/02/11 13:19:37 mbse Exp $
|
||||
* Purpose ...............: User Pack Util
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2007
|
||||
*
|
||||
* 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(CYAN, BLACK);
|
||||
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(LIGHTGRAY, BLACK);
|
||||
ExitClient(MBERR_OK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Program header
|
||||
*/
|
||||
void ProgName(void)
|
||||
{
|
||||
if (do_quiet)
|
||||
return;
|
||||
|
||||
mbse_colour(WHITE, BLACK);
|
||||
printf("\nMBUSER: MBSE BBS %s - User maintenance utility\n", VERSION);
|
||||
mbse_colour(YELLOW, BLACK);
|
||||
printf(" %s\n\n", COPYRIGHT);
|
||||
mbse_colour(LIGHTGRAY, BLACK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Help(void)
|
||||
{
|
||||
do_quiet = FALSE;
|
||||
ProgName();
|
||||
|
||||
mbse_colour(LIGHTCYAN, BLACK);
|
||||
printf("\nUsage: mbuser [commands] <options>\n\n");
|
||||
mbse_colour(LIGHTBLUE, BLACK);
|
||||
printf(" Commands are:\n\n");
|
||||
mbse_colour(CYAN, BLACK);
|
||||
printf(" kill [n] [l] Kill users not called in \"n\" days below level \"l\"\n");
|
||||
printf(" pack Pack the userbase\n");
|
||||
mbse_colour(LIGHTBLUE, BLACK);
|
||||
printf("\n Options are:\n\n");
|
||||
mbse_colour(CYAN, BLACK);
|
||||
printf(" -quiet Quiet mode, (no screen output)\n\n");
|
||||
|
||||
mbse_colour(LIGHTGRAY, BLACK);
|
||||
printf("\n");
|
||||
ExitClient(MBERR_COMMANDLINE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Userpack routine
|
||||
*/
|
||||
void UserPack(int days, int level, int pack)
|
||||
{
|
||||
FILE *fin, *fout;
|
||||
char *fnin, *fnout, *cmd;
|
||||
int oldsize, curpos;
|
||||
int updated, delete = 0, rc, highest = 0, record = 0, sysop = FALSE;
|
||||
time_t Last;
|
||||
|
||||
fnin = calloc(PATH_MAX, sizeof(char));
|
||||
fnout = calloc(PATH_MAX, sizeof(char));
|
||||
snprintf(fnin, PATH_MAX, "%s/etc/users.data", getenv("MBSE_ROOT"));
|
||||
snprintf(fnout, PATH_MAX, "%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));
|
||||
if (strlen(CFG.externaleditor))
|
||||
usr.MsgEditor = EXTEDIT;
|
||||
else
|
||||
usr.MsgEditor = FSEDIT;
|
||||
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
9
mbutils/mbuser.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _MBUSER_H
|
||||
#define _MBUSER_H
|
||||
|
||||
void ProgName(void);
|
||||
void Help(void);
|
||||
void UserPack(int, int, int);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user