Major refactoring

This commit is contained in:
Andrew Pamment 2016-08-06 14:36:36 +10:00
parent c51fe6943b
commit 1370a10fed
13 changed files with 694 additions and 751 deletions

Binary file not shown.

218
bbs.c
View File

@ -117,8 +117,8 @@ void timer_handler(int signum) {
gUser->timeleft--; gUser->timeleft--;
if (gUser->timeleft <= 0) { if (gUser->timeleft <= 0) {
s_putstring(gSocket, "\r\n\r\nSorry, you're out of time today..\r\n"); s_printf("\r\n\r\nSorry, you're out of time today..\r\n");
disconnect(gSocket, "Out of Time"); disconnect("Out of Time");
} }
@ -127,21 +127,32 @@ void timer_handler(int signum) {
usertimeout--; usertimeout--;
} }
if (usertimeout <= 0) { if (usertimeout <= 0) {
s_putstring(gSocket, "\r\n\r\nTimeout waiting for input..\r\n"); s_printf("\r\n\r\nTimeout waiting for input..\r\n");
disconnect(gSocket, "Timeout"); disconnect("Timeout");
} }
} }
} }
void s_putchar(int socket, char c) { void s_printf(char *fmt, ...) {
write(socket, &c, 1); char buffer[512];
va_list ap;
va_start(ap, fmt);
vsnprintf(buffer, 512, fmt, ap);
va_end(ap);
s_putstring(buffer);
} }
void s_putstring(int socket, char *c) { void s_putchar(char c) {
write(socket, c, strlen(c)); write(gSocket, &c, 1);
} }
void s_displayansi_p(int socket, char *file) { void s_putstring(char *c) {
write(gSocket, c, strlen(c));
}
void s_displayansi_p(char *file) {
FILE *fptr; FILE *fptr;
char c; char c;
@ -151,14 +162,14 @@ void s_displayansi_p(int socket, char *file) {
} }
c = fgetc(fptr); c = fgetc(fptr);
while (!feof(fptr) && c != 0x1a) { while (!feof(fptr) && c != 0x1a) {
s_putchar(socket, c); s_putchar(c);
c = fgetc(fptr); c = fgetc(fptr);
} }
fclose(fptr); fclose(fptr);
} }
void s_displayansi(int socket, char *file) { void s_displayansi(char *file) {
FILE *fptr; FILE *fptr;
char c; char c;
@ -172,39 +183,39 @@ void s_displayansi(int socket, char *file) {
} }
c = fgetc(fptr); c = fgetc(fptr);
while (!feof(fptr) && c != 0x1a) { while (!feof(fptr) && c != 0x1a) {
s_putchar(socket, c); s_putchar(c);
c = fgetc(fptr); c = fgetc(fptr);
} }
fclose(fptr); fclose(fptr);
} }
char s_getchar(int socket) { char s_getchar() {
unsigned char c; unsigned char c;
int len; int len;
do { do {
len = read(socket, &c, 1); len = read(gSocket, &c, 1);
if (len == 0) { if (len == 0) {
disconnect(socket, "Socket Closed"); disconnect("Socket Closed");
} }
while (c == 255) { while (c == 255) {
len = read(socket, &c, 1); len = read(gSocket, &c, 1);
if (len == 0) { if (len == 0) {
disconnect(socket, "Socket Closed"); disconnect("Socket Closed");
} else if (c == 255) { } else if (c == 255) {
usertimeout = 10; usertimeout = 10;
return c; return c;
} }
len = read(socket, &c, 1); len = read(gSocket, &c, 1);
if (len == 0) { if (len == 0) {
disconnect(socket, "Socket Closed"); disconnect("Socket Closed");
} }
len = read(socket, &c, 1); len = read(gSocket, &c, 1);
if (len == 0) { if (len == 0) {
disconnect(socket, "Socket Closed"); disconnect("Socket Closed");
} }
} }
@ -212,7 +223,7 @@ char s_getchar(int socket) {
if (c == '\r') { if (c == '\r') {
if (len == 0) { if (len == 0) {
disconnect(socket, "Socket Closed"); disconnect("Socket Closed");
} }
} }
} while (c == '\n'); } while (c == '\n');
@ -220,25 +231,25 @@ char s_getchar(int socket) {
return (char)c; return (char)c;
} }
char s_getc(int socket) { char s_getc() {
char c = s_getchar(socket); char c = s_getchar();
s_putchar(socket, c); s_putchar(c);
return (char)c; return (char)c;
} }
void s_readstring(int socket, char *buffer, int max) { void s_readstring(char *buffer, int max) {
int i; int i;
char c; char c;
memset(buffer, 0, max); memset(buffer, 0, max);
for (i=0;i<max;i++) { for (i=0;i<max;i++) {
c = s_getchar(socket); c = s_getchar();
if ((c == '\b' || c == 127) && i > 0) { if ((c == '\b' || c == 127) && i > 0) {
buffer[i-1] = '\0'; buffer[i-1] = '\0';
i -= 2; i -= 2;
s_putstring(socket, "\e[D \e[D"); s_printf("\e[D \e[D");
continue; continue;
} else if (c == '\b' || c == 127) { } else if (c == '\b' || c == 127) {
i -= 1; i -= 1;
@ -248,23 +259,23 @@ void s_readstring(int socket, char *buffer, int max) {
if (c == '\n' || c == '\r') { if (c == '\n' || c == '\r') {
return; return;
} }
s_putchar(socket, c); s_putchar(c);
buffer[i] = c; buffer[i] = c;
buffer[i+1] = '\0'; buffer[i+1] = '\0';
} }
} }
void s_readpass(int socket, char *buffer, int max) { void s_readpass(char *buffer, int max) {
int i; int i;
char c; char c;
for (i=0;i<max;i++) { for (i=0;i<max;i++) {
c = s_getchar(socket); c = s_getchar();
if ((c == '\b' || c == 127) && i > 0) { if ((c == '\b' || c == 127) && i > 0) {
buffer[i-1] = '\0'; buffer[i-1] = '\0';
i-=2; i-=2;
s_putstring(socket, "\e[D \e[D"); s_printf("\e[D \e[D");
continue; continue;
} else if (c == '\b' || c == 127) { } else if (c == '\b' || c == 127) {
i -= 1; i -= 1;
@ -274,13 +285,13 @@ void s_readpass(int socket, char *buffer, int max) {
if (c == '\n' || c == '\r') { if (c == '\n' || c == '\r') {
return; return;
} }
s_putchar(socket, '*'); s_putchar('*');
buffer[i] = c; buffer[i] = c;
buffer[i+1] = '\0'; buffer[i+1] = '\0';
} }
} }
void disconnect(int socket, char *calledby) { void disconnect(char *calledby) {
char buffer[256]; char buffer[256];
if (gUser != NULL) { if (gUser != NULL) {
save_user(gUser); save_user(gUser);
@ -288,7 +299,7 @@ void disconnect(int socket, char *calledby) {
dolog("Node %d disconnected (%s)", mynode, calledby); dolog("Node %d disconnected (%s)", mynode, calledby);
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(gSocket);
exit(0); exit(0);
} }
@ -332,16 +343,15 @@ void record_last10_callers(struct user_record *user) {
} }
} }
void display_last10_callers(int socket, struct user_record *user) { void display_last10_callers(struct user_record *user) {
struct last10_callers callers[10]; struct last10_callers callers[10];
int i,z,j; int i,z,j;
char buffer[256];
struct tm l10_time; struct tm l10_time;
FILE *fptr = fopen("last10.dat", "rb"); FILE *fptr = fopen("last10.dat", "rb");
s_putstring(socket, "\r\n\e[1;37mLast 10 callers:\r\n"); s_printf("\r\n\e[1;37mLast 10 callers:\r\n");
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\r\n"); s_printf("\e[1;30m-------------------------------------------------------------------------------\r\n");
if (fptr != NULL) { if (fptr != NULL) {
@ -358,53 +368,41 @@ void display_last10_callers(int socket, struct user_record *user) {
for (z=0;z<i;z++) { for (z=0;z<i;z++) {
localtime_r(&callers[z].time, &l10_time); localtime_r(&callers[z].time, &l10_time);
sprintf(buffer, "\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%02d:%02d %02d-%02d-%02d\e[0m\r\n", callers[z].name, callers[z].location, l10_time.tm_hour, l10_time.tm_min, l10_time.tm_mday, l10_time.tm_mon + 1, l10_time.tm_year - 100); s_printf("\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%02d:%02d %02d-%02d-%02d\e[0m\r\n", callers[z].name, callers[z].location, l10_time.tm_hour, l10_time.tm_min, l10_time.tm_mday, l10_time.tm_mon + 1, l10_time.tm_year - 100);
s_putstring(socket, buffer);
} }
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
sprintf(buffer, "Press any key to continue...\r\n"); s_printf("Press any key to continue...\r\n");
s_putstring(socket, buffer); s_getc();
s_getc(socket);
} }
void display_info(int socket) { void display_info() {
char buffer[256];
struct utsname name; struct utsname name;
uname(&name); uname(&name);
sprintf(buffer, "\r\n\r\n\e[1;37mSystem Information\r\n"); s_printf("\r\n\r\n\e[1;37mSystem Information\r\n");
s_putstring(socket, buffer); s_printf("\e[1;30m----------------------------------------------\r\n");
sprintf(buffer, "\e[1;30m----------------------------------------------\r\n"); s_printf("\e[1;32mBBS Name : \e[1;37m%s\r\n", conf.bbs_name);
s_putstring(socket, buffer); s_printf("\e[1;32mSysOp Name : \e[1;37m%s\r\n", conf.sysop_name);
sprintf(buffer, "\e[1;32mBBS Name : \e[1;37m%s\r\n", conf.bbs_name); s_printf("\e[1;32mNode : \e[1;37m%d\r\n", mynode);
s_putstring(socket, buffer); s_printf("\e[1;32mBBS Version : \e[1;37mMagicka %d.%d (%s)\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_STR);
sprintf(buffer, "\e[1;32mSysOp Name : \e[1;37m%s\r\n", conf.sysop_name); s_printf("\e[1;32mSystem : \e[1;37m%s (%s)\r\n", name.sysname, name.machine);
s_putstring(socket, buffer); s_printf("\e[1;30m----------------------------------------------\e[0m\r\n");
sprintf(buffer, "\e[1;32mNode : \e[1;37m%d\r\n", mynode);
s_putstring(socket, buffer);
sprintf(buffer, "\e[1;32mBBS Version : \e[1;37mMagicka %d.%d (%s)\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_STR);
s_putstring(socket, buffer);
sprintf(buffer, "\e[1;32mSystem : \e[1;37m%s (%s)\r\n", name.sysname, name.machine);
s_putstring(socket, buffer);
sprintf(buffer, "\e[1;30m----------------------------------------------\e[0m\r\n");
s_putstring(socket, buffer);
sprintf(buffer, "Press any key to continue...\r\n"); s_printf("Press any key to continue...\r\n");
s_putstring(socket, buffer); s_getc();
s_getc(socket);
} }
void automessage_write(int socket, struct user_record *user) { void automessage_write(struct user_record *user) {
FILE *fptr; FILE *fptr;
char automsg[450]; char automsg[450];
char buffer[90]; char buffer[76];
int i; int i;
struct tm timenow; struct tm timenow;
time_t timen; time_t timen;
memset(automsg, 0, 450); memset(automsg, 0, 450);
memset(buffer, 0, 90); memset(buffer, 0, 76);
if (user->sec_level >= conf.automsgwritelvl) { if (user->sec_level >= conf.automsgwritelvl) {
timen = time(NULL); timen = time(NULL);
@ -414,11 +412,10 @@ void automessage_write(int socket, struct user_record *user) {
automsg[strlen(automsg) - 1] = '\r'; automsg[strlen(automsg) - 1] = '\r';
automsg[strlen(automsg)] = '\n'; automsg[strlen(automsg)] = '\n';
s_putstring(socket, "\r\nEnter your message (4 lines):\r\n"); s_printf("\r\nEnter your message (4 lines):\r\n");
for (i=0;i<4;i++) { for (i=0;i<4;i++) {
sprintf(buffer, "\r\n%d: ", i); s_printf("\r\n%d: ", i);
s_putstring(socket, buffer); s_readstring(buffer, 75);
s_readstring(socket, buffer, 75);
strcat(automsg, buffer); strcat(automsg, buffer);
strcat(automsg, "\r\n"); strcat(automsg, "\r\n");
} }
@ -433,12 +430,12 @@ void automessage_write(int socket, struct user_record *user) {
} }
} }
void automessage_display(int socket) { void automessage_display() {
struct stat s; struct stat s;
FILE *fptr; FILE *fptr;
char buffer[90]; char buffer[90];
int i; int i;
s_putstring(socket, "\r\n\r\n"); s_printf("\r\n\r\n");
if (stat("automessage.txt", &s) == 0) { if (stat("automessage.txt", &s) == 0) {
fptr = fopen("automessage.txt", "r"); fptr = fopen("automessage.txt", "r");
if (fptr) { if (fptr) {
@ -448,17 +445,17 @@ void automessage_display(int socket) {
buffer[strlen(buffer) - 1] = '\r'; buffer[strlen(buffer) - 1] = '\r';
buffer[strlen(buffer)] = '\n'; buffer[strlen(buffer)] = '\n';
s_putstring(socket, buffer); s_printf(buffer);
} }
fclose(fptr); fclose(fptr);
} else { } else {
dolog("Error opening automessage.txt"); dolog("Error opening automessage.txt");
} }
} else { } else {
s_putstring(socket, "No automessage!\r\n"); s_printf("No automessage!\r\n");
} }
s_putstring(socket, "\e[0mPress any key to continue...\r\n"); s_printf("\e[0mPress any key to continue...\r\n");
s_getc(socket); s_getc();
} }
void runbbs(int socket, char *ip) { void runbbs(int socket, char *ip) {
@ -484,10 +481,10 @@ void runbbs(int socket, char *ip) {
write(socket, iac_echo, 3); write(socket, iac_echo, 3);
write(socket, iac_sga, 3); write(socket, iac_sga, 3);
gUser = NULL;
gSocket = socket;
s_printf("Magicka BBS v%d.%d (%s), Loading...\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_STR);
sprintf(buffer, "Magicka BBS v%d.%d (%s), Loading...\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_STR);
s_putstring(socket, buffer);
// find out which node we are // find out which node we are
mynode = 0; mynode = 0;
@ -510,12 +507,11 @@ void runbbs(int socket, char *ip) {
} }
if (mynode == 0) { if (mynode == 0) {
s_putstring(socket, "Sorry, all nodes are in use. Please try later\r\n"); s_printf("Sorry, all nodes are in use. Please try later\r\n");
close(socket); close(socket);
exit(1); exit(1);
} }
gUser = NULL;
gSocket = socket;
usertimeout = 10; usertimeout = 10;
timeoutpaused = 0; timeoutpaused = 0;
@ -531,22 +527,22 @@ void runbbs(int socket, char *ip) {
setitimer (ITIMER_REAL, &itime, 0); setitimer (ITIMER_REAL, &itime, 0);
s_displayansi(socket, "issue"); s_displayansi("issue");
s_putstring(socket, "\e[0mEnter your Login Name or NEW to create an account\r\n"); s_printf("\e[0mEnter your Login Name or NEW to create an account\r\n");
s_putstring(socket, "Login:> "); s_printf("Login:> ");
s_readstring(socket, buffer, 25); s_readstring(buffer, 25);
if (strcasecmp(buffer, "new") == 0) { if (strcasecmp(buffer, "new") == 0) {
user = new_user(socket); user = new_user();
} else { } else {
s_putstring(socket, "\r\nPassword:> "); s_printf("\r\nPassword:> ");
s_readpass(socket, password, 16); s_readpass(password, 16);
user = check_user_pass(socket, buffer, password); user = check_user_pass(buffer, password);
if (user == NULL) { if (user == NULL) {
s_putstring(socket, "\r\nIncorrect Login.\r\n"); s_printf("\r\nIncorrect Login.\r\n");
disconnect(socket, "Incorrect Login"); disconnect("Incorrect Login");
} }
for (i=1;i<=conf.nodes;i++) { for (i=1;i<=conf.nodes;i++) {
@ -555,14 +551,14 @@ void runbbs(int socket, char *ip) {
nodefile = fopen(buffer, "r"); nodefile = fopen(buffer, "r");
if (!nodefile) { if (!nodefile) {
dolog("Error opening nodefile!"); dolog("Error opening nodefile!");
disconnect(socket, "Error opening nodefile!"); disconnect("Error opening nodefile!");
} }
fgets(buffer, 256, nodefile); fgets(buffer, 256, nodefile);
if (strcasecmp(user->loginname, buffer) == 0) { if (strcasecmp(user->loginname, buffer) == 0) {
fclose(nodefile); fclose(nodefile);
s_putstring(socket, "\r\nYou are already logged in.\r\n"); s_printf("\r\nYou are already logged in.\r\n");
disconnect(socket, "Already Logged in"); disconnect("Already Logged in");
} }
fclose(nodefile); fclose(nodefile);
} }
@ -621,10 +617,9 @@ void runbbs(int socket, char *ip) {
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(buffer);
sprintf(buffer, "\e[0mPress any key to continue...\r\n"); s_printf("\e[0mPress any key to continue...\r\n");
s_putstring(socket, buffer); s_getc();
s_getc(socket);
i++; i++;
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
} }
@ -632,28 +627,27 @@ void runbbs(int socket, char *ip) {
// external login cmd // external login cmd
// display info // display info
display_info(socket); display_info();
display_last10_callers(socket, user); display_last10_callers(user);
// check email // check email
i = mail_getemailcount(user); i = mail_getemailcount(user);
if (i > 0) { if (i > 0) {
sprintf(buffer, "\r\nYou have %d e-mail(s) in your inbox.\r\n", i); s_printf("\r\nYou have %d e-mail(s) in your inbox.\r\n", i);
s_putstring(socket, buffer);
} else { } else {
s_putstring(socket, "\r\nYou have no e-mail.\r\n"); s_printf("\r\nYou have no e-mail.\r\n");
} }
mail_scan(socket, user); mail_scan(user);
automessage_display(socket); automessage_display();
} }
record_last10_callers(user); record_last10_callers(user);
// main menu // main menu
main_menu(socket, user); main_menu(user);
s_displayansi(socket, "goodbye"); s_displayansi("goodbye");
dolog("%s is logging out, on node %d", user->loginname, mynode); dolog("%s is logging out, on node %d", user->loginname, mynode);
disconnect(socket, "Log out"); disconnect("Log out");
} }

59
bbs.h
View File

@ -136,52 +136,53 @@ struct user_record {
int timeson; int timeson;
}; };
extern void automessage_write(int socket, struct user_record *user); extern void automessage_write(struct user_record *user);
extern void automessage_display(int socket); extern void automessage_display();
extern void dolog(char *fmt, ...); extern void dolog(char *fmt, ...);
extern void runbbs(int sock, char *ipaddress); extern void runbbs(int sock, char *ipaddress);
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(char c);
extern void s_putstring(int socket, char *c); extern void s_printf(char *fmt, ...);
extern void s_displayansi_p(int socket, char *file); extern void s_putstring(char *c);
extern void s_displayansi(int socket, char *file); extern void s_displayansi_p(char *file);
extern char s_getchar(int socket); extern void s_displayansi(char *file);
extern void s_readpass(int socket, char *buffer, int max); extern char s_getchar();
extern void s_readstring(int socket, char *buffer, int max); extern void s_readpass(char *buffer, int max);
extern char s_getc(int socket); extern void s_readstring(char *buffer, int max);
extern void disconnect(int socket, char *calledby); extern char s_getc();
extern void display_info(int socket); extern void disconnect(char *calledby);
extern void display_last10_callers(int socket, struct user_record *user); extern void display_info();
extern void display_last10_callers(struct user_record *user);
extern void gen_salt(char **s); extern void gen_salt(char **s);
extern char *hash_sha256(char *pass, char *salt); extern char *hash_sha256(char *pass, char *salt);
extern int save_user(struct user_record *user); extern int save_user(struct user_record *user);
extern int check_user(char *loginname); extern int check_user(char *loginname);
extern struct user_record *new_user(int socket); extern struct user_record *new_user();
extern struct user_record *check_user_pass(int socket, char *loginname, char *password); extern struct user_record *check_user_pass(char *loginname, char *password);
extern void list_users(int socket, struct user_record *user); extern void list_users(struct user_record *user);
extern void main_menu(int socket, struct user_record *user); extern void main_menu(struct user_record *user);
extern void mail_scan(int socket, struct user_record *user); extern void mail_scan(struct user_record *user);
extern int mail_menu(int socket, struct user_record *user); extern int mail_menu(struct user_record *user);
extern char *editor(int socket, struct user_record *user, char *quote, char *from, int email); extern char *editor(struct user_record *user, char *quote, char *from, int email);
extern char *external_editor(int socket, struct user_record *user, char *to, char *from, char *quote, char *qfrom, char *subject, int email); extern char *external_editor(struct user_record *user, char *to, char *from, char *quote, char *qfrom, char *subject, int email);
extern int door_menu(int socket, struct user_record *user); extern int door_menu(struct user_record *user);
extern void rundoor(int socket, struct user_record *user, char *cmd, int stdio); extern void rundoor(struct user_record *user, char *cmd, int stdio);
extern void bbs_list(int socket, struct user_record *user); extern void bbs_list(struct user_record *user);
extern void chat_system(int sock, struct user_record *user); extern void chat_system(struct user_record *user);
extern int mail_getemailcount(struct user_record *user); extern int mail_getemailcount(struct user_record *user);
extern void send_email(int socket, struct user_record *user); extern void send_email(struct user_record *user);
extern void list_emails(int socket, struct user_record *user); extern void list_emails(struct user_record *user);
extern int file_menu(int socket, struct user_record *user); extern int file_menu(struct user_record *user);
extern void settings_menu(int sock, struct user_record *user); extern void settings_menu(struct user_record *user);
extern void lua_push_cfunctions(lua_State *L); extern void lua_push_cfunctions(lua_State *L);
#endif #endif

View File

@ -8,7 +8,7 @@
extern struct bbs_config conf; extern struct bbs_config conf;
extern int mynode; extern int mynode;
void add_bbs(int socket, struct user_record *user) { void add_bbs(struct user_record *user) {
char *create_sql = "CREATE TABLE IF NOT EXISTS bbslist (" char *create_sql = "CREATE TABLE IF NOT EXISTS bbslist ("
"id INTEGER PRIMARY KEY," "id INTEGER PRIMARY KEY,"
"bbsname TEXT," "bbsname TEXT,"
@ -28,27 +28,24 @@ void add_bbs(int socket, struct user_record *user) {
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
s_putstring(socket, "\r\n\e[1;37mEnter the BBS Name: \e[0m"); s_printf("\r\n\e[1;37mEnter the BBS Name: \e[0m");
s_readstring(socket, bbsname, 18); s_readstring(bbsname, 18);
s_putstring(socket, "\r\n\e[1;37mEnter the Sysop's Name: \e[0m"); s_printf("\r\n\e[1;37mEnter the Sysop's Name: \e[0m");
s_readstring(socket, sysop, 16); s_readstring(sysop, 16);
s_putstring(socket, "\r\n\e[1;37mEnter the Telnet URL: \e[0m"); s_printf("\r\n\e[1;37mEnter the Telnet URL: \e[0m");
s_readstring(socket, telnet, 38); s_readstring(telnet, 38);
s_putstring(socket, "\r\nYou entered:\r\n"); s_printf("\r\nYou entered:\r\n");
s_putstring(socket, "\e[1;30m----------------------------------------------\e[0m\r\n"); s_printf("\e[1;30m----------------------------------------------\e[0m\r\n");
sprintf(buffer, "\e[1;37mBBS Name: \e[1;32m%s\r\n", bbsname); s_printf("\e[1;37mBBS Name: \e[1;32m%s\r\n", bbsname);
s_putstring(socket, buffer); s_printf("\e[1;37mSysop: \e[1;32m%s\r\n", sysop);
sprintf(buffer, "\e[1;37mSysop: \e[1;32m%s\r\n", sysop); s_printf("\e[1;37mTelnet URL: \e[1;32m%s\r\n", telnet);
s_putstring(socket, buffer); s_printf("\e[1;30m----------------------------------------------\e[0m\r\n");
sprintf(buffer, "\e[1;37mTelnet URL: \e[1;32m%s\r\n", telnet); s_printf("Is this correct? (Y/N) :");
s_putstring(socket, buffer);
s_putstring(socket, "\e[1;30m----------------------------------------------\e[0m\r\n");
s_putstring(socket, "Is this correct? (Y/N) :");
c = s_getc(socket); c = s_getc();
if (tolower(c) == 'y') { if (tolower(c) == 'y') {
sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path); sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path);
@ -96,13 +93,13 @@ void add_bbs(int socket, struct user_record *user) {
} }
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
s_putstring(socket, "\r\n\e[1;32mAdded!\e[0m\r\n"); s_printf("\r\n\e[1;32mAdded!\e[0m\r\n");
} else { } else {
s_putstring(socket, "\r\n\e[1;31mAborted!\e[0m\r\n"); s_printf("\r\n\e[1;31mAborted!\e[0m\r\n");
} }
} }
void delete_bbs(int socket, struct user_record *user) { void delete_bbs(struct user_record *user) {
char buffer[256]; char buffer[256];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
@ -112,8 +109,8 @@ void delete_bbs(int socket, struct user_record *user) {
int i; int i;
char c; char c;
s_putstring(socket, "\r\nPlease enter the id of the BBS you want to delete: "); s_printf("\r\nPlease enter the id of the BBS you want to delete: ");
s_readstring(socket, buffer, 5); s_readstring(buffer, 5);
i = atoi(buffer); i = atoi(buffer);
sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path); sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path);
@ -128,37 +125,36 @@ void delete_bbs(int socket, struct user_record *user) {
sqlite3_bind_int(res, 2, user->id); sqlite3_bind_int(res, 2, user->id);
} else { } else {
sqlite3_close(db); sqlite3_close(db);
s_putstring(socket, "\r\nThere are no BBSes in the list yet!\r\n"); s_printf("\r\nThere are no BBSes in the list yet!\r\n");
return; return;
} }
if (sqlite3_step(res) == SQLITE_ROW) { if (sqlite3_step(res) == SQLITE_ROW) {
sprintf(buffer, "\r\nAre you sure you want to delete %s?\r\n", sqlite3_column_text(res, 0)); s_printf("\r\nAre you sure you want to delete %s?\r\n", sqlite3_column_text(res, 0));
s_putstring(socket, buffer);
sqlite3_finalize(res); sqlite3_finalize(res);
c = s_getc(socket); c = s_getc();
if (tolower(c) == 'y') { if (tolower(c) == 'y') {
rc = sqlite3_prepare_v2(db, dsql, -1, &res, 0); rc = sqlite3_prepare_v2(db, dsql, -1, &res, 0);
if (rc == SQLITE_OK) { if (rc == SQLITE_OK) {
sqlite3_bind_int(res, 1, i); sqlite3_bind_int(res, 1, i);
} else { } else {
sqlite3_close(db); sqlite3_close(db);
s_putstring(socket, "\r\nThere are no BBSes in the list yet!\r\n"); s_printf("\r\nThere are no BBSes in the list yet!\r\n");
return; return;
} }
sqlite3_step(res); sqlite3_step(res);
s_putstring(socket, "\r\n\e[1;32mDeleted!\e[0m\r\n"); s_printf("\r\n\e[1;32mDeleted!\e[0m\r\n");
sqlite3_finalize(res); sqlite3_finalize(res);
} else { } else {
s_putstring(socket, "\r\n\e[1;32mAborted!\e[0m\r\n"); s_printf("\r\n\e[1;32mAborted!\e[0m\r\n");
} }
} else { } else {
sqlite3_finalize(res); sqlite3_finalize(res);
s_putstring(socket, "\r\nThat BBS entry either doesn't exist or wasn't created by you.\r\n"); s_printf("\r\nThat BBS entry either doesn't exist or wasn't created by you.\r\n");
} }
sqlite3_close(db); sqlite3_close(db);
} }
void list_bbses(int socket) { void list_bbses() {
char buffer[256]; char buffer[256];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
@ -177,51 +173,48 @@ void list_bbses(int socket) {
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
sqlite3_close(db); sqlite3_close(db);
s_putstring(socket, "\r\nThere are no BBSes in the list yet!\r\n"); s_printf("\r\nThere are no BBSes in the list yet!\r\n");
return; return;
} }
i = 0; i = 0;
s_putstring(socket, "\r\n\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); s_printf("\r\n\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
while (sqlite3_step(res) == SQLITE_ROW) { while (sqlite3_step(res) == SQLITE_ROW) {
sprintf(buffer, "\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;37m%-18s \e[1;33m%-16s \e[1;32m%-37s\e[0m\r\n", sqlite3_column_int(res, 0), sqlite3_column_text(res, 1), sqlite3_column_text(res, 2), sqlite3_column_text(res, 3)); s_printf("\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;37m%-18s \e[1;33m%-16s \e[1;32m%-37s\e[0m\r\n", sqlite3_column_int(res, 0), sqlite3_column_text(res, 1), sqlite3_column_text(res, 2), sqlite3_column_text(res, 3));
s_putstring(socket, buffer);
i++; i++;
if (i == 20) { if (i == 20) {
sprintf(buffer, "Press any key to continue...\r\n"); s_printf("Press any key to continue...\r\n");
s_putstring(socket, buffer); s_getc();
s_getc(socket);
i = 0; i = 0;
} }
} }
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
sprintf(buffer, "Press any key to continue...\r\n"); s_printf("Press any key to continue...\r\n");
s_putstring(socket, buffer); s_getc();
s_getc(socket);
} }
void bbs_list(int socket, struct user_record *user) { void bbs_list(struct user_record *user) {
int doquit = 0; int doquit = 0;
char c; char c;
while(!doquit) { while(!doquit) {
s_putstring(socket, "\r\n\e[1;32mBBS Listings: \e[1;37m(\e[1;33mL\e[1;37m) \e[1;32mList, \e[1;37m(\e[1;33mA\e[1;37m) \e[1;32mAdd \e[1;37m(\e[1;33mD\e[1;37m) \e[1;32mDelete \e[1;37m(\e[1;33mQ\e[1;37m) \e[1;32mQuit\e[0m\r\n"); s_printf("\r\n\e[1;32mBBS Listings: \e[1;37m(\e[1;33mL\e[1;37m) \e[1;32mList, \e[1;37m(\e[1;33mA\e[1;37m) \e[1;32mAdd \e[1;37m(\e[1;33mD\e[1;37m) \e[1;32mDelete \e[1;37m(\e[1;33mQ\e[1;37m) \e[1;32mQuit\e[0m\r\n");
c = s_getc(socket); c = s_getc();
switch(tolower(c)) { switch(tolower(c)) {
case 'l': case 'l':
list_bbses(socket); list_bbses();
break; break;
case 'a': case 'a':
add_bbs(socket, user); add_bbs(user);
break; break;
case 'd': case 'd':
delete_bbs(socket, user); delete_bbs(user);
break; break;
case 'q': case 'q':
doquit = 1; doquit = 1;

View File

@ -11,6 +11,7 @@
extern struct bbs_config conf; extern struct bbs_config conf;
extern int mynode; extern int mynode;
extern int gSocket;
static char **screenbuffer; static char **screenbuffer;
static int chat_socket; static int chat_socket;
@ -87,7 +88,7 @@ void append_screenbuffer(char *buffer) {
row_at = 0; row_at = 0;
} }
void chat_system(int sock, struct user_record *user) { void chat_system(struct user_record *user) {
struct sockaddr_in servaddr; struct sockaddr_in servaddr;
fd_set fds; fd_set fds;
int t; int t;
@ -117,12 +118,12 @@ void chat_system(int sock, struct user_record *user) {
char *target; char *target;
memset(inputbuffer, 0, 80); memset(inputbuffer, 0, 80);
if (conf.irc_server == NULL) { if (conf.irc_server == NULL) {
s_putstring(sock, "\r\nSorry, Chat is not supported on this system.\r\n"); s_putstring("\r\nSorry, Chat is not supported on this system.\r\n");
return; return;
} }
row_at = 0; row_at = 0;
line_at = 0; line_at = 0;
s_putstring(sock, "\e[2J"); s_putstring("\e[2J");
memset(&servaddr, 0, sizeof(struct sockaddr_in)); memset(&servaddr, 0, sizeof(struct sockaddr_in));
servaddr.sin_family = AF_INET; servaddr.sin_family = AF_INET;
@ -156,23 +157,23 @@ void chat_system(int sock, struct user_record *user) {
while (1) { while (1) {
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(sock, &fds); FD_SET(gSocket, &fds);
FD_SET(chat_socket, &fds); FD_SET(chat_socket, &fds);
if (chat_socket > sock) { if (chat_socket > gSocket) {
t = chat_socket + 1; t = chat_socket + 1;
} else { } else {
t = sock + 1; t = gSocket + 1;
} }
ret = select(t, &fds, NULL, NULL, NULL); ret = select(t, &fds, NULL, NULL, NULL);
if (ret > 0) { if (ret > 0) {
if (FD_ISSET(sock, &fds)) { if (FD_ISSET(gSocket, &fds)) {
len = read(sock, &c, 1); len = read(gSocket, &c, 1);
if (len == 0) { if (len == 0) {
raw("QUIT\r\n"); raw("QUIT\r\n");
disconnect(sock, "Socket closed"); disconnect("Socket closed");
} }
if (c == '\r') { if (c == '\r') {
@ -209,7 +210,7 @@ void chat_system(int sock, struct user_record *user) {
if (FD_ISSET(chat_socket, &fds)) { if (FD_ISSET(chat_socket, &fds)) {
len = read(chat_socket, &c, 1); len = read(chat_socket, &c, 1);
if (len == 0) { if (len == 0) {
s_putstring(sock, "\r\n\r\n\r\nLost connection to chat server!\r\n"); s_putstring("\r\n\r\n\r\nLost connection to chat server!\r\n");
for (i=0;i<22;i++) { for (i=0;i<22;i++) {
free(screenbuffer[i]); free(screenbuffer[i]);
} }
@ -271,22 +272,20 @@ void chat_system(int sock, struct user_record *user) {
} }
} }
if (do_update == 1) { if (do_update == 1) {
s_putstring(sock, "\e[2J"); s_putstring("\e[2J");
for (i=0;i<=line_at;i++) { for (i=0;i<=line_at;i++) {
sprintf(buffer2, "%s\r\n", screenbuffer[i]); s_printf("%s\r\n", screenbuffer[i]);
s_putstring(sock, buffer2);
} }
for (i=line_at+1;i<22;i++) { for (i=line_at+1;i<22;i++) {
s_putstring(sock, "\r\n"); s_putstring("\r\n");
} }
s_putstring(sock, "\e[1;45;37m Type /Quit to Exit\e[K\e[0m\r\n"); s_putstring("\e[1;45;37m Type /Quit to Exit\e[K\e[0m\r\n");
if (inputbuffer_at > 0) { if (inputbuffer_at > 0) {
s_putstring(sock, inputbuffer); s_putstring(inputbuffer);
} }
do_update = 0; do_update = 0;
} else if (do_update == 2) { } else if (do_update == 2) {
sprintf(buffer2, "\e[24;1f%s\e[K", inputbuffer); s_printf("\e[24;1f%s\e[K", inputbuffer);
s_putstring(sock, buffer2);
} }
} }
} }

43
doors.c
View File

@ -22,6 +22,7 @@
extern struct bbs_config conf; extern struct bbs_config conf;
extern int mynode; extern int mynode;
extern int gSocket;
int running_door_pid = 0; int running_door_pid = 0;
int running_door = 0; int running_door = 0;
@ -36,7 +37,7 @@ void doorchld_handler(int s)
running_door = 0; running_door = 0;
} }
int write_door32sys(int socket, struct user_record *user) { int write_door32sys(struct user_record *user) {
struct stat s; struct stat s;
char buffer[256]; char buffer[256];
FILE *fptr; FILE *fptr;
@ -59,7 +60,7 @@ int write_door32sys(int socket, struct user_record *user) {
} }
fprintf(fptr, "2\n"); // telnet type fprintf(fptr, "2\n"); // telnet type
fprintf(fptr, "%d\n", socket); // socket fprintf(fptr, "%d\n", gSocket); // socket
fprintf(fptr, "38400\n"); // baudrate fprintf(fptr, "38400\n"); // baudrate
fprintf(fptr, "Magicka %d.%d\n", VERSION_MAJOR, VERSION_MINOR); fprintf(fptr, "Magicka %d.%d\n", VERSION_MAJOR, VERSION_MINOR);
fprintf(fptr, "%d\n", user->id); fprintf(fptr, "%d\n", user->id);
@ -126,7 +127,7 @@ int write_door32sys(int socket, struct user_record *user) {
return 0; return 0;
} }
void rundoor(int socket, struct user_record *user, char *cmd, int stdio) { void rundoor(struct user_record *user, char *cmd, int stdio) {
char buffer[256]; char buffer[256];
int pid; int pid;
char *arguments[4]; char *arguments[4];
@ -143,7 +144,7 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
timeoutpaused = 1; timeoutpaused = 1;
if (write_door32sys(socket, user) != 0) { if (write_door32sys(user) != 0) {
return; return;
} }
@ -152,7 +153,7 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
arguments[0] = strdup(cmd); arguments[0] = strdup(cmd);
sprintf(buffer, "%d", mynode); sprintf(buffer, "%d", mynode);
arguments[1] = strdup(buffer); arguments[1] = strdup(buffer);
sprintf(buffer, "%d", socket); sprintf(buffer, "%d", gSocket);
arguments[2] = strdup(buffer); arguments[2] = strdup(buffer);
arguments[3] = NULL; arguments[3] = NULL;
@ -192,19 +193,19 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
while(running_door != 0) { while(running_door != 0) {
FD_ZERO(&fdset); FD_ZERO(&fdset);
FD_SET(master, &fdset); FD_SET(master, &fdset);
FD_SET(socket, &fdset); FD_SET(gSocket, &fdset);
if (master > socket) { if (master > gSocket) {
t = master + 1; t = master + 1;
} else { } else {
t = socket + 1; t = gSocket + 1;
} }
ret = select(t, &fdset, NULL, NULL, NULL); ret = select(t, &fdset, NULL, NULL, NULL);
if (ret > 0) { if (ret > 0) {
if (FD_ISSET(socket, &fdset)) { if (FD_ISSET(gSocket, &fdset)) {
len = read(socket, &c, 1); len = read(gSocket, &c, 1);
if (len == 0) { if (len == 0) {
close(master); close(master);
disconnect(socket, "Socket Closed"); disconnect("Socket Closed");
return; return;
} }
if (c == '\n' || c == '\0') { if (c == '\n' || c == '\0') {
@ -217,7 +218,7 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
close(master); close(master);
break; break;
} }
write(socket, &c, 1); write(gSocket, &c, 1);
} }
} }
} }
@ -227,16 +228,15 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
free(arguments[1]); free(arguments[1]);
free(arguments[2]); free(arguments[2]);
} else { } else {
sprintf(buffer, "%s %d %d", cmd, mynode, socket); sprintf(buffer, "%s %d %d", cmd, mynode, gSocket);
system(buffer); system(buffer);
} }
timeoutpaused = 0; timeoutpaused = 0;
} }
int door_menu(int socket, struct user_record *user) { int door_menu(struct user_record *user) {
int doquit = 0; int doquit = 0;
int dodoors = 0; int dodoors = 0;
char prompt[128];
char buffer[256]; char buffer[256];
int i; int i;
char c; char c;
@ -268,12 +268,11 @@ int door_menu(int socket, struct user_record *user) {
while (!dodoors) { while (!dodoors) {
if (do_internal_menu == 1) { if (do_internal_menu == 1) {
s_displayansi(socket, "doors"); s_displayansi("doors");
sprintf(prompt, "\e[0m\r\nTL: %dm :> ", user->timeleft); s_printf("\e[0m\r\nTL: %dm :> ", user->timeleft);
s_putstring(socket, prompt);
c = s_getc(socket); c = s_getc();
} else { } else {
lua_getglobal(L, "menu"); lua_getglobal(L, "menu");
result = lua_pcall(L, 0, 1, 0); result = lua_pcall(L, 0, 1, 0);
@ -293,8 +292,8 @@ int door_menu(int socket, struct user_record *user) {
break; break;
case 'g': case 'g':
{ {
s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)"); s_printf("\r\nAre you sure you want to log off? (Y/N)");
c = s_getc(socket); c = s_getc();
if (tolower(c) == 'y') { if (tolower(c) == 'y') {
doquit = 1; doquit = 1;
dodoors = 1; dodoors = 1;
@ -306,7 +305,7 @@ 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); 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(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); dolog("%s is returned from door %s, on node %d", user->loginname, conf.doors[i]->name, mynode);
break; break;
} }

77
email.c
View File

@ -8,7 +8,7 @@
extern struct bbs_config conf; extern struct bbs_config conf;
void send_email(int socket, struct user_record *user) { void send_email(struct user_record *user) {
char buffer[256]; char buffer[256];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
@ -27,30 +27,30 @@ void send_email(int socket, struct user_record *user) {
char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)"; char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)";
char *err_msg = 0; char *err_msg = 0;
s_putstring(socket, "\r\nTO: "); s_printf("\r\nTO: ");
s_readstring(socket, buffer, 16); s_readstring(buffer, 16);
if (strlen(buffer) == 0) { if (strlen(buffer) == 0) {
s_putstring(socket, "\r\nAborted\r\n"); s_printf("\r\nAborted\r\n");
return; return;
} }
if (check_user(buffer)) { if (check_user(buffer)) {
s_putstring(socket, "\r\n\r\nInvalid Username\r\n"); s_printf("\r\n\r\nInvalid Username\r\n");
return; return;
} }
recipient = strdup(buffer); recipient = strdup(buffer);
s_putstring(socket, "\r\nSUBJECT: "); s_printf("\r\nSUBJECT: ");
s_readstring(socket, buffer, 25); s_readstring(buffer, 25);
if (strlen(buffer) == 0) { if (strlen(buffer) == 0) {
free(recipient); free(recipient);
s_putstring(socket, "\r\nAborted\r\n"); s_printf("\r\nAborted\r\n");
return; return;
} }
subject = strdup(buffer); subject = strdup(buffer);
// post a message // post a message
msg = external_editor(socket, user, user->loginname, recipient, NULL, NULL, subject, 1); msg = external_editor(user, user->loginname, recipient, NULL, NULL, subject, 1);
if (msg != NULL) { if (msg != NULL) {
sprintf(buffer, "%s/email.sq3", conf.bbs_path); sprintf(buffer, "%s/email.sq3", conf.bbs_path);
@ -87,7 +87,7 @@ void send_email(int socket, struct user_record *user) {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
s_putstring(socket, "\r\nNo such email\r\n"); s_printf("\r\nNo such email\r\n");
return; return;
} }
sqlite3_step(res); sqlite3_step(res);
@ -139,7 +139,7 @@ void show_email(int socket, struct user_record *user, int msgno) {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
s_putstring(socket, "\r\nNo such email\r\n"); s_printf("\r\nNo such email\r\n");
return; return;
} }
if (sqlite3_step(res) == SQLITE_ROW) { if (sqlite3_step(res) == SQLITE_ROW) {
@ -150,16 +150,14 @@ void show_email(int socket, struct user_record *user, int msgno) {
date = (time_t)sqlite3_column_int(res, 4); date = (time_t)sqlite3_column_int(res, 4);
sprintf(buffer, "\e[2J\e[1;32mFrom : \e[1;37m%s\r\n", sender); s_printf("\e[2J\e[1;32mFrom : \e[1;37m%s\r\n", sender);
s_putstring(socket, buffer); s_printf("\e[1;32mSubject : \e[1;37m%s\r\n", subject);
sprintf(buffer, "\e[1;32mSubject : \e[1;37m%s\r\n", subject);
s_putstring(socket, buffer);
localtime_r(&date, &msg_date); localtime_r(&date, &msg_date);
sprintf(buffer, "\e[1;32mDate : \e[1;37m%s", asctime(&msg_date)); sprintf(buffer, "\e[1;32mDate : \e[1;37m%s", asctime(&msg_date));
buffer[strlen(buffer) - 1] = '\0'; buffer[strlen(buffer) - 1] = '\0';
strcat(buffer, "\r\n"); strcat(buffer, "\r\n");
s_putstring(socket, buffer); s_printf(buffer);
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
lines = 0; lines = 0;
chars = 0; chars = 0;
@ -167,16 +165,16 @@ void show_email(int socket, struct user_record *user, int msgno) {
for (z=0;z<strlen(body);z++) { for (z=0;z<strlen(body);z++) {
if (body[z] == '\r' || chars == 79) { if (body[z] == '\r' || chars == 79) {
chars = 0; chars = 0;
s_putstring(socket, "\r\n"); s_printf("\r\n");
lines++; lines++;
if (lines == 19) { if (lines == 19) {
s_putstring(socket, "\e[1;37mPress a key to continue...\e[0m"); s_printf("\e[1;37mPress a key to continue...\e[0m");
s_getc(socket); s_getc();
lines = 0; lines = 0;
s_putstring(socket, "\e[5;1H\e[0J"); s_printf("\e[5;1H\e[0J");
} }
} else { } else {
s_putchar(socket, body[z]); s_putchar(body[z]);
chars++; chars++;
} }
} }
@ -195,8 +193,8 @@ void show_email(int socket, struct user_record *user, int msgno) {
} }
sqlite3_step(res); sqlite3_step(res);
s_putstring(socket, "\e[1;37mPress \e[1;36mR\e[1;37m to reply, \e[1;36mD\e[1;37m to delete \e[1;36mEnter\e[1;37m to quit...\e[0m\r\n"); s_printf("\e[1;37mPress \e[1;36mR\e[1;37m to reply, \e[1;36mD\e[1;37m to delete \e[1;36mEnter\e[1;37m to quit...\e[0m\r\n");
c = s_getc(socket); c = s_getc();
if (tolower(c) == 'r') { if (tolower(c) == 'r') {
if (subject != NULL) { if (subject != NULL) {
if (strncasecmp(buffer, "RE:", 3) != 0) { if (strncasecmp(buffer, "RE:", 3) != 0) {
@ -209,8 +207,7 @@ void show_email(int socket, struct user_record *user, int msgno) {
subject = (char *)malloc(strlen(buffer) + 1); subject = (char *)malloc(strlen(buffer) + 1);
strcpy(subject, buffer); strcpy(subject, buffer);
//replybody = editor(socket, user, body, sender); replybody = external_editor(user, user->loginname, sender, body, sender, subject, 1);
replybody = external_editor(socket, user, user->loginname, sender, body, sender, subject, 1);
if (replybody != NULL) { if (replybody != NULL) {
rc = sqlite3_prepare_v2(db, isql, -1, &res, 0); rc = sqlite3_prepare_v2(db, isql, -1, &res, 0);
@ -224,7 +221,7 @@ void show_email(int socket, struct user_record *user, int msgno) {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
s_putstring(socket, "\r\nNo such email\r\n"); s_printf("\r\nNo such email\r\n");
return; return;
} }
sqlite3_step(res); sqlite3_step(res);
@ -249,7 +246,7 @@ void show_email(int socket, struct user_record *user, int msgno) {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
s_putstring(socket, "\r\nNo such email\r\n"); s_printf("\r\nNo such email\r\n");
return; return;
} }
sqlite3_step(res); sqlite3_step(res);
@ -265,7 +262,7 @@ void show_email(int socket, struct user_record *user, int msgno) {
} }
} }
void list_emails(int socket, struct user_record *user) { void list_emails(struct user_record *user) {
char buffer[256]; char buffer[256];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
@ -298,12 +295,12 @@ void list_emails(int socket, struct user_record *user) {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
s_putstring(socket, "\r\nYou have no email\r\n"); s_printf("\r\nYou have no email\r\n");
return; return;
} }
msgid = 0; msgid = 0;
s_putstring(socket, "\e[2J\e[1;37;44m[MSG#] Subject From Date \r\n\e[0m"); s_printf("\e[2J\e[1;37;44m[MSG#] Subject From Date \r\n\e[0m");
while (sqlite3_step(res) == SQLITE_ROW) { while (sqlite3_step(res) == SQLITE_ROW) {
from = strdup((char *)sqlite3_column_text(res, 0)); from = strdup((char *)sqlite3_column_text(res, 0));
subject = strdup((char *)sqlite3_column_text(res, 1)); subject = strdup((char *)sqlite3_column_text(res, 1));
@ -311,18 +308,16 @@ void list_emails(int socket, struct user_record *user) {
date = (time_t)sqlite3_column_int(res, 3); date = (time_t)sqlite3_column_int(res, 3);
localtime_r(&date, &msg_date); localtime_r(&date, &msg_date);
if (seen == 0) { if (seen == 0) {
sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid + 1, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); s_printf("\e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid + 1, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
} else { } else {
sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid + 1, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); s_printf("\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid + 1, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
} }
s_putstring(socket, buffer);
free(from); free(from);
free(subject); free(subject);
if (msgid % 22 == 0 && msgid != 0) { if (msgid % 22 == 0 && msgid != 0) {
s_putstring(socket, "\e[1;37mEnter \e[1;36m# \e[1;37mto read, \e[1;36mQ \e[1;37mto quit or \e[1;36mEnter\e[1;37m to continue\e[0m\r\n"); s_printf("\e[1;37mEnter \e[1;36m# \e[1;37mto read, \e[1;36mQ \e[1;37mto quit or \e[1;36mEnter\e[1;37m to continue\e[0m\r\n");
s_readstring(socket, buffer, 5); s_readstring(buffer, 5);
if (strlen(buffer) > 0) { if (strlen(buffer) > 0) {
if (tolower(buffer[0]) == 'q') { if (tolower(buffer[0]) == 'q') {
sqlite3_finalize(res); sqlite3_finalize(res);
@ -336,15 +331,15 @@ void list_emails(int socket, struct user_record *user) {
return; return;
} }
} }
s_putstring(socket, "\e[2J\e[1;37;44m[MSG#] Subject From Date \r\n\e[0m"); s_printf("\e[2J\e[1;37;44m[MSG#] Subject From Date \r\n\e[0m");
} }
msgid++; msgid++;
} }
if (msgid == 0) { if (msgid == 0) {
s_putstring(socket, "\r\nYou have no email\r\n"); s_printf( "\r\nYou have no email\r\n");
} else { } else {
s_putstring(socket, "\e[1;37mEnter \e[1;36m# \e[1;37mto read, or \e[1;36mEnter\e[1;37m to quit\e[0m\r\n"); s_printf("\e[1;37mEnter \e[1;36m# \e[1;37mto read, or \e[1;36mEnter\e[1;37m to quit\e[0m\r\n");
s_readstring(socket, buffer, 5); s_readstring(buffer, 5);
if (strlen(buffer) > 0) { if (strlen(buffer) > 0) {
msgtoread = atoi(buffer) - 1; msgtoread = atoi(buffer) - 1;
sqlite3_finalize(res); sqlite3_finalize(res);

130
files.c
View File

@ -13,6 +13,7 @@
#include "lua/lualib.h" #include "lua/lualib.h"
#include "lua/lauxlib.h" #include "lua/lauxlib.h"
extern struct bbs_config conf; extern struct bbs_config conf;
extern int gSocket;
static int doCancel = 0; static int doCancel = 0;
@ -127,7 +128,7 @@ int doIO(ZModem *zm) {
} else if (i > 0) { } else if (i > 0) {
len = read(zm->ifd, buffer, 2048); len = read(zm->ifd, buffer, 2048);
if (len == 0) { if (len == 0) {
disconnect(zm->ifd, "Socket closed"); disconnect("Socket closed");
} }
pos = 0; pos = 0;
@ -159,7 +160,7 @@ int doIO(ZModem *zm) {
return done; return done;
} }
void upload_zmodem(int socket, struct user_record *user) { void upload_zmodem(struct user_record *user) {
ZModem zm; ZModem zm;
int done; int done;
@ -170,8 +171,8 @@ void upload_zmodem(int socket, struct user_record *user) {
zm.windowsize = 0; zm.windowsize = 0;
zm.bufsize = 0; zm.bufsize = 0;
zm.ifd = socket; zm.ifd = gSocket;
zm.ofd = socket; zm.ofd = gSocket;
zm.zrinitflags = 0; zm.zrinitflags = 0;
zm.zsinitflags = 0; zm.zsinitflags = 0;
@ -183,7 +184,7 @@ void upload_zmodem(int socket, struct user_record *user) {
doIO(&zm); doIO(&zm);
} }
void upload(int socket, struct user_record *user) { void upload(struct user_record *user) {
char buffer[331]; char buffer[331];
char buffer2[66]; char buffer2[66];
char buffer3[256]; char buffer3[256];
@ -202,14 +203,13 @@ void upload(int socket, struct user_record *user) {
struct stat s; struct stat s;
char *err_msg = NULL; char *err_msg = NULL;
upload_zmodem(socket, user); upload_zmodem(user);
s_putstring(socket, "\r\nPlease enter a description:\r\n"); s_printf("\r\nPlease enter a description:\r\n");
buffer[0] = '\0'; buffer[0] = '\0';
for (i=0;i<5;i++) { for (i=0;i<5;i++) {
sprintf(buffer2, "\r\n%d: ", i); s_printf("\r\n%d: ", i);
s_putstring(socket, buffer2); s_readstring(buffer2, 65);
s_readstring(socket, buffer2, 65);
if (strlen(buffer2) == 0) { if (strlen(buffer2) == 0) {
break; break;
} }
@ -261,7 +261,7 @@ void upload(int socket, struct user_record *user) {
sqlite3_close(db); sqlite3_close(db);
} }
void download_zmodem(int socket, struct user_record *user, char *filename) { void download_zmodem(struct user_record *user, char *filename) {
ZModem zm; ZModem zm;
int done ; int done ;
fd_set readfds; fd_set readfds;
@ -280,8 +280,8 @@ void download_zmodem(int socket, struct user_record *user, char *filename) {
zm.windowsize = 0; zm.windowsize = 0;
zm.bufsize = 0; zm.bufsize = 0;
zm.ifd = socket; zm.ifd = gSocket;
zm.ofd = socket; zm.ofd = gSocket;
zm.zrinitflags = 0; zm.zrinitflags = 0;
zm.zsinitflags = 0; zm.zsinitflags = 0;
@ -331,7 +331,7 @@ void download_zmodem(int socket, struct user_record *user, char *filename) {
} }
} }
void download(int socket, struct user_record *user) { void download(struct user_record *user) {
int i; int i;
char *ssql = "select dlcount from files where filename like ?"; char *ssql = "select dlcount from files where filename like ?";
char *usql = "update files set dlcount=? where filename like ?"; char *usql = "update files set dlcount=? where filename like ?";
@ -343,7 +343,7 @@ void download(int socket, struct user_record *user) {
int rc; int rc;
for (i=0;i<tagged_count;i++) { for (i=0;i<tagged_count;i++) {
download_zmodem(socket, user, tagged_files[i]); download_zmodem(user, tagged_files[i]);
sprintf(buffer, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database); sprintf(buffer, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database);
@ -397,7 +397,7 @@ void download(int socket, struct user_record *user) {
tagged_count = 0; tagged_count = 0;
} }
void list_files(int socket, struct user_record *user) { void list_files(struct user_record *user) {
char *sql = "select filename, description, size, dlcount from files where approved=1"; char *sql = "select filename, description, size, dlcount from files where approved=1";
char buffer[256]; char buffer[256];
sqlite3 *db; sqlite3 *db;
@ -430,7 +430,7 @@ void list_files(int socket, struct user_record *user) {
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
s_putstring(socket, "\r\nNo files in this area!\r\n"); s_printf("\r\nNo files in this area!\r\n");
return; return;
} }
@ -455,10 +455,10 @@ void list_files(int socket, struct user_record *user) {
sqlite3_close(db); sqlite3_close(db);
if (files_c == 0) { if (files_c == 0) {
s_putstring(socket, "\r\nNo files in this area!\r\n"); s_printf("\r\nNo files in this area!\r\n");
return; return;
} }
s_putstring(socket, "\r\n"); s_printf("\r\n");
for (i=0;i<files_c;i++) { for (i=0;i<files_c;i++) {
file_size = files_e[i]->size; file_size = files_e[i]->size;
if (file_size > 1024 * 1024 * 1024) { if (file_size > 1024 * 1024 * 1024) {
@ -473,20 +473,19 @@ void list_files(int socket, struct user_record *user) {
} else { } else {
file_unit = 'b'; file_unit = 'b';
} }
sprintf(buffer, "\r\n\r\n\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;33m%3ddloads \e[1;36m%4d%c \e[1;37m%-56s\r\n \e[0;32m", i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); s_printf("\r\n\r\n\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;33m%3ddloads \e[1;36m%4d%c \e[1;37m%-56s\r\n \e[0;32m", i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename));
s_putstring(socket, buffer);
lines+=3; lines+=3;
for (j=0;j<strlen(files_e[i]->description);j++) { for (j=0;j<strlen(files_e[i]->description);j++) {
if (files_e[i]->description[j] == '\n') { if (files_e[i]->description[j] == '\n') {
s_putstring(socket, "\r\n"); s_printf("\r\n");
lines++; lines++;
if (lines >= 18) { if (lines >= 18) {
lines = 0; lines = 0;
while (1) { while (1) {
s_putstring(socket, "\r\n\e[0mEnter # to tag, Q to quit, Enter to continue: "); s_printf("\r\n\e[0mEnter # to tag, Q to quit, Enter to continue: ");
s_readstring(socket, buffer, 5); s_readstring(buffer, 5);
if (strlen(buffer) == 0) { if (strlen(buffer) == 0) {
s_putstring(socket, "\r\n"); s_printf("\r\n");
break; break;
} else if (tolower(buffer[0]) == 'q') { } else if (tolower(buffer[0]) == 'q') {
for (z=0;z<files_c;z++) { for (z=0;z<files_c;z++) {
@ -495,7 +494,7 @@ void list_files(int socket, struct user_record *user) {
free(files_e[z]); free(files_e[z]);
} }
free(files_e); free(files_e);
s_putstring(socket, "\r\n"); s_printf("\r\n");
return; return;
} else { } else {
z = atoi(buffer); z = atoi(buffer);
@ -516,28 +515,27 @@ void list_files(int socket, struct user_record *user) {
} }
tagged_files[tagged_count] = strdup(files_e[z]->filename); tagged_files[tagged_count] = strdup(files_e[z]->filename);
tagged_count++; tagged_count++;
sprintf(buffer, "\r\nTagged %s\r\n", basename(files_e[z]->filename)); s_printf("\r\nTagged %s\r\n", basename(files_e[z]->filename));
s_putstring(socket, buffer);
} else { } else {
s_putstring(socket, "\r\nAlready Tagged\r\n"); s_printf("\r\nAlready Tagged\r\n");
} }
} else { } else {
s_putstring(socket, "\r\nSorry, you don't have permission to download from this area\r\n"); s_printf("\r\nSorry, you don't have permission to download from this area\r\n");
} }
} }
} }
} }
} else { } else {
s_putstring(socket, " \e[0;32m"); s_printf(" \e[0;32m");
} }
} else { } else {
s_putchar(socket, files_e[i]->description[j]); s_putchar(files_e[i]->description[j]);
} }
} }
} }
while (1) { while (1) {
s_putstring(socket, "\r\n\e[0mEnter # to tag, Enter to quit: "); s_printf("\r\n\e[0mEnter # to tag, Enter to quit: ");
s_readstring(socket, buffer, 5); s_readstring(buffer, 5);
if (strlen(buffer) == 0) { if (strlen(buffer) == 0) {
for (z=0;z<files_c;z++) { for (z=0;z<files_c;z++) {
free(files_e[z]->filename); free(files_e[z]->filename);
@ -545,7 +543,7 @@ void list_files(int socket, struct user_record *user) {
free(files_e[z]); free(files_e[z]);
} }
free(files_e); free(files_e);
s_putstring(socket, "\r\n"); s_printf("\r\n");
return; return;
} else { } else {
z = atoi(buffer); z = atoi(buffer);
@ -566,20 +564,19 @@ void list_files(int socket, struct user_record *user) {
} }
tagged_files[tagged_count] = strdup(files_e[z]->filename); tagged_files[tagged_count] = strdup(files_e[z]->filename);
tagged_count++; tagged_count++;
sprintf(buffer, "\r\nTagged %s\r\n", basename(files_e[z]->filename)); s_printf("\r\nTagged %s\r\n", basename(files_e[z]->filename));
s_putstring(socket, buffer);
} else { } else {
s_putstring(socket, "\r\nAlready Tagged\r\n"); s_printf("\r\nAlready Tagged\r\n");
} }
} else { } else {
s_putstring(socket, "\r\nSorry, you don't have permission to download from this area\r\n"); s_printf("\r\nSorry, you don't have permission to download from this area\r\n");
} }
} }
} }
} }
} }
int file_menu(int socket, struct user_record *user) { int file_menu(struct user_record *user) {
int doquit = 0; int doquit = 0;
int dofiles = 0; int dofiles = 0;
char c; char c;
@ -614,12 +611,11 @@ int file_menu(int socket, struct user_record *user) {
while (!dofiles) { while (!dofiles) {
if (do_internal_menu == 1) { if (do_internal_menu == 1) {
s_displayansi(socket, "filemenu"); s_displayansi("filemenu");
sprintf(prompt, "\e[0m\r\nDir: (%d) %s\r\nSub: (%d) %s\r\nTL: %dm :> ", user->cur_file_dir, conf.file_directories[user->cur_file_dir]->name, user->cur_file_sub, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->name, user->timeleft); s_printf("\e[0m\r\nDir: (%d) %s\r\nSub: (%d) %s\r\nTL: %dm :> ", user->cur_file_dir, conf.file_directories[user->cur_file_dir]->name, user->cur_file_sub, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->name, user->timeleft);
s_putstring(socket, prompt);
c = s_getc(socket); c = s_getc();
} else { } else {
lua_getglobal(L, "menu"); lua_getglobal(L, "menu");
result = lua_pcall(L, 0, 1, 0); result = lua_pcall(L, 0, 1, 0);
@ -636,25 +632,24 @@ int file_menu(int socket, struct user_record *user) {
switch(tolower(c)) { switch(tolower(c)) {
case 'i': case 'i':
{ {
s_putstring(socket, "\r\n\r\nFile Directories:\r\n\r\n"); s_printf("\r\n\r\nFile Directories:\r\n\r\n");
for (i=0;i<conf.file_directory_count;i++) { for (i=0;i<conf.file_directory_count;i++) {
if (conf.file_directories[i]->sec_level <= user->sec_level) { if (conf.file_directories[i]->sec_level <= user->sec_level) {
sprintf(prompt, " %d. %s\r\n", i, conf.file_directories[i]->name); s_printf(" %d. %s\r\n", i, conf.file_directories[i]->name);
s_putstring(socket, prompt);
} }
if (i != 0 && i % 20 == 0) { if (i != 0 && i % 20 == 0) {
s_putstring(socket, "Press any key to continue...\r\n"); s_printf("Press any key to continue...\r\n");
c = s_getc(socket); c = s_getc();
} }
} }
s_putstring(socket, "Enter the directory number: "); s_printf("Enter the directory number: ");
s_readstring(socket, prompt, 5); s_readstring(prompt, 5);
if (tolower(prompt[0]) != 'q') { if (tolower(prompt[0]) != 'q') {
j = atoi(prompt); j = atoi(prompt);
if (j < 0 || j >= conf.file_directory_count || conf.file_directories[j]->sec_level > user->sec_level) { if (j < 0 || j >= conf.file_directory_count || conf.file_directories[j]->sec_level > user->sec_level) {
s_putstring(socket, "\r\nInvalid directory number!\r\n"); s_printf("\r\nInvalid directory number!\r\n");
} else { } else {
s_putstring(socket, "\r\n"); s_printf("\r\n");
user->cur_file_dir = j; user->cur_file_dir = j;
user->cur_file_sub = 0; user->cur_file_sub = 0;
} }
@ -663,43 +658,42 @@ int file_menu(int socket, struct user_record *user) {
break; break;
case 's': case 's':
{ {
s_putstring(socket, "\r\n\r\nFile Subdirectories:\r\n\r\n"); s_printf("\r\n\r\nFile Subdirectories:\r\n\r\n");
for (i=0;i<conf.file_directories[user->cur_file_dir]->file_sub_count;i++) { for (i=0;i<conf.file_directories[user->cur_file_dir]->file_sub_count;i++) {
sprintf(prompt, " %d. %s\r\n", i, conf.file_directories[user->cur_file_dir]->file_subs[i]->name); s_printf(" %d. %s\r\n", i, conf.file_directories[user->cur_file_dir]->file_subs[i]->name);
s_putstring(socket, prompt);
if (i != 0 && i % 20 == 0) { if (i != 0 && i % 20 == 0) {
s_putstring(socket, "Press any key to continue...\r\n"); s_printf("Press any key to continue...\r\n");
c = s_getc(socket); c = s_getc();
} }
} }
s_putstring(socket, "Enter the sub directory number: "); s_printf("Enter the sub directory number: ");
s_readstring(socket, prompt, 5); s_readstring(prompt, 5);
if (tolower(prompt[0]) != 'q') { if (tolower(prompt[0]) != 'q') {
j = atoi(prompt); j = atoi(prompt);
if (j < 0 || j >= conf.file_directories[user->cur_file_dir]->file_sub_count) { if (j < 0 || j >= conf.file_directories[user->cur_file_dir]->file_sub_count) {
s_putstring(socket, "\r\nInvalid sub directiry number!\r\n"); s_printf("\r\nInvalid sub directiry number!\r\n");
} else { } else {
s_putstring(socket, "\r\n"); s_printf("\r\n");
user->cur_file_sub = j; user->cur_file_sub = j;
} }
} }
} }
break; break;
case 'l': case 'l':
list_files(socket, user); list_files(user);
break; break;
case 'u': case 'u':
{ {
if (user->sec_level >= conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->upload_sec_level) { if (user->sec_level >= conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->upload_sec_level) {
upload(socket, user); upload(user);
} else { } else {
s_putstring(socket, "Sorry, you don't have permission to upload in this Sub\r\n"); s_printf("Sorry, you don't have permission to upload in this Sub\r\n");
} }
} }
break; break;
case 'd': case 'd':
download(socket, user); download(user);
break; break;
case 'c': case 'c':
{ {
@ -764,8 +758,8 @@ int file_menu(int socket, struct user_record *user) {
break; break;
case 'g': case 'g':
{ {
s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)"); s_printf("\r\nAre you sure you want to log off? (Y/N)");
c = s_getc(socket); c = s_getc();
if (tolower(c) == 'y') { if (tolower(c) == 'y') {
dofiles = 1; dofiles = 1;
doquit = 1; doquit = 1;

View File

@ -12,7 +12,7 @@ extern int gSocket;
int l_bbsWString(lua_State *L) { int l_bbsWString(lua_State *L) {
char *str = (char *)lua_tostring(L, -1); char *str = (char *)lua_tostring(L, -1);
s_putstring(gSocket, str); s_printf("%s", str);
return 0; return 0;
} }
@ -25,7 +25,7 @@ int l_bbsRString(lua_State *L) {
len = 256; len = 256;
} }
s_readstring(gSocket, buffer, len); s_readstring(buffer, len);
lua_pushstring(L, buffer); lua_pushstring(L, buffer);
@ -35,7 +35,7 @@ int l_bbsRString(lua_State *L) {
int l_bbsRChar(lua_State *L) { int l_bbsRChar(lua_State *L) {
char c; char c;
c = s_getc(gSocket); c = s_getc();
lua_pushlstring(L, &c, 1); lua_pushlstring(L, &c, 1);
@ -45,7 +45,7 @@ int l_bbsRChar(lua_State *L) {
int l_bbsDisplayAnsi(lua_State *L) { int l_bbsDisplayAnsi(lua_State *L) {
char *str = (char *)lua_tostring(L, -1); char *str = (char *)lua_tostring(L, -1);
s_displayansi(gSocket, str); s_displayansi(str);
return 0; return 0;
} }
@ -94,7 +94,7 @@ int l_bbsGetEmailCount(lua_State *L) {
} }
int l_bbsMailScan(lua_State *L) { int l_bbsMailScan(lua_State *L) {
mail_scan(gSocket, gUser); mail_scan(gUser);
return 0; return 0;
} }
@ -102,7 +102,7 @@ int l_bbsRunDoor(lua_State *L) {
char *cmd = (char *)lua_tostring(L, 1); char *cmd = (char *)lua_tostring(L, 1);
int stdio = lua_toboolean(L, 2); int stdio = lua_toboolean(L, 2);
rundoor(gSocket, gUser, cmd, stdio); rundoor(gUser, cmd, stdio);
return 0; return 0;
} }
@ -114,7 +114,7 @@ int l_bbsTimeLeft(lua_State *L) {
} }
int l_bbsDisplayAutoMsg(lua_State *L) { int l_bbsDisplayAutoMsg(lua_State *L) {
automessage_display(gSocket); automessage_display();
return 0; return 0;
} }

View File

@ -261,7 +261,7 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r
return msghs; return msghs;
} }
char *external_editor(int socket, struct user_record *user, char *to, char *from, char *quote, char *qfrom, char *subject, int email) { char *external_editor(struct user_record *user, char *to, char *from, char *quote, char *qfrom, char *subject, int email) {
char c; char c;
FILE *fptr; FILE *fptr;
char *body = NULL; char *body = NULL;
@ -279,8 +279,8 @@ char *external_editor(int socket, struct user_record *user, char *to, char *from
if (conf.external_editor_cmd != NULL) { if (conf.external_editor_cmd != NULL) {
s_putstring(socket, "\r\nUse external editor? (Y/N) "); s_printf("\r\nUse external editor? (Y/N) ");
c = s_getc(socket); c = s_getc();
if (tolower(c) == 'y') { if (tolower(c) == 'y') {
sprintf(buffer, "%s/node%d", conf.bbs_path, mynode); sprintf(buffer, "%s/node%d", conf.bbs_path, mynode);
@ -335,7 +335,7 @@ char *external_editor(int socket, struct user_record *user, char *to, char *from
} }
fclose(fptr); fclose(fptr);
rundoor(socket, user, conf.external_editor_cmd, conf.external_editor_stdio); rundoor(user, conf.external_editor_cmd, conf.external_editor_stdio);
// readin msgtmp // readin msgtmp
sprintf(buffer, "%s/node%d/MSGTMP", conf.bbs_path, mynode); sprintf(buffer, "%s/node%d/MSGTMP", conf.bbs_path, mynode);
@ -413,10 +413,10 @@ char *external_editor(int socket, struct user_record *user, char *to, char *from
return body2; return body2;
} }
} }
return editor(socket, user, quote, qfrom, email); return editor(user, quote, qfrom, email);
} }
char *editor(int socket, struct user_record *user, char *quote, char *from, int email) { char *editor(struct user_record *user, char *quote, char *from, int email) {
int lines = 0; int lines = 0;
char buffer[256]; char buffer[256];
char linebuffer[80]; char linebuffer[80];
@ -460,14 +460,13 @@ char *editor(int socket, struct user_record *user, char *quote, char *from, int
} }
} }
} }
s_putstring(socket, "\r\n\e[1;32mMagicka Internal Editor, Type \e[1;37m/S \e[1;32mto save, \e[1;37m/A \e[1;32mto abort and \e[1;37m/? \e[1;32mfor help\r\n"); s_printf("\r\n\e[1;32mMagicka Internal Editor, Type \e[1;37m/S \e[1;32mto save, \e[1;37m/A \e[1;32mto abort and \e[1;37m/? \e[1;32mfor help\r\n");
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m"); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m");
while(!doquit) { while(!doquit) {
sprintf(prompt, "\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", lines, next_line_buffer); s_printf("\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", lines, next_line_buffer);
s_putstring(socket, prompt);
strcpy(linebuffer, next_line_buffer); strcpy(linebuffer, next_line_buffer);
s_readstring(socket, &linebuffer[strlen(next_line_buffer)], 70 - strlen(next_line_buffer)); s_readstring(&linebuffer[strlen(next_line_buffer)], 70 - strlen(next_line_buffer));
memset(next_line_buffer, 0, 70); memset(next_line_buffer, 0, 70);
if (strlen(linebuffer) == 70 && linebuffer[69] != ' ') { if (strlen(linebuffer) == 70 && linebuffer[69] != ' ') {
@ -475,8 +474,7 @@ char *editor(int socket, struct user_record *user, char *quote, char *from, int
if (linebuffer[i] == ' ') { if (linebuffer[i] == ' ') {
linebuffer[i] = '\0'; linebuffer[i] = '\0';
strcpy(next_line_buffer, &linebuffer[i+1]); strcpy(next_line_buffer, &linebuffer[i+1]);
sprintf(prompt, "\e[%dD\e[0K", 70 - i); s_printf("\e[%dD\e[0K", 70 - i);
s_putstring(socket, prompt);
break; break;
} }
} }
@ -548,21 +546,20 @@ char *editor(int socket, struct user_record *user, char *quote, char *from, int
return NULL; return NULL;
} else if (toupper(linebuffer[1]) == 'Q') { } else if (toupper(linebuffer[1]) == 'Q') {
if (quote == NULL) { if (quote == NULL) {
s_putstring(socket, "\r\nNo message to quote!\r\n"); s_printf("\r\nNo message to quote!\r\n");
} else { } else {
s_putstring(socket, "\r\n"); s_printf("\r\n");
for (i=0;i<quotelines;i++) { for (i=0;i<quotelines;i++) {
sprintf(buffer, "\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", i, quotecontent[i]); s_printf("\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", i, quotecontent[i]);
s_putstring(socket, buffer);
} }
s_putstring(socket, "\r\nQuote from Line: "); s_printf("\r\nQuote from Line: ");
s_readstring(socket, buffer, 5); s_readstring(buffer, 5);
qfrom = atoi(buffer); qfrom = atoi(buffer);
s_putstring(socket, "\r\nQuote to Line: "); s_printf("\r\nQuote to Line: ");
s_readstring(socket, buffer, 5); s_readstring(buffer, 5);
qto = atoi(buffer); qto = atoi(buffer);
s_putstring(socket, "\r\n"); s_printf("\r\n");
if (qto > quotelines) { if (qto > quotelines) {
qto = quotelines; qto = quotelines;
@ -571,7 +568,7 @@ char *editor(int socket, struct user_record *user, char *quote, char *from, int
qfrom = 0; qfrom = 0;
} }
if (qfrom > qto) { if (qfrom > qto) {
s_putstring(socket, "Quoting Cancelled\r\n"); s_printf("Quoting Cancelled\r\n");
} }
for (i=qfrom;i<=qto;i++) { for (i=qfrom;i<=qto;i++) {
@ -585,40 +582,38 @@ char *editor(int socket, struct user_record *user, char *quote, char *from, int
lines++; lines++;
} }
s_putstring(socket, "\r\n\e[1;32mMagicka Internal Editor, Type \e[1;37m/S \e[1;32mto save, \e[1;37m/A \e[1;32mto abort and \e[1;37m/? \e[1;32mfor help\r\n"); s_printf("\r\n\e[1;32mMagicka Internal Editor, Type \e[1;37m/S \e[1;32mto save, \e[1;37m/A \e[1;32mto abort and \e[1;37m/? \e[1;32mfor help\r\n");
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m"); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m");
for (i=0;i<lines;i++) { for (i=0;i<lines;i++) {
sprintf(buffer, "\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", i, content[i]); s_printf("\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", i, content[i]);
s_putstring(socket, buffer);
} }
} }
} else if (toupper(linebuffer[1]) == 'L') { } else if (toupper(linebuffer[1]) == 'L') {
s_putstring(socket, "\r\n\e[1;32mMagicka Internal Editor, Type \e[1;37m/S \e[1;32mto save, \e[1;37m/A \e[1;32mto abort and \e[1;37m/? \e[1;32mfor help\r\n"); s_printf("\r\n\e[1;32mMagicka Internal Editor, Type \e[1;37m/S \e[1;32mto save, \e[1;37m/A \e[1;32mto abort and \e[1;37m/? \e[1;32mfor help\r\n");
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m"); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m");
for (i=0;i<lines;i++) { for (i=0;i<lines;i++) {
sprintf(buffer, "\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", i, content[i]); s_printf("\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", i, content[i]);
s_putstring(socket, buffer);
} }
} else if (linebuffer[1] == '?') { } else if (linebuffer[1] == '?') {
s_putstring(socket, "\e[1;33m\r\nHELP\r\n"); s_printf("\e[1;33m\r\nHELP\r\n");
s_putstring(socket, "/S - Save Message\r\n"); s_printf("/S - Save Message\r\n");
s_putstring(socket, "/A - Abort Message\r\n"); s_printf("/A - Abort Message\r\n");
s_putstring(socket, "/Q - Quote Message\r\n"); s_printf("/Q - Quote Message\r\n");
s_putstring(socket, "/E - Edit (Rewrite) Line\r\n"); s_printf("/E - Edit (Rewrite) Line\r\n");
s_putstring(socket, "/D - Delete Line\r\n"); s_printf("/D - Delete Line\r\n");
s_putstring(socket, "/I - Insert Line\r\n"); s_printf("/I - Insert Line\r\n");
s_putstring(socket, "/L - Relist Message\r\n\e[0m"); s_printf("/L - Relist Message\r\n\e[0m");
} else if (toupper(linebuffer[1]) == 'D') { } else if (toupper(linebuffer[1]) == 'D') {
s_putstring(socket, "\r\nWhich line do you want to delete? "); s_printf("\r\nWhich line do you want to delete? ");
s_readstring(socket, buffer, 6); s_readstring(buffer, 6);
if (strlen(buffer) == 0) { if (strlen(buffer) == 0) {
s_putstring(socket, "\r\nAborted...\r\n"); s_printf("\r\nAborted...\r\n");
} else { } else {
z = atoi(buffer); z = atoi(buffer);
if (z < 0 || z >= lines) { if (z < 0 || z >= lines) {
s_putstring(socket, "\r\nAborted...\r\n"); s_printf("\r\nAborted...\r\n");
} else { } else {
for (i=z;i<lines-1;i++) { for (i=z;i<lines-1;i++) {
free(content[i]); free(content[i]);
@ -630,37 +625,34 @@ char *editor(int socket, struct user_record *user, char *quote, char *from, int
} }
} }
} else if (toupper(linebuffer[1]) == 'E') { } else if (toupper(linebuffer[1]) == 'E') {
s_putstring(socket, "\r\nWhich line do you want to edit? "); s_printf("\r\nWhich line do you want to edit? ");
s_readstring(socket, buffer, 6); s_readstring(buffer, 6);
if (strlen(buffer) == 0) { if (strlen(buffer) == 0) {
s_putstring(socket, "\r\nAborted...\r\n"); s_printf("\r\nAborted...\r\n");
} else { } else {
z = atoi(buffer); z = atoi(buffer);
if (z < 0 || z >= lines) { if (z < 0 || z >= lines) {
s_putstring(socket, "\r\nAborted...\r\n"); s_printf("\r\nAborted...\r\n");
} else { } else {
sprintf(buffer, "\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", z, content[z]); s_printf("\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", z, content[z]);
s_putstring(socket, buffer); s_printf("\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m", z);
sprintf(buffer, "\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m", z); s_readstring(linebuffer, 70);
s_putstring(socket, buffer);
s_readstring(socket, linebuffer, 70);
free(content[z]); free(content[z]);
content[z] = strdup(linebuffer); content[z] = strdup(linebuffer);
} }
} }
} else if (toupper(linebuffer[1]) == 'I') { } else if (toupper(linebuffer[1]) == 'I') {
s_putstring(socket, "\r\nInsert before which line? "); s_printf("\r\nInsert before which line? ");
s_readstring(socket, buffer, 6); s_readstring(buffer, 6);
if (strlen(buffer) == 0) { if (strlen(buffer) == 0) {
s_putstring(socket, "\r\nAborted...\r\n"); s_printf("\r\nAborted...\r\n");
} else { } else {
z = atoi(buffer); z = atoi(buffer);
if (z < 0 || z >= lines) { if (z < 0 || z >= lines) {
s_putstring(socket, "\r\nAborted...\r\n"); s_printf("\r\nAborted...\r\n");
} else { } else {
sprintf(buffer, "\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m", z); s_printf("\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m", z);
s_putstring(socket, buffer); s_readstring(linebuffer, 70);
s_readstring(socket, linebuffer, 70);
lines++; lines++;
content = (char **)realloc(content, sizeof(char *) * lines); content = (char **)realloc(content, sizeof(char *) * lines);
@ -750,24 +742,20 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
if (msghs->msgs[mailno]->oaddress != NULL && conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { if (msghs->msgs[mailno]->oaddress != NULL && conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) {
from_addr = parse_fido_addr(msghs->msgs[mailno]->oaddress); from_addr = parse_fido_addr(msghs->msgs[mailno]->oaddress);
sprintf(buffer, "\e[2J\e[1;32mFrom : \e[1;37m%s (%d:%d/%d.%d)\r\n", msghs->msgs[mailno]->from, from_addr->zone, from_addr->net, from_addr->node, from_addr->point); s_printf("\e[2J\e[1;32mFrom : \e[1;37m%s (%d:%d/%d.%d)\r\n", msghs->msgs[mailno]->from, from_addr->zone, from_addr->net, from_addr->node, from_addr->point);
free(from_addr); free(from_addr);
} else { } else {
sprintf(buffer, "\e[2J\e[1;32mFrom : \e[1;37m%s\r\n", msghs->msgs[mailno]->from); s_printf("\e[2J\e[1;32mFrom : \e[1;37m%s\r\n", msghs->msgs[mailno]->from);
} }
s_putstring(socket, buffer); s_printf("\e[1;32mTo : \e[1;37m%-27.27s \e[1;32mArea : \e[1;37m%-27.27s\r\n", msghs->msgs[mailno]->to, conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name);
sprintf(buffer, "\e[1;32mTo : \e[1;37m%-27.27s \e[1;32mArea : \e[1;37m%-27.27s\r\n", msghs->msgs[mailno]->to, conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name); s_printf("\e[1;32mSubject : \e[1;37m%-27.27s \e[1;32mMsgNo : \e[1;37m%4d of %4d\r\n", msghs->msgs[mailno]->subject, mailno + 1, msghs->msg_count);
s_putstring(socket, buffer);
sprintf(buffer, "\e[1;32mSubject : \e[1;37m%-27.27s \e[1;32mMsgNo : \e[1;37m%4d of %4d\r\n", msghs->msgs[mailno]->subject, mailno + 1, msghs->msg_count);
s_putstring(socket, buffer);
localtime_r((time_t *)&msghs->msgs[mailno]->msg_h->DateWritten, &msg_date); localtime_r((time_t *)&msghs->msgs[mailno]->msg_h->DateWritten, &msg_date);
sprintf(buffer, "\e[1;32mDate : \e[1;37m%s", asctime(&msg_date)); sprintf(buffer, "\e[1;32mDate : \e[1;37m%s", asctime(&msg_date));
buffer[strlen(buffer) - 1] = '\0'; buffer[strlen(buffer) - 1] = '\0';
strcat(buffer, "\r\n"); strcat(buffer, "\r\n");
s_putstring(socket, buffer); s_printf(buffer);
sprintf(buffer, "\e[1;32mAttribs : \e[1;37m%s\r\n", (msghs->msgs[mailno]->msg_h->Attribute & MSG_SENT ? "SENT" : "")); s_printf("\e[1;32mAttribs : \e[1;37m%s\r\n", (msghs->msgs[mailno]->msg_h->Attribute & MSG_SENT ? "SENT" : ""));
s_putstring(socket, buffer); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
body = (char *)malloc(msghs->msgs[mailno]->msg_h->TxtLen); body = (char *)malloc(msghs->msgs[mailno]->msg_h->TxtLen);
@ -817,16 +805,16 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
if (body[z] == '\r' || chars == 79) { if (body[z] == '\r' || chars == 79) {
chars = 0; chars = 0;
if (body[z] == '\r') { if (body[z] == '\r') {
s_putstring(socket, "\r\n"); s_printf("\r\n");
} else { } else {
s_putchar(socket, body[z]); s_putchar(body[z]);
} }
lines++; lines++;
if (lines >= 17) { if (lines >= 17) {
s_putstring(socket, "\e[1;37mPress a key to continue...\e[0m"); s_printf("\e[1;37mPress a key to continue...\e[0m");
s_getc(socket); s_getc();
lines = 0; lines = 0;
s_putstring(socket, "\e[7;1H\e[0J"); s_printf("\e[7;1H\e[0J");
} }
} else if (body[z] == '\e' && body[z + 1] == '[') { } else if (body[z] == '\e' && body[z + 1] == '[') {
ansi = z; ansi = z;
@ -835,7 +823,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
if (body[z] == 'm') { if (body[z] == 'm') {
strncpy(buffer, &body[ansi], (z - ansi) + 1); strncpy(buffer, &body[ansi], (z - ansi) + 1);
buffer[z - ansi + 1] = '\0'; buffer[z - ansi + 1] = '\0';
s_putstring(socket, buffer); s_printf("%s", buffer);
} else if (body[z] == 'A') { } else if (body[z] == 'A') {
j = atoi(&body[ansi + 2]); j = atoi(&body[ansi + 2]);
if (j == 0 && ansi + 2 == z) { if (j == 0 && ansi + 2 == z) {
@ -843,7 +831,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
} }
for (i=0;i<j;i++) { for (i=0;i<j;i++) {
if (lines - 1 >= 0) { if (lines - 1 >= 0) {
s_putstring(socket, "\e[A"); s_printf("\e[A");
lines--; lines--;
} else { } else {
break; break;
@ -856,7 +844,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
} }
for (i=0;i<j;i++) { for (i=0;i<j;i++) {
if (chars + 1 <= 79) { if (chars + 1 <= 79) {
s_putstring(socket, "\e[C"); s_printf("\e[C");
chars++; chars++;
} else { } else {
break; break;
@ -869,7 +857,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
} }
for (i=0;i<j;i++) { for (i=0;i<j;i++) {
if (lines + 1 < 17) { if (lines + 1 < 17) {
s_putstring(socket, "\e[B"); s_printf("\e[B");
lines++; lines++;
} else { } else {
break; break;
@ -882,7 +870,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
} }
for (i=0;i<j;i++) { for (i=0;i<j;i++) {
if (chars - 1 >= 0) { if (chars - 1 >= 0) {
s_putstring(socket, "\e[D"); s_printf("\e[D");
chars--; chars--;
} else { } else {
break; break;
@ -891,18 +879,18 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
} }
} else { } else {
chars++; chars++;
s_putchar(socket, body[z]); s_putchar(body[z]);
} }
} }
s_putstring(socket, "\r\n\e[1;37mPress \e[1;36mR \e[1;37mto reply, \e[1;36mQ \e[1;37mto quit, \e[1;36mB \e[1;37mto go Back, \e[1;36mSPACE \e[1;37mfor Next Mesage..."); s_printf("\r\n\e[1;37mPress \e[1;36mR \e[1;37mto reply, \e[1;36mQ \e[1;37mto quit, \e[1;36mB \e[1;37mto go Back, \e[1;36mSPACE \e[1;37mfor Next Mesage...");
c = s_getc(socket); c = s_getc();
if (tolower(c) == 'r') { if (tolower(c) == 'r') {
JAM_CloseMB(jb); JAM_CloseMB(jb);
if (user->sec_level < conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->write_sec_level) { if (user->sec_level < conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->write_sec_level) {
s_putstring(socket, "\r\nSorry, you are not allowed to post in this area\r\n"); s_printf("\r\nSorry, you are not allowed to post in this area\r\n");
} else { } else {
if (msghs->msgs[mailno]->subject != NULL) { if (msghs->msgs[mailno]->subject != NULL) {
if (strncasecmp(msghs->msgs[mailno]->subject, "RE:", 3) != 0) { if (strncasecmp(msghs->msgs[mailno]->subject, "RE:", 3) != 0) {
@ -914,25 +902,24 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
subject = (char *)malloc(strlen(buffer) + 1); subject = (char *)malloc(strlen(buffer) + 1);
strcpy(subject, buffer); strcpy(subject, buffer);
sprintf(buffer, "\r\n\r\nReplying to: %s\r\n", subject); s_printf("\r\n\r\nReplying to: %s\r\n", subject);
s_putstring(socket, buffer); s_printf("Change Subject? (Y/N) ");
s_putstring(socket, "Change Subject? (Y/N) ");
c = s_getc(socket); c = s_getc();
if (tolower(c) == 'y') { if (tolower(c) == 'y') {
s_putstring(socket, "\r\nNew subject: "); s_printf("\r\nNew subject: ");
s_readstring(socket, buffer, 25); s_readstring(buffer, 25);
if (strlen(buffer) == 0) { if (strlen(buffer) == 0) {
s_putstring(socket, "\r\nOk, not changing the subject line..."); s_printf("\r\nOk, not changing the subject line...");
} else { } else {
free(subject); free(subject);
subject = (char *)malloc(strlen(buffer) + 1); subject = (char *)malloc(strlen(buffer) + 1);
strcpy(subject, buffer); strcpy(subject, buffer);
} }
} }
s_putstring(socket, "\r\n"); s_printf("\r\n");
if (msghs->msgs[mailno]->from != NULL) { if (msghs->msgs[mailno]->from != NULL) {
strcpy(buffer, msghs->msgs[mailno]->from); strcpy(buffer, msghs->msgs[mailno]->from);
@ -961,7 +948,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
to = (char *)malloc(strlen(buffer) + 1); to = (char *)malloc(strlen(buffer) + 1);
strcpy(to, buffer); strcpy(to, buffer);
} }
replybody = external_editor(socket, user, to, from, body, msghs->msgs[mailno]->from, subject, 0); replybody = external_editor(user, to, from, body, msghs->msgs[mailno]->from, subject, 0);
if (replybody != NULL) { if (replybody != NULL) {
jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
@ -1189,7 +1176,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
} else if (c == ' ') { } else if (c == ' ') {
mailno++; mailno++;
if (mailno >= msghs->msg_count) { if (mailno >= msghs->msg_count) {
s_putstring(socket, "\r\n\r\nNo more messages\r\n"); s_printf("\r\n\r\nNo more messages\r\n");
doquit = 1; doquit = 1;
} }
} else if (tolower(c) == 'b') { } else if (tolower(c) == 'b') {
@ -1200,7 +1187,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
} }
} }
int mail_menu(int socket, struct user_record *user) { int mail_menu(struct user_record *user) {
int doquit = 0; int doquit = 0;
int domail = 0; int domail = 0;
char c; char c;
@ -1269,13 +1256,12 @@ int mail_menu(int socket, struct user_record *user) {
while (!domail) { while (!domail) {
if (do_internal_menu == 1) { if (do_internal_menu == 1) {
s_displayansi(socket, "mailmenu"); s_displayansi("mailmenu");
sprintf(prompt, "\e[0m\r\nConf: (%d) %s\r\nArea: (%d) %s\r\nTL: %dm :> ", user->cur_mail_conf, conf.mail_conferences[user->cur_mail_conf]->name, user->cur_mail_area, conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name, user->timeleft); s_printf("\e[0m\r\nConf: (%d) %s\r\nArea: (%d) %s\r\nTL: %dm :> ", user->cur_mail_conf, conf.mail_conferences[user->cur_mail_conf]->name, user->cur_mail_area, conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name, user->timeleft);
s_putstring(socket, prompt);
c = s_getc(socket); c = s_getc();
} else { } else {
lua_getglobal(L, "menu"); lua_getglobal(L, "menu");
result = lua_pcall(L, 0, 1, 0); result = lua_pcall(L, 0, 1, 0);
@ -1292,7 +1278,7 @@ int mail_menu(int socket, struct user_record *user) {
switch(tolower(c)) { switch(tolower(c)) {
case 'd': case 'd':
{ {
s_putstring(socket, "\r\n"); s_printf("\r\n");
// list mail in message base // list mail in message base
msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user); msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user);
if (msghs != NULL && msghs->msg_count > 0) { if (msghs != NULL && msghs->msg_count > 0) {
@ -1308,9 +1294,9 @@ int mail_menu(int socket, struct user_record *user) {
all_unread = 1; all_unread = 1;
} }
JAM_CloseMB(jb); JAM_CloseMB(jb);
sprintf(buffer, "Read message [1-%d] or N for New: ", msghs->msg_count); s_printf("Read message [1-%d] or N for New: ", msghs->msg_count);
s_putstring(socket, buffer);
s_readstring(socket, buffer, 6); s_readstring(buffer, 6);
if (tolower(buffer[0]) == 'n') { if (tolower(buffer[0]) == 'n') {
if (all_unread == 0) { if (all_unread == 0) {
@ -1341,14 +1327,14 @@ int mail_menu(int socket, struct user_record *user) {
case 'p': case 'p':
{ {
if (user->sec_level < conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->write_sec_level) { if (user->sec_level < conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->write_sec_level) {
s_putstring(socket, "\r\nSorry, you are not allowed to post in this area\r\n"); s_printf("\r\nSorry, you are not allowed to post in this area\r\n");
break; break;
} }
if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_WWIV && conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA) { if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_WWIV && conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA) {
sprintf(buffer, "ALL"); sprintf(buffer, "ALL");
} else { } else {
s_putstring(socket, "\r\nTO: "); s_printf("\r\nTO: ");
s_readstring(socket, buffer, 16); s_readstring(buffer, 16);
} }
if (strlen(buffer) == 0) { if (strlen(buffer) == 0) {
strcpy(buffer, "ALL"); strcpy(buffer, "ALL");
@ -1356,43 +1342,41 @@ int mail_menu(int socket, struct user_record *user) {
if (conf.mail_conferences[user->cur_mail_conf]->networked == 0 && strcasecmp(buffer, "ALL") != 0) { if (conf.mail_conferences[user->cur_mail_conf]->networked == 0 && strcasecmp(buffer, "ALL") != 0) {
if (check_user(buffer)) { if (check_user(buffer)) {
s_putstring(socket, "\r\n\r\nInvalid Username\r\n"); s_printf("\r\n\r\nInvalid Username\r\n");
break; break;
} }
} }
if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) {
s_putstring(socket, "\r\nADDR: "); s_printf("\r\nADDR: ");
s_readstring(socket, buffer2, 32); s_readstring(buffer2, 32);
if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) {
from_addr = parse_fido_addr(buffer2); from_addr = parse_fido_addr(buffer2);
if (!from_addr) { if (!from_addr) {
s_putstring(socket, "\r\n\r\nInvalid Address\r\n"); s_printf("\r\n\r\nInvalid Address\r\n");
break; break;
} else { } else {
if (from_addr->zone == 0 && from_addr->net == 0 && from_addr->node == 0 && from_addr->point == 0) { if (from_addr->zone == 0 && from_addr->net == 0 && from_addr->node == 0 && from_addr->point == 0) {
free(from_addr); free(from_addr);
s_putstring(socket, "\r\n\r\nInvalid Address\r\n"); s_printf("\r\n\r\nInvalid Address\r\n");
break; break;
} }
sprintf(buffer2, "\r\nMailing to %d:%d/%d.%d\r\n", from_addr->zone, from_addr->net, from_addr->node, from_addr->point); s_printf(buffer2, "\r\nMailing to %d:%d/%d.%d\r\n", from_addr->zone, from_addr->net, from_addr->node, from_addr->point);
s_putstring(socket, buffer2);
} }
} else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_WWIV) { } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_WWIV) {
wwiv_to = atoi(buffer2); wwiv_to = atoi(buffer2);
if (wwiv_to == 0) { if (wwiv_to == 0) {
s_putstring(socket, "\r\n\r\nInvalid Address\r\n"); s_printf("\r\n\r\nInvalid Address\r\n");
break; break;
} else { } else {
sprintf(buffer2, "\r\nMailing to @%d\r\n", wwiv_to); s_printf("\r\nMailing to @%d\r\n", wwiv_to);
s_putstring(socket, buffer2);
} }
} }
} }
to = strdup(buffer); to = strdup(buffer);
s_putstring(socket, "\r\nSUBJECT: "); s_printf("\r\nSUBJECT: ");
s_readstring(socket, buffer, 25); s_readstring(buffer, 25);
if (strlen(buffer) == 0) { if (strlen(buffer) == 0) {
s_putstring(socket, "\r\nAborted!\r\n"); s_printf("\r\nAborted!\r\n");
free(to); free(to);
if (from_addr != NULL) { if (from_addr != NULL) {
free(from_addr); free(from_addr);
@ -1402,7 +1386,7 @@ int mail_menu(int socket, struct user_record *user) {
subject = strdup(buffer); subject = strdup(buffer);
// post a message // post a message
msg = external_editor(socket, user, to, from, NULL, NULL, subject, 0); msg = external_editor(user, to, from, NULL, NULL, subject, 0);
if (msg != NULL) { if (msg != NULL) {
jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
@ -1599,7 +1583,7 @@ int mail_menu(int socket, struct user_record *user) {
break; break;
case 'l': case 'l':
{ {
s_putstring(socket, "\r\n"); s_printf("\r\n");
// list mail in message base // list mail in message base
msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user); msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user);
if (msghs != NULL && msghs->msg_count > 0) { if (msghs != NULL && msghs->msg_count > 0) {
@ -1615,10 +1599,9 @@ int mail_menu(int socket, struct user_record *user) {
all_unread = 1; all_unread = 1;
} }
JAM_CloseMB(jb); JAM_CloseMB(jb);
sprintf(buffer, "Start at message [1-%d] or N for New? ", msghs->msg_count); s_printf("Start at message [1-%d] or N for New? ", msghs->msg_count);
s_putstring(socket, buffer);
s_readstring(socket, buffer, 6); s_readstring(buffer, 6);
if (tolower(buffer[0]) == 'n') { if (tolower(buffer[0]) == 'n') {
if (all_unread == 0) { if (all_unread == 0) {
k = jlr.HighReadMsg; k = jlr.HighReadMsg;
@ -1638,21 +1621,19 @@ int mail_menu(int socket, struct user_record *user) {
} }
} }
closed = 0; closed = 0;
s_putstring(socket, "\e[2J\e[1;37;44m[MSG#] Subject From To Date \r\n\e[0m"); s_printf("\e[2J\e[1;37;44m[MSG#] Subject From To Date \r\n\e[0m");
for (j=i-1;j<msghs->msg_count;j++) { for (j=i-1;j<msghs->msg_count;j++) {
localtime_r((time_t *)&msghs->msgs[j]->msg_h->DateWritten, &msg_date); localtime_r((time_t *)&msghs->msgs[j]->msg_h->DateWritten, &msg_date);
if (msghs->msgs[j]->msg_no > jlr.HighReadMsg || all_unread) { if (msghs->msgs[j]->msg_no > jlr.HighReadMsg || all_unread) {
sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); s_printf("\e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
} else { } else {
sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); s_printf("\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
} }
s_putstring(socket, buffer);
if ((j - (i - 1)) != 0 && (j - (i - 1)) % 20 == 0) { if ((j - (i - 1)) != 0 && (j - (i - 1)) % 20 == 0) {
sprintf(buffer, "(#) Read Message # (Q) Quit (ENTER) Continue\r\n"); s_printf("(#) Read Message # (Q) Quit (ENTER) Continue\r\n");
s_putstring(socket, buffer); s_readstring(buffer, 6);
s_readstring(socket, buffer, 6);
if (tolower(buffer[0]) == 'q') { if (tolower(buffer[0]) == 'q') {
closed = 1; closed = 1;
@ -1665,14 +1646,13 @@ int mail_menu(int socket, struct user_record *user) {
break; break;
} }
} }
s_putstring(socket, "\e[2J\e[1;37;44m[MSG#] Subject From To Date \r\n\e[0m"); s_printf("\e[2J\e[1;37;44m[MSG#] Subject From To Date \r\n\e[0m");
} }
} }
if (closed == 0) { if (closed == 0) {
sprintf(buffer, "(#) Read Message # (ENTER) Quit\r\n"); s_printf("(#) Read Message # (ENTER) Quit\r\n");
s_putstring(socket, buffer); s_readstring(buffer, 6);
s_readstring(socket, buffer, 6);
if (strlen(buffer) > 0) { if (strlen(buffer) > 0) {
z = atoi(buffer); z = atoi(buffer);
if (z > 0 && z <= msghs->msg_count) { if (z > 0 && z <= msghs->msg_count) {
@ -1686,31 +1666,30 @@ int mail_menu(int socket, struct user_record *user) {
free_message_headers(msghs); free_message_headers(msghs);
} }
} else { } else {
s_putstring(socket, "\r\nThere is no mail in this area\r\n"); s_printf("\r\nThere is no mail in this area\r\n");
} }
} }
break; break;
case 'c': case 'c':
{ {
s_putstring(socket, "\r\n\r\nMail Conferences:\r\n\r\n"); s_printf("\r\n\r\nMail Conferences:\r\n\r\n");
for (i=0;i<conf.mail_conference_count;i++) { for (i=0;i<conf.mail_conference_count;i++) {
if (conf.mail_conferences[i]->sec_level <= user->sec_level) { if (conf.mail_conferences[i]->sec_level <= user->sec_level) {
sprintf(buffer, " %d. %s\r\n", i, conf.mail_conferences[i]->name); s_printf(" %d. %s\r\n", i, conf.mail_conferences[i]->name);
s_putstring(socket, buffer);
} }
if (i != 0 && i % 20 == 0) { if (i != 0 && i % 20 == 0) {
s_putstring(socket, "Press any key to continue...\r\n"); s_printf("Press any key to continue...\r\n");
c = s_getc(socket); c = s_getc();
} }
} }
s_putstring(socket, "Enter the conference number: "); s_printf("Enter the conference number: ");
s_readstring(socket, buffer, 5); s_readstring(buffer, 5);
if (tolower(buffer[0]) != 'q') { if (tolower(buffer[0]) != 'q') {
j = atoi(buffer); j = atoi(buffer);
if (j < 0 || j >= conf.mail_conference_count || conf.mail_conferences[j]->sec_level > user->sec_level) { if (j < 0 || j >= conf.mail_conference_count || conf.mail_conferences[j]->sec_level > user->sec_level) {
s_putstring(socket, "\r\nInvalid conference number!\r\n"); s_printf("\r\nInvalid conference number!\r\n");
} else { } else {
s_putstring(socket, "\r\n"); s_printf("\r\n");
user->cur_mail_conf = j; user->cur_mail_conf = j;
user->cur_mail_area = 0; user->cur_mail_area = 0;
} }
@ -1719,25 +1698,24 @@ int mail_menu(int socket, struct user_record *user) {
break; break;
case 'a': case 'a':
{ {
s_putstring(socket, "\r\n\r\nMail Areas:\r\n\r\n"); s_printf("\r\n\r\nMail Areas:\r\n\r\n");
for (i=0;i<conf.mail_conferences[user->cur_mail_conf]->mail_area_count;i++) { for (i=0;i<conf.mail_conferences[user->cur_mail_conf]->mail_area_count;i++) {
if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->read_sec_level <= user->sec_level) { if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->read_sec_level <= user->sec_level) {
sprintf(buffer, " %d. %s\r\n", i, conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->name); s_printf(" %d. %s\r\n", i, conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->name);
s_putstring(socket, buffer);
} }
if (i != 0 && i % 20 == 0) { if (i != 0 && i % 20 == 0) {
s_putstring(socket, "Press any key to continue...\r\n"); s_printf("Press any key to continue...\r\n");
c = s_getc(socket); c = s_getc();
} }
} }
s_putstring(socket, "Enter the area number: "); s_printf("Enter the area number: ");
s_readstring(socket, buffer, 5); s_readstring(buffer, 5);
if (tolower(buffer[0]) != 'q') { if (tolower(buffer[0]) != 'q') {
j = atoi(buffer); j = atoi(buffer);
if (j < 0 || j >= conf.mail_conferences[user->cur_mail_conf]->mail_area_count || conf.mail_conferences[user->cur_mail_conf]->mail_areas[j]->read_sec_level > user->sec_level) { if (j < 0 || j >= conf.mail_conferences[user->cur_mail_conf]->mail_area_count || conf.mail_conferences[user->cur_mail_conf]->mail_areas[j]->read_sec_level > user->sec_level) {
s_putstring(socket, "\r\nInvalid area number!\r\n"); s_printf("\r\nInvalid area number!\r\n");
} else { } else {
s_putstring(socket, "\r\n"); s_printf("\r\n");
user->cur_mail_area = j; user->cur_mail_area = j;
} }
} }
@ -1750,8 +1728,8 @@ int mail_menu(int socket, struct user_record *user) {
break; break;
case 'g': case 'g':
{ {
s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)"); s_printf("\r\nAre you sure you want to log off? (Y/N)");
c = s_getc(socket); c = s_getc();
if (tolower(c) == 'y') { if (tolower(c) == 'y') {
domail = 1; domail = 1;
doquit = 1; doquit = 1;
@ -1760,14 +1738,14 @@ int mail_menu(int socket, struct user_record *user) {
break; break;
case 'e': case 'e':
{ {
send_email(socket, user); send_email(user);
} }
break; break;
case 'r': case 'r':
{ {
// Read your email... // Read your email...
s_putstring(socket, "\r\n"); s_printf("\r\n");
list_emails(socket, user); list_emails(user);
} }
break; break;
case '}': case '}':
@ -1832,7 +1810,7 @@ int mail_menu(int socket, struct user_record *user) {
return doquit; return doquit;
} }
void mail_scan(int socket, struct user_record *user) { void mail_scan(struct user_record *user) {
s_JamBase *jb; s_JamBase *jb;
s_JamBaseHeader jbh; s_JamBaseHeader jbh;
s_JamLastRead jlr; s_JamLastRead jlr;
@ -1843,16 +1821,15 @@ void mail_scan(int socket, struct user_record *user) {
char buffer[256]; char buffer[256];
int count; int count;
s_putstring(socket, "\r\nScan for new mail? (Y/N) : "); s_printf("\r\nScan for new mail? (Y/N) : ");
c = s_getc(socket); c = s_getc();
if (tolower(c) == 'y') { if (tolower(c) == 'y') {
for (i=0;i<conf.mail_conference_count;i++) { for (i=0;i<conf.mail_conference_count;i++) {
if (conf.mail_conferences[i]->sec_level > user->sec_level) { if (conf.mail_conferences[i]->sec_level > user->sec_level) {
continue; continue;
} }
sprintf(buffer, "\r\n%d. %s\r\n", i, conf.mail_conferences[i]->name); s_printf("\r\n%d. %s\r\n", i, conf.mail_conferences[i]->name);
s_putstring(socket, buffer);
for (j=0;j<conf.mail_conferences[i]->mail_area_count;j++) { for (j=0;j<conf.mail_conferences[i]->mail_area_count;j++) {
if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level > user->sec_level) { if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level > user->sec_level) {
continue; continue;
@ -1871,21 +1848,19 @@ void mail_scan(int socket, struct user_record *user) {
JAM_CloseMB(jb); JAM_CloseMB(jb);
continue; continue;
} }
sprintf(buffer, " --> %d. %s (%d new)\r\n", j, conf.mail_conferences[i]->mail_areas[j]->name, jbh.ActiveMsgs); s_printf(" --> %d. %s (%d new)\r\n", j, conf.mail_conferences[i]->mail_areas[j]->name, jbh.ActiveMsgs);
} else { } else {
if (jlr.HighReadMsg < (jbh.ActiveMsgs - 1)) { if (jlr.HighReadMsg < (jbh.ActiveMsgs - 1)) {
sprintf(buffer, " --> %d. %s (%d new)\r\n", j, conf.mail_conferences[i]->mail_areas[j]->name, (jbh.ActiveMsgs - 1) - jlr.HighReadMsg); s_printf(" --> %d. %s (%d new)\r\n", j, conf.mail_conferences[i]->mail_areas[j]->name, (jbh.ActiveMsgs - 1) - jlr.HighReadMsg);
} else { } else {
JAM_CloseMB(jb); JAM_CloseMB(jb);
continue; continue;
} }
} }
s_putstring(socket, buffer);
JAM_CloseMB(jb); JAM_CloseMB(jb);
} }
} }
sprintf(buffer, "\r\nPress any key to continue...\r\n"); s_printf("\r\nPress any key to continue...\r\n");
s_putstring(socket, buffer); s_getc();
s_getc(socket);
} }
} }

View File

@ -10,7 +10,7 @@
extern struct bbs_config conf; extern struct bbs_config conf;
void main_menu(int socket, struct user_record *user) { void main_menu(struct user_record *user) {
int doquit = 0; int doquit = 0;
char c; char c;
char prompt[128]; char prompt[128];
@ -45,13 +45,12 @@ void main_menu(int socket, struct user_record *user) {
while (!doquit) { while (!doquit) {
if (do_internal_menu == 1) { if (do_internal_menu == 1) {
s_displayansi(socket, "mainmenu"); s_displayansi("mainmenu");
sprintf(prompt, "\r\n\e[0mTL: %dm :> ", user->timeleft); s_printf("\r\n\e[0mTL: %dm :> ", user->timeleft);
s_putstring(socket, prompt);
c = s_getc(socket); c = s_getc();
} else { } else {
lua_getglobal(L, "menu"); lua_getglobal(L, "menu");
result = lua_pcall(L, 0, 1, 0); result = lua_pcall(L, 0, 1, 0);
@ -77,49 +76,48 @@ void main_menu(int socket, struct user_record *user) {
if (conf.text_file_count > 0) { if (conf.text_file_count > 0) {
while(1) { while(1) {
s_putstring(socket, "\r\n\e[1;32mText Files Collection\r\n"); s_printf("\r\n\e[1;32mText Files Collection\r\n");
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
for (i=0;i<conf.text_file_count;i++) { for (i=0;i<conf.text_file_count;i++) {
sprintf(buffer, "\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;37m%s\r\n", i, conf.text_files[i]->name); s_printf("\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;37m%s\r\n", i, conf.text_files[i]->name);
s_putstring(socket, buffer);
} }
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
s_putstring(socket, "Enter the number of a text file to display or Q to quit: "); s_printf("Enter the number of a text file to display or Q to quit: ");
s_readstring(socket, buffer, 4); s_readstring(buffer, 4);
if (tolower(buffer[0]) != 'q') { if (tolower(buffer[0]) != 'q') {
i = atoi(buffer); i = atoi(buffer);
if (i >= 0 && i < conf.text_file_count) { if (i >= 0 && i < conf.text_file_count) {
s_putstring(socket, "\r\n"); s_printf("\r\n");
s_displayansi_p(socket, conf.text_files[i]->path); s_displayansi_p(conf.text_files[i]->path);
s_putstring(socket, "Press any key to continue..."); s_printf("Press any key to continue...");
s_getc(socket); s_getc();
s_putstring(socket, "\r\n"); s_printf("\r\n");
} }
} else { } else {
break; break;
} }
} }
} else { } else {
s_putstring(socket, "\r\nSorry, there are no text files to display\r\n"); s_printf("\r\nSorry, there are no text files to display\r\n");
s_putstring(socket, "Press any key to continue...\r\n"); s_printf("Press any key to continue...\r\n");
s_getc(socket); s_getc();
} }
} }
break; break;
case 'c': case 'c':
{ {
chat_system(socket, user); chat_system(user);
} }
break; break;
case 'l': case 'l':
{ {
bbs_list(socket, user); bbs_list(user);
} }
break; break;
case 'u': case 'u':
{ {
list_users(socket, user); list_users(user);
} }
break; break;
case 'b': case 'b':
@ -129,10 +127,9 @@ 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(buffer);
sprintf(buffer, "\e[0mPress any key to continue...\r\n"); s_printf("\e[0mPress any key to continue...\r\n");
s_putstring(socket, buffer); s_getc();
s_getc(socket);
i++; i++;
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
} }
@ -140,23 +137,23 @@ void main_menu(int socket, struct user_record *user) {
break; break;
case '1': case '1':
{ {
display_last10_callers(socket, user); display_last10_callers(user);
} }
break; break;
case 'd': case 'd':
{ {
doquit = door_menu(socket, user); doquit = door_menu(user);
} }
break; break;
case 'm': case 'm':
{ {
doquit = mail_menu(socket, user); doquit = mail_menu(user);
} }
break; break;
case 'g': case 'g':
{ {
s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)"); s_printf("\r\nAre you sure you want to log off? (Y/N)");
c = s_getc(socket); c = s_getc();
if (tolower(c) == 'y') { if (tolower(c) == 'y') {
doquit = 1; doquit = 1;
} }
@ -164,12 +161,12 @@ void main_menu(int socket, struct user_record *user) {
break; break;
case 't': case 't':
{ {
doquit = file_menu(socket, user); doquit = file_menu(user);
} }
break; break;
case 's': case 's':
{ {
settings_menu(socket, user); settings_menu(user);
} }
break; break;
} }

View File

@ -4,32 +4,31 @@
#include <ctype.h> #include <ctype.h>
#include "bbs.h" #include "bbs.h"
void settings_menu(int sock, struct user_record *user) { void settings_menu(struct user_record *user) {
char buffer[256]; char buffer[256];
int dosettings = 0; int dosettings = 0;
char c; char c;
char *hash; char *hash;
while (!dosettings) { while (!dosettings) {
s_putstring(sock, "\e[2J\e[1;32mYour Settings\r\n"); s_printf("\e[2J\e[1;32mYour Settings\r\n");
s_putstring(sock, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
s_putstring(sock, "\e[0;36mP. \e[1;37mPassword (\e[1;33mNot Shown\e[1;37m)\r\n"); s_printf("\e[0;36mP. \e[1;37mPassword (\e[1;33mNot Shown\e[1;37m)\r\n");
sprintf(buffer, "\e[0;36mL. \e[1;37mLocation (\e[1;33m%s\e[1;37m)\r\n", user->location); s_printf("\e[0;36mL. \e[1;37mLocation (\e[1;33m%s\e[1;37m)\r\n", user->location);
s_putstring(sock, buffer); s_printf("\e[0;36mQ. \e[1;37mQuit to Main Menu\r\n");
s_putstring(sock, "\e[0;36mQ. \e[1;37mQuit to Main Menu\r\n"); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
s_putstring(sock, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
c = s_getc(sock); c = s_getc();
switch(tolower(c)) { switch(tolower(c)) {
case 'p': case 'p':
{ {
s_putstring(sock, "\r\nEnter your current password: "); s_printf("\r\nEnter your current password: ");
s_readpass(sock, buffer, 16); s_readpass(buffer, 16);
hash = hash_sha256(buffer, user->salt); hash = hash_sha256(buffer, user->salt);
if (strcmp(hash, user->password) == 0) { if (strcmp(hash, user->password) == 0) {
s_putstring(sock, "\r\nEnter your new password (8 chars min): "); s_printf("\r\nEnter your new password (8 chars min): ");
s_readstring(sock, buffer, 16); s_readstring(buffer, 16);
if (strlen(buffer) >= 8) { if (strlen(buffer) >= 8) {
free(user->password); free(user->password);
free(user->salt); free(user->salt);
@ -38,19 +37,19 @@ void settings_menu(int sock, struct user_record *user) {
user->password = hash_sha256(buffer, user->salt); user->password = hash_sha256(buffer, user->salt);
save_user(user); save_user(user);
s_putstring(sock, "\r\nPassword Changed!\r\n"); s_printf("\r\nPassword Changed!\r\n");
} else { } else {
s_putstring(sock, "\r\nPassword too short!\r\n"); s_printf("\r\nPassword too short!\r\n");
} }
} else { } else {
s_putstring(sock, "\r\nPassword Incorrect!\r\n"); s_printf("\r\nPassword Incorrect!\r\n");
} }
} }
break; break;
case 'l': case 'l':
{ {
s_putstring(sock, "\r\nEnter your new location: "); s_printf("\r\nEnter your new location: ");
s_readstring(sock, buffer, 32); s_readstring(buffer, 32);
free(user->location); free(user->location);
user->location = (char *)malloc(strlen(buffer) + 1); user->location = (char *)malloc(strlen(buffer) + 1);
strcpy(user->location, buffer); strcpy(user->location, buffer);

113
users.c
View File

@ -219,7 +219,7 @@ int inst_user(struct user_record *user) {
return 1; return 1;
} }
struct user_record *check_user_pass(int socket, char *loginname, char *password) { struct user_record *check_user_pass(char *loginname, char *password) {
struct user_record *user; struct user_record *user;
char buffer[256]; char buffer[256];
sqlite3 *db; sqlite3 *db;
@ -322,7 +322,7 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password)
return user; return user;
} }
void list_users(int socket, struct user_record *user) { void list_users(struct user_record *user) {
char buffer[256]; char buffer[256];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
@ -346,29 +346,26 @@ void list_users(int socket, struct user_record *user) {
sqlite3_close(db); sqlite3_close(db);
exit(1); exit(1);
} }
s_putstring(socket, "\e[2J\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); s_printf("\e[2J\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
s_putstring(socket, "User Name Location Times On\r\n"); s_printf("User Name Location Times On\r\n");
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
i = 0; i = 0;
while (sqlite3_step(res) == SQLITE_ROW) { while (sqlite3_step(res) == SQLITE_ROW) {
sprintf(buffer, "\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%5d\r\n", sqlite3_column_text(res, 0), sqlite3_column_text(res, 1), sqlite3_column_int(res, 2)); s_printf("\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%5d\r\n", sqlite3_column_text(res, 0), sqlite3_column_text(res, 1), sqlite3_column_int(res, 2));
s_putstring(socket, buffer);
i++; i++;
if (i == 20) { if (i == 20) {
sprintf(buffer, "Press any key to continue...\r\n"); s_printf("Press any key to continue...\r\n");
s_putstring(socket, buffer); s_getc();
s_getc(socket);
i = 0; i = 0;
} }
} }
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
sqlite3_finalize(res); sqlite3_finalize(res);
sqlite3_close(db); sqlite3_close(db);
sprintf(buffer, "Press any key to continue...\r\n"); s_printf("Press any key to continue...\r\n");
s_putstring(socket, buffer); s_getc();
s_getc(socket);
} }
int check_user(char *loginname) { int check_user(char *loginname) {
@ -409,7 +406,7 @@ int check_user(char *loginname) {
return 1; return 1;
} }
struct user_record *new_user(int socket) { struct user_record *new_user() {
char buffer[256]; char buffer[256];
struct user_record *user; struct user_record *user;
int done = 0; int done = 0;
@ -419,24 +416,24 @@ struct user_record *new_user(int socket) {
int i; int i;
user = (struct user_record *)malloc(sizeof(struct user_record)); user = (struct user_record *)malloc(sizeof(struct user_record));
s_putstring(socket, "\r\n\r\n"); s_printf("\r\n\r\n");
s_displayansi(socket, "newuser"); s_displayansi("newuser");
do { do {
passok = 0; passok = 0;
nameok = 0; nameok = 0;
do { do {
s_putstring(socket, "\r\nWhat is your login name: "); s_printf("\r\nWhat is your login name: ");
s_readstring(socket, buffer, 16); s_readstring(buffer, 16);
s_putstring(socket, "\r\n"); s_printf("\r\n");
if (strlen(buffer) < 3) { if (strlen(buffer) < 3) {
s_putstring(socket, "Sorry, that name is too short.\r\n"); s_printf("Sorry, that name is too short.\r\n");
continue; continue;
} }
for (i=0;i<strlen(buffer);i++) { for (i=0;i<strlen(buffer);i++) {
if (!(tolower(buffer[i]) >= 97 && tolower(buffer[i]) <= 122)) { if (!(tolower(buffer[i]) >= 97 && tolower(buffer[i]) <= 122)) {
s_putstring(socket, "Sorry, invalid character, can only use alpha characters.\r\n"); s_printf("Sorry, invalid character, can only use alpha characters.\r\n");
nameok = 1; nameok = 1;
break; break;
} }
@ -446,80 +443,80 @@ struct user_record *new_user(int socket) {
continue; continue;
} }
if (strcasecmp(buffer, "unknown") == 0) { if (strcasecmp(buffer, "unknown") == 0) {
s_putstring(socket, "Sorry, that name is reserved.\r\n"); s_printf("Sorry, that name is reserved.\r\n");
continue; continue;
} }
if (strcasecmp(buffer, "all") == 0) { if (strcasecmp(buffer, "all") == 0) {
s_putstring(socket, "Sorry, that name is reserved.\r\n"); s_printf("Sorry, that name is reserved.\r\n");
continue; continue;
} }
if (strcasecmp(buffer, "new") == 0) { if (strcasecmp(buffer, "new") == 0) {
s_putstring(socket, "Sorry, that name is reserved.\r\n"); s_printf("Sorry, that name is reserved.\r\n");
continue; continue;
} }
user->loginname = strdup(buffer); user->loginname = strdup(buffer);
nameok = check_user(user->loginname); nameok = check_user(user->loginname);
if (!nameok) { if (!nameok) {
s_putstring(socket, "Sorry, that name is in use.\r\n"); s_printf("Sorry, that name is in use.\r\n");
free(user->loginname); free(user->loginname);
memset(buffer, 0, 256); memset(buffer, 0, 256);
} }
} while (!nameok); } while (!nameok);
s_putstring(socket, "What is your first name: "); s_printf("What is your first name: ");
memset(buffer, 0, 256); memset(buffer, 0, 256);
s_readstring(socket, buffer, 32); s_readstring(buffer, 32);
s_putstring(socket, "\r\n"); s_printf("\r\n");
user->firstname = strdup(buffer); user->firstname = strdup(buffer);
s_putstring(socket, "What is your last name: "); s_printf("What is your last name: ");
memset(buffer, 0, 256); memset(buffer, 0, 256);
s_readstring(socket, buffer, 32); s_readstring(buffer, 32);
s_putstring(socket, "\r\n"); s_printf("\r\n");
user->lastname = strdup(buffer); user->lastname = strdup(buffer);
s_putstring(socket, "What is your e-mail address: "); s_printf("What is your e-mail address: ");
memset(buffer, 0, 256); memset(buffer, 0, 256);
s_readstring(socket, buffer, 64); s_readstring(buffer, 64);
s_putstring(socket, "\r\n"); s_printf("\r\n");
user->email = strdup(buffer); user->email = strdup(buffer);
s_putstring(socket, "Where are you located: "); s_printf("Where are you located: ");
memset(buffer, 0, 256); memset(buffer, 0, 256);
s_readstring(socket, buffer, 32); s_readstring(buffer, 32);
s_putstring(socket, "\r\n"); s_printf("\r\n");
user->location = strdup(buffer); user->location = strdup(buffer);
do { do {
s_putstring(socket, "What password would you like (at least 8 characters): "); s_printf("What password would you like (at least 8 characters): ");
memset(buffer, 0, 256); memset(buffer, 0, 256);
s_readstring(socket, buffer, 16); s_readstring(buffer, 16);
s_putstring(socket, "\r\n"); s_printf("\r\n");
if (strlen(buffer) >= 8) { if (strlen(buffer) >= 8) {
passok = 1; passok = 1;
} else { } else {
s_putstring(socket, "Password too short!\r\n"); s_printf("Password too short!\r\n");
} }
} while (!passok); } while (!passok);
gen_salt(&user->salt); gen_salt(&user->salt);
user->password = hash_sha256(buffer, user->salt); user->password = hash_sha256(buffer, user->salt);
s_putstring(socket, "You Entered:\r\n"); s_printf("You Entered:\r\n");
s_putstring(socket, "-------------------------------------\r\n"); s_printf("-------------------------------------\r\n");
s_putstring(socket, "Login Name: "); s_printf("Login Name: ");
s_putstring(socket, user->loginname); s_printf(user->loginname);
s_putstring(socket, "\r\nFirst Name: "); s_printf("\r\nFirst Name: ");
s_putstring(socket, user->firstname); s_printf(user->firstname);
s_putstring(socket, "\r\nLast Name: "); s_printf("\r\nLast Name: ");
s_putstring(socket, user->lastname); s_printf(user->lastname);
s_putstring(socket, "\r\nE-mail: "); s_printf("\r\nE-mail: ");
s_putstring(socket, user->email); s_printf(user->email);
s_putstring(socket, "\r\nLocation: "); s_printf("\r\nLocation: ");
s_putstring(socket, user->location); s_printf(user->location);
s_putstring(socket, "\r\n-------------------------------------\r\n"); s_printf("\r\n-------------------------------------\r\n");
s_putstring(socket, "Is this Correct? (Y/N)"); s_printf("Is this Correct? (Y/N)");
c = s_getchar(socket); c = s_getchar();
while (tolower(c) != 'y' && tolower(c) != 'n') { while (tolower(c) != 'y' && tolower(c) != 'n') {
c = s_getchar(socket); c = s_getchar();
} }
if (tolower(c) == 'y') { if (tolower(c) == 'y') {