<body>
<h1>It's NewpixbOTTification time!</h1>
<form method="get" action="/cgi/npb/npbd">
- NewpixbOTTify by URL (not ready!)<br>
+ NewpixbOTTify by URL<br>
URL:
<input type="text" name="inpix" value="http://">
<input type="submit" value="NewpixbOTTify!">
#include <cgi.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
+#include <sys/stat.h>
#define WGET_PATH "/usr/bin/wget"
#define NPB_PATH "./npb"
+#define RM_PATH "/bin/rm"
int main (int argc, char *argv[]);
+void mustard(int mustard);
+
+FILE *pix;
+unsigned char buf[1024];
+char url[1024];
+char path[256];
+//char cmd[1024];
+s_cgi *cgi;
+int t;
+pid_t sub;
+struct stat st;
+unsigned long p;
+unsigned short q;
+
int main (int argc, char *argv[])
{
- FILE *pix;
- char url[1024];
- char path[256];
- //char cmd[1024];
- s_cgi *cgi;
- int t;
- pid_t sub;
cgi=cgiInit();
sprintf(url,"%s",cgiGetValue(cgi,"inpix"));
if(sub==0)
{
t=execl(WGET_PATH,WGET_PATH,"-q","-O",path,url,(char *)0);
- return t;
+ exit(t);
}
waitpid(sub,&t,0);
- if(t)return t;
+ if(t)mustard(t);
sub=fork();
if(sub==0)
{
t=execl(NPB_PATH,NPB_PATH,path,path,"q",(char *)0);
- return t;
+ exit(t);
}
waitpid(sub,&t,0);
+ if(t)mustard(t);
- printf("Content-type: text/html\n\n");
- printf("<html><head><title>It's NewpixbOTTification time!</title></head><body>");
- printf("<h1>It's NewpixbOTTification time!</h1>");
- printf("%s<br>",path);
- printf("%s<br>",url);
- printf("%d<br>",t);
- printf("%lu<br>",(unsigned long)sub);
- printf("</body></html>\n");
-
+ pix=fopen(path,"rb");
+ if(pix==NULL)
+ mustard(123);
+ fstat(fileno(pix),&st);
+ p=st.st_size/1024;
+ q=st.st_size%1024;
-
- //npbpix=fopen("/var/tmp/test","wb");
- //fclose(npbpix);
- return 0;
+ printf("Content-Length: %lu\n",(unsigned long)(st.st_size));
+ printf("Content-type: image/png\n\n");
+ for(unsigned long i=0;i<p;++i)
+ {
+ fread(buf,1,1024,pix);
+ fwrite(buf,1,1024,stdout);
+ }
+ if(q!=0)
+ {
+ fread(buf,1,q,pix);
+ fwrite(buf,1,q,pix);
+ }
+ fclose(pix);
+ fflush(stdout);
+ mustard(0);//no mustard
+}
+
+void mustard(int mustard)
+{
+ if(mustard)
+ {
+ cgiRedirect("/pro/npb/mpb.png");
+ }
+ sub=fork();
+ if(sub==0)
+ {
+ t=execl(RM_PATH,RM_PATH,"-f",path,(char *)0);
+ exit(t);
+ }
+ waitpid(sub,&t,0);
+ exit(mustard);
}
\ No newline at end of file