diff --git a/tasmota/language/af_AF.h b/tasmota/language/af_AF.h index 6d4500990..76b555acb 100644 --- a/tasmota/language/af_AF.h +++ b/tasmota/language/af_AF.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Bestuur lêerstelsel" #define D_FS_SIZE "Grootte" #define D_FS_FREE "Vry" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "versterking:" diff --git a/tasmota/language/bg_BG.h b/tasmota/language/bg_BG.h index d37361752..145448e04 100644 --- a/tasmota/language/bg_BG.h +++ b/tasmota/language/bg_BG.h @@ -915,6 +915,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "усилване:" diff --git a/tasmota/language/cs_CZ.h b/tasmota/language/cs_CZ.h index a4405b404..af7fa2d8b 100644 --- a/tasmota/language/cs_CZ.h +++ b/tasmota/language/cs_CZ.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/de_DE.h b/tasmota/language/de_DE.h index f8831c5ad..a466598c7 100644 --- a/tasmota/language/de_DE.h +++ b/tasmota/language/de_DE.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Verwalte Dateisystem" #define D_FS_SIZE "Größe" #define D_FS_FREE "Frei" +#define D_NEW_FILE "neue-datei.txt" +#define D_CREATE_NEW_FILE "Neue Datei erstellen und bearbeiten" +#define D_EDIT_FILE "Datei bearbeiten" //xsns_67_as3935.ino #define D_AS3935_GAIN "Umgebung:" diff --git a/tasmota/language/el_GR.h b/tasmota/language/el_GR.h index 969718b10..16ad54b6f 100644 --- a/tasmota/language/el_GR.h +++ b/tasmota/language/el_GR.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/en_GB.h b/tasmota/language/en_GB.h index 52dadf8d9..73dacd8a3 100644 --- a/tasmota/language/en_GB.h +++ b/tasmota/language/en_GB.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/es_ES.h b/tasmota/language/es_ES.h index 8487e5e6d..8bcefba0d 100644 --- a/tasmota/language/es_ES.h +++ b/tasmota/language/es_ES.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Explorar Archivos" #define D_FS_SIZE "Tamaño" #define D_FS_FREE "Libre" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "Ganancia:" diff --git a/tasmota/language/fr_FR.h b/tasmota/language/fr_FR.h index 545341bfb..a37dd796d 100644 --- a/tasmota/language/fr_FR.h +++ b/tasmota/language/fr_FR.h @@ -915,6 +915,9 @@ #define D_MANAGE_FILE_SYSTEM "Gestion du Système de Fichier" #define D_FS_SIZE "Taille" #define D_FS_FREE "Libre" +#define D_NEW_FILE "nouveau-fichier.txt" +#define D_CREATE_NEW_FILE "Créer and modifier un nouveau fichier" +#define D_EDIT_FILE "Modification de fichier" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/fy_NL.h b/tasmota/language/fy_NL.h index a3aa1c6fa..5f00102ab 100644 --- a/tasmota/language/fy_NL.h +++ b/tasmota/language/fy_NL.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Bestânbehearder" #define D_FS_SIZE "Grutte" #define D_FS_FREE "Frij" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/he_HE.h b/tasmota/language/he_HE.h index 60c37d543..f25d847eb 100644 --- a/tasmota/language/he_HE.h +++ b/tasmota/language/he_HE.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/hu_HU.h b/tasmota/language/hu_HU.h index 195172128..f4d210a5c 100644 --- a/tasmota/language/hu_HU.h +++ b/tasmota/language/hu_HU.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Fájlrendszer kezelése" #define D_FS_SIZE "Méret" #define D_FS_FREE "Szabad" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "nyereség:" diff --git a/tasmota/language/it_IT.h b/tasmota/language/it_IT.h index 3a5230d0e..f15d873a7 100644 --- a/tasmota/language/it_IT.h +++ b/tasmota/language/it_IT.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Gestione File system" #define D_FS_SIZE "Dimensione" #define D_FS_FREE "Liberi" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "guadagno:" diff --git a/tasmota/language/ko_KO.h b/tasmota/language/ko_KO.h index ca33d2207..ef341444e 100644 --- a/tasmota/language/ko_KO.h +++ b/tasmota/language/ko_KO.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/nl_NL.h b/tasmota/language/nl_NL.h index e90b2db19..667c7ac91 100644 --- a/tasmota/language/nl_NL.h +++ b/tasmota/language/nl_NL.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Bestandsbeheer" #define D_FS_SIZE "Grootte" #define D_FS_FREE "Vrij" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/pl_PL.h b/tasmota/language/pl_PL.h index af6185933..00840c694 100644 --- a/tasmota/language/pl_PL.h +++ b/tasmota/language/pl_PL.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Menadżer plików" #define D_FS_SIZE "Rozmiar" #define D_FS_FREE "Wolne" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "wejście:" diff --git a/tasmota/language/pt_BR.h b/tasmota/language/pt_BR.h index cc05a5552..398d49286 100644 --- a/tasmota/language/pt_BR.h +++ b/tasmota/language/pt_BR.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/pt_PT.h b/tasmota/language/pt_PT.h index 23cd2a44d..d2aeec758 100644 --- a/tasmota/language/pt_PT.h +++ b/tasmota/language/pt_PT.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/ro_RO.h b/tasmota/language/ro_RO.h index 0bcf7674b..d5d9733df 100644 --- a/tasmota/language/ro_RO.h +++ b/tasmota/language/ro_RO.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/ru_RU.h b/tasmota/language/ru_RU.h index f8a33be61..5a4ef6cad 100644 --- a/tasmota/language/ru_RU.h +++ b/tasmota/language/ru_RU.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/sk_SK.h b/tasmota/language/sk_SK.h index 1510a1546..2f4d37a99 100644 --- a/tasmota/language/sk_SK.h +++ b/tasmota/language/sk_SK.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/sv_SE.h b/tasmota/language/sv_SE.h index 7166c6687..a1a2077a2 100644 --- a/tasmota/language/sv_SE.h +++ b/tasmota/language/sv_SE.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/tr_TR.h b/tasmota/language/tr_TR.h index 51b297bb8..dd041c94c 100644 --- a/tasmota/language/tr_TR.h +++ b/tasmota/language/tr_TR.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/uk_UA.h b/tasmota/language/uk_UA.h index 2d3de8097..0b6f967ae 100644 --- a/tasmota/language/uk_UA.h +++ b/tasmota/language/uk_UA.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/vi_VN.h b/tasmota/language/vi_VN.h index 9b8fce166..e47e52952 100644 --- a/tasmota/language/vi_VN.h +++ b/tasmota/language/vi_VN.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "khuếch đại:" diff --git a/tasmota/language/zh_CN.h b/tasmota/language/zh_CN.h index aced421f3..6b5a4c301 100644 --- a/tasmota/language/zh_CN.h +++ b/tasmota/language/zh_CN.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/language/zh_TW.h b/tasmota/language/zh_TW.h index 2c83e5dc0..2a36f65b7 100644 --- a/tasmota/language/zh_TW.h +++ b/tasmota/language/zh_TW.h @@ -916,6 +916,9 @@ #define D_MANAGE_FILE_SYSTEM "Manage File system" #define D_FS_SIZE "Size" #define D_FS_FREE "Free" +#define D_NEW_FILE "newfile.txt" +#define D_CREATE_NEW_FILE "Create and edit new file" +#define D_EDIT_FILE "Edit File" //xsns_67_as3935.ino #define D_AS3935_GAIN "gain:" diff --git a/tasmota/xdrv_50_filesystem.ino b/tasmota/xdrv_50_filesystem.ino index 3a5626cfb..c187df02c 100644 --- a/tasmota/xdrv_50_filesystem.ino +++ b/tasmota/xdrv_50_filesystem.ino @@ -279,7 +279,7 @@ bool TfsFileExists(const char *fname){ bool yes = ffsp->exists(fname); if (!yes) { - AddLog(LOG_LEVEL_DEBUG, PSTR("TFS: File not found")); + AddLog(LOG_LEVEL_DEBUG, PSTR("TFS: File '%s' not found"), fname); } return yes; } @@ -320,7 +320,7 @@ bool TfsLoadFile(const char *fname, uint8_t *buf, uint32_t len) { File file = ffsp->open(fname, "r"); if (!file) { - AddLog(LOG_LEVEL_INFO, PSTR("TFS: File not found")); + AddLog(LOG_LEVEL_INFO, PSTR("TFS: File '%s' not found"), fname); return false; } @@ -564,21 +564,46 @@ const char UFS_FORM_SDC_DIRa[] PROGMEM = const char UFS_FORM_SDC_DIRc[] PROGMEM = ""; const char UFS_FORM_FILE_UPGb[] PROGMEM = +#ifdef GUI_EDIT_FILE + "
" +#endif "" "" " "; const char UFS_FORM_SDC_DIRd[] PROGMEM = "%s"; const char UFS_FORM_SDC_DIRb[] PROGMEM = - "
%s %s %8d %s"; + "
%s %s %8d %s %s"; const char UFS_FORM_SDC_HREF[] PROGMEM = - "http://%_I/ufsd?download=%s/%s"; + "ufsd?download=%s/%s"; + #ifdef GUI_TRASH_FILE const char UFS_FORM_SDC_HREFdel[] PROGMEM = - //"🗑"; - "🔥"; // 🔥 + //"🗑"; // 🗑️ + "🔥"; // 🔥 #endif // GUI_TRASH_FILE +#ifdef GUI_EDIT_FILE + +#define FILE_BUFFER_SIZE 1024 + +const char UFS_FORM_SDC_HREFedit[] PROGMEM = + "📝"; // 📝 + +const char HTTP_EDITOR_FORM_START[] PROGMEM = + ""; + +#endif // #ifdef GUI_EDIT_FILE + void UfsDirectory(void) { if (!HttpCheckPriviledgedAccess()) { return; } @@ -656,7 +681,7 @@ void UfsListDir(char *path, uint8_t depth) { if (dir) { dir.rewindDirectory(); if (strlen(path)>1) { - ext_snprintf_P(npath, sizeof(npath), PSTR("http://%_I/ufsd?download=%s"), (uint32_t)WiFi.localIP(), path); + ext_snprintf_P(npath, sizeof(npath), PSTR("ufsd?download=%s"), path); for (uint32_t cnt = strlen(npath) - 1; cnt > 0; cnt--) { if (npath[cnt] == '/') { if (npath[cnt - 1] == '=') { @@ -698,7 +723,7 @@ void UfsListDir(char *path, uint8_t depth) { sprintf(cp, format, ep); if (entry.isDirectory()) { - ext_snprintf_P(npath, sizeof(npath), UFS_FORM_SDC_HREF, (uint32_t)WiFi.localIP(), pp, ep); + ext_snprintf_P(npath, sizeof(npath), UFS_FORM_SDC_HREF, pp, ep); WSContentSend_P(UFS_FORM_SDC_DIRd, npath, ep, name); uint8_t plen = strlen(path); if (plen > 1) { @@ -710,13 +735,20 @@ void UfsListDir(char *path, uint8_t depth) { } else { #ifdef GUI_TRASH_FILE char delpath[128]; - ext_snprintf_P(delpath, sizeof(delpath), UFS_FORM_SDC_HREFdel, (uint32_t)WiFi.localIP(), pp, ep); + ext_snprintf_P(delpath, sizeof(delpath), UFS_FORM_SDC_HREFdel, pp, ep); #else char delpath[2]; delpath[0]=0; #endif // GUI_TRASH_FILE - ext_snprintf_P(npath, sizeof(npath), UFS_FORM_SDC_HREF, (uint32_t)WiFi.localIP(), pp, ep); - WSContentSend_P(UFS_FORM_SDC_DIRb, npath, ep, name, tstr.c_str(), entry.size(), delpath); +#ifdef GUI_EDIT_FILE + char editpath[128]; + ext_snprintf_P(editpath, sizeof(editpath), UFS_FORM_SDC_HREFedit, pp, ep); +#else + char editpath[2]; + editpath[0]=0; +#endif // GUI_TRASH_FILE + ext_snprintf_P(npath, sizeof(npath), UFS_FORM_SDC_HREF, pp, ep); + WSContentSend_P(UFS_FORM_SDC_DIRb, npath, ep, name, tstr.c_str(), entry.size(), delpath, editpath); } } entry.close(); @@ -733,13 +765,13 @@ uint8_t UfsDownloadFile(char *file) { File download_file; if (!dfsp->exists(file)) { - AddLog(LOG_LEVEL_INFO, PSTR("UFS: File not found")); + AddLog(LOG_LEVEL_INFO, PSTR("UFS: File '%s' not found"), file); return 0; } download_file = dfsp->open(file, UFS_FILE_READ); if (!download_file) { - AddLog(LOG_LEVEL_INFO, PSTR("UFS: Could not open file")); + AddLog(LOG_LEVEL_INFO, PSTR("UFS: Could not open file '%s'"), file); return 0; } @@ -877,6 +909,117 @@ void UfsUploadFileClose(void) { ufs_upload_file.close(); } + +//****************************************************************************************** +// File Editor +//****************************************************************************************** + +#ifdef GUI_EDIT_FILE + +void UfsEditor(void) { + if (!HttpCheckPriviledgedAccess()) { return; } + + AddLog(LOG_LEVEL_DEBUG, PSTR("UFS: UfsEditor GET")); + + String fname; + if (Webserver->hasArg(F("file"))) { + fname = Webserver->arg(F("file")); + } + else { + fname = D_NEW_FILE; + } + if (fname[0] != '/') fname = "/" +fname; + + AddLog(LOG_LEVEL_DEBUG, PSTR("UFS: UfsEditor: file=%s, ffs_type=%d, TfsFileExist=%d"), fname.c_str(), ffs_type, TfsFileExists(fname.c_str())); + + WSContentStart_P(PSTR(D_EDIT_FILE)); + WSContentSendStyle(); + WSContentSend_P(HTTP_EDITOR_FORM_START, fname.c_str()); + + if (ffs_type && TfsFileExists(fname.c_str())) { + File fp = ffsp->open(fname.c_str(), "r"); + if (!fp) { + AddLog(LOG_LEVEL_DEBUG, PSTR("UFS: UfsEditor: file open failed")); + WSContentSend_P(D_NEW_FILE); + } + else { + uint8_t *buf = (uint8_t*)malloc(FILE_BUFFER_SIZE+1); + size_t filelen = fp.size(); + AddLog(LOG_LEVEL_DEBUG, PSTR("UFS: UfsEditor: file len=%d"), filelen); + while ( filelen > 0 ) { + size_t l = fp.read(buf, FILE_BUFFER_SIZE); + AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("UFS: UfsEditor: read=%d"), l); + if (l < 0) break; + buf[l] = '\0'; + WSContentSend_P((const char*)buf); + filelen -= l; + } + fp.close(); + free(buf); + AddLog(LOG_LEVEL_DEBUG, PSTR("UFS: UfsEditor: read done")); + } + } + else { + WSContentSend_P(D_NEW_FILE); + } + + WSContentSend_P(HTTP_EDITOR_FORM_END); + WSContentSend_P(UFS_WEB_DIR, PSTR(D_MANAGE_FILE_SYSTEM)); + WSContentStop(); +} + +void UfsEditorUpload(void) { + AddLog(LOG_LEVEL_DEBUG, PSTR("UFS: UfsEditor: file upload")); + + if (!HttpCheckPriviledgedAccess()) { return; } + + if (!Webserver->hasArg("name")) { + AddLog(LOG_LEVEL_ERROR, PSTR("UFS: UfsEditor: file upload - no filename")); + WSSend(400, CT_PLAIN, F("400: Bad request - no filename")); + return; + } + String name = Webserver->arg("name"); + AddLog(LOG_LEVEL_DEBUG, PSTR("UFS: UfsEditor: file '%s'"), name.c_str()); + + if (!Webserver->hasArg("content")) { + AddLog(LOG_LEVEL_ERROR, PSTR("UFS: UfsEditor: file upload - no content")); + WSSend(400, CT_PLAIN, F("400: Bad request - no content")); + return; + } + String content = Webserver->arg("content"); + + if (!ffsp) { + Web.upload_error = 1; + AddLog(LOG_LEVEL_ERROR, PSTR("UFS: UfsEditor: 507: no storage available")); + WSSend(507, CT_PLAIN, F("507: no storage available")); + return; + } + + File fp = ffsp->open(name.c_str(), "w"); + if(!fp) { + Web.upload_error = 1; + AddLog(LOG_LEVEL_ERROR, PSTR("UFS: UfsEditor: 400: invalid file name '%s'"), name.c_str()); + WSSend(400, CT_PLAIN, F("400: bad request - invalid filename")); + return; + } + + if (*content.c_str()) { + content.replace("\r\n", "\n"); + content.replace("\r", "\n"); + } + + if (!fp.print(content)) { + AddLog(LOG_LEVEL_ERROR, PSTR("UFS: UfsEditor: write error on '%s'"), name.c_str()); + } + + fp.close(); + + Webserver->sendHeader(F("Location"),F("/ufsu")); + Webserver->send(303); +} + +#endif // #ifdef GUI_EDIT_FILE + #endif // USE_WEBSERVER /*********************************************************************************************\ @@ -916,6 +1059,10 @@ bool Xdrv50(uint8_t function) { Webserver->on("/ufsd", UfsDirectory); Webserver->on("/ufsu", HTTP_GET, UfsDirectory); Webserver->on("/ufsu", HTTP_POST,[](){Webserver->sendHeader(F("Location"),F("/ufsu"));Webserver->send(303);}, HandleUploadLoop); +#ifdef GUI_EDIT_FILE + Webserver->on("/ufse", HTTP_GET, UfsEditor); + Webserver->on("/ufse", HTTP_POST, UfsEditorUpload); +#endif break; #endif // USE_WEBSERVER }