1616# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717#
1818
19- # print encode_json \%{$configuration->{'config'}->{'web'}};
19+ # print to_json \%{$configuration->{'config'}->{'web'}};
2020 # print Data::Dumper->Dump([$configuration]);
2121
2222# use diagnostics;
@@ -41,10 +41,6 @@ sub new
4141 $this -> Debug(3," " );
4242 $this -> {' rrd' }=();
4343 $this -> {' daemon' }-> {' confFiles' } = [];
44- # $this->{'counter'}->{'static'} = 0;
45- # $this->{'counter'}->{'dynamic'} = 0;
46- # $this->{'counter'}->{'status'} = 0;
47- # $this->{'counter'}->{'statistics'} = 0;
4844 return $this ;
4945}
5046
@@ -65,13 +61,14 @@ sub Load
6561 $_ = abs_path($0 );
6662 my ($path ,$file ) = /(.*)\/([^\/]*)$/ ;
6763
68- if ( scalar (@{$this -> {' daemon' }-> {' confFiles' }}) == 0 ) {
69- @{$this -> {' daemon' }-> {' confFiles' }} = ( @{$this -> {' daemon' }-> {' confFiles' }}, glob " /etc/rpimonitor/*.conf" ) ;
70- }
64+ push (@{$this -> {' daemon' }-> {' confFiles' }}," /etc/rpimonitor/data.conf" );
65+ push (@{$this -> {' daemon' }-> {' confFiles' }}," /etc/rpimonitor/daemon.conf" );
7166
7267 foreach ( @{$this -> {' daemon' }-> {' confFiles' }} ) {
68+ # print "$_\n";
7369 $this -> LoadFile($_ );
7470 }
71+ delete ($this -> {' daemon' }-> {' confFiles' });
7572
7673 # Set version (used by web pagescache mechanism)
7774 $this -> {' version' } = localtime ();
@@ -123,10 +120,13 @@ sub Load
123120
124121 # manage menu
125122 foreach (@{$this -> {' web' }-> {' status' }}) {
126- $_ -> {' name' } and push (@{$this -> {' menu' }-> {' status' }}, $_ -> {' name' });
123+ $_ -> {' name' } and push (@{$this -> {' web ' } -> { ' menu' }-> {' status' }}, $_ -> {' name' });
127124 }
128125 foreach (@{$this -> {' web' }-> {' statistics' }}) {
129- $_ -> {' name' } and push (@{$this -> {' menu' }-> {' statistics' }}, $_ -> {' name' });
126+ $_ -> {' name' } and push (@{$this -> {' web' }-> {' menu' }-> {' statistics' }}, $_ -> {' name' });
127+ }
128+ foreach (@{$this -> {' web' }-> {' addons' }}) {
129+ $_ -> {' name' } and push (@{$this -> {' web' }-> {' menu' }-> {' addons' }}, $_ -> {' name' });
130130 }
131131
132132 $this -> {' sharedmem' } = IPC::ShareLite-> new(
@@ -267,7 +267,7 @@ use POSIX;
267267use IO::Handle;
268268use HTTP::Daemon;
269269use HTTP::Status;
270- use JSON;
270+ use JSON -convert_blessed_universally ;
271271# use Data::Dumper;
272272
273273sub new
@@ -278,6 +278,8 @@ sub new
278278 # List of files to be delivered
279279 my @paths = (
280280 " /" ,
281+ " /all.json" ,
282+ " /addons.json" ,
281283 " /static.json" ,
282284 " /dynamic.json" ,
283285 " /status.json" ,
@@ -289,9 +291,9 @@ sub new
289291 " /favicon.ico" ,
290292
291293 " /index.html" ,
294+ " /addons.html" ,
292295 " /statistics.html" ,
293296 " /status.html" ,
294- " /shellinabox.html" ,
295297 " /cacert.pem" ,
296298 " /certificate.p12" ,
297299 " /shellinabox" ,
@@ -311,6 +313,8 @@ sub new
311313 " /js/rpimonitor.shellinabox.js" ,
312314 " /js/rpimonitor.statistics.js" ,
313315 " /js/rpimonitor.status.js" ,
316+ " /js/rpimonitor.utils.js" ,
317+ " /js/rpimonitor.addons.js" ,
314318 " /js/rpimonitor.index.js" ,
315319 " /js/rpimonitor.js" ,
316320 " /js/jsqrencode.min.js" ,
@@ -443,12 +447,14 @@ sub DoGET
443447 # The file need to be known or we return an error
444448 my $isvalid ;
445449 foreach (@{$this -> {' paths' }}) {
446- if ( $path =~ / $_ $ / ) {
450+ if ( $path =~ / $_ $ / ) {
447451 $isvalid =1;
448452 $path =$_ ;
449453 last ;
450454 }
451455 }
456+ $isvalid ||= ( $path =~ / \/ addons\/ / );
457+
452458 # $isvalid or $connection->send_error(404,"<br><b>$path</b> not in <br>". join ('<br>',@{$this->{'paths'}} )) and return;
453459 $isvalid or $this -> SendError(404);
454460
@@ -485,12 +491,17 @@ sub Run
485491 unshift ( @{$this -> {' paths' }}, $1 );
486492 }
487493 @{$this -> {' paths' }} = ( @{ $configuration -> {' rrdlist' }}, @{$this -> {' paths' }} );
488- $this -> {' status' } = encode_json(\@{$configuration -> {' web' }-> {' status' }});
489- $this -> {' statistics' } = encode_json(\@{$configuration -> {' web' }-> {' statistics' }});
490- $this -> {' friends' } = encode_json(\@{$configuration -> {' web' }-> {' friends' }});
491- $this -> {' page' } = encode_json(\%{$configuration -> {' web' }-> {' page' }});
492- $this -> {' static' } = encode_json(\%{$monitor -> {' static' }});
493- $this -> {' menu' } = encode_json(\%{$configuration -> {' menu' }});
494+ $this -> {' status' } = to_json(\@{$configuration -> {' web' }-> {' status' }});
495+ $this -> {' statistics' } = to_json(\@{$configuration -> {' web' }-> {' statistics' }});
496+ $this -> {' friends' } = to_json(\@{$configuration -> {' web' }-> {' friends' }});
497+ $this -> {' page' } = to_json(\%{$configuration -> {' web' }-> {' page' }});
498+ $this -> {' static' } = to_json(\%{$monitor -> {' static' }});
499+ $this -> {' menu' } = to_json(\%{$configuration -> {' web' }-> {' menu' }});
500+ $this -> {' addons' } = to_json(\@{$configuration -> {' web' }-> {' addons' }});
501+ my $json = JSON-> new;
502+ $json = $json -> allow_blessed([$configuration ]);
503+ $json = $json -> convert_blessed([$configuration ]);
504+ $this -> {' all' } = $json -> encode( \%{$configuration } );
494505 $this -> {' version' } = " {\" version\" :\" $configuration ->{'version'}\" }" ;
495506 # print Data::Dumper->Dump([$this->{'paths'}]);
496507
@@ -563,27 +574,31 @@ sub Run
563574 # write json if server is not running
564575 open (FILE, " > $configuration ->{'daemon'}->{'webroot'}/static.json" )
565576 or warn $! ;
566- print FILE encode_json \%{$this -> {' static' }} ;
577+ print FILE to_json \%{$this -> {' static' }} ;
567578 close (FILE);
568579 open (FILE, " > $configuration ->{'daemon'}->{'webroot'}/status.json" )
569580 or warn $! ;
570- print FILE encode_json \@{$configuration -> {' web' }-> {' status' }} ;
581+ print FILE to_json \@{$configuration -> {' web' }-> {' status' }} ;
571582 close (FILE);
572583 open (FILE, " > $configuration ->{'daemon'}->{'webroot'}/page.json" )
573584 or warn $! ;
574- print FILE encode_json \%{$configuration -> {' web' }-> {' page' }} ;
585+ print FILE to_json \%{$configuration -> {' web' }-> {' page' }} ;
575586 close (FILE);
576587 open (FILE, " > $configuration ->{'daemon'}->{'webroot'}/statistics.json" )
577588 or warn $! ;
578- print FILE encode_json \@{$configuration -> {' web' }-> {' statistics' }} ;
589+ print FILE to_json \@{$configuration -> {' web' }-> {' statistics' }} ;
579590 close (FILE);
580591 open (FILE, " > $configuration ->{'daemon'}->{'webroot'}/friends.json" )
581592 or warn $! ;
582- print FILE encode_json (\@{$configuration -> {' web' }-> {' friends' }});
593+ print FILE to_json (\@{$configuration -> {' web' }-> {' friends' }});
583594 close (FILE);
584595 open (FILE, " > $configuration ->{'daemon'}->{'webroot'}/menu.json" )
585596 or warn $! ;
586- print FILE encode_json(\%{$configuration -> {' menu' }});
597+ print FILE to_json(\%{$configuration -> {' web' }-> {' menu' }});
598+ close (FILE);
599+ open (FILE, " > $configuration ->{'daemon'}->{'webroot'}/addons.json" )
600+ or warn $! ;
601+ print FILE to_json(\@{$configuration -> {' web' }-> {' addons' }});
587602 close (FILE);
588603 open (FILE, " > $configuration ->{'daemon'}->{'webroot'}/version.json" )
589604 or warn $! ;
@@ -668,7 +683,7 @@ sub Status
668683 my ($sec ,$min ,$hour ,$mday ,$mon ,$year ) = (localtime)[0,1,2,3,4,5];
669684 @{$this ->{'dynamic'}->{'localtime'}}=($year +1900,$mon +1,$mday ,$hour ,$min ,$sec );
670685
671- my $json =encode_json \% {$this ->{'dynamic'}};
686+ my $json =to_json \% {$this ->{'dynamic'}};
672687 $this ->Debug(4,"\n $json ");
673688
674689 # if embeded server is not used, we write the json file else the
0 commit comments