Started on a WWW server, not complete disabled by default
This commit is contained in:
parent
86e39b7522
commit
f214eb2faf
@ -1,16 +1,17 @@
|
||||
CC=cc
|
||||
CFLAGS=-I/usr/local/include
|
||||
CFLAGS=-I/usr/local/include
|
||||
DEPS = bbs.h
|
||||
JAMLIB = jamlib/jamlib.a
|
||||
ZMODEM = Xmodem/libzmodem.a
|
||||
LUA = lua/liblua.a
|
||||
MICROHTTPD=
|
||||
|
||||
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o
|
||||
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
magicka: $(OBJ)
|
||||
$(CC) -o magicka -o $@ $^ $(CFLAGS) -L/usr/local/lib -lsqlite3 $(JAMLIB) $(ZMODEM) $(LUA) -lutil -lm -lssl -lcrypto -lssh
|
||||
$(CC) -o magicka -o $@ $^ $(CFLAGS) -L/usr/local/lib -lsqlite3 $(JAMLIB) $(ZMODEM) $(LUA) -lutil -lm -lssl -lcrypto -lssh $(MICROHTTPD)
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
|
19
Makefile.freebsd.WWW
Normal file
19
Makefile.freebsd.WWW
Normal file
@ -0,0 +1,19 @@
|
||||
CC=cc
|
||||
CFLAGS=-I/usr/local/include -DENABLE_WWW=1
|
||||
DEPS = bbs.h
|
||||
JAMLIB = jamlib/jamlib.a
|
||||
ZMODEM = Xmodem/libzmodem.a
|
||||
LUA = lua/liblua.a
|
||||
MICROHTTPD=-lmicrohttpd
|
||||
|
||||
OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o lua_glue.o strings.o www.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
magicka: $(OBJ)
|
||||
$(CC) -o magicka -o $@ $^ $(CFLAGS) -L/usr/local/lib -lsqlite3 $(JAMLIB) $(ZMODEM) $(LUA) -lutil -lm -lssl -lcrypto -lssh $(MICROHTTPD)
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) magicka
|
12
bbs.h
12
bbs.h
@ -2,6 +2,9 @@
|
||||
#define __BBS_H__
|
||||
|
||||
#include <time.h>
|
||||
#if defined(ENABLE_WWW)
|
||||
#include <microhttpd.h>
|
||||
#endif
|
||||
#include "lua/lua.h"
|
||||
#include "lua/lauxlib.h"
|
||||
|
||||
@ -91,7 +94,9 @@ struct bbs_config {
|
||||
char *netmail_sem;
|
||||
char *default_tagline;
|
||||
int telnet_port;
|
||||
|
||||
int www_server;
|
||||
int www_port;
|
||||
char *www_path;
|
||||
int ssh_server;
|
||||
int ssh_port;
|
||||
char *ssh_dsa_key;
|
||||
@ -195,4 +200,9 @@ extern void lua_push_cfunctions(lua_State *L);
|
||||
|
||||
extern void load_strings();
|
||||
extern char *get_string(int offset);
|
||||
|
||||
#if defined(ENABLE_WWW)
|
||||
extern int www_handler(void * cls, struct MHD_Connection * connection, const char * url, const char * method, const char * version, const char * upload_data, size_t * upload_data_size, void ** ptr);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -12,12 +12,15 @@ External Editor cmd = /home/andrew/MagickaBBS/doors/oedit.sh
|
||||
External Editor stdio = false
|
||||
Automessage Write Level = 10
|
||||
Fork = false
|
||||
Enable WWW = false
|
||||
WWW Port = 8080
|
||||
Enable SSH = false
|
||||
SSH Port = 2024
|
||||
SSH DSA Key = /home/andrew/MagickaBBS/keys/ssh_host_dsa_key
|
||||
SSH RSA Key = /home/andrew/MagickaBBS/keys/ssh_host_rsa_key
|
||||
|
||||
[paths]
|
||||
WWW Path = /home/andrew/MagickaBBS/www
|
||||
String File = /home/andrew/MagickaBBS/magicka.strings
|
||||
PID File = /home/andrew/MagickaBBS/magicka.pid
|
||||
ANSI Path = /home/andrew/MagickaBBS/ansis
|
||||
|
2
doors.c
2
doors.c
@ -174,7 +174,7 @@ void rundoor(struct user_record *user, char *cmd, int stdio) {
|
||||
if (openpty(&master, &slave, NULL, NULL, &ws) == 0) {
|
||||
sa.sa_handler = doorchld_handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_RESTART;
|
||||
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||
if (sigaction(SIGCHLD, &sa, NULL) == -1) {
|
||||
perror("sigaction");
|
||||
exit(1);
|
||||
|
@ -105,7 +105,7 @@ minix:
|
||||
$(MAKE) $(ALL) CC="clang" SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-L/usr/pkg/lib -Wl,-E -lreadline"
|
||||
|
||||
freebsd:
|
||||
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -lreadline"
|
||||
$(MAKE) $(ALL) CC="cc" SYSCFLAGS="-DLUA_USE_LINUX -I/usr/local/include" SYSLIBS="-Wl,-E -L/usr/local/lib -lreadline"
|
||||
|
||||
generic: $(ALL)
|
||||
|
||||
|
44
main.c
44
main.c
@ -22,6 +22,9 @@
|
||||
#else
|
||||
# include <libutil.h>
|
||||
#endif
|
||||
#if defined(ENABLE_WWW)
|
||||
# include <microhttpd.h>
|
||||
#endif
|
||||
#include <termios.h>
|
||||
#include "bbs.h"
|
||||
#include "inih/ini.h"
|
||||
@ -33,6 +36,10 @@ int ssh_pid = -1;
|
||||
int bbs_pid = 0;
|
||||
int server_socket = -1;
|
||||
|
||||
#if defined(ENABLE_WWW)
|
||||
struct MHD_Daemon *www_daemon;
|
||||
#endif
|
||||
|
||||
void sigterm_handler(int s)
|
||||
{
|
||||
if (ssh_pid != -1) {
|
||||
@ -41,6 +48,11 @@ void sigterm_handler(int s)
|
||||
if (server_socket != -1) {
|
||||
close(server_socket);
|
||||
}
|
||||
#if defined(ENABLE_WWW)
|
||||
if (www_daemon != NULL) {
|
||||
MHD_stop_daemon(www_daemon);
|
||||
}
|
||||
#endif
|
||||
remove(conf.pid_file);
|
||||
exit(0);
|
||||
}
|
||||
@ -259,6 +271,14 @@ static int handler(void* user, const char* section, const char* name,
|
||||
} else {
|
||||
conf->ssh_server = 0;
|
||||
}
|
||||
} else if (strcasecmp(name, "enable www") == 0) {
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
conf->www_server = 1;
|
||||
} else {
|
||||
conf->www_server = 0;
|
||||
}
|
||||
} else if (strcasecmp(name, "www port") == 0) {
|
||||
conf->www_port = atoi(value);
|
||||
} else if (strcasecmp(name, "ssh port") == 0) {
|
||||
conf->ssh_port = atoi(value);
|
||||
} else if (strcasecmp(name, "ssh dsa key") == 0) {
|
||||
@ -313,6 +333,8 @@ static int handler(void* user, const char* section, const char* name,
|
||||
conf->pid_file = strdup(value);
|
||||
} else if (strcasecmp(name, "string file") == 0) {
|
||||
conf->string_file = strdup(value);
|
||||
} else if (strcasecmp(name, "www path") == 0) {
|
||||
conf->www_path = strdup(value);
|
||||
}
|
||||
} else if (strcasecmp(section, "mail conferences") == 0) {
|
||||
if (conf->mail_conference_count == 0) {
|
||||
@ -627,29 +649,34 @@ void server(int port) {
|
||||
int client_sock, c;
|
||||
int pid;
|
||||
struct sockaddr_in server, client;
|
||||
#if defined(ENABLE_WWW)
|
||||
www_daemon = NULL;
|
||||
#endif
|
||||
|
||||
sa.sa_handler = sigchld_handler; // reap all dead processes
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_RESTART;
|
||||
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||
if (sigaction(SIGCHLD, &sa, NULL) == -1) {
|
||||
perror("sigaction - sigchld");
|
||||
remove(conf.pid_file);
|
||||
perror("sigaction");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
st.sa_handler = sigterm_handler;
|
||||
sigemptyset(&st.sa_mask);
|
||||
st.sa_flags = SA_SIGINFO;
|
||||
if (sigaction(SIGTERM, &st, NULL) == -1) {
|
||||
perror("sigaction - sigterm");
|
||||
remove(conf.pid_file);
|
||||
perror("sigaction");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sq.sa_handler = sigterm_handler;
|
||||
sigemptyset(&sq.sa_mask);
|
||||
sq.sa_flags = SA_SIGINFO;
|
||||
if (sigaction(SIGQUIT, &sq, NULL) == -1) {
|
||||
perror("sigaction - sigquit");
|
||||
remove(conf.pid_file);
|
||||
perror("sigaction");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -667,6 +694,12 @@ void server(int port) {
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ENABLE_WWW)
|
||||
if (conf.www_server && conf.www_path != NULL) {
|
||||
www_daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, conf.www_port, NULL, NULL, &www_handler, NULL, MHD_OPTION_END);
|
||||
}
|
||||
#endif
|
||||
|
||||
server_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (server_socket == -1) {
|
||||
remove(conf.pid_file);
|
||||
@ -741,7 +774,8 @@ int main(int argc, char **argv) {
|
||||
conf.netmail_sem = NULL;
|
||||
conf.telnet_port = 0;
|
||||
conf.string_file = NULL;
|
||||
|
||||
conf.www_path = NULL;
|
||||
|
||||
// Load BBS data
|
||||
if (ini_parse(argv[1], handler, &conf) <0) {
|
||||
fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]);
|
||||
|
142
www.c
Normal file
142
www.c
Normal file
@ -0,0 +1,142 @@
|
||||
#if defined(ENABLE_WWW)
|
||||
|
||||
#include <microhttpd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include "bbs.h"
|
||||
|
||||
extern struct bbs_config conf;
|
||||
|
||||
int www_handler(void * cls, struct MHD_Connection * connection, const char * url, const char * method, const char * version, const char * upload_data, size_t * upload_data_size, void ** ptr) {
|
||||
struct MHD_Response *response;
|
||||
|
||||
int ret;
|
||||
char *page;
|
||||
char buffer[4096];
|
||||
struct stat s;
|
||||
char *header;
|
||||
char *footer;
|
||||
char *whole_page;
|
||||
FILE *fptr;
|
||||
|
||||
snprintf(buffer, 4096, "%s/header.tpl", conf.www_path);
|
||||
|
||||
header = NULL;
|
||||
|
||||
if (stat(buffer, &s) == 0) {
|
||||
header = (char *)malloc(s.st_size + 1);
|
||||
if (header == NULL) {
|
||||
return MHD_NO;
|
||||
}
|
||||
fptr = fopen(buffer, "r");
|
||||
if (fptr) {
|
||||
fread(header, s.st_size, 1, fptr);
|
||||
fclose(fptr);
|
||||
} else {
|
||||
free(header);
|
||||
header = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (header == NULL) {
|
||||
header = (char *)malloc(strlen(conf.bbs_name) * 2 + 61);
|
||||
if (header == NULL) {
|
||||
return MHD_NO;
|
||||
}
|
||||
sprintf(header, "<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n</HEAD>\n<BODY>\n<H1>%s</H1><HR />", conf.bbs_name, conf.bbs_name);
|
||||
}
|
||||
|
||||
snprintf(buffer, 4096, "%s/footer.tpl", conf.www_path);
|
||||
|
||||
footer = NULL;
|
||||
|
||||
if (stat(buffer, &s) == 0) {
|
||||
footer = (char *)malloc(s.st_size + 1);
|
||||
if (footer == NULL) {
|
||||
free(header);
|
||||
return MHD_NO;
|
||||
}
|
||||
fptr = fopen(buffer, "r");
|
||||
if (fptr) {
|
||||
fread(footer, s.st_size, 1, fptr);
|
||||
fclose(fptr);
|
||||
} else {
|
||||
free(footer);
|
||||
footer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (footer == NULL) {
|
||||
footer = (char *)malloc(43);
|
||||
if (footer == NULL) {
|
||||
free(header);
|
||||
return MHD_NO;
|
||||
}
|
||||
sprintf(footer, "<HR />Powered by Magicka BBS</BODY></HTML>");
|
||||
}
|
||||
|
||||
if (strcmp(method, "GET") == 0) {
|
||||
if (strcasecmp(url, "/") == 0) {
|
||||
|
||||
snprintf(buffer, 4096, "%s/index.tpl", conf.www_path);
|
||||
|
||||
page = NULL;
|
||||
|
||||
if (stat(buffer, &s) == 0) {
|
||||
page = (char *)malloc(s.st_size + 1);
|
||||
if (page == NULL) {
|
||||
free(header);
|
||||
free(footer);
|
||||
return MHD_NO;
|
||||
}
|
||||
fptr = fopen(buffer, "r");
|
||||
if (fptr) {
|
||||
fread(page, s.st_size, 1, fptr);
|
||||
fclose(fptr);
|
||||
} else {
|
||||
free(page);
|
||||
page = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (page == NULL) {
|
||||
page = (char *)malloc(16);
|
||||
if (page == NULL) {
|
||||
free(header);
|
||||
free(footer);
|
||||
return MHD_NO;
|
||||
}
|
||||
sprintf(page, "Missing Content");
|
||||
}
|
||||
|
||||
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
|
||||
|
||||
sprintf(whole_page, "%s%s%s", header, page, footer);
|
||||
} else if (strncasecmp(url, "/static/", 8) == 0) {
|
||||
// sanatize path
|
||||
|
||||
// load file
|
||||
} else {
|
||||
free(header);
|
||||
free(footer);
|
||||
return MHD_NO;
|
||||
}
|
||||
} else if (strcmp(method, "POST") == 0) {
|
||||
free(header);
|
||||
free(footer);
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
response = MHD_create_response_from_buffer (strlen (whole_page), (void*) whole_page, MHD_RESPMEM_PERSISTENT);
|
||||
|
||||
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response (response);
|
||||
free(whole_page);
|
||||
free(page);
|
||||
free(header);
|
||||
free(footer);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
2
www/footer.tpl
Normal file
2
www/footer.tpl
Normal file
@ -0,0 +1,2 @@
|
||||
</BODY>
|
||||
</HTML>
|
4
www/header.tpl
Normal file
4
www/header.tpl
Normal file
@ -0,0 +1,4 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
</HEAD>
|
||||
<BODY>
|
3
www/index.tpl
Normal file
3
www/index.tpl
Normal file
@ -0,0 +1,3 @@
|
||||
<h2>Welcome to another Magicka BBS!</h2>
|
||||
|
||||
The sysop should customize this file with what he wants on the front page!
|
Reference in New Issue
Block a user