#!/usr/bin/perl
+# $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>
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);
'distribution' => 'Distribution',
'access' => 'Access',
'sponsor' => 'Sponsor',
- 'sponsorurl' => 'Sponsor URL',
'sponsor-admin' => 'Sponsor admin',
'location' => 'Location',
'machine' => 'Processor',
'memory' => 'Memory',
'disk' => 'Disk space',
'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', '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',
'host' => 'just for a link',
'architecture' => 'Architecture',
+ 'distribution' => 'Distribution',
+ 'status' => 'Status',
'access' => 'Access');
-@summaryorder = ('hostname', 'architecture', 'access');
+@summaryorder = ('hostname', 'architecture', 'distribution', 'status', 'access');
# Global settings...
my %config = &Util::ReadConfigFile;
$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;
$mesg->code && &Util::HTMLError($mesg->error);
$entries = $mesg->as_struct;
-foreach $dn (sort {$entries->{$a}->{host}->[0] <=> $entries->{$b}->{host}->[0]} keys(%$entries)) {
+foreach $dn (sort {$entries->{$a}->{host}->[0] cmp $entries->{$b}->{host}->[0]} keys(%$entries)) {
$data = $entries->{$dn};
my $thishost = $data->{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});
# 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
- $output{sponsor} = sprintf("<a href=\"%s\">%s</a>", $output{sponsorurl}, $output{sponsor});
+ my ($sponsor, $url) = undef;
+ $output{sponsor} = undef;
+ foreach $sponsor (@{$data->{sponsor}}) {
+ $sponsor =~ m#((http|ftp)://\S+)#i;
+ $url = $1;
+ $sponsor =~ s/\s*$url\s*//;
+ $output{sponsor} .= "<br>" if ($output{sponsor});
+ if ($url) {
+ $output{sponsor} .= sprintf("<a href=\"%s\">%s</a>", $url, $sponsor);
+ } else {
+ $output{sponsor} .= $sponsor;
+ }
+ }
+
+ #Reformat purposes to be pleasing for the human eye:
+ $output{purpose} = join(",", @{$data->{purpose}});
$selected = " selected ";
}
$summary{$thishost}{$key} = $data->{$key}->[0];
}
- $summary{$thishost}{hostname} = sprintf("<a href=\"machines.cgi?host=%s\">%s</a>",
- $summary{$thishost}{host}, $summary{$thishost}{hostname});
+ $summary{$thishost}{hostname} = undef;
+ foreach my $hostname (@{$data->{hostname}}) {
+ $summary{$thishost}{hostname} .= sprintf("%s<a href=\"machines.cgi?host=%s\">%s</a>", ($summary{$thishost}{hostname} ? '<br>' : ''), $summary{$thishost}{host}, $hostname);
+ }
}
$ldap->unbind;
$hostdetails .= "<ul>\n";
foreach $key (@attrorder) {
if ($output{$key}) {
- $hostdetails .= "<li><b>$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<th>";
+ $hostdetails .= "<table border=\"1\" width=\"90%\">\n<tr>";
foreach $key (@summaryorder) {
- $hostdetails .= "<td>$summaryattrs{$key}</td>";
+ $hostdetails .= "<th>$summaryattrs{$key}</th>";
}
- $hostdetails .= "</th>\n";
+ $hostdetails .= "</tr>\n";
foreach $host (sort(keys(%summary))) {
$hostdetails .= "<tr>";