mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2026-01-27 12:50:39 +03:00
test5
This commit is contained in:
@@ -368,15 +368,8 @@ std::string decrypt_pw_string(std::string toDecrypt)
|
||||
// Checks if all passwords on the SD are encrypted and if they are not encrypted, it encrypts them.
|
||||
esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename)
|
||||
{
|
||||
std::string line = "";
|
||||
|
||||
std::vector<std::string> splitted;
|
||||
std::vector<std::string> temp_file;
|
||||
|
||||
all_pw_were_encrypted = false;
|
||||
|
||||
std::string fn = format_filename(filename);
|
||||
FILE *pFile = fopen(fn.c_str(), "r");
|
||||
std::string _filename = format_filename(filename);
|
||||
FILE *pFile = fopen(_filename.c_str(), "r");
|
||||
|
||||
if (pFile == NULL)
|
||||
{
|
||||
@@ -387,6 +380,7 @@ esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename)
|
||||
|
||||
ESP_LOGD(TAG, "EncryptDecryptConfigPwOnSD: config.ini opened");
|
||||
|
||||
std::string line = "";
|
||||
char temp_line[256];
|
||||
|
||||
if (fgets(temp_line, sizeof(temp_line), pFile) == NULL)
|
||||
@@ -401,6 +395,11 @@ esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename)
|
||||
line = std::string(temp_line);
|
||||
}
|
||||
|
||||
all_pw_were_encrypted = false;
|
||||
|
||||
std::vector<std::string> splitted;
|
||||
std::vector<std::string> temp_file;
|
||||
|
||||
if (_encrypt)
|
||||
{
|
||||
while ((line.size() > 0) || !(feof(pFile)))
|
||||
@@ -425,7 +424,7 @@ esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename)
|
||||
line = "apikey = " + encrypt_pw_string(splitted[1]) + "\n";
|
||||
}
|
||||
}
|
||||
else if (filename == NETWORK_CONFIG_FILE)
|
||||
else if ((filename == WLAN_CONFIG_FILE) || (filename == NETWORK_CONFIG_FILE))
|
||||
{
|
||||
if (_param == "PASSWORD")
|
||||
{
|
||||
@@ -474,7 +473,7 @@ esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename)
|
||||
line = "apikey = " + decrypt_pw_string(splitted[1]) + "\n";
|
||||
}
|
||||
}
|
||||
else if (filename == NETWORK_CONFIG_FILE)
|
||||
else if ((filename == WLAN_CONFIG_FILE) || (filename == NETWORK_CONFIG_FILE))
|
||||
{
|
||||
if (_param == "PASSWORD")
|
||||
{
|
||||
@@ -505,7 +504,7 @@ esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename)
|
||||
// Only write to the SD if not all passwords are encrypted
|
||||
if ((all_pw_were_encrypted == false && _encrypt == true) || (all_pw_were_encrypted == true && _encrypt == false))
|
||||
{
|
||||
pFile = fopen(fn.c_str(), "w+");
|
||||
pFile = fopen(_filename.c_str(), "w+");
|
||||
|
||||
if (pFile == NULL)
|
||||
{
|
||||
@@ -1140,16 +1139,16 @@ size_t find_delimiter_pos(string input, string delimiter)
|
||||
bool rename_file(string from, string to)
|
||||
{
|
||||
// ESP_LOGI(logTag, "Renaming File: %s", from.c_str());
|
||||
FILE *fpSourceFile = fopen(from.c_str(), "rb");
|
||||
FILE *pFile = fopen(from.c_str(), "rb");
|
||||
|
||||
// Sourcefile does not exist otherwise there is a mistake when renaming!
|
||||
if (!fpSourceFile)
|
||||
if (!pFile)
|
||||
{
|
||||
ESP_LOGE(TAG, "RenameFile: File %s does not exist!", from.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
fclose(fpSourceFile);
|
||||
fclose(pFile);
|
||||
rename(from.c_str(), to.c_str());
|
||||
|
||||
return true;
|
||||
@@ -1175,15 +1174,15 @@ bool rename_folder(string from, string to)
|
||||
|
||||
bool file_exists(string filename)
|
||||
{
|
||||
FILE *fpSourceFile = fopen(filename.c_str(), "rb");
|
||||
FILE *pFile = fopen(filename.c_str(), "rb");
|
||||
|
||||
// Sourcefile does not exist
|
||||
if (!fpSourceFile)
|
||||
if (!pFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
fclose(fpSourceFile);
|
||||
fclose(pFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1207,16 +1206,16 @@ bool delete_file(string filename)
|
||||
{
|
||||
// ESP_LOGI(logTag, "Deleting file: %s", filename.c_str());
|
||||
/* Delete file */
|
||||
FILE *fpSourceFile = fopen(filename.c_str(), "rb");
|
||||
FILE *pFile = fopen(filename.c_str(), "rb");
|
||||
|
||||
// Sourcefile does not exist otherwise there is a mistake in copying!
|
||||
if (!fpSourceFile)
|
||||
if (!pFile)
|
||||
{
|
||||
ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
fclose(fpSourceFile);
|
||||
fclose(pFile);
|
||||
unlink(filename.c_str());
|
||||
|
||||
return true;
|
||||
@@ -1227,13 +1226,12 @@ bool copy_file(string input, string output)
|
||||
input = format_filename(input);
|
||||
output = format_filename(output);
|
||||
|
||||
if (to_upper(input).compare(NETWORK_CONFIG_FILE) == 0)
|
||||
if ((to_upper(input).compare(WLAN_CONFIG_FILE) == 0) || (to_upper(input).compare(NETWORK_CONFIG_FILE) == 0))
|
||||
{
|
||||
ESP_LOGD(TAG, "wlan.ini kann nicht kopiert werden!");
|
||||
return false;
|
||||
}
|
||||
|
||||
char cTemp;
|
||||
FILE *fpSourceFile = fopen(input.c_str(), "rb");
|
||||
|
||||
// Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
|
||||
@@ -1245,18 +1243,19 @@ bool copy_file(string input, string output)
|
||||
|
||||
FILE *fpTargetFile = fopen(output.c_str(), "wb");
|
||||
|
||||
// Code Section
|
||||
char temp_char[1024];
|
||||
|
||||
// Read From The Source File - "Copy"
|
||||
while (fread(&cTemp, 1, 1, fpSourceFile) == 1)
|
||||
while (fread(&temp_char, 1, 1, fpSourceFile) == 1)
|
||||
{
|
||||
// Write To The Target File - "Paste"
|
||||
fwrite(&cTemp, 1, 1, fpTargetFile);
|
||||
fwrite(&temp_char, 1, 1, fpTargetFile);
|
||||
}
|
||||
|
||||
// Close The Files
|
||||
fclose(fpSourceFile);
|
||||
fclose(fpTargetFile);
|
||||
|
||||
ESP_LOGD(TAG, "File copied: %s to %s", input.c_str(), output.c_str());
|
||||
|
||||
return true;
|
||||
@@ -1466,7 +1465,6 @@ string round_output(double _in, int _anzNachkomma)
|
||||
{
|
||||
std::stringstream stream;
|
||||
int temp_value = _in;
|
||||
// ESP_LOGD(TAG, "AnzNachkomma: %d", _anzNachkomma);
|
||||
|
||||
if (_anzNachkomma > 0)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "esp_rom_crc.h"
|
||||
#include "esp_rom_crc.h"
|
||||
#include "ClassLogFile.h"
|
||||
|
||||
static const char *TAG = "SDCARD";
|
||||
@@ -15,52 +15,60 @@ static const char *TAG = "SDCARD";
|
||||
int SDCardCheckRW(void)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Basic R/W check started...");
|
||||
FILE* pFile = NULL;
|
||||
int iCRCMessage = 0;
|
||||
|
||||
pFile = fopen("/sdcard/sdcheck.txt","w");
|
||||
if (pFile == NULL) {
|
||||
|
||||
FILE *pFile = fopen("/sdcard/sdcheck.txt", "w");
|
||||
if (pFile == NULL)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Basic R/W check: (E1) No able to open file to write");
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string sMessage = "This message is used for a SD-Card basic check!";
|
||||
iCRCMessage = esp_rom_crc16_le(0, (uint8_t*)sMessage.c_str(), sMessage.length());
|
||||
if (fwrite(sMessage.c_str(), sMessage.length(), 1, pFile) == 0 ) {
|
||||
iCRCMessage = esp_rom_crc16_le(0, (uint8_t *)sMessage.c_str(), sMessage.length());
|
||||
if (fwrite(sMessage.c_str(), sMessage.length(), 1, pFile) == 0)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Basic R/W check: (E2) Not able to write file");
|
||||
fclose(pFile);
|
||||
unlink("/sdcard/sdcheck.txt");
|
||||
return -2;
|
||||
}
|
||||
fclose(pFile);
|
||||
fclose(pFile);
|
||||
}
|
||||
|
||||
pFile = fopen("/sdcard/sdcheck.txt","r");
|
||||
if (pFile == NULL) {
|
||||
pFile = fopen("/sdcard/sdcheck.txt", "r");
|
||||
if (pFile == NULL)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Basic R/W check: (E3) Not able to open file to read back");
|
||||
unlink("/sdcard/sdcheck.txt");
|
||||
return -3;
|
||||
}
|
||||
else {
|
||||
}
|
||||
else
|
||||
{
|
||||
char cReadBuf[50];
|
||||
if (fgets(cReadBuf, sizeof(cReadBuf), pFile) == 0) {
|
||||
if (fgets(cReadBuf, sizeof(cReadBuf), pFile) == 0)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Basic R/W check: (E4) Not able to read file back");
|
||||
fclose(pFile);
|
||||
unlink("/sdcard/sdcheck.txt");
|
||||
return -4;
|
||||
}
|
||||
else {
|
||||
if (esp_rom_crc16_le(0, (uint8_t*)cReadBuf, strlen(cReadBuf)) != iCRCMessage) {
|
||||
else
|
||||
{
|
||||
if (esp_rom_crc16_le(0, (uint8_t *)cReadBuf, strlen(cReadBuf)) != iCRCMessage)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Basic R/W check: (E5) Read back, but wrong CRC");
|
||||
fclose(pFile);
|
||||
unlink("/sdcard/sdcheck.txt");
|
||||
return -5;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(pFile);
|
||||
}
|
||||
|
||||
if (unlink("/sdcard/sdcheck.txt") != 0) {
|
||||
if (unlink("/sdcard/sdcheck.txt") != 0)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Basic R/W check: (E6) Unable to delete the file");
|
||||
return -6;
|
||||
}
|
||||
@@ -76,86 +84,135 @@ bool SDCardCheckFolderFilePresence()
|
||||
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Folder/file presence check started...");
|
||||
/* check if folder exists: config */
|
||||
if (stat("/sdcard/config", &sb) != 0) {
|
||||
if (stat("/sdcard/config", &sb) != 0)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: Folder /config not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if folder exists: html */
|
||||
if (stat("/sdcard/html", &sb) != 0) {
|
||||
if (stat("/sdcard/html", &sb) != 0)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: Folder /html not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if folder exists: firmware */
|
||||
if (stat("/sdcard/firmware", &sb) != 0) {
|
||||
if (stat("/sdcard/firmware", &sb) != 0)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: Folder /firmware not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if folder exists: img_tmp */
|
||||
if (stat("/sdcard/img_tmp", &sb) != 0) {
|
||||
if (stat("/sdcard/img_tmp", &sb) != 0)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: Folder /img_tmp not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if folder exists: log */
|
||||
if (stat("/sdcard/log", &sb) != 0) {
|
||||
if (stat("/sdcard/log", &sb) != 0)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: Folder /log not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if folder exists: demo */
|
||||
if (stat("/sdcard/demo", &sb) != 0) {
|
||||
if (stat("/sdcard/demo", &sb) != 0)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: Folder /demo not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if file exists: wlan.ini */
|
||||
if (stat("/sdcard/wlan.ini", &sb) != 0) {
|
||||
if ((stat("/sdcard/wlan.ini", &sb) != 0) && (stat("/sdcard/network.ini", &sb) != 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /wlan.ini not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if file exists: config.ini */
|
||||
if (stat("/sdcard/config/config.ini", &sb) != 0) {
|
||||
if (stat("/sdcard/config/config.ini", &sb) != 0)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /config/config.ini not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if file exists: index.html */
|
||||
if ((stat("/sdcard/html/index.html", &sb) != 0) && (stat("/sdcard/html/index.html.gz", &sb) != 0)) {
|
||||
if ((stat("/sdcard/html/index.html", &sb) != 0) && (stat("/sdcard/html/index.html.gz", &sb) != 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/index.html not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if file exists: overview.html */
|
||||
if ((stat("/sdcard/html/overview.html", &sb) != 0) && (stat("/sdcard/html/overview.html.gz", &sb) != 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/overview.html not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if file exists: ota.html */
|
||||
if ((stat("/sdcard/html/ota_page.html", &sb) != 0) && (stat("/sdcard/html/ota_page.html.gz", &sb) != 0)) {
|
||||
if ((stat("/sdcard/html/ota_page.html", &sb) != 0) && (stat("/sdcard/html/ota_page.html.gz", &sb) != 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/ota.html not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if file exists: log.html */
|
||||
if ((stat("/sdcard/html/log.html", &sb) != 0) && (stat("/sdcard/html/log.html.gz", &sb) != 0)) {
|
||||
if ((stat("/sdcard/html/log.html", &sb) != 0) && (stat("/sdcard/html/log.html.gz", &sb) != 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/log.html not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if file exists: common.js */
|
||||
if ((stat("/sdcard/html/common.js", &sb) != 0) && (stat("/sdcard/html/common.js.gz", &sb) != 0)) {
|
||||
if ((stat("/sdcard/html/common.js", &sb) != 0) && (stat("/sdcard/html/common.js.gz", &sb) != 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/common.js not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if file exists: version.txt */
|
||||
if (stat("/sdcard/html/version.txt", &sb) != 0) {
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/version.txt not found");
|
||||
/* check if file exists: readconfigcommon.js */
|
||||
if ((stat("/sdcard/html/readconfigcommon.js", &sb) != 0) && (stat("/sdcard/html/readconfigcommon.js.gz", &sb) != 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/readconfigcommon.js not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
if (bRetval) {
|
||||
/* check if file exists: readconfigparam.js */
|
||||
if ((stat("/sdcard/html/readconfigparam.js", &sb) != 0) && (stat("/sdcard/html/readconfigparam.js.gz", &sb) != 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/readconfigparam.js not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if file exists: jquery-3.6.0.min.js */
|
||||
if ((stat("/sdcard/html/jquery-3.6.0.min.js", &sb) != 0) && (stat("/sdcard/html/jquery-3.6.0.min.js.gz", &sb) != 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/jquery-3.6.0.min.js not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if file exists: firework.js */
|
||||
if ((stat("/sdcard/html/firework.js", &sb) != 0) && (stat("/sdcard/html/firework.js.gz", &sb) != 0))
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/firework.js not found");
|
||||
bRetval = false;
|
||||
}
|
||||
|
||||
/* check if file exists: version.txt */
|
||||
if (stat("/sdcard/html/version.txt", &sb) != 0)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Folder/file check: File /html/version.txt not found");
|
||||
// bRetval = false;
|
||||
}
|
||||
|
||||
if (bRetval)
|
||||
{
|
||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Folder/file presence check successful");
|
||||
}
|
||||
|
||||
|
||||
return bRetval;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user