Skip to content

Commit

Permalink
Merge pull request #63 from femto-code/master
Browse files Browse the repository at this point in the history
Update v1.1.5 (installer)
  • Loading branch information
femto-code authored Nov 25, 2023
2 parents 9f44fee + 0b00f91 commit 525e2cb
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 82 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Open for your feature [requests](https://github.com/femto-code/Rasberry-Pi-Dashboard/pulls) or [issues](https://github.com/femto-code/Rasberry-Pi-Dashboard/issues)!
[https://github.com/femto-code/Rasberry-Pi-Dashboard](https://github.com/femto-code/Rasberry-Pi-Dashboard)

## [1.1.5] - 2023-11-25
- [new] added installer script (alpha) for automated dashboard setup

## [1.1.4] - 2023-10-13
- fix stats not showing up on systems with PHP version 8.1+ (#61)

Expand Down
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@
</div>
<br>
<p align="center"><a href="https://github.com/femto-code/Raspberry-Pi-Dashboard/issues">Report a bug</a> | <a href="https://github.com/femto-code/Raspberry-Pi-Dashboard/discussions">Request a new feature</a> | <a href="https://github.com/femto-code/Raspberry-Pi-Dashboard/pulls">Help develop this project</a></p>
<p align="center"><i>Loved the project? Please consider giving a star</i> :)</p>

## Features

- Live surveillance of RPi hardware (CPU temperature, frequency, loads etc.) with customizable warning thresholds
- Live surveillance of RPi hardware (CPU temperature, frequency, load etc.) with customizable warning thresholds
- Detailed software/hardware information (web server, PHP, storage / partition workload, core voltage, plugged USB devices, kernel version, model specifications, OS, CPU, network config)
- Protected access with password login ([configure password](https://github.com/femto-code/Raspberry-Pi-Dashboard#configure-password-manually))
- Power (shutdown/reboot) Raspberry Pi with scheduling options ([setup instructions](https://github.com/femto-code/Raspberry-Pi-Dashboard#enable-shutdown--reboot-optional))
- Responsive mobile web-app
- Shutdown / Reboot your Raspberry Pi with scheduling options ([setup instructions](https://github.com/femto-code/Raspberry-Pi-Dashboard#enable-shutdown--reboot-optional))
- Responsive mobile web app
- Dark Theme (manual / auto)

> Update your existing dashboard setup by navigating to project root folder and running `git pull` in the terminal. Please keep in mind, this only works if there are no changes in the workspace.
### ❗ If you run into issues and getting error message "Permission denied" or "unable to open file": [see issue #22](https://github.com/femto-code/Raspberry-Pi-Dashboard/issues/22) or [read here](https://github.com/femto-code/Raspberry-Pi-Dashboard#valid-permissions) for help and instructions to solve. ❗
### 🆕 Use the installer script to set up the dashboard!

## Screenshots

Expand All @@ -40,41 +37,47 @@
|:-------------------------------------------------:|:-----------------------------------------------:|
| ![](img/m2.png?raw=true) | ![](img/m1.png?raw=true) |

## Download and Installation
## Use installer script (alpha)

```bash
wget -O install.sh https://github.com/femto-code/Raspberry-Pi-Dashboard/raw/release/installer.sh
bash install.sh
```

## Manual download and installation

### Prerequisites

- Running Web Server (e.g. *Lighttpd* or *Apache*) with *PHP* installed
- Running web server (e.g. *Lighttpd* or *Apache*) with *PHP* installed
- Installed *Git* (comes preinstalled on Raspberry Pi OS / formerly Raspbian as well as other Linux distros)
- Valid permissions within `/var/www/html`
- Valid permissions set within `/var/www/html`

#### Valid permissions

The following configuration is the commonly recommended set-up for your web server folder and is meant to be secure to a certain level (with the **minimum** need of permissions):

1. First, make sure `www-data` group exists and add your current user to that system group:<br>
1. Make sure `www-data` group exists and add your current user to that system group:<br>
_(if you are using another distro than Raspberry Pi OS the username of web server can differ)_<br>
`sudo groupadd www-data`<br>
`sudo usermod -a -G www-data www-data`<br>
`sudo usermod -a -G www-data <yourlogin>` (replace `<yourlogin>` with your username)

1. Second, give the ownership of web folder to the `www-data` group and *your* user.<br>The following commands ensure that you have _full_ access on the files within the web folder while group members (`www-data`) cannot edit/write for security reasons:<br>
1. Give the ownership of web folder to the `www-data` group and *your* user.<br>The following commands ensure that you have _full_ access on the files within the web folder while group members (`www-data`) cannot edit/write for security reasons:<br>
`sudo chown -R <yourlogin>:www-data /var/www/html` (replace `<yourlogin>` with your username)<br>
`sudo chmod -R 755 /var/www/html`

3. Reboot your RPi (for permission changes to take effect)
3. Reboot your RPi or log out and back in (for permission changes to take effect)

### Setup project

- navigate to your web folder: `cd /var/www/html`
- clone this GitHub repository: `git clone https://github.com/femto-code/Rasberry-Pi-Dashboard.git <your_subfolder_name>`<br>(replace `<your_subfolder_name>` with a name of your choice accordingly, you can also rename the base folder at any time afterwards)
- ***Alternatively*** download and extract ZIP file from [releases](https://github.com/femto-code/Raspberry-Pi-Dashboard/releases)
- clone the project into your web folder:<br>`git clone https://github.com/femto-code/Rasberry-Pi-Dashboard.git /var/www/html/<your_subfolder_name>`<br>(replace `<your_subfolder_name>` with a name of your choice accordingly, you can also rename this base folder at any time afterwards)
- ***Alternatively*** download this repo as a ZIP file and extract it
- Run in a terminal to set valid permissions:
- `sudo chown -R <yourlogin>:www-data /var/www/html/<your_subfolder_name>`<br>(replace `<yourlogin>` with your username)
- `sudo chmod -R 775 /var/www/html/<your_subfolder_name>`
- this will allow the `www-data` user exclusively to write/edit (7**7**5) files **only in your dashboard folder**!
> An erroneous permission typically results in the situation where the user responsible for web server (e.g. `www-data`) does not have rights to create/modify the local config file for saving your dashboard adjustments (your custom thresholds, password etc.). In this case, the dashboard won't work at all and will throw this error.
- **DONE!** Open web browser with URL: `http://IP_OF_YOUR_RPI/<your_subfolder_name>`
- **DONE!** Open web browser with URL: `http://<IP_OF_YOUR_RPI>/<your_subfolder_name>`
## Additional configuration / Help

Expand All @@ -90,7 +93,7 @@ The `vcgencmd` command (specifically dedicated to RPi firmware) is a system comm

#### Enable shutdown / reboot (optional)

> Recommended only, if your RPi is **not** accessible over the Internet!
> Recommended only, if your RPi is **not** accessible from outside your local (LAN) network!
In order to use the remote shutdown functionality you have to give the user `www-data` advanced rights for running one specific command:
1. Run `sudo visudo` to open the editor for adjusting user rights
Expand All @@ -104,7 +107,7 @@ In order to use the remote shutdown functionality you have to give the user `www
- forgotten password (and access to dashboard therefore impossible)

1. Go to [https://www.md5-generator.de/](https://www.md5-generator.de/) and generate *MD5 encrypted passphrase*.
2. Open `local.config` (dynamically created at first start) and apply your custom passphrase string (generated in **step 1**) as follows (don't alter other lines):
2. Open `local.config` or create it and apply your custom passphrase string (generated in **step 1**) as follows (don't alter other lines):
```
[...]
'general' =>
Expand All @@ -116,9 +119,7 @@ In order to use the remote shutdown functionality you have to give the user `www
[...]
```

4. Remember password and enjoy!

> **As always**: Make sure to change the default password (which is **root**) and choose a more secure one at first setup and if your dashboard is accessible on the network.
> **As always**: Make sure to change the default password (which is **root**) and choose a more secure one at first setup and consider more security if your dashboard is accessible on the network.
## License

Expand Down
51 changes: 2 additions & 49 deletions backend/sys_infos.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,53 +103,6 @@
}

}
//
if(isset($_GET["statemail"])){

$name_tag = array();
$name_tag[0] = "Sunday";
$name_tag[1] = "Monday";
$name_tag[2] = "Tuesday";
$name_tag[3] = "Wednesday";
$name_tag[4] = "Thursday";
$name_tag[5] = "Friday";
$name_tag[6] = "Saturday";
$num_tag = date("w");
$tag = $name_tag[$num_tag];
$jahr = date("Y");
$n = date("d");
$monat = date("m");
$time = date("H:i");

$msg = "\n\n :: Request sent on $tag, $n.$monat.$jahr - $time ::\n\n";
$msg .= "Uptime: ".$uptime_string."\n\n";
$msg .= "CPU Temperature: ".$cputemp." Grad Celsius\n\n";
$msg .= "CPU Frequency: ".$cpufreq." MHz\n\n";
$msg .= "CPU Loads: ".$getLoad[0].",".$getLoad[1].",".$getLoad[2]."\n\n";
$msg .= "RAM: ".$memperc."%\n\n";
$msg .= "RAM unused: ".$mavail." MB\n\n";
$msg .= "RAM used: ".$munavail." MB\n\n";
$msg .= "SWAP: ".$swapperc."%\n\n";
$msg .= "SWAP overall: ".$swaptotal." MB\n\n";
$msg .= "SWAP used: ".$swapused." MB\n\n";

$command='python /var/www/html/'.$config->get("general.folder").'/statemail.py "Status Mail of RPi" "'.$msg.'"';
//echo $command;
$output=shell_exec($command);
echo "<pre>$output</pre><br>";

$a1 = "\n<div class=\"testbox\" style=\"border: 1px dotted green; position: absolute; margin:0px; padding:10px; z-index:5; background-color:#ffffcc; color:#000000;\"> \n";
$a2 = " \n </div> \n";
$ausgabe = $a1 . "Status mail was sent!<br><button onclick='location.replace(\"../index.php\");'>Zurück</button>" . $a2;
echo $ausgabe;

}else{
$output = array('auth' => 'true', 'timest' => $timed, 'uptime' => $uptime_string, 'cputemp' => $cputemp, 'cpufreq' => $cpufreq, 'load' => $getLoad, 'memperc' => $memperc, 'memavail' => $mavail, 'memunavail' => $munavail, 'swapperc' => $swapperc, 'swaptotal' => $swaptotal, 'swapused' => $swapused);
echo json_encode($output);
}

//$DURATION_start=microtime(true);
//$DURATION_end=microtime(true);
//$DURATION = $DURATION_end - $DURATION_start;
//echo "<p><font size='0'>Site generated in ".round($DURATION,3)." seconds</font></p>\n";
$output = array('auth' => 'true', 'timest' => $timed, 'uptime' => $uptime_string, 'cputemp' => $cputemp, 'cpufreq' => $cpufreq, 'load' => $getLoad, 'memperc' => $memperc, 'memavail' => $mavail, 'memunavail' => $munavail, 'swapperc' => $swapperc, 'swaptotal' => $swaptotal, 'swapused' => $swapused);
echo json_encode($output);
?>
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#accordionExample">
<div class="accordion-body">
<h3><span class='text-success'>&#10003;</span> Version 1.1.4</h3>
<h3><span class='text-success'>&#10003;</span> Version 1.1.5</h3>
<ul><li>live page title with hostname + status of monitored RPi</li><li>overhauled project documentation / readme</li><li><a href='https://github.com/femto-code/Rasberry-Pi-Dashboard/releases'>Stay updated here</a></li><li><i><a href="CHANGELOG.md">All changes</a></i></li></ul>
<small>most important changes since RPi Dashboard v1.0</small>
</div>
Expand Down Expand Up @@ -571,7 +571,7 @@
<!-- Footer -->
<footer style="line-height: 40px; margin-top: 10px;" class="border-top py-1">
<div class="container text-center">
RPi Dashboard v1.1.4 <span class="text-muted">(Oct 2023)</span> <span id="dot">&middot;</span> <span id="notf" class="text-success">See the <a href="https://github.com/femto-code/Rasberry-Pi-Dashboard/releases">Github releases</a> for updates!</span><br />
RPi Dashboard v1.1.5 <span class="text-muted">(Nov 2023)</span> <span id="dot">&middot;</span> <span id="notf" class="text-success">See the <a href="https://github.com/femto-code/Rasberry-Pi-Dashboard/releases">Github releases</a> for updates!</span><br />
<button class="btn btn-secondary mb-2" onclick="$('#exampleModal').modal('show');"><i class="bi bi-gear"></i>&nbsp;Options</button>
<hr style="margin-top: 0; margin-bottom: 0;">
femto-code&nbsp;<a href="https://github.com/femto-code"><i class="bi bi-github"></i></a> &middot; <span class="text-muted">2018 - 2023</span>
Expand Down
75 changes: 75 additions & 0 deletions installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

cecho () {
declare -A colors;
colors=(\
['black']='\E[0;47m'\
['red']='\E[0;31m'\
['green']='\E[0;32m'\
['yellow']='\E[0;33m'\
['blue']='\E[0;34m'\
['magenta']='\E[0;35m'\
['cyan']='\E[0;36m'\
['white']='\E[0;37m'\
);

local defaultMSG="No message passed.";
local defaultColor="black";
local defaultNewLine=true;

while [[ $# -gt 1 ]];
do
key="$1";

case $key in
-c|--color)
color="$2";
shift;
;;
-n|--noline)
newLine=false;
;;
*)
# unknown option
;;
esac
shift;
done

message=${1:-$defaultMSG}; # Defaults to default message.
color=${color:-$defaultColor}; # Defaults to default color, if not specified.
newLine=${newLine:-$defaultNewLine};

echo -en "${colors[$color]}";
echo -en "$message";
if [ "$newLine" = true ] ; then
echo;
fi
tput sgr0; # Reset text attributes to normal without clearing screen.

}
### Colors ##
ESC=$(printf '\033') RESET="${ESC}[0m" BLACK="${ESC}[30m" RED="${ESC}[31m"
GREEN="${ESC}[32m" YELLOW="${ESC}[33m" BLUE="${ESC}[34m" MAGENTA="${ESC}[35m"
CYAN="$ESC[36m" WHITE="${ESC}[37m" DEFAULT="${ESC}[39m"
cyanprint() { printf "${CYAN}%s${RESET}\n" "$1"; }
_process() {
echo -e "\n"
cyanprint "$@"
}
_success() {
printf "\n%s✓ Success:%s\n" "$(tput setaf 2)" "$(tput sgr0) $1"
}

cecho -c 'blue' "Welcome to the RPi Dashboard installer!"
read -p "This setup assumes you have a working web server installed that is up and running. Continue? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
hostn="`hostname`"
cecho -c 'blue' "This setup will install the dashboard to /var/www/html."
_process "Please choose your subfolder name, so you will be able to call the dashboard at http://$hostn/{your_subfolder_name}"
read -p "Enter custom subfolder name: " subfoldern
cd /var/www/html
git clone https://github.com/femto-code/Raspberry-Pi-Dashboard $subfoldern
_process "Setting up valid permissions for /var/www/html/$subfoldern..."
sudo chown -R ${whoami}:www-data /var/www/html/$subfoldern
sudo chmod -R 775 /var/www/html/$subfoldern
_success "Installation done! To access the dashboard open up a web browser with URL: http://$hostn/$subfoldern"
17 changes: 8 additions & 9 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,17 @@ function updatedb(){
// CPU Frequency
document.getElementById("frequency").innerHTML=result.cpufreq;
// CPU Loads
var str=result.load+'';
var array=str.split(",");
document.getElementById("m1").innerHTML=array[0];
document.getElementById("m5").innerHTML=array[1];
document.getElementById("m15").innerHTML=array[2];
console.log(result.load);
document.getElementById("m1").innerHTML = Math.round(result.load[0] * 100) / 100;
document.getElementById("m5").innerHTML = Math.round(result.load[1] * 100) / 100;
document.getElementById("m15").innerHTML = Math.round(result.load[2] * 100) / 100;
removeData(chart);
removeData(chart);
removeData(chart);
addData(chart, "1 min", array[0]);
addData(chart, "5 min", array[1]);
addData(chart, "15 min", array[2]);
if (array[0] >= warn_loads_size){
addData(chart, "1 min", Math.round(result.load[0] * 100) / 100);
addData(chart, "5 min", Math.round(result.load[0] * 100) / 100);
addData(chart, "15 min", Math.round(result.load[0] * 100) / 100);
if (result.load[0] >= warn_loads_size){
document.getElementById("cput").innerHTML="CPU <font class='text-warning'>(WARNING)</font>";
addWarning("CPU Loads","cpu");
warn++;
Expand Down

0 comments on commit 525e2cb

Please sign in to comment.