ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostStatus/HostStatus.cpp
(Generate patch)

Comparing HostStatus/HostStatus.cpp (file contents):
Revision 27 by Douglas Thrift, 2003-11-14T11:38:42-08:00 vs.
Revision 38 by Douglas Thrift, 2003-11-15T20:23:23-08:00

# Line 5 | Line 5
5   // $Id$
6  
7   #include "HostStatus.hpp"
8 + #include "Host.hpp"
9  
10   int main(int argc, char* argv[])
11   {
# Line 15 | Line 16 | int main(int argc, char* argv[])
16  
17   HostStatus::HostStatus()
18   {
19 <        //
19 > #ifndef __CYGWIN__
20 >        sputenv("TZ=:America/Los_Angeles");
21 > #else
22 >        sputenv("TZ= PST8PDT");
23 > #endif
24 >        tzset();
25 >
26 >        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 >                page = format != "t" ? true : false;
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 >        hostupdate.ignore(26);
91 >
92 >        list<Host> hosts;
93 >        bool done = false;
94 >
95 >        do
96 >        {
97 >                Host host;
98 >
99 >                hostupdate >> host;
100 >
101 >                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 >        }
116 >        while (!done && hostupdate.good());
117 >
118 >        if (page) header();
119 >
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 >        if (page) footer();
128 > }
129 >
130 > void HostStatus::header()
131 > {
132 >        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 >                << "<head>\n"
136 >                << "<link rel=\"StyleSheet\" href=\"../stylesheets/regular.css\" type="
137 >                << "\"text/css\">\n"
138 >                << "<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 > /*              << "<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 >                << "</html>\n";
164   }

Comparing HostStatus/HostStatus.cpp (property svn:eol-style):
Revision 27 by Douglas Thrift, 2003-11-14T11:38:42-08:00 vs.
Revision 38 by Douglas Thrift, 2003-11-15T20:23:23-08:00

# Line 0 | Line 1
1 + native

Comparing HostStatus/HostStatus.cpp (property svn:keywords):
Revision 27 by Douglas Thrift, 2003-11-14T11:38:42-08:00 vs.
Revision 38 by Douglas Thrift, 2003-11-15T20:23:23-08:00

# Line 0 | Line 1
1 + Id

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines