ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostStatus/HostStatus.cpp
Revision: 38
Committed: 2003-11-15T20:23:23-08:00 (21 years, 7 months ago) by Douglas Thrift
File size: 2524 byte(s)
Log Message:
Works right in Cygwin now.

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 38 #ifndef __CYGWIN__
20 Douglas Thrift 32 sputenv("TZ=:America/Los_Angeles");
21 Douglas Thrift 38 #else
22     sputenv("TZ= PST8PDT");
23     #endif
24     tzset();
25 Douglas Thrift 32
26 Douglas Thrift 29 string method = sgetenv("REQUEST_METHOD");
27    
28     parse(method);
29    
30     multimap<string, string>::iterator itor = cgi.find("format");
31    
32     if (itor != cgi.end())
33     {
34     string format = itor->second;
35    
36 Douglas Thrift 35 page = format != "t" ? true : false;
37 Douglas Thrift 29 }
38    
39     display(method);
40 Douglas Thrift 27 }
41 Douglas Thrift 29
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 Douglas Thrift 30 hostupdate << '\n' << flush;
88 Douglas Thrift 29 }
89    
90 Douglas Thrift 35 hostupdate.ignore(26);
91 Douglas Thrift 34
92     list<Host> hosts;
93     bool done = false;
94    
95     do
96 Douglas Thrift 29 {
97 Douglas Thrift 34 Host host;
98 Douglas Thrift 29
99 Douglas Thrift 34 hostupdate >> host;
100 Douglas Thrift 29
101 Douglas Thrift 34 hosts.push_back(host);
102    
103     switch (hostupdate.peek())
104     {
105     case 'h':
106     case 'n':
107     case 'a':
108     case 'p':
109     case 's':
110     break;
111     default:
112     done = true;
113     break;
114     }
115 Douglas Thrift 29 }
116 Douglas Thrift 34 while (!done && hostupdate.good());
117    
118 Douglas Thrift 35 if (page) header();
119 Douglas Thrift 34
120     for (list<Host>::iterator itor = hosts.begin(); itor != hosts.end(); itor++)
121     {
122     Host host = *itor;
123    
124     cout << host << flush;
125     }
126    
127 Douglas Thrift 35 if (page) footer();
128 Douglas Thrift 29 }
129 Douglas Thrift 35
130     void HostStatus::header()
131     {
132 Douglas Thrift 36 cout << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\"\n"
133     << "\t\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
134     << "<html>\n"
135 Douglas Thrift 35 << "<head>\n"
136 Douglas Thrift 36 << "<link rel=\"StyleSheet\" href=\"../stylesheets/regular.css\" type="
137     << "\"text/css\">\n"
138 Douglas Thrift 35 << "<title>Host Status</title>\n"
139     << "</head>\n"
140     << "<body>\n"
141     << "<h1 id=\"title\" class=\"center\">Host Status</h1>\n"
142     << "<table class=\"center\">\n";
143     }
144    
145     void HostStatus::footer()
146     {
147     cout << "</table>\n"
148 Douglas Thrift 37 /* << "<pre>" << flush;
149    
150     ipstream env("env");
151    
152     do
153     {
154     string line;
155    
156     getline(env, line);
157    
158     cout << line << '\n';
159     }
160     while (env.good());
161    
162     cout << "</pre>\n"*/
163 Douglas Thrift 35 << "</html>\n";
164     }

Properties

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