Skip to content

Commit 014d934

Browse files
authored
Update auth.cpp
1 parent 53a2f06 commit 014d934

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

auth.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#define WIN32_LEAN_AND_MEAN
1111
#endif
1212

13+
#define _CRT_SECURE_NO_WARNINGS
14+
1315
#include <auth.hpp>
1416
#include <strsafe.h>
1517
#include <windows.h>
@@ -27,6 +29,9 @@
2729
#include <stdlib.h>
2830
#include <atlstr.h>
2931

32+
#include <ctime>
33+
#include <filesystem>
34+
3035
#pragma comment(lib, "libcurl.lib")
3136
#pragma comment(lib, "rpcrt4.lib")
3237
#pragma comment(lib, "httpapi.lib")
@@ -58,6 +63,7 @@ std::string get_str_between_two_str(const std::string& s, const std::string& sta
5863
bool constantTimeStringCompare(const char* str1, const char* str2, size_t length);
5964
void checkInit();
6065
std::string checksum();
66+
void debugInfo(std::string data, std::string url, std::string response);
6167
void modify();
6268
void error(std::string message);
6369
std::string signature;
@@ -1253,6 +1259,8 @@ std::string KeyAuth::api::req(std::string data, std::string url) {
12531259
if (code != CURLE_OK)
12541260
error(curl_easy_strerror(code));
12551261

1262+
debugInfo(data, url, to_return);
1263+
12561264
return to_return;
12571265
}
12581266
void error(std::string message) {
@@ -1391,6 +1399,89 @@ bool constantTimeStringCompare(const char* str1, const char* str2, size_t length
13911399
return result == 0;
13921400
}
13931401

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+
13941485
void checkInit() {
13951486
if (!initalized) {
13961487
error("You need to run the KeyAuthApp.init(); function before any other KeyAuth functions");

0 commit comments

Comments
 (0)