Handle hostnames with upper-case letters
[webmin.git] / bacula-backup / save_schedule.cgi
1 #!/usr/local/bin/perl
2 # Create, update or delete a backup schedule
3
4 require './bacula-backup-lib.pl';
5 &ReadParse();
6 $conf = &get_director_config();
7 $parent = &get_director_config_parent();
8 @schedules = &find("Schedule", $conf);
9
10 if (!$in{'new'}) {
11         $schedule = &find_by("Name", $in{'old'}, \@schedules);
12         $schedule || &error($text{'schedule_egone'});
13         }
14 else {
15         $schedule = { 'type' => 1,
16                      'name' => 'Schedule',
17                      'members' => [ ] };
18         }
19
20 &lock_file($parent->{'file'});
21 if ($in{'delete'}) {
22         # Just delete this one
23         $name = &find_value("Name", $schedule->{'members'});
24         $child = &find_dependency("Schedule", $name, [ "Job", "JobDefs" ], $conf);
25         $child && &error(&text('schedule_echild', $child));
26         &save_directive($conf, $parent, $schedule, undef, 0);
27         }
28 else {
29         # Validate and store inputs
30         &error_setup($text{'schedule_err'});
31         $in{'name'} =~ /\S/ || &error($text{'schedule_ename'});
32         if ($in{'new'} || $in{'name'} ne $in{'old'}) {
33                 $clash = &find_by("Name", $in{'name'}, \@schedules);
34                 $clash && &error($text{'schedule_eclash'});
35                 }
36         &save_directive($conf, $schedule, "Name", $in{'name'}, 1);
37
38         # Parse and save run times
39         for($i=0; defined($level = $in{"level_$i"}); $i++) {
40                 next if (!$level);
41                 $times = $in{"times_$i"};
42                 $times =~ /\S/ || &error(&text('schedule_etimes', $i+1));
43                 push(@runs, "Level=$level ".
44                             ($in{"pool_$i"} ? "Pool=".$in{"pool_$i"}." " : "").
45                             $times);
46                 }
47         &save_directives($conf, $schedule, "Run", \@runs, 1);
48
49         # Create or update
50         if ($in{'new'}) {
51                 &save_directive($conf, $parent, undef, $schedule, 0);
52                 }
53         }
54
55 &flush_file_lines();
56 &unlock_file($parent->{'file'});
57 &auto_apply_configuration();
58 &webmin_log($in{'new'} ? "create" : $in{'delete'} ? "delete" : "modify",
59             "schedule", $in{'old'} || $in{'name'});
60 &redirect("list_schedules.cgi");
61