X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap-cgi.git;a=blobdiff_plain;f=machines.cgi;h=98567ec9f137afa55ea5c010b59ecae67e98308b;hp=b7cc9d0449a94dcf265d498b7c7256fb7cfae9d5;hb=5cea731d1b6f9504bd695fd2f201761c35f71a2c;hpb=b6d2744f934a1a6349be7a7ade1b4831e6eab2bd diff --git a/machines.cgi b/machines.cgi index b7cc9d0..98567ec 100755 --- a/machines.cgi +++ b/machines.cgi @@ -11,13 +11,13 @@ use strict vars; #use Apache::Registry; use CGI; use Util; -use Net::LDAP qw(:all); +use Net::LDAP qw(LDAP_SUCCESS LDAP_PROTOCOL_ERROR); use Fcntl; 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', @@ -50,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; @@ -73,7 +74,8 @@ sub sshfingerprint { return '' if (!$key); my @field = split(/ /, $key); - return '' if $field[0] ne 'ssh-dss' and $field[0] ne 'ssh-rsa'; + my %keytypes = map {$_=>1} (qw{ssh-dss ssh-rsa ecdsa-sha2-nistp256}); + return '' unless $keytypes{$field[0]}; return '' if !$field[1]; my $fpr = md5_hex(decode_base64($field[1])); my $hrfpr = $field[0] . " " . substr($fpr,0,2,""); @@ -85,33 +87,47 @@ sub sshfingerprint { sub wiki_link($) { my ($in) = @_; - $in =~ s#\[\[(.*?)\|(.*?)\]\]#$2#g; - $in =~ s#\[\[(.*?)\]\]#$1#g; + # [[hostname|text]] makes a link + # [[hostname]] makes a link too + # if you add a * after [[ it's still the same, only not used for ssh_known_hosts in ud-generate + # [[-hostname]] are not links, but get added to known_hosts. we should drop the [[- ]] tho + $in =~ s#\[\[-(.*?)\]\]#$1#g; + $in =~ s#\[\[\*?(.*?)\|(.*?)\]\]#$2#g; + $in =~ s#\[\[\*?(.*?)\]\]#$1#g; return $in; } +# in the purpose field [[host|some other text]] (where some other text is optional) +# makes a hyperlink on the web thing. we now also add these hosts to the ssh known_hosts +# file. But so that we don't have to add everything we link we can add an asterisk +# and say [[*... to ignore it. In order to be able to add stuff to ssh without +# http linking it we also support [[-hostname]] entries. +# +# sponsors are also wikified like purpose. maybe others as well sub item_uplist($) { my ($items) = @_; my $out = undef; + my(@tmp) = @$items; - if (scalar @$items >= 1) { + if (scalar @tmp>= 1) { $out = ""; } return $out; } -$SIG{__DIE__} = \&DieHandler; +#$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'; @@ -162,16 +178,21 @@ foreach $dn (sort {$entries->{$a}->{host}->[0] cmp $entries->{$b}->{host}->[0]} my $purpose = item_uplist($data->{purpose}); $output{purpose} = $purpose if defined $purpose; - $selected = " selected "; + $selected = " selected "; } - - $hostlist .= "