]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
Online!
authorb <b@276fc840-c973-4a23-809e-93696693fc29>
Sat, 24 May 2014 14:01:54 +0000 (14:01 +0000)
committerb <b@276fc840-c973-4a23-809e-93696693fc29>
Sat, 24 May 2014 14:01:54 +0000 (14:01 +0000)
git-svn-id: svn://botcastle1b/bluenh@2 276fc840-c973-4a23-809e-93696693fc29

bluenh.htm [new file with mode: 0644]
bluenhd.cpp [new file with mode: 0644]
makefile
nh.png [new file with mode: 0644]
param.png [new file with mode: 0644]

diff --git a/bluenh.htm b/bluenh.htm
new file mode 100644 (file)
index 0000000..3997431
--- /dev/null
@@ -0,0 +1,33 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
+<html lang="pl">
+       <head>
+               <title>ENHANCE! &bull; Bicycles on the Moon</title>
+               <meta http-equiv="Content-type" content="text/html; charset=iso-8859-2">
+               <link rel="icon" type="image/png" href="/img/favicon.png"/>
+       </head>
+       <body>
+               <a href="/"><img src="/img/botmlogo2.png" alt="1190.bicyclesonthemoon.dnsd.info" border="0"></a>
+               <h1>ENHANCE!</h1>
+               <form method="post" action="/cgi/bluenh/bluenhd" enctype='multipart/form-data'>
+                       <img src="param.png" alt="parameter explanation picture"><br>
+                       <br>
+                       a=<input type="text" name="a" value=  "0">, b=<input type="text" name="b" value= "34">, c=<input type="text" name="c" value= "41">,<br>
+                       d=<input type="text" name="d" value=  "0">, e=<input type="text" name="e" value= "40">, f=<input type="text" name="f" value="255">.<br>
+                       <br>
+                       
+                       Enhance by URL<br>
+                       URL of image:
+                       <input type="text" name="inpix">
+                       <input type="submit" value="ENHANCE!"><br>
+                       <br>
+                       Enhance by file upload<br>
+                       Upload the image:
+                       <input type="file" name="inpix2">
+                       <input type="submit" value="ENHANCE!">
+               </form>
+               <br>
+               <br>
+               Source code available at <a href="svn://bicyclesonthemoon.dnsd.info/bluenh">svn://bicyclesonthemoon.dnsd.info/bluenh</a> (use "e" to login) or <a href="http://1190.bicyclesonthemoon.dnsd.info/pro/bluenh">http://1190.bicyclesonthemoon.dnsd.info/pro/bluenh</a>.
+               
+       </body>
+</html>
diff --git a/bluenhd.cpp b/bluenhd.cpp
new file mode 100644 (file)
index 0000000..54ef528
--- /dev/null
@@ -0,0 +1,124 @@
+//  //  //Download images and 
+   //  // ENHANCE them!
+  //  //  
+ //  //   Requires cgilib
+//  //  //line 146 of cgi.h
+   //  // must be changed
+  //  //  from "extern }"
+ //  //   to "}"
+//  //  //
+   //  // ~~bicyclesonthemoon
+
+#include <cgi.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+
+#define WGET_PATH  "/usr/bin/wget"
+#define ENH_PATH   "./bluenh"
+#define RM_PATH    "/bin/rm"
+#define LOG_PATH   "/eizm/log/bluenh/bluenh.log"
+#define USERAGENT  "Bluenhancement\x20(1190.bicyclesonthemoon.dnsd.info/bluenh/bluenh.htm)"
+#define MSTD_PATH  "/pro/bluenh/nh.png"
+
+int main (int argc, char *argv[]);
+void mustard(int mustard);
+
+FILE *pix;
+unsigned char buf[1024];
+char url[1024];
+char path[256];
+char method[256];
+s_cgi *cgi;
+int t;
+pid_t sub;
+struct stat st;
+unsigned long p;
+unsigned short q;
+char **up;
+// unsigned char a,b,c,d,e,f;
+// bool meg=false;
+
+int main (int argc, char *argv[])
+{
+       cgi=cgiInit();
+       
+       up=cgiGetFiles(cgi);
+       if (up)
+       {
+               sprintf(path,"%s",cgiGetFile(cgi,up[0])->tmpfile);
+               sprintf(url,"%s",cgiGetFile(cgi,up[0])->filename);
+       }
+       else
+       {
+               sprintf(url,"%s",(cgiGetValue(cgi,"inpix")!=NULL)?(cgiGetValue(cgi,"inpix")):"");
+               sprintf(path,"/var/tmp/%lu",(unsigned long)getpid());
+               
+               //Why is  there no spawnl() in linux?
+               sub=fork();
+               if(sub==0)
+               {
+                       t=execl(WGET_PATH,WGET_PATH,"-q","-t","2","-U",USERAGENT,"-O",path,url,(char *)0);
+                       exit(t);
+               }
+               waitpid(sub,&t,0);
+               if(t)mustard(t);
+       }
+       
+       sub=fork();
+       if(sub==0)
+       {
+               t=execl(ENH_PATH,ENH_PATH,path,path,cgiGetValue(cgi,"a")!=NULL?cgiGetValue(cgi,"a"):"0",cgiGetValue(cgi,"b")!=NULL?cgiGetValue(cgi,"b"):"127",cgiGetValue(cgi,"c")!=NULL?cgiGetValue(cgi,"c"):"255",cgiGetValue(cgi,"d")!=NULL?cgiGetValue(cgi,"d"):"0",cgiGetValue(cgi,"e")!=NULL?cgiGetValue(cgi,"e"):"127",cgiGetValue(cgi,"f")!=NULL?cgiGetValue(cgi,"f"):"255","q",(char *)0);
+               exit(t);
+       }
+       waitpid(sub,&t,0);
+       if(t)mustard(t);
+       
+       pix=fopen(path,"rb");
+       if(pix==NULL)
+               mustard(123);
+       fstat(fileno(pix),&st);
+       p=st.st_size/1024;
+       q=st.st_size%1024;
+       
+       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,stdout);
+       }
+       fclose(pix);
+       fflush(stdout);
+       mustard(0);//no mustard
+}
+
+void mustard(int mustard)
+{
+       if(mustard)
+       {
+               cgiRedirect(MSTD_PATH);
+       }
+       sub=fork();
+       if(sub==0)
+       {
+               t=execl(RM_PATH,RM_PATH,"-f",path,(char *)0);
+               exit(t);
+       }
+       waitpid(sub,&t,0);
+       pix=fopen(LOG_PATH,"at");
+       if(pix!=NULL)
+       {
+               fprintf(pix,"%x %s\n",mustard,url);
+               fclose(pix);
+       }
+       exit(mustard);
+}
\ No newline at end of file
index cfa52ece423e73cfa3b92c703c707e6ae0e830ba..ed211d220dbbeeb9956ed9beb57207a827d40d79 100644 (file)
--- a/makefile
+++ b/makefile
@@ -1,8 +1,12 @@
 CC=g++
 CF=-g -Wall
 LF=-lIL
+LF2=-lcgi
 
-all: bluenh
+all: bluenh bluenhd
 
 bluenh: bluenh.cpp makefile
        $(CC) $(CF) $(LF) -o bluenh bluenh.cpp
+
+bluenhd: bluenhd.cpp makefile
+       $(CC) $(CF) -o bluenhd bluenhd.cpp $(LF2)
diff --git a/nh.png b/nh.png
new file mode 100644 (file)
index 0000000..c9aa032
Binary files /dev/null and b/nh.png differ
diff --git a/param.png b/param.png
new file mode 100644 (file)
index 0000000..d71c090
Binary files /dev/null and b/param.png differ