1 |
Douglas Thrift |
27 |
// Host Status |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
#include "HostStatus.hpp" |
8 |
Douglas Thrift |
31 |
#include "Host.hpp" |
9 |
Douglas Thrift |
27 |
|
10 |
|
|
int main(int argc, char* argv[]) |
11 |
|
|
{ |
12 |
|
|
HostStatus status; |
13 |
|
|
|
14 |
|
|
return 0; |
15 |
|
|
} |
16 |
|
|
|
17 |
|
|
HostStatus::HostStatus() |
18 |
|
|
{ |
19 |
Douglas Thrift |
29 |
string method = sgetenv("REQUEST_METHOD"); |
20 |
|
|
|
21 |
|
|
parse(method); |
22 |
Douglas Thrift |
39 |
mode(); |
23 |
Douglas Thrift |
29 |
|
24 |
|
|
display(method); |
25 |
Douglas Thrift |
27 |
} |
26 |
Douglas Thrift |
29 |
|
27 |
|
|
void HostStatus::parse(const string& method) |
28 |
|
|
{ |
29 |
|
|
string query; |
30 |
|
|
|
31 |
|
|
if (method == "POST") |
32 |
|
|
{ |
33 |
|
|
getline(cin, query); |
34 |
|
|
} |
35 |
|
|
else |
36 |
|
|
{ |
37 |
|
|
query = sgetenv("QUERY_STRING"); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
if (query == "") return; |
41 |
|
|
|
42 |
|
|
istringstream input(query); |
43 |
|
|
|
44 |
|
|
do |
45 |
|
|
{ |
46 |
|
|
string name, value; |
47 |
|
|
|
48 |
|
|
getline(input, name, '='); |
49 |
|
|
getline(input, value, '&'); |
50 |
|
|
|
51 |
|
|
cgi.insert(pair<string, string>(name, value)); |
52 |
|
|
} |
53 |
|
|
while (input.good()); |
54 |
|
|
} |
55 |
|
|
|
56 |
Douglas Thrift |
39 |
void HostStatus::mode() |
57 |
|
|
{ |
58 |
|
|
multimap<string, string>::iterator itor = cgi.find("format"); |
59 |
|
|
|
60 |
|
|
if (itor != cgi.end()) |
61 |
|
|
{ |
62 |
|
|
string format = itor->second; |
63 |
|
|
|
64 |
|
|
page = format != "t" ? true : false; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
if (!page) return; |
68 |
|
|
|
69 |
|
|
host = false, name = false, address = false, platform = false, since = |
70 |
|
|
false; |
71 |
|
|
|
72 |
|
|
for (multimap<string, string>::iterator itor = cgi.find("mode"); itor != |
73 |
|
|
cgi.upper_bound("mode") && itor != cgi.end(); itor++) |
74 |
|
|
{ |
75 |
|
|
string mode = itor->second; |
76 |
|
|
|
77 |
|
|
for (string::iterator itor = mode.begin(); itor != mode.end(); itor++) |
78 |
|
|
{ |
79 |
|
|
char mode = *itor; |
80 |
|
|
|
81 |
|
|
switch (mode) |
82 |
|
|
{ |
83 |
|
|
case 'h': |
84 |
|
|
if (!host) host = true; |
85 |
|
|
break; |
86 |
|
|
case 'n': |
87 |
|
|
if (!name) name = true; |
88 |
|
|
break; |
89 |
|
|
case 'a': |
90 |
|
|
if (!address) address = true; |
91 |
|
|
break; |
92 |
|
|
case 'p': |
93 |
|
|
if (!platform) platform = true; |
94 |
|
|
break; |
95 |
|
|
case 's': |
96 |
|
|
if (!since) since = true; |
97 |
|
|
break; |
98 |
|
|
default: |
99 |
|
|
break; |
100 |
|
|
} |
101 |
|
|
} |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
if (!host && !name && !address && !platform && !since) host = true, name = |
105 |
|
|
true, address = true, platform = true, since = true; |
106 |
|
|
} |
107 |
|
|
|
108 |
Douglas Thrift |
29 |
void HostStatus::display(const string& method) |
109 |
|
|
{ |
110 |
|
|
cout << "Content-Type: text/html\n\n"; |
111 |
|
|
|
112 |
|
|
if (method == "POST") sunsetenv("HTTP_USER_AGENT"); |
113 |
|
|
|
114 |
|
|
pstream hostupdate("./hostupdate.cgi"); |
115 |
|
|
|
116 |
|
|
if (method == "POST") |
117 |
|
|
{ |
118 |
|
|
for (multimap<string, string>::iterator itor = cgi.begin(); itor != |
119 |
|
|
cgi.end(); itor++) |
120 |
|
|
{ |
121 |
|
|
hostupdate << itor->first << '=' << itor->second << '&'; |
122 |
|
|
} |
123 |
|
|
|
124 |
Douglas Thrift |
30 |
hostupdate << '\n' << flush; |
125 |
Douglas Thrift |
29 |
} |
126 |
|
|
|
127 |
Douglas Thrift |
35 |
hostupdate.ignore(26); |
128 |
Douglas Thrift |
34 |
|
129 |
|
|
list<Host> hosts; |
130 |
|
|
bool done = false; |
131 |
|
|
|
132 |
|
|
do |
133 |
Douglas Thrift |
29 |
{ |
134 |
Douglas Thrift |
34 |
Host host; |
135 |
Douglas Thrift |
29 |
|
136 |
Douglas Thrift |
34 |
hostupdate >> host; |
137 |
Douglas Thrift |
29 |
|
138 |
Douglas Thrift |
34 |
hosts.push_back(host); |
139 |
|
|
|
140 |
|
|
switch (hostupdate.peek()) |
141 |
|
|
{ |
142 |
|
|
case 'h': |
143 |
|
|
case 'n': |
144 |
|
|
case 'a': |
145 |
|
|
case 'p': |
146 |
|
|
case 's': |
147 |
|
|
break; |
148 |
|
|
default: |
149 |
|
|
done = true; |
150 |
|
|
break; |
151 |
|
|
} |
152 |
Douglas Thrift |
29 |
} |
153 |
Douglas Thrift |
34 |
while (!done && hostupdate.good()); |
154 |
|
|
|
155 |
Douglas Thrift |
40 |
if (page) header(method); |
156 |
Douglas Thrift |
34 |
|
157 |
Douglas Thrift |
40 |
for (list<Host>::iterator itor = hosts.begin(); itor != hosts.end(); |
158 |
|
|
itor++) |
159 |
Douglas Thrift |
34 |
{ |
160 |
|
|
Host host = *itor; |
161 |
|
|
|
162 |
|
|
cout << host << flush; |
163 |
|
|
} |
164 |
|
|
|
165 |
Douglas Thrift |
35 |
if (page) footer(); |
166 |
Douglas Thrift |
29 |
} |
167 |
Douglas Thrift |
35 |
|
168 |
Douglas Thrift |
40 |
void HostStatus::header(const string& method) |
169 |
Douglas Thrift |
35 |
{ |
170 |
Douglas Thrift |
36 |
cout << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\"\n" |
171 |
|
|
<< "\t\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" |
172 |
|
|
<< "<html>\n" |
173 |
Douglas Thrift |
35 |
<< "<head>\n" |
174 |
Douglas Thrift |
36 |
<< "<link rel=\"StyleSheet\" href=\"../stylesheets/regular.css\" type=" |
175 |
|
|
<< "\"text/css\">\n" |
176 |
Douglas Thrift |
35 |
<< "<title>Host Status</title>\n" |
177 |
|
|
<< "</head>\n" |
178 |
|
|
<< "<body>\n" |
179 |
Douglas Thrift |
64 |
<< "<div>\n" |
180 |
Douglas Thrift |
35 |
<< "<h1 id=\"title\" class=\"center\">Host Status</h1>\n" |
181 |
Douglas Thrift |
64 |
<< "</div>\n" |
182 |
|
|
<< "<div class=\"hr\">\n" |
183 |
|
|
<< "<p class=\"floatleft\"><a href=\"./\"><img src=\"/icons/back.gif\"" |
184 |
|
|
<< " alt=\"\"></a></p>\n" |
185 |
Douglas Thrift |
39 |
<< "<form action=\"hoststatus.cgi\" method=\"POST\">\n" |
186 |
Douglas Thrift |
42 |
<< "<table class=\"center\">\n" |
187 |
|
|
<< "<tr>\n" |
188 |
Douglas Thrift |
43 |
<< "<td>\n" |
189 |
|
|
<< "<select name=\"host\" size=\"2\" multiple>\n"; |
190 |
Douglas Thrift |
40 |
|
191 |
|
|
if (method != "POST") sputenv("QUERY_STRING=mode=h"); |
192 |
|
|
|
193 |
|
|
pstream hostupdate("./hostupdate.cgi"); |
194 |
|
|
|
195 |
|
|
if (method == "POST") hostupdate << "mode=h\n" << flush; |
196 |
|
|
|
197 |
|
|
hostupdate.ignore(26); |
198 |
|
|
|
199 |
|
|
list<Host> hosts; |
200 |
|
|
bool done = false; |
201 |
|
|
|
202 |
|
|
do |
203 |
|
|
{ |
204 |
|
|
Host host; |
205 |
|
|
|
206 |
|
|
hostupdate >> host; |
207 |
|
|
|
208 |
|
|
hosts.push_back(host); |
209 |
|
|
|
210 |
|
|
switch (hostupdate.peek()) |
211 |
|
|
{ |
212 |
|
|
case 'h': |
213 |
|
|
break; |
214 |
|
|
default: |
215 |
|
|
done = true; |
216 |
|
|
break; |
217 |
|
|
} |
218 |
|
|
} |
219 |
|
|
while (!done && hostupdate.good()); |
220 |
|
|
|
221 |
Douglas Thrift |
44 |
set<string> selected; |
222 |
|
|
|
223 |
|
|
for (multimap<string, string>::iterator itor = cgi.find("host"); itor != |
224 |
|
|
cgi.upper_bound("host") && itor != cgi.end(); itor++) |
225 |
|
|
{ |
226 |
|
|
string host = itor->second; |
227 |
|
|
|
228 |
|
|
if (host != "") selected.insert(host); |
229 |
|
|
} |
230 |
|
|
|
231 |
Douglas Thrift |
40 |
for (list<Host>::iterator itor = hosts.begin(); itor != hosts.end(); |
232 |
|
|
itor++) |
233 |
|
|
{ |
234 |
|
|
Host host = *itor; |
235 |
|
|
|
236 |
Douglas Thrift |
44 |
cout << "<option" << (selected.find(host.getHost()) != selected.end() ? |
237 |
|
|
" selected>" : ">") << host.getHost() << "</option>\n"; |
238 |
Douglas Thrift |
40 |
} |
239 |
|
|
|
240 |
Douglas Thrift |
44 |
bool all = host && name && address && platform && since; |
241 |
|
|
|
242 |
Douglas Thrift |
43 |
cout << "</select>\n" |
243 |
|
|
<< "</td>\n" |
244 |
|
|
<< "<td>\n" |
245 |
Douglas Thrift |
44 |
<< "<input type=\"checkbox\" name=\"mode\" value=\"h\"" |
246 |
|
|
<< (host && !all ? " checked" : "") << "> Host\n" |
247 |
|
|
<< "<input type=\"checkbox\" name=\"mode\" value=\"n\"" |
248 |
|
|
<< (name && !all ? " checked" : "") << "> Name\n" |
249 |
|
|
<< "<input type=\"checkbox\" name=\"mode\" value=\"a\"" |
250 |
|
|
<< (address && !all ? " checked" : "") << "> Address\n" |
251 |
|
|
<< "<input type=\"checkbox\" name=\"mode\" value=\"p\"" |
252 |
|
|
<< (platform && !all ? " checked" : "") << "> Platform\n" |
253 |
|
|
<< "<input type=\"checkbox\" name=\"mode\" value=\"s\"" |
254 |
|
|
<< (since && !all ? " checked" : "") << "> Since\n" |
255 |
Douglas Thrift |
42 |
<< "</td>\n" |
256 |
|
|
<< "<td><input type=\"submit\" value=\"Status\"></td>\n" |
257 |
|
|
<< "</tr>\n" |
258 |
|
|
<< "</table>\n" |
259 |
Douglas Thrift |
40 |
<< "</form>\n" |
260 |
Douglas Thrift |
39 |
<< "<table class=\"center\">\n" |
261 |
|
|
<< "<tr>\n"; |
262 |
|
|
|
263 |
|
|
if (host) cout << "<th>Host</th>\n"; |
264 |
|
|
if (name) cout << "<th>Name</th>\n"; |
265 |
|
|
if (address) cout << "<th>Address</th>\n"; |
266 |
|
|
if (platform) cout << "<th>Platform</th>\n"; |
267 |
|
|
if (since) cout << "<th>Since</th>\n"; |
268 |
|
|
|
269 |
|
|
cout << "</tr>\n"; |
270 |
Douglas Thrift |
35 |
} |
271 |
|
|
|
272 |
|
|
void HostStatus::footer() |
273 |
|
|
{ |
274 |
|
|
cout << "</table>\n" |
275 |
Douglas Thrift |
64 |
<< "</div>\n" |
276 |
Douglas Thrift |
35 |
<< "</html>\n"; |
277 |
|
|
} |