-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp_install.cgi
190 lines (154 loc) · 3.94 KB
/
php_install.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/perl
require './oci-lib.pl';
require '../webmin/webmin-lib.pl'; #for OS detection
foreign_require('software', 'software-lib.pl');
sub get_packages_yum{
my $cmd_out='';
my $cmd_err='';
local $out = &execute_command("yum search php", undef, \$cmd_out, \$cmd_err, 0, 0);
if($out != 0){
&error("Error: yum: $cmd_err");
return 1;
}
my %pkgs;
my @lines = split /\n/, $cmd_out;
foreach my $line (@lines){
if($line =~ /^(php[a-z0-9_\.-]+)\.(noarch|x86_64)+ : (.*)/i){
$pkgs{$1} = $3;
}
}
return %pkgs;
}
sub get_installed_yum{
my $href = $_[0];
my $pkg_list = "";
foreach my $pkg (keys %$href){
$pkg_list .= " $pkg";
}
my $cmd_out='';
my $cmd_err='';
local $out = &execute_command("rpm -q --queryformat \"%{NAME}\n\" $pkg_list", undef, \$cmd_out, \$cmd_err, 0, 0);
my %pkgs;
my @lines = split /\n/, $cmd_out;
foreach my $line (@lines){
if($line =~ /^package\s+([a-z0-9_\.-]+)\s/i){ #package php is not installed
$pkgs{$1} = 0;
}else{
$pkgs{$line} = 1;
}
}
return %pkgs;
};
sub get_packages_apt{
my $cmd_out='';
my $cmd_err='';
local $out = &execute_command("apt-cache search '^php'", undef, \$cmd_out, \$cmd_err, 0, 0);
if($cmd_err ne ""){
&error("Error: apt-cache: $cmd_err");
return 1;
}
my %pkgs;
my @lines = split /\n/, $cmd_out;
foreach my $line (@lines){
if($line =~ /^(php.*) - (.*)/i){
$pkgs{$1} = $2;
}
}
return %pkgs;
}
sub get_installed_apt{
my $href = $_[0]; #package names
my %pkgs;
my $cmd_out='';
my $cmd_err='';
local $out = &execute_command("dpkg -l 'php*'", undef, \$cmd_out, \$cmd_err);
if($cmd_err ne ""){
&error("Error: dpkg: $cmd_err");
return %pkgs;
}
#set all packages to not installed, since dpkg won't list them
foreach my $name (keys %$href){
$pkgs{$name} = 0;
}
my @lines = split /\n/, $cmd_out;
foreach my $line (@lines){
if($line =~ /^(..)\s+(php[a-z0-9_\.-]+)\s+/i){
my $pkg = $2;
if($1 =~ /[uirph]i/){
$pkgs{$pkg} = 1;
}
}
}
return %pkgs;
};
sub update_packages{
my $pkgs_install = $_[0];
my $pkgs_remove = $_[1]; #\@lref
if($pkgs_install ne ""){
software::update_system_install($pkgs_install, undef);
}
if(@$pkgs_remove){
print "<br><p>Removing packages</p>";
my %opts = ('depstoo'=>1);
my $error = "";
if (defined(&delete_packages)) {
$error = software::delete_packages($pkgs_remove, \%opts, undef);
}else{
foreach my $pkg (@$pkgs_remove){
$error .= software::delete_package($pkg, \%opts, undef)
}
}
if($error ne ""){
&error($error);
}else{
foreach my $pkg (@$pkgs_remove){
print "<tt>Deleted $pkg</tt><br>"
}
}
}
}
&ui_print_header(undef, $text{'php_inst_title'}, "", "intro", 1, 1);
my $no_install = 1;
if($ENV{'CONTENT_TYPE'} =~ /boundary=(.*)$/) {
&ReadParseMime();
$no_install = 0;
}else{
&ReadParse();
$no_install = 1;
}
my %pkgs;
my %pkgs_installed;
my %osinfo = &detect_operating_system();
if( $osinfo{'os_type'} =~ /redhat/i){ #other redhat
%pkgs = get_packages_yum();
%pkgs_installed = get_installed_yum(\%pkgs);
}elsif( $osinfo{'real_os_type'} =~ /ubuntu/i){ #ubuntu
%pkgs = get_packages_apt();
%pkgs_installed = get_installed_apt(\%pkgs);
}
#Check what is updated
if ($ENV{REQUEST_METHOD} eq "POST" && $no_install == 0) {
#find what was changed
my @pkgs_remove;
my $pkgs_install="";
foreach my $pkg (sort keys %pkgs_installed){
if($in{$pkg.'_status'} != $pkgs_installed{$pkg}){
if($in{$pkg.'_status'} == 1){
$pkgs_install .= " $pkg";
}else{
push(@pkgs_remove, $pkg);
}
}
}
update_packages($pkgs_install, \@pkgs_remove);
&ui_print_footer("", $text{'index_return'});
exit;
}
print &ui_form_start("php_install.cgi", "form-data");
print &ui_table_start($text{'php_inst_edit'}, "width=100%", 3);
foreach my $pkg (sort keys %pkgs){
print &ui_table_row($pkg, ui_yesno_radio($pkg.'_status', $pkgs_installed{$pkg}).$pkgs{$pkg} ,3);
}
print &ui_table_end();
print &ui_form_end([ [ "", $text{'php_inst_save'} ] ]);
&ui_print_footer("", $text{'index_return'});