Replace printf / fprintf(stderr... with dolog
This commit is contained in:
parent
7a12fb716f
commit
6b78526669
12
bbs.c
12
bbs.c
@ -41,7 +41,7 @@ void dolog(char *fmt, ...) {
|
|||||||
snprintf(buffer, 512, "%s/%04d%02d%02d.log", conf.log_path, time_now.tm_year + 1900, time_now.tm_mon + 1, time_now.tm_mday);
|
snprintf(buffer, 512, "%s/%04d%02d%02d.log", conf.log_path, time_now.tm_year + 1900, time_now.tm_mon + 1, time_now.tm_mday);
|
||||||
logfptr = fopen(buffer, "a");
|
logfptr = fopen(buffer, "a");
|
||||||
if (!logfptr) {
|
if (!logfptr) {
|
||||||
printf("Error opening log file!\n");
|
dolog("Error opening log file!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -422,7 +422,7 @@ void automessage_write(int socket, struct user_record *user) {
|
|||||||
fwrite(automsg, strlen(automsg), 1, fptr);
|
fwrite(automsg, strlen(automsg), 1, fptr);
|
||||||
fclose(fptr);
|
fclose(fptr);
|
||||||
} else {
|
} else {
|
||||||
printf("Unable to open automessage.txt for writing\n");
|
dolog("Unable to open automessage.txt for writing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -446,7 +446,7 @@ void automessage_display(int socket) {
|
|||||||
}
|
}
|
||||||
fclose(fptr);
|
fclose(fptr);
|
||||||
} else {
|
} else {
|
||||||
printf("Error opening automessage.txt\n");
|
dolog("Error opening automessage.txt");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
s_putstring(socket, "No automessage!\r\n");
|
s_putstring(socket, "No automessage!\r\n");
|
||||||
@ -491,7 +491,7 @@ void runbbs(int socket, char *ip) {
|
|||||||
mynode = i;
|
mynode = i;
|
||||||
nodefile = fopen(buffer, "w");
|
nodefile = fopen(buffer, "w");
|
||||||
if (!nodefile) {
|
if (!nodefile) {
|
||||||
printf("Error opening nodefile!\n");
|
dolog("Error opening nodefile!");
|
||||||
close(socket);
|
close(socket);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -548,7 +548,7 @@ void runbbs(int socket, char *ip) {
|
|||||||
if (stat(buffer, &s) == 0) {
|
if (stat(buffer, &s) == 0) {
|
||||||
nodefile = fopen(buffer, "r");
|
nodefile = fopen(buffer, "r");
|
||||||
if (!nodefile) {
|
if (!nodefile) {
|
||||||
printf("Error opening nodefile!\n");
|
dolog("Error opening nodefile!");
|
||||||
disconnect(socket, "Error opening nodefile!");
|
disconnect(socket, "Error opening nodefile!");
|
||||||
}
|
}
|
||||||
fgets(buffer, 256, nodefile);
|
fgets(buffer, 256, nodefile);
|
||||||
@ -566,7 +566,7 @@ void runbbs(int socket, char *ip) {
|
|||||||
sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode);
|
sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode);
|
||||||
nodefile = fopen(buffer, "w");
|
nodefile = fopen(buffer, "w");
|
||||||
if (!nodefile) {
|
if (!nodefile) {
|
||||||
printf("Error opening nodefile!\n");
|
dolog("Error opening nodefile!");
|
||||||
close(socket);
|
close(socket);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
92
bbs_list.c
92
bbs_list.c
@ -15,7 +15,7 @@ void add_bbs(int socket, struct user_record *user) {
|
|||||||
"sysop TEXT,"
|
"sysop TEXT,"
|
||||||
"telnet TEXT,"
|
"telnet TEXT,"
|
||||||
"owner INTEGER);";
|
"owner INTEGER);";
|
||||||
|
|
||||||
char *insert_sql = "INSERT INTO bbslist (bbsname, sysop, telnet, owner) VALUES(?,?, ?, ?)";
|
char *insert_sql = "INSERT INTO bbslist (bbsname, sysop, telnet, owner) VALUES(?,?, ?, ?)";
|
||||||
|
|
||||||
char bbsname[19];
|
char bbsname[19];
|
||||||
@ -23,20 +23,20 @@ void add_bbs(int socket, struct user_record *user) {
|
|||||||
char telnet[39];
|
char telnet[39];
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
char c;
|
char c;
|
||||||
char *err_msg = 0;
|
char *err_msg = 0;
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
sqlite3_stmt *res;
|
sqlite3_stmt *res;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
s_putstring(socket, "\r\n\e[1;37mEnter the BBS Name: \e[0m");
|
s_putstring(socket, "\r\n\e[1;37mEnter the BBS Name: \e[0m");
|
||||||
s_readstring(socket, bbsname, 18);
|
s_readstring(socket, bbsname, 18);
|
||||||
|
|
||||||
s_putstring(socket, "\r\n\e[1;37mEnter the Sysop's Name: \e[0m");
|
s_putstring(socket, "\r\n\e[1;37mEnter the Sysop's Name: \e[0m");
|
||||||
s_readstring(socket, sysop, 16);
|
s_readstring(socket, sysop, 16);
|
||||||
|
|
||||||
s_putstring(socket, "\r\n\e[1;37mEnter the Telnet URL: \e[0m");
|
s_putstring(socket, "\r\n\e[1;37mEnter the Telnet URL: \e[0m");
|
||||||
s_readstring(socket, telnet, 38);
|
s_readstring(socket, telnet, 38);
|
||||||
|
|
||||||
s_putstring(socket, "\r\nYou entered:\r\n");
|
s_putstring(socket, "\r\nYou entered:\r\n");
|
||||||
s_putstring(socket, "\e[1;30m----------------------------------------------\e[0m\r\n");
|
s_putstring(socket, "\e[1;30m----------------------------------------------\e[0m\r\n");
|
||||||
sprintf(buffer, "\e[1;37mBBS Name: \e[1;32m%s\r\n", bbsname);
|
sprintf(buffer, "\e[1;37mBBS Name: \e[1;32m%s\r\n", bbsname);
|
||||||
@ -47,55 +47,55 @@ void add_bbs(int socket, struct user_record *user) {
|
|||||||
s_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
s_putstring(socket, "\e[1;30m----------------------------------------------\e[0m\r\n");
|
s_putstring(socket, "\e[1;30m----------------------------------------------\e[0m\r\n");
|
||||||
s_putstring(socket, "Is this correct? (Y/N) :");
|
s_putstring(socket, "Is this correct? (Y/N) :");
|
||||||
|
|
||||||
c = s_getc(socket);
|
c = s_getc(socket);
|
||||||
if (tolower(c) == 'y') {
|
if (tolower(c) == 'y') {
|
||||||
sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path);
|
sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
|
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||||
if (rc != SQLITE_OK ) {
|
if (rc != SQLITE_OK ) {
|
||||||
|
|
||||||
fprintf(stderr, "SQL error: %s\n", err_msg);
|
dolog("SQL error: %s", err_msg);
|
||||||
|
|
||||||
sqlite3_free(err_msg);
|
sqlite3_free(err_msg);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0);
|
rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0);
|
||||||
|
|
||||||
if (rc == SQLITE_OK) {
|
if (rc == SQLITE_OK) {
|
||||||
sqlite3_bind_text(res, 1, bbsname, -1, 0);
|
sqlite3_bind_text(res, 1, bbsname, -1, 0);
|
||||||
sqlite3_bind_text(res, 2, sysop, -1, 0);
|
sqlite3_bind_text(res, 2, sysop, -1, 0);
|
||||||
sqlite3_bind_text(res, 3, telnet, -1, 0);
|
sqlite3_bind_text(res, 3, telnet, -1, 0);
|
||||||
sqlite3_bind_int(res, 4, user->id);
|
sqlite3_bind_int(res, 4, user->id);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rc = sqlite3_step(res);
|
rc = sqlite3_step(res);
|
||||||
|
|
||||||
if (rc != SQLITE_DONE) {
|
if (rc != SQLITE_DONE) {
|
||||||
|
|
||||||
printf("execution failed: %s", sqlite3_errmsg(db));
|
dolog("execution failed: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
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_putstring(socket, "\r\n\e[1;32mAdded!\e[0m\r\n");
|
||||||
} else {
|
} else {
|
||||||
s_putstring(socket, "\r\n\e[1;31mAborted!\e[0m\r\n");
|
s_putstring(socket, "\r\n\e[1;31mAborted!\e[0m\r\n");
|
||||||
@ -111,13 +111,13 @@ void delete_bbs(int socket, struct user_record *user) {
|
|||||||
char *dsql = "DELETE FROM bbslist WHERE id=?";
|
char *dsql = "DELETE FROM bbslist WHERE id=?";
|
||||||
int i;
|
int i;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
s_putstring(socket, "\r\nPlease enter the id of the BBS you want to delete: ");
|
s_putstring(socket, "\r\nPlease enter the id of the BBS you want to delete: ");
|
||||||
s_readstring(socket, buffer, 5);
|
s_readstring(socket, buffer, 5);
|
||||||
i = atoi(buffer);
|
i = atoi(buffer);
|
||||||
|
|
||||||
sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path);
|
sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
return;
|
return;
|
||||||
@ -165,12 +165,12 @@ void list_bbses(int socket) {
|
|||||||
int rc;
|
int rc;
|
||||||
char *sql = "SELECT id,bbsname,sysop,telnet FROM bbslist";
|
char *sql = "SELECT id,bbsname,sysop,telnet FROM bbslist";
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path);
|
sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -190,29 +190,29 @@ void list_bbses(int socket) {
|
|||||||
if (i == 20) {
|
if (i == 20) {
|
||||||
sprintf(buffer, "Press any key to continue...\r\n");
|
sprintf(buffer, "Press any key to continue...\r\n");
|
||||||
s_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
s_getc(socket);
|
s_getc(socket);
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
|
s_putstring(socket, "\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");
|
sprintf(buffer, "Press any key to continue...\r\n");
|
||||||
s_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
s_getc(socket);
|
s_getc(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bbs_list(int socket, struct user_record *user) {
|
void bbs_list(int socket, 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_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");
|
||||||
|
|
||||||
c = s_getc(socket);
|
c = s_getc(socket);
|
||||||
|
|
||||||
switch(tolower(c)) {
|
switch(tolower(c)) {
|
||||||
case 'l':
|
case 'l':
|
||||||
list_bbses(socket);
|
list_bbses(socket);
|
||||||
|
84
doors.c
84
doors.c
@ -42,22 +42,22 @@ int write_door32sys(int socket, struct user_record *user) {
|
|||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
sprintf(buffer, "%s/node%d", conf.bbs_path, mynode);
|
sprintf(buffer, "%s/node%d", conf.bbs_path, mynode);
|
||||||
|
|
||||||
if (stat(buffer, &s) != 0) {
|
if (stat(buffer, &s) != 0) {
|
||||||
mkdir(buffer, 0755);
|
mkdir(buffer, 0755);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buffer, "%s/node%d/door32.sys", conf.bbs_path, mynode);
|
sprintf(buffer, "%s/node%d/door32.sys", conf.bbs_path, mynode);
|
||||||
|
|
||||||
fptr = fopen(buffer, "w");
|
fptr = fopen(buffer, "w");
|
||||||
|
|
||||||
if (!fptr) {
|
if (!fptr) {
|
||||||
printf("Unable to open %s for writing!\n", buffer);
|
dolog("Unable to open %s for writing!", buffer);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fptr, "2\n"); // telnet type
|
fprintf(fptr, "2\n"); // telnet type
|
||||||
fprintf(fptr, "%d\n", socket); // socket
|
fprintf(fptr, "%d\n", socket); // socket
|
||||||
fprintf(fptr, "38400\n"); // baudrate
|
fprintf(fptr, "38400\n"); // baudrate
|
||||||
@ -69,30 +69,30 @@ int write_door32sys(int socket, struct user_record *user) {
|
|||||||
fprintf(fptr, "%d\n", user->timeleft);
|
fprintf(fptr, "%d\n", user->timeleft);
|
||||||
fprintf(fptr, "1\n"); // ansi emulation = 1
|
fprintf(fptr, "1\n"); // ansi emulation = 1
|
||||||
fprintf(fptr, "%d\n", mynode);
|
fprintf(fptr, "%d\n", mynode);
|
||||||
|
|
||||||
fclose(fptr);
|
fclose(fptr);
|
||||||
|
|
||||||
// create dorinfo1.def
|
// create dorinfo1.def
|
||||||
|
|
||||||
sprintf(buffer, "%s/node%d", conf.bbs_path, mynode);
|
sprintf(buffer, "%s/node%d", conf.bbs_path, mynode);
|
||||||
|
|
||||||
if (stat(buffer, &s) != 0) {
|
if (stat(buffer, &s) != 0) {
|
||||||
mkdir(buffer, 0755);
|
mkdir(buffer, 0755);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buffer, "%s/node%d/dorinfo1.def", conf.bbs_path, mynode);
|
sprintf(buffer, "%s/node%d/dorinfo1.def", conf.bbs_path, mynode);
|
||||||
|
|
||||||
fptr = fopen(buffer, "w");
|
fptr = fopen(buffer, "w");
|
||||||
|
|
||||||
if (!fptr) {
|
if (!fptr) {
|
||||||
printf("Unable to open %s for writing!\n", buffer);
|
dolog("Unable to open %s for writing!", buffer);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(buffer, conf.sysop_name);
|
strcpy(buffer, conf.sysop_name);
|
||||||
|
|
||||||
ptr = NULL;
|
ptr = NULL;
|
||||||
|
|
||||||
for (i=0;i<strlen(buffer);i++) {
|
for (i=0;i<strlen(buffer);i++) {
|
||||||
if (buffer[i] == ' ') {
|
if (buffer[i] == ' ') {
|
||||||
ptr = &buffer[i+1];
|
ptr = &buffer[i+1];
|
||||||
@ -100,7 +100,7 @@ int write_door32sys(int socket, struct user_record *user) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fptr, "%s\n", conf.bbs_name); // telnet type
|
fprintf(fptr, "%s\n", conf.bbs_name); // telnet type
|
||||||
fprintf(fptr, "%s\n", buffer);
|
fprintf(fptr, "%s\n", buffer);
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
@ -119,10 +119,10 @@ int write_door32sys(int socket, struct user_record *user) {
|
|||||||
fprintf(fptr, "%d\n", user->timeleft);
|
fprintf(fptr, "%d\n", user->timeleft);
|
||||||
fprintf(fptr, "-1\n");
|
fprintf(fptr, "-1\n");
|
||||||
|
|
||||||
|
|
||||||
fclose(fptr);
|
fclose(fptr);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,27 +140,27 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
|
|||||||
int t;
|
int t;
|
||||||
struct winsize ws;
|
struct winsize ws;
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
|
|
||||||
timeoutpaused = 1;
|
timeoutpaused = 1;
|
||||||
|
|
||||||
if (write_door32sys(socket, user) != 0) {
|
if (write_door32sys(socket, user) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stdio) {
|
if (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", socket);
|
||||||
arguments[2] = strdup(buffer);
|
arguments[2] = strdup(buffer);
|
||||||
arguments[3] = NULL;
|
arguments[3] = NULL;
|
||||||
|
|
||||||
ws.ws_row = 24;
|
ws.ws_row = 24;
|
||||||
ws.ws_col = 80;
|
ws.ws_col = 80;
|
||||||
|
|
||||||
running_door = 1;
|
running_door = 1;
|
||||||
|
|
||||||
if (openpty(&master, &slave, NULL, NULL, &ws) == 0) {
|
if (openpty(&master, &slave, NULL, NULL, &ws) == 0) {
|
||||||
sa.sa_handler = doorchld_handler;
|
sa.sa_handler = doorchld_handler;
|
||||||
sigemptyset(&sa.sa_mask);
|
sigemptyset(&sa.sa_mask);
|
||||||
@ -169,26 +169,26 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
|
|||||||
perror("sigaction");
|
perror("sigaction");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
return;
|
return;
|
||||||
} else if (pid == 0) {
|
} else if (pid == 0) {
|
||||||
|
|
||||||
close(master);
|
close(master);
|
||||||
dup2(slave, 0);
|
dup2(slave, 0);
|
||||||
dup2(slave, 1);
|
dup2(slave, 1);
|
||||||
|
|
||||||
close(slave);
|
close(slave);
|
||||||
|
|
||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
ioctl(0, TIOCSCTTY, 1);
|
ioctl(0, TIOCSCTTY, 1);
|
||||||
|
|
||||||
execvp(cmd, arguments);
|
execvp(cmd, arguments);
|
||||||
} else {
|
} else {
|
||||||
running_door_pid = pid;
|
running_door_pid = pid;
|
||||||
|
|
||||||
while(running_door != 0) {
|
while(running_door != 0) {
|
||||||
FD_ZERO(&fdset);
|
FD_ZERO(&fdset);
|
||||||
FD_SET(master, &fdset);
|
FD_SET(master, &fdset);
|
||||||
@ -245,7 +245,7 @@ int door_menu(int socket, struct user_record *user) {
|
|||||||
char *lRet;
|
char *lRet;
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if (conf.script_path != NULL) {
|
if (conf.script_path != NULL) {
|
||||||
sprintf(buffer, "%s/doors.lua", conf.script_path);
|
sprintf(buffer, "%s/doors.lua", conf.script_path);
|
||||||
if (stat(buffer, &s) == 0) {
|
if (stat(buffer, &s) == 0) {
|
||||||
@ -256,7 +256,7 @@ int door_menu(int socket, struct user_record *user) {
|
|||||||
do_internal_menu = 0;
|
do_internal_menu = 0;
|
||||||
result = lua_pcall(L, 0, 1, 0);
|
result = lua_pcall(L, 0, 1, 0);
|
||||||
if (result) {
|
if (result) {
|
||||||
fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1));
|
dolog("Failed to run script: %s", lua_tostring(L, -1));
|
||||||
do_internal_menu = 1;
|
do_internal_menu = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -269,16 +269,16 @@ 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(socket, "doors");
|
||||||
|
|
||||||
sprintf(prompt, "\e[0m\r\nTL: %dm :> ", user->timeleft);
|
sprintf(prompt, "\e[0m\r\nTL: %dm :> ", user->timeleft);
|
||||||
s_putstring(socket, prompt);
|
s_putstring(socket, prompt);
|
||||||
|
|
||||||
c = s_getc(socket);
|
c = s_getc(socket);
|
||||||
} else {
|
} else {
|
||||||
lua_getglobal(L, "menu");
|
lua_getglobal(L, "menu");
|
||||||
result = lua_pcall(L, 0, 1, 0);
|
result = lua_pcall(L, 0, 1, 0);
|
||||||
if (result) {
|
if (result) {
|
||||||
fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1));
|
dolog("Failed to run script: %s", lua_tostring(L, -1));
|
||||||
do_internal_menu = 1;
|
do_internal_menu = 1;
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
continue;
|
continue;
|
||||||
@ -292,7 +292,7 @@ int door_menu(int socket, struct user_record *user) {
|
|||||||
dodoors = 1;
|
dodoors = 1;
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
{
|
{
|
||||||
s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)");
|
s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)");
|
||||||
c = s_getc(socket);
|
c = s_getc(socket);
|
||||||
if (tolower(c) == 'y') {
|
if (tolower(c) == 'y') {
|
||||||
|
188
email.c
188
email.c
@ -26,10 +26,10 @@ void send_email(int socket, struct user_record *user) {
|
|||||||
"seen INTEGER);";
|
"seen INTEGER);";
|
||||||
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_putstring(socket, "\r\nTO: ");
|
||||||
s_readstring(socket, buffer, 16);
|
s_readstring(socket, buffer, 16);
|
||||||
|
|
||||||
if (strlen(buffer) == 0) {
|
if (strlen(buffer) == 0) {
|
||||||
s_putstring(socket, "\r\nAborted\r\n");
|
s_putstring(socket, "\r\nAborted\r\n");
|
||||||
return;
|
return;
|
||||||
@ -38,7 +38,7 @@ void send_email(int socket, struct user_record *user) {
|
|||||||
s_putstring(socket, "\r\n\r\nInvalid Username\r\n");
|
s_putstring(socket, "\r\n\r\nInvalid Username\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
recipient = strdup(buffer);
|
recipient = strdup(buffer);
|
||||||
s_putstring(socket, "\r\nSUBJECT: ");
|
s_putstring(socket, "\r\nSUBJECT: ");
|
||||||
s_readstring(socket, buffer, 25);
|
s_readstring(socket, buffer, 25);
|
||||||
@ -48,54 +48,54 @@ void send_email(int socket, struct user_record *user) {
|
|||||||
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(socket, 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);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
|
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
|
||||||
if (rc != SQLITE_OK ) {
|
if (rc != SQLITE_OK ) {
|
||||||
|
|
||||||
fprintf(stderr, "SQL error: %s\n", err_msg);
|
dolog("SQL error: %s", err_msg);
|
||||||
|
|
||||||
sqlite3_free(err_msg);
|
sqlite3_free(err_msg);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(db, isql, -1, &res, 0);
|
rc = sqlite3_prepare_v2(db, isql, -1, &res, 0);
|
||||||
|
|
||||||
if (rc == SQLITE_OK) {
|
if (rc == SQLITE_OK) {
|
||||||
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
||||||
sqlite3_bind_text(res, 2, recipient, -1, 0);
|
sqlite3_bind_text(res, 2, recipient, -1, 0);
|
||||||
sqlite3_bind_text(res, 3, subject, -1, 0);
|
sqlite3_bind_text(res, 3, subject, -1, 0);
|
||||||
sqlite3_bind_text(res, 4, msg, -1, 0);
|
sqlite3_bind_text(res, 4, msg, -1, 0);
|
||||||
sqlite3_bind_int(res, 5, time(NULL));
|
sqlite3_bind_int(res, 5, time(NULL));
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", 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_putstring(socket, "\r\nNo such email\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sqlite3_step(res);
|
sqlite3_step(res);
|
||||||
|
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
free(msg);
|
free(msg);
|
||||||
}
|
}
|
||||||
free(subject);
|
free(subject);
|
||||||
free(recipient);
|
free(recipient);
|
||||||
}
|
}
|
||||||
@ -120,26 +120,26 @@ void show_email(int socket, struct user_record *user, int msgno) {
|
|||||||
char c;
|
char c;
|
||||||
char *replybody;
|
char *replybody;
|
||||||
int chars;
|
int chars;
|
||||||
|
|
||||||
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
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_bind_text(res, 1, user->loginname, -1, 0);
|
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
||||||
sqlite3_bind_int(res, 2, msgno);
|
sqlite3_bind_int(res, 2, msgno);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", 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_putstring(socket, "\r\nNo such email\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (sqlite3_step(res) == SQLITE_ROW) {
|
if (sqlite3_step(res) == SQLITE_ROW) {
|
||||||
@ -148,8 +148,8 @@ void show_email(int socket, struct user_record *user, int msgno) {
|
|||||||
subject = strdup((char *)sqlite3_column_text(res, 2));
|
subject = strdup((char *)sqlite3_column_text(res, 2));
|
||||||
body = strdup((char *)sqlite3_column_text(res, 3));
|
body = strdup((char *)sqlite3_column_text(res, 3));
|
||||||
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);
|
sprintf(buffer, "\e[2J\e[1;32mFrom : \e[1;37m%s\r\n", sender);
|
||||||
s_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
sprintf(buffer, "\e[1;32mSubject : \e[1;37m%s\r\n", subject);
|
sprintf(buffer, "\e[1;32mSubject : \e[1;37m%s\r\n", subject);
|
||||||
@ -160,10 +160,10 @@ void show_email(int socket, struct user_record *user, int msgno) {
|
|||||||
strcat(buffer, "\r\n");
|
strcat(buffer, "\r\n");
|
||||||
s_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
|
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
|
||||||
|
|
||||||
lines = 0;
|
lines = 0;
|
||||||
chars = 0;
|
chars = 0;
|
||||||
|
|
||||||
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;
|
||||||
@ -180,24 +180,24 @@ void show_email(int socket, struct user_record *user, int msgno) {
|
|||||||
chars++;
|
chars++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(db, ssql, -1, &res, 0);
|
rc = sqlite3_prepare_v2(db, ssql, -1, &res, 0);
|
||||||
|
|
||||||
if (rc == SQLITE_OK) {
|
if (rc == SQLITE_OK) {
|
||||||
sqlite3_bind_int(res, 1, id);
|
sqlite3_bind_int(res, 1, id);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sqlite3_step(res);
|
sqlite3_step(res);
|
||||||
|
|
||||||
s_putstring(socket, "Press R to reply, D to delete Enter to quit...\r\n");
|
s_putstring(socket, "Press R to reply, D to delete Enter to quit...\r\n");
|
||||||
c = s_getc(socket);
|
c = s_getc(socket);
|
||||||
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) {
|
||||||
snprintf(buffer, 256, "RE: %s", subject);
|
snprintf(buffer, 256, "RE: %s", subject);
|
||||||
@ -208,58 +208,58 @@ 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 = editor(socket, user, body, sender);
|
||||||
replybody = external_editor(socket, 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);
|
||||||
|
|
||||||
if (rc == SQLITE_OK) {
|
if (rc == SQLITE_OK) {
|
||||||
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
||||||
sqlite3_bind_text(res, 2, sender, -1, 0);
|
sqlite3_bind_text(res, 2, sender, -1, 0);
|
||||||
sqlite3_bind_text(res, 3, subject, -1, 0);
|
sqlite3_bind_text(res, 3, subject, -1, 0);
|
||||||
sqlite3_bind_text(res, 4, replybody, -1, 0);
|
sqlite3_bind_text(res, 4, replybody, -1, 0);
|
||||||
sqlite3_bind_int(res, 5, time(NULL));
|
sqlite3_bind_int(res, 5, time(NULL));
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", 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_putstring(socket, "\r\nNo such email\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sqlite3_step(res);
|
sqlite3_step(res);
|
||||||
|
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
free(replybody);
|
free(replybody);
|
||||||
}
|
}
|
||||||
free(sender);
|
free(sender);
|
||||||
free(subject);
|
free(subject);
|
||||||
free(body);
|
free(body);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
} else if (tolower(c) == 'd') {
|
} else if (tolower(c) == 'd') {
|
||||||
free(sender);
|
free(sender);
|
||||||
free(subject);
|
free(subject);
|
||||||
free(body);
|
free(body);
|
||||||
|
|
||||||
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, id);
|
sqlite3_bind_int(res, 1, id);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", 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_putstring(socket, "\r\nNo such email\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sqlite3_step(res);
|
sqlite3_step(res);
|
||||||
|
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printf("Failed\n");
|
dolog("Failed");
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
}
|
}
|
||||||
@ -280,31 +280,31 @@ void list_emails(int socket, struct user_record *user) {
|
|||||||
int msgid;
|
int msgid;
|
||||||
int msgtoread;
|
int msgtoread;
|
||||||
struct tm msg_date;
|
struct tm msg_date;
|
||||||
|
|
||||||
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
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_bind_text(res, 1, user->loginname, -1, 0);
|
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", 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_putstring(socket, "\r\nYou have no email\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
msgid = 0;
|
msgid = 0;
|
||||||
|
|
||||||
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));
|
||||||
seen = sqlite3_column_int(res, 2);
|
seen = sqlite3_column_int(res, 2);
|
||||||
@ -316,10 +316,10 @@ void list_emails(int socket, struct user_record *user) {
|
|||||||
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, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
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, 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);
|
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, "Enter # to read, Q to quit or Enter to continue\r\n");
|
s_putstring(socket, "Enter # to read, Q to quit or Enter to continue\r\n");
|
||||||
|
|
||||||
@ -337,9 +337,9 @@ void list_emails(int socket, struct user_record *user) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
msgid++;
|
msgid++;
|
||||||
}
|
}
|
||||||
if (msgid == 0) {
|
if (msgid == 0) {
|
||||||
@ -354,7 +354,7 @@ void list_emails(int socket, struct user_record *user) {
|
|||||||
show_email(socket, user, msgtoread);
|
show_email(socket, user, msgtoread);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
@ -367,36 +367,36 @@ int mail_getemailcount(struct user_record *user) {
|
|||||||
char buffer[256];
|
char buffer[256];
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
sqlite3_stmt *res;
|
sqlite3_stmt *res;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
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_bind_text(res, 1, user->loginname, -1, 0);
|
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
if (sqlite3_step(res) == SQLITE_ROW) {
|
if (sqlite3_step(res) == SQLITE_ROW) {
|
||||||
count = sqlite3_column_int(res, 0);
|
count = sqlite3_column_int(res, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
209
files.c
209
files.c
@ -28,7 +28,7 @@ int tagged_count = 0;
|
|||||||
|
|
||||||
int ZXmitStr(u_char *str, int len, ZModem *info) {
|
int ZXmitStr(u_char *str, int len, ZModem *info) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i=0;i<len;i++) {
|
for (i=0;i<len;i++) {
|
||||||
if (str[i] == 255) {
|
if (str[i] == 255) {
|
||||||
if (write(info->ofd, &str[i], 1) == 0) {
|
if (write(info->ofd, &str[i], 1) == 0) {
|
||||||
@ -39,7 +39,7 @@ int ZXmitStr(u_char *str, int len, ZModem *info) {
|
|||||||
return ZmErrSys;
|
return ZmErrSys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ int ZAttn(ZModem *info) {
|
|||||||
|
|
||||||
for(ptr = info->attn; *ptr != '\0'; ++ptr) {
|
for(ptr = info->attn; *ptr != '\0'; ++ptr) {
|
||||||
if( *ptr == ATTNBRK ) {
|
if( *ptr == ATTNBRK ) {
|
||||||
|
|
||||||
} else if( *ptr == ATTNPSE ) {
|
} else if( *ptr == ATTNPSE ) {
|
||||||
sleep(1);
|
sleep(1);
|
||||||
} else {
|
} else {
|
||||||
@ -78,18 +78,17 @@ char *upload_path;
|
|||||||
char upload_filename[1024];
|
char upload_filename[1024];
|
||||||
|
|
||||||
FILE *ZOpenFile(char *name, u_long crc, ZModem *info) {
|
FILE *ZOpenFile(char *name, u_long crc, ZModem *info) {
|
||||||
|
|
||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
|
||||||
snprintf(upload_filename, 1023, "%s/%s", upload_path, basename(name));
|
snprintf(upload_filename, 1023, "%s/%s", upload_path, basename(name));
|
||||||
fprintf(stderr, "%s\n", upload_filename);
|
|
||||||
if (stat(upload_filename, &s) == 0) {
|
if (stat(upload_filename, &s) == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fptr = fopen(upload_filename, "wb");
|
fptr = fopen(upload_filename, "wb");
|
||||||
|
|
||||||
return fptr;
|
return fptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,14 +114,14 @@ int doIO(ZModem *zm) {
|
|||||||
int done = 0;
|
int done = 0;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
while(!done) {
|
while(!done) {
|
||||||
FD_ZERO(&readfds);
|
FD_ZERO(&readfds);
|
||||||
FD_SET(zm->ifd, &readfds) ;
|
FD_SET(zm->ifd, &readfds) ;
|
||||||
timeout.tv_sec = zm->timeout ;
|
timeout.tv_sec = zm->timeout ;
|
||||||
timeout.tv_usec = 0 ;
|
timeout.tv_usec = 0 ;
|
||||||
i = select(zm->ifd+1, &readfds,NULL,NULL, &timeout) ;
|
i = select(zm->ifd+1, &readfds,NULL,NULL, &timeout) ;
|
||||||
|
|
||||||
if( i==0 ) {
|
if( i==0 ) {
|
||||||
done = ZmodemTimeout(zm) ;
|
done = ZmodemTimeout(zm) ;
|
||||||
} else if (i > 0) {
|
} else if (i > 0) {
|
||||||
@ -130,7 +129,7 @@ int doIO(ZModem *zm) {
|
|||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
disconnect(zm->ifd, "Socket closed");
|
disconnect(zm->ifd, "Socket closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
for (j=0;j<len;j++) {
|
for (j=0;j<len;j++) {
|
||||||
if (buffer[j] == 255) {
|
if (buffer[j] == 255) {
|
||||||
@ -153,7 +152,7 @@ int doIO(ZModem *zm) {
|
|||||||
} else {
|
} else {
|
||||||
// SIG INT catch
|
// SIG INT catch
|
||||||
if (errno != EINTR) {
|
if (errno != EINTR) {
|
||||||
printf("SELECT ERROR %s\n", strerror(errno));
|
dolog("SELECT ERROR %s", strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,19 +165,19 @@ void upload_zmodem(int socket, struct user_record *user) {
|
|||||||
|
|
||||||
|
|
||||||
upload_path = conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->upload_path;
|
upload_path = conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->upload_path;
|
||||||
|
|
||||||
zm.attn = NULL;
|
zm.attn = NULL;
|
||||||
zm.windowsize = 0;
|
zm.windowsize = 0;
|
||||||
zm.bufsize = 0;
|
zm.bufsize = 0;
|
||||||
|
|
||||||
zm.ifd = socket;
|
zm.ifd = socket;
|
||||||
zm.ofd = socket;
|
zm.ofd = socket;
|
||||||
|
|
||||||
zm.zrinitflags = 0;
|
zm.zrinitflags = 0;
|
||||||
zm.zsinitflags = 0;
|
zm.zsinitflags = 0;
|
||||||
|
|
||||||
zm.packetsize = 1024;
|
zm.packetsize = 1024;
|
||||||
|
|
||||||
done = ZmodemRInit(&zm);
|
done = ZmodemRInit(&zm);
|
||||||
|
|
||||||
doIO(&zm);
|
doIO(&zm);
|
||||||
@ -202,9 +201,9 @@ void upload(int socket, struct user_record *user) {
|
|||||||
int rc;
|
int rc;
|
||||||
struct stat s;
|
struct stat s;
|
||||||
char *err_msg = NULL;
|
char *err_msg = NULL;
|
||||||
|
|
||||||
upload_zmodem(socket, user);
|
upload_zmodem(socket, user);
|
||||||
|
|
||||||
s_putstring(socket, "\r\nPlease enter a description:\r\n");
|
s_putstring(socket, "\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++) {
|
||||||
@ -217,45 +216,45 @@ void upload(int socket, struct user_record *user) {
|
|||||||
strcat(buffer, buffer2);
|
strcat(buffer, buffer2);
|
||||||
strcat(buffer, "\n");
|
strcat(buffer, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buffer3, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database);
|
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);
|
rc = sqlite3_open(buffer3, &db);
|
||||||
|
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||||
if (rc != SQLITE_OK ) {
|
if (rc != SQLITE_OK ) {
|
||||||
fprintf(stderr, "SQL error: %s\n", err_msg);
|
dolog("SQL error: %s", err_msg);
|
||||||
sqlite3_free(err_msg);
|
sqlite3_free(err_msg);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
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) {
|
||||||
stat(upload_filename, &s);
|
stat(upload_filename, &s);
|
||||||
|
|
||||||
sqlite3_bind_text(res, 1, upload_filename, -1, 0);
|
sqlite3_bind_text(res, 1, upload_filename, -1, 0);
|
||||||
sqlite3_bind_text(res, 2, buffer, -1, 0);
|
sqlite3_bind_text(res, 2, buffer, -1, 0);
|
||||||
sqlite3_bind_int(res, 3, s.st_size);
|
sqlite3_bind_int(res, 3, s.st_size);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3_step(res);
|
rc = sqlite3_step(res);
|
||||||
|
|
||||||
if (rc != SQLITE_DONE) {
|
if (rc != SQLITE_DONE) {
|
||||||
printf("execution failed: %s", sqlite3_errmsg(db));
|
dolog("execution failed: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
@ -271,43 +270,43 @@ void download_zmodem(int socket, struct user_record *user, char *filename) {
|
|||||||
int j;
|
int j;
|
||||||
int len;
|
int len;
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
u_char buffer[2048];
|
u_char buffer[2048];
|
||||||
u_char buffer2[1024];
|
u_char buffer2[1024];
|
||||||
|
|
||||||
printf("Attempting to upload %s\n", filename);
|
dolog("Attempting to upload %s", filename);
|
||||||
|
|
||||||
zm.attn = NULL;
|
zm.attn = NULL;
|
||||||
zm.windowsize = 0;
|
zm.windowsize = 0;
|
||||||
zm.bufsize = 0;
|
zm.bufsize = 0;
|
||||||
|
|
||||||
zm.ifd = socket;
|
zm.ifd = socket;
|
||||||
zm.ofd = socket;
|
zm.ofd = socket;
|
||||||
|
|
||||||
zm.zrinitflags = 0;
|
zm.zrinitflags = 0;
|
||||||
zm.zsinitflags = 0;
|
zm.zsinitflags = 0;
|
||||||
|
|
||||||
zm.packetsize = 1024;
|
zm.packetsize = 1024;
|
||||||
|
|
||||||
|
|
||||||
ZmodemTInit(&zm) ;
|
ZmodemTInit(&zm) ;
|
||||||
done = doIO(&zm);
|
done = doIO(&zm);
|
||||||
if ( done != ZmDone ) {
|
if ( done != ZmDone ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
done = ZmodemTFile(filename, basename(filename), ZCBIN,0,0,0,0,0, &zm) ;
|
done = ZmodemTFile(filename, basename(filename), ZCBIN,0,0,0,0,0, &zm) ;
|
||||||
|
|
||||||
switch( done ) {
|
switch( done ) {
|
||||||
case 0:
|
case 0:
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case ZmErrCantOpen:
|
case ZmErrCantOpen:
|
||||||
fprintf(stderr, "cannot open file \"%s\": %s\n", filename, strerror(errno)) ;
|
dolog("cannot open file \"%s\": %s\n", filename, strerror(errno)) ;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case ZmFileTooLong:
|
case ZmFileTooLong:
|
||||||
fprintf(stderr, "filename \"%s\" too long, skipping...\n", filename) ;
|
dolog("filename \"%s\" too long, skipping...\n", filename) ;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case ZmDone:
|
case ZmDone:
|
||||||
@ -316,17 +315,17 @@ void download_zmodem(int socket, struct user_record *user, char *filename) {
|
|||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!done) {
|
if (!done) {
|
||||||
done = doIO(&zm);
|
done = doIO(&zm);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( done != ZmDone ) {
|
if ( done != ZmDone ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
done = ZmodemTFinish(&zm);
|
done = ZmodemTFinish(&zm);
|
||||||
|
|
||||||
if (!done) {
|
if (!done) {
|
||||||
done = doIO(&zm);
|
done = doIO(&zm);
|
||||||
}
|
}
|
||||||
@ -342,55 +341,55 @@ void download(int socket, struct user_record *user) {
|
|||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
sqlite3_stmt *res;
|
sqlite3_stmt *res;
|
||||||
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(socket, 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);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
|
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
rc = sqlite3_prepare_v2(db, ssql, -1, &res, 0);
|
rc = sqlite3_prepare_v2(db, ssql, -1, &res, 0);
|
||||||
|
|
||||||
if (rc == SQLITE_OK) {
|
if (rc == SQLITE_OK) {
|
||||||
sqlite3_bind_text(res, 1, tagged_files[i], -1, 0);
|
sqlite3_bind_text(res, 1, tagged_files[i], -1, 0);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3_step(res);
|
rc = sqlite3_step(res);
|
||||||
|
|
||||||
if (rc != SQLITE_ROW) {
|
if (rc != SQLITE_ROW) {
|
||||||
fprintf(stderr, "Downloaded a file not in database!!!!!");
|
dolog("Downloaded a file not in database!!!!!");
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
dloads = sqlite3_column_int(res, 0);
|
dloads = sqlite3_column_int(res, 0);
|
||||||
dloads++;
|
dloads++;
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(db, usql, -1, &res, 0);
|
rc = sqlite3_prepare_v2(db, usql, -1, &res, 0);
|
||||||
|
|
||||||
if (rc == SQLITE_OK) {
|
if (rc == SQLITE_OK) {
|
||||||
sqlite3_bind_int(res, 1, dloads);
|
sqlite3_bind_int(res, 1, dloads);
|
||||||
sqlite3_bind_text(res, 2, tagged_files[i], -1, 0);
|
sqlite3_bind_text(res, 2, tagged_files[i], -1, 0);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3_step(res);
|
rc = sqlite3_step(res);
|
||||||
|
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0;i<tagged_count;i++) {
|
for (i=0;i<tagged_count;i++) {
|
||||||
free(tagged_files[i]);
|
free(tagged_files[i]);
|
||||||
}
|
}
|
||||||
@ -414,28 +413,28 @@ void list_files(int socket, struct user_record *user) {
|
|||||||
int z;
|
int z;
|
||||||
int k;
|
int k;
|
||||||
int match;
|
int match;
|
||||||
|
|
||||||
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);
|
sprintf(buffer, "%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) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
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_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
s_putstring(socket, "\r\nNo files in this area!\r\n");
|
s_putstring(socket, "\r\nNo files in this area!\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
files_c = 0;
|
files_c = 0;
|
||||||
|
|
||||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||||
@ -449,15 +448,15 @@ void list_files(int socket, 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_c++;
|
files_c++;
|
||||||
}
|
}
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
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_putstring(socket, "\r\nNo files in this area!\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s_putstring(socket, "\r\n");
|
s_putstring(socket, "\r\n");
|
||||||
for (i=0;i<files_c;i++) {
|
for (i=0;i<files_c;i++) {
|
||||||
@ -534,7 +533,7 @@ void list_files(int socket, struct user_record *user) {
|
|||||||
} else {
|
} else {
|
||||||
s_putchar(socket, files_e[i]->description[j]);
|
s_putchar(socket, files_e[i]->description[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (1) {
|
while (1) {
|
||||||
s_putstring(socket, "\r\n\e[0mEnter # to tag, Enter to quit: ");
|
s_putstring(socket, "\r\n\e[0mEnter # to tag, Enter to quit: ");
|
||||||
@ -576,7 +575,7 @@ void list_files(int socket, struct user_record *user) {
|
|||||||
s_putstring(socket, "\r\nSorry, you don't have permission to download from this area\r\n");
|
s_putstring(socket, "\r\nSorry, you don't have permission to download from this area\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -592,7 +591,7 @@ int file_menu(int socket, struct user_record *user) {
|
|||||||
char *lRet;
|
char *lRet;
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if (conf.script_path != NULL) {
|
if (conf.script_path != NULL) {
|
||||||
sprintf(prompt, "%s/filemenu.lua", conf.script_path);
|
sprintf(prompt, "%s/filemenu.lua", conf.script_path);
|
||||||
if (stat(prompt, &s) == 0) {
|
if (stat(prompt, &s) == 0) {
|
||||||
@ -603,7 +602,7 @@ int file_menu(int socket, struct user_record *user) {
|
|||||||
do_internal_menu = 0;
|
do_internal_menu = 0;
|
||||||
result = lua_pcall(L, 0, 1, 0);
|
result = lua_pcall(L, 0, 1, 0);
|
||||||
if (result) {
|
if (result) {
|
||||||
fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1));
|
dolog("Failed to run script: %s", lua_tostring(L, -1));
|
||||||
do_internal_menu = 1;
|
do_internal_menu = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -612,27 +611,27 @@ int file_menu(int socket, struct user_record *user) {
|
|||||||
} else {
|
} else {
|
||||||
do_internal_menu = 1;
|
do_internal_menu = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!dofiles) {
|
while (!dofiles) {
|
||||||
if (do_internal_menu == 1) {
|
if (do_internal_menu == 1) {
|
||||||
s_displayansi(socket, "filemenu");
|
s_displayansi(socket, "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);
|
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_putstring(socket, prompt);
|
s_putstring(socket, prompt);
|
||||||
|
|
||||||
c = s_getc(socket);
|
c = s_getc(socket);
|
||||||
} else {
|
} else {
|
||||||
lua_getglobal(L, "menu");
|
lua_getglobal(L, "menu");
|
||||||
result = lua_pcall(L, 0, 1, 0);
|
result = lua_pcall(L, 0, 1, 0);
|
||||||
if (result) {
|
if (result) {
|
||||||
fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1));
|
dolog("Failed to run script: %s", lua_tostring(L, -1));
|
||||||
do_internal_menu = 1;
|
do_internal_menu = 1;
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
lRet = (char *)lua_tostring(L, -1);
|
lRet = (char *)lua_tostring(L, -1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
c = lRet[0];
|
c = lRet[0];
|
||||||
}
|
}
|
||||||
switch(tolower(c)) {
|
switch(tolower(c)) {
|
||||||
case 'i':
|
case 'i':
|
||||||
@ -686,7 +685,7 @@ int file_menu(int socket, struct user_record *user) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
list_files(socket, user);
|
list_files(socket, user);
|
||||||
break;
|
break;
|
||||||
@ -704,7 +703,7 @@ int file_menu(int socket, struct user_record *user) {
|
|||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
{
|
{
|
||||||
// Clear tagged files
|
// Clear tagged files
|
||||||
if (tagged_count > 0) {
|
if (tagged_count > 0) {
|
||||||
for (i=0;i<tagged_count;i++) {
|
for (i=0;i<tagged_count;i++) {
|
||||||
free(tagged_files[i]);
|
free(tagged_files[i]);
|
||||||
|
30
mail_menu.c
30
mail_menu.c
@ -48,7 +48,7 @@ s_JamBase *open_jam_base(char *path) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
free(jb);
|
free(jb);
|
||||||
printf("Got %d\n", ret);
|
dolog("Got %d", ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r
|
|||||||
|
|
||||||
jb = open_jam_base(conf.mail_conferences[msgconf]->mail_areas[msgarea]->path);
|
jb = open_jam_base(conf.mail_conferences[msgconf]->mail_areas[msgarea]->path);
|
||||||
if (!jb) {
|
if (!jb) {
|
||||||
printf("Error opening JAM base.. %s\n", conf.mail_conferences[msgconf]->mail_areas[msgarea]->path);
|
dolog("Error opening JAM base.. %s", conf.mail_conferences[msgconf]->mail_areas[msgarea]->path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r
|
|||||||
memset(&jmh, 0, sizeof(s_JamMsgHeader));
|
memset(&jmh, 0, sizeof(s_JamMsgHeader));
|
||||||
z = JAM_ReadMsgHeader(jb, i, &jmh, &jsp);
|
z = JAM_ReadMsgHeader(jb, i, &jmh, &jsp);
|
||||||
if (z != 0) {
|
if (z != 0) {
|
||||||
printf("Failed to read msg header: %d Erro %d\n", z, JAM_Errno(jb));
|
dolog("Failed to read msg header: %d Erro %d", z, JAM_Errno(jb));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,7 +730,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
|
|||||||
|
|
||||||
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);
|
||||||
if (!jb) {
|
if (!jb) {
|
||||||
printf("Error opening JAM base.. %s\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
|
dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -961,7 +961,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
|
|||||||
|
|
||||||
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);
|
||||||
if (!jb) {
|
if (!jb) {
|
||||||
printf("Error opening JAM base.. %s\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
|
dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
|
||||||
free(replybody);
|
free(replybody);
|
||||||
free(body);
|
free(body);
|
||||||
free(subject);
|
free(subject);
|
||||||
@ -1135,12 +1135,12 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh
|
|||||||
free(subject);
|
free(subject);
|
||||||
free(to);
|
free(to);
|
||||||
free(from);
|
free(from);
|
||||||
printf("Failed to lock msg base!\n");
|
dolog("Failed to lock msg base!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (JAM_AddMessage(jb, &jmh, jsp, (char *)replybody, strlen(replybody))) {
|
if (JAM_AddMessage(jb, &jmh, jsp, (char *)replybody, strlen(replybody))) {
|
||||||
printf("Failed to add message\n");
|
dolog("Failed to add message");
|
||||||
} else {
|
} else {
|
||||||
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) {
|
||||||
if (conf.netmail_sem != NULL) {
|
if (conf.netmail_sem != NULL) {
|
||||||
@ -1252,7 +1252,7 @@ int mail_menu(int socket, struct user_record *user) {
|
|||||||
do_internal_menu = 0;
|
do_internal_menu = 0;
|
||||||
result = lua_pcall(L, 0, 1, 0);
|
result = lua_pcall(L, 0, 1, 0);
|
||||||
if (result) {
|
if (result) {
|
||||||
fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1));
|
dolog("Failed to run script: %s", lua_tostring(L, -1));
|
||||||
do_internal_menu = 1;
|
do_internal_menu = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1275,7 +1275,7 @@ int mail_menu(int socket, struct user_record *user) {
|
|||||||
lua_getglobal(L, "menu");
|
lua_getglobal(L, "menu");
|
||||||
result = lua_pcall(L, 0, 1, 0);
|
result = lua_pcall(L, 0, 1, 0);
|
||||||
if (result) {
|
if (result) {
|
||||||
fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1));
|
dolog("Failed to run script: %s", lua_tostring(L, -1));
|
||||||
do_internal_menu = 1;
|
do_internal_menu = 1;
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
continue;
|
continue;
|
||||||
@ -1293,7 +1293,7 @@ int mail_menu(int socket, struct user_record *user) {
|
|||||||
if (msghs != NULL && msghs->msg_count > 0) {
|
if (msghs != NULL && msghs->msg_count > 0) {
|
||||||
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);
|
||||||
if (!jb) {
|
if (!jb) {
|
||||||
printf("Error opening JAM base.. %s\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
|
dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
all_unread = 0;
|
all_unread = 0;
|
||||||
@ -1402,7 +1402,7 @@ int mail_menu(int socket, struct user_record *user) {
|
|||||||
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);
|
||||||
if (!jb) {
|
if (!jb) {
|
||||||
printf("Error opening JAM base.. %s\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
|
dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
|
||||||
free(msg);
|
free(msg);
|
||||||
free(to);
|
free(to);
|
||||||
free(subject);
|
free(subject);
|
||||||
@ -1557,7 +1557,7 @@ int mail_menu(int socket, struct user_record *user) {
|
|||||||
free(msg);
|
free(msg);
|
||||||
free(to);
|
free(to);
|
||||||
free(subject);
|
free(subject);
|
||||||
printf("Failed to lock msg base!\n");
|
dolog("Failed to lock msg base!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1567,7 +1567,7 @@ int mail_menu(int socket, struct user_record *user) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (JAM_AddMessage(jb, &jmh, jsp, (char *)msg, strlen(msg))) {
|
if (JAM_AddMessage(jb, &jmh, jsp, (char *)msg, strlen(msg))) {
|
||||||
printf("Failed to add message\n");
|
dolog("Failed to add message");
|
||||||
} else {
|
} else {
|
||||||
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) {
|
||||||
if (conf.netmail_sem != NULL) {
|
if (conf.netmail_sem != NULL) {
|
||||||
@ -1600,7 +1600,7 @@ int mail_menu(int socket, struct user_record *user) {
|
|||||||
if (msghs != NULL && msghs->msg_count > 0) {
|
if (msghs != NULL && msghs->msg_count > 0) {
|
||||||
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);
|
||||||
if (!jb) {
|
if (!jb) {
|
||||||
printf("Error opening JAM base.. %s\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
|
dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
all_unread = 0;
|
all_unread = 0;
|
||||||
@ -1854,7 +1854,7 @@ void mail_scan(int socket, struct user_record *user) {
|
|||||||
}
|
}
|
||||||
jb = open_jam_base(conf.mail_conferences[i]->mail_areas[j]->path);
|
jb = open_jam_base(conf.mail_conferences[i]->mail_areas[j]->path);
|
||||||
if (!jb) {
|
if (!jb) {
|
||||||
printf("Unable to open message base\n");
|
dolog("Unable to open message base");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (JAM_ReadMBHeader(jb, &jbh) != 0) {
|
if (JAM_ReadMBHeader(jb, &jbh) != 0) {
|
||||||
|
12
main.c
12
main.c
@ -341,7 +341,7 @@ void server(int port) {
|
|||||||
|
|
||||||
socket_desc = socket(AF_INET, SOCK_STREAM, 0);
|
socket_desc = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (socket_desc == -1) {
|
if (socket_desc == -1) {
|
||||||
printf("Couldn't create socket..\n");
|
fprintf(stderr, "Couldn't create socket..\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ int main(int argc, char **argv) {
|
|||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
printf("Usage ./magicka config/bbs.ini port\n");
|
fprintf(stderr, "Usage ./magicka config/bbs.ini port\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,26 +412,26 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// Load BBS data
|
// Load BBS data
|
||||||
if (ini_parse(argv[1], handler, &conf) <0) {
|
if (ini_parse(argv[1], handler, &conf) <0) {
|
||||||
printf("Unable to load configuration ini (%s)!\n", argv[1]);
|
fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
// Load mail Areas
|
// Load mail Areas
|
||||||
for (i=0;i<conf.mail_conference_count;i++) {
|
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) {
|
if (ini_parse(conf.mail_conferences[i]->path, mail_area_handler, conf.mail_conferences[i]) <0) {
|
||||||
printf("Unable to load configuration ini (%s)!\n", conf.mail_conferences[i]->path);
|
fprintf(stderr, "Unable to load configuration ini (%s)!\n", conf.mail_conferences[i]->path);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Load file Subs
|
// Load file Subs
|
||||||
for (i=0;i<conf.file_directory_count;i++) {
|
for (i=0;i<conf.file_directory_count;i++) {
|
||||||
if (ini_parse(conf.file_directories[i]->path, file_sub_handler, conf.file_directories[i]) <0) {
|
if (ini_parse(conf.file_directories[i]->path, file_sub_handler, conf.file_directories[i]) <0) {
|
||||||
printf("Unable to load configuration ini (%s)!\n", conf.file_directories[i]->path);
|
fprintf(stderr, "Unable to load configuration ini (%s)!\n", conf.file_directories[i]->path);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ini_parse("config/doors.ini", door_config_handler, &conf) <0) {
|
if (ini_parse("config/doors.ini", door_config_handler, &conf) <0) {
|
||||||
printf("Unable to load configuration ini (doors.ini)!\n");
|
fprintf(stderr, "Unable to load configuration ini (doors.ini)!\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
main_menu.c
28
main_menu.c
@ -8,7 +8,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;
|
||||||
|
|
||||||
void main_menu(int socket, struct user_record *user) {
|
void main_menu(int socket, struct user_record *user) {
|
||||||
int doquit = 0;
|
int doquit = 0;
|
||||||
@ -21,7 +21,7 @@ void main_menu(int socket, struct user_record *user) {
|
|||||||
char *lRet;
|
char *lRet;
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if (conf.script_path != NULL) {
|
if (conf.script_path != NULL) {
|
||||||
sprintf(buffer, "%s/mainmenu.lua", conf.script_path);
|
sprintf(buffer, "%s/mainmenu.lua", conf.script_path);
|
||||||
if (stat(buffer, &s) == 0) {
|
if (stat(buffer, &s) == 0) {
|
||||||
@ -32,7 +32,7 @@ void main_menu(int socket, struct user_record *user) {
|
|||||||
do_internal_menu = 0;
|
do_internal_menu = 0;
|
||||||
result = lua_pcall(L, 0, 1, 0);
|
result = lua_pcall(L, 0, 1, 0);
|
||||||
if (result) {
|
if (result) {
|
||||||
fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1));
|
dolog("Failed to run script: %s", lua_tostring(L, -1));
|
||||||
do_internal_menu = 1;
|
do_internal_menu = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -41,22 +41,22 @@ void main_menu(int socket, struct user_record *user) {
|
|||||||
} else {
|
} else {
|
||||||
do_internal_menu = 1;
|
do_internal_menu = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!doquit) {
|
while (!doquit) {
|
||||||
|
|
||||||
if (do_internal_menu == 1) {
|
if (do_internal_menu == 1) {
|
||||||
s_displayansi(socket, "mainmenu");
|
s_displayansi(socket, "mainmenu");
|
||||||
|
|
||||||
|
|
||||||
sprintf(prompt, "\r\n\e[0mTL: %dm :> ", user->timeleft);
|
sprintf(prompt, "\r\n\e[0mTL: %dm :> ", user->timeleft);
|
||||||
s_putstring(socket, prompt);
|
s_putstring(socket, prompt);
|
||||||
|
|
||||||
c = s_getc(socket);
|
c = s_getc(socket);
|
||||||
} else {
|
} else {
|
||||||
lua_getglobal(L, "menu");
|
lua_getglobal(L, "menu");
|
||||||
result = lua_pcall(L, 0, 1, 0);
|
result = lua_pcall(L, 0, 1, 0);
|
||||||
if (result) {
|
if (result) {
|
||||||
fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1));
|
dolog("Failed to run script: %s", lua_tostring(L, -1));
|
||||||
do_internal_menu = 1;
|
do_internal_menu = 1;
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
continue;
|
continue;
|
||||||
@ -65,7 +65,7 @@ void main_menu(int socket, struct user_record *user) {
|
|||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
c = lRet[0];
|
c = lRet[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(tolower(c)) {
|
switch(tolower(c)) {
|
||||||
case 'o':
|
case 'o':
|
||||||
{
|
{
|
||||||
@ -75,11 +75,11 @@ void main_menu(int socket, struct user_record *user) {
|
|||||||
case 'a':
|
case 'a':
|
||||||
{
|
{
|
||||||
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_putstring(socket, "\r\n\e[1;32mText Files Collection\r\n");
|
||||||
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
|
s_putstring(socket, "\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);
|
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_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
@ -126,7 +126,7 @@ void main_menu(int socket, struct user_record *user) {
|
|||||||
{
|
{
|
||||||
i = 0;
|
i = 0;
|
||||||
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
|
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
|
||||||
|
|
||||||
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(socket, buffer);
|
||||||
@ -135,7 +135,7 @@ void main_menu(int socket, struct user_record *user) {
|
|||||||
s_getc(socket);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '1':
|
case '1':
|
||||||
|
220
users.c
220
users.c
@ -12,12 +12,12 @@ static int secLevel(void* user, const char* section, const char* name,
|
|||||||
const char* value)
|
const char* value)
|
||||||
{
|
{
|
||||||
struct sec_level_t *conf = (struct sec_level_t *)user;
|
struct sec_level_t *conf = (struct sec_level_t *)user;
|
||||||
|
|
||||||
if (strcasecmp(section, "main") == 0) {
|
if (strcasecmp(section, "main") == 0) {
|
||||||
if (strcasecmp(name, "time per day") == 0) {
|
if (strcasecmp(name, "time per day") == 0) {
|
||||||
conf->timeperday = atoi(value);
|
conf->timeperday = atoi(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,25 +26,25 @@ int save_user(struct user_record *user) {
|
|||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
sqlite3_stmt *res;
|
sqlite3_stmt *res;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
char *update_sql = "UPDATE users SET password=?, firstname=?,"
|
char *update_sql = "UPDATE users SET password=?, firstname=?,"
|
||||||
"lastname=?, email=?, location=?, sec_level=?, last_on=?, time_left=?, cur_mail_conf=?, cur_mail_area=?, cur_file_dir=?, cur_file_sub=?, times_on=? where loginname LIKE ?";
|
"lastname=?, email=?, location=?, sec_level=?, last_on=?, time_left=?, cur_mail_conf=?, cur_mail_area=?, cur_file_dir=?, cur_file_sub=?, times_on=? where loginname LIKE ?";
|
||||||
char *err_msg = 0;
|
char *err_msg = 0;
|
||||||
|
|
||||||
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
|
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(db, update_sql, -1, &res, 0);
|
rc = sqlite3_prepare_v2(db, update_sql, -1, &res, 0);
|
||||||
|
|
||||||
if (rc == SQLITE_OK) {
|
if (rc == SQLITE_OK) {
|
||||||
sqlite3_bind_text(res, 1, user->password, -1, 0);
|
sqlite3_bind_text(res, 1, user->password, -1, 0);
|
||||||
sqlite3_bind_text(res, 2, user->firstname, -1, 0);
|
sqlite3_bind_text(res, 2, user->firstname, -1, 0);
|
||||||
sqlite3_bind_text(res, 3, user->lastname, -1, 0);
|
sqlite3_bind_text(res, 3, user->lastname, -1, 0);
|
||||||
@ -60,16 +60,16 @@ int save_user(struct user_record *user) {
|
|||||||
sqlite3_bind_int(res, 13, user->timeson);
|
sqlite3_bind_int(res, 13, user->timeson);
|
||||||
sqlite3_bind_text(res, 14, user->loginname, -1, 0);
|
sqlite3_bind_text(res, 14, user->loginname, -1, 0);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rc = sqlite3_step(res);
|
rc = sqlite3_step(res);
|
||||||
|
|
||||||
if (rc != SQLITE_DONE) {
|
if (rc != SQLITE_DONE) {
|
||||||
|
|
||||||
printf("execution failed: %s", sqlite3_errmsg(db));
|
dolog("execution failed: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
@ -98,36 +98,36 @@ int inst_user(struct user_record *user) {
|
|||||||
"cur_file_sub INTEGER,"
|
"cur_file_sub INTEGER,"
|
||||||
"cur_file_dir INTEGER,"
|
"cur_file_dir INTEGER,"
|
||||||
"times_on INTEGER);";
|
"times_on INTEGER);";
|
||||||
|
|
||||||
char *insert_sql = "INSERT INTO users (loginname, password, firstname,"
|
char *insert_sql = "INSERT INTO users (loginname, password, firstname,"
|
||||||
"lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on) VALUES(?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
"lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on) VALUES(?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
char *err_msg = 0;
|
char *err_msg = 0;
|
||||||
|
|
||||||
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
|
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
||||||
if (rc != SQLITE_OK ) {
|
if (rc != SQLITE_OK ) {
|
||||||
|
|
||||||
fprintf(stderr, "SQL error: %s\n", err_msg);
|
dolog("SQL error: %s", err_msg);
|
||||||
|
|
||||||
sqlite3_free(err_msg);
|
sqlite3_free(err_msg);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0);
|
rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0);
|
||||||
|
|
||||||
if (rc == SQLITE_OK) {
|
if (rc == SQLITE_OK) {
|
||||||
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
||||||
sqlite3_bind_text(res, 2, user->password, -1, 0);
|
sqlite3_bind_text(res, 2, user->password, -1, 0);
|
||||||
sqlite3_bind_text(res, 3, user->firstname, -1, 0);
|
sqlite3_bind_text(res, 3, user->firstname, -1, 0);
|
||||||
@ -142,24 +142,24 @@ int inst_user(struct user_record *user) {
|
|||||||
sqlite3_bind_int(res, 12, user->cur_file_dir);
|
sqlite3_bind_int(res, 12, user->cur_file_dir);
|
||||||
sqlite3_bind_int(res, 13, user->cur_file_sub);
|
sqlite3_bind_int(res, 13, user->cur_file_sub);
|
||||||
sqlite3_bind_int(res, 14, user->timeson);
|
sqlite3_bind_int(res, 14, user->timeson);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rc = sqlite3_step(res);
|
rc = sqlite3_step(res);
|
||||||
|
|
||||||
if (rc != SQLITE_DONE) {
|
if (rc != SQLITE_DONE) {
|
||||||
|
|
||||||
printf("execution failed: %s", sqlite3_errmsg(db));
|
dolog("execution failed: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
user->id = sqlite3_last_insert_rowid(db);
|
user->id = sqlite3_last_insert_rowid(db);
|
||||||
|
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -171,30 +171,30 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password)
|
|||||||
sqlite3_stmt *res;
|
sqlite3_stmt *res;
|
||||||
int rc;
|
int rc;
|
||||||
char *sql = "SELECT * FROM users WHERE loginname LIKE ?";
|
char *sql = "SELECT * FROM users WHERE loginname LIKE ?";
|
||||||
|
|
||||||
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
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_bind_text(res, 1, loginname, -1, 0);
|
sqlite3_bind_text(res, 1, loginname, -1, 0);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int step = sqlite3_step(res);
|
int step = sqlite3_step(res);
|
||||||
|
|
||||||
if (step == SQLITE_ROW) {
|
if (step == SQLITE_ROW) {
|
||||||
user = (struct user_record *)malloc(sizeof(struct user_record));
|
user = (struct user_record *)malloc(sizeof(struct user_record));
|
||||||
user->id = sqlite3_column_int(res, 0);
|
user->id = sqlite3_column_int(res, 0);
|
||||||
user->loginname = strdup((char *)sqlite3_column_text(res, 1));
|
user->loginname = strdup((char *)sqlite3_column_text(res, 1));
|
||||||
@ -211,7 +211,7 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password)
|
|||||||
user->cur_file_dir = sqlite3_column_int(res, 13);
|
user->cur_file_dir = sqlite3_column_int(res, 13);
|
||||||
user->cur_file_sub = sqlite3_column_int(res, 12);
|
user->cur_file_sub = sqlite3_column_int(res, 12);
|
||||||
user->timeson = sqlite3_column_int(res, 14);
|
user->timeson = sqlite3_column_int(res, 14);
|
||||||
|
|
||||||
if (strcmp(password, user->password) != 0) {
|
if (strcmp(password, user->password) != 0) {
|
||||||
free(user->loginname);
|
free(user->loginname);
|
||||||
free(user->firstname);
|
free(user->firstname);
|
||||||
@ -220,33 +220,33 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password)
|
|||||||
free(user->location);
|
free(user->location);
|
||||||
free(user);
|
free(user);
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t));
|
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);
|
sprintf(buffer, "%s/config/s%d.ini", conf.bbs_path, user->sec_level);
|
||||||
if (ini_parse(buffer, secLevel, user->sec_info) <0) {
|
if (ini_parse(buffer, secLevel, user->sec_info) <0) {
|
||||||
printf("Unable to load sec Level ini (%s)!\n", buffer);
|
dolog("Unable to load sec Level ini (%s)!", buffer);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user->cur_mail_conf > conf.mail_conference_count) {
|
if (user->cur_mail_conf > conf.mail_conference_count) {
|
||||||
user->cur_mail_conf = 0;
|
user->cur_mail_conf = 0;
|
||||||
}
|
}
|
||||||
if (user->cur_file_dir > conf.file_directory_count) {
|
if (user->cur_file_dir > conf.file_directory_count) {
|
||||||
user->cur_file_dir = 0;
|
user->cur_file_dir = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user->cur_mail_area > conf.mail_conferences[user->cur_mail_conf]->mail_area_count) {
|
if (user->cur_mail_area > conf.mail_conferences[user->cur_mail_conf]->mail_area_count) {
|
||||||
user->cur_mail_area = 0;
|
user->cur_mail_area = 0;
|
||||||
}
|
}
|
||||||
@ -255,8 +255,8 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password)
|
|||||||
user->cur_file_sub = 0;
|
user->cur_file_sub = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_users(int socket, struct user_record *user) {
|
void list_users(int socket, struct user_record *user) {
|
||||||
@ -265,21 +265,21 @@ void list_users(int socket, struct user_record *user) {
|
|||||||
sqlite3_stmt *res;
|
sqlite3_stmt *res;
|
||||||
int rc;
|
int rc;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
char *sql = "SELECT loginname,location,times_on FROM users";
|
char *sql = "SELECT loginname,location,times_on FROM users";
|
||||||
|
|
||||||
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
|
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
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) {
|
||||||
fprintf(stderr, "Cannot prepare statement: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot prepare statement: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -290,22 +290,22 @@ void list_users(int socket, struct user_record *user) {
|
|||||||
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));
|
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_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
if (i == 20) {
|
if (i == 20) {
|
||||||
sprintf(buffer, "Press any key to continue...\r\n");
|
sprintf(buffer, "Press any key to continue...\r\n");
|
||||||
s_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
s_getc(socket);
|
s_getc(socket);
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
|
s_putstring(socket, "\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");
|
sprintf(buffer, "Press any key to continue...\r\n");
|
||||||
s_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
s_getc(socket);
|
s_getc(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_user(char *loginname) {
|
int check_user(char *loginname) {
|
||||||
@ -314,33 +314,33 @@ int check_user(char *loginname) {
|
|||||||
sqlite3_stmt *res;
|
sqlite3_stmt *res;
|
||||||
int rc;
|
int rc;
|
||||||
char *sql = "SELECT * FROM users WHERE loginname = ?";
|
char *sql = "SELECT * FROM users WHERE loginname = ?";
|
||||||
|
|
||||||
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
|
||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
|
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
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_bind_text(res, 1, loginname, -1, 0);
|
sqlite3_bind_text(res, 1, loginname, -1, 0);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
int step = sqlite3_step(res);
|
int step = sqlite3_step(res);
|
||||||
|
|
||||||
if (step == SQLITE_ROW) {
|
if (step == SQLITE_ROW) {
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return 1;
|
return 1;
|
||||||
@ -354,11 +354,11 @@ struct user_record *new_user(int socket) {
|
|||||||
int nameok = 0;
|
int nameok = 0;
|
||||||
int passok = 0;
|
int passok = 0;
|
||||||
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_putstring(socket, "\r\n\r\n");
|
||||||
s_displayansi(socket, "newuser");
|
s_displayansi(socket, "newuser");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
passok = 0;
|
passok = 0;
|
||||||
nameok = 0;
|
nameok = 0;
|
||||||
@ -370,12 +370,12 @@ struct user_record *new_user(int socket) {
|
|||||||
s_putstring(socket, "Sorry, that name is too short.\r\n");
|
s_putstring(socket, "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_putstring(socket, "Sorry, invalid character, can only use alpha characters.\r\n");
|
||||||
nameok = 1;
|
nameok = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nameok == 1) {
|
if (nameok == 1) {
|
||||||
@ -384,16 +384,16 @@ struct user_record *new_user(int socket) {
|
|||||||
}
|
}
|
||||||
if (strcasecmp(buffer, "unknown") == 0) {
|
if (strcasecmp(buffer, "unknown") == 0) {
|
||||||
s_putstring(socket, "Sorry, that name is reserved.\r\n");
|
s_putstring(socket, "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_putstring(socket, "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_putstring(socket, "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) {
|
||||||
@ -407,7 +407,7 @@ struct user_record *new_user(int socket) {
|
|||||||
s_readstring(socket, buffer, 32);
|
s_readstring(socket, buffer, 32);
|
||||||
s_putstring(socket, "\r\n");
|
s_putstring(socket, "\r\n");
|
||||||
user->firstname = strdup(buffer);
|
user->firstname = strdup(buffer);
|
||||||
|
|
||||||
s_putstring(socket, "What is your last name: ");
|
s_putstring(socket, "What is your last name: ");
|
||||||
memset(buffer, 0, 256);
|
memset(buffer, 0, 256);
|
||||||
s_readstring(socket, buffer, 32);
|
s_readstring(socket, buffer, 32);
|
||||||
@ -424,7 +424,7 @@ struct user_record *new_user(int socket) {
|
|||||||
memset(buffer, 0, 256);
|
memset(buffer, 0, 256);
|
||||||
s_readstring(socket, buffer, 32);
|
s_readstring(socket, buffer, 32);
|
||||||
s_putstring(socket, "\r\n");
|
s_putstring(socket, "\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_putstring(socket, "What password would you like (at least 8 characters): ");
|
||||||
@ -438,7 +438,7 @@ struct user_record *new_user(int socket) {
|
|||||||
}
|
}
|
||||||
} while (!passok);
|
} while (!passok);
|
||||||
user->password = strdup(buffer);
|
user->password = strdup(buffer);
|
||||||
|
|
||||||
s_putstring(socket, "You Entered:\r\n");
|
s_putstring(socket, "You Entered:\r\n");
|
||||||
s_putstring(socket, "-------------------------------------\r\n");
|
s_putstring(socket, "-------------------------------------\r\n");
|
||||||
s_putstring(socket, "Login Name: ");
|
s_putstring(socket, "Login Name: ");
|
||||||
@ -459,7 +459,7 @@ struct user_record *new_user(int socket) {
|
|||||||
while (tolower(c) != 'y' && tolower(c) != 'n') {
|
while (tolower(c) != 'y' && tolower(c) != 'n') {
|
||||||
c = s_getchar(socket);
|
c = s_getchar(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tolower(c) == 'y') {
|
if (tolower(c) == 'y') {
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
@ -467,13 +467,13 @@ struct user_record *new_user(int socket) {
|
|||||||
user->sec_level = conf.newuserlvl;
|
user->sec_level = conf.newuserlvl;
|
||||||
|
|
||||||
user->sec_info = (struct sec_level_t *)malloc(sizeof(struct sec_level_t));
|
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);
|
sprintf(buffer, "%s/config/s%d.ini", conf.bbs_path, user->sec_level);
|
||||||
|
|
||||||
if (ini_parse(buffer, secLevel, user->sec_info) <0) {
|
if (ini_parse(buffer, secLevel, user->sec_info) <0) {
|
||||||
printf("Unable to load sec Level ini (%s)!\n", buffer);
|
dolog("Unable to load sec Level ini (%s)!", buffer);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
user->laston = time(NULL);
|
user->laston = time(NULL);
|
||||||
user->timeleft = user->sec_info->timeperday;
|
user->timeleft = user->sec_info->timeperday;
|
||||||
@ -483,6 +483,6 @@ struct user_record *new_user(int socket) {
|
|||||||
user->cur_mail_conf = 0;
|
user->cur_mail_conf = 0;
|
||||||
user->timeson = 0;
|
user->timeson = 0;
|
||||||
inst_user(user);
|
inst_user(user);
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user