Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
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 Oct 15 '12 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 Oct 16 '12 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 Oct 16 '12 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 Oct 16 '12 at 8:03
add comment

2 Answers

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.

share|improve this answer
    
+1 for touching on input sanitization. I don't think this has been emphasized enough here. –  Joseph R. Aug 3 '13 at 19:06
add comment

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>";
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.