#include #include #include #include #include #include #include #include #include cookiecheck(int mode,char *name) { int sock; int rval; struct sockaddr_in server; struct hostent *hp, *gethostbyname(); char buf[1024]; char s[1024]; int x,y,z; char c; char *fname; int fd, status; int temp; char cookiestr[20]; char host[20]; int number; FILE *logfile; mode = 0; strcpy(name,"#"); if(mode != 10) { if(getenv("HTTP_COOKIE") == NULL) strcpy(cookiestr,""); else strcpy(cookiestr,getenv("HTTP_COOKIE")); } if(cookiestr[0] == 0) number = -1; else number = atoi(&cookiestr[9]); strcpy(host,getenv("REMOTE_ADDR")); temp = 0; /* 0 if currently NOT pressed, 1 is currently pressed */ logfile=fopen("/tmp/cookielog","a+"); fprintf(logfile,"mode: %d cookiestr: .%s.\n",mode,cookiestr); fclose(logfile); if(mode == 1 && number == -1) { printf("Guest"); exit(0); } sock = socket(AF_INET, SOCK_STREAM, 0); if(sock < 0) { perror("opening stream socket"); exit(1); } server.sin_family = AF_INET; hp = gethostbyname("doorbell"); if(hp == (struct hostent *)0) { fprintf(stderr,"%s: unknown host","doorbell"); exit(2); } bcopy(hp->h_addr, &server.sin_addr, hp->h_length); server.sin_port = htons(5202); if((connect(sock, &server, sizeof(server)), 0) < 0) { perror("connecting stream socket"); exit(1); } strcpy(s,""); sprintf(s,"%d %s %s",number,name,host); if((write(sock, s, strlen(s)), 0) < 0) perror("writing on stream socket"); if(( rval = read(sock, buf, 1024)) < 0) perror("Reading from stream socket"); close(sock); // printf("Message: .%s.\n",buf); sscanf(buf,"%d %s %s",&number,name,host); } main(argc, argv) int argc; char *argv[]; { int sock; int rval; struct sockaddr_in server; struct hostent *hp, *gethostbyname(); char buf[10010]; char s[1024]; int x,y,z; char c; FILE *in; char *fname; int fd, status; int temp; char qs[40]; char name[40]; strcpy(qs,getenv("QUERY_STRING")); temp = 0; /* 0 if currently NOT pressed, 1 is currently pressed */ fprintf(stderr,"Got query string: %s\n",qs); sock = socket(AF_INET, SOCK_STREAM, 0); if(sock < 0) { perror("opening stream socket"); exit(1); } server.sin_family = AF_INET; hp = gethostbyname("doorbell"); if(hp == (struct hostent *)0) { fprintf(stderr,"%s: unknown host", "doorbell"); exit(2); } bcopy(hp->h_addr, &server.sin_addr, hp->h_length); server.sin_port = htons(5203); fprintf(stderr,"connecting.\n"); if((connect(sock, &server, sizeof(server)), 0) < 0) { perror("connecting stream socket"); exit(1); } fprintf(stderr,"Connected.\n"); sprintf(s,"LIST %s",qs); if((write(sock, s, strlen(s)), 0) < 0) perror("writing on stream socket"); fprintf(stderr,"Sent command.\n"); x = 0; do { if(( rval = read(sock, &buf[x], 1460)) < 0) perror("Reading from stream socket"); x = x + rval; fprintf(stderr,"Reading. x=%d rval=%d\n",x,rval); } while(rval >= 1460); fprintf(stderr,"Done reading.\n"); close(sock); x=0; y=0; printf("Content-type: text/html"); printf("\n\n"); printf("\n"); in=fopen("/var/lib/httpd/htdocs/sidebar.txt","r"); fgets(s,2000,in); while(!feof(in)) { printf("%s",s); fgets(s,2000,in); } fclose(in); printf("
\n"); printf("\n"); if(buf[0] == 0) { printf("\n"); } else while(buf[x] != 0) { for(x=y;buf[x] != '\n' && buf[x] != 0;x++); strncpy(s,&buf[y],x-y); s[x-y] = 0; y=x+1; if(strcmp(s,"<.>") == 0) { printf("\n"); } else continue; } // printf("%s\n",buf); printf("
No Comments
\n"); y++; for(x=y;buf[x] != '>';x++); strncpy(s,&buf[y],x-y); s[(x-y)] = 0; printf("Nick: %s
\n",s); y=x+3; for(x=y;buf[x] != '>';x++); strncpy(s,&buf[y],x-y); s[(x-y)] = 0; printf("Date: %s

\n",s); y=x+2; for(x=y;buf[x] != '>';x++); y=x+2; for(x=y;strncmp(&buf[x],"",5) != 0;x++); strncpy(s,&buf[y],x-y); s[(x-y)] = 0; printf("%s\n",s); y=x; for(x=y;buf[x] != '>';x++); y=x+2; printf("

\n"); printf("Enter your comment here:

\n"); printf("

\n"); printf("\n",qs); cookiecheck(1,name); printf("Nick: \n",name); printf("

Comment:
\n"); printf("

\n"); printf("\n"); printf("

\n"); printf("There are no specific posting guidelines... (yet).. however, excessively obscene, abusive, harrassing, trollish, or posts with illegal content may be removed at the discretion of the site owner.\n"); printf("

\n"); }