1#!/usr/local/bin/perl 2# Save, delete or create a scheduled copy 3 4require './cluster-copy-lib.pl'; 5&error_setup($text{'save_err'}); 6&ReadParse(); 7 8if (!$in{'new'}) { 9 $copy = &get_copy($in{'id'}); 10 $job = &find_cron_job($copy); 11 } 12 13if ($in{'run'}) { 14 # Run the job now 15 &redirect("exec.cgi?id=$in{'id'}"); 16 exit; 17 } 18elsif ($in{'delete'}) { 19 # Just delete it 20 &delete_copy($copy); 21 if ($job) { 22 &lock_file(&cron::cron_file($job)); 23 &cron::delete_cron_job($job); 24 &unlock_file(&cron::cron_file($job)); 25 } 26 } 27else { 28 # Check and parse inputs 29 $in{'files'} =~ s/\r//g; 30 @files = split(/\n/, $in{'files'}); 31 foreach $f (@files) { 32 $f =~ /^\// || &error(&text('save_efile', $f)); 33 } 34 $copy->{'files'} = join("\t", @files); 35 @files || &error($text{'save_efiles'}); 36 $in{'dest'} =~ /^\// || &error($text{'save_edest'}); 37 if ($in{'email_def'}) { 38 $copy->{'email'} = ''; 39 } 40 else { 41 $in{'email'} =~ /^\S+$/ || &error($text{'save_eemail'}); 42 $copy->{'email'} = $in{'email'}; 43 } 44 $copy->{'dest'} = $in{'dest'}; 45 $copy->{'dmode'} = $in{'dmode'}; 46 $copy->{'before'} = $in{'before'}; 47 $copy->{'cmd'} = $in{'cmd'}; 48 $copy->{'beforelocal'} = !$in{'beforeremote'}; 49 $copy->{'cmdlocal'} = !$in{'cmdremote'}; 50 @servers = split(/\0/, $in{'servers'}); 51 @servers || &error($text{'save_eservers'}); 52 $copy->{'servers'} = join(" ", @servers); 53 $copy->{'sched'} = $in{'sched'}; 54 &cron::parse_times_input($copy, \%in); 55 56 # Save or create 57 &save_copy($copy); 58 if ($job) { 59 &lock_file(&cron::cron_file($job)); 60 &cron::delete_cron_job($job); 61 } 62 if ($in{'sched'}) { 63 &cron::create_wrapper($cron_cmd, $module_name, "copy.pl"); 64 $job = { 'user' => 'root', 65 'command' => "$cron_cmd $copy->{'id'}", 66 'active' => 1, 67 'mins' => $copy->{'mins'}, 68 'hours' => $copy->{'hours'}, 69 'days' => $copy->{'days'}, 70 'months' => $copy->{'months'}, 71 'weekdays' => $copy->{'weekdays'}, 72 'special' => $copy->{'special'} }; 73 &lock_file(&cron::cron_file($job)); 74 &cron::create_cron_job($job); 75 } 76 &unlock_file(&cron::cron_file($job)) if ($job); 77 } 78&webmin_log($in{'new'} ? 'create' : $in{'delete'} ? 'delete' : 'modify', 79 'copy', undef, $copy); 80&redirect(""); 81 82 83