Handle hostnames with upper-case letters
[webmin.git] / acl / cert_issue.cgi
1 #!/usr/local/bin/perl
2 # cert_issue.cgi
3
4 require './acl-lib.pl';
5 &ReadParse();
6
7 &error_setup($text{'cert_err'});
8 $in{'key'} || &error($text{'cert_ekey'});
9 &get_miniserv_config(\%miniserv);
10
11 # Create the new key
12 $temp1 = &transname();
13 $temp2 = &tempname();
14 open(IN, ">$temp1");
15 foreach $k ("emailAddress", "organizationalUnitName", "organizationName",
16             "stateOrProvinceName", "countryName", "commonName") {
17         print IN "$k = $in{$k}\n";
18         }
19 $in{'key'} =~ s/\s//g;
20 print IN "SPKAC = $in{'key'}\n";
21 close(IN);
22 $cmd = &get_ssleay();
23 $ssleay = &backquote_logged("$cmd ca -spkac $temp1 -out $temp2 -config $module_config_directory/openssl.cnf -days 1095 2>&1");
24 unlink($temp1);
25 if ($?) {
26         &error("<pre>$ssleay</pre>");
27         }
28 else {
29         # Display status and redirect to actual cert file
30         $| = 1;
31         &ui_print_header(undef, $text{'cert_title'}, "");
32         print "<p>",&text('cert_done', $in{'commonName'}),"<p>\n";
33         print "<font size=+1>",&text('cert_pickup', "cert_output.cgi?file=$temp2"),"</font><p>\n";
34         &ui_print_footer("", $text{'index_return'});
35
36         # Update the miniserv users file
37         &lock_file($miniserv{'userfile'});
38         $lref = &read_file_lines($miniserv{'userfile'});
39         foreach $l (@$lref) {
40                 @u = split(/:/, $l);
41                 if ($u[0] eq $base_remote_user) {
42                         $l = "$u[0]:$u[1]:$u[2]:/C=$in{'countryName'}/ST=$in{'stateOrProvinceName'}/O=$in{'organizationName'}/OU=$in{'organizationalUnitName'}/CN=$in{'commonName'}/Email=$in{'emailAddress'}";
43                         }
44                 }
45         &flush_file_lines();
46         &unlock_file($miniserv{'userfile'});
47
48         sleep(1);
49         &restart_miniserv();
50         &webmin_log("cert", undef, $base_remote_user, \%in);
51         }
52