X-Git-Url: https://git.rapsys.eu/ihttpd/blobdiff_plain/340ee8bb30b4db4e9b52b78743b1a1be8ba74a2e..72625a495e1c6ba10da830bcf5cdf212ae919b30:/SOURCES/index.bin.c?ds=inline diff --git a/SOURCES/index.bin.c b/SOURCES/index.bin.c index a71c252..cf44c6c 100644 --- a/SOURCES/index.bin.c +++ b/SOURCES/index.bin.c @@ -78,6 +78,10 @@ #define ASKPASSWORDLOG "/run/ihttpd/log/child.askpassword.log" #define IHTTPDLOG "/run/ihttpd/log/child.ihttpd.log" +//Define form uri +#define FORMID "5903c738" +#define FORMURI "/" FORMID ".html" + //Create struct for http error status struct httpStatusStruct { int value; @@ -100,6 +104,7 @@ const struct httpStatusStruct httpStatuses[] = { void die(const int, const char*); void header(const int, const char*); void showForm(const char*, const int, const int); +void showMaintenance(); int extractValue(char**, int*, char*, int); int extractLuksDevice(char**, char**); int extractIHttpdPid(pid_t *); @@ -164,7 +169,10 @@ void showForm(const char *requestUri, const int keyfileSizeMax, const int passph header(503, "text/html"); printf("\r\n"); printf("\r\n"); - printf("Key upload form\r\n"); + printf("\r\n"); + printf("Key upload form!\r\n"); + printf("\r\n"); + printf("\r\n"); printf("\r\n"); printf("
\r\n"); printf("
Upload key
\r\n", requestUri, keyfileSizeMax); @@ -174,6 +182,29 @@ void showForm(const char *requestUri, const int keyfileSizeMax, const int passph printf("\r\n"); } +/** + * Show maintenance + */ +void showMaintenance() { + header(503, "text/html"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("Service unavailable!\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("

Service unavailable!

\r\n"); + printf("

The server is temporarily unable to service your\r\n"); + printf("request due to maintenance downtime or capacity\r\n"); + printf("problems. Please try again later.

\r\n"); + printf("

Error 503

\r\n"); + printf("
%s
%s
\r\n", getenv("SERVER_NAME"), getenv("SERVER_SOFTWARE")); + printf("\r\n", FORMID); + printf("\r\n"); + printf("\r\n"); +} + /** * Extract value */ @@ -766,6 +797,8 @@ int extractIHttpdPid(pid_t *pid) { int main(int argc, char **argv) { //Get request method char *requestMethod = getenv("REQUEST_METHOD"); + //Get request uri + char *requestUri = getenv("REQUEST_URI"); //Handle unknown requests if (requestMethod == NULL || (strncmp(requestMethod, "GET", 3) && strncmp(requestMethod, "HEAD", 4) && strncmp(requestMethod, "POST", 4))) { @@ -773,8 +806,15 @@ int main(int argc, char **argv) { die(405, "Unsupported request method"); //Handle get and head } else if (!strncmp(requestMethod, "GET", 3) || !strncmp(requestMethod, "HEAD", 4)) { - //Send form - showForm(getenv("REQUEST_URI")?getenv("REQUEST_URI"):"/", DEFAULT_KEYFILE_SIZE_MAX, DEFAULT_PASSPHRASE_SIZE_MAX); + //Check if we have form uri + if (requestUri != NULL && strlen(requestUri) == strlen(FORMURI) && !strncmp(requestUri, FORMURI, strlen(FORMURI))) { + //Send form + showForm(requestUri, DEFAULT_KEYFILE_SIZE_MAX, DEFAULT_PASSPHRASE_SIZE_MAX); + //Not form uri requested + } else { + //Send maintenance page + showMaintenance(); + } //Handle post } else /*if (!strncmp(requestMethod, "POST", 4))*/ { //Return value @@ -848,7 +888,7 @@ int main(int argc, char **argv) { //Declare cargv array char *cargvs[] = { CRYPTSETUP, "-d", "-", "luksOpen", device, luks, NULL }; //TODO: device cannot be an UUID=xyz, a resolved block device is required for it - char *scargvs[] = { SYSTEMDCRYPTSETUP, "attach", luks, device, "-", NULL }; + //char *scargvs[] = { SYSTEMDCRYPTSETUP, "attach", luks, device, "-", NULL }; //Check cryptsetup binary if (access(CRYPTSETUP, F_OK|X_OK) == -1) {