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 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-php-3.0.0/root/usr/share/perl5/vendor_perl/esmith/php.pm 2021-03-07 01:04:34.688000000 -0500 @@ -0,0 +1,138 @@ +package esmith::php; + +use strict; +use warnings; +use esmith::ConfigDB; + +our @ISA = qw(Exporter); +our @EXPORT = qw( listPHPVersionFPM listPHPVersionShort listPHPVersionHash listPHPVersionHashShort); + +=head1 NAME + +esmith::php - A few tools to help with php-fpm installed versions + +=head1 SYNOPSIS + + use esmith::php; + + my @phps=listPHPVersionFPM('enabled'); + +=head1 DESCRIPTION + +This is intended to help playing with installed php versions. + +=head1 Methods + + +=head2 listPHPVersionFPM +param = (enabled, disabled, all) , if empty default to all +this will return you an array of php-fpm versions available php version +print "'$_'\n" for listPHPVersionFPM('all'); +'php-fpm' +'php55-php-fpm' +'php56-php-fpm' +'php70-php-fpm' +'php71-php-fpm' +'php72-php-fpm' +'php73-php-fpm' +'php74-php-fpm' +'php80-php-fpm' + +this will return only available and enabled +print "'$_'\n" for listPHPVersionFPM('enabled'); +=cut +sub listPHPVersionFPM { + my $status = shift || 'all'; + my $conf = esmith::ConfigDB->open_ro or die "Could not open accounts db"; + my @list = $conf->get_all_by_prop( type => 'service' ); + my @keys = map {$_->key; } @list; + my @FPM; + foreach my $service ( grep(/^(php[0-9]{2}-)?php-fpm$/,@keys) ) { + my $s = $conf->get($service); + next unless ($s) ; + next unless (-f "/usr/lib/systemd/system/$service.service") ; + next unless ( $status eq "all" || ($s->prop('status') || "disabled") eq $status ); + push @FPM, $service; + } + return @FPM +} + +=head2 listPHPVersionShort +param = (enabled, disabled, all) , if empty default to all + +this will return you an array of numerical available php version +print "'$_'\n" for listPHPVersionShort('all'); +'54' +'55' +'56' +'70' +'71' +'72' +'73' +'74' +'80' + +this will returnonly available and enabled +print "'$_'\n" for listPHPVersionShort('enabled'); +=cut +sub listPHPVersionShort { + my $status = shift || 'all'; + my @FPM = listPHPVersionFPM($status); + s/^php([0-9]{2})-php-fpm$/$1/ for @FPM ; + s/^php-fpm$/54/ for @FPM ; + return @FPM; +} + +=head2 listPHPVersionHash +param = (enabled, disabled, all) , if empty default to all + +this will return you a hash order by version +my %list= listPHPVersionHash(); +print "$_ => $list{$_}\n" for (sort keys %list); +54 => php-fpm +55 => php55-php-fpm +56 => php56-php-fpm +70 => php70-php-fpm +71 => php71-php-fpm +72 => php72-php-fpm +73 => php73-php-fpm +74 => php74-php-fpm +80 => php80-php-fpm +=cut +sub listPHPVersionHash { + my $status = shift || 'all'; + my @FPM = listPHPVersionFPM($status); + my %myfpm; + for my $php ( @FPM) { + $myfpm{"54"}="$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 + +this will return you a hash order by version +my %list= listPHPVersionHashShort(); +print "$_ => $list{$_}\n" for (sort keys %list); +54 => php +55 => php55 +56 => php56 +70 => php70 +71 => php71 +72 => php72 +73 => php73 +74 => php74 +80 => php80 +=cut +sub listPHPVersionHashShort { + my $status = shift || 'all'; + my %myfpm = listPHPVersionHash($status); + my %rfpm; + foreach my $key (keys %myfpm) { + my $php = $myfpm{$key}; + ($rfpm{$key}= $php)=~s/(php[0-9]{0,2}).*/$1/; + } + return %rfpm; +}