Handle hostnames with upper-case letters
[webmin.git] / qmailadmin / list_routes.cgi
1 #!/usr/local/bin/perl
2 # list_routes.cgi
3 # Display a list of SMTP routes
4
5 require './qmail-lib.pl';
6 &ReadParse();
7 &ui_print_header(undef, $text{'routes_title'}, "");
8
9 @routes = &list_routes();
10 ($defroute) = grep { !$_->{'from'} } @routes;
11 @routes = grep { $_ ne $defroute } @routes;
12 &route_form();
13
14 if ($in{'search'}) {
15         # Restrict to search results
16         @routes = grep { $_->{'from'} =~ /$in{'search'}/ } @routes;
17         }
18 elsif ($config{'max_records'} && @routes > $config{'max_records'}) {
19         # Show search form
20         print $text{'routes_toomany'},"<br>\n";
21         print "<form action=list_routes.cgi>\n";
22         print "<input type=submit value='$text{'routes_go'}'>\n";
23         print "<input name=search size=20></form>\n";
24         undef(@routes);
25         }
26
27 if (@routes) {
28         # sort if needed
29         if ($config{'sort_mode'} == 1) {
30                 @routes = sort { lc($a->{'from'}) cmp lc($b->{'from'}) }
31                                @routes;
32                 }
33
34         # render tables
35         print &ui_form_start("delete_routes.cgi", "post");
36         print &select_all_link("d", 1),"\n";
37         print &select_invert_link("d", 1),"<br>\n";
38         if ($config{'columns'} == 2) {
39                 $mid = int((@routes+1)/2);
40                 print "<table width=100%> <tr><td width=50% valign=top>\n";
41                 &routes_table(@routes[0..$mid-1]);
42                 print "</td><td width=50% valign=top>\n";
43                 if ($mid < @routes) { &routes_table(@routes[$mid..$#routes]); }
44                 print "</td></tr> </table><br>\n";
45                 }
46         else {
47                 &routes_table(@routes);
48                 }
49         print &select_all_link("d", 1),"\n";
50         print &select_invert_link("d", 1),"<br>\n";
51         print &ui_form_end([ [ "delete", $text{'routes_delete'} ] ]);
52         }
53
54 print &ui_hr();
55 print "<form action=save_defroute.cgi>\n";
56 print "<input type=hidden name=idx value='$defroute->{'idx'}'>\n"
57         if ($defroute);
58 print "<b>$text{'routes_defroute'}</b>\n";
59 printf "<input type=radio name=direct value=1 %s> %s\n",
60         $defroute ? "" : "checked", $text{'routes_direct'};
61 printf "<input type=radio name=direct value=0 %s> %s\n",
62         $defroute ? "checked" : "";
63 printf "<input name=defroute size=30 value='$defroute->{'to'}'>\n";
64 print "<input type=submit value='$text{'save'}'></form>\n";
65
66 &ui_print_footer("", $text{'index_return'});
67
68 sub routes_table
69 {
70 print "<table border width=100%>\n";
71 print "<tr $tb> <td width=5><br></td> <td><b>$text{'routes_from'}</b></td> ",
72       "<td><b>$text{'routes_to'}</b></td> </tr>\n";
73 foreach $r (@_) {
74         print "<tr $cb>\n";
75         print "<td width=5>",&ui_checkbox("d", $r->{'from'}),"</td>\n";
76         print "<td valign=top><a href=\"edit_route.cgi?idx=$r->{'idx'}\">",
77               &html_escape($r->{'from'}),"</a></td>\n";
78         print "<td>",$r->{'port'} ? &html_escape("$r->{'to'}:$r->{'port'}") :
79                      $r->{'to'} ? &html_escape($r->{'to'}) :
80                           "<i>$text{'routes_direct'}</i>","</td> </tr>\n";
81         }
82 print "</table>\n";
83 }
84