@@ -10,20 +10,41 @@ window.onload = function() {
10
10
return response . json ( ) ;
11
11
} ;
12
12
13
- fetch ( '/api/all' )
14
- . then ( handleResponse )
15
- . then ( data => {
16
- document . getElementById ( 'current-time' ) . textContent = data [ 'Current Time' ] ;
17
- document . getElementById ( 'ip-address' ) . textContent = data [ 'IP Address' ] . replaceAll ( " " , "\n" ) ;
18
- document . getElementById ( 'cpu-usage' ) . textContent = data [ 'CPU Usage' ] ;
19
- document . getElementById ( 'soc-temp' ) . textContent = data [ 'SoC Temperature' ] . replace ( "C" , "°C" ) ;
20
- document . getElementById ( 'total-ram' ) . textContent = data [ 'Total RAM' ] ;
21
- document . getElementById ( 'used-ram' ) . textContent = data [ 'Used RAM' ] . concat ( "MiB" ) ;
22
- document . getElementById ( 'total-swap' ) . textContent = data [ 'Total Swap' ] ;
23
- document . getElementById ( 'used-swap' ) . textContent = data [ 'Used Swap' ] . concat ( "MiB" ) ;
24
- } )
25
- . catch ( error => console . error ( 'Error fetching API data:' , error ) ) ;
13
+ // Function to fetch and update data
14
+ const updateData = ( ) => {
15
+ fetch ( '/api/all' )
16
+ . then ( handleResponse )
17
+ . then ( data => {
18
+ // Original metrics
19
+ document . getElementById ( 'current-time' ) . textContent = data [ 'Current Time' ] ;
20
+ document . getElementById ( 'ip-address' ) . textContent = data [ 'IP Address' ] . replaceAll ( " " , "\n" ) ;
21
+ document . getElementById ( 'cpu-usage' ) . textContent = data [ 'CPU Usage' ] ;
22
+ document . getElementById ( 'soc-temp' ) . textContent = data [ 'SoC Temperature' ] . replace ( "C" , "°C" ) ;
23
+ document . getElementById ( 'total-ram' ) . textContent = data [ 'Total RAM' ] ;
24
+ document . getElementById ( 'used-ram' ) . textContent = data [ 'Used RAM' ] . concat ( "MiB" ) ;
25
+ document . getElementById ( 'total-swap' ) . textContent = data [ 'Total Swap' ] ;
26
+ document . getElementById ( 'used-swap' ) . textContent = data [ 'Used Swap' ] . concat ( "MiB" ) ;
27
+
28
+ // New metrics
29
+ document . getElementById ( 'system-uptime' ) . textContent = data [ 'System Uptime' ] ;
30
+ document . getElementById ( 'disk-usage' ) . textContent = data [ 'Disk Usage' ] ;
31
+ document . getElementById ( 'disk-total' ) . textContent = data [ 'Disk Total' ] ;
32
+ document . getElementById ( 'disk-used' ) . textContent = data [ 'Disk Used' ] ;
33
+ document . getElementById ( 'disk-available' ) . textContent = data [ 'Disk Available' ] ;
34
+ document . getElementById ( 'system-model' ) . textContent = data [ 'System Model' ] ;
35
+ document . getElementById ( 'kernel-version' ) . textContent = data [ 'Kernel Version' ] ;
36
+ document . getElementById ( 'os-version' ) . textContent = data [ 'OS' ] ;
37
+ } )
38
+ . catch ( error => console . error ( 'Error fetching API data:' , error ) ) ;
39
+ } ;
40
+
41
+ // Initial data load
42
+ updateData ( ) ;
26
43
44
+ // Update data every 5 seconds
45
+ setInterval ( updateData , 5000 ) ;
46
+
47
+ // Shutdown button handler
27
48
document . getElementById ( 'shutdown-btn' ) . addEventListener ( 'click' , function ( ) {
28
49
const apiKey = prompt ( 'Please enter your API key:' ) ;
29
50
if ( apiKey && confirm ( 'Are you sure you want to shut down the system?' ) ) {
@@ -39,6 +60,23 @@ window.onload = function() {
39
60
}
40
61
} ) ;
41
62
63
+ // Reboot button handler
64
+ document . getElementById ( 'reboot-btn' ) . addEventListener ( 'click' , function ( ) {
65
+ const apiKey = prompt ( 'Please enter your API key:' ) ;
66
+ if ( apiKey && confirm ( 'Are you sure you want to reboot the system?' ) ) {
67
+ fetch ( '/api/reboot' , {
68
+ method : 'POST' ,
69
+ headers : {
70
+ 'x-api-key' : apiKey
71
+ }
72
+ } )
73
+ . then ( handleResponse )
74
+ . then ( data => alert ( data . message ) )
75
+ . catch ( error => console . error ( 'Error during reboot:' , error ) ) ;
76
+ }
77
+ } ) ;
78
+
79
+ // Update button handler
42
80
document . getElementById ( 'update-btn' ) . addEventListener ( 'click' , function ( ) {
43
81
const apiKey = prompt ( 'Please enter your API key:' ) ;
44
82
if ( apiKey && confirm ( 'Are you sure you want to update the system?' ) ) {
0 commit comments