Skip to content

Commit

Permalink
Add "literalsearch" option to filter targets using literal strings in…
Browse files Browse the repository at this point in the history
…stead of regex (#409)

* Add "literalsearch" option to filter targets using literal strings instead of regex

* Apply suggestions from code review
  • Loading branch information
jlu5 authored Aug 9, 2024
1 parent 98d1bd2 commit 0e77c05
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- add fix for curl feature checking introduced in curl 7.74 and later @matellis
- enhancement to extend color handling, making dark templates easier to do @matellis
- enhancement to remove more borders with graphborders set to no @matellis
- add "literalsearch" option to filter targets using literal strings instead
of regex @jlu5

2021-08-13 08:12:06 +0200 Tobias Oetiker <[email protected]>

Expand Down
2 changes: 2 additions & 0 deletions etc/config.dist.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ AVERAGE 0.5 144 2400
template = @prefix@/etc/basepage.html.dist
htmltitle = yes
graphborders = no
# If enabled, treat all filter menu queries as literal strings instead of regex
literalsearch = no

+ charts

Expand Down
26 changes: 23 additions & 3 deletions lib/Smokeping.pm
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,13 @@ sub target_menu($$$$;$){
}
};
if ($filter){
if (($menu and $menu =~ /$filter/i) or ($title and $title =~ /$filter/i)){
my $filter_re;
if (($cfg->{Presentation}{literalsearch} || 'no') eq 'yes') {
$filter_re = qr/\Q$filter\E/i;
} else {
$filter_re = qr/$filter/i;
}
if (($menu and $menu =~ $filter_re) or ($title and $title =~ $filter_re)){
push @matches, ["$path$key$suffix",$menu,$class,$menuclass];
};
push @matches, target_menu($tree->{$key}, $open, "$path$key.",$filter, $suffix);
Expand Down Expand Up @@ -1718,7 +1724,12 @@ sub display_webpage($$){
my $open_orig = [@$open];
$open_orig->[-1] .= '~'.$slave if $slave;

my($filter) = ($q->param('filter') and $q->param('filter') =~ m{([- _0-9a-zA-Z\+\*\(\)\|\^\[\]\.\$]+)});
my $filter;
if (($cfg->{Presentation}{literalsearch} || 'no') eq 'yes') {
$filter = $q->param('filter');
} else {
($filter) = ($q->param('filter') and $q->param('filter') =~ m{([- _0-9a-zA-Z\+\*\(\)\|\^\[\]\.\$]+)});
}

my $tree = $cfg->{Targets};
if ($hierarchy){
Expand Down Expand Up @@ -3243,7 +3254,7 @@ Defines how the SmokePing data should be presented.
DOC
_sections => [ qw(overview detail charts multihost hierarchies) ],
_mandatory => [ qw(overview template detail) ],
_vars => [ qw (template charset htmltitle graphborders colortext colorbackground colorborder) ],
_vars => [ qw (template charset htmltitle graphborders literalsearch colortext colorbackground colorborder) ],
template =>
{
_doc => <<DOC,
Expand Down Expand Up @@ -3279,6 +3290,15 @@ DOC
By default, SmokePing will render gray border on a light gray background,
if set to 'no' borders will be hidden and the background and canvas
will be transparent.
DOC
_re => '(yes|no)',
_re_error =>"this must either be 'yes' or 'no'",
},
literalsearch => {
_doc => <<DOC,
By default, SmokePing will process filter menu queries as regular
expressions, if set to 'yes' searches will be treated as literal strings
instead.
DOC
_re => '(yes|no)',
_re_error =>"this must either be 'yes' or 'no'",
Expand Down

0 comments on commit 0e77c05

Please sign in to comment.