]> bicyclesonthemoon.info Git - ott/enhance/blob - posted.c
ef4e19fd6d671d4e22ac3e086cb2d1c7228efc46
[ott/enhance] / posted.c
1 // posted.c (1190.bicyclesonthemoon.info/ct-if)\r
2 // Display the post list\r
3 // 23.11.2014\r
4 // \r
5 // Copyright (C) 2014  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 LS_PATH "/bin/ls"\r
30 #define RM_PATH "/bin/rm"\r
31 #define MAWK_PATH "/usr/bin/mawk"\r
32 #define AWK_POSTED "/eizm/pro/ong1/posted.awk"\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[256]="";\r
41         char line[32];\r
42         char filename[32];\r
43         char postpath[256];\r
44         FILE *tempfile;\r
45         // FILE *postfile;\r
46         unsigned char i;\r
47         unsigned char fff;\r
48         // dup2(fileno(stdout),fileno(stderr));\r
49         cgi=cgiInit();\r
50         fff=(cgiGetValue(cgi,"fff")!=NULL);\r
51         \r
52         sprintf(temppath,"%s%lu",TEMP_PATH,(unsigned long)getpid());\r
53         \r
54         printf("Content-type: text/html\n\n");\r
55         printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"\">\n");\r
56         printf("<html lang=\"en\"><head>\n");\r
57         printf("<title>Chronotransponder test interface &bull; Bicycles on the Moon</title>\n");\r
58         printf("<meta http-equiv=\"Content-type\" content=\"text/html; charset=UTF-8\">\n");\r
59         printf("<link rel=\"icon\" type=\"image/png\" href=\"/img/favicon.png\">\n");\r
60         printf("<link rel=\"stylesheet\" href=\"/css/botm.css\">\n");\r
61         printf("</head><body><a href=\"/\"><img src=\"/img/botmlogo2.png\" alt=\"1190.bicyclesonthemoon.info\" border=\"0\"></a>\n");\r
62         printf("<h1>Chronotransponder test interface</h1>\n");\r
63         \r
64         fflush(stdout);\r
65         sub=fork();\r
66         if(sub==0)\r
67         {\r
68                 if(freopen(temppath,"wt",stdout)==NULL)\r
69                         exit(255);\r
70                 r=execl(LS_PATH,LS_PATH,"-1","--color=never",MPOST_PATH,(char *)0);\r
71                 exit(r);\r
72         }\r
73         waitpid(sub,&r,0);\r
74         if(r)\r
75                 printf("No messages.<br>\n");\r
76         else\r
77         {\r
78                 printf("<table class=\"pl\"><tr class=\"pls\"><td colspan=\"5\">CT</td></tr>\n");\r
79                 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
80                 \r
81                 tempfile=fopen(temppath,"rt");\r
82                 if(tempfile!=NULL)\r
83                 {\r
84                         for(i=0; fgets(line,31,tempfile)!=NULL; ++i)\r
85                         {\r
86                                 sscanf(line,"%s",filename);\r
87                                 sprintf(postpath,"%s%s",MPOST_PATH,filename);\r
88                                 \r
89                                 fflush(stdout);\r
90                                 sub=fork();\r
91                                 if(!sub)\r
92                                 {\r
93                                         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
94                                         exit(r);\r
95                                 }\r
96                                 waitpid(sub,&r,0);\r
97                                 \r
98                         }\r
99                         fclose(tempfile);\r
100                 }\r
101                 printf("</table><br><b><a href=\"/ct-if-p%s\">Send a message</a></b><br>\n",fff?"?fff=fff":"");\r
102 \r
103         }\r
104         \r
105         // if(fff)\r
106         // {\r
107         fflush(stdout);\r
108         sub=fork();\r
109         if(sub==0)\r
110         {\r
111                 if(freopen(temppath,"wt",stdout)==NULL)\r
112                         exit(255);\r
113                 r=execl(LS_PATH,LS_PATH,"-1","--color=never",WAIT_PATH,(char *)0);\r
114                 exit(r);\r
115         }\r
116         waitpid(sub,&r,0);\r
117         if(r)\r
118                 printf("No messages.<br>\n");\r
119         else\r
120         {\r
121                 printf("<br><table class=\"pl\"><tr class=\"pls\"><td colspan=\"5\">WAIT</td></tr>\n");\r
122                 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
123                 \r
124                 tempfile=fopen(temppath,"rt");\r
125                 if(tempfile!=NULL)\r
126                 {\r
127                         for(i=0; fgets(line,31,tempfile)!=NULL; ++i)\r
128                         {\r
129                                 sscanf(line,"%s",filename);\r
130                                 sprintf(postpath,"%s%s",WAIT_PATH,filename);\r
131                                 \r
132                                 fflush(stdout);\r
133                                 sub=fork();\r
134                                 if(!sub)\r
135                                 {\r
136                                         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
137                                         exit(r);\r
138                                 }\r
139                                 waitpid(sub,&r,0);\r
140                                 if(r)\r
141                                 --i;\r
142                                 \r
143                         }\r
144                         fclose(tempfile);\r
145                 }\r
146                 \r
147                 printf("</table>%s\n",fff?"<br><b><a href=\"/ct-if-f\">Force delivery</a></b><br>":"");\r
148         }\r
149 // }\r
150         \r
151         printf("<br><a href=\"/\">1190.bicyclesonthemoon.info</a></body></html>\n");\r
152         \r
153         fflush(stdout);\r
154         sub=fork();\r
155         if(sub==0)\r
156         {\r
157                 r=execl(RM_PATH,RM_PATH,"-f",temppath,(char *)0);\r
158                 exit(r);\r
159         }\r
160         waitpid(sub,&r,0);\r
161         \r
162         return 0;\r
163 }\r