diff --git a/README.md b/README.md index 9f7da2b..31ad722 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# LoMeS +Meshtastic - +# LoMeS **LOcal MEshtastic Server** _in development_ Idea is to: -- develop an offline web app client and python backend, running in your local network and **nowhere** else. +- develop an offline Meshtastic server, running in your local network and **nowhere** else. - create a web app, coded in `html`, `css`, `js` and `php` and make it a bit prettier than the original. - code a backend utilising `flask`, `python`, `python3-meshtastic` and `python3-requests`. - make it as light but versatile as possible _let's see how this is gonna work out..._ @@ -26,9 +26,16 @@ for now everything will be developed and tested on Raspberry Pi 3B and newer act ## Development Setup 1. Flash Raspberry Pi OS lite 64bit -2. Install dependencies: +2. Install git: ```bash -sudo apt install --install-suggests -y nginx python3-meshtastic python3-flask python3-requests +sudo apt install -y git ``` -3. Configure `nginx` the way you need | _or use the example config located [here](https://lab.c95.org/fr4nz/LoMeS/src/branch/main/assets/config/nginx/nginx.conf) edit at least lines 9 & 15 - 18 to your needs_ -4. Start developing \ No newline at end of file +3. Clone repository +```bash +git clone https://lab.c95.org/fr4nz/LoMeS.git && cd LoMeS +``` +4. Run development environment setup +```bash +chmod +x lomes-setup.sh && sudo ./lomes-setup.sh +``` +5. Start developing \ No newline at end of file diff --git a/assets/config/deps/dependencies b/assets/config/deps/dependencies new file mode 100644 index 0000000..aebbc0c --- /dev/null +++ b/assets/config/deps/dependencies @@ -0,0 +1,2 @@ +#deps="openssl nginx nginx-common python3-meshtastic python3-flask python3-requests" +deps=("openssl" "nginx" "python3-meshtastic" "python3-flask" "python3-requests" "usbip" "python3-usb") \ No newline at end of file diff --git a/assets/config/flask/lomes-app.py b/assets/config/flask/lomes-app.py new file mode 100644 index 0000000..60ef82d --- /dev/null +++ b/assets/config/flask/lomes-app.py @@ -0,0 +1,12 @@ +#!/bin/python3 + +from flask import Flask, render_template + +app = Flask(__name__, static_folder="/var/www/html", static_url_path="/var/www/html", send_from_directory("data/images, lomes.svg")) + +@app.route("/") +def index(): + return app.send_static_file("index.html") + + +app.run(host="127.0.0.1", port=5000) \ No newline at end of file diff --git a/assets/config/nginx/nginx_HTTP.conf b/assets/config/nginx/nginx_HTTP.conf new file mode 100644 index 0000000..293b59a --- /dev/null +++ b/assets/config/nginx/nginx_HTTP.conf @@ -0,0 +1,14 @@ +########################################################### +### ### +### MESHPI NGINX CONFIG ### +### ### +########################################################### + +server { + listen 80; + server_name DOMAIN IPADDR; + + location / { + proxy_pass http://127.0.0.1:5000; + } +} diff --git a/assets/config/nginx/nginx.conf b/assets/config/nginx/nginx_SSL.conf similarity index 78% rename from assets/config/nginx/nginx.conf rename to assets/config/nginx/nginx_SSL.conf index b8d2141..a0323c0 100644 --- a/assets/config/nginx/nginx.conf +++ b/assets/config/nginx/nginx_SSL.conf @@ -14,8 +14,8 @@ server { listen 443 ssl; server_name DOMAIN IPADDR; - ssl_certificate /etc/nginx/ssl/CERTNAME.crt; - ssl_certificate_key /etc/nginx/ssl/CERTNAME.key; + ssl_certificate CERTPATH.crt; + ssl_certificate_key KEYPATH.key; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5; @@ -26,8 +26,6 @@ server { add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; location / { - try_files $uri $uri/ =404; - root /var/www/html; - index index.html; + proxy_pass http://127.0.0.1:5000; } } diff --git a/assets/images/Mesh_Logo_White.svg b/assets/images/Mesh_Logo_White.svg deleted file mode 100644 index b1bcd57..0000000 --- a/assets/images/Mesh_Logo_White.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/assets/images/favicon.ico b/assets/images/favicon.ico new file mode 100644 index 0000000..5ee2b1b --- /dev/null +++ b/assets/images/favicon.ico @@ -0,0 +1,57 @@ + + + + + + + + + + + diff --git a/assets/images/lomes.png b/assets/images/lomes.png new file mode 100644 index 0000000..866e824 Binary files /dev/null and b/assets/images/lomes.png differ diff --git a/assets/images/lomes.svg b/assets/images/lomes.svg new file mode 100644 index 0000000..a9886b3 --- /dev/null +++ b/assets/images/lomes.svg @@ -0,0 +1,57 @@ + + + + + + + + + + + diff --git a/assets/notes/FrontToBackend.md b/assets/notes/FrontToBackend.md index 84285ea..849906d 100644 --- a/assets/notes/FrontToBackend.md +++ b/assets/notes/FrontToBackend.md @@ -1,3 +1,11 @@ +[CRUD REST API](https://youtu.be/I07FyMH1DzI) + +--- + +[Meshtastic Python API Documentation](https://python.meshtastic.org/) + +--- + To send commands from a Python script to a web server, you can use HTTP requests. The requests library is a popular and user-friendly option for making HTTP calls in Python. For example, you can send a POST request with data to a specific URL: diff --git a/assets/notes/notes.md b/assets/notes/notes.md index 977af73..df5b017 100644 --- a/assets/notes/notes.md +++ b/assets/notes/notes.md @@ -1,7 +1,7 @@ # Notes ## To Do -1. [ ] define actions and plan -2. [ ] create simple web interface with flask and nginx +1. [x] define actions and plan +2. [ ] create setup script 3. [ ] communicate with Meshtastic device via web interface ## Follow up @@ -18,4 +18,88 @@ ### Backend - Environment setup script in development -### Frontend \ No newline at end of file +### Frontend + +### Thoughts +- Play with usbip + +To establish a connection between a website and a USB device connected to a Linux server, you cannot directly connect a web application to a USB device over a network using standard web protocols. However, you can achieve this functionality by creating a bridge between the web application and the USB device using a local service on the Linux server. Here’s how: + +1. Use USB/IP to Share the USB Device Over the Network: The USB/IP project allows you to share a physical USB device connected to a Linux server over a TCP/IP network, making it appear as a local USB device on a client machine. This is the most direct method for network access. + - On the Server (where the USB device is physically connected): + - Install the usbip package. + - Load the required kernel modules: usbip_core and usbip_host by creating a `.conf` file in `/etc/modules-load.d/` and adding the modules. + - Start and enable the usbipd.service daemon. + - List the available USB devices using usbip list -l to find the device's bus ID. + - Bind the specific USB device to the USB/IP service using usbip bind -b . This makes the device available for remote access. + - On the Client (the machine running the web application): + - Ensure the vhci_hcd kernel module is loaded. + - List the available devices from the server using usbip list -r . + - Attach the device to the client using usbip attach -r -b . Once attached, the device will appear as a local USB device on the client machine. +2. Integrate the Attached Device with Your Web Application: Once the USB device is attached to the client machine via USB/IP, it will be accessible to any software running on that machine, including a web application. The web application can then communicate with the device using standard USB communication libraries (e.g., libusb for C/C++, pyusb for Python) just as if the device were directly connected to the client machine. The web server (e.g., Apache, Nginx) and the application framework (e.g., Node.js, Django) on the client machine handle the web interface, while the application code uses the local USB device. +3. Alternative: Use a Local Service (e.g., a Web API): Instead of attaching the device to the web server machine, you can create a separate local service (a daemon or a small application) on the server that communicates directly with the USB device. This service can then expose a simple HTTP API (e.g., using a lightweight framework like Flask or Express) that the web application can call to send commands to or receive data from the USB device. This approach keeps the USB device connection confined to the server and uses standard web protocols for communication. + +In summary, the most practical approach is to use USB/IP to make the USB device appear as a local device on the machine hosting the web application, allowing the application to interact with it directly through standard USB libraries. + +### Troubble Shooting + +**usbip: error: could not connect to 192.168.1.8:3240: System error** adjust firewall? `vhci_hcd` on client machine? + +So for the daemon - /etc/systemd/system/usbipd.service +``` +[Unit] +Description=usbip host daemon +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +Restart=always +ExecStartPre=/usr/sbin/modprobe usbip-core +ExecStartPre=/usr/sbin/modprobe usbip-host +ExecStart=/usr/sbin/usbipd +ExecStopPost=/usr/sbin/rmmod usbip-host +ExecStopPost=/usr/sbin/rmmod usbip-core + +[Install] +WantedBy=multi-user.target +``` + +And the template for the binds - /etc/systemd/system/usbip-bind@.service + +``` +[Unit] +Description=Bind USB device to usbipd +After=network-online.target usbipd.service +Wants=network-online.target usbipd.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/sbin/usbip bind --busid %i +ExecStop=/usr/sbin/usbip unbind --busid %i + +[Install] +WantedBy=multi-user.target +``` + +Enable and start the daemon with: +``` +systemctl enable usbipd +systemctl start usbuipd +``` + +Then add binds with: + +``` +systemctl enable usbip-bind@1-1.2.3 +systemctl start usbip-bind@1-1.2.3 +``` +Replace 1-1.2.3 with the bind id of the USB device you want to share. You can use as many of these as devices you want to share and you can then bind and unbind each one individually and have then bind at machine startup (or not). + +Find the bind ids with: + +`usbip list -l` +Note that usbip binds seem to expire if not attached by a remote machine within around 10 mins - not very helpful! + +I haven't yet decided how I'm going to tackle the client attach, possibly not with systemd. It would be really helpful if usbip had a bit more intelligence... \ No newline at end of file diff --git a/assets/shell/shell_colors b/assets/shell/colors similarity index 100% rename from assets/shell/shell_colors rename to assets/shell/colors diff --git a/assets/test/test.sh b/assets/test/test.sh index 1fb107a..209beee 100755 --- a/assets/test/test.sh +++ b/assets/test/test.sh @@ -1,99 +1,60 @@ #!/bin/bash -source assets/shell/shell_colors + +source assets/shell/colors +source assets/config/deps/dependencies + ### DEPENDENCY CHECK & INSTALLER -pkgs="openssl nginx" - -echo -e "\n${CYN} Dependency and Privilege Check running...${CRS}\n" +echo -e "\n ${LCY}Dependency and Privilege Check running...${CRS}\n" ### PRIVILEGES -if (( $(id -u) == 0 )); then - echo -e "${GRN} Privilege check passed...${CRS}\n" +if (( $(id -u) == 0 )); then ### AM I ROOT? + echo -e " ${GRN}Privilege check passed...${CRS}\n" else - echo -e "${RED} Privilege check failed... Please run script with sudo or as root!${CRS}\n" + echo -e " ${RED}Privilege check failed... Please run script with sudo or as root!${CRS}\n" exit 1 fi ### DEPENDENCIES + +dep_check() { + local pkg="$1" -if command -v "$pkgs" >/dev/null 2>&1; then - echo -e "${GRN} Dependency check passed...${CRS}\n" - + if dpkg -s "$pkg" >/dev/null 2>&1; then + echo "$pkg" >>/tmp/installed_dev + else + echo "$pkg" >>/tmp/missing_dev + fi +} + +for pkg in "${deps[@]}"; do + dep_check "$pkg" +done + +installed="$(cat /tmp/installed_dev 2>/dev/null)" +missing="$(cat /tmp/missing_dev 2>/dev/null)" + +if ! [ "$missing" ]; then + echo -e "\n ${GRN}Dependencies met. Proceeding...${CRS}\n" else - echo -e "${YEL} Dependencies not met.${CRS}\n" - + echo -e "\n ${RED}Following dependencies are missing :${CRS}\n\n$missing" while true; do - echo -e " ${YEL}Do you wish to install via APT? (${GRN}Y${YEL}/${RED}n${YEL})${CRS}" - read -p " --> " install - echo "" - if [[ "$install" = "" || "$install" = "y" || "$install" = "Y" ]]; then - sudo apt update && sudo apt install --install-suggests -y $pkgs --simulate ## DEV - echo -e "\n${GRN} Dependencies installed. Proceeding...${CRS}\n" - break - - elif [[ "$install" == "n" || "$install" = "N" ]]; then - echo -e "\n${RED} Missing dependencies... Exiting!${CRS}\n" + echo -e "\n ${YEL}Do you wish to install via APT?" + read -p " (Y/n) --> " install_dep + echo -e "${CRS}" + if [[ "$install_dep" = "" || "$install_dep" = "y" || "$install_dep" = "Y" ]]; then + sudo apt update && sudo apt install -y $missing --simulate + echo -e "\n ${GRN}Dependencies installed. Proceeding...${CRS}\n" + sudo rm /tmp/installed_dev /tmp/missing_dev 2>/dev/null + break + elif [[ "$install_dep" == "n" || "$install_dep" = "N" ]]; then + echo -e "\n ${RED}Missing dependencies... Exiting!${CRS}\n" + sudo rm /tmp/installed_dev /tmp/missing_dev 2>/dev/null exit 1 - else - echo -e "\n${YEL} Invalid response... Try again...\n\n ${GRN}Y ${YEL}= (Yes, install dependencies and continue)\n ${RED}N ${YEL}= (No, don't install dependencies and exit)${CRS}\n " + echo -e "\n ${YEL}Invalid response... Try again...\n\n ${GRN}Y ${YEL}= (Yes, install dependencies and continue)\n ${RED}N ${YEL}= (No, don't install dependencies and exit)${CRS}\n " fi done -fi - -### NGINX SETUP & CONFIG - -###### CERTIFICATION - -while true; do - echo -e " ${YEL}Configure SSL and create a self signed cetrificate? (Y/n)${CRS}" - read -p " --> " installSSL - if [[ "$installSSL" = "" || "$installSSL" = "y" || "$installSSL" = "Y" ]]; then - echo -e " ${YEL}Enter path to certificates folder${CRS}" - read -p " default = /etc/nginx/ssl --> " cert_path - if ! [ "$cert_path" ]; then - cert_path=/etc/nginx/ssl - elif [[ "$cert_path" = "." ]]; then - cert_path=$PWD - else - : - fi - echo "" - echo -e " ${YEL}Enter file name for certificate and key${CRS}" - read -p " default --> $HOSTNAME --> " cert_name - if ! [ "$cert_name" ]; then - cert_name=$HOSTNAME - else - : - fi - echo "" - sudo mkdir -p "$cert_path" - sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "$cert_path"/"$cert_name".key -out "$cert_path"/"$cert_name".crt - echo -e "\n${GRN} SSL certificate files ${YEL}$cert_name.crt ${GRN}and ${YEL}$cert_name.key ${GRN}created and stored in ${YEL}$cert_path${CRS}\n" - break - elif [[ "$installSSL" == "n" || "$installSSL" = "N" ]]; then - echo -e "\n${RED} No encryption established${CRS}\n" - break - else - echo -e "\n${YEL} Invalid response... Try again...\n\nY = (Yes, configure SSL certificate and continue)\nN = (No, leave unencrypted and continue)${CRS}\n " - fi - done - - -echo -e "${YEL} Your current hostname is ${CYN}$HOSTNAME${CRS} would you like to change it?${CRS}" - -# ask for network interface & get IP -# ask to change hostname in /etc/hosts & /etc/hostname - -### DEV STATUS - -#sudo cp -R assets/config/nginx/nginx.conf /etc/nginx/sites-enabled/ -## JEFF -# utilise sed to edit config -# test nginx config -# restart nginx -## JEFF END - -echo -e "${GRN}\nScript ran through...${CRS}" +fi \ No newline at end of file diff --git a/dev_env_setup.sh b/dev_env_setup.sh deleted file mode 100755 index 2a5fd13..0000000 --- a/dev_env_setup.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash -source assets/shell/shell_colors -### DEPENDENCY CHECK & INSTALLER - -pkgs="openssl nginx" - -echo -e "\n${CYN} Dependency and Privilege Check running...${CRS}\n" - -### PRIVILEGES - -if (( $(id -u) == 0 )); then - echo -e "${GRN} Privilege check passed...${CRS}\n" - -else - echo -e "${RED} Privilege check failed... Please run script with sudo or as root!${CRS}\n" - exit 1 -fi - -### DEPENDENCIES - -if command -v "$pkgs" >/dev/null 2>&1; then - echo -e "${GRN} Dependency check passed...${CRS}\n" - -else - echo -e "${YEL} Dependencies not met.${CRS}\n" - - while true; do - echo -e " ${YEL}Do you wish to install via APT? (${GRN}Y${YEL}/${RED}n${YEL})${CRS}" - read -p " --> " install - echo "" - if [[ "$install" = "" || "$install" = "y" || "$install" = "Y" ]]; then - sudo apt update && sudo apt install --install-suggests -y $pkgs --simulate ## DEV - echo -e "\n${GRN} Dependencies installed. Proceeding...${CRS}\n" - break - - elif [[ "$install" == "n" || "$install" = "N" ]]; then - echo -e "\n${RED} Missing dependencies... Exiting!${CRS}\n" - exit 1 - - else - echo -e "\n${YEL} Invalid response... Try again...\n\n ${GRN}Y ${YEL}= (Yes, install dependencies and continue)\n ${RED}N ${YEL}= (No, don't install dependencies and exit)${CRS}\n " - fi - done -fi - -### NGINX SETUP & CONFIG - -###### CERTIFICATION - -while true; do - echo -e " ${YEL}Configure SSL and create a self signed cetrificate? (Y/n)${CRS}" - read -p " --> " installSSL - if [[ "$installSSL" = "" || "$installSSL" = "y" || "$installSSL" = "Y" ]]; then - echo -e " ${YEL}Enter path to certificates folder${CRS}" - read -p " default = /etc/nginx/ssl --> " cert_path - if ! [ "$cert_path" ]; then - cert_path=/etc/nginx/ssl - elif [[ "$cert_path" = "." ]]; then - cert_path=$PWD - else - : - fi - echo "" - echo -e " ${YEL}Enter file name for certificate and key${CRS}" - read -p " default --> $HOSTNAME --> " cert_name - if ! [ "$cert_name" ]; then - cert_name=$HOSTNAME - else - : - fi - echo "" - sudo mkdir -p "$cert_path" - sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "$cert_path"/"$cert_name".key -out "$cert_path"/"$cert_name".crt - echo -e "\n${GRN} SSL certificate files ${YEL}$cert_name.crt ${GRN}and ${YEL}$cert_name.key ${GRN}created and stored in ${YEL}$cert_path${CRS}\n" - break - elif [[ "$installSSL" == "n" || "$installSSL" = "N" ]]; then - echo -e "\n${RED} No encryption established${CRS}\n" - break - else - echo -e "\n${YEL} Invalid response... Try again...\n\nY = (Yes, configure SSL certificate and continue)\nN = (No, leave unencrypted and continue)${CRS}\n " - fi - done diff --git a/lomes-app.py b/lomes-app.py new file mode 100755 index 0000000..a8260e7 --- /dev/null +++ b/lomes-app.py @@ -0,0 +1,21 @@ +#!/bin/python3 + +from flask import Flask, render_template +import datetime +import getpass +import os + +app = Flask(__name__) + +@app.route("/") +def index(): + user = getpass.getuser() + preTime = datetime.datetime.now() + time = preTime.strftime("%H:%M:%S - %a %d.%m.%Y") + uname_fields = ("System", "Hostname", "Kernel") + uname_info = os.uname() + sysinfo = "\n".join(f"{field}: {value} | " for field, value in zip(uname_fields, uname_info)) + + return render_template("index.html", user=user, time=time, sysinfo=sysinfo) + +app.run(host="127.0.0.1", port=5000, debug=True) \ No newline at end of file diff --git a/lomes-setup.sh b/lomes-setup.sh new file mode 100755 index 0000000..4c93cd5 --- /dev/null +++ b/lomes-setup.sh @@ -0,0 +1,276 @@ +#!/bin/bash +trap "exit" INT + +chmod +x lomes-app.py +mkdir -p /tmp/LoMeS +source assets/shell/colors +source assets/config/deps/dependencies + +### DEPENDENCY CHECK & INSTALLER + +echo -e "\n ${LCY}Dependency and Privilege Check running...${CRS}\n" + +### PRIVILEGES + +if (( $(id -u) == 0 )); then ### AM I ROOT ? + echo -e " ${LCY}- ${GRN}Privilege check passed...${CRS}\n" + +else + echo -e " ${LCY}- ${RED}Privilege check failed... Please run script with sudo or as root!${CRS}\n" + exit 1 + +fi + +### DEPENDENCIES + +dep_check() { ### MISSING PKGS ? + local pkg="$1" + + if dpkg -s "$pkg" >/dev/null 2>&1; then + echo "$pkg" >>/tmp/LoMeS/installed_dev + + else + echo "$pkg" >>/tmp/LoMeS/missing_dev + + fi +} + +for pkg in "${deps[@]}"; do + dep_check "$pkg" + +done + +installed="$(cat /tmp/LoMeS/installed_dev 2>/dev/null)" +missing="$(cat /tmp/LoMeS/missing_dev 2>/dev/null)" + +if ! [ "$missing" ]; then + echo -e " ${LCY}- ${GRN}Dependencies met. Proceeding...${CRS}\n" + +else ### INSTALLING PKGS ! + echo -e " ${LCY}- ${RED}Following dependencies are missing :\n\n$missing${CRS}" + + while true; do + echo -e "\n ${YEL}Do you wish to install via APT?" + read -p " (Y/n) --> " install_dep + echo -e "${CRS}" + + if [[ "$install_dep" = "" || "$install_dep" = "y" || "$install_dep" = "Y" ]]; then + sudo apt update > /dev/null 2>&1 && sudo apt install -y $missing --simulate > /dev/null 2>&1 + echo -e " ${LCY}- ${GRN}Dependencies installed. Proceeding...${CRS}\n" + sudo rm /tmp/LoMeS/installed_dev /tmp/LoMeS/missing_dev 2>/dev/null + break + + elif [[ "$install_dep" == "n" || "$install_dep" = "N" ]]; then + echo -e " ${RED}Missing dependencies... Exiting!${CRS}\n" + sudo rm /tmp/LoMeS/installed_dev /tmp/LoMeS/missing_dev 2>/dev/null + exit 1 + + else + echo -e " ${YEL}Invalid response... Try again...\n\n ${GRN}Y ${YEL}= (Yes, install dependencies and continue)\n ${RED}N ${YEL}= (No, don't install dependencies and exit)${CRS}\n " + + fi + done +fi + +### NGINX SETUP & CONFIG + +###### CONNECTION & INTERFACE + +onif=$(/sbin/ip route get 162.249.72.1 | awk '{print $5}' | cut -d/ -f1) + +while true; do ### SELECT NETWORK INTERFACE ! + echo -e " ${YEL}What network interface will nginx be using?" + read -p " current = "$onif" --> " nif + echo -e "${CRS}" + + if ! [ "$nif" ]; then + nif="$onif" + break + + elif [ -d "/sys/class/net/$nif" ]; then + break + + else + echo -e "\n ${LRD}Interface not found... Try again!${CRS}\n" + + fi +done + +ip4=$(/sbin/ip -o -4 addr list "$nif" | awk '{print $4}' | cut -d/ -f1) ### GET IP FOR CHOSEN INTERFACE ! +echo -e "\n ${YEL}Current hostname : ${LCY}$(hostname)${CRS}" +echo -e " ${YEL}Current ip address : ${LCY}$ip4 ${YEL}@ ${LCY}$nif${CRS}" +echo -e "\n ${YEL}This information will be used to configure ${LCY}nginx.conf ${YEL}during the next steps." + +while true; do ### HOST NAME CHANGE ? + read -p " Would you like to change the hostname? (y/N) --> " conf_hostname + echo -e "${CRS}" + + if [[ "$conf_hostname" = "" || "$conf_hostname" = "n" || "$conf_hostname" = "N" ]]; then + new_hostname=$(hostname) + break + + elif [[ "$conf_hostname" = "y" || "$conf_hostname" = "Y" ]]; then + read -p " Enter new hostname --> " new_hostname + sudo sed -i.backup "s/$(hostname)/$new_hostname/g" /etc/hosts + sudo echo "$new_hostname" > /etc/hostname + sudo systemctl restart NetworkManager 2>/dev/null + hostname -F /etc/hostname 2>/dev/null + echo -e "\n ${GRN}Host name changed to ${LCY}$(hostname)${CRS}" + echo "HC" > /tmp/LoMeS/honacha + break + + else + echo -e "\n ${YEL}Invalid response... Try again...\n\n Y = (Yes, set new hostname)\n N = (No, leave as is)${CRS}\n " + + fi +done + +while true; do ### CERTIFICATION & CONFIGURATION HTTPS + echo -e "\n ${YEL}Configure nginx with SSL and create a self signed cetrificate?" + read -p " (Y/n) --> " nginxSSL + echo -e "${CRS}" + + if [[ "$nginxSSL" = "" || "$nginxSSL" = "y" || "$nginxSSL" = "Y" ]]; then + echo -e " ${YEL}Enter path to certificates folder" + read -p " default = /etc/nginx/ssl --> " cert_path + echo -e "${CRS}" + + if ! [ "$cert_path" ]; then + cert_path=/etc/nginx/ssl + + elif [[ "$cert_path" = "." ]]; then + cert_path=$PWD + + else + : + + fi + echo -e " ${YEL}Enter file name for certificate and key" + read -p " default = $(hostname) --> " cert_name + echo -e "${CRS}" + + if ! [ "$cert_name" ]; then + cert_name=$(hostname) + + else + : + + fi + sudo mkdir -p "$cert_path" + sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "$cert_path"/"$cert_name".key -out "$cert_path"/"$cert_name".crt + echo -e "\n ${GRN}SSL certificate files ${LCY}$cert_name.crt ${GRN}and ${LCY}$cert_name.key ${GRN}created and stored in ${LCY}$cert_path${CRS}" + sudo chmod 644 "$cert_path"/"$cert_name".crt + sudo chmod 600 "$cert_path"/"$cert_name".key + sudo cp assets/config/nginx/nginx_SSL.conf /etc/nginx/sites-enabled/$(hostname).conf + sudo sed -i "s/DOMAIN/$(hostname).local/g" /etc/nginx/sites-enabled/$(hostname).conf + sudo sed -i "s/IPADDR/$ip4/g" /etc/nginx/sites-enabled/$(hostname).conf + sudo sed -i "s|CERTPATH|$cert_path/$cert_name|" /etc/nginx/sites-enabled/$(hostname).conf + sudo sed -i "s|KEYPATH|$cert_path/$cert_name|" /etc/nginx/sites-enabled/$(hostname).conf + break + + elif [[ "$nginxSSL" == "n" || "$nginxSSL" = "N" ]]; then + while true; do ### CONFIGURATION HTTP + echo -e " ${YEL}Configure nginx with HTTP?" + read -p " (Y/n) --> " nginxHTTP + echo -e "${CRS}" + + if [[ "$nginxHTTP" = "" || "$nginxHTTP" = "y" || "$nginxHTTP" = "Y" ]]; then + sudo cp assets/config/nginx/nginx_HTTP.conf /etc/nginx/sites-enabled/$(hostname).conf + sudo sed -i "s/DOMAIN/$(hostname).local/g" /etc/nginx/sites-enabled/$(hostname).conf + sudo sed -i "s/IPADDR/$ip4/g" /etc/nginx/sites-enabled/$(hostname).conf + break + + elif [[ "$nginxHTTP" = "n" || "$nginxHTTP" = "N" ]]; then + echo -e " ${LCY}- ${LRD}Keeping nginx default configuration!${CRS}" + break + + else + echo -e " ${YEL}Invalid response... Try again...\n\n Y = (Yes, configure nginx)\n N = (No, skip nginx configuration)${CRS}\n " + break + + fi + done + break + + else + echo -e "\n ${YEL}Invalid response... Try again...\n\n Y = (Yes, configure SSL certificate and continue)\n N = (No, leave unencrypted and continue)${CRS}\n " + + fi +done + +###### NGINX MAINTENANCE + +sudo rm -rf /var/www/html + +if ! [ "$(sudo nginx -t > /dev/null 2>&1)" ]; then ### NGINX CONF CHECK + echo -e "\n ${LCY}- ${LGN}Nginx configuration checks out...${CRS}" + +else + echo -e "\n ${LRD}Nginx configuration is malformed!${CRS}" + echo "nginx -t --> failed" >> /tmp/LoMeS/install_log +fi + +if ! [ "$(sudo nginx -s reload > /dev/null 2>&1)" ]; then ### RELOAD NGINX + echo -e "\n ${LCY}- ${LGN}Nginx reloaded...${CRS}" + +else + echo -e "\n ${LRD}Nginx couldn't reload!${CRS}" + echo "nginx -s reload --> failed" >> /tmp/LoMeS/install_log +fi + +if ! [ -f "/tmp/LoMeS/install_log" ]; then ### LOG CHECK + echo -e "\n ${LCY}- ${LGN}No errors while setting up...${CRS}" + +else + echo -e "\n ${LRD}Error occured during setup! Please check ${LCY}/tmp/LoMeS/install_log ${LRD}for details...${CRS}" + +fi + +if [ -f "/tmp/LoMeS/honacha" ]; then ### REBOOT DUE TO HOST NAME CHANGE + echo -e "\n ${YEL}During setup you changed this machines host name. For the change to take effect, you should reboot! " + + while true; do + read -p " Would you like to reboot? (Y/n) --> " reboot + echo -e "${CRS}" + + if [[ "$reboot" = "" || "$reboot" = "y" || "$reboot" = "Y" ]]; then + echo -e " ${YEL}Rebooting in 10sec..." + echo -e " ${YEL}to start flask manually, run ${LCY}python3 lomes-app.py ${YEL}from LoMeS directory${CRS}" + sleep 10s + sudo reboot + + elif [[ "$reboot" = "n" || "$reboot" = "N" ]]; then + echo -e " ${YEL}to start flask manually, run ${LCY}python3 lomes-app.py ${YEL}from LoMeS directory${CRS}" + break + + else + echo -e "\n ${YEL}Invalid response... Try again...\n\n Y = (Yes, reboot)\n N = (No, don't reboot)${CRS}\n " + + fi + done + +else + + while true; do + echo -e "${YEL}" ### START FLASK ? + read -p " Would you like to start flask? (Y/n) --> " flask_start + echo -e "${CRS}" + + if [[ "$flask_start" = "" || "$flask_start" = "y" || "$flask_start" = "Y" ]]; then + echo -e " ${YEL}Starting flask in 10sec..." + echo -e " ${YEL}to start flask manually, run ${LCY}python3 lomes-app.py ${YEL}from LoMeS directory${CRS}\n" + sleep 10s + python3 lomes-app.py + break + + elif [[ "$flask_start" = "n" || "$flask_start" = "N" ]]; then + echo -e " ${YEL}to start flask manually, run ${LCY}python3 lomes-app.py ${YEL}from LoMeS directory${CRS}\n" + break + + else + echo -e "\n ${YEL}Invalid response... Try again...\n\n Y = (Yes, to start flask)\n N = (No, start flask later)${CRS}\n " + + fi + done + +fi diff --git a/static/css/style.css b/static/css/style.css new file mode 100644 index 0000000..700a19e --- /dev/null +++ b/static/css/style.css @@ -0,0 +1,146 @@ +*{ + margin: 0; + padding: 0; + font-family: Gravity; +} + +@font-face { + font-family: 'Gravity'; + src: url('font/Gravity-UltraLight.woff2') format('woff2'), + url('font/Gravity-UltraLight.woff') format('woff'); + font-weight: 200; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Gravity'; + src: url('font/Gravity-Light.woff2') format('woff2'), + url('font/Gravity-Light.woff') format('woff'); + font-weight: 300; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Gravity'; + src: url('font/Gravity-Bold.woff2') format('woff2'), + url('font/Gravity-Bold.woff') format('woff'); + font-weight: bold; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Gravity'; + src: url('font/Gravity-LightItalic.woff2') format('woff2'), + url('font/Gravity-LightItalic.woff') format('woff'); + font-weight: 300; + font-style: italic; + font-display: swap; +} + +@font-face { + font-family: 'Gravity'; + src: url('font/Gravity-Italic.woff2') format('woff2'), + url('font/Gravity-Italic.woff') format('woff'); + font-weight: normal; + font-style: italic; + font-display: swap; +} + +@font-face { + font-family: 'Gravity Book'; + src: url('font/Gravity-Book.woff2') format('woff2'), + url('font/Gravity-Book.woff') format('woff'); + font-weight: normal; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Gravity'; + src: url('font/Gravity-BoldItalic.woff2') format('woff2'), + url('font/Gravity-BoldItalic.woff') format('woff'); + font-weight: bold; + font-style: italic; + font-display: swap; +} + +@font-face { + font-family: 'Gravity Book'; + src: url('font/Gravity-BookItalic.woff2') format('woff2'), + url('font/Gravity-BookItalic.woff') format('woff'); + font-weight: normal; + font-style: italic; + font-display: swap; +} + +@font-face { + font-family: 'Gravity'; + src: url('font/Gravity-Regular.woff2') format('woff2'), + url('font/Gravity-Regular.woff') format('woff'); + font-weight: normal; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Gravity'; + src: url('font/Gravity-UltraLightItalic.woff2') format('woff2'), + url('font/Gravity-UltraLightItalic.woff') format('woff'); + font-weight: 200; + font-style: italic; + font-display: swap; +} + +body { + background-color: darkslategrey; +} + +header { + display: flex; + align-items: center; + justify-content: center; + padding-top: 30px; +} + +.icon { + height: 80px; +} + +.textBox { + padding-top: 20px; +} + +h1 { + font-size: 26px; + padding: 5px; + padding-bottom: 10px; + text-align: center; + color: lightgray; +} + +h3 { + font-size: 20px; + padding: 5px; + padding-bottom: 10px; + text-align: center; + color: lightgray; +} + +p { + font-size: 16px; + padding: 5px; + padding-bottom: 10px; + text-align: center; + color: lightgray; +} + +li { + font-size: 16px; + padding: 5px; + padding-bottom: 10px; + text-align: center; + color: lightgray; +} diff --git a/static/font/Gravity-Bold.woff b/static/font/Gravity-Bold.woff new file mode 100644 index 0000000..bd94496 Binary files /dev/null and b/static/font/Gravity-Bold.woff differ diff --git a/static/font/Gravity-Bold.woff2 b/static/font/Gravity-Bold.woff2 new file mode 100644 index 0000000..d3dfc2b Binary files /dev/null and b/static/font/Gravity-Bold.woff2 differ diff --git a/static/font/Gravity-BoldItalic.woff b/static/font/Gravity-BoldItalic.woff new file mode 100644 index 0000000..674ef3e Binary files /dev/null and b/static/font/Gravity-BoldItalic.woff differ diff --git a/static/font/Gravity-BoldItalic.woff2 b/static/font/Gravity-BoldItalic.woff2 new file mode 100644 index 0000000..7489325 Binary files /dev/null and b/static/font/Gravity-BoldItalic.woff2 differ diff --git a/static/font/Gravity-Book.woff b/static/font/Gravity-Book.woff new file mode 100644 index 0000000..ae705ec Binary files /dev/null and b/static/font/Gravity-Book.woff differ diff --git a/static/font/Gravity-Book.woff2 b/static/font/Gravity-Book.woff2 new file mode 100644 index 0000000..5e90874 Binary files /dev/null and b/static/font/Gravity-Book.woff2 differ diff --git a/static/font/Gravity-BookItalic.woff b/static/font/Gravity-BookItalic.woff new file mode 100644 index 0000000..5e1d14c Binary files /dev/null and b/static/font/Gravity-BookItalic.woff differ diff --git a/static/font/Gravity-BookItalic.woff2 b/static/font/Gravity-BookItalic.woff2 new file mode 100644 index 0000000..4752f17 Binary files /dev/null and b/static/font/Gravity-BookItalic.woff2 differ diff --git a/static/font/Gravity-Italic.woff b/static/font/Gravity-Italic.woff new file mode 100644 index 0000000..8b23e2a Binary files /dev/null and b/static/font/Gravity-Italic.woff differ diff --git a/static/font/Gravity-Italic.woff2 b/static/font/Gravity-Italic.woff2 new file mode 100644 index 0000000..83d4e4c Binary files /dev/null and b/static/font/Gravity-Italic.woff2 differ diff --git a/static/font/Gravity-Light.woff b/static/font/Gravity-Light.woff new file mode 100644 index 0000000..fbd80fb Binary files /dev/null and b/static/font/Gravity-Light.woff differ diff --git a/static/font/Gravity-Light.woff2 b/static/font/Gravity-Light.woff2 new file mode 100644 index 0000000..a0f022d Binary files /dev/null and b/static/font/Gravity-Light.woff2 differ diff --git a/static/font/Gravity-LightItalic.woff b/static/font/Gravity-LightItalic.woff new file mode 100644 index 0000000..b30c6c0 Binary files /dev/null and b/static/font/Gravity-LightItalic.woff differ diff --git a/static/font/Gravity-LightItalic.woff2 b/static/font/Gravity-LightItalic.woff2 new file mode 100644 index 0000000..4b1015f Binary files /dev/null and b/static/font/Gravity-LightItalic.woff2 differ diff --git a/static/font/Gravity-Regular.woff b/static/font/Gravity-Regular.woff new file mode 100644 index 0000000..975db9c Binary files /dev/null and b/static/font/Gravity-Regular.woff differ diff --git a/static/font/Gravity-Regular.woff2 b/static/font/Gravity-Regular.woff2 new file mode 100644 index 0000000..0c8b99e Binary files /dev/null and b/static/font/Gravity-Regular.woff2 differ diff --git a/static/font/Gravity-UltraLight.woff b/static/font/Gravity-UltraLight.woff new file mode 100644 index 0000000..e9126ec Binary files /dev/null and b/static/font/Gravity-UltraLight.woff differ diff --git a/static/font/Gravity-UltraLight.woff2 b/static/font/Gravity-UltraLight.woff2 new file mode 100644 index 0000000..5b913c8 Binary files /dev/null and b/static/font/Gravity-UltraLight.woff2 differ diff --git a/static/font/Gravity-UltraLightItalic.woff b/static/font/Gravity-UltraLightItalic.woff new file mode 100644 index 0000000..f9ee0c1 Binary files /dev/null and b/static/font/Gravity-UltraLightItalic.woff differ diff --git a/static/font/Gravity-UltraLightItalic.woff2 b/static/font/Gravity-UltraLightItalic.woff2 new file mode 100644 index 0000000..7dd35c7 Binary files /dev/null and b/static/font/Gravity-UltraLightItalic.woff2 differ diff --git a/static/images/favicon.ico b/static/images/favicon.ico new file mode 100644 index 0000000..5ee2b1b --- /dev/null +++ b/static/images/favicon.ico @@ -0,0 +1,57 @@ + + + + + + + + + + + diff --git a/static/images/lomes.svg b/static/images/lomes.svg new file mode 100644 index 0000000..a9886b3 --- /dev/null +++ b/static/images/lomes.svg @@ -0,0 +1,57 @@ + + + + + + + + + + + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..d386b72 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,33 @@ + + + + + + LoMeS | Meshtastic + + + + +
+
+ +

Welcome to LoMeS

+
+
+

A Local Meshtastic Server in development


+

If you see this site, means "LoMeS" development environment is running!

+

Thanks for collaborating and trying to make things more real...

+
+
+

Configuration Summary

+
+
    +
  • User executing flask : {{user}}
  • +
  • Machine time : {{time}}
  • +
  • {{sysinfo}}
  • +
+
+
+
+ +