diff --git a/Source Code/esprfidtool/api.h b/Source Code/esprfidtool/api.h
new file mode 100644
index 0000000..8643b24
--- /dev/null
+++ b/Source Code/esprfidtool/api.h
@@ -0,0 +1,158 @@
+void apiinfo(int prettify) {
+
+ FSInfo fs_info;
+ SPIFFS.info(fs_info);
+ String total;
+ total=fs_info.totalBytes;
+ String used;
+ used=fs_info.usedBytes;
+ String freespace;
+ freespace=fs_info.totalBytes-fs_info.usedBytes;
+
+ const size_t bufferSize = JSON_ARRAY_SIZE(5) + JSON_OBJECT_SIZE(3);
+ DynamicJsonBuffer jsonAPIbuffer(bufferSize);
+ JsonObject& apilog = jsonAPIbuffer.createObject();
+
+ apilog["Device"] = "ESP-RFID-Tool";
+ apilog["Firmware"] = version;
+ apilog["API"] = APIversion;
+ JsonObject& apifs = apilog.createNestedObject("File System");
+ apifs["Total Space"]=total;
+ apifs["Used Space"]=used;
+ apifs["Free Space"]=freespace;
+ apilog["Free Memory"] = String(ESP.getFreeHeap(),DEC);
+
+ String API_Response="";
+ if (prettify==1) {
+ apilog.prettyPrintTo(API_Response);
+ }
+ else {
+ apilog.printTo(API_Response);
+ }
+ server.send(200, "application/json", API_Response);
+ delay(50);
+ jsonAPIbuffer.clear();
+}
+
+void apilistlogs(int prettify) {
+ Dir dir = SPIFFS.openDir("/");
+ String FileList = "";
+ int logcount=0;
+
+ while (dir.next()) {
+ File f = dir.openFile("r");
+ String FileName = dir.fileName();
+ if((!FileName.startsWith("/payloads/"))&&(!FileName.startsWith("/esploit.json"))&&(!FileName.startsWith("/esportal.json"))&&(!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) {
+ logcount++;
+ }
+ f.close();
+ }
+
+ const size_t bufferSize = JSON_ARRAY_SIZE(5) + JSON_OBJECT_SIZE(1);
+ DynamicJsonBuffer jsonAPIbuffer(bufferSize);
+ JsonObject& apilog = jsonAPIbuffer.createObject();
+
+ apilog["Device"] = "ESP-RFID-Tool";
+ apilog["Firmware"] = version;
+ apilog["API"] = APIversion;
+ apilog["Log Count"] = logcount;
+
+ int currentlog=0;
+ Dir dir2ndrun = SPIFFS.openDir("/");
+ while (dir2ndrun.next()) {
+ File f = dir2ndrun.openFile("r");
+ String FileName = dir2ndrun.fileName();
+ if ((!FileName.startsWith("/payloads/"))&&(!FileName.startsWith("/esploit.json"))&&(!FileName.startsWith("/esportal.json"))&&(!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) {
+ currentlog++;
+ JsonObject& apilistlogs = apilog.createNestedObject(String(currentlog));
+ apilistlogs["File Name"]=FileName;
+ }
+ f.close();
+ }
+
+ String API_Response="";
+ if (prettify==1) {
+ apilog.prettyPrintTo(API_Response);
+ }
+ else {
+ apilog.printTo(API_Response);
+ }
+ server.send(200, "application/json", API_Response);
+ delay(50);
+ jsonAPIbuffer.clear();
+}
+
+void apilog(String logfile,int prettify) {
+ File f = SPIFFS.open(String()+"/"+logfile, "r");
+ if (!f) {
+ server.send(200, "application/json", "Log file not found");
+ delay(50);
+ }
+ else {
+ int apiCAPTUREcount=0;
+ while(f.available()) {
+ String line = f.readStringUntil('\n');
+ if(line.indexOf(",Binary:") > 0) {
+ apiCAPTUREcount++;
+ int firstIndex = line.indexOf(",Binary:");
+ int secondIndex = line.indexOf(",", firstIndex + 1);
+ String binaryCaptureLINE=line.substring(firstIndex+8, secondIndex);
+ }
+ }
+ f.close();
+ const size_t bufferSize = JSON_ARRAY_SIZE(6) + JSON_OBJECT_SIZE(4);
+ DynamicJsonBuffer jsonAPIbuffer(bufferSize);
+ JsonObject& apilog = jsonAPIbuffer.createObject();
+
+ apilog["Device"] = "ESP-RFID-Tool";
+ apilog["Firmware"] = version;
+ apilog["API"] = APIversion;
+ apilog["Log File"] = logfile;
+ apilog["Captures"] = apiCAPTUREcount;
+
+ int apiCURRENTcapture=0;
+ File f = SPIFFS.open(String()+"/"+logfile, "r");
+ while(f.available()) {
+ String line = f.readStringUntil('\n');
+
+ if(line.indexOf(",Binary:") > 0) {
+ apiCURRENTcapture++;
+ int firstIndex = line.indexOf(",Binary:");
+ int secondIndex = line.indexOf(",", firstIndex + 1);
+ String binaryCaptureLINE=line.substring(firstIndex+8, secondIndex);
+ if ( binaryCaptureLINE.indexOf(" ") > 0 ) {
+ binaryCaptureLINE=binaryCaptureLINE.substring(binaryCaptureLINE.indexOf(" ")+1);
+ }
+ binaryCaptureLINE.replace("\r","");
+ JsonObject& apiCURRENTcaptureOBJECT = apilog.createNestedObject(String(apiCURRENTcapture));
+ apiCURRENTcaptureOBJECT["Bit Count"]=binaryCaptureLINE.length();
+ apiCURRENTcaptureOBJECT["Binary"]=binaryCaptureLINE;
+ if(line.indexOf(",HEX:") > 0) {
+ int hfirstIndex = line.indexOf(",HEX:");
+ int hsecondIndex = line.indexOf(",", hfirstIndex + 1);
+ String hexCURRENT=line.substring(hfirstIndex+5, hsecondIndex);
+ hexCURRENT.replace("\r","");
+ apiCURRENTcaptureOBJECT["Hexidecimal"]=hexCURRENT;
+ }
+ if(line.indexOf(",Keypad Code:") > 0) {
+ int kfirstIndex = line.indexOf(",Keypad Code:");
+ int ksecondIndex = line.indexOf(",", kfirstIndex + 1);
+ String pinCURRENT=line.substring(kfirstIndex+13, ksecondIndex);
+ pinCURRENT.replace("\r","");
+ apiCURRENTcaptureOBJECT["Keypad Press"]=pinCURRENT;
+ }
+ }
+ }
+ f.close();
+ String API_Response="";
+ if (prettify==1) {
+ apilog.prettyPrintTo(API_Response);
+ }
+ else {
+ apilog.printTo(API_Response);
+ }
+ server.send(200, "application/json", API_Response);
+ delay(50);
+ jsonAPIbuffer.clear();
+ }
+}
diff --git a/Source Code/esprfidtool/api_server.h b/Source Code/esprfidtool/api_server.h
new file mode 100644
index 0000000..0260669
--- /dev/null
+++ b/Source Code/esprfidtool/api_server.h
@@ -0,0 +1,43 @@
+server.on("/api/help", [](){
+ String apihelpHTML=F(
+ "<- BACK TO INDEX
"
+ "/api/info
"
+ "Usage: [server]/api/info
"
+ "/api/viewlog
"
+ "Usage: [server]/api/viewlog?logfile=[log.txt]
"
+ "/api/listlogs
"
+ "Usage: [server]/api/listlogs
"
+ "Optional Arguments
"
+ "Prettify: [api-url]?[args]&prettify=1
"
+ );
+ server.send(200, "text/html", apihelpHTML);
+});
+
+server.on("/api/info", [](){
+ int prettify=0;
+ if (server.hasArg("prettify")) {
+ prettify=1;
+ }
+ apiinfo(prettify);
+});
+
+server.on("/api/listlogs", [](){
+ int prettify=0;
+ if (server.hasArg("prettify")) {
+ prettify=1;
+ }
+ apilistlogs(prettify);
+});
+
+server.on("/api/viewlog", [](){
+ int prettify=0;
+ if (server.hasArg("prettify")) {
+ prettify=1;
+ }
+ if (server.hasArg("logfile")) {
+ apilog(server.arg("logfile"),prettify);
+ }
+ else {
+ server.send(200, "application/json", F("Usage: [server]/api/viewlog?logfile=[logfile.txt]"));
+ }
+});
diff --git a/Source Code/esprfidtool/esprfidtool.ino b/Source Code/esprfidtool/esprfidtool.ino
index a435cd5..f0375dc 100644
--- a/Source Code/esprfidtool/esprfidtool.ino
+++ b/Source Code/esprfidtool/esprfidtool.ino
@@ -56,6 +56,8 @@ DNSServer dnsServer;
HTTPClient http;
+#include "api.h"
+
const char* update_path = "/update";
int accesspointmode;
char ssid[32];
@@ -531,6 +533,9 @@ void LogWiegand(WiegandNG &tempwg) {
f.println("?");
}
}
+ else if (countedBits==248) {
+ f.println(",");
+ }
else {
f.println("");
}
@@ -790,6 +795,8 @@ bool loadDefaults() {
json["safemode"] = "0";
File configFile = SPIFFS.open("/esprfidtool.json", "w");
json.printTo(configFile);
+ configFile.close();
+ jsonBuffer.clear();
loadConfig();
}
@@ -895,7 +902,8 @@ bool loadConfig() {
// Serial.print("IP address = ");
// Serial.println(WiFi.localIP());
}
-
+ configFile.close();
+ jsonBuffer.clear();
return true;
}
@@ -925,6 +933,8 @@ bool saveConfig() {
File configFile = SPIFFS.open("/esprfidtool.json", "w");
json.printTo(configFile);
+ configFile.close();
+ jsonBuffer.clear();
return true;
}
@@ -949,6 +959,7 @@ void ListLogs(){
File f = dir.openFile("r");
FileList += " ";
if((!FileName.startsWith("/payloads/"))&&(!FileName.startsWith("/esploit.json"))&&(!FileName.startsWith("/esportal.json"))&&(!FileName.startsWith("/esprfidtool.json"))&&(!FileName.startsWith("/config.json"))) FileList += "