More robust bluewave unpacking/packing, added file_id.diz importing for zip files
This commit is contained in:
parent
3bb76b6b5f
commit
d568da0b65
53
bbs.c
53
bbs.c
@ -10,6 +10,8 @@
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdarg.h>
|
||||
#include <fts.h>
|
||||
#include <errno.h>
|
||||
#include "bbs.h"
|
||||
#include "lua/lua.h"
|
||||
#include "lua/lualib.h"
|
||||
@ -800,3 +802,54 @@ void runbbs_ssh(char *ip) {
|
||||
}
|
||||
runbbs_real(-1, ip, 1);
|
||||
}
|
||||
|
||||
int recursive_delete(const char *dir) {
|
||||
int ret = 0;
|
||||
FTS *ftsp = NULL;
|
||||
FTSENT *curr;
|
||||
|
||||
char *files[] = { (char *) dir, NULL };
|
||||
|
||||
ftsp = fts_open(files, FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV, NULL);
|
||||
if (!ftsp) {
|
||||
dolog("%s: fts_open failed: %s", dir, strerror(errno));
|
||||
ret = -1;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
while ((curr = fts_read(ftsp))) {
|
||||
switch (curr->fts_info) {
|
||||
case FTS_NS:
|
||||
case FTS_DNR:
|
||||
case FTS_ERR:
|
||||
dolog("%s: fts_read error: %s", curr->fts_accpath, strerror(curr->fts_errno));
|
||||
break;
|
||||
|
||||
case FTS_DC:
|
||||
case FTS_DOT:
|
||||
case FTS_NSOK:
|
||||
break;
|
||||
|
||||
case FTS_D:
|
||||
break;
|
||||
|
||||
case FTS_DP:
|
||||
case FTS_F:
|
||||
case FTS_SL:
|
||||
case FTS_SLNONE:
|
||||
case FTS_DEFAULT:
|
||||
if (remove(curr->fts_accpath) < 0) {
|
||||
dolog("%s: Failed to remove: %s", curr->fts_path, strerror(errno));
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
finish:
|
||||
if (ftsp) {
|
||||
fts_close(ftsp);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
1
bbs.h
1
bbs.h
@ -174,6 +174,7 @@ struct msg_headers {
|
||||
int msg_count;
|
||||
};
|
||||
|
||||
extern int recursive_delete(const char *dir);
|
||||
extern void automessage_write(struct user_record *user);
|
||||
extern void automessage_display();
|
||||
extern void dolog(char *fmt, ...);
|
||||
|
56
bluewave.c
56
bluewave.c
@ -228,15 +228,21 @@ void bwave_create_packet() {
|
||||
mkdir(buffer, 0755);
|
||||
}
|
||||
|
||||
snprintf(buffer, 1024, "%s/node%d/bwave/", conf.bbs_path, mynode);
|
||||
|
||||
snprintf(buffer, 1024, "%s/node%d/%s.FTI", conf.bbs_path, mynode, conf.bwave_name);
|
||||
if (stat(buffer, &s) == 0) {
|
||||
recursive_delete(buffer);
|
||||
}
|
||||
mkdir(buffer, 0755);
|
||||
|
||||
snprintf(buffer, 1024, "%s/node%d/bwave/%s.FTI", conf.bbs_path, mynode, conf.bwave_name);
|
||||
|
||||
fti_file = fopen(buffer, "wb");
|
||||
|
||||
snprintf(buffer, 1024, "%s/node%d/%s.MIX", conf.bbs_path, mynode, conf.bwave_name);
|
||||
snprintf(buffer, 1024, "%s/node%d/bwave/%s.MIX", conf.bbs_path, mynode, conf.bwave_name);
|
||||
mix_file = fopen(buffer, "wb");
|
||||
|
||||
snprintf(buffer, 1024, "%s/node%d/%s.DAT", conf.bbs_path, mynode, conf.bwave_name);
|
||||
snprintf(buffer, 1024, "%s/node%d/bwave/%s.DAT", conf.bbs_path, mynode, conf.bwave_name);
|
||||
dat_file = fopen(buffer, "wb");
|
||||
|
||||
s_printf("\r\n");
|
||||
@ -307,7 +313,7 @@ void bwave_create_packet() {
|
||||
fclose(mix_file);
|
||||
fclose(fti_file);
|
||||
|
||||
snprintf(buffer, 1024, "%s/node%d/%s.INF", conf.bbs_path, mynode, conf.bwave_name);
|
||||
snprintf(buffer, 1024, "%s/node%d/bwave/%s.INF", conf.bbs_path, mynode, conf.bwave_name);
|
||||
|
||||
inf_file = fopen(buffer, "wb");
|
||||
fwrite(&hdr, sizeof(INF_HEADER), 1, inf_file);
|
||||
@ -337,7 +343,7 @@ void bwave_create_packet() {
|
||||
sprintf(&buffer[bpos], "%s", archive);
|
||||
bpos = strlen(buffer);
|
||||
} else if (conf.zip_cmd[i] == 'f') {
|
||||
sprintf(&buffer[bpos], "%s/node%d/%s.INF %s/node%d/%s.MIX %s/node%d/%s.FTI %s/node%d/%s.DAT", conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name);
|
||||
sprintf(&buffer[bpos], "%s/node%d/bwave/%s.INF %s/node%d/bwave/%s.MIX %s/node%d/bwave/%s.FTI %s/node%d/bwave/%s.DAT", conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name, conf.bbs_path, mynode, conf.bwave_name);
|
||||
bpos = strlen(buffer);
|
||||
} else if (conf.zip_cmd[i] == '*') {
|
||||
buffer[bpos++] = '*';
|
||||
@ -360,14 +366,9 @@ void bwave_create_packet() {
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldit);
|
||||
tcsetattr(STDOUT_FILENO, TCSANOW, &oldot);
|
||||
}
|
||||
snprintf(buffer, 1024, "%s/node%d/%s.FTI", conf.bbs_path, mynode, conf.bwave_name);
|
||||
unlink(buffer);
|
||||
snprintf(buffer, 1024, "%s/node%d/%s.MIX", conf.bbs_path, mynode, conf.bwave_name);
|
||||
unlink(buffer);
|
||||
snprintf(buffer, 1024, "%s/node%d/%s.DAT", conf.bbs_path, mynode, conf.bwave_name);
|
||||
unlink(buffer);
|
||||
snprintf(buffer, 1024, "%s/node%d/%s.INF", conf.bbs_path, mynode, conf.bwave_name);
|
||||
unlink(buffer);
|
||||
snprintf(buffer, 1024, "%s/node%d/bwave", conf.bbs_path, mynode);
|
||||
recursive_delete(buffer);
|
||||
|
||||
unlink(archive);
|
||||
gUser->bwavepktno++;
|
||||
if (gUser->bwavepktno > 999) {
|
||||
@ -565,7 +566,12 @@ void bwave_upload_reply() {
|
||||
mkdir(buffer, 0755);
|
||||
}
|
||||
|
||||
snprintf(buffer, 1024, "%s/node%d/", conf.bbs_path, mynode);
|
||||
snprintf(buffer, 1024, "%s/node%d/bwave/", conf.bbs_path, mynode);
|
||||
|
||||
if (stat(buffer, &s) == 0) {
|
||||
recursive_delete(buffer);
|
||||
}
|
||||
mkdir(buffer, 0755);
|
||||
|
||||
upload_zmodem(gUser, buffer);
|
||||
|
||||
@ -577,7 +583,7 @@ void bwave_upload_reply() {
|
||||
sprintf(&buffer[bpos], "%s", upload_filename);
|
||||
bpos = strlen(buffer);
|
||||
} else if (conf.unzip_cmd[i] == 'd') {
|
||||
sprintf(&buffer[bpos], "%s/node%d/", conf.bbs_path, mynode);
|
||||
sprintf(&buffer[bpos], "%s/node%d/bwave/", conf.bbs_path, mynode);
|
||||
bpos = strlen(buffer);
|
||||
} else if (conf.unzip_cmd[i] == '*') {
|
||||
buffer[bpos++] = '*';
|
||||
@ -592,12 +598,12 @@ void bwave_upload_reply() {
|
||||
|
||||
unlink(upload_filename);
|
||||
|
||||
snprintf(buffer, 1024, "%s/node%d/%s.UPL", conf.bbs_path, mynode, conf.bwave_name);
|
||||
snprintf(buffer, 1024, "%s/node%d/bwave/%s.UPL", conf.bbs_path, mynode, conf.bwave_name);
|
||||
|
||||
upl_file = fopen(buffer, "r");
|
||||
|
||||
if (!upl_file) {
|
||||
snprintf(buffer, 1024, "%s/node%d/%s.upl", conf.bbs_path, mynode, conf.bwave_name);
|
||||
snprintf(buffer, 1024, "%s/node%d/bwave/%s.upl", conf.bbs_path, mynode, conf.bwave_name);
|
||||
upl_file = fopen(buffer, "r");
|
||||
if (!upl_file) {
|
||||
s_printf(get_string(196));
|
||||
@ -666,7 +672,7 @@ void bwave_upload_reply() {
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(msgbuffer, 1024, "%s/node%d/%s", conf.bbs_path, mynode, upl_rec.filename);
|
||||
snprintf(msgbuffer, 1024, "%s/node%d/bwave/%s", conf.bbs_path, mynode, upl_rec.filename);
|
||||
|
||||
if (conf.mail_conferences[confr]->tagline != NULL) {
|
||||
tagline = conf.mail_conferences[confr]->tagline;
|
||||
@ -702,9 +708,7 @@ void bwave_upload_reply() {
|
||||
|
||||
fread(body, 1, s.st_size, msg_file);
|
||||
fclose(msg_file);
|
||||
|
||||
unlink(msgbuffer);
|
||||
|
||||
|
||||
body[s.st_size] = '\0';
|
||||
|
||||
strcat(body, originlinebuffer);
|
||||
@ -740,12 +744,10 @@ void bwave_upload_reply() {
|
||||
}
|
||||
}
|
||||
|
||||
fclose(upl_file);
|
||||
unlink(buffer);
|
||||
snprintf(buffer, 1024, "%s/node%d/%s.OLC", conf.bbs_path, mynode, conf.bwave_name);
|
||||
unlink(buffer);
|
||||
snprintf(buffer, 1024, "%s/node%d/%s.REQ", conf.bbs_path, mynode, conf.bwave_name);
|
||||
unlink(buffer);
|
||||
snprintf(buffer, 1024, "%s/node%d/bwave/", conf.bbs_path, mynode);
|
||||
recursive_delete(buffer);
|
||||
|
||||
|
||||
|
||||
s_printf("\r\n");
|
||||
s_printf(get_string(6));
|
||||
|
147
files.c
147
files.c
@ -16,6 +16,7 @@
|
||||
extern struct bbs_config conf;
|
||||
extern int gSocket;
|
||||
extern int sshBBS;
|
||||
extern int mynode;
|
||||
|
||||
struct file_entry {
|
||||
char *filename;
|
||||
@ -217,6 +218,88 @@ void upload_zmodem(struct user_record *user, char *upload_p) {
|
||||
}
|
||||
}
|
||||
|
||||
char *get_file_id_diz(char *filename) {
|
||||
char *description;
|
||||
char buffer[1024];
|
||||
struct stat s;
|
||||
int bpos;
|
||||
int i;
|
||||
FILE *fptr;
|
||||
int len;
|
||||
|
||||
if (tolower(filename[strlen(filename) - 1]) != 'p' || tolower(filename[strlen(filename) - 2]) != 'i' || tolower(filename[strlen(filename) - 3]) != 'z') {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
snprintf(buffer, 1024, "%s/node%d", conf.bbs_path, mynode);
|
||||
if (stat(buffer, &s) != 0) {
|
||||
mkdir(buffer, 0755);
|
||||
}
|
||||
|
||||
snprintf(buffer, 1024, "%s/node%d/temp", conf.bbs_path, mynode);
|
||||
if (stat(buffer, &s) != 0) {
|
||||
|
||||
if (recursive_delete(buffer) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
mkdir(buffer, 0755);
|
||||
|
||||
bpos = 0;
|
||||
for (i=0;i<strlen(conf.unzip_cmd);i++) {
|
||||
if (conf.unzip_cmd[i] == '*') {
|
||||
i++;
|
||||
if (conf.unzip_cmd[i] == 'a') {
|
||||
sprintf(&buffer[bpos], "%s", filename);
|
||||
bpos = strlen(buffer);
|
||||
} else if (conf.unzip_cmd[i] == 'd') {
|
||||
sprintf(&buffer[bpos], "%s/node%d/temp/", conf.bbs_path, mynode);
|
||||
bpos = strlen(buffer);
|
||||
} else if (conf.unzip_cmd[i] == '*') {
|
||||
buffer[bpos++] = '*';
|
||||
buffer[bpos] = '\0';
|
||||
}
|
||||
} else {
|
||||
buffer[bpos++] = conf.unzip_cmd[i];
|
||||
buffer[bpos] = '\0';
|
||||
}
|
||||
}
|
||||
system(buffer);
|
||||
|
||||
snprintf(buffer, 1024, "%s/node%d/temp/FILE_ID.DIZ", conf.bbs_path, mynode);
|
||||
if (stat(buffer, &s) != 0) {
|
||||
snprintf(buffer, 1024, "%s/node%d/temp/file_id.diz", conf.bbs_path, mynode);
|
||||
if (stat(buffer, &s) != 0) {
|
||||
snprintf(buffer, 1024, "%s/node%d/temp", conf.bbs_path, mynode);
|
||||
recursive_delete(buffer);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
description = (char *)malloc(s.st_size + 1);
|
||||
|
||||
fptr = fopen(buffer, "rb");
|
||||
|
||||
fread(description, 1, s.st_size, fptr);
|
||||
description[s.st_size] = '\0';
|
||||
fclose(fptr);
|
||||
|
||||
bpos = 0;
|
||||
len = strlen(description);
|
||||
for (i=0;i<len;i++) {
|
||||
if (description[i] == '\r') {
|
||||
continue;
|
||||
} else {
|
||||
description[bpos++] = description[i];
|
||||
|
||||
}
|
||||
}
|
||||
description[bpos] = '\0';
|
||||
|
||||
return description;
|
||||
}
|
||||
|
||||
void upload(struct user_record *user) {
|
||||
char buffer[331];
|
||||
char buffer2[66];
|
||||
@ -231,26 +314,36 @@ void upload(struct user_record *user) {
|
||||
"approved INTEGER);";
|
||||
char *sql = "INSERT INTO files (filename, description, size, dlcount, approved) VALUES(?, ?, ?, 0, 0)";
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
struct stat s;
|
||||
char *err_msg = NULL;
|
||||
|
||||
sqlite3_stmt *res;
|
||||
int rc;
|
||||
struct stat s;
|
||||
char *err_msg = NULL;
|
||||
char *description;
|
||||
|
||||
upload_zmodem(user, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->upload_path);
|
||||
|
||||
|
||||
s_printf("\r\nPlease enter a description:\r\n");
|
||||
buffer[0] = '\0';
|
||||
for (i=0;i<5;i++) {
|
||||
s_printf("\r\n%d: ", i);
|
||||
s_readstring(buffer2, 65);
|
||||
if (strlen(buffer2) == 0) {
|
||||
break;
|
||||
description = NULL;
|
||||
|
||||
s_printf(get_string(198));
|
||||
description = get_file_id_diz(upload_filename);
|
||||
|
||||
if (description == NULL) {
|
||||
s_printf(get_string(199));
|
||||
s_printf(get_string(200));
|
||||
buffer[0] = '\0';
|
||||
for (i=0;i<5;i++) {
|
||||
s_printf("\r\n%d: ", i);
|
||||
s_readstring(buffer2, 65);
|
||||
if (strlen(buffer2) == 0) {
|
||||
break;
|
||||
}
|
||||
strcat(buffer, buffer2);
|
||||
strcat(buffer, "\n");
|
||||
}
|
||||
strcat(buffer, buffer2);
|
||||
strcat(buffer, "\n");
|
||||
}
|
||||
|
||||
} else {
|
||||
s_printf(get_string(201));
|
||||
}
|
||||
sprintf(buffer3, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database);
|
||||
|
||||
rc = sqlite3_open(buffer3, &db);
|
||||
@ -266,6 +359,9 @@ void upload(struct user_record *user) {
|
||||
dolog("SQL error: %s", err_msg);
|
||||
sqlite3_free(err_msg);
|
||||
sqlite3_close(db);
|
||||
if (description != NULL) {
|
||||
free(description);
|
||||
}
|
||||
return;
|
||||
}
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||
@ -274,12 +370,19 @@ void upload(struct user_record *user) {
|
||||
stat(upload_filename, &s);
|
||||
|
||||
sqlite3_bind_text(res, 1, upload_filename, -1, 0);
|
||||
sqlite3_bind_text(res, 2, buffer, -1, 0);
|
||||
if (description == NULL) {
|
||||
sqlite3_bind_text(res, 2, buffer, -1, 0);
|
||||
} else {
|
||||
sqlite3_bind_text(res, 2, description, -1, 0);
|
||||
}
|
||||
sqlite3_bind_int(res, 3, s.st_size);
|
||||
} else {
|
||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
if (description != NULL) {
|
||||
free(description);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -289,10 +392,20 @@ void upload(struct user_record *user) {
|
||||
dolog("execution failed: %s", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
if (description != NULL) {
|
||||
free(description);
|
||||
}
|
||||
return;
|
||||
}
|
||||
sqlite3_finalize(res);
|
||||
sqlite3_close(db);
|
||||
if (description != NULL) {
|
||||
free(description);
|
||||
}
|
||||
|
||||
s_printf(get_string(202));
|
||||
s_printf(get_string(6));
|
||||
s_getc();
|
||||
}
|
||||
|
||||
void download_zmodem(struct user_record *user, char *filename) {
|
||||
|
@ -196,3 +196,8 @@ Is this Correct? (Y/N)
|
||||
\e[1;32mScanned \e[1;37m%s\e[1;32m->\e[1;37m%s\e[1;32m got \e[1;37m%d\e[1;32m msgs...\e[0m\r\n
|
||||
\e[1;31mInvalid Reply Packet!\e[0m
|
||||
\r\n\e[1;31mFailed to add message\e[0m\r\n
|
||||
\r\n\e[1;32mChecking for file_id.diz...\r\n
|
||||
...Not Found!\r\n\r\n
|
||||
\r\nPlease enter a description:\r\n
|
||||
...Found!\r\n\r\n
|
||||
\e[1;32mUpload Successful!\e[0m\r\n
|
||||
|
Reference in New Issue
Block a user