#include #ifndef NO_STDLIB_H #include #else char *getenv(); #endif typedef struct { char name[228]; char val[228]; } entry; void getword(char *word, char *line, char stop); char x2c(char *what); void unescape_url(char *url); void plustospace(char *str); void escape_shell_cmd(char *cmd); void html_header(void); void html_trailer(void); main(int argc, char *argv[]) { entry entries[7]; register int x,m=0; char *cl; char comando[300]; char xpath[355]; FILE *fp; char leo[3], *error; strcpy(leo,"000"); printf("Content-type: text/html%c%c",10,10); if(strcmp(getenv("REQUEST_METHOD"),"GET")) { html_header(); printf("This script should be referenced with a METHOD of GET.\n"); printf("If you don't understand this, see this "); printf("forms overview.%c",10); html_trailer(); exit(1); } cl = getenv("QUERY_STRING"); if(cl == NULL) { html_header(); printf("No query information to decode.\n"); html_trailer(); exit(1); } for(x=0;cl[0] != '\0';x++) { m=x; getword(entries[x].val,cl,'&'); plustospace(entries[x].val); unescape_url(entries[x].val); getword(entries[x].name,entries[x].val,'='); } html_header(); for(x=0; x <= m; x++) { if(strcmp(entries[x].name,"clasif") == 0) { strcpy(comando,"/home/httpd/cgi-bin/resdal/libros/busca11 "); /* strcat(comando, xpath);*/ if(entries[x].val[0] == '\0') { entries[x].val[0] = '+'; entries[x].val[1] = '\0'; } escape_shell_cmd(entries[x].val); strcat(comando,entries[x].val); } if(strcmp(entries[x].name, "autor") == 0) { strcat(comando," "); if(entries[x].val[0] == '\0') { entries[x].val[0] = '+'; entries[x].val[1] = '\0'; } escape_shell_cmd(entries[x].val); strcat(comando,entries[x].val); } if(strcmp(entries[x].name, "idioma") == 0) { strcat(comando," "); if(entries[x].val[0] == '\0') { entries[x].val[0] = '+'; entries[x].val[1] = '\0'; } escape_shell_cmd(entries[x].val); strcat(comando,entries[x].val); } if(strcmp(entries[x].name, "desde") == 0) { strcat(comando, " "); if(entries[x].val[0] == '\0') { entries[x].val[0] = '+'; entries[x].val[1] = '\0'; } escape_shell_cmd(entries[x].val); strcat(comando,entries[x].val); } if(strcmp(entries[x].name, "hasta") == 0) { strcat(comando, " "); if(entries[x].val[0] == '\0') { entries[x].val[0] = '+'; entries[x].val[1] = '\0'; } escape_shell_cmd(entries[x].val); strcat(comando, entries[x].val); fflush(stdout); system(comando); strcat(comando," "); strcat(comando,"> /tmp/cant"); system(comando); fp=fopen("/tmp/cant","r"); fgets(leo,20,fp); if (strcmp(leo,"000") == 0) { printf("Su búsqueda no produjo resultados %c%c",10,10); } } } html_trailer(); } void html_header(void) { printf("%c",10); printf("%c",10); printf("RESDAL - Red de Seguridad y Defensa de América Latina%c",10); printf("%c",10); printf(" "); printf("
"); printf(""); printf("%c",10); printf("
%c",10); printf("    Búsquedas en la Base de datos de Libros
"); printf("

%c",10);}

void html_trailer(void)
{
	printf("
%c",10); printf("
%c",10); printf(" © RESDAL - Red de Seguridad y Defensa de América Latina %c",10); printf("%c%c",10,10); }