Private
Server IP : 195.201.23.43  /  Your IP : 3.17.135.12
Web Server : Apache
System : Linux webserver2.vercom.be 5.4.0-192-generic #212-Ubuntu SMP Fri Jul 5 09:47:39 UTC 2024 x86_64
User : kdecoratie ( 1041)
PHP Version : 7.1.33-63+ubuntu20.04.1+deb.sury.org+1
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/share/webmin/virtual-server/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /usr/share/webmin/virtual-server/list-databases.pl
#!/usr/bin/perl

=head1 list-databases.pl

Lists databases for some virtual server

This program simply displays a list of MySQL and PostgreSQL databases that are owned by one server. You must supply the C<--domain> flag followed by the domain name of the server to list. By default the output is in a reader-friendly table, but the C<--multiline> option can be used to switch to a format more suitable for reading by programs (and containing more information).

To output just a list of database names, use the C<--name-only> flag. To limit
the list to databases of a particular type, use C<--type> followed by a code
like C<mysql> or C<postgres>.

=cut

package virtual_server;
if (!$module_name) {
	$main::no_acl_check++;
	$ENV{'WEBMIN_CONFIG'} ||= "/etc/webmin";
	$ENV{'WEBMIN_VAR'} ||= "/var/webmin";
	if ($0 =~ /^(.*)\/[^\/]+$/) {
		chdir($pwd = $1);
		}
	else {
		chop($pwd = `pwd`);
		}
	$0 = "$pwd/list-databases.pl";
	require './virtual-server-lib.pl';
	$< == 0 || die "list-databases.pl must be run as root";
	}

# Parse command-line args
while(@ARGV > 0) {
	local $a = shift(@ARGV);
	if ($a eq "--domain") {
		$domain = shift(@ARGV);
		}
	elsif ($a eq "--multiline") {
		$multi = 1;
		}
	elsif ($a eq "--name-only") {
		$nameonly = 1;
		}
	elsif ($a eq "--type") {
		$type = shift(@ARGV);
		}
	elsif ($a eq "--help") {
		&usage();
		}
	else {
		&usage("Unknown parameter $a");
		}
	}

$domain || &usage("No domain specified");
$d = &get_domain_by("dom", $domain);
$d || usage("Virtual server $domain does not exist");
@dbs = &domain_databases($d);
if ($type) {
	@dbs = grep { $_->{'type'} eq $type } @dbs;
	}
if ($multi) {
	# Show each database on a separate line
	if (defined(&list_domain_scripts)) {
		@scripts = &list_domain_scripts($d);
		}
	foreach $db (@dbs) {
		print "$db->{'name'}\n";
		print "    Type: $db->{'type'}\n";
		($size, $tables, undef, $count) = &get_one_database_usage($d, $db);
		if ($size) {
			print "    Size: ",&nice_size($size),"\n";
			print "    Byte size: ",$size,"\n";
			}
		if ($count) {
			print "    Files: ",$count,"\n";
			}
		print "    Tables: $tables\n";
		if ($db->{'host'}) {
			print "    Host: $db->{'host'}\n";
			}

		# Show scripts that use it
		@slist = ( );
		foreach $sinfo (@scripts) {
			($dbtype, $dbname) =
				split(/_/, $sinfo->{'opts'}->{'db'}, 2);
			if ($dbtype eq $db->{'type'} &&
			    $dbname eq $db->{'name'}) {
				push(@slist, $sinfo->{'name'}." ".
					     $sinfo->{'version'});
				}
			}
		if (@slist) {
			print "    Used by scripts: ",join(", ", @slist),"\n";
			}
		}
	}
elsif ($nameonly) {
	# Just show DB names
	foreach $db (@dbs) {
		print $db->{'name'},"\n";
		}
	}
else {
	# Show all on one line
	$fmt = "%-30.30s %-20.20s %-15.15s %-10.10s\n";
	printf $fmt, "Database", "Type", "Size", "Tables";
	printf $fmt, ("-" x 30), ("-" x 20), ("-" x 15), ("-" x 10);
	foreach $db (@dbs) {
		($size, $tables) = &get_one_database_usage($d, $db);
		printf $fmt, $db->{'name'}, $db->{'type'},
			     $size ? &nice_size($size) : "Unknown", $tables;
		}
	}

sub usage
{
print "$_[0]\n\n" if ($_[0]);
print "Lists the databases associated with some virtual server.\n";
print "\n";
print "virtualmin list-databases --domain domain.name\n";
print "                         [--multiline | --name-only]\n";
print "                         [--type dbtype]\n";
exit(1);
}

Private