Handle hostnames with upper-case letters
[webmin.git] / bacula-backup / save_group.cgi
1 #!/usr/local/bin/perl
2 # Create, update or delete a special client used as a group
3
4 require './bacula-backup-lib.pl';
5 &ReadParse();
6
7 $conf = &get_director_config();
8 $parent = &get_director_config_parent();
9 @clients = &find("Client", $conf);
10
11 # Get node group
12 @nodegroups = &list_node_groups();
13 $ngname = $in{'old'} || $in{'new'};
14 ($nodegroup) = grep { $_->{'name'} eq $ngname } @nodegroups;
15
16 if (!$in{'new'}) {
17         $client = &find_by("Name", "ocgroup_".$in{'old'}, \@clients);
18         $client || &error($text{'group_egone'});
19         }
20 else {
21         $client = { 'type' => 1,
22                      'name' => 'Client',
23                      'members' => [ ] };
24         }
25
26 &lock_file($parent->{'file'});
27 if ($in{'delete'}) {
28         # Just delete this one
29         # XXX
30         #$name = &find_value("Name", $client->{'members'});
31         #$child = &find_dependency("Client", $name, [ "Job", "JobDefs" ], $conf);
32         #$child && &error(&text('client_echild', $child));
33         &save_directive($conf, $parent, $client, undef, 0);
34         }
35 else {
36         # Validate and store inputs
37         &error_setup($text{'group_err'});
38         if ($in{'new'}) {
39                 &save_directive($conf, $client, "Name", "ocgroup_".$in{'new'}, 1);
40                 $clash = &find_by("Name", "ocgroup_".$in{'name'}, \@clients);
41                 $clash && &error($text{'group_eclash'});
42                 }
43
44         &save_directive($conf, $client, "Address", "localhost", 1);
45
46         $in{'pass'} || &error($text{'client_epass'});
47         &save_directive($conf, $client, "Password", $in{'pass'}, 1);
48
49         $in{'port'} =~ /^\d+$/ && $in{'port'} > 0 && $in{'port'} < 65536 ||
50                 &error($text{'client_eport'});
51         &save_directive($conf, $client, "FDPort", $in{'port'}, 1);
52
53         &save_directive($conf, $client, "Catalog", $in{'catalog'}, 1);
54
55         &save_directive($conf, $client, "AutoPrune", $in{'prune'} || undef, 1);
56
57         $fileret = &parse_period_input("fileret");
58         $fileret || &error($text{'client_efileret'});
59         &save_directive($conf, $client, "File Retention", $fileret, 1);
60
61         $jobret = &parse_period_input("jobret");
62         $jobret || &error($text{'client_ejobret'});
63         &save_directive($conf, $client, "Job Retention", $jobret, 1);
64
65         # Create or update
66         if ($in{'new'}) {
67                 &save_directive($conf, $parent, undef, $client, 0);
68                 }
69         }
70
71 if ($nodegroup) {
72         # Force update to all dependent clients
73         &sync_group_clients($nodegroup);
74         }
75
76 &flush_file_lines();
77 &unlock_file($parent->{'file'});
78 &auto_apply_configuration();
79 &webmin_log($in{'new'} ? "create" : $in{'delete'} ? "delete" : "modify",
80             "group", $ngname);
81 &redirect("list_groups.cgi");
82