X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=machines.cgi;h=383f7cd08ba0d7a2098b7d441f15b7927b18efa6;hb=7d4df26c66fcce393db4f57374f92ed9407c43dd;hp=383f791d409e33a8bc6b77241ef9b32433f2d04a;hpb=09e42a2060a62daacd132ec109ebd901b0ead11c;p=mirror%2Fuserdir-ldap-cgi.git diff --git a/machines.cgi b/machines.cgi index 383f791..383f7cd 100755 --- a/machines.cgi +++ b/machines.cgi @@ -1,7 +1,9 @@ #!/usr/bin/perl -# $Id: machines.cgi,v 1.6 2000/08/19 02:34:11 tausq Exp $ +# $Id: machines.cgi,v 1.12 2006/12/27 23:00:04 rmurray Exp $ # (c) 1999 Randolph Chung. Licensed under the GPL. +# (c) 2004 Martin Schulze. Licensed under the GPL. +# (c) 2006 Ryan Murray. Licensed under the GPL. use lib '.'; use strict vars; @@ -9,6 +11,10 @@ use strict vars; use CGI; use Util; use Net::LDAP qw(:all); +use Fcntl; +use POSIX; +use MIME::Base64; +use Digest::MD5 qw(md5_hex); my (%attrs, @attrorder, %summaryattrs, @summaryorder); @@ -27,14 +33,18 @@ my (%attrs, @attrorder, %summaryattrs, @summaryorder); 'bandwidth' => 'Bandwidth', 'status' => 'Status', 'notes' => 'Notes', - 'createtimestamp' => 'Entry created', - 'modifytimestamp' => 'Entry modified' + 'sshrsahostkey' => 'SSH host key', + 'sshrsahostfprint' => 'SSH host fingerprint', + 'description' => 'Description', +# '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', 'status', 'notes', 'createtimestamp', 'modifytimestamp'); +@attrorder = qw(hostname admin architecture distribution access + sponsor sponsor-admin location machine memory + disk bandwidth status notes sshrsahostkey sshrsahostfprint + description); # ditto for summary %summaryattrs = ('hostname' => 'Host name', @@ -54,6 +64,23 @@ sub DieHandler { $ldap->unbind if (defined($ldap)); } +# human readable fingerprint +sub sshfingerprint { + my $key = shift; + + return '' if (!$key); + + my @field = split(/ /, $key); + return '' if $field[0] ne 'ssh-dss' and $field[0] ne 'ssh-rsa'; + return '' if !$field[1]; + my $fpr = md5_hex(decode_base64($field[1])); + my $hrfpr = $field[0] . " " . substr($fpr,0,2,""); + while (length $fpr > 0) { + $hrfpr .= ':' . substr($fpr,0,2,""); + } + return $hrfpr; +} + $SIG{__DIE__} = \&DieHandler; my $query = new CGI; @@ -80,6 +107,11 @@ foreach $dn (sort {$entries->{$a}->{host}->[0] cmp $entries->{$b}->{host}->[0]} foreach $key (keys(%attrs)) { $output{$key} = $data->{$key}->[0]; } + + $output{hostname} = undef; + foreach my $hostname (@{$data->{hostname}}) { + $output{hostname} .= sprintf("%s%s", ($output{hostname} ? ', ' : ''), $hostname); + } # Modified/created time. TODO: maybe add is the name of the creator/modifier $output{modifytimestamp} = &Util::FormatTimestamp($output{modifytimestamp}); @@ -88,6 +120,15 @@ foreach $dn (sort {$entries->{$a}->{host}->[0] cmp $entries->{$b}->{host}->[0]} # Format email addresses $output{admin} = sprintf("%s", $output{admin}, $output{admin}); $output{'sponsor-admin'} = sprintf("%s", $output{'sponsor-admin'}, $output{'sponsor-admin'}); + + $output{sshrsahostkey} = undef; + foreach $key (@{$data->{sshrsahostkey}}) { + $output{sshrsahostkey} .= $key . "
"; + } + + foreach $key (@{$data->{sshrsahostkey}}) { + $output{sshrsahostfprint} .= sshfingerprint($key) . "
"; + } # URL my ($sponsor, $url) = undef; @@ -95,7 +136,7 @@ foreach $dn (sort {$entries->{$a}->{host}->[0] cmp $entries->{$b}->{host}->[0]} foreach $sponsor (@{$data->{sponsor}}) { $sponsor =~ m#((http|ftp)://\S+)#i; $url = $1; - $sponsor =~ s/$url//; + $sponsor =~ s/\s*$url\s*//; $output{sponsor} .= "
" if ($output{sponsor}); if ($url) { $output{sponsor} .= sprintf("%s", $url, $sponsor); @@ -116,7 +157,7 @@ foreach $dn (sort {$entries->{$a}->{host}->[0] cmp $entries->{$b}->{host}->[0]} $summary{$thishost}{hostname} = undef; foreach my $hostname (@{$data->{hostname}}) { - $summary{$thishost}{hostname} .= sprintf("%s%s", ($summary{$thishost}{hostname} ? ', ' : ''), $summary{$thishost}{host}, $hostname); + $summary{$thishost}{hostname} .= sprintf("%s%s", ($summary{$thishost}{hostname} ? '
' : ''), $summary{$thishost}{host}, $hostname); } } $ldap->unbind; @@ -126,14 +167,14 @@ if ($output{havehostdata}) { $hostdetails .= "
    \n"; foreach $key (@attrorder) { if ($output{$key}) { - $hostdetails .= "
  • $attrs{$key}: $output{$key}\n"; + $hostdetails .= "
  • $attrs{$key}:$output{$key}\n"; } } $hostdetails .= "
\n"; } else { # display summary info $hostdetails = "

Summary

\n"; - $hostdetails .= "\n"; + $hostdetails .= "
\n"; foreach $key (@summaryorder) { $hostdetails .= ""; }
$summaryattrs{$key}