2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2001-11-04 16:41:54 +00:00
|
|
|
* $Id$
|
2001-08-17 05:46:24 +00:00
|
|
|
* Purpose ...............: Announce new files and FileFind
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2007-09-02 11:17:31 +00:00
|
|
|
* Copyright (C) 1997-2007
|
2001-08-17 05:46:24 +00:00
|
|
|
*
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
* Beekmansbos 10
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
* the Netherlands
|
|
|
|
*
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
*
|
|
|
|
* This BBS is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* MBSE BBS is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
2003-08-15 20:05:34 +00:00
|
|
|
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
2001-08-17 05:46:24 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../config.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbselib.h"
|
2002-01-07 19:16:03 +00:00
|
|
|
#include "../lib/users.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbsedb.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "../lib/msg.h"
|
|
|
|
#include "announce.h"
|
|
|
|
#include "filefind.h"
|
|
|
|
#include "mbaff.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int do_announce = FALSE; /* Announce flag */
|
|
|
|
int do_filefind = FALSE; /* FileFind flag */
|
2002-06-19 20:31:35 +00:00
|
|
|
extern int do_quiet; /* Suppress screen output */
|
2001-08-17 05:46:24 +00:00
|
|
|
extern int show_log; /* Show logging */
|
|
|
|
time_t t_start; /* Start time */
|
|
|
|
time_t t_end; /* End time */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ProgName(void)
|
|
|
|
{
|
2003-08-03 14:42:12 +00:00
|
|
|
if (do_quiet)
|
|
|
|
return;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(WHITE, BLACK);
|
2003-08-03 14:42:12 +00:00
|
|
|
printf("\nMBAFF: MBSE BBS %s Announce new files and FileFind\n", VERSION);
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(YELLOW, BLACK);
|
2003-08-03 14:42:12 +00:00
|
|
|
printf(" %s\n", COPYRIGHT);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void die(int onsig)
|
|
|
|
{
|
2003-08-03 14:42:12 +00:00
|
|
|
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 *)"mbaff");
|
|
|
|
t_end = time(NULL);
|
|
|
|
Syslog(' ', "MBAFF finished in %s", t_elapsed(t_start, t_end));
|
|
|
|
|
|
|
|
if (!do_quiet) {
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(LIGHTGRAY, BLACK);
|
2003-08-03 14:42:12 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
ExitClient(onsig);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2003-08-03 14:42:12 +00:00
|
|
|
int i, Mail = FALSE;
|
|
|
|
char *cmd;
|
|
|
|
struct passwd *pw;
|
|
|
|
struct tm *t;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
InitConfig();
|
2004-10-27 11:08:09 +00:00
|
|
|
mbse_TermInit(1, 80, 25);
|
2003-08-03 14:42:12 +00:00
|
|
|
t_start = time(NULL);
|
|
|
|
t = localtime(&t_start);
|
|
|
|
Diw = t->tm_wday;
|
|
|
|
Miy = t->tm_mon;
|
|
|
|
umask(002);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-02-09 15:11:19 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
/*
|
|
|
|
* Catch all signals we can, and ignore the rest.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < NSIG; i++) {
|
2007-09-02 11:17:31 +00:00
|
|
|
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || (i == SIGIOT))
|
2003-08-03 14:42:12 +00:00
|
|
|
signal(i, (void (*))die);
|
2003-12-04 22:07:33 +00:00
|
|
|
else if ((i != SIGKILL) && (i != SIGSTOP))
|
2003-08-03 14:42:12 +00:00
|
|
|
signal(i, SIG_IGN);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
if (argc < 2)
|
|
|
|
Help();
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
cmd = xstrcpy((char *)"Command line: mbaff");
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
for (i = 1; i < argc; i++) {
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
cmd = xstrcat(cmd, (char *)" ");
|
|
|
|
cmd = xstrcat(cmd, tl(argv[i]));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
if (!strncmp(argv[i], "a", 1))
|
|
|
|
do_announce = TRUE;
|
|
|
|
if (!strncmp(argv[i], "f", 1))
|
|
|
|
do_filefind = TRUE;
|
|
|
|
if (!strncmp(argv[i], "-q", 2))
|
|
|
|
do_quiet = TRUE;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
ProgName();
|
|
|
|
pw = getpwuid(getuid());
|
2003-09-09 19:39:51 +00:00
|
|
|
InitClient(pw->pw_name, (char *)"mbaff", CFG.location, CFG.logfile,
|
|
|
|
CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
Syslog(' ', " ");
|
|
|
|
Syslog(' ', "MBAFF v%s", VERSION);
|
|
|
|
Syslog(' ', cmd);
|
|
|
|
free(cmd);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
if (!do_quiet)
|
|
|
|
printf("\n");
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2004-03-21 12:55:45 +00:00
|
|
|
if (enoughspace(CFG.freespace) == 0)
|
2003-08-03 14:42:12 +00:00
|
|
|
die(MBERR_DISK_FULL);
|
|
|
|
|
|
|
|
if (lockprogram((char *)"mbaff")) {
|
|
|
|
if (!do_quiet)
|
|
|
|
printf("Can't lock mbaff, abort.\n");
|
|
|
|
die(MBERR_NO_PROGLOCK);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
memset(&MsgBase, 0, sizeof(MsgBase));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
if (do_announce)
|
|
|
|
if (Announce())
|
|
|
|
Mail = TRUE;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
if (do_filefind)
|
|
|
|
if (Filefind())
|
|
|
|
Mail = TRUE;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
if (Mail) {
|
|
|
|
CreateSema((char *)"mailout");
|
|
|
|
CreateSema((char *)"msglink");
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-08-03 14:42:12 +00:00
|
|
|
die(MBERR_OK);
|
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Help(void)
|
|
|
|
{
|
|
|
|
do_quiet = FALSE;
|
|
|
|
ProgName();
|
|
|
|
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(LIGHTMAGENTA, BLACK);
|
2001-08-17 05:46:24 +00:00
|
|
|
printf("\nUsage: mbaff [command] <options>\n\n");
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(LIGHTBLUE, BLACK);
|
2001-08-17 05:46:24 +00:00
|
|
|
printf(" Commands are:\n\n");
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(CYAN, BLACK);
|
2001-08-17 05:46:24 +00:00
|
|
|
printf(" a announce Announce new files\n");
|
|
|
|
printf(" f filefind FileFind service\n");
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(LIGHTBLUE, BLACK);
|
2001-08-17 05:46:24 +00:00
|
|
|
printf("\n Options are:\n\n");
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(CYAN, BLACK);
|
2001-08-17 05:46:24 +00:00
|
|
|
printf(" -q -quiet Quiet mode\n");
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(LIGHTGRAY, BLACK);
|
2001-08-17 05:46:24 +00:00
|
|
|
printf("\n");
|
2002-10-20 20:58:55 +00:00
|
|
|
die(MBERR_COMMANDLINE);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|