// Host Update // // Douglas Thrift // // $Id$ #include "HostUpdate.hpp" #include "Host.hpp" int main(int argc, char* argv[]) { HostUpdate update; return 0; } HostUpdate::HostUpdate() { struct stat* hosts = new struct stat; if (stat("hosts", hosts) != 0) { mkdir("hosts"); } delete [] hosts; chdir("hosts"); CgiEnvironment env = cgi.getEnvironment(); string agent = env.getUserAgent(); string method = env.getRequestMethod(); if (agent.find("Host Update/") == 0 && method == "GET" && agent.find(" (") != string::npos && agent.find(") libwww-perl/") != string::npos) { update(env, agent); } else { display(env); } } HostUpdate::~HostUpdate() { // } void HostUpdate::update(CgiEnvironment& env, const string& agent) { cout << "Content-Type: text/plain\n\n"; vector entries; if (!cgi.getElement("host", entries)) return; if (entries[0].isEmpty()) return; string host = entries[0].getStrippedValue(); string name = env.getRemoteHost(); string address = env.getRemoteAddr(); if (name == address) name = ""; string::size_type begin = agent.find('(') + 1, end = agent.find(begin, ')'); string platform = agent.substr(begin, end - begin); } void HostUpdate::display(CgiEnvironment& env) { // }