Added External Editor support
This commit is contained in:
parent
aa0185000a
commit
0a837a6806
9
bbs.c
9
bbs.c
@ -305,6 +305,14 @@ static int handler(void* user, const char* section, const char* name,
|
||||
conf->irc_channel = strdup(value);
|
||||
} else if (strcasecmp(name, "default tagline") == 0) {
|
||||
conf->default_tagline = strdup(value);
|
||||
} else if (strcasecmp(name, "external editor cmd") == 0) {
|
||||
conf->external_editor_cmd = strdup(value);
|
||||
} else if (strcasecmp(name, "external editor stdio") == 0) {
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
conf->external_editor_stdio = 1;
|
||||
} else {
|
||||
conf->external_editor_stdio = 0;
|
||||
}
|
||||
}
|
||||
} else if (strcasecmp(section, "paths") == 0){
|
||||
if (strcasecmp(name, "ansi path") == 0) {
|
||||
@ -619,6 +627,7 @@ void runbbs(int socket, char *config_path) {
|
||||
conf.irc_server = NULL;
|
||||
conf.irc_port = 6667;
|
||||
conf.text_file_count = 0;
|
||||
conf.external_editor_cmd = NULL;
|
||||
|
||||
// Load BBS data
|
||||
if (ini_parse(config_path, handler, &conf) <0) {
|
||||
|
5
bbs.h
5
bbs.h
@ -90,6 +90,9 @@ struct bbs_config {
|
||||
int irc_port;
|
||||
char *irc_channel;
|
||||
|
||||
char *external_editor_cmd;
|
||||
int external_editor_stdio;
|
||||
|
||||
int nodes;
|
||||
int newuserlvl;
|
||||
int mail_conference_count;
|
||||
@ -150,8 +153,10 @@ extern void main_menu(int socket, struct user_record *user);
|
||||
extern void mail_scan(int socket, struct user_record *user);
|
||||
extern int mail_menu(int socket, struct user_record *user);
|
||||
extern char *editor(int socket, struct user_record *user, char *quote, char *from);
|
||||
extern char *external_editor(int socket, 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 void rundoor(int socket, struct user_record *user, char *cmd, int stdio);
|
||||
|
||||
extern void bbs_list(int socket, struct user_record *user);
|
||||
|
||||
|
@ -7,6 +7,8 @@ IRC Server = localhost
|
||||
IRC Port = 6667
|
||||
IRC Channel = #bbs
|
||||
Default Tagline = Brought to you by Another Magicka BBS!
|
||||
External Editor cmd = /home/andrew/MagickaBBS/doors/oedit.sh
|
||||
External Editor stdio = false
|
||||
|
||||
[paths]
|
||||
ANSI Path = /home/andrew/MagickaBBS/ansis
|
||||
|
267
doors.c
267
doors.c
@ -1,267 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ioctl.h>
|
||||
#if defined(linux)
|
||||
# include <pty.h>
|
||||
#elif defined(__OpenBSD__) || defined(__NetBSD__)
|
||||
# include <util.h>
|
||||
#else
|
||||
# include <libutil.h>
|
||||
#endif
|
||||
#include "bbs.h"
|
||||
|
||||
extern struct bbs_config conf;
|
||||
extern int mynode;
|
||||
|
||||
int running_door_pid = 0;
|
||||
int running_door = 0;
|
||||
|
||||
void doorchld_handler(int s)
|
||||
{
|
||||
// waitpid() might overwrite errno, so we save and restore it:
|
||||
while(waitpid(-1, NULL, WNOHANG) > 0);
|
||||
|
||||
running_door = 0;
|
||||
}
|
||||
|
||||
int write_door32sys(int socket, struct user_record *user) {
|
||||
struct stat s;
|
||||
char buffer[256];
|
||||
FILE *fptr;
|
||||
char *ptr;
|
||||
int i;
|
||||
|
||||
sprintf(buffer, "%s/node%d", conf.bbs_path, mynode);
|
||||
|
||||
if (stat(buffer, &s) != 0) {
|
||||
mkdir(buffer, 0755);
|
||||
}
|
||||
|
||||
sprintf(buffer, "%s/node%d/door32.sys", conf.bbs_path, mynode);
|
||||
|
||||
fptr = fopen(buffer, "w");
|
||||
|
||||
if (!fptr) {
|
||||
printf("Unable to open %s for writing!\n", buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(fptr, "2\n"); // telnet type
|
||||
fprintf(fptr, "%d\n", socket); // socket
|
||||
fprintf(fptr, "38400\n"); // baudrate
|
||||
fprintf(fptr, "Magicka %d.%d\n", VERSION_MAJOR, VERSION_MINOR);
|
||||
fprintf(fptr, "%d\n", user->id);
|
||||
fprintf(fptr, "%s %s\n", user->firstname, user->lastname);
|
||||
fprintf(fptr, "%s\n", user->loginname);
|
||||
fprintf(fptr, "%d\n", user->sec_level);
|
||||
fprintf(fptr, "%d\n", user->timeleft);
|
||||
fprintf(fptr, "1\n"); // ansi emulation = 1
|
||||
fprintf(fptr, "%d\n", mynode);
|
||||
|
||||
fclose(fptr);
|
||||
|
||||
// create dorinfo1.def
|
||||
|
||||
sprintf(buffer, "%s/node%d", conf.bbs_path, mynode);
|
||||
|
||||
if (stat(buffer, &s) != 0) {
|
||||
mkdir(buffer, 0755);
|
||||
}
|
||||
|
||||
sprintf(buffer, "%s/node%d/dorinfo1.def", conf.bbs_path, mynode);
|
||||
|
||||
fptr = fopen(buffer, "w");
|
||||
|
||||
if (!fptr) {
|
||||
printf("Unable to open %s for writing!\n", buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
strcpy(buffer, conf.sysop_name);
|
||||
|
||||
ptr = NULL;
|
||||
|
||||
for (i=0;i<strlen(buffer);i++) {
|
||||
if (buffer[i] == ' ') {
|
||||
ptr = &buffer[i+1];
|
||||
buffer[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(fptr, "%s\n", conf.bbs_name); // telnet type
|
||||
fprintf(fptr, "%s\n", buffer);
|
||||
if (ptr != NULL) {
|
||||
fprintf(fptr, "%s\n", ptr);
|
||||
} else {
|
||||
fprintf(fptr, "\n");
|
||||
}
|
||||
fprintf(fptr, "COM1\n"); // com port
|
||||
fprintf(fptr, "38400 BAUD,N,8,1\n");
|
||||
fprintf(fptr, "0\n");
|
||||
fprintf(fptr, "%s\n", user->firstname);
|
||||
fprintf(fptr, "%s\n", user->lastname);
|
||||
fprintf(fptr, "%s\n", user->location);
|
||||
fprintf(fptr, "1\n");
|
||||
fprintf(fptr, "30\n");
|
||||
fprintf(fptr, "%d\n", user->timeleft);
|
||||
fprintf(fptr, "-1\n");
|
||||
|
||||
|
||||
fclose(fptr);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
|
||||
char buffer[256];
|
||||
int pid;
|
||||
char *arguments[4];
|
||||
int ret;
|
||||
char c;
|
||||
int len;
|
||||
int status;
|
||||
int master;
|
||||
int slave;
|
||||
fd_set fdset;
|
||||
int t;
|
||||
struct winsize ws;
|
||||
struct sigaction sa;
|
||||
|
||||
if (write_door32sys(socket, user) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stdio) {
|
||||
|
||||
arguments[0] = strdup(cmd);
|
||||
sprintf(buffer, "%d", mynode);
|
||||
arguments[1] = strdup(buffer);
|
||||
sprintf(buffer, "%d", socket);
|
||||
arguments[2] = strdup(buffer);
|
||||
arguments[3] = NULL;
|
||||
|
||||
ws.ws_row = 24;
|
||||
ws.ws_col = 80;
|
||||
|
||||
running_door = 1;
|
||||
|
||||
if (openpty(&master, &slave, NULL, NULL, &ws) == 0) {
|
||||
sa.sa_handler = doorchld_handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_RESTART;
|
||||
if (sigaction(SIGCHLD, &sa, NULL) == -1) {
|
||||
perror("sigaction");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
return;
|
||||
} else if (pid == 0) {
|
||||
|
||||
close(master);
|
||||
dup2(slave, 0);
|
||||
dup2(slave, 1);
|
||||
|
||||
close(slave);
|
||||
|
||||
setsid();
|
||||
|
||||
ioctl(0, TIOCSCTTY, 1);
|
||||
|
||||
execvp(cmd, arguments);
|
||||
} else {
|
||||
running_door_pid = pid;
|
||||
|
||||
while(running_door != 0) {
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(master, &fdset);
|
||||
FD_SET(socket, &fdset);
|
||||
if (master > socket) {
|
||||
t = master + 1;
|
||||
} else {
|
||||
t = socket + 1;
|
||||
}
|
||||
ret = select(t, &fdset, NULL, NULL, NULL);
|
||||
if (ret > 0) {
|
||||
if (FD_ISSET(socket, &fdset)) {
|
||||
len = read(socket, &c, 1);
|
||||
if (len == 0) {
|
||||
close(master);
|
||||
disconnect(socket);
|
||||
return;
|
||||
}
|
||||
write(master, &c, 1);
|
||||
} else if (FD_ISSET(master, &fdset)) {
|
||||
len = read(master, &c, 1);
|
||||
if (len == 0) {
|
||||
close(master);
|
||||
break;
|
||||
}
|
||||
write(socket, &c, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(arguments[0]);
|
||||
free(arguments[1]);
|
||||
free(arguments[2]);
|
||||
} else {
|
||||
sprintf(buffer, "%s %d %d", cmd, mynode, socket);
|
||||
system(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
int door_menu(int socket, struct user_record *user) {
|
||||
int doquit = 0;
|
||||
int dodoors = 0;
|
||||
char prompt[128];
|
||||
int i;
|
||||
char c;
|
||||
while (!dodoors) {
|
||||
s_displayansi(socket, "doors");
|
||||
|
||||
sprintf(prompt, "\e[0m\r\nTL: %dm :> ", user->timeleft);
|
||||
s_putstring(socket, prompt);
|
||||
|
||||
c = s_getc(socket);
|
||||
|
||||
switch(tolower(c)) {
|
||||
case 'q':
|
||||
dodoors = 1;
|
||||
break;
|
||||
case 'g':
|
||||
{
|
||||
s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)");
|
||||
c = s_getc(socket);
|
||||
if (tolower(c) == 'y') {
|
||||
doquit = 1;
|
||||
dodoors = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
for (i=0;i<conf.door_count;i++) {
|
||||
if (tolower(c) == tolower(conf.doors[i]->key)) {
|
||||
rundoor(socket, user, conf.doors[i]->command, conf.doors[i]->stdio);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return doquit;
|
||||
}
|
6
email.c
6
email.c
@ -50,7 +50,7 @@ void send_email(int socket, struct user_record *user) {
|
||||
subject = strdup(buffer);
|
||||
|
||||
// post a message
|
||||
msg = editor(socket, user, NULL, NULL);
|
||||
msg = external_editor(socket, user, user->loginname, recipient, NULL, NULL, subject, 1);
|
||||
|
||||
if (msg != NULL) {
|
||||
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
||||
@ -188,8 +188,8 @@ void show_email(int socket, struct user_record *user, int msgno) {
|
||||
subject = (char *)malloc(strlen(buffer) + 1);
|
||||
strcpy(subject, buffer);
|
||||
|
||||
replybody = editor(socket, user, body, sender);
|
||||
|
||||
//replybody = editor(socket, user, body, sender);
|
||||
replybody = external_editor(socket, user, user->loginname, sender, body, sender, subject, 1);
|
||||
if (replybody != NULL) {
|
||||
rc = sqlite3_prepare_v2(db, isql, -1, &res, 0);
|
||||
|
||||
|
115
mail_menu.c
115
mail_menu.c
@ -4,11 +4,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "jamlib/jam.h"
|
||||
#include "bbs.h"
|
||||
|
||||
extern struct bbs_config conf;
|
||||
|
||||
extern int mynode;
|
||||
struct jam_msg {
|
||||
int msg_no;
|
||||
s_JamMsgHeader *msg_h;
|
||||
@ -255,6 +256,113 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r
|
||||
return msghs;
|
||||
}
|
||||
|
||||
char *external_editor(int socket, struct user_record *user, char *to, char *from, char *quote, char *qfrom, char *subject, int email) {
|
||||
char c;
|
||||
FILE *fptr;
|
||||
char *body = NULL;
|
||||
char buffer[256];
|
||||
int len;
|
||||
int totlen;
|
||||
char *body2 = NULL;
|
||||
char *tagline;
|
||||
int i;
|
||||
int j;
|
||||
struct stat s;
|
||||
|
||||
if (conf.external_editor_cmd != NULL) {
|
||||
s_putstring(socket, "\r\nUse external editor? (Y/N) ");
|
||||
c = s_getc(socket);
|
||||
if (tolower(c) == 'y') {
|
||||
|
||||
sprintf(buffer, "%s/node%d/MSGTMP", conf.bbs_path, mynode);
|
||||
|
||||
if (stat(buffer, &s) == 0) {
|
||||
remove(buffer);
|
||||
}
|
||||
|
||||
// write msgtemp
|
||||
if (quote != NULL) {
|
||||
fptr = fopen(buffer, "w");
|
||||
fwrite(quote, strlen(quote), 1, fptr);
|
||||
fclose(fptr);
|
||||
}
|
||||
sprintf(buffer, "%s/node%d/MSGINF", conf.bbs_path, mynode);
|
||||
fptr = fopen(buffer, "w");
|
||||
fprintf(fptr, "%s\r\n", user->loginname);
|
||||
fprintf(fptr, "%s\r\n", to);
|
||||
fprintf(fptr, "%s\r\n", subject);
|
||||
fprintf(fptr, "0\r\n");
|
||||
if (email == 1) {
|
||||
fprintf(fptr, "E-Mail\r\n");
|
||||
fprintf(fptr, "YES\r\n");
|
||||
} else {
|
||||
fprintf(fptr, "%s\r\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name);
|
||||
if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA){
|
||||
fprintf(fptr, "YES\r\n");
|
||||
} else {
|
||||
fprintf(fptr, "NO\r\n");
|
||||
}
|
||||
}
|
||||
fclose(fptr);
|
||||
|
||||
rundoor(socket, user, conf.external_editor_cmd, conf.external_editor_stdio);
|
||||
|
||||
// readin msgtmp
|
||||
sprintf(buffer, "%s/node%d/MSGTMP", conf.bbs_path, mynode);
|
||||
fptr = fopen(buffer, "r");
|
||||
if (!fptr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
totlen = 0;
|
||||
len = fread(buffer, 1, 256, fptr);
|
||||
while (len > 0) {
|
||||
totlen += len;
|
||||
if (body == NULL) {
|
||||
body = (char *)malloc(totlen + 1);
|
||||
} else {
|
||||
body = (char *)realloc(body, totlen + 1);
|
||||
}
|
||||
|
||||
memcpy(&body[totlen - len], buffer, len);
|
||||
body[totlen] = '\0';
|
||||
|
||||
len = fread(buffer, 1, 256, fptr);
|
||||
}
|
||||
|
||||
fclose(fptr);
|
||||
|
||||
if (email == 1) {
|
||||
tagline = conf.default_tagline;
|
||||
} else {
|
||||
if (conf.mail_conferences[user->cur_mail_conf]->tagline != NULL) {
|
||||
tagline = conf.mail_conferences[user->cur_mail_conf]->tagline;
|
||||
} else {
|
||||
tagline = conf.default_tagline;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
body2 = (char *)malloc(strlen(body) + 19 + strlen(tagline));
|
||||
|
||||
j = 0;
|
||||
|
||||
for (i=0;i<strlen(body);i++) {
|
||||
if (body[i] == '\n') {
|
||||
continue;
|
||||
}
|
||||
body2[j++] = body[i];
|
||||
}
|
||||
|
||||
sprintf(buffer, "\r---\r * Origin: %s \r", tagline);
|
||||
strcat(body2, buffer);
|
||||
|
||||
return body2;
|
||||
}
|
||||
}
|
||||
return editor(socket, user, quote, qfrom);
|
||||
}
|
||||
|
||||
char *editor(int socket, struct user_record *user, char *quote, char *from) {
|
||||
int lines = 0;
|
||||
char buffer[256];
|
||||
@ -272,6 +380,7 @@ char *editor(int socket, struct user_record *user, char *quote, char *from) {
|
||||
int z;
|
||||
char *tagline;
|
||||
|
||||
|
||||
if (quote != NULL) {
|
||||
for (i=0;i<strlen(quote);i++) {
|
||||
|
||||
@ -670,7 +779,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
|
||||
to = (char *)malloc(strlen(buffer) + 1);
|
||||
strcpy(to, buffer);
|
||||
}
|
||||
replybody = editor(socket, user, body, to);
|
||||
replybody = external_editor(socket, user, to, from, body, msghs->msgs[mailno]->from, subject, 0);
|
||||
if (replybody != NULL) {
|
||||
|
||||
jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
|
||||
@ -1007,7 +1116,7 @@ int mail_menu(int socket, struct user_record *user) {
|
||||
subject = strdup(buffer);
|
||||
|
||||
// post a message
|
||||
msg = editor(socket, user, NULL, NULL);
|
||||
replybody = external_editor(socket, user, to, from, NULL, NULL, subject, 0);
|
||||
|
||||
if (msg != NULL) {
|
||||
jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
|
||||
|
Reference in New Issue
Block a user