diff options
Diffstat (limited to 'database/sqlite/administration.c')
| -rw-r--r-- | database/sqlite/administration.c | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c index 18752a6..6def2e8 100644 --- a/database/sqlite/administration.c +++ b/database/sqlite/administration.c @@ -53,6 +53,7 @@ #define FMAP_USERCERTS #define FMAP_ADMINACCESS #define FMAP_LASTLOG +#define FMAP_OVPNATTEMPTS #include "fieldmapping.h" #if DRIVERAPIVERSION > 1 @@ -1562,10 +1563,66 @@ xmlDoc *eDBadminGetLastlog(eurephiaCTX *ctx, xmlDoc *srch, const char *sortkeys) return doc; } -xmlDoc *eDBadminGetAttemptsLog(eurephiaCTX *ctx, xmlDoc *usersrch, xmlDoc *certsrch, - const char *sortkeys) -{ - return NULL; +// The search XML document format is: +// <eurephia format="1"> +// <attempts mode="{search|add|delete}"> +// <fieldMapping table="attempts"> +// <{field name}>{field value}</{field field}> +// </fieldMapping> +// </attempts> +// </eurehpia> +// +// It can be several search field tags to limit the search even more. +// +xmlDoc *attempts_list(eurephiaCTX *ctx, eDBfieldMap *fmap); +xmlDoc *attempts_add(eurephiaCTX *ctx, eDBfieldMap *fmap); +xmlDoc *attempts_delete(eurephiaCTX *ctx, eDBfieldMap *fmap); + +xmlDoc *eDBadminAttemptsLog(eurephiaCTX *ctx, xmlDoc *qryxml) { + eDBfieldMap *fmap = NULL; + char *mode = NULL; + xmlDoc *resxml = NULL; + xmlNode *root_n = NULL, *fieldmap_n = NULL; + + DEBUG(ctx, 20, "Function call: eDBadminAttemptsLog(ctx, {xmlDoc})"); + assert( (ctx != NULL) && (qryxml != NULL) ); + + if( (ctx->context_type != ECTX_ADMIN_CONSOLE) && (ctx->context_type != ECTX_ADMIN_WEB) ) { + eurephia_log(ctx, LOG_CRITICAL, 0, + "eurephia admin function call attempted with wrong context type"); + return NULL; + } + + root_n = eurephiaXML_getRoot(ctx, qryxml, "attempts", 1); + if( root_n == NULL ) { + eurephia_log(ctx, LOG_CRITICAL, 0, "Invalid XML input."); + return NULL; + } + mode = xmlGetAttrValue(root_n->properties, "mode"); + if( mode == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Missing mode attribute"); + return NULL; + } + + fieldmap_n = xmlFindNode(root_n, "fieldMapping"); + if( fieldmap_n == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Missing fieldMapping"); + } + fmap = eDBxmlMapping(ctx, tbl_sqlite_attempts, NULL, fieldmap_n); + + if( strcmp(mode, "list") == 0 ) { + resxml = attempts_list(ctx, fmap); + } else if( strcmp(mode, "add") == 0 ) { + resxml = attempts_add(ctx, fmap); + } else if( strcmp(mode, "delete") == 0 ) { + resxml = attempts_delete(ctx, fmap); + } else { + eurephia_log(ctx, LOG_ERROR, 0, "FirewallProfiles - Unknown mode: '%s'", mode); + resxml = eurephiaXML_ResultMsg(ctx, exmlERROR, "Unknown mode '%s'", mode); + } + eDBfreeMapping(fmap); + return resxml; + } #endif |
