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