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

2232 lines
52 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: All the file 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"
2004-05-06 21:33:13 +00:00
#include "../lib/mbsedb.h"
2001-08-17 05:46:24 +00:00
#include "filesub.h"
#include "file.h"
#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"
#include "whoson.h"
2001-08-17 05:46:24 +00:00
#include "change.h"
2003-04-12 11:12:26 +00:00
#include "dispfile.h"
#include "term.h"
2004-11-03 20:48:45 +00:00
#include "ttyio.h"
#include "openport.h"
2001-08-17 05:46:24 +00:00
extern long arecno; /* File area number in xxxScan() functions */
int Strlen = 0;
int FileRecno = 0;
2001-11-12 21:42:17 +00:00
int CheckFile(char *, int);
int CheckFile(char *File, int iArea)
{
2004-05-06 21:33:13 +00:00
struct _fdbarea *fdb_area = NULL;
if ((fdb_area = mbsedb_OpenFDB(iArea, 30)) == NULL)
return FALSE;
/*
* Check long and short filenames, case insensitive
*/
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
if (((strcasecmp(fdb.Name, File)) == 0) || ((strcasecmp(fdb.LName, File)) == 0)) {
mbsedb_CloseFDB(fdb_area);
return TRUE;
}
}
mbsedb_CloseFDB(fdb_area);
2004-03-06 21:48:41 +00:00
return FALSE;
2001-11-12 21:42:17 +00:00
}
2001-08-17 05:46:24 +00:00
/*
* Show filelist from current area, called from the menu.
*/
void File_List()
{
2004-11-03 20:48:45 +00:00
int FileCount = 0;
unsigned FileBytes = 0;
_Tag T;
2004-05-06 21:33:13 +00:00
struct _fdbarea *fdb_area = NULL;
2004-11-03 20:48:45 +00:00
char temp[81];
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
iLineCount = 0;
WhosDoingWhat(FILELIST, NULL);
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
Syslog('+', "Listing File Area # %d", iAreaNumber);
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
if (Access(exitinfo.Security, area.LTSec) == FALSE) {
2004-11-03 20:48:45 +00:00
Enter(1);
2004-03-06 21:48:41 +00:00
/* You don't have enough security to list this area */
2004-11-03 20:48:45 +00:00
pout(YELLOW, BLACK, (char *) Language(236));
Enter(2);
2004-03-06 21:48:41 +00:00
Pause();
return;
}
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
InitTag();
2001-08-17 05:46:24 +00:00
2004-05-06 21:33:13 +00:00
if ((fdb_area = mbsedb_OpenFDB(iAreaNumber, 30)) == NULL)
return;
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
clear();
Header();
if (iLC(2) == 1) {
2004-05-06 21:33:13 +00:00
mbsedb_CloseFDB(fdb_area);
2004-03-06 21:48:41 +00:00
return;
}
2001-08-17 05:46:24 +00:00
2004-05-06 21:33:13 +00:00
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
2004-03-06 21:48:41 +00:00
memset(&T, 0, sizeof(T));
T.Area = iAreaNumber;
T.Active = FALSE;
T.Size = fdb.Size;
strncpy(T.SFile, fdb.Name, 12);
strncpy(T.LFile, fdb.LName, 80);
SetTag(T);
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
if (ShowOneFile() == 1) {
2004-05-06 21:33:13 +00:00
mbsedb_CloseFDB(fdb_area);
2004-03-06 21:48:41 +00:00
return;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if (fdb.Deleted) {
2004-03-06 21:48:41 +00:00
/* D E L E T E D */ /* Uploaded by: */
2004-11-03 20:48:45 +00:00
sprintf(temp, " -- %-12s %s [%4ld] %s%s\n", fdb.Name, (char *) Language(239),
2004-03-06 21:48:41 +00:00
fdb.TimesDL, (char *) Language(238), fdb.Uploader);
2004-11-03 20:48:45 +00:00
PUTSTR(temp);
}
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
FileCount++; /* Increase File Counter by 1 */
FileBytes += fdb.Size; /* Increase File Byte Count */
}
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
Mark();
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
Enter(1);
2004-03-06 21:48:41 +00:00
/* Total Files: */
2004-11-03 20:48:45 +00:00
sprintf(temp, "%s%d / %d bytes", (char *) Language(242), FileCount, FileBytes);
pout(LIGHTCYAN, BLACK, temp);
Enter(2);
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
iLineCount = 0;
2004-05-06 21:33:13 +00:00
mbsedb_CloseFDB(fdb_area);
2004-03-06 21:48:41 +00:00
Pause();
2001-08-17 05:46:24 +00:00
}
/*
* Download files already tagged, called from the menu.
*/
void Download(void)
{
DIR *dirp;
struct dirent *dp;
2004-05-06 21:33:13 +00:00
FILE *tf, *fd;
2004-11-03 20:48:45 +00:00
int i, err, Count = 0, OldArea;
char *symTo, *symFrom, *temp;
long Size = 0, CostSize = 0;
time_t ElapstimeStart, ElapstimeFin, iTime;
long iTransfer = 0;
2004-05-06 21:33:13 +00:00
struct _fdbarea *fdb_area = NULL;
Enter(2);
OldArea = iAreaNumber;
2003-10-11 21:22:16 +00:00
WhosDoingWhat(DOWNLOAD, NULL);
2004-05-08 14:55:40 +00:00
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "-rf %s/%s/tag", CFG.bbs_usersdir, exitinfo.Name);
execute_pth((char *)"rm", temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
sprintf(temp, "%s/%s/tag", CFG.bbs_usersdir, exitinfo.Name);
CheckDir(temp);
if ((tf = fopen("taglist", "r+")) == NULL) {
Syslog('+', "Download command but no files marked");
/* No files marked for download. */
2004-11-03 20:48:45 +00:00
pout(LIGHTRED, BLACK, (char *) Language(258));
2001-08-17 05:46:24 +00:00
Enter(2);
Pause();
2004-11-03 20:48:45 +00:00
free(temp);
return;
}
symTo = calloc(PATH_MAX, sizeof(char));
symFrom = calloc(PATH_MAX, sizeof(char));
/* Checking your marked downloads, please wait... */
2004-11-03 20:48:45 +00:00
pout(LIGHTMAGENTA, BLACK, (char *) Language(255));
Enter(2);
ReadExitinfo();
while (fread(&Tag, sizeof(Tag), 1, tf) == 1) {
if (Tag.Active) {
SetFileArea(Tag.Area);
/*
2004-03-06 21:48:41 +00:00
* Check password for selected file FIXME: Where???
*/
2004-03-06 21:48:41 +00:00
memset(&fdb, 0, sizeof(fdb));
2004-05-06 21:33:13 +00:00
if ((fdb_area = mbsedb_OpenFDB(Tag.Area, 30)) != NULL) {
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
if (strcmp(fdb.LName, Tag.LFile) == 0)
break;
}
mbsedb_CloseFDB(fdb_area);
}
2004-03-06 21:48:41 +00:00
if (strcmp(fdb.LName, Tag.LFile) == 0) {
Syslog('b', "Found file %s in area %d", fdb.LName, Tag.Area);
if (fdb.Deleted) {
/* Sorry that file is unavailable for download */
2004-11-03 20:48:45 +00:00
sprintf(temp, "%s (%s)", (char *) Language(248), fdb.LName);
poutCR(CFG.HiliteF, CFG.HiliteB, temp);
Tag.Active = FALSE;
2004-03-06 21:48:41 +00:00
Syslog('+', "File %s in area %d unavailable for download, deleted", fdb.LName, Tag.Area);
}
}
2001-08-17 05:46:24 +00:00
if (Tag.Active) {
/*
* Create/Append file description list while we're
* busy checking. If the users doesn't want it we
* can unlink it aftwerwards. We also insert CR
* characters to please the poor DOS (M$oft) users.
*/
sprintf(symTo, "./tag/filedesc.%ld", exitinfo.Downloads % 256);
if ((fd = fopen(symTo, "a")) != NULL) {
2004-03-06 21:48:41 +00:00
fprintf(fd, "%s (%s)\r\n", fdb.LName, fdb.Name);
for (i = 0; i < 25; i++) {
2004-03-06 21:48:41 +00:00
if (strlen(fdb.Desc[i]) > 1)
fprintf(fd, " %s\r\n", fdb.Desc[i]);
}
fprintf(fd, "\r\n");
fclose(fd);
Syslog('b', "Added info to %s", symTo);
} else {
WriteError("Can't add info to %s", symTo);
}
2001-08-17 05:46:24 +00:00
/*
* Make a symlink to the users download dir.
* First unlink, in case there was an old one.
* The shortname is linked to the original longname.
*/
chdir("./tag");
unlink(Tag.SFile);
sprintf(symFrom, "%s", Tag.SFile);
sprintf(symTo, "%s/%s", sAreaPath, Tag.LFile);
if (symlink(symTo, symFrom)) {
WriteError("$Can't create symlink %s %s %d", symTo, symFrom, errno);
Tag.Active = FALSE;
} else {
Syslog('b', "Created symlink %s -> %s", symFrom, symTo);
}
if ((access(symFrom, R_OK)) != 0) {
/*
* Extra check, is symlink really there?
*/
WriteError("Symlink %s check failed, unmarking download", symFrom);
Tag.Active = FALSE;
}
Home();
}
2001-08-17 05:46:24 +00:00
if (!Tag.Active) {
/*
* Update the download active flag in the
* taglist
*/
fseek(tf, - sizeof(Tag), SEEK_CUR);
fwrite(&Tag, sizeof(Tag), 1, tf);
Syslog('b', "Download file %s marked inactive in taglist", Tag.LFile);
} else {
/*
* Count file and sizes.
*/
Count++;
2004-03-06 21:48:41 +00:00
Size += fdb.Size;
if (!area.Free)
CostSize += fdb.Size;
}
2001-08-17 05:46:24 +00:00
}
}
fclose(tf);
/*
* If anything left to download...
*/
if (!Count) {
SetFileArea(OldArea);
unlink("taglist");
/* No files marked for download */
2004-11-03 20:48:45 +00:00
pout(LIGHTRED, BLACK, (char *) Language(258));
Enter(2);
2001-08-17 05:46:24 +00:00
Pause();
free(symTo);
free(symFrom);
2004-11-03 20:48:45 +00:00
free(temp);
Syslog('+', "No files left to download");
return;
}
/* You have */ /* files( */ /* bytes) marked for download */
2004-11-03 20:48:45 +00:00
sprintf(temp, "%s %d %s%ld %s", (char *) Language(249), Count, (char *) Language(280), Size, (char *) Language(281));
pout(YELLOW, BLACK, temp);
Enter(2);
/*
* If user has no default protocol, make sure he has one.
*/
if (!ForceProtocol()) {
SetFileArea(OldArea);
free(symTo);
free(symFrom);
2004-11-03 20:48:45 +00:00
free(temp);
return;
}
2001-08-17 05:46:24 +00:00
if (!CheckBytesAvailable(CostSize)) {
SetFileArea(OldArea);
free(symTo);
free(symFrom);
2004-11-03 20:48:45 +00:00
free(temp);
return;
}
Pause();
clear();
/* File(s) : */
2004-11-03 20:48:45 +00:00
pout(YELLOW, BLACK, (char *) Language(349)); sprintf(temp, "%d", Count); PUTSTR(temp); Enter(1);
/* Size : */
2004-11-03 20:48:45 +00:00
pout( CYAN, BLACK, (char *) Language(350)); sprintf(temp, "%lu", Size); PUTSTR(temp); Enter(1);
/* Protocol : */
2004-11-03 20:48:45 +00:00
pout( CYAN, BLACK, (char *) Language(351)); sprintf(temp, "%s", sProtName); PUTSTR(temp); Enter(1);
Syslog('+', "Download tagged files start, protocol: %s", sProtName);
2004-11-03 20:48:45 +00:00
PUTSTR(sProtAdvice);
Enter(2);
/*
* Wait a while before download
*/
sleep(2);
ElapstimeStart = time(NULL);
2001-08-17 05:46:24 +00:00
/*
* Transfer the files. Set the Client/Server time at the maximum
* time the user has plus 10 minutes. The overall timer 10 seconds
* less. Not a nice but working solution.
*/
alarm_set(((exitinfo.iTimeLeft + 10) * 60) - 10);
Altime((exitinfo.iTimeLeft + 10) * 60);
sprintf(temp, "%s/%s/tag", CFG.bbs_usersdir, exitinfo.Name);
if ((dirp = opendir(temp)) == NULL) {
WriteError("$Download: Can't open dir: %s", temp);
free(temp);
} else {
chdir(temp);
free(temp);
temp = NULL;
while ((dp = readdir(dirp)) != NULL ) {
if (*(dp->d_name) != '.') {
if (temp != NULL) {
temp = xstrcat(temp, (char *)" ");
temp = xstrcat(temp, dp->d_name);
} else {
temp = xstrcpy(dp->d_name);
}
}
}
if (temp != NULL) {
2004-03-02 20:47:23 +00:00
if ((err = execute_str(sProtDn, temp, NULL, NULL, NULL, NULL))) {
2004-11-03 20:48:45 +00:00
WriteError("$Download error %d, prot: %s", err, sProtDn);
}
2004-11-03 20:48:45 +00:00
/*
* Restore rawport
*/
rawport();
free(temp);
} else {
WriteError("No filebatch created");
2001-08-17 05:46:24 +00:00
}
closedir(dirp);
}
Altime(0);
alarm_off();
alarm_on();
Home();
ElapstimeFin = time(NULL);
/*
* Get time from Before Download and After Download to get
* download time, if the time is zero, it will be one.
*/
iTime = ElapstimeFin - ElapstimeStart;
if (!iTime)
iTime = 1;
/*
* Checking the successfull sent files, they are missing from
* the ./tag directory. Failed files are still there.
*/
2004-11-03 20:48:45 +00:00
PUTCHAR('\r');
/* Updating download counters, please wait ... */
2004-11-03 20:48:45 +00:00
pout(LIGHTCYAN, BLACK, (char *) Language(352));
Enter(2);
Count = Size = 0;
if ((tf = fopen("taglist", "r+")) != NULL) {
while (fread(&Tag, sizeof(Tag), 1, tf) == 1) {
if (Tag.Active) {
sprintf(symTo, "./tag/%s", Tag.SFile);
/*
* If symlink is gone the file is sent.
*/
if ((access(symTo, R_OK)) != 0) {
Syslog('+', "File %s from area %d sent ok", Tag.LFile, Tag.Area);
Tag.Active = FALSE;
fseek(tf, - sizeof(Tag), SEEK_CUR);
fwrite(&Tag, sizeof(Tag), 1, tf);
/*
* Update the download counter and the last download date.
*/
SetFileArea(Tag.Area);
2004-05-06 21:33:13 +00:00
if ((fdb_area = mbsedb_OpenFDB(Tag.Area, 30))) {
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
if (strcmp(fdb.LName, Tag.LFile) == 0)
break;
}
Size += fdb.Size;
fdb.TimesDL++;
fdb.LastDL = time(NULL);
if (mbsedb_LockFDB(fdb_area, 30)) {
fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR);
fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp);
mbsedb_UnlockFDB(fdb_area);
}
mbsedb_CloseFDB(fdb_area);
Count++;
}
} else {
Syslog('+', "Failed to sent %s from area %d", Tag.LFile, Tag.Area);
2001-08-17 05:46:24 +00:00
}
}
}
fclose(tf);
}
/*
* Work out transfer rate in seconds by dividing the
* Size of the File by the amount of time it took to download
* the file.
*/
iTransfer = Size / iTime;
Syslog('+', "Download time %ld seconds (%lu cps), %d files", iTime, iTransfer, Count);
/*
* Update the users record.
*/
ReadExitinfo();
exitinfo.Downloads += Count; /* Increase download counter */
exitinfo.DownloadK += (Size / 1024); /* Increase amount download today */
/*
* Minus the amount downloaded today from downloadktoday
* if less than zero, it won't let the user download anymore.
*/
if (LIMIT.DownK || LIMIT.DownF) {
exitinfo.DownloadKToday -= (Size / 1024);
exitinfo.iTransferTime = iTransfer;
}
WriteExitinfo();
Pause();
SetFileArea(OldArea);
free(symTo);
free(symFrom);
2001-08-17 05:46:24 +00:00
}
/*
* Show Raw directory
*/
void File_RawDir(char *OpData)
{
2004-11-03 20:48:45 +00:00
DIR *dirp;
char *FileName, *temp, temp2[81];
int iFileCount = 0, LineCount = 2, iBytes = 0;
struct dirent *dp;
struct stat statfile;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
FileName = calloc(PATH_MAX, sizeof(char));
temp = calloc(PATH_MAX, sizeof(char));
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if ((strcmp(OpData, "/F")) == 0)
strcpy(temp, sAreaPath);
else
strcpy(temp, OpData);
if ((dirp = opendir(temp)) == NULL) {
clear();
WriteError("$RawDir: Can't open dir: %s", temp);
Enter(1);
pout(LIGHTRED, BLACK, (char *)"Can't open directory for raw listing!");
Enter(2);
Pause();
} else {
clear();
/* Filename Size Date */
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(261));
Enter(1);
fLine(78);
while ((dp = readdir( dirp )) != NULL ) {
sprintf(FileName, "%s/%s", temp, dp->d_name);
if (*(dp->d_name) != '.') {
iFileCount++;
if (stat(FileName, &statfile) != 0) {
pout(LIGHTRED, BLACK, (char *)"Can't stat file ");
PUTSTR(FileName);
} else {
iBytes += statfile.st_size;
sprintf(temp2, "%-54s " , dp->d_name);
pout(YELLOW, BLACK, temp2);
sprintf(temp2, "%-12ld", (long)(statfile.st_size));
pout(LIGHTMAGENTA, BLACK, temp2);
sprintf(temp2, "%-10s", StrDateDMY(statfile.st_mtime));
pout(LIGHTGREEN, BLACK, temp2);
}
Enter(1);
LineCount++;
if (LineCount == exitinfo.iScreenLen) {
Pause();
LineCount = 0;
}
}
2001-08-17 05:46:24 +00:00
}
2004-11-03 20:48:45 +00:00
colour(CFG.HiliteF, CFG.HiliteB);
fLine(78);
/* Total Files: */ /* Bytes */
sprintf(temp2, "%s %d, %d %s", (char *) Language(242), iFileCount, iBytes, (char *) Language(354));
pout(LIGHTGREEN, BLACK, temp2);
Enter(2);
Pause();
closedir(dirp);
}
free(temp);
free(FileName);
2001-08-17 05:46:24 +00:00
}
/*
* Search for keyword, called from menu.
*/
int KeywordScan()
{
2004-05-06 21:33:13 +00:00
FILE *pAreas;
2004-03-06 21:48:41 +00:00
int i, z, y, Found, Count = 0;
char *Name, *tmpname, *BigDesc, temp[81];
_Tag T;
unsigned long OldArea;
2004-05-06 21:33:13 +00:00
struct _fdbarea *fdb_area = NULL;
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
Name = calloc(81, sizeof(char));
tmpname = calloc(81, sizeof(char));
BigDesc = calloc(1230, sizeof(char));
OldArea = iAreaNumber;
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
iLineCount = 2; /* Reset Line Counter to Zero */
arecno = 1; /* Reset Area Number to One */
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
Enter(2);
/* Enter keyword to use for Search: */
2004-11-03 20:48:45 +00:00
pout(LIGHTCYAN, BLACK, (char *) Language(267));
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
colour(CFG.InputColourF, CFG.InputColourB);
GetstrC(Name, 80);
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
if ((strcmp(Name, "")) == 0)
return 0;
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
strcpy(tmpname, tl(Name));
strcpy(Name, "");
y = strlen(tmpname);
for (z = 0; z < y; z++) {
if (tmpname[z] != '*') {
sprintf(temp, "%c", tmpname[z]);
strcat(Name, temp);
2001-08-17 05:46:24 +00:00
}
2004-03-06 21:48:41 +00:00
}
Syslog('+', "KeywordScan(): \"%s\"", Name);
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
clear();
/* File search by keyword */
2004-11-03 20:48:45 +00:00
pout(WHITE, BLACK, (char *) Language(268));
2004-03-06 21:48:41 +00:00
Enter(1);
InitTag();
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
if ((pAreas = OpenFareas(FALSE)) == NULL)
return 0;
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
while (fread(&area, areahdr.recsize, 1, pAreas) == 1) {
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
if ((Access(exitinfo.Security, area.LTSec)) && (area.Available) && (strlen(area.Password) == 0)) {
2001-08-17 05:46:24 +00:00
2004-05-06 21:33:13 +00:00
if ((fdb_area = mbsedb_OpenFDB(arecno, 30))) {
2004-03-06 21:48:41 +00:00
Nopper();
Found = FALSE;
Sheader();
2001-08-17 05:46:24 +00:00
2004-05-06 21:33:13 +00:00
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
2004-03-06 21:48:41 +00:00
for (i = 0; i < 25; i++)
sprintf(BigDesc, "%s%s", BigDesc, *(fdb.Desc + i));
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
if ((strstr(fdb.Name,Name) != NULL) || (strstr(tl(BigDesc), Name) != NULL)) {
if (!Found) {
Enter(2);
if (iLC(2) == 1) {
free(BigDesc);
free(Name);
free(tmpname);
SetFileArea(OldArea);
return 1;
}
Found = TRUE;
}
memset(&T, 0, sizeof(T));
T.Area = arecno;
T.Active = FALSE;
T.Size = fdb.Size;
strncpy(T.SFile, fdb.Name, 12);
strncpy(T.LFile, fdb.LName, 80);
SetTag(T);
Count++;
if (ShowOneFile() == 1) {
free(BigDesc);
free(Name);
free(tmpname);
SetFileArea(OldArea);
return 1;
}
}
strcpy(BigDesc, ""); /* Clear BigDesc */
} /* while */
2004-05-06 21:33:13 +00:00
mbsedb_CloseFDB(fdb_area);
2004-03-06 21:48:41 +00:00
if (Found) {
Enter(2);
if (iLC(2) == 1) {
free(BigDesc);
free(Name);
free(tmpname);
SetFileArea(OldArea);
return 1;
}
}
} /* End check for LTSec */
} /* if access */
arecno++; /* Go to next file area */
} /* End of Main */
Syslog('+', "Found %d files", Count);
free(BigDesc);
free(Name);
free(tmpname);
fclose(pAreas);
2004-11-03 20:48:45 +00:00
Enter(1);
2004-03-06 21:48:41 +00:00
if (Count)
Mark();
else
Pause();
SetFileArea(OldArea);
return 1;
2001-08-17 05:46:24 +00:00
}
/*
* Search for a file, called from the menu.
*/
int FilenameScan()
{
2004-05-06 21:33:13 +00:00
FILE *pAreas;
int Found, Count = 0;
2004-03-08 20:51:04 +00:00
char mask[256];
char *Name;
_Tag T;
unsigned long OldArea;
2004-05-06 21:33:13 +00:00
struct _fdbarea *fdb_area = NULL;
2001-08-17 05:46:24 +00:00
Name = calloc(81, sizeof(char));
OldArea = iAreaNumber;
2001-08-17 05:46:24 +00:00
iLineCount = 2; /* Reset Line Counter to Zero */
arecno = 1; /* Reset Area Number to One */
2001-08-17 05:46:24 +00:00
Enter(2);
/* Accepts wildcards such as : *.zip, *.gz, *.* */
2004-11-03 20:48:45 +00:00
pout(WHITE, BLACK, (char *) Language(269));
2001-08-17 05:46:24 +00:00
Enter(2);
/* Enter filename to search for : */
2004-11-03 20:48:45 +00:00
pout(LIGHTCYAN, BLACK, (char *) Language(271));
2001-08-17 05:46:24 +00:00
colour(CFG.InputColourF, CFG.InputColourB);
GetstrC(Name, 80);
2001-08-17 05:46:24 +00:00
if ((strcmp(Name, "")) == 0) {
free(Name);
return 0;
}
2001-08-17 05:46:24 +00:00
2004-03-08 20:51:04 +00:00
strcpy(mask, re_mask(Name, TRUE));
Syslog('+', "FilenameScan(): \"%s\" -> \"%s\"", Name, mask);
free(Name);
re_comp(mask);
2001-08-17 05:46:24 +00:00
clear();
/* File Search by Filename */
2004-11-03 20:48:45 +00:00
pout(WHITE, BLACK, (char *) Language(272));
Enter(1);
InitTag();
2001-08-17 05:46:24 +00:00
if ((pAreas = OpenFareas(FALSE)) == NULL)
return 0;
2001-08-17 05:46:24 +00:00
while (fread(&area, areahdr.recsize, 1, pAreas) == 1) {
if ((Access(exitinfo.Security, area.LTSec)) && (area.Available) && (strlen(area.Password) == 0)) {
2001-08-17 05:46:24 +00:00
2004-05-06 21:33:13 +00:00
if ((fdb_area = mbsedb_OpenFDB(arecno, 30))) {
Found = FALSE;
Sheader();
Nopper();
2001-08-17 05:46:24 +00:00
2004-05-06 21:33:13 +00:00
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
2004-03-06 21:48:41 +00:00
if (re_exec(fdb.Name) || re_exec(fdb.LName)) {
if (!Found) {
Enter(2);
if (iLC(2) == 1) {
SetFileArea(OldArea);
return 1;
}
Found = TRUE;
}
2001-08-17 05:46:24 +00:00
memset(&T, 0, sizeof(T));
T.Area = arecno;
T.Active = FALSE;
2004-03-06 21:48:41 +00:00
T.Size = fdb.Size;
strncpy(T.SFile, fdb.Name, 12);
strncpy(T.LFile, fdb.LName, 81);
SetTag(T);
Count++;
if (ShowOneFile() == 1) {
SetFileArea(OldArea);
return 1;
}
}
2001-08-17 05:46:24 +00:00
} /* End of while */
2001-08-17 05:46:24 +00:00
2004-05-06 21:33:13 +00:00
mbsedb_CloseFDB(fdb_area);
if (Found) {
Enter(2);
if (iLC(2) == 1) {
SetFileArea(OldArea);
return 1;
}
}
2001-08-17 05:46:24 +00:00
} /* End Check for LTSec */
} /* if access */
arecno++; /* Go to next file area */
2001-08-17 05:46:24 +00:00
} /* End of Main */
2001-08-17 05:46:24 +00:00
Syslog('+', "Found %d files", Count);
fclose(pAreas);
2004-11-03 20:48:45 +00:00
Enter(1);
if (Count)
Mark();
else
Pause();
SetFileArea(OldArea);
return 1;
2001-08-17 05:46:24 +00:00
}
/*
* Scan for new files, called from menu.
*/
int NewfileScan(int AskStart)
{
2004-05-06 21:33:13 +00:00
FILE *pAreas;
long ifDate, itDate;
char *temp, *Date;
int Found, Count = 0;
_Tag T;
2004-05-06 21:33:13 +00:00
struct _fdbarea *fdb_area = NULL;
2001-08-17 05:46:24 +00:00
Date = calloc(81, sizeof(char));
temp = calloc(81, sizeof(char));
iLineCount = 2;
arecno = 1; /* Reset Area Number to One */
if (AskStart) {
2001-08-17 05:46:24 +00:00
Enter(2);
/* Search for new since your last call [Y/n]: */
2004-11-03 20:48:45 +00:00
pout(LIGHTCYAN, BLACK, (char *) Language(273));
colour(CFG.InputColourF, CFG.InputColourB);
2004-11-03 20:48:45 +00:00
if (toupper(Readkey()) == Keystroke(273, 1)) {
Enter(1);
/* Enter new date to search for [DD-MM-YYYY]: */
2004-11-03 20:48:45 +00:00
pout(GREEN, BLACK, (char *) Language(274));
colour(CFG.InputColourF, CFG.InputColourB);
GetDate(temp, 10);
2004-11-03 20:48:45 +00:00
} else {
strcpy(temp, LastLoginDate);
2004-11-03 20:48:45 +00:00
}
} else {
strcpy(temp, LastLoginDate);
2004-11-03 20:48:45 +00:00
}
2001-08-17 05:46:24 +00:00
Syslog('+', "NewfileScan() since %s", temp);
clear();
/* File Search by Date */
2004-11-03 20:48:45 +00:00
pout(WHITE, BLACK, (char *) Language(275));
Enter(2);
2001-08-17 05:46:24 +00:00
Date[0] = temp[6]; /* Swap the date around */
Date[1] = temp[7]; /* Instead of DD-MM-YYYY */
Date[2] = temp[8]; /* Let it equal YYYYMMDD */
Date[3] = temp[9]; /* Swap the date around */
Date[4] = temp[3]; /* Swap the date around */
Date[5] = temp[4]; /* because when you convert */
Date[6] = temp[0]; /* a string to an int you */
Date[7] = temp[1]; /* loose the front Zero */
Date[8] = '\0'; /* making the number smaller */
itDate = atol(Date);
2001-08-17 05:46:24 +00:00
InitTag();
2001-08-17 05:46:24 +00:00
if ((pAreas = OpenFareas(FALSE)) == NULL)
return 0;
2001-08-17 05:46:24 +00:00
while (fread(&area, areahdr.recsize, 1, pAreas) == 1) {
2001-08-17 05:46:24 +00:00
if ((Access(exitinfo.Security, area.LTSec)) && (area.Available) && (strlen(area.Password) == 0) && (area.New)) {
2001-08-17 05:46:24 +00:00
2004-05-06 21:33:13 +00:00
if ((fdb_area = mbsedb_OpenFDB(arecno, 30))) {
Sheader();
Found = FALSE;
Nopper();
2001-08-17 05:46:24 +00:00
2004-05-06 21:33:13 +00:00
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
2004-03-06 21:48:41 +00:00
strcpy(temp, StrDateDMY(fdb.UploadDate)); /* Realloc Space for Date */
Date[0] = temp[6]; /* Swap the date around */
Date[1] = temp[7]; /* Instead of DD-MM-YYYY */
Date[2] = temp[8]; /* Let it equal YYYYMMDD */
Date[3] = temp[9]; /* Swap the date around */
Date[4] = temp[3]; /* Swap the date around */
Date[5] = temp[4]; /* because when you convert */
Date[6] = temp[0]; /* a string to an int you */
Date[7] = temp[1]; /* loose the front Zero */
Date[8] = '\0'; /* making the number smaller */
/* and invalid to this cause */
ifDate = atol(Date);
if (ifDate >= itDate) {
if (!Found) {
2004-11-03 20:48:45 +00:00
Enter(2);
if (iLC(2) == 1) {
free(Date);
free(temp);
2004-05-06 21:33:13 +00:00
mbsedb_CloseFDB(fdb_area);
fclose(pAreas);
return 1;
}
Found = TRUE;
}
2001-08-17 05:46:24 +00:00
memset(&T, 0, sizeof(T));
T.Area = arecno;
T.Active = FALSE;
2004-03-06 21:48:41 +00:00
T.Size = fdb.Size;
strncpy(T.SFile, fdb.Name, 12);
strncpy(T.LFile, fdb.LName, 80);
SetTag(T);
2001-08-17 05:46:24 +00:00
Count++;
if (ShowOneFile() == 1) {
free(Date);
free(temp);
2004-05-06 21:33:13 +00:00
mbsedb_CloseFDB(fdb_area);
fclose(pAreas);
return 1;
}
} /* End of if */
} /* End of while */
2001-08-17 05:46:24 +00:00
2004-05-06 21:33:13 +00:00
mbsedb_CloseFDB(fdb_area);
/*
* Add 2 blank lines after found files.
*/
if (Found) {
2004-11-03 20:48:45 +00:00
Enter(2);
if (iLC(2) == 1) {
free(Date);
free(temp);
fclose(pAreas);
return 1;
}
}
2001-08-17 05:46:24 +00:00
} /* End of open filebase */
2001-08-17 05:46:24 +00:00
} /* End of check new files scan */
arecno++; /* Go to next file area */
} /* End of Main */
2001-08-17 05:46:24 +00:00
if (Count)
Syslog('+', "Found %d new files", Count);
fclose(pAreas);
2004-11-03 20:48:45 +00:00
Enter(1);
if (Count)
Mark();
else
Pause();
free(temp);
free(Date);
return 1;
2001-08-17 05:46:24 +00:00
}
/*
* Upload a file.
*/
int Upload()
{
char temp[81];
int Area, err;
2004-11-03 20:48:45 +00:00
unsigned long OldArea;
time_t ElapstimeStart, ElapstimeFin, iTime;
DIR *dirp;
struct dirent *dp;
struct stat statfile;
char *arc;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
WhosDoingWhat(UPLOAD, NULL);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Select default protocol if users hasn't any.
*/
if (!ForceProtocol())
return 0;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
Enter(1);
Area = OldArea = iAreaNumber;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* If there is a special upload area for the current area
* then select it.
*/
if (area.Upload)
Area = area.Upload;
SetFileArea(Area);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
SetFileArea(Area);
Syslog('+', "Upload area is %d %s", Area, area.Name);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Check upload access for the real upload directory.
*/
if (!Access(exitinfo.Security, area.UPSec)) {
Enter(1);
/* You do not have enough access to upload to this area */
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(278));
Enter(2);
2001-08-17 05:46:24 +00:00
SetFileArea(OldArea);
Pause();
2004-11-03 20:48:45 +00:00
return 0;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
clear();
Enter(2);
colour(CFG.HiliteF, CFG.HiliteB);
/* Please start your upload now ...*/
pout(CFG.HiliteF, CFG.HiliteB, sProtAdvice);
PUTCHAR(' ');
PUTSTR((char *) Language(283));
Enter(2);
2001-08-17 05:46:24 +00:00
Syslog('+', "Upload using %s", sProtName);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
sprintf(temp, "%s/%s/upl", CFG.bbs_usersdir, exitinfo.Name);
if (chdir(temp)) {
WriteError("$Can't chdir to %s", temp);
SetFileArea(OldArea);
return 0;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
sleep(2);
ElapstimeStart = time(NULL);
/*
* Get the file(s). Set the Client/Server time to 2 hours.
* This is not a nice solution, at least it works and prevents
* that the bbs will hang.
*/
Altime(7200);
alarm_set(7190);
err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL);
rawport();
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if (err) {
2001-08-17 05:46:24 +00:00
/*
2004-11-03 20:48:45 +00:00
* Log any errors
2001-08-17 05:46:24 +00:00
*/
2004-11-03 20:48:45 +00:00
WriteError("$Upload error %d, prot: %s", err, sProtUp);
}
Altime(0);
alarm_off();
alarm_on();
Enter(3);
ElapstimeFin = time(NULL);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Get time from Before Upload and After Upload to get
* upload time, if the time is zero, it will be one.
*/
iTime = ElapstimeFin - ElapstimeStart;
if (!iTime)
iTime = 1;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
Syslog('b', "Transfer time %ld", iTime);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if ((dirp = opendir(".")) == NULL) {
WriteError("$Upload: can't open ./upl");
Home();
SetFileArea(OldArea);
return 1;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
Enter(2);
pout(CFG.UnderlineColourF, CFG.UnderlineColourB, (char *)"Checking your upload(s)");
Enter(1);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
while ((dp = readdir(dirp)) != NULL) {
if (*(dp->d_name) != '.') {
stat(dp->d_name, &statfile);
Syslog('+', "Uploaded \"%s\", %ld bytes", dp->d_name, statfile.st_size);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if ((arc = GetFileType(dp->d_name)) == NULL) {
2001-08-17 05:46:24 +00:00
/*
2004-11-03 20:48:45 +00:00
* If the filetype is unknown, it is probably
* a textfile or so. Import it direct.
2001-08-17 05:46:24 +00:00
*/
2004-11-03 20:48:45 +00:00
Syslog('b', "Unknown file type");
if (!ScanDirect(dp->d_name))
ImportFile(dp->d_name, Area, FALSE, iTime, statfile.st_size);
} else {
2001-08-17 05:46:24 +00:00
/*
2004-11-03 20:48:45 +00:00
* We figured out the type of the uploaded file.
2001-08-17 05:46:24 +00:00
*/
2004-11-03 20:48:45 +00:00
Syslog('b', "File type is %s", arc);
2001-08-17 05:46:24 +00:00
/*
2004-11-03 20:48:45 +00:00
* MS-DOS executables are handled direct.
2001-08-17 05:46:24 +00:00
*/
2004-11-03 20:48:45 +00:00
if ((strcmp("EXE", arc) == 0) || (strcmp("COM", arc) == 0)) {
if (!ScanDirect(dp->d_name))
ImportFile(dp->d_name, Area, FALSE, iTime, statfile.st_size);
} else {
switch (ScanArchive(dp->d_name, arc)) {
case 0: ImportFile(dp->d_name, Area, TRUE, iTime, statfile.st_size);
break;
case 1: break;
case 2: break;
case 3: /*
* No valid unarchiver found, just import after scanning,
* may catch macro viri.
*/
if (!ScanDirect(dp->d_name))
ImportFile(dp->d_name, Area, FALSE, iTime, statfile.st_size);
break;
}
}
}
2001-08-17 05:46:24 +00:00
}
2004-11-03 20:48:45 +00:00
}
closedir(dirp);
Home();
SetFileArea(OldArea);
Pause();
return 1;
2001-08-17 05:46:24 +00:00
}
/*
2004-11-03 20:48:45 +00:00
* Function will download a specific file
2001-08-17 05:46:24 +00:00
*/
2004-11-03 20:48:45 +00:00
int DownloadDirect(char *Name, int Wait)
2001-08-17 05:46:24 +00:00
{
2004-11-03 20:48:45 +00:00
int err, rc;
char *symTo, *symFrom, temp[81];
long Size;
time_t ElapstimeStart, ElapstimeFin, iTime;
long iTransfer = 0;
if ((Size = file_size(Name)) == -1) {
WriteError("No file %s", Name);
pout(CFG.HiliteF, CFG.HiliteB, (char *)"File not found");
Enter(2);
Pause();
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Make a symlink to the users tmp dir.
*/
symTo = calloc(PATH_MAX, sizeof(char));
symFrom = calloc(PATH_MAX, sizeof(char));
sprintf(symFrom, "%s/%s/tmp%s", CFG.bbs_usersdir, exitinfo.Name, strrchr(Name, '/'));
sprintf(symTo, "%s", Name);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if (symlink(symTo, symFrom)) {
WriteError("$Can't create symlink %s %s", symTo, symFrom);
free(symTo);
free(symFrom);
return FALSE;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* If user has no default protocol, make sure he has one.
*/
if (!ForceProtocol()) {
unlink(symFrom);
free(symTo);
free(symFrom);
return FALSE;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
WhosDoingWhat(DOWNLOAD, NULL);
ReadExitinfo();
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
clear();
/* File(s) : */
pout(YELLOW, BLACK, (char *) Language(349)); sprintf(temp, "%s", symFrom); PUTSTR(temp); Enter(1);
/* Size : */
pout( CYAN, BLACK, (char *) Language(350)); sprintf(temp, "%lu", Size); PUTSTR(temp); Enter(1);
/* Protocol : */
pout( CYAN, BLACK, (char *) Language(351)); sprintf(temp, "%s", sProtName); PUTSTR(temp); Enter(1);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
Syslog('+', "Download direct start %s", Name);
PUTSTR(sProtAdvice);
Enter(2);
/*
* Wait a while before download
*/
sleep(2);
ElapstimeStart = time(NULL);
/*
* Transfer the file. Set the Client/Server time at the maximum
* time the user has plus 10 minutes. The overall timer 10 seconds
* less.
*/
alarm_set(((exitinfo.iTimeLeft + 10) * 60) - 10);
Altime((exitinfo.iTimeLeft + 10) * 60);
err = execute_str(sProtDn, symFrom, NULL, NULL, NULL, NULL);
rawport();
if (err) {
/*
* Only log the error, we might have sent some files
* instead of nothing.
*/
WriteError("$Download error %d, prot: %s", err, sProtDn);
}
Altime(0);
alarm_off();
alarm_on();
ElapstimeFin = time(NULL);
/*
* Get time from Before Download and After Download to get
* download time, if the time is zero, it will be one.
*/
iTime = ElapstimeFin - ElapstimeStart;
if (!iTime)
iTime = 1;
if ((access(symFrom, R_OK)) != 0) {
/*
* Work out transfer rate in seconds by dividing the
* Size of the File by the amount of time it took to download
* the file.
*/
iTransfer = Size / iTime;
Syslog('+', "Download ok, time %ld seconds (%lu cps)", iTime, iTransfer);
/*
* Update the users record. The file is free, so only statistics.
*/
ReadExitinfo();
exitinfo.Downloads++; /* Increase download counter */
exitinfo.iTransferTime = iTransfer;
WriteExitinfo();
rc = TRUE;
} else {
Syslog('+', "Download failed to sent file");
unlink(symFrom);
rc = FALSE;
}
if (Wait)
Pause();
free(symTo);
free(symFrom);
return rc;
2001-08-17 05:46:24 +00:00
}
/*
2004-11-03 20:48:45 +00:00
* Function will list users home directory
2001-08-17 05:46:24 +00:00
*/
2004-11-03 20:48:45 +00:00
void List_Home()
2001-08-17 05:46:24 +00:00
{
2004-11-03 20:48:45 +00:00
DIR *dirp;
char *FileName, *temp;
int iFileCount = 0, iBytes = 0;
struct dirent *dp;
struct stat statfile;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
FileName = calloc(PATH_MAX, sizeof(char));
temp = calloc(PATH_MAX, sizeof(char));
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
iLineCount = 2;
clear();
sprintf(temp, "%s/%s/wrk", CFG.bbs_usersdir, exitinfo.Name);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if ((dirp = opendir(temp)) == NULL) {
WriteError("$List_Home: Can't open dir: %s", temp);
Enter(1);
/* Can't open directory for listing: */
pout(LIGHTRED, BLACK, (char *) Language(290));
Enter(2);
Pause();
} else {
/* Home directory listing for */
sprintf(temp, " %s", (char *) Language(291));
pout(BLUE, LIGHTGRAY, temp);
sprintf(temp, "%-51s", exitinfo.sUserName);
pout(RED, LIGHTGRAY, temp);
2001-08-17 05:46:24 +00:00
Enter(1);
2004-11-03 20:48:45 +00:00
while ((dp = readdir( dirp )) != NULL ) {
sprintf(temp, "%s/%s/wrk", CFG.bbs_usersdir, exitinfo.Name);
sprintf(FileName, "%s/%s", temp, dp->d_name);
/*
* Check first letter of file for a ".", do not display hidden files
* This includes the current directory and parent directory . & ..
*/
if (*(dp->d_name) != '.') {
iFileCount++;
if (stat(FileName, &statfile) != 0) {
WriteError("$Can't stat file %s",FileName);
} else {
iBytes += statfile.st_size;
sprintf(temp, "%-20s", dp->d_name);
pout(YELLOW, BLACK, temp);
sprintf(temp, "%-12ld", (long)(statfile.st_size));
pout(LIGHTMAGENTA, BLACK, temp);
sprintf(temp, "%s ", StrDateDMY(statfile.st_mtime));
pout(LIGHTGREEN, BLACK, temp);
sprintf(temp, "%s", StrTimeHMS(statfile.st_mtime));
pout(LIGHTCYAN, BLACK, temp);
Enter(1);
}
}
if (iLC(1) == 1)
2001-08-17 05:46:24 +00:00
return;
}
2004-11-03 20:48:45 +00:00
Enter(2);
/* Total Files: */ /* Bytes */
sprintf(temp, "%s%d / %d %s", (char *) Language(242), iFileCount, iBytes, (char *) Language(354));
pout(LIGHTCYAN, BLACK, temp);
Enter(1);
Pause();
closedir(dirp);
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
free(temp);
free(FileName);
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Delete files from home directory
*/
void Delete_Home()
{
char *temp, *temp1;
int i;
temp = calloc(PATH_MAX, sizeof(char));
temp1 = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/%s/wrk/", CFG.bbs_usersdir, exitinfo.Name);
Enter(1);
/* Please enter filename to delete: */
pout(9, 0, (char *) Language(292));
colour(CFG.InputColourF, CFG.InputColourB);
GetstrC(temp1, 80);
if (strcmp(temp1, "") == 0) {
2001-08-17 05:46:24 +00:00
free(temp);
free(temp1);
2004-11-03 20:48:45 +00:00
return;
}
if (temp1[0] == '.') {
Enter(1);
/* Sorry you may not delete hidden files ...*/
pout(12, 0, (char *) Language(293));
} else {
strcat(temp, temp1);
if ((access(temp, R_OK)) == 0) {
Enter(1);
/* Delete file: */ /* Are you Sure? [Y/n]: */
sprintf(temp1, "%s %s, %s", (char *) Language(368), temp1, (char *) Language(369));
pout(LIGHTGREEN, BLACK, temp1);
i = toupper(Readkey());
if (i == Keystroke(369, 0) || i == 13) {
i = unlink(temp);
if (i == -1) {
Enter(1);
/* Unable to delete file ... */
pout(LIGHTRED, BLACK, (char *) Language(294));
} else {
Syslog('+', "Delete %s from homedir", temp1);
}
} else {
Enter(2);
/* Aborting ... */
pout(DARKGRAY, BLACK, (char *) Language(116));
}
} else {
Enter(1);
/* Invalid filename, please try again ... */
pout(LIGHTRED, BLACK, (char *) Language(295));
}
}
Enter(2);
free(temp);
free(temp1);
Pause();
2001-08-17 05:46:24 +00:00
}
/*
* Function allows user to download from his/her home directory
* but still does all the necessary checks
*/
int Download_Home()
{
2004-11-03 20:48:45 +00:00
char *temp, *File;
struct stat statfile;
int rc;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
File = calloc(PATH_MAX, sizeof(char));
temp = calloc(PATH_MAX, sizeof(char));
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
WhosDoingWhat(DOWNLOAD, NULL);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
Enter(1);
/* Please enter filename: */
pout(YELLOW, BLACK, (char *) Language(245));
colour(CFG.InputColourF, CFG.InputColourB);
GetstrC(File, 80);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if (( strcmp(File, "")) == 0) {
Enter(2);
/* No filename entered, Aborting. */
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(246));
Enter(2);
Pause();
free(File);
free(temp);
return FALSE;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if (*(File) == '/' || *(File) == ' ') {
Enter(2);
/* Illegal Filename! */
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247));
Enter(2);
Pause();
free(File);
free(temp);
return FALSE;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Get path for users home directory
*/
sprintf(temp, "%s/%s/wrk/%s", CFG.bbs_usersdir, exitinfo.Name, File);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if (stat(temp, &statfile) != 0) {
Enter(2);
/* File does not exist, please try again ...*/
pout(LIGHTRED, BLACK, (char *) Language(296));
Enter(2);
Pause();
2001-08-17 05:46:24 +00:00
free(File);
free(temp);
2004-11-03 20:48:45 +00:00
return FALSE;
}
rc = DownloadDirect(temp, TRUE);
free(File);
free(temp);
return rc;
2001-08-17 05:46:24 +00:00
}
/*
* Function will upload to users home directory
*/
int Upload_Home()
{
2004-11-03 20:48:45 +00:00
DIR *dirp;
struct dirent *dp;
char *File, *sFileName, *temp, *arc;
time_t ElapstimeStart, ElapstimeFin, iTime;
int err;
struct stat statfile;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
WhosDoingWhat(UPLOAD, NULL);
if (!ForceProtocol())
return 0;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
File = calloc(PATH_MAX, sizeof(char));
sFileName = calloc(PATH_MAX, sizeof(char));
temp = calloc(PATH_MAX, sizeof(char));
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
clear();
Enter(2);
/* Please start your upload now ...*/
sprintf(temp, "%s, %s", sProtAdvice, (char *) Language(283));
pout(CFG.HiliteF, CFG.HiliteB, temp);
Enter(2);
Syslog('+', "Upload using %s", sProtName);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
sprintf(temp, "%s/%s/upl", CFG.bbs_usersdir, exitinfo.Name);
if (chdir(temp)) {
WriteError("$Can't chdir to %s", temp);
free(File);
free(sFileName);
free(temp);
return 0;
}
sleep(2);
ElapstimeStart = time(NULL);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Get the file(s). Set the Client/Server time to 2 hours.
* This is not a nice solution, at least it works and prevents
* that the bbs will hang.
*/
Altime(7200);
alarm_set(7190);
err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL);
rawport();
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if (err) {
2001-08-17 05:46:24 +00:00
/*
2004-11-03 20:48:45 +00:00
* Log any errors
2001-08-17 05:46:24 +00:00
*/
2004-11-03 20:48:45 +00:00
WriteError("$Upload error %d, prot: %s", err, sProtUp);
}
Altime(0);
alarm_off();
alarm_on();
Enter(3);
ElapstimeFin = time(NULL);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Get time from Before Upload and After Upload to get
* upload time, if the time is zero, it will be one.
*/
iTime = ElapstimeFin - ElapstimeStart;
if (!iTime)
iTime = 1;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
Syslog('b', "Transfer time %ld", iTime);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if ((dirp = opendir(".")) == NULL) {
WriteError("$Upload: can't open ./upl");
Home();
free(File);
free(sFileName);
free(temp);
return 1;
}
Syslog('b', "Start checking uploaded files");
Enter(2);
pout(CFG.UnderlineColourF, CFG.UnderlineColourB, (char *)"Checking your upload(s)");
Enter(2);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
while ((dp = readdir(dirp)) != NULL) {
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if (*(dp->d_name) != '.') {
stat(dp->d_name, &statfile);
Syslog('+', "Uploaded \"%s\", %ld bytes", dp->d_name, statfile.st_size);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if ((arc = GetFileType(dp->d_name)) == NULL) {
/*
* If the filetype is unknown, it is probably
* a textfile or so. Import it direct.
*/
Syslog('b', "Unknown file type");
ImportHome(dp->d_name);
} else {
/*
* We figured out the type of the uploaded file.
*/
Syslog('b', "File type is %s", arc);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* MS-DOS executables are handled direct.
*/
if ((strcmp("EXE", arc) == 0) || (strcmp("COM", arc) == 0)) {
if (!ScanDirect(dp->d_name))
ImportHome(dp->d_name);
} else {
switch(ScanArchive(dp->d_name, arc)) {
case 0: ImportHome(dp->d_name);
break;
case 1: break;
case 2: break;
case 3: /*
* No valid unarchiver found, just import
2001-08-17 05:46:24 +00:00
*/
2004-11-03 20:48:45 +00:00
ImportHome(dp->d_name);
break;
}
2001-08-17 05:46:24 +00:00
}
2004-11-03 20:48:45 +00:00
}
2001-08-17 05:46:24 +00:00
}
2004-11-03 20:48:45 +00:00
}
closedir(dirp);
Home();
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
ReadExitinfo();
exitinfo.Uploads++;
WriteExitinfo();
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
Pause();
free(File);
free(sFileName);
free(temp);
return 1;
2001-08-17 05:46:24 +00:00
}
/*
* Select filearea, called from menu.
*/
void FileArea_List(char *Option)
{
2004-11-03 20:48:45 +00:00
FILE *pAreas;
int iAreaCount = 6, Recno = 1, iOldArea, iAreaNum = 0;
int iGotArea = FALSE; /* Flag to check if user typed in area */
long offset;
char *temp;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Save old area, incase he picks a invalid area
*/
iOldArea = iAreaNumber;
if ((pAreas = OpenFareas(FALSE)) == NULL)
return;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Count howmany records there are
*/
fseek(pAreas, 0, SEEK_END);
iAreaNum = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* If there are menu options, select area direct.
*/
if (strlen(Option) != 0) {
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if (strcmp(Option, "F+") == 0) {
while (TRUE) {
iAreaNumber++;
if (iAreaNumber > iAreaNum)
iAreaNumber = 1;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
offset = areahdr.hdrsize + ((iAreaNumber - 1) * areahdr.recsize);
if (fseek(pAreas, offset, 0) != 0) {
printf("Can't move pointer here");
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
fread(&area, areahdr.recsize, 1, pAreas);
if ((Access(exitinfo.Security, area.LTSec)) && (area.Available) && (strlen(area.Password) == 0))
break;
}
2001-08-17 05:46:24 +00:00
}
2004-11-03 20:48:45 +00:00
if (strcmp(Option, "F-") == 0) {
while (TRUE) {
iAreaNumber--;
if (iAreaNumber < 1)
iAreaNumber = iAreaNum;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
offset = areahdr.hdrsize + ((iAreaNumber - 1) * areahdr.recsize);
if (fseek(pAreas, offset, 0) != 0) {
printf("Can't move pointer here");
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
fread(&area, areahdr.recsize, 1, pAreas);
if ((Access(exitinfo.Security, area.LTSec)) && (area.Available) && (strlen(area.Password) == 0))
break;
}
}
SetFileArea(iAreaNumber);
Syslog('+', "File area %lu %s", iAreaNumber, sAreaDesc);
fclose(pAreas);
return;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Interactive mode
*/
clear();
Enter(1);
/* File Areas */
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(298));
Enter(2);
temp = calloc(81, sizeof(char));
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
fseek(pAreas, areahdr.hdrsize, 0);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
while (fread(&area, areahdr.recsize, 1, pAreas) == 1) {
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if ((Access(exitinfo.Security, area.LTSec)) && (area.Available)) {
area.Name[31] = '\0';
sprintf(temp, "%5d", Recno);
pout(WHITE, BLACK, temp);
sprintf(temp, " %c ", 46);
pout(LIGHTBLUE, BLACK, temp);
sprintf(temp, "%-31s", area.Name);
pout(CYAN, BLACK, temp);
iAreaCount++;
if ((iAreaCount % 2) == 0) {
Enter(1);
} else {
PUTCHAR(' ');
}
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
Recno++;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if ((iAreaCount / 2) == exitinfo.iScreenLen) {
/* More (Y/n/=/Area #): */
pout(CFG.MoreF, CFG.MoreB, (char *) Language(207));
/*
* Ask user for Area or enter to continue
*/
colour(CFG.InputColourF, CFG.InputColourB);
GetstrC(temp, 7);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if (toupper(*(temp)) == Keystroke(207, 1))
break;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if ((strcmp(temp, "")) != 0) {
iGotArea = TRUE;
break;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
iAreaCount = 2;
2001-08-17 05:46:24 +00:00
}
2004-11-03 20:48:45 +00:00
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* If user type in area above during area listing
* don't ask for it again
*/
if (!iGotArea) {
Enter(1);
/* Select Area: */
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(232));
colour(CFG.InputColourF, CFG.InputColourB);
GetstrC(temp, 80);
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Check if user pressed ENTER
*/
if ((strcmp(temp, "")) == 0) {
fclose(pAreas);
return;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
iAreaNumber = atoi(temp);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Do a check in case user enters a negative value
*/
if (iAreaNumber < 1)
iAreaNumber = 1;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
offset = areahdr.hdrsize + ((iAreaNumber - 1) * areahdr.recsize);
if (fseek(pAreas, offset, 0) != 0)
printf("Can't move pointer there.");
else
fread(&area, areahdr.recsize, 1, pAreas);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Do a check if area is greater or less number than allowed,
* security access level, is oke, and the area is active.
*/
if (iAreaNumber > iAreaNum || iAreaNumber < 1 ||
2001-08-17 05:46:24 +00:00
(Access(exitinfo.Security, area.LTSec) == FALSE) ||
(strlen(area.Name) == 0)) {
2004-11-03 20:48:45 +00:00
Enter(1);
/* Invalid area specified - Please try again ...*/
pout(LIGHTRED, BLACK, (char *) Language(233));
Enter(2);
Pause();
fclose(pAreas);
iAreaNumber = iOldArea;
2001-08-17 05:46:24 +00:00
SetFileArea(iAreaNumber);
2004-11-03 20:48:45 +00:00
free(temp);
return;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
SetFileArea(iAreaNumber);
Syslog('+', "File area %lu %s", iAreaNumber, sAreaDesc);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/*
* Check if file area has a password, if it does ask user for it
*/
if ((strlen(area.Password)) > 2) {
Enter(2);
/* Please enter Area Password: */
pout(WHITE, BLACK, (char *) Language(299));
colour(CFG.InputColourF, CFG.InputColourB);
GetstrC(temp, 20);
Enter(1);
if ((strcmp(temp, area.Password)) != 0) {
/* Password is incorrect */
pout(LIGHTRED, BLACK, (char *) Language(234));
Syslog('!', "Incorrect File Area # %d password given: %s", iAreaNumber, temp);
SetFileArea(iOldArea);
} else {
/* Password is correct */
pout(WHITE, BLACK, (char *) Language(235));
}
Enter(2);
Pause();
}
free(temp);
fclose(pAreas);
2001-08-17 05:46:24 +00:00
}
/*
* Show filelist from current area, called from the menu.
*/
void Copy_Home()
{
2004-03-06 21:48:41 +00:00
char *File, *temp1, *temp2;
int err, Found = FALSE;
2004-05-06 21:33:13 +00:00
struct _fdbarea *fdb_area = NULL;
2004-03-06 21:48:41 +00:00
File = calloc(81, sizeof(char));
temp1 = calloc(PATH_MAX, sizeof(char));
temp2 = calloc(PATH_MAX, sizeof(char));
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
Enter(1);
2004-03-06 21:48:41 +00:00
/* Please enter filename: */
2004-11-03 20:48:45 +00:00
pout(YELLOW, BLACK, (char *) Language(245));
2004-03-06 21:48:41 +00:00
colour(CFG.InputColourF, CFG.InputColourB);
GetstrC(File, 80);
2004-11-03 20:48:45 +00:00
Enter(2);
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
if ((strcmp(File, "")) == 0) {
/* No filename entered, Aborting. */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(246));
Enter(2);
2004-03-06 21:48:41 +00:00
Pause();
free(File);
free(temp1);
free(temp2);
return;
}
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
if (*(File) == '/' || *(File) == ' ') {
/* Illegal Filename! */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247));
Enter(2);
2004-03-06 21:48:41 +00:00
Pause();
free(File);
free(temp1);
free(temp2);
return;
}
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
if (Access(exitinfo.Security, area.DLSec) == FALSE) {
2004-11-03 20:48:45 +00:00
pout(YELLOW, BLACK, (char *) Language(236));
Enter(2);
2004-03-06 21:48:41 +00:00
Pause();
free(File);
free(temp1);
free(temp2);
return;
}
2001-08-17 05:46:24 +00:00
2004-05-06 21:33:13 +00:00
if ((fdb_area = mbsedb_OpenFDB(iAreaNumber, 30)) == NULL) {
free(File);
2004-03-06 21:48:41 +00:00
free(temp1);
free(temp2);
return;
}
2001-08-17 05:46:24 +00:00
2004-05-06 21:33:13 +00:00
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
2004-03-06 21:48:41 +00:00
if ((strcasecmp(File, fdb.Name) == 0) || (strcasecmp(File, fdb.LName) == 0)) {
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
Found = TRUE;
if (((fdb.Size + Quota()) > (CFG.iQuota * 1048576))) {
/* You have not enough diskspace free to copy this file */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(279));
Enter(1);
2004-03-06 21:48:41 +00:00
Syslog('+', "Copy homedir, not enough quota");
} else {
sprintf(temp1, "%s/%s", area.Path, fdb.LName); /* Use real longname here */
sprintf(temp2, "%s/%s/wrk/%s", CFG.bbs_usersdir, exitinfo.Name, File);
colour(CFG.TextColourF, CFG.TextColourB);
/* Start copy: */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(289));
PUTSTR(File);
PUTCHAR(' ');
2004-03-06 21:48:41 +00:00
Syslog('b', "Copy from : %s", temp1);
Syslog('b', "Copy to : %s", temp2);
if ((err = file_cp(temp1, temp2))) {
/* Failed! */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(353));
2004-03-06 21:48:41 +00:00
WriteError("Copy %s to homedir failed, code %d", File, err);
} else {
/* Ok */
2004-11-03 20:48:45 +00:00
PUTSTR((char *) Language(200));
2004-03-06 21:48:41 +00:00
Syslog('+', "Copied %s from area %d to homedir", File, iAreaNumber);
2001-08-17 05:46:24 +00:00
}
2004-11-03 20:48:45 +00:00
Enter(1);
2004-03-06 21:48:41 +00:00
}
2001-08-17 05:46:24 +00:00
}
2004-03-06 21:48:41 +00:00
}
2004-05-06 21:33:13 +00:00
mbsedb_CloseFDB(fdb_area);
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
if (!Found) {
/* File does not exist, please try again ... */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(296));
Enter(1);
2004-03-06 21:48:41 +00:00
}
2001-08-17 05:46:24 +00:00
2004-03-06 21:48:41 +00:00
Pause();
free(File);
free(temp1);
free(temp2);
2001-08-17 05:46:24 +00:00
}
/*
* Edit the list of tagged files.
*/
void EditTaglist()
{
2004-11-03 20:48:45 +00:00
FILE *tf;
int i, x, Fg, Count;
char *temp;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if ((tf = fopen("taglist", "r+")) == NULL) {
Enter(1);
/* No files tagged. */
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(361));
Enter(2);
Pause();
return;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
temp = calloc(81, sizeof(char));
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
while (TRUE) {
clear();
fseek(tf, 0, SEEK_SET);
Count = 0;
/* # Area Active File Size Cost */
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(355));
Enter(1);
colour(LIGHTGREEN, BLACK);
fLine(48);
while ((fread(&Tag, sizeof(Tag), 1, tf) == 1)) {
Count++;
if (Tag.Active)
Fg = WHITE;
else
Fg = LIGHTGRAY;
sprintf(temp, "%3d ", Count);
pout(Fg, BLACK, temp);
Fg--;
sprintf(temp, "%5ld ", Tag.Area);
pout(Fg, BLACK, temp);
Fg--;
if (Tag.Active)
/* Yes */
sprintf(temp, "%-6s ", (char *) Language(356));
else
/* No */
sprintf(temp, "%-6s ", (char *) Language(357));
pout(Fg, BLACK, temp);
Fg--;
sprintf(temp, "%-12s", Tag.SFile);
pout(Fg, BLACK, temp);
Fg--;
sprintf(temp, " %8ld", (long)(Tag.Size));
pout(Fg, BLACK, temp);
Fg--;
sprintf(temp, " %5d", Tag.Cost);
pout(Fg, BLACK, temp);
Enter(1);
}
colour(LIGHTGREEN, BLACK);
fLine(48);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
/* (T)oggle active, (E)rase all, (ENTER) to continue: */
pout(WHITE, RED, (char *) Language(358));
i = toupper(Readkey());
colour(CFG.CRColourF, CFG.CRColourB);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if (i == Keystroke(358, 0)) {
Enter(2);
/* Enter file number, 1.. */
sprintf(temp, "%s%d ", (char *) Language(359), Count);
PUTSTR(temp);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
GetstrC(temp, 5);
x = atoi(temp);
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if ((x > 0) && (x <= Count)) {
if (fseek(tf, (x - 1) * sizeof(Tag), SEEK_SET) == 0) {
if (fread(&Tag, sizeof(Tag), 1, tf) == 1) {
2001-08-17 05:46:24 +00:00
if (Tag.Active)
2004-11-03 20:48:45 +00:00
Tag.Active = FALSE;
2001-08-17 05:46:24 +00:00
else
2004-11-03 20:48:45 +00:00
Tag.Active = TRUE;
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
fseek(tf,(x - 1) * sizeof(Tag), SEEK_SET);
fwrite(&Tag, sizeof(Tag), 1, tf);
}
2001-08-17 05:46:24 +00:00
}
2004-11-03 20:48:45 +00:00
}
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if (i == Keystroke(358, 1)) {
fclose(tf);
unlink("taglist");
free(temp);
return;
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
if ((i == '\r') || (i == '\n')) {
fclose(tf);
free(temp);
return;
2001-08-17 05:46:24 +00:00
}
2004-11-03 20:48:45 +00:00
}
2001-08-17 05:46:24 +00:00
}
/*
2003-02-07 20:49:01 +00:00
* View a file in the current area, menu 103.
2003-04-12 11:12:26 +00:00
* If a file name is given, display direct,
* else ask for filename to view.
2001-08-17 05:46:24 +00:00
*/
2003-04-12 11:12:26 +00:00
void ViewFile(char *name)
2001-08-17 05:46:24 +00:00
{
2003-04-12 11:12:26 +00:00
char *File, *temp, *arc;
int count, total, rc, found = FALSE;
2004-05-06 21:33:13 +00:00
FILE *fp;
struct _fdbarea *fdb_area = NULL;
2003-04-12 11:12:26 +00:00
Syslog('+', "ViewFile(%s)", printable(name, 0));
if (Access(exitinfo.Security, area.LTSec) == FALSE) {
2004-11-03 20:48:45 +00:00
Enter(1);
2003-04-12 11:12:26 +00:00
/* You don't have enough security to list this area */
2004-11-03 20:48:45 +00:00
pout(YELLOW, BLACK, (char *) Language(236));
Enter(2);
2003-04-12 11:12:26 +00:00
Pause();
return;
}
File = calloc(PATH_MAX, sizeof(char));
if ((name != NULL) && strlen(name)) {
strcpy(File, name);
} else {
Enter(2);
/* Please enter filename: */
pout(YELLOW, BLACK, (char *) Language(245));
colour(CFG.InputColourF, CFG.InputColourB);
GetstrC(File, 80);
if ((strcmp(File, "")) == 0) {
free(File);
return;
}
if (*(File) == '.' || *(File) == '*' || *(File) == ' ' || *(File) == '/') {
2004-11-03 20:48:45 +00:00
Enter(1);
2003-04-12 11:12:26 +00:00
/* Illegal Filename! */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247));
Enter(2);
2003-04-12 11:12:26 +00:00
Pause();
free(File);
return;
}
Strlen = strlen(File);
Strlen--;
if (*(File + Strlen) == '.' || *(File + Strlen) == '/' || *(File + Strlen) == ' ') {
2004-11-03 20:48:45 +00:00
Enter(1);
2003-04-12 11:12:26 +00:00
/* Illegal Filename! */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247));
Enter(2);
2003-04-12 11:12:26 +00:00
Pause();
free(File);
return;
}
if ((!strcmp(File, "files.bbs")) || (!strcmp(File, "00index")) || (strstr(File, (char *)".html"))) {
2004-11-03 20:48:45 +00:00
Enter(1);
2003-04-12 11:12:26 +00:00
/* Illegal Filename! */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247));
Enter(2);
2003-04-12 11:12:26 +00:00
Pause();
free(File);
return;
}
}
/*
* Now check if this file is present
*/
2004-05-06 21:33:13 +00:00
if ((fdb_area = mbsedb_OpenFDB(iAreaNumber, 30)) == NULL) {
2003-04-12 11:12:26 +00:00
free(File);
return;
}
2004-05-06 21:33:13 +00:00
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
2004-03-06 21:48:41 +00:00
if (((strcasecmp(File, fdb.Name) == 0) || (strcasecmp(File, fdb.LName) == 0)) && (!fdb.Deleted)) {
2003-04-12 11:12:26 +00:00
found = TRUE;
break;
}
}
2004-05-06 21:33:13 +00:00
mbsedb_CloseFDB(fdb_area);
2003-04-12 11:12:26 +00:00
if (!found) {
2004-11-03 20:48:45 +00:00
Enter(1);
2003-04-12 11:12:26 +00:00
/* File does not exist, please try again ... */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(296));
Enter(2);
2003-04-12 11:12:26 +00:00
free(File);
Pause();
return;
}
2004-03-06 21:48:41 +00:00
sprintf(File, "%s/%s", sAreaPath, fdb.LName);
2003-04-12 11:12:26 +00:00
arc = GetFileType(File);
2004-03-06 21:48:41 +00:00
Syslog('+', "File to view: %s, type %s", fdb.LName, printable(arc, 0));
2003-04-12 11:12:26 +00:00
if (arc != NULL) {
found = FALSE;
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/etc/archiver.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) != NULL) {
fread(&archiverhdr, sizeof(archiverhdr), 1, fp);
while (fread(&archiver, archiverhdr.recsize, 1, fp) == 1) {
if ((strcmp(arc, archiver.name) == 0) && (archiver.available)) {
found = TRUE;
break;
}
}
fclose(fp);
}
if (!found || (strlen(archiver.varc) == 0)) {
Syslog('+', "No archiver view for %s available", File);
2004-11-03 20:48:45 +00:00
Enter(1);
2003-04-12 11:12:26 +00:00
/* Archiver not available */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, Language(442));
Enter(2);
2003-04-12 11:12:26 +00:00
free(File);
free(temp);
Pause();
return;
}
/*
* Archiver viewer is available. Make a temp file which we will
* display to the user.
*/
sprintf(temp, "%s/%s/temptxt", CFG.bbs_usersdir, exitinfo.Name);
2004-03-02 20:47:23 +00:00
rc = execute_str(archiver.varc, File, NULL, (char *)"/dev/null", temp, (char *)"/dev/null");
2003-04-12 11:12:26 +00:00
Syslog('+', "Display temp file %s", temp);
DisplayTextFile(temp);
unlink(temp);
free(temp);
} else {
/*
* Most likely a textfile, first check.
*/
total = count = 0;
if ((fp = fopen(File, "r"))) {
while (TRUE) {
rc = fgetc(fp);
if (rc == EOF)
break;
total++;
if (isascii(rc))
count++;
}
fclose(fp);
}
if (((count * 10) / total) < 8) {
Syslog('+', "This is not a ASCII textfile");
2004-11-03 20:48:45 +00:00
Enter(1);
pout(CFG.HiliteF, CFG.HiliteB, Language(17));
Enter(2);
2003-04-12 11:12:26 +00:00
Pause();
free(File);
return;
}
Syslog('+', "Display text file %s", File);
DisplayTextFile(File);
}
free(File);
2001-08-17 05:46:24 +00:00
}