From 9e916300b6c0c7e84fc65b56c7e5e2b5b0c57dfb Mon Sep 17 00:00:00 2001 From: Will Budic Date: Thu, 7 Nov 2019 07:03:39 +1100 Subject: [PATCH] Added IPC::Run module to handle various STDOUT situations. --- Installation.txt | 4 ++++ htdocs/cgi-bin/stats.cgi | 31 +++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Installation.txt b/Installation.txt index 2150ddc..364d6bb 100644 --- a/Installation.txt +++ b/Installation.txt @@ -96,6 +96,7 @@ sudo cpanm Number/Bytes/Human.pm; sudo cpanm Regexp::Common; sudo cpanm JSON; sudo cpanm Switch; +sudo cpanm install IPC::Run #Install DBI module sudo cpanm DBI; @@ -110,6 +111,9 @@ Platforms supported, Windows, Unix (all), Mac. Installing perl as an developer, requires no sudo. But hence can't run server (system level) like. +If developer and running perlbrew, recommended is to use +cpan to install required modules. + #Upgrade Instructions To upgrade to newer version of this software requires data migration. diff --git a/htdocs/cgi-bin/stats.cgi b/htdocs/cgi-bin/stats.cgi index 7be5ae7..d91d7a3 100755 --- a/htdocs/cgi-bin/stats.cgi +++ b/htdocs/cgi-bin/stats.cgi @@ -15,11 +15,7 @@ use DBI; use DateTime; use DateTime::Format::SQLite; use Number::Bytes::Human qw(format_bytes); -my $HS; -#perlbrew fix, with main::sub not recognised in inxi.pl -BEGIN { - $HS = `inxi -b -c0; uptime -p`; -} +use IPC::Run qw( run ); #SETTINGS HERE! @@ -29,6 +25,7 @@ my $LOG_PATH = '../../dbLifeLog/'; my $RELEASE_VER = ""; my $THEME = 0; my $TH_CSS = 'main.css'; +my $DEBUG = 0; #END OF SETTINGS my $cgi = CGI->new; @@ -39,11 +36,15 @@ my $userid =$session->param('alias'); my $password=$session->param('passw'); if(!$userid||!$dbname){ - # print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid"); - # exit; - $userid ="admin"; - $dbname = "data_admin_log.db"; - $password = "admin"; + if ($DEBUG){ + $userid ="admin"; + $dbname = "data_admin_log.db"; + $password = "admin"; + } + else{ + print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid"); + exit; + } } my $database = '../../dbLifeLog/' . $dbname; @@ -103,6 +104,16 @@ my $gross = big_money($income - $expense); $expense = big_money(sprintf("%.2f",$expense)); $income = big_money(sprintf("%.2f",$income)); + +#Under perlbrew, sometimes STDOUT is not piped back to our cgi, +#utility inxi could be a perl written version on newer systems. +#So I use the inter processing module here for inxi. -- @wbudic +my $HS = ""; +my @cmd = ("inxi", "-b", "-c0"); +run \@cmd, '>&', \$HS; #instead of -> system("inxi",'-b', '-c0'); + $HS .= `uptime -p`; + + my $hardware_status = $HS;#`inxi -b -c0; uptime -p`; $hardware_status =~ s/\n//g; $hardware_status =~ s/Memory:/Memory:/g; -- 2.34.1