1. Environmental
/usr/local/apache/htdocs/(Files to be retrieved are in this directory)
/usr/local/apache/temp/(as a transit folder)
/usr/local/apache/cgi-bin/
2. Place the a.out produced by GCC search.c in/usr/local/apache/cgi-bin/and the permissions set to nobody can be performed.
3. Chown-r Nobody.nobody/usr/local/apache/temp
4. Add a file deletetemp permission in/etc/cron.daily to 555
Rm-f/usr/local/apache/temp/*
5. Add a file myupdate permission in/etc/cron.hourly to 555
Updatedb-u/usr/local/apache/htdocs
6. Delete a file in the/etc/cron.daily Slocate.cron
Appendix (total 2 article):
1. Index.htm's source code
<title>untitled document</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
<p> Please enter your query string </p>
<form name= "Form1" action= "" >
<p> </p>
<p>
<input name= "KeyName" value= "" type=text>
</p>
<p>
<input type= "Submit" value= "Query" >
</p>
</form>
<p> </p>
</body>
2. SEARCH.C's source code
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
int main (int argc, char* argv ())
{
int FD;
int status;
time_t i;
Char cFileName (64);
Char Ctempname (64);
Char Cbuffer (1024);
char *p = cbuffer;
Char ccontent (10240);
Char *data;
char keyword (1024);
data = getenv ("query_string");
if (data==null)
{
printf ("content-type:text/html");
printf ("Not found!");
Exit (1);
}
SSCANF (data, "keyname=%s&", keyword);
p + + sprintf (p, "locate '%s ' | Sed-e ' s#^/usr/local/apache/htdocs#http://129.158.217.223# ' | Sed-e ' S#^.*$#<a href=&>&</a>
# ' > ', keyword);
i = time (NULL);
sprintf (Ctempname, "%d.html", I);
sprintf (cFileName, "/usr/local/apache/temp/%d.html", I);
strcat (Cbuffer, cFileName);
Cbuffer (1024-1) = 0;
System (Cbuffer);
FD = open (cFileName, O_RDWR);
Status = Read (FD, ccontent, sizeof (ccontent)-1);
Close (FD);
printf ("content-type:text/html");
printf ("<meta http-equiv=refresh content=0;url=" ">", Ctempname);
printf ("Waiting ............... ");
printf ("%s", keyword);
return 0;
}