summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--database/eurephiadb.c3
-rw-r--r--database/eurephiadb_driver.h3
-rw-r--r--database/sqlite/edb-sqlite.c46
3 files changed, 52 insertions, 0 deletions
diff --git a/database/eurephiadb.c b/database/eurephiadb.c
index 3d77ea7..3816ba7 100644
--- a/database/eurephiadb.c
+++ b/database/eurephiadb.c
@@ -97,6 +97,9 @@ int eDBlink_init(eurephiaCTX *ctx, const char *dbl, const int minver)
eDBadminRegisterLogin = eGetSym(ctx, ctx->eurephia_driver, "eDBadminRegisterLogin");
eDBadminLogout = eGetSym(ctx, ctx->eurephia_driver, "eDBadminLogout");
+ eDBadminConfigSet = eGetSym(ctx, ctx->eurephia_driver, "eDBadminConfigSet");
+ eDBadminConfigDelete = eGetSym(ctx, ctx->eurephia_driver, "eDBadminConfigDelete");
+
eDBgetUserList = eGetSym(ctx, ctx->eurephia_driver, "eDBgetUserList");
eDBgetUserInfo = eGetSym(ctx, ctx->eurephia_driver, "eDBgetUserInfo");
eDBaddUser = eGetSym(ctx, ctx->eurephia_driver, "eDBaddUser");
diff --git a/database/eurephiadb_driver.h b/database/eurephiadb_driver.h
index be0c4c8..00c2ba4 100644
--- a/database/eurephiadb_driver.h
+++ b/database/eurephiadb_driver.h
@@ -91,6 +91,9 @@ int (*eDBadminValidateSession) (eurephiaCTX *ctx, const char *sesskey);
int (*eDBadminRegisterLogin) (eurephiaCTX *ctx, eurephiaSESSION *session);
int (*eDBadminLogout) (eurephiaCTX *ctx, eurephiaSESSION *session);
+int (*eDBadminConfigSet) (eurephiaCTX *ctx, const char *key, const char *val);
+int (*eDBadminConfigDelete) (eurephiaCTX *ctx, const char *key);
+
eurephiaUSERLIST *(*eDBgetUserList) (eurephiaCTX *ctx, const int sortkey);
eurephiaUSERINFO *(*eDBgetUserInfo) (eurephiaCTX *ctx, eurephiaUSERINFO *searchkey);
int (*eDBaddUser) (eurephiaCTX *ctx, eurephiaUSERINFO *userinfo);
diff --git a/database/sqlite/edb-sqlite.c b/database/sqlite/edb-sqlite.c
index d9a29a8..4227234 100644
--- a/database/sqlite/edb-sqlite.c
+++ b/database/sqlite/edb-sqlite.c
@@ -1146,6 +1146,52 @@ int eDBadminLogout(eurephiaCTX *ctx, eurephiaSESSION *session) {
return 1;
}
+int eDBadminConfigSet(eurephiaCTX *ctx, const char *key, const char *val) {
+ dbresult *res = NULL;
+ int found = 0;
+
+ assert((ctx != NULL) && (ctx->dbc != NULL));
+
+ res = sqlite_query(ctx, "SELECT count(*) FROM openvpn_config WHERE datakey = '%q'", key);
+ if( !res ) {
+ eurephia_log(ctx, LOG_ERROR, 0, "Could not query configuration table");
+ return 0;
+ }
+ found = atoi_nullsafe(sqlite_get_value(res, 0, 0));
+ sqlite_free_results(res);
+
+ if( found == 0 ) {
+ res = sqlite_query(ctx,
+ "INSERT INTO openvpn_config (datakey, dataval) VALUES ('%q','%q')",
+ key, val);
+ } else {
+ res = sqlite_query(ctx, "UPDATE openvpn_config SET dataval = '%q' WHERE datakey = '%q'",
+ val, key);
+ }
+
+ if( res == NULL ) {
+ eurephia_log(ctx, LOG_ERROR, 0, "Could not register configuration entry (%s = '%s'", key, val);
+ return 0;
+ }
+ sqlite_free_results(res);
+ eAdd_value(ctx, ctx->dbc->config, key, val);
+ return 1;
+}
+
+int eDBadminConfigDelete(eurephiaCTX *ctx, const char *key) {
+ dbresult *res = NULL;
+
+ assert((ctx != NULL) && (ctx->dbc != NULL));
+
+ res = sqlite_query(ctx, "DELETE FROM openvpn_config WHERE datakey = '%q'", key);
+ if( !res ) {
+ eurephia_log(ctx, LOG_ERROR, 0, "Could delete config configuration entry (%s)", key);
+ return 0;
+ }
+ sqlite_free_results(res);
+ return 1;
+}
+
eurephiaUSERLIST *eDBgetUserList(eurephiaCTX *ctx, const int sortkey) {
return NULL;
}