Big update for uploading with external protocols. May or may not work with SSH,tested with lrzsz
This commit is contained in:
parent
ee0d516d2e
commit
380375bd99
30
bbs.c
30
bbs.c
@ -914,3 +914,33 @@ finish:
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int copy_file(char *src, char *dest) {
|
||||
FILE *src_file;
|
||||
FILE *dest_file;
|
||||
|
||||
char c;
|
||||
|
||||
src_file = fopen(src, "rb");
|
||||
if (!src_file) {
|
||||
return -1;
|
||||
}
|
||||
dest_file = fopen(dest, "wb");
|
||||
if (!dest_file) {
|
||||
fclose(src_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
c = fgetc(src_file);
|
||||
if (!feof(src_file)) {
|
||||
fputc(c, dest_file);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(src_file);
|
||||
fclose(dest_file);
|
||||
return 0;
|
||||
}
|
||||
|
19
bbs.h
19
bbs.h
@ -94,6 +94,15 @@ struct archiver {
|
||||
char *pack;
|
||||
};
|
||||
|
||||
struct protocol {
|
||||
char *name;
|
||||
char *upload;
|
||||
char *download;
|
||||
int internal_zmodem;
|
||||
int stdio;
|
||||
int upload_prompt;
|
||||
};
|
||||
|
||||
struct bbs_config {
|
||||
char *bbs_name;
|
||||
char *bwave_name;
|
||||
@ -141,9 +150,12 @@ struct bbs_config {
|
||||
int text_file_count;
|
||||
struct text_file **text_files;
|
||||
|
||||
char *archiver_path;
|
||||
char *config_path;
|
||||
int archiver_count;
|
||||
struct archiver **archivers;
|
||||
|
||||
int protocol_count;
|
||||
struct protocol **protocols;
|
||||
};
|
||||
|
||||
struct sec_level_t {
|
||||
@ -189,7 +201,7 @@ struct msg_headers {
|
||||
struct jam_msg **msgs;
|
||||
int msg_count;
|
||||
};
|
||||
|
||||
extern int copy_file(char *src, char *dest);
|
||||
extern int recursive_delete(const char *dir);
|
||||
extern void automessage_write(struct user_record *user);
|
||||
extern void automessage_display();
|
||||
@ -234,6 +246,7 @@ extern unsigned long generate_msgid();
|
||||
|
||||
extern int door_menu(struct user_record *user);
|
||||
extern void rundoor(struct user_record *user, char *cmd, int stdio);
|
||||
extern void runexternal(struct user_record *user, char *cmd, int stdio, char **argv, char *cwd, int raw);
|
||||
|
||||
extern void bbs_list(struct user_record *user);
|
||||
|
||||
@ -248,6 +261,8 @@ extern void download_zmodem(struct user_record *user, char *filename);
|
||||
extern void settings_menu(struct user_record *user);
|
||||
extern void upload_zmodem(struct user_record *user, char *upload_p);
|
||||
extern int ttySetRaw(int fd, struct termios *prevTermios);
|
||||
extern int do_upload(struct user_record *user, char *final_path);
|
||||
extern int do_download(struct user_record *user, char *file);
|
||||
|
||||
extern void lua_push_cfunctions(lua_State *L);
|
||||
|
||||
|
17
bluewave.c
17
bluewave.c
@ -357,15 +357,8 @@ void bwave_create_packet() {
|
||||
system(buffer);
|
||||
|
||||
|
||||
if (sshBBS) {
|
||||
ttySetRaw(STDIN_FILENO, &oldit);
|
||||
ttySetRaw(STDOUT_FILENO, &oldot);
|
||||
}
|
||||
download_zmodem(gUser, archive);
|
||||
if (sshBBS) {
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldit);
|
||||
tcsetattr(STDOUT_FILENO, TCSANOW, &oldot);
|
||||
}
|
||||
do_download(gUser, archive);
|
||||
|
||||
snprintf(buffer, 1024, "%s/node%d/bwave", conf.bbs_path, mynode);
|
||||
recursive_delete(buffer);
|
||||
|
||||
@ -586,7 +579,11 @@ void bwave_upload_reply() {
|
||||
}
|
||||
mkdir(buffer, 0755);
|
||||
|
||||
upload_zmodem(gUser, buffer);
|
||||
if (!do_upload(gUser, buffer)) {
|
||||
s_printf(get_string(211));
|
||||
recursive_delete(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
bpos = 0;
|
||||
for (i=0;i<strlen(conf.archivers[gUser->defarchiver-1]->unpack);i++) {
|
||||
|
@ -23,12 +23,12 @@ QWK Name = MAGICKA
|
||||
QWK Max Messages = 5000
|
||||
ZIP Command = zip -j *a *f
|
||||
UNZIP Command = unzip -j -o *a -d *d
|
||||
Archivers = config/archivers.ini
|
||||
Broadcast Enable = false
|
||||
Broadcast Port = 2027
|
||||
Broadcast Address = 192.168.1.255
|
||||
|
||||
[paths]
|
||||
Config Path = /home/andrew/MagickaBBS/config
|
||||
WWW Path = /home/andrew/MagickaBBS/www
|
||||
String File = /home/andrew/MagickaBBS/magicka.strings
|
||||
PID File = /home/andrew/MagickaBBS/magicka.pid
|
||||
|
8
config_default/protocols.ini
Normal file
8
config_default/protocols.ini
Normal file
@ -0,0 +1,8 @@
|
||||
[ZModem]
|
||||
Internal ZModem = true
|
||||
|
||||
[LRZSZ Zmodem]
|
||||
Upload Prompt = false
|
||||
Upload Command = rz -R
|
||||
Download Command = sz *f
|
||||
stdio = true
|
108
doors.c
108
doors.c
@ -128,12 +128,38 @@ int write_door32sys(struct user_record *user) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void rundoor(struct user_record *user, char *cmd, int stdio) {
|
||||
char buffer[256];
|
||||
int pid;
|
||||
char *arguments[4];
|
||||
int door_out;
|
||||
char buffer[10];
|
||||
|
||||
if (sshBBS) {
|
||||
door_out = STDOUT_FILENO;
|
||||
} else {
|
||||
door_out = gSocket;
|
||||
}
|
||||
arguments[0] = strdup(cmd);
|
||||
sprintf(buffer, "%d", mynode);
|
||||
arguments[1] = strdup(buffer);
|
||||
sprintf(buffer, "%d", door_out);
|
||||
arguments[2] = strdup(buffer);
|
||||
arguments[3] = NULL;
|
||||
|
||||
runexternal(user, cmd, stdio, arguments, NULL, 0);
|
||||
|
||||
free(arguments[0]);
|
||||
free(arguments[1]);
|
||||
free(arguments[2]);
|
||||
}
|
||||
|
||||
void runexternal(struct user_record *user, char *cmd, int stdio, char *argv[], char *cwd, int raw) {
|
||||
|
||||
char buffer[1024];
|
||||
int pid;
|
||||
int ret;
|
||||
char c;
|
||||
unsigned char c;
|
||||
int len;
|
||||
int master;
|
||||
int slave;
|
||||
@ -143,9 +169,15 @@ void rundoor(struct user_record *user, char *cmd, int stdio) {
|
||||
struct sigaction sa;
|
||||
int door_in;
|
||||
int door_out;
|
||||
|
||||
int i;
|
||||
int gotiac;
|
||||
int flush;
|
||||
struct timeval thetimeout;
|
||||
struct termios oldit;
|
||||
timeoutpaused = 1;
|
||||
|
||||
printf("\"%s\"\n", cmd);
|
||||
|
||||
if (write_door32sys(user) != 0) {
|
||||
return;
|
||||
}
|
||||
@ -159,13 +191,6 @@ void rundoor(struct user_record *user, char *cmd, int stdio) {
|
||||
door_out = gSocket;
|
||||
}
|
||||
|
||||
arguments[0] = strdup(cmd);
|
||||
sprintf(buffer, "%d", mynode);
|
||||
arguments[1] = strdup(buffer);
|
||||
sprintf(buffer, "%d", door_out);
|
||||
arguments[2] = strdup(buffer);
|
||||
arguments[3] = NULL;
|
||||
|
||||
ws.ws_row = 24;
|
||||
ws.ws_col = 80;
|
||||
|
||||
@ -179,12 +204,17 @@ void rundoor(struct user_record *user, char *cmd, int stdio) {
|
||||
perror("sigaction");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (raw) {
|
||||
ttySetRaw(master, &oldit);
|
||||
ttySetRaw(slave, &oldit);
|
||||
}
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
return;
|
||||
} else if (pid == 0) {
|
||||
|
||||
if (cwd != NULL) {
|
||||
chdir(cwd);
|
||||
}
|
||||
close(master);
|
||||
dup2(slave, 0);
|
||||
dup2(slave, 1);
|
||||
@ -195,11 +225,13 @@ void rundoor(struct user_record *user, char *cmd, int stdio) {
|
||||
|
||||
ioctl(0, TIOCSCTTY, 1);
|
||||
|
||||
execvp(cmd, arguments);
|
||||
execvp(cmd, argv);
|
||||
} else {
|
||||
running_door_pid = pid;
|
||||
gotiac = 0;
|
||||
flush = 0;
|
||||
|
||||
while(running_door != 0) {
|
||||
while(running_door || !flush) {
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(master, &fdset);
|
||||
FD_SET(door_in, &fdset);
|
||||
@ -208,7 +240,10 @@ void rundoor(struct user_record *user, char *cmd, int stdio) {
|
||||
} else {
|
||||
t = door_in + 1;
|
||||
}
|
||||
ret = select(t, &fdset, NULL, NULL, NULL);
|
||||
|
||||
thetimeout.tv_sec = 5;
|
||||
thetimeout.tv_usec = 0;
|
||||
ret = select(t, &fdset, NULL, NULL, &thetimeout);
|
||||
if (ret > 0) {
|
||||
if (FD_ISSET(door_in, &fdset)) {
|
||||
len = read(door_in, &c, 1);
|
||||
@ -217,29 +252,62 @@ void rundoor(struct user_record *user, char *cmd, int stdio) {
|
||||
disconnect("Socket Closed");
|
||||
return;
|
||||
}
|
||||
if (!raw) {
|
||||
if (c == '\n' || c == '\0') {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!running_door) {
|
||||
continue;
|
||||
}
|
||||
if (c == 255) {
|
||||
if (gotiac == 1) {
|
||||
write(master, &c, 1);
|
||||
gotiac = 0;
|
||||
} else {
|
||||
gotiac = 1;
|
||||
}
|
||||
} else {
|
||||
if (gotiac < 2 && gotiac != 0) {
|
||||
gotiac++;
|
||||
} else {
|
||||
write(master, &c, 1);
|
||||
gotiac = 0;
|
||||
}
|
||||
}
|
||||
} else if (FD_ISSET(master, &fdset)) {
|
||||
len = read(master, &c, 1);
|
||||
if (len == 0) {
|
||||
close(master);
|
||||
break;
|
||||
}
|
||||
if (c == 255) {
|
||||
write(door_out, &c, 1);
|
||||
}
|
||||
write(door_out, &c, 1);
|
||||
}
|
||||
} else {
|
||||
if (!running_door) {
|
||||
flush = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(arguments[0]);
|
||||
free(arguments[1]);
|
||||
free(arguments[2]);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!sshBBS) {
|
||||
sprintf(buffer, "%s %d %d", cmd, mynode, gSocket);
|
||||
snprintf(buffer, 1024, "%s", cmd);
|
||||
for (i=0;argv[i] != NULL; i++) {
|
||||
snprintf(&buffer[strlen(buffer) - 1], 1024 - strlen(buffer), " %s", argv[i]);
|
||||
}
|
||||
if (cwd != NULL) {
|
||||
chdir(cwd);
|
||||
}
|
||||
system(buffer);
|
||||
if (cwd != NULL) {
|
||||
chdir(conf.bbs_path);
|
||||
}
|
||||
} else {
|
||||
s_printf(get_string(51));
|
||||
}
|
||||
|
250
files.c
250
files.c
@ -8,6 +8,7 @@
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <termios.h>
|
||||
#include <dirent.h>
|
||||
#include "Xmodem/zmodem.h"
|
||||
#include "bbs.h"
|
||||
#include "lua/lua.h"
|
||||
@ -326,10 +327,238 @@ char *get_file_id_diz(char *filename) {
|
||||
return description;
|
||||
}
|
||||
|
||||
int do_download(struct user_record *user, char *file) {
|
||||
struct termios oldit;
|
||||
struct termios oldot;
|
||||
char download_command[1024];
|
||||
int i;
|
||||
int argc;
|
||||
int last_char_space;
|
||||
char **arguments;
|
||||
int bpos;
|
||||
if (conf.protocols[user->defprotocol - 1]->internal_zmodem) {
|
||||
if (sshBBS) {
|
||||
ttySetRaw(STDIN_FILENO, &oldit);
|
||||
ttySetRaw(STDOUT_FILENO, &oldot);
|
||||
}
|
||||
download_zmodem(user, file);
|
||||
if (sshBBS) {
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldit);
|
||||
tcsetattr(STDOUT_FILENO, TCSANOW, &oldot);
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
bpos = 0;
|
||||
for (i=0;i<strlen(conf.protocols[user->defprotocol - 1]->download);i++) {
|
||||
if (conf.protocols[user->defprotocol - 1]->download[i] == '*') {
|
||||
i++;
|
||||
if (conf.protocols[user->defprotocol - 1]->download[i] == '*') {
|
||||
download_command[bpos++] = conf.protocols[user->defprotocol - 1]->download[i];
|
||||
download_command[bpos] = '\0';
|
||||
continue;
|
||||
} else if (conf.protocols[user->defprotocol - 1]->download[i] == 'f') {
|
||||
sprintf(&download_command[bpos], "%s", file);
|
||||
bpos = strlen(download_command);
|
||||
|
||||
continue;
|
||||
} else if (conf.protocols[user->defprotocol - 1]->download[i] == 's') {
|
||||
if (!sshBBS) {
|
||||
sprintf(&download_command[bpos], "%d", gSocket);
|
||||
bpos = strlen(download_command);
|
||||
} else {
|
||||
s_printf(get_string(209), conf.protocols[user->defprotocol - 1]->name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
download_command[bpos++] = conf.protocols[user->defprotocol - 1]->download[i];
|
||||
download_command[bpos] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
bpos = 1;
|
||||
arguments = (char **)malloc(sizeof(char *) * (argc + 1));
|
||||
|
||||
for (i=0;i<strlen(download_command);i++) {
|
||||
if (download_command[i] != ' ') {
|
||||
continue;
|
||||
}
|
||||
|
||||
download_command[i] = '\0';
|
||||
i++;
|
||||
|
||||
while (download_command[i] == ' ')
|
||||
i++;
|
||||
|
||||
arguments[bpos++] = &download_command[i];
|
||||
}
|
||||
arguments[bpos] = NULL;
|
||||
|
||||
arguments[0] = download_command;
|
||||
|
||||
runexternal(user, download_command, conf.protocols[user->defprotocol - 1]->stdio, arguments, conf.bbs_path, 1);
|
||||
|
||||
free(arguments);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int do_upload(struct user_record *user, char *final_path) {
|
||||
char upload_path[1024];
|
||||
char upload_command[1024];
|
||||
char buffer3[256];
|
||||
int bpos;
|
||||
int i;
|
||||
int argc;
|
||||
int last_char_space;
|
||||
char **arguments;
|
||||
DIR *inb;
|
||||
struct dirent *dent;
|
||||
struct stat s;
|
||||
|
||||
if (conf.protocols[user->defprotocol - 1]->internal_zmodem) {
|
||||
upload_zmodem(user, final_path);
|
||||
return 1;
|
||||
} else {
|
||||
|
||||
if (conf.protocols[user->defprotocol - 1]->upload_prompt) {
|
||||
s_printf(get_string(210));
|
||||
s_readstring(buffer3, 256);
|
||||
s_printf("\r\n");
|
||||
}
|
||||
bpos = 0;
|
||||
for (i=0;i<strlen(conf.protocols[user->defprotocol - 1]->upload);i++) {
|
||||
if (conf.protocols[user->defprotocol - 1]->upload[i] == '*') {
|
||||
i++;
|
||||
if (conf.protocols[user->defprotocol - 1]->upload[i] == '*') {
|
||||
upload_command[bpos++] = conf.protocols[user->defprotocol - 1]->upload[i];
|
||||
upload_command[bpos] = '\0';
|
||||
continue;
|
||||
} else if (conf.protocols[user->defprotocol - 1]->upload[i] == 'f') {
|
||||
if (conf.protocols[user->defprotocol - 1]->upload_prompt) {
|
||||
sprintf(&upload_command[bpos], "%s", buffer3);
|
||||
bpos = strlen(upload_command);
|
||||
}
|
||||
continue;
|
||||
} else if (conf.protocols[user->defprotocol - 1]->upload[i] == 's') {
|
||||
if (!sshBBS) {
|
||||
sprintf(&upload_command[bpos], "%d", gSocket);
|
||||
bpos = strlen(upload_command);
|
||||
} else {
|
||||
s_printf(get_string(209), conf.protocols[user->defprotocol - 1]->name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
upload_command[bpos++] = conf.protocols[user->defprotocol - 1]->upload[i];
|
||||
upload_command[bpos] = '\0';
|
||||
}
|
||||
}
|
||||
argc = 1;
|
||||
last_char_space = 0;
|
||||
for (i=0;i<strlen(upload_command);i++) {
|
||||
if (upload_command[i] == ' ') {
|
||||
if (!last_char_space) {
|
||||
argc++;
|
||||
last_char_space = 1;
|
||||
}
|
||||
} else {
|
||||
last_char_space = 0;
|
||||
}
|
||||
}
|
||||
bpos = 1;
|
||||
arguments = (char **)malloc(sizeof(char *) * (argc + 1));
|
||||
|
||||
for (i=0;i<strlen(upload_command);i++) {
|
||||
if (upload_command[i] != ' ') {
|
||||
continue;
|
||||
}
|
||||
|
||||
upload_command[i] = '\0';
|
||||
i++;
|
||||
|
||||
while (upload_command[i] == ' ')
|
||||
i++;
|
||||
|
||||
arguments[bpos++] = &upload_command[i];
|
||||
}
|
||||
arguments[bpos] = NULL;
|
||||
|
||||
arguments[0] = upload_command;
|
||||
|
||||
snprintf(upload_path, 1024, "%s/node%d/upload/", conf.bbs_path, mynode);
|
||||
|
||||
if (stat(upload_path, &s) == 0) {
|
||||
recursive_delete(upload_path);
|
||||
}
|
||||
|
||||
mkdir(upload_path, 0755);
|
||||
|
||||
runexternal(user, upload_command, conf.protocols[user->defprotocol - 1]->stdio, arguments, upload_path, 1);
|
||||
|
||||
free(arguments);
|
||||
|
||||
if (conf.protocols[user->defprotocol - 1]->upload_prompt) {
|
||||
snprintf(upload_command, 1024, "%s%s", upload_path, buffer3);
|
||||
if (stat(buffer3, &s) != 0) {
|
||||
recursive_delete(upload_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
snprintf(upload_filename, 1024, "%s/%s", final_path, buffer3);
|
||||
if (stat(upload_filename, &s) == 0) {
|
||||
recursive_delete(upload_path);
|
||||
s_printf(get_string(214));
|
||||
return 0;
|
||||
}
|
||||
if (copy_file(upload_command, upload_filename) != 0) {
|
||||
recursive_delete(upload_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
recursive_delete(upload_path);
|
||||
return 1;
|
||||
} else {
|
||||
inb = opendir(upload_path);
|
||||
if (!inb) {
|
||||
return 0;
|
||||
}
|
||||
while ((dent = readdir(inb)) != NULL) {
|
||||
if (dent->d_type == DT_REG) {
|
||||
snprintf(upload_command, 1-24, "%s%s", upload_path, dent->d_name);
|
||||
snprintf(upload_filename, 1024, "%s/%s", final_path, dent->d_name);
|
||||
|
||||
if (stat(upload_filename, &s) == 0) {
|
||||
recursive_delete(upload_path);
|
||||
s_printf(get_string(214));
|
||||
closedir(inb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (copy_file(upload_command, upload_filename) != 0) {
|
||||
recursive_delete(upload_path);
|
||||
closedir(inb);
|
||||
return 0;
|
||||
}
|
||||
closedir(inb);
|
||||
recursive_delete(upload_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
closedir(inb);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
void upload(struct user_record *user) {
|
||||
char buffer[331];
|
||||
char buffer2[66];
|
||||
char buffer3[256];
|
||||
|
||||
int i;
|
||||
char *create_sql = "CREATE TABLE IF NOT EXISTS files ("
|
||||
"Id INTEGER PRIMARY KEY,"
|
||||
@ -346,7 +575,11 @@ void upload(struct user_record *user) {
|
||||
char *err_msg = NULL;
|
||||
char *description;
|
||||
|
||||
upload_zmodem(user, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->upload_path);
|
||||
|
||||
if (!do_upload(user, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->upload_path)) {
|
||||
s_printf(get_string(211));
|
||||
return;
|
||||
}
|
||||
|
||||
description = NULL;
|
||||
|
||||
@ -508,15 +741,11 @@ void download(struct user_record *user) {
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
struct termios oldit;
|
||||
struct termios oldot;
|
||||
if (sshBBS) {
|
||||
ttySetRaw(STDIN_FILENO, &oldit);
|
||||
ttySetRaw(STDOUT_FILENO, &oldot);
|
||||
}
|
||||
|
||||
|
||||
for (i=0;i<tagged_count;i++) {
|
||||
|
||||
download_zmodem(user, tagged_files[i]);
|
||||
do_download(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);
|
||||
|
||||
@ -563,10 +792,7 @@ void download(struct user_record *user) {
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
if (sshBBS) {
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldit);
|
||||
tcsetattr(STDOUT_FILENO, TCSANOW, &oldot);
|
||||
}
|
||||
|
||||
|
||||
for (i=0;i<tagged_count;i++) {
|
||||
free(tagged_files[i]);
|
||||
|
@ -207,3 +207,9 @@ Is this Correct? (Y/N)
|
||||
\r\n\e[1;32mSelect an archiver...\e[0m\r\n\r\n
|
||||
\e[1;31m%d. \e[1;37m%s\e[0m\r\n
|
||||
>
|
||||
Sorry, this %s is unavailable over SSH\r\n
|
||||
Please enter the filename of the file you want to upload\r\n>
|
||||
\r\nUpload Failed\r\n
|
||||
\r\n\e[1;32mSelect a protocol...\e[0m\r\n\r\n
|
||||
\e[0;36mO. \e[1;37mDefault Protocol (\e[1;33m%s\e[1;37m)\r\n
|
||||
File exists!\r\n
|
||||
|
106
main.c
106
main.c
@ -67,6 +67,83 @@ void sigchld_handler(int s)
|
||||
errno = saved_errno;
|
||||
}
|
||||
|
||||
static int protocol_config_handler(void* user, const char* section, const char* name,
|
||||
const char* value)
|
||||
{
|
||||
struct bbs_config *conf = (struct bbs_config *)user;
|
||||
int i;
|
||||
|
||||
for (i=0;i<conf->protocol_count;i++) {
|
||||
if (strcasecmp(conf->protocols[i]->name, section) == 0) {
|
||||
// found it
|
||||
if (strcasecmp(name, "upload command") == 0) {
|
||||
conf->protocols[i]->upload = strdup(value);
|
||||
} else if (strcasecmp(name, "download command") == 0) {
|
||||
conf->protocols[i]->download = strdup(value);
|
||||
} else if (strcasecmp(name, "internal zmodem") == 0) {
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
conf->protocols[i]->internal_zmodem = 1;
|
||||
} else {
|
||||
conf->protocols[i]->internal_zmodem = 0;
|
||||
}
|
||||
} else if (strcasecmp(name, "stdio") == 0) {
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
conf->protocols[i]->stdio = 1;
|
||||
} else {
|
||||
conf->protocols[i]->stdio = 0;
|
||||
}
|
||||
} else if (strcasecmp(name, "upload prompt") == 0) {
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
conf->protocols[i]->upload_prompt = 1;
|
||||
} else {
|
||||
conf->protocols[i]->upload_prompt = 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (conf->protocol_count == 0) {
|
||||
conf->protocols = (struct protocol **)malloc(sizeof(struct protocol *));
|
||||
} else {
|
||||
conf->protocols = (struct protocol **)realloc(conf->protocols, sizeof(struct protocol *) * (conf->protocol_count + 1));
|
||||
}
|
||||
|
||||
conf->protocols[conf->protocol_count] = (struct protocol *)malloc(sizeof(struct archiver));
|
||||
|
||||
conf->protocols[conf->protocol_count]->name = strdup(section);
|
||||
conf->protocols[conf->protocol_count]->internal_zmodem = 0;
|
||||
conf->protocols[conf->protocol_count]->upload_prompt = 0;
|
||||
conf->protocols[conf->protocol_count]->stdio = 0;
|
||||
|
||||
if (strcasecmp(name, "upload command") == 0) {
|
||||
conf->protocols[conf->protocol_count]->upload = strdup(value);
|
||||
} else if (strcasecmp(name, "download command") == 0) {
|
||||
conf->protocols[conf->protocol_count]->download = strdup(value);
|
||||
} else if (strcasecmp(name, "internal zmodem") == 0) {
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
conf->protocols[conf->protocol_count]->internal_zmodem = 1;
|
||||
} else {
|
||||
conf->protocols[conf->protocol_count]->internal_zmodem = 0;
|
||||
}
|
||||
} else if (strcasecmp(name, "stdio") == 0) {
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
conf->protocols[conf->protocol_count]->stdio = 1;
|
||||
} else {
|
||||
conf->protocols[conf->protocol_count]->stdio = 0;
|
||||
}
|
||||
} else if (strcasecmp(name, "upload prompt") == 0) {
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
conf->protocols[conf->protocol_count]->upload_prompt = 1;
|
||||
} else {
|
||||
conf->protocols[conf->protocol_count]->upload_prompt = 0;
|
||||
}
|
||||
}
|
||||
conf->protocol_count++;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int archiver_config_handler(void* user, const char* section, const char* name,
|
||||
const char* value)
|
||||
{
|
||||
@ -381,8 +458,6 @@ static int handler(void* user, const char* section, const char* name,
|
||||
conf->main_aka = parse_fido_addr(value);
|
||||
} else if (strcasecmp(name, "qwk max messages") == 0) {
|
||||
conf->bwave_max_msgs = atoi(value);
|
||||
} else if (strcasecmp(name, "archivers") == 0) {
|
||||
conf->archiver_path = strdup(value);
|
||||
} else if (strcasecmp(name, "broadcast enable") == 0) {
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
conf->broadcast_enable = 1;
|
||||
@ -413,6 +488,8 @@ static int handler(void* user, const char* section, const char* name,
|
||||
conf->string_file = strdup(value);
|
||||
} else if (strcasecmp(name, "www path") == 0) {
|
||||
conf->www_path = strdup(value);
|
||||
} else if (strcasecmp(name, "config path") == 0) {
|
||||
conf->config_path = strdup(value);
|
||||
}
|
||||
} else if (strcasecmp(section, "mail conferences") == 0) {
|
||||
if (conf->mail_conference_count == 0) {
|
||||
@ -833,6 +910,7 @@ int main(int argc, char **argv) {
|
||||
int main_pid;
|
||||
FILE *fptr;
|
||||
struct stat s;
|
||||
char buffer[1024];
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage ./magicka config/bbs.ini\n");
|
||||
@ -854,17 +932,23 @@ int main(int argc, char **argv) {
|
||||
conf.telnet_port = 0;
|
||||
conf.string_file = NULL;
|
||||
conf.www_path = NULL;
|
||||
conf.archiver_path = NULL;
|
||||
conf.archiver_count = 0;
|
||||
conf.broadcast_enable = 0;
|
||||
conf.broadcast_port = 0;
|
||||
conf.broadcast_address = NULL;
|
||||
conf.config_path = NULL;
|
||||
|
||||
// Load BBS data
|
||||
if (ini_parse(argv[1], handler, &conf) <0) {
|
||||
fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (conf.config_path == NULL) {
|
||||
fprintf(stderr, "Config Path must be set in your bbs ini!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Load mail Areas
|
||||
for (i=0;i<conf.mail_conference_count;i++) {
|
||||
if (ini_parse(conf.mail_conferences[i]->path, mail_area_handler, conf.mail_conferences[i]) <0) {
|
||||
@ -880,18 +964,26 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (ini_parse("config/doors.ini", door_config_handler, &conf) <0) {
|
||||
snprintf(buffer, 1024, "%s/doors.ini", conf.config_path);
|
||||
|
||||
if (ini_parse(buffer, door_config_handler, &conf) <0) {
|
||||
fprintf(stderr, "Unable to load configuration ini (doors.ini)!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (conf.archiver_path != NULL) {
|
||||
if (ini_parse(conf.archiver_path, archiver_config_handler, &conf) <0) {
|
||||
fprintf(stderr, "Unable to load configuration ini %s\n", conf.archiver_path);
|
||||
snprintf(buffer, 1024, "%s/archivers.ini", conf.config_path);
|
||||
if (ini_parse(buffer, archiver_config_handler, &conf) <0) {
|
||||
fprintf(stderr, "Unable to load configuration ini %s\n", buffer);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
snprintf(buffer, 1024, "%s/protocols.ini", conf.config_path);
|
||||
if (ini_parse(buffer, protocol_config_handler, &conf) <0) {
|
||||
fprintf(stderr, "Unable to load configuration ini %s\n", buffer);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
load_strings();
|
||||
|
||||
if (conf.fork) {
|
||||
|
22
settings.c
22
settings.c
@ -20,6 +20,7 @@ void settings_menu(struct user_record *user) {
|
||||
s_printf(get_string(151));
|
||||
s_printf(get_string(152), user->location);
|
||||
s_printf(get_string(205), conf.archivers[user->defarchiver - 1]->name);
|
||||
s_printf(get_string(213), conf.protocols[user->defprotocol - 1]->name);
|
||||
s_printf(get_string(153));
|
||||
s_printf(get_string(154));
|
||||
|
||||
@ -89,6 +90,27 @@ void settings_menu(struct user_record *user) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
{
|
||||
s_printf(get_string(212));
|
||||
|
||||
for (i=0;i<conf.protocol_count;i++) {
|
||||
s_printf(get_string(207), i + 1, conf.protocols[i]->name);
|
||||
}
|
||||
|
||||
s_printf(get_string(208));
|
||||
s_readstring(buffer, 5);
|
||||
new_arc = atoi(buffer);
|
||||
|
||||
if (new_arc - 1 < 0 || new_arc > conf.protocol_count) {
|
||||
break;
|
||||
} else {
|
||||
user->defprotocol = new_arc;
|
||||
save_user(user);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'q':
|
||||
dosettings = 1;
|
||||
break;
|
||||
|
4
users.c
4
users.c
@ -228,7 +228,7 @@ int inst_user(struct user_record *user) {
|
||||
|
||||
struct user_record *check_user_pass(char *loginname, char *password) {
|
||||
struct user_record *user;
|
||||
char buffer[256];
|
||||
char buffer[1024];
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
@ -306,7 +306,7 @@ struct user_record *check_user_pass(char *loginname, char *password) {
|
||||
|
||||
user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t));
|
||||
|
||||
sprintf(buffer, "%s/config/s%d.ini", conf.bbs_path, user->sec_level);
|
||||
snprintf(buffer, 1024, "%s/s%d.ini", conf.config_path, user->sec_level);
|
||||
if (ini_parse(buffer, secLevel, user->sec_info) <0) {
|
||||
dolog("Unable to load sec Level ini (%s)!", buffer);
|
||||
exit(-1);
|
||||
|
Reference in New Issue
Block a user