国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

自制c語言編制cgi實現搜索功能

2019-11-17 05:26:38
字體:
來源:轉載
供稿:網友

  1. 環境
/usr/local/apache/htdocs/ (待檢索的文件在該目錄下)
/usr/local/apache/temp/ (作為中轉的文件夾)
/usr/local/apache/cgi-bin/
2. 將gcc search.c產生的a.out放置在/usr/local/apache/cgi-bin/中,權限設置為nobody可
以執行。
3. chown -R nobody.nobody /usr/local/apache/temp
4. 在/etc/cron.daily中增加一個文件deletetemp 權限為555
rm -f /usr/local/apache/temp/*
5. 在/etc/cron.hourly中增加一個文件myupdate 權限為555
updatedb -U /usr/local/apache/htdocs
6. 刪除/etc/cron.daily中的一個文件slocate.cron

附錄(共2條):
1. index.htm的源碼
<Html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body>
<p>請輸入你的查詢字符串</p>
<form name="form1" action="http://129.158.217.223/cgi-bin/a.out">
<p> </p>
<p>
<input name="keyname" value="" type=text>
</p>
<p>
<input type="submit" value="查詢">
</p>
</form>
<p>  </p>
</body>
</html>

2. search.c的源碼
#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("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="http://129.158.217.223/temp/%s">
", cTempName);
printf("Waiting.......................
");

printf("%s", keyword);
return 0;
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 寿光市| 天津市| 灵台县| 壶关县| 松滋市| 利津县| 灵武市| 搜索| 普洱| 嵊泗县| 安达市| 福鼎市| 新郑市| 微山县| 永兴县| 乌审旗| 温宿县| 金塔县| 磐安县| 普兰店市| 思茅市| 全椒县| 拉萨市| 兴和县| 武安市| 马鞍山市| 汉寿县| 渑池县| 南充市| 娄底市| 诏安县| 邯郸市| 清新县| 怀安县| 盐边县| 厦门市| 常州市| 长海县| 乌审旗| 泸西县| 宁化县|