2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-07 19:04:20 +00:00

98_version.pm: add optional "noheader" attribute by betateilchen (Forum: #48362), eval regexp before using to avoid FHEM crash

git-svn-id: https://svn.fhem.de/fhem/trunk@10656 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2016-01-29 16:12:09 +00:00
parent 42dd13e8a0
commit b25041f63d

View File

@ -7,7 +7,7 @@ use warnings;
sub version_Initialize($$) {
$cmds{version} = { Fn => "CommandVersion",
Hlp=>"[filter],print SVN version of loaded modules"};
Hlp=>"[<filter>] [noheader],print SVN version of loaded modules"};
}
#####################################
@ -16,6 +16,11 @@ CommandVersion($$)
{
my ($cl, $param) = @_;
my $noheader = ($param =~ s/\s+noheader\s*$//);
eval { "test" =~ /$param/ };
return "invalid filter regexp" if($@);
my @ret;
my $max = 0;
my $modpath = (exists($attr{global}{modpath}) ? $attr{global}{modpath} : "");
@ -55,7 +60,7 @@ CommandVersion($$)
@ret = map {/\$Id\: (\S+) (\S+) (.+?) \$/ ? sprintf("%-".$max."s %5d %s",$1,$2,$3) : $_} @ret;
@ret = sort {version_sortModules($a, $b)} grep {(defined($param) ? $_ =~ /$param/ : 1)} @ret;
return "no loaded modules found that match: $param" if($param && !@ret);
return sprintf("%-".$max."s %s","File","Rev Last Change\n\n").
return ($noheader ? "" : sprintf("%-".$max."s %s","File","Rev Last Change\n\n")).
trim(join("\n", grep (($_ =~ /^fhem.pl|\d\d_/), @ret))."\n\n".
join("\n", grep (($_ !~ /^fhem.pl|\d\d_/), @ret))
);
@ -91,13 +96,15 @@ sub version_sortModules($$)
<a name="version"></a>
<h3>version</h3>
<ul>
<code>version [filter]</code>
<code>version [&lt;filter&gt;] [noheader]</code>
<br><br>
List the version of fhem.pl and all loaded modules. The optional parameter
can be used to filter the ouput.
can be used to filter the ouput.<br><br>
The optional flag <code>noheader</code> disables the output of the header line (File, Rev, Last Change).
<br><br>
Example output of "<code>version</code>":
Example output of <code>version</code>:
<ul>
<code><br>
File&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rev&nbsp;&nbsp;&nbsp;Last&nbsp;Change<br><br>
@ -106,16 +113,24 @@ sub version_sortModules($$)
98_autocreate.pm&nbsp;10165&nbsp;2015-12-13&nbsp;11:14:15Z&nbsp;rudolfkoenig<br>
00_CUL.pm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10146&nbsp;2015-12-10&nbsp;10:17:42Z&nbsp;rudolfkoenig<br>
10_CUL_HM.pm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10411&nbsp;2016-01-08&nbsp;15:18:17Z&nbsp;martinp876<br>
...
</code>
</ul>
<br>
Example output of "<code>version fhem</code>":
Example output of <code>version fhem.pl</code>:
<ul>
<code><br>
File&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rev&nbsp;&nbsp;&nbsp;Last&nbsp;Change<br><br>
fhem.pl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10397&nbsp;2016-01-07&nbsp;08:36:49Z&nbsp;rudolfkoenig<br>
</code>
</ul>
<br>
Example output of <code>version fhem.pl noheader</code>:
<ul>
<code><br>
fhem.pl&nbsp;10397&nbsp;2016-01-07&nbsp;08:36:49Z&nbsp;rudolfkoenig<br>
</code>
</ul>
</ul>
=end html
@ -125,13 +140,14 @@ sub version_sortModules($$)
<a name="version"></a>
<h3>version</h3>
<ul>
<code>version [filter]</code>
<code>version [&lt;filter&gt;] [noheader]</code>
<br><br>
Gibt die Versionsinformation von fhem.pl und aller geladenen Module aus. Mit
der optionalen Parameter kann man die Ausgabe filtern.
<br><br>
Beispiel der Ausgabe von "<code>version</code>":
Der optionale Parameter <code>noheader</code> unterdrückt die Ausgabe des Listenkopf (File, Rev, Last Change).
<br><br>
Beispiel der Ausgabe von <code>version</code>:
<ul>
<code><br>
File&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rev&nbsp;&nbsp;&nbsp;Last&nbsp;Change<br><br>
@ -140,16 +156,24 @@ sub version_sortModules($$)
98_autocreate.pm&nbsp;10165&nbsp;2015-12-13&nbsp;11:14:15Z&nbsp;rudolfkoenig<br>
00_CUL.pm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10146&nbsp;2015-12-10&nbsp;10:17:42Z&nbsp;rudolfkoenig<br>
10_CUL_HM.pm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10411&nbsp;2016-01-08&nbsp;15:18:17Z&nbsp;martinp876<br>
...
</code>
</ul>
<br>
Beispiel der Ausgabe von "<code>version fhem</code>":
Beispiel der Ausgabe von <code>version fhem</code>:
<ul>
<code><br>
File&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rev&nbsp;&nbsp;&nbsp;Last&nbsp;Change<br><br>
fhem.pl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10397&nbsp;2016-01-07&nbsp;08:36:49Z&nbsp;rudolfkoenig<br>
</code>
</ul>
<br>
Beispiel der Ausgabe von <code>version fhem.pl noheader</code>:
<ul>
<code><br>
fhem.pl&nbsp;10397&nbsp;2016-01-07&nbsp;08:36:49Z&nbsp;rudolfkoenig<br>
</code>
</ul>
</ul>
=end html_DE