ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostStatus/HostStatus.cpp
(Generate patch)

Comparing HostStatus/HostStatus.cpp (file contents):
Revision 38 by Douglas Thrift, 2003-11-15T20:23:23-08:00 vs.
Revision 44 by Douglas Thrift, 2003-11-17T11:05:37-08:00

# Line 26 | Line 26 | HostStatus::HostStatus()
26          string method = sgetenv("REQUEST_METHOD");
27  
28          parse(method);
29 <
30 <        multimap<string, string>::iterator itor = cgi.find("format");
31 <
32 <        if (itor != cgi.end())
33 <        {
34 <                string format = itor->second;
35 <
36 <                page = format != "t" ? true : false;
37 <        }
29 >        mode();
30  
31          display(method);
32   }
# Line 68 | Line 60 | void HostStatus::parse(const string& met
60          while (input.good());
61   }
62  
63 + void HostStatus::mode()
64 + {
65 +        multimap<string, string>::iterator itor = cgi.find("format");
66 +
67 +        if (itor != cgi.end())
68 +        {
69 +                string format = itor->second;
70 +
71 +                page = format != "t" ? true : false;
72 +        }
73 +
74 +        if (!page) return;
75 +
76 +        host = false, name = false, address = false, platform = false, since =
77 +                false;
78 +
79 +        for (multimap<string, string>::iterator itor = cgi.find("mode"); itor !=
80 +                cgi.upper_bound("mode") && itor != cgi.end(); itor++)
81 +        {
82 +                string mode = itor->second;
83 +
84 +                for (string::iterator itor = mode.begin(); itor != mode.end(); itor++)
85 +                {
86 +                        char mode = *itor;
87 +
88 +                        switch (mode)
89 +                        {
90 +                        case 'h':
91 +                                if (!host) host = true;
92 +                                break;
93 +                        case 'n':
94 +                                if (!name) name = true;
95 +                                break;
96 +                        case 'a':
97 +                                if (!address) address = true;
98 +                                break;
99 +                        case 'p':
100 +                                if (!platform) platform = true;
101 +                                break;
102 +                        case 's':
103 +                                if (!since) since = true;
104 +                                break;
105 +                        default:
106 +                                break;
107 +                        }
108 +                }
109 +        }
110 +
111 +        if (!host && !name && !address && !platform && !since) host = true, name =
112 +                true, address = true, platform = true, since = true;
113 + }
114 +
115   void HostStatus::display(const string& method)
116   {
117          cout << "Content-Type: text/html\n\n";
# Line 115 | Line 159 | void HostStatus::display(const string& m
159          }
160          while (!done && hostupdate.good());
161  
162 <        if (page) header();
162 >        if (page) header(method);
163  
164 <        for (list<Host>::iterator itor = hosts.begin(); itor != hosts.end(); itor++)
164 >        for (list<Host>::iterator itor = hosts.begin(); itor != hosts.end();
165 >                itor++)
166          {
167                  Host host = *itor;
168  
# Line 127 | Line 172 | void HostStatus::display(const string& m
172          if (page) footer();
173   }
174  
175 < void HostStatus::header()
175 > void HostStatus::header(const string& method)
176   {
177          cout << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\"\n"
178                  << "\t\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
# Line 139 | Line 184 | void HostStatus::header()
184                  << "</head>\n"
185                  << "<body>\n"
186                  << "<h1 id=\"title\" class=\"center\">Host Status</h1>\n"
187 <                << "<table class=\"center\">\n";
188 < }
187 >                << "<form action=\"hoststatus.cgi\" method=\"POST\">\n"
188 >                << "<table class=\"center\">\n"
189 >                << "<tr>\n"
190 >                << "<td>\n"
191 >                << "<select name=\"host\" size=\"2\" multiple>\n";
192  
193 < void HostStatus::footer()
194 < {
195 <        cout << "</table>\n"
148 < /*              << "<pre>" << flush;
193 >        if (method != "POST") sputenv("QUERY_STRING=mode=h");
194 >
195 >        pstream hostupdate("./hostupdate.cgi");
196  
197 <        ipstream env("env");
197 >        if (method == "POST") hostupdate << "mode=h\n" << flush;
198 >
199 >        hostupdate.ignore(26);
200 >
201 >        list<Host> hosts;
202 >        bool done = false;
203  
204          do
205          {
206 <                string line;
206 >                Host host;
207 >
208 >                hostupdate >> host;
209  
210 <                getline(env, line);
210 >                hosts.push_back(host);
211  
212 <                cout << line << '\n';
212 >                switch (hostupdate.peek())
213 >                {
214 >                case 'h':
215 >                        break;
216 >                default:
217 >                        done = true;
218 >                        break;
219 >                }
220          }
221 <        while (env.good());
221 >        while (!done && hostupdate.good());
222  
223 <        cout << "</pre>\n"*/
223 >        set<string> selected;
224 >
225 >        for (multimap<string, string>::iterator itor = cgi.find("host"); itor !=
226 >                cgi.upper_bound("host") && itor != cgi.end(); itor++)
227 >        {
228 >                string host = itor->second;
229 >
230 >                if (host != "") selected.insert(host);
231 >        }
232 >
233 >        for (list<Host>::iterator itor = hosts.begin(); itor != hosts.end();
234 >                itor++)
235 >        {
236 >                Host host = *itor;
237 >
238 >                cout << "<option" << (selected.find(host.getHost()) != selected.end() ?
239 >                        " selected>" : ">") << host.getHost() << "</option>\n";
240 >        }
241 >
242 >        bool all = host && name && address && platform && since;
243 >
244 >        cout << "</select>\n"
245 >                << "</td>\n"
246 >                << "<td>\n"
247 >                << "<input type=\"checkbox\" name=\"mode\" value=\"h\""
248 >                << (host && !all ? " checked" : "") << ">&nbsp;Host\n"
249 >                << "<input type=\"checkbox\" name=\"mode\" value=\"n\""
250 >                << (name && !all ? " checked" : "") << ">&nbsp;Name\n"
251 >                << "<input type=\"checkbox\" name=\"mode\" value=\"a\""
252 >                << (address && !all ? " checked" : "") << ">&nbsp;Address\n"
253 >                << "<input type=\"checkbox\" name=\"mode\" value=\"p\""
254 >                << (platform && !all ? " checked" : "") << ">&nbsp;Platform\n"
255 >                << "<input type=\"checkbox\" name=\"mode\" value=\"s\""
256 >                << (since && !all ? " checked" : "") << ">&nbsp;Since\n"
257 >                << "</td>\n"
258 >                << "<td><input type=\"submit\" value=\"Status\"></td>\n"
259 >                << "</tr>\n"
260 >                << "</table>\n"
261 >                << "</form>\n"
262 >                << "<table class=\"center\">\n"
263 >                << "<tr>\n";
264 >
265 >        if (host) cout << "<th>Host</th>\n";
266 >        if (name) cout << "<th>Name</th>\n";
267 >        if (address) cout << "<th>Address</th>\n";
268 >        if (platform) cout << "<th>Platform</th>\n";
269 >        if (since) cout << "<th>Since</th>\n";
270 >
271 >        cout << "</tr>\n";
272 > }
273 >
274 > void HostStatus::footer()
275 > {
276 >        cout << "</table>\n"
277                  << "</html>\n";
278   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines