X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=machines.cgi;h=5cdbbcd021449508136426ab902403e44e9a4d55;hb=f9609dae4f7fce6ca978c830f8e6311b7a94723c;hp=8fe4bfa8110b87308962f7eb61e0431315f85ca8;hpb=beceaeac140991c67a064ddbbff6f8445dceb9f6;p=mirror%2Fuserdir-ldap-cgi.git diff --git a/machines.cgi b/machines.cgi index 8fe4bfa..5cdbbcd 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; @@ -16,7 +17,7 @@ use POSIX; use MIME::Base64; use Digest::MD5 qw(md5_hex); -my (%attrs, @attrorder, %summaryattrs, @summaryorder); +my (%attrs, @attrorder, %summaryattrs, @summaryorder, %summarylistitems); # This defines the description of the fields, and which fields are retrieved %attrs = ('hostname' => 'Host name', @@ -49,13 +50,14 @@ my (%attrs, @attrorder, %summaryattrs, @summaryorder); # ditto for summary %summaryattrs = ('hostname' => 'Host name', - 'host' => 'just for a link', - 'architecture' => 'Architecture', - 'distribution' => 'Distribution', + 'host' => 'just for a link', + 'architecture' => 'Architecture', 'status' => 'Status', - 'access' => 'Access'); - -@summaryorder = ('hostname', 'architecture', 'distribution', 'status', 'access'); + 'access' => 'Access', + 'sponsor' => 'Sponsor', + 'purpose' => 'Purpose'); +@summaryorder = qw{hostname architecture sponsor purpose status access}; +%summarylistitems = map {$_=>1} qw{purpose sponsor}; # Global settings... my %config = &Util::ReadConfigFile; @@ -82,13 +84,38 @@ sub sshfingerprint { return $hrfpr; } +sub wiki_link($) { + my ($in) = @_; + $in =~ s#\[\[(.*?)\|(.*?)\]\]#$2#g; + $in =~ s#\[\[(.*?)\]\]#$1#g; + return $in; +} + +sub item_uplist($) { + my ($items) = @_; + my $out = undef; + + if (scalar @$items >= 1) { + $out = "
    ". + join("", map { + "
  • ".wiki_link($_)."
  • \n"; + } sort {my $A=$a; my $B=$b; $A =~ s/[\[\]]//g; $B =~ s/[\[\]]//g; $A cmp $B} @{$items} + ). + "
"; + } + 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; @@ -131,34 +158,26 @@ foreach $dn (sort {$entries->{$a}->{host}->[0] cmp $entries->{$b}->{host}->[0]} $output{sshrsahostfprint} .= sshfingerprint($key) . "
"; } - # URL - 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} .= "
" if ($output{sponsor}); - if ($url) { - $output{sponsor} .= sprintf("%s", $url, $sponsor); - } else { - $output{sponsor} .= $sponsor; - } - } + my $sponsor = item_uplist($data->{sponsor}); + $output{sponsor} = $sponsor if defined $sponsor; + my $purpose = item_uplist($data->{purpose}); + $output{purpose} = $purpose if defined $purpose; - #Reformat purposes to be pleasing for the human eye: - $output{purpose} = join(",", @{$data->{purpose}}); - - $selected = " selected "; + $selected = " selected "; } - - $hostlist .= "