Handle hostnames with upper-case letters
[webmin.git] / postfix / map_chooser.cgi
1 #!/usr/local/bin/perl
2 # Show a form for selecting the source for a map
3
4 $trust_unknown_referers = 1;
5 require './postfix-lib.pl';
6 &ReadParse();
7 &popup_header($text{'chooser_title'});
8
9 # Parse into files
10 @maps = &get_maps_types_files($in{'map'});
11 push(@maps, [ ]);
12 @sources = &list_mysql_sources();
13
14 print &ui_form_start("map_chooser_save.cgi", "post");
15 print &ui_hidden("map", $in{'map'});
16 print &ui_hidden("mapname", $in{'mapname'});
17 $i = 0;
18 foreach $tv (@maps) {
19         print &ui_hidden_table_start(&text('chooser_header', $i+1),
20                                      "width=100%", 2, "section$i",
21                                      $tv->[0] || $i == 0, [ "width=30%" ]);
22
23         # Work out type
24         $t = $tv->[0] eq "" ? "" :
25              $tv->[0] eq "hash" ? "hash" :
26              $tv->[0] eq "regexp" ? "regexp" :
27              $tv->[0] eq "pcre" && &supports_map_type("pcre") ? "pcre" :
28              $tv->[0] eq "mysql" && &supports_map_type("mysql") &&
29               $tv->[1] =~ /^[\/\.]/ ? "mysql" :
30              $tv->[0] eq "mysql" && &supports_map_type("mysql") &&
31               $tv->[1] !~ /^[\/\.]/ ? "mysqlsrc" :
32              $tv->[0] eq "ldap" && &supports_map_type("ldap") ? "ldap" :
33                                     "other";
34
35         # For MySQL, read config file and generate inputs
36         $myconf = { };
37         if ($t eq "mysql") {
38                 $myconf = &get_backend_config($tv->[1]);
39                 }
40         $mtable = &ui_table_start(undef, "width=100%", 2,
41                                   [ "nowrap", "nowrap" ]);
42         $mtable .= &ui_table_row($text{'chooser_mhosts'},
43                 &ui_opt_textbox("mhosts_$i", $myconf->{'hosts'}, 30,
44                                 "<tt>localhost</tt>"));
45         $mtable .= &ui_table_row($text{'chooser_muser'},
46                 &ui_textbox("muser_$i", $myconf->{'user'}, 30));
47         $mtable .= &ui_table_row($text{'chooser_mpassword'},
48                 &ui_textbox("mpassword_$i", $myconf->{'password'}, 30));
49         $mtable .= &ui_table_row($text{'chooser_mdbname'},
50                 &ui_textbox("mdbname_$i", $myconf->{'dbname'}, 30));
51         if ($postfix_version >= 2.2) {
52                 # Can use custom query
53                 $mtable .= &ui_table_row($text{'chooser_mquery'},
54                         &ui_opt_textbox("mquery_$i", $myconf->{'query'}, 40,
55                                         $text{'chooser_none'}));
56                 }
57         $mtable .= &ui_table_row($text{'chooser_mtable'},
58                 &ui_textbox("mtable_$i", $myconf->{'table'}, 30));
59         $mtable .= &ui_table_row($text{'chooser_mwhere_field'},
60                 &ui_textbox("mwhere_field_$i", $myconf->{'where_field'}, 30));
61         $mtable .= &ui_table_row($text{'chooser_mselect_field'},
62                 &ui_textbox("mselect_field_$i", $myconf->{'select_field'}, 30));
63         $mtable .= &ui_table_row($text{'chooser_madditional_conditions'},
64                 &ui_opt_textbox("madditional_conditions_$i",
65                         $myconf->{'additional_conditions'}, 30,
66                         $text{'chooser_none'}));
67         $mtable .= &ui_table_end();
68
69         # For LDAP, read config and generate inputs too
70         $lconf = { };
71         if ($t eq "ldap") {
72                 $lconf = &get_backend_config($tv->[1]);
73                 }
74         $ltable = &ui_table_start(undef, "width=100%", 2,
75                                   [ "nowrap", "nowrap" ]);
76         $ltable .= &ui_table_row($text{'chooser_lserver_host'},
77                 &ui_opt_textbox("lserver_host_$i", $lconf->{'server_host'}, 30,
78                                 "<tt>localhost</tt>"));
79         $ltable .= &ui_table_row($text{'chooser_lserver_port'},
80                 &ui_opt_textbox("lserver_port_$i", $lconf->{'server_port'}, 5,
81                                 "$text{'default'} (389)"));
82         $ltable .= &ui_table_row($text{'chooser_lstart_tls'},
83                 &ui_radio("lstart_tls_$i", $lconf->{'start_tls'} || 'no',
84                           [ [ 'yes', $text{'yes'} ],
85                             [ 'no', $text{'no'} ] ]));
86         $ltable .= &ui_table_row($text{'chooser_lsearch_base'},
87                 &ui_textbox("lsearch_base_$i", $lconf->{'search_base'}, 50));
88         $ltable .= &ui_table_row($text{'chooser_lquery_filter'},
89                 &ui_opt_textbox("lquery_filter_$i", $lconf->{'query_filter'},50,
90                     "$text{'default'} (<tt>mailacceptinggeneralid=%s</tt>)<br>",
91                     $text{'chooser_lfilter'}));
92         $ltable .= &ui_table_row($text{'chooser_lresult_attribute'},
93                 &ui_opt_textbox("lresult_attribute_$i",
94                                 $lconf->{'result_attribute'}, 20,
95                                 "$text{'default'} (<tt>maildrop</tt>)<br>",
96                                 $text{'chooser_lattribute'}));
97         $ltable .= &ui_table_row($text{'chooser_lscope'},
98                 &ui_select("lscope_$i", $lconf->{'scope'},
99                            [ [ "", "$text{'default'} ($text{'chooser_lsub'})" ],
100                              map { [ $_, $text{'chooser_l'.$_} ] }
101                                  ('sub', 'base', 'one') ]));
102         $ltable .= &ui_table_row($text{'chooser_lbind'},
103                 &ui_radio("lbind_$i", $lconf->{'bind'} || 'yes',
104                           [ [ 'yes', $text{'yes'} ],
105                             [ 'no', $text{'no'} ] ]));
106         $ltable .= &ui_table_row($text{'chooser_lbind_dn'},
107                 &ui_opt_textbox("lbind_dn_$i", $lconf->{'bind_dn'}, 40,
108                                 $text{'chooser_none'}));
109         $ltable .= &ui_table_row($text{'chooser_lbind_pw'},
110                 &ui_opt_textbox("lbind_pw_$i", $lconf->{'bind_pw'}, 20,
111                                 $text{'chooser_none'}));
112         $ltable .= &ui_table_end();
113
114         # Generate possible modes
115         @opts = ( );
116         push(@opts, [ "", $text{'chooser_none'} ]);
117         push(@opts, [ "hash", $text{'chooser_hash'},
118             &ui_textbox("hash_$i", $t eq "hash" ? $tv->[1] : undef, 50) ]);
119         push(@opts, [ "regexp", $text{'chooser_regexp'},
120             &ui_textbox("regexp_$i", $t eq "regexp" ? $tv->[1] : undef, 50) ]);
121         if (&supports_map_type("pcre")) {
122                 push(@opts, [ "pcre", $text{'chooser_pcre'},
123                     &ui_textbox("pcre_$i",
124                                 $t eq "pcre" ? $tv->[1] : undef, 50) ]);
125                 }
126         if (&supports_map_type("mysql")) {
127                 push(@opts, [ "mysql", $text{'chooser_mysql'}, $mtable ]);
128                 if (@sources || $t eq "mysqlsrc") {
129                         push(@opts, [ "mysqlsrc", $text{'chooser_mysqlsrc'},
130                                       &ui_select("mysqlsrc_$i",
131                                          $t eq "mysqlsrc" ? $tv->[1] : undef,
132                                          \@sources) ]);
133                         }
134                 }
135         if (&supports_map_type("ldap")) {
136                 push(@opts, [ "ldap", $text{'chooser_ldap'}, $ltable ]);
137                 }
138         push(@opts, [ "other", $text{'chooser_other'},
139             &ui_textbox("other_$i", $t eq "other" ? $tv->[1] : undef, 60) ]);
140
141         # Display mode selector
142         print &ui_table_row(undef,
143                 &ui_radio_table("type_$i", $t, \@opts), 2);
144
145         print &ui_hidden_table_end();
146         $i++;
147         }
148 print &ui_form_end([ [ undef, $text{'save'} ] ]);
149
150 &popup_footer();
151