Handle hostnames with upper-case letters
[webmin.git] / bacula-backup / save_fdirector.cgi
1 #!/usr/local/bin/perl
2 # Create, update or delete a file daemon director
3
4 require './bacula-backup-lib.pl';
5 &ReadParse();
6
7 $conf = &get_file_config();
8 $parent = &get_file_config_parent();
9 @fdirectors = &find("Director", $conf);
10
11 if (!$in{'new'}) {
12         $fdirector = &find_by("Name", $in{'old'}, \@fdirectors);
13         $fdirector || &error($text{'fdirector_egone'});
14         }
15 else {
16         $fdirector = { 'type' => 1,
17                      'name' => 'Director',
18                      'members' => [ ] };
19         }
20
21 &lock_file($parent->{'file'});
22 if ($in{'delete'}) {
23         # Just delete this one
24         $name = &find_value("Name", $fdirector->{'members'});
25         &save_directive($conf, $parent, $fdirector, undef, 0);
26         }
27 else {
28         # Validate and store inputs
29         &error_setup($text{'fdirector_err'});
30         $in{'name'} =~ /\S/ || &error($text{'fdirector_ename'});
31         if ($in{'new'} || $in{'name'} ne $in{'old'}) {
32                 $clash = &find_by("Name", $in{'name'}, \@fdirectors);
33                 $clash && &error($text{'fdirector_eclash'});
34                 }
35         &save_directive($conf, $fdirector, "Name", $in{'name'}, 1);
36
37         $in{'pass'} || &error($text{'fdirector_epass'});
38         &save_directive($conf, $fdirector, "Password", $in{'pass'}, 1);
39
40         &save_directive($conf, $fdirector, "Monitor",
41                         $in{'monitor'} || undef, 1);
42
43         # Save SSL options
44         &parse_tls_directives($conf, $fdirector, 1);
45
46         # Create or update
47         if ($in{'new'}) {
48                 &save_directive($conf, $parent, undef, $fdirector, 0);
49                 }
50         }
51
52 &flush_file_lines();
53 &unlock_file($parent->{'file'});
54 &auto_apply_configuration();
55 &webmin_log($in{'new'} ? "create" : $in{'delete'} ? "delete" : "modify",
56             "fdirector", $in{'old'} || $in{'name'});
57 &redirect("list_fdirectors.cgi");
58