summaryrefslogtreecommitdiffstats
path: root/database/sqlite/attempts.c
diff options
context:
space:
mode:
Diffstat (limited to 'database/sqlite/attempts.c')
-rw-r--r--database/sqlite/attempts.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/database/sqlite/attempts.c b/database/sqlite/attempts.c
index 4afd981..a524175 100644
--- a/database/sqlite/attempts.c
+++ b/database/sqlite/attempts.c
@@ -62,7 +62,7 @@ xmlDoc *attempts_list(eurephiaCTX *ctx, eDBfieldMap *fmap) {
NULL, fmap, "atpid");
if( res == NULL ) {
eurephia_log(ctx, LOG_ERROR, 0, "Error querying the attempts log");
- return 0;
+ return NULL;
}
eurephiaXML_CreateDoc(ctx, 1, "attemptslog", &doc, &root_n);
@@ -106,12 +106,52 @@ xmlDoc *attempts_list(eurephiaCTX *ctx, eDBfieldMap *fmap) {
}
-xmlDoc *attempts_add(eurephiaCTX *ctx, eDBfieldMap *fmap) {
- return NULL;
+xmlDoc *attempts_reset(eurephiaCTX *ctx, eDBfieldMap *fmap) {
+ dbresult *res = NULL;
+ xmlDoc *ret = NULL;
+ int fields = 0;
+ eDBfieldMap update_vals[] = {
+ {TABLE_ATTEMPTS, NULL, FIELD_ATTEMPTS, ft_INT, flt_NOTSET, "attempts", "0", NULL},
+ {0, NULL, 0, ft_UNDEF, flt_NOTSET, NULL, NULL, NULL}
+ };
+
+ fields = eDBmappingFieldsPresent(fmap);
+ if( (fields & (FIELD_UNAME | FIELD_CERTDIGEST | FIELD_REMOTEIP | FIELD_RECID)) == 0 ) {
+ return eurephiaXML_ResultMsg(ctx, exmlERROR,
+ "Missing username, IP address, certificate digest or atpid");
+ }
+
+ res = sqlite_query_mapped(ctx, SQL_UPDATE, "UPDATE openvpn_attempts", update_vals, fmap, NULL);
+ if( res == NULL ) {
+ eurephia_log(ctx, LOG_FATAL, 0, "Could not reset the attempts count");
+ ret = eurephiaXML_ResultMsg(ctx, exmlERROR, "Could not reset the attempts count");
+ } else {
+ ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, "Attempts count reset");
+ sqlite_free_results(res);
+ }
+ return ret;
}
xmlDoc *attempts_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) {
- return NULL;
+ dbresult *res = NULL;
+ xmlDoc *ret = NULL;
+ int fields;
+
+ fields = eDBmappingFieldsPresent(fmap);
+ if( (fields & (FIELD_UNAME | FIELD_CERTDIGEST | FIELD_REMOTEIP | FIELD_RECID)) == 0 ) {
+ return eurephiaXML_ResultMsg(ctx, exmlERROR,
+ "Missing username, IP address, certificate digest or atpid");
+ }
+
+ res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_attempts", NULL, fmap, NULL);
+ if( res == NULL ) {
+ eurephia_log(ctx, LOG_FATAL, 0, "Could not remove attempts record");
+ ret = eurephiaXML_ResultMsg(ctx, exmlERROR, "Could not delete the attempts record");
+ } else {
+ ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, "Attempts record removed");
+ sqlite_free_results(res);
+ }
+ return ret;
}