chiark / gitweb /
add note about unexpected password requests
[bcp5-registry.git] / listdb.pl
1 # Routines for actually displaying (parts of) database in CGI output.
2 #
3 # Copyright (C) 1999 Ian Jackson <ijackson@chiark.greenend.org.uk>
4 #
5 # This is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2,
8 # or (at your option) any later version.
9 #
10 # This is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public
16 # License along with this file; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 sub list_database ($) {
20     my ($instyle) = @_;
21     my ($t, $v, $k, $x);
22 print DEBUG "ldb 0 $instyle\n";
23     $instyle =~ m/^all|area|viewoverlap|overlap/ or die "$instyle ?";
24     $listing= $&;
25     &{"dblist_prep_$listing"}();
26     @kl= ();
27 print DEBUG "ldb 1 $v @kl\n";
28     foreach $k (keys %db) {
29 print DEBUG "ldb q $k\n";
30         $ent= $db{$k};
31         $dblt_network= $ent->{'network'};
32         $dblt_prefix= $ent->{'prefix'};
33         next unless &{"dblist_cond_$listing"};
34         push @kl,$k;
35     }
36 print DEBUG "ldb 2 @kl\n";
37     @kl= sort {
38         $x= $db{$a}->{'network'} cmp $db{$b}->{'network'}; return $x if $x;
39         $x= $db{$a}->{'prefix'} <=> $db{$b}->{'prefix'}; return $x if $x;
40         return -1 if $a eq 'picked' && $b ne 'picked';
41         return +1 if $b eq 'picked' && $a ne 'picked';;
42         $x= $db{$a}->{'name'} cmp $db{$b}->{'name'}; return $x if $x;
43         $x= $db{$a}->{'contact'} cmp $db{$b}->{'contact'}; return $x if $x;
44         return $a cmp $b;
45     } @kl;
46 print DEBUG "ldb 3 @kl\n";
47     $listingnonefound= @kl ? 0 : 1;
48 print DEBUG "ldb end $listingnonefound\n";
49     $v= "listing$listing"; $$v= 1;
50     $list= 1;
51 }
52
53 sub dblist_prep_all { }
54 sub dblist_cond_all { 1; }
55
56 sub dblist_prep_area {
57     $dblo_network= $area_networks[$list_areai];
58     $dblo_prefix= $area_prefixes[$list_areai];
59     $listarea= display_net($dblo_network,$dblo_prefix);
60 }
61 sub dblist_cond_area { dblist_cond_overlap(); }
62
63 sub dblist_prep_overlap {
64     ($dblo_network,$dblo_prefix) = parse_netrange($in{'with'});
65     $listoverlap= display_net($dblo_network,$dblo_prefix);
66 }
67 sub dblist_cond_overlap {
68     return net_overlap($dblt_network,$dblt_prefix, $dblo_network,$dblo_prefix);
69 }
70
71 sub dblist_prep_viewoverlap {
72     ($dblo_network,$dblo_prefix) = ($network,$prefix);
73     $listoverlap= display_net($network,$prefix);
74 }
75 sub dblist_cond_viewoverlap { dblist_cond_overlap(); }
76
77 sub foreach_start_db { $db_i=0; }
78 sub foreach_cond_db { return $db_i < @kl; }
79 sub foreach_incr_db { $db_i++; }
80 sub foreach_setvars_db {
81     my ($k, $ent);
82     $k= $kl[$db_i];
83     $ent= $db{$k};
84     $dblt_network= $ent->{'network'};
85     $dblt_prefix= $ent->{'prefix'};
86     $db_picked= $k eq 'picked';
87     if ($db_picked) {
88         undef $db_id;
89     } else {
90         $db_id= $k;
91     }
92     $db_net= display_net($dblt_network,$dblt_prefix);
93     if (exists $db{'picked'}) {
94         $db_pickedoverlap= net_overlap($dblt_network, $dblt_prefix,
95                                        $pick_network, $pick_prefix);
96     } else {
97         $db_pickedoverlap= 0;
98     }
99     if (defined $id) {
100         $db_viewing= ($k eq $id);
101     } else {
102         $db_viewing= 0;
103     }
104     $db_name= html_sani($ent->{'name'});
105     $db_contact= html_sani($ent->{'contact'});
106     $db_hiddenemail= !!$ent->{'hiddenemail'};
107     $db_email= $db_hiddenemail ? "" : html_sani($ent->{'email'});
108     $db_confirmed= !!$ent->{'changed'};
109 }
110
111 1;