X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=machines.cgi;h=de4d30f029e8776101f173a13cec60c5db336859;hb=f1af5002f6710b37cf3d2b3903ef3103a34424a6;hp=e0ee813c8766f72c04ea2b5eca066e1295bb1ad3;hpb=26a428ef723aaefce54586871e9547ade9e359a9;p=mirror%2Fuserdir-ldap-cgi.git diff --git a/machines.cgi b/machines.cgi index e0ee813..de4d30f 100755 --- a/machines.cgi +++ b/machines.cgi @@ -1,7 +1,8 @@ #!/usr/bin/perl -# $Id: machines.cgi,v 1.8 2000/08/20 02:32:46 tausq Exp $ +# $Id: machines.cgi,v 1.11 2004/11/18 14:27:46 joey Exp $ # (c) 1999 Randolph Chung. Licensed under the GPL. +# (c) 2004 Martin Schulze. Licensed under the GPL. use lib '.'; use strict vars; @@ -9,6 +10,8 @@ use strict vars; use CGI; use Util; use Net::LDAP qw(:all); +use Fcntl; +use POSIX; my (%attrs, @attrorder, %summaryattrs, @summaryorder); @@ -27,16 +30,18 @@ my (%attrs, @attrorder, %summaryattrs, @summaryorder); 'bandwidth' => 'Bandwidth', 'status' => 'Status', 'notes' => 'Notes', + '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', 'description', - 'createtimestamp', 'modifytimestamp'); +@attrorder = qw(hostname admin architecture distribution access + sponsor sponsor-admin location machine memory + disk bandwidth status notes sshrsahostkey sshrsahostfprint + description createtimestamp modifytimestamp); # ditto for summary %summaryattrs = ('hostname' => 'Host name', @@ -56,6 +61,30 @@ sub DieHandler { $ldap->unbind if (defined($ldap)); } +sub sshfingerprint { + my $keys = shift; + my $res = ''; + my $fn = ''; + + return '' if (!$keys); + do { + $fn = tmpnam(); + } until sysopen(FH, $fn, O_RDWR|O_CREAT|O_EXCL, 0600); + + foreach my $key (split(/
/, $keys)) { + printf FH "foo %s\n", $key; + } + close (FH); + + if (open (S, "ssh-keygen -l -f $fn|")) { + $res = join("\n", ); + close (S); + } + $res =~ s/\n/
/g; + unlink ($fn); + return $res; +} + $SIG{__DIE__} = \&DieHandler; my $query = new CGI; @@ -95,6 +124,13 @@ 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 . "
"; + } + + $output{sshrsahostfprint} = sshfingerprint($output{sshrsahostkey}); # URL my ($sponsor, $url) = undef;