X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=machines.cgi;h=bf0c058869bd9516fe6cbd2ab1035bdb01fc1c0a;hb=0703b543dee932b71a73e7c4b1b1922a6f4247b4;hp=72f729bae8844a5b205486eed268dc15f92d9764;hpb=d242cbc0a1f1bf7e36ec02464fb33d0ad234cd8d;p=mirror%2Fuserdir-ldap-cgi.git diff --git a/machines.cgi b/machines.cgi index 72f729b..bf0c058 100755 --- a/machines.cgi +++ b/machines.cgi @@ -1,7 +1,10 @@ #!/usr/bin/perl -# $Id: machines.cgi,v 1.7 2000/08/19 02:53:56 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. +# (c) 2008 Martin Zobel-Helas. Licensed under the GPL. use lib '.'; use strict vars; @@ -9,6 +12,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 +34,19 @@ 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', + 'purpose' => 'purposes of this server', +# '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 purpose); # ditto for summary %summaryattrs = ('hostname' => 'Host name', @@ -54,13 +66,55 @@ 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; +} + +sub wiki_link($) { + my ($in) = @_; + $in =~ s#\[\[(.*?)\|(.*?)\]\]#$2#g; + $in =~ s#\[\[(.*?)\]\]#$1#g; + return $in; +} + +sub purposes_uplist($) { + my ($purposes) = @_; + my $out = undef; + + if (scalar @$purposes >= 1) { + $out = "
    ". + join("", map { + "
  • ".wiki_link($_)."
  • \n"; + } sort {my $A=$a; my $B=$b; $A =~ s/[\[\]]//g; $B =~ s/[\[\]]//g; $A cmp $B} @{$purposes} + ). + "
"; + } + return $out; +} + $SIG{__DIE__} = \&DieHandler; my $query = new CGI; my $host = lc($query->param('host')); +my $sortby = lc($query->param('sortby')) || "host"; +my $sortorder = lc($query->param('sortorder')) || "asc"; &Util::HTMLSendHeader; $ldap = Net::LDAP->new($config{ldaphost}) || &Util::HTMLError($!); +&Util::UpgradeConnection($ldap) unless $config{usessl} eq 'False'; $mesg; $ldap->bind; @@ -93,6 +147,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; @@ -100,7 +163,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); @@ -108,7 +171,10 @@ foreach $dn (sort {$entries->{$a}->{host}->[0] cmp $entries->{$b}->{host}->[0]} $output{sponsor} .= $sponsor; } } - + + my $purpose = purposes_uplist($data->{purpose}); + $output{purpose} = $purpose if defined $purpose; + $selected = " selected "; } @@ -131,20 +197,34 @@ 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 .= ""; + if ($sortby ne $key) { + $hostdetails .= ""; + } else { + if ($sortorder ne "dsc") { + $hostdetails .= ""; + } else { + $hostdetails .= ""; + } + } } $hostdetails .= "\n"; - foreach $host (sort(keys(%summary))) { + my @sorted; + if ($sortorder eq "asc") { + @sorted = sort {($summary{$a}->{$sortby} cmp $summary{$b}->{$sortby}) || ($summary{$a}->{'host'} cmp $summary{$b}->{'host'})} keys(%summary) + } else { + @sorted = sort {($summary{$b}->{$sortby} cmp $summary{$a}->{$sortby}) || ($summary{$a}->{'host'} cmp $summary{$b}->{'host'})} keys(%summary) + } + foreach $host (@sorted) { $hostdetails .= ""; foreach $key (@summaryorder) { $hostdetails .= "";
$summaryattrs{$key}$summaryattrs{$key}$summaryattrs{$key}$summaryattrs{$key}
$summary{$host}{$key}