Add option to enable / disable external editor

This commit is contained in:
Andrew Pamment 2017-09-11 16:10:38 +10:00
parent d5e9f84c6e
commit a259082692
6 changed files with 62 additions and 10 deletions

1
bbs.h
View File

@ -203,6 +203,7 @@ struct user_record {
int defprotocol; int defprotocol;
int nodemsgs; int nodemsgs;
int codepage; int codepage;
int exteditor;
}; };
struct jam_msg { struct jam_msg {

View File

@ -220,3 +220,4 @@ File exists!\r\n
\r\n\e[1;37mEnter your message (256 chars max)...\e[0m\r\n \r\n\e[1;37mEnter your message (256 chars max)...\e[0m\r\n
%s on node %d says:\r\n %s\r\n\r\n %s on node %d says:\r\n %s\r\n\r\n
\e[0;36mC. \e[1;37mCodepage (\e[1;33m%s\e[1;37m)\r\n \e[0;36mC. \e[1;37mCodepage (\e[1;33m%s\e[1;37m)\r\n
\e[0;36mE. \e[1;37mUse External Editor (\e[1;33m%s\e[1;37m)\r\n

View File

@ -366,9 +366,13 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot
if (conf.external_editor_cmd != NULL) { if (conf.external_editor_cmd != NULL && user->exteditor != 0) {
s_printf(get_string(85)); if (user->exteditor == 2) {
c = s_getc(); s_printf(get_string(85));
c = s_getc();
} else {
c = 'y';
}
if (tolower(c) == 'y') { if (tolower(c) == 'y') {
sprintf(buffer, "%s/node%d", conf.bbs_path, mynode); sprintf(buffer, "%s/node%d", conf.bbs_path, mynode);

View File

@ -23,6 +23,18 @@ void settings_menu(struct user_record *user) {
s_printf(get_string(213), conf.protocols[user->defprotocol - 1]->name); s_printf(get_string(213), conf.protocols[user->defprotocol - 1]->name);
s_printf(get_string(215), (user->nodemsgs ? "TRUE" : "FALSE")); s_printf(get_string(215), (user->nodemsgs ? "TRUE" : "FALSE"));
s_printf(get_string(221), (user->codepage ? "UTF-8" : "CP437")); s_printf(get_string(221), (user->codepage ? "UTF-8" : "CP437"));
switch (user->exteditor) {
case 0:
sprintf(buffer, "NO");
break;
case 1:
sprintf(buffer, "YES");
break;
case 2:
sprintf(buffer, "ASK");
break;
}
s_printf(get_string(222), buffer);
s_printf(get_string(153)); s_printf(get_string(153));
s_printf(get_string(154)); s_printf(get_string(154));
@ -124,7 +136,16 @@ void settings_menu(struct user_record *user) {
user->codepage = !user->codepage; user->codepage = !user->codepage;
save_user(user); save_user(user);
} }
break; break;
case 'e':
{
user->exteditor++;
if (user->exteditor == 3) {
user->exteditor = 0;
}
save_user(user);
}
break;
case 'q': case 'q':
dosettings = 1; dosettings = 1;
break; break;

15
users.c
View File

@ -81,7 +81,7 @@ int save_user(struct user_record *user) {
int rc; int rc;
char *update_sql = "UPDATE users SET password=?, salt=?, firstname=?," 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=? 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=? where loginname LIKE ?";
sprintf(buffer, "%s/users.sq3", conf.bbs_path); sprintf(buffer, "%s/users.sq3", conf.bbs_path);
@ -116,7 +116,8 @@ sqlite3_busy_timeout(db, 5000);
sqlite3_bind_int(res, 17, user->defprotocol); sqlite3_bind_int(res, 17, user->defprotocol);
sqlite3_bind_int(res, 18, user->nodemsgs); sqlite3_bind_int(res, 18, user->nodemsgs);
sqlite3_bind_int(res, 19, user->codepage); sqlite3_bind_int(res, 19, user->codepage);
sqlite3_bind_text(res, 20, user->loginname, -1, 0); sqlite3_bind_int(res, 20, user->exteditor);
sqlite3_bind_text(res, 21, user->loginname, -1, 0);
} else { } else {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
} }
@ -161,10 +162,11 @@ int inst_user(struct user_record *user) {
"archiver INTEGER," "archiver INTEGER,"
"protocol INTEGER," "protocol INTEGER,"
"nodemsgs INTEGER," "nodemsgs INTEGER,"
"codepage INTEGER);"; "codepage INTEGER,"
"exteditor INTEGER);";
char *insert_sql = "INSERT INTO users (loginname, password, salt, firstname," 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) 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) 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);
@ -212,6 +214,7 @@ sqlite3_busy_timeout(db, 5000);
sqlite3_bind_int(res, 18, user->defprotocol); sqlite3_bind_int(res, 18, user->defprotocol);
sqlite3_bind_int(res, 19, user->nodemsgs); sqlite3_bind_int(res, 19, user->nodemsgs);
sqlite3_bind_int(res, 20, user->codepage); sqlite3_bind_int(res, 20, user->codepage);
sqlite3_bind_int(res, 21, user->exteditor);
} else { } else {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
} }
@ -239,7 +242,7 @@ struct user_record *check_user_pass(char *loginname, char *password) {
sqlite3_stmt *res; sqlite3_stmt *res;
int rc; int rc;
char *sql = "SELECT Id, loginname, password, salt, firstname," 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 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 FROM users WHERE loginname LIKE ?";
char *pass_hash; char *pass_hash;
sprintf(buffer, "%s/users.sq3", conf.bbs_path); sprintf(buffer, "%s/users.sq3", conf.bbs_path);
@ -288,6 +291,7 @@ struct user_record *check_user_pass(char *loginname, char *password) {
user->defprotocol = sqlite3_column_int(res, 18); user->defprotocol = sqlite3_column_int(res, 18);
user->nodemsgs = sqlite3_column_int(res, 19); user->nodemsgs = sqlite3_column_int(res, 19);
user->codepage = sqlite3_column_int(res, 20); user->codepage = sqlite3_column_int(res, 20);
user->exteditor = sqlite3_column_int(res, 21);
pass_hash = hash_sha256(password, user->salt); pass_hash = hash_sha256(password, user->salt);
if (strcmp(pass_hash, user->password) != 0) { if (strcmp(pass_hash, user->password) != 0) {
@ -573,6 +577,7 @@ struct user_record *new_user() {
user->defarchiver = 1; user->defarchiver = 1;
user->nodemsgs = 1; user->nodemsgs = 1;
user->codepage = conf.codepage; user->codepage = conf.codepage;
user->exteditor = 2;
inst_user(user); inst_user(user);
return user; return user;

View File

@ -135,4 +135,24 @@ if (check_exists("codepage") == 0) {
my $sql = "ALTER TABLE users ADD COLUMN codepage INTEGER DEFAULT 0"; my $sql = "ALTER TABLE users ADD COLUMN codepage INTEGER DEFAULT 0";
$dbh->do($sql); $dbh->do($sql);
$dbh->disconnect; $dbh->disconnect;
} }
if (check_exists("exteditor") == 0) {
print "Column \"exteditor\" 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 exteditor INTEGER DEFAULT 2";
$dbh->do($sql);
$dbh->disconnect;
}