--- HostStatus/HostStatus.cpp 2003/11/16 04:23:23 38 +++ HostStatus/HostStatus.cpp 2004/01/02 01:55:25 65 @@ -16,25 +16,10 @@ int main(int argc, char* argv[]) HostStatus::HostStatus() { -#ifndef __CYGWIN__ - sputenv("TZ=:America/Los_Angeles"); -#else - sputenv("TZ= PST8PDT"); -#endif - tzset(); - 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; - } + mode(); display(method); } @@ -68,6 +53,58 @@ void HostStatus::parse(const string& met while (input.good()); } +void HostStatus::mode() +{ + multimap::iterator itor = cgi.find("format"); + + if (itor != cgi.end()) + { + string format = itor->second; + + page = format != "t" ? true : false; + } + + if (!page) return; + + host = false, name = false, address = false, platform = false, since = + false; + + for (multimap::iterator itor = cgi.find("mode"); itor != + cgi.upper_bound("mode") && itor != cgi.end(); itor++) + { + string mode = itor->second; + + for (string::iterator itor = mode.begin(); itor != mode.end(); itor++) + { + char mode = *itor; + + switch (mode) + { + case 'h': + if (!host) host = true; + break; + case 'n': + if (!name) name = true; + break; + case 'a': + if (!address) address = true; + break; + case 'p': + if (!platform) platform = true; + break; + case 's': + if (!since) since = true; + break; + default: + break; + } + } + } + + if (!host && !name && !address && !platform && !since) host = true, name = + true, address = true, platform = true, since = true; +} + void HostStatus::display(const string& method) { cout << "Content-Type: text/html\n\n"; @@ -115,9 +152,10 @@ void HostStatus::display(const string& m } while (!done && hostupdate.good()); - if (page) header(); + if (page) header(method); - for (list::iterator itor = hosts.begin(); itor != hosts.end(); itor++) + for (list::iterator itor = hosts.begin(); itor != hosts.end(); + itor++) { Host host = *itor; @@ -127,7 +165,7 @@ void HostStatus::display(const string& m if (page) footer(); } -void HostStatus::header() +void HostStatus::header(const string& method) { cout << "\n" @@ -138,27 +176,102 @@ void HostStatus::header() << "Host Status\n" << "\n" << "\n" + << "
\n" << "

Host Status

\n" - << "\n"; -} + << "\n" + << "
\n" + << "

\"\"

\n" + << "
\n" + << "

\n" + << "\n" + << "
\n" + << "
\n" -/* << "
" << flush;
+	if (method != "POST") sputenv("QUERY_STRING=mode=h");
+
+	pstream hostupdate("./hostupdate.cgi");
+
+	if (method == "POST") hostupdate << "mode=h\n" << flush;
 
-	ipstream env("env");
+	hostupdate.ignore(26);
+
+	list hosts;
+	bool done = false;
 
 	do
 	{
-		string line;
+		Host host;
+
+		hostupdate >> host;
+
+		hosts.push_back(host);
+
+		switch (hostupdate.peek())
+		{
+		case 'h':
+			break;
+		default:
+			done = true;
+			break;
+		}
+	}
+	while (!done && hostupdate.good());
+
+	set selected;
+
+	for (multimap::iterator itor = cgi.find("host"); itor !=
+		cgi.upper_bound("host") && itor != cgi.end(); itor++)
+	{
+		string host = itor->second;
+
+		if (host != "") selected.insert(host);
+	}
 
-		getline(env, line);
+	for (list::iterator itor = hosts.begin(); itor != hosts.end();
+		itor++)
+	{
+		Host host = *itor;
 
-		cout << line << '\n';
+		cout << "" : ">") << host.getHost() << "\n";
 	}
-	while (env.good());
 
-	cout << "
\n"*/ + bool all = host && name && address && platform && since; + + cout << "\n" + << "\n" + << "\n" + << " Host\n" + << " Name\n" + << " Address\n" + << " Platform\n" + << " Since\n" + << "\n" + << "\n" + << "\n" + << "\n" + << "\n" + << "\n" + << "\n"; + + if (host) cout << "\n"; + if (name) cout << "\n"; + if (address) cout << "\n"; + if (platform) cout << "\n"; + if (since) cout << "\n"; + + cout << "\n"; +} + +void HostStatus::footer() +{ + cout << "
HostNameAddressPlatformSince
\n" + << "
\n" << "\n"; }