From dd1d4d4eaa92a8e491927fda212d7c2076f334b9 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sat, 13 Jan 2018 19:17:22 +1000 Subject: [PATCH] Add signature capability --- magicka.strings | 2 + src/bbs.h | 6 +- src/email.c | 4 +- src/mail_menu.c | 108 +++++++++++++++++---------- src/settings.c | 22 ++++++ src/users.c | 22 ++++-- utils/sql_update/users_sql_update.pl | 40 ++++++++++ 7 files changed, 156 insertions(+), 48 deletions(-) diff --git a/magicka.strings b/magicka.strings index 15a8f99..d36d87c 100644 --- a/magicka.strings +++ b/magicka.strings @@ -243,3 +243,5 @@ File exists!\r\n \r\nLastname may not begin or end with a space\r\n \r\nFirst & Last Name combination in use!\r\n \r\nSpaces not allowed\r\n +\e[0;36mS. \e[1;37mSet Signature...\r\n +\e[0;36mT. \e[1;37mToggle Auto-Signature (\e[1;33m%s\e[1;37m)\r\n diff --git a/src/bbs.h b/src/bbs.h index b539d82..e271713 100644 --- a/src/bbs.h +++ b/src/bbs.h @@ -190,6 +190,8 @@ struct user_record { char *lastname; char *email; char *location; + char *signature; + int autosig; int sec_level; struct sec_level_t *sec_info; time_t laston; @@ -267,8 +269,8 @@ extern s_JamBase *open_jam_base(char *path); extern void free_message_headers(struct msg_headers *msghs); extern struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_record *user); extern void mail_scan(struct user_record *user); -extern char *editor(struct user_record *user, char *quote, int qlen, char *from, int email); -extern char *external_editor(struct user_record *user, char *to, char *from, char *quote, int qlen, char *qfrom, char *subject, int email); +extern char *editor(struct user_record *user, char *quote, int qlen, char *from, int email, int sig); +extern char *external_editor(struct user_record *user, char *to, char *from, char *quote, int qlen, char *qfrom, char *subject, int email, int sig); extern int msg_is_to(struct user_record *user, char *addressed_to, char *address, int type, int rn, int msgconf); extern int msg_is_from(struct user_record *user, char *addressed_from, char *address, int type, int rn, int msgconf); extern unsigned long generate_msgid(); diff --git a/src/email.c b/src/email.c index a2faf05..0f7de15 100644 --- a/src/email.c +++ b/src/email.c @@ -59,7 +59,7 @@ void send_email(struct user_record *user) { subject = strdup(buffer); // post a message - msg = external_editor(user, user->loginname, recipient, NULL, 0, NULL, subject, 1); + msg = external_editor(user, user->loginname, recipient, NULL, 0, NULL, subject, 1, 0); if (msg != NULL) { sprintf(buffer, "%s/email.sq3", conf.bbs_path); @@ -278,7 +278,7 @@ void show_email(struct user_record *user, int msgno, int email_count, struct ema subject = (char *)malloc(strlen(buffer) + 1); strcpy(subject, buffer); - replybody = external_editor(user, user->loginname, emails[msgno]->from, emails[msgno]->body, strlen(emails[msgno]->body), emails[msgno]->from, subject, 1); + replybody = external_editor(user, user->loginname, emails[msgno]->from, emails[msgno]->body, strlen(emails[msgno]->body), emails[msgno]->from, subject, 1, 0); if (replybody != NULL) { sprintf(buffer, "%s/email.sq3", conf.bbs_path); diff --git a/src/mail_menu.c b/src/mail_menu.c index 23107aa..3c37817 100644 --- a/src/mail_menu.c +++ b/src/mail_menu.c @@ -355,7 +355,7 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r return msghs; } -char *external_editor(struct user_record *user, char *to, char *from, char *quote, int qlen, char *qfrom, char *subject, int email) { +char *external_editor(struct user_record *user, char *to, char *from, char *quote, int qlen, char *qfrom, char *subject, int email, int sig) { char c; FILE *fptr; char *body = NULL; @@ -423,11 +423,16 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot fprintf(fptr, "E-Mail\r\n"); fprintf(fptr, "YES\r\n"); } else { - fprintf(fptr, "%s\r\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name); - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA){ - fprintf(fptr, "YES\r\n"); + if (!sig) { + fprintf(fptr, "%s\r\n", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name); + if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA){ + fprintf(fptr, "YES\r\n"); + } else { + fprintf(fptr, "NO\r\n"); + } } else { - fprintf(fptr, "NO\r\n"); + fprintf(fptr, "None\r\n"); + fprintf(fptr, "NO\r\n"); } } fclose(fptr); @@ -471,24 +476,31 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot } } - uname(&name); + if (!sig) { + uname(&name); - - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO && !email) { - if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point == 0) { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO && !email) { + if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point == 0) { + snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + } else { + snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + } } else { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline); + } + if (user->autosig) { + body2 = (char *)malloc(totlen + 3 + strlen(buffer) + strlen(user->signature)); + } else { + body2 = (char *)malloc(totlen + 2 + strlen(buffer)); } } else { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline); + body2 = (char *)malloc(totlen + 1); } - body2 = (char *)malloc(totlen + 2 + strlen(buffer)); j = 0; @@ -502,18 +514,23 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot body2[j] = '\0'; } - - strcat(body2, buffer); + if (!sig) { + if (user->autosig) { + strcat(body2, "\r"); + strcat(body2, user->signature); + } + strcat(body2, buffer); + } free(body); return body2; } } - return editor(user, quote, qlen, qfrom, email); + return editor(user, quote, qlen, qfrom, email, sig); } -char *editor(struct user_record *user, char *quote, int quotelen, char *from, int email) { +char *editor(struct user_record *user, char *quote, int quotelen, char *from, int email, int sig) { int lines = 0; char buffer[256]; char linebuffer[80]; @@ -594,23 +611,32 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in } else { tagline = conf.default_tagline; } - uname(&name); - if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO && !email) { - if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point == 0) { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + if (!sig) { + uname(&name); + if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO && !email) { + if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point == 0) { + snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node); + } else { + snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, + conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + } } else { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, - conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point); + snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline); + } + if (user->autosig) { + size += 3; + size += strlen(buffer) + strlen(user->signature); + } else { + size += 2; + size += strlen(buffer); } } else { - snprintf(buffer, 256, "\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s \r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline); + size += 1; } - size += 2; - size += strlen(buffer); msg = (char *)malloc(size); memset(msg, 0, size); @@ -620,7 +646,13 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in free(content[i]); } - strcat(msg, buffer); + if (!sig) { + if (user->autosig) { + strcat(msg, "\r"); + strcat(msg, user->signature); + } + strcat(msg, buffer); + } free(content); if (quote != NULL) { @@ -1664,7 +1696,7 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno to = (char *)malloc(strlen(buffer) + 1); strcpy(to, buffer); } - replybody = external_editor(user, to, from, body, z2, msghs->msgs[mailno]->from, subject, 0); + replybody = external_editor(user, to, from, body, z2, msghs->msgs[mailno]->from, subject, 0, 0); if (replybody != NULL) { jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); @@ -2092,7 +2124,7 @@ void post_message(struct user_record *user) { from = (char *)malloc(strlen(user->firstname) + strlen(user->lastname) + 2); sprintf(from, "%s %s", user->firstname, user->lastname); } - msg = external_editor(user, to, from, NULL, 0, NULL, subject, 0); + msg = external_editor(user, to, from, NULL, 0, NULL, subject, 0, 0); free(from); diff --git a/src/settings.c b/src/settings.c index 0f545eb..667d595 100644 --- a/src/settings.c +++ b/src/settings.c @@ -13,6 +13,7 @@ void settings_menu(struct user_record *user) { char *hash; int new_arc; int i; + char *sig; while (!dosettings) { s_printf(get_string(149)); @@ -36,6 +37,8 @@ void settings_menu(struct user_record *user) { } s_printf(get_string(222), buffer); s_printf(get_string(235), (user->bwavestyle ? "mo?,tu? ..." : "000-999")); + s_printf(get_string(245)); + s_printf(get_string(246), (user->autosig ? "TRUE" : "FALSE")); s_printf(get_string(153)); s_printf(get_string(154)); @@ -154,6 +157,25 @@ void settings_menu(struct user_record *user) { save_user(user); } break; + case 's': + { + // set signature + if (user->signature != NULL) { + free(user->signature); + } + sig = external_editor(user, "No-One", "No-One", NULL, 0, "No-One", "Signature Editor", 0, 1); + if (sig != NULL) { + user->signature = sig; + save_user(user); + } + } + break; + case 't': + { + user->autosig = !user->autosig; + save_user(user); + } + break; case 'q': dosettings = 1; break; diff --git a/src/users.c b/src/users.c index 581b355..3e716a2 100644 --- a/src/users.c +++ b/src/users.c @@ -82,7 +82,7 @@ int save_user(struct user_record *user) { int rc; char *update_sql = "UPDATE users SET password=?, salt=?, firstname=?," - "lastname=?, email=?, location=?, sec_level=?, last_on=?, time_left=?, cur_mail_conf=?, cur_mail_area=?, cur_file_dir=?, cur_file_sub=?, times_on=?, bwavepktno=?, archiver=?, protocol=?,nodemsgs=?,codepage=?,exteditor=?,bwavestyle=? 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=?, bwavepktno=?, archiver=?, protocol=?,nodemsgs=?,codepage=?,exteditor=?,bwavestyle=?,signature=?,autosig=? where loginname LIKE ?"; sprintf(buffer, "%s/users.sq3", conf.bbs_path); @@ -119,7 +119,9 @@ int save_user(struct user_record *user) { sqlite3_bind_int(res, 19, user->codepage); sqlite3_bind_int(res, 20, user->exteditor); sqlite3_bind_int(res, 21, user->bwavestyle); - sqlite3_bind_text(res, 22, user->loginname, -1, 0); + sqlite3_bind_text(res, 22, user->signature, -1, 0); + sqlite3_bind_int(res, 23, user->autosig); + sqlite3_bind_text(res, 24, user->loginname, -1, 0); } else { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); } @@ -262,10 +264,12 @@ int inst_user(struct user_record *user) { "nodemsgs INTEGER," "codepage INTEGER," "exteditor INTEGER," - "bwavestyle INTEGER);"; + "bwavestyle INTEGER," + "signature TEXT," + "autosig INT);"; char *insert_sql = "INSERT INTO users (loginname, password, salt, firstname," - "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol, nodemsgs, codepage, exteditor, bwavestyle) VALUES(?,?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol, nodemsgs, codepage, exteditor, bwavestyle, signature, autosig) VALUES(?,?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; char *err_msg = 0; snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); @@ -315,6 +319,8 @@ int inst_user(struct user_record *user) { sqlite3_bind_int(res, 20, user->codepage); sqlite3_bind_int(res, 21, user->exteditor); sqlite3_bind_int(res, 22, user->bwavestyle); + sqlite3_bind_text(res, 23, user->signature, -1, 0); + sqlite3_bind_int(res, 24, user->autosig); } else { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_close(db); @@ -344,7 +350,7 @@ struct user_record *check_user_pass(char *loginname, char *password) { sqlite3_stmt *res; int rc; char *sql = "SELECT Id, loginname, password, salt, firstname," - "lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on, bwavepktno, archiver, protocol,nodemsgs, codepage, exteditor, bwavestyle FROM users 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, bwavepktno, archiver, protocol,nodemsgs, codepage, exteditor, bwavestyle, signature, autosig FROM users WHERE loginname LIKE ?"; char *pass_hash; sprintf(buffer, "%s/users.sq3", conf.bbs_path); @@ -395,6 +401,8 @@ struct user_record *check_user_pass(char *loginname, char *password) { user->codepage = sqlite3_column_int(res, 20); user->exteditor = sqlite3_column_int(res, 21); user->bwavestyle = sqlite3_column_int(res, 22); + user->signature = strdup((char *)sqlite3_column_text(res, 23)); + user->autosig = sqlite3_column_int(res, 24); pass_hash = hash_sha256(password, user->salt); if (strcmp(pass_hash, user->password) != 0) { @@ -404,6 +412,7 @@ struct user_record *check_user_pass(char *loginname, char *password) { free(user->email); free(user->location); free(user->salt); + free(user->signature); free(user); free(pass_hash); sqlite3_finalize(res); @@ -744,7 +753,6 @@ struct user_record *new_user() { user->sec_level = conf.newuserlvl; user->bwavepktno = 0; 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); if (ini_parse(buffer, secLevel, user->sec_info) <0) { @@ -765,6 +773,8 @@ struct user_record *new_user() { user->codepage = conf.codepage; user->exteditor = 2; user->bwavestyle = 0; + user->signature = strdup(""); + user->autosig = 0; inst_user(user); return user; diff --git a/utils/sql_update/users_sql_update.pl b/utils/sql_update/users_sql_update.pl index 4f87ded..d80b69c 100755 --- a/utils/sql_update/users_sql_update.pl +++ b/utils/sql_update/users_sql_update.pl @@ -177,3 +177,43 @@ if (check_exists("bwavestyle") == 0) { $dbh->do($sql); $dbh->disconnect; } + +if (check_exists("signature") == 0) { + print "Column \"signature\" doesn't exist... adding..\n"; + + my ($needed) = @_; + + my $dsn = "dbi:SQLite:dbname=$dbfile"; + my $user = ""; + my $password = ""; + my $dbh = DBI->connect($dsn, $user, $password, { + PrintError => 0, + RaiseError => 1, + AutoCommit => 1, + FetchHashKeyName => 'NAME_lc', + }); + + my $sql = "ALTER TABLE users ADD COLUMN signature TEXT DEFAULT \"\""; + $dbh->do($sql); + $dbh->disconnect; +} + +if (check_exists("autosig") == 0) { + print "Column \"autosig\" doesn't exist... adding..\n"; + + my ($needed) = @_; + + my $dsn = "dbi:SQLite:dbname=$dbfile"; + my $user = ""; + my $password = ""; + my $dbh = DBI->connect($dsn, $user, $password, { + PrintError => 0, + RaiseError => 1, + AutoCommit => 1, + FetchHashKeyName => 'NAME_lc', + }); + + my $sql = "ALTER TABLE users ADD COLUMN autosig INTEGER DEFAULT 0"; + $dbh->do($sql); + $dbh->disconnect; +}