3 # Display a form for editing or creating an allowed host
5 require './postgresql-lib.pl';
7 $v = &get_postgresql_version();
10 &ui_print_header(undef, $text{"host_create"}, "");
11 $host = { 'type' => $type, 'netmask' => '0.0.0.0',
12 'auth' => 'trust', 'db' => 'all' };
15 @all = &get_hba_config($v);
16 $host = $all[$in{'idx'}];
17 $type = $host->{'type'};
18 &ui_print_header(undef, $text{"host_edit"}, "");
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);
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) ],
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"));
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'}>" ] );
61 push(@dbopts, [ "samegroup", "<$text{'host_gsame'}>" ]);
63 foreach $d (&list_databases()) {
65 $found++ if ($host->{'db'} eq $d);
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));
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'}));
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;
88 if ($a eq 'password') {
90 $extra = &ui_checkbox("passwordarg", 1,
91 $text{'host_passwordarg'}, $arg)." ".
92 &ui_textbox("password", $arg, 40);
94 elsif ($a eq 'ident') {
96 $extra = &ui_checkbox("identarg", 1, $text{'host_identarg'},
98 &ui_textbox("ident", $arg, 20);
100 elsif ($a eq 'pam') {
102 $extra = &ui_checkbox("pamarg", 1, $text{'host_pamarg'},
104 &ui_textbox("pam", $arg, 20);
106 push(@auths, [ $a, $text{"host_$a"}, $extra ]);
108 print &ui_table_row($text{'host_auth'},
109 &ui_radio_table("auth", $host->{'auth'}, \@auths));
112 print &ui_table_end();
114 print &ui_form_end([ [ undef, $text{'create'} ] ]);
117 print &ui_form_end([ [ undef, $text{'save'} ],
118 [ 'delete', $text{'delete'} ] ]);
121 &ui_print_footer("list_hosts.cgi", $text{'host_return'});