int get_article(char *msgid, char *ftntag) { char cmd[81], *resp; int retval, done = FALSE; FILE *fp = NULL, *dp; char dpath[PATH_MAX]; Syslog('m', "Get article %s, %s", msgid, ftntag); if (!SearchMsgs(ftntag)) { WriteError("Search message area %s failed", ftntag); return RETVAL_ERROR; } snprintf(dpath, PATH_MAX, "%s/tmp/scannews.last", getenv("MBSE_ROOT")); dp = fopen(dpath, "w"); IsDoing("Article %d", (news_in + 1)); snprintf(cmd, 81, "ARTICLE %s\r\n", msgid); fprintf(dp, "ARTICLE %s\n", msgid); nntp_send(cmd); resp = nntp_receive(); fprintf(dp, "%s\n", resp); retval = atoi(strtok(resp, " ")); switch (retval) { case 412: WriteError("No newsgroup selected"); return RETVAL_UNEXPECTEDANS; case 420: WriteError("No current article has been selected"); return RETVAL_UNEXPECTEDANS; case 423: WriteError("No such article in this group"); return RETVAL_UNEXPECTEDANS; case 430: WriteError("No such article found"); return RETVAL_UNEXPECTEDANS; case 220: if ((fp = tmpfile()) == NULL) { WriteError("$Can't open tmpfile"); return RETVAL_UNEXPECTEDANS; } while (done == FALSE) { resp = nntp_receive(); fwrite(resp, strlen(resp), 1, dp); fprintf(dp, "\n"); fflush(dp); if ((strlen(resp) == 1) && (strcmp(resp, ".") == 0)) { done = TRUE; } else { fwrite(resp, strlen(resp), 1, fp); fputc('\n', fp); } } break; } IsDoing("Article %d", (news_in)); retval = rfc2ftn(fp, NULL); fclose(fp); fclose(dp); return retval; }
/* * Pack message area if there are deleted messages. */ void PackArea(char *Path, int Areanr) { IsDoing("Packing %ld", Areanr); if (Msg_Open(Path)) { if (!do_quiet) { mbse_colour(LIGHTRED, BLACK); printf(" (Packing)"); fflush(stdout); } if (Msg_Lock(30L)) { Msg_Pack(); Msg_UnLock(); } else Syslog('+', "Can't lock %s", Path); Msg_Close(); if (!do_quiet) { printf("\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } } if (CFG.slow_util && do_quiet) msleep(1); }
/* * Show the toberep database */ void ToBeRep(void) { char *temp; FILE *fp; struct _filerecord rep; if (do_quiet) return; IsDoing("Toberep"); mbse_colour(CYAN, BLACK); temp = calloc(PATH_MAX, sizeof(char)); snprintf(temp, PATH_MAX, "%s/etc/toberep.data", getenv("MBSE_ROOT")); if ((fp = fopen(temp, "r")) == NULL) { printf("No toberep database present\n"); } else { // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 printf(" File echo Group File name Kbyte Date Announce\n"); printf("-------------------- ------------ ------------ ----- ---------- --------\n"); mbse_colour(LIGHTGRAY, BLACK); while (fread(&rep, sizeof(rep), 1, fp) == 1) { printf("%-20s %-12s %-12s %5d %s %s\n", rep.Echo, rep.Group, rep.Name, rep.SizeKb, StrDateDMY(rep.Fdate), rep.Announce ? "Yes":"No "); Syslog('f', "%-20s %-12s %-12s %5d %s %s", rep.Echo, rep.Group, rep.Name, rep.SizeKb, StrDateDMY(rep.Fdate), rep.Announce ? "Yes":"No "); } fclose(fp); } free(temp); }
void LinkArea(char *Path, int Areanr) { int rc; IsDoing("Linking %ld", Areanr); rc = Msg_Link(Path, do_quiet, CFG.slow_util); if (rc != -1) { msg_link += rc; processed = TRUE; } }
/* * Flush outbound queue to real outbound. */ void flush_queue(void) { char *temp; struct dirent *de; DIR *dp; Syslog('+', "Flushing outbound queue"); if (enoughspace(CFG.freespace) == 0) { Syslog('+', "Low diskspace, not flushing outbound queue"); return; } IsDoing("Flush queue"); if (!do_quiet) { mbse_colour(LIGHTBLUE, BLACK); printf("Flushing outbound queue\n"); mbse_colour(CYAN, BLACK); } temp = calloc(PATH_MAX, sizeof(char)); snprintf(temp, PATH_MAX, "%s/foobar", CFG.out_queue); mkdirs(temp, 0750); if ((dp = opendir(CFG.out_queue)) == 0) { WriteError("$Can't open %s", CFG.out_queue); free(temp); return; } /* * The outbound queue contains subdirectories which actuallly hold the * queue outbound files. Process each found subdirectory. */ while ((de = readdir(dp))) { if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) { snprintf(temp, PATH_MAX, "%s/%s", CFG.out_queue, de->d_name); Syslog('p', "Queue directory %s", temp); flush_dir(de->d_name); if (chdir(CFG.out_queue)) WriteError("$Can't chdir to %s", CFG.out_queue); if (rmdir(temp)) WriteError("$Can't rmdir %s", temp); } } closedir(dp); free(temp); if (!do_quiet) { printf("\r \r"); fflush(stdout); } }
void initdatabases(void) { if (!init) { clr_index(); working(1, 0, 0); set_color(WHITE, BLACK); ftnd_mvprintw( 5, 6, " INIT DATABASES"); IsDoing("Init Databases"); } config_read(); InitArchive(); InitDomain(); InitFilearea(); InitFilefind(); InitFGroup(); InitFidonetdb(); InitFidonet(); InitHatch(); InitLanguage(); InitLimits(); InitMagics(); InitMsgarea(); InitMGroup(); InitModem(); InitNewfiles(); InitNGroup(); InitNodes(); InitOneline(); InitProtocol(); InitService(); InitTicarea(); InitTtyinfo(); InitUsers(); InitVirus(); InitRoute(); InitFDB(); InitIBC(); if (!init) { clr_index(); } }
int main(int argc, char *argv[]) { struct passwd *pw; int i, rc; socklen_t addrlen = sizeof(struct sockaddr_in6); char str[INET6_ADDRSTRLEN]; #ifdef HAVE_GEOIP_H GeoIP *gi; #endif /* * The next trick is to supply a fake environment variable * FTND_ROOT because this program is started from inetd. * This will setup the variable so InitConfig() will work. * The /etc/passwd must point to the correct homedirectory. */ pw = getpwuid(geteuid()); if (getenv("FTND_ROOT") == NULL) { envptr = xstrcpy((char *)"FTND_ROOT="); envptr = xstrcat(envptr, pw->pw_dir); putenv(envptr); } mypid = getpid(); /* * Read the global configuration data, registrate connection */ InitConfig(); InitMsgs(); InitUser(); InitFidonet(); InitNode(); umask(002); memset(&usrconfig, 0, sizeof(usrconfig)); t_start = time(NULL); InitClient(pw->pw_name, (char *)"ftnnntp", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog); Syslog(' ', "FTNNNTP v%s", VERSION); IsDoing("Loging in"); #ifdef USE_NEWSGATE WriteError("FTNd is compiled for full newsgate, you cannot use ftnnntp!"); #endif /* * Catch all the signals we can, and ignore the rest. */ for(i = 0; i < NSIG; i++) { if ((i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || (i == SIGIOT)) signal(i, (void (*))die); else if (i == SIGCHLD) signal(i, SIG_DFL); else if ((i != SIGKILL) && (i != SIGSTOP)) signal(i, SIG_IGN); } if ((rc = rawport()) != 0) WriteError("Unable to set raw mode"); else { if (getpeername(0,(struct sockaddr*)&peeraddr6,&addrlen) == 0) { /* * Copy IPv4 part into the IPv6 structure. There has to be a better way * to deal with mixed incoming sockets ??? */ memcpy(&peeraddr4, &peeraddr6, sizeof(struct sockaddr_in)); if ((peeraddr6.sin6_family == AF_INET6) && (inet_ntop(AF_INET6, &peeraddr6.sin6_addr, str, sizeof(str)))) { Syslog('+', "Incoming IPv6 connection from %s", str); } else if ((peeraddr4.sin_family == AF_INET) && (inet_ntop(AF_INET, &peeraddr4.sin_addr, str, sizeof(str)))) { Syslog('+', "Incoming IPv4 connection from %s", str); } #ifdef HAVE_GEOIP_H _GeoIP_setup_dbfilename(); if (peeraddr6.sin6_family == AF_INET6) { if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) { if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD)) != NULL) { geoiplookup(gi, str, GEOIP_COUNTRY_EDITION_V6); } GeoIP_delete(gi); } } else if (peeraddr6.sin6_family == AF_INET) { if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) { if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_STANDARD)) != NULL) { geoiplookup(gi, str, GEOIP_COUNTRY_EDITION); } GeoIP_delete(gi); } } #endif #ifdef USE_NEWSGATE send_nntp("400 Server closed"); #else if (! check_free()) { send_nntp("400 Server closed"); } else { send_nntp("200 FTNNNTP v%s server ready -- posting allowed", VERSION); nntp(); } #endif } } cookedport(); die(0); return 0; }
void EditNGroup(void) { int records, i, o, x, y; char pick[12]; FILE *fil; char temp[PATH_MAX]; int offset; clr_index(); working(1, 0, 0); IsDoing("Browsing Menu"); if (config_read() == -1) { working(2, 0, 0); return; } records = CountNGroup(); if (records == -1) { working(2, 0, 0); return; } if (OpenNGroup() == -1) { working(2, 0, 0); return; } o = 0; for (;;) { clr_index(); set_color(WHITE, BLACK); ftnd_mvprintw( 5, 4, "11. NEWFILES GROUPS SETUP"); set_color(CYAN, BLACK); if (records != 0) { snprintf(temp, PATH_MAX, "%s/etc/ngroups.temp", getenv("FTND_ROOT")); working(1, 0, 0); if ((fil = fopen(temp, "r")) != NULL) { fread(&ngrouphdr, sizeof(ngrouphdr), 1, fil); x = 2; y = 7; set_color(CYAN, BLACK); for (i = 1; i <= 20; i++) { if (i == 11 ) { x = 42; y = 7; } if ((o + i) <= records) { offset = sizeof(ngrouphdr) + (((o + i) - 1) * ngrouphdr.recsize); fseek(fil, offset, 0); fread(&ngroup, ngrouphdr.recsize, 1, fil); if (ngroup.Active) set_color(CYAN, BLACK); else set_color(LIGHTBLUE, BLACK); snprintf(temp, 81, "%3d. %-12s %-18s", o + i, ngroup.Name, ngroup.Comment); temp[38] = '\0'; ftnd_mvprintw(y, x, temp); y++; } } fclose(fil); } } strcpy(pick, select_record(records, 20)); if (strncmp(pick, "-", 1) == 0) { CloseNGroup(FALSE); return; } if (strncmp(pick, "A", 1) == 0) { working(1, 0, 0); if (AppendNGroup() == 0) { records++; working(1, 0, 0); } else working(2, 0, 0); } if (strncmp(pick, "N", 1) == 0) if ((o + 20) < records) o = o + 20; if (strncmp(pick, "P", 1) == 0) if ((o - 20) >= 0) o = o - 20; if ((atoi(pick) >= 1) && (atoi(pick) <= records)) { EditNGrpRec(atoi(pick)); o = ((atoi(pick) - 1) / 20) * 20; } } }
/* * Check files for age, and not downloaded for x days. If they match * one of these criteria (setable in areas setup), the file will be * move to some retire area or deleted, depending on the setup. * If they are moved, the upload date is reset to the current date, * so you can set new removal criteria again. */ void Kill(void) { FILE *pAreas; int i, iAreas, iAreasNew = 0, iTotal = 0, iKilled = 0, iMoved = 0, rc, Killit; char *sAreas, *newdir = NULL, *sTemp, from[PATH_MAX], to[PATH_MAX]; time_t Now; struct fileareas darea; struct _fdbarea *fdb_area = NULL, *dst_area = NULL; sAreas = calloc(PATH_MAX, sizeof(char)); sTemp = calloc(PATH_MAX, sizeof(char)); IsDoing("Kill files"); if (!do_quiet) { mbse_colour(CYAN, BLACK); printf("Kill/move files...\n"); } snprintf(sAreas, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT")); if ((pAreas = fopen (sAreas, "r")) == NULL) { WriteError("Can't open %s", sAreas); die(MBERR_INIT_ERROR); } fread(&areahdr, sizeof(areahdr), 1, pAreas); fseek(pAreas, 0, SEEK_END); iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize; Now = time(NULL); for (i = 1; i <= iAreas; i++) { fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET); fread(&area, areahdr.recsize, 1, pAreas); if ((area.Available) && (area.DLdays || area.FDdays)) { if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); if (!do_quiet) { printf("\r%4d => %-44s \b\b\b\b", i, area.Name); fflush(stdout); } /* * Check if download directory exists, if not, create the directory. */ if (access(area.Path, R_OK) == -1) { Syslog('!', "Create dir: %s", area.Path); newdir = xstrcpy(area.Path); newdir = xstrcat(newdir, (char *)"/"); mkdirs(newdir, 0755); free(newdir); newdir = NULL; } if ((fdb_area = mbsedb_OpenFDB(i, 30)) == NULL) die(MBERR_GENERAL); /* * Now start checking the files in the filedatabase * against the contents of the directory. */ while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) { iTotal++; Marker(); Killit = FALSE; if (!fdb.UploadDate) Syslog('!', "Warning: file %s in area %d has no upload date", fdb.Name, i); if (area.DLdays) { /* * Test last download date or never downloaded and the * file is more then n days available for download. */ if ((fdb.LastDL) && (((Now - fdb.LastDL) / 84400) > area.DLdays)) { Killit = TRUE; } if ((!fdb.LastDL) && fdb.UploadDate && (((Now - fdb.UploadDate) / 84400) > area.DLdays)) { Killit = TRUE; } } if (area.FDdays) { /* * Check filedate */ if (fdb.UploadDate && (((Now - fdb.UploadDate) / 84400) > area.FDdays)) { Killit = TRUE; } } if (Killit) { do_pack = TRUE; if (area.MoveArea) { fseek(pAreas, ((area.MoveArea -1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET); fread(&darea, areahdr.recsize, 1, pAreas); snprintf(from, PATH_MAX, "%s/%s", area.Path, fdb.Name); snprintf(to, PATH_MAX, "%s/%s", darea.Path, fdb.Name); if ((rc = file_mv(from, to)) == 0) { Syslog('+', "Move %s, area %d => %d", fdb.Name, i, area.MoveArea); if ((dst_area = mbsedb_OpenFDB(area.MoveArea, 30))) { fdb.UploadDate = time(NULL); fdb.LastDL = time(NULL); mbsedb_InsertFDB(dst_area, fdb, FALSE); mbsedb_CloseFDB(dst_area); } /* * Now again if there is a dotted version (thumbnail) of this file. */ snprintf(from, PATH_MAX, "%s/.%s", area.Path, fdb.Name); snprintf(to, PATH_MAX, "%s/.%s", darea.Path, fdb.Name); if (file_exist(from, R_OK) == 0) file_mv(from, to); /* * Unlink the old symbolic link */ snprintf(from, PATH_MAX, "%s/%s", area.Path, fdb.LName); unlink(from); /* * Create the new symbolic link */ snprintf(from, PATH_MAX, "%s/%s", darea.Path, fdb.Name); snprintf(to, PATH_MAX, "%s/%s", darea.Path, fdb.LName); symlink(from, to); fdb.Deleted = TRUE; 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); } iMoved++; } else { WriteError("Move %s to area %d failed, %s", fdb.Name, area.MoveArea, strerror(rc)); } } else { Syslog('+', "Delete %s, area %d", fdb.LName, i); fdb.Deleted = TRUE; 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); } iKilled++; snprintf(from, PATH_MAX, "%s/%s", area.Path, fdb.LName); unlink(from); snprintf(from, PATH_MAX, "%s/%s", area.Path, fdb.Name); unlink(from); snprintf(from, PATH_MAX, "%s/.%s", area.Path, fdb.Name); unlink(from); } } } /* * Now we must pack this area database otherwise * we run into trouble later on. */ mbsedb_PackFDB(fdb_area); mbsedb_CloseFDB(fdb_area); iAreasNew++; } /* if area.Available */ } fclose(pAreas); Syslog('+', "Kill Areas [%6d] Files [%6d] Deleted [%6d] Moved [%6d]", iAreasNew, iTotal, iKilled, iMoved); if (!do_quiet) { printf("\r \r"); fflush(stdout); } free(sTemp); free(sAreas); }
void EditFDB() { int records, i, o, x, y; char pick[12]; FILE *fil; char temp[PATH_MAX]; int offset; clr_index(); working(1, 0, 0); IsDoing("Browsing Menu"); if (config_read() == -1) { working(2, 0, 0); return; } records = CountFilearea(); if (records == -1) { working(2, 0, 0); return; } o = 0; for (;;) { clr_index(); set_color(WHITE, BLACK); mbse_mvprintw( 5, 4, "14. EDIT FILES DATABSE"); set_color(CYAN, BLACK); if (records != 0) { snprintf(temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT")); working(1, 0, 0); if ((fil = fopen(temp, "r")) != NULL) { fread(&areahdr, sizeof(areahdr), 1, fil); x = 2; y = 7; set_color(CYAN, BLACK); for (i = 1; i <= 20; i++) { if (i == 11) { x = 42; y = 7; } if ((o + i) <= records) { offset = sizeof(areahdr) + (((o + i) - 1) * areahdr.recsize); fseek(fil, offset, SEEK_SET); fread(&area, areahdr.recsize, 1, fil); if (area.Available) set_color(CYAN, BLACK); else set_color(LIGHTBLUE, BLACK); snprintf(temp, 81, "%3d. %-32s", o + i, area.Name); temp[37] = 0; mbse_mvprintw(y, x, temp); y++; } } fclose(fil); } } strcpy(pick, select_pick(records, 20)); if (strncmp(pick, "-", 1) == 0) { return; } if (strncmp(pick, "N", 1) == 0) if ((o + 20) < records) o = o + 20; if (strncmp(pick, "P", 1) == 0) if ((o - 20) >= 0) o = o - 20; if ((atoi(pick) >= 1) && (atoi(pick) <= records)) { snprintf(temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT")); if ((fil = fopen(temp, "r")) != NULL) { offset = areahdr.hdrsize + ((atoi(pick) - 1) * areahdr.recsize); fseek(fil, offset, SEEK_SET); fread(&area, areahdr.recsize, 1, fil); fclose(fil); if (area.Available) { E_F(atoi(pick)); } o = ((atoi(pick) - 1) / 20) * 20; } } } }
void EditMGroup(void) { int records, i, o, x, y; char pick[12], temp[PATH_MAX]; FILE *fil; int offset; clr_index(); working(1, 0, 0); IsDoing("Browsing Menu"); if (config_read() == -1) { working(2, 0, 0); return; } records = CountMGroup(); if (records == -1) { working(2, 0, 0); return; } if (OpenMGroup() == -1) { working(2, 0, 0); return; } o = 0; if (! check_free()) return; for (;;) { clr_index(); set_color(WHITE, BLACK); mbse_mvprintw( 5, 4, "9.1 MESSAGE GROUPS SETUP"); set_color(CYAN, BLACK); if (records != 0) { snprintf(temp, PATH_MAX, "%s/etc/mgroups.temp", getenv("MBSE_ROOT")); working(1, 0, 0); if ((fil = fopen(temp, "r")) != NULL) { fread(&mgrouphdr, sizeof(mgrouphdr), 1, fil); x = 2; y = 7; set_color(CYAN, BLACK); for (i = 1; i <= 20; i++) { if (i == 11 ) { x = 42; y = 7; } if ((o + i) <= records) { offset = sizeof(mgrouphdr) + (((o + i) - 1) * mgrouphdr.recsize); fseek(fil, offset, 0); fread(&mgroup, mgrouphdr.recsize, 1, fil); if (mgroup.Active) set_color(CYAN, BLACK); else set_color(LIGHTBLUE, BLACK); snprintf(temp, 81, "%3d. %-12s %-18s", o + i, mgroup.Name, mgroup.Comment); temp[38] = '\0'; mbse_mvprintw(y, x, temp); y++; } } fclose(fil); } } strcpy(pick, select_record(records, 20)); if (strncmp(pick, "-", 1) == 0) { CloseMGroup(FALSE); open_bbs(); return; } if (strncmp(pick, "A", 1) == 0) { if (records < CFG.toss_groups) { working(1, 0, 0); if (AppendMGroup() == 0) { records++; working(1, 0, 0); } else working(2, 0, 0); } else { errmsg("Cannot add group, change global setting in menu 1.12.12"); } } if (strncmp(pick, "N", 1) == 0) if ((o + 20) < records) o = o + 20; if (strncmp(pick, "P", 1) == 0) if ((o - 20) >= 0) o = o - 20; if ((atoi(pick) >= 1) && (atoi(pick) <= records)) { EditMGrpRec(atoi(pick)); o = ((atoi(pick) - 1) / 20) * 20; } } }
/* * Edit one record, return -1 if there are errors, 0 if ok. */ int EditMGrpRec(int Area) { FILE *fil; static char mfile[PATH_MAX], temp[13]; static int offset; static int i, j, tmp; unsigned int crc, crc1; int oldgrp, newgrp; clr_index(); working(1, 0, 0); IsDoing("Edit MessageGroup"); snprintf(mfile, PATH_MAX, "%s/etc/mgroups.temp", getenv("MBSE_ROOT")); if ((fil = fopen(mfile, "r")) == NULL) { working(2, 0, 0); return -1; } offset = sizeof(mgrouphdr) + ((Area -1) * sizeof(mgroup)); if (fseek(fil, offset, 0) != 0) { working(2, 0, 0); return -1; } fread(&mgroup, sizeof(mgroup), 1, fil); fclose(fil); crc = 0xffffffff; crc = upd_crc32((char *)&mgroup, crc, sizeof(mgroup)); MgScreen(); for (;;) { set_color(WHITE, BLACK); show_str( 7,16,12, mgroup.Name); show_str( 8,16,55, mgroup.Comment); show_str( 9,16,64, mgroup.BasePath); show_sec( 10,16, mgroup.RDSec); show_sec( 11,16, mgroup.WRSec); show_sec( 12,16, mgroup.SYSec); mbse_mvprintw( 13,22, getflag(mgroup.LinkSec.flags, mgroup.LinkSec.notflags)); show_int( 14,16, mgroup.StartArea); show_int( 15,16, mgroup.NetReply); show_bool(16,16, mgroup.UsrDelete); show_bool(17,16, mgroup.Aliases); show_bool(18,16, mgroup.Quotes); show_bool(19,16, mgroup.Active); show_bool(14,42, mgroup.Deleted); show_bool(15,42, mgroup.AutoChange); show_bool(16,42, mgroup.UserChange); show_aka( 17,42, mgroup.UseAka); show_aka( 18,42, mgroup.UpLink); show_str( 19,42,12, mgroup.AreaFile); show_charset(14,70, mgroup.Charset); snprintf(temp, 5, "#%03d", mgroup.GoldEDgroup); show_str( 15,70, 5, temp); j = select_menu(21); switch(j) { case 0: if (!mgroup.StartArea && strlen(mgroup.AreaFile)) { errmsg("Areas file defined but no BBS start area"); break; } crc1 = 0xffffffff; crc1 = upd_crc32((char *)&mgroup, crc1, sizeof(mgroup)); if (crc != crc1) { if (yes_no((char *)"Record is changed, save") == 1) { working(1, 0, 0); if ((fil = fopen(mfile, "r+")) == NULL) { WriteError("$Can't reopen %s", mfile); working(2, 0, 0); return -1; } fseek(fil, offset, 0); fwrite(&mgroup, sizeof(mgroup), 1, fil); fclose(fil); MGrpUpdated = 1; working(6, 0, 0); } } IsDoing("Browsing Menu"); return 0; case 1: if (CheckMgroup()) break; strcpy(mgroup.Name, edit_str(7,16,12, mgroup.Name, (char *)"The ^name^ for this message group")); if (strlen(mgroup.BasePath) == 0) { memset(&temp, 0, sizeof(temp)); strcpy(temp, mgroup.Name); for (i = 0; i < strlen(temp); i++) { if (temp[i] == '.') temp[i] = '/'; if (isupper(temp[i])) temp[i] = tolower(temp[i]); } snprintf(mgroup.BasePath, 65, "%s/var/mail/%s", getenv("MBSE_ROOT"), temp); } break; case 2: E_STR( 8,16,55, mgroup.Comment, "The ^desription^ for this message group") case 3: E_PTH( 9,16,64, mgroup.BasePath, "The ^Base path^ where new JAM areas are created", 0770) case 4: E_SEC( 10,16, mgroup.RDSec, "9.1.4 MESSAGE GROUP READ SECURITY", MgScreen) case 5: E_SEC( 11,16, mgroup.WRSec, "9.1.5 MESSAGE GROUP WRITE SECURITY", MgScreen) case 6: E_SEC( 12,16, mgroup.SYSec, "9.1.6 MESSAGE GROUP SYSOP SECURITY", MgScreen) case 7: mgroup.LinkSec = edit_asec(mgroup.LinkSec, (char *)"9.1.7 DEFAULT SECURITY FOR NEW AREAS"); MgScreen(); break; case 8: E_INT( 14,16, mgroup.StartArea, "The ^Start area number^ from where to add areas") case 9: E_INT( 15,16, mgroup.NetReply, "The ^Area Number^ for netmail replies") case 10:E_BOOL(16,16, mgroup.UsrDelete, "Allow users to ^Delete^ their messages") case 11:E_BOOL(17,16, mgroup.Aliases, "Allow ^Aliases^ or real names only") case 12:E_BOOL(18,16, mgroup.Quotes, "Allow random ^quotes^ to new messages") case 13:if (mgroup.Active && CheckMgroup()) break; E_BOOL(19,16, mgroup.Active, "Is this message group ^active^") case 14:if (CheckMgroup()) break; E_BOOL(14,42, mgroup.Deleted, "Is this group ^Deleted^") case 15:E_BOOL(15,42, mgroup.AutoChange, "^Auto change^ areas from new areas lists") case 16:tmp = edit_bool(16,42, mgroup.UserChange, (char *)"^Auto add/delete^ areas from downlinks requests"); if (tmp && !mgroup.UpLink.zone) errmsg("It looks like you are the toplevel, no Uplink defined"); else mgroup.UserChange = tmp; break; case 17:tmp = PickAka((char *)"9.1.17", TRUE); if (tmp != -1) memcpy(&mgroup.UseAka, &CFG.aka[tmp], sizeof(fidoaddr)); MgScreen(); break; case 18:mgroup.UpLink = PullUplink((char *)"9.1.18"); MgScreen(); break; case 19:E_STR( 19,42,12, mgroup.AreaFile, "The name of the ^Areas File^ from the uplink (case sensitive)") case 20:mgroup.Charset = edit_charset(14, 70, mgroup.Charset); break; case 21:oldgrp = mgroup.GoldEDgroup; newgrp = edit_int(15, 70, oldgrp, (char *)"The new groupnumber for the ^GoldED groups^ (1..999)"); if ((newgrp < 1) || (newgrp > 999)) { errmsg("Groupnumber must be between 1 and 999"); } else if (newgrp && (newgrp != oldgrp)) { if (gedgrps[newgrp] == 1) { errmsg("This groupnumber is already in use"); } else { gedgrps[oldgrp] = 0; gedgrps[newgrp] = 1; mgroup.GoldEDgroup = newgrp; } } break; } } return 0; }
/* * Sort files database */ void SortFileBase(int Area) { FILE *pAreas; int iAreas; char *sAreas; struct _fdbarea *fdb_area = NULL; sAreas = calloc(PATH_MAX, sizeof(char)); IsDoing("Sort filebase"); if (!do_quiet) { ftnd_colour(CYAN, BLACK); } snprintf(sAreas, PATH_MAX, "%s/etc/fareas.data", getenv("FTND_ROOT")); if ((pAreas = fopen (sAreas, "r")) == NULL) { WriteError("Can't open %s", sAreas); die(FTNERR_INIT_ERROR); } fread(&areahdr, sizeof(areahdr), 1, pAreas); fseek(pAreas, 0, SEEK_END); iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize; if ((Area < 1) || (Area > iAreas)) { if (!do_quiet) { printf("Area must be between 1 and %d\n", iAreas); } } else { fseek(pAreas, ((Area - 1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET); fread(&area, areahdr.recsize, 1, pAreas); if (area.Available) { if (enoughspace(CFG.freespace) == 0) die(FTNERR_DISK_FULL); if (!do_quiet) { printf("Sorting area %d: %-44s", Area, area.Name); fflush(stdout); } if ((fdb_area = ftnddb_OpenFDB(Area, 30))) { ftnddb_SortFDB(fdb_area); ftnddb_CloseFDB(fdb_area); } Syslog('+', "Sorted file area %d: %s", Area, area.Name); do_index = TRUE; } else { printf("You cannot sort area %d\n", Area); } } fclose(pAreas); if (!do_quiet) { printf("\r \r"); fflush(stdout); } free(sAreas); }
void user(void) { FILE *pUsrConfig, *pLimits; int i, x, FoundName = FALSE, iFoundLimit = FALSE, IsNew = FALSE, logins = 0, Start; int l1, l2; char *token, temp[PATH_MAX], temp1[84], UserName[37], buf[128], *fullname; time_t LastLogin; struct stat st; grecno = 0; Syslog('+', "Unixmode login: %s", sUnixName); snprintf(temp, PATH_MAX, "%s/etc/users.data", getenv("FTND_ROOT")); if ((pUsrConfig = fopen(temp,"r+")) == NULL) { /* * This should not happen. */ WriteError("$Can't open %s", temp); PUTSTR((char *)"Can't open userfile, run \"newuser\" first"); Enter(1); ExitClient(FTNERR_OK); } fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig); while (fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig) == 1) { if (strcmp(usrconfig.Name, sUnixName) == 0) { FoundName = TRUE; break; } else grecno++; } if (!FoundName) { fclose(pUsrConfig); snprintf(temp, PATH_MAX, "Unknown username: %s\r\n", sUnixName); PUTSTR(temp); /* FATAL ERROR: You are not in the BBS users file.*/ snprintf(temp, PATH_MAX, "%s\r\n", (char *) Language(389)); PUTSTR(temp); /* Please run 'newuser' to create an account */ snprintf(temp, PATH_MAX, "%s\r\n", (char *) Language(390)); PUTSTR(temp); Syslog('?', "FATAL: Could not find user in BBS users file."); Syslog('?', " and system is using unix accounts\n"); Free_Language(); ExitClient(FTNERR_OK); } /* * Copy username, split first and lastname. */ strncpy(UserName, usrconfig.sUserName, sizeof(UserName)-1); if ((strchr(UserName,' ') == NULL) && !CFG.iOneName) { token = strtok(UserName, " "); strncpy(FirstName, token, sizeof(FirstName)-1); token = strtok(NULL, "\0"); i = strlen(token); for (x = 2; x < i; x++) { if (token[x] == ' ') token[x] = '\0'; } strncpy(LastName, token, sizeof(LastName)-1); } else strncpy(FirstName, UserName, sizeof(FirstName)-1); strncpy(UserName, usrconfig.sUserName, sizeof(UserName)-1); Syslog('+', "%s On-Line from \"%s\", node %d", UserName, ttyinfo.comment, iNode); IsDoing("Just Logged In"); /* * Check some essential files, create them if they don't exist. */ ChkFiles(); /* * Setup users favourite language. */ utf8 = (usrconfig.Charset == FTNC_UTF8); Set_Language(usrconfig.iLanguage); Free_Language(); InitLanguage(); /* * User logged in, tell it to the server. Check if a location is * set, if Ask User location for new users is off, this field is * empty but we have to send something to the server. */ if (strlen(usrconfig.sLocation)) UserCity(mypid, usrconfig.Name, usrconfig.sLocation); else UserCity(mypid, usrconfig.Name, (char *)"N/A"); /* * Count simultaneous logins */ Start = TRUE; while (TRUE) { if (Start) snprintf(buf, 128, "GMON:1,1;"); else snprintf(buf, 128, "GMON:1,0;"); Start = FALSE; if (socket_send(buf) == 0) { strcpy(buf, socket_receive()); if (strncmp(buf, "100:0;", 6) == 0) break; /* No more data */ if (strstr(buf, "ftnbbs")) { /* * Only ftnbbs is wanted */ strtok(buf, ","); /* response */ strtok(NULL, ","); /* pid */ strtok(NULL, ","); /* tty */ fullname = xstrcpy(cldecode(strtok(NULL, ","))); /* username */ if (strcmp(fullname, usrconfig.Name) == 0) { logins++; } free(fullname); } } } if (CFG.max_logins && (logins > CFG.max_logins)) { Syslog('+', "User logins %d, allowed %d, disconnecting", logins, CFG.max_logins); colour(LIGHTRED, BLACK); snprintf(temp, PATH_MAX, "%s %d %s\r\n", (char *) Language(18), CFG.max_logins, (char *) Language(19)); PUTSTR(temp); Quick_Bye(FTNERR_INIT_ERROR); } /* * Set last file and message area so these numbers are saved when * the user hangs up or is logged off before het gets to the main * menu. Later in this function the areas are set permanent. */ iAreaNumber = usrconfig.iLastFileArea; iMsgAreaNumber = usrconfig.iLastMsgArea; /* * See if this user is the Sysop. */ strcpy(temp, UserName); strcpy(temp1, CFG.sysop_name); if ((strcasecmp(CFG.sysop_name, UserName)) == 0) { /* * If login name is sysop, set SYSOP true */ SYSOP = TRUE; Syslog('+', "Sysop is online"); } /* * Is this a new user? */ if (usrconfig.iTotalCalls == 0) IsNew = TRUE; /* * Pause after logo screen. */ alarm_on(); Pause(); if (usrconfig.Archiver[0] == '\0') { usrconfig.Archiver[0] = 'Z'; usrconfig.Archiver[1] = 'I'; usrconfig.Archiver[2] = 'P'; Syslog('+', "Setup default archiver ZIP"); } /* * Check users date format. We do it strict as we * need this to be good for several other purposes. * If it is correct, the users age is set in UserAge */ if (!Test_DOB(usrconfig.sDateOfBirth)) { Syslog('!', "Error in Date of Birth"); Chg_DOB(); strcpy(usrconfig.sDateOfBirth, exitinfo.sDateOfBirth); } /* * Check to see if user must expire */ snprintf(temp,PATH_MAX, "%s", (char *) GetDateDMY()); SwapDate(temp, usrconfig.sExpiryDate); /* Convert Date1 & Date2 to longs for compare */ l1 = atol(Date1); l2 = atol(Date2); if (l1 >= l2 && l2 != 0) { /* * If Expiry Date is the same as today expire to * Expire Sec level */ usrconfig.Security = usrconfig.ExpirySec; Syslog('!', "User is expired, resetting level"); /* * Show texfile to user telling him about this. */ DisplayFile((char *)"expired"); } free(Date1); free(Date2); /* * Copy limits.data into memory */ snprintf(temp, PATH_MAX, "%s/etc/limits.data", getenv("FTND_ROOT")); if ((pLimits = fopen(temp,"rb")) == NULL) { WriteError("$Can't open %s", temp); } else { fread(&LIMIThdr, sizeof(LIMIThdr), 1, pLimits); while (fread(&LIMIT, sizeof(LIMIT), 1, pLimits) == 1) { if (LIMIT.Security == usrconfig.Security.level) { iFoundLimit = TRUE; break; } } fclose(pLimits); } if (!iFoundLimit) { WriteError("Unknown Security Level in limits.data"); usrconfig.iTimeLeft = 0; /* Could not find limit, so set to Zero */ usrconfig.iTimeUsed = 0; /* Set to Zero as well */ } else { /* * Give user new time limit everyday, also new users get a new limit. */ snprintf(temp,PATH_MAX, "%s", (char *) GetDateDMY()); if (((strcmp(StrDateDMY(usrconfig.tLastLoginDate), temp)) != 0) || IsNew) { /* * If no timelimit set give user 24 hours. */ if (LIMIT.Time) usrconfig.iTimeLeft = LIMIT.Time; else usrconfig.iTimeLeft = 86400; usrconfig.iTimeUsed = 0; /* Set time used today to Zero */ usrconfig.iConnectTime = 0; /* Set connect time to Zero */ /* * Give user new bytes and files every day if needed. */ if (LIMIT.DownK) { usrconfig.DownloadKToday = LIMIT.DownK; } if (LIMIT.DownF) { usrconfig.DownloadsToday = LIMIT.DownF; } } } /* End of else */ usrconfig.iConnectTime = 0; /* Copy Users Protocol into Memory */ Set_Protocol(usrconfig.sProtocol); tlf(usrconfig.sProtocol); /* * Set last login Date and Time, copy previous session * values in memory. */ snprintf(LastLoginDate, 12, "%s", StrDateDMY(usrconfig.tLastLoginDate)); snprintf(LastLoginTime, 9, "%s", StrTimeHMS(usrconfig.tLastLoginDate)); LastLogin = usrconfig.tLastLoginDate; usrconfig.tLastLoginDate = ltime; /* Set current login to current date */ usrconfig.iTotalCalls++; /* * Update user record. */ if (fseek(pUsrConfig, usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize), 0) != 0) { WriteError("Can't seek in %s/etc/users.data", getenv("FTND_ROOT")); } else { fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig); } fclose(pUsrConfig); /* * Write users structure to tmp file in ~/home/unixname/exitinfo * A copy of the userrecord is also in the variable exitinfo. */ if (! InitExitinfo()) Good_Bye(FTNERR_INIT_ERROR); /* * If user has not set a preferred character set, force this */ if (exitinfo.Charset == FTNC_NONE) { Chg_Charset(); } setlocale(LC_CTYPE, getlocale(exitinfo.Charset)); Syslog('b', "setlocale(LC_CTYPE, NULL) returns \"%s\"", printable(setlocale(LC_CTYPE, NULL), 0)); GetLastUser(); StartTime = xstrcpy(GetLocalHM()); ChangeHomeDir(exitinfo.Name, exitinfo.Email); Syslog('+', "User successfully logged into BBS"); Syslog('+', "Level %d (%s), %d mins. left, port %s", exitinfo.Security.level, LIMIT.Description, exitinfo.iTimeLeft, pTTY); Time2Go = time(NULL); Time2Go += exitinfo.iTimeLeft * 60; iUserTimeLeft = exitinfo.iTimeLeft; IsDoing("Welcome screens"); DisplayFile((char *)"mainlogo"); DisplayFile((char *)"welcome"); /* * The following files are only displayed if the user has * turned the Bulletins on. */ if (exitinfo.ieNEWS) { DisplayFile((char *)"welcome1"); DisplayFile((char *)"welcome2"); DisplayFile((char *)"welcome3"); DisplayFile((char *)"welcome4"); DisplayFile((char *)"welcome5"); DisplayFile((char *)"welcome6"); DisplayFile((char *)"welcome7"); DisplayFile((char *)"welcome8"); DisplayFile((char *)"welcome9"); snprintf(temp, PATH_MAX, "%s", (char *) GetDateDMY() ); if ((strcmp(exitinfo.sDateOfBirth, temp)) == 0) DisplayFile((char *)"birthday"); /* * Displays file if it exists DD-MM.A?? */ snprintf(temp, PATH_MAX, "%s", (char *) GetDateDMY()); strcpy(temp1, ""); strncat(temp1, temp, 5); snprintf(temp, PATH_MAX, "%s", temp1); DisplayFile(temp); /* * Displays users security file if it exists */ snprintf(temp, PATH_MAX, "sec%d", exitinfo.Security.level); DisplayFile(temp); /* * Display News file */ DisplayFile((char *)"news"); } /* * Display Onceonly file, first get the date of that * file, search order is the same as in DisplayFile() */ st.st_mtime = 0; snprintf(temp, PATH_MAX, "%s/share/int/txtfiles/%s/onceonly.ans", getenv("FTND_ROOT"), lang.lc); stat(temp, &st); if (st.st_mtime == 0) { snprintf(temp, PATH_MAX, "%s/share/int/txtfiles/%s/onceonly.ans", getenv("FTND_ROOT"), CFG.deflang); stat(temp, &st); } if (st.st_mtime == 0) { snprintf(temp, PATH_MAX, "%s/share/int/txtfiles/%s/onceonly.asc", getenv("FTND_ROOT"), lang.lc); stat(temp, &st); if (st.st_mtime == 0) { snprintf(temp, PATH_MAX, "%s/share/int/txtfiles/%s/onceonly.asc", getenv("FTND_ROOT"), CFG.deflang); stat(temp, &st); } } if ((st.st_mtime != 0) && (LastLogin < st.st_mtime)) DisplayFile((char *)"onceonly"); OLR_SyncTags(); if (exitinfo.MailScan) { IsDoing("New mail check"); CheckMail(); } /* * We don't show new files to new users. */ if (exitinfo.ieFILE && (!IsNew)) { IsDoing("New files check"); NewfileScan(FALSE); } /* * Copy last file Area in to current Area */ SetFileArea(exitinfo.iLastFileArea); /* * Copy Last Message Area in to Current Msg Area */ SetMsgArea(usrconfig.iLastMsgArea); SetEmailArea((char *)"mailbox"); /* * Set or Reset the DoNotDisturb flag, now is the time * we may be interrupted. */ UserSilent(usrconfig.DoNotDisturb); /* * Start the menu. */ menu(); }
void nntp(void) { char buf[4096]; int len; while (TRUE) { IsDoing("Waiting"); len = get_nntp(buf, sizeof(buf) -1); if (len < 0) return; if (len == 0) continue; if (strcasestr(buf, (char *)"AUTHINFO PASS") == NULL) { Syslog('n', "< \"%s\"", printable(buf, 0)); } else { Syslog('n', "< \"AUTHINFO PASS ********\""); } if (! check_free()) { send_nntp("400 server closed"); return; } /* * Process received command */ if (strncasecmp(buf, "QUIT", 4) == 0) { send_nntp("205 Goodbye\r\n"); return; } else if (strncasecmp(buf, "AUTHINFO USER", 13) == 0) { auth_user(buf); } else if (strncasecmp(buf, "AUTHINFO PASS", 13) == 0) { auth_pass(buf); } else if (strncasecmp(buf, "ARTICLE", 7) == 0) { if (check_auth(buf)) command_abhs(buf); } else if (strncasecmp(buf, "BODY", 4) == 0) { if (check_auth(buf)) command_abhs(buf); } else if (strncasecmp(buf, "LIST", 4) == 0) { if (check_auth(buf)) command_list(buf); } else if (strncasecmp(buf, "GROUP", 5) == 0) { if (check_auth(buf)) command_group(buf); } else if (strncasecmp(buf, "HEAD", 4) == 0) { if (check_auth(buf)) command_abhs(buf); } else if (strncasecmp(buf, "POST", 4) == 0) { if (check_auth(buf)) command_post(buf); } else if (strncasecmp(buf, "IHAVE", 5) == 0) { send_nntp("435 Article not wanted - do not send it"); } else if (strncasecmp(buf, "NEWGROUPS", 9) == 0) { send_nntp("235 Warning: NEWGROUPS not implemented, returning empty list"); send_nntp("."); } else if (strncasecmp(buf, "NEWNEWS", 7) == 0) { send_nntp("230 Warning: NEWNEWS not implemented, returning empty list"); send_nntp("."); } else if (strncasecmp(buf, "SLAVE", 5) == 0) { send_nntp("202 Slave status noted"); } else if (strncasecmp(buf, "STAT", 4) == 0) { if (check_auth(buf)) command_abhs(buf); } else if (strncasecmp(buf, "MODE READER", 11) == 0) { if (check_auth(buf)) { if (authorized) send_nntp("200 Server ready, posting allowed"); else send_nntp("201 Server ready, no posting allowed"); } } else if (strncasecmp(buf, "XOVER", 5) == 0) { if (check_auth(buf)) command_xover(buf); } else if (strncasecmp(buf, "HELP", 4) == 0) { send_nntp("100 Help text follows"); send_nntp("Recognized commands:"); send_nntp(""); send_nntp("ARTICLE"); send_nntp("AUTHINFO"); send_nntp("BODY"); send_nntp("GROUP"); send_nntp("HEAD"); send_nntp("IHAVE (not implemented, messages are always rejected)"); send_nntp("LIST"); send_nntp("NEWGROUPS (not implemented, always returns an empty list)"); send_nntp("NEWNEWS (not implemented, always returns an empty list)"); send_nntp("POST"); send_nntp("QUIT"); send_nntp("SLAVE (has no effect)"); send_nntp("STAT"); send_nntp("XOVER"); send_nntp(""); send_nntp("FTNNNTP supports most of RFC-977 and also has support for AUTHINFO and"); send_nntp("limited XOVER support (RFC-2980)"); send_nntp("."); } else { send_nntp("500 Unknown command"); } } }
/* * Removes records who are marked for deletion. If there is still a file * on disk, it will be removed too. */ void PackFileBase(void) { FILE *pAreas; int i, iAreas, iAreasNew = 0, rc, iTotal = 0, iRemoved = 0; char *sAreas, fn[PATH_MAX]; struct _fdbarea *fdb_area = NULL; int purge; sAreas = calloc(PATH_MAX, sizeof(char)); IsDoing("Pack filebase"); if (!do_quiet) { mbse_colour(CYAN, BLACK); printf("Packing file database...\n"); } snprintf(sAreas, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT")); if ((pAreas = fopen (sAreas, "r")) == NULL) { WriteError("Can't open %s", sAreas); die(MBERR_INIT_ERROR); } fread(&areahdr, sizeof(areahdr), 1, pAreas); fseek(pAreas, 0, SEEK_END); iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize; for (i = 1; i <= iAreas; i++) { fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET); fread(&area, areahdr.recsize, 1, pAreas); if (area.Available) { if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); if (!do_quiet) { printf("\r%4d => %-44s", i, area.Name); fflush(stdout); } Marker(); if ((fdb_area = mbsedb_OpenFDB(i, 30)) == NULL) die(MBERR_GENERAL); purge = 0; while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) { iTotal++; if ((fdb.Deleted) || (fdb.Double) || (strcmp(fdb.Name, "") == 0)) { iRemoved++; purge++; if (fdb.Double) { Syslog('+', "Removed double record file \"%s\" from area %d", fdb.LName, i); } else { Syslog('+', "Removed file \"%s\" from area %d", fdb.LName, i); snprintf(fn, PATH_MAX, "%s/%s", area.Path, fdb.LName); rc = unlink(fn); if (rc && (errno != ENOENT)) WriteError("PackFileBase(): unlink %s failed, result %s", fn, strerror(rc)); snprintf(fn, PATH_MAX, "%s/%s", area.Path, fdb.Name); rc = unlink(fn); if (rc && (errno != ENOENT)) WriteError("PackFileBase(): unlink %s failed, result %s", fn, strerror(rc)); /* * If a dotted version (thumbnail) exists, remove it silently */ snprintf(fn, PATH_MAX, "%s/.%s", area.Path, fdb.Name); unlink(fn); } do_index = TRUE; } } if (purge) mbsedb_PackFDB(fdb_area); mbsedb_CloseFDB(fdb_area); iAreasNew++; } /* if area.Available */ } fclose(pAreas); Syslog('+', "Pack Areas [%6d] Files [%6d] Removed [%6d]", iAreasNew, iTotal, iRemoved); if (!do_quiet) { printf("\r \r"); fflush(stdout); } free(sAreas); }
/* * Scan for new news available at the nntp server. */ void ScanNews(void) { List *art = NULL; POverview tmp, old; FILE *pAreas; char *sAreas; struct msgareashdr Msgshdr; struct msgareas Msgs; IsDoing((char *)"Scan News"); if (nntp_connect() == -1) { WriteError("Can't connect to newsserver"); return; } if (get_xoverview()) { return; } if (!do_quiet) { mbse_colour(LIGHTGREEN, BLACK); printf("Scan for new news articles\n"); } sAreas = calloc(PATH_MAX, sizeof(char)); snprintf(sAreas, PATH_MAX, "%s/etc/mareas.data", getenv("MBSE_ROOT")); if(( pAreas = fopen (sAreas, "r")) == NULL) { WriteError("$Can't open Messages Areas File."); return; } fread(&Msgshdr, sizeof(Msgshdr), 1, pAreas); while (fread(&Msgs, Msgshdr.recsize, 1, pAreas) == 1) { fseek(pAreas, Msgshdr.syssize, SEEK_CUR); #ifdef USE_NEWSGATE if ((Msgs.Active) && strlen(Msgs.Newsgroup)) { #else if ((Msgs.Active) && strlen(Msgs.Newsgroup) && (Msgs.Type == NEWS)) { #endif if (IsSema((char *)"upsalarm")) { Syslog('+', "Detected upsalarm semafore, aborting newsscan"); break; } Syslog('m', "Scan newsgroup: %s", Msgs.Newsgroup); if (!do_quiet) { mbse_colour(CYAN, BLACK); printf("\r%-40s", Msgs.Newsgroup); fflush(stdout); } Nopper(); if (do_one_group(&art, Msgs.Newsgroup, Msgs.Tag, Msgs.MaxArticles) == RETVAL_ERROR) break; /* * To be safe, update the dupes database after each area. */ CloseDupes(); } } fclose(pAreas); free(sAreas); for (tmp = xoverview; tmp; tmp = old) { old = tmp->next; if (tmp->header) free(tmp->header); if (tmp->field) free(tmp->field); free(tmp); } nntp_close(); do_flush = TRUE; if (!do_quiet) printf("\r \r"); } int do_one_group(List **art, char *grpname, char *ftntag, int maxarticles) { List *tmp; char temp[128], *resp; int retval, fetched = 0; int total, start, end; Syslog('m', "do_one_group(%s, %s)", grpname, ftntag); IsDoing((char *)"Scan %s", grpname); snprintf(temp, 128, "GROUP %s\r\n", grpname); nntp_send(temp); resp = nntp_receive(); retval = atoi(strtok(resp, " ")); if (retval == 480) { /* * We must login */ if (nntp_auth() == FALSE) { WriteError("Authorisation failure"); nntp_close(); return RETVAL_NOAUTH; } nntp_send(temp); resp = nntp_receive(); retval = atoi(strtok(resp, " ")); } if (retval != 211) { if (retval == 411) { WriteError("No such newsgroup: %s", grpname); return RETVAL_UNEXPECTEDANS; } WriteError("Unknown response %d to GROUP command", retval); return RETVAL_ERROR; } total = atol(strtok(NULL, " ")); start = atol(strtok(NULL, " ")); end = atol(strtok(NULL, " '\0'")); Syslog('m', "GROUP total %d, start %d, end %d, max %d", total, start, end, maxarticles); if ((maxarticles) && (total > maxarticles)) { start = end - maxarticles; total = maxarticles; Syslog('m', "NEW: total %d, start %d, end %d", total, start, end); } if (!total) { Syslog('+', "Fetched 0 articles from %s", grpname); return RETVAL_NOARTICLES; } retval = get_xover(grpname, start, end, art); if (retval != RETVAL_OK) { tidy_artlist(art); return retval; } if (!do_learn) { for (tmp = *art; tmp; tmp = tmp->next) { if (!tmp->isdupe) { /* * If the message isn't a dupe, it must be new for us. */ get_article(tmp->msgid, ftntag); fetched++; } } } tidy_artlist(art); if ((maxarticles) && (fetched == maxarticles)) Syslog('!', "Warning: the max. articles value in newsgroup %s might be to low", grpname); Syslog('+', "Fetched %d article%s from %s", fetched, (fetched == 1) ? "":"s", grpname); return RETVAL_OK; }
/* * Edit one record, return -1 if there are errors, 0 if ok. */ int EditMagicRec(int Area) { FILE *fil; char mfile[PATH_MAX]; int offset; int j, choices; unsigned int crc, crc1; clr_index(); working(1, 0, 0); IsDoing("Edit Magics"); snprintf(mfile, PATH_MAX, "%s/etc/magic.temp", getenv("FTND_ROOT")); if ((fil = fopen(mfile, "r")) == NULL) { working(2, 0, 0); return -1; } offset = sizeof(magichdr) + ((Area -1) * sizeof(magic)); if (fseek(fil, offset, 0) != 0) { working(2, 0, 0); return -1; } fread(&magic, sizeof(magic), 1, fil); fclose(fil); crc = 0xffffffff; crc = upd_crc32((char *)&magic, crc, sizeof(magic)); for (;;) { ScreenM(); FieldsM(); switch(magic.Attrib) { case MG_UPDALIAS: case MG_DELETE: choices = 5; break; case MG_EXEC: case MG_COPY: case MG_UNPACK: choices = 7; break; default: choices = 6; } j = select_menu(choices); switch(j) { case 0: crc1 = 0xffffffff; crc1 = upd_crc32((char *)&magic, crc1, sizeof(magic)); if (crc != crc1) { if (yes_no((char *)"Record is changed, save") == 1) { working(1, 0, 0); if ((fil = fopen(mfile, "r+")) == NULL) { working(2, 0, 0); return -1; } fseek(fil, offset, 0); fwrite(&magic, sizeof(magic), 1, fil); fclose(fil); MagicUpdated = 1; working(6, 0, 0); } } IsDoing("Browsing Menu"); return 0; case 1: magic.Attrib = edit_magictype(7,16, magic.Attrib); break; case 2: E_STR( 8,16,14, magic.Mask, "File ^mask^ to test for this magic") case 3: E_BOOL( 9,16, magic.Active, "Is this magic ^active^") case 4: E_BOOL(10,16, magic.Deleted,"Is this record ^deleted^") case 5: strcpy(magic.From, PickTicarea((char *)"10.4.5")); break; case 6: switch(magic.Attrib) { case MG_ADOPT: case MG_MOVE: strcpy(magic.ToArea, PickTicarea((char *)"10.4.6")); break; case MG_COPY: case MG_UNPACK: E_PTH(12,16,64, magic.Path, "The ^path^ to use", 0750) case MG_EXEC: E_STR(12,16,64, magic.Cmd, "The ^command^ to execute") case MG_KEEPNUM: E_INT(12,16, magic.KeepNum,"The number of files to ^keep^") } break; case 7: E_BOOL(13,16, magic.Compile, "Trigger the ^compile nodelist^ flag") } } return 0; }
void DoMsgBase() { FILE *pAreas; char *sAreas, *Name; int arearec; int Del = 0; sAreas = calloc(PATH_MAX, sizeof(char)); Name = calloc(PATH_MAX, sizeof(char )); IsDoing("Msg Maintenance"); if (do_area) Syslog('+', "Processing message area %ld", do_area); else Syslog('+', "Processing all message areas"); if (do_kill) { Syslog('-', " Total Max. Days/Killed Max. Nr/Killed Area name"); Syslog('-', "------ ------ ------ ------ ------ ----------------------------------"); } snprintf(sAreas, PATH_MAX, "%s/etc/mareas.data", getenv("MBSE_ROOT")); if(( pAreas = fopen (sAreas, "r")) == NULL) { WriteError("$Can't open %s", sAreas); die(MBERR_GENERAL); } fread(&msgshdr, sizeof(msgshdr), 1, pAreas); if (do_area) { if (fseek(pAreas, (msgshdr.recsize + msgshdr.syssize) * (do_area - 1), SEEK_CUR) == 0) { fread(&msgs, msgshdr.recsize, 1, pAreas); if (msgs.Active) { if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); if (!do_quiet) { mbse_colour(CYAN, BLACK); printf("\r%5d .. %-40s", do_area, msgs.Name); fflush(stdout); } are_tot++; mkdirs(msgs.Base, 0770); if (do_kill) KillArea(msgs.Base, msgs.Name, msgs.DaysOld, msgs.MaxMsgs, do_area); if (do_pack || msg_del) PackArea(msgs.Base, do_area); if (do_link) LinkArea(msgs.Base, do_area); if (processed) are_proc++; } } } else { arearec = 0; while (fread(&msgs, msgshdr.recsize, 1, pAreas) == 1) { fseek(pAreas, msgshdr.syssize, SEEK_CUR); arearec++; if (msgs.Active) { if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); Nopper(); if (!do_quiet) { mbse_colour(CYAN, BLACK); printf("\r%5d .. %-40s", arearec, msgs.Name); fflush(stdout); } are_tot++; mkdirs(msgs.Base, 0770); processed = FALSE; if (do_kill) KillArea(msgs.Base, msgs.Name, msgs.DaysOld, msgs.MaxMsgs, arearec); if (do_pack || (Del != msg_del)) { PackArea(msgs.Base, arearec); } Del = msg_del; if (do_link) LinkArea(msgs.Base, arearec); if (processed) are_proc++; } } } fclose(pAreas); if (!do_area) { snprintf(sAreas, PATH_MAX, "%s/etc/users.data", getenv("MBSE_ROOT")); if ((pAreas = fopen (sAreas, "r")) == NULL) { WriteError("$Can't open %s", sAreas); die(MBERR_GENERAL); } fread(&usrconfighdr, sizeof(usrconfighdr), 1, pAreas); while (fread(&usrconfig, usrconfighdr.recsize, 1, pAreas) == 1) { if (usrconfig.Email && strlen(usrconfig.Name)) { Nopper(); snprintf(Name, PATH_MAX, "User %s email area: mailbox", usrconfig.Name); if (!do_quiet) { mbse_colour(CYAN, BLACK); printf("\r .. %-40s", Name); fflush(stdout); } snprintf(sAreas, PATH_MAX, "%s/%s/mailbox", CFG.bbs_usersdir, usrconfig.Name); are_tot++; processed = FALSE; if (do_kill) KillArea(sAreas, Name, 0, CFG.defmsgs, 0); if (do_pack || (Del != msg_del)) { PackArea(sAreas, 0); } Del = msg_del; if (do_link) LinkArea(sAreas, 0); if (processed) are_proc++; snprintf(sAreas, PATH_MAX, "%s/%s/archive", CFG.bbs_usersdir, usrconfig.Name); snprintf(Name, 80, "User %s email area: archive", usrconfig.Name); are_tot++; processed = FALSE; if (do_kill) KillArea(sAreas, Name, 0, CFG.defmsgs, 0); if (do_pack || (Del != msg_del)) PackArea(sAreas, 0); Del = msg_del; if (do_link) LinkArea(sAreas, 0); if (processed) are_proc++; snprintf(sAreas, PATH_MAX, "%s/%s/trash", CFG.bbs_usersdir, usrconfig.Name); snprintf(Name, 80, "User %s email area: trash", usrconfig.Name); are_tot++; processed = FALSE; if (do_kill) KillArea(sAreas, Name, CFG.defdays, CFG.defmsgs, 0); if (do_pack || (Del != msg_del)) PackArea(sAreas, 0); Del = msg_del; if (do_link) LinkArea(sAreas, 0); if (processed) are_proc++; } } fclose(pAreas); } if (do_link) RemoveSema((char *)"msglink"); free(sAreas); free(Name); die(MBERR_OK); }
void EditMagics(void) { int records, i, o, x, y; char pick[12]; FILE *fil; char temp[PATH_MAX]; int offset; clr_index(); working(1, 0, 0); IsDoing("Browsing Menu"); if (config_read() == -1) { working(2, 0, 0); return; } records = CountMagics(); if (records == -1) { working(2, 0, 0); return; } if (OpenMagics() == -1) { working(2, 0, 0); return; } o = 0; for (;;) { clr_index(); set_color(WHITE, BLACK); ftnd_mvprintw( 5, 2, "10.4. MAGICS EDITOR"); set_color(CYAN, BLACK); if (records != 0) { snprintf(temp, PATH_MAX, "%s/etc/magic.temp", getenv("FTND_ROOT")); working(1, 0, 0); if ((fil = fopen(temp, "r")) != NULL) { fread(&magichdr, sizeof(magichdr), 1, fil); x = 2; y = 7; set_color(CYAN, BLACK); for (i = 1; i <= 20; i++) { if (i == 11) { x = 42; y = 7; } if ((o + i) <= records) { offset = sizeof(magichdr) + (((i + o) - 1) * magichdr.recsize); fseek(fil, offset, 0); fread(&magic, magichdr.recsize, 1, fil); if (magic.Active) set_color(CYAN, BLACK); else set_color(LIGHTBLUE, BLACK); snprintf(temp, 81, "%3d. %s %s", o + i, getmagictype(magic.Attrib), magic.Mask); temp[37] = 0; ftnd_mvprintw(y, x, temp); y++; } } fclose(fil); } } strcpy(pick, select_record(records, 20)); if (strncmp(pick, "-", 1) == 0) { CloseMagics(FALSE); return; } if (strncmp(pick, "A", 1) == 0) { working(1, 0, 0); if (AppendMagics() == 0) { records++; working(1, 0, 0); } else working(2, 0, 0); } if (strncmp(pick, "N", 1) == 0) if ((o + 20) < records) o = o + 20; if (strncmp(pick, "P", 1) == 0) if ((o - 20) >= 0) o = o - 20; if ((atoi(pick) >= 1) && (atoi(pick) <= records)) { EditMagicRec(atoi(pick)); o = ((atoi(pick) - 1) / 20) * 20; } } }
/* * Kill messages according to age and max messages. */ void KillArea(char *Path, char *Name, int DaysOld, int MaxMsgs, int Areanr) { unsigned int Number, TotalMsgs = 0, *Active, Counter = 0; int i, DelCount = 0, DelAge = 0, Done; time_t Today, MsgDate; IsDoing("Killing %ld", Areanr); Today = time(NULL) / 86400L; if (Msg_Open(Path)) { if (!do_quiet) { mbse_colour(LIGHTRED, BLACK); printf(" (Killing)"); mbse_colour(LIGHTMAGENTA, BLACK); fflush(stdout); } if (Msg_Lock(30L)) { TotalMsgs = Msg_Number(); if (TotalMsgs) { if ((Active = (unsigned int *)malloc((size_t)((TotalMsgs + 100L) * sizeof(unsigned int)))) != NULL) { i = 0; Number = Msg_Lowest(); do { Active[i++] = Number; } while (Msg_Next(&Number) == TRUE); } } else Active = NULL; Number = Msg_Lowest(); do { if (CFG.slow_util && do_quiet) msleep(1); if ((!do_quiet) && ((Counter % 10L) == 0)) { printf("%6u / %6u\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", Counter, TotalMsgs); fflush(stdout); } if ((Counter % 10L) == 0) DoNop(); Counter++; msg_tot++; if (Msg_ReadHeader(Number) == TRUE) { Done = FALSE; if (DaysOld) { /* * GoldED doesn't fill the Msg.Arrived field, use the * written date instead. */ if (Msg.Arrived == 0L) MsgDate = Msg.Written / 86400L; else MsgDate = Msg.Arrived / 86400L; if ((Today - MsgDate) > DaysOld) { Msg_Delete(Number); Done = TRUE; DelAge++; msg_del++; if (Active != NULL) { for (i = 0; i < TotalMsgs; i++) { if (Active[i] == Number) Active[i] = 0L; } } } } if (Done == FALSE && (MaxMsgs) && Msg_Number() > MaxMsgs) { Msg_Delete(Number); DelCount++; msg_del++; if (Active != NULL) { for (i = 0; i < TotalMsgs; i++) { if (Active[i] == Number) Active[i] = 0L; } } } } } while (Msg_Next(&Number) == TRUE); if (Active != NULL) free(Active); Msg_UnLock(); } else { Syslog('+', "Can't lock msgbase %s", Path); } if (!do_quiet) { printf(" \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } Msg_Close(); Syslog('-', "%6d %6d %6d %6d %6d %s", TotalMsgs, DaysOld, DelAge, MaxMsgs, DelCount, Name); if (!do_quiet) { printf("\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } } else Syslog('+', "Failed to open %s", Path); }
/* * returns: -1 = Errors. * 0 = No files processed * 1 = Processed file(s) */ int Tic() { char *inbound, *fname; DIR *dp; struct dirent *de; struct stat sbuf; int i, rc = 0, Age; fd_list *fdl = NULL; orphans *opl = NULL, *tmp; time_t Now, Fdate; IsDoing("Process .tic files"); CompileNL = FALSE; if (do_unprot) { inbound = xstrcpy(CFG.inbound); } else { inbound = xstrcpy(CFG.pinbound); } Syslog('+', "Pass: process ticfiles (%s)", inbound); if (enoughspace(CFG.freespace) == 0) { Syslog('+', "Low diskspace, abort tic processing"); free(inbound); return -1; } if (chdir(inbound) == -1) { WriteError("$Can't chdir(%s)", inbound); free(inbound); return -1; } if ((dp = opendir(inbound)) == NULL) { WriteError("$Can't opendir(%s)", inbound); free(inbound); return -1; } while ((de = readdir(dp))) { if ((strlen(de->d_name) == 12) && (strncasecmp(de->d_name+11, "c", 1) == 0)) { if ((strncasecmp(de->d_name+8, ".a", 2) == 0) || (strncasecmp(de->d_name+8, ".c", 2) == 0) || (strncasecmp(de->d_name+8, ".z", 2) == 0) || (strncasecmp(de->d_name+8, ".l", 2) == 0) || (strncasecmp(de->d_name+8, ".r", 2) == 0) || (strncasecmp(de->d_name+8, ".0", 2) == 0)) { if (checkspace(inbound, de->d_name, UNPACK_FACTOR)) { if ((unpack(de->d_name)) != 0) { WriteError("Error unpacking %s", de->d_name); } } else { Syslog('+', "Insufficient space to unpack file %s", de->d_name); } } } } rewinddir(dp); while ((de = readdir(dp))) { if ((strlen(de->d_name) == 12) && (strncasecmp(de->d_name+8, ".tic", 4) == 0)) { stat(de->d_name, &sbuf); fill_fdlist(&fdl, de->d_name, sbuf.st_mtime); } } closedir(dp); sort_fdlist(&fdl); while ((fname = pull_fdlist(&fdl)) != NULL) { if (LoadTic(inbound, fname, &opl) == 0) rc = 1; if (IsSema((char *)"upsalarm")) { rc = 0; Syslog('+', "Detected upsalarm semafore, aborting tic processing"); break; } if (enoughspace(CFG.freespace) == 0) { Syslog('+', "Low diskspace, aborting tic processing"); rc = 0; break; } } if (!do_quiet) { printf("\r"); for (i = 0; i < 79; i++) printf(" "); printf("\r"); fflush(stdout); } if (rc) do_flush = TRUE; if (CompileNL) CreateSema((char *)"ftnindex"); /* * Handle the array with orphaned and bad crc ticfiles. */ Now = time(NULL); for (tmp = opl; tmp; tmp = tmp->next) { /* * Bad CRC and not marked purged are real crc errors. */ if (tmp->BadCRC && (! tmp->Purged)) { Syslog('+', "Moving %s and %s to badtic directory", tmp->TicName, tmp->FileName); mover(tmp->TicName); mover(tmp->FileName); tic_bad++; } /* * Orphans that are not marked purged are real orphans, check age. */ if (tmp->Orphaned && (! tmp->Purged)) { fname = calloc(PATH_MAX, sizeof(char)); snprintf(fname, PATH_MAX, "%s/%s", inbound, tmp->TicName); Fdate = file_time(fname); Age = (Now - Fdate) / 84400; if (Age > 21) { Syslog('+', "Moving %s of %d days old to badtic", tmp->TicName, Age); tic_bad++; mover(tmp->TicName); } else { Syslog('+', "Keeping %s of %d days old for %d days", tmp->TicName, Age, 21 - Age); } free(fname); } /* * If marked to purge, remove the ticfile */ if (tmp->Purged) { fname = calloc(PATH_MAX, sizeof(char)); snprintf(fname, PATH_MAX, "%s/%s", inbound, tmp->TicName); unlink(fname); Syslog('+', "Removing obsolete %s", tmp->TicName); free(fname); } } tidy_orphans(&opl); free(inbound); return rc; }
void Masterlist() { FILE *fp, *np, *fu, *nu, *pAreas, *pHeader; int AreaNr = 0, z, x = 0, New; unsigned int AllFiles = 0, AllKBytes = 0, NewFiles = 0, NewKBytes = 0; unsigned int AllAreaFiles, AllAreaBytes, popdown, down, NewAreaFiles, NewAreaBytes; char *sAreas, temp[PATH_MAX], pop[81]; struct _fdbarea *fdb_area = NULL; sAreas = calloc(PATH_MAX, sizeof(char)); IsDoing("Create Allfiles list"); snprintf(sAreas, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT")); if(( pAreas = fopen (sAreas, "r")) == NULL) { WriteError("Can't open File Areas File: %s", sAreas); mbse_colour(LIGHTGRAY, BLACK); die(MBERR_GENERAL); } fread(&areahdr, sizeof(areahdr), 1, pAreas); if (!do_quiet) printf("Processing file areas\n"); if ((fp = fopen("allfiles.tmp", "a+")) == NULL) { WriteError("$Can't open allfiles.tmp"); die(MBERR_GENERAL); } if ((np = fopen("newfiles.tmp", "a+")) == NULL) { WriteError("$Can't open newfiles.tmp"); fclose(fp); die(MBERR_GENERAL); } if ((fu = fopen("allfiles.ump", "a+")) == NULL) { WriteError("$Can't open allfiles.ump"); fclose(fp); fclose(np); die(MBERR_GENERAL); } if ((nu = fopen("newfiles.ump", "a+")) == NULL) { WriteError("$Can't open newfiles.ump"); fclose(fp); fclose(np); fclose(fu); die(MBERR_GENERAL); } chartran_init((char *)"CP437", (char *)"UTF-8", 'B'); TopBox(fp, fu, TRUE); TopBox(np, nu, TRUE); snprintf(temp, 81, "All available files at %s", CFG.bbs_name); MidLine(temp, fp, fu, TRUE); snprintf(temp, 81, "New available files since %d days at %s", CFG.newdays, CFG.bbs_name); MidLine(temp, np, nu, TRUE); BotBox(fp, fu, TRUE); BotBox(np, nu, TRUE); snprintf(temp, PATH_MAX, "%s/etc/header.txt", getenv("MBSE_ROOT")); if (( pHeader = fopen(temp, "r")) != NULL) { Syslog('+', "Inserting %s", temp); while( fgets(temp, 80 ,pHeader) != NULL) { Striplf(temp); fprintf(fp, "%s\r\n", temp); fprintf(np, "%s\r\n", temp); fprintf(fu, "%s\r\n", chartran(temp)); fprintf(nu, "%s\r\n", chartran(temp)); } fclose(pHeader); } while (fread(&area, areahdr.recsize, 1, pAreas) == 1) { AreaNr++; AllAreaFiles = 0; AllAreaBytes = 0; NewAreaFiles = 0; NewAreaBytes = 0; if (area.Available && (area.LTSec.level <= CFG.security.level)) { Nopper(); if ((fdb_area = mbsedb_OpenFDB(AreaNr, 30)) == 0) { WriteError("Can't open Area %d (%s)! Skipping ...", AreaNr, area.Name); } else { popdown = 0; while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) { if (!fdb.Deleted) { /* * The next is to reduce system load. */ x++; if (CFG.slow_util && do_quiet && ((x % 3) == 0)) msleep(1); AllFiles++; AllAreaFiles++; AllAreaBytes += fdb.Size; down = fdb.TimesDL; if (down > popdown) { popdown = down; snprintf(pop, 81, "%s", fdb.Name); } if (((t_start - fdb.UploadDate) / 84400) <= CFG.newdays) { NewFiles++; NewAreaFiles++; NewAreaBytes += fdb.Size; } } } AllKBytes += AllAreaBytes / 1024; NewKBytes += NewAreaBytes / 1024; /* * If there are files to report do it. */ if (AllAreaFiles) { TopBox(fp, fu, TRUE); TopBox(np, nu, NewAreaFiles); snprintf(temp, 81, "Area %d - %s", AreaNr, area.Name); MidLine(temp, fp, fu, TRUE); MidLine(temp, np, nu, NewAreaFiles); snprintf(temp, 81, "File Requests allowed"); MidLine(temp, fp, fu, area.FileReq); MidLine(temp, np, nu, area.FileReq && NewAreaFiles); snprintf(temp, 81, "%d KBytes in %d files", AllAreaBytes / 1024, AllAreaFiles); MidLine(temp, fp, fu, TRUE); snprintf(temp, 81, "%d KBytes in %d files", NewAreaBytes / 1024, NewAreaFiles); MidLine(temp, np, nu, NewAreaFiles); if (popdown) { snprintf(temp, 81, "Most popular file is %s", pop); MidLine(temp, fp, fu, TRUE); } BotBox(fp, fu, TRUE); BotBox(np, nu, NewAreaFiles); fseek(fdb_area->fp, fdbhdr.hdrsize, SEEK_SET); while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) { if (!fdb.Deleted) { New = (((t_start - fdb.UploadDate) / 84400) <= CFG.newdays); snprintf(temp, 81, "%s", fdb.LName); WriteFiles(fp, fu, np, nu, New, temp); snprintf(temp, 81, "%-12s%10u K %s [%04d] Uploader: %s", fdb.Name, (int)(fdb.Size / 1024), StrDateDMY(fdb.UploadDate), fdb.TimesDL, strlen(fdb.Uploader)?fdb.Uploader:""); WriteFiles(fp, fu, np, nu, New, temp); for (z = 0; z < 25; z++) { if (strlen(fdb.Desc[z])) { if ((fdb.Desc[z][0] == '@') && (fdb.Desc[z][1] == 'X')) { snprintf(temp, 81, " %s", fdb.Desc[z]+4); } else { snprintf(temp, 81, " %s", fdb.Desc[z]); } WriteFiles(fp, fu, np, nu, New, temp); } } if (strlen(fdb.Magic)) { snprintf(temp, 81, " Magic filerequest: %s", fdb.Magic); WriteFiles(fp, fu, np, nu, New, temp); } WriteFiles(fp, fu, np, nu, New, (char *)""); } } } mbsedb_CloseFDB(fdb_area); } } } /* End of While Loop Checking for Areas Done */ fclose(pAreas); TopBox(fp, fu, TRUE); TopBox(np, nu, TRUE); snprintf(temp, 81, "Total %d files, %d KBytes", AllFiles, AllKBytes); MidLine(temp, fp, fu, TRUE); snprintf(temp, 81, "Total %d files, %d KBytes", NewFiles, NewKBytes); MidLine(temp, np, nu, TRUE); MidLine((char *)"", fp, fu, TRUE); MidLine((char *)"", np, nu, TRUE); snprintf(temp, 81, "Created by MBSE BBS v%s (%s-%s) at %s", VERSION, OsName(), OsCPU(), StrDateDMY(t_start)); MidLine(temp, fp, fu, TRUE); MidLine(temp, np, nu, TRUE); BotBox(fp, fu, TRUE); BotBox(np, nu, TRUE); snprintf(temp, PATH_MAX, "%s/etc/footer.txt", getenv("MBSE_ROOT")); if(( pHeader = fopen(temp, "r")) != NULL) { Syslog('+', "Inserting %s", temp); while( fgets(temp, 80 ,pHeader) != NULL) { Striplf(temp); fprintf(fp, "%s\r\n", temp); fprintf(np, "%s\r\n", temp); fprintf(fu, "%s\r\n", chartran(temp)); fprintf(nu, "%s\r\n", chartran(temp)); } fclose(pHeader); } fclose(fp); fclose(np); fclose(fu); fclose(nu); chartran_close(); if ((rename("allfiles.tmp", "allfiles.txt")) == 0) unlink("allfiles.tmp"); if ((rename("newfiles.tmp", "newfiles.txt")) == 0) unlink("newfiles.tmp"); if ((rename("allfiles.ump", "allfiles.utf")) == 0) unlink("allfiles.ump"); if ((rename("newfiles.ump", "newfiles.utf")) == 0) unlink("newfiles.ump"); Syslog('+', "Allfiles: %ld, %ld MBytes", AllFiles, AllKBytes / 1024); Syslog('+', "Newfiles: %ld, %ld MBytes", NewFiles, NewKBytes / 1024); free(sAreas); }
void Good_Bye(int onsig) { FILE *pUsrConfig, *pExitinfo; char *temp; int offset; time_t t_end; int i; IsDoing("Hangup"); temp = calloc(PATH_MAX, sizeof(char)); Syslog('+', "Good_Bye(%d)", onsig); /* * Don't display goodbye screen on SIGHUP and idle timeout. * With idle timeout this will go into a loop. */ if ((onsig != SIGALRM) && (onsig != FTNERR_TIMEOUT) && (hanged_up == 0)) DisplayFile((char *)"goodbye"); SaveLastCallers(); /* * Update the users database record. */ snprintf(temp, PATH_MAX, "%s/etc/users.data", getenv("FTND_ROOT")); if ((pUsrConfig = fopen(temp,"r+")) != NULL) { snprintf(temp, PATH_MAX, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name); if ((pExitinfo = fopen(temp,"rb")) != NULL) { fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig); fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo); usrconfig = exitinfo; fclose(pExitinfo); usrconfig.iLastFileArea = iAreaNumber; /* If time expired, do not say say successful logoff */ if (!iExpired && !hanged_up) Syslog('+', "User successfully logged off BBS"); usrconfig.iLastMsgArea = iMsgAreaNumber; offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize); if (fseek(pUsrConfig, offset, SEEK_SET) != 0) { WriteError("$Can't move pointer in file %s/etc/users.data", getenv("FTND_ROOT")); } else { fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig); } fclose(pUsrConfig); } } /* * Update mib counters */ t_end = time(NULL); mib_minutes = (unsigned int) ((t_end - t_start) / 60); mib_sessions++; sendmibs(); /* * Flush all data to the user, wait 5 seconds to * be sure the user received all data. */ if ((onsig != SIGALRM) && (onsig != FTNERR_TIMEOUT) && (hanged_up == 0)) { colour(LIGHTGRAY, BLACK); sleep(4); } for (i = 0; i < NSIG; i++) { if (i == SIGCHLD) signal(i, SIG_DFL); else if ((i != SIGKILL) && (i != SIGSTOP)) signal(i, SIG_DFL); } if ((onsig != SIGALRM) && (onsig != FTNERR_TIMEOUT) && (hanged_up == 0)) { cookedport(); } /* * Ignore SIGHUP during hangup. */ signal(SIGHUP, SIG_IGN); hangup(); for (i = 0; i < NSIG; i++) { if ((i == SIGHUP) || (i == SIGPIPE) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) signal(i, SIG_DFL); } if (do_mailout) CreateSema((char *)"mailout"); t_end = time(NULL); Syslog(' ', "FTNDBBS finished in %s", t_elapsed(t_start, t_end)); sleep(1); /* * Start shutting down this session, cleanup some files. */ socket_shutdown(mypid); snprintf(temp, PATH_MAX, "%s/tmp/ftnd%d", getenv("FTND_ROOT"), getpid()); unlink(temp); snprintf(temp, PATH_MAX, "%s/%s/.quote", CFG.bbs_usersdir, exitinfo.Name); unlink(temp); snprintf(temp, PATH_MAX, "%s/%s/data.msg", CFG.bbs_usersdir, exitinfo.Name); unlink(temp); snprintf(temp, PATH_MAX, "%s/%s/door.sys", CFG.bbs_usersdir, exitinfo.Name); unlink(temp); snprintf(temp, PATH_MAX, "%s/%s/door32.sys", CFG.bbs_usersdir, exitinfo.Name); unlink(temp); snprintf(temp, PATH_MAX, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name); unlink(temp); free(temp); unlink("taglist"); Free_Language(); free(pTTY); if (StartTime) free(StartTime); deinitnl(); exit(onsig); }
/* * Edit one record, return -1 if there are errors, 0 if ok. */ int EditNGrpRec(int Area) { FILE *fil; char mfile[PATH_MAX]; int offset; int j; unsigned int crc, crc1; clr_index(); working(1, 0, 0); IsDoing("Edit NewfileGroup"); snprintf(mfile, PATH_MAX, "%s/etc/ngroups.temp", getenv("FTND_ROOT")); if ((fil = fopen(mfile, "r")) == NULL) { working(2, 0, 0); return -1; } offset = sizeof(ngrouphdr) + ((Area -1) * sizeof(ngroup)); if (fseek(fil, offset, 0) != 0) { working(2, 0, 0); return -1; } fread(&ngroup, sizeof(ngroup), 1, fil); fclose(fil); crc = 0xffffffff; crc = upd_crc32((char *)&ngroup, crc, sizeof(ngroup)); NgScreen(); for (;;) { set_color(WHITE, BLACK); show_str( 7,18,12, ngroup.Name); show_str( 8,18,55, ngroup.Comment); show_bool( 9,18, ngroup.Active); show_bool(10,18, ngroup.Deleted); j = select_menu(4); switch(j) { case 0: crc1 = 0xffffffff; crc1 = upd_crc32((char *)&ngroup, crc1, sizeof(ngroup)); if (crc != crc1) { if (yes_no((char *)"Record is changed, save") == 1) { working(1, 0, 0); if ((fil = fopen(mfile, "r+")) == NULL) { working(2, 0, 0); return -1; } fseek(fil, offset, 0); fwrite(&ngroup, sizeof(ngroup), 1, fil); fclose(fil); NGrpUpdated = 1; working(6, 0, 0); } } IsDoing("Browsing Menu"); return 0; case 1: E_UPS( 7,18,12,ngroup.Name,"The ^name^ for this message group") case 2: E_STR( 8,18,55,ngroup.Comment,"The ^desription^ for this message group") case 3: E_BOOL(9,18, ngroup.Active, "Is this message group ^active^") case 4: E_BOOL(10,18, ngroup.Deleted, "Is this group ^Deleted^") } } return 0; }
int Announce() { gr_list *fgr = NULL, *tmp; char *temp; FILE *fp; int Count = 0, rc = FALSE; int filepos, filepos1, filepos2; char group[13]; int i, groups, any; if (!do_quiet) { mbse_colour(CYAN, BLACK); printf("Announce new files\n"); } Uploads(); IsDoing("Announce files"); temp = calloc(PATH_MAX, sizeof(char)); snprintf(temp, PATH_MAX, "%s/etc/toberep.data", getenv("MBSE_ROOT")); if ((fp = fopen(temp, "r")) == NULL) { Syslog('+', "No new files to announce"); free(temp); if (!do_quiet) { printf(" No new files.\n"); } return FALSE; } if (!do_quiet) printf(" Preparing reports...\n"); while (fread(&T_File, sizeof(T_File), 1, fp) == 1) { if (T_File.Announce) { fill_grlist(&fgr, T_File.Group, T_File.Echo); Count++; } } fclose(fp); if (Count == 0) { unlink(temp); if (!do_quiet) printf(" No new files.\n"); Syslog('+', "No new files to announce"); free(temp); return FALSE; } if (!do_quiet) printf(" %d new files found\n", Count); sort_grlist(&fgr); /* * At this point we have a sorted list of groups with a counter * indicating howmany files to report in each group. */ snprintf(temp, PATH_MAX, "%s/etc/newfiles.data", getenv("MBSE_ROOT")); if ((fp = fopen(temp, "r")) == NULL) { WriteError("$Can't open %s", temp); if (!do_quiet) printf(" No newfile reports defined\n"); free(temp); return FALSE; } fread(&newfileshdr, sizeof(newfileshdr), 1, fp); groups = newfileshdr.grpsize / 13; while (fread(&newfiles, newfileshdr.recsize, 1, fp) == 1) { if (newfiles.Active) { filepos = ftell(fp); if (!do_quiet) printf(" %s\n", newfiles.Comment); any = FALSE; for (i = 0; i < groups; i++) { fread(&group, 13, 1, fp); for (tmp = fgr; tmp; tmp = tmp->next) if (strcmp(tmp->group, group) == 0) any = TRUE; } if (any) { fseek(fp, filepos, SEEK_SET); rc = TRUE; Syslog('+', "Create report: %s", newfiles.Comment); MsgCount = 1; if ((filepos1 = StartMsg()) != -1) { filepos2 = 0; while (fread(&group, 13, 1, fp) == 1) { for (tmp = fgr; tmp; tmp = tmp->next) { if (!strcmp(tmp->group, group)) { filepos2 = Report(tmp, filepos1); } } } FinishMsg(TRUE, filepos2); } } else { if (!do_quiet) printf(" No matching groups\n"); } fseek(fp, filepos, SEEK_SET); } fseek(fp, newfileshdr.grpsize, SEEK_CUR); } fclose(fp); tidy_grlist(&fgr); if (rc) { snprintf(temp, PATH_MAX, "%s/etc/toberep.data", getenv("MBSE_ROOT")); unlink(temp); } free(temp); return rc; }
void site_docs(void) { FILE *fp, *hp, *toc; char temp[PATH_MAX], temp1[PATH_MAX]; int page = 0, line = 0; if (config_read() == -1) return; snprintf(temp, PATH_MAX, "%s/share/doc/site.doc", getenv("FTND_ROOT")); mkdirs(temp, 0755); if ((fp = fopen(temp, "w")) == NULL) return; snprintf(temp1, PATH_MAX, "%s/tmp/toc.tmp", getenv("FTND_ROOT")); if ((toc = fopen(temp1, "w+")) == NULL) { fclose(fp); return; } clr_index(); working(1, 0, 0); IsDoing("Making Sitedocs"); Syslog('+', "Start creating sitedocs"); set_color(WHITE, BLACK); ftnd_mvprintw( 5, 6, "21. CREATING SITEDOCS"); set_color(CYAN, BLACK); ftnd_mvprintw( 7,11, (char *)"Erasing directory %s/share/doc/html", getenv("FTND_ROOT")); fflush(stdout); snprintf(temp, PATH_MAX, "-r -f %s/share/doc/html", getenv("FTND_ROOT")); execute_pth((char *)"rm", temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); if ((hp = open_webdoc((char *)"index.html", (char *)"BBS Site Documentation", NULL))) { fprintf(hp, "<UL>\n"); fprintf(hp, " <LI><A HREF=\"global.html\">Global Configuration</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"fidonet.html\">Fido Networks</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"archivers.html\">Archivers</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"virscan.html\">Virus Scanners</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"modem.html\">Modem Types</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"ttyinfo.html\">TTY Lines Info</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"nodes.html\">Fidonet Nodes</A></LI>\n"); fprintf(hp, " <LI>BBS: <A HREF=\"limits.html\">Security Limits</A></LI>\n"); fprintf(hp, " <LI>BBS: <A HREF=\"language.html\">Language Setup</A></LI>\n"); fprintf(hp, " <LI>BBS: <A HREF=\"menus.html\">BBS Menus</A></LI>\n"); fprintf(hp, " <LI>BBS: <A HREF=\"fileareas.html\">File Areas</A></LI>\n"); fprintf(hp, " <LI>BBS: <A HREF=\"protocol.html\">Transfer Protocols</A></LI>\n"); fprintf(hp, " <LI>BBS: <A HREF=\"oneliners.html\">Oneliners</A></LI>\n"); fprintf(hp, " <LI>Mail: <A HREF=\"msggroup.html\">Echomail Groups</A></LI>\n"); fprintf(hp, " <LI>Mail: <A HREF=\"msgareas.html\">Echomail Areas</A></LI>\n"); fprintf(hp, " <LI>TIC: <A HREF=\"filegroup.html\">FileEcho Groups</A></LI>\n"); fprintf(hp, " <LI>TIC: <A HREF=\"ticareas.html\">Fileecho Areas</A></LI>\n"); fprintf(hp, " <LI>TIC: <A HREF=\"hatch.html\">Hatch Manager</A></LI>\n"); fprintf(hp, " <LI>TIC: <A HREF=\"magic.html\">Magic Files</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"newgroup.html\">Newfiles Groups</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"newfiles.html\">Newfiles Reports</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"filefind.html\">Filefind Setup</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"users.html\">BBS Users</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"service.html\">Mail Service Manager</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"domain.html\">Domain translation</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"task.html\">Task Manager</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"route.html\">Network Routing</A></LI>\n"); fprintf(hp, " <LI><A HREF=\"ibcsrv.html\">Internet BBS Chat</A></LI>\n"); fprintf(hp, "</UL>\n"); close_webdoc(hp); } else { Syslog('+', "Can't create html documentation"); } ftnd_mvprintw(8,11, (char *)"Creating site documents"); fflush(stdout); horiz = 35; page = global_doc(fp, toc, page); dotter(); page = fido_doc(fp, toc, page); dotter(); page = archive_doc(fp, toc, page); dotter(); page = virus_doc(fp, toc, page); dotter(); page = modem_doc(fp, toc, page); dotter(); page = tty_doc(fp, toc, page); dotter(); page = node_doc(fp, toc, page); dotter(); page = bbs_doc(fp, toc, page); dotter(); page = mail_doc(fp, toc, page); dotter(); page = tic_doc(fp, toc, page); dotter(); page = newf_group_doc(fp, toc, page); dotter(); page = new_doc(fp, toc, page); dotter(); page = ff_doc(fp, toc, page); dotter(); page = service_doc(fp, toc, page); dotter(); page = domain_doc(fp, toc, page); dotter(); page = task_doc(fp, toc, page); dotter(); page = route_doc(fp, toc, page); dotter(); page = ibc_doc(fp, toc, page); dotter(); users_doc(); dotter(); ol_doc(); clrtoeol(); ftnd_mvprintw( 8,11, (char *)"Created site documents in %s/share/doc", getenv("FTND_ROOT")); fflush(stdout); /* * Append table of contents */ page = newpage(fp, page); addtoc(fp, toc, 21, 0, page, (char *)"Table of contents"); fprintf(fp, "\n\n"); line = 4; rewind(toc); while (fgets(temp, 256, toc) != NULL) { fprintf(fp, "%s", temp); line++; if (line == 56) { page = newpage(fp, page); line = 0; } } fprintf(fp, "\f"); fclose(fp); fclose(toc); unlink(temp1); Syslog('+', "Sitedocs created"); /* * Remove obsolete documents */ snprintf(temp, PATH_MAX, "%s/doc/xref.doc", getenv("FTND_ROOT")); unlink(temp); snprintf(temp, PATH_MAX, "%s/doc/stat.doc", getenv("FTND_ROOT")); unlink(temp); center_addstr(LINES -4, (char *)"Press any key"); readkey(LINES -4, COLS / 2 + 8, LIGHTGRAY, BLACK); return; }
void Uploads() { FILE *pAreas; char *sAreas; int Count = 0, i = 0, j, k; struct _fdbarea *fdb_area = NULL; sAreas = calloc(PATH_MAX, sizeof(char)); Syslog('+', "Checking for uploads"); IsDoing("Check uploads"); if (!do_quiet) { mbse_colour(CYAN, BLACK); printf(" Checking uploads...\n"); } snprintf(sAreas, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT")); if ((pAreas = fopen(sAreas, "r")) == NULL) { WriteError("$Can't open %s", sAreas); free(sAreas); return; } fread(&areahdr, sizeof(areahdr), 1, pAreas); while (fread(&area, areahdr.recsize, 1, pAreas) == 1) { i++; if (CFG.slow_util && do_quiet) msleep(1); if ((area.Available) && strlen(area.NewGroup)) { if (!do_quiet) { printf("\r %4d => %-44s", i, area.Name); fflush(stdout); } if ((fdb_area = mbsedb_OpenFDB(i, 30))) { while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) { Nopper(); if (!fdb.Announced) { Syslog('m', " %d %s", i, fdb.Name); memset(&T_File, 0, sizeof(T_File)); if (strlen(fdb.TicArea)) strncpy(T_File.Echo, fdb.TicArea, sizeof(T_File.Echo) -1); else snprintf(T_File.Echo, 21, "AREA %d", i); strncpy(T_File.Group, area.NewGroup, sizeof(T_File.Group) -1); strncpy(T_File.Comment, area.Name, sizeof(T_File.Comment) -1); strncpy(T_File.Name, fdb.Name, sizeof(T_File.Name) -1); strncpy(T_File.LName, fdb.LName, sizeof(T_File.LName) -1); if (strlen(fdb.Magic)) strncpy(T_File.Magic, fdb.Magic, sizeof(T_File.Magic) -1); T_File.Size = fdb.Size; T_File.SizeKb = fdb.Size / 1024; T_File.Fdate = fdb.FileDate; snprintf(T_File.Crc, 9, "%08x", fdb.Crc32); snprintf(T_File.Desc, 256, "%s %s %s %s", fdb.Desc[0], fdb.Desc[1], fdb.Desc[2], fdb.Desc[3]); k = 0; for (j = 0; j < 25; j++) { if (strlen(fdb.Desc[j])) { snprintf(T_File.LDesc[k], 49, "%s", fdb.Desc[j]); T_File.LDesc[k][48] = '\0'; k++; } } T_File.TotLdesc = k; T_File.Announce = TRUE; if (Add_ToBeRep(T_File)) Count++; /* * Mark file is announced. */ fdb.Announced = TRUE; 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); } } } if (!do_quiet) { printf("\r \r"); if (Count) printf(" %d new uploads\n", Count); fflush(stdout); } if (Count) Syslog('+', "%d new uploads", Count); fclose(pAreas); free(sAreas); }
int main(int argc, char *argv[]) { int loop = 1; struct passwd *pw; /* * Find out who is on the keyboard or automated the keyboard. */ pw = getpwuid(geteuid()); if (strcmp(pw->pw_name, (char *)"ftnd")) { printf("ERROR: only user \"ftnd\" may use this program\n"); exit(FTNERR_INIT_ERROR); } /* * Read the global configuration data, registrate connection */ config_check(getenv("FTND_ROOT")); config_read(); if (strlen(CFG.debuglog) == 0) snprintf(CFG.debuglog, 15, "debug.log"); InitClient(pw->pw_name, (char *)"ftnsetup", CFG.location, CFG.logfile, 0x1f, CFG.error_log, CFG.mgrlog, CFG.debuglog); /* * Setup several signals so when the program terminate's it * will properly close the curses screens. */ signal(SIGINT, (void (*))die); signal(SIGBUS, (void (*))die); signal(SIGSEGV,(void (*))die); signal(SIGTERM,(void (*))die); signal(SIGKILL,(void (*))die); signal(SIGIOT, (void (*))die); oldmask = umask(002); do_quiet = TRUE; Syslog(' ', " "); Syslog(' ', "FTNSETUP v%s started by %s", VERSION, pw->pw_name); if (init) Syslog('+', "Cmd: ftnsetup init"); if ((argc == 2) && (strncmp(tl(argv[1]), "i", 1) == 0)) init = TRUE; else screen_start((char *)"ftnsetup"); if (lockprogram((char *)"ftnsetup")) { printf("\n\7Another ftnsetup is already running, abort.\n\n"); die(FTNERR_NO_PROGLOCK); } bbs_free = FALSE; initdatabases(); if (!init) { do { IsDoing("Browsing Menu"); clr_index(); set_color(WHITE, BLACK); ftnd_mvprintw( 5, 6, "0. MAIN SETUP"); set_color(CYAN, BLACK); ftnd_mvprintw( 7, 6, "1. Edit Global configuration"); ftnd_mvprintw( 8, 6, "2. Edit Fido Networks"); ftnd_mvprintw( 9, 6, "3. Edit Archiver Programs"); ftnd_mvprintw(10, 6, "4. Edit Virus Scanners"); ftnd_mvprintw(11, 6, "5. Edit Modem types"); ftnd_mvprintw(12, 6, "6. Edit TTY lines info"); ftnd_mvprintw(13, 6, "7. Edit Fidonet Nodes"); ftnd_mvprintw(14, 6, "8. Edit BBS Setup"); ftnd_mvprintw(15, 6, "9. Edit Mail Setup"); ftnd_mvprintw(16, 6, "10. Edit File Echo's setup"); ftnd_mvprintw(17, 6, "11. Edit Newfiles Groups"); ftnd_mvprintw( 7,46, "12. Edit Newfiles Reports"); ftnd_mvprintw( 8,46, "13. Edit FileFind Setup"); ftnd_mvprintw( 9,46, "14. Edit Files Database"); ftnd_mvprintw(10,46, "15. Edit BBS Users"); ftnd_mvprintw(11,46, "16. Edit Services"); ftnd_mvprintw(12,46, "17. Edit Domains"); ftnd_mvprintw(13,46, "18. Edit Task Manager"); ftnd_mvprintw(14,46, "19. Edit Routing Table"); ftnd_mvprintw(15,46, "20. Edit Internet BBS Chat"); ftnd_mvprintw(16,46, "21. Show software information"); ftnd_mvprintw(17,46, "22. Create site documents"); switch(select_menu(22)) { case 0: loop = 0; break; case 1: global_menu(); break; case 2: EditFidonet(); break; case 3: EditArchive(); break; case 4: EditVirus(); break; case 5: EditModem(); break; case 6: EditTtyinfo(); break; case 7: EditNodes(); break; case 8: bbs_menu(); break; case 9: mail_menu(); break; case 10: tic_menu(); break; case 11: EditNGroup(); break; case 12: EditNewfiles(); break; case 13: EditFilefind(); break; case 14: EditFDB(); break; case 15: EditUsers(); break; case 16: EditService(); break; case 17: EditDomain(); break; case 18: task_menu(); break; case 19: EditRoute(); break; case 20: EditIBC(); break; case 21: soft_info(); break; case 22: site_docs(); break; } } while (loop == 1); } die(FTNERR_OK); return 0; }
/* * Delete a file */ void Delete(int UnDel, int Area, char *File) { char mask[256]; int rc = FALSE; struct _fdbarea *fdb_area = NULL; if (UnDel) IsDoing("Undelete file"); else IsDoing("Delete file"); ftnd_colour(LIGHTRED, BLACK); /* * Check area */ if (LoadAreaRec(Area) == FALSE) { WriteError("Can't load record %d", Area); die(FTNERR_INIT_ERROR); } if (!area.Available) { WriteError("Area %d not available", Area); if (!do_quiet) printf("Area %d not available\n", Area); die(FTNERR_CONFIG_ERROR); } if ((fdb_area = ftnddb_OpenFDB(Area, 30)) == NULL) die(FTNERR_GENERAL); ftnd_colour(CYAN, BLACK); strcpy(mask, re_mask(File, FALSE)); if (re_comp(mask)) die(FTNERR_GENERAL); while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) { if (re_exec(fdb.LName) || re_exec(fdb.Name)) { if (UnDel && fdb.Deleted) { fdb.Deleted = FALSE; Syslog('+', "Marked file %s in area %d for undeletion", fdb.Name, Area); if (!do_quiet) printf("Marked file %s in area %d for undeletion\n", fdb.Name, Area); rc = TRUE; } if (!UnDel && !fdb.Deleted) { fdb.Deleted = TRUE; Syslog('+', "Marked file %s in area %d for deletion", fdb.Name, Area); if (!do_quiet) printf("Marked file %s in area %d for deletion\n", fdb.Name, Area); rc = TRUE; } if (rc) { if (ftnddb_LockFDB(fdb_area, 30)) { fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR); fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp); ftnddb_UnlockFDB(fdb_area); } else { rc = FALSE; } } } } ftnddb_CloseFDB(fdb_area); if (!rc) { Syslog('+', "%selete %s in area %d failed", UnDel?"Und":"D", File, Area); if (!do_quiet) printf("%selete %s in area %d failed\n", UnDel?"Und":"D", File, Area); } }