2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

93_DbLog: avoid FHEM from crash if SVG requests a wrong date/time format, Forum: #101005

git-svn-id: https://svn.fhem.de/fhem/trunk@20838 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2019-12-28 07:09:08 +00:00
parent d3cdc5eb42
commit d4e1365e76
3 changed files with 101 additions and 51 deletions

View File

@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- change: 93_DbLog: avoid FHEM from crash if SVG requests a wrong date/time
format, Forum: #101005
- feature 14_SD_UT: new model remote control with 4 buttons for dieselheating
new model for xavax 00111939
- bugfix: 14_SD_UT: model TR-502MSV, ident was only 8 bit, must be 12 bit long

View File

@ -30,6 +30,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
# Version History intern by DS_Starter:
our %DbLog_vNotesIntern = (
"4.9.3" => "28.12.2019 check date/time format got from SVG, Forum: #101005 ",
"4.9.2" => "16.12.2019 add \$DEVICE to attr DbLogValueFn for readonly access to the device name ",
"4.9.1" => "13.11.2019 escape \ with \\ in DbLog_Push and DbLog_PushAsync ",
"4.9.0" => "11.11.2019 new attribute defaultMinInterval to set a default minInterval central in dblog for all events ".
@ -2879,10 +2880,10 @@ sub DbLog_explode_datetime($%) {
if ($date[1]) {$retv{month} = $date[1];} else {$retv{month} = $def{month};}
if ($date[2]) {$retv{day} = $date[2];} else {$retv{day} = $def{day};}
if ($time[0]) {$retv{hour} = $time[0];} else {$retv{hour} = $def{hour};}
if ($time[1]) {$retv{minute}= $time[1];} else {$retv{minute}= $def{minute};}
if ($time[2]) {$retv{second}= $time[2];} else {$retv{second}= $def{second};}
if ($time[1]) {$retv{minute} = $time[1];} else {$retv{minute} = $def{minute};}
if ($time[2]) {$retv{second} = $time[2];} else {$retv{second} = $def{second};}
$retv{datetime}=DbLog_implode_datetime($retv{year}, $retv{month}, $retv{day}, $retv{hour}, $retv{minute}, $retv{second});
$retv{datetime} = DbLog_implode_datetime($retv{year}, $retv{month}, $retv{day}, $retv{hour}, $retv{minute}, $retv{second});
# Log 1, Dumper(%retv);
return %retv
@ -2892,7 +2893,7 @@ sub DbLog_implode_datetime($$$$$$) {
my ($year, $month, $day, $hour, $minute, $second) = @_;
my $retv = $year."-".$month."-".$day." ".$hour.":".$minute.":".$second;
return $retv;
return $retv;
}
###################################################################################
@ -3125,7 +3126,7 @@ sub DbLog_Get($@) {
my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0;
my $history = $hash->{HELPER}{TH};
my $current = $hash->{HELPER}{TC};
my $dbh;
my ($dbh,$err);
return DbLog_dbReadings($hash,@a) if $a[1] =~ m/^Readings/;
@ -3179,6 +3180,18 @@ sub DbLog_Get($@) {
$from = $from_datetime{datetime};
$to = $to_datetime{datetime};
$err = DbLog_checkTimeformat($from); # Forum: https://forum.fhem.de/index.php/topic,101005.0.html
if($err) {
Log3($name, 1, "DbLog $name - Wrong date/time format (from: $from) requested by SVG: $err");
return;
}
$err = DbLog_checkTimeformat($to); # Forum: https://forum.fhem.de/index.php/topic,101005.0.html
if($err) {
Log3($name, 1, "DbLog $name - Wrong date/time format (to: $to) requested by SVG: $err");
return;
}
if($to =~ /(\d{4})-(\d{2})-(\d{2}) 23:59:59/) {
# 03.09.2018 : https://forum.fhem.de/index.php/topic,65860.msg815640.html#msg815640
$to =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/;
@ -5707,27 +5720,38 @@ return ($desc, \@htmlArr, join("<br>", @example));
}
################################################################
#
# Charting Specific functions start here
#
################################################################
################################################################
#
# Error handling, returns a JSON String
#
################################################################
sub DbLog_jsonError($) {
my $errormsg = $_[0];
my $json = '{"success": "false", "msg":"'.$errormsg.'"}';
return $json;
return $json;
}
################################################################
# Check Zeitformat
# Zeitformat: YYYY-MM-DD HH:MI:SS
################################################################
sub DbLog_checkTimeformat ($) {
my ($t) = @_;
my (@datetime, @date, @time);
@datetime = split(" ", $t); # Datum und Zeit auftrennen
@date = split("-", $datetime[0]);
@time = split(":", $datetime[1]);
eval { timelocal($time[2], $time[1], $time[0], $date[2], $date[1]-1, $date[0]-1900); };
if ($@) {
return $@;
}
return;
}
################################################################
#
# Prepare the SQL String
#
################################################################
sub DbLog_prepareSql(@) {
my ($hash, @a) = @_;

View File

@ -1,5 +1,5 @@
############################################################################################################################################
# $Id: 93_DbLog.pm 20515 2019-11-16 09:09:31Z DS_Starter $
# $Id: 93_DbLog.pm 20773 2019-12-17 21:41:33Z DS_Starter $
#
# 93_DbLog.pm
# written by Dr. Boris Neubert 2007-12-30
@ -30,6 +30,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
# Version History intern by DS_Starter:
our %DbLog_vNotesIntern = (
"4.9.3" => "28.12.2019 check date/time format got from SVG, Forum: #101005 ",
"4.9.2" => "16.12.2019 add \$DEVICE to attr DbLogValueFn for readonly access to the device name ",
"4.9.1" => "13.11.2019 escape \ with \\ in DbLog_Push and DbLog_PushAsync ",
"4.9.0" => "11.11.2019 new attribute defaultMinInterval to set a default minInterval central in dblog for all events ".
@ -2879,10 +2880,10 @@ sub DbLog_explode_datetime($%) {
if ($date[1]) {$retv{month} = $date[1];} else {$retv{month} = $def{month};}
if ($date[2]) {$retv{day} = $date[2];} else {$retv{day} = $def{day};}
if ($time[0]) {$retv{hour} = $time[0];} else {$retv{hour} = $def{hour};}
if ($time[1]) {$retv{minute}= $time[1];} else {$retv{minute}= $def{minute};}
if ($time[2]) {$retv{second}= $time[2];} else {$retv{second}= $def{second};}
if ($time[1]) {$retv{minute} = $time[1];} else {$retv{minute} = $def{minute};}
if ($time[2]) {$retv{second} = $time[2];} else {$retv{second} = $def{second};}
$retv{datetime}=DbLog_implode_datetime($retv{year}, $retv{month}, $retv{day}, $retv{hour}, $retv{minute}, $retv{second});
$retv{datetime} = DbLog_implode_datetime($retv{year}, $retv{month}, $retv{day}, $retv{hour}, $retv{minute}, $retv{second});
# Log 1, Dumper(%retv);
return %retv
@ -2892,7 +2893,7 @@ sub DbLog_implode_datetime($$$$$$) {
my ($year, $month, $day, $hour, $minute, $second) = @_;
my $retv = $year."-".$month."-".$day." ".$hour.":".$minute.":".$second;
return $retv;
return $retv;
}
###################################################################################
@ -3125,7 +3126,7 @@ sub DbLog_Get($@) {
my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0;
my $history = $hash->{HELPER}{TH};
my $current = $hash->{HELPER}{TC};
my $dbh;
my ($dbh,$err);
return DbLog_dbReadings($hash,@a) if $a[1] =~ m/^Readings/;
@ -3179,6 +3180,18 @@ sub DbLog_Get($@) {
$from = $from_datetime{datetime};
$to = $to_datetime{datetime};
$err = DbLog_checkTimeformat($from); # Forum: https://forum.fhem.de/index.php/topic,101005.0.html
if($err) {
Log3($name, 1, "DbLog $name - Wrong date/time format (from: $from) requested by SVG: $err");
return;
}
$err = DbLog_checkTimeformat($to); # Forum: https://forum.fhem.de/index.php/topic,101005.0.html
if($err) {
Log3($name, 1, "DbLog $name - Wrong date/time format (to: $to) requested by SVG: $err");
return;
}
if($to =~ /(\d{4})-(\d{2})-(\d{2}) 23:59:59/) {
# 03.09.2018 : https://forum.fhem.de/index.php/topic,65860.msg815640.html#msg815640
$to =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/;
@ -5707,27 +5720,38 @@ return ($desc, \@htmlArr, join("<br>", @example));
}
################################################################
#
# Charting Specific functions start here
#
################################################################
################################################################
#
# Error handling, returns a JSON String
#
################################################################
sub DbLog_jsonError($) {
my $errormsg = $_[0];
my $json = '{"success": "false", "msg":"'.$errormsg.'"}';
return $json;
return $json;
}
################################################################
# Check Zeitformat
# Zeitformat: YYYY-MM-DD HH:MI:SS
################################################################
sub DbLog_checkTimeformat ($) {
my ($t) = @_;
my (@datetime, @date, @time);
@datetime = split(" ", $t); # Datum und Zeit auftrennen
@date = split("-", $datetime[0]);
@time = split(":", $datetime[1]);
eval { timelocal($time[2], $time[1], $time[0], $date[2], $date[1]-1, $date[0]-1900); };
if ($@) {
return $@;
}
return;
}
################################################################
#
# Prepare the SQL String
#
################################################################
sub DbLog_prepareSql(@) {
my ($hash, @a) = @_;
@ -6043,12 +6067,12 @@ sub DbLog_setVersionInfo($) {
if($modules{$type}{META}{x_prereqs_src} && !$hash->{HELPER}{MODMETAABSENT}) {
# META-Daten sind vorhanden
$modules{$type}{META}{version} = "v".$v; # Version aus META.json überschreiben, Anzeige mit {Dumper $modules{DbLog}{META}}
if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id: 93_DbLog.pm 20515 2019-11-16 09:09:31Z DS_Starter $ im Kopf komplett! vorhanden )
if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id: 93_DbLog.pm 20773 2019-12-17 21:41:33Z DS_Starter $ im Kopf komplett! vorhanden )
$modules{$type}{META}{x_version} =~ s/1.1.1/$v/g;
} else {
$modules{$type}{META}{x_version} = $v;
}
return $@ unless (FHEM::Meta::SetInternals($hash)); # FVERSION wird gesetzt ( nur gesetzt wenn $Id: 93_DbLog.pm 20515 2019-11-16 09:09:31Z DS_Starter $ im Kopf komplett! vorhanden )
return $@ unless (FHEM::Meta::SetInternals($hash)); # FVERSION wird gesetzt ( nur gesetzt wenn $Id: 93_DbLog.pm 20773 2019-12-17 21:41:33Z DS_Starter $ im Kopf komplett! vorhanden )
if(__PACKAGE__ eq "FHEM::$type" || __PACKAGE__ eq $type) {
# es wird mit Packages gearbeitet -> Perl übliche Modulversion setzen
# mit {<Modul>->VERSION()} im FHEMWEB kann Modulversion abgefragt werden