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 29 by Douglas Thrift, 2003-11-14T12:44:58-08:00 vs.
Revision 42 by Douglas Thrift, 2003-11-16T20:01:53-08:00

# Line 5 | Line 5
5   // $Id$
6  
7   #include "HostStatus.hpp"
8 + #include "Host.hpp"
9  
10   int main(int argc, char* argv[])
11   {
# Line 15 | Line 16 | int main(int argc, char* argv[])
16  
17   HostStatus::HostStatus()
18   {
19 + #ifndef __CYGWIN__
20 +        sputenv("TZ=:America/Los_Angeles");
21 + #else
22 +        sputenv("TZ= PST8PDT");
23 + #endif
24 +        tzset();
25 +
26          string method = sgetenv("REQUEST_METHOD");
27  
28          parse(method);
29 <
22 <        multimap<string, string>::iterator itor = cgi.find("format");
23 <
24 <        if (itor != cgi.end())
25 <        {
26 <                string format = itor->second;
27 <
28 <                if (format == "t")
29 <                {
30 <                        this->format = table;
31 <                }
32 <                else
33 <                {
34 <                        this->format = page;
35 <                }
36 <        }
29 >        mode();
30  
31          display(method);
32   }
# Line 67 | 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 83 | Line 128 | void HostStatus::display(const string& m
128                          hostupdate << itor->first << '=' << itor->second << '&';
129                  }
130  
131 <                hostupdate << '\n';
131 >                hostupdate << '\n' << flush;
132          }
133  
134 +        hostupdate.ignore(26);
135 +
136 +        list<Host> hosts;
137 +        bool done = false;
138 +
139          do
140          {
141 <                string line;
141 >                Host host;
142 >
143 >                hostupdate >> host;
144  
145 <                getline(hostupdate, line);
145 >                hosts.push_back(host);
146  
147 <                cout << line << '\n';
147 >                switch (hostupdate.peek())
148 >                {
149 >                case 'h':
150 >                case 'n':
151 >                case 'a':
152 >                case 'p':
153 >                case 's':
154 >                        break;
155 >                default:
156 >                        done = true;
157 >                        break;
158 >                }
159          }
160 <        while (hostupdate.good());
160 >        while (!done && hostupdate.good());
161 >
162 >        if (page) header(method);
163 >
164 >        for (list<Host>::iterator itor = hosts.begin(); itor != hosts.end();
165 >                itor++)
166 >        {
167 >                Host host = *itor;
168 >
169 >                cout << host << flush;
170 >        }
171 >
172 >        if (page) footer();
173 > }
174 >
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"
179 >                << "<html>\n"
180 >                << "<head>\n"
181 >                << "<link rel=\"StyleSheet\" href=\"../stylesheets/regular.css\" type="
182 >                << "\"text/css\">\n"
183 >                << "<title>Host Status</title>\n"
184 >                << "</head>\n"
185 >                << "<body>\n"
186 >                << "<h1 id=\"title\" class=\"center\">Host Status</h1>\n"
187 >                << "<form action=\"hoststatus.cgi\" method=\"POST\">\n"
188 >                << "<table class=\"center\">\n"
189 >                << "<tr>\n"
190 >                << "<td><select name=\"host\" multiple>\n";
191 >
192 >        if (method != "POST") sputenv("QUERY_STRING=mode=h");
193 >
194 >        pstream hostupdate("./hostupdate.cgi");
195 >
196 >        if (method == "POST") hostupdate << "mode=h\n" << flush;
197 >
198 >        hostupdate.ignore(26);
199 >
200 >        list<Host> hosts;
201 >        bool done = false;
202 >
203 >        do
204 >        {
205 >                Host host;
206 >
207 >                hostupdate >> host;
208 >
209 >                hosts.push_back(host);
210 >
211 >                switch (hostupdate.peek())
212 >                {
213 >                case 'h':
214 >                        break;
215 >                default:
216 >                        done = true;
217 >                        break;
218 >                }
219 >        }
220 >        while (!done && hostupdate.good());
221 >
222 >        for (list<Host>::iterator itor = hosts.begin(); itor != hosts.end();
223 >                itor++)
224 >        {
225 >                Host host = *itor;
226 >
227 >                cout << "<option>" << host.getHost() << "</option>\n";
228 >        }
229 >
230 >        cout << "</select></td>\n"
231 >                << "<td><input type=\"checkbox\" name=\"mode\" value=\"h\">&nbsp;Host"
232 >                << "\n<input type=\"checkbox\" name=\"mode\" value=\"n\">&nbsp;Name\n"
233 >                << "<input type=\"checkbox\" name=\"mode\" value=\"a\">&nbsp;Address\n"
234 >                << "<input type=\"checkbox\" name=\"mode\" value=\"p\">&nbsp;Platform"
235 >                << "\n<input type=\"checkbox\" name=\"mode\" value=\"s\">&nbsp;Since\n"
236 >                << "</td>\n"
237 >                << "<td><input type=\"submit\" value=\"Status\"></td>\n"
238 >                << "</tr>\n"
239 >                << "</table>\n"
240 >                << "</form>\n"
241 >                << "<table class=\"center\">\n"
242 >                << "<tr>\n";
243 >
244 >        if (host) cout << "<th>Host</th>\n";
245 >        if (name) cout << "<th>Name</th>\n";
246 >        if (address) cout << "<th>Address</th>\n";
247 >        if (platform) cout << "<th>Platform</th>\n";
248 >        if (since) cout << "<th>Since</th>\n";
249 >
250 >        cout << "</tr>\n";
251 > }
252 >
253 > void HostStatus::footer()
254 > {
255 >        cout << "</table>\n"
256 >                << "</html>\n";
257   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines