Handle hostnames with upper-case letters
[webmin.git] / apache / mod_ssl.pl
1 # mod_ssl.pl
2 # Defines editors for mod_ssl directives
3
4 sub mod_ssl_directives
5 {
6 local($rv);
7 $rv = [ [ 'SSLEngine', 0, 14, 'virtual', undef, 10 ],
8         [ 'SSLProtocol', 0, 14, 'virtual', undef, 10 ],
9         [ 'SSLCertificateFile', 0, 14, 'virtual', undef, 9 ],
10         [ 'SSLCertificateKeyFile', 0, 14, 'virtual', undef, 8 ],
11         [ 'SSLCACertificateFile', 0, 14, 'virtual', undef, 7.7 ],
12         [ 'SSLPassPhraseDialog', 1, 14, 'global', 2.0, 7.5 ],
13         [ 'SSLVerifyClient', 0, 14, 'virtual directory htaccess', undef, 7 ],
14         [ 'SSLVerifyDepth', 0, 14, 'virtual directory htaccess', undef, 6 ],
15         [ 'SSLLog', 0, 14, 'virtual', undef, 5 ],
16         [ 'SSLRequireSSL', 0, 14, 'directory htaccess', undef, 4 ],
17       ];
18 return &make_directives($rv, $_[0], "mod_ssl");
19 }
20
21 sub edit_SSLEngine
22 {
23 return (1, $text{'mod_ssl_enable'},
24         &choice_input($_[0]->{'value'}, "SSLEngine", "",
25               "$text{'yes'},on", "$text{'no'},off", "$text{'default'},"));
26 }
27 sub save_SSLEngine
28 {
29 if ($in{'SSLEngine'} eq 'on' &&
30     $in{'SSLCertificateFile_def'}) {
31         # SSL enabled but no cert .. fail
32         &error($text{'mod_ssl_ecerton'});
33         }
34 return &parse_choice("SSLEngine");
35 }
36
37 @sslprotos = ("SSLv2", "SSLv3", "TLSv1");
38 sub edit_SSLProtocol
39 {
40 local ($rv, $p, %prot);
41 local @list = $_[0] ? @{$_[0]->{'words'}} : ("all");
42 foreach $p (@list) {
43         if ($p =~ /^\+?all$/i) { map { $prot{lc($_)} = 1 } @sslprotos; }
44         elsif ($p =~ /^\-all$/i) { undef(%prot); }
45         elsif ($p =~ /^\-(\S+)/) { $prot{lc($1)} = 0; }
46         elsif ($p =~ /^\+(\S+)/) { $prot{lc($1)} = 1; }
47         }
48 foreach $p (@sslprotos) {
49         $rv .= sprintf "<input type=checkbox name=SSLProtocol value=$p %s> $p ",
50                 $prot{lc($p)} ? "checked" : "";
51         }
52 return (1, $text{'mod_ssl_proto'}, $rv);
53 }
54 sub save_SSLProtocol
55 {
56 local @sel = split(/\0/, $in{'SSLProtocol'});
57 if (scalar(@sel) == scalar(@sslprotos)) { return ( [ ] ); }
58 return ( [ join(" ", (map { "+$_" } @sel)) ] );
59 }
60
61 sub edit_SSLCertificateFile
62 {
63 return (2, $text{'mod_ssl_cfile'},
64         &opt_input($_[0]->{'value'}, "SSLCertificateFile", $text{'mod_ssl_default'}, 35).
65         &file_chooser_button("SSLCertificateFile", 0));
66 }
67 sub save_SSLCertificateFile
68 {
69 return &parse_opt("SSLCertificateFile", '\S', $text{'mod_ssl_ecfile'});
70 }
71
72 sub edit_SSLCertificateKeyFile
73 {
74 return (2, $text{'mod_ssl_kfile'},
75         &opt_input($_[0]->{'value'}, "SSLCertificateKeyFile", $text{'mod_ssl_default'}, 35).
76         &file_chooser_button("SSLCertificateKeyFile", 0));
77 }
78 sub save_SSLCertificateKeyFile
79 {
80 return &parse_opt("SSLCertificateKeyFile", '\S', $text{'mod_ssl_ekfile'});
81 }
82
83 sub edit_SSLCACertificateFile
84 {
85 return (2, $text{'mod_ssl_cafile'},
86         &opt_input($_[0]->{'value'}, "SSLCACertificateFile", $text{'mod_ssl_default'}, 35).
87         &file_chooser_button("SSLCACertificateFile", 0));
88 }
89 sub save_SSLCACertificateFile
90 {
91 return &parse_opt("SSLCACertificateFile", '\S', $text{'mod_ssl_ecafile'});
92 }
93
94
95
96 sub edit_SSLVerifyClient
97 {
98 return (1, $text{'mod_ssl_clcert'},
99         &select_input($_[0]->{'value'}, "SSLVerifyClient", "",
100                       "$text{'default'},", "$text{'mod_ssl_nreq'},none",
101                       "$text{'mod_ssl_opt'},optional",
102                       "$text{'mod_ssl_req'},require",
103                       "$text{'mod_ssl_optca'},optional_no_ca"));
104 }
105 sub save_SSLVerifyClient
106 {
107 return &parse_select("SSLVerifyClient");
108 }
109
110 sub edit_SSLVerifyDepth
111 {
112 return (1, $text{'mod_ssl_cdepth'},
113         &opt_input($_[0]->{'value'}, "SSLVerifyDepth", $text{'mod_ssl_default'}, 6));
114 }
115 sub save_SSLVerifyDepth
116 {
117 return &parse_opt("SSLVerifyDepth", '^\d+$', $text{'mod_ssl_ecdepth'});
118 }
119
120 sub edit_SSLLog
121 {
122 return (1, $text{'mod_ssl_log'},
123         &opt_input($_[0]->{'value'}, "SSLLog", $text{'mod_ssl_default'}, 20));
124 }
125 sub save_SSLLog
126 {
127 return &parse_opt("SSLLog", '\S', $text{'mod_ssl_elog'});
128 }
129
130 sub edit_SSLRequireSSL
131 {
132 return (1, $text{'mod_ssl_onlyssl'},
133         &choice_input($_[0] ? 1 : 0, "SSLRequireSSL", 0, "$text{'yes'},1", "$text{'no'},0"));
134 }
135 sub save_SSLRequireSSL
136 {
137 return $in{'SSLRequireSSL'} ? ( [ "" ] ) : ( [ ] );
138 }
139
140 sub edit_SSLPassPhraseDialog
141 {
142 local $table = &ui_columns_start();
143 local $i = 0;
144 foreach my $p (@{$_[0]}, { }) {
145         local ($mode, $script, $pass, $file);
146         if ($p->{'value'} eq 'builtin') {
147                 $mode = 1;
148                 }
149         elsif ($p->{'value'} =~ /^exec:(.*)$/) {
150                 $file = $1;
151                 local $data = &read_file_contents($1);
152                 if ($data =~ /^#!\/bin\/sh\necho\s(.*)\n$/) {
153                         $pass = $1;
154                         $mode = 2;
155                         }
156                 else {
157                         $script = $file;
158                         $file = undef;
159                         $mode = 3;
160                         }
161                 }
162         elsif ($p->{'value'}) {
163                 $script = $p->{'value'};
164                 $mode = 1;
165                 }
166         else {
167                 $mode = 0;
168                 }
169         $table .= &ui_columns_row([
170                 &ui_radio("SSLPassPhraseDialog_$i", $mode,
171                         [ [ 0, $text{'mod_ssl_passnone'}."<br>" ],
172                           [ 1, $text{'mod_ssl_builtin'}."<br>" ],
173                           [ 2, &text('mod_ssl_passph',
174                              &ui_textbox("SSLPassPhraseDialog_pass_$i",
175                                          $pass, 20))."<br>" ],
176                           [ 3, &text('mod_ssl_passsc', 
177                              &ui_textbox("SSLPassPhraseDialog_script_$i",
178                                          $script, 40)) ],
179                         ])."\n".
180                 &ui_hidden("SSLPassPhraseDialog_file_$i", $file)
181                 ]);
182         $i++;
183         }
184 $table .= &ui_columns_end();
185 return (2, $text{'mod_ssl_pass'}, $table);
186 }
187 sub save_SSLPassPhraseDialog
188 {
189 local @rv;
190 local $mode;
191 for(my $i=0; defined($in{"SSLPassPhraseDialog_$i"}); $i++) {
192         if ($in{"SSLPassPhraseDialog_$i"} == 0) {
193                 # Nothing to add
194                 }
195         elsif ($in{"SSLPassPhraseDialog_$i"} == 1) {
196                 push(@rv, "builtin");
197                 }
198         elsif ($in{"SSLPassPhraseDialog_$i"} == 2) {
199                 $in{"SSLPassPhraseDialog_pass_$i"} =~ /\S/ ||
200                         &error($text{'mod_ssl_epassph'});
201                 local $file = $in{"SSLPassPhraseDialog_file_$i"} ||
202                         "$config{'httpd_dir'}/passphrase.".time().".sh";
203                 &open_tempfile(PASS, ">$file");
204                 &print_tempfile(PASS, "#!/bin/sh\n");
205                 &print_tempfile(PASS, "echo ",
206                         $in{"SSLPassPhraseDialog_pass_$i"},"\n");
207                 &close_tempfile(PASS);
208                 &set_ownership_permissions(undef, undef, 0755, $file);
209                 push(@rv, "exec:$file");
210                 }
211         elsif ($in{"SSLPassPhraseDialog_$i"} == 3) {
212                 if ($in{"SSLPassPhraseDialog_script_$i"} =~ /^[a-z]+:/) {
213                         push(@rv, $in{"SSLPassPhraseDialog_script_$i"});
214                         }
215                 else {
216                         $in{"SSLPassPhraseDialog_script_$i"} =~ /^\/\S/ ||
217                                 &error($text{'mod_ssl_epasssc'});
218                         push(@rv, "exec:".$in{"SSLPassPhraseDialog_script_$i"});
219                         }
220                 }
221         }
222 return ( \@rv );
223 }
224