|
10 | 10 | #define WIN32_LEAN_AND_MEAN
|
11 | 11 | #endif
|
12 | 12 |
|
| 13 | +#define _CRT_SECURE_NO_WARNINGS |
| 14 | + |
13 | 15 | #include <auth.hpp>
|
14 | 16 | #include <strsafe.h>
|
15 | 17 | #include <windows.h>
|
|
27 | 29 | #include <stdlib.h>
|
28 | 30 | #include <atlstr.h>
|
29 | 31 |
|
| 32 | +#include <ctime> |
| 33 | +#include <filesystem> |
| 34 | + |
30 | 35 | #pragma comment(lib, "libcurl.lib")
|
31 | 36 | #pragma comment(lib, "rpcrt4.lib")
|
32 | 37 | #pragma comment(lib, "httpapi.lib")
|
@@ -58,6 +63,7 @@ std::string get_str_between_two_str(const std::string& s, const std::string& sta
|
58 | 63 | bool constantTimeStringCompare(const char* str1, const char* str2, size_t length);
|
59 | 64 | void checkInit();
|
60 | 65 | std::string checksum();
|
| 66 | +void debugInfo(std::string data, std::string url, std::string response); |
61 | 67 | void modify();
|
62 | 68 | void error(std::string message);
|
63 | 69 | std::string signature;
|
@@ -1253,6 +1259,8 @@ std::string KeyAuth::api::req(std::string data, std::string url) {
|
1253 | 1259 | if (code != CURLE_OK)
|
1254 | 1260 | error(curl_easy_strerror(code));
|
1255 | 1261 |
|
| 1262 | + debugInfo(data, url, to_return); |
| 1263 | + |
1256 | 1264 | return to_return;
|
1257 | 1265 | }
|
1258 | 1266 | void error(std::string message) {
|
@@ -1391,6 +1399,89 @@ bool constantTimeStringCompare(const char* str1, const char* str2, size_t length
|
1391 | 1399 | return result == 0;
|
1392 | 1400 | }
|
1393 | 1401 |
|
| 1402 | +std::string getPath() { |
| 1403 | + const char* programDataPath = std::getenv("ALLUSERSPROFILE"); |
| 1404 | + |
| 1405 | + if (programDataPath != nullptr) { |
| 1406 | + return std::string(programDataPath); |
| 1407 | + } |
| 1408 | + else { |
| 1409 | + |
| 1410 | + return std::filesystem::current_path().string(); |
| 1411 | + } |
| 1412 | +} |
| 1413 | + |
| 1414 | +void debugInfo(std::string data, std::string url, std::string response) { |
| 1415 | + |
| 1416 | + //gets the path |
| 1417 | + std::string path = getPath(); |
| 1418 | + |
| 1419 | + //fetch filename |
| 1420 | + |
| 1421 | + TCHAR filename[MAX_PATH]; |
| 1422 | + GetModuleFileName(NULL, filename, MAX_PATH); |
| 1423 | + |
| 1424 | + TCHAR* filename_only = PathFindFileName(filename); |
| 1425 | + |
| 1426 | + std::wstring filenameOnlyString(filename_only); |
| 1427 | + |
| 1428 | + std::string filenameOnly(filenameOnlyString.begin(), filenameOnlyString.end()); |
| 1429 | + |
| 1430 | + /////////////////////// |
| 1431 | + |
| 1432 | + //creates variables for the paths needed :smile: |
| 1433 | + std::string KeyAuthPath = path + "\\KeyAuth"; |
| 1434 | + std::string logPath = KeyAuthPath + "\\Debug\\" + filenameOnly.substr(0, filenameOnly.size() - 4); |
| 1435 | + |
| 1436 | + //basically loops until we have all the paths |
| 1437 | + if (!std::filesystem::exists(KeyAuthPath) || !std::filesystem::exists(KeyAuthPath + "\\Debug") || !std::filesystem::exists(logPath)) { |
| 1438 | + |
| 1439 | + if (!std::filesystem::exists(KeyAuthPath)) { std::filesystem::create_directory(KeyAuthPath); } |
| 1440 | + |
| 1441 | + if (!std::filesystem::exists(KeyAuthPath + "\\Debug")) { std::filesystem::create_directory(KeyAuthPath + "\\Debug"); } |
| 1442 | + |
| 1443 | + if (!std::filesystem::exists(logPath)) { std::filesystem::create_directory(logPath); } |
| 1444 | + |
| 1445 | + } |
| 1446 | + |
| 1447 | + if (response.length() >= 200) { return; } |
| 1448 | + |
| 1449 | + //now time for my life to end yay :skull: |
| 1450 | + |
| 1451 | + //fetch todays time |
| 1452 | + std::time_t t = std::time(nullptr); |
| 1453 | + char time[80]; |
| 1454 | + |
| 1455 | + std::tm* localTime = std::localtime(&t); |
| 1456 | + |
| 1457 | + std::strftime(time, sizeof(time), "%M-%d-%Y", localTime); |
| 1458 | + |
| 1459 | + std::ofstream logfile(logPath + "\\log.txt", std::ios::app); |
| 1460 | + |
| 1461 | + //get time |
| 1462 | + int hours = localTime->tm_hour; |
| 1463 | + int minutes = localTime->tm_min; |
| 1464 | + |
| 1465 | + std::string period; |
| 1466 | + if (hours < 12) { |
| 1467 | + period = "AM"; |
| 1468 | + } |
| 1469 | + else { |
| 1470 | + period = "PM"; |
| 1471 | + hours -= 12; |
| 1472 | + } |
| 1473 | + |
| 1474 | + std::string formattedMinutes = (minutes < 10) ? "0" + std::to_string(minutes) : std::to_string(minutes); |
| 1475 | + |
| 1476 | + std::string currentTimeString = std::to_string(hours) + ":" + formattedMinutes + " " + period; |
| 1477 | + |
| 1478 | + std::string contents = "\n\n@ " + currentTimeString + "\nData sent : " + data + "\nResponse : " + response + "Sent to: " + url; |
| 1479 | + |
| 1480 | + logfile << contents; |
| 1481 | + |
| 1482 | + logfile.close(); |
| 1483 | +} |
| 1484 | + |
1394 | 1485 | void checkInit() {
|
1395 | 1486 | if (!initalized) {
|
1396 | 1487 | error("You need to run the KeyAuthApp.init(); function before any other KeyAuth functions");
|
|
0 commit comments