2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2001-12-23 16:44:18 +00:00
|
|
|
* $Id$
|
2001-08-17 05:46:24 +00:00
|
|
|
* Purpose ...............: Change BBS status
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2002-01-07 19:16:03 +00:00
|
|
|
* Copyright (C) 1997-2002
|
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
|
|
|
|
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../config.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "../lib/libs.h"
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../lib/memwatch.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "../lib/structs.h"
|
2002-01-07 19:16:03 +00:00
|
|
|
#include "../lib/users.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "../lib/records.h"
|
|
|
|
#include "../lib/common.h"
|
|
|
|
#include "../lib/clcomm.h"
|
|
|
|
#include "../lib/dbcfg.h"
|
|
|
|
#include "mbstat.h"
|
|
|
|
|
|
|
|
|
|
|
|
extern int do_quiet;
|
|
|
|
time_t t_start, t_end;
|
|
|
|
|
|
|
|
|
|
|
|
void Help(void)
|
|
|
|
{
|
|
|
|
do_quiet = FALSE;
|
|
|
|
ProgName();
|
|
|
|
|
|
|
|
colour(11, 0);
|
|
|
|
printf("\nUsage: mbstat [command] <options>\n\n");
|
|
|
|
colour(9, 0);
|
|
|
|
printf(" Commands are:\n\n");
|
|
|
|
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");
|
|
|
|
colour(9,0);
|
|
|
|
printf(" Options are:\n\n");
|
|
|
|
colour(3, 0);
|
|
|
|
printf(" -q -quiet Quiet, no screen output\n");
|
|
|
|
colour(7, 0);
|
|
|
|
die(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ProgName(void)
|
|
|
|
{
|
|
|
|
if (do_quiet)
|
|
|
|
return;
|
|
|
|
|
|
|
|
colour(15, 0);
|
|
|
|
printf("\nMBSTAT: MBSE BBS %s Status Changer\n", VERSION);
|
|
|
|
colour(14, 0);
|
2001-11-04 16:41:54 +00:00
|
|
|
printf(" %s\n", COPYRIGHT);
|
2001-08-17 05:46:24 +00:00
|
|
|
colour(3, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void die(int onsig)
|
|
|
|
{
|
|
|
|
signal(onsig, SIG_IGN);
|
|
|
|
|
|
|
|
if (onsig)
|
2002-05-10 18:14:27 +00:00
|
|
|
WriteError("Terminated on signal %d", onsig);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
if (!do_quiet) {
|
|
|
|
colour(7, 0);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2001-12-23 16:44:18 +00:00
|
|
|
t_end = time(NULL);
|
2001-08-17 05:46:24 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
#ifdef MEMWATCH
|
|
|
|
mwInit();
|
|
|
|
#endif
|
|
|
|
InitConfig();
|
|
|
|
TermInit(1);
|
2001-12-23 16:44:18 +00:00
|
|
|
t_start = time(NULL);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Catch or ignore signals
|
|
|
|
*/
|
|
|
|
for (i = 0; i < NSIG; i++) {
|
|
|
|
if ((i == SIGHUP) || (i == SIGINT) || (i == SIGBUS) ||
|
|
|
|
(i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) ||
|
|
|
|
(i == SIGKILL))
|
|
|
|
signal(i, (void (*))die);
|
|
|
|
else
|
|
|
|
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());
|
2002-09-28 22:22:50 +00:00
|
|
|
InitClient(pw->pw_name, (char *)"mbstat", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog);
|
2001-08-17 05:46:24 +00:00
|
|
|
usleep(1);
|
|
|
|
|
|
|
|
Syslog(' ', " ");
|
|
|
|
Syslog(' ', "MBSTAT v%s", VERSION);
|
|
|
|
Syslog(' ', cmd);
|
|
|
|
free(cmd);
|
|
|
|
|
|
|
|
if (!do_quiet) {
|
|
|
|
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();
|
|
|
|
|
|
|
|
usleep(1);
|
|
|
|
die(0);
|
|
|
|
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];
|
|
|
|
|
|
|
|
sprintf(buf, "%s/sema/upsdown", getenv("MBSE_ROOT"));
|
2002-05-04 18:14:50 +00:00
|
|
|
if (file_exist(buf, R_OK) == 0)
|
2001-08-17 05:46:24 +00:00
|
|
|
Waiting = 30;
|
|
|
|
|
2002-05-29 19:53:42 +00:00
|
|
|
Syslog('+', "Waiting for the BBS to become free, timeout %d seconds", Waiting);
|
2001-08-17 05:46:24 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|