Handle hostnames with upper-case letters
[webmin.git] / pam / edit_mod.cgi
1 #!/usr/local/bin/perl
2 # edit_mod.cgi
3 # Edit one PAM authentication module for some service
4
5 require './pam-lib.pl';
6 &ReadParse();
7 if ($in{'inc'}) {
8         # Redirect to include form
9         &redirect("edit_inc.cgi?idx=$in{'idx'}&type=$in{'type'}");
10         return;
11         }
12
13 @pam = &get_pam_config();
14 $pam = $pam[$in{'idx'}];
15 if ($in{'midx'} ne '') {
16         $mod = $pam->{'mods'}->[$in{'midx'}];
17         $module = $mod->{'module'};
18         $module =~ s/^.*\///;
19         $type = $mod->{'type'};
20         &ui_print_header(undef, $text{'mod_edit'}, "");
21         }
22 else {
23         $module = $in{'module'};
24         $type = $in{'type'};
25         &ui_print_header(undef, $text{'mod_create'}, "");
26         }
27
28
29 print &ui_form_start("save_mod.cgi");
30 print &ui_hidden("idx", $in{'idx'});
31 print &ui_hidden("midx", $in{'midx'});
32 print &ui_hidden("_module", $in{'module'});
33 print &ui_hidden("_type", $in{'type'});
34 print &ui_table_start($text{'mod_header'}, "width=100%", 2);
35
36 # PAM service name
37 $t = $text{'desc_'.$pam->{'name'}};
38 print &ui_table_row($text{'mod_name'},
39                     "<tt>".&html_escape($pam->{'name'})."</tt> ".
40                     ($pam->{'desc'} ? "($pam->{'desc'})" : $t ? "($t)" : ""));
41
42 # PAM module name
43 $t = $text{$module};
44 print &ui_table_row($text{'mod_mod'},
45                     "<tt>$module</tt> ".($t ? "($t)" : ""));
46
47 print &ui_table_row($text{'mod_type'},
48                     $text{'mod_type_'.$type});
49
50 # Control mode
51 print &ui_table_row($text{'mod_control'},
52             &ui_select("control", $mod->{'control'},
53                 [ map { [ $_, $text{'control_'.$_}." (".
54                               $text{'control_desc_'.$_}.")" ] }
55                       ('required', 'requisite', 'sufficient', 'optional') ],
56                 1, 0, $in{'midx'} eq '' ? 0 : 1));
57
58 if (-r "./$module.pl") {
59         do "./$module.pl";
60         if (!$module_has_no_args) {
61                 print &ui_table_hr();
62                 foreach $a (split(/\s+/, $mod->{'args'})) {
63                         if ($a =~ /^([^\s=]+)=(\S*)$/) {
64                                 $args{$1} = $2;
65                                 }
66                         else {
67                                 $args{$a} = "";
68                                 }
69                         }
70                 &display_module_args($pam, $mod, \%args);
71                 }
72         }
73 else {
74         # Text-only args
75         print &ui_table_hr();
76         print &ui_table_row($text{'mod_args'},
77                             &ui_textbox("args", $mod->{'args'}, 60), 3);
78         }
79
80 print &ui_table_end();
81
82 if ($in{'midx'} ne '') {
83         print &ui_form_end([ [ undef, $text{'save'} ],
84                              [ 'delete', $text{'delete'} ] ]);
85         }
86 else {
87         print &ui_form_end([ [ undef, $text{'create'} ] ]);
88         }
89
90 &ui_print_footer("edit_pam.cgi?idx=$in{'idx'}", $text{'edit_return'},
91                  "", $text{'index_return'});
92