Add a system blog
This commit is contained in:
parent
371aa84ea0
commit
396f5c2bb9
@ -39,6 +39,31 @@ LINE: 5 MODIFIED
|
||||
OLDSTRING: "\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%02d:%02d %02d-%02d-%02d\e[0m\r\n"
|
||||
NEWSTRING: "\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%02d:%02d %02d-%02d-%02d \e[1;33m%c\e[0m\r\n"
|
||||
|
||||
LINE: 281 NEW
|
||||
OLDSTRING: (NONE)
|
||||
NEWSTRING: "\e[1;33mSystem Blog\e[0m\r\n"
|
||||
|
||||
LINE: 282 NEW
|
||||
OLDSTRING: (NONE)
|
||||
NEWSTRING: "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"
|
||||
|
||||
LINE: 283 NEW
|
||||
OLDSTRING: (NONE)
|
||||
NEWSTRING: "\e[0mNo Entries...\r\n"
|
||||
|
||||
LINE: 284 NEW
|
||||
OLDSTRING: (NONE)
|
||||
NEWSTRING: "\e[1;37m%s (by \e[1;36m%s\e[1;37m)\r\n"
|
||||
|
||||
LINE: 285 NEW
|
||||
OLDSTRING: (NONE)
|
||||
NEWSTRING: "\e[1;35m%d:%02d%s %s, %s %d %d\r\n"
|
||||
|
||||
LINE: 286 NEW
|
||||
OLDSTRING: (NONE)
|
||||
NEWSTRING: "\r\n\r\n\e[1;37mEnter a title:\e[0m "
|
||||
|
||||
|
||||
Changes from v0.8-alpha -> v0.9-alpha
|
||||
--------------------------------------------------------------
|
||||
LINE: 255 NEW
|
||||
|
BIN
dist/ansis/bulletin1.ans
vendored
BIN
dist/ansis/bulletin1.ans
vendored
Binary file not shown.
6
dist/magicka.strings
vendored
6
dist/magicka.strings
vendored
@ -278,3 +278,9 @@ File exists!\r\n
|
||||
\e[1;32mConference: \e[1;37m%d. %s\e[0m\r\n
|
||||
\e[1;32m Area: \e[1;37m%d. %s \e[1;33m(%d New Messages)\e[0m\r\n\r\n
|
||||
Read Now ? (Y / N):
|
||||
\e[1;33mSystem Blog\e[0m\r\n
|
||||
\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n
|
||||
\e[0mNo Entries...\r\n
|
||||
\e[1;37m%s (by \e[1;36m%s\e[1;37m)\r\n
|
||||
\e[1;35m%d:%02d%s %s, %s %d %d\r\n
|
||||
\r\n\r\n\e[1;37mEnter a title:\e[0m
|
||||
|
3
dist/scripts/login_stanza.lua
vendored
3
dist/scripts/login_stanza.lua
vendored
@ -30,6 +30,9 @@ while(true) do
|
||||
i = i + 1;
|
||||
end
|
||||
|
||||
-- Display Blog
|
||||
bbs_display_blog();
|
||||
|
||||
-- Display Info
|
||||
local bbsname;
|
||||
local sysopname;
|
||||
|
3
dist/www-bootstrap/header.tpl
vendored
3
dist/www-bootstrap/header.tpl
vendored
@ -65,6 +65,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="@@WWW_URL@@">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="@@WWW_URL@@blog/">News</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="@@WWW_URL@@last10/">Last 10 Callers</a>
|
||||
</li>
|
||||
|
18
dist/www-bootstrap/static/style-mobile.css
vendored
18
dist/www-bootstrap/static/style-mobile.css
vendored
@ -354,6 +354,24 @@
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.blog-header {
|
||||
border: 1px solid #666666;
|
||||
background-color: #eee;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.blog-date {
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
.blog-author {
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
.blog-entry {
|
||||
padding: 25px;
|
||||
}
|
||||
|
||||
#msgbody {
|
||||
background-color: black;
|
||||
color: gray;
|
||||
|
19
dist/www-bootstrap/static/style.css
vendored
19
dist/www-bootstrap/static/style.css
vendored
@ -288,6 +288,25 @@
|
||||
background-color: #111111;
|
||||
}
|
||||
|
||||
.blog-header {
|
||||
border: 1px solid #666666;
|
||||
background-color: #eee;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.blog-date {
|
||||
float: right;
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
.blog-author {
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
.blog-entry {
|
||||
padding: 25px;
|
||||
}
|
||||
|
||||
.last10-row {
|
||||
background-color: #eee;
|
||||
display: -webkit-box;
|
||||
|
@ -131,3 +131,7 @@ Finally, an optional SECLEVEL command indicates the required security level for
|
||||
**NLBROWSER** Browse the nodelist for the current conference.
|
||||
|
||||
**SENDFEEDBACK** Send feedback to the Sysop.
|
||||
|
||||
**BLOGDISPLAY** Display the System Blog.
|
||||
|
||||
**BLOGWRITE** Add an entry to the System Blog.
|
@ -113,3 +113,5 @@ Where data is the name of the lua script to call without the extension.
|
||||
**bbs_data_path** Returns a path for script data storage. This is shared with all scripts, so make sure your filenames are unique.
|
||||
|
||||
**bbs_user_security** Returns the current user's security level.
|
||||
|
||||
**bbs_display_blog** Display the System Blog.
|
||||
|
5
seabattle.sh
Executable file
5
seabattle.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd /home/andrew/Projects/seabattle
|
||||
./SeaBattle -D /home/andrew/MagickaBBS/node$1/dorinfo1.def
|
||||
|
@ -29,7 +29,7 @@ $(CDK):
|
||||
cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses
|
||||
cd ../deps/cdk-5.0-20161210/ && $(MAKE)
|
||||
|
||||
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 bluewave.o hashmap/hashmap.o menus.o nodelist.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 bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
|
@ -34,7 +34,7 @@ $(CDK):
|
||||
cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses
|
||||
cd ../deps/cdk-5.0-20161210/ && $(MAKE)
|
||||
|
||||
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o 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 bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o nodelist.o
|
||||
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o 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 bluewave.o www.o www_email.o www_msgs.o www_last10.o www_blog.o www_files.o hashmap/hashmap.o menus.o nodelist.o blog.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
|
@ -30,7 +30,7 @@ $(CDK):
|
||||
cd ../deps/cdk-5.0-20161210/ && $(MAKE)
|
||||
|
||||
|
||||
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 bluewave.o hashmap/hashmap.o menus.o nodelist.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 bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
|
@ -34,7 +34,7 @@ $(CDK):
|
||||
cd ../deps/cdk-5.0-20161210/ && ./configure
|
||||
cd ../deps/cdk-5.0-20161210/ && $(MAKE)
|
||||
|
||||
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o 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 www_email.o www_msgs.o www_last10.o www_files.o bluewave.o hashmap/hashmap.o menus.o nodelist.o
|
||||
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o 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 www_email.o www_msgs.o www_last10.o www_blog.o www_files.o bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
|
@ -29,7 +29,7 @@ $(CDK):
|
||||
cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses
|
||||
cd ../deps/cdk-5.0-20161210/ && $(MAKE)
|
||||
|
||||
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 bluewave.o hashmap/hashmap.o menus.o nodelist.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 bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
|
@ -34,7 +34,7 @@ $(CDK):
|
||||
cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/pkg/include && ./configure --with-ncurses
|
||||
cd ../deps/cdk-5.0-20161210/ && $(MAKE)
|
||||
|
||||
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o 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 bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o nodelist.o
|
||||
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o 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 bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o www_blog.o hashmap/hashmap.o menus.o nodelist.o blog.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
|
@ -29,7 +29,7 @@ $(CDK):
|
||||
cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses
|
||||
cd ../deps/cdk-5.0-20161210/ && $(MAKE)
|
||||
|
||||
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 bluewave.o hashmap/hashmap.o menus.o nodelist.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 bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
|
@ -34,7 +34,7 @@ $(CDK):
|
||||
cd ../deps/cdk-5.0-20161210/ && export CPPFLAGS=-I/usr/local/include && ./configure --with-ncurses
|
||||
cd ../deps/cdk-5.0-20161210/ && $(MAKE)
|
||||
|
||||
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o 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 bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o hashmap/hashmap.o menus.o nodelist.o
|
||||
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o 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 bluewave.o www.o www_email.o www_msgs.o www_last10.o www_files.o www_blog.o hashmap/hashmap.o menus.o nodelist.o blog.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
|
@ -8,7 +8,7 @@ ODOORS = ../deps/odoors/libs-`uname -s`/libODoors.a
|
||||
JSMN = ../deps/jsmn/libjsmn.a
|
||||
CDK = ../deps/cdk-5-20161210/libcdk.a
|
||||
|
||||
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 bluewave.o hashmap/hashmap.o menus.o nodelist.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 bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o
|
||||
|
||||
all: magicka magimail magiedit ticproc mgpost magichat fileapprove magiftpd reset_pass
|
||||
|
||||
|
@ -34,7 +34,7 @@ $(CDK):
|
||||
cd ../deps/cdk-5.0-20161210/ && ./configure
|
||||
cd ../deps/cdk-5.0-20161210/ && $(MAKE)
|
||||
|
||||
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o 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 www_email.o www_msgs.o www_last10.o www_files.o bluewave.o hashmap/hashmap.o menus.o nodelist.o
|
||||
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o 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 www_email.o www_msgs.o www_last10.o www_files.o www_blog.o bluewave.o hashmap/hashmap.o menus.o nodelist.o blog.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
|
@ -30,7 +30,7 @@ $(CDK):
|
||||
cd ../deps/cdk-5.0-20161210/ && $(MAKE)
|
||||
|
||||
|
||||
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 bluewave.o hashmap/hashmap.o menus.o os/sunos.o nodelist.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 bluewave.o hashmap/hashmap.o menus.o os/sunos.o nodelist.o blog.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
|
@ -34,7 +34,7 @@ $(CDK):
|
||||
cd ../deps/cdk-5.0-20161210/ && ./configure
|
||||
cd ../deps/cdk-5.0-20161210/ && $(MAKE)
|
||||
|
||||
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o 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 www_email.o www_msgs.o www_last10.o bluewave.o www_files.o hashmap/hashmap.o menus.o os/sunos.o nodelist.o
|
||||
OBJ = ../deps/aha/aha.o ../deps/hashids/hashids.o 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 www_email.o www_msgs.o www_last10.o bluewave.o www_files.o www_blog.o hashmap/hashmap.o menus.o os/sunos.o nodelist.o blog.o
|
||||
%.o: %.c $(DEPS)
|
||||
$(CC) -c -o $@ $< $(CFLAGS)
|
||||
|
||||
|
@ -1108,8 +1108,8 @@ tryagain:
|
||||
// bulletins
|
||||
display_bulletins();
|
||||
|
||||
// external login cmd
|
||||
|
||||
blog_display();
|
||||
|
||||
// display info
|
||||
display_info();
|
||||
|
||||
|
13
src/bbs.h
13
src/bbs.h
@ -243,6 +243,13 @@ struct msg_headers {
|
||||
int msg_count;
|
||||
};
|
||||
|
||||
struct blog_entry_t {
|
||||
char *subject;
|
||||
char *author;
|
||||
char *body;
|
||||
time_t date;
|
||||
};
|
||||
|
||||
extern char *str_replace(const char *orig, const char *rep, const char *with);
|
||||
extern int copy_file(char *src, char *dest);
|
||||
extern int recursive_delete(const char *dir);
|
||||
@ -377,9 +384,15 @@ extern char *www_sanitize(char *inp);
|
||||
extern char *www_files_display_listing(int dir, int sub);
|
||||
extern char *www_files_areas();
|
||||
extern char *www_files_get_from_area(int dir, int sub, char *file);
|
||||
extern char *www_blog();
|
||||
#endif
|
||||
extern int menu_system(char *menufile);
|
||||
|
||||
extern char *nl_get_bbsname(struct fido_addr *addr, char *domain);
|
||||
extern void nl_browser();
|
||||
|
||||
extern void blog_display();
|
||||
extern void blog_write();
|
||||
extern int blog_load(struct blog_entry_t ***entries);
|
||||
|
||||
#endif
|
||||
|
247
src/blog.c
Normal file
247
src/blog.c
Normal file
@ -0,0 +1,247 @@
|
||||
#include <sqlite3.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include "bbs.h"
|
||||
|
||||
extern struct bbs_config conf;
|
||||
extern struct user_record *gUser;
|
||||
|
||||
int blog_load(struct blog_entry_t ***entries) {
|
||||
int blog_entry_count = 0;
|
||||
struct blog_entry_t **blog_entries;
|
||||
char *sql = "SELECT author, title, body, date FROM blog ORDER BY date DESC";
|
||||
|
||||
char buffer[PATH_MAX];
|
||||
int rc;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
|
||||
snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path);
|
||||
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
*entries = NULL;
|
||||
return 0;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
*entries = NULL;
|
||||
return 0;
|
||||
}
|
||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||
if (blog_entry_count == 0) {
|
||||
blog_entries = (struct blog_entry_t **)malloc(sizeof(struct blog_entry_t *));
|
||||
} else {
|
||||
blog_entries = (struct blog_entry_t **)realloc(blog_entries, sizeof(struct blog_entry_t *) * (blog_entry_count + 1));
|
||||
}
|
||||
blog_entries[blog_entry_count] = (struct blog_entry_t *)malloc(sizeof(struct blog_entry_t));
|
||||
|
||||
blog_entries[blog_entry_count]->author = strdup(sqlite3_column_text(res, 0));
|
||||
blog_entries[blog_entry_count]->subject = strdup(sqlite3_column_text(res, 1));
|
||||
blog_entries[blog_entry_count]->body = strdup(sqlite3_column_text(res, 2));
|
||||
blog_entries[blog_entry_count]->date = sqlite3_column_int(res, 3);
|
||||
blog_entry_count++;
|
||||
}
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
|
||||
*entries = blog_entries;
|
||||
return blog_entry_count;
|
||||
}
|
||||
|
||||
void blog_display() {
|
||||
|
||||
struct blog_entry_t **blog_entries;
|
||||
int blog_entry_count = 0;
|
||||
|
||||
int i;
|
||||
struct tm thetime;
|
||||
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
|
||||
char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
|
||||
char c;
|
||||
|
||||
int j;
|
||||
int lines = 2;
|
||||
s_printf("\e[2J\e[1;1H");
|
||||
s_printf(get_string(280));
|
||||
s_printf(get_string(281));
|
||||
|
||||
blog_entry_count = blog_load(&blog_entries);
|
||||
if (blog_entry_count == 0) {
|
||||
s_printf(get_string(282));
|
||||
s_printf(get_string(6));
|
||||
s_getchar();
|
||||
return;
|
||||
}
|
||||
|
||||
c = 'y';
|
||||
|
||||
for (i=0;i<blog_entry_count;i++) {
|
||||
localtime_r(&blog_entries[i]->date, &thetime);
|
||||
|
||||
s_printf(get_string(283), blog_entries[i]->subject, blog_entries[i]->author);
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
|
||||
s_printf(get_string(284), (thetime.tm_hour - 12 == 0 ? 12 : thetime.tm_hour - 12), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900);
|
||||
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
|
||||
s_printf("\r\n\e[0m");
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
for (j=0; j<strlen(blog_entries[i]->body); j++) {
|
||||
if (blog_entries[i]->body[j] == '\r') {
|
||||
s_printf("\r\n");
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
} else {
|
||||
s_printf("%c", blog_entries[i]->body[j]);
|
||||
}
|
||||
}
|
||||
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n");
|
||||
lines++;
|
||||
if (lines == 22 && tolower(c) != 'c') {
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(223));
|
||||
c = s_getchar();
|
||||
if (tolower(c) == 'n') {
|
||||
break;
|
||||
}
|
||||
s_printf("\r\n\r\n");
|
||||
lines = 0;
|
||||
}
|
||||
}
|
||||
for (i=0;i<blog_entry_count;i++) {
|
||||
free(blog_entries[i]->subject);
|
||||
free(blog_entries[i]->author);
|
||||
free(blog_entries[i]->body);
|
||||
free(blog_entries[i]);
|
||||
}
|
||||
|
||||
free(blog_entries);
|
||||
|
||||
s_printf(get_string(6));
|
||||
s_getchar();
|
||||
|
||||
}
|
||||
|
||||
void blog_write() {
|
||||
char *csql = "CREATE TABLE IF NOT EXISTS blog ("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"author TEXT COLLATE NOCASE,"
|
||||
"title TEXT,"
|
||||
"body TEXT,"
|
||||
"date INTEGER);";
|
||||
|
||||
char *isql = "INSERT INTO blog (author, title, body, date) VALUES(?, ?, ?, ?)";
|
||||
int rc;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
char *blog_entry;
|
||||
char buffer[PATH_MAX];
|
||||
char *blog_subject;
|
||||
char *err_msg = 0;
|
||||
|
||||
s_printf(get_string(285));
|
||||
s_readstring(buffer, 64);
|
||||
s_printf("\r\n");
|
||||
|
||||
blog_subject = strdup(buffer);
|
||||
|
||||
blog_entry = external_editor(gUser, "No-One", "No-One", NULL, 0, "No-One", "Blog Editor", 0, 1);
|
||||
|
||||
if (blog_entry != NULL) {
|
||||
snprintf(buffer, PATH_MAX, "%s/blog.sq3", conf.bbs_path);
|
||||
rc = sqlite3_open(buffer, &db);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||
free(blog_entry);
|
||||
free(blog_subject);
|
||||
return;
|
||||
}
|
||||
sqlite3_busy_timeout(db, 5000);
|
||||
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
|
||||
if (rc != SQLITE_OK ) {
|
||||
dolog("SQL error: %s", err_msg);
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
free(blog_entry);
|
||||
free(blog_subject);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = sqlite3_prepare_v2(db, isql, -1, &res, 0);
|
||||
|
||||
if (rc == SQLITE_OK) {
|
||||
sqlite3_bind_text(res, 1, gUser->loginname, -1, 0);
|
||||
sqlite3_bind_text(res, 2, blog_subject, -1, 0);
|
||||
sqlite3_bind_text(res, 3, blog_entry, -1, 0);
|
||||
sqlite3_bind_int(res, 4, time(NULL));
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
free(blog_entry);
|
||||
free(blog_subject);
|
||||
return;
|
||||
}
|
||||
sqlite3_step(res);
|
||||
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
free(blog_entry);
|
||||
free(blog_subject);
|
||||
return;
|
||||
}
|
||||
free(blog_subject);
|
||||
}
|
@ -21,6 +21,12 @@ int l_bbsWString(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_displayBlog(lua_State *L) {
|
||||
blog_display();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_bbsRString(lua_State *L) {
|
||||
char buffer[256];
|
||||
int len = lua_tonumber(L, -1);
|
||||
@ -615,7 +621,9 @@ void lua_push_cfunctions(lua_State *L) {
|
||||
lua_pushcfunction(L, l_userSecurity);
|
||||
lua_setglobal(L, "bbs_user_security");
|
||||
lua_pushcfunction(L, l_bbsPersonalMailScan);
|
||||
lua_setglobal(L, "bbs_personal_mail_scan");
|
||||
lua_setglobal(L, "bbs_personal_mail_scan");
|
||||
lua_pushcfunction(L, l_displayBlog);
|
||||
lua_setglobal(L, "bbs_display_blog");
|
||||
}
|
||||
|
||||
void do_lua_script(char *script) {
|
||||
|
12
src/menus.c
12
src/menus.c
@ -57,6 +57,8 @@
|
||||
#define MENU_GENWWWURLS 47
|
||||
#define MENU_NLBROWSER 48
|
||||
#define MENU_SENDFEEDBACK 49
|
||||
#define MENU_BLOGDISPLAY 50
|
||||
#define MENU_BLOGWRITE 51
|
||||
|
||||
extern struct bbs_config conf;
|
||||
extern struct user_record *gUser;
|
||||
@ -225,6 +227,10 @@ int menu_system(char *menufile) {
|
||||
menu[menu_items-1]->command = MENU_NLBROWSER;
|
||||
} else if (strncasecmp(&buffer[8], "SENDFEEDBACK", 12) == 0) {
|
||||
menu[menu_items-1]->command = MENU_SENDFEEDBACK;
|
||||
} else if (strncasecmp(&buffer[8], "BLOGDISPLAY", 11) == 0) {
|
||||
menu[menu_items-1]->command = MENU_BLOGDISPLAY;
|
||||
} else if (strncasecmp(&buffer[8], "BLOGWRITE", 9) == 0) {
|
||||
menu[menu_items-1]->command = MENU_BLOGWRITE;
|
||||
}
|
||||
} else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) {
|
||||
menu[menu_items-1]->seclevel = atoi(&buffer[9]);
|
||||
@ -586,6 +592,12 @@ int menu_system(char *menufile) {
|
||||
free(msg);
|
||||
}
|
||||
break;
|
||||
case MENU_BLOGDISPLAY:
|
||||
blog_display();
|
||||
break;
|
||||
case MENU_BLOGWRITE:
|
||||
blog_write();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
10
src/www.c
10
src/www.c
@ -576,6 +576,16 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
||||
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
|
||||
|
||||
sprintf(whole_page, "%s%s%s", header, page, footer);
|
||||
} else if (strcasecmp(url, "/blog") == 0 || strcasecmp(url, "/blog/") == 0) {
|
||||
page = www_blog();
|
||||
if (page == NULL) {
|
||||
free(header);
|
||||
free(footer);
|
||||
return MHD_NO;
|
||||
}
|
||||
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
|
||||
|
||||
sprintf(whole_page, "%s%s%s", header, page, footer);
|
||||
} else if (strcasecmp(url, "/email/") == 0 || strcasecmp(url, "/email") == 0) {
|
||||
con_inf->user = www_auth_ok(connection, url_);
|
||||
|
||||
|
98
src/www_blog.c
Normal file
98
src/www_blog.c
Normal file
@ -0,0 +1,98 @@
|
||||
#if defined(ENABLE_WWW)
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include "bbs.h"
|
||||
|
||||
|
||||
extern struct bbs_config conf;
|
||||
|
||||
char *www_blog() {
|
||||
char *page;
|
||||
int max_len;
|
||||
int len;
|
||||
char buffer[4096];
|
||||
|
||||
struct blog_entry_t **blog_entries;
|
||||
int blog_entry_count = 0;
|
||||
int i, j;
|
||||
struct tm thetime;
|
||||
|
||||
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???"};
|
||||
char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"};
|
||||
|
||||
page = (char *)malloc(4096);
|
||||
max_len = 4096;
|
||||
len = 0;
|
||||
memset(page, 0, 4096);
|
||||
|
||||
sprintf(buffer, "<div class=\"content-header\"><h2>System Blog</h2></div>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
blog_entry_count = blog_load(&blog_entries);
|
||||
|
||||
if (blog_entry_count == 0) {
|
||||
sprintf(buffer, "<p>No Entries</p>\n");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
} else {
|
||||
for (i=0;i<blog_entry_count;i++) {
|
||||
localtime_r(&blog_entries[i]->date, &thetime);
|
||||
sprintf(buffer, "<div class=\"blog-header\"><div class=\"blog-title\"><h3>%s</h3></div><div class=\"blog-date\">%d:%02d%s %s, %s %d %d</div><div class=\"blog-author\">by %s</div></div>", blog_entries[i]->subject,(thetime.tm_hour - 12 == 0 ? 12 : thetime.tm_hour - 12), thetime.tm_min, (thetime.tm_hour >= 12 ? "pm" : "am"), days[thetime.tm_wday], months[thetime.tm_mon], thetime.tm_mday, thetime.tm_year + 1900, blog_entries[i]->author);
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
sprintf(buffer, "<div class=\"blog-entry\">");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
|
||||
for (j=0;j<strlen(blog_entries[i]->body);j++) {
|
||||
if (blog_entries[i]->body[j] == '\r') {
|
||||
sprintf(buffer, "<br />");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
} else {
|
||||
if (len + 1 > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
page[len++] = blog_entries[i]->body[j];
|
||||
page[len] = '\0';
|
||||
}
|
||||
}
|
||||
sprintf(buffer, "</div>");
|
||||
if (len + strlen(buffer) > max_len - 1) {
|
||||
max_len += 4096;
|
||||
page = (char *)realloc(page, max_len);
|
||||
}
|
||||
strcat(page, buffer);
|
||||
len += strlen(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user