diff --git a/fhem/CHANGED b/fhem/CHANGED
index 85b8a78fa..291764b70 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -48,6 +48,7 @@
- change: separating common functions used by the FHEM modules into
*Utils.pm files from fhem.pl
- feature: portpassword and basicAuth may use evaluated functions
+ - feature: motd with SecurityCheck added
- 2011-12-31 (5.2)
- bugfix: applying smallscreen attributes to firefox/opera
diff --git a/fhem/fhem.pl b/fhem/fhem.pl
index dd41ced19..d6a66f95b 100755
--- a/fhem/fhem.pl
+++ b/fhem/fhem.pl
@@ -195,7 +195,7 @@ $modules{Global}{AttrList} =
"verbose:1,2,3,4,5 mseclog version nofork logdir holiday2we " .
"autoload_undefined_devices dupTimeout latitude longitude " .
"backupcmd backupdir backupsymlink backup_before_update " .
- "exclude_from_update ";
+ "exclude_from_update motd";
$modules{Global}{AttrFn} = "GlobalAttr";
@@ -355,9 +355,18 @@ if($pfn) {
# create the global interface definitions
createInterfaceDefinitions();
+$attr{global}{motd} = "SecurityCheck:\n\n"
+ if(!$attr{global}{motd} || $attr{global}{motd} =~ m/^SecurityCheck/);
+
$init_done = 1;
DoTrigger("global", "INITIALIZED");
+$attr{global}{motd} .=
+ "\nSet the global attribute motd to none to supress this message,\n".
+ "or restart fhem for a new check if the problem ist fixed.\n"
+ if($attr{global}{motd} =~ m/^SecurityCheck:\n\n./);
+delete($attr{global}{motd}) if($attr{global}{motd} eq "SecurityCheck:\n\n");
+
Log 0, "Server started (version $attr{global}{version}, pid $$)";
################################################
@@ -682,6 +691,11 @@ AnalyzeInput($)
}
} else {
$client{$c}{prompt} = 1; # Empty return
+ if(!$client{$c}{motdDisplayed}) {
+ my $motd = $attr{global}{motd};
+ push @ret, $motd if($motd && $motd ne "none");
+ $client{$c}{motdDisplayed} = 1;
+ }
}
next if($rest);
}
@@ -1155,6 +1169,7 @@ CommandSave($$)
($a eq "configfile" || $a eq "version"));
my $val = $attr{$d}{$a};
$val =~ s/;/;;/g;
+ $val =~ s/\n/\\\n/g;
print $fh "attr $d $a $val\n";
}
}
diff --git a/fhem/webfrontend/pgm2/01_FHEMWEB.pm b/fhem/webfrontend/pgm2/01_FHEMWEB.pm
index 1cf552da8..78c859e80 100755
--- a/fhem/webfrontend/pgm2/01_FHEMWEB.pm
+++ b/fhem/webfrontend/pgm2/01_FHEMWEB.pm
@@ -92,7 +92,7 @@ FHEMWEB_Initialize($)
$hash->{AttrFn} = "FW_Attr";
$hash->{DefFn} = "FW_Define";
$hash->{UndefFn} = "FW_Undef";
- $hash->{NotifyFn}= "FW_Notify";
+ $hash->{NotifyFn}= "FW_SecurityCheck";
$hash->{AttrList}= "loglevel:0,1,2,3,4,5,6 webname fwmodpath fwcompress:0,1 ".
"plotmode:gnuplot,gnuplot-scroll,SVG plotsize refresh " .
"touchpad smallscreen plotfork basicAuth basicAuthMsg ".
@@ -109,6 +109,25 @@ FHEMWEB_Initialize($)
addToAttrList("icon");
}
+#####################################
+sub
+FW_SecurityCheck($$)
+{
+ my ($ntfy, $dev) = @_;
+ return if($dev->{NAME} ne "global" ||
+ !grep(m/^INITIALIZED$/, @{$dev->{CHANGED}}));
+ my $motd = AttrVal("global", "motd", "");
+ if($motd =~ "^SecurityCheck") {
+ my @list = grep { !AttrVal($_, "basicAuth", undef) }
+ devspec2array("TYPE=FHEMWEB");
+ $motd .= (join(",", sort @list)." has no basicAuth attribute\n")
+ if(@list);
+ $attr{global}{motd} = $motd;
+ }
+ $modules{FHEMWEB}{NotifyFn}= "FW_Notify";
+ return undef;
+}
+
#####################################
sub
FW_Define($$)
@@ -274,7 +293,7 @@ FW_Read($)
# BASIC HTTP AUTH
my $basicAuth = AttrVal($FW_wname, "basicAuth", undef);
if($basicAuth) {
- $hash->{BUF} =~ m/^Authorization: Basic (.*)/m;
+ $hash->{BUF} =~ m/Authorization: Basic ([^\r\n]*)/s;
my $secret = $1;
my $pwok = ($secret && $secret eq $basicAuth);
if($secret && $basicAuth =~ m/^{.*}$/) {
@@ -293,6 +312,7 @@ FW_Read($)
print $c "HTTP/1.1 401 Authorization Required\r\n",
"WWW-Authenticate: Basic realm=\"$msg\"\r\n",
"Content-Length: 0\r\n\r\n";
+ $hash->{BUF}="";
return;
};
}
@@ -302,6 +322,7 @@ FW_Read($)
my ($mode, $arg, $method) = split(" ", $FW_httpheader[0]);
$hash->{BUF} = "";
+ $arg = "" if(!defined($arg));
Log $ll, "HTTP $name GET $arg";
my $pid;
if(AttrVal($FW_wname, "plotfork", undef)) {
@@ -545,6 +566,11 @@ FW_AnswerCall($)
elsif($FW_detail) { FW_doDetail($FW_detail); }
elsif($FW_room) { FW_showRoom(); }
elsif($cmd =~ /^logwrapper/) { FW_logWrapper($cmd); }
+ elsif(AttrVal("global", "motd", "none") ne "none") {
+ my $motd = AttrVal("global","motd",undef);
+ $motd =~ s/\n/
/g;
+ FW_pO "