Skip to content

Commit

Permalink
fix Command cat
Browse files Browse the repository at this point in the history
  • Loading branch information
wangqinghua committed Jun 20, 2021
1 parent a3db859 commit d851718
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
16 changes: 6 additions & 10 deletions remote_payloads_cli/remote_payloads_cli.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//#define DEBUG;
String username = "wangqinghua";
String password = "4dcc4173d80a2817206e196a38f0dbf7850188ff"; // sha1 of password "hacker"
String hidenDir = "wangqinghua/"; //url including hidenDir is forbidden to browser but accessible to CLI
String hiddenDir = "wangqinghua/"; //url including hidenDir is forbidden to browser but accessible to CLI
//-----config-end-----//
ESP8266WiFiMulti wifier; // 建立ESP8266WiFiMulti对象,对象名称是 'wifier'
ESP8266WebServer shell(80); // 建立cli服务器对象shell,该对象用于响应cli请求。监听端口(80)
Expand Down Expand Up @@ -164,7 +164,7 @@ void handleLogs() {
logs += shell.argName(i) + ": " + shell.arg(i) + "\n";
}
logs += "\n";
File logFile = SPIFFS.open("/payloads/logs", "a");
File logFile = SPIFFS.open("/" + hiddenDir + "logs", "a");
logFile.println(logs);
logFile.close();
if (toUrl) {
Expand All @@ -179,7 +179,7 @@ void handleList() {
String dirList = "<html><head><meta charset=\"UTF-8\"><title>remote payloads</title></head>";
dirList += "<body><center><h1>ESP8266 SPIFFS Remote Payloads</h1><hr/>";
while (dir.next()) {
if (dir.fileName().indexOf(hidenDir) < 0) {
if (dir.fileName().indexOf(hiddenDir) < 0) {
dirList += "<a href=\"" + dir.fileName() + "\">" + dir.fileName() + "</a><br/>";
}
}
Expand Down Expand Up @@ -236,12 +236,8 @@ void _ls(String dir) {

void _cat(String filePath) {
File dataFile = SPIFFS.open(filePath, "r");
String data = "";
for (int i = 0; i < dataFile.size(); i++) {
data += (char)dataFile.read();
}
dataFile.close();
shell.send(200, "text/plain", data);
shell.streamFile(dataFile, "text/plain");
dataFile.close();
}

void _rm(String filePath) {
Expand Down Expand Up @@ -345,7 +341,7 @@ bool handler() {
return false;
}
// 黑名单认证
if (webAddress.indexOf(hidenDir) > 0) {
if (webAddress.indexOf(hiddenDir) > 0) {
if (!cookieNow) {
shell.send(403, "text/plain", "no cookie!");
return false;
Expand Down
15 changes: 7 additions & 8 deletions remote_payloads_sd_cli/remote_payloads_sd_cli.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//#define TIME; // remove comment if you want to know date of each file
String username = "wangqinghua";
String password = "4dcc4173d80a2817206e196a38f0dbf7850188ff"; // sha1 of password "hacker"
String hidenDir = "wangqinghua/"; //url including hidenDir is forbidden to browser but accessible to CLI
String hiddenDir = "wangqinghua/"; //url including hidenDir is forbidden to browser but accessible to CLI
//-----config-end-----//
ESP8266WiFiMulti wifier; // 建立ESP8266WiFiMulti对象,对象名称是 'wifier'
ESP8266WebServer shell(80);
Expand Down Expand Up @@ -138,7 +138,7 @@ void handleLogs() {
for (int i = 0; i < shell.args(); i++) {
logs += shell.argName(i) + ": " + shell.arg(i) + "\n";
}
File logFile = SD.open("/payloads/logs", FILE_WRITE);
File logFile = SD.open("/" + hiddenDir + "logs", FILE_WRITE);
logFile.println(logs);
logFile.close();
if (toUrl) {
Expand Down Expand Up @@ -166,6 +166,9 @@ void deviation(struct tm * tmstruct, int* year, int* month, int* day, int* hour,

void printDirectory(File dir, String dirPath, int numTabs, String* result, bool html) {
while (true) {
if ((html) && (dirPath.indexOf(hiddenDir))) {
break;
}
File entry = dir.openNextFile();
if (!entry) {
break;
Expand Down Expand Up @@ -269,12 +272,8 @@ void _ls(String dirPath) {

void _cat(String filePath) {
File dataFile = SD.open(filePath, FILE_READ);
String data = "";
for (int i = 0; i < dataFile.size(); i++) {
data += (char)dataFile.read();
}
dataFile.close();
shell.send(200, "text/plain", data);
shell.streamFile(dataFile, "text/plain");
dataFile.close();
}

void rmDir(String filePath) {
Expand Down

0 comments on commit d851718

Please sign in to comment.