1 // posted.c (1190.bicyclesonthemoon.info/ct-if)
\r
2 // Display the post list
\r
5 // Copyright (C) 2014, 2016 Balthasar SzczepaĆski
\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
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
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
24 #include <sys/wait.h>
\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
39 int main(int argc, char **argv)
\r
41 char temppath[256]="";
\r
49 // dup2(fileno(stdout),fileno(stderr));
\r
51 fff=(cgiGetValue(cgi,"fff")!=NULL);
\r
53 sprintf(temppath,"%s%lu",TEMP_PATH,(unsigned long)getpid());
\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 • 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
69 if(freopen(temppath,"wt",stdout)==NULL)
\r
71 r=execl(LS_PATH,LS_PATH,"-1","--color=never",MPOST_PATH,(char *)0);
\r
76 printf("No messages.<br>\n");
\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
82 tempfile=fopen(temppath,"rt");
\r
85 for(i=0; fgets(line,31,tempfile)!=NULL; ++i)
\r
87 sscanf(line,"%s",filename);
\r
88 sprintf(postpath,"%s%s",MPOST_PATH,filename);
\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
102 printf("</table><br><b><a href=\"/ct-if-p%s\">Send a message</a></b><br>\n",fff?"?fff=fff":"");
\r
112 if(freopen(temppath,"wt",stdout)==NULL)
\r
114 r=execl(LS_PATH,LS_PATH,"-1","--color=never",WAIT_PATH,(char *)0);
\r
119 printf("No messages.<br>\n");
\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
125 tempfile=fopen(temppath,"rt");
\r
128 for(i=0; fgets(line,31,tempfile)!=NULL; ++i)
\r
130 sscanf(line,"%s",filename);
\r
131 sprintf(postpath,"%s%s",WAIT_PATH,filename);
\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
148 printf("</table>%s\n",fff?"<br><b><a href=\"/ct-if-f\">Force delivery</a></b><br>":"");
\r
158 if(freopen(temppath,"wt",stdout)==NULL)
\r
160 r=execl(LS_PATH,LS_PATH,"-1","--color=never",RMOV_PATH,(char *)0);
\r
165 printf("No messages.<br>\n");
\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
171 tempfile=fopen(temppath,"rt");
\r
174 for(i=0; fgets(line,31,tempfile)!=NULL; ++i)
\r
176 sscanf(line,"%s",filename);
\r
177 sprintf(postpath,"%s%s",RMOV_PATH,filename);
\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
195 printf("</table>\n");
\r
197 printf("<br><a href=\"/\">1190.bicyclesonthemoon.info</a></body></html>\n");
\r
203 r=execl(RM_PATH,RM_PATH,"-f",temppath,(char *)0);
\r