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

247 lines
6.3 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
*
*****************************************************************************
2004-02-21 17:22:00 +00:00
* Copyright (C) 1997-2004
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"
2001-08-17 05:46:24 +00:00
#include "../lib/mbse.h"
2002-01-07 19:16:03 +00:00
#include "../lib/users.h"
2001-08-17 05:46:24 +00:00
#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"
#include "term.h"
2004-11-03 20:48:45 +00:00
#include "ttyio.h"
#include "openport.h"
2001-11-12 21:42:17 +00:00
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)
{
2004-07-04 13:33:43 +00:00
FILE *pTty;
char *p, *tty, temp[PATH_MAX];
2004-11-03 20:48:45 +00:00
int i, rc;
2004-07-04 13:33:43 +00:00
struct stat sb;
2001-08-17 05:46:24 +00:00
2002-12-05 20:44:38 +00:00
pTTY = calloc(15, sizeof(char));
tty = ttyname(1);
/*
* Find username from the environment
*/
sUnixName[0] = '\0';
if (getenv("LOGNAME") != NULL) {
strncpy(sUnixName, getenv("LOGNAME"), 8);
} else if (getenv("USER") != NULL) {
strcpy(sUnixName, getenv("USER"));
} else {
2004-11-03 20:48:45 +00:00
fprintf(stderr, "No username in environment\n");
2002-12-05 20:44:38 +00:00
Quick_Bye(MBERR_OK);
}
/*
* Get MBSE_ROOT Path and load Config into Memory
*/
FindMBSE();
/*
* Set local time and statistic indexes.
*/
Time_Now = t_start = time(NULL);
l_date = localtime(&Time_Now);
Diw = l_date->tm_wday;
Miy = l_date->tm_mon;
ltime = time(NULL);
/*
* Initialize this client with the server.
*/
do_quiet = TRUE;
2003-09-09 19:39:51 +00:00
InitClient(sUnixName, (char *)"mbsebbs", (char *)"Unknown", CFG.logfile,
CFG.bbs_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
2002-12-05 20:44:38 +00:00
IsDoing("Loging in");
Syslog(' ', " ");
Syslog(' ', "MBSEBBS v%s", VERSION);
2004-11-03 20:48:45 +00:00
if ((rc = rawport()) != 0) {
WriteError("Unable to set raw mode");
Quick_Bye(MBERR_OK);;
}
PUTSTR((char *)"Loading MBSE BBS ...");
2004-11-30 20:07:19 +00:00
Enter(1);
2004-11-03 20:48:45 +00:00
2002-12-05 20:44:38 +00:00
if ((p = getenv("CONNECT")) != NULL)
Syslog('+', "CONNECT %s", p);
if ((p = getenv("CALLER_ID")) != NULL)
if (strncmp(p, "none", 4))
2003-08-04 19:32:07 +00:00
Syslog('+', "CALLER_ID %s", p);
if ((p = getenv("REMOTEHOST")) != NULL)
Syslog('+', "REMOTEHOST %s", p);
if ((p = getenv("TERM")) != NULL)
Syslog('+', "TERM=%s", p);
2005-07-14 19:29:59 +00:00
if ((p = getenv("LANG")) != NULL)
2005-07-14 19:29:25 +00:00
Syslog('+', "LANG=%s", p);
if ((p = getenv("LC_ALL")) != NULL)
Syslog('+', "LC_ALL=%s", p);
2002-12-05 20:44:38 +00:00
/*
* Initialize
*/
InitLanguage();
InitMenu();
memset(&MsgBase, 0, sizeof(MsgBase));
2001-08-17 05:46:24 +00:00
2002-12-05 20:44:38 +00:00
i = getpid();
if ((tty = ttyname(0)) == NULL) {
WriteError("Not at a tty");
2003-12-04 22:07:33 +00:00
Free_Language();
2002-12-05 20:44:38 +00:00
Quick_Bye(MBERR_OK);
}
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);
/*
* Trap signals
*/
2004-11-03 20:48:45 +00:00
for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGPIPE) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
2002-12-05 20:44:38 +00:00
signal(i, (void (*))die);
2004-04-09 18:31:22 +00:00
else if (i == SIGCHLD)
signal(i, SIG_DFL);
2002-12-05 20:44:38 +00:00
}
/*
* Default set the terminal to ANSI mode. If your logo
* is in color, the user will see color no mather what.
*/
2004-02-21 17:22:00 +00:00
TermInit(1, 80, 24);
2004-11-03 20:48:45 +00:00
2002-12-05 20:44:38 +00:00
/*
* 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");
2003-12-04 22:07:33 +00:00
Free_Language();
2002-12-05 20:44:38 +00:00
Quick_Bye(MBERR_OK);
}
clear();
DisplayLogo();
2004-11-03 20:48:45 +00:00
sprintf(temp, "MBSE BBS v%s (Release: %s) on %s/%s", VERSION, ReleaseDate, OsName(), OsCPU());
poutCR(YELLOW, BLACK, temp);
pout(WHITE, BLACK, (char *)COPYRIGHT);
Enter(2);
2002-12-05 20:44:38 +00:00
2004-07-04 13:33:43 +00:00
/*
* Check users homedirectory, some *nix systems let users in if no
* homedirectory exists
*/
sprintf(temp, "%s/%s", CFG.bbs_usersdir, sUnixName);
if (stat(temp, &sb)) {
2004-11-03 20:48:45 +00:00
sprintf(temp, "No homedirectory\r\n\r\n");
PUTSTR(temp);
2004-07-04 13:33:43 +00:00
WriteError("homedirectory %s doesn't exist", temp);
Quick_Bye(MBERR_OK);
}
2002-12-05 20:44:38 +00:00
/*
* Check if this port is available. In iNode we set a fake
* line number, this will be used by doors.
*/
sprintf(temp, "%s/etc/ttyinfo.data", getenv("MBSE_ROOT"));
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) {
if (strcmp(ttyinfo.tty, pTTY) == 0)
break;
2001-08-17 05:46:24 +00:00
}
2002-12-05 20:44:38 +00:00
fclose(pTty);
2001-08-17 05:46:24 +00:00
2002-12-05 20:44:38 +00:00
if ((strcmp(ttyinfo.tty, pTTY) != 0) || (!ttyinfo.available)) {
Syslog('+', "No BBS allowed on port \"%s\"", pTTY);
2004-11-03 20:48:45 +00:00
sprintf(temp, "No BBS on this port allowed!\r\n\r\n");
PUTSTR(temp);
2003-12-04 22:07:33 +00:00
Free_Language();
2002-12-05 20:44:38 +00:00
Quick_Bye(MBERR_OK);
}
2001-08-17 05:46:24 +00:00
2002-12-05 20:44:38 +00:00
/*
* Display Connect String if turned on.
2001-08-17 05:46:24 +00:00
*/
2002-12-05 20:44:38 +00:00
if (CFG.iConnectString) {
/* Connected on port */
2004-11-03 20:48:45 +00:00
sprintf(temp, "%s\"%s\" ", (char *) Language(348), ttyinfo.comment);
pout(CYAN, BLACK, temp);
2002-12-05 20:44:38 +00:00
/* on */
2004-11-03 20:48:45 +00:00
sprintf(temp, "%s %s", (char *) Language(135), ctime(&ltime));
PUTSTR(temp);
Enter(1);
2001-08-17 05:46:24 +00:00
}
2002-12-05 20:44:38 +00:00
}
2001-08-17 05:46:24 +00:00
/*
* Some debugging for me
*/
2005-04-03 14:12:12 +00:00
Syslog('b', "setlocale(LC_ALL, NULL) returns \"%s\"", printable(setlocale(LC_ALL, NULL), 0));
2004-11-29 21:52:59 +00:00
/* Next is not usefull */
2005-04-03 11:58:49 +00:00
Syslog('b', "nl_langinfo(LC_CTYPE) returns \"%s\"", printable(nl_langinfo(LC_CTYPE), 0));
2002-12-05 20:44:38 +00:00
sprintf(sMailbox, "mailbox");
colour(LIGHTGRAY, BLACK);
user();
return 0;
2001-08-17 05:46:24 +00:00
}