Handle hostnames with upper-case letters
[webmin.git] / proftpd / save_vserv.cgi
1 #!/usr/local/bin/perl
2 # save_vserv.cgi
3 # Save virtual server options such as the port and address
4
5 require './proftpd-lib.pl';
6 &ReadParse();
7 $conf = &get_config();
8 $vconf = $conf->[$in{'virt'}];
9
10 if ($in{'delete'}) {
11         # Delete a virtual server
12         &lock_file($vconf->{'file'});
13         &before_changing();
14         $lref = &read_file_lines($vconf->{'file'});
15         splice(@$lref, $vconf->{'line'},
16                $vconf->{'eline'} - $vconf->{'line'} + 1);
17         &flush_file_lines();
18         &after_changing();
19         &unlock_file($vconf->{'file'});
20         &webmin_log("virt", "delete", $vconf->{'value'});
21         &redirect("");
22         }
23 else {
24         # Update virtual server and directives
25         &error_setup($text{'vserv_err'});
26
27         # Check inputs
28         &to_ipaddress($in{'addr'}) || &to_ip6address($in{'addr'}) ||
29                 &error($text{'vserv_eaddr'});
30         $in{'Port_def'} || $in{'Port'} =~ /^\d+$/ ||
31                 &error($text{'vserv_eport'});
32         $in{'ServerName_def'} || $in{'ServerName'} =~ /\S/ ||
33                 &error($text{'vserv_ename'});
34
35         # Update <VirtualHost> directive
36         &lock_file($vconf->{'file'});
37         &before_changing();
38         $lref = &read_file_lines($vconf->{'file'});
39         $lref->[$vconf->{'line'}] = "<VirtualHost $in{'addr'}>";
40
41         # Update DocumentRoot and ServerName
42         &save_directive("ServerName", $in{'ServerName_def'} ? [ ] :
43                                       [ "\"$in{'ServerName'}\"" ], 
44                         $vconf->{'members'}, $conf);
45         &save_directive("Port", $in{'Port_def'} ? [ ] : [ $in{'Port'} ],
46                         $vconf->{'members'}, $conf);
47
48         # write out file
49         &flush_file_lines();
50         &after_changing();
51         &unlock_file($vconf->{'file'});
52         &webmin_log("virt", "save", $vconf->{'value'}, \%in);
53         &redirect("virt_index.cgi?virt=$in{'virt'}");
54         }
55