Added basic logging
This commit is contained in:
parent
70a2ced9cf
commit
fc970f3d25
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,4 +9,5 @@ last10.dat
|
|||||||
ansis/*
|
ansis/*
|
||||||
config/*
|
config/*
|
||||||
illusion/*
|
illusion/*
|
||||||
|
logs/*
|
||||||
*.a
|
*.a
|
||||||
|
38
bbs.c
38
bbs.c
@ -9,6 +9,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include "inih/ini.h"
|
#include "inih/ini.h"
|
||||||
#include "bbs.h"
|
#include "bbs.h"
|
||||||
|
|
||||||
@ -21,6 +22,34 @@ int gSocket;
|
|||||||
int usertimeout;
|
int usertimeout;
|
||||||
int timeoutpaused;
|
int timeoutpaused;
|
||||||
|
|
||||||
|
void dolog(char *fmt, ...) {
|
||||||
|
char buffer[512];
|
||||||
|
struct tm time_now;
|
||||||
|
time_t timen;
|
||||||
|
FILE *logfptr;
|
||||||
|
|
||||||
|
if (conf.log_path == NULL) return;
|
||||||
|
|
||||||
|
timen = time(NULL);
|
||||||
|
|
||||||
|
localtime_r(&timen, &time_now);
|
||||||
|
|
||||||
|
snprintf(buffer, 512, "%s/%04d%02d%02d.log", conf.log_path, time_now.tm_year + 1900, time_now.tm_mon + 1, time_now.tm_mday);
|
||||||
|
logfptr = fopen(buffer, "a");
|
||||||
|
if (!logfptr) {
|
||||||
|
printf("Error opening log file!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(buffer, 512, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
fprintf(logfptr, "%02d:%02d:%02d %s\n", time_now.tm_hour, time_now.tm_min, time_now.tm_sec, buffer);
|
||||||
|
|
||||||
|
fclose(logfptr);
|
||||||
|
}
|
||||||
|
|
||||||
struct fido_addr *parse_fido_addr(const char *str) {
|
struct fido_addr *parse_fido_addr(const char *str) {
|
||||||
struct fido_addr *ret = (struct fido_addr *)malloc(sizeof(struct fido_addr));
|
struct fido_addr *ret = (struct fido_addr *)malloc(sizeof(struct fido_addr));
|
||||||
int c;
|
int c;
|
||||||
@ -322,6 +351,8 @@ static int handler(void* user, const char* section, const char* name,
|
|||||||
conf->ansi_path = strdup(value);
|
conf->ansi_path = strdup(value);
|
||||||
} else if (strcasecmp(name, "bbs path") == 0) {
|
} else if (strcasecmp(name, "bbs path") == 0) {
|
||||||
conf->bbs_path = strdup(value);
|
conf->bbs_path = strdup(value);
|
||||||
|
} else if (strcasecmp(name, "log path") == 0) {
|
||||||
|
conf->log_path = strdup(value);
|
||||||
}
|
}
|
||||||
} else if (strcasecmp(section, "mail conferences") == 0) {
|
} else if (strcasecmp(section, "mail conferences") == 0) {
|
||||||
if (conf->mail_conference_count == 0) {
|
if (conf->mail_conference_count == 0) {
|
||||||
@ -512,6 +543,7 @@ void disconnect(int socket) {
|
|||||||
if (gUser != NULL) {
|
if (gUser != NULL) {
|
||||||
save_user(gUser);
|
save_user(gUser);
|
||||||
}
|
}
|
||||||
|
dolog("Node %d disconnected", mynode);
|
||||||
sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode);
|
sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode);
|
||||||
remove(buffer);
|
remove(buffer);
|
||||||
close(socket);
|
close(socket);
|
||||||
@ -631,6 +663,7 @@ void runbbs(int socket, char *config_path) {
|
|||||||
conf.irc_port = 6667;
|
conf.irc_port = 6667;
|
||||||
conf.text_file_count = 0;
|
conf.text_file_count = 0;
|
||||||
conf.external_editor_cmd = NULL;
|
conf.external_editor_cmd = NULL;
|
||||||
|
conf.log_path = NULL;
|
||||||
|
|
||||||
// Load BBS data
|
// Load BBS data
|
||||||
if (ini_parse(config_path, handler, &conf) <0) {
|
if (ini_parse(config_path, handler, &conf) <0) {
|
||||||
@ -751,6 +784,7 @@ void runbbs(int socket, char *config_path) {
|
|||||||
fclose(nodefile);
|
fclose(nodefile);
|
||||||
|
|
||||||
// do post-login
|
// do post-login
|
||||||
|
dolog("%s logged in, on node %d", user->loginname, mynode);
|
||||||
// check time left
|
// check time left
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
localtime_r(&now, &thetime);
|
localtime_r(&now, &thetime);
|
||||||
@ -770,7 +804,7 @@ void runbbs(int socket, char *config_path) {
|
|||||||
while (stat(buffer, &s) == 0) {
|
while (stat(buffer, &s) == 0) {
|
||||||
sprintf(buffer, "bulletin%d", i);
|
sprintf(buffer, "bulletin%d", i);
|
||||||
s_displayansi(socket, buffer);
|
s_displayansi(socket, buffer);
|
||||||
sprintf(buffer, "Press any key to continue...\r\n");
|
sprintf(buffer, "\e[0mPress any key to continue...\r\n");
|
||||||
s_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
s_getc(socket);
|
s_getc(socket);
|
||||||
i++;
|
i++;
|
||||||
@ -799,6 +833,6 @@ void runbbs(int socket, char *config_path) {
|
|||||||
main_menu(socket, user);
|
main_menu(socket, user);
|
||||||
|
|
||||||
s_displayansi(socket, "goodbye");
|
s_displayansi(socket, "goodbye");
|
||||||
|
dolog("%s is logging out, on node %d", user->loginname, mynode);
|
||||||
disconnect(socket);
|
disconnect(socket);
|
||||||
}
|
}
|
||||||
|
3
bbs.h
3
bbs.h
@ -83,6 +83,7 @@ struct bbs_config {
|
|||||||
|
|
||||||
char *ansi_path;
|
char *ansi_path;
|
||||||
char *bbs_path;
|
char *bbs_path;
|
||||||
|
char *log_path;
|
||||||
|
|
||||||
char *default_tagline;
|
char *default_tagline;
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ struct user_record {
|
|||||||
int timeson;
|
int timeson;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern void dolog(char *fmt, ...);
|
||||||
extern void runbbs(int sock, char *config);
|
extern void runbbs(int sock, char *config);
|
||||||
extern struct fido_addr *parse_fido_addr(const char *str);
|
extern struct fido_addr *parse_fido_addr(const char *str);
|
||||||
extern void s_putchar(int socket, char c);
|
extern void s_putchar(int socket, char c);
|
||||||
|
@ -13,6 +13,7 @@ External Editor stdio = false
|
|||||||
[paths]
|
[paths]
|
||||||
ANSI Path = /home/andrew/MagickaBBS/ansis
|
ANSI Path = /home/andrew/MagickaBBS/ansis
|
||||||
BBS Path = /home/andrew/MagickaBBS
|
BBS Path = /home/andrew/MagickaBBS
|
||||||
|
Log Path = /home/andrew/MagickaBBS/logs
|
||||||
|
|
||||||
[mail conferences]
|
[mail conferences]
|
||||||
Local Mail = config/localmail.ini
|
Local Mail = config/localmail.ini
|
||||||
|
2
doors.c
2
doors.c
@ -262,7 +262,9 @@ int door_menu(int socket, struct user_record *user) {
|
|||||||
{
|
{
|
||||||
for (i=0;i<conf.door_count;i++) {
|
for (i=0;i<conf.door_count;i++) {
|
||||||
if (tolower(c) == tolower(conf.doors[i]->key)) {
|
if (tolower(c) == tolower(conf.doors[i]->key)) {
|
||||||
|
dolog("%s is launched door %s, on node %d", user->loginname, conf.doors[i]->name, mynode);
|
||||||
rundoor(socket, user, conf.doors[i]->command, conf.doors[i]->stdio);
|
rundoor(socket, user, conf.doors[i]->command, conf.doors[i]->stdio);
|
||||||
|
dolog("%s is returned from door %s, on node %d", user->loginname, conf.doors[i]->name, mynode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
main.c
2
main.c
@ -8,6 +8,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
#include "bbs.h"
|
#include "bbs.h"
|
||||||
|
|
||||||
void sigchld_handler(int s)
|
void sigchld_handler(int s)
|
||||||
@ -71,7 +72,6 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
close(socket_desc);
|
close(socket_desc);
|
||||||
|
|
||||||
runbbs(client_sock, argv[1]);
|
runbbs(client_sock, argv[1]);
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -82,7 +82,7 @@ void main_menu(int socket, struct user_record *user) {
|
|||||||
while (stat(buffer, &s) == 0) {
|
while (stat(buffer, &s) == 0) {
|
||||||
sprintf(buffer, "bulletin%d", i);
|
sprintf(buffer, "bulletin%d", i);
|
||||||
s_displayansi(socket, buffer);
|
s_displayansi(socket, buffer);
|
||||||
sprintf(buffer, "Press any key to continue...\r\n");
|
sprintf(buffer, "\e[0mPress any key to continue...\r\n");
|
||||||
s_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
s_getc(socket);
|
s_getc(socket);
|
||||||
i++;
|
i++;
|
||||||
|
Reference in New Issue
Block a user