16 |
|
|
17 |
|
HostUpdate::HostUpdate() |
18 |
|
{ |
19 |
< |
/* CgiEnvironment env = cgi.getEnvironment(); |
19 |
> |
struct stat* hosts = new struct stat; |
20 |
|
|
21 |
< |
cout << "Location: " << (env.usingHTTPS() ? "https" : "http") << "://" |
22 |
< |
<< env.getServerName() << ":" << env.getServerPort() << "/\n\n"; |
21 |
> |
if (stat("hosts", hosts) != 0) |
22 |
> |
{ |
23 |
> |
mkdir("hosts"); |
24 |
> |
} |
25 |
> |
|
26 |
> |
delete [] hosts; |
27 |
> |
|
28 |
> |
chdir("hosts"); |
29 |
> |
|
30 |
> |
CgiEnvironment env = cgi.getEnvironment(); |
31 |
> |
|
32 |
> |
string agent = env.getUserAgent(); |
33 |
> |
string method = env.getRequestMethod(); |
34 |
> |
|
35 |
> |
if (agent.find("Host Update/") == 0 && method == "GET" && agent.find(" (") |
36 |
> |
!= string::npos && agent.find(") libwww-perl/") != string::npos) |
37 |
> |
{ |
38 |
> |
update(env, agent); |
39 |
> |
} |
40 |
> |
else |
41 |
> |
{ |
42 |
> |
display(env); |
43 |
> |
} |
44 |
> |
} |
45 |
> |
|
46 |
> |
HostUpdate::~HostUpdate() |
47 |
> |
{ |
48 |
> |
// |
49 |
> |
} |
50 |
> |
|
51 |
> |
void HostUpdate::update(CgiEnvironment& env, const string& agent) |
52 |
> |
{ |
53 |
> |
cout << "Content-Type: text/plain\n\n"; |
54 |
|
|
55 |
< |
form_iterator itor = cgi["host"]; |
25 |
< |
FormEntry host = *itor;*/ |
55 |
> |
vector<FormEntry> entries; |
56 |
|
|
57 |
< |
Host host("douglaspc", "", "192.168.0.1"); |
57 |
> |
if (!cgi.getElement("host", entries)) return; |
58 |
> |
if (entries[0].isEmpty()) return; |
59 |
|
|
60 |
< |
host--; |
60 |
> |
string host = entries[0].getStrippedValue(); |
61 |
> |
string name = env.getRemoteHost(); |
62 |
> |
string address = env.getRemoteAddr(); |
63 |
|
|
64 |
< |
cout << host.getName() << '\n' << host.getAddress(); |
64 |
> |
if (name == address) name = ""; |
65 |
> |
|
66 |
> |
string::size_type begin = agent.find('(') + 1, end = agent.find(begin, ')'); |
67 |
> |
string platform = agent.substr(begin, end - begin); |
68 |
|
} |
69 |
|
|
70 |
< |
HostUpdate::~HostUpdate() |
70 |
> |
void HostUpdate::display(CgiEnvironment& env) |
71 |
|
{ |
72 |
|
// |
73 |
|
} |