diff --git a/src/freedombone-installer b/src/freedombone-installer index f478fb52c0e2557c480b3b8d21c1eb53e56dfac1..822f560e9660c1bf3919269f1024fef9a6a17e6a 100755 --- a/src/freedombone-installer +++ b/src/freedombone-installer @@ -50,6 +50,7 @@ FIREWALL_DOMAINS=/root/${PROJECT_NAME}-firewall-domains.cfg local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local webadmin_install_dir="/var/www/${local_hostname}/htdocs/admin" +system_monitor_file="$webadmin_install_dir/.system_monitor.txt" dynamic_dns_file="$webadmin_install_dir/.dynamicdns.txt" reset_file="$webadmin_install_dir/.reset.txt" shutdown_file="$webadmin_install_dir/.shutdown.txt" @@ -1341,6 +1342,38 @@ function update_dynamic_dns { fi } +function update_system_monitor { + if [ -f "$system_monitor_file" ]; then + rm "$system_monitor_file" + + disk_use=$(df -h | grep /dev/sda1) + disk_use_percent=0 + if [[ "$disk_use" == *'/dev/sda1'* ]]; then + disk_use_percent=$(df -h | grep /dev/sda1 | awk -F ' ' '{print $5}') + else + disk_use_percent=$(df -h | grep /dev/mmcblk0p1 | awk -F ' ' '{print $5}') + fi + + used_memory=$(free -m | grep "Mem:" | awk -F ' ' '{print $3}') + total_memory=$(free -m | grep "Mem:" | awk -F ' ' '{print $2}') + used_memory_percent=$((used_memory * 100 / total_memory)) + + local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local + webadmin_install_dir="/var/www/${local_hostname}/htdocs/admin" + if [ -f "$webadmin_install_dir/system_monitor_template.html" ]; then + cp "$webadmin_install_dir/system_monitor_template.html" "$webadmin_install_dir/system_monitor.html" + + if [[ "$disk_use_percent" == *'%'* ]]; then + sed -i "s|<div name=\"diskspace\" class=\"w3-container.*|<div name=\"diskspace\" class=\"w3-container w3-blue w3-round-xlarge\" style=\"width:$disk_use_percent\">$disk_use_percent</div>|g" "$webadmin_install_dir/system_monitor.html" + fi + + sed -i "s|<div name=\"memory\" class=\"w3-container.*|<div name=\"memory\" class=\"w3-container w3-blue w3-round-xlarge\" style=\"width:$used_memory_percent\">$used_memory_percent</div>|g" "$webadmin_install_dir/system_monitor.html" + + chown www-data:www-data "$webadmin_install_dir/system_monitor.html" + fi + fi +} + # If the freedombone command is already running then kill its process #shellcheck disable=SC2009 install_process=$(ps a | grep '/usr/local/bin/freedombone -c' | grep -v 'grep') @@ -1401,6 +1434,7 @@ do webadmin_change_password update_blocklist update_dynamic_dns + update_system_monitor backup_and_restore backup_and_restore_keys add_remove_users diff --git a/src/freedombone-utils-webadmin b/src/freedombone-utils-webadmin index 277140538701cc2501c1be547b56238451c45978..30f88d7e010a89b1832e93ef17960fcb0b33bbde 100755 --- a/src/freedombone-utils-webadmin +++ b/src/freedombone-utils-webadmin @@ -692,6 +692,34 @@ function regenerate_webadmin_dynamic_dns { fi } +function webadmin_update_system_monitor { + disk_use=$(df -h | grep /dev/sda1) + disk_use_percent=0 + if [[ "$disk_use" == *'/dev/sda1'* ]]; then + disk_use_percent=$(df -h | grep /dev/sda1 | awk -F ' ' '{print $5}') + else + disk_use_percent=$(df -h | grep /dev/mmcblk0p1 | awk -F ' ' '{print $5}') + fi + + used_memory=$(free -m | grep "Mem:" | awk -F ' ' '{print $3}') + total_memory=$(free -m | grep "Mem:" | awk -F ' ' '{print $2}') + used_memory_percent=$((used_memory * 100 / total_memory)) + + local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local + webadmin_install_dir="/var/www/${local_hostname}/htdocs/admin" + if [ -f "$webadmin_install_dir/system_monitor_template.html" ]; then + cp "$webadmin_install_dir/system_monitor_template.html" "$webadmin_install_dir/system_monitor.html" + + if [[ "$disk_use_percent" == *'%'* ]]; then + sed -i "s|<div name=\"diskspace\" class=\"w3-container.*|<div name=\"diskspace\" class=\"w3-container w3-blue w3-round-xlarge\" style=\"width:$disk_use_percent\">$disk_use_percent</div>|g" "$webadmin_install_dir/system_monitor.html" + fi + + sed -i "s|<div name=\"memory\" class=\"w3-container.*|<div name=\"memory\" class=\"w3-container w3-blue w3-round-xlarge\" style=\"width:$used_memory_percent\">$used_memory_percent</div>|g" "$webadmin_install_dir/system_monitor.html" + + chown www-data:www-data "$webadmin_install_dir/system_monitor.html" + fi +} + function install_web_admin { # This is intended as an admin web user interface # similar to Plinth or the yunohost @@ -874,6 +902,8 @@ function install_web_admin { regenerate_webadmin_blocklist regenerate_webadmin_dynamic_dns + + webadmin_update_system_monitor } # NOTE: deliberately no exit 0 diff --git a/webadmin/EN/system_monitor_template.html b/webadmin/EN/system_monitor_template.html new file mode 100644 index 0000000000000000000000000000000000000000..5b9deeecb4969cf89295e95510ab415d29f18a1b --- /dev/null +++ b/webadmin/EN/system_monitor_template.html @@ -0,0 +1,103 @@ +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Refresh" content="10"> + <link rel="stylesheet" href="w3.css"> + <style> + #headerpic { + width: 60%; + height: auto; + margin-right : auto; + margin-left : auto; + min-width : 220px; + } + + .header { + text-align: center; + padding: 32px; + } + .headertext { + color: #72a7cf; + text-align: center; + font-size: 120%; + font-weight: bold; + } + + #iconpic { + width: 20%; + height: auto; + margin-right : auto; + margin-left : auto; + min-width : 120px; + } + + .appurl { + color: grey; + font-size: 100%; + } + + .titletext { + color: black; + font-size: 100%; + } + + .appdesc { + color: black; + font-size: 65%; + } + + button { + border: none; + outline: 0; + display: inline-block; + padding: 8px; + color: white; + background-color: #000; + text-align: center; + cursor: pointer; + width: 100%; + font-size: 18px; + } + + a { + text-decoration: none; + color: black; + } + + button:hover, a:hover { + opacity: 0.7; + } + + .w3-light-grey,.w3-hover-light-grey:hover,.w3-light-gray,.w3-hover-light-gray:hover{ + color:#000!important; + background-color:#f1f1f1!important + } + + </style> + </head> + <body> + <div class="header"> + <a href="index.html"><img id="headerpic" class="img-responsive" src="images/logo.png"></a> + + <p class="headertext">System Monitor</p> + + <p class="titletext">Disk space used</p> + <div class="w3-light-grey w3-round-xlarge"> + <div name="diskspace" class="w3-container w3-blue w3-round-xlarge" style="width:50%">50%</div> + </div> + + <p class="titletext">Memory used</p> + <div class="w3-light-grey w3-round-xlarge"> + <div name="memory" class="w3-container w3-blue w3-round-xlarge" style="width:80%">80%</div> + </div> + + <br><br> + + <form action="systemmonitor.php" method="post"> + <input type="submit" name="submitsystemmonitorback" value="Go Back" /> + <input type="submit" name="submitsystemmonitor" value="Update" /> + </form> + + </div> + </body> +</html> diff --git a/webadmin/systemmonitor.php b/webadmin/systemmonitor.php new file mode 100755 index 0000000000000000000000000000000000000000..e8fff7ba1ab9e5f2795acbbaf64d81cd4c3f63cf --- /dev/null +++ b/webadmin/systemmonitor.php @@ -0,0 +1,17 @@ +<?php + +// Updates values for the system monitor screen + +$output_filename = "settings.html"; + +if (isset($_POST['submitsystemmonitor'])) { + $system_monitor_file = fopen(".system_monitor.txt", "w") or die("Unable to create setup file"); + fwrite($system_monitor_file, " "); + fclose($system_monitor_file); +} + +$htmlfile = fopen("$output_filename", "r") or die("Unable to open $output_filename"); +echo fread($htmlfile,filesize("$output_filename")); +fclose($htmlfile); + +?>