#!/usr/bin/perl
-# $Id: machines.cgi,v 1.9 2001/01/08 07:03:23 tausq Exp $
+# $Id: machines.cgi,v 1.12 2006/12/27 23:00:04 rmurray Exp $
# (c) 1999 Randolph Chung. Licensed under the GPL. <tausq@debian.org>
+# (c) 2004 Martin Schulze. Licensed under the GPL. <joey@debian.org>
+# (c) 2006 Ryan Murray. Licensed under the GPL. <rmurray@debian.org>
+# (c) 2008 Martin Zobel-Helas. Licensed under the GPL. <zobel@debian.org>
use lib '.';
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);
'bandwidth' => 'Bandwidth',
'status' => 'Status',
'notes' => 'Notes',
- 'sshrsahostkey' => 'SSH host key (RSA)',
- 'sshdsahostkey' => 'SSH host key (DSA)',
+ 'sshrsahostkey' => 'SSH host key',
+ 'sshrsahostfprint' => 'SSH host fingerprint',
'description' => 'Description',
- 'createtimestamp' => 'Entry created',
- 'modifytimestamp' => 'Entry modified'
+ 'purpose' => 'purposes of this server',
+# '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 sshdsahostkey
- description createtimestamp modifytimestamp);
+ disk bandwidth status notes sshrsahostkey sshrsahostfprint
+ description purpose);
# ditto for summary
%summaryattrs = ('hostname' => 'Host name',
$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;
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($!);
# Format email addresses
$output{admin} = sprintf("<a href=\"mailto:%s\">%s</a>", $output{admin}, $output{admin});
$output{'sponsor-admin'} = sprintf("<a href=\"mailto:%s\">%s</a>", $output{'sponsor-admin'}, $output{'sponsor-admin'});
+
+ $output{sshrsahostkey} = undef;
+ foreach $key (@{$data->{sshrsahostkey}}) {
+ $output{sshrsahostkey} .= $key . "<br>";
+ }
+
+ foreach $key (@{$data->{sshrsahostkey}}) {
+ $output{sshrsahostfprint} .= sshfingerprint($key) . "<br>";
+ }
# URL
my ($sponsor, $url) = undef;
foreach $sponsor (@{$data->{sponsor}}) {
$sponsor =~ m#((http|ftp)://\S+)#i;
$url = $1;
- $sponsor =~ s/$url//;
+ $sponsor =~ s/\s*$url\s*//;
$output{sponsor} .= "<br>" if ($output{sponsor});
if ($url) {
$output{sponsor} .= sprintf("<a href=\"%s\">%s</a>", $url, $sponsor);
$output{sponsor} .= $sponsor;
}
}
+
+ #Reformat purposes to be pleasing for the human eye:
+ $output{purpose} = join(",", @{$data->{purpose}});
$selected = " selected ";
}
$hostdetails .= "<ul>\n";
foreach $key (@attrorder) {
if ($output{$key}) {
- $hostdetails .= "<li><b>$attrs{$key}:</b> $output{$key}\n";
+ $hostdetails .= "<li><b>$attrs{$key}:</b>$output{$key}\n";
}
}
$hostdetails .= "</ul>\n";
} else {
# display summary info
$hostdetails = "<h1>Summary</h1>\n";
- $hostdetails .= "<table border=1 width=90%>\n<tr>";
+ $hostdetails .= "<table border=\"1\" width=\"90%\">\n<tr>";
foreach $key (@summaryorder) {
- $hostdetails .= "<th>$summaryattrs{$key}</th>";
+ if ($sortby ne $key) {
+ $hostdetails .= "<th><a href=\"machines.cgi?sortby=$key&sortorder=asc\">$summaryattrs{$key}</a></th>";
+ } else {
+ if ($sortorder ne "dsc") {
+ $hostdetails .= "<th><a href=\"machines.cgi?sortby=$key&sortorder=dsc\">$summaryattrs{$key}</a></th>";
+ } else {
+ $hostdetails .= "<th><a href=\"machines.cgi?sortby=$key&sortorder=asc\">$summaryattrs{$key}</a></th>";
+ }
+ }
}
$hostdetails .= "</tr>\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 .= "<tr>";
foreach $key (@summaryorder) {
$hostdetails .= "<td>$summary{$host}{$key} </td>";