Skip to content

Commit 0b8d85e

Browse files
committed
Fix web loader
1 parent 1c88c53 commit 0b8d85e

File tree

1 file changed

+99
-36
lines changed

1 file changed

+99
-36
lines changed

auth.cpp

Lines changed: 99 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -291,28 +291,127 @@ void KeyAuth::api::web_login()
291291
HTTPAPI_VERSION version = HTTPAPI_VERSION_2;
292292
result = HttpInitialize(version, HTTP_INITIALIZE_SERVER, 0);
293293

294+
if (result == ERROR_INVALID_PARAMETER) {
295+
MessageBoxA(NULL, "The Flags parameter contains an unsupported value.", "Error", MB_ICONEXCLAMATION);
296+
exit(0);
297+
}
298+
if (result != NO_ERROR) {
299+
MessageBoxA(NULL, "System error for Initialize", "Error", MB_ICONEXCLAMATION);
300+
exit(0);
301+
}
302+
294303
// Create server session.
295304
HTTP_SERVER_SESSION_ID serverSessionId;
296305
result = HttpCreateServerSession(version, &serverSessionId, 0);
297306

307+
if (result == ERROR_REVISION_MISMATCH) {
308+
MessageBoxA(NULL, "Version for session invalid", "Error", MB_ICONEXCLAMATION);
309+
exit(0);
310+
}
311+
312+
if (result == ERROR_INVALID_PARAMETER) {
313+
MessageBoxA(NULL, "pServerSessionId parameter is null", "Error", MB_ICONEXCLAMATION);
314+
exit(0);
315+
}
316+
317+
if (result != NO_ERROR) {
318+
MessageBoxA(NULL, "System error for HttpCreateServerSession", "Error", MB_ICONEXCLAMATION);
319+
exit(0);
320+
}
321+
298322
// Create URL group.
299323
HTTP_URL_GROUP_ID groupId;
300324
result = HttpCreateUrlGroup(serverSessionId, &groupId, 0);
301325

326+
if (result == ERROR_INVALID_PARAMETER) {
327+
MessageBoxA(NULL, "Url group create parameter error", "Error", MB_ICONEXCLAMATION);
328+
exit(0);
329+
}
330+
331+
if (result != NO_ERROR) {
332+
MessageBoxA(NULL, "System error for HttpCreateUrlGroup", "Error", MB_ICONEXCLAMATION);
333+
exit(0);
334+
}
335+
302336
// Create request queue.
303337
HANDLE requestQueueHandle;
304338
result = HttpCreateRequestQueue(version, NULL, NULL, 0, &requestQueueHandle);
305339

340+
if (result == ERROR_REVISION_MISMATCH) {
341+
MessageBoxA(NULL, "Wrong version", "Error", MB_ICONEXCLAMATION);
342+
exit(0);
343+
}
344+
345+
if (result == ERROR_INVALID_PARAMETER) {
346+
MessageBoxA(NULL, "Byte length exceeded", "Error", MB_ICONEXCLAMATION);
347+
exit(0);
348+
}
349+
350+
if (result == ERROR_ALREADY_EXISTS) {
351+
MessageBoxA(NULL, "pName already used", "Error", MB_ICONEXCLAMATION);
352+
exit(0);
353+
}
354+
355+
if (result == ERROR_ACCESS_DENIED) {
356+
MessageBoxA(NULL, "queue access denied", "Error", MB_ICONEXCLAMATION);
357+
exit(0);
358+
}
359+
360+
if (result == ERROR_DLL_INIT_FAILED) {
361+
MessageBoxA(NULL, "Initialize not called", "Error", MB_ICONEXCLAMATION);
362+
exit(0);
363+
}
364+
365+
if (result != NO_ERROR) {
366+
MessageBoxA(NULL, "System error for HttpCreateRequestQueue", "Error", MB_ICONEXCLAMATION);
367+
exit(0);
368+
}
369+
306370
// Attach request queue to URL group.
307371
HTTP_BINDING_INFO info;
308372
info.Flags.Present = 1;
309373
info.RequestQueueHandle = requestQueueHandle;
310374
result = HttpSetUrlGroupProperty(groupId, HttpServerBindingProperty, &info, sizeof(info));
311375

376+
if (result == ERROR_INVALID_PARAMETER) {
377+
MessageBoxA(NULL, XorStr("Invalid parameter").c_str(), "Error", MB_ICONEXCLAMATION);
378+
exit(0);
379+
}
380+
381+
if (result != NO_ERROR) {
382+
MessageBoxA(NULL, XorStr("System error for HttpSetUrlGroupProperty").c_str(), "Error", MB_ICONEXCLAMATION);
383+
exit(0);
384+
}
385+
312386
// Add URLs to URL group.
313387
PCWSTR url = L"http://localhost:1337/handshake";
314388
result = HttpAddUrlToUrlGroup(groupId, url, 0, 0);
315389

390+
if (result == ERROR_ACCESS_DENIED) {
391+
MessageBoxA(NULL, XorStr("No permissions to run web server").c_str(), "Error", MB_ICONEXCLAMATION);
392+
exit(0);
393+
}
394+
395+
if (result == ERROR_ALREADY_EXISTS) {
396+
MessageBoxA(NULL, XorStr("You are running this program already").c_str(), "Error", MB_ICONEXCLAMATION);
397+
exit(0);
398+
}
399+
400+
if (result == ERROR_INVALID_PARAMETER) {
401+
MessageBoxA(NULL, XorStr("ERROR_INVALID_PARAMETER for HttpAddUrlToUrlGroup").c_str(), "Error", MB_ICONEXCLAMATION);
402+
exit(0);
403+
}
404+
405+
if (result == ERROR_SHARING_VIOLATION) {
406+
MessageBoxA(NULL, XorStr("Another program is using the webserver. Close Razer Chroma mouse software if you use that. Try to restart computer.").c_str(), "Error", MB_ICONEXCLAMATION);
407+
exit(0);
408+
}
409+
410+
if (result != NO_ERROR) {
411+
MessageBoxA(NULL, XorStr("System error for HttpAddUrlToUrlGroup").c_str(), "Error", MB_ICONEXCLAMATION);
412+
exit(0);
413+
}
414+
316415
// Announce that it is running.
317416
// wprintf(L"Listening. Please submit requests to: %s\n", url);
318417

@@ -362,18 +461,6 @@ void KeyAuth::api::web_login()
362461
response.pReason = static_cast<PCSTR>(XorStr("OK").c_str());
363462
response.ReasonLength = (USHORT)strlen(response.pReason);
364463

365-
response.Headers.KnownHeaders[HttpHeaderServer].pRawValue = XorStr("Apache/2.4.48 nginx/1.12.2").c_str(); // confuse anyone looking at server header
366-
response.Headers.KnownHeaders[HttpHeaderServer].RawValueLength = 24;
367-
368-
response.Headers.KnownHeaders[HttpHeaderVia].pRawValue = XorStr("hugzho's big brain").c_str();
369-
response.Headers.KnownHeaders[HttpHeaderVia].RawValueLength = 18;
370-
371-
response.Headers.KnownHeaders[HttpHeaderRetryAfter].pRawValue = XorStr("never lmao").c_str();
372-
response.Headers.KnownHeaders[HttpHeaderRetryAfter].RawValueLength = 10;
373-
374-
response.Headers.KnownHeaders[HttpHeaderLocation].pRawValue = XorStr("your kernel ;)").c_str();
375-
response.Headers.KnownHeaders[HttpHeaderLocation].RawValueLength = 14;
376-
377464
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/6d468747-2221-4f4a-9156-f98f355a9c08/using-httph-to-set-up-an-https-server-that-is-queried-by-a-client-that-uses-cross-origin-requests?forum=vcgeneral
378465
HTTP_UNKNOWN_HEADER accessControlHeader;
379466
const char testCustomHeader[] = "Access-Control-Allow-Origin";
@@ -461,18 +548,6 @@ void KeyAuth::api::web_login()
461548
}
462549
// end keyauth request
463550

464-
response.Headers.KnownHeaders[HttpHeaderServer].pRawValue = XorStr("Apache/2.4.48 nginx/1.12.2").c_str(); // confuse anyone looking at server header
465-
response.Headers.KnownHeaders[HttpHeaderServer].RawValueLength = 24;
466-
467-
response.Headers.KnownHeaders[HttpHeaderVia].pRawValue = XorStr("hugzho's big brain").c_str();
468-
response.Headers.KnownHeaders[HttpHeaderVia].RawValueLength = 18;
469-
470-
response.Headers.KnownHeaders[HttpHeaderRetryAfter].pRawValue = XorStr("never lmao").c_str();
471-
response.Headers.KnownHeaders[HttpHeaderRetryAfter].RawValueLength = 10;
472-
473-
response.Headers.KnownHeaders[HttpHeaderLocation].pRawValue = XorStr("your kernel ;)").c_str();
474-
response.Headers.KnownHeaders[HttpHeaderLocation].RawValueLength = 14;
475-
476551
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/6d468747-2221-4f4a-9156-f98f355a9c08/using-httph-to-set-up-an-https-server-that-is-queried-by-a-client-that-uses-cross-origin-requests?forum=vcgeneral
477552
HTTP_UNKNOWN_HEADER accessControlHeader;
478553
const char testCustomHeader[] = "Access-Control-Allow-Origin";
@@ -597,18 +672,6 @@ void KeyAuth::api::button(std::string button)
597672
response.pReason = XorStr("SHEESH").c_str();
598673
response.ReasonLength = (USHORT)strlen(response.pReason);
599674

600-
response.Headers.KnownHeaders[HttpHeaderServer].pRawValue = XorStr("Apache/2.4.48 nginx/1.12.2").c_str(); // confuse anyone looking at server header
601-
response.Headers.KnownHeaders[HttpHeaderServer].RawValueLength = 24;
602-
603-
response.Headers.KnownHeaders[HttpHeaderVia].pRawValue = XorStr("hugzho's big brain").c_str();
604-
response.Headers.KnownHeaders[HttpHeaderVia].RawValueLength = 18;
605-
606-
response.Headers.KnownHeaders[HttpHeaderRetryAfter].pRawValue = XorStr("never lmao").c_str();
607-
response.Headers.KnownHeaders[HttpHeaderRetryAfter].RawValueLength = 10;
608-
609-
response.Headers.KnownHeaders[HttpHeaderLocation].pRawValue = XorStr("your kernel ;)").c_str();
610-
response.Headers.KnownHeaders[HttpHeaderLocation].RawValueLength = 14;
611-
612675
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/6d468747-2221-4f4a-9156-f98f355a9c08/using-httph-to-set-up-an-https-server-that-is-queried-by-a-client-that-uses-cross-origin-requests?forum=vcgeneral
613676
HTTP_UNKNOWN_HEADER accessControlHeader;
614677
const char testCustomHeader[] = "Access-Control-Allow-Origin";

0 commit comments

Comments
 (0)