3 # Install a package from some source
5 require './software-lib.pl';
6 if ($ENV{REQUEST_METHOD} eq "POST") {
7 &ReadParse(\%getin, "GET");
8 &ReadParseMime(undef, \&read_parse_mime_callback, [ $getin{'id'} ]);
14 &error_setup($text{'install_err'});
16 if ($in{source} >= 2) {
17 &ui_print_unbuffered_header(undef, $text{'install_title'}, "", "install");
20 &ui_print_header(undef, $text{'install_title'}, "", "install");
23 if ($in{source} == 0) {
24 # installing from local file (or maybe directory)
26 { &install_error($text{'install_elocal'}); }
27 if (!-r $in{'local'} && !-d $in{'local'} && $in{'local'} !~ /\*|\?/)
28 { &install_error(&text('install_elocal2', $in{'local'})); }
29 $source = $in{'local'};
30 $pfile = $in{'local'};
33 elsif ($in{source} == 1) {
34 # installing from upload .. store file in temp location
36 &install_error($text{'install_eupload'});
38 $in{'upload_filename'} =~ /([^\/\\]+$)/;
39 $pfile = &tempname("$1");
40 &open_tempfile(PFILE, ">$pfile", 0, 1);
41 &print_tempfile(PFILE, $in{'upload'});
42 &close_tempfile(PFILE);
43 $source = $in{'upload_filename'};
46 elsif ($in{source} == 2) {
47 # installing from URL.. store downloaded file in temp location
48 $in{'url'} = &convert_osdn_url($in{'url'});
49 $in{'url'} =~ /\/([^\/]+)\/*$/;
50 $pfile = &tempname("$1");
52 $progress_callback_url = $in{'url'};
53 if ($in{'url'} =~ /^(http|https):\/\/([^\/]+)(\/.*)$/) {
56 $host = $2; $page = $3; $port = $ssl ? 443 : 80;
57 if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; }
58 &http_download($host, $port, $page, $pfile, \$error,
59 \&progress_callback, $ssl);
61 elsif ($in{'url'} =~ /^ftp:\/\/([^\/]+)(:21)?(\/.*)$/) {
62 $host = $1; $file = $3;
63 &ftp_download($host, $file, $pfile, \$error,
67 &install_error(&text('install_eurl', $in{'url'}));
69 &install_error($error) if ($error);
73 elsif ($in{'source'} == 3) {
74 # installing from some update system
76 $in{'update'} =~ /\S/ || &error($text{'install_eupdate'});
77 @packs = &update_system_install($in{'update'}, \%in);
80 print &ui_hr() if (@packs);
82 local @pinfo = &show_package_info($p);
84 &webmin_log($config{'update_system'}, "install", undef,
85 { 'packages' => \@packs } ) if (@packs);
87 if ($in{'caller'} && &foreign_check("webmin")) {
88 # Software installed - refresh installed flag cache
89 &foreign_require("webmin", "webmin-lib.pl");
91 &webmin::build_installed_modules(0, $in{'caller'});
92 if (@$changed && defined(&theme_post_change_modules)) {
93 &theme_post_change_modules();
98 &ui_print_footer($in{'return'}, $in{'returndesc'});
101 &ui_print_footer("", $text{'index_return'});
107 if (!&is_package($pfile)) {
109 &install_error(&text('install_edir', &package_system()));
112 # attempt to uncompress
113 local $unc = &uncompress_if_needed($pfile, $need_unlink);
114 if ($unc ne $pfile) {
116 if (!&is_package($unc)) {
118 &install_error(&text('install_ezip',
124 # uncompress failed.. give up
125 #unlink($pfile) if ($need_unlink);
126 &install_error(&text('install_efile', &package_system()));
131 # ask for package to install and install options
132 @rv = &file_packages($pfile);
134 print &ui_form_start("do_install.cgi");
135 print &ui_hidden("file", $pfile);
136 print &ui_hidden("need_unlink", $need_unlink);
137 print &ui_table_start($text{'install_header'}, undef, 4);
139 # Packages to install
142 ($p, $d) = split(/\s+/, $_, 2);
144 $plist .= &html_escape($d)," (",&html_escape($p),")<br>\n";
147 $plist .= &html_escape($p),"<br>\n";
150 print &ui_table_row($text{'install_packs'}, $plist, 3);
152 # Type-specific options
153 &install_options($pfile, $p);
155 print &ui_table_end();
156 print &ui_form_end([ [ undef, $text{'install_ok'} ] ]);
158 &ui_print_footer("", $text{'index_return'});
162 print "<br><b>$main::whatfailed : $_[0]</b> <p>\n";
163 &ui_print_footer("", $text{'index_return'});