diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-11-30 18:29:04 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-11-30 18:29:04 +0100 |
commit | 3f1a2311fe8912659bc1c88fc586fc499955e479 (patch) | |
tree | a29a9dafa9839ac5d573d0f3a62bc60a50317b99 /database/sqlite/edb-sqlite.c | |
parent | e0ee773ffa5b14294d9664f1504707e0bd545638 (diff) | |
download | eurephia-3f1a2311fe8912659bc1c88fc586fc499955e479.tar.gz eurephia-3f1a2311fe8912659bc1c88fc586fc499955e479.tar.xz eurephia-3f1a2311fe8912659bc1c88fc586fc499955e479.zip |
eurephiadm can now use eDBadminValidateSession(...) to use open session. Auto-logout implemented as well
Diffstat (limited to 'database/sqlite/edb-sqlite.c')
-rw-r--r-- | database/sqlite/edb-sqlite.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/database/sqlite/edb-sqlite.c b/database/sqlite/edb-sqlite.c index c137a3f..35c0460 100644 --- a/database/sqlite/edb-sqlite.c +++ b/database/sqlite/edb-sqlite.c @@ -1020,6 +1020,8 @@ int eDBadminAuth(eurephiaCTX *ctx, const char *uname, const char *pwd) { } int eDBadminValidateSession(eurephiaCTX *ctx, char *sesskey) { + dbresult *res = NULL; + int valid = 0; assert( (ctx != NULL) && (sesskey != NULL) ); @@ -1028,7 +1030,48 @@ int eDBadminValidateSession(eurephiaCTX *ctx, char *sesskey) { eurephia_log(ctx, LOG_ERROR, 0, "Wrong eurephia context type (0x%04x)", ctx->context_type); return 0; } - return 0; + + // Check if the session is still valid. + res = sqlite_query(ctx, + "SELECT (strftime('%%s',CURRENT_TIMESTAMP)-strftime('%%s',last_action)) > %i" + " FROM eurephia_adminlog" + " WHERE status = 1" + " AND sessionkey = '%q'", + (60 * atoi_nullsafe(defaultValue(eGet_value(ctx->dbc->config, + "eurephiadmin_autologout"), + "10") + )), + sesskey); + if( (res == NULL) || (sqlite_get_numtuples(res) != 1) ) { + eurephia_log(ctx, LOG_FATAL, 0, "Could not validate session"); + return 0; + } + + valid = (atoi_nullsafe(sqlite_get_value(res, 0, 0)) == 0); + sqlite_free_results(res); + + // If still valid, update last_action + if( valid ) { + res = sqlite_query(ctx, + "UPDATE eurephia_adminlog" + " SET last_action = CURRENT_TIMESTAMP" + " WHERE sessionkey = '%q'", sesskey); + if( res == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Could not register session activity"); + } + sqlite_free_results(res); + } else { + // If not valid, register session as auto-logged out + res = sqlite_query(ctx, + "UPDATE eurephia_adminlog" + " SET logout = CURRENT_TIMESTAMP, status = 3" + " WHERE sessionkey = '%q'", sesskey); + if( res == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Could not register old session as logged out"); + } + } + + return valid; } int eDBadminRegisterLogin(eurephiaCTX *ctx, eurephiaSESSION *session) { |