From 7d4df26c66fcce393db4f57374f92ed9407c43dd Mon Sep 17 00:00:00 2001 From: rmurray <> Date: Wed, 27 Dec 2006 22:00:04 +0000 Subject: [PATCH] Improve sshfingerprint implementation, remove unavailable fields from being displayed --- debian/changelog | 9 +++++++++ machines.cgi | 50 +++++++++++++++++++++++------------------------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/debian/changelog b/debian/changelog index 3ac7f7f..7c61cb3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +userdir-ldap-cgi (0.3.9) unstable; urgency=low + + * machines.cgi + - Reimplement ssh fingerprint without using temp files and external + programs. + - Remove access-restricted date fields. + + -- Ryan Murray Wed, 27 Dec 2006 15:59:34 -0700 + userdir-ldap-cgi (0.3.8) unstable; urgency=low Changes by Martin Schulze: diff --git a/machines.cgi b/machines.cgi index de4d30f..383f7cd 100755 --- a/machines.cgi +++ b/machines.cgi @@ -1,8 +1,9 @@ #!/usr/bin/perl -# $Id: machines.cgi,v 1.11 2004/11/18 14:27:46 joey 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; @@ -12,6 +13,8 @@ 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); @@ -33,15 +36,15 @@ my (%attrs, @attrorder, %summaryattrs, @summaryorder); 'sshrsahostkey' => 'SSH host key', 'sshrsahostfprint' => 'SSH host fingerprint', 'description' => 'Description', - 'createtimestamp' => 'Entry created', - 'modifytimestamp' => 'Entry modified' +# 'createtimestamp' => 'Entry created', +# 'modifytimestamp' => 'Entry modified' ); # This defines what fields are displayed, and in what order @attrorder = qw(hostname admin architecture distribution access sponsor sponsor-admin location machine memory disk bandwidth status notes sshrsahostkey sshrsahostfprint - description createtimestamp modifytimestamp); + description); # ditto for summary %summaryattrs = ('hostname' => 'Host name', @@ -61,28 +64,21 @@ sub DieHandler { $ldap->unbind if (defined($ldap)); } +# human readable fingerprint sub sshfingerprint { - my $keys = shift; - my $res = ''; - my $fn = ''; + my $key = shift; - return '' if (!$keys); - do { - $fn = tmpnam(); - } until sysopen(FH, $fn, O_RDWR|O_CREAT|O_EXCL, 0600); + return '' if (!$key); - foreach my $key (split(/
/, $keys)) { - printf FH "foo %s\n", $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,""); } - close (FH); - - if (open (S, "ssh-keygen -l -f $fn|")) { - $res = join("\n", ); - close (S); - } - $res =~ s/\n/
/g; - unlink ($fn); - return $res; + return $hrfpr; } $SIG{__DIE__} = \&DieHandler; @@ -130,7 +126,9 @@ foreach $dn (sort {$entries->{$a}->{host}->[0] cmp $entries->{$b}->{host}->[0]} $output{sshrsahostkey} .= $key . "
"; } - $output{sshrsahostfprint} = sshfingerprint($output{sshrsahostkey}); + foreach $key (@{$data->{sshrsahostkey}}) { + $output{sshrsahostfprint} .= sshfingerprint($key) . "
"; + } # URL my ($sponsor, $url) = undef; @@ -138,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); @@ -169,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 .= ""; } -- 2.20.1
$summaryattrs{$key}