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 35 by Douglas Thrift, 2003-11-15T01:40:10-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 >        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 << "<html>\n"
128 >                << "<head>\n"
129 >                << "<link rel=\"StyleSheet\" href=\"../stylesheets/regular.css\" type\""
130 >                << "text/css\">\n"
131 >                << "<title>Host Status</title>\n"
132 >                << "</head>\n"
133 >                << "<body>\n"
134 >                << "<h1 id=\"title\" class=\"center\">Host Status</h1>\n"
135 >                << "<table class=\"center\">\n";
136 > }
137 >
138 > void HostStatus::footer()
139 > {
140 >        cout << "</table>\n"
141 >                << "</html>\n";
142   }

Comparing HostStatus/HostStatus.cpp (property svn:eol-style):
Revision 27 by Douglas Thrift, 2003-11-14T11:38:42-08:00 vs.
Revision 35 by Douglas Thrift, 2003-11-15T01:40:10-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 35 by Douglas Thrift, 2003-11-15T01:40:10-08:00

# Line 0 | Line 1
1 + Id

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines