diff options
Diffstat (limited to 'database/sqlite/administration.c')
| -rw-r--r-- | database/sqlite/administration.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c index a810516..6bd46a8 100644 --- a/database/sqlite/administration.c +++ b/database/sqlite/administration.c @@ -54,6 +54,7 @@ #define FMAP_ADMINACCESS #define FMAP_LASTLOG #define FMAP_OVPNATTEMPTS +#define FMAP_OVPNBLACKLIST #include "fieldmapping.h" #if DRIVERAPIVERSION > 1 @@ -1624,4 +1625,66 @@ xmlDoc *eDBadminAttemptsLog(eurephiaCTX *ctx, xmlDoc *qryxml) { return resxml; } + +// The XML document format for blacklist actions is: +// <eurephia format="1"> +// <blacklist mode="{list|add|delete}"> +// <fieldMapping table="blacklist"> +// <{field name}>{field value}</{field field}> +// </fieldMapping> +// </blacklist> +// </eurehpia> +// +// For listing and delete mode it be several field tags to limit the search even more. +// For add mode only username, IP address or certificate digest can be given. +// +xmlDoc *blacklist_list(eurephiaCTX *ctx, eDBfieldMap *fmap); +xmlDoc *blacklist_add(eurephiaCTX *ctx, eDBfieldMap *fmap); +xmlDoc *blacklist_delete(eurephiaCTX *ctx, eDBfieldMap *fmap); + +xmlDoc *eDBadminBlacklist(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: eDBadminBlacklist(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, "blacklist", 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_blacklist, NULL, fieldmap_n); + + if( strcmp(mode, "list") == 0 ) { + resxml = blacklist_list(ctx, fmap); + } else if( strcmp(mode, "add") == 0 ) { + resxml = blacklist_add(ctx, fmap); + } else if( strcmp(mode, "delete") == 0 ) { + resxml = blacklist_delete(ctx, fmap); + } else { + eurephia_log(ctx, LOG_ERROR, 0, "Blacklist - Unknown mode: '%s'", mode); + resxml = eurephiaXML_ResultMsg(ctx, exmlERROR, "Unknown mode '%s'", mode); + } + eDBfreeMapping(fmap); + return resxml; +} #endif |
