1 |
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 |
2 |
--- smeserver-php-3.0.0.old/root/usr/share/perl5/vendor_perl/esmith/php.pm 1969-12-31 19:00:00.000000000 -0500 |
3 |
+++ smeserver-php-3.0.0/root/usr/share/perl5/vendor_perl/esmith/php.pm 2021-03-07 01:04:34.688000000 -0500 |
4 |
@@ -0,0 +1,138 @@ |
5 |
+package esmith::php; |
6 |
+ |
7 |
+use strict; |
8 |
+use warnings; |
9 |
+use esmith::ConfigDB; |
10 |
+ |
11 |
+our @ISA = qw(Exporter); |
12 |
+our @EXPORT = qw( listPHPVersionFPM listPHPVersionShort listPHPVersionHash listPHPVersionHashShort); |
13 |
+ |
14 |
+=head1 NAME |
15 |
+ |
16 |
+esmith::php - A few tools to help with php-fpm installed versions |
17 |
+ |
18 |
+=head1 SYNOPSIS |
19 |
+ |
20 |
+ use esmith::php; |
21 |
+ |
22 |
+ my @phps=listPHPVersionFPM('enabled'); |
23 |
+ |
24 |
+=head1 DESCRIPTION |
25 |
+ |
26 |
+This is intended to help playing with installed php versions. |
27 |
+ |
28 |
+=head1 Methods |
29 |
+ |
30 |
+ |
31 |
+=head2 listPHPVersionFPM |
32 |
+param = (enabled, disabled, all) , if empty default to all |
33 |
+this will return you an array of php-fpm versions available php version |
34 |
+print "'$_'\n" for listPHPVersionFPM('all'); |
35 |
+'php-fpm' |
36 |
+'php55-php-fpm' |
37 |
+'php56-php-fpm' |
38 |
+'php70-php-fpm' |
39 |
+'php71-php-fpm' |
40 |
+'php72-php-fpm' |
41 |
+'php73-php-fpm' |
42 |
+'php74-php-fpm' |
43 |
+'php80-php-fpm' |
44 |
+ |
45 |
+this will return only available and enabled |
46 |
+print "'$_'\n" for listPHPVersionFPM('enabled'); |
47 |
+=cut |
48 |
+sub listPHPVersionFPM { |
49 |
+ my $status = shift || 'all'; |
50 |
+ my $conf = esmith::ConfigDB->open_ro or die "Could not open accounts db"; |
51 |
+ my @list = $conf->get_all_by_prop( type => 'service' ); |
52 |
+ my @keys = map {$_->key; } @list; |
53 |
+ my @FPM; |
54 |
+ foreach my $service ( grep(/^(php[0-9]{2}-)?php-fpm$/,@keys) ) { |
55 |
+ my $s = $conf->get($service); |
56 |
+ next unless ($s) ; |
57 |
+ next unless (-f "/usr/lib/systemd/system/$service.service") ; |
58 |
+ next unless ( $status eq "all" || ($s->prop('status') || "disabled") eq $status ); |
59 |
+ push @FPM, $service; |
60 |
+ } |
61 |
+ return @FPM |
62 |
+} |
63 |
+ |
64 |
+=head2 listPHPVersionShort |
65 |
+param = (enabled, disabled, all) , if empty default to all |
66 |
+ |
67 |
+this will return you an array of numerical available php version |
68 |
+print "'$_'\n" for listPHPVersionShort('all'); |
69 |
+'54' |
70 |
+'55' |
71 |
+'56' |
72 |
+'70' |
73 |
+'71' |
74 |
+'72' |
75 |
+'73' |
76 |
+'74' |
77 |
+'80' |
78 |
+ |
79 |
+this will returnonly available and enabled |
80 |
+print "'$_'\n" for listPHPVersionShort('enabled'); |
81 |
+=cut |
82 |
+sub listPHPVersionShort { |
83 |
+ my $status = shift || 'all'; |
84 |
+ my @FPM = listPHPVersionFPM($status); |
85 |
+ s/^php([0-9]{2})-php-fpm$/$1/ for @FPM ; |
86 |
+ s/^php-fpm$/54/ for @FPM ; |
87 |
+ return @FPM; |
88 |
+} |
89 |
+ |
90 |
+=head2 listPHPVersionHash |
91 |
+param = (enabled, disabled, all) , if empty default to all |
92 |
+ |
93 |
+this will return you a hash order by version |
94 |
+my %list= listPHPVersionHash(); |
95 |
+print "$_ => $list{$_}\n" for (sort keys %list); |
96 |
+54 => php-fpm |
97 |
+55 => php55-php-fpm |
98 |
+56 => php56-php-fpm |
99 |
+70 => php70-php-fpm |
100 |
+71 => php71-php-fpm |
101 |
+72 => php72-php-fpm |
102 |
+73 => php73-php-fpm |
103 |
+74 => php74-php-fpm |
104 |
+80 => php80-php-fpm |
105 |
+=cut |
106 |
+sub listPHPVersionHash { |
107 |
+ my $status = shift || 'all'; |
108 |
+ my @FPM = listPHPVersionFPM($status); |
109 |
+ my %myfpm; |
110 |
+ for my $php ( @FPM) { |
111 |
+ $myfpm{"54"}="$php" for ( $php=~/^php-fpm$/); |
112 |
+ $myfpm{$_}="$php" for ( $php=~/^php([0-9]{2})-php-fpm$/); |
113 |
+ } |
114 |
+ return %myfpm; |
115 |
+} |
116 |
+ |
117 |
+=head2 listPHPVersionHashShort |
118 |
+param = (enabled, disabled, all) , if empty default to all |
119 |
+ |
120 |
+this will return you a hash order by version |
121 |
+my %list= listPHPVersionHashShort(); |
122 |
+print "$_ => $list{$_}\n" for (sort keys %list); |
123 |
+54 => php |
124 |
+55 => php55 |
125 |
+56 => php56 |
126 |
+70 => php70 |
127 |
+71 => php71 |
128 |
+72 => php72 |
129 |
+73 => php73 |
130 |
+74 => php74 |
131 |
+80 => php80 |
132 |
+=cut |
133 |
+sub listPHPVersionHashShort { |
134 |
+ my $status = shift || 'all'; |
135 |
+ my %myfpm = listPHPVersionHash($status); |
136 |
+ my %rfpm; |
137 |
+ foreach my $key (keys %myfpm) { |
138 |
+ my $php = $myfpm{$key}; |
139 |
+ ($rfpm{$key}= $php)=~s/(php[0-9]{0,2}).*/$1/; |
140 |
+ } |
141 |
+ return %rfpm; |
142 |
+} |