--- HostStatus/HostStatus.cpp 2003/11/16 04:23:23 38 +++ HostStatus/HostStatus.cpp 2003/11/17 03:43:17 40 @@ -26,15 +26,7 @@ HostStatus::HostStatus() 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 +60,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 +159,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 +172,7 @@ void HostStatus::display(const string& m if (page) footer(); } -void HostStatus::header() +void HostStatus::header(const string& method) { cout << "\n" @@ -139,26 +184,71 @@ void HostStatus::header() << "\n" << "\n" << "

Host Status

\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());
 
-		getline(env, line);
+	for (list::iterator itor = hosts.begin(); itor != hosts.end();
+		itor++)
+	{
+		Host host = *itor;
 
-		cout << line << '\n';
+		cout << "\n";
 	}
-	while (env.good());
 
-	cout << "
\n"*/ + cout << "\n" + << " Host\n" + << " Name\n" + << " Address\n" + << " Platform" + << '\n' + << " Since\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"; }