diff options
Diffstat (limited to 'www/create_user.c')
-rw-r--r-- | www/create_user.c | 106 |
1 files changed, 106 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> +#include <string.h> + +#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("<!DOCTYPE html>\n"); +printf("<html>\n"); +printf("<head><style> .description {"); + printf("text-align: justify; /* Make the text have even left and right edges */"); + + printf(" max-width: 700px; /* Example: Limit the width of the paragraph */ }"); + +printf(" </style>\n"); +printf("<title>KILLSWITCH PUBLIC ACCESS</title>\n"); +printf("<style>\n"); +printf("a { text-decoration: none; }\n"); +printf("a:hover { text-decoration: underline; }\n"); +printf("a:link, a:visited, a:active { color: #999999; }\n"); +printf(".plate {\n"); +printf(" background: linear-gradient(rgba(0,0,0,0.75), rgba(0,0,0,0.2), rgba(0,0,0,0.0)), url(https://computerarson.neocities.org/PvnaJep.png);\n"); +printf(" padding-left: 5px;\n"); +printf(" padding-right: 5px;\n"); +printf(" padding-bottom: 5px;\n"); +printf("}\n"); +printf(".form-td {\n"); +printf(" background-color: #D3D3D3;\n"); +printf(" color: white;\n"); +printf("}\n"); +printf("input {\n"); +printf(" border-color: #800000;\n"); +printf(" border-style: solid;\n"); +printf(" border-width: 1px;\n"); +printf(" font-family: verdana;\n"); +printf(" font-size: 10px;\n"); +printf("}\n"); +printf(".submit-btn {\n"); +printf(" border-color: #800000;\n"); +printf(" border-style: solid;\n"); +printf(" border-width: 1px;\n"); +printf(" color: #800000;\n"); +printf(" font-size: 15px;\n"); +printf("}\n"); +printf("</style>\n"); +printf("</head>\n"); +printf("<body bgcolor=\"black\" topmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" style=\"margin-top: 0px;\">\n"); +printf("<table cellspacing=\"0\" cellpadding=\"0\" width=\"720\" align=\"center\">\n"); +printf("<tr><td bgcolor=\"black\" valign=\"top\">\n"); +printf("<div style=\"margin-top: 8px; margin-left: 15px; margin-right: 5px;\" align=\"right\" class=\"welcome\">\n"); +printf("<b></b> <br><br>\n"); +printf("</div>\n"); +printf("</td></tr>\n"); +printf("<tr style=\"border: 1px solid #800000;\"><td class=\"plate\" style=\"border: 1px solid #800000;\" valign=\"top\">\n"); +printf("<div align=\"center\">\n"); +printf("<table cellspacing=\"2\" cellpadding=\"10\" border=\"0\" width=\"97%%\">\n"); +printf("<tr><td valign=\"top\">\n"); +printf("<font face=\"verdana\" size=\"3\" color=\"#999999\" margin=\"1\">\n"); +printf("KILLSWITCH PUBLIC ACCESS SYSTEM <br><br>\n"); +printf("</font>\n"); +printf("<font face=\"verdana\" size=\"2\" color=\"#999999\" margin=\"1\">\n"); +printf("</font> <br>\n <font face=\"verdana\" size=\"3\" color=\"#999999\" margin=\"1\">"); + + 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("<p>Invalid username or password.</p>"); + + 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("<h1>Account Created Successfully</h1>\n"); + printf("<p><b>Username:</b> %s</p>\n", username); + printf("<p class=\"description\"><b>Password:</b> %s</p>\n", masked); + } else { + printf("<h1>Failure</h1><p>Could not create user. Exit code: %d</p>", WEXITSTATUS(result)); + } + + return 0; +} |