X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=machines.cgi;h=c50c4cbc6dc38b25e984e5f41e9f7f5f7162fa31;hb=2208385fcd937d7896023bcd60f6521102693a0d;hp=383f7cd08ba0d7a2098b7d441f15b7927b18efa6;hpb=7d4df26c66fcce393db4f57374f92ed9407c43dd;p=mirror%2Fuserdir-ldap-cgi.git diff --git a/machines.cgi b/machines.cgi index 383f7cd..c50c4cb 100755 --- a/machines.cgi +++ b/machines.cgi @@ -4,6 +4,7 @@ # (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; @@ -36,6 +37,7 @@ my (%attrs, @attrorder, %summaryattrs, @summaryorder); 'sshrsahostkey' => 'SSH host key', 'sshrsahostfprint' => 'SSH host fingerprint', 'description' => 'Description', + 'purpose' => 'purposes of this server', # 'createtimestamp' => 'Entry created', # 'modifytimestamp' => 'Entry modified' ); @@ -44,7 +46,7 @@ my (%attrs, @attrorder, %summaryattrs, @summaryorder); @attrorder = qw(hostname admin architecture distribution access sponsor sponsor-admin location machine memory disk bandwidth status notes sshrsahostkey sshrsahostfprint - description); + description purpose); # ditto for summary %summaryattrs = ('hostname' => 'Host name', @@ -81,13 +83,32 @@ sub sshfingerprint { return $hrfpr; } +sub purposes_uplist($) { + my ($purposes) = @_; + my $out = undef; + + if (scalar @$purposes >= 1) { + $out = "
    ". + join("", map { + s#\[\[(.*?)\]\]#$1#g; + "
  • $_
  • \n"; + } sort {my $A=$a; my $B=$b; $A =~ s/[\[\]]//g; $B =~ s/[\[\]]//g; $A cmp $B} @{$data->{purpose}} + ). + "
"; + } + 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; @@ -144,7 +165,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 "; } @@ -176,11 +200,25 @@ if ($output{havehostdata}) { $hostdetails = "

Summary

\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}