Comm - 1
This commit is contained in:
@@ -1 +0,0 @@
|
||||
filelist mbmon
|
@@ -1,62 +0,0 @@
|
||||
# Makefile for the mbsetup.
|
||||
# Copyright (c) 1997-2001 by M. Broek.
|
||||
# $Id: Makefile,v 1.16 2007/05/27 12:50:47 mbse Exp $
|
||||
|
||||
include ../Makefile.global
|
||||
|
||||
SRCS = mutil.c mbmon.c proglock.c
|
||||
HDRS = mutil.h mbmon.h proglock.h
|
||||
OBJS = mutil.o mbmon.o proglock.o
|
||||
SLIBS = ../lib/libmbse.a ../lib/libdbase.a
|
||||
OTHER = Makefile
|
||||
|
||||
#############################################################################
|
||||
|
||||
.c.o:
|
||||
${CC} ${CFLAGS} ${INCLUDES} ${DEFINES} -c $<
|
||||
|
||||
all: mbmon
|
||||
|
||||
|
||||
mbmon: ${OBJS} ${SLIBS}
|
||||
${CC} -o mbmon ${OBJS} ${LDFLAGS} ${LIBS} ${SLIBS}
|
||||
|
||||
clean:
|
||||
rm -f mbmon *.o *.h~ *.c~ core filelist Makefile.bak
|
||||
|
||||
install: all
|
||||
${INSTALL} -c -s -g ${GROUP} -o ${OWNER} -m 0700 mbmon ${BINDIR}
|
||||
|
||||
filelist: Makefile
|
||||
BASE=`pwd`; \
|
||||
BASE=`basename $${BASE}`; \
|
||||
(for f in ${SRCS} ${HDRS} ${OTHER} ;do echo ${PACKAGE}-${VERSION}/$${BASE}/$$f; done) >filelist
|
||||
|
||||
depend:
|
||||
@rm -f Makefile.bak; \
|
||||
mv Makefile Makefile.bak; \
|
||||
sed -e '/^# DO NOT DELETE/,$$d' Makefile.bak >Makefile; \
|
||||
${ECHO} '# DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT' \
|
||||
>>Makefile; \
|
||||
${ECHO} '# Dependencies generated by make depend' >>Makefile; \
|
||||
for f in ${SRCS}; \
|
||||
do \
|
||||
${ECHO} "Dependencies for $$f:\c"; \
|
||||
${ECHO} "`basename $$f .c`.o:\c" >>Makefile; \
|
||||
for h in `sed -n -e \
|
||||
's/^#[ ]*include[ ]*"\([^"]*\)".*/\1/p' $$f`; \
|
||||
do \
|
||||
${ECHO} " $$h\c"; \
|
||||
${ECHO} " $$h\c" >>Makefile; \
|
||||
done; \
|
||||
${ECHO} " done."; \
|
||||
${ECHO} "" >>Makefile; \
|
||||
done; \
|
||||
${ECHO} '# End of generated dependencies' >>Makefile
|
||||
|
||||
# DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT
|
||||
# Dependencies generated by make depend
|
||||
mutil.o: ../config.h ../lib/mbselib.h mutil.h
|
||||
mbmon.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h proglock.h mutil.h
|
||||
proglock.o: ../config.h ../lib/mbselib.h proglock.h
|
||||
# End of generated dependencies
|
850
mbmon/mbmon.c
850
mbmon/mbmon.c
@@ -1,850 +0,0 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Purpose ...............: Monitor Program
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2011
|
||||
*
|
||||
* 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 "../lib/users.h"
|
||||
#include "../lib/mbsedb.h"
|
||||
#include "proglock.h"
|
||||
#include "mutil.h"
|
||||
|
||||
|
||||
int cols = 80;
|
||||
int rows = 24;
|
||||
|
||||
extern int bbs_free;
|
||||
extern int ttyfd;
|
||||
extern pid_t mypid;
|
||||
|
||||
struct sysconfig CFG;
|
||||
|
||||
|
||||
char rbuf[50][81]; /* Chat receive buffer */ /* FIXME: must be a dynamic buffer */
|
||||
int rpointer = 0; /* Chat receive pointer */
|
||||
int rsize = 5; /* Chat receive size */
|
||||
|
||||
|
||||
static void die(int onsig)
|
||||
{
|
||||
char buf[128];
|
||||
|
||||
signal(onsig, SIG_IGN);
|
||||
|
||||
/*
|
||||
* Prevent clear screen when the program was locked
|
||||
*/
|
||||
if (onsig != MBERR_NO_PROGLOCK)
|
||||
screen_stop();
|
||||
|
||||
if (onsig && (onsig <= NSIG))
|
||||
Syslog('?', "MBMON Finished on signal %s", SigName[onsig]);
|
||||
else
|
||||
Syslog(' ', "MBMON Normally finished");
|
||||
|
||||
snprintf(buf, 128, "CSYS:2,%d,0;", mypid);
|
||||
if (socket_send(buf) == 0)
|
||||
snprintf(buf, 128, "%s", socket_receive());
|
||||
ulockprogram((char *)"mbmon");
|
||||
ExitClient(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ShowSysinfo(void)
|
||||
{
|
||||
int ch;
|
||||
char buf[128], *lc;
|
||||
|
||||
clr_index();
|
||||
set_color(WHITE, BLACK);
|
||||
mbse_mvprintw( 5, 6, "4. SHOW BBS SYSTEM INFO");
|
||||
set_color(CYAN, BLACK);
|
||||
mbse_mvprintw( 7, 6, "1. Total calls");
|
||||
mbse_mvprintw( 8, 6, "2. Pots calls");
|
||||
mbse_mvprintw( 9, 6, "3. ISDN calls");
|
||||
mbse_mvprintw(10, 6, "4. Network calls");
|
||||
mbse_mvprintw(11, 6, "5. Local calls");
|
||||
mbse_mvprintw(12, 6, "6. Date started");
|
||||
mbse_mvprintw(13, 6, "7. Last caller");
|
||||
center_addstr(rows - 3, (char *)"Press any key");
|
||||
IsDoing("View System Info");
|
||||
|
||||
do {
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
snprintf(buf, 128, "GSYS:1,%d;", getpid());
|
||||
if (socket_send(buf) == 0) {
|
||||
snprintf(buf, 128, "%s", socket_receive());
|
||||
if (strncmp(buf, "100:7,", 6) == 0) {
|
||||
strtok(buf, ",");
|
||||
mbse_mvprintw( 7,26, "%s", strtok(NULL, ","));
|
||||
mbse_mvprintw( 8,26, "%s", strtok(NULL, ","));
|
||||
mbse_mvprintw( 9,26, "%s", strtok(NULL, ","));
|
||||
mbse_mvprintw(10,26, "%s", strtok(NULL, ","));
|
||||
mbse_mvprintw(11,26, "%s", strtok(NULL, ","));
|
||||
mbse_mvprintw(12,26, "%s", strtok(NULL, ","));
|
||||
lc = xstrcpy(cldecode(strtok(NULL, ";")));
|
||||
mbse_mvprintw(13,26, "%s", lc);
|
||||
free(lc);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
ch = testkey(rows - 3, cols / 2 + 8);
|
||||
} while (ch == '\0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ShowLastcaller(void)
|
||||
{
|
||||
int records, maxrows, ch, i, y, o;
|
||||
char buf[128];
|
||||
|
||||
clr_index();
|
||||
set_color(WHITE, BLACK);
|
||||
mbse_mvprintw( 4, 6, "5. SHOW BBS LASTCALLERS");
|
||||
set_color(YELLOW, RED);
|
||||
mbse_mvprintw( 6, 1, "Nr Username Location Level Device Time Mins Calls Speed Actions ");
|
||||
set_color(CYAN, BLACK);
|
||||
center_addstr(rows - 1, (char *)"Press any key");
|
||||
IsDoing("View Lastcallers");
|
||||
maxrows = rows - 10;
|
||||
|
||||
do {
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
records = 0;
|
||||
snprintf(buf, 128, "GLCC:0;");
|
||||
if (socket_send(buf) == 0) {
|
||||
snprintf(buf, 128, "%s", socket_receive());
|
||||
if (strncmp(buf, "100:1,", 6) == 0) {
|
||||
strtok(buf, ",");
|
||||
records = atoi(strtok(NULL, ";"));
|
||||
}
|
||||
}
|
||||
|
||||
if (records) {
|
||||
y = 7;
|
||||
if (records > maxrows)
|
||||
o = records - maxrows;
|
||||
else
|
||||
o = 1;
|
||||
set_color(CYAN, BLACK);
|
||||
for (i = o; i <= records; i++) {
|
||||
snprintf(buf, 128, "GLCR:1,%d;", i);
|
||||
if (socket_send(buf) == 0) {
|
||||
snprintf(buf, 128, "%s", socket_receive());
|
||||
if (strncmp(buf, "100:9,", 6) == 0) {
|
||||
strtok(buf, ",");
|
||||
mbse_mvprintw(y, 1, "%2d", i);
|
||||
mbse_mvprintw(y, 4, "%s", cldecode(strtok(NULL, ",")));
|
||||
mbse_mvprintw(y,19, "%s", cldecode(strtok(NULL, ",")));
|
||||
mbse_mvprintw(y,32, "%s", strtok(NULL, ","));
|
||||
mbse_mvprintw(y,38, "%s", strtok(NULL, ","));
|
||||
mbse_mvprintw(y,45, "%s", strtok(NULL, ","));
|
||||
mbse_mvprintw(y,51, "%s", strtok(NULL, ","));
|
||||
mbse_mvprintw(y,56, "%s", strtok(NULL, ","));
|
||||
mbse_mvprintw(y,62, "%s", strtok(NULL, ","));
|
||||
mbse_mvprintw(y,72, "%s", strtok(NULL, ";"));
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ch = testkey(rows - 1, cols / 2 + 8);
|
||||
} while (ch == '\0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
void system_moni(void)
|
||||
{
|
||||
int ch, y, eof;
|
||||
char buf[128];
|
||||
time_t start, now;
|
||||
|
||||
clr_index();
|
||||
set_color(WHITE, BLACK);
|
||||
mbse_mvprintw( 5, 6, "1. SERVER CLIENTS");
|
||||
set_color(YELLOW, RED);
|
||||
mbse_mvprintw( 7, 1, "Pid tty user program city doing time ");
|
||||
set_color(CYAN, BLACK);
|
||||
center_addstr(rows - 1, (char *)"Press any key");
|
||||
IsDoing("System Monitor");
|
||||
|
||||
do {
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
|
||||
eof = 0;
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
|
||||
for (y = 8; y <= rows - 2; y++) {
|
||||
if (y == 8)
|
||||
snprintf(buf, 128, "GMON:1,1;");
|
||||
else
|
||||
snprintf(buf, 128, "GMON:1,0;");
|
||||
if (eof == 0) {
|
||||
if (socket_send(buf) == 0) {
|
||||
strncpy(buf, socket_receive(), 128);
|
||||
mbse_locate(y, 1);
|
||||
clrtoeol();
|
||||
if (strncmp(buf, "100:0;", 6) == 0) {
|
||||
/*
|
||||
* There's no more information
|
||||
*/
|
||||
eof = 1;
|
||||
} else {
|
||||
strtok(buf, ",");
|
||||
mbse_mvprintw(y, 1, (char *)"%.5s", strtok(NULL, ","));
|
||||
mbse_mvprintw(y, 7, (char *)"%.6s", strtok(NULL, ","));
|
||||
mbse_mvprintw(y,14, (char *)"%.8s", cldecode(strtok(NULL, ",")));
|
||||
mbse_mvprintw(y,23, (char *)"%.8s", cldecode(strtok(NULL, ",")));
|
||||
mbse_mvprintw(y,32, (char *)"%.15s", cldecode(strtok(NULL, ",")));
|
||||
mbse_mvprintw(y,48, (char *)"%.26s", cldecode(strtok(NULL, ",")));
|
||||
start = atoi(strtok(NULL, ";"));
|
||||
now = time(NULL);
|
||||
mbse_mvprintw(y,75, (char *)"%s", t_elapsed(start, now));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* If no valid data, clear line
|
||||
*/
|
||||
mbse_locate(y, 1);
|
||||
clrtoeol();
|
||||
}
|
||||
} /* for () */
|
||||
|
||||
ch = testkey(rows - 1, cols / 2 + 8);
|
||||
} while (ch == '\0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
void system_stat(void)
|
||||
{
|
||||
int ch;
|
||||
char buf[256];
|
||||
time_t now;
|
||||
|
||||
clr_index();
|
||||
set_color(WHITE, BLACK);
|
||||
mbse_mvprintw( 5, 6, "2. SERVER STATISTICS");
|
||||
set_color(CYAN, BLACK);
|
||||
mbse_mvprintw( 7, 6, "First date started");
|
||||
mbse_mvprintw( 7,59, "BBS Open");
|
||||
mbse_mvprintw( 8, 6, "Last date started");
|
||||
mbse_mvprintw( 8,59, "ZMH");
|
||||
mbse_mvprintw( 9, 6, "Total server starts");
|
||||
mbse_mvprintw( 9,59, "Internet up");
|
||||
mbse_mvprintw(10, 6, "Connected clients");
|
||||
mbse_mvprintw(10,59, "Need inet");
|
||||
mbse_mvprintw(11,59, "Running");
|
||||
mbse_mvprintw(12,30, "Total Today");
|
||||
mbse_mvprintw(12,59, "Load average");
|
||||
hor_lin(13,30,8);
|
||||
hor_lin(13,45,8);
|
||||
mbse_mvprintw(13,59, "Diskspace");
|
||||
mbse_mvprintw(14, 6, "Client connects");
|
||||
mbse_mvprintw(14,59, "IBC servers");
|
||||
mbse_mvprintw(15, 6, "Peak connections");
|
||||
mbse_mvprintw(15,59, "IBC channels");
|
||||
mbse_mvprintw(16, 6, "Protocol syntax errors");
|
||||
mbse_mvprintw(16,59, "IBC users");
|
||||
mbse_mvprintw(17, 6, "Communication errors");
|
||||
mbse_mvprintw(19, 6, "Next sequence number");
|
||||
mbse_mvprintw(rows -3,59, "Press any key");
|
||||
IsDoing("System Statistics");
|
||||
|
||||
do {
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
|
||||
snprintf(buf, 256, "GSTA:1,%d;", getpid());
|
||||
if (socket_send(buf) == 0) {
|
||||
strncpy(buf, socket_receive(), 256);
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
strtok(buf, ",");
|
||||
now = atoi(strtok(NULL, ","));
|
||||
mbse_mvprintw(7, 30, "%s", ctime(&now));
|
||||
now = atoi(strtok(NULL, ","));
|
||||
mbse_mvprintw(8, 30, "%s", ctime(&now));
|
||||
strtok(NULL, ",");
|
||||
mbse_mvprintw(9, 30, (char *)"%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(10,30, (char *)"%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(14,30, (char *)"%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(15,30, (char *)"%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(16,30, (char *)"%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(17,30, (char *)"%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(14,45, (char *)"%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(15,45, (char *)"%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(16,45, (char *)"%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(17,45, (char *)"%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(7,72, "%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No ");
|
||||
mbse_mvprintw(8,72, "%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No ");
|
||||
mbse_mvprintw(9,72, "%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No ");
|
||||
mbse_mvprintw(10,72,"%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No ");
|
||||
mbse_mvprintw(11,72,"%s", atoi(strtok(NULL, ",")) == 1?"Yes":"No ");
|
||||
mbse_mvprintw(12,72, "%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(19,30, (char *)"%s", strtok(NULL, ","));
|
||||
mbse_mvprintw(14,72, (char *)"%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(15,72, (char *)"%s ", strtok(NULL, ","));
|
||||
mbse_mvprintw(16,72, (char *)"%s ", strtok(NULL, ";"));
|
||||
}
|
||||
|
||||
switch (enoughspace(CFG.freespace)) {
|
||||
case 0: mbse_mvprintw(13, 72, "Full ");
|
||||
break;
|
||||
case 1: mbse_mvprintw(13, 72, "Ok ");
|
||||
break;
|
||||
case 2: mbse_mvprintw(13, 72, "N/A ");
|
||||
break;
|
||||
case 3: mbse_mvprintw(13, 72, "Error");
|
||||
break;
|
||||
}
|
||||
|
||||
ch = testkey(rows -3,73);
|
||||
} while (ch == '\0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
void disk_stat(void)
|
||||
{
|
||||
int ch, i, ro;
|
||||
char buf[1024], *cnt, *type, *fs, *p, sign;
|
||||
unsigned int last[10], size, used, perc, avail;
|
||||
|
||||
clr_index();
|
||||
set_color(WHITE, BLACK);
|
||||
mbse_mvprintw( 5, 6, "3. FILESYSTEM USAGE");
|
||||
set_color(YELLOW, RED);
|
||||
mbse_mvprintw( 7, 1, " Size MB Free MB Used FS-Type St Mountpoint ");
|
||||
set_color(CYAN, BLACK);
|
||||
mbse_mvprintw(rows - 2, 6, "Press any key");
|
||||
IsDoing("Filesystem Usage");
|
||||
for (i = 0; i < 10; i++)
|
||||
last[i] = 0;
|
||||
|
||||
do {
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
|
||||
snprintf(buf, 1024, "DGFS:0;");
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
cnt = strtok(buf, ":");
|
||||
cnt = strtok(NULL, ",;");
|
||||
if (atoi(cnt)) {
|
||||
for (i = 0; i < atoi(cnt); i++) {
|
||||
p = strtok(NULL, " ");
|
||||
size = atoi(p);
|
||||
avail = atoi(strtok(NULL, " "));
|
||||
used = size - avail;
|
||||
perc = (used * 100) / size;
|
||||
sign = ' ';
|
||||
fs = strtok(NULL, " ");
|
||||
type = strtok(NULL, " ");
|
||||
ro = atoi(strtok(NULL, ",;"));
|
||||
if (used > last[i])
|
||||
sign = '^';
|
||||
if (used < last[i])
|
||||
sign = 'v';
|
||||
if (last[i] == 0)
|
||||
sign = ' ';
|
||||
last[i] = used;
|
||||
set_color(CYAN, BLACK);
|
||||
mbse_mvprintw(i+8, 1, "%8lu %8lu ", size, avail);
|
||||
set_color(WHITE, BLACK);
|
||||
printf("%c ", sign);
|
||||
if (ro == 0) {
|
||||
if (avail <= CFG.freespace)
|
||||
set_color(LIGHTRED, BLACK);
|
||||
else if (avail <= (CFG.freespace * 4))
|
||||
set_color(YELLOW, BLACK);
|
||||
else
|
||||
set_color(CYAN, BLACK);
|
||||
} else {
|
||||
set_color(GREEN, BLACK);
|
||||
}
|
||||
printf("%3u", perc);
|
||||
putchar('%');
|
||||
set_color(CYAN, BLACK);
|
||||
printf(" %-8s %s %-37s", type, ro ?"RO":"RW", fs);
|
||||
}
|
||||
mbse_locate(i+8, 1);
|
||||
clrtoeol();
|
||||
}
|
||||
}
|
||||
|
||||
ch = testkey(rows - 2, 20);
|
||||
} while (ch == '\0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
void soft_info(void)
|
||||
{
|
||||
char temp[81], *p;
|
||||
|
||||
clr_index();
|
||||
set_color(YELLOW, BLACK);
|
||||
|
||||
#if defined(__linux__)
|
||||
p = xstrcpy((char *)"MBSE BBS (GNU/Linux");
|
||||
#elif defined(__FreeBSD__)
|
||||
p = xstrcpy((char *)"MBSE BBS (FreeBSD");
|
||||
#elif defined(__NetBSD__)
|
||||
p = xstrcpy((char *)"MBSE BBS (NetBSD");
|
||||
#elif defined(__OpenBSD__)
|
||||
p = xstrcpy((char *)"MBSE BBS (OpenBSD");
|
||||
#else
|
||||
#error "Unknown OS"
|
||||
#endif
|
||||
|
||||
#if defined(__i386__)
|
||||
p = xstrcat(p, (char *)" i386)");
|
||||
#elif defined(__x86_64__)
|
||||
p = xstrcat(p, (char *)" x86-64");
|
||||
#elif defined(__PPC__) || defined(__ppc__)
|
||||
p = xstrcat(p, (char *)" PPC)");
|
||||
#elif defined(__sparc__)
|
||||
p = xstrcat(p, (char *)" Sparc)");
|
||||
#elif defined(__alpha__)
|
||||
p = xstrcat(p, (char *)" Alpha)");
|
||||
#elif defined(__hppa__)
|
||||
p = xstrcat(p, (char *)" HPPA)");
|
||||
#elif defined(__arm__)
|
||||
p = xstrcat(p, (char *)" ARM)");
|
||||
#else
|
||||
#error "Unknown CPU"
|
||||
#endif
|
||||
|
||||
center_addstr( 6, p);
|
||||
free(p);
|
||||
set_color(WHITE, BLACK);
|
||||
center_addstr( 8, (char *)COPYRIGHT);
|
||||
set_color(YELLOW, BLACK);
|
||||
center_addstr(10, (char *)"Ceeated in the Netherlands.");
|
||||
set_color(WHITE, BLACK);
|
||||
#ifdef __GLIBC__
|
||||
snprintf(temp, 81, "Compiled on glibc v%d.%d", __GLIBC__, __GLIBC_MINOR__);
|
||||
#else
|
||||
#ifdef __GNU_LIBRARY__
|
||||
snprintf(temp, 81, "Compiled on libc v%d", __GNU_LIBRARY__);
|
||||
#else
|
||||
snprintf(temp, 81, "Compiled on unknown library");
|
||||
#endif
|
||||
#endif
|
||||
center_addstr(12, temp);
|
||||
set_color(LIGHTCYAN, BLACK);
|
||||
center_addstr(14, (char *)"https://sourceforge.net/projects/mbsebbs");
|
||||
set_color(LIGHTGREEN, BLACK);
|
||||
center_addstr(rows -7, (char *)"This is free software; released under the terms of the GNU General");
|
||||
center_addstr(rows -6, (char *)"Public License as published by the Free Software Foundation.");
|
||||
set_color(CYAN, BLACK);
|
||||
center_addstr(rows -4, (char *)"Press any key");
|
||||
readkey(rows - 4, cols / 2 + 8, LIGHTGRAY, BLACK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Colorize the chat window
|
||||
*/
|
||||
void Showline(int y, int x, char *msg)
|
||||
{
|
||||
int i, done = FALSE;
|
||||
|
||||
if (strlen(msg)) {
|
||||
mbse_locate(y, x);
|
||||
if (msg[0] == '<') {
|
||||
mbse_colour(LIGHTCYAN, BLACK);
|
||||
putchar('<');
|
||||
mbse_colour(LIGHTBLUE, BLACK);
|
||||
for (i = 1; i < strlen(msg); i++) {
|
||||
if ((msg[i] == '>') && (! done)) {
|
||||
mbse_colour(LIGHTCYAN, BLACK);
|
||||
putchar(msg[i]);
|
||||
mbse_colour(CYAN, BLACK);
|
||||
done = TRUE;
|
||||
} else {
|
||||
putchar(msg[i]);
|
||||
}
|
||||
}
|
||||
} else if (msg[0] == '*') {
|
||||
if (msg[1] == '*') {
|
||||
if (msg[2] == '*')
|
||||
mbse_colour(YELLOW, BLACK);
|
||||
else
|
||||
mbse_colour(LIGHTRED, BLACK);
|
||||
} else {
|
||||
mbse_colour(LIGHTMAGENTA, BLACK);
|
||||
}
|
||||
for (i = 0; i < strlen(msg); i++)
|
||||
putchar(msg[i]);
|
||||
} else {
|
||||
mbse_colour(GREEN, BLACK);
|
||||
for (i = 0; i < strlen(msg); i++)
|
||||
putchar(msg[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Display received chat message
|
||||
*/
|
||||
void DispMsg(char *);
|
||||
void DispMsg(char *msg)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
* Beep on minor system messages
|
||||
*/
|
||||
if ((msg[0] == '*') && (msg[1] != '*'))
|
||||
putchar('\007');
|
||||
|
||||
strncpy(rbuf[rpointer], msg, 81);
|
||||
Showline(4+rpointer, 1, rbuf[rpointer]);
|
||||
if (rpointer == rsize) {
|
||||
/*
|
||||
* Scroll buffer
|
||||
*/
|
||||
for (i = 0; i <= rsize; i++) {
|
||||
mbse_locate(i+4,1);
|
||||
clrtoeol();
|
||||
strncpy(rbuf[i], rbuf[i+1], 81);
|
||||
// snprintf(rbuf[i], 81, "%s", rbuf[i+1]);
|
||||
Showline(i+4, 1, rbuf[i]);
|
||||
}
|
||||
} else {
|
||||
rpointer++;
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Sysop/user chat
|
||||
*/
|
||||
void Chat(int sysop)
|
||||
{
|
||||
int curpos = 0, width, stop = FALSE, data, rc;
|
||||
unsigned char ch = 0;
|
||||
char *p, sbuf[81], resp[128], *sysop_name, *name;
|
||||
static char buf[200];
|
||||
|
||||
clr_index();
|
||||
rsize = rows - 7;
|
||||
rpointer = 0;
|
||||
|
||||
sysop_name = xstrcpy(clencode(CFG.sysop_name));
|
||||
name = xstrcpy(clencode(CFG.sysop));
|
||||
width = cols - (strlen(name) + 3);
|
||||
snprintf(buf, 200, "CCON,4,%d,%s,%s,%s;", mypid, sysop_name, name, sysop ? "1":"0");
|
||||
free(sysop_name);
|
||||
free(name);
|
||||
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
if (strncmp(buf, "200:1,", 6) == 0) {
|
||||
set_color(LIGHTRED, BLACK);
|
||||
mbse_mvprintw(4, 1, (char *)"Add \"fido 60179/udp # Chatserver\" to /etc/services");
|
||||
mbse_mvprintw(5, 1, (char *)"Leave mbmon, then restart mbtask and come back here");
|
||||
working(2, 0, 0);
|
||||
working(0, 0, 0);
|
||||
center_addstr(rows -4, (char *)"Press any key");
|
||||
readkey(rows - 4, cols / 2 + 8, LIGHTGRAY, BLACK);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mbse_locate(rows - 2, 1);
|
||||
set_color(WHITE, BLUE);
|
||||
clrtoeol();
|
||||
mbse_mvprintw(rows - 2, 2, "Chat, type \"/EXIT\" to exit or \"/HELP\" for help");
|
||||
|
||||
set_color(WHITE, BLACK);
|
||||
mbse_mvprintw(rows - 1, 1, ">");
|
||||
mbse_mvprintw(rows - 1, width + 2, "<");
|
||||
memset(&sbuf, 0, sizeof(sbuf));
|
||||
memset(&rbuf, 0, sizeof(rbuf));
|
||||
|
||||
if (sysop) {
|
||||
/*
|
||||
* Join channel #sysop automatic
|
||||
*/
|
||||
snprintf(buf, 200, "CPUT:2,%d,/JOIN #sysop;", mypid);
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
}
|
||||
}
|
||||
|
||||
while (stop == FALSE) {
|
||||
|
||||
/*
|
||||
* Check for new message, loop fast until no more data available.
|
||||
*/
|
||||
data = TRUE;
|
||||
while (data) {
|
||||
snprintf(buf, 200, "CGET:1,%d;", mypid);
|
||||
if (socket_send(buf) == 0) {
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
strncpy(buf, socket_receive(), sizeof(buf)-1);
|
||||
if (strncmp(buf, "100:2,", 6) == 0) {
|
||||
strncpy(resp, strtok(buf, ":"), 10); /* Should be 100 */
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* Should be 2 */
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error */
|
||||
rc = atoi(resp);
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
strncpy(resp, cldecode(strtok(NULL, ";")), 81); /* The message */
|
||||
DispMsg(resp);
|
||||
if (rc == 1) {
|
||||
Syslog('+', "Chat server message: %s", resp);
|
||||
stop = TRUE;
|
||||
data = FALSE;
|
||||
}
|
||||
} else {
|
||||
data = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stop)
|
||||
break;
|
||||
|
||||
/*
|
||||
* Update top bars
|
||||
*/
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
|
||||
/*
|
||||
* Check for a pressed key, if so then process it
|
||||
*/
|
||||
ch = testkey(rows -1, curpos + 2);
|
||||
if (isprint(ch)) {
|
||||
set_color(CYAN, BLACK);
|
||||
if (curpos < width) {
|
||||
putchar(ch);
|
||||
fflush(stdout);
|
||||
sbuf[curpos] = ch;
|
||||
curpos++;
|
||||
} else {
|
||||
putchar(7);
|
||||
}
|
||||
} else if ((ch == KEY_BACKSPACE) || (ch == KEY_RUBOUT) || (ch == KEY_DEL)) {
|
||||
set_color(CYAN, BLACK);
|
||||
if (curpos) {
|
||||
curpos--;
|
||||
sbuf[curpos] = '\0';
|
||||
printf("\b \b");
|
||||
} else {
|
||||
putchar(7);
|
||||
}
|
||||
} else if ((ch == '\r') && curpos) {
|
||||
snprintf(buf, 12, "%d", mypid);
|
||||
p = xstrcpy((char *)"CPUT:2,");
|
||||
p = xstrcat(p, buf);
|
||||
p = xstrcat(p, (char *)",");
|
||||
p = xstrcat(p, clencode(sbuf));
|
||||
p = xstrcat(p, (char *)";");
|
||||
strncpy(buf, p, 200);
|
||||
free(p);
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
if (strncmp(buf, "100:2,", 6) == 0) {
|
||||
strncpy(resp, strtok(buf, ":"), 10); /* Should be 100 */
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* Should be 2 */
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error, end chat */
|
||||
rc = atoi(resp);
|
||||
strncpy(resp, cldecode(strtok(NULL, ";")), 81); /* The message */
|
||||
DispMsg(resp);
|
||||
if (rc == 1) {
|
||||
Syslog('+', "Chat server error: %s", resp);
|
||||
stop = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
curpos = 0;
|
||||
memset(&sbuf, 0, sizeof(sbuf));
|
||||
mbse_locate(rows - 1, 2);
|
||||
clrtoeol();
|
||||
set_color(WHITE, BLACK);
|
||||
mbse_mvprintw(rows - 1, 1, ">");
|
||||
mbse_mvprintw(rows - 1, width + 2, "<");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Before sending the close command, purge all outstanding messages.
|
||||
*/
|
||||
data = TRUE;
|
||||
while (data) {
|
||||
snprintf(buf, 200, "CGET:1,%d;", mypid);
|
||||
if (socket_send(buf) == 0) {
|
||||
strncpy(buf, socket_receive(), sizeof(buf)-1);
|
||||
if (strncmp(buf, "100:2,", 6) == 0) {
|
||||
strncpy(resp, strtok(buf, ":"), 10); /* Should be 100 */
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* Should be 2 */
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error */
|
||||
rc = atoi(resp);
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
|
||||
DispMsg(resp);
|
||||
if (rc == 1) {
|
||||
Syslog('+', "Chat server error: %s", resp);
|
||||
data = FALSE;
|
||||
}
|
||||
} else {
|
||||
data = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Close server connection
|
||||
*/
|
||||
snprintf(buf, 200, "CCLO,1,%d;", mypid);
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct passwd *pw;
|
||||
struct winsize ws;
|
||||
char buf[128];
|
||||
|
||||
/*
|
||||
* Find out who is on the keyboard or automated the keyboard.
|
||||
*/
|
||||
pw = getpwuid(geteuid());
|
||||
if (strcmp(pw->pw_name, (char *)"mbse")) {
|
||||
printf("ERROR: only user \"mbse\" may use this program\n");
|
||||
exit(MBERR_INIT_ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the global configuration data, registrate connection
|
||||
*/
|
||||
InitConfig();
|
||||
InitClient(pw->pw_name, (char *)"mbmon", CFG.location, (char *)"mbmon.log", CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
|
||||
Syslog(' ', "MBMON Started by %s", pw->pw_name);
|
||||
bbs_free = FALSE;
|
||||
|
||||
/*
|
||||
* Report sysop available for chat
|
||||
*/
|
||||
snprintf(buf, 128, "CSYS:2,%d,1;", mypid);
|
||||
if (socket_send(buf) == 0)
|
||||
snprintf(buf, 128, "%s", socket_receive());
|
||||
|
||||
|
||||
/*
|
||||
* Setup several signals so when the program terminate's it
|
||||
* will properly close.
|
||||
*/
|
||||
signal(SIGINT, (void (*))die);
|
||||
signal(SIGBUS, (void (*))die);
|
||||
signal(SIGSEGV,(void (*))die);
|
||||
signal(SIGTERM,(void (*))die);
|
||||
signal(SIGKILL,(void (*))die);
|
||||
signal(SIGIOT,(void (*))die);
|
||||
|
||||
if (ioctl(1, TIOCGWINSZ, &ws) != -1 && (ws.ws_col > 0) && (ws.ws_row > 0)) {
|
||||
rows = ws.ws_row;
|
||||
if (rows < 24) {
|
||||
Syslog('!', "Warning, only %d screen rows, forcing to 24", rows);
|
||||
rows = 24;
|
||||
}
|
||||
}
|
||||
Syslog('+', "Screen size set to %dx%d", cols, rows);
|
||||
|
||||
if (lockprogram((char *)"mbmon")) {
|
||||
printf("\n\7Another mbmon is already running, abort.\n\n");
|
||||
die(MBERR_NO_PROGLOCK);
|
||||
}
|
||||
|
||||
screen_start((char *)"MBmon");
|
||||
|
||||
for (;;) {
|
||||
|
||||
IsDoing("Browsing Menu");
|
||||
clr_index();
|
||||
set_color(WHITE, BLACK);
|
||||
mbse_mvprintw( 5, 6, "0. MBSE BBS MONITOR");
|
||||
set_color(CYAN, BLACK);
|
||||
mbse_mvprintw( 7, 6, "1. View Server Clients");
|
||||
mbse_mvprintw( 8, 6, "2. View Server Statistics");
|
||||
mbse_mvprintw( 9, 6, "3. View Filesystem Usage");
|
||||
mbse_mvprintw(10, 6, "4. View BBS System Information");
|
||||
mbse_mvprintw(11, 6, "5. View BBS Lastcallers List");
|
||||
mbse_mvprintw(12, 6, "6. Chat with any user");
|
||||
mbse_mvprintw(13, 6, "7. Respond to sysop page");
|
||||
mbse_mvprintw(14, 6, "8. View Software Information");
|
||||
|
||||
switch(select_menu(8)) {
|
||||
case 0:
|
||||
die(0);
|
||||
break;
|
||||
case 1:
|
||||
system_moni();
|
||||
break;
|
||||
case 2:
|
||||
system_stat();
|
||||
break;
|
||||
case 3:
|
||||
disk_stat();
|
||||
break;
|
||||
case 4:
|
||||
ShowSysinfo();
|
||||
break;
|
||||
case 5:
|
||||
ShowLastcaller();
|
||||
break;
|
||||
case 6:
|
||||
Chat(FALSE);
|
||||
break;
|
||||
case 7:
|
||||
Chat(TRUE);
|
||||
break;
|
||||
case 8:
|
||||
soft_info();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +0,0 @@
|
||||
#ifndef _MBMON_H
|
||||
#define _MBMON_H
|
||||
|
||||
/* $Id: mbmon.h,v 1.3 2003/03/24 19:44:39 mbroek Exp $ */
|
||||
|
||||
static void die(int);
|
||||
void ShowSysinfo(void);
|
||||
void ShowLastcaller(void);
|
||||
void system_moni(void);
|
||||
void system_stat(void);
|
||||
void disk_stat(void);
|
||||
void soft_info(void);
|
||||
void Chat(void);
|
||||
|
||||
#endif
|
605
mbmon/mutil.c
605
mbmon/mutil.c
@@ -1,605 +0,0 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id: mutil.c,v 1.21 2005/10/17 18:02:00 mbse Exp $
|
||||
* Purpose ...............: Utilities
|
||||
*
|
||||
*****************************************************************************
|
||||
* 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 "mutil.h"
|
||||
|
||||
|
||||
extern int rows, cols;
|
||||
extern int ttyfd;
|
||||
int bbs_free;
|
||||
|
||||
|
||||
unsigned char readkey(int y, int x, int fg, int bg)
|
||||
{
|
||||
int rc = -1, i;
|
||||
unsigned char ch = 0;
|
||||
|
||||
if ((ttyfd = open("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) {
|
||||
perror("open /dev/tty");
|
||||
exit(MBERR_TTYIO_ERROR);
|
||||
}
|
||||
mbse_Setraw();
|
||||
|
||||
i = 0;
|
||||
while (rc == -1) {
|
||||
if ((i % 10) == 0)
|
||||
show_date(fg, bg, 0, 0);
|
||||
|
||||
mbse_locate(y, x);
|
||||
fflush(stdout);
|
||||
rc = mbse_Waitchar(&ch, 5);
|
||||
if ((rc == 1) && (ch != KEY_ESCAPE))
|
||||
break;
|
||||
|
||||
if ((rc == 1) && (ch == KEY_ESCAPE))
|
||||
rc = mbse_Escapechar(&ch);
|
||||
|
||||
if (rc == 1)
|
||||
break;
|
||||
i++;
|
||||
Nopper();
|
||||
}
|
||||
|
||||
mbse_Unsetraw();
|
||||
close(ttyfd);
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned char testkey(int y, int x)
|
||||
{
|
||||
int rc;
|
||||
unsigned char ch = 0;
|
||||
|
||||
Nopper();
|
||||
mbse_locate(y, x);
|
||||
fflush(stdout);
|
||||
|
||||
if ((ttyfd = open("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) {
|
||||
perror("open /dev/tty");
|
||||
exit(MBERR_TTYIO_ERROR);
|
||||
}
|
||||
mbse_Setraw();
|
||||
|
||||
rc = mbse_Waitchar(&ch, 50);
|
||||
if (rc == 1) {
|
||||
if (ch == KEY_ESCAPE)
|
||||
rc = mbse_Escapechar(&ch);
|
||||
}
|
||||
|
||||
mbse_Unsetraw();
|
||||
close(ttyfd);
|
||||
|
||||
if (rc == 1)
|
||||
return ch;
|
||||
else
|
||||
return '\0';
|
||||
}
|
||||
|
||||
|
||||
|
||||
void show_field(int y, int x, char *str, int length, int fill)
|
||||
{
|
||||
mbse_mvprintw(y, x, padleft(str, length, fill));
|
||||
}
|
||||
|
||||
|
||||
int insertflag = 0;
|
||||
|
||||
void newinsert(int i, int fg, int bg)
|
||||
{
|
||||
insertflag = i;
|
||||
set_color(YELLOW, RED);
|
||||
if (insertflag != 0) {
|
||||
mbse_mvprintw(2,36," INS ");
|
||||
} else {
|
||||
mbse_mvprintw(2,36," OVR ");
|
||||
}
|
||||
set_color(fg, bg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
char *edit_field(int y, int x, int w, int p, char *s_)
|
||||
{
|
||||
int i, charok, first, curpos;
|
||||
static char s[256];
|
||||
unsigned int ch;
|
||||
|
||||
memset((char *)s, 0, 256);
|
||||
snprintf(s, 256, "%s", s_);
|
||||
curpos = 0;
|
||||
first = 1;
|
||||
newinsert(1, YELLOW, BLUE);
|
||||
|
||||
do {
|
||||
set_color(YELLOW, BLUE);
|
||||
show_field(y, x, s, w, '_');
|
||||
mbse_locate(y, x + curpos);
|
||||
do {
|
||||
ch = readkey(y, x + curpos, YELLOW, BLUE);
|
||||
set_color(YELLOW, BLUE);
|
||||
|
||||
/*
|
||||
* Test if the pressed key is a valid key.
|
||||
*/
|
||||
charok = 0;
|
||||
if ((ch >= ' ') && (ch <= '~')) {
|
||||
switch(p) {
|
||||
case '!':
|
||||
ch = toupper(ch);
|
||||
charok = 1;
|
||||
break;
|
||||
case 'X':
|
||||
charok = 1;
|
||||
break;
|
||||
case '9':
|
||||
if (ch == ' ' || ch == '-' || ch == ',' ||
|
||||
ch == '.' || isdigit(ch))
|
||||
charok = 1;
|
||||
break;
|
||||
case 'U':
|
||||
ch = toupper(ch);
|
||||
if (isupper(ch))
|
||||
charok = 1;
|
||||
break;
|
||||
default:
|
||||
putchar(7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} while (charok == 0 && ch != KEY_ENTER && ch != KEY_LINEFEED &&
|
||||
ch != KEY_DEL && ch != KEY_INS && ch != KEY_HOME &&
|
||||
ch != KEY_LEFT && ch != KEY_RIGHT && ch != KEY_ESCAPE &&
|
||||
ch != KEY_BACKSPACE && ch != KEY_RUBOUT && ch != KEY_END);
|
||||
|
||||
|
||||
if (charok == 1) {
|
||||
if (first == 1) {
|
||||
first = 0;
|
||||
memset((char *)s, 0, 256);
|
||||
curpos = 0;
|
||||
}
|
||||
if (curpos < w) {
|
||||
if (insertflag == 1) {
|
||||
/*
|
||||
* Insert mode
|
||||
*/
|
||||
if (strlen(s) < w) {
|
||||
if (curpos < strlen(s)) {
|
||||
for (i = strlen(s); i >= curpos; i--)
|
||||
s[i+1] = s[i];
|
||||
}
|
||||
s[curpos] = ch;
|
||||
if (curpos < w)
|
||||
curpos++;
|
||||
} else {
|
||||
putchar(7);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Overwrite mode
|
||||
*/
|
||||
s[curpos] = ch;
|
||||
if (curpos < w)
|
||||
curpos++;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* The field is full
|
||||
*/
|
||||
putchar(7);
|
||||
}
|
||||
} /* if charok */
|
||||
|
||||
first = 0;
|
||||
switch (ch) {
|
||||
case KEY_HOME:
|
||||
curpos = 0;
|
||||
break;
|
||||
case KEY_END:
|
||||
curpos = strlen(s);
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
if (curpos > 0)
|
||||
curpos--;
|
||||
else
|
||||
putchar(7);
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
if (curpos < strlen(s))
|
||||
curpos++;
|
||||
else
|
||||
putchar(7);
|
||||
break;
|
||||
case KEY_INS:
|
||||
if (insertflag == 1)
|
||||
newinsert(0, YELLOW, BLUE);
|
||||
else
|
||||
newinsert(1, YELLOW, BLUE);
|
||||
break;
|
||||
case KEY_BACKSPACE:
|
||||
case KEY_RUBOUT:
|
||||
if (strlen(s) > 0) {
|
||||
if (curpos >= strlen(s)) {
|
||||
curpos--;
|
||||
s[curpos] = '\0';
|
||||
} else {
|
||||
for (i = curpos; i < strlen(s); i++)
|
||||
s[i] = s[i+1];
|
||||
s[i] = '\0';
|
||||
}
|
||||
} else
|
||||
putchar(7);
|
||||
break;
|
||||
case KEY_DEL:
|
||||
if (strlen(s) > 0) {
|
||||
if ((curpos) == (strlen(s) -1)) {
|
||||
s[curpos] = '\0';
|
||||
} else {
|
||||
for (i = curpos; i < strlen(s); i++)
|
||||
s[i] = s[i+1];
|
||||
s[i] = '\0';
|
||||
}
|
||||
} else
|
||||
putchar(7);
|
||||
break;
|
||||
}
|
||||
} while ((ch != KEY_ENTER) && (ch != KEY_LINEFEED) && (ch != KEY_ESCAPE));
|
||||
|
||||
set_color(LIGHTGRAY, BLUE);
|
||||
mbse_mvprintw(2,36, " ");
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Select menu, max is the highest item to pick. Returns zero if
|
||||
* "-" (previous level) is selected.
|
||||
*/
|
||||
int select_menu(int max)
|
||||
{
|
||||
static char *menu=(char *)"-";
|
||||
char help[80];
|
||||
int pick;
|
||||
|
||||
snprintf(help, 80, "Select menu item (1..%d) or ^\"-\"^ for previous level.", max);
|
||||
showhelp(help);
|
||||
|
||||
/*
|
||||
* Loop forever until it's right.
|
||||
*/
|
||||
for (;;) {
|
||||
mbse_mvprintw(rows - 2, 6, "Enter your choice >");
|
||||
menu = (char *)"-";
|
||||
menu = edit_field(rows - 2, 26, 3, '9', menu);
|
||||
mbse_locate(rows - 2, 6);
|
||||
clrtoeol();
|
||||
|
||||
if (strncmp(menu, "-", 1) == 0)
|
||||
return 0;
|
||||
|
||||
pick = atoi(menu);
|
||||
if ((pick >= 1) && (pick <= max))
|
||||
return pick;
|
||||
|
||||
working(2, 0, 0);
|
||||
working(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void clrtoeol()
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("\r");
|
||||
for (i = 0; i < cols; i++)
|
||||
putchar(' ');
|
||||
printf("\r");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void hor_lin(int y, int x, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
mbse_locate(y, x);
|
||||
for (i = 0; i < len; i++)
|
||||
putchar('-');
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int old_f = -1;
|
||||
static int old_b = -1;
|
||||
|
||||
void set_color(int f, int b)
|
||||
{
|
||||
if ((f != old_f) || (b != old_b)) {
|
||||
old_f = f;
|
||||
old_b = b;
|
||||
mbse_colour(f, b);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static time_t lasttime;
|
||||
|
||||
/*
|
||||
* Show the current date & time in the second status row.
|
||||
* Show user paging status in third screen row.
|
||||
*/
|
||||
void show_date(int fg, int bg, int y, int x)
|
||||
{
|
||||
time_t now;
|
||||
char *p, buf[128], *pid, *page, *reason;
|
||||
|
||||
now = time(NULL);
|
||||
if (now != lasttime) {
|
||||
lasttime = now;
|
||||
set_color(LIGHTGREEN, BLUE);
|
||||
p = ctime(&now);
|
||||
Striplf(p);
|
||||
mbse_mvprintw(1, cols - 36, (char *)"%s TZUTC %s", p, gmtoffset(now));
|
||||
p = asctime(gmtime(&now));
|
||||
Striplf(p);
|
||||
mbse_mvprintw(2, cols - 36, (char *)"%s UTC", p);
|
||||
|
||||
/*
|
||||
* Indicator if bbs is free
|
||||
*/
|
||||
strcpy(buf, SockR("SFRE:0;"));
|
||||
if (strncmp(buf, "100:0;", 6) == 0) {
|
||||
strcpy(buf, SockR("SBBS:0;"));
|
||||
if (strncmp(buf, "100:2,1", 7) == 0) {
|
||||
set_color(WHITE, RED);
|
||||
mbse_mvprintw(2,cols - 6, (char *)" Down ");
|
||||
} else {
|
||||
set_color(WHITE, BLUE);
|
||||
mbse_mvprintw(2,cols - 6, (char *)" Free ");
|
||||
}
|
||||
bbs_free = TRUE;
|
||||
} else {
|
||||
set_color(WHITE, RED);
|
||||
mbse_mvprintw(2,cols - 6, (char *)" Busy ");
|
||||
bbs_free = FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check paging status
|
||||
*/
|
||||
strcpy(buf, SockR("CCKP:0;"));
|
||||
if (strcmp(buf, "100:0;") == 0) {
|
||||
mbse_locate(3, 1);
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
clrtoeol();
|
||||
} else {
|
||||
pid = strtok(buf, ",");
|
||||
pid = strtok(NULL, ",");
|
||||
page = strtok(NULL, ",");
|
||||
reason = xstrcpy(cldecode(strtok(NULL, ";")));
|
||||
if (strlen(reason) > 60)
|
||||
reason[60] = '\0';
|
||||
|
||||
mbse_locate(3, 1);
|
||||
if (strcmp(page, "1")) {
|
||||
set_color(RED, BLACK);
|
||||
mbse_mvprintw(3, 1, " Old page (%s) %-60s", pid, reason);
|
||||
if ((now % 10) == 0) /* Every 10 seconds */
|
||||
putchar(7);
|
||||
} else {
|
||||
set_color(LIGHTRED, BLACK);
|
||||
mbse_mvprintw(3, 1, " Sysop page (%s) %-60s", pid, reason);
|
||||
putchar(7); /* Each second */
|
||||
}
|
||||
free(reason);
|
||||
}
|
||||
|
||||
if (y && x)
|
||||
mbse_locate(y, x);
|
||||
set_color(fg, bg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void center_addstr(int y, char *s)
|
||||
{
|
||||
mbse_mvprintw(y, (cols / 2) - (strlen(s) / 2), s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Curses and screen initialisation.
|
||||
*/
|
||||
void screen_start(char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
mbse_TermInit(1, cols, rows);
|
||||
/*
|
||||
* Overwrite screen the first time, if user had it black on white
|
||||
* it will change to white on black. clear() won't do the trick.
|
||||
*/
|
||||
set_color(LIGHTGRAY, BLUE);
|
||||
mbse_locate(1, 1);
|
||||
for (i = 0; i < rows; i++) {
|
||||
if (i == 3)
|
||||
mbse_colour(LIGHTGRAY, BLACK);
|
||||
clrtoeol();
|
||||
if (i < rows)
|
||||
printf("\n");
|
||||
}
|
||||
fflush(stdout);
|
||||
|
||||
set_color(WHITE, BLUE);
|
||||
mbse_locate(1, 1);
|
||||
printf((char *)"%s for MBSE BBS version %s", name, VERSION);
|
||||
set_color(YELLOW, BLUE);
|
||||
mbse_locate(2, 1);
|
||||
printf((char *)SHORTRIGHT);
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Screen deinit
|
||||
*/
|
||||
void screen_stop()
|
||||
{
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
mbse_clear();
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Message at the upperright window about actions
|
||||
*/
|
||||
void working(int txno, int y, int x)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
* If txno not 0 there will be something written. The
|
||||
* reversed attributes for mono, or white on red for
|
||||
* color screens is set. The cursor is turned off and
|
||||
* original cursor position is saved.
|
||||
*/
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
|
||||
if (txno != 0)
|
||||
set_color(YELLOW, RED);
|
||||
else
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
|
||||
switch (txno) {
|
||||
case 0: mbse_mvprintw(4, cols - 14, (char *)" ");
|
||||
break;
|
||||
case 1: mbse_mvprintw(4, cols - 14, (char *)"Working . . .");
|
||||
break;
|
||||
case 2: mbse_mvprintw(4, cols - 14, (char *)">>> ERROR <<<");
|
||||
for (i = 1; i <= 5; i++) {
|
||||
putchar(7);
|
||||
fflush(stdout);
|
||||
msleep(150);
|
||||
}
|
||||
msleep(550);
|
||||
break;
|
||||
case 3: mbse_mvprintw(4, cols - 14, (char *)"Form inserted");
|
||||
putchar(7);
|
||||
fflush(stdout);
|
||||
sleep(1);
|
||||
break;
|
||||
case 4: mbse_mvprintw(4, cols - 14, (char *)"Form deleted ");
|
||||
putchar(7);
|
||||
fflush(stdout);
|
||||
sleep(1);
|
||||
break;
|
||||
}
|
||||
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
if (y && x)
|
||||
mbse_locate(y, x);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Clear the middle window
|
||||
*/
|
||||
void clr_index()
|
||||
{
|
||||
int i;
|
||||
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
for (i = 4; i <= (rows); i++) {
|
||||
mbse_locate(i, 1);
|
||||
clrtoeol();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Show help at the bottom of the screen.
|
||||
*/
|
||||
void showhelp(char *T)
|
||||
{
|
||||
int f, i, x, forlim;
|
||||
|
||||
f = FALSE;
|
||||
mbse_locate(rows, 1);
|
||||
set_color(WHITE, RED);
|
||||
clrtoeol();
|
||||
x = 0;
|
||||
forlim = strlen(T);
|
||||
|
||||
for (i = 0; i < forlim; i++) {
|
||||
if (T[i] == '^') {
|
||||
if (f == FALSE) {
|
||||
f = TRUE;
|
||||
set_color(YELLOW, RED);
|
||||
} else {
|
||||
f = FALSE;
|
||||
set_color(WHITE, RED);
|
||||
}
|
||||
} else {
|
||||
putchar(T[i]);
|
||||
x++;
|
||||
}
|
||||
}
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
@@ -1,22 +0,0 @@
|
||||
#ifndef _MUTIL_H
|
||||
#define _MUTIL_H
|
||||
|
||||
unsigned char readkey(int, int, int, int);
|
||||
unsigned char testkey(int, int);
|
||||
void show_field(int, int, char *, int, int);
|
||||
void newinsert(int, int, int);
|
||||
char *edit_field(int, int, int, int, char *);
|
||||
int select_menu(int);
|
||||
void clrtoeol(void);
|
||||
void hor_lin(int, int, int);
|
||||
void set_color(int, int);
|
||||
void show_date(int, int, int, int);
|
||||
void center_addstr(int y, char *s);
|
||||
void screen_start(char *);
|
||||
void screen_stop(void);
|
||||
void working(int, int, int);
|
||||
void clr_index(void);
|
||||
void showhelp(char *);
|
||||
|
||||
#endif
|
||||
|
140
mbmon/proglock.c
140
mbmon/proglock.c
@@ -1,140 +0,0 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id: proglock.c,v 1.6 2005/08/28 17:08:04 mbse Exp $
|
||||
* Purpose ...............: Program Locking
|
||||
*
|
||||
*****************************************************************************
|
||||
* 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.
|
||||
*
|
||||
* MBSE BBS is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../config.h"
|
||||
#include "../lib/mbselib.h"
|
||||
#include "proglock.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Put a lock on a program.
|
||||
*/
|
||||
int lockprogram(char *progname)
|
||||
{
|
||||
char *tempfile, *lockfile;
|
||||
FILE *fp;
|
||||
pid_t oldpid;
|
||||
|
||||
tempfile = calloc(PATH_MAX, sizeof(char));
|
||||
lockfile = calloc(PATH_MAX, sizeof(char));
|
||||
|
||||
snprintf(tempfile, PATH_MAX, "%s/var/run/%s.tmp", getenv("MBSE_ROOT"), progname);
|
||||
snprintf(lockfile, PATH_MAX, "%s/var/run/%s", getenv("MBSE_ROOT"), progname);
|
||||
|
||||
if ((fp = fopen(tempfile, "w")) == NULL) {
|
||||
Syslog('?', "$Can't create lockfile \"%s\"", tempfile);
|
||||
free(tempfile);
|
||||
free(lockfile);
|
||||
return 1;
|
||||
}
|
||||
fprintf(fp, "%10u\n", getpid());
|
||||
fclose(fp);
|
||||
|
||||
while (TRUE) {
|
||||
if (link(tempfile, lockfile) == 0) {
|
||||
unlink(tempfile);
|
||||
free(tempfile);
|
||||
free(lockfile);
|
||||
return 0;
|
||||
}
|
||||
if ((fp = fopen(lockfile, "r")) == NULL) {
|
||||
Syslog('?', "$Can't open lockfile \"%s\"", lockfile);
|
||||
unlink(tempfile);
|
||||
free(tempfile);
|
||||
free(lockfile);
|
||||
return 1;
|
||||
}
|
||||
if (fscanf(fp, "%u", &oldpid) != 1) {
|
||||
Syslog('?', "$Can't read old pid from \"%s\"", tempfile);
|
||||
fclose(fp);
|
||||
unlink(tempfile);
|
||||
free(tempfile);
|
||||
free(lockfile);
|
||||
return 1;
|
||||
}
|
||||
fclose(fp);
|
||||
if (kill(oldpid,0) == -1) {
|
||||
if (errno == ESRCH) {
|
||||
Syslog('+', "Stale lock found for pid %u", oldpid);
|
||||
unlink(lockfile);
|
||||
/* no return, try lock again */
|
||||
} else {
|
||||
Syslog('?', "$Kill for %u failed", oldpid);
|
||||
unlink(tempfile);
|
||||
free(tempfile);
|
||||
free(lockfile);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
Syslog('+', "%s already running, pid=%u", progname, oldpid);
|
||||
unlink(tempfile);
|
||||
free(tempfile);
|
||||
free(lockfile);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ulockprogram(char *progname)
|
||||
{
|
||||
char *lockfile;
|
||||
pid_t oldpid;
|
||||
FILE *fp;
|
||||
|
||||
lockfile = calloc(PATH_MAX, sizeof(char));
|
||||
snprintf(lockfile, PATH_MAX, "%s/var/run/%s", getenv("MBSE_ROOT"), progname);
|
||||
|
||||
if ((fp = fopen(lockfile, "r")) == NULL) {
|
||||
Syslog('?', "$Can't open lockfile \"%s\"", lockfile);
|
||||
free(lockfile);
|
||||
return;
|
||||
}
|
||||
if (fscanf(fp, "%u", &oldpid) != 1) {
|
||||
Syslog('?', "$Can't read old pid from \"%s\"", lockfile);
|
||||
fclose(fp);
|
||||
unlink(lockfile);
|
||||
free(lockfile);
|
||||
return;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
if (oldpid == getpid()) {
|
||||
(void)unlink(lockfile);
|
||||
} else {
|
||||
Syslog('?', "Lockfile owned by pid %d, not removed", oldpid);
|
||||
}
|
||||
|
||||
free(lockfile);
|
||||
}
|
||||
|
@@ -1,9 +0,0 @@
|
||||
#ifndef _PROGLOCK_H
|
||||
#define _PROGLOCK_H
|
||||
|
||||
/* $Id: proglock.h,v 1.1 2003/08/03 14:08:08 mbroek Exp $ */
|
||||
|
||||
int lockprogram(char *);
|
||||
void ulockprogram(char*);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user