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/misc.c

236 lines
5.7 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
2001-11-08 22:45:15 +00:00
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: Misc functions
*
*****************************************************************************
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 "funcs.h"
#include "input.h"
2001-08-17 05:46:24 +00:00
#include "language.h"
#include "misc.h"
#include "timeout.h"
#include "exitinfo.h"
2001-11-02 22:08:33 +00:00
extern char *StartTime; /* Time user logged in */
/*
* Last caller action flags
*/
int LC_Download = FALSE;
int LC_Upload = FALSE;
int LC_Read = FALSE;
int LC_Wrote = FALSE;
int LC_Chat = FALSE;
int LC_Olr = FALSE;
int LC_Door = FALSE;
2001-08-17 05:46:24 +00:00
int ChkFiles()
{
FILE *fp;
char *temp;
time_t Now;
temp = calloc(PATH_MAX, sizeof(char));
/*
* Check if users.data exists, if not create a new one.
*/
sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp,"rb")) == NULL) {
if ((fp = fopen(temp,"wb")) == NULL) {
WriteError("$Can't create %s", temp);
ExitClient(MBERR_INIT_ERROR);
} else {
usrconfighdr.hdrsize = sizeof(usrconfighdr);
usrconfighdr.recsize = sizeof(usrconfig);
fwrite(&usrconfighdr, sizeof(usrconfighdr), 1, fp);
fclose(fp);
2001-08-17 05:46:24 +00:00
}
} else {
fclose(fp);
}
chmod(temp, 0660);
/*
* Check if sysinfo.data exists, if not, create a new one.
*/
sprintf(temp, "%s/etc/sysinfo.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "rb")) == NULL) {
if ((fp = fopen(temp, "wb")) == NULL) {
WriteError("$ChkFiles: Can't create %s", temp);
} else {
memset((char *)&SYSINFO, 0, sizeof(SYSINFO));
Now = time(NULL);
SYSINFO.StartDate = Now;
fwrite(&SYSINFO, sizeof(SYSINFO), 1, fp);
fclose(fp);
2001-08-17 05:46:24 +00:00
}
} else {
fclose(fp);
}
chmod(temp, 0660);
free(temp);
return 1;
2001-08-17 05:46:24 +00:00
}
void DisplayLogo()
{
FILE *pLogo;
char *sString, *temp;
temp = calloc(PATH_MAX, sizeof(char));
sString = calloc(81, sizeof(char));
sprintf(temp, "%s/%s", CFG.bbs_txtfiles, CFG.welcome_logo);
if ((pLogo = fopen(temp,"rb")) == NULL)
WriteError("$DisplayLogo: Can't open %s", temp);
else {
while (fgets(sString, 80, pLogo) != NULL)
printf("%s", sString);
fclose(pLogo);
}
free(sString);
free(temp);
2001-08-17 05:46:24 +00:00
}
/*
* Update a variable in the exitinfo file.
*/
void Setup(char *Option, char *variable)
{
ReadExitinfo();
strcpy(Option, variable);
WriteExitinfo();
2001-08-17 05:46:24 +00:00
}
2001-11-02 22:08:33 +00:00
void SaveLastCallers()
2001-08-17 05:46:24 +00:00
{
FILE *pGLC;
char *sFileName, sFileDate[9], sDate[9];
struct stat statfile;
/*
* First check if we passed midnight, in that case we create a fresh file.
*/
sFileName = calloc(PATH_MAX, sizeof(char));
sprintf(sFileName,"%s/etc/lastcall.data", getenv("MBSE_ROOT"));
stat(sFileName, &statfile);
sprintf(sFileDate,"%s", StrDateDMY(statfile.st_mtime));
sprintf(sDate,"%s", (char *) GetDateDMY());
if ((strcmp(sDate,sFileDate)) != 0) {
unlink(sFileName);
Syslog('+', "Erased old lastcall.data");
}
/*
* Check if file exists, if not create the file and write the fileheader.
*/
if ((pGLC = fopen(sFileName, "r")) == NULL) {
if ((pGLC = fopen(sFileName, "w")) != NULL) {
LCALLhdr.hdrsize = sizeof(LCALLhdr);
LCALLhdr.recsize = sizeof(LCALL);
fwrite(&LCALLhdr, sizeof(LCALLhdr), 1, pGLC);
fclose(pGLC);
Syslog('+', "Created new lastcall.data");
2001-08-17 05:46:24 +00:00
}
} else {
fclose(pGLC);
}
chmod(sFileName, 0660);
/*
* Now append a record
*/
if ((pGLC = fopen(sFileName,"a+")) == NULL) {
WriteError("$Can't open %s", sFileName);
return;
} else {
ReadExitinfo();
memset(&LCALL, 0, sizeof(LCALL));
sprintf(LCALL.UserName,"%s", exitinfo.sUserName);
sprintf(LCALL.Handle,"%s", exitinfo.sHandle);
sprintf(LCALL.Name, "%s", exitinfo.Name);
sprintf(LCALL.TimeOn,"%s", StartTime);
sprintf(LCALL.Device,"%s", pTTY);
LCALL.SecLevel = exitinfo.Security.level;
LCALL.Calls = exitinfo.iTotalCalls;
LCALL.CallTime = exitinfo.iConnectTime;
LCALL.Download = LC_Download;
LCALL.Upload = LC_Upload;
LCALL.Read = LC_Read;
LCALL.Wrote = LC_Wrote;
LCALL.Chat = LC_Chat;
LCALL.Olr = LC_Olr;
LCALL.Door = LC_Door;
sprintf(LCALL.Speed, "%s", ttyinfo.speed);
/* If true then set hidden so it doesn't display in lastcallers function */
LCALL.Hidden = exitinfo.Hidden;
sprintf(LCALL.Location,"%s", exitinfo.sLocation);
rewind(pGLC); /* ???????????? */
fwrite(&LCALL, sizeof(LCALL), 1, pGLC);
fclose(pGLC);
}
free(sFileName);
2001-08-17 05:46:24 +00:00
}
/* Gets Date for GetLastCallers(), returns DD:Mmm */
char *GLCdate()
{
static char GLcdate[15];
2001-08-17 05:46:24 +00:00
Time_Now = time(NULL);
l_date = localtime(&Time_Now);
sprintf(GLcdate,"%02d-", l_date->tm_mday);
2001-08-17 05:46:24 +00:00
strcat(GLcdate,GetMonth(l_date->tm_mon+1));
return(GLcdate);
2001-08-17 05:46:24 +00:00
}