From: Raphaƫl Gertz Date: Thu, 31 Jan 2019 15:52:21 +0000 (+0100) Subject: Add maintenance page X-Git-Tag: 2.4.38-6~10 X-Git-Url: https://git.rapsys.eu/ihttpd/commitdiff_plain/d3c728f459bc34bb44bbeb6e888790053034f14a Add maintenance page Add formid to only have form on a specific uri Grow version --- diff --git a/SOURCES/index.bin.c b/SOURCES/index.bin.c index a71c252..f0275a4 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 "" +#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) { diff --git a/SPECS/ihttpd.spec b/SPECS/ihttpd.spec index f0f4594..15729b1 100644 --- a/SPECS/ihttpd.spec +++ b/SPECS/ihttpd.spec @@ -6,7 +6,7 @@ Name: ihttpd Version: 2.4.33 -Release: %mkrel 4 +Release: %mkrel 5 Summary: The most widely used Web server on the Internet License: Apache License Group: System/Servers