diff --git a/mbsetup/Makefile b/mbsetup/Makefile index 51655560..ef84d9d3 100644 --- a/mbsetup/Makefile +++ b/mbsetup/Makefile @@ -79,7 +79,7 @@ m_marea.o: ../config.h ../lib/mbselib.h ../lib/msg.h ../lib/users.h ../lib/mbsed m_new.o: ../config.h ../lib/mbselib.h screen.h mutil.h ledit.h stlist.h m_global.h grlist.h m_new.h m_lang.h m_marea.h m_ngroup.h m_protocol.o: ../config.h ../lib/mbselib.h ../paths.h screen.h mutil.h ledit.h stlist.h m_global.h m_protocol.h m_ticarea.o: ../config.h ../lib/mbselib.h screen.h mutil.h ledit.h stlist.h grlist.h m_global.h m_node.h m_fgroup.h m_farea.h m_archive.h m_ticarea.h -mbsetup.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h screen.h mutil.h ledit.h m_global.h m_bbs.h m_farea.h m_fgroup.h m_mail.h m_mgroup.h m_hatch.h m_tic.h m_ticarea.h m_magic.h m_fido.h m_lang.h m_archive.h m_virus.h m_tty.h m_limits.h m_users.h m_node.h m_fdb.h m_new.h m_ol.h m_bbslist.h m_protocol.h m_ff.h m_modem.h m_marea.h m_ngroup.h m_service.h m_domain.h m_task.h m_route.h +mbsetup.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h screen.h mutil.h ledit.h m_global.h m_bbs.h m_farea.h m_fgroup.h m_mail.h m_mgroup.h m_hatch.h m_tic.h m_ticarea.h m_magic.h m_fido.h m_lang.h m_archive.h m_virus.h m_tty.h m_limits.h m_users.h m_node.h m_fdb.h m_new.h m_ol.h m_bbslist.h m_protocol.h m_ff.h m_modem.h m_marea.h m_ngroup.h m_service.h m_domain.h m_task.h m_route.h m_ibc.h ledit.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/msg.h screen.h mutil.h ledit.h m_farea.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h screen.h mutil.h ledit.h m_global.h m_fgroup.h m_archive.h m_farea.h m_fgroup.h m_ngroup.h m_fido.o: ../config.h ../lib/mbselib.h screen.h mutil.h ledit.h stlist.h m_global.h m_fido.h diff --git a/mbsetup/m_ibc.c b/mbsetup/m_ibc.c new file mode 100644 index 00000000..d37cea98 --- /dev/null +++ b/mbsetup/m_ibc.c @@ -0,0 +1,436 @@ +/***************************************************************************** + * + * $Id$ + * Purpose ...............: Setup Internet BBS Chat + * + ***************************************************************************** + * Copyright (C) 1997-2005 + * + * 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. + * + * MB 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 MB BBS; see the file COPYING. If not, write to the Free + * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + *****************************************************************************/ + +#include "../config.h" +#include "../lib/mbselib.h" +#include "../paths.h" +#include "screen.h" +#include "mutil.h" +#include "ledit.h" +#include "stlist.h" +#include "m_global.h" +#include "m_ibc.h" + +#ifdef USE_EXPERIMENT + + +int IBCUpdated = 0; + + +/* + * Count nr of IBC records in the database. + * Creates the database if it doesn't exist. + */ +int CountIBC(void) +{ + FILE *fil; + char ffile[PATH_MAX]; + int count; + + sprintf(ffile, "%s/etc/ibcsrv.data", getenv("MBSE_ROOT")); + if ((fil = fopen(ffile, "r")) == NULL) { + if ((fil = fopen(ffile, "a+")) != NULL) { + Syslog('+', "Created new %s", ffile); + ibcsrvhdr.hdrsize = sizeof(ibcsrvhdr); + ibcsrvhdr.recsize = sizeof(ibcsrv); + fwrite(&ibcsrvhdr, sizeof(ibcsrvhdr), 1, fil); + + return 0; + } else + return -1; + } + + fread(&ibcsrvhdr, sizeof(ibcsrvhdr), 1, fil); + fseek(fil, 0, SEEK_END); + count = (ftell(fil) - ibcsrvhdr.hdrsize) / ibcsrvhdr.recsize; + fclose(fil); + + return count; +} + + + +/* + * Open database for editing. The datafile is copied, if the format + * is changed it will be converted on the fly. All editing must be + * done on the copied file. + */ +int OpenIBC(void); +int OpenIBC(void) +{ + FILE *fin, *fout; + char fnin[PATH_MAX], fnout[PATH_MAX]; + long oldsize; + + sprintf(fnin, "%s/etc/ibcsrv.data", getenv("MBSE_ROOT")); + sprintf(fnout, "%s/etc/ibcsrv.temp", getenv("MBSE_ROOT")); + if ((fin = fopen(fnin, "r")) != NULL) { + if ((fout = fopen(fnout, "w")) != NULL) { + fread(&ibcsrvhdr, sizeof(ibcsrvhdr), 1, fin); + /* + * In case we are automatic upgrading the data format + * we save the old format. If it is changed, the + * database must always be updated. + */ + oldsize = ibcsrvhdr.recsize; + if (oldsize != sizeof(ibcsrv)) { + IBCUpdated = 1; + Syslog('+', "Upgraded %s, format changed", fnin); + } else + IBCUpdated = 0; + ibcsrvhdr.hdrsize = sizeof(ibcsrvhdr); + ibcsrvhdr.recsize = sizeof(ibcsrv); + fwrite(&ibcsrvhdr, sizeof(ibcsrvhdr), 1, fout); + + /* + * The datarecord is filled with zero's before each + * read, so if the format changed, the new fields + * will be empty. + */ + memset(&ibcsrv, 0, sizeof(ibcsrv)); + while (fread(&ibcsrv, oldsize, 1, fin) == 1) { + fwrite(&ibcsrv, sizeof(ibcsrv), 1, fout); + memset(&ibcsrv, 0, sizeof(ibcsrv)); + } + + fclose(fin); + fclose(fout); + return 0; + } else + return -1; + } + return -1; +} + + + +void CloseIBC(int); +void CloseIBC(int force) +{ + char fin[PATH_MAX], fout[PATH_MAX]; + FILE *fi, *fo; + st_list *vir = NULL, *tmp; + + sprintf(fin, "%s/etc/ibcsrv.data", getenv("MBSE_ROOT")); + sprintf(fout,"%s/etc/ibcsrv.temp", getenv("MBSE_ROOT")); + + if (IBCUpdated == 1) { + if (force || (yes_no((char *)"Database is changed, save changes") == 1)) { + working(1, 0, 0); + fi = fopen(fout, "r"); + fo = fopen(fin, "w"); + fread(&ibcsrvhdr, ibcsrvhdr.hdrsize, 1, fi); + fwrite(&ibcsrvhdr, ibcsrvhdr.hdrsize, 1, fo); + + while (fread(&ibcsrv, ibcsrvhdr.recsize, 1, fi) == 1) + if (!ibcsrv.deleted) + fill_stlist(&vir, ibcsrv.comment, ftell(fi) - ibcsrvhdr.recsize); + sort_stlist(&vir); + + for (tmp = vir; tmp; tmp = tmp->next) { + fseek(fi, tmp->pos, SEEK_SET); + fread(&ibcsrv, ibcsrvhdr.recsize, 1, fi); + fwrite(&ibcsrv, ibcsrvhdr.recsize, 1, fo); + } + + tidy_stlist(&vir); + fclose(fi); + fclose(fo); + unlink(fout); + chmod(fin, 0640); + Syslog('+', "Updated \"ibcsrv.data\""); + if (!force) + working(6, 0, 0); + return; + } + } + chmod(fin, 0640); + unlink(fout); +} + + + +int AppendIBC(void) +{ + FILE *fil; + char ffile[PATH_MAX]; + + sprintf(ffile, "%s/etc/ibcsrv.temp", getenv("MBSE_ROOT")); + if ((fil = fopen(ffile, "a")) != NULL) { + memset(&ibcsrv, 0, sizeof(ibcsrv)); + fwrite(&ibcsrv, sizeof(ibcsrv), 1, fil); + fclose(fil); + IBCUpdated = 1; + return 0; + } else + return -1; +} + + + +/* + * Edit one record, return -1 if there are errors, 0 if ok. + */ +int EditIBCRec(int Area) +{ + FILE *fil; + char mfile[PATH_MAX]; + long offset; + int j; + unsigned long crc, crc1; + + clr_index(); + working(1, 0, 0); + IsDoing("Edit ibcsrv"); + + sprintf(mfile, "%s/etc/ibcsrv.temp", getenv("MBSE_ROOT")); + if ((fil = fopen(mfile, "r")) == NULL) { + working(2, 0, 0); + return -1; + } + + offset = sizeof(ibcsrvhdr) + ((Area -1) * sizeof(ibcsrv)); + if (fseek(fil, offset, 0) != 0) { + working(2, 0, 0); + return -1; + } + + fread(&ibcsrv, sizeof(ibcsrv), 1, fil); + fclose(fil); + crc = 0xffffffff; + crc = upd_crc32((char *)&ibcsrv, crc, sizeof(ibcsrv)); + + set_color(WHITE, BLACK); + mbse_mvprintw( 5, 2, "20. EDIT INTERNET BBS CHAT SERVER"); + set_color(CYAN, BLACK); + mbse_mvprintw( 7, 2, "1. Comment"); + mbse_mvprintw( 8, 2, "2. Server"); + mbse_mvprintw( 9, 2, "3. Password"); + mbse_mvprintw(10, 2, "4. Active"); + mbse_mvprintw(11, 2, "5. Deleted"); + mbse_mvprintw(12, 2, "6. Compress"); + + for (;;) { + set_color(WHITE, BLACK); + show_str( 7,16,40, ibcsrv.comment); + show_str( 8,16,63, ibcsrv.server); + show_str( 9,16,15, ibcsrv.password); + show_bool(10,16, ibcsrv.Active); + show_bool(11,16, ibcsrv.Deleted); + show_bool(12,16, ibcsrv.Compress); + + j = select_menu(6); + switch(j) { + case 0: crc1 = 0xffffffff; + crc1 = upd_crc32((char *)&ibcsrv, crc1, sizeof(ibcsrv)); + 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(&ibcsrv, sizeof(ibcsrv), 1, fil); + fclose(fil); + IBCUpdated = 1; + working(6, 0, 0); + } + } + IsDoing("Browsing Menu"); + return 0; + case 1: E_STR( 7,16,40,ibcsrv.comment, "The ^Comment^ for this record") + case 2: E_STR( 8,16,64,ibcsrv.server, "The internet ^name^ or ^IP^ address of the server") + case 3: E_STR( 9,16,64,ibcsrv.password, "The ^password^ for this server") + case 4: E_BOOL(10,16, ibcsrv.Active, "Switch if this server is ^Active^ for chat") + case 5: E_BOOL(11,16, ibcsrv.Deleted, "Is this server to be ^Deleted^") + case 6: E_BOOL(12,16, ibcsrv.Compress, "Use ^zlib compression^ with this server") + } + } + + return 0; +} + + + +void EditIBC(void) +{ + int records, i, x, y; + char pick[12]; + FILE *fil; + char temp[PATH_MAX]; + long offset; + + clr_index(); + working(1, 0, 0); + IsDoing("Browsing Menu"); + if (config_read() == -1) { + working(2, 0, 0); + return; + } + + records = CountIBC(); + if (records == -1) { + working(2, 0, 0); + return; + } + + if (OpenIBC() == -1) { + working(2, 0, 0); + return; + } + + for (;;) { + clr_index(); + set_color(WHITE, BLACK); + mbse_mvprintw( 5, 4, "20. INTERNET BBS CHAT SETUP"); + set_color(CYAN, BLACK); + if (records != 0) { + sprintf(temp, "%s/etc/ibcsrv.temp", getenv("MBSE_ROOT")); + if ((fil = fopen(temp, "r")) != NULL) { + fread(&ibcsrvhdr, sizeof(ibcsrvhdr), 1, fil); + x = 2; + y = 7; + set_color(CYAN, BLACK); + for (i = 1; i <= records; i++) { + offset = sizeof(ibcsrvhdr) + ((i - 1) * ibcsrvhdr.recsize); + fseek(fil, offset, 0); + fread(&ibcsrv, ibcsrvhdr.recsize, 1, fil); + if (i == 11) { + x = 42; + y = 7; + } + if (ibcsrv.Active) + set_color(CYAN, BLACK); + else + set_color(LIGHTBLUE, BLACK); + sprintf(temp, "%3d. %-32s", i, ibcsrv.comment); + temp[37] = 0; + mbse_mvprintw(y, x, temp); + y++; + } + fclose(fil); + } + } + strcpy(pick, select_record(records, 20)); + + if (strncmp(pick, "-", 1) == 0) { + CloseIBC(FALSE); + return; + } + + if (strncmp(pick, "A", 1) == 0) { + working(1, 0, 0); + if (AppendIBC() == 0) { + records++; + working(3, 0, 0); + } else + working(2, 0, 0); + } + + if ((atoi(pick) >= 1) && (atoi(pick) <= records)) + EditIBCRec(atoi(pick)); + } +} + + + +void InitIBC(void) +{ + CountIBC(); + OpenIBC(); + CloseIBC(TRUE); +} + + + +int ibc_doc(FILE *fp, FILE *toc, int page) +{ + char temp[PATH_MAX]; + FILE *wp, *ip, *vir; + int nr = 0, j; + + sprintf(temp, "%s/etc/ibcsrv.data", getenv("MBSE_ROOT")); + if ((vir = fopen(temp, "r")) == NULL) + return page; + + page = newpage(fp, page); + addtoc(fp, toc, 4, 0, page, (char *)"Internet BBS Chatservers"); + j = 0; + fprintf(fp, "\n\n"); + fread(&ibcsrvhdr, sizeof(ibcsrvhdr), 1, vir); + + ip = open_webdoc((char *)"ibcsrv.html", (char *)"Internet BBS Chatservers", NULL); + fprintf(ip, "Main\n"); + fprintf(ip, "\n"); + close_webdoc(ip); + + fclose(vir); + return page; +} + +#endif + diff --git a/mbsetup/m_ibc.h b/mbsetup/m_ibc.h new file mode 100644 index 00000000..aae9ed63 --- /dev/null +++ b/mbsetup/m_ibc.h @@ -0,0 +1,15 @@ +/* $Id$ */ + +#ifndef _M_IBC_H +#define _M_IBC_H + +#ifdef USE_EXPERIMENT + +int CountIBC(void); +void EditIBC(void); +void InitIBC(void); +int ibc_doc(FILE *, FILE *, int); + +#endif + +#endif diff --git a/mbsetup/mbsetup.c b/mbsetup/mbsetup.c index 4a7f0b1e..5fa624b1 100644 --- a/mbsetup/mbsetup.c +++ b/mbsetup/mbsetup.c @@ -66,6 +66,7 @@ #include "m_domain.h" #include "m_task.h" #include "m_route.h" +#include "m_ibc.h" mode_t oldmask; /* Old umask value */ @@ -252,6 +253,9 @@ void site_docs(void) fprintf(hp, "
  • Domain translation
  • \n"); fprintf(hp, "
  • Task Manager
  • \n"); fprintf(hp, "
  • Network Routing
  • \n"); +#ifdef USE_EXPERIMENT + fprintf(hp, "
  • Internet BBS Chat
  • \n"); +#endif fprintf(hp, "\n"); close_webdoc(hp); } else { @@ -295,6 +299,10 @@ void site_docs(void) dotter(); page = route_doc(fp, toc, page); dotter(); +#ifdef USE_EXPERIMENT + page = ibc_doc(fp, toc, page); + dotter(); +#endif users_doc(); dotter(); ol_doc(); @@ -381,6 +389,9 @@ void initdatabases(void) InitVirus(); InitRoute(); InitFDB(); +#ifdef USE_EXPERIMENT + InitIBC(); +#endif if (!init) { clr_index(); @@ -469,10 +480,13 @@ int main(int argc, char *argv[]) mbse_mvprintw(12,46, "17. Edit Domains"); mbse_mvprintw(13,46, "18. Edit Task Manager"); mbse_mvprintw(14,46, "19. Edit Routing Table"); - mbse_mvprintw(15,46, "20. Show software information"); - mbse_mvprintw(16,46, "21. Create site documents"); +#ifdef USE_EXPERIMENT + mbse_mvprintw(15,46, "20. Edit Internet BBS Chat"); +#endif + mbse_mvprintw(16,46, "21. Show software information"); + mbse_mvprintw(17,46, "22. Create site documents"); - switch(select_menu(21)) { + switch(select_menu(22)) { case 0: loop = 0; break; @@ -533,10 +547,15 @@ int main(int argc, char *argv[]) case 19: EditRoute(); break; +#ifdef USE_EXPERIMENT case 20: + EditIBC(); + break; +#endif + case 21: soft_info(); break; - case 21: + case 22: site_docs(); break; }