diff --git a/.gitignore b/.gitignore
index 442798f..c076286 100644
--- a/.gitignore
+++ b/.gitignore
@@ -75,3 +75,4 @@ menus/file.mnu
menus/logoff.mnu
menus/mail.mnu
menus/main.mnu
+.vscode/settings.json
diff --git a/dist/config/bbs.ini b/dist/config/bbs.ini
index 3a2736a..22dd472 100644
--- a/dist/config/bbs.ini
+++ b/dist/config/bbs.ini
@@ -16,6 +16,7 @@ Automessage Write Level = 10
Fork = false
Enable WWW = false
WWW Port = 8080
+WWW URL = http://127.0.0.1:8080/
Enable SSH = false
SSH Port = 2024
SSH DSA Key = /home/andrew/MagickaBBS/keys/ssh_host_dsa_key
diff --git a/dist/www/header.tpl b/dist/www/header.tpl
index 29bb8f5..7dd9a84 100644
--- a/dist/www/header.tpl
+++ b/dist/www/header.tpl
@@ -1,19 +1,19 @@
Magicka BBS
-
+
diff --git a/file_id.diz b/file_id.diz
index 110c861..95d964a 100644
--- a/file_id.diz
+++ b/file_id.diz
@@ -1,6 +1,6 @@
. . . .__ .__ __.
|\/| _. _ * _.;_/ _. [__)[__)(__
-| |(_](_]|(_.| \(_] [__)[__).__) v0.8a
+| |(_](_]|(_.| \(_] [__)[__).__) v0.9a
-------._|----------------------------------
Magicka BBS is a Free BBS System for Linux,
macOS, FreeBSD, NetBSD, OpenIndiana,
diff --git a/src/bbs.c b/src/bbs.c
index 04e4a2c..11802bd 100644
--- a/src/bbs.c
+++ b/src/bbs.c
@@ -1075,3 +1075,49 @@ int copy_file(char *src, char *dest) {
fclose(dest_file);
return 0;
}
+
+char *str_replace(char *orig, char *rep, char *with) {
+ char *result; // the return string
+ char *ins; // the next insert point
+ char *tmp; // varies
+ int len_rep; // length of rep (the string to remove)
+ int len_with; // length of with (the string to replace rep with)
+ int len_front; // distance between rep and end of last rep
+ int count; // number of replacements
+
+ // sanity checks and initialization
+ if (!orig || !rep)
+ return NULL;
+ len_rep = strlen(rep);
+ if (len_rep == 0)
+ return NULL; // empty rep causes infinite loop during count
+ if (!with)
+ with = "";
+ len_with = strlen(with);
+
+ // count the number of replacements needed
+ ins = orig;
+ for (count = 0; tmp = strstr(ins, rep); ++count) {
+ ins = tmp + len_rep;
+ }
+
+ tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1);
+
+ if (!result)
+ return NULL;
+
+ // first time through the loop, all the variable are set correctly
+ // from here on,
+ // tmp points to the end of the result string
+ // ins points to the next occurrence of rep in orig
+ // orig points to the remainder of orig after "end of rep"
+ while (count--) {
+ ins = strstr(orig, rep);
+ len_front = ins - orig;
+ tmp = strncpy(tmp, orig, len_front) + len_front;
+ tmp = strcpy(tmp, with) + len_with;
+ orig += len_front + len_rep; // move to next "end of rep"
+ }
+ strcpy(tmp, orig);
+ return result;
+}
diff --git a/src/bbs.h b/src/bbs.h
index efe4e7a..e745edf 100644
--- a/src/bbs.h
+++ b/src/bbs.h
@@ -12,7 +12,7 @@
#include "jamlib/jam.h"
#define VERSION_MAJOR 0
-#define VERSION_MINOR 8
+#define VERSION_MINOR 9
#define VERSION_STR "alpha"
#define NETWORK_FIDO 1
@@ -128,6 +128,7 @@ struct bbs_config {
char *netmail_sem;
char *default_tagline;
int telnet_port;
+ char *www_url;
int www_server;
int www_port;
char *www_path;
@@ -227,6 +228,8 @@ struct msg_headers {
struct jam_msg **msgs;
int msg_count;
};
+
+extern char *str_replace(char *orig, char *rep, char *with);
extern int copy_file(char *src, char *dest);
extern int recursive_delete(const char *dir);
extern void automessage_write(struct user_record *user);
diff --git a/src/main.c b/src/main.c
index 19a6cc2..43c0c1e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -425,6 +425,13 @@ static int handler(void* user, const char* section, const char* name,
}
} else if (strcasecmp(name, "www port") == 0) {
conf->www_port = atoi(value);
+ } else if (strcasecmp(name, "www url") == 0) {
+ if (value[strlen(value) - 1] == '/') {
+ conf->www_url = strdup(value);
+ } else {
+ conf->www_url = (char *)malloc(strlen(value) + 2);
+ sprintf(conf->www_url, "%s/", value);
+ }
} else if (strcasecmp(name, "ssh port") == 0) {
conf->ssh_port = atoi(value);
} else if (strcasecmp(name, "ssh dsa key") == 0) {
@@ -1065,7 +1072,7 @@ void server(int port, int ipv6) {
}
#if defined(ENABLE_WWW)
- if (conf.www_server && conf.www_path != NULL) {
+ if (conf.www_server && conf.www_path != NULL && conf.www_url != NULL) {
if (!conf.fork) {
printf(" - HTTP Starting on Port %d (IPv%d)\n", conf.www_port, (ipv6 ? 6 : 4));
}
@@ -1241,6 +1248,7 @@ int main(int argc, char **argv) {
conf.telnet_port = 0;
conf.string_file = NULL;
conf.www_path = NULL;
+ conf.www_url = NULL;
conf.archiver_count = 0;
conf.broadcast_enable = 0;
conf.broadcast_port = 0;
diff --git a/src/www.c b/src/www.c
index bbb1bd2..39c398e 100644
--- a/src/www.c
+++ b/src/www.c
@@ -40,8 +40,14 @@ struct connection_info_s {
};
void *www_logger(void * cls, const char * uri, struct MHD_Connection *con) {
- struct sockaddr_in *so = (struct sockaddr_in *)MHD_get_connection_info(con, MHD_CONNECTION_INFO_CLIENT_ADDRESS)->client_addr;
- ipaddress = strdup(inet_ntoa(so->sin_addr));
+ struct sockaddr *so = (struct sockaddr *)MHD_get_connection_info(con, MHD_CONNECTION_INFO_CLIENT_ADDRESS)->client_addr;
+ if (so->sa_family == AF_INET) {
+ ipaddress = (char *)malloc(INET_ADDRSTRLEN + 1);
+ inet_ntop(AF_INET, &((struct sockaddr_in *)so)->sin_addr, ipaddress, INET_ADDRSTRLEN);
+ } else if (so->sa_family == AF_INET6) {
+ ipaddress = (char *)malloc(INET6_ADDRSTRLEN + 1);
+ inet_ntop(AF_INET6, &((struct sockaddr_in6 *)so)->sin6_addr, ipaddress, INET6_ADDRSTRLEN);
+ }
dolog("%s", uri);
free(ipaddress);
ipaddress = NULL;
@@ -78,6 +84,7 @@ void www_request_completed(void *cls, struct MHD_Connection *connection, void **
free(con_info->user->email);
free(con_info->user->location);
free(con_info->user->sec_info);
+ free(con_info->user->signature);
free(con_info->user);
}
@@ -181,7 +188,7 @@ char *www_get_mime_type(const char *extension) {
int www_401(char *header, char *footer, struct MHD_Connection * connection) {
char buffer[4096];
- char *page;
+ char *page, *page_tmp;
struct stat s;
char *whole_page;
struct MHD_Response *response;
@@ -190,32 +197,35 @@ int www_401(char *header, char *footer, struct MHD_Connection * connection) {
snprintf(buffer, 4096, "%s/401.tpl", conf.www_path);
- page = NULL;
+ page_tmp = NULL;
if (stat(buffer, &s) == 0) {
- page = (char *)malloc(s.st_size + 1);
- if (page == NULL) {
+ page_tmp = (char *)malloc(s.st_size + 1);
+ if (page_tmp == NULL) {
return -1;
}
- memset(page, 0, s.st_size + 1);
+ memset(page_tmp, 0, s.st_size + 1);
fptr = fopen(buffer, "r");
if (fptr) {
- fread(page, s.st_size, 1, fptr);
+ fread(page_tmp, s.st_size, 1, fptr);
fclose(fptr);
} else {
- free(page);
- page = NULL;
+ free(page_tmp);
+ page_tmp = NULL;
}
}
- if (page == NULL) {
- page = (char *)malloc(16);
- if (page == NULL) {
+ if (page_tmp == NULL) {
+ page_tmp = (char *)malloc(16);
+ if (page_tmp == NULL) {
return -1;
}
- sprintf(page, "Missing Content");
+ sprintf(page_tmp, "Missing Content");
}
-
+
+ page = str_replace(page_tmp, "@@WWW_URL@@", conf.www_url);
+ free(page_tmp);
+
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
@@ -233,7 +243,7 @@ int www_401(char *header, char *footer, struct MHD_Connection * connection) {
int www_404(char *header, char *footer, struct MHD_Connection * connection) {
char buffer[4096];
- char *page;
+ char *page, *page_tmp;
struct stat s;
char *whole_page;
struct MHD_Response *response;
@@ -242,32 +252,35 @@ int www_404(char *header, char *footer, struct MHD_Connection * connection) {
snprintf(buffer, 4096, "%s/404.tpl", conf.www_path);
- page = NULL;
+ page_tmp = NULL;
if (stat(buffer, &s) == 0) {
- page = (char *)malloc(s.st_size + 1);
- if (page == NULL) {
+ page_tmp = (char *)malloc(s.st_size + 1);
+ if (page_tmp == NULL) {
return -1;
}
- memset(page, 0, s.st_size + 1);
+ memset(page_tmp, 0, s.st_size + 1);
fptr = fopen(buffer, "r");
if (fptr) {
- fread(page, s.st_size, 1, fptr);
+ fread(page_tmp, s.st_size, 1, fptr);
fclose(fptr);
} else {
- free(page);
+ free(page_tmp);
page = NULL;
}
}
- if (page == NULL) {
- page = (char *)malloc(16);
- if (page == NULL) {
+ if (page_tmp == NULL) {
+ page_tmp = (char *)malloc(16);
+ if (page_tmp == NULL) {
return -1;
}
- sprintf(page, "Missing Content");
+ sprintf(page_tmp, "Missing Content");
}
-
+
+ page = str_replace(page_tmp, "@@WWW_URL@@", conf.www_url);
+ free(page_tmp);
+
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
@@ -283,7 +296,7 @@ int www_404(char *header, char *footer, struct MHD_Connection * connection) {
int www_403(char *header, char *footer, struct MHD_Connection * connection) {
char buffer[4096];
- char *page;
+ char *page, *page_tmp;
struct stat s;
char *whole_page;
struct MHD_Response *response;
@@ -292,32 +305,35 @@ int www_403(char *header, char *footer, struct MHD_Connection * connection) {
snprintf(buffer, 4096, "%s/403.tpl", conf.www_path);
- page = NULL;
+ page_tmp = NULL;
if (stat(buffer, &s) == 0) {
- page = (char *)malloc(s.st_size + 1);
- if (page == NULL) {
+ page_tmp = (char *)malloc(s.st_size + 1);
+ if (page_tmp == NULL) {
return -1;
}
- memset(page, 0, s.st_size + 1);
+ memset(page_tmp, 0, s.st_size + 1);
fptr = fopen(buffer, "r");
if (fptr) {
- fread(page, s.st_size, 1, fptr);
+ fread(page_tmp, s.st_size, 1, fptr);
fclose(fptr);
} else {
- free(page);
- page = NULL;
+ free(page_tmp);
+ page_tmp = NULL;
}
}
- if (page == NULL) {
- page = (char *)malloc(16);
- if (page == NULL) {
+ if (page_tmp == NULL) {
+ page_tmp = (char *)malloc(16);
+ if (page_tmp == NULL) {
return -1;
}
- sprintf(page, "Missing Content");
+ sprintf(page_tmp, "Missing Content");
}
-
+
+ page = str_replace(page_tmp, "@@WWW_URL@@", conf.www_url);
+ free(page_tmp);
+
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
@@ -376,11 +392,11 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
struct MHD_Response *response;
int ret;
- char *page;
+ char *page, *page_tmp;
char buffer[4096];
struct stat s;
- char *header;
- char *footer;
+ char *header, *header_tmp;
+ char *footer, *footer_tmp;
char *whole_page;
FILE *fptr;
char *mime;
@@ -432,97 +448,106 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
snprintf(buffer, 4096, "%s/header.tpl", conf.www_path);
- header = NULL;
+ header_tmp = NULL;
if (stat(buffer, &s) == 0) {
- header = (char *)malloc(s.st_size + 1);
- if (header == NULL) {
+ header_tmp = (char *)malloc(s.st_size + 1);
+ if (header_tmp == NULL) {
return MHD_NO;
}
- memset(header, 0, s.st_size + 1);
+ memset(header_tmp, 0, s.st_size + 1);
fptr = fopen(buffer, "r");
if (fptr) {
- fread(header, s.st_size, 1, fptr);
+ fread(header_tmp, s.st_size, 1, fptr);
fclose(fptr);
} else {
- free(header);
- header = NULL;
+ free(header_tmp);
+ header_tmp = NULL;
}
}
- if (header == NULL) {
- header = (char *)malloc(strlen(conf.bbs_name) * 2 + 61);
- if (header == NULL) {
+ if (header_tmp == NULL) {
+ header_tmp = (char *)malloc(strlen(conf.bbs_name) * 2 + 61);
+ if (header_tmp == NULL) {
return MHD_NO;
}
- sprintf(header, "\n\n%s\n\n\n%s
", conf.bbs_name, conf.bbs_name);
+ sprintf(header_tmp, "\n\n%s\n\n\n%s
", conf.bbs_name, conf.bbs_name);
}
+ header = str_replace(header_tmp, "@@WWW_URL@@", conf.www_url);
+ free(header_tmp);
+
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) {
+ footer_tmp = (char *)malloc(s.st_size + 1);
+ if (footer_tmp == NULL) {
free(header);
return MHD_NO;
}
- memset(footer, 0, s.st_size + 1);
+ memset(footer_tmp, 0, s.st_size + 1);
fptr = fopen(buffer, "r");
if (fptr) {
- fread(footer, s.st_size, 1, fptr);
+ fread(footer_tmp, s.st_size, 1, fptr);
fclose(fptr);
} else {
- free(footer);
- footer = NULL;
+ free(footer_tmp);
+ footer_tmp = NULL;
}
}
- if (footer == NULL) {
- footer = (char *)malloc(43);
- if (footer == NULL) {
+ if (footer_tmp == NULL) {
+ footer_tmp = (char *)malloc(43);
+ if (footer_tmp == NULL) {
free(header);
return MHD_NO;
}
- sprintf(footer, "
Powered by Magicka BBS");
+ sprintf(footer_tmp, "
Powered by Magicka BBS");
}
-
+
+ footer = str_replace(footer_tmp, "@@WWW_URL@@", conf.www_url);
+ free(footer_tmp);
+
if (strcmp(method, "GET") == 0) {
if (strcasecmp(url, "/") == 0) {
snprintf(buffer, 4096, "%s/index.tpl", conf.www_path);
- page = NULL;
+ page_tmp = NULL;
if (stat(buffer, &s) == 0) {
- page = (char *)malloc(s.st_size + 1);
- if (page == NULL) {
+ page_tmp = (char *)malloc(s.st_size + 1);
+ if (page_tmp == NULL) {
free(header);
free(footer);
return MHD_NO;
}
- memset(page, 0, s.st_size + 1);
+ memset(page_tmp, 0, s.st_size + 1);
fptr = fopen(buffer, "r");
if (fptr) {
- fread(page, s.st_size, 1, fptr);
+ fread(page_tmp, s.st_size, 1, fptr);
fclose(fptr);
} else {
- free(page);
- page = NULL;
+ free(page_tmp);
+ page_tmp = NULL;
}
}
- if (page == NULL) {
- page = (char *)malloc(16);
- if (page == NULL) {
+ if (page_tmp == NULL) {
+ page_tmp = (char *)malloc(16);
+ if (page_tmp == NULL) {
free(header);
free(footer);
return MHD_NO;
}
- sprintf(page, "Missing Content");
+ sprintf(page_tmp, "Missing Content");
}
-
+
+ page = str_replace(page_tmp, "@@WWW_URL@@", conf.www_url);
+ free(page_tmp);
+
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
sprintf(whole_page, "%s%s%s", header, page, footer);
@@ -756,7 +781,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
MHD_destroy_response (response);
free(header);
free(footer);
- return MHD_YES;
+ return ret;
} else {
if (www_403(header, footer, connection) != 0) {
free(header);
@@ -864,7 +889,8 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
to = NULL;
body = NULL;
replyid = NULL;
-
+ conference = -1;
+ area = -1;
for (i=0;icount;i++) {
if (strcmp(con_inf->keys[i], "recipient") == 0) {
@@ -881,8 +907,9 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
replyid = con_inf->values[i];
}
}
+
if (!www_send_msg(con_inf->user, to, subj, conference, area, replyid, body)) {
- page = (char *)malloc(50);
+ page = (char *)malloc(31);
if (page == NULL) {
free(header);
free(footer);
@@ -890,7 +917,7 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
}
sprintf(page, "Error Sending Message
");
} else {
- page = (char *)malloc(21);
+ page = (char *)malloc(23);
if (page == NULL) {
free(header);
free(footer);
diff --git a/src/www_email.c b/src/www_email.c
index 6addda8..e0ba8d1 100644
--- a/src/www_email.c
+++ b/src/www_email.c
@@ -80,10 +80,16 @@ int www_send_email(struct user_record *user, char *recipient, char *subject, cha
int i;
int pos;
+ if (recipient == NULL || subject == NULL || ibody == NULL) {
+ return 0;
+ }
+
if (check_user(recipient)) {
return 0;
}
+
+
uname(&name);
snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, conf.default_tagline);
@@ -159,7 +165,7 @@ char *www_new_email() {
strcat(page, buffer);
len += strlen(buffer);
- sprintf(buffer, "