-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd12869
commit a67d0dd
Showing
5 changed files
with
236 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
server.on("/api/help", [](){ | ||
String apihelpHTML=F( | ||
"<a href=\"/\"><- BACK TO INDEX</a><br><br>" | ||
"<b>/api/info</b><br>" | ||
"<small>Usage: [server]/api/info</small><br>" | ||
"<b>/api/viewlog</b><br>" | ||
"<small>Usage: [server]/api/viewlog?logfile=[log.txt]</small><br>" | ||
"<b>/api/listlogs</b><br>" | ||
"<small>Usage: [server]/api/listlogs</small><br>" | ||
"<b>Optional Arguments</b><br>" | ||
"<small>Prettify: [api-url]?[args]<u>&prettify=1</u></small><br>" | ||
); | ||
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]")); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
void pinSEND(int pinDELAY,String pinBIN) { | ||
for (int i=0; i<=pinBIN.length(); i++) { | ||
if (pinBIN.charAt(i) == '0') { | ||
digitalWrite(DATA0, LOW); | ||
delayMicroseconds(txdelayus); | ||
digitalWrite(DATA0, HIGH); | ||
} | ||
else if (pinBIN.charAt(i) == '1') { | ||
digitalWrite(DATA1, LOW); | ||
delayMicroseconds(txdelayus); | ||
digitalWrite(DATA1, HIGH); | ||
} | ||
delay(txdelayms); | ||
} | ||
yield(); | ||
delay(pinDELAY); | ||
pinBIN=""; | ||
pinDELAY=100; | ||
} | ||
void pinSEND(int pinDELAY,String pinBIN) { | ||
for (int i=0; i<=pinBIN.length(); i++) { | ||
if (pinBIN.charAt(i) == '0') { | ||
digitalWrite(DATA0, LOW); | ||
delayMicroseconds(txdelayus); | ||
digitalWrite(DATA0, HIGH); | ||
} | ||
else if (pinBIN.charAt(i) == '1') { | ||
digitalWrite(DATA1, LOW); | ||
delayMicroseconds(txdelayus); | ||
digitalWrite(DATA1, HIGH); | ||
} | ||
delay(txdelayms); | ||
} | ||
yield(); | ||
delay(pinDELAY); | ||
pinBIN=""; | ||
pinDELAY=100; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
String version = "1.1.5"; | ||
String version = "1.1.6"; | ||
String APIversion = "1.0.0"; |