3 # (c) 1999 Randolph Chung. Licensed under the GPL. <tausq@debian.org>
10 use Net::LDAP qw(:all);
12 my (%attrs, @attrorder, %summaryattrs, @summaryorder);
14 # This defines the description of the fields, and which fields are retrieved
15 %attrs = ('hostname' => 'Host name',
16 'admin' => 'Admin contact',
17 'architecture' => 'Architecture',
18 'distribution' => 'Distribution',
20 'sponsor' => 'Sponsor',
21 'sponsorurl' => 'Sponsor URL',
22 'sponsor-admin' => 'Sponsor admin',
23 'location' => 'Location',
24 'machine' => 'Processor',
26 'disk' => 'Disk space',
27 'bandwidth' => 'Bandwidth',
29 'createtimestamp' => 'Entry created',
30 'modifytimestamp' => 'Entry modified'
33 # This defines what fields are displayed, and in what order
34 @attrorder = ('hostname', 'admin', 'architecture', 'distribution', 'access',
35 'sponsor', 'sponsor-admin', 'location', 'machine', 'memory',
36 'disk', 'bandwidth', 'notes', 'createtimestamp', 'modifytimestamp');
39 %summaryattrs = ('hostname' => 'Host name',
40 'host' => 'just for a link',
41 'architecture' => 'Architecture',
42 'access' => 'Access');
44 @summaryorder = ('hostname', 'architecture', 'access');
47 my %config = &Util::ReadConfigFile;
49 my ($ldap, $mesg, $dn, $entries, $data, %output, $key, $hostlist, $hostdetails, $selected, %summary);
51 $ldap->unbind if (defined($ldap));
54 $SIG{__DIE__} = \&DieHandler;
57 my $host = lc($query->param('host'));
59 &Util::HTMLSendHeader;
60 $ldap = Net::LDAP->new($config{ldaphost}) || &Util::HTMLError($!);
64 $mesg = $ldap->search(base => $config{hostbasedn}, filter => 'host=*');
65 $mesg->code && &Util::HTMLError($mesg->error);
66 $entries = $mesg->as_struct;
68 foreach $dn (sort {$entries->{$a}->{host}->[0] <=> $entries->{$b}->{host}->[0]} keys(%$entries)) {
69 $data = $entries->{$dn};
71 my $thishost = $data->{host}->[0];
74 if (lc($thishost) eq $host) {
75 $output{havehostdata} = 1;
77 foreach $key (keys(%attrs)) {
78 $output{$key} = $data->{$key}->[0];
81 # Modified/created time. TODO: maybe add is the name of the creator/modifier
82 $output{modifytimestamp} = &Util::FormatTimestamp($output{modifytimestamp});
83 $output{createtimestamp} = &Util::FormatTimestamp($output{createtimestamp});
85 # Format email addresses
86 $output{admin} = sprintf("<a href=\"mailto:%s\">%s</a>", $output{admin}, $output{admin});
87 $output{'sponsor-admin'} = sprintf("<a href=\"mailto:%s\">%s</a>", $output{'sponsor-admin'}, $output{'sponsor-admin'});
90 $output{sponsor} = sprintf("<a href=\"%s\">%s</a>", $output{sponsorurl}, $output{sponsor});
92 $selected = " selected ";
95 $hostlist .= "<option value=\"$thishost\"$selected>$thishost\n";
97 # collect summary info
98 foreach $key (keys(%summaryattrs)) {
99 $summary{$thishost}{$key} = $data->{$key}->[0];
102 $summary{$thishost}{hostname} = sprintf("<a href=\"machines.cgi?host=%s\">%s</a>",
103 $summary{$thishost}{host}, $summary{$thishost}{hostname});
107 if ($output{havehostdata}) {
108 $hostdetails = "<h1>Information about $output{hostname}</h1>\n";
109 $hostdetails .= "<ul>\n";
110 foreach $key (@attrorder) {
112 $hostdetails .= "<li><b>$key:</b> $output{$key}\n";
115 $hostdetails .= "</ul>\n";
117 # display summary info
118 $hostdetails = "<h1>Summary</h1>\n";
119 $hostdetails .= "<table border=1 width=90%>\n<th>";
120 foreach $key (@summaryorder) {
121 $hostdetails .= "<td>$summaryattrs{$key}</td>";
123 $hostdetails .= "</th>\n";
125 foreach $host (sort(keys(%summary))) {
126 $hostdetails .= "<tr>";
127 foreach $key (@summaryorder) {
128 $hostdetails .= "<td>$summary{$host}{$key} </td>";
130 $hostdetails .= "</tr>\n";
132 $hostdetails .= "</table>\n";
135 # Finally, we can write the output... yuck...
136 open (F, "<$config{hosthtml}") || &Util::HTMLError("Cannot open host template");
138 s/~hostlist~/$hostlist/;
139 s/~hostdetails~/$hostdetails/;