From 8aa6841f615e3bdb01ec612e9ac9d7ea71040094 Mon Sep 17 00:00:00 2001 From: kanoi Date: Sun, 6 Sep 2015 23:04:37 +1000 Subject: [PATCH] ckdb/php - keep 2fa success messages seperate from errors --- pool/inc.php | 1 + pool/page_2fa.php | 11 +++++++++-- src/ckdb.h | 2 +- src/ckdb_cmd.c | 13 +++++++------ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/pool/inc.php b/pool/inc.php index 5ae064df..c855da5f 100644 --- a/pool/inc.php +++ b/pool/inc.php @@ -99,6 +99,7 @@ span.hdr {font-weight:bold;text-decoration:underline;} span.nn {font-weight:bold;color:red;} span.warn {color:orange;font-weight:bold;} span.urg {color:red;font-weight:bold;} +span.notice {color:blue;font-weight:bold;font-size:120%;} span.err {color:red;font-weight:bold;font-size:120%;} span.alert {color:red;font-weight:bold;font-size:250%;} input.tiny {width:0px;height:0px;margin:0px;padding:0px;outline:none;border:0px;} diff --git a/pool/page_2fa.php b/pool/page_2fa.php index 37e1ff2d..6687846d 100644 --- a/pool/page_2fa.php +++ b/pool/page_2fa.php @@ -11,7 +11,7 @@ function app_txt($ones) return $app; } # -function set_2fa($data, $user, $tfa, $ans, $err) +function set_2fa($data, $user, $tfa, $ans, $err, $msg) { $draw = false; @@ -20,6 +20,9 @@ function set_2fa($data, $user, $tfa, $ans, $err) if ($err !== null and $err != '') $pg .= "$err

"; + if ($msg !== null and $msg != '') + $pg .= "$msg

"; + $pg .= ''; $pg .= '
'; @@ -162,6 +165,7 @@ function do2fa($data, $user) { $mailmode = ''; $err = ''; + $msg = ''; $setup = getparam('Setup', false); if ($setup === 'Setup') { @@ -248,7 +252,10 @@ function do2fa($data, $user) $tfa = null; else $tfa = $ans['2fa_status']; - $pg = set_2fa($data, $user, $tfa, $ans, $err); + if (isset($ans['2fa_msg'])) + $msg = $ans['2fa_msg']; + + $pg = set_2fa($data, $user, $tfa, $ans, $err, $msg); return $pg; } # diff --git a/src/ckdb.h b/src/ckdb.h index fcb313c3..af0ff79e 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -55,7 +55,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.2" -#define CKDB_VERSION DB_VERSION"-1.240" +#define CKDB_VERSION DB_VERSION"-1.241" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 7ad2e25b..f4911289 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -213,7 +213,7 @@ static char *cmd_2fa(__maybe_unused PGconn *conn, char *cmd, char *id, int32_t entropy, value; USERS *users; char *action, *buf = NULL, *st = NULL; - char *sfa_status = EMPTY, *sfa_error = EMPTY; + char *sfa_status = EMPTY, *sfa_error = EMPTY, *sfa_msg = EMPTY; bool ok = false, key = false; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); @@ -301,7 +301,7 @@ static char *cmd_2fa(__maybe_unused PGconn *conn, char *cmd, char *id, else { key = false; sfa_status = "ok"; - sfa_error = "2FA Enabled"; + sfa_msg = "2FA Enabled"; } // Report sfa_error to web ok = true; @@ -317,7 +317,7 @@ static char *cmd_2fa(__maybe_unused PGconn *conn, char *cmd, char *id, ok = true; sfa_status = EMPTY; key = false; - sfa_error = "2FA Cancelled"; + sfa_msg = "2FA Cancelled"; } } else if (strcmp(action, "new") == 0) { // Can't new if 2FA isn't already present -> setup @@ -359,7 +359,7 @@ static char *cmd_2fa(__maybe_unused PGconn *conn, char *cmd, char *id, ok = true; sfa_status = EMPTY; key = false; - sfa_error = "2FA Removed"; + sfa_msg = "2FA Removed"; } } } @@ -430,8 +430,9 @@ dame: return strdup("failed."); } - snprintf(tmp, sizeof(tmp), "2fa_status=%s%c2fa_error=%s", - sfa_status, FLDSEP, sfa_error); + snprintf(tmp, sizeof(tmp), "2fa_status=%s%c2fa_error=%s%c2fa_msg=%s", + sfa_status, FLDSEP, sfa_error, FLDSEP, + sfa_msg); APPEND_REALLOC(buf, off, len, tmp); LOGDEBUG("%s.%s-%s.%s", id, transfer_data(i_username), action, buf); return buf;