Handle hostnames with upper-case letters
[webmin.git] / ldap-server / acl_form.cgi
1 #!/usr/local/bin/perl
2 # Show the details of one access control rule
3
4 require './ldap-server-lib.pl';
5 &local_ldap_server() == 1 || &error($text{'slapd_elocal'});
6 $access{'acl'} || &error($text{'acl_ecannot'});
7 &ReadParse();
8
9 # Get ACLs
10 if (&get_config_type() == 1) {
11         $conf = &get_config();
12         @access = &find("access", $conf);
13         }
14 else {
15         $defdb = &get_default_db();
16         $conf = &get_ldif_config();
17         @access = &find_ldif("olcAccess", $conf, $defdb);
18         }
19
20 # Page header
21 if ($in{'new'}) {
22         &ui_print_header(undef, $text{'eacl_title1'}, "", "eacl");
23         $p = { 'what' => '*',
24                'by' => [ ] };
25         }
26 else {
27         &ui_print_header(undef, $text{'eacl_title2'}, "", "eacl");
28         $acl = $access[$in{'idx'}];
29         $p = &parse_ldap_access($acl);
30         }
31
32 # Form header
33 print &ui_form_start("acl_save.cgi", "post");
34 print &ui_hidden("new", $in{'new'});
35 print &ui_hidden("idx", $in{'idx'});
36 print &ui_table_start($text{'eacl_header'}, undef, 2);
37
38 # Granting to what object
39 $what = $p->{'what'} eq '*' || $p->{'what'} eq '' ? 1 : 0;
40 if ($p->{'what'} =~ /^dn(\.([^=]+))?="(.*)"$/i ||
41     $p->{'what'} =~ /^dn(\.([^=]+))?=(.*)$/i) {
42         $dn = $3;
43         $style = $2;
44         if ($dn eq "") {
45                 $what = 2;
46                 }
47         }
48 print &ui_table_row($text{'eacl_what'},
49         &ui_radio_table("what", $what,
50                 [ [ 1, $text{'eacl_what1'} ],
51                   [ 2, $text{'eacl_what2'} ],
52                   [ 0, $text{'eacl_what0'},
53                     &ui_textbox("what_dn", $dn, 30)." ".
54                     $text{'eacl_mtype'}." ".
55                     &ui_select("what_style", $style,
56                                [ [ '', $text{'default'} ],
57                                  map { [ $_, $text{'eacl_'.$_} ] }
58                                      @acl_dn_styles ]) ] ])."\n".
59         &ui_checkbox("filter_on", 1, $text{'eacl_filter'}, $p->{'filter'})." ".
60         &ui_textbox("filter", $p->{'filter'}, 40)."<br>\n".
61         &ui_checkbox("attrs_on", 1, $text{'eacl_attrs'}, $p->{'attrs'})." ".
62         &ui_textbox("attrs", $p->{'attrs'}, 40) );
63
64 # Access rights table
65 @tds = ( "width=40% nowrap", "width=30%", "width=30%" );
66 $wtable = &ui_columns_start([ $text{'eacl_who'},
67                               $text{'eacl_access'},
68                               $text{'eacl_control'} ], 100, 0, \@tds);
69 $i = 0;
70 foreach $b (@{$p->{'by'}}, { }, { }, { }) {
71         $kwho = $b->{'who'} eq 'self' || $b->{'who'} eq 'users' ||
72                 $b->{'who'} eq 'anonymous' || $b->{'who'} eq '*' ||
73                 $b->{'who'} eq '';
74         $kacc = !$b->{'access'} ? 'read' :
75                 &indexof($b->{'access'}, @acl_access_levels) >= 0 ?
76                         $b->{'access'} : undef;
77         $wtable .= &ui_columns_row([
78                 # Who are we granting?
79                 &ui_select("wmode_$i",
80                            $kwho ? $b->{'who'} : 'other',
81                            [ [ '', "&nbsp;" ],
82                              [ '*', $text{'eacl_every'} ],
83                              [ 'self', $text{'eacl_self'} ],
84                              [ 'users', $text{'eacl_users'} ],
85                              [ 'anonymous', $text{'eacl_anonymous'} ],
86                              [ 'other', $text{'eacl_other'} ] ],
87                            1, 0, 0, 0,
88                            "style='width:45%' onChange='form.who_$i.disabled = (form.wmode_$i.value != \"other\")'").
89                 &ui_textbox("who_$i", $kwho ? "" : $b->{'who'}, 50,
90                             $kwho, undef, "style='width:45%'"),
91
92                 # What access level? Show textbox if complex
93                 $kacc ? &ui_select("access_$i", $kacc,
94                                    [ map { [ $_, $text{'access_l'.$_} ] }
95                                          @acl_access_levels ], 1, 0, 0, 0,
96                                    "style='width:90%'")
97                       : &ui_textbox("access_$i", $b->{'access'}, 20,
98                                     0, undef, "style='width:90%'"),
99
100                 # Additional attrs
101                 &ui_textbox("control_$i", join(" ", @{$b->{'control'}}), 30,
102                             0, undef, "style='width:90%'"),
103                 ], \@tds);
104         $i++;
105         }
106 $wtable .= &ui_columns_end();
107 print &ui_table_row(undef, $wtable, 2);
108
109 # Form and page end
110 print &ui_table_end();
111 if ($in{'new'}) {
112         print &ui_form_end([ [ undef, $text{'create'} ] ]);
113         }
114 else {
115         print &ui_form_end([ [ undef, $text{'save'} ],
116                              [ 'delete', $text{'delete'} ] ]);
117         }
118 &ui_print_footer("edit_acl.cgi", $text{'acl_return'});
119