6 |
|
|
7 |
|
#include "HostUpdate.hpp" |
8 |
|
#include "Host.hpp" |
9 |
+ |
#include <windows.h> |
10 |
|
|
11 |
|
int main(int argc, char* argv[]) |
12 |
|
{ |
42 |
|
} |
43 |
|
} |
44 |
|
|
44 |
– |
HostUpdate::~HostUpdate() |
45 |
– |
{ |
46 |
– |
// |
47 |
– |
} |
48 |
– |
|
45 |
|
void HostUpdate::parse(const string& method) |
46 |
|
{ |
47 |
|
string query; |
76 |
|
cout << "Content-Type: text/plain\n\n"; |
77 |
|
|
78 |
|
multimap<string, string>::iterator itor = cgi.find("host"); |
79 |
< |
|
79 |
> |
|
80 |
|
if (itor == cgi.end()) return; |
81 |
|
if (itor->second == "") return; |
82 |
|
|
102 |
|
cout << "Content-Type: text/plain\n\n"; |
103 |
|
|
104 |
|
set<Host> hosts; |
105 |
+ |
|
106 |
+ |
#ifndef _WIN32 |
107 |
|
DIR* dir = opendir("hosts"); |
108 |
|
struct dirent* ent; |
109 |
|
|
112 |
|
string file = ent->d_name; |
113 |
|
|
114 |
|
if (file == "." || file == "..") continue; |
115 |
< |
|
115 |
> |
|
116 |
|
Host host(file); |
117 |
|
|
118 |
|
hosts.insert(++host); |
119 |
|
} |
120 |
|
|
121 |
|
closedir(dir); |
122 |
+ |
#else |
123 |
+ |
WIN32_FIND_DATA found; |
124 |
+ |
HANDLE find = FindFirstFile("hosts\\*", &found); |
125 |
+ |
|
126 |
+ |
do |
127 |
+ |
{ |
128 |
+ |
string file = found.cFileName; |
129 |
+ |
|
130 |
+ |
if (file == "." || file == "..") continue; |
131 |
+ |
|
132 |
+ |
Host host(file); |
133 |
+ |
|
134 |
+ |
hosts.insert(++host); |
135 |
+ |
} |
136 |
+ |
while (FindNextFile(find, &found) != 0); |
137 |
+ |
|
138 |
+ |
FindClose(find); |
139 |
+ |
#endif |
140 |
|
|
141 |
|
for (set<Host>::iterator itor = hosts.begin(); itor != hosts.end(); itor++) |
142 |
|
{ |
143 |
< |
Host host = *itor; |
143 |
> |
display(*itor); |
144 |
> |
} |
145 |
> |
} |
146 |
> |
|
147 |
> |
void HostUpdate::display(const Host& host) |
148 |
> |
{ |
149 |
> |
cout << "host=" << host.getHost() << '\n' |
150 |
> |
<< "name=" << host.getName() << '\n' |
151 |
> |
<< "address=" << host.getAddress() << '\n' |
152 |
> |
<< "platform=" << host.getPlatform() << '\n'; |
153 |
> |
|
154 |
> |
string name = string("hosts") + slash + host.getHost(); |
155 |
> |
struct stat file; |
156 |
> |
|
157 |
> |
if (stat(name.c_str(), &file) == 0) |
158 |
> |
{ |
159 |
> |
char since[20]; |
160 |
> |
|
161 |
> |
strftime(since, 20, "%m/%d/%Y %H:%M:%S", gmtime(&file.st_mtime)); |
162 |
|
|
163 |
< |
cout << "host=" << host.getHost() << '\n' |
130 |
< |
<< "name=" << host.getName() << '\n' |
131 |
< |
<< "address=" << host.getAddress() << '\n' |
132 |
< |
<< "platform=" << host.getPlatform() << "\n\n"; |
163 |
> |
cout << "since=" << since << " GMT\n"; |
164 |
|
} |
165 |
|
} |