// 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 == "POST" && 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(), name = env.getRemoteHost(), 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); cout << "host=" << host << '\n' << "name=" << name << '\n' << "address=" << address << '\n' << "platform=" << platform << '\n'; Host client(host, name, address, platform), saved(host); if (client != ++saved) client--; } void HostUpdate::display(CgiEnvironment& env) { cout << "Status: 401\nWWW-Authenticate: Basic realm=\"Host Update\"\n\n"; }