Handle hostnames with upper-case letters
[webmin.git] / postgresql / edit_host.cgi
1 #!/usr/local/bin/perl
2 # edit_host.cgi
3 # Display a form for editing or creating an allowed host
4
5 require './postgresql-lib.pl';
6 &ReadParse();
7 $v = &get_postgresql_version();
8 if ($in{'new'}) {
9         $type = $in{'new'};
10         &ui_print_header(undef, $text{"host_create"}, "");
11         $host = { 'type' => $type, 'netmask' => '0.0.0.0',
12                   'auth' => 'trust', 'db' => 'all' };
13         }
14 else {
15         @all = &get_hba_config($v);
16         $host = $all[$in{'idx'}];
17         $type = $host->{'type'};
18         &ui_print_header(undef, $text{"host_edit"}, "");
19         }
20
21 # Start of form block
22 print &ui_form_start("save_host.cgi", "post");
23 print &ui_hidden("idx", $in{'idx'});
24 print &ui_hidden("new", $in{'new'});
25 print &ui_table_start($text{'host_header'}, "width=100%", 2);
26
27 # Allowed IP address, network or connection type
28 $mode = $type eq 'local' ? 3 :
29         $host->{'cidr'} ne '' ? 4 :
30         $host->{'netmask'} eq '0.0.0.0' ? 0 :
31         $host->{'netmask'} eq '255.255.255.255' ? 1 : 2;
32 print &ui_table_row($text{'host_address'},
33     &ui_radio_table("addr_mode", $mode,
34         [ [ 3, $text{'host_local'} ],
35           [ 0, $text{'host_any'} ],
36           [ 1, $text{'host_single'},
37             &ui_textbox("host", $mode == 1 ? $host->{'address'} : '', 20) ],
38           [ 2, $text{'host_network'},
39             &ui_textbox("network", $mode == 2 ? $host->{'address'} : '', 20).
40             " ".$text{'host_netmask'}." ".
41             &ui_textbox("netmask", $mode == 2 ? $host->{'netmask'} : '', 20) ],
42           [ 4, $text{'host_network'},
43             &ui_textbox("network2", $mode == 4 ? $host->{'address'} : '', 20).
44             " ".$text{'host_cidr'}." ".
45             &ui_textbox("cidr", $mode == 4 ? $host->{'cidr'} : '', 5) ],
46         ]));
47
48 # Force SSL connection?
49 if ($type eq "hostssl" || $v >= 7.3) {
50         print &ui_table_row($text{'host_ssl'},
51                 &ui_yesno_radio("ssl", $type eq "hostssl"));
52         }
53
54 # Allowed databases
55 local $found = !$host->{'db'} || $host->{'db'} eq 'all' ||
56                $host->{'db'} eq 'sameuser' ||
57                $host->{'db'} eq 'samegroup';
58 @dbopts = ( [ "all", "<$text{'host_all'}>" ],
59             [ "sameuser", "<$text{'host_same'}>" ] );
60 if ($v >= 7.3) {
61         push(@dbopts, [ "samegroup", "<$text{'host_gsame'}>" ]);
62         }
63 foreach $d (&list_databases()) {
64         push(@dbopts, $d);
65         $found++ if ($host->{'db'} eq $d);
66         }
67 push(@dbopts, [ '', $text{'host_other'} ]);
68 print &ui_table_row($text{'host_db'},
69         &ui_select("db", $found ? $host->{'db'} : '', \@dbopts)." ".
70         &ui_textbox("dbother",
71                     $found ? "" : join(" ", split(/,/, $host->{'db'})), 40));
72
73 # Allowed users
74 if ($v >= 7.3) {
75         print &ui_table_row($text{'host_user'},
76                 &ui_opt_textbox("user",
77                         $host->{'user'} eq 'all' ? '' :
78                           join(" ", split(/,/, $host->{'user'})),
79                         40, $text{'host_uall'}, $text{'host_usel'}));
80         }
81
82 # Authentication type
83 foreach $a ('password', 'crypt', ($v >= 7.2 ? ( 'md5' ) : ( )),
84             'trust', 'reject', 'ident', 'krb4', 'krb5',
85             ($v >= 7.3 ? ( 'pam' ) : ( )) ) {
86         $arg = $host->{'auth'} eq $a ? $host->{'arg'} : undef;
87         $extra = undef;
88         if ($a eq 'password') {
89                 # Password file
90                 $extra = &ui_checkbox("passwordarg", 1,
91                                       $text{'host_passwordarg'}, $arg)." ".
92                          &ui_textbox("password", $arg, 40);
93                 }
94         elsif ($a eq 'ident') {
95                 # Ident server
96                 $extra = &ui_checkbox("identarg", 1, $text{'host_identarg'},
97                                       $arg)." ".
98                          &ui_textbox("ident", $arg, 20);
99                 }
100         elsif ($a eq 'pam') {
101                 # PAM service
102                 $extra = &ui_checkbox("pamarg", 1, $text{'host_pamarg'},
103                                       $arg)." ".
104                          &ui_textbox("pam", $arg, 20);
105                 }
106         push(@auths, [ $a, $text{"host_$a"}, $extra ]);
107         }
108 print &ui_table_row($text{'host_auth'},
109         &ui_radio_table("auth", $host->{'auth'}, \@auths));
110
111 # End of the form
112 print &ui_table_end();
113 if ($in{'new'}) {
114         print &ui_form_end([ [ undef, $text{'create'} ] ]);
115         }
116 else {
117         print &ui_form_end([ [ undef, $text{'save'} ],
118                              [ 'delete', $text{'delete'} ] ]);
119         }
120
121 &ui_print_footer("list_hosts.cgi", $text{'host_return'});
122