initial commit of file from CVS for smeserver-phpki-ng on Sat Sep 7 20:50:40 AEST 2024

This commit is contained in:
Trevor Batley
2024-09-07 20:50:40 +10:00
parent 216095c0ea
commit c46ac6300b
35 changed files with 1065 additions and 2 deletions

View File

@@ -0,0 +1,38 @@
{
# use Data::Validate::IP;
use Net::IP qw(ip_is_ipv4 ip_is_ipv6);
our $KeySize = $modSSL{KeySize} ||'4096';
our $FQDN = "$SystemName.$DomainName";
our $Country = $modSSL{Country} || "--";
our $State = $modSSL{State} || "----";
our $commonName = $modSSL{CommonName} || $FQDN;
our $crt = "/home/e-smith/ssl.crt/$FQDN.crt";
our $key = "/home/e-smith/ssl.key/$FQDN.key";
our $defaultCity = $ldap{defaultCity} || '-';
our $defaultCompany = $ldap{defaultCompany} || $commonName ;
our $defaultDepartment = $ldap{defaultDepartment} || '-';
our $email = "admin\@$DomainName";
our @subjectAlt = `/sbin/e-smith/generate-subjectaltnames`;
chomp @subjectAlt;
our $subjectAltName = "";
my $i=0;
for my $elem (@subjectAlt) {
$subjectAltName .= ", " if $i>0;
$i++;
if (ip_is_ipv4($elem) || ip_is_ipv6($elem) ){
$subjectAltName .= "IP:$elem";
next;
}
$subjectAltName .= "DNS:$elem";
}
$subjectAltName = ( $subjectAltName eq "DNS: ")? "": $subjectAltName;
# crop fields that are too long for X509:
$Country = substr($Country, 0, 2);
$defaultCity = substr($defaultCity, 0, 128);
$defaultCompany = substr($defaultCompany, 0, 64);
$defaultDepartment = substr($defaultDepartment, 0, 64);
$email = substr($email, 0, 64);
$commonName = substr($commonName, 0, 64);
$OUT="";
}

View File

@@ -0,0 +1,30 @@
{
my $phone = ${ldap}{defaultPhoneNumber} || "none";
my $zip = ${ldap}{postalCode} || "H0H 0H0";
my $street = ${ldap}{defaultStreet} || "Address Line #1";
@lines = map {
m:\$config\['common_name'\]: && s/.*/\$config['common_name']='$commonName';/;
m:\$config\['unit'\]: && s/.*/\$config['unit']='$defaultDepartment';/;
m:\$config\['keysize'\]: && s/.*/\$config['keysize']='4096';/;
m:\$config\['country'\]: && s/.*/\$config['country']='$Country';/;
m:\$config\['province'\]: && s/.*/\$config['province']='$State';/;
m:\$config\['locality'\]: && s/.*/\$config['locality']='$defaultCity';/;
m:\$config\['organization'\]: && s/.*/\$config['organization']='$defaultCompany';/;
m:\$config\['contact'\]: && s/.*/\$config['contact']='$email';/;
m:\$config\['base_url'\]: && s/.*/\$config['base_url']='https:\/\/$commonName\/phpki\/';/;
s/(^|\n)[\n\s]*/$1/g;;
$_
} @lines;
push @lines, "\$config['common_name']='$commonName';" unless grep( /\$config\['common_name'\]/ ,@lines);
push @lines, "\$config['unit']='$defaultDepartment';" unless grep( /\$config\['unit'\]/ ,@lines);
push @lines, "\$config['keysize']='4096';" unless grep( /\$config\['keysize'\]/ ,@lines);
push @lines, "\$config['country']='$Country';" unless grep( /\$config\['country'\]/ ,@lines);
push @lines, "\$config['province']='$State';" unless grep( /\$config\['province'\]/ ,@lines);
push @lines, "\$config['locality']='$defaultCity';" unless grep( /\$config\['locality'\]/ ,@lines);
push @lines, "\$config['organization']='$defaultCompany';" unless grep( /\$config\['organization'\]/ ,@lines);
push @lines, "\$config['contact']='$email';" unless grep( /\$config\['contact'\]/ ,@lines);
push @lines, "\$config['base_url']='https://$commonName/phpki/';" unless grep( /\$config\['base_url'\]/ ,@lines);
# we do not update the following as it will mess up the file.
push @lines, "\$config[\'getting_help\']=\'<b>Contact:</b><br>\nFirst-Name Last-Name<br>\n$defaultCompany/$defaultDepartment<br>\n$street<br>\n$defaultCity, $State, $zip<br>\n<br>\nPhone: $phone<br>\nE-mail: <a href=mailto:$email>$email</a>&nbsp;&nbsp;&nbsp;<i><b>E-mail is preferred.</b></i><br>\';" unless grep( /\$config\['getting_help'\]/ ,@lines);
"";
}

View File

@@ -0,0 +1,12 @@
{
$OUT .= "";
foreach my $line (@lines)
{
chomp $line;
next if grep { /^$/ } $line ;
push @lines, $_;
$OUT .= "$line\n";
}
$OUT .= "?>";
}

View File

@@ -0,0 +1,17 @@
{
# vim: ft=perl:
%lines = ();
@lines = ();
open (RD, "</opt/phpki/html/config.php")
|| warn "Cannot open input file /opt/phpki/html/config.php: $!\n";
while (<RD>)
{
chomp;
next if grep { /^$/ } $_ ;
next if grep { /^\?/ } $_;
push @lines, $_;
$lines{$_} = 1;
}
close(RD);
"";
}