]> bicyclesonthemoon.info Git - ott/ong1/blob - posted.c
Update from src directory as of 26.11.2016
[ott/ong1] / posted.c
1 // posted.c (1190.bicyclesonthemoon.info/ct-if)\r
2 // Display the post list\r
3 // 26.11.2016\r
4 // \r
5 // Copyright (C) 2014, 2016  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 #include <cgi.h>\r
21 #include <stdio.h>\r
22 #include <stdlib.h>\r
23 #include <unistd.h>\r
24 #include <sys/wait.h>\r
25 \r
26 #define TEMP_PATH "/eizm/tmp/ong1/posted."\r
27 #define MPOST_PATH "/eizm/mem/ong1/mpost/"\r
28 #define WAIT_PATH "/eizm/mem/ong1/mpost/wait/"\r
29 #define RMOV_PATH "/eizm/mem/ong1/mpost/rm/"\r
30 #define LS_PATH "/bin/ls"\r
31 #define RM_PATH "/bin/rm"\r
32 #define MAWK_PATH "/usr/bin/mawk"\r
33 #define AWK_POSTED "/eizm/pro/ong1/posted.awk"\r
34 \r
35 s_cgi *cgi;\r
36 pid_t sub;\r
37 int r;\r
38 \r
39 int main(int argc, char **argv)\r
40 {\r
41         char temppath[256]="";\r
42         char line[32];\r
43         char filename[32];\r
44         char postpath[256];\r
45         FILE *tempfile;\r
46         // FILE *postfile;\r
47         unsigned char i;\r
48         unsigned char fff;\r
49         // dup2(fileno(stdout),fileno(stderr));\r
50         cgi=cgiInit();\r
51         fff=(cgiGetValue(cgi,"fff")!=NULL);\r
52         \r
53         sprintf(temppath,"%s%lu",TEMP_PATH,(unsigned long)getpid());\r
54         \r
55         printf("Content-type: text/html\n\n");\r
56         printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"\">\n");\r
57         printf("<html lang=\"en\"><head>\n");\r
58         printf("<title>Chronotransponder test interface &bull; Bicycles on the Moon</title>\n");\r
59         printf("<meta http-equiv=\"Content-type\" content=\"text/html; charset=UTF-8\">\n");\r
60         printf("<link rel=\"icon\" type=\"image/png\" href=\"/img/favicon.png\">\n");\r
61         printf("<link rel=\"stylesheet\" href=\"/css/botm.css\">\n");\r
62         printf("</head><body><a href=\"/\"><img src=\"/img/botmlogo2.png\" alt=\"1190.bicyclesonthemoon.info\" border=\"0\"></a>\n");\r
63         printf("<h1>Chronotransponder test interface</h1>\n");\r
64         \r
65         fflush(stdout);\r
66         sub=fork();\r
67         if(sub==0)\r
68         {\r
69                 if(freopen(temppath,"wt",stdout)==NULL)\r
70                         exit(255);\r
71                 r=execl(LS_PATH,LS_PATH,"-1","--color=never",MPOST_PATH,(char *)0);\r
72                 exit(r);\r
73         }\r
74         waitpid(sub,&r,0);\r
75         if(r)\r
76                 printf("No messages.<br>\n");\r
77         else\r
78         {\r
79                 printf("<table class=\"pl\"><tr class=\"pls\"><td colspan=\"5\">CT</td></tr>\n");\r
80                 printf("<tr class=\"plt\"><td class=\"plk\">sent</td><td class=\"plk\">received</td><td class=\"plk\">author</td><td class=\"plk\">subject</td><td class=\"plk\">action</td></tr>\n");\r
81                 \r
82                 tempfile=fopen(temppath,"rt");\r
83                 if(tempfile!=NULL)\r
84                 {\r
85                         for(i=0; fgets(line,31,tempfile)!=NULL; ++i)\r
86                         {\r
87                                 sscanf(line,"%s",filename);\r
88                                 sprintf(postpath,"%s%s",MPOST_PATH,filename);\r
89                                 \r
90                                 fflush(stdout);\r
91                                 sub=fork();\r
92                                 if(!sub)\r
93                                 {\r
94                                         r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_POSTED,"-v",i&0x1?"r2=1":"r2=0","-v","cat=ct","-v",fff?"fff=fff":"f=f",postpath,(char *)0);\r
95                                         exit(r);\r
96                                 }\r
97                                 waitpid(sub,&r,0);\r
98                                 \r
99                         }\r
100                         fclose(tempfile);\r
101                 }\r
102                 printf("</table><br><b><a href=\"/ct-if-p%s\">Send a message</a></b><br>\n",fff?"?fff=fff":"");\r
103 \r
104         }\r
105         \r
106         // if(fff)\r
107         // {\r
108         fflush(stdout);\r
109         sub=fork();\r
110         if(sub==0)\r
111         {\r
112                 if(freopen(temppath,"wt",stdout)==NULL)\r
113                         exit(255);\r
114                 r=execl(LS_PATH,LS_PATH,"-1","--color=never",WAIT_PATH,(char *)0);\r
115                 exit(r);\r
116         }\r
117         waitpid(sub,&r,0);\r
118         if(r)\r
119                 printf("No messages.<br>\n");\r
120         else\r
121         {\r
122                 printf("<br><table class=\"pl\"><tr class=\"pls\"><td colspan=\"5\">WAIT</td></tr>\n");\r
123                 printf("<tr class=\"plt\"><td class=\"plk\">sent</td><td class=\"plk\">to be received</td><td class=\"plk\">author</td><td class=\"plk\">subject</td><td class=\"plk\">action</td></tr>\n");\r
124                 \r
125                 tempfile=fopen(temppath,"rt");\r
126                 if(tempfile!=NULL)\r
127                 {\r
128                         for(i=0; fgets(line,31,tempfile)!=NULL; ++i)\r
129                         {\r
130                                 sscanf(line,"%s",filename);\r
131                                 sprintf(postpath,"%s%s",WAIT_PATH,filename);\r
132                                 \r
133                                 fflush(stdout);\r
134                                 sub=fork();\r
135                                 if(!sub)\r
136                                 {\r
137                                         r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_POSTED,"-v",i&0x1?"r2=1":"r2=0","-v","cat=wt","-v",fff?"fff=fff":"f=f",postpath,(char *)0);\r
138                                         exit(r);\r
139                                 }\r
140                                 waitpid(sub,&r,0);\r
141                                 if(r)\r
142                                 --i;\r
143                                 \r
144                         }\r
145                         fclose(tempfile);\r
146                 }\r
147                 \r
148                 printf("</table>%s\n",fff?"<br><b><a href=\"/ct-if-f\">Force delivery</a></b><br>":"");\r
149         }\r
150 // }\r
151         \r
152         if(fff)\r
153         {\r
154                 fflush(stdout);\r
155                 sub=fork();\r
156                 if(sub==0)\r
157                 {\r
158                         if(freopen(temppath,"wt",stdout)==NULL)\r
159                                 exit(255);\r
160                         r=execl(LS_PATH,LS_PATH,"-1","--color=never",RMOV_PATH,(char *)0);\r
161                         exit(r);\r
162                 }\r
163                 waitpid(sub,&r,0);\r
164                 if(r)\r
165                         printf("No messages.<br>\n");\r
166                 else\r
167                 {\r
168                         printf("<br><table class=\"pl\"><tr class=\"pls\"><td colspan=\"5\">RMVD</td></tr>\n");\r
169                         printf("<tr class=\"plt\"><td class=\"plk\">sent</td><td class=\"plk\">received</td><td class=\"plk\">author</td><td class=\"plk\">subject</td><td class=\"plk\">action</td></tr>\n");\r
170                         \r
171                         tempfile=fopen(temppath,"rt");\r
172                         if(tempfile!=NULL)\r
173                         {\r
174                                 for(i=0; fgets(line,31,tempfile)!=NULL; ++i)\r
175                                 {\r
176                                         sscanf(line,"%s",filename);\r
177                                         sprintf(postpath,"%s%s",RMOV_PATH,filename);\r
178                                         \r
179                                         fflush(stdout);\r
180                                         sub=fork();\r
181                                         if(!sub)\r
182                                         {\r
183                                                 r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_POSTED,"-v",i&0x1?"r2=1":"r2=0","-v","cat=rm","-v",fff?"fff=fff":"f=f",postpath,(char *)0);\r
184                                                 exit(r);\r
185                                         }\r
186                                         waitpid(sub,&r,0);\r
187                                         if(r)\r
188                                         --i;\r
189                                         \r
190                                 }\r
191                                 fclose(tempfile);\r
192                         }\r
193                         \r
194                 }\r
195                 printf("</table>\n");\r
196         }       \r
197         printf("<br><a href=\"/\">1190.bicyclesonthemoon.info</a></body></html>\n");\r
198         \r
199         fflush(stdout);\r
200         sub=fork();\r
201         if(sub==0)\r
202         {\r
203                 r=execl(RM_PATH,RM_PATH,"-f",temppath,(char *)0);\r
204                 exit(r);\r
205         }\r
206         waitpid(sub,&r,0);\r
207         \r
208         return 0;\r
209 }\r