@@ -1238,6 +1238,37 @@ void KeyAuth::api::forgot(std::string username, std::string email)
1238
1238
load_response_data (json);
1239
1239
}
1240
1240
1241
+ void KeyAuth::api::logout () {
1242
+ checkInit ();
1243
+
1244
+ auto data =
1245
+ XorStr (" type=logout" ) +
1246
+ XorStr (" &sessionid=" ) + sessionid +
1247
+ XorStr (" &name=" ) + name +
1248
+ XorStr (" &ownerid=" ) + ownerid;
1249
+ auto response = req (data, url);
1250
+ auto json = response_decoder.parse (response);
1251
+ if (json[(XorStr (" success" ))]) {
1252
+
1253
+ // clear all old user data from program
1254
+ user_data.createdate .clear ();
1255
+ user_data.ip .clear ();
1256
+ user_data.hwid .clear ();
1257
+ user_data.lastlogin .clear ();
1258
+ user_data.username .clear ();
1259
+ user_data.subscriptions .clear ();
1260
+
1261
+ // clear sessionid
1262
+ sessionid.clear ();
1263
+
1264
+ // clear enckey
1265
+ enckey.clear ();
1266
+
1267
+ }
1268
+
1269
+ load_response_data (json);
1270
+ }
1271
+
1241
1272
// credits https://stackoverflow.com/a/3790661
1242
1273
static std::string hexDecode (const std::string& hex)
1243
1274
{
@@ -1466,8 +1497,61 @@ std::string getPath() {
1466
1497
}
1467
1498
}
1468
1499
1500
+ void RedactField (nlohmann::json& jsonObject, const std::string& fieldName)
1501
+ {
1502
+
1503
+ if (jsonObject.contains (fieldName)) {
1504
+ jsonObject[fieldName] = " REDACTED" ;
1505
+ }
1506
+ }
1507
+
1469
1508
void debugInfo (std::string data, std::string url, std::string response) {
1470
1509
1510
+ // turn response into json
1511
+ nlohmann::json responses = nlohmann::json::parse (response);
1512
+ RedactField (responses, " sessionid" );
1513
+ RedactField (responses, " ownerid" );
1514
+ RedactField (responses, " app" );
1515
+ RedactField (responses, " name" );
1516
+ RedactField (responses, " contents" );
1517
+ RedactField (responses, " key" );
1518
+ RedactField (responses, " username" );
1519
+ RedactField (responses, " password" );
1520
+ RedactField (responses, " secret" );
1521
+ RedactField (responses, " version" );
1522
+ RedactField (responses, " fileid" );
1523
+ RedactField (responses, " webhooks" );
1524
+ std::string redacted_response = responses.dump ();
1525
+
1526
+ // turn data into json
1527
+ std::replace (data.begin (), data.end (), ' &' , ' ' );
1528
+
1529
+ nlohmann::json datas;
1530
+
1531
+ std::istringstream iss (data);
1532
+ std::vector<std::string> results ((std::istream_iterator<std::string>(iss)),
1533
+ std::istream_iterator<std::string>());
1534
+
1535
+ for (auto const & value : results) {
1536
+ datas[value.substr (0 , value.find (' =' ))] = value.substr (value.find (' =' ) + 1 );
1537
+ }
1538
+
1539
+ RedactField (datas, " sessionid" );
1540
+ RedactField (datas, " ownerid" );
1541
+ RedactField (datas, " app" );
1542
+ RedactField (datas, " name" );
1543
+ RedactField (datas, " key" );
1544
+ RedactField (datas, " username" );
1545
+ RedactField (datas, " password" );
1546
+ RedactField (datas, " contents" );
1547
+ RedactField (datas, " secret" );
1548
+ RedactField (datas, " version" );
1549
+ RedactField (datas, " fileid" );
1550
+ RedactField (datas, " webhooks" );
1551
+
1552
+ std::string redacted_data = datas.dump ();
1553
+
1554
+
1471
1555
// gets the path
1472
1556
std::string path = getPath ();
1473
1557
@@ -1485,7 +1569,7 @@ void debugInfo(std::string data, std::string url, std::string response) {
1485
1569
// /////////////////////
1486
1570
1487
1571
// creates variables for the paths needed :smile:
1488
- std::string KeyAuthPath = path + " \\ KeyAuth" ;
1572
+ std::string KeyAuthPath = path + " \\ KeyAuth" ;
1489
1573
std::string logPath = KeyAuthPath + " \\ Debug\\ " + filenameOnly.substr (0 , filenameOnly.size () - 4 );
1490
1574
1491
1575
// basically loops until we have all the paths
@@ -1530,7 +1614,7 @@ void debugInfo(std::string data, std::string url, std::string response) {
1530
1614
1531
1615
std::string currentTimeString = std::to_string (hours) + " :" + formattedMinutes + " " + period;
1532
1616
1533
- std::string contents = " \n\n @ " + currentTimeString + " \n Data sent : " + data + " \n Response : " + response + " Sent to: " + url;
1617
+ std::string contents = " \n\n @ " + currentTimeString + " \n Data sent : " + redacted_data + " \n Response : " + redacted_response + " Sent to: " + url;
1534
1618
1535
1619
logfile << contents;
1536
1620
0 commit comments