From c0bd58d40cb50a03fbcc3bbc130b86e28737c4fc Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Thu, 22 Feb 2024 05:02:14 +0100 Subject: [PATCH 01/22] Added WebServer/WebServices for Native Linux Meshtastic and web gui --- .gitignore | 4 + .vscode/extensions.json | 9 +- .vscode/settings.json | 72 +++- Dockerfile | 2 +- arch/portduino/portduino.ini | 2 +- bin/config-dist.yaml | 4 + bin/prepare-native.sh | 2 + platformio.ini | 6 +- src/main.cpp | 2 + src/mesh/http/ContentHandler.cpp | 2 + src/mesh/http/ContentHandler.h | 4 +- src/mesh/http/ContentHelper.cpp | 2 + src/mesh/http/PiWebServer.cpp | 527 +++++++++++++++++++++++ src/mesh/http/PiWebServer.h | 58 +++ src/mesh/http/WebServer.cpp | 4 +- src/mesh/http/WebServer.h | 2 + src/platform/portduino/PortduinoGlue.cpp | 5 + src/platform/portduino/PortduinoGlue.h | 5 +- variants/portduino/platformio.ini | 2 +- 19 files changed, 700 insertions(+), 14 deletions(-) create mode 100755 bin/prepare-native.sh create mode 100644 src/mesh/http/PiWebServer.cpp create mode 100644 src/mesh/http/PiWebServer.h diff --git a/.gitignore b/.gitignore index 89f8ee065e..2471fa68f1 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,7 @@ venv/ release/ .vscode/extensions.json /compile_commands.json +src/mesh/http/certificate.pem +src/mesh/http/private_key.pem +arch/portduino/portduino.ini +.vscode/extensions.json \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 783791f0ba..080e70d08b 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,8 +2,9 @@ // See http://go.microsoft.com/fwlink/?LinkId=827846 // for the documentation about the extensions.json format "recommendations": [ - "ms-vscode.cpptools", - "platformio.platformio-ide", - "trunk.io" + "platformio.platformio-ide" ], -} \ No newline at end of file + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 03922dc72b..679c99dc83 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,75 @@ { "editor.formatOnSave": true, "editor.defaultFormatter": "trunk.io", - "trunk.enableWindows": true + "trunk.enableWindows": true, + "files.associations": { + "string": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "strstream": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "chrono": "cpp", + "compare": "cpp", + "complex": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp", + "variant": "cpp" + } } diff --git a/Dockerfile b/Dockerfile index 21e42ad876..ff0624f37f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Install build deps USER root RUN apt-get update && \ - apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev + apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev libgpiod2 # create a non-priveleged user & group RUN groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 mesh diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index 0dcc9afc21..c88bde2616 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -11,7 +11,7 @@ build_src_filter = - - - - - + + - - - diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index b5b105e4c2..5f5a3b1bf3 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -117,3 +117,7 @@ Input: Logging: LogLevel: info # debug, info, warn, error + +Webserver: + Port: 9001 # Port for Webserver & Webservices + RootPath: /home/user/web # Root Dir of WebServer diff --git a/bin/prepare-native.sh b/bin/prepare-native.sh new file mode 100755 index 0000000000..570739ff51 --- /dev/null +++ b/bin/prepare-native.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +sudo apt -y install openssl libssl-dev libsdl2-dev libulfius-dev liborcania-dev diff --git a/platformio.ini b/platformio.ini index 0033b6e469..21536ac18a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2,7 +2,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = tbeam +;default_envs = tbeam ;default_envs = pico ;default_envs = tbeam-s3-core ;default_envs = tbeam0.7 @@ -21,7 +21,7 @@ default_envs = tbeam ;default_envs = t-echo ;default_envs = canaryone ;default_envs = nrf52840dk-geeksville -;default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here +default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here ;default_envs = nano-g1 ;default_envs = pca10059_diy_eink ;default_envs = meshtastic-diy-v1 @@ -129,4 +129,4 @@ lib_deps = adafruit/Adafruit PM25 AQI Sensor@^1.0.6 adafruit/Adafruit MPU6050@^2.2.4 adafruit/Adafruit LIS3DH@^1.2.4 - https://github.com/lewisxhe/BMA423_Library@^0.0.1 + https://github.com/lewisxhe/BMA423_Library@^0.0.1 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 2af912d15b..8666192323 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,6 +68,7 @@ NRF52Bluetooth *nrf52Bluetooth; #ifdef ARCH_PORTDUINO #include "linux/LinuxHardwareI2C.h" +#include "mesh/http/PiWebServer.h" #include "platform/portduino/PortduinoGlue.h" #include #include @@ -906,6 +907,7 @@ void setup() #endif #ifdef ARCH_PORTDUINO + piwebServerThread = new PiWebServerThread(); initApiServer(TCPPort); #endif diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index 7640e879c9..986b26dd95 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -1,3 +1,4 @@ +#ifndef PORTDUINO_LINUX_HARDWARE #include "NodeDB.h" #include "PowerFSM.h" #include "RadioLibInterface.h" @@ -855,3 +856,4 @@ void handleScanNetworks(HTTPRequest *req, HTTPResponse *res) res->print(value->Stringify().c_str()); delete value; } +#endif \ No newline at end of file diff --git a/src/mesh/http/ContentHandler.h b/src/mesh/http/ContentHandler.h index 987e3ffef9..ba900e18fd 100644 --- a/src/mesh/http/ContentHandler.h +++ b/src/mesh/http/ContentHandler.h @@ -1,3 +1,4 @@ +#ifndef PORTDUINO_LINUX_HARDWARE #pragma once void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer); @@ -33,4 +34,5 @@ class HttpAPI : public PhoneAPI protected: /// Check the current underlying physical link to see if the client is currently connected virtual bool checkIsConnected() override { return true; } // FIXME, be smarter about this -}; \ No newline at end of file +}; +#endif \ No newline at end of file diff --git a/src/mesh/http/ContentHelper.cpp b/src/mesh/http/ContentHelper.cpp index 8f283932b6..02660a7e95 100644 --- a/src/mesh/http/ContentHelper.cpp +++ b/src/mesh/http/ContentHelper.cpp @@ -1,3 +1,4 @@ +#ifndef PORTDUINO_LINUX_HARDWARE #include "mesh/http/ContentHelper.h" // #include // #include "main.h" @@ -12,3 +13,4 @@ void replaceAll(std::string &str, const std::string &from, const std::string &to start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx' } } +#endif \ No newline at end of file diff --git a/src/mesh/http/PiWebServer.cpp b/src/mesh/http/PiWebServer.cpp new file mode 100644 index 0000000000..be6d72db4d --- /dev/null +++ b/src/mesh/http/PiWebServer.cpp @@ -0,0 +1,527 @@ +/* +Adds a WebServer and WebService callbacks to meshtastic as Linux Version. The WebServer & Webservices +runs in a real linux thread beside the portdunio threading emulation. It replaces the complete ESP32 +Webserver libs including generation of SSL certifcicates, because the use ESP specific details in +the lib that can't be emulated. + +The WebServices adapt to the two major phoneapi functions "handleAPIv1FromRadio,handleAPIv1ToRadio" +The WebServer just adds basaic support to deliver WebContent, so it can be used to +deliver the WebGui definded by the WebClient Project. + +Steps to get it running: +1.) Add these Linux Libs to the compile and target machine: + + sudo apt update && \ + apt -y install openssl libssl-dev libopenssl libsdl2-dev \ + libulfius-dev liborcania-dev + +2.) Configure the root directory of the web Content in the config.yaml file. + The followinng tags should be included and set at your needs + + Example entry in the config.yaml + Webserver: + Port: 9001 # Port for Webserver & Webservices + RootPath: /home/marc/web # Root Dir of WebServer + +3.) Checkout the web project + https://github.com/meshtastic/web.git + + Build it and copy the content of the folder web/dist/* to the folder you did set as "RootPath" + +!!!The WebServer should not be used as production system or exposed to the Internet. Its a raw basic version!!! + +Author: Marc Philipp Hammermann +mail: marchammermann@googlemail.com + +*/ +#ifdef PORTDUINO_LINUX_HARDWARE +#include "PiWebServer.h" +#include "NodeDB.h" +#include "PhoneAPI.h" +#include "PowerFSM.h" +#include "RadioLibInterface.h" +#include "airtime.h" +#include "graphics/Screen.h" +#include "main.h" +#include "mesh/wifi/WiFiAPClient.h" +#include "sleep.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "PortduinoFS.h" +#include "platform/portduino/PortduinoGlue.h" + +#define DEFAULT_REALM "default_realm" +#define PREFIX "" + +struct _file_config configWeb; + +// We need to specify some content-type mapping, so the resources get delivered with the +// right content type and are displayed correctly in the browser +char contentTypes[][2][32] = {{".txt", "text/plain"}, {".html", "text/html"}, + {".js", "text/javascript"}, {".png", "image/png"}, + {".jpg", "image/jpg"}, {".gz", "application/gzip"}, + {".gif", "image/gif"}, {".json", "application/json"}, + {".css", "text/css"}, {".ico", "image/vnd.microsoft.icon"}, + {".svg", "image/svg+xml"}, {".ts", "text/javascript"}, + {".tsx", "text/javascript"}, {"", ""}}; + +#undef str + +volatile bool isWebServerReady; +volatile bool isCertReady; + +HttpAPI webAPI; + +PiWebServerThread *piwebServerThread; + +/** + * Return the filename extension + */ +const char *get_filename_ext(const char *path) +{ + const char *dot = strrchr(path, '.'); + if (!dot || dot == path) + return "*"; + if (strchr(dot, '?') != NULL) { + //*strchr(dot, '?') = '\0'; + const char *empty = "\0"; + return empty; + } + return dot; +} + +/** + * Streaming callback function to ease sending large files + */ +static ssize_t callback_static_file_stream(void *cls, uint64_t pos, char *buf, size_t max) +{ + (void)(pos); + if (cls != NULL) { + return fread(buf, 1, max, (FILE *)cls); + } else { + return U_STREAM_END; + } +} + +/** + * Cleanup FILE* structure when streaming is complete + */ +static void callback_static_file_stream_free(void *cls) +{ + if (cls != NULL) { + fclose((FILE *)cls); + } +} + +/** + * static file callback endpoint that delivers the content for WebServer calls + */ +int callback_static_file(const struct _u_request *request, struct _u_response *response, void *user_data) +{ + size_t length; + FILE *f; + char *file_requested, *file_path, *url_dup_save, *real_path = NULL; + const char *content_type; + + /* + * Comment this if statement if you don't access static files url from root dir, like /app + */ + if (request->callback_position > 0) { + return U_CALLBACK_CONTINUE; + } else if (user_data != NULL && (configWeb.files_path != NULL)) { + file_requested = o_strdup(request->http_url); + url_dup_save = file_requested; + + while (file_requested[0] == '/') { + file_requested++; + } + file_requested += o_strlen(configWeb.url_prefix); + while (file_requested[0] == '/') { + file_requested++; + } + + if (strchr(file_requested, '#') != NULL) { + *strchr(file_requested, '#') = '\0'; + } + + if (strchr(file_requested, '?') != NULL) { + *strchr(file_requested, '?') = '\0'; + } + + if (file_requested == NULL || o_strlen(file_requested) == 0 || 0 == o_strcmp("/", file_requested)) { + o_free(url_dup_save); + url_dup_save = file_requested = o_strdup("index.html"); + } + + file_path = msprintf("%s/%s", configWeb.files_path, file_requested); + real_path = realpath(file_path, NULL); + if (0 == o_strncmp(configWeb.files_path, real_path, o_strlen(configWeb.files_path))) { + if (access(file_path, F_OK) != -1) { + f = fopen(file_path, "rb"); + if (f) { + fseek(f, 0, SEEK_END); + length = ftell(f); + fseek(f, 0, SEEK_SET); + + content_type = u_map_get_case(&configWeb.mime_types, get_filename_ext(file_requested)); + if (content_type == NULL) { + content_type = u_map_get(&configWeb.mime_types, "*"); + LOG_DEBUG("Static File Server - Unknown mime type for extension %s \n", get_filename_ext(file_requested)); + } + u_map_put(response->map_header, "Content-Type", content_type); + u_map_copy_into(response->map_header, &configWeb.map_header); + + if (ulfius_set_stream_response(response, 200, callback_static_file_stream, callback_static_file_stream_free, + length, STATIC_FILE_CHUNK, f) != U_OK) { + LOG_DEBUG("callback_static_file - Error ulfius_set_stream_response\n "); + } + } + } else { + if (configWeb.redirect_on_404 == NULL) { + ulfius_set_string_body_response(response, 404, "File not found"); + } else { + ulfius_add_header_to_response(response, "Location", configWeb.redirect_on_404); + response->status = 302; + } + } + } else { + if (configWeb.redirect_on_404 == NULL) { + ulfius_set_string_body_response(response, 404, "File not found"); + } else { + ulfius_add_header_to_response(response, "Location", configWeb.redirect_on_404); + response->status = 302; + } + } + + o_free(file_path); + o_free(url_dup_save); + free(real_path); // realpath uses malloc + return U_CALLBACK_CONTINUE; + } else { + LOG_DEBUG("Static File Server - Error, user_data is NULL or inconsistent\n"); + return U_CALLBACK_ERROR; + } +} + +static void handleWebResponse() {} + +/* + * Adapt the radioapi to the Webservice handleAPIv1ToRadio + * Trigger : WebGui(SAVE)->WebServcice->phoneApi + */ +int handleAPIv1ToRadio(const struct _u_request *req, struct _u_response *res, void *user_data) +{ + LOG_DEBUG("handleAPIv1ToRadio web -> radio \n"); + + ulfius_add_header_to_response(res, "Content-Type", "application/x-protobuf"); + ulfius_add_header_to_response(res, "Access-Control-Allow-Headers", "Content-Type"); + ulfius_add_header_to_response(res, "Access-Control-Allow-Origin", "*"); + ulfius_add_header_to_response(res, "Access-Control-Allow-Methods", "PUT, OPTIONS"); + ulfius_add_header_to_response(res, "X-Protobuf-Schema", + "https://raw.githubusercontent.com/meshtastic/protobufs/master/mesh.proto"); + + if (req->http_verb == "OPTIONS") { + ulfius_set_response_properties(res, U_OPT_STATUS, 204); + return U_CALLBACK_CONTINUE; + } + + byte buffer[MAX_TO_FROM_RADIO_SIZE]; + size_t s = req->binary_body_length; + + memcpy(buffer, req->binary_body, MAX_TO_FROM_RADIO_SIZE); + + // FIXME* Problem with portdunio loosing mountpoint maybe because of running in a real sep. thread + + portduinoVFS->mountpoint("/home/marc/.portduino/default"); + + LOG_DEBUG("Received %d bytes from PUT request\n", s); + webAPI.handleToRadio(buffer, s); + LOG_DEBUG("end web->radio \n"); + return U_CALLBACK_COMPLETE; +} + +/* + * Adapt the radioapi to the Webservice handleAPIv1FromRadio + * Trigger : WebGui(POLL)->handleAPIv1FromRadio->phoneapi->Meshtastic(Radio) events + */ +int handleAPIv1FromRadio(const struct _u_request *req, struct _u_response *res, void *user_data) +{ + + LOG_DEBUG("handleAPIv1FromRadio radio -> web\n"); + std::string valueAll; + + // Status code is 200 OK by default. + ulfius_add_header_to_response(res, "Content-Type", "application/x-protobuf"); + ulfius_add_header_to_response(res, "Access-Control-Allow-Origin", "*"); + ulfius_add_header_to_response(res, "Access-Control-Allow-Methods", "GET"); + ulfius_add_header_to_response(res, "X-Protobuf-Schema", + "https://raw.githubusercontent.com/meshtastic/protobufs/master/mesh.proto"); + + uint8_t txBuf[MAX_STREAM_BUF_SIZE]; + uint32_t len = 1; + + if (valueAll == "true") { + while (len) { + len = webAPI.getFromRadio(txBuf); + ulfius_set_response_properties(res, U_OPT_STATUS, 200, U_OPT_BINARY_BODY, txBuf, len); + const char *tmpa = (const char *)txBuf; + ulfius_set_string_body_response(res, 200, tmpa); + LOG_DEBUG("\n----webAPI response all:----\n"); + LOG_DEBUG(tmpa); + LOG_DEBUG("\n"); + } + // Otherwise, just return one protobuf + } else { + len = webAPI.getFromRadio(txBuf); + const char *tmpa = (const char *)txBuf; + ulfius_set_binary_body_response(res, 200, tmpa, len); + LOG_DEBUG("\n----webAPI response:\n"); + LOG_DEBUG(tmpa); + LOG_DEBUG("\n"); + } + + LOG_DEBUG("end radio->web\n", len); + return U_CALLBACK_COMPLETE; +} + +/* +OpenSSL RSA Key Gen +*/ +int generate_rsa_key(EVP_PKEY **pkey) +{ + EVP_PKEY_CTX *pkey_ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL); + if (!pkey_ctx) + return -1; + if (EVP_PKEY_keygen_init(pkey_ctx) <= 0) + return -1; + if (EVP_PKEY_CTX_set_rsa_keygen_bits(pkey_ctx, 2048) <= 0) + return -1; + if (EVP_PKEY_keygen(pkey_ctx, pkey) <= 0) + return -1; + EVP_PKEY_CTX_free(pkey_ctx); + return 0; // SUCCESS +} + +int generate_self_signed_x509(EVP_PKEY *pkey, X509 **x509) +{ + *x509 = X509_new(); + if (!*x509) + return -1; + if (X509_set_version(*x509, 2) != 1) + return -1; + ASN1_INTEGER_set(X509_get_serialNumber(*x509), 1); + X509_gmtime_adj(X509_get_notBefore(*x509), 0); + X509_gmtime_adj(X509_get_notAfter(*x509), 31536000L); // 1 YEAR ACCESS + + X509_set_pubkey(*x509, pkey); + + // SET Subject Name + X509_NAME *name = X509_get_subject_name(*x509); + X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, (unsigned char *)"DE", -1, -1, 0); + X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC, (unsigned char *)"Meshtastic", -1, -1, 0); + X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, (unsigned char *)"meshtastic.local", -1, -1, 0); + // Selfsigned, Issuer = Subject + X509_set_issuer_name(*x509, name); + + // Certificate signed with our privte key + if (X509_sign(*x509, pkey, EVP_sha256()) <= 0) + return -1; + + return 0; +} + +char *read_file_into_string(const char *filename) +{ + FILE *file = fopen(filename, "rb"); + if (file == NULL) { + LOG_INFO("Fehler beim Öffnen der Datei\n"); + return NULL; + } + + // Size of file + fseek(file, 0, SEEK_END); + long filesize = ftell(file); + rewind(file); + + // reserve mem for file + 1 byte + char *buffer = (char *)malloc(filesize + 1); + if (buffer == NULL) { + LOG_INFO("Speicherreservierung fehlgeschlagen\n"); + fclose(file); + return NULL; + } + + // read content + size_t readSize = fread(buffer, 1, filesize, file); + if (readSize != filesize) { + LOG_INFO("Fehler beim Lesen der Datei\n"); + free(buffer); + fclose(file); + return NULL; + } + + // add terminator sign at the end + buffer[filesize] = '\0'; + fclose(file); + return buffer; // return pointer +} + +int PiWebServerThread::CheckSSLandLoad() +{ + // read certificate + cert_pem = read_file_into_string("certificate.pem"); + if (cert_pem == NULL) { + LOG_INFO("ERROR SSL Certificate File can't be loaded\n"); + return 1; + } + // read private key + key_pem = read_file_into_string("private_key.pem"); + if (key_pem == NULL) { + LOG_INFO("ERROR SSL Certificate File can't be loaded\n"); + return 2; + } + + return 0; +} + +int PiWebServerThread::CreateSSLCertificate() +{ + + EVP_PKEY *pkey = NULL; + X509 *x509 = NULL; + + if (generate_rsa_key(&pkey) != 0) { + LOG_INFO("Error generating RSA-Key.\n"); + return 1; + } + + if (generate_self_signed_x509(pkey, &x509) != 0) { + LOG_INFO("Error generating of X509-Certificat.\n"); + return 2; + } + + // Ope file to write private key file + FILE *pkey_file = fopen("private_key.pem", "wb"); + if (!pkey_file) { + LOG_INFO("Error opening private key file.\n"); + return 3; + } + // write private key file + PEM_write_PrivateKey(pkey_file, pkey, NULL, NULL, 0, NULL, NULL); + fclose(pkey_file); + + // open Certificate file + FILE *x509_file = fopen("certificate.pem", "wb"); + if (!x509_file) { + LOG_INFO("Error opening certificate.\n"); + return 4; + } + // write cirtificate + PEM_write_X509(x509_file, x509); + fclose(x509_file); + + EVP_PKEY_free(pkey); + X509_free(x509); + LOG_INFO("Create SSL Certifictate -certificate.pem- succesfull \n"); + return 0; +} + +void initWebServer() {} + +PiWebServerThread::PiWebServerThread() +{ + int ret, retssl, webservport; + + if (CheckSSLandLoad() != 0) { + CreateSSLCertificate(); + if (CheckSSLandLoad() != 0) { + LOG_INFO("Major Error Gen & Read SSL Certificate\n"); + } + } + + if (settingsMap[webserverport] != 0) { + LOG_INFO("Using webserver port from yaml config.\n"); + webservport = settingsMap[webserverport]; + } else { + LOG_INFO("No webserver port found in yaml config using default port 80.\n"); + webservport = 80; + } + + // Web Content Service Instance + if (ulfius_init_instance(&instanceWeb, webservport, NULL, DEFAULT_REALM) != U_OK) { + LOG_INFO("Webserver couldn't be started, abort execution\n"); + } else { + + LOG_INFO("Webserver started ....\n"); + u_map_init(&configWeb.mime_types); + u_map_put(&configWeb.mime_types, "*", "application/octet-stream"); + u_map_put(&configWeb.mime_types, ".html", "text/html"); + u_map_put(&configWeb.mime_types, ".htm", "text/html"); + u_map_put(&configWeb.mime_types, ".tsx", "application/javascript"); + u_map_put(&configWeb.mime_types, ".ts", "application/javascript"); + u_map_put(&configWeb.mime_types, ".css", "text/css"); + u_map_put(&configWeb.mime_types, ".js", "application/javascript"); + u_map_put(&configWeb.mime_types, ".json", "application/json"); + u_map_put(&configWeb.mime_types, ".png", "image/png"); + u_map_put(&configWeb.mime_types, ".gif", "image/gif"); + u_map_put(&configWeb.mime_types, ".jpeg", "image/jpeg"); + u_map_put(&configWeb.mime_types, ".jpg", "image/jpeg"); + u_map_put(&configWeb.mime_types, ".ttf", "font/ttf"); + u_map_put(&configWeb.mime_types, ".woff", "font/woff"); + u_map_put(&configWeb.mime_types, ".ico", "image/x-icon"); + u_map_put(&configWeb.mime_types, ".svg", "image/svg+xml"); + + webrootpath = settingsStrings[webserverrootpath]; + + configWeb.files_path = (char *)webrootpath.c_str(); + configWeb.url_prefix = ""; + + u_map_put(instanceWeb.default_headers, "Access-Control-Allow-Origin", "*"); + // Maximum body size sent by the client is 1 Kb + instanceWeb.max_post_body_size = 1024; + ulfius_add_endpoint_by_val(&instanceWeb, "GET", PREFIX, "/api/v1/fromradio/*", 1, &handleAPIv1FromRadio, NULL); + ulfius_add_endpoint_by_val(&instanceWeb, "PUT", PREFIX, "/api/v1/toradio/*", 1, &handleAPIv1ToRadio, NULL); + + // Add callback function to all endpoints for the Web Server + ulfius_add_endpoint_by_val(&instanceWeb, "GET", NULL, "/*", 2, &callback_static_file, &configWeb); + + // thats for serving without SSL + // retssl = ulfius_start_framework(&instanceWeb); + + // thats for serving with SSL + retssl = ulfius_start_secure_framework(&instanceWeb, key_pem, cert_pem); + + if (retssl == U_OK) { + LOG_INFO("Web Server framework srated on port: %i \n", webservport); + LOG_INFO("Web Server root %s\n", (char *)webrootpath.c_str()); + } else { + LOG_INFO("Error starting Web Server framework\n"); + } + } +} + +PiWebServerThread::~PiWebServerThread() +{ + u_map_clean(&configWeb.mime_types); + + ulfius_stop_framework(&instanceWeb); + ulfius_stop_framework(&instanceWeb); + + ulfius_clean_instance(&instanceService); + ulfius_clean_instance(&instanceService); + free(cert_pem); + LOG_INFO("End framework"); +} + +#endif \ No newline at end of file diff --git a/src/mesh/http/PiWebServer.h b/src/mesh/http/PiWebServer.h new file mode 100644 index 0000000000..ccd3c71151 --- /dev/null +++ b/src/mesh/http/PiWebServer.h @@ -0,0 +1,58 @@ +#pragma once +#ifdef PORTDUINO_LINUX_HARDWARE +#include "PhoneAPI.h" +#include "ulfius-cfg.h" +#include "ulfius.h" +#include +#include + +#define STATIC_FILE_CHUNK 256 + +void initWebServer(); +void createSSLCert(); +int callback_static_file(const struct _u_request *request, struct _u_response *response, void *user_data); +const char *get_filename_ext(const char *path); + +struct _file_config { + char *files_path; + char *url_prefix; + struct _u_map mime_types; + struct _u_map map_header; + char *redirect_on_404; +}; + +class PiWebServerThread +{ + private: + char *key_pem = NULL; + char *cert_pem = NULL; + // struct _u_map mime_types; + std::string webrootpath; + + public: + PiWebServerThread(); + ~PiWebServerThread(); + int CreateSSLCertificate(); + int CheckSSLandLoad(); + uint32_t requestRestart = 0; + struct _u_instance instanceWeb; + struct _u_instance instanceService; +}; + +class HttpAPI : public PhoneAPI +{ + + public: + // Nothing here yet + + private: + // Nothing here yet + + protected: + /// Check the current underlying physical link to see if the client is currently connected + virtual bool checkIsConnected() override { return true; } // FIXME, be smarter about this +}; + +extern PiWebServerThread *piwebServerThread; + +#endif \ No newline at end of file diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index 7814f2c296..f6e5d9b180 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -1,3 +1,4 @@ +#ifndef PORTDUINO_LINUX_HARDWARE #include "mesh/http/WebServer.h" #include "NodeDB.h" #include "graphics/Screen.h" @@ -210,4 +211,5 @@ void initWebServer() } else { LOG_ERROR("Web Servers Failed! ;-( \n"); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/mesh/http/WebServer.h b/src/mesh/http/WebServer.h index 815d87432d..4eea413a77 100644 --- a/src/mesh/http/WebServer.h +++ b/src/mesh/http/WebServer.h @@ -1,3 +1,4 @@ +#ifdef PORTDUINO_LINUX_HARDWARE #pragma once #include "PhoneAPI.h" @@ -20,3 +21,4 @@ class WebServerThread : private concurrency::OSThread }; extern WebServerThread *webServerThread; +#endif \ No newline at end of file diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index c8fcc3d13d..f59784921d 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -195,6 +195,11 @@ void portduinoSetup() settingsStrings[keyboardDevice] = (yamlConfig["Input"]["KeyboardDevice"]).as(""); } + if (yamlConfig["Webserver"]) { + settingsMap[webserverport] = (yamlConfig["Webserver"]["Port"]).as(-1); + settingsStrings[webserverrootpath] = (yamlConfig["Webserver"]["RootPath"]).as(""); + } + } catch (YAML::Exception e) { std::cout << "*** Exception " << e.what() << std::endl; exit(EXIT_FAILURE); diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index f8da20e37c..3fe5f74bf0 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -33,7 +33,10 @@ enum configNames { displayOffsetY, displayInvert, keyboardDevice, - logoutputlevel + logoutputlevel, + webserver, + webserverport, + webserverrootpath }; enum { no_screen, st7789, st7735, st7735s, ili9341 }; enum { no_touchscreen, xpt2046, stmpe610 }; diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index d37c6be21f..4f7ddeaff4 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -1,6 +1,6 @@ [env:native] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino +build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -lSDL2 -lulfius -lorcania -lssl -lcrypto board = cross_platform lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} \ No newline at end of file From b9972b8f9cecbaa0d2c00cec3c751d84974d47b0 Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Thu, 22 Feb 2024 05:14:25 +0100 Subject: [PATCH 02/22] Fix bug in login functionality --- .editorconfig | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..e69de29bb2 From 8e9af81483fdffd04692ab89d39de732e2448c75 Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Thu, 22 Feb 2024 11:42:20 +0100 Subject: [PATCH 03/22] Added customized config of portdunio.ini with LovyannGFX from marelab repro --- arch/portduino/portduino.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index c88bde2616..a15ac4b649 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -23,7 +23,7 @@ lib_deps = ${env.lib_deps} ${networking_base.lib_deps} rweather/Crypto@^0.4.0 - lovyan03/LovyanGFX@^1.1.12 + https://github.com/marelab/LovyanGFX.git build_flags = ${arduino_base.build_flags} From f6a978fe2534d13ad0cc5b69c29d64a1ebc8ce5d Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Thu, 22 Feb 2024 23:05:36 +0100 Subject: [PATCH 04/22] Compile Problem resolved with developer version of LovyanGFX.git --- platformio.ini | 2 +- variants/portduino/platformio.ini | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 21536ac18a..74589fad8f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -21,7 +21,7 @@ ;default_envs = t-echo ;default_envs = canaryone ;default_envs = nrf52840dk-geeksville -default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here +default_envs = native-cross #native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here ;default_envs = nano-g1 ;default_envs = pca10059_diy_eink ;default_envs = meshtastic-diy-v1 diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index 4f7ddeaff4..ba977055a6 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -3,4 +3,11 @@ extends = portduino_base build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -lSDL2 -lulfius -lorcania -lssl -lcrypto board = cross_platform lib_deps = ${portduino_base.lib_deps} +build_src_filter = ${portduino_base.build_src_filter} + +[env:native-cross] +extends = portduino_base +build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -lSDL2 -lulfius -lorcania -lssl -lcrypto +board = cross_platform +lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} \ No newline at end of file From 7da107f448930a0afa7076f3597b7c61cb873000 Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Thu, 22 Feb 2024 23:07:24 +0100 Subject: [PATCH 05/22] Compile against dev version --- arch/portduino/portduino.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index a15ac4b649..d4bc32603d 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -1,6 +1,7 @@ ; The Portduino based sim environment on top of any host OS, all hardware will be simulated [portduino_base] -platform = https://github.com/meshtastic/platform-native.git#a28dd5a9ccd5c48a9bede46037855ff83915d74b +platform = https://github.com/marelab/platform-native.git +;platform = https://github.com/meshtastic/platform-native.git#a28dd5a9ccd5c48a9bede46037855ff83915d74b framework = arduino build_src_filter = @@ -23,7 +24,8 @@ lib_deps = ${env.lib_deps} ${networking_base.lib_deps} rweather/Crypto@^0.4.0 - https://github.com/marelab/LovyanGFX.git + https://github.com/lovyan03/LovyanGFX.git#develop + ;https://github.com/marelab/LovyanGFX.git build_flags = ${arduino_base.build_flags} From f910e79bdde9ff62034b41a5e7cf63847ba42aea Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Thu, 22 Feb 2024 23:12:24 +0100 Subject: [PATCH 06/22] Fixes to fit into main branch --- arch/portduino/portduino.ini | 4 ++-- platformio.ini | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index d4bc32603d..2fe4d0f880 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -1,7 +1,7 @@ ; The Portduino based sim environment on top of any host OS, all hardware will be simulated [portduino_base] -platform = https://github.com/marelab/platform-native.git -;platform = https://github.com/meshtastic/platform-native.git#a28dd5a9ccd5c48a9bede46037855ff83915d74b +;platform = https://github.com/marelab/platform-native.git +platform = https://github.com/meshtastic/platform-native.git#a28dd5a9ccd5c48a9bede46037855ff83915d74b framework = arduino build_src_filter = diff --git a/platformio.ini b/platformio.ini index 74589fad8f..21536ac18a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -21,7 +21,7 @@ ;default_envs = t-echo ;default_envs = canaryone ;default_envs = nrf52840dk-geeksville -default_envs = native-cross #native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here +default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here ;default_envs = nano-g1 ;default_envs = pca10059_diy_eink ;default_envs = meshtastic-diy-v1 From a094d9776cb486cc6ed3e2d1712857a1891230ef Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Fri, 23 Feb 2024 21:59:40 +0100 Subject: [PATCH 07/22] Update variant.h, main.cpp, .gitignore, WebServer.cpp, esp32s2.ini, WebServer.h, ContentHandler.cpp, rp2040.ini, nrf52.ini, ContentHelper.cpp, Dockerfile, ContentHandler.h, esp32.ini, stm32wl5e.ini --- .gitignore | 6 +----- Dockerfile | 2 +- arch/esp32/esp32.ini | 2 +- arch/esp32/esp32s2.ini | 5 ++--- arch/nrf52/nrf52.ini | 2 +- arch/portduino/portduino.ini | 6 +++--- arch/rp2040/rp2040.ini | 2 +- arch/stm32/stm32wl5e.ini | 2 +- platformio.ini | 4 ++-- src/main.cpp | 2 +- src/mesh/http/ContentHandler.cpp | 4 +--- src/mesh/http/ContentHandler.h | 4 +--- src/mesh/http/ContentHelper.cpp | 4 +--- src/mesh/http/WebServer.cpp | 4 +--- src/mesh/http/WebServer.h | 4 +--- src/mesh/{http => raspihttp}/PiWebServer.cpp | 0 src/mesh/{http => raspihttp}/PiWebServer.h | 0 variants/portduino/platformio.ini | 9 +-------- variants/portduino/variant.h | 2 +- 19 files changed, 21 insertions(+), 43 deletions(-) rename src/mesh/{http => raspihttp}/PiWebServer.cpp (100%) rename src/mesh/{http => raspihttp}/PiWebServer.h (100%) diff --git a/.gitignore b/.gitignore index 2471fa68f1..4b5b346dcf 100644 --- a/.gitignore +++ b/.gitignore @@ -30,8 +30,4 @@ __pycache__ venv/ release/ .vscode/extensions.json -/compile_commands.json -src/mesh/http/certificate.pem -src/mesh/http/private_key.pem -arch/portduino/portduino.ini -.vscode/extensions.json \ No newline at end of file +/compile_commands.json \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ff0624f37f..a3f7102369 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Install build deps USER root RUN apt-get update && \ - apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev libgpiod2 + apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev libgpiod2 openssl libssl-dev libulfius-dev liborcania-dev bash # create a non-priveleged user & group RUN groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 mesh diff --git a/arch/esp32/esp32.ini b/arch/esp32/esp32.ini index bf84dd9395..39935b8491 100644 --- a/arch/esp32/esp32.ini +++ b/arch/esp32/esp32.ini @@ -4,7 +4,7 @@ extends = arduino_base platform = platformio/espressif32@6.3.2 # This is a temporary fix to the S3-based devices bluetooth issues until we can determine what within ESP-IDF changed and can develop a suitable patch. build_src_filter = - ${arduino_base.build_src_filter} - - - - + ${arduino_base.build_src_filter} - - - - - upload_speed = 921600 debug_init_break = tbreak setup diff --git a/arch/esp32/esp32s2.ini b/arch/esp32/esp32s2.ini index 3bde3465a1..5de0fa5497 100644 --- a/arch/esp32/esp32s2.ini +++ b/arch/esp32/esp32s2.ini @@ -2,7 +2,7 @@ extends = esp32_base build_src_filter = - ${esp32_base.build_src_filter} - + ${esp32_base.build_src_filter} - - monitor_speed = 115200 @@ -12,5 +12,4 @@ build_flags = lib_ignore = ${esp32_base.lib_ignore} - NimBLE-Arduino - + NimBLE-Arduino \ No newline at end of file diff --git a/arch/nrf52/nrf52.ini b/arch/nrf52/nrf52.ini index 04ca89a54d..5155eaadc8 100644 --- a/arch/nrf52/nrf52.ini +++ b/arch/nrf52/nrf52.ini @@ -11,7 +11,7 @@ build_flags = -Isrc/platform/nrf52 build_src_filter = - ${arduino_base.build_src_filter} - - - - - - - - - + ${arduino_base.build_src_filter} - - - - - - - - - - lib_deps= ${arduino_base.lib_deps} diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index 2fe4d0f880..bd18aa2373 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -1,6 +1,5 @@ ; The Portduino based sim environment on top of any host OS, all hardware will be simulated [portduino_base] -;platform = https://github.com/marelab/platform-native.git platform = https://github.com/meshtastic/platform-native.git#a28dd5a9ccd5c48a9bede46037855ff83915d74b framework = arduino @@ -12,7 +11,8 @@ build_src_filter = - - - - + + - + + - - - @@ -25,7 +25,7 @@ lib_deps = ${networking_base.lib_deps} rweather/Crypto@^0.4.0 https://github.com/lovyan03/LovyanGFX.git#develop - ;https://github.com/marelab/LovyanGFX.git + ;lovyan03/LovyanGFX@^1.1.12 build_flags = ${arduino_base.build_flags} diff --git a/arch/rp2040/rp2040.ini b/arch/rp2040/rp2040.ini index 48fe0dae65..edc4373ad4 100644 --- a/arch/rp2040/rp2040.ini +++ b/arch/rp2040/rp2040.ini @@ -12,7 +12,7 @@ build_flags = -D__PLAT_RP2040__ # -D _POSIX_THREADS build_src_filter = - ${arduino_base.build_src_filter} - - - - - - - - + ${arduino_base.build_src_filter} - - - - - - - - - lib_ignore = BluetoothOTA diff --git a/arch/stm32/stm32wl5e.ini b/arch/stm32/stm32wl5e.ini index 4483ff5262..4d74ade8fb 100644 --- a/arch/stm32/stm32wl5e.ini +++ b/arch/stm32/stm32wl5e.ini @@ -13,7 +13,7 @@ build_flags = -DVECT_TAB_OFFSET=0x08000000 build_src_filter = - ${arduino_base.build_src_filter} - - - - - - - - - - - - - + ${arduino_base.build_src_filter} - - - - - - - - - - - - - - board_upload.offset_address = 0x08000000 upload_protocol = stlink diff --git a/platformio.ini b/platformio.ini index 21536ac18a..d626c0ca5b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2,7 +2,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -;default_envs = tbeam +default_envs = tbeam ;default_envs = pico ;default_envs = tbeam-s3-core ;default_envs = tbeam0.7 @@ -21,7 +21,7 @@ ;default_envs = t-echo ;default_envs = canaryone ;default_envs = nrf52840dk-geeksville -default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here +;default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here ;default_envs = nano-g1 ;default_envs = pca10059_diy_eink ;default_envs = meshtastic-diy-v1 diff --git a/src/main.cpp b/src/main.cpp index f63dfb83f9..961e176cc3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,7 +68,7 @@ NRF52Bluetooth *nrf52Bluetooth; #ifdef ARCH_PORTDUINO #include "linux/LinuxHardwareI2C.h" -#include "mesh/http/PiWebServer.h" +#include "mesh/raspihttp/PiWebServer.h" #include "platform/portduino/PortduinoGlue.h" #include #include diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index 986b26dd95..6debd7240f 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -1,4 +1,3 @@ -#ifndef PORTDUINO_LINUX_HARDWARE #include "NodeDB.h" #include "PowerFSM.h" #include "RadioLibInterface.h" @@ -855,5 +854,4 @@ void handleScanNetworks(HTTPRequest *req, HTTPResponse *res) JSONValue *value = new JSONValue(jsonObjOuter); res->print(value->Stringify().c_str()); delete value; -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/mesh/http/ContentHandler.h b/src/mesh/http/ContentHandler.h index ba900e18fd..987e3ffef9 100644 --- a/src/mesh/http/ContentHandler.h +++ b/src/mesh/http/ContentHandler.h @@ -1,4 +1,3 @@ -#ifndef PORTDUINO_LINUX_HARDWARE #pragma once void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer); @@ -34,5 +33,4 @@ class HttpAPI : public PhoneAPI protected: /// Check the current underlying physical link to see if the client is currently connected virtual bool checkIsConnected() override { return true; } // FIXME, be smarter about this -}; -#endif \ No newline at end of file +}; \ No newline at end of file diff --git a/src/mesh/http/ContentHelper.cpp b/src/mesh/http/ContentHelper.cpp index 02660a7e95..2cca7008e0 100644 --- a/src/mesh/http/ContentHelper.cpp +++ b/src/mesh/http/ContentHelper.cpp @@ -1,4 +1,3 @@ -#ifndef PORTDUINO_LINUX_HARDWARE #include "mesh/http/ContentHelper.h" // #include // #include "main.h" @@ -12,5 +11,4 @@ void replaceAll(std::string &str, const std::string &from, const std::string &to str.replace(start_pos, from.length(), to); start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx' } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index f6e5d9b180..7814f2c296 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -1,4 +1,3 @@ -#ifndef PORTDUINO_LINUX_HARDWARE #include "mesh/http/WebServer.h" #include "NodeDB.h" #include "graphics/Screen.h" @@ -211,5 +210,4 @@ void initWebServer() } else { LOG_ERROR("Web Servers Failed! ;-( \n"); } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/mesh/http/WebServer.h b/src/mesh/http/WebServer.h index 4eea413a77..1da8fadedd 100644 --- a/src/mesh/http/WebServer.h +++ b/src/mesh/http/WebServer.h @@ -1,4 +1,3 @@ -#ifdef PORTDUINO_LINUX_HARDWARE #pragma once #include "PhoneAPI.h" @@ -20,5 +19,4 @@ class WebServerThread : private concurrency::OSThread virtual int32_t runOnce() override; }; -extern WebServerThread *webServerThread; -#endif \ No newline at end of file +extern WebServerThread *webServerThread; \ No newline at end of file diff --git a/src/mesh/http/PiWebServer.cpp b/src/mesh/raspihttp/PiWebServer.cpp similarity index 100% rename from src/mesh/http/PiWebServer.cpp rename to src/mesh/raspihttp/PiWebServer.cpp diff --git a/src/mesh/http/PiWebServer.h b/src/mesh/raspihttp/PiWebServer.h similarity index 100% rename from src/mesh/http/PiWebServer.h rename to src/mesh/raspihttp/PiWebServer.h diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index ba977055a6..cf14974be2 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -1,13 +1,6 @@ [env:native] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -lSDL2 -lulfius -lorcania -lssl -lcrypto -board = cross_platform -lib_deps = ${portduino_base.lib_deps} -build_src_filter = ${portduino_base.build_src_filter} - -[env:native-cross] -extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -lSDL2 -lulfius -lorcania -lssl -lcrypto +build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -lulfius -lorcania -lssl -lcrypto board = cross_platform lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} \ No newline at end of file diff --git a/variants/portduino/variant.h b/variants/portduino/variant.h index f47b58afc2..6fe858e255 100644 --- a/variants/portduino/variant.h +++ b/variants/portduino/variant.h @@ -1,3 +1,3 @@ #define HAS_SCREEN 1 #define CANNED_MESSAGE_MODULE_ENABLE 1 -#define HAS_GPS 1 +#define HAS_GPS 1 \ No newline at end of file From 93cd5ec04359390d6d4f05af6d59c2449b3e1a26 Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Fri, 23 Feb 2024 22:31:01 +0100 Subject: [PATCH 08/22] Added linux pi std /usr/include dir --- arch/portduino/portduino.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index bd18aa2373..408c95218f 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -31,6 +31,7 @@ build_flags = ${arduino_base.build_flags} -fPIC -Isrc/platform/portduino + -I/usr/include -DRADIOLIB_EEPROM_UNSUPPORTED -DPORTDUINO_LINUX_HARDWARE -lbluetooth From 19d33b23735430c4dad90ab4105b578da0ca8b9a Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Fri, 23 Feb 2024 22:45:46 +0100 Subject: [PATCH 09/22] Adding /usr/innclude for Linux compile against native libs that are not hadled by platformio --- variants/portduino/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index cf14974be2..c7cfb9d187 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -1,6 +1,6 @@ [env:native] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -lulfius -lorcania -lssl -lcrypto +build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -I /usr/include -lulfius -lorcania -lssl -lcrypto board = cross_platform lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} \ No newline at end of file From dbbd35e3d6dda9195cfbeafe5313b07bcaedd77f Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Fri, 23 Feb 2024 23:50:39 +0100 Subject: [PATCH 10/22] Review log level changes & translation --- Dockerfile | 2 +- src/mesh/raspihttp/PiWebServer.cpp | 34 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index a3f7102369..630c911f3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Install build deps USER root RUN apt-get update && \ - apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev libgpiod2 openssl libssl-dev libulfius-dev liborcania-dev bash + apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev libg piod2 openssl libssl-dev libulfius-dev liborcania-dev bash # create a non-priveleged user & group RUN groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 mesh diff --git a/src/mesh/raspihttp/PiWebServer.cpp b/src/mesh/raspihttp/PiWebServer.cpp index be6d72db4d..d6bfa5e277 100644 --- a/src/mesh/raspihttp/PiWebServer.cpp +++ b/src/mesh/raspihttp/PiWebServer.cpp @@ -258,7 +258,7 @@ int handleAPIv1ToRadio(const struct _u_request *req, struct _u_response *res, vo int handleAPIv1FromRadio(const struct _u_request *req, struct _u_response *res, void *user_data) { - LOG_DEBUG("handleAPIv1FromRadio radio -> web\n"); + // LOG_DEBUG("handleAPIv1FromRadio radio -> web\n"); std::string valueAll; // Status code is 200 OK by default. @@ -277,7 +277,7 @@ int handleAPIv1FromRadio(const struct _u_request *req, struct _u_response *res, ulfius_set_response_properties(res, U_OPT_STATUS, 200, U_OPT_BINARY_BODY, txBuf, len); const char *tmpa = (const char *)txBuf; ulfius_set_string_body_response(res, 200, tmpa); - LOG_DEBUG("\n----webAPI response all:----\n"); + // LOG_DEBUG("\n----webAPI response all:----\n"); LOG_DEBUG(tmpa); LOG_DEBUG("\n"); } @@ -286,12 +286,12 @@ int handleAPIv1FromRadio(const struct _u_request *req, struct _u_response *res, len = webAPI.getFromRadio(txBuf); const char *tmpa = (const char *)txBuf; ulfius_set_binary_body_response(res, 200, tmpa, len); - LOG_DEBUG("\n----webAPI response:\n"); + // LOG_DEBUG("\n----webAPI response:\n"); LOG_DEBUG(tmpa); LOG_DEBUG("\n"); } - LOG_DEBUG("end radio->web\n", len); + // LOG_DEBUG("end radio->web\n", len); return U_CALLBACK_COMPLETE; } @@ -345,7 +345,7 @@ char *read_file_into_string(const char *filename) { FILE *file = fopen(filename, "rb"); if (file == NULL) { - LOG_INFO("Fehler beim Öffnen der Datei\n"); + LOG_ERROR("Error reading File : %s \n", filename); return NULL; } @@ -357,7 +357,7 @@ char *read_file_into_string(const char *filename) // reserve mem for file + 1 byte char *buffer = (char *)malloc(filesize + 1); if (buffer == NULL) { - LOG_INFO("Speicherreservierung fehlgeschlagen\n"); + LOG_ERROR("Malloc of mem failed for file : %s \n", filename); fclose(file); return NULL; } @@ -365,7 +365,7 @@ char *read_file_into_string(const char *filename) // read content size_t readSize = fread(buffer, 1, filesize, file); if (readSize != filesize) { - LOG_INFO("Fehler beim Lesen der Datei\n"); + LOG_ERROR("Error reading file into buffer\n"); free(buffer); fclose(file); return NULL; @@ -382,13 +382,13 @@ int PiWebServerThread::CheckSSLandLoad() // read certificate cert_pem = read_file_into_string("certificate.pem"); if (cert_pem == NULL) { - LOG_INFO("ERROR SSL Certificate File can't be loaded\n"); + LOG_ERROR("ERROR SSL Certificate File can't be loaded or is missing\n"); return 1; } // read private key key_pem = read_file_into_string("private_key.pem"); if (key_pem == NULL) { - LOG_INFO("ERROR SSL Certificate File can't be loaded\n"); + LOG_ERROR("ERROR file private_key can't be loaded or is missing\n"); return 2; } @@ -402,19 +402,19 @@ int PiWebServerThread::CreateSSLCertificate() X509 *x509 = NULL; if (generate_rsa_key(&pkey) != 0) { - LOG_INFO("Error generating RSA-Key.\n"); + LOG_ERROR("Error generating RSA-Key.\n"); return 1; } if (generate_self_signed_x509(pkey, &x509) != 0) { - LOG_INFO("Error generating of X509-Certificat.\n"); + LOG_ERROR("Error generating of X509-Certificat.\n"); return 2; } // Ope file to write private key file FILE *pkey_file = fopen("private_key.pem", "wb"); if (!pkey_file) { - LOG_INFO("Error opening private key file.\n"); + LOG_ERROR("Error opening private key file.\n"); return 3; } // write private key file @@ -424,7 +424,7 @@ int PiWebServerThread::CreateSSLCertificate() // open Certificate file FILE *x509_file = fopen("certificate.pem", "wb"); if (!x509_file) { - LOG_INFO("Error opening certificate.\n"); + LOG_ERROR("Error opening certificate.\n"); return 4; } // write cirtificate @@ -446,13 +446,13 @@ PiWebServerThread::PiWebServerThread() if (CheckSSLandLoad() != 0) { CreateSSLCertificate(); if (CheckSSLandLoad() != 0) { - LOG_INFO("Major Error Gen & Read SSL Certificate\n"); + LOG_ERROR("Major Error Gen & Read SSL Certificate\n"); } } if (settingsMap[webserverport] != 0) { - LOG_INFO("Using webserver port from yaml config.\n"); webservport = settingsMap[webserverport]; + LOG_INFO("Using webserver port from yaml config. %i \n", webservport); } else { LOG_INFO("No webserver port found in yaml config using default port 80.\n"); webservport = 80; @@ -460,7 +460,7 @@ PiWebServerThread::PiWebServerThread() // Web Content Service Instance if (ulfius_init_instance(&instanceWeb, webservport, NULL, DEFAULT_REALM) != U_OK) { - LOG_INFO("Webserver couldn't be started, abort execution\n"); + LOG_ERROR("Webserver couldn't be started, abort execution\n"); } else { LOG_INFO("Webserver started ....\n"); @@ -506,7 +506,7 @@ PiWebServerThread::PiWebServerThread() LOG_INFO("Web Server framework srated on port: %i \n", webservport); LOG_INFO("Web Server root %s\n", (char *)webrootpath.c_str()); } else { - LOG_INFO("Error starting Web Server framework\n"); + LOG_ERROR("Error starting Web Server framework\n"); } } } From c52741ff03e5fa9aec9c88a4d5d1a53b62b7e8aa Mon Sep 17 00:00:00 2001 From: Marc Philipp Hammermann Date: Sat, 24 Feb 2024 03:32:43 +0100 Subject: [PATCH 11/22] Update Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 630c911f3e..32588d06c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Install build deps USER root RUN apt-get update && \ - apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev libg piod2 openssl libssl-dev libulfius-dev liborcania-dev bash + apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev libgpiod2 openssl libssl-dev libulfius-dev liborcania-dev bash # create a non-priveleged user & group RUN groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 mesh @@ -38,4 +38,4 @@ USER mesh WORKDIR /home/mesh CMD sh -cx "./meshtasticd_linux_x86_64 --hwid '${HWID:-$RANDOM}'" -HEALTHCHECK NONE \ No newline at end of file +HEALTHCHECK NONE From 27c8241b3cd7d8f3dac9160ac7b1b69406cabf5e Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Mon, 26 Feb 2024 15:12:31 +0100 Subject: [PATCH 12/22] Fix Typo & VFS ref. Part1 --- src/mesh/raspihttp/PiWebServer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mesh/raspihttp/PiWebServer.cpp b/src/mesh/raspihttp/PiWebServer.cpp index d6bfa5e277..3b54eb7b79 100644 --- a/src/mesh/raspihttp/PiWebServer.cpp +++ b/src/mesh/raspihttp/PiWebServer.cpp @@ -486,12 +486,13 @@ PiWebServerThread::PiWebServerThread() configWeb.files_path = (char *)webrootpath.c_str(); configWeb.url_prefix = ""; + configWeb.rootPath = strdup(portduinoVFS->mountpoint()); u_map_put(instanceWeb.default_headers, "Access-Control-Allow-Origin", "*"); // Maximum body size sent by the client is 1 Kb instanceWeb.max_post_body_size = 1024; ulfius_add_endpoint_by_val(&instanceWeb, "GET", PREFIX, "/api/v1/fromradio/*", 1, &handleAPIv1FromRadio, NULL); - ulfius_add_endpoint_by_val(&instanceWeb, "PUT", PREFIX, "/api/v1/toradio/*", 1, &handleAPIv1ToRadio, NULL); + ulfius_add_endpoint_by_val(&instanceWeb, "PUT", PREFIX, "/api/v1/toradio/*", 1, &handleAPIv1ToRadio, configWeb.rootPath); // Add callback function to all endpoints for the Web Server ulfius_add_endpoint_by_val(&instanceWeb, "GET", NULL, "/*", 2, &callback_static_file, &configWeb); @@ -503,7 +504,7 @@ PiWebServerThread::PiWebServerThread() retssl = ulfius_start_secure_framework(&instanceWeb, key_pem, cert_pem); if (retssl == U_OK) { - LOG_INFO("Web Server framework srated on port: %i \n", webservport); + LOG_INFO("Web Server framework started on port: %i \n", webservport); LOG_INFO("Web Server root %s\n", (char *)webrootpath.c_str()); } else { LOG_ERROR("Error starting Web Server framework\n"); From 5b626a77099e217d1f3939119dbb4a6dd2af33b9 Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Mon, 26 Feb 2024 15:14:36 +0100 Subject: [PATCH 13/22] Fix Typo & VFS ref. --- src/mesh/raspihttp/PiWebServer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mesh/raspihttp/PiWebServer.h b/src/mesh/raspihttp/PiWebServer.h index ccd3c71151..a9571d59d5 100644 --- a/src/mesh/raspihttp/PiWebServer.h +++ b/src/mesh/raspihttp/PiWebServer.h @@ -19,6 +19,7 @@ struct _file_config { struct _u_map mime_types; struct _u_map map_header; char *redirect_on_404; + char *rootPath; }; class PiWebServerThread From 04312cd73b91956469d8c56c026590a7cdbd3d15 Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Sun, 25 Feb 2024 01:17:45 +0100 Subject: [PATCH 14/22] Dev Version for ulfius web lib --- variants/portduino/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index c7cfb9d187..094a650e5f 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -1,6 +1,6 @@ [env:native] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -I /usr/include -lulfius -lorcania -lssl -lcrypto +build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -I /usr/include -lulfius-dev -lorcania -lssl -lcrypto board = cross_platform lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} \ No newline at end of file From 50280132190483a8da2fb08c565e009229ab40ba Mon Sep 17 00:00:00 2001 From: Marc Philipp Hammermann Date: Mon, 26 Feb 2024 16:05:28 +0100 Subject: [PATCH 15/22] Update platformio.ini --- variants/portduino/platformio.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index 094a650e5f..0d0ab397cf 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -1,6 +1,6 @@ [env:native] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -I /usr/include -lulfius-dev -lorcania -lssl -lcrypto +build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -I /usr/include -lulfius -lorcania -lssl -lcrypto board = cross_platform lib_deps = ${portduino_base.lib_deps} -build_src_filter = ${portduino_base.build_src_filter} \ No newline at end of file +build_src_filter = ${portduino_base.build_src_filter} From 3256442441efc14e14f89cba9c1585d474ae87d5 Mon Sep 17 00:00:00 2001 From: marc hammermann Date: Mon, 26 Feb 2024 15:58:04 +0100 Subject: [PATCH 16/22] Free VFS path string --- .gitignore | 4 +++- src/mesh/raspihttp/PiWebServer.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 4b5b346dcf..0f2202f8d4 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,6 @@ __pycache__ venv/ release/ .vscode/extensions.json -/compile_commands.json \ No newline at end of file +/compile_commands.json +src/mesh/raspihttp/certificate.pem +src/mesh/raspihttp/private_key.pem \ No newline at end of file diff --git a/src/mesh/raspihttp/PiWebServer.cpp b/src/mesh/raspihttp/PiWebServer.cpp index 3b54eb7b79..2e295ccaaa 100644 --- a/src/mesh/raspihttp/PiWebServer.cpp +++ b/src/mesh/raspihttp/PiWebServer.cpp @@ -518,7 +518,7 @@ PiWebServerThread::~PiWebServerThread() ulfius_stop_framework(&instanceWeb); ulfius_stop_framework(&instanceWeb); - + free(configWeb.rootPath); ulfius_clean_instance(&instanceService); ulfius_clean_instance(&instanceService); free(cert_pem); From 90e303a47fa7551d9b8d3052effd89cda17116df Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 6 Mar 2024 13:10:01 -0600 Subject: [PATCH 17/22] Remove unintended changes --- .vscode/extensions.json | 7 ++-- .vscode/settings.json | 72 +------------------------------- platformio.ini | 2 +- src/mesh/http/ContentHandler.cpp | 2 +- src/mesh/http/ContentHelper.cpp | 2 +- src/mesh/http/WebServer.h | 2 +- variants/portduino/variant.h | 2 +- 7 files changed, 9 insertions(+), 80 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 080e70d08b..4fc84fa780 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,9 +2,8 @@ // See http://go.microsoft.com/fwlink/?LinkId=827846 // for the documentation about the extensions.json format "recommendations": [ - "platformio.platformio-ide" + "ms-vscode.cpptools", + "platformio.platformio-ide", + "trunk.io" ], - "unwantedRecommendations": [ - "ms-vscode.cpptools-extension-pack" - ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 679c99dc83..03922dc72b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,75 +1,5 @@ { "editor.formatOnSave": true, "editor.defaultFormatter": "trunk.io", - "trunk.enableWindows": true, - "files.associations": { - "string": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "array": "cpp", - "atomic": "cpp", - "strstream": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "bitset": "cpp", - "chrono": "cpp", - "compare": "cpp", - "complex": "cpp", - "concepts": "cpp", - "condition_variable": "cpp", - "cstdint": "cpp", - "deque": "cpp", - "list": "cpp", - "map": "cpp", - "set": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "mutex": "cpp", - "new": "cpp", - "numbers": "cpp", - "ostream": "cpp", - "semaphore": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "stop_token": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "cinttypes": "cpp", - "typeindex": "cpp", - "typeinfo": "cpp", - "variant": "cpp" - } + "trunk.enableWindows": true } diff --git a/platformio.ini b/platformio.ini index d626c0ca5b..0033b6e469 100644 --- a/platformio.ini +++ b/platformio.ini @@ -129,4 +129,4 @@ lib_deps = adafruit/Adafruit PM25 AQI Sensor@^1.0.6 adafruit/Adafruit MPU6050@^2.2.4 adafruit/Adafruit LIS3DH@^1.2.4 - https://github.com/lewisxhe/BMA423_Library@^0.0.1 \ No newline at end of file + https://github.com/lewisxhe/BMA423_Library@^0.0.1 diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index 6debd7240f..7640e879c9 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -854,4 +854,4 @@ void handleScanNetworks(HTTPRequest *req, HTTPResponse *res) JSONValue *value = new JSONValue(jsonObjOuter); res->print(value->Stringify().c_str()); delete value; -} \ No newline at end of file +} diff --git a/src/mesh/http/ContentHelper.cpp b/src/mesh/http/ContentHelper.cpp index 2cca7008e0..8f283932b6 100644 --- a/src/mesh/http/ContentHelper.cpp +++ b/src/mesh/http/ContentHelper.cpp @@ -11,4 +11,4 @@ void replaceAll(std::string &str, const std::string &from, const std::string &to str.replace(start_pos, from.length(), to); start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx' } -} \ No newline at end of file +} diff --git a/src/mesh/http/WebServer.h b/src/mesh/http/WebServer.h index 1da8fadedd..815d87432d 100644 --- a/src/mesh/http/WebServer.h +++ b/src/mesh/http/WebServer.h @@ -19,4 +19,4 @@ class WebServerThread : private concurrency::OSThread virtual int32_t runOnce() override; }; -extern WebServerThread *webServerThread; \ No newline at end of file +extern WebServerThread *webServerThread; diff --git a/variants/portduino/variant.h b/variants/portduino/variant.h index 6fe858e255..f47b58afc2 100644 --- a/variants/portduino/variant.h +++ b/variants/portduino/variant.h @@ -1,3 +1,3 @@ #define HAS_SCREEN 1 #define CANNED_MESSAGE_MODULE_ENABLE 1 -#define HAS_GPS 1 \ No newline at end of file +#define HAS_GPS 1 From df1a828810b2ca0d66f14fbeaac3db6a7fe0f06a Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 6 Mar 2024 13:15:55 -0600 Subject: [PATCH 18/22] More unintentional changes --- .editorconfig | 0 bin/prepare-native.sh | 2 -- 2 files changed, 2 deletions(-) delete mode 100644 .editorconfig delete mode 100755 bin/prepare-native.sh diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bin/prepare-native.sh b/bin/prepare-native.sh deleted file mode 100755 index 570739ff51..0000000000 --- a/bin/prepare-native.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -sudo apt -y install openssl libssl-dev libsdl2-dev libulfius-dev liborcania-dev From 4a1b20a1900611953fd5b46b60c338d499bb890a Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 6 Mar 2024 13:57:32 -0600 Subject: [PATCH 19/22] Make the HTTP server optional on native --- src/main.cpp | 2 ++ src/mesh/raspihttp/PiWebServer.cpp | 2 ++ src/mesh/raspihttp/PiWebServer.h | 2 ++ variants/portduino/platformio.ini | 6 +++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 961e176cc3..03f444e1cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -858,7 +858,9 @@ void setup() #endif #ifdef ARCH_PORTDUINO +#if __has_include() piwebServerThread = new PiWebServerThread(); +#endif initApiServer(TCPPort); #endif diff --git a/src/mesh/raspihttp/PiWebServer.cpp b/src/mesh/raspihttp/PiWebServer.cpp index 2e295ccaaa..60a8a3e785 100644 --- a/src/mesh/raspihttp/PiWebServer.cpp +++ b/src/mesh/raspihttp/PiWebServer.cpp @@ -35,6 +35,7 @@ mail: marchammermann@googlemail.com */ #ifdef PORTDUINO_LINUX_HARDWARE +#if __has_include() #include "PiWebServer.h" #include "NodeDB.h" #include "PhoneAPI.h" @@ -525,4 +526,5 @@ PiWebServerThread::~PiWebServerThread() LOG_INFO("End framework"); } +#endif #endif \ No newline at end of file diff --git a/src/mesh/raspihttp/PiWebServer.h b/src/mesh/raspihttp/PiWebServer.h index a9571d59d5..c4c49e9197 100644 --- a/src/mesh/raspihttp/PiWebServer.h +++ b/src/mesh/raspihttp/PiWebServer.h @@ -1,5 +1,6 @@ #pragma once #ifdef PORTDUINO_LINUX_HARDWARE +#if __has_include() #include "PhoneAPI.h" #include "ulfius-cfg.h" #include "ulfius.h" @@ -56,4 +57,5 @@ class HttpAPI : public PhoneAPI extern PiWebServerThread *piwebServerThread; +#endif #endif \ No newline at end of file diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index 0d0ab397cf..46417e388e 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -1,6 +1,10 @@ [env:native] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -I /usr/include -lulfius -lorcania -lssl -lcrypto +; The pkg-config commands below optionally add link flags. +; the || : is just a "or run the null command" to avoid returning an error code +build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino -I /usr/include + !pkg-config --libs libulfius --silence-errors || : + !pkg-config --libs openssl --silence-errors || : board = cross_platform lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} From 0000ce5bfbeebc0793c358cf6ed68b84e549594a Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 6 Mar 2024 15:23:15 -0600 Subject: [PATCH 20/22] Tune-up for Native web defaults --- bin/config-dist.yaml | 4 ++-- src/main.cpp | 4 +++- src/mesh/raspihttp/PiWebServer.cpp | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 5f5a3b1bf3..a241a929a2 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -119,5 +119,5 @@ Logging: LogLevel: info # debug, info, warn, error Webserver: - Port: 9001 # Port for Webserver & Webservices - RootPath: /home/user/web # Root Dir of WebServer +# Port: 443 # Port for Webserver & Webservices +# RootPath: /usr/share/doc/meshtasticd/web # Root Dir of WebServer diff --git a/src/main.cpp b/src/main.cpp index 03f444e1cb..3619b0053a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -859,7 +859,9 @@ void setup() #ifdef ARCH_PORTDUINO #if __has_include() - piwebServerThread = new PiWebServerThread(); + if (settingsMap[webserverport] != -1) { + piwebServerThread = new PiWebServerThread(); + } #endif initApiServer(TCPPort); #endif diff --git a/src/mesh/raspihttp/PiWebServer.cpp b/src/mesh/raspihttp/PiWebServer.cpp index 60a8a3e785..41f6727a4b 100644 --- a/src/mesh/raspihttp/PiWebServer.cpp +++ b/src/mesh/raspihttp/PiWebServer.cpp @@ -455,8 +455,8 @@ PiWebServerThread::PiWebServerThread() webservport = settingsMap[webserverport]; LOG_INFO("Using webserver port from yaml config. %i \n", webservport); } else { - LOG_INFO("No webserver port found in yaml config using default port 80.\n"); - webservport = 80; + LOG_INFO("Webserver port in yaml config set to 0, so defaulting to port 443.\n"); + webservport = 443; } // Web Content Service Instance From 09fb7369d1daedb81b4a161d53d3371ba324adb9 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 6 Mar 2024 15:25:54 -0600 Subject: [PATCH 21/22] Don't modify build system yet --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 32588d06c6..21e42ad876 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Install build deps USER root RUN apt-get update && \ - apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev libgpiod2 openssl libssl-dev libulfius-dev liborcania-dev bash + apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev # create a non-priveleged user & group RUN groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 mesh @@ -38,4 +38,4 @@ USER mesh WORKDIR /home/mesh CMD sh -cx "./meshtasticd_linux_x86_64 --hwid '${HWID:-$RANDOM}'" -HEALTHCHECK NONE +HEALTHCHECK NONE \ No newline at end of file From 3970762e929298175b15f6ccd01da178d9fe9879 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 6 Mar 2024 15:55:05 -0600 Subject: [PATCH 22/22] Remove more unneeded changes --- arch/portduino/portduino.ini | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index 408c95218f..368fb5d0e3 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -24,14 +24,12 @@ lib_deps = ${env.lib_deps} ${networking_base.lib_deps} rweather/Crypto@^0.4.0 - https://github.com/lovyan03/LovyanGFX.git#develop - ;lovyan03/LovyanGFX@^1.1.12 + lovyan03/LovyanGFX@^1.1.12 build_flags = ${arduino_base.build_flags} -fPIC -Isrc/platform/portduino - -I/usr/include -DRADIOLIB_EEPROM_UNSUPPORTED -DPORTDUINO_LINUX_HARDWARE -lbluetooth