grep_search1.cgi

来自「嵌入式WEB」· CGI 代码 · 共 56 行

CGI
56
字号
#!/usr/bin/perl -wT# WARNING: This code has significant limitations; see descriptionuse strict;use CGI;use CGIBook::Error;# Make the environment safe to call fgrepBEGIN {    $ENV{PATH} = "/bin:/usr/bin";    delete @ENV{ qw( IFS CDPATH ENV BASH_ENV ) };}my $FGREP         = "/usr/local/bin/fgrep";my $DOCUMENT_ROOT = $ENV{DOCUMENT_ROOT};my $VIRTUAL_PATH  = "";my $q       = new CGI;my $query   = $q->param( "query" );$query =~ s/[^\w ]//g;$query =~ /([\w ]+)/;$query = $1;unless ( defined $query ) {    error( $q, "Please specify a valid query!" );}my $results = search( $q, $query );print $q->header( "text/html" ),      $q->start_html( "Simple Search with fgrep" ),      $q->h1( "Search for: $query" ),      $q->ul( $results || "No matches found" ),      $q->end_html;sub search {    my( $q, $query ) = @_;    local *PIPE;    my $matches = "";        open PIPE, "$FGREP -il '$query' $DOCUMENT_ROOT/* |"        or die "Cannot open fgrep: $!";        while ( <PIPE> ) {        chomp;        s|.*/||;        $matches .= $q->li(                        $q->a( { href => "$VIRTUAL_PATH/$_" }, $_ )                    );    }    close PIPE;    return $matches;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?