7 |
|
#include "HostUpdate.hpp" |
8 |
|
#include "Host.hpp" |
9 |
|
|
10 |
< |
#ifdef _WIN32 |
10 |
> |
#ifndef _WIN32 |
11 |
> |
|
12 |
> |
extern "C" |
13 |
> |
{ |
14 |
> |
#include <resolv.h> |
15 |
> |
} |
16 |
> |
|
17 |
> |
#else |
18 |
> |
|
19 |
|
#include <windows.h> |
20 |
+ |
|
21 |
|
#endif |
22 |
|
|
23 |
|
int main(int argc, char* argv[]) |
24 |
|
{ |
25 |
+ |
#ifndef _WIN32 |
26 |
+ |
res_init(); |
27 |
+ |
|
28 |
+ |
for (short index(0); index < MAXNS; ++index) |
29 |
+ |
{ |
30 |
+ |
if (index + 1 < MAXNS) |
31 |
+ |
{ |
32 |
+ |
memcpy(&_res.nsaddr_list[index].sin_addr, |
33 |
+ |
&_res.nsaddr_list[index + 1].sin_addr, sizeof(in_addr_t)); |
34 |
+ |
} |
35 |
+ |
else |
36 |
+ |
{ |
37 |
+ |
memset(&_res.nsaddr_list[index].sin_addr, 0, sizeof(in_addr_t)); |
38 |
+ |
} |
39 |
+ |
} |
40 |
+ |
#endif |
41 |
+ |
|
42 |
|
HostUpdate update; |
43 |
|
|
44 |
|
return 0; |
45 |
|
} |
46 |
|
|
47 |
< |
HostUpdate::HostUpdate() |
47 |
> |
HostUpdate::HostUpdate() : host(false), name(false), address(false), |
48 |
> |
platform(false), since(false) |
49 |
|
{ |
50 |
|
struct stat* hosts = new struct stat; |
51 |
|
|
109 |
|
|
110 |
|
void HostUpdate::mode() |
111 |
|
{ |
112 |
< |
host = false, name = false, address = false, platform = false, since = |
113 |
< |
false; |
87 |
< |
|
88 |
< |
for (multimap<string, string>::iterator itor = cgi.find("mode"); itor != |
89 |
< |
cgi.upper_bound("mode") && itor != cgi.end(); itor++) |
112 |
> |
for (multimap<string, string>::iterator itor(cgi.find("mode")); |
113 |
> |
itor != cgi.upper_bound("mode") && itor != cgi.end(); itor++) |
114 |
|
{ |
115 |
< |
string mode = itor->second; |
115 |
> |
string mode(itor->second); |
116 |
|
|
117 |
< |
for (string::iterator itor = mode.begin(); itor != mode.end(); itor++) |
117 |
> |
for (string::iterator itor(mode.begin()); itor != mode.end(); itor++) |
118 |
|
{ |
119 |
< |
char mode = *itor; |
119 |
> |
char mode(*itor); |
120 |
|
|
121 |
|
switch (mode) |
122 |
|
{ |
154 |
|
if (itor == cgi.end()) return; |
155 |
|
if (itor->second == "") return; |
156 |
|
|
157 |
< |
string host = itor->second, name = sgetenv("REMOTE_HOST"), address = |
158 |
< |
sgetenv("REMOTE_ADDR"); |
157 |
> |
string host(itor->second), name(sgetenv("REMOTE_HOST")), |
158 |
> |
address(sgetenv("REMOTE_ADDR")); |
159 |
|
|
160 |
< |
string::size_type begin = agent.find('(') + 1, end = agent.rfind(')'); |
160 |
> |
string::size_type begin(agent.find('(') + 1), end(agent.rfind(')')); |
161 |
|
|
162 |
|
if (begin >= end) return; |
163 |
|
|
164 |
< |
string platform = agent.substr(begin, end - begin); |
164 |
> |
string platform(agent.substr(begin, end - begin)); |
165 |
|
|
166 |
|
Host client(host, name, address, platform), saved(host); |
167 |
|
|
175 |
|
cout << "Content-Type: text/plain\n\n"; |
176 |
|
|
177 |
|
{ |
178 |
< |
bool request = false; |
178 |
> |
bool request(false); |
179 |
|
|
180 |
< |
for (multimap<string, string>::iterator itor = cgi.find("host"); itor != |
181 |
< |
cgi.upper_bound("host") && itor != cgi.end(); itor++) |
180 |
> |
for (multimap<string, string>::iterator itor(cgi.find("host")); |
181 |
> |
itor != cgi.upper_bound("host") && itor != cgi.end(); itor++) |
182 |
|
{ |
183 |
< |
if (itor->second != "") |
183 |
> |
if (!itor->second.empty()) |
184 |
|
{ |
185 |
|
Host host(itor->second); |
186 |
|
|
196 |
|
set<Host> hosts; |
197 |
|
|
198 |
|
#ifndef _WIN32 |
199 |
< |
DIR* dir = opendir("hosts"); |
199 |
> |
DIR* dir(opendir("hosts")); |
200 |
|
struct dirent* ent; |
201 |
|
|
202 |
|
while ((ent = readdir(dir)) != NULL) |
203 |
|
{ |
204 |
< |
string file = ent->d_name; |
204 |
> |
string file(ent->d_name); |
205 |
|
|
206 |
|
if (file == "." || file == "..") continue; |
207 |
|
|
213 |
|
closedir(dir); |
214 |
|
#else |
215 |
|
WIN32_FIND_DATA found; |
216 |
< |
HANDLE find = FindFirstFile("hosts\\*", &found); |
216 |
> |
HANDLE find(FindFirstFile("hosts\\*", &found)); |
217 |
|
|
218 |
|
do |
219 |
|
{ |
220 |
< |
string file = found.cFileName; |
220 |
> |
string file(found.cFileName); |
221 |
|
|
222 |
|
if (file == "." || file == "..") continue; |
223 |
|
|
230 |
|
FindClose(find); |
231 |
|
#endif |
232 |
|
|
233 |
< |
for (set<Host>::iterator itor = hosts.begin(); itor != hosts.end(); itor++) |
233 |
> |
for (set<Host>::iterator itor(hosts.begin()); itor != hosts.end(); itor++) |
234 |
|
{ |
235 |
|
display(*itor); |
236 |
|
} |
243 |
|
if (address) cout << "address=" << host.getAddress() << '\n'; |
244 |
|
if (platform) cout << "platform=" << host.getPlatform() << '\n'; |
245 |
|
|
246 |
< |
string name = string("hosts") + slash + host.getHost(); |
246 |
> |
string name(string("hosts") + slash + host.getHost()); |
247 |
|
struct stat file; |
248 |
|
|
249 |
|
if (since && stat(name.c_str(), &file) == 0) |
257 |
|
else if (since) |
258 |
|
{ |
259 |
|
char since[20]; |
260 |
< |
time_t* now = new time_t; |
237 |
< |
|
238 |
< |
time(now); |
239 |
< |
strftime(since, 20, "%m/%d/%Y %H:%M:%S", gmtime(now)); |
260 |
> |
time_t now(time(NULL)); |
261 |
|
|
262 |
< |
delete now; |
262 |
> |
strftime(since, 20, "%m/%d/%Y %H:%M:%S", gmtime(&now)); |
263 |
|
|
264 |
|
cout << "since=" << since << " GMT\n"; |
265 |
|
} |