Initial try at new file scan

This commit is contained in:
Andrew Pamment 2017-09-28 19:11:00 +10:00
parent 8ada1a50ea
commit a74caa16b2
9 changed files with 104 additions and 5 deletions

Binary file not shown.

View File

@ -229,3 +229,5 @@ File exists!\r\n
\e[1;31mUNSUB\e[0m \e[1;31mUNSUB\e[0m
\r\n\e[1;37mAre you sure you want to reset all messages in %s to unread? \e[0m \r\n\e[1;37mAre you sure you want to reset all messages in %s to unread? \e[0m
\r\n\e[1;37mAre you sure you want to reset \e[1;31mall messages \e[1;37min all bases to unread? \e[0m \r\n\e[1;37mAre you sure you want to reset \e[1;31mall messages \e[1;37min all bases to unread? \e[0m
\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[1;31mNEW \e[0;32m
\r\nScan for new files? (Y/N) :

View File

@ -31,6 +31,9 @@ COMMAND NEXTFILESUB
HOTKEY [ HOTKEY [
COMMAND PREVFILESUB COMMAND PREVFILESUB
HOTKEY !
COMMAND FILESCAN
HOTKEY Q HOTKEY Q
COMMAND PREVMENU COMMAND PREVMENU

View File

@ -82,6 +82,8 @@ end
bbs_mail_scan(); bbs_mail_scan();
bbs_file_scan();
-- Display Auto Message -- Display Auto Message
bbs_display_automsg(); bbs_display_automsg();

View File

@ -30,6 +30,7 @@ int gSocket;
int sshBBS; int sshBBS;
int usertimeout; int usertimeout;
int timeoutpaused; int timeoutpaused;
time_t userlaston;
char *ipaddress = NULL; char *ipaddress = NULL;
@ -856,6 +857,8 @@ tryagain:
localtime_r(&now, &thetime); localtime_r(&now, &thetime);
localtime_r(&user->laston, &oldtime); localtime_r(&user->laston, &oldtime);
userlaston = user->laston;
if (thetime.tm_mday != oldtime.tm_mday || thetime.tm_mon != oldtime.tm_mon || thetime.tm_year != oldtime.tm_year) { if (thetime.tm_mday != oldtime.tm_mday || thetime.tm_mon != oldtime.tm_mon || thetime.tm_year != oldtime.tm_year) {
user->timeleft = user->sec_info->timeperday; user->timeleft = user->sec_info->timeperday;
user->laston = now; user->laston = now;
@ -902,6 +905,8 @@ tryagain:
mail_scan(user); mail_scan(user);
file_scan();
automessage_display(); automessage_display();
} }
record_last10_callers(user); record_last10_callers(user);

View File

@ -310,6 +310,7 @@ extern void next_file_dir(struct user_record *user);
extern void prev_file_dir(struct user_record *user); extern void prev_file_dir(struct user_record *user);
extern void next_file_sub(struct user_record *user); extern void next_file_sub(struct user_record *user);
extern void prev_file_sub(struct user_record *user); extern void prev_file_sub(struct user_record *user);
extern void file_scan();
extern void lua_push_cfunctions(lua_State *L); extern void lua_push_cfunctions(lua_State *L);
extern void do_lua_script(char *script); extern void do_lua_script(char *script);

View File

@ -23,12 +23,15 @@ extern int mynode;
extern int bbs_stdin; extern int bbs_stdin;
extern int bbs_stdout; extern int bbs_stdout;
extern int bbs_stderr; extern int bbs_stderr;
extern time_t userlaston;
extern struct user_record *gUser;
struct file_entry { struct file_entry {
char *filename; char *filename;
char *description; char *description;
int size; int size;
int dlcount; int dlcount;
time_t uploaddate;
}; };
char **tagged_files; char **tagged_files;
@ -851,8 +854,8 @@ void download(struct user_record *user) {
} }
void list_files(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, uploaddate from files where approved=1";
char buffer[256]; char buffer[PATH_MAX];
sqlite3 *db; sqlite3 *db;
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
@ -868,7 +871,7 @@ void list_files(struct user_record *user) {
struct file_entry **files_e; struct file_entry **files_e;
sprintf(buffer, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database); snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database);
rc = sqlite3_open(buffer, &db); rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
@ -901,7 +904,7 @@ void list_files(struct user_record *user) {
files_e[files_c]->description = strdup((char *)sqlite3_column_text(res, 1)); files_e[files_c]->description = strdup((char *)sqlite3_column_text(res, 1));
files_e[files_c]->size = sqlite3_column_int(res, 2); files_e[files_c]->size = sqlite3_column_int(res, 2);
files_e[files_c]->dlcount = sqlite3_column_int(res, 3); files_e[files_c]->dlcount = sqlite3_column_int(res, 3);
files_e[files_c]->uploaddate = sqlite3_column_int(res, 4);
files_c++; files_c++;
} }
sqlite3_finalize(res); sqlite3_finalize(res);
@ -926,7 +929,11 @@ void list_files(struct user_record *user) {
} else { } else {
file_unit = 'b'; file_unit = 'b';
} }
if (files_e[i]->uploaddate > userlaston) {
s_printf(get_string(231), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename));
} else {
s_printf(get_string(69), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); s_printf(get_string(69), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename));
}
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') {
@ -1193,3 +1200,69 @@ void prev_file_sub(struct user_record *user) {
user->cur_file_sub = i - 1; user->cur_file_sub = i - 1;
} }
void file_scan() {
char c;
int i;
int j;
char buffer[PATH_MAX];
char sql[] = "SELECT COUNT(*) FROM files WHERE uploaddate > ?";
int rc;
sqlite3 *db;
sqlite3_stmt *res;
int new_files;
int lines = 0;
s_printf(get_string(232));
c = s_getc();
if (tolower(c) == 'y') {
for (i=0;i<conf.file_directory_count;i++) {
if (conf.file_directories[i]->sec_level > gUser->sec_level) {
continue;
}
s_printf(get_string(140), i, conf.file_directories[i]->name);
lines += 2;
if (lines == 22) {
s_printf(get_string(6));
s_getc();
lines = 0;
}
for (j=0;j<conf.file_directories[i]->file_sub_count;j++) {
if (conf.file_directories[i]->file_subs[j]->download_sec_level > gUser->sec_level) {
continue;
}
snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[i]->file_subs[j]->database);
rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) {
dolog("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
sqlite3_busy_timeout(db, 5000);
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc != SQLITE_OK) {
sqlite3_finalize(res);
sqlite3_close(db);
continue;
}
sqlite3_bind_int(res, 1, userlaston);
if (sqlite3_step(res) != SQLITE_ERROR) {
new_files = sqlite3_column_int(res, 0);
s_printf(get_string(141), j, conf.file_directories[i]->file_subs[j]->name, new_files);
lines++;
}
sqlite3_finalize(res);
sqlite3_close(db);
if (lines == 22) {
s_printf(get_string(6));
s_getc();
lines = 0;
}
}
}
}
}

View File

@ -108,6 +108,11 @@ int l_bbsMailScan(lua_State *L) {
return 0; return 0;
} }
int l_bbsFileScan(lua_State *L) {
file_scan();
return 0;
}
int l_bbsRunDoor(lua_State *L) { 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);
@ -192,6 +197,8 @@ void lua_push_cfunctions(lua_State *L) {
lua_setglobal(L, "bbs_display_automsg"); lua_setglobal(L, "bbs_display_automsg");
lua_pushcfunction(L, l_getBBSInfo); lua_pushcfunction(L, l_getBBSInfo);
lua_setglobal(L, "bbs_get_info"); lua_setglobal(L, "bbs_get_info");
lua_pushcfunction(L, l_bbsFileScan);
lua_setglobal(L, "bbs_file_scan");
} }
void do_lua_script(char *script) { void do_lua_script(char *script) {

View File

@ -49,6 +49,7 @@
#define MENU_SUBUNSUBCONF 39 #define MENU_SUBUNSUBCONF 39
#define MENU_RESETPOINTERS 40 #define MENU_RESETPOINTERS 40
#define MENU_RESETALLPOINTERS 41 #define MENU_RESETALLPOINTERS 41
#define MENU_FILESCAN 42
extern struct bbs_config conf; extern struct bbs_config conf;
extern struct user_record *gUser; extern struct user_record *gUser;
@ -197,6 +198,8 @@ int menu_system(char *menufile) {
menu[menu_items-1]->command = MENU_RESETPOINTERS; menu[menu_items-1]->command = MENU_RESETPOINTERS;
} else if (strncasecmp(&buffer[8], "RESETALLMSGPTRS", 15) == 0) { } else if (strncasecmp(&buffer[8], "RESETALLMSGPTRS", 15) == 0) {
menu[menu_items-1]->command = MENU_RESETALLPOINTERS; menu[menu_items-1]->command = MENU_RESETALLPOINTERS;
} else if (strncasecmp(&buffer[8], "FILESCAN", 8) == 0) {
menu[menu_items-1]->command = MENU_FILESCAN;
} }
} else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) { } else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) {
menu[menu_items-1]->seclevel = atoi(&buffer[9]); menu[menu_items-1]->seclevel = atoi(&buffer[9]);
@ -495,6 +498,9 @@ int menu_system(char *menufile) {
msgbase_reset_all_pointers(); msgbase_reset_all_pointers();
} }
break; break;
case MENU_FILESCAN:
file_scan();
break;
default: default:
break; break;
} }