--- HostStatus/HostStatus.cpp 2003/11/14 19:38:42 27 +++ HostStatus/HostStatus.cpp 2003/11/15 23:12:56 37 @@ -5,6 +5,7 @@ // $Id$ #include "HostStatus.hpp" +#include "Host.hpp" int main(int argc, char* argv[]) { @@ -15,5 +16,144 @@ int main(int argc, char* argv[]) HostStatus::HostStatus() { - // + sputenv("TZ=:America/Los_Angeles"); + + string method = sgetenv("REQUEST_METHOD"); + + parse(method); + + multimap::iterator itor = cgi.find("format"); + + if (itor != cgi.end()) + { + string format = itor->second; + + page = format != "t" ? true : false; + } + + display(method); +} + +void HostStatus::parse(const string& method) +{ + string query; + + if (method == "POST") + { + getline(cin, query); + } + else + { + query = sgetenv("QUERY_STRING"); + } + + if (query == "") return; + + istringstream input(query); + + do + { + string name, value; + + getline(input, name, '='); + getline(input, value, '&'); + + cgi.insert(pair(name, value)); + } + while (input.good()); +} + +void HostStatus::display(const string& method) +{ + cout << "Content-Type: text/html\n\n"; + + if (method == "POST") sunsetenv("HTTP_USER_AGENT"); + + pstream hostupdate("./hostupdate.cgi"); + + if (method == "POST") + { + for (multimap::iterator itor = cgi.begin(); itor != + cgi.end(); itor++) + { + hostupdate << itor->first << '=' << itor->second << '&'; + } + + hostupdate << '\n' << flush; + } + + hostupdate.ignore(26); + + list hosts; + bool done = false; + + do + { + Host host; + + hostupdate >> host; + + hosts.push_back(host); + + switch (hostupdate.peek()) + { + case 'h': + case 'n': + case 'a': + case 'p': + case 's': + break; + default: + done = true; + break; + } + } + while (!done && hostupdate.good()); + + if (page) header(); + + for (list::iterator itor = hosts.begin(); itor != hosts.end(); itor++) + { + Host host = *itor; + + cout << host << flush; + } + + if (page) footer(); +} + +void HostStatus::header() +{ + cout << "\n" + << "\n" + << "\n" + << "\n" + << "Host Status\n" + << "\n" + << "\n" + << "

Host Status

\n" + << "\n"; +} + +void HostStatus::footer() +{ + cout << "
\n" +/* << "
" << flush;
+
+	ipstream env("env");
+
+	do
+	{
+		string line;
+
+		getline(env, line);
+
+		cout << line << '\n';
+	}
+	while (env.good());
+
+	cout << "
\n"*/ + << "\n"; }