2

In my lab, we are trying to build a web that allows the user to enter queries for find, ack, grep on a specific directory. The web would return an HTML with a table of a list of clickable files (click on them would download the file).

For example, in this interface the user would type a word in a form in the browser, and the system would call find . -name "*word*" and send back an HTML with the result.

Has anything like this been done before? We would like to avoid reinventing the wheel. What toolkits, utilities or packages would be helpful to build this functionality?

4
  • 3
    Hundreds of times. I guess everybody who ever used CGIs did that or a similar thing at one point or another. Also, it is pretty straightforward to get using a simple Perl script, if what you are looking for is simplicity, then maybe this will be easier than to install and configure something way more complex.
    – January
    Commented Oct 15, 2012 at 18:08
  • @January, I'm not so sure about the simplicity of the task. By default from a CGI script find and grep will probably run with other user's permissions than the one using the web interface, so they will not be able to access a lot of files. And while a brute force search with find and grep may take quite long, some intermediary feedback to the user will be needed. Additionally you may have to overcome the web server's maximum request time limitation. And if the result list is too long, some paging, preferably with caching, will be needed too.
    – manatwork
    Commented Oct 16, 2012 at 7:47
  • 2
    @manatwork: first, the permissions are not an issue, since we are talking "specific directory" and read only access. Also, to do it properly, yes, it would require more effort. But to do it properly, no one will build a web interface to command line tools for searching files in lieu of a database.
    – January
    Commented Oct 16, 2012 at 7:49
  • 1
    @January, you are right. But as I understand, user27915816 wants a solution usable in their daily work. Maybe a desktop search engine would serve his needs better. For example Beagle desktop search engine with Peagle web interface.
    – manatwork
    Commented Oct 16, 2012 at 8:03

3 Answers 3

2

My favorite solution in this case is a CGI perl script. In this way you can handle special cases like

word = " -delete -name "

and you have to provide a mapping from a path in your file system to a web server url.

1
  • 1
    +1 for touching on input sanitization. I don't think this has been emphasized enough here.
    – Joseph R.
    Commented Aug 3, 2013 at 19:06
1

At its simplest, what you are asking for is very easy:

HTML

<html><body>
 <form action="../cgi-bin/find_files.pl" method="POST">
  <input type="text" name=name></input>
  <input type=submit>
 </form>

Perl script

#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser); 
my $cgi = new CGI;
my $target='/tmp';   ## directory to search in
my $name = $cgi->param('name') || carp("no search terms entered");
my $res=`find $target -name $name`;
my @lines=split(/\n/,$res);
print header;
print "<table>";
foreach my $line (@lines) {
    print "<tr><td>$line</td></tr>";
}
print "</table>";
-1

Here's a web-based tool like you've requested that has been around since 2009: https://www.online-utility.org/text/grep.jsp

But it only works on static text, so you'd have to figure out a way to get your local directory listings into the browser.

4
  • Answers should be self-contained. If you link to another site, please at least summarize the relevant bits from the linked document.
    – Kusalananda
    Commented Jan 30, 2018 at 13:42
  • A link is almost what is requested in the question here, but not quite. If the linked utility is available for download and local use, you should say so before this answer gets deleted for not answering the question.
    – Jeff Schaller
    Commented Jan 30, 2018 at 14:28
  • it's not a document at the link it's a tool @Kusalananda Commented Jan 30, 2018 at 18:34
  • @MattSephton Well, the OP wanted help with constructing their own too, so if the site you linked to does not help with this I'm not sure the answer is very helpful.
    – Kusalananda
    Commented Jan 30, 2018 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .