5 |
|
// $Id$ |
6 |
|
|
7 |
|
#include "HostStatus.hpp" |
8 |
+ |
#include "Host.hpp" |
9 |
|
|
10 |
|
int main(int argc, char* argv[]) |
11 |
|
{ |
16 |
|
|
17 |
|
HostStatus::HostStatus() |
18 |
|
{ |
19 |
< |
// |
19 |
> |
string method = sgetenv("REQUEST_METHOD"); |
20 |
> |
|
21 |
> |
parse(method); |
22 |
> |
|
23 |
> |
multimap<string, string>::iterator itor = cgi.find("format"); |
24 |
> |
|
25 |
> |
if (itor != cgi.end()) |
26 |
> |
{ |
27 |
> |
string format = itor->second; |
28 |
> |
|
29 |
> |
if (format == "t") |
30 |
> |
{ |
31 |
> |
this->format = table; |
32 |
> |
} |
33 |
> |
else |
34 |
> |
{ |
35 |
> |
this->format = page; |
36 |
> |
} |
37 |
> |
} |
38 |
> |
|
39 |
> |
display(method); |
40 |
> |
} |
41 |
> |
|
42 |
> |
void HostStatus::parse(const string& method) |
43 |
> |
{ |
44 |
> |
string query; |
45 |
> |
|
46 |
> |
if (method == "POST") |
47 |
> |
{ |
48 |
> |
getline(cin, query); |
49 |
> |
} |
50 |
> |
else |
51 |
> |
{ |
52 |
> |
query = sgetenv("QUERY_STRING"); |
53 |
> |
} |
54 |
> |
|
55 |
> |
if (query == "") return; |
56 |
> |
|
57 |
> |
istringstream input(query); |
58 |
> |
|
59 |
> |
do |
60 |
> |
{ |
61 |
> |
string name, value; |
62 |
> |
|
63 |
> |
getline(input, name, '='); |
64 |
> |
getline(input, value, '&'); |
65 |
> |
|
66 |
> |
cgi.insert(pair<string, string>(name, value)); |
67 |
> |
} |
68 |
> |
while (input.good()); |
69 |
> |
} |
70 |
> |
|
71 |
> |
void HostStatus::display(const string& method) |
72 |
> |
{ |
73 |
> |
cout << "Content-Type: text/html\n\n"; |
74 |
> |
|
75 |
> |
if (method == "POST") sunsetenv("HTTP_USER_AGENT"); |
76 |
> |
|
77 |
> |
pstream hostupdate("./hostupdate.cgi"); |
78 |
> |
|
79 |
> |
if (method == "POST") |
80 |
> |
{ |
81 |
> |
for (multimap<string, string>::iterator itor = cgi.begin(); itor != |
82 |
> |
cgi.end(); itor++) |
83 |
> |
{ |
84 |
> |
hostupdate << itor->first << '=' << itor->second << '&'; |
85 |
> |
} |
86 |
> |
|
87 |
> |
hostupdate << '\n' << flush; |
88 |
> |
} |
89 |
> |
|
90 |
> |
do |
91 |
> |
{ |
92 |
> |
string line; |
93 |
> |
|
94 |
> |
getline(hostupdate, line); |
95 |
> |
|
96 |
> |
cout << line << '\n'; |
97 |
> |
} |
98 |
> |
while (hostupdate.good()); |
99 |
|
} |