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

# User Rev Content
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 Douglas Thrift 35 page = format != "t" ? true : false;
32 Douglas Thrift 29 }
33    
34     display(method);
35 Douglas Thrift 27 }
36 Douglas Thrift 29
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 Douglas Thrift 30 hostupdate << '\n' << flush;
83 Douglas Thrift 29 }
84    
85 Douglas Thrift 35 hostupdate.ignore(26);
86 Douglas Thrift 34
87     list<Host> hosts;
88     bool done = false;
89    
90     do
91 Douglas Thrift 29 {
92 Douglas Thrift 34 Host host;
93 Douglas Thrift 29
94 Douglas Thrift 34 hostupdate >> host;
95 Douglas Thrift 29
96 Douglas Thrift 34 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 Douglas Thrift 29 }
111 Douglas Thrift 34 while (!done && hostupdate.good());
112    
113 Douglas Thrift 35 if (page) header();
114 Douglas Thrift 34
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 Douglas Thrift 35 if (page) footer();
123 Douglas Thrift 29 }
124 Douglas Thrift 35
125     void HostStatus::header()
126     {
127 Douglas Thrift 36 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 Douglas Thrift 35 << "<head>\n"
131 Douglas Thrift 36 << "<link rel=\"StyleSheet\" href=\"../stylesheets/regular.css\" type="
132     << "\"text/css\">\n"
133 Douglas Thrift 35 << "<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