Handle hostnames with upper-case letters
[webmin.git] / bacula-backup / save_pool.cgi
1 #!/usr/local/bin/perl
2 # Create, update or delete a volume pool
3
4 require './bacula-backup-lib.pl';
5 &ReadParse();
6
7 if ($in{'status'}) {
8         # Go to status page
9         &redirect("poolstatus_form.cgi?pool=".&urlize($in{'old'}));
10         exit;
11         }
12
13 $conf = &get_director_config();
14 $parent = &get_director_config_parent();
15 @pools = &find("Pool", $conf);
16
17 if (!$in{'new'}) {
18         $pool = &find_by("Name", $in{'old'}, \@pools);
19         $pool || &error($text{'pool_egone'});
20         }
21 else {
22         $pool = { 'type' => 1,
23                   'name' => 'Pool',
24                   'members' => [ ] };
25         }
26
27 &lock_file($parent->{'file'});
28 if ($in{'delete'}) {
29         # Just delete this one
30         $name = &find_value("Name", $pool->{'members'});
31         $child = &find_dependency("Pool", $name, [ "Job", "JobDefs" ], $conf);
32         $child && &error(&text('pool_echild', $child));
33         &save_directive($conf, $parent, $pool, undef, 0);
34         }
35 else {
36         # Validate and store inputs
37         &error_setup($text{'pool_err'});
38         $in{'name'} =~ /\S/ || &error($text{'pool_ename'});
39         if ($in{'new'} || $in{'name'} ne $in{'old'}) {
40                 $clash = &find_by("Name", $in{'name'}, \@pools);
41                 $clash && &error($text{'pool_eclash'});
42                 }
43         &save_directive($conf, $pool, "Name", $in{'name'}, 1);
44         &save_directive($conf, $pool, "Pool Type", $in{'type'}, 1);
45
46         # Max volume jobs
47         if ($in{'maxmode'} == 0) {
48                 &save_directive($conf, $pool, "Maximum Volume Jobs", undef, 1);
49                 }
50         else {
51                 $in{'max'} =~ /^\d+$/ || &error($text{'pool_emax'});
52                 &save_directive($conf, $pool, "Maximum Volume Jobs", $in{'max'}, 1);
53                 }
54
55         # Retention period
56         $reten = &parse_period_input("reten");
57         $reten || &error($text{'pool_ereten'});
58         &save_directive($conf, $pool, "Volume Retention", $reten, 1);
59
60         # Save yes/no options
61         &save_directive($conf, $pool, "Recycle", $in{'recycle'} || undef, 1);
62         &save_directive($conf, $pool, "AutoPrune", $in{'auto'} || undef, 1);
63         if (&get_bacula_version_cached() < 2) {
64                 &save_directive($conf, $pool, "Accept Any Volume",
65                                 $in{'any'} || undef, 1);
66                 }
67         &save_directive($conf, $pool, "LabelFormat", $in{'autolabel'} || undef, 1);
68         &save_directive($conf, $pool, "Maximum Volume Bytes", $in{'maxvolsize'} || undef, 1);
69
70
71         # Create or update
72         if ($in{'new'}) {
73                 &save_directive($conf, $parent, undef, $pool, 0);
74                 }
75         }
76
77 &flush_file_lines();
78 &unlock_file($parent->{'file'});
79 &auto_apply_configuration();
80 &webmin_log($in{'new'} ? "create" : $in{'delete'} ? "delete" : "modify",
81             "pool", $in{'old'} || $in{'name'});
82 &redirect("list_pools.cgi");
83