Handle hostnames with upper-case letters
[webmin.git] / bacula-backup / save_client.cgi
1 #!/usr/local/bin/perl
2 # Create, update or delete a client
3
4 require './bacula-backup-lib.pl';
5 &ReadParse();
6
7 if ($in{'status'}) {
8         # Go to status page
9         &redirect("clientstatus_form.cgi?client=".&urlize($in{'old'}));
10         exit;
11         }
12
13 $conf = &get_director_config();
14 $parent = &get_director_config_parent();
15 @clients = &find("Client", $conf);
16
17 if (!$in{'new'}) {
18         $client = &find_by("Name", $in{'old'}, \@clients);
19         $client || &error($text{'client_egone'});
20         }
21 else {
22         $client = { 'type' => 1,
23                      'name' => 'Client',
24                      'members' => [ ] };
25         }
26
27 &lock_file($parent->{'file'});
28 if ($in{'delete'}) {
29         # Just delete this one
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{'client_err'});
38         $in{'name'} =~ /^\S+$/ || &error($text{'client_ename'});
39         if ($in{'new'} || $in{'name'} ne $in{'old'}) {
40                 $clash = &find_by("Name", $in{'name'}, \@clients);
41                 $clash && &error($text{'client_eclash'});
42                 }
43         &save_directive($conf, $client, "Name", $in{'name'}, 1);
44
45         $in{'pass'} || &error($text{'client_epass'});
46         &save_directive($conf, $client, "Password", $in{'pass'}, 1);
47
48         &to_ipaddress($in{'address'}) || &to_ip6address($in{'address'}) ||
49                 &error($text{'client_eaddress'});
50         &save_directive($conf, $client, "Address", $in{'address'}, 1);
51
52         $in{'port'} =~ /^\d+$/ && $in{'port'} > 0 && $in{'port'} < 65536 ||
53                 &error($text{'client_eport'});
54         &save_directive($conf, $client, "FDPort", $in{'port'}, 1);
55
56         &save_directive($conf, $client, "Catalog", $in{'catalog'}, 1);
57
58         &save_directive($conf, $client, "AutoPrune", $in{'prune'} || undef, 1);
59
60         $fileret = &parse_period_input("fileret");
61         $fileret || &error($text{'client_efileret'});
62         &save_directive($conf, $client, "File Retention", $fileret, 1);
63
64         $jobret = &parse_period_input("jobret");
65         $jobret || &error($text{'client_ejobret'});
66         &save_directive($conf, $client, "Job Retention", $jobret, 1);
67
68         # Save SSL options
69         &parse_tls_directives($conf, $client, 1);
70
71         # Create or update
72         if ($in{'new'}) {
73                 &save_directive($conf, $parent, undef, $client, 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             "client", $in{'old'} || $in{'name'});
82 &redirect("list_clients.cgi");
83