]> bicyclesonthemoon.info Git - ott/enhance/blob - reveal-cgi.c
diff online
[ott/enhance] / reveal-cgi.c
1 /*
2 reveal-cgi.c
3 The online interface for the hidden detail revealer tool
4 04.12.2022
5
6 Copyright (C) 2022  Balthasar SzczepaƄski
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 Requires cgilib (http://www.infodrom.org/projects/cgilib/)
22 */
23
24 #include <stdio.h>
25 #include <stdint.h>
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <sys/wait.h>
29 //#include <stdint.h>
30 //#include <inttypes.h>
31
32 #include <cgi.h>
33
34 #include "online-core.h"
35 #include "rvl.h"
36
37 int reveal (char *inpix, char *outpix);
38
39 int main (int argc, char *argv[])
40 {
41         s_cgi *cgi;
42         char in_tmp[256];
43         char out_tmp[256];
44         char *in_path;
45         
46         int r=0;
47         int r1=0;
48         int r2=0;
49         int r3=0;
50
51         do {
52                 make_tmp_path(in_tmp, 256, 0, "");
53                 make_tmp_path(out_tmp, 256, 1, ".png");
54                 
55                 cgi=cgiInit();
56                 
57                 r = get_file(cgi,"inpix", in_tmp, &in_path);
58                 if (r)
59                         break;
60                 
61                 r = reveal(in_path, out_tmp);
62                 if (r)
63                         break;
64                 r1 = send_file(out_tmp, "image/png", 0);
65         } while (0);
66         if (r)
67         {
68                 r1 = send_data(rvl, rvl_size, "image/png", 500);
69         }
70         r2 = rm(in_tmp);
71         r3 = rm(out_tmp);
72         if (r)
73                 return r;
74         if (r1)
75                 return r1;
76         if (r2)
77                 return r2;
78         if (r3)
79                 return r3;
80         return 0;
81 }
82
83 int reveal (char *inpix, char *outpix)
84 {
85         pid_t sub;
86         int r;
87         
88         sub = fork();
89         if (sub == 0)
90         {
91                 r = execl(REVEAL_PATH, REVEAL_PATH, inpix, outpix, (char *)0);
92                 exit(r);
93         }
94         waitpid(sub, &r, 0);
95         return r;
96 }