"makegraphbox" is modified to remove the old iframe method and output
a modern div container instead.
Graph errors are now returned, to be displayed by getrrdimage.cgi.
entropy.cgi and netovpnsrv.cgi are modified to ensure compatibility.
Add cache control HTTP header to image output.
Signed-off-by: Leo-Andres Hofmann <hofmann@leo-andres.de>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
+use experimental 'smartmatch';
require '/var/ipfire/general-functions.pl';
require "${General::swroot}/lang.pl";
require '/var/ipfire/general-functions.pl';
require "${General::swroot}/lang.pl";
&General::readhash("${General::swroot}/sensors/settings", \%sensorsettings);
# Generate a nice box for selection of time range in graphs
&General::readhash("${General::swroot}/sensors/settings", \%sensorsettings);
# Generate a nice box for selection of time range in graphs
-# this will generate a nice iframe for the cgi every klick for
-# the graph will be handled inside the iframe
+# this will generate a nice div box for the cgi every klick for
+# the graph will be handled by javascript
# 0 is the cgi refering to
# 1 is the graph name
# 0 is the cgi refering to
# 1 is the graph name
-# 2 is the time range for the graph
-# 3 if given is the height of the iframe default if nothing is given
+# 2 is the time range for the graph (optional)
- print "<center>";
- print "<a href='".$_[0]."?".$_[1]."?hour' target='".$_[1]."box'><b>".$Lang::tr{'hour'}."</b></a>";
- print " - ";
- print "<a href='".$_[0]."?".$_[1]."?day' target='".$_[1]."box'><b>".$Lang::tr{'day'}."</b></a>";
- print " - ";
- print "<a href='".$_[0]."?".$_[1]."?week' target='".$_[1]."box'><b>".$Lang::tr{'week'}."</b></a>";
- print " - ";
- print "<a href='".$_[0]."?".$_[1]."?month' target='".$_[1]."box'><b>".$Lang::tr{'month'}."</b></a>";
- print " - ";
- print "<a href='".$_[0]."?".$_[1]."?year' target='".$_[1]."box'><b>".$Lang::tr{'year'}."</b></a>";
- print "<br></center>";
- print "<iframe class='graph' src='".$_[0]."?".$_[1]."?".$_[2]."' scrolling='no' frameborder='no' marginheight='0' name='".$_[1]."box'></iframe>";
+ my ($origin, $name, $default_range) = @_;
+
+ # Optional time range: Default to "day" unless otherwise specified
+ $default_range = "day" unless ($default_range ~~ @time_ranges);
+
+ print <<END;
+<div class="rrdimage" id="rrdimg-$name" data-origin="$origin" data-graph="$name" data-default-range="$default_range">
+ <ul>
+END
+
+ # Print range select buttons
+ foreach my $range (@time_ranges) {
+ print <<END;
+ <li><button data-range="$range" onclick="rrdimage_selectRange(this)">$Lang::tr{$range}</button></li>
+END
+ }
+
+ print <<END;
+ </ul>
+ <img src="/cgi-bin/getrrdimage.cgi?origin=${origin}&graph=${name}&range=${default_range}" alt="$Lang::tr{'graph'} ($name)">
+</div>
+END
}
# Generate the CPU Graph for the current period of time for values given by
}
# Generate the CPU Graph for the current period of time for values given by
RRDs::graph (@command);
$ERROR = RRDs::error;
RRDs::graph (@command);
$ERROR = RRDs::error;
- print "Error in RRD::graph for cpu: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for cpu: ".$ERROR."\n" if $ERROR;
}
# Generate the Load Graph for the current period of time for values given by collecd
}
# Generate the Load Graph for the current period of time for values given by collecd
"LINE1:load1".$color{"color18"},
);
$ERROR = RRDs::error;
"LINE1:load1".$color{"color18"},
);
$ERROR = RRDs::error;
- print "Error in RRD::graph for load: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for load: ".$ERROR."\n" if $ERROR;
}
# Generate the Memory Graph for the current period of time for values given by collecd
}
# Generate the Memory Graph for the current period of time for values given by collecd
"GPRINT:freepct:LAST:%3.2lf%%\\j",
);
$ERROR = RRDs::error;
"GPRINT:freepct:LAST:%3.2lf%%\\j",
);
$ERROR = RRDs::error;
- print "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
}
# Generate the Swap Graph for the current period of time for values given by collecd
}
# Generate the Swap Graph for the current period of time for values given by collecd
"GPRINT:freepct:LAST:%3.2lf%%\\j",
);
$ERROR = RRDs::error;
"GPRINT:freepct:LAST:%3.2lf%%\\j",
);
$ERROR = RRDs::error;
- print "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
}
# Generate the Process Cpu Graph for the current period of time for values given by collecd
}
# Generate the Process Cpu Graph for the current period of time for values given by collecd
RRDs::graph (@command);
$ERROR = RRDs::error;
RRDs::graph (@command);
$ERROR = RRDs::error;
- print "Error in RRD::graph for processes: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for processes: ".$ERROR."\n" if $ERROR;
}
# Generate the Process Memory Graph for the current period of time for values given by collecd
}
# Generate the Process Memory Graph for the current period of time for values given by collecd
RRDs::graph (@command);
$ERROR = RRDs::error;
RRDs::graph (@command);
$ERROR = RRDs::error;
- print "Error in RRD::graph for processesmemory: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for processesmemory: ".$ERROR."\n" if $ERROR;
}
# Generate the Disk Graph for the current period of time for values given by collecd
}
# Generate the Disk Graph for the current period of time for values given by collecd
"GPRINT:write:LAST:%8.1lf %sBps\\j",
);
$ERROR = RRDs::error;
"GPRINT:write:LAST:%8.1lf %sBps\\j",
);
$ERROR = RRDs::error;
- print "Error in RRD::graph for ".$disk.": ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for ".$disk.": ".$ERROR."\n" if $ERROR;
}
# Generate the Interface Graph for the current period of time for values given by collecd
}
# Generate the Interface Graph for the current period of time for values given by collecd
"GPRINT:outgoing:LAST:%8.1lf %sBps\\j",
);
$ERROR = RRDs::error;
"GPRINT:outgoing:LAST:%8.1lf %sBps\\j",
);
$ERROR = RRDs::error;
- print "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
"GPRINT:outgoing:LAST:%8.1lf %sBps\\j",
);
$ERROR = RRDs::error;
"GPRINT:outgoing:LAST:%8.1lf %sBps\\j",
);
$ERROR = RRDs::error;
- print "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
}
sub updatevpnn2ngraph {
}
sub updatevpnn2ngraph {
"GPRINT:compression_out:LAST:%8.1lf %sBps\\j",
);
$ERROR = RRDs::error;
"GPRINT:compression_out:LAST:%8.1lf %sBps\\j",
);
$ERROR = RRDs::error;
- print "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR;
}
# Generate the Firewall Graph for the current period of time for values given by collecd
}
# Generate the Firewall Graph for the current period of time for values given by collecd
"GPRINT:portscan:LAST:%8.1lf %sBps\\j",
);
$ERROR = RRDs::error;
"GPRINT:portscan:LAST:%8.1lf %sBps\\j",
);
$ERROR = RRDs::error;
- print "Error in RRD::graph for firewallhits: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for firewallhits: ".$ERROR."\n" if $ERROR;
}
# Generate the Line Quality Graph for the current period of time for values given by collecd
}
# Generate the Line Quality Graph for the current period of time for values given by collecd
"GPRINT:roundtrip:LAST:%3.2lf ms\\j",
);
$ERROR = RRDs::error;
"GPRINT:roundtrip:LAST:%3.2lf ms\\j",
);
$ERROR = RRDs::error;
- print "Error in RRD::graph for link quality: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for link quality: ".$ERROR."\n" if $ERROR;
}
sub updatewirelessgraph {
}
sub updatewirelessgraph {
"GPRINT:power:LAST:%5.1lf %sdBm\\j",
);
$ERROR = RRDs::error;
"GPRINT:power:LAST:%5.1lf %sdBm\\j",
);
$ERROR = RRDs::error;
- print "Error in RRD::graph for wireless: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for wireless: ".$ERROR."\n" if $ERROR;
}
# Generate the HDD Temp Graph for the current period of time for values given by collecd and lm_sensors
}
# Generate the HDD Temp Graph for the current period of time for values given by collecd and lm_sensors
"GPRINT:temperature:LAST:%3.0lf °C\\j",
);
$ERROR = RRDs::error;
"GPRINT:temperature:LAST:%3.0lf °C\\j",
);
$ERROR = RRDs::error;
- print "Error in RRD::graph for hdd-".$disk.": ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for hdd-".$disk.": ".$ERROR."\n" if $ERROR;
}
# Generate the Temp Graph for the current period of time for values given by collecd and lm_sensors
}
# Generate the Temp Graph for the current period of time for values given by collecd and lm_sensors
RRDs::graph (@command);
$ERROR = RRDs::error;
RRDs::graph (@command);
$ERROR = RRDs::error;
- print "Error in RRD::graph for HDD Temp: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for HDD Temp: ".$ERROR."\n" if $ERROR;
}
# Generate the Fan Graph for the current period of time for values given by collecd and lm_sensors
}
# Generate the Fan Graph for the current period of time for values given by collecd and lm_sensors
RRDs::graph (@command);
$ERROR = RRDs::error;
RRDs::graph (@command);
$ERROR = RRDs::error;
- print "Error in RRD::graph for Fan Speed: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for Fan Speed: ".$ERROR."\n" if $ERROR;
}
# Generate the Voltage Graph for the current period of time for values given by collecd and lm_sensors
}
# Generate the Voltage Graph for the current period of time for values given by collecd and lm_sensors
RRDs::graph (@command);
$ERROR = RRDs::error;
RRDs::graph (@command);
$ERROR = RRDs::error;
- print "Error in RRD::graph for Voltage: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for Voltage: ".$ERROR."\n" if $ERROR;
}
RRDs::graph (@command);
$ERROR = RRDs::error;
}
RRDs::graph (@command);
$ERROR = RRDs::error;
- print "Error in RRD::graph for qos device ".$qossettings{'DEV'}.": ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for qos device ".$qossettings{'DEV'}.": ".$ERROR."\n" if $ERROR;
}
# Generate the CPU Frequency Graph for the current period of time for values given by collectd an lm_sensors
}
# Generate the CPU Frequency Graph for the current period of time for values given by collectd an lm_sensors
RRDs::graph (@command);
$ERROR = RRDs::error;
RRDs::graph (@command);
$ERROR = RRDs::error;
- print "Error in RRD::graph for cpu freq: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for cpu freq: ".$ERROR."\n" if $ERROR;
}
# Generate the Thermal Zone Temp CPU Graph
}
# Generate the Thermal Zone Temp CPU Graph
RRDs::graph (@command);
$ERROR = RRDs::error;
RRDs::graph (@command);
$ERROR = RRDs::error;
- print "Error in RRD::graph for thermal temp: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for thermal temp: ".$ERROR."\n" if $ERROR;
RRDs::graph (@command);
$ERROR = RRDs::error;
RRDs::graph (@command);
$ERROR = RRDs::error;
- print "Error in RRD::graph for entropy: ".$ERROR."\n" if $ERROR;
+ return "Error in RRD::graph for entropy: ".$ERROR."\n" if $ERROR;
}
sub updateconntrackgraph {
}
sub updateconntrackgraph {
RRDs::graph(@command);
$ERROR = RRDs::error;
RRDs::graph(@command);
$ERROR = RRDs::error;
- print STDERR "Error in RRD::Graph for conntrack: " . $ERROR . "\n" if $ERROR;
+ return "Error in RRD::Graph for conntrack: " . $ERROR . "\n" if $ERROR;
&Header::openbigbox('100%', 'left');
&Header::openbox('100%', 'center', $Lang::tr{'entropy'});
&Header::openbigbox('100%', 'left');
&Header::openbox('100%', 'center', $Lang::tr{'entropy'});
- &Graphs::makegraphbox("entropy.cgi", "day");
+ &Graphs::makegraphbox("entropy.cgi", "entropy", "day");
&Header::closebox();
# Check for hardware support.
&Header::closebox();
# Check for hardware support.
if (@vpns || %ipsecgraphs) {
foreach my $name (sort keys %ipsecgraphs) {
&Header::openbox('100%', 'center', "$Lang::tr{'ipsec connection'}: $name");
if (@vpns || %ipsecgraphs) {
foreach my $name (sort keys %ipsecgraphs) {
&Header::openbox('100%', 'center', "$Lang::tr{'ipsec connection'}: $name");
- &Graphs::makegraphbox("netovpnsrv.cgi", $ipsecgraphs{$name}, "day");
+ &Graphs::makegraphbox("netovpnsrv.cgi", "ipsec-$ipsecgraphs{$name}", "day");