mysql/ 0040775 0005671 0000012 00000000000 10740467706 011724 5 ustar jcameron wheel mysql/backup_db.cgi 0100775 0005671 0000012 00000014223 10740467703 014321 0 ustar jcameron wheel #!/usr/local/bin/perl
# backup_db.cgi
# Do the actual backup
require './mysql-lib.pl';
&ReadParse();
if ($in{'all'}) {
@alldbs = &list_databases();
@dbs = grep { &can_edit_db($_) } @alldbs;
@alldbs == @dbs || &error($text{'dbase_ecannot'});
}
else {
&can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
}
$access{'edonly'} && &error($text{'dbase_ecannot'});
$access{'buser'} || &error($text{'dbase_ecannot'});
&error_setup($text{'backup_err'});
if (!$in{'save'} || $in{'sched'}) {
if ($in{'all'}) {
-d $in{'file'} || -d &date_subs($in{'file'}) || $in{'mkdir'} ||
&error($text{'backup_efile2'});
}
else {
$in{'file'} =~ /^\/\S+$/ || &error($text{'backup_efile'});
}
$in{'where_def'} || $in{'where'} || &error($text{'backup_ewhere'});
$in{'charset_def'} || $in{'charset'} =~ /^\S+$/ ||
&error($text{'backup_echarset'});
$ccmd = $in{'compress'} == 1 ? "gzip" :
$in{'compress'} == 2 ? "bzip2" : undef;
!$ccmd || &has_command($ccmd) ||
&error(&text('backup_eccmd', "$ccmd"));
if (!&is_under_directory($access{'bpath'}, $in{'file'})) {
&error($text{'backup_epath'}."
".
&text('backup_eunder', "$access{'bpath'}"));
}
if (!$in{'all'} && !$in{'tables_def'}) {
@tables = split(/\0/, $in{'tables'});
@tables || &error($text{'backup_etables'});
}
}
@compat = $in{'compatible_def'} ? ( ) : ( $in{'compatible'} );
push(@compat, split(/\0/, $in{'options'}));
$cron = !$module_info{'usermin'} && $access{'buser'} eq 'root' &&
!$access{'user'} && &foreign_installed("cron");
$cmode = 0;
if ($cron) {
$config{'backup_before_'.$in{'db'}} = $in{'before'};
$config{'backup_after_'.$in{'db'}} = $in{'after'};
if ($in{'all'}) {
$config{'backup_cmode_'.$in{'db'}} = $in{'cmode'};
$cmode = $in{'cmode'};
}
&foreign_require("cron", "cron-lib.pl");
@jobs = &cron::list_cron_jobs();
$cmd = $in{'all'} ? "$cron_cmd --all" : "$cron_cmd $in{'db'}";
($job) = grep { $_->{'command'} eq $cmd } @jobs;
$oldjob = $job;
$job ||= { 'command' => $cmd,
'user' => 'root',
'active' => 1 };
&cron::parse_times_input($job, \%in);
}
# Save choices for next time the form is visited (and for the cron job)
if ($module_info{'usermin'}) {
$userconfig{'backup_'.$in{'db'}} = $in{'file'};
$userconfig{'backup_where_'.$in{'db'}} =
$in{'where_def'} ? undef : $in{'where'};
$userconfig{'backup_charset_'.$in{'db'}} =
$in{'charset_def'} ? undef : $in{'charset'};
$userconfig{'backup_compatible_'.$in{'db'}} =
$in{'compatible_def'} ? undef : $in{'compatible'};
$userconfig{'backup_options_'.$in{'db'}} =
join(" ", split(/\0/, $in{'options'}));
$userconfig{'backup_compress_'.$in{'db'}} = $in{'compress'};
$userconfig{'backup_drop_'.$in{'db'}} = $in{'drop'};
$userconfig{'backup_tables_'.$in{'db'}} = join(" ", @tables);
&write_file("$user_module_config_directory/config", \%userconfig);
}
else {
$config{'backup_'.$in{'db'}} = $in{'file'};
$config{'backup_mkdir_'.$in{'db'}} = $in{'mkdir'};
$config{'backup_where_'.$in{'db'}} =
$in{'where_def'} ? undef : $in{'where'};
$config{'backup_charset_'.$in{'db'}} =
$in{'charset_def'} ? undef : $in{'charset'};
$config{'backup_compatible_'.$in{'db'}} =
$in{'compatible_def'} ? undef : $in{'compatible'};
$config{'backup_options_'.$in{'db'}} =
join(" ", split(/\0/, $in{'options'}));
$config{'backup_compress_'.$in{'db'}} = $in{'compress'};
$config{'backup_drop_'.$in{'db'}} = $in{'drop'};
$config{'backup_tables_'.$in{'db'}} = join(" ", @tables);
&write_file("$module_config_directory/config", \%config);
}
&ui_print_header(undef, $text{'backup_title'}, "");
if (!$in{'save'}) {
# Actually execute the backup now
@dbs = $in{'all'} ? @alldbs : ( $in{'db'} );
if ($cmode == 1) {
# Run and check before-backup command (for all DBs)
$bok = &execute_before(undef, STDOUT, 1, $in{'file'}, undef);
if (!$bok) {
print "$main::whatfailed : ",$text{'backup_ebefore'},"
\n"; goto donebackup; } } foreach $db (@dbs) { if ($in{'all'}) { $dir = &date_subs($in{'file'}); &make_dir($dir, 0755) if ($in{'mkdir'}); $file = $dir."/".$db.".sql". ($in{'compress'} == 1 ? ".gz" : $in{'compress'} == 2 ? ".bz2" : ""); } else { $file = &date_subs($in{'file'}); } if ($cron && $cmode == 0) { # Run and check before-backup command (for one DB) $bok = &execute_before($db, STDOUT, 1, $file, $in{'all'} ? undef : $db); if (!$bok) { print "$main::whatfailed : ",$text{'backup_ebefore'},"
\n"; next; } } unlink($file); if ($in{'compress'} == 0) { $writer = ">$file"; } elsif ($in{'compress'} == 1) { $writer = "| gzip -c >$file"; } elsif ($in{'compress'} == 2) { $writer = "| bzip2 -c >$file"; } local $err = &backup_database($db, $file, $in{'compress'}, $in{'drop'}, $in{'where_def'} ? undef : $in{'where'}, $in{'charset_def'} ? undef : $in{'charset'}, \@compat, \@tables, $access{'buser'}); if ($err) { print "$main::whatfailed : ", &text('backup_ebackup',"
$err"),"
\n"; } else { @st = stat($file); print &text('backup_done', "$db", "$file", int($st[7])),"
\n"; } &execute_after($db, STDOUT, 1, $file, $in{'all'} ? undef : $db) if ($cron && $cmode == 0); } &execute_after(undef, STDOUT, 1, $in{'file'}, undef) if ($cmode == 1); donebackup: } if ($cron) { &lock_file($cron_cmd); &cron::create_wrapper($cron_cmd, $module_name, "backup.pl"); &unlock_file($cron_cmd); &lock_file(&cron::cron_file($job)); if ($in{'sched'} && !$oldjob) { &cron::create_cron_job($job); $what = "backup_ccron"; } elsif (!$in{'sched'} && $oldjob) { # Need to delete cron job &cron::delete_cron_job($job); $what = "backup_dcron"; } elsif ($in{'sched'} && $oldjob) { # Need to update cron job &cron::change_cron_job($job); $what = "backup_ucron"; } else { $what = "backup_ncron"; } &unlock_file(&cron::cron_file($job)); # Tell the user what was done print $text{$what},"
\n" if ($what); } &webmin_log("backup", undef, $in{'all'} ? "" : $in{'db'}, \%in); if ($in{'all'}) { &ui_print_footer("", $text{'index_return'}); } else { &ui_print_footer("edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'}, "", $text{'index_return'}); } mysql/backup_form.cgi 0100775 0005671 0000012 00000012626 10740467703 014704 0 ustar jcameron wheel #!/usr/local/bin/perl # backup_form.cgi # Display a form for backing up this database, or all databases require './mysql-lib.pl'; &ReadParse(); if ($in{'all'}) { @alldbs = &list_databases(); @dbs = grep { &can_edit_db($_) } @alldbs; @alldbs == @dbs || &error($text{'dbase_ecannot'}); } else { &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'}); } $access{'edonly'} && &error($text{'dbase_ecannot'}); $access{'buser'} || &error($text{'dbase_ecannot'}); &ui_print_header(undef, $in{'all'} ? $text{'backup_title2'} : $text{'backup_title'}, "", "backup_form"); if (!-x $config{'mysqldump'}) { print &text('backup_edump', "$config{'mysqldump'}", "../config.cgi?$module_name"),"
\n"; &ui_print_footer("edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'}); exit; } $cron = !$module_info{'usermin'} && $access{'buser'} eq 'root' && !$access{'user'} && &foreign_installed("cron"); if ($in{'all'}) { print "$text{'backup_desc3'}\n"; } else { print &text('backup_desc', "$in{'db'}"),"\n"; } if ($cron) { print "$text{'backup_desc2'}\n"; } print "
\n";
%c = $module_info{'usermin'} ? %userconfig : %config;
print &ui_form_start("backup_db.cgi", "post");
print &ui_hidden("db", $in{'db'});
print &ui_hidden("all", $in{'all'});
print &ui_hidden_table_start($text{'backup_header1'}, undef, 2, "main", 1,
[ "width=30%" ]);
# Destination file or directory
print &ui_table_row($in{'all'} ? $text{'backup_file2'}
: $text{'backup_file'},
&ui_textbox("file", $c{'backup_'.$in{'db'}}, 60)." ".
&file_chooser_button("file"));
# Create destination dir
if ($in{'all'}) {
print &ui_table_row($text{'backup_mkdir'},
&ui_yesno_radio("mkdir", int($c{'backup_mkdir_'.$in{'db'}})));
}
if (!$in{'all'}) {
# Show input to select tables
$t = $c{'backup_tables_'.$in{'db'}};
@tables = &list_tables($in{'db'});
print &ui_table_row($text{'backup_tables'},
&ui_radio("tables_def", $t ? 0 : 1,
[ [ 1, $text{'backup_alltables'} ],
[ 0, $text{'backup_seltables'} ] ])."
".
&ui_select("tables", [ split(/\s+/, $t) ],
[ sort @tables ], 5, 1));
}
print &ui_hidden_table_end("main");
print &ui_hidden_table_start($text{'backup_header2'}, undef, 2, "opts", 0,
[ "width=30%" ]);
# Show input for where clause
$w = $c{'backup_where_'.$in{'db'}};
print &ui_table_row($text{'backup_where'},
&ui_opt_textbox("where", $w, 30, $text{'backup_none'}));
# Show option to include drop statements in SQL
$d = $c{'backup_drop_'.$in{'db'}};
print &ui_table_row($text{'backup_drop'},
&ui_yesno_radio("drop", $d ? 1 : 0));
# Show input for character set
$s = $c{'backup_charset_'.$in{'db'}};
print &ui_table_row($text{'backup_charset'},
&ui_radio("charset_def", $s ? 0 : 1,
[ [ 1, $text{'default'} ],
[ 0, &ui_select("charset", $s,
[ &list_character_sets($in{'db'}) ]) ] ]));
if ($mysql_version >= 5.0) {
# Show compatability format option
$cf = $c{'backup_compatible_'.$in{'db'}};
print &ui_table_row($text{'backup_compatible'},
&ui_radio("compatible_def", $cf ? 0 : 1,
[ [ 1, $text{'default'} ],
[ 0, &text('backup_compwith',
&ui_select("compatible", $cf,
[ &list_compatible_formats() ])) ] ]));
%co = map { $_, 1 } split(/\s+/, $c{'backup_options_'.$in{'db'}});
$opts = "";
foreach $o (&list_compatible_options()) {
$opts .= &ui_checkbox("options", $o->[0], $o->[1] || $o->[0],
$co{$o->[0]})."
\n";
}
print &ui_table_row($text{'backup_options'}, $opts);
}
else {
print &ui_hidden("compatible_def", 1),"\n";
}
# Show compression option
$cp = int($c{'backup_compress_'.$in{'db'}});
print &ui_table_row($text{'backup_compress'},
&ui_radio("compress", $cp,
[ [ 0, $text{'backup_cnone'} ],
[ 1, $text{'backup_gzip'} ],
[ 2, $text{'backup_bzip2'} ] ]));
if ($cron) {
# Show before/after commands
$b = $c{'backup_before_'.$in{'db'}};
print &ui_table_row($text{'backup_before'},
&ui_textbox("before", $b, 60));
$a = $c{'backup_after_'.$in{'db'}};
print &ui_table_row($text{'backup_after'},
&ui_textbox("after", $a, 60));
if ($in{'all'}) {
# Command mode option
$cmode = $c{'backup_cmode_'.$in{'db'}};
print &ui_table_row($text{'backup_cmode'},
&ui_radio("cmode", int($cmode),
[ [ 0, $text{'backup_cmode0'} ],
[ 1, $text{'backup_cmode1'} ] ]));
}
print &ui_hidden_table_end("opts");
print &ui_hidden_table_start($text{'backup_header3'}, undef, 2, "sched",
1, [ "width=30%" ]);
# Show cron time
&foreign_require("cron", "cron-lib.pl");
@jobs = &cron::list_cron_jobs();
$cmd = $in{'all'} ? "$cron_cmd --all" : "$cron_cmd $in{'db'}";
($job) = grep { $_->{'command'} eq $cmd } @jobs;
print &ui_table_row($text{'backup_sched'},
&ui_radio("sched", $job ? 1 : 0,
[ [ 0, $text{'no'} ], [ 1, $text{'backup_sched1'} ] ]));
$job ||= { 'mins' => 0,
'hours' => 0,
'days' => '*',
'months' => '*',
'weekdays' => '*' };
print &ui_table_row(undef,
"
\n";
&ui_print_footer("edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'},
"", $text{'index_return'});
}
sub quote_csv
{
local ($str, $q) = @_;
$str =~ s/\r//g;
foreach my $c (split(//, $q)) {
local $qc = $c eq "\"" ? "\\\"" :
$c eq "\n" ? "\\n" :
$c eq "," ? "\\," :
$c eq "\t" ? "\\t" : $c;
$str =~ s/\Q$c\E/$qc/g;
}
return $str;
}
mysql/csv_form.cgi 0100775 0005671 0000012 00000003224 10740467703 014224 0 ustar jcameron wheel #!/usr/local/bin/perl
# Show a form for exporting CSV data
require './mysql-lib.pl';
&ReadParse();
&can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
$access{'edonly'} && &error($text{'dbase_ecannot'});
$desc = &text('table_header', "$in{'table'}", "$in{'db'}");
&ui_print_header($desc, $text{'csv_title'}, "", "csv");
print &ui_form_start("csv.cgi/$in{'table'}.csv", "post");
print &ui_hidden("db", $in{'db'}),"\n";
print &ui_hidden("table", $in{'table'}),"\n";
print &ui_table_start($text{'csv_header'}, undef, 2);
print &ui_table_row($text{'csv_format'},
&ui_radio("format", 0, [ [ 0, $text{'csv_format0'} ],
[ 1, $text{'csv_format1'} ],
[ 2, $text{'csv_format2'} ] ]));
print &ui_table_row($text{'csv_headers'},
&ui_yesno_radio("headers", 0));
if ($access{'buser'}) {
# Only allow saving to file if a backup user is configured
print &ui_table_row($text{'csv_dest'},
&ui_radio("dest", 0, [ [ 0, $text{'csv_browser'}."
" ],
[ 1, $text{'csv_file'} ] ])."\n".
&ui_textbox("file", undef, 40)." ".
&file_chooser_button("file"));
}
# Rows to select
print &ui_table_row($text{'csv_where'},
&ui_opt_textbox("where", undef, 30, $text{'csv_all'}));
# Columns to select
@str = &table_structure($in{'db'}, $in{'table'});
@cols = map { $_->{'field'} } @str;
print &ui_table_row($text{'csv_cols'},
&ui_select("cols", \@cols,
[ map { [ $_->{'field'}, "$_->{'field'} - $_->{'type'}" ] } @str ], 5, 1));
print &ui_table_end();
print &ui_form_end([ [ "ok", $text{'csv_ok'} ] ]);
&ui_print_footer("edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'},
"", $text{'index_return'});
mysql/download.cgi 0100775 0005671 0000012 00000002151 10740467703 014213 0 ustar jcameron wheel #!/usr/local/bin/perl
# download.cgi
# Output the contents of a blob field
if (-r 'mysql-lib.pl') {
require './mysql-lib.pl';
}
else {
require './postgresql-lib.pl';
}
require './view-lib.pl';
&ReadParse();
&can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
@str = &table_structure($in{'db'}, $in{'table'});
# Get search and limiting SQL
($search, $searchhids, $searchargs) = &get_search_args(\%in);
$limitsql = &get_search_limit(\%in);
($sortsql, $sorthids, $sortargs) = &get_search_sort(\%in);
$d = &execute_sql($in{'db'},
"select * from "."e_table($in{'table'})." $search $limitsql $sortsql");
# Work out the MIME type based on the data
$data = $d->{'data'}->[$in{'row'}]->[$in{'col'}];
if ($data =~ /^\s*(