This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-mbse/mbsebbs/mbsebbs.c

225 lines
5.1 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: Main startup
*
*****************************************************************************
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/mbse.h"
#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/msg.h"
#include "mbsebbs.h"
#include "user.h"
#include "dispfile.h"
2001-08-17 05:46:24 +00:00
#include "language.h"
#include "menu.h"
#include "misc.h"
#include "bye.h"
#include "timeout.h"
2001-11-12 21:42:17 +00:00
#include "funcs.h"
2001-08-17 05:46:24 +00:00
extern int do_quiet; /* Logging quiet flag */
time_t t_start;
int main(int argc, char **argv)
{
FILE *pTty;
char *p, *tty;
int i;
char temp[PATH_MAX];
#ifdef MEMWATCH
mwInit();
#endif
printf("Loading MBSE BBS ...\n");
pTTY = calloc(15, sizeof(char));
tty = ttyname(1);
2002-01-27 12:59:38 +00:00
/*
* Find username from the environment
*/
sUnixName[0] = '\0';
if (getenv("LOGNAME") != NULL) {
strcpy(sUnixName, getenv("LOGNAME"));
} else if (getenv("USER") != NULL) {
strcpy(sUnixName, getenv("USER"));
} else {
WriteError("No username in environment");
Quick_Bye(0);
}
2001-08-17 05:46:24 +00:00
/*
* Set the users device to writable by other bbs users, so they
* can send one-line messages
*/
chmod(tty, 00666);
/*
* Get MBSE_ROOT Path and load Config into Memory
*/
FindMBSE();
/*
* Set local time and statistic indexes.
*/
2001-12-23 16:44:18 +00:00
Time_Now = t_start = time(NULL);
2001-08-17 05:46:24 +00:00
l_date = localtime(&Time_Now);
Diw = l_date->tm_wday;
Miy = l_date->tm_mon;
2001-12-23 16:44:18 +00:00
ltime = time(NULL);
2001-08-17 05:46:24 +00:00
/*
* Initialize this client with the server.
2001-08-17 05:46:24 +00:00
*/
do_quiet = TRUE;
2002-09-28 22:22:50 +00:00
InitClient(sUnixName, (char *)"mbsebbs", (char *)"Unknown", CFG.logfile, CFG.bbs_loglevel, CFG.error_log, CFG.mgrlog);
2001-08-17 05:46:24 +00:00
IsDoing("Loging in");
Syslog(' ', " ");
Syslog(' ', "MBSEBBS v%s", VERSION);
if ((p = getenv("CONNECT")) != NULL)
Syslog('+', "CONNECT %s", p);
if ((p = getenv("CALLER_ID")) != NULL)
if (!strncmp(p, "none", 4))
Syslog('+', "CALLER %s", p);
/*
* Initialize
*/
InitLanguage();
InitMenu();
memset(&MsgBase, 0, sizeof(MsgBase));
i = getpid();
if ((tty = ttyname(0)) == NULL) {
WriteError("Not at a tty");
Quick_Bye(0);
}
2001-08-17 05:46:24 +00:00
if (strncmp("/dev/", tty, 5) == 0)
sprintf(pTTY, "%s", tty+5);
else if (*tty == '/') {
tty = strrchr(ttyname(0), '/');
++tty;
sprintf(pTTY, "%s", tty);
}
umask(007);
2001-08-17 05:46:24 +00:00
/*
* Trap signals
*/
for(i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGBUS) || (i == SIGILL) ||
(i == SIGSEGV) || (i == SIGTERM) || (i == SIGKILL))
signal(i, (void (*))die);
else
signal(i, SIG_IGN);
}
/*
* Default set the terminal to ANSI mode. If your logo
* is in color, the user will see color no mather what.
*/
TermInit(1);
sprintf(temp, "chat.%s", pTTY);
if(access(temp, F_OK) == 0)
unlink(temp);
/*
* Now it's time to check if the bbs is open. If not, we
* log the user off.
*/
if (CheckStatus() == FALSE) {
Syslog('+', "Kicking user out, the BBS is closed");
Quick_Bye(0);
}
clear();
DisplayLogo();
2001-11-02 22:34:32 +00:00
colour(YELLOW, BLACK);
2001-08-17 05:46:24 +00:00
printf("MBSE BBS v%s (Release: %s)\n", VERSION, ReleaseDate);
2001-11-02 22:34:32 +00:00
colour(WHITE, BLACK);
printf("%s\n\n", COPYRIGHT);
2001-08-17 05:46:24 +00:00
/*
* Check if this port is available.
*/
sprintf(temp, "%s/etc/ttyinfo.data", getenv("MBSE_ROOT"));
2001-10-22 17:33:55 +00:00
iNode = 0;
2001-08-17 05:46:24 +00:00
if ((pTty = fopen(temp, "r")) == NULL) {
WriteError("Can't read %s", temp);
} else {
fread(&ttyinfohdr, sizeof(ttyinfohdr), 1, pTty);
while (fread(&ttyinfo, ttyinfohdr.recsize, 1, pTty) == 1) {
2001-10-22 17:33:55 +00:00
iNode++;
if (strcmp(ttyinfo.tty, pTTY) == 0)
2001-08-17 05:46:24 +00:00
break;
}
fclose(pTty);
if ((strcmp(ttyinfo.tty, pTTY) != 0) || (!ttyinfo.available)) {
Syslog('+', "No BBS allowed on port \"%s\"", pTTY);
printf("No BBS on this port allowed!\n\n");
Quick_Bye(0);
}
2001-10-22 17:33:55 +00:00
Syslog('b', "Node number %d", iNode);
2001-08-17 05:46:24 +00:00
/*
* Ask whether to display Connect String
*/
2001-11-02 22:34:32 +00:00
if (CFG.iConnectString) {
2001-08-17 05:46:24 +00:00
/* Connected on port */
2001-11-02 22:34:32 +00:00
colour(CYAN, BLACK);
2001-08-17 05:46:24 +00:00
printf("%s\"%s\" ", (char *) Language(348), ttyinfo.comment);
/* on */
printf("%s %s\n", (char *) Language(135), ctime(&ltime));
}
}
sprintf(sMailbox, "mailbox");
2001-11-02 22:34:32 +00:00
colour(LIGHTGRAY, BLACK);
2001-08-17 05:46:24 +00:00
user();
return 0;
}