Browse Source

ckdb/php - keep 2fa success messages seperate from errors

master
kanoi 9 years ago
parent
commit
8aa6841f61
  1. 1
      pool/inc.php
  2. 11
      pool/page_2fa.php
  3. 2
      src/ckdb.h
  4. 13
      src/ckdb_cmd.c

1
pool/inc.php

@ -99,6 +99,7 @@ span.hdr {font-weight:bold;text-decoration:underline;}
span.nn {font-weight:bold;color:red;} span.nn {font-weight:bold;color:red;}
span.warn {color:orange;font-weight:bold;} span.warn {color:orange;font-weight:bold;}
span.urg {color:red;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.err {color:red;font-weight:bold;font-size:120%;}
span.alert {color:red;font-weight:bold;font-size:250%;} span.alert {color:red;font-weight:bold;font-size:250%;}
input.tiny {width:0px;height:0px;margin:0px;padding:0px;outline:none;border:0px;} input.tiny {width:0px;height:0px;margin:0px;padding:0px;outline:none;border:0px;}

11
pool/page_2fa.php

@ -11,7 +11,7 @@ function app_txt($ones)
return $app; return $app;
} }
# #
function set_2fa($data, $user, $tfa, $ans, $err) function set_2fa($data, $user, $tfa, $ans, $err, $msg)
{ {
$draw = false; $draw = false;
@ -20,6 +20,9 @@ function set_2fa($data, $user, $tfa, $ans, $err)
if ($err !== null and $err != '') if ($err !== null and $err != '')
$pg .= "<span class=err>$err<br><br></span>"; $pg .= "<span class=err>$err<br><br></span>";
if ($msg !== null and $msg != '')
$pg .= "<span class=notice>$msg<br><br></span>";
$pg .= '<table cellpadding=20 cellspacing=0 border=1>'; $pg .= '<table cellpadding=20 cellspacing=0 border=1>';
$pg .= '<tr class=dc><td><center>'; $pg .= '<tr class=dc><td><center>';
@ -162,6 +165,7 @@ function do2fa($data, $user)
{ {
$mailmode = ''; $mailmode = '';
$err = ''; $err = '';
$msg = '';
$setup = getparam('Setup', false); $setup = getparam('Setup', false);
if ($setup === 'Setup') if ($setup === 'Setup')
{ {
@ -248,7 +252,10 @@ function do2fa($data, $user)
$tfa = null; $tfa = null;
else else
$tfa = $ans['2fa_status']; $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; return $pg;
} }
# #

2
src/ckdb.h

@ -55,7 +55,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.2" #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 " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #define WHERE_FFL_HERE __FILE__, __func__, __LINE__

13
src/ckdb_cmd.c

@ -213,7 +213,7 @@ static char *cmd_2fa(__maybe_unused PGconn *conn, char *cmd, char *id,
int32_t entropy, value; int32_t entropy, value;
USERS *users; USERS *users;
char *action, *buf = NULL, *st = NULL; 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; bool ok = false, key = false;
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
@ -301,7 +301,7 @@ static char *cmd_2fa(__maybe_unused PGconn *conn, char *cmd, char *id,
else { else {
key = false; key = false;
sfa_status = "ok"; sfa_status = "ok";
sfa_error = "2FA Enabled"; sfa_msg = "2FA Enabled";
} }
// Report sfa_error to web // Report sfa_error to web
ok = true; ok = true;
@ -317,7 +317,7 @@ static char *cmd_2fa(__maybe_unused PGconn *conn, char *cmd, char *id,
ok = true; ok = true;
sfa_status = EMPTY; sfa_status = EMPTY;
key = false; key = false;
sfa_error = "2FA Cancelled"; sfa_msg = "2FA Cancelled";
} }
} else if (strcmp(action, "new") == 0) { } else if (strcmp(action, "new") == 0) {
// Can't new if 2FA isn't already present -> setup // 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; ok = true;
sfa_status = EMPTY; sfa_status = EMPTY;
key = false; key = false;
sfa_error = "2FA Removed"; sfa_msg = "2FA Removed";
} }
} }
} }
@ -430,8 +430,9 @@ dame:
return strdup("failed."); return strdup("failed.");
} }
snprintf(tmp, sizeof(tmp), "2fa_status=%s%c2fa_error=%s", snprintf(tmp, sizeof(tmp), "2fa_status=%s%c2fa_error=%s%c2fa_msg=%s",
sfa_status, FLDSEP, sfa_error); sfa_status, FLDSEP, sfa_error, FLDSEP,
sfa_msg);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
LOGDEBUG("%s.%s-%s.%s", id, transfer_data(i_username), action, buf); LOGDEBUG("%s.%s-%s.%s", id, transfer_data(i_username), action, buf);
return buf; return buf;

Loading…
Cancel
Save