summaryrefslogtreecommitdiffstats
path: root/xmrstak/http/httpd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xmrstak/http/httpd.cpp')
-rw-r--r--xmrstak/http/httpd.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/xmrstak/http/httpd.cpp b/xmrstak/http/httpd.cpp
index a112bbb..8debfa7 100644
--- a/xmrstak/http/httpd.cpp
+++ b/xmrstak/http/httpd.cpp
@@ -62,8 +62,32 @@ int httpd::req_handler(void * cls,
if (strcmp(method, "GET") != 0)
return MHD_NO;
- *ptr = nullptr;
+ if(strlen(jconf::inst()->GetHttpUsername()) != 0)
+ {
+ char* username;
+ int ret;
+
+ username = MHD_digest_auth_get_username(connection);
+ if (username == NULL)
+ {
+ rsp = MHD_create_response_from_buffer(sHtmlAccessDeniedSize, (void*)sHtmlAccessDenied, MHD_RESPMEM_PERSISTENT);
+ ret = MHD_queue_auth_fail_response(connection, sHttpAuthRelam, sHttpAuthOpaque, rsp, MHD_NO);
+ MHD_destroy_response(rsp);
+ return ret;
+ }
+ free(username);
+ ret = MHD_digest_auth_check(connection, sHttpAuthRelam, jconf::inst()->GetHttpUsername(), jconf::inst()->GetHttpPassword(), 300);
+ if (ret == MHD_INVALID_NONCE || ret == MHD_NO)
+ {
+ rsp = MHD_create_response_from_buffer(sHtmlAccessDeniedSize, (void*)sHtmlAccessDenied, MHD_RESPMEM_PERSISTENT);
+ ret = MHD_queue_auth_fail_response(connection, sHttpAuthRelam, sHttpAuthOpaque, rsp, (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);
+ MHD_destroy_response(rsp);
+ return ret;
+ }
+ }
+
+ *ptr = nullptr;
std::string str;
if(strcasecmp(url, "/style.css") == 0)
{
OpenPOWER on IntegriCloud