From 1f223abe705a9da0151f8e7863e0b00f83829cbf Mon Sep 17 00:00:00 2001
From: Dmitri Popov
Date: Thu, 14 Feb 2019 11:11:34 +0100
Subject: [PATCH] Add disk usage info
---
scripts/index.php | 111 ++++++++++++++++++++++++++++++----------------
1 file changed, 72 insertions(+), 39 deletions(-)
diff --git a/scripts/index.php b/scripts/index.php
index 6110df8..dc8496b 100644
--- a/scripts/index.php
+++ b/scripts/index.php
@@ -3,25 +3,25 @@
License: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt -->
-
- Little Backup Box
-
-
-
-
-
+
+ Little Backup Box
+
+
+
+
+
@@ -52,26 +52,59 @@
+
+ &1 & echo $!');
+ }
+ if (isset($_POST['camerabackup']))
+ {
+ shell_exec('sudo ./camera-backup.sh 2>&1 & echo $!');
+ }
+ if (isset($_POST['minidlna']))
+ {
+ shell_exec('sudo ./minidlna.sh 2>&1 & echo $!');
+
+ // folder to check
+ $dir = '/media/storage';
+
+ // get disk space free (in bytes)
+ $disk_free = disk_free_space($dir);
+
+ // get disk space total (in bytes)
+ $disk_total = disk_total_space($dir);
+
+ // calculate the disk space used (in bytes)
+ $disk_used = $disk_total - $disk_free;
+
+ // percentage of disk used
+ $disk_used_p = sprintf('%.2f',($disk_used / $disk_total) * 100);
+
+ // this function will convert bytes value to KB, MB, GB and TB
+ function convertSize( $bytes )
+ {
+ $sizes = array( 'B', 'KB', 'MB', 'GB', 'TB' );
+ for( $i = 0; $bytes >= 1024 && $i < ( count( $sizes ) -1 ); $bytes /= 1024, $i++ );
+ return( round( $bytes, 2 ) . " " . $sizes[$i] );
+ }
+
+ // format the disk sizes using the function (B, KB, MB, GB and TB)
+ $disk_free = convertSize($disk_free);
+ $disk_used = convertSize($disk_used);
+ $disk_total = convertSize($disk_total);
+
+ echo '';
+ echo '- Total: '.$disk_total.'
';
+ echo '- Used: '.$disk_used.' ('.$disk_used_p.'%)
';
+ echo '- Free: '.$disk_free.'
';
+ echo '
';
+ }
+ if (isset($_POST['shutdown']))
+ {
+ shell_exec('sudo shutdown -h now 2>&1 & echo $!');
+ }
+ ?>
-