summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/drakbackup
diff options
context:
space:
mode:
authorStew Benedict <stewb@mandriva.org>2004-02-10 15:34:54 +0000
committerStew Benedict <stewb@mandriva.org>2004-02-10 15:34:54 +0000
commit2bc8a0f15540d93d6a4011a3a6b679f4ed1612bd (patch)
tree252967a8b0c888b1fc936fca27fe2c664ce32349 /perl-install/standalone/drakbackup
parent9837fad1b71f1809b333c2adb49ee8f39adc55f4 (diff)
downloaddrakx-backup-do-not-use-2bc8a0f15540d93d6a4011a3a6b679f4ed1612bd.tar
drakx-backup-do-not-use-2bc8a0f15540d93d6a4011a3a6b679f4ed1612bd.tar.gz
drakx-backup-do-not-use-2bc8a0f15540d93d6a4011a3a6b679f4ed1612bd.tar.bz2
drakx-backup-do-not-use-2bc8a0f15540d93d6a4011a3a6b679f4ed1612bd.tar.xz
drakx-backup-do-not-use-2bc8a0f15540d93d6a4011a3a6b679f4ed1612bd.zip
Use logdrake mail method, allow definition of SMTP server. (Arnaud de Lorbeau)
Diffstat (limited to 'perl-install/standalone/drakbackup')
-rwxr-xr-xperl-install/standalone/drakbackup58
1 files changed, 41 insertions, 17 deletions
diff --git a/perl-install/standalone/drakbackup b/perl-install/standalone/drakbackup
index c6b7db182..eceba65de 100755
--- a/perl-install/standalone/drakbackup
+++ b/perl-install/standalone/drakbackup
@@ -145,6 +145,7 @@ my $tape_norewind = 0;
my $no_critical_sys = 1;
my $send_mail = 0;
my $user_mail;
+my $smtp_server = "localhost";
my $scp_port = 22;
my $use_expect = 0;
my $xfer_keys = 0;
@@ -199,7 +200,7 @@ sub setup_tooltips() {
'use_incr_decr' => N("This option will save files that have changed. Exact behavior depends on whether incremental or differential mode is used."),
'use_incremental' => N("Incremental backups only save files that have changed or are new since the last backup."),
'use_differential' => N("Differential backups only save files that have changed or are new since the original 'base' backup."),
- 'send_mail_to' => N("This should be a comma-separated list of local users or email addresses that you want the backup results sent to. You will need a functioning mail transfer agent setup on your system."),
+ 'send_mail_to' => N("This should be a local user or email addresse that you want the backup results sent to. You will need to define a functioning mail server."),
'backupignore' => N("Files or wildcards listed in a .backupignore file at the top of a directory tree will not be backed up."),
'delete_files' => N("For backups to other media, files are still created on the hard drive, then moved to the other media. Enabling this option will remove the hard drive tar files after the backup."),
'dir_or_module' => N("Some protocols, like rsync, may be configured at the server end. Rather than using a directory path, you would use the 'module' name for the service path."),
@@ -494,6 +495,7 @@ sub get_cd_info() {
sub save_conf_file() {
write_sitecopyrc() if $net_proto eq 'webdav';
write_password_file() if $net_proto eq 'rsync' && $passwd_user;
+ return 1 if $send_mail && verify_mail_setup();
if (!$backup_daemon) {
$when_space = "";
$daemon_media = "";
@@ -511,6 +513,7 @@ sub save_conf_file() {
"NET_PROTO=$net_proto\n",
"CD_TIME=$cd_time\n",
"USER_MAIL=$user_mail\n",
+ "SMTP_SERVER=$smtp_server\n",
"CD_DEVICE=$cd_device\n",
"LOGIN=$login_user\n",
"TAPE_DEVICE=$tape_device\n",
@@ -675,6 +678,7 @@ sub read_conf_file() {
if (/^LOGIN/) { s/^LOGIN=//gi; $login_user = $_ }
if (/^PASSWD/) { s/^PASSWD=//gi; $passwd_user = $_; $remember_pass = 1 }
if (/^USER_MAIL/) { s/^USER_MAIL=//gi; $user_mail = $_ }
+ if (/^SMTP_SERVER/) { s/^SMTP_SERVER=//gi; $smtp_server = $_ }
if (/^SEND_MAIL/) { $send_mail = 1 }
if (/^TAPE_DEVICE/) { s/TAPE_DEVICE=//gi; $tape_device = $_ }
if (/^MEDIA_ERASE/) { $media_erase = 1 }
@@ -705,6 +709,18 @@ sub read_conf_file() {
check_valid_users() if $cfg_file_exist;
}
+sub verify_mail_setup() {
+ all_user_list() if @user_list_all == ();
+ if ($user_mail ne "root" && $user_mail !~ /[\w.-]*\@[\w.-]/ && !member($user_mail, @user_list_all)) {
+ show_warning("f", N("\"%s\" neither is a valid email nor is an existing local user!", $user_mail));
+ return 1;
+ }
+ if (member($user_mail, @user_list_all) && $smtp_server ne "localhost") {
+ show_warning("f", N("\"%s\" is a local user, but you did not select a local smtp, so you must use a complete email address!", $user_mail));
+ return 1;
+ }
+}
+
sub check_valid_users() {
all_user_list();
my @new_user_list = intersection(\@user_list, \@user_list_all);
@@ -1161,20 +1177,19 @@ sub build_tape() {
}
}
-# share this with logdrake
sub send_mail {
my ($result) = @_;
- my $datem = `date`;
-
- local *F;
- open F, "|/usr/sbin/sendmail -f$user_mail $user_mail" or return 1;
- print F "From: drakbackup\n";
- print F "To: $user_mail \n";
- print F "Subject: DrakBackup report on $datem \n";
- print F "\n";
- print F "$result\n";
- close F or return 1;
- return 0;
+ my $datem = `date`;
+ use Mail::Mailer;
+ my $mailer = Mail::Mailer->new('smtp', Server => $smtp_server);
+ $mailer->open({ From => 'drakbackup',
+ To => $user_mail,
+ Subject => "DrakBackup report on $datem",
+ })
+ or return 1;
+ print $mailer $result;
+ $mailer->close;
+ 0;
}
sub build_backup_files() {
@@ -1472,7 +1487,7 @@ sub build_backup_files() {
if ($send_mail) {
if (send_mail($results)) {
- $interactive and $in->ask_warn(N("Error"), N("Error during sendmail. Your report mail was not sent. Please configure sendmail"));
+ $interactive and $in->ask_warn(N("Error"), N("Error sending mail. Your report mail was not sent."));
$interactive or print N(" Error while sending mail. \n");
}
}
@@ -2549,7 +2564,7 @@ sub combo_to_cron_string {
sub advanced_options() {
my $box_options;
-
+
gtkpack($advanced_box,
$box_options = gtkpack_(new Gtk2::VBox(0, 15),
0, my $check_tar_bz2 = new Gtk2::CheckButton(N("Use tar and bzip2 (rather than tar and gzip)")),
@@ -2557,7 +2572,13 @@ sub advanced_options() {
0, gtkpack_(new Gtk2::HBox(0,10),
0, my $check_mail = new Gtk2::CheckButton(N("Send mail report after each backup to:")),
1, new Gtk2::HBox(0,10),
- 0, my $mail_entry = new Gtk2::Entry(),
+ 0, gtkset_sensitive(my $mail_entry = new Gtk2::Entry(), $send_mail),
+ ),
+ 0, gtkpack_(new Gtk2::HBox(0,10),
+ 1, new Gtk2::HBox(0,10),
+ 0, N("SMTP server for mail:"),
+ 1, new Gtk2::HBox(0,10),
+ 0, gtkset_sensitive(my $smtp_entry = new Gtk2::Entry(), $send_mail),
),
0, gtkpack_(new Gtk2::HBox(0,10),
0, my $check_del_hd_files = new Gtk2::CheckButton(N("Delete Hard Drive tar files after backup to other media.")),
@@ -2567,6 +2588,8 @@ sub advanced_options() {
check_list([$check_mail, \$send_mail], [$check_tar_bz2, \$comp_mode], [$check_del_hd_files, \$del_hd_files], [$check_backupignore, \$backupignore]);
$mail_entry->set_text($user_mail);
$mail_entry->signal_connect('changed', sub { $user_mail = $mail_entry->get_text });
+ $smtp_entry->set_text($smtp_server);
+ $smtp_entry->signal_connect('changed', sub { $smtp_server = $smtp_entry->get_text });
set_help_tip($check_backupignore, 'backupignore');
set_help_tip($check_mail, 'send_mail_to');
set_help_tip($check_del_hd_files, 'delete_files');
@@ -2890,7 +2913,8 @@ sub system_state() {
}
$system_state .= N("\tUse .backupignore files\n") if $backupignore;
- $system_state .= N("\tSend mail to %s\n", $user_mail) if $user_mail;
+ $system_state .= N("\tSend mail to %s\n", $user_mail) if $send_mail;
+ $system_state .= N("\tUsing SMTP server %s\n", $smtp_server) if $send_mail;
$daemon_media and $system_state .= N("\n- Daemon, %s via:\n", $when_space);
$daemon_media eq 'hd' and $system_state .= N("\t-Hard drive.\n");