Fix <directory> when updating document root
authorJamie Cameron <jcameron@webmin.com>
Tue, 9 Sep 2008 17:38:34 +0000 (17:38 +0000)
committerJamie Cameron <jcameron@webmin.com>
Tue, 9 Sep 2008 17:38:34 +0000 (17:38 +0000)
apache/CHANGELOG
apache/save_vserv.cgi
apache/virt_index.cgi

index a716130..1660390 100644 (file)
@@ -39,3 +39,5 @@ Available Apache modules are now fully automatically detected on all operating s
 Moved the SSL password option to the global settings level, to correspond with the way Apache expects it.
 ---- Changes since 1.410 ----
 Added support for the funny ${APACHE_RUN_USER} and ${APACHE_PID_FILE} variables seen in apache2.conf on Ubuntu 8.04.
+---- Changes since 1.430 ----
+When a virtual host's base directory is changed, all <directory> blocks under it are updated too.
index 58a9f37..ea603e3 100755 (executable)
@@ -106,7 +106,26 @@ else {
        &save_directive("ServerName", $name ? [ $name ] : [ ],
                        $vconf->{'members'}, $conf);
 
-       # write out file
+       # Update any <Directory> blocks under the old path
+       if ($in{'root'} ne $in{'old_root'}) {
+               @dirs = &find_directive_struct("Directory", $vmembers);
+               foreach $dir (@dirs) {
+                       if ($dir->{'words'}->[0] eq $in{'old_root'}) {
+                               # Same dir
+                               $dir->{'value'} = $in{'root'};
+                               }
+                       elsif ($dir->{'words'}->[0] =~ /^\Q$in{'old_root'}\E(\/.*)$/) {
+                               # Under the dir
+                               $dir->{'value'} = $in{'root'}.$1;
+                               }
+                       else {
+                               next;
+                               }
+                       &save_directive_struct($dir, $dir, $vconf, $vconf, 1);
+                       }
+               }
+
+       # Write out file
        &flush_file_lines();
        &after_changing();
        &unlock_file($vconf->{'file'});
index fdffacc..7ea87f2 100755 (executable)
@@ -102,6 +102,7 @@ if ($in{'virt'} && $access{'vaddr'}) {
        else { $addr = $val; }
 
        if ($addrs) {
+               # Multiple addresses and ports
                print &ui_table_row($text{'vserv_addrs'},
                        &ui_textarea("addrs", join("\n", split(/\s+/, $addrs)),
                                    4, 30));
@@ -130,6 +131,7 @@ if ($in{'virt'} && $access{'vaddr'}) {
                &opt_input($root->{'words'}->[0], "root",
                                          $text{'vserv_default'}, 50).
                &file_chooser_button("root", 1, 1));
+       print &ui_hidden("old_root", $root->{'words'}->[0]);
 
        # Server name
        $name = &find_directive("ServerName", $v->{'members'});