ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostStatus/HostStatus.cpp
Revision: 36
Committed: 2003-11-15T02:21:22-08:00 (21 years, 7 months ago) by Douglas Thrift
File size: 2291 byte(s)
Log Message:
Eat this!

File Contents

# Content
1 // Host Status
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #include "HostStatus.hpp"
8 #include "Host.hpp"
9
10 int main(int argc, char* argv[])
11 {
12 HostStatus status;
13
14 return 0;
15 }
16
17 HostStatus::HostStatus()
18 {
19 sputenv("TZ=:America/Los_Angeles");
20
21 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 page = format != "t" ? true : false;
32 }
33
34 display(method);
35 }
36
37 void HostStatus::parse(const string& method)
38 {
39 string query;
40
41 if (method == "POST")
42 {
43 getline(cin, query);
44 }
45 else
46 {
47 query = sgetenv("QUERY_STRING");
48 }
49
50 if (query == "") return;
51
52 istringstream input(query);
53
54 do
55 {
56 string name, value;
57
58 getline(input, name, '=');
59 getline(input, value, '&');
60
61 cgi.insert(pair<string, string>(name, value));
62 }
63 while (input.good());
64 }
65
66 void HostStatus::display(const string& method)
67 {
68 cout << "Content-Type: text/html\n\n";
69
70 if (method == "POST") sunsetenv("HTTP_USER_AGENT");
71
72 pstream hostupdate("./hostupdate.cgi");
73
74 if (method == "POST")
75 {
76 for (multimap<string, string>::iterator itor = cgi.begin(); itor !=
77 cgi.end(); itor++)
78 {
79 hostupdate << itor->first << '=' << itor->second << '&';
80 }
81
82 hostupdate << '\n' << flush;
83 }
84
85 hostupdate.ignore(26);
86
87 list<Host> hosts;
88 bool done = false;
89
90 do
91 {
92 Host host;
93
94 hostupdate >> host;
95
96 hosts.push_back(host);
97
98 switch (hostupdate.peek())
99 {
100 case 'h':
101 case 'n':
102 case 'a':
103 case 'p':
104 case 's':
105 break;
106 default:
107 done = true;
108 break;
109 }
110 }
111 while (!done && hostupdate.good());
112
113 if (page) header();
114
115 for (list<Host>::iterator itor = hosts.begin(); itor != hosts.end(); itor++)
116 {
117 Host host = *itor;
118
119 cout << host << flush;
120 }
121
122 if (page) footer();
123 }
124
125 void HostStatus::header()
126 {
127 cout << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\"\n"
128 << "\t\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
129 << "<html>\n"
130 << "<head>\n"
131 << "<link rel=\"StyleSheet\" href=\"../stylesheets/regular.css\" type="
132 << "\"text/css\">\n"
133 << "<title>Host Status</title>\n"
134 << "</head>\n"
135 << "<body>\n"
136 << "<h1 id=\"title\" class=\"center\">Host Status</h1>\n"
137 << "<table class=\"center\">\n";
138 }
139
140 void HostStatus::footer()
141 {
142 cout << "</table>\n"
143 << "</html>\n";
144 }

Properties

Name Value
svn:eol-style native
svn:keywords Id