[ Avaa Bypassed ]




Upload:

Command:

www-data@3.148.202.164: ~ $
#!/usr/bin/perl
# upgrade.cgi
# Download usermin and upgrade all managed servers of compatible types

require './cluster-usermin-lib.pl';
&foreign_require("proc", "proc-lib.pl");
&foreign_require("webmin", "webmin-lib.pl");
&foreign_require("webmin", "gnupg-lib.pl");
&ReadParseMime();

&ui_print_unbuffered_header(undef, $text{'upgrade_title'}, "");

# Save this CGI from being killed by the upgrade
$SIG{'TERM'} = 'IGNORE';

if ($in{'source'} == 0) {
	# from local file
	&error_setup(&usermin::text('upgrade_err1', $in{'file'}));
	$file = $in{'file'};
	if (!(-r $file)) { &inst_error($usermin::text{'upgrade_efile'}); }
	}
elsif ($in{'source'} == 1) {
	# from uploaded file
	&error_setup($usermin::text{'upgrade_err2'});
	$file = &tempname();
	$need_unlink = 1;
	if ($no_upload) {
                &inst_error($usermin::text{'upgrade_ebrowser'});
                }
	open(MOD, ">$file");
	print MOD $in{'upload'};
	close(MOD);
	}
elsif ($in{'source'} == 2) {
	# find latest version at www.usermin.com by looking at index page
	&error_setup($usermin::text{'upgrade_err3'});
	$file = &tempname();
	&http_download($usermin::update_host, $usermin::update_port, '/index6.html', $file, \$error);
	$error && &inst_error($error);
	open(FILE, "<$file");
	while(<FILE>) {
		if (/usermin-([0-9\.]+)\.tar\.gz/) {
			$site_version = $1;
			last;
			}
		}
	close(FILE);
	unlink($file);
	if ($in{'mode'} eq 'rpm') {
		$progress_callback_url = "http://$usermin::update_host/download/rpm/usermin-${site_version}-1.noarch.rpm";
		&http_download($usermin::update_host, $usermin::update_port,
		  "/download/rpm/usermin-${site_version}-1.noarch.rpm", $file,
		  \$error, \&progress_callback);
		}
	elsif ($in{'mode'} eq 'deb') {
		$progress_callback_url = "http://$usermin::update_host/download/deb/usermin_${site_version}_all.deb";
		&http_download($usermin::update_host, $usermin::update_port,
		  "/download/deb/usermin_${site_version}_all.deb", $file,
		  \$error, \&progress_callback);
		}
	else {
		$progress_callback_url = "http://$usermin::update_host/download/usermin-${site_version}.tar.gz";
		&http_download($usermin::update_host, $usermin::update_port,
		  "/download/usermin-${site_version}.tar.gz", $file,
		  \$error, \&progress_callback);
		}
	$error && &inst_error($error);
	$need_unlink = 1;
	}
elsif ($in{'source'} == 5) {
	# Download from some URL
	&error_setup(&usermin::text('upgrade_err5', $in{'url'}));
	$file = &tempname();
	$progress_callback_url = $in{'url'};
	if ($in{'url'} =~ /^(http|https):\/\/([^\/]+)(\/.*)$/) {
		$ssl = $1 eq 'https';
		$host = $2; $page = $3; $port = $ssl ? 443 : 80;
		if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; }
		&http_download($host, $port, $page, $file, \$error,
			       \&progress_callback, $ssl);
		}
	elsif ($in{'url'} =~ /^ftp:\/\/([^\/]+)(:21)?\/(.*)$/) {
		$host = $1; $ffile = $3;
		&ftp_download($host, $ffile, $file,
			      \$error, \&progress_callback);
		}
	else { &inst_error($usermin::text{'upgrade_eurl'}); }
	$need_unlink = 1;
	$error && &inst_error($error);
	}

# Work out what kind of file we have (RPM or tar.gz)
if (`rpm -qp $file 2>&1` =~ /(^|\n)usermin-(\d+\.\d+)/) {
	# Looks like a usermin RPM
	$mode = "rpm";
	$version = $2;
	}
elsif (`dpkg --info $file 2>&1` =~ /Package:\s+usermin\n\s*Version:\s+(\d+\.\d+)/) {
        # Looks like a Usermin Debian package
        $mode = "deb";
        $version = $2;
        }
else {
        # Check if it is a usermin tar.gz file
        open(TAR, "gunzip -c $file | tar tf - 2>&1 |");
        while(<TAR>) {
                s/\r|\n//g;
                if (/^usermin-([0-9\.]+)\//) {
                        $version = $1;
                        }
                if (/^webmin-([0-9\.]+)\//) {
                        $webmin_version = $1;
                        }
                if (/^[^\/]+\/(\S+)$/) {
                        $hasfile{$1}++;
                        }
                if (/^(usermin-([0-9\.]+)\/[^\/]+)$/) {
                        push(@topfiles, $1);
                        }
                elsif (/^usermin-[0-9\.]+\/([^\/]+)\//) {
                        $intar{$1}++;
                        }
                }
        close(TAR);
        if ($webmin_version) {
                &inst_error(&usermin::text('upgrade_ewebmin',
					   $webmin_version));
                }
        if (!$version) {
                if ($hasfile{'module.info'}) {
                        &inst_error(&usermin::text('upgrade_emod', 'index.cgi'));
                        }
                else {
                        &inst_error($usermin::text{'upgrade_etar'});
                        }
                }
	$mode = "";
	}

# gunzip the file if needed
open(FILE, "<$file");
read(FILE, $two, 2);
close(FILE);
if ($two eq "\037\213") {
	if (!&has_command("gunzip")) {
		&inst_error($usermin::text{'upgrade_egunzip'});
		}
	$newfile = &tempname();
	$out = `gunzip -c $file 2>&1 >$newfile`;
	if ($?) {
		unlink($newfile);
		&inst_error(&usermin::text('upgrade_egzip', "<tt>$out</tt>"));
		}
	unlink($file) if ($need_unlink);
	$need_unlink = 1;
	$file = $newfile;
	}

# Setup error handler for down hosts
sub inst_error
{
$inst_error_msg = join("", @_);
}
&remote_error_setup(\&inst_error);

# Build list of selected hosts
@hosts = &list_usermin_hosts();
@servers = &list_servers();
if ($in{'server'} == -2) {
	# Upgrade servers know to run older versions?
	@hosts = grep { $_->{'version'} < $version } @hosts;
	print "<b>",&text('upgrade_header3', $version),"</b><p>\n";
	}
elsif ($in{'server'} =~ /^group_(.*)/) {
	# Upgrade members of some group
        local ($group) = grep { $_->{'name'} eq $1 }
                              &servers::list_all_groups(\@servers);
        @hosts = grep { local $hid = $_->{'id'};
                        local ($s) = grep { $_->{'id'} == $hid } @servers;
                        &indexof($s->{'host'}, @{$group->{'members'}}) >= 0 }
                      @hosts;
        print "<b>",&text('upgrade_header4', $group->{'name'}),"</b><p>\n";
	}
elsif ($in{'server'} != -1) {
        # Upgrade one host
        @hosts = grep { $_->{'id'} == $in{'server'} } @hosts;
        local ($s) = grep { $_->{'id'} == $hosts[0]->{'id'} } @servers;
        print "<b>",&text('upgrade_header2', &server_name($s)),"</b><p>\n";
        }
else {
	# Upgrading every host
	print "<p><b>",&text('upgrade_header'),"</b><p>\n";
        }

# Run the install
$p = 0;
foreach $h (@hosts) {
	local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;

	local ($rh = "READ$p", $wh = "WRITE$p");
	pipe($rh, $wh);
	select($wh); $| = 1; select(STDOUT);
	if (!fork()) {
		# Do the install in a subprocess
		close($rh);

		if (!$s->{'fast'} && $s->{'id'} != 0) {
			print $wh &serialise_variable($text{'upgrade_efast'});
			exit;
			}
		&remote_foreign_require($s->{'host'}, "usermin",
						      "usermin-lib.pl");
		if ($inst_error_msg) {
			# Failed to contact host ..
			print $wh &serialise_variable($inst_error_msg);
			exit;
			}

		# Check the remote host's version
		local $rver = &remote_foreign_call($s->{'host'}, "usermin",
						   "get_usermin_version");
		if ($version == $rver) {
			print $wh &serialise_variable(
				&usermin::text('upgrade_elatest', $version));
			exit;
			}
		elsif ($version <= $rver) {
			print $wh &serialise_variable(
				&usermin::text('upgrade_eversion', $version));
			exit;
			}

		# Check the install type on the remote host
		local $rmode = &remote_eval($s->{'host'}, "usermin",
		    "&get_usermin_miniserv_config(\\\%miniserv); chop(\$m = `cat \$miniserv{'root'}/install-type`); \$m");
		if ($rmode ne $mode) {
			print $wh &serialise_variable(
				&text('upgrade_emode',
				      $text{'upgrade_mode_'.$rmode},
				      $text{'upgrade_mode_'.$mode}));
			exit;
			}

		# Get the file to the server somehow
		local $rfile;
		local $host_need_unlink = 1;
		if (!$s->{'id'}) {
			# This host, so we already have the file
			$rfile = $file;
			$host_need_unlink = 0;
			}
		elsif ($in{'source'} == 0) {
			# Is the file the same on remote? (like if we have NFS)
			local @st = stat($file);
			local $rst = &remote_eval($s->{'host'}, "usermin",
						  "[ stat('$file') ]");
			local @rst = @$rst;
			if (@st && @rst && $st[7] == $rst[7] &&
			    $st[9] == $rst[9]) {
				# File is the same! No need to download
				$rfile = $file;
				$host_need_unlink = 0;
				}
			else {
				# Need to copy the file across :(
				$rfile = &remote_write(
					$s->{'host'}, $file);
				}
			}
		else {
			# Need to copy the file across :(
			$rfile = &remote_write($s->{'host'}, $file);
			}

		# Do the install ..
		if ($mode eq "rpm") {
			# Can just run RPM command
			# XXX doesn't actually check output!
			&remote_eval($s->{'host'}, "usermin", "system(\"rpm --import \$root_directory/webmin/jcameron-key.asc >/dev/null 2>&1\")");
			($out, $ex) = &remote_eval($s->{'host'}, "usermin", "\$out = `rpm -U --ignoreos --ignorearch '$rfile' >/dev/null 2>&1 </dev/null`; (\$out, \$?)");
			&remote_eval($s->{'host'}, "usermin",
				     "unlink('$rfile')")
				if ($host_need_unlink);
			if ($ex) {
				print $wh &serialise_variable(
					"<pre>$out</pre>");
				exit;
				}
			}
                elsif ($mode eq "deb") {
                        # Can just run dpkg command
                        ($out, $ex) = &remote_eval($s->{'host'}, "usermin", "\$out = `dpkg --install '$rfile' >/dev/null 2>&1 </dev/null`; (\$out, \$?)");
                        &remote_eval($s->{'host'}, "usermin","unlink('$rfile')")
                                if ($host_need_unlink);
                        if ($ex) {
                                print $wh &serialise_variable(
                                        "<pre>$out</pre>");
                                exit;
                                }
                        }
		else {
			# Get the original install directory
			local $rdir = &remote_eval($s->{'host'}, "usermin",
			    "chop(\$m = `cat \$config{'usermin_dir'}/install-dir`); \$m");
			if ($rdir) {
				# Extract tar.gz in temporary location first
				$extract = &remote_foreign_call($s->{'host'}, "usermin", "tempname");
				&remote_eval($s->{'host'}, "usermin", "mkdir('$extract', 0755)");
				}
			else {
				# Extract next to original dir
				$oldroot = &remote_eval($s->{'host'}, "usermin", "\$root_directory");
				$extract = "$oldroot/..";
				}

			# Actually unpack the tar file
			local ($out, $ex) = &remote_eval($s->{'host'}, "usermin", "\$out = `cd '$extract' ; tar xf '$rfile' 2>&1 >/dev/null`; (\$out, \$?)");
			if ($ex) {
				print $wh &serialise_variable(
					"<pre>$out</pre>");
				exit;
				}

			# Delete the original tar.gz
			&remote_eval($s->{'host'}, "usermin", "unlink('$rfile')")
				if ($host_need_unlink);

			# Run setup.sh in the extracted directory
			$setup = $rdir ? "./setup.sh '$rdir'" : "./setup.sh";
			($out, $ex) = &remote_eval($s->{'host'}, "usermin",
				"\$SIG{'TERM'} = 'IGNORE';
				 \$ENV{'config_dir'} = \$config{'usermin_dir'};
				 \$ENV{'webmin_upgrade'} = 1;
				 \$ENV{'autothird'} = 1;
				 \$out = `(cd $extract/usermin-$version && $setup) </dev/null 2>&1 | tee /tmp/.webmin/usermin-setup.out`;
				 (\$out, \$?)");
			if ($out !~ /success/i) {
				print $wh &serialise_variable(
					"<pre>$out</pre>");
				exit;
				}
			if ($rdir) {
				# Can delete the temporary source directory
				&remote_eval($s->{'host'}, "usermin",
					     "system(\"rm -rf \'$extract\'\")");
				}
			elsif ($in{'delete'}) {
				# Can delete the old root directory
				&remote_eval($s->{'host'}, "usermin",
					     "system(\"rm -rf \'$oldroot\'\")");
				}
			}

		# Force an RPC re-connect to new version
		&remote_finished();
		&remote_foreign_require($s->{'host'}, "usermin",
					"usermin-lib.pl");
		if ($inst_error_msg) {
			# Failed to contact host ..
			print $wh &serialise_variable(
				&text('upgrade_ereconn', $inst_error_msg));
			exit;
			}
		&remote_foreign_require($s->{'host'}, "acl", "acl-lib.pl");

		# Update local version number and module lists
		$h->{'version'} = $version;
		local @mods = &remote_foreign_call($s->{'host'},
				"usermin", "list_modules");
		@mods = grep { !$_->{'clone'} } @mods;
		$h->{'modules'} = \@mods;
		local @themes = &remote_foreign_call($s->{'host'},
				 "usermin", "list_themes");
		$h->{'themes'} = \@themes;
		&save_usermin_host($h);

		print $wh &serialise_variable("");
		close($wh);
		exit;
		}
	close($wh);
	$p++;
	}

# Get back all the results
$p = 0;
foreach $h (@hosts) {
	local $rh = "READ$p";
	local $line = <$rh>;
	close($rh);
	local $rv = &unserialise_variable($line);

	local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
	local $d = &server_name($s);

	if (!$line) {
		print &text('upgrade_failed', $d, "Unknown reason"),"<br>\n";
		}
	elsif ($rv) {
		print &text('upgrade_failed', $d, $rv),"<br>\n";
		}
	else {
		print &text('upgrade_ok',
			    $text{'upgrade_mode_'.$mode}, $d),"<br>\n";
		}
	$p++;
	}
unlink($file) if ($need_unlink);
print "<p><b>$text{'upgrade_done'}</b><p>\n";

&remote_finished();
&ui_print_footer("", $text{'index_return'});

sub inst_error
{
unlink($file) if ($need_unlink);
print "<br><b>$whatfailed : $_[0]</b> <p>\n";
&ui_print_footer("", $text{'index_return'});
exit;
}


Filemanager

Name Type Size Permission Actions
help Folder 0755
images Folder 0755
lang Folder 0755
CHANGELOG File 319 B 0644
add.cgi File 2.04 KB 0755
cluster-usermin-lib.pl File 7.14 KB 0755
config File 25 B 0644
config.info File 108 B 0644
config.info.ca File 133 B 0644
config.info.cs File 79 B 0644
config.info.de File 125 B 0644
config.info.es File 63 B 0644
config.info.fr File 134 B 0644
config.info.hr File 0 B 0644
config.info.hu File 0 B 0644
config.info.ms File 131 B 0644
config.info.nl File 129 B 0644
config.info.no File 127 B 0644
config.info.pl File 122 B 0644
delete_host.cgi File 251 B 0755
delete_mod.cgi File 3.89 KB 0755
edit_acl.cgi File 4.2 KB 0755
edit_host.cgi File 3.37 KB 0755
edit_mod.cgi File 5.42 KB 0755
index.cgi File 6.02 KB 0755
install.cgi File 7.5 KB 0755
module.info File 211 B 0644
module.info.af File 0 B 0644
module.info.af.auto File 141 B 0644
module.info.ar File 0 B 0644
module.info.ar.auto File 196 B 0644
module.info.be File 0 B 0644
module.info.be.auto File 213 B 0644
module.info.bg File 0 B 0644
module.info.bg.auto File 213 B 0644
module.info.ca File 131 B 0644
module.info.ca.auto File 24 B 0644
module.info.cs File 34 B 0644
module.info.cs.auto File 105 B 0644
module.info.da File 0 B 0644
module.info.da.auto File 148 B 0644
module.info.de File 125 B 0644
module.info.de.auto File 24 B 0644
module.info.el File 0 B 0644
module.info.el.auto File 258 B 0644
module.info.es File 42 B 0644
module.info.es.auto File 109 B 0644
module.info.eu File 0 B 0644
module.info.eu.auto File 162 B 0644
module.info.fa File 0 B 0644
module.info.fa.auto File 190 B 0644
module.info.fi File 0 B 0644
module.info.fi.auto File 142 B 0644
module.info.fr File 36 B 0644
module.info.fr.auto File 115 B 0644
module.info.he File 0 B 0644
module.info.he.auto File 166 B 0644
module.info.hr File 0 B 0644
module.info.hr.auto File 157 B 0644
module.info.hu File 34 B 0644
module.info.hu.auto File 116 B 0644
module.info.it File 0 B 0644
module.info.it.auto File 125 B 0644
module.info.ja File 0 B 0644
module.info.ja.auto File 195 B 0644
module.info.ko File 0 B 0644
module.info.ko.auto File 158 B 0644
module.info.lt File 0 B 0644
module.info.lt.auto File 160 B 0644
module.info.lv File 0 B 0644
module.info.lv.auto File 145 B 0644
module.info.ms File 112 B 0644
module.info.ms.auto File 24 B 0644
module.info.mt File 0 B 0644
module.info.mt.auto File 145 B 0644
module.info.nl File 32 B 0644
module.info.nl.auto File 105 B 0644
module.info.no File 33 B 0644
module.info.no.auto File 115 B 0644
module.info.pl File 125 B 0644
module.info.pl.auto File 28 B 0644
module.info.pt File 0 B 0644
module.info.pt.auto File 145 B 0644
module.info.pt_BR File 0 B 0644
module.info.pt_BR.auto File 154 B 0644
module.info.ro File 0 B 0644
module.info.ro.auto File 141 B 0644
module.info.ru File 0 B 0644
module.info.ru.auto File 219 B 0644
module.info.sk File 0 B 0644
module.info.sk.auto File 142 B 0644
module.info.sl File 0 B 0644
module.info.sl.auto File 140 B 0644
module.info.sv File 0 B 0644
module.info.sv.auto File 138 B 0644
module.info.th File 0 B 0644
module.info.th.auto File 282 B 0644
module.info.tr File 0 B 0644
module.info.tr.auto File 146 B 0644
module.info.uk File 0 B 0644
module.info.uk.auto File 227 B 0644
module.info.ur File 0 B 0644
module.info.ur.auto File 216 B 0644
module.info.vi File 0 B 0644
module.info.vi.auto File 158 B 0644
module.info.zh File 0 B 0644
module.info.zh.auto File 126 B 0644
module.info.zh_TW File 0 B 0644
module.info.zh_TW.auto File 135 B 0644
prefs.info File 28 B 0644
refresh.cgi File 3.36 KB 0755
save_acl.cgi File 3.28 KB 0755
sync.cgi File 3.94 KB 0755
sync_form.cgi File 1.78 KB 0755
update.cgi File 4.1 KB 0755
upgrade.cgi File 12.87 KB 0755