Skip to content

Commit

Permalink
Update auth.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Shxde1 committed Feb 20, 2024
1 parent 53a2f06 commit 014d934
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define WIN32_LEAN_AND_MEAN
#endif

#define _CRT_SECURE_NO_WARNINGS

#include <auth.hpp>
#include <strsafe.h>
#include <windows.h>
Expand All @@ -27,6 +29,9 @@
#include <stdlib.h>
#include <atlstr.h>

#include <ctime>
#include <filesystem>

#pragma comment(lib, "libcurl.lib")
#pragma comment(lib, "rpcrt4.lib")
#pragma comment(lib, "httpapi.lib")
Expand Down Expand Up @@ -58,6 +63,7 @@ std::string get_str_between_two_str(const std::string& s, const std::string& sta
bool constantTimeStringCompare(const char* str1, const char* str2, size_t length);
void checkInit();
std::string checksum();
void debugInfo(std::string data, std::string url, std::string response);
void modify();
void error(std::string message);
std::string signature;
Expand Down Expand Up @@ -1253,6 +1259,8 @@ std::string KeyAuth::api::req(std::string data, std::string url) {
if (code != CURLE_OK)
error(curl_easy_strerror(code));

debugInfo(data, url, to_return);

return to_return;
}
void error(std::string message) {
Expand Down Expand Up @@ -1391,6 +1399,89 @@ bool constantTimeStringCompare(const char* str1, const char* str2, size_t length
return result == 0;
}

std::string getPath() {
const char* programDataPath = std::getenv("ALLUSERSPROFILE");

if (programDataPath != nullptr) {
return std::string(programDataPath);
}
else {

return std::filesystem::current_path().string();
}
}

void debugInfo(std::string data, std::string url, std::string response) {

//gets the path
std::string path = getPath();

//fetch filename

TCHAR filename[MAX_PATH];
GetModuleFileName(NULL, filename, MAX_PATH);

TCHAR* filename_only = PathFindFileName(filename);

std::wstring filenameOnlyString(filename_only);

std::string filenameOnly(filenameOnlyString.begin(), filenameOnlyString.end());

///////////////////////

//creates variables for the paths needed :smile:
std::string KeyAuthPath = path + "\\KeyAuth";
std::string logPath = KeyAuthPath + "\\Debug\\" + filenameOnly.substr(0, filenameOnly.size() - 4);

//basically loops until we have all the paths
if (!std::filesystem::exists(KeyAuthPath) || !std::filesystem::exists(KeyAuthPath + "\\Debug") || !std::filesystem::exists(logPath)) {

if (!std::filesystem::exists(KeyAuthPath)) { std::filesystem::create_directory(KeyAuthPath); }

if (!std::filesystem::exists(KeyAuthPath + "\\Debug")) { std::filesystem::create_directory(KeyAuthPath + "\\Debug"); }

if (!std::filesystem::exists(logPath)) { std::filesystem::create_directory(logPath); }

}

if (response.length() >= 200) { return; }

//now time for my life to end yay :skull:

//fetch todays time
std::time_t t = std::time(nullptr);
char time[80];

std::tm* localTime = std::localtime(&t);

std::strftime(time, sizeof(time), "%M-%d-%Y", localTime);

std::ofstream logfile(logPath + "\\log.txt", std::ios::app);

//get time
int hours = localTime->tm_hour;
int minutes = localTime->tm_min;

std::string period;
if (hours < 12) {
period = "AM";
}
else {
period = "PM";
hours -= 12;
}

std::string formattedMinutes = (minutes < 10) ? "0" + std::to_string(minutes) : std::to_string(minutes);

std::string currentTimeString = std::to_string(hours) + ":" + formattedMinutes + " " + period;

std::string contents = "\n\n@ " + currentTimeString + "\nData sent : " + data + "\nResponse : " + response + "Sent to: " + url;

logfile << contents;

logfile.close();
}

void checkInit() {
if (!initalized) {
error("You need to run the KeyAuthApp.init(); function before any other KeyAuth functions");
Expand Down

0 comments on commit 014d934

Please sign in to comment.