From: tausq <> Date: Thu, 30 Sep 1999 03:38:06 +0000 (+0000) Subject: host information web-based information scripts added X-Git-Tag: release-0.3.33~157 X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap-cgi.git;a=commitdiff_plain;h=9796375e06612fdc1d9b96edf1dd9c6fd05d0b63 host information web-based information scripts added --- diff --git a/machines.cgi b/machines.cgi new file mode 100755 index 0000000..193eeca --- /dev/null +++ b/machines.cgi @@ -0,0 +1,142 @@ +#!/usr/bin/perl + +# (c) 1999 Randolph Chung. Licensed under the GPL. + +use lib '.'; +use strict vars; +#use Apache::Registry; +use CGI; +use Util; +use Net::LDAP qw(:all); + +my (%attrs, @attrorder, %summaryattrs, @summaryorder); + +# This defines the description of the fields, and which fields are retrieved +%attrs = ('hostname' => 'Host name', + 'admin' => 'Admin contact', + 'architecture' => 'Architecture', + 'distribution' => 'Distribution', + 'access' => 'Access', + 'sponsor' => 'Sponsor', + 'sponsorurl' => 'Sponsor URL', + 'sponsor-admin' => 'Sponsor admin', + 'location' => 'Location', + 'machine' => 'Processor', + 'memory' => 'Memory', + 'disk' => 'Disk space', + 'bandwidth' => 'Bandwidth', + 'notes' => 'Notes', + 'createtimestamp' => 'Entry created', + 'modifytimestamp' => 'Entry modified' + ); + +# This defines what fields are displayed, and in what order +@attrorder = ('hostname', 'admin', 'architecture', 'distribution', 'access', + 'sponsor', 'sponsor-admin', 'location', 'machine', 'memory', + 'disk', 'bandwidth', 'notes', 'createtimestamp', 'modifytimestamp'); + +# ditto for summary +%summaryattrs = ('hostname' => 'Host name', + 'host' => 'just for a link', + 'architecture' => 'Architecture', + 'access' => 'Access'); + +@summaryorder = ('hostname', 'architecture', 'access'); + +# Global settings... +my %config = &Util::ReadConfigFile; + +my ($ldap, $mesg, $dn, $entries, $data, %output, $key, $hostlist, $hostdetails, $selected, %summary); +sub DieHandler { + $ldap->unbind if (defined($ldap)); +} + +$SIG{__DIE__} = \&DieHandler; + +my $query = new CGI; +my $host = lc($query->param('host')); + +&Util::HTMLSendHeader; +$ldap = Net::LDAP->new($config{ldaphost}) || &Util::HTMLError($!); +$mesg; +$ldap->bind; + +$mesg = $ldap->search(base => $config{hostbasedn}, filter => 'host=*'); +$mesg->code && &Util::HTMLError($mesg->error); +$entries = $mesg->as_struct; + +foreach $dn (sort {$entries->{$a}->{host}->[0] <=> $entries->{$b}->{host}->[0]} keys(%$entries)) { + $data = $entries->{$dn}; + + my $thishost = $data->{host}->[0]; + $selected = ""; + + if (lc($thishost) eq $host) { + $output{havehostdata} = 1; + + foreach $key (keys(%attrs)) { + $output{$key} = $data->{$key}->[0]; + } + + # Modified/created time. TODO: maybe add is the name of the creator/modifier + $output{modifytimestamp} = &Util::FormatTimestamp($output{modifytimestamp}); + $output{createtimestamp} = &Util::FormatTimestamp($output{createtimestamp}); + + # Format email addresses + $output{admin} = sprintf("%s", $output{admin}, $output{admin}); + $output{'sponsor-admin'} = sprintf("%s", $output{'sponsor-admin'}, $output{'sponsor-admin'}); + + # URL + $output{sponsor} = sprintf("%s", $output{sponsorurl}, $output{sponsor}); + + $selected = " selected "; + } + + $hostlist .= "