3 # Install a package from some source
5 require './cluster-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_pack");
20 &ui_print_header(undef, $text{'install_title'}, "", "install_pack");
23 if ($in{source} == 0) {
24 # installing from local file (or maybe directory)
26 { &install_error($text{'install_elocal'}); }
28 { &install_error(&text('install_elocal2', $in{'local'})); }
29 $source = $in{'local'};
30 $pfile = $in{'local'};
31 $filename = $in{'local'};
32 $filename =~ s/^(.*)[\\\/]//;
35 elsif ($in{source} == 1) {
36 # installing from upload .. store file in temp location
38 &install_error($text{'install_eupload'});
40 $in{'upload_filename'} =~ /([^\/\\]+$)/;
41 $filename = $in{'upload_filename'};
42 $filename =~ s/^(.*)[\\\/]//;
43 $pfile = &tempname("$1");
44 &open_tempfile(PFILE, ">$pfile");
45 &print_tempfile(PFILE, $in{'upload'});
46 &close_tempfile(PFILE);
47 $source = $in{'upload_filename'};
50 elsif ($in{source} == 2) {
51 # installing from URL.. store downloaded file in temp location
52 $in{'url'} =~ /\/([^\/]+)\/*$/;
53 $pfile = &tempname("$1");
54 $progress_callback_url = $in{'url'};
55 if ($in{'url'} =~ /^(http|https):\/\/([^\/]+)(\/.*)$/) {
58 $host = $2; $page = $3; $port = $ssl ? 443 : 80;
59 if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; }
60 &http_download($host, $port, $page, $pfile, \$error,
61 \&progress_callback, $ssl);
63 elsif ($in{'url'} =~ /^ftp:\/\/([^\/]+)(:21)?(\/.*)$/) {
64 $host = $1; $file = $3;
65 &ftp_download($host, $file, $pfile, \$error,
68 else { &install_error(&text('install_eurl', $in{'url'})); }
69 &install_error($error) if ($error);
72 $filename = $in{'url'};
73 $filename =~ s/^(.*)[\\\/]//;
75 elsif ($in{source} == 3) {
76 # installing from some update system, so nothing to do here
77 $pfile = $in{'update'};
78 @rv = split(/\s+/, $in{'update'});
81 # Check if any remote systems are using the same package system
82 @anysame = grep { &same_package_system($_) } &list_software_hosts();
83 @anydiff = grep { !&same_package_system($_) } &list_software_hosts();
85 # Check validity, if we can
87 if ($in{'source'} != 3) {
88 $ps = &software::package_system();
89 if (!&software::is_package($pfile)) {
91 &install_error(&text('install_edir', $ps));
94 # attempt to uncompress
95 local $unc = &software::uncompress_if_needed(
96 $pfile, $need_unlink);
99 if (!&software::is_package($unc)) {
100 # but still not valid :(
103 &text('install_ezip', $ps);
110 # uncompress failed.. give up
111 $invalid_msg = &text('install_efile', $ps);
117 # ask for package to install and install options
118 @rv = &software::file_packages($pfile);
123 # Could not check package .. but this is OK if we have any remote
124 # systems of different types
126 $filename =~ s/\.[a-z]+$//i;
128 $unknownfile = $filename;
131 unlink($pfile) if ($need_unlink);
132 &install_error($invalid_msg);
137 print &ui_form_start("do_install.cgi");
138 print &ui_hidden("file", $pfile);
139 print &ui_hidden("unknownfile", $unknownfile);
140 print &ui_hidden("need_unlink", $need_unlink);
141 print &ui_hidden("source", $in{'source'});
142 print &ui_hidden("ssl", $ssl);
143 print &ui_hidden("host", $host);
144 print &ui_hidden("page", $page);
145 print &ui_hidden("port", $port);
146 print &ui_hidden("ftpfile", $file);
147 print &ui_hidden("down", $in{'down'});
148 print &ui_table_start($text{'install_header'}, undef, 4);
150 # Packages to install
153 ($p, $d) = split(/\s+/, $_, 2);
155 $plist .= &html_escape($d)," (",&html_escape($p),")<br>\n";
158 $plist .= &html_escape($p),"<br>\n";
161 print &ui_table_row($text{'install_packs'}, $plist, 3);
163 # Type-specific options
164 if ($in{'source'} != 3 && !@anydiff) {
165 &software::install_options($pfile, $p);
168 # Show input for hosts to install on
169 &create_on_input($text{'install_servers'},
170 $in{'source'} == 3, $in{'source'} == 3);
172 print &ui_table_end();
173 print &ui_form_end([ [ undef, $text{'install_ok'} ] ]);
176 &ui_print_footer("", $text{'index_return'});
180 print "<b>$main::whatfailed : $_[0]</b> <p>\n";
181 &ui_print_footer("", $text{'index_return'});