ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostUpdate/HostUpdate.cpp
Revision: 13
Committed: 2003-11-07T12:17:57-08:00 (21 years, 7 months ago) by Douglas Thrift
File size: 1542 byte(s)
Log Message:
Goodbye, cruel world, goodbye, cruel lamp...

File Contents

# Content
1 // Host Update
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #include "HostUpdate.hpp"
8 #include "Host.hpp"
9
10 int main(int argc, char* argv[])
11 {
12 HostUpdate update;
13
14 return 0;
15 }
16
17 HostUpdate::HostUpdate()
18 {
19 struct stat* hosts = new struct stat;
20
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 == "POST" && 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 vector<FormEntry> entries;
56
57 if (!cgi.getElement("host", entries)) return;
58 if (entries[0].isEmpty()) return;
59
60 string host = entries[0].getStrippedValue(), name = env.getRemoteHost(),
61 address = env.getRemoteAddr();
62
63 if (name == address) name = "";
64
65 string::size_type begin = agent.find('(') + 1, end = agent.find(')',
66 begin);
67 string platform = agent.substr(begin, end - begin);
68
69 cout << "host=" << host << '\n'
70 << "name=" << name << '\n'
71 << "address=" << address << '\n'
72 << "platform=" << platform << '\n';
73
74 Host client(host, name, address, platform), saved(host);
75
76 if (client != ++saved) client--;
77 }
78
79 void HostUpdate::display(CgiEnvironment& env)
80 {
81 cout << "Status: 401\nWWW-Authenticate: Basic realm=\"Host Update\"\n\n";
82 }

Properties

Name Value
svn:eol-style native
svn:keywords Id