Handle hostnames with upper-case letters
[webmin.git] / shorewall / list.cgi
1 #!/usr/bin/perl
2 # list.cgi
3 # Display the contents of some table
4
5 require './shorewall-lib.pl';
6 &ReadParse();
7 &can_access($in{'table'}) || &error($text{'list_ecannot'});
8 &get_clean_table_name(\%in);
9 &ui_print_header(undef, $text{$in{'tableclean'}."_title"}, "");
10
11 $desc = $text{$in{'tableclean'}."_desc"};
12 print "$desc<p>\n" if ($desc);
13
14 $pfunc = &get_parser_func(\%in);
15 @table = &read_table_file($in{'table'}, $pfunc);
16 $cfunc = $in{'tableclean'}."_columns";
17 $cols = &$cfunc() if (defined(&$cfunc));
18 $nfunc = $in{'tableclean'}."_colnames";
19 #&debug_message("cfunc = $cfunc");
20 #&debug_message("nfunc = $nfunc");
21 if (defined(&$nfunc)) {
22         @colnames = &$nfunc();
23         }
24 else {
25         @colnames = ( );
26         for($j=0; defined($cols) ? ($j<$cols) : ($text{$in{'tableclean'}."_".$j}); $j++) {
27                 push(@colnames, $text{$in{'tableclean'}."_".$j});
28                 }
29         }
30
31 # Work out select/create links
32 @links = ( &select_all_link("d"),
33            &select_invert_link("d"),
34            "<a href='edit.cgi?table=$in{'table'}&new=1'>".
35             $text{$in{'tableclean'}."_add"}."</a>" );
36 if (&version_atleast(3, 3, 3) && &indexof($in{'table'}, @comment_tables) >= 0) {
37         push(@links, "<a href='editcmt.cgi?table=$in{'table'}&new=1'>".
38                      $text{"comment_add"}."</a>");
39         }
40
41 # Show the table
42 if (@table) {
43         print &ui_form_start("delete.cgi", "post");
44         print &ui_hidden("table", $in{'table'}),"\n";
45         print &ui_links_row(\@links);
46         print &ui_columns_start([
47                 "",
48                 @colnames,
49                 (@table > 1 ? ( $text{'list_move'} ) : ( )),
50                 $text{'list_add'}
51                 ], undef, 0, [ "width=5" ]);
52
53         $rfunc = $in{'tableclean'}."_row";
54         for($i=0; $i<@table; $i++) {
55                 @t = @{$table[$i]};
56                 local @cols;
57                 local @tds;
58                 if ($t[0] eq "COMMENT") {
59                         # Special case - a comment line
60                         push(@cols, "<a href='editcmt.cgi?table=$in{'table'}&".
61                                     "idx=$i'><i>".join(" ", @t[1..$#t]).
62                                     "</i></a>" );
63                         @tds = ( "width=5", "colspan=".scalar(@colnames) );
64                         }
65                 else {
66                         # Some rule or other object
67                         if (defined(&$rfunc)) {
68                                 @t = &$rfunc(@t);
69                                 }
70                         for($j=0; $j<@colnames; $j++) {
71                                 if ($j == 0) {
72                                         $lnk = "<a href='edit.cgi?table=$in{'table'}&idx=$i'>$t[$j]</a>";
73                                         }
74                                 else {
75                                         $lnk = $t[$j];
76                                         }
77                                 push(@cols, $lnk);
78                                 }
79                         @tds = ( "width=5" );
80                         }
81                 if (@table > 1) {
82                         $mover = "";
83                         if ($i == 0) {
84                                 $mover .= "<img src=images/gap.gif>";
85                                 }
86                         else {
87                                 $mover .= "<a href='up.cgi?table=$in{'table'}&idx=$i'><img src=images/up.gif border=0></a>\n";
88                                 }
89                         if ($i == $#table) {
90                                 $mover .= "<img src=images/gap.gif>";
91                                 }
92                         else {
93                                 $mover .= "<a href='down.cgi?table=$in{'table'}&idx=$i'><img src=images/down.gif border=0></a>\n";
94                                 }
95                         push(@cols, $mover);
96                         }
97                 push(@cols, 
98                       "<a href='edit.cgi?table=$in{'table'}&new=1&before=$i'>".
99                       "<img src=images/before.gif border=0></a>\n".
100                       "<a href='edit.cgi?table=$in{'table'}&new=1&after=$i'>".
101                       "<img src=images/after.gif border=0></a>\n");
102                 print &ui_checked_columns_row(\@cols, \@tds, "d", $i);
103                 }
104         print &ui_columns_end();
105         }
106 else {
107         print "<b>",$text{$in{'tableclean'}."_none"},"</b><p>\n";
108         shift(@links); shift(@links);
109         }
110 print &ui_links_row(\@links);
111 if (@table) {
112         print &ui_form_end([ [ "delete", $text{'list_delete'} ] ]);
113         }
114
115 print &ui_hr();
116 print &ui_buttons_start();
117 print &ui_buttons_row("manual_form.cgi", $text{'list_manual'},
118                       &text('list_manualdesc',
119                         "<tt>$config{'config_dir'}/$in{'table'}</tt>"),
120                       &ui_hidden("table", $in{'table'}));
121 print &ui_buttons_end();
122
123 &ui_print_footer("", $text{'index_return'});