diff -Nur --no-dereference smeserver-php-3.0.0.old/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/20LoadModule80PHP smeserver-php-3.0.0/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/20LoadModule80PHP --- smeserver-php-3.0.0.old/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/20LoadModule80PHP 2021-03-07 15:11:54.624000000 -0500 +++ smeserver-php-3.0.0/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/20LoadModule80PHP 2021-03-08 01:04:26.910000000 -0500 @@ -3,8 +3,8 @@ # default we return with nothing activated return "#PHP mod is disabled by default, please use PHP-fpm" unless (exists $php{status} and $php{status} eq "enabled" and $phpModule eq "enabled"); - $PHPVersion = $php{'PHPVersion'} ||'73'; - ($PHPVersion) = $PHPVersion =~ /([0-9]{2})/; + use esmith::php; + our $PHPVersion = PHPdefault(1); my $phpMR = substr($PHPVersion,0,1) || ''; #php7 software collection libphp72.so return "LoadModule php$\{phpMR\}_module modules/libphp$PHPVersion.so\n" if (-r "/usr/lib64/httpd/modules/libphp$PHPVersion.so"); diff -Nur --no-dereference smeserver-php-3.0.0.old/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/20LoadModule81FastCGI smeserver-php-3.0.0/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/20LoadModule81FastCGI --- smeserver-php-3.0.0.old/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/20LoadModule81FastCGI 2020-01-28 13:50:45.000000000 -0500 +++ smeserver-php-3.0.0/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/20LoadModule81FastCGI 2021-03-08 01:04:07.503000000 -0500 @@ -1,6 +1,4 @@ { -$PHPVersion = $php{'PHPVersion'} ||'73'; -my ($PHPVersion) = $PHPVersion =~ /([0-9]{2})/; $fastcgi_mod = 'mod_proxy_fcgi'; $OUT .=<<_EOF; LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so diff -Nur --no-dereference smeserver-php-3.0.0.old/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/95AddType00PHP2ibays smeserver-php-3.0.0/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/95AddType00PHP2ibays --- smeserver-php-3.0.0.old/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/95AddType00PHP2ibays 2021-03-07 15:11:54.710000000 -0500 +++ smeserver-php-3.0.0/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/95AddType00PHP2ibays 2021-03-08 01:04:47.612000000 -0500 @@ -14,8 +14,7 @@ # configuration to enable php-fpm for the ibay if ($fastcgi_mod eq 'mod_proxy_fcgi') { - my $version = $ibay->prop('PHPVersion') || $PHPVersion || '73'; - ($version) = $version =~ /([0-9]{2})/ unless $version eq ''; + my $version = PhpFpmVersionToUse($ibay); my $name = lc $key; $OUT .=<<"_EOF"; SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=\$1 diff -Nur --no-dereference smeserver-php-3.0.0.old/root/etc/e-smith/templates/etc/php-fpm.d/ibays.conf/10Ibays smeserver-php-3.0.0/root/etc/e-smith/templates/etc/php-fpm.d/ibays.conf/10Ibays --- smeserver-php-3.0.0.old/root/etc/e-smith/templates/etc/php-fpm.d/ibays.conf/10Ibays 2021-03-07 15:11:54.736000000 -0500 +++ smeserver-php-3.0.0/root/etc/e-smith/templates/etc/php-fpm.d/ibays.conf/10Ibays 2021-03-08 01:06:11.720000000 -0500 @@ -1,12 +1,11 @@ { use esmith::AccountsDB; +use esmith::php; my $a = esmith::AccountsDB->open_ro || die "Couldn't open the accounts database"; foreach my $ibay ($a->get_all_by_prop(type => 'ibay')){ - my $PHPVersion = $php{'PHPVersion'} ||'73'; - ($PHPVersion) = $PHPVersion =~ /([0-9]{2})/; - my $version = $ibay->prop('PHPVersion') || $PHPVersion || '73'; + my $version = PhpFpmVersionToUse($ibay); my $dynamic = $ibay->prop('CgiBin') || 'disabled'; my $custom = $ibay->prop('PHPCustomPool') || undef; next unless ($dynamic eq 'enabled' && $version eq $PHP_VERSION && !$custom); diff -Nur --no-dereference smeserver-php-3.0.0.old/root/usr/share/perl5/vendor_perl/esmith/php.pm smeserver-php-3.0.0/root/usr/share/perl5/vendor_perl/esmith/php.pm --- smeserver-php-3.0.0.old/root/usr/share/perl5/vendor_perl/esmith/php.pm 2021-03-07 15:11:54.741000000 -0500 +++ smeserver-php-3.0.0/root/usr/share/perl5/vendor_perl/esmith/php.pm 2021-03-08 01:26:46.184000000 -0500 @@ -4,8 +4,11 @@ use warnings; use esmith::ConfigDB; +our $PHPDEFAULT = 74; +our $BASEPHP = 54; + our @ISA = qw(Exporter); -our @EXPORT = qw( listPHPVersionFPM listPHPVersionShort listPHPVersionHash listPHPVersionHashShort); +our @EXPORT = qw( listPHPVersionFPM listPHPVersionShort listPHPVersionHash listPHPVersionHashShort PHPdefault VersionToUse PhpFpmVersionToUse); =head1 NAME @@ -58,7 +61,8 @@ } =head2 listPHPVersionShort -param = (enabled, disabled, all) , if empty default to all +param1 = (enabled, disabled, all) , if empty default to all +param2 = will use "" as output for base php this will return you an array of numerical available php version print "'$_'\n" for listPHPVersionShort('all'); @@ -77,15 +81,17 @@ =cut sub listPHPVersionShort { my $status = shift || 'all'; + my $emptyforbase = shift; my @FPM = listPHPVersionFPM($status); s/^php([0-9]{2})-php-fpm$/$1/ for @FPM ; - s/^php-fpm$/54/ for @FPM ; + my $base= (defined $emptyforbase) ? "" : $BASEPHP; + s/^php-fpm$/$base/ for @FPM ; return @FPM; } =head2 listPHPVersionHash -param = (enabled, disabled, all) , if empty default to all - +param1 = (enabled, disabled, all) , if empty default to all +param2 = if defined will use "" as key for php-fpm this will return you a hash order by version my %list= listPHPVersionHash(); print "$_ => $list{$_}\n" for (sort keys %list); @@ -101,17 +107,20 @@ =cut sub listPHPVersionHash { my $status = shift || 'all'; + my $emptyforbase = shift; my @FPM = listPHPVersionFPM($status); my %myfpm; + my $base= (defined $emptyforbase) ? "" : $BASEPHP; for my $php ( @FPM) { - $myfpm{"54"}="$php" for ( $php=~/^php-fpm$/); + $myfpm{$base}="$php" for ( $php=~/^php-fpm$/); $myfpm{$_}="$php" for ( $php=~/^php([0-9]{2})-php-fpm$/); } return %myfpm; } =head2 listPHPVersionHashShort -param = (enabled, disabled, all) , if empty default to all +param1 = (enabled, disabled, all) , if empty default to all +param2 = if defined will use "" as key for php-fpm this will return you a hash order by version my %list= listPHPVersionHashShort(); @@ -128,11 +137,94 @@ =cut sub listPHPVersionHashShort { my $status = shift || 'all'; - my %myfpm = listPHPVersionHash($status); + my $emptyforbase = shift; + my %myfpm = listPHPVersionHash($status, $emptyforbase); my %rfpm; foreach my $key (keys %myfpm) { my $php = $myfpm{$key}; - ($rfpm{$key}= $php)=~s/(php[0-9]{0,2}).*/$1/; + ($rfpm{$key}= $php)=~s/(^php[0-9]{0,2}).*/$1/; } return %rfpm; } + +=head2 PHPdefault + return the php default version for the system, i.e. default chosen by rpm or the one overrided by the admin in php PHPVersion property. + one optional argument is to display 54 as empty string (i.e. base php-fpm) + +=cut +sub PHPdefault { + my $emptyforbase = shift; + my $conf = esmith::ConfigDB->open_ro or die "Could not open accounts db"; + my $php = $conf->get('php') ; + my $PHPVersion = ( defined $php->prop('PHPVersion') ) ? $php->prop('PHPVersion') : $PHPDEFAULT; + $PHPVersion = ($PHPVersion eq "") ? $BASEPHP : $PHPVersion; + $PHPVersion = ($PHPVersion =~ /([0-9]{2})/) ? $1 : $PHPDEFAULT; + return $PHPVersion unless defined $emptyforbase; + $PHPVersion = ( $PHPVersion eq $BASEPHP ) ? "" : $PHPVersion; + return $PHPVersion; +} + +=head2 VersionToUse +argument 1 : output from $account->get('ibayname') or similar (shares,custom) + it is expected to find in this entry a property PHPVersion +artgument 2 : optional, a locally forced PHP version, if you do not want to trust globally prefered one. + +output : a two digit php version : 74 for php 7.4 . 54 will be for php-fpm 5.4 as default php on CentOS 7 /SME 9 + + my $ibay=$account->get('ibayname'); + my $version = VersionToUse($ibay,'80'); + +logic: +# if not defined => $PHPDEFAULT +# if defined and empty strin => $BASEPHP +# if defined and not empty => its value + +# defined entry (e.g. ibay) PHPVersion property override + - defined forced PHPVersion provided (2nd argument, if provided) which override + - php PHPVersion property which override + - default $PHPDEFAULT + +=cut +sub VersionToUse { + my $entry = shift or return "need a db entry"; + my $conf = esmith::ConfigDB->open_ro or die "Could not open accounts db"; + + my $PHPVersion = PHPdefault(); + + my $forcedefault = shift ; + $forcedefault = ( defined $forcedefault ) ? $forcedefault : $PHPVersion; + $forcedefault = ($forcedefault eq "") ? $BASEPHP : $forcedefault; + $forcedefault = ($forcedefault =~ /([0-9]{2})/) ? $1 : $PHPVersion; + + my $entryPHPVersion = (defined $entry->prop('PHPVersion') ) ? $entry->prop('PHPVersion') : $forcedefault; + $entryPHPVersion = ($entryPHPVersion eq "") ? $BASEPHP : $entryPHPVersion; + $entryPHPVersion = ($entryPHPVersion =~ /([0-9]{2})/) ? $1 : $forcedefault; + + # we currently assume that it is installed and enabled, but could test it here + + my $version= $entryPHPVersion ; + #$version = " $PHPDEFAULT - $PHPVersion - $forcedefault - $entryPHPVersion"; + + return $version; +} + +=head2 PhpFpmVersionToUse +same as VersionToUse except it will return null string in place of $BASEPHP (i.e. "" in place of 54) + +argument 1 : output from $account->get('ibayname') or similar (shares,custom) + it is expected to find in this entry a property PHPVersion +artgument 2 : optional, a locally forced PHP version, if you do not want to trust globally prefered one. + +output : a two digit php version : 74 for php 7.4 or empty string, as '' will take place of 54 for php-fpm 5.4 as default php on CentOS 7 /SME 9 + +=cut +sub PhpFpmVersionToUse { + #my $entry = shift or return "need a db entry"; + #my $forcedefault = shift ; + my $version ; + $version = VersionToUse(@_) ;#$entry,$forcedefault);# if defined $forcedefault; + #$version = VersionToUse($entry) unless defined $forcedefault; + # here we convert $BASEPHP to empty string + $version = ( $version eq $BASEPHP ) ? "" : $version; + return $version; +}