]> bicyclesonthemoon.info Git - ott/enhance/blob - upload.c
Update from src as of 25.05.2021
[ott/enhance] / upload.c
1 // upload.c (1190.bicyclesonthemoon.info/aftertime/upload)\r
2 // The post upload interface\r
3 // 28.03.2015\r
4 // \r
5 // Copyright (C) 2015  Balthasar SzczepaƄski\r
6 // \r
7 // This program is free software: you can redistribute it and/or modify\r
8 // it under the terms of the GNU Affero General Public License as\r
9 // published by the Free Software Foundation, either version 3 of the\r
10 // License, or (at your option) any later version.\r
11 // \r
12 // This program is distributed in the hope that it will be useful,\r
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 // GNU Affero General Public License for more details.\r
16 // \r
17 // You should have received a copy of the GNU Affero General Public License\r
18 // along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
19 \r
20 \r
21 #include <cgi.h>\r
22 #include <time.h>\r
23 #include <stdio.h>\r
24 #include <stdlib.h>\r
25 #include <unistd.h>\r
26 #include <sys/wait.h>\r
27 \r
28 #define RM_PATH "/bin/rm"\r
29 #define MAWK_PATH "/usr/bin/mawk"\r
30 #define AWK_UPLOAD "/eizm/pro/aftertime/upload.awk"\r
31 #define TEMP_PATH "/eizm/tmp/aftertime/upload."\r
32 #define RM_PATH "/bin/rm"\r
33 \r
34 s_cgi *cgi;\r
35 pid_t sub;\r
36 int r;\r
37 \r
38 int main(int argc, char **argv)\r
39 {\r
40         char *temppath;\r
41         char **up;\r
42         time_t posttime;\r
43         struct tm *nowS;\r
44         char timetext[64];\r
45         char timenumber[64];\r
46         char temppath2[247];\r
47         char temppath3[256];\r
48         \r
49         setvbuf(stdout, NULL, _IONBF, 0);\r
50         dup2(fileno(stdout),fileno(stderr));\r
51         \r
52         cgi=cgiInit();\r
53         \r
54         sprintf(temppath2,"%s%lu",TEMP_PATH,(unsigned long)getpid());\r
55         sprintf(temppath3,"tempfile=%s",temppath2);\r
56         \r
57         printf("Content-type: text\n\n");\r
58         up=cgiGetFiles(cgi);\r
59         if (up)\r
60         {\r
61                 temppath=cgiGetFile(cgi,up[0])->tmpfile;\r
62                 \r
63                 posttime=time(NULL);\r
64                 nowS=gmtime(&posttime);\r
65                 \r
66                 sprintf(timenumber,"timenumber=%lu",(unsigned long)posttime);\r
67                 sprintf(timetext,"timetext=%04d%02d%02d%02d",nowS->tm_year+1900,nowS->tm_mon+1,nowS->tm_mday,nowS->tm_hour);\r
68                 \r
69                 // printf("%s\n%s\n%s\n",timenumber,timetext,temppath);\r
70                 \r
71                 sub=fork();\r
72                 if(!sub)\r
73                 {\r
74                         r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_UPLOAD,"-v",timetext,"-v",timenumber,"-v",temppath3,temppath,(char *)0);\r
75                         exit(r);\r
76                 }\r
77                 waitpid(sub,&r,0);\r
78                 \r
79                 sub=fork();\r
80                 if(!sub)\r
81                 {\r
82                         r=execl(RM_PATH,RM_PATH,"-f",temppath,(char *)0);\r
83                         exit(r);\r
84                 }\r
85                 waitpid(sub,&r,0);\r
86                 sub=fork();\r
87                 if(!sub)\r
88                 {\r
89                         r=execl(RM_PATH,RM_PATH,"-f",temppath2,(char *)0);\r
90                         exit(r);\r
91                 }\r
92                 waitpid(sub,&r,0);\r
93                 \r
94                 return 0;\r
95         }\r
96         printf("File missing\n");\r
97         return 0;\r
98 }\r