From dd55f98281c1c0c28a5f8df3c87031bc84dd450d Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 26 Jun 2025 00:23:53 +0000 Subject: custom scripts used to manage the public access system --- www/create_user.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 www/create_user.c (limited to 'www') diff --git a/www/create_user.c b/www/create_user.c new file mode 100644 index 0000000..19768fc --- /dev/null +++ b/www/create_user.c @@ -0,0 +1,106 @@ +#include +#include +#include + +#define MAX_INPUT 4000 +// Function to parse POST data +void parse_post(char* data, char* username, char* password) { + sscanf(data, "username=%[^&]&password=%s", username, password); +} +void mask_password(char *src, char *dest) { + size_t len = strlen(src); + for (size_t i = 0; i < len; i++) { + dest[i] = '*'; + } + dest[len] = '\0'; +} + +int main() { + printf("Content-type: text/html\n\n"); +printf("\n"); +printf("\n"); +printf("\n"); +printf("KILLSWITCH PUBLIC ACCESS\n"); +printf("\n"); +printf("\n"); +printf("\n"); +printf("\n"); +printf("\n"); +printf("
\n"); +printf("
\n"); +printf("   

\n"); +printf("
\n"); +printf("
\n"); +printf("
\n"); +printf("\n"); +printf("
\n"); +printf("\n"); +printf("KILLSWITCH PUBLIC ACCESS SYSTEM

\n"); +printf("
\n"); +printf("\n"); +printf("
\n "); + + char *content_length = getenv("CONTENT_LENGTH"); + int len = content_length ? atoi(content_length) : 0; + + char post_data[MAX_INPUT] = {0}; + fread(post_data, 1, len, stdin); + char username[64] = {0}, password[3000] = {0}; + parse_post(post_data, username, password); + + + if (strlen(username) == 0 || strlen(password) == 0) { + printf("

Invalid username or password.

"); + + return 1; + } + + // Call external shell script to create jailed user + char cmd[MAX_INPUT]; + snprintf(cmd, sizeof(cmd), "sudo /usr/local/bin/create_user.sh '%s' '%s' > /tmp/create_user_log.txt 2>&1", username, password); + int result = system(cmd); + if (WIFEXITED(result) && WEXITSTATUS(result) == 0) { + char masked[64]; + mask_password(password, masked); + printf("

Account Created Successfully

\n"); + printf("

Username: %s

\n", username); + printf("

Password: %s

\n", masked); + } else { + printf("

Failure

Could not create user. Exit code: %d

", WEXITSTATUS(result)); + } + + return 0; +} -- cgit v1.2.3