Handle hostnames with upper-case letters
[webmin.git] / webmin / clone_mod.cgi
1 #!/usr/local/bin/perl
2 # clone_mod.cgi
3 # Clone an existing module under a new name
4
5 require './webmin-lib.pl';
6 &ReadParse();
7 &error_setup($text{'clone_err'});
8
9 # Symlink the code directory
10 $src = $in{'mod'};
11 %minfo = &get_module_info($src);
12 $count = 2;
13 do {
14         $dst = $src.$count;
15         $count++;
16         } while(-d "../$dst");
17 symlink($src, "../$dst") || &error(&text('clone_elink', $!));
18
19 # Symlink in the theme directory
20 if ($gconfig{'theme'}) {
21         unlink("../$gconfig{'theme'}/$dst");
22         symlink($src, "../$gconfig{'theme'}/$dst");
23         }
24
25 mkdir("$config_directory/$dst", 0700);
26 if ($in{'reset'}) {
27         # Setup config directory from scratch
28         $perl = &get_perl_path();
29         system("cd $root_directory ; $perl $root_directory/copyconfig.pl '$gconfig{'os_type'}' '$gconfig{'os_version'}' '$root_directory' '$config_directory' '$dst'");
30         }
31 else {
32         # Copy the config directory
33         $out = `( (cd $config_directory/$src ; tar cf - .) | (cd $config_directory/$dst ; tar xpf -) ) 2>&1`;
34         if ($?) {
35                 &error(&text('clone_ecopy', $out));
36                 }
37         $in{'desc'} = &text('clone_desc', $minfo{'desc'}) if (!$in{'desc'});
38         }
39 &open_tempfile(CLONE, ">$config_directory/$dst/clone");
40 &print_tempfile(CLONE, "desc=$in{'desc'}\n");
41 &close_tempfile(CLONE);
42
43 # Delete .lock files from the config directory
44 system("(find '$config_directory/$dst' -name '*.lock' | xargs rm -f) >/dev/null 2>&1");
45
46 # Grant access to the clone to this user
47 &read_acl(undef, \%acl);
48 &open_tempfile(ACL, "> ".&acl_filename());
49 foreach $u (keys %acl) {
50         my @mods = @{$acl{$u}};
51         if ($u eq $base_remote_user) {
52                 @mods = &unique(@mods, $dst);
53                 }
54         &print_tempfile(ACL, "$u: ",join(' ', @mods),"\n");
55         }
56 &close_tempfile(ACL);
57
58 if ($in{'cat'} ne '*') {
59         # Assign to category
60         &lock_file("$config_directory/webmin.cats");
61         &read_file("$config_directory/webmin.cats", \%cats);
62         $cats{$dst} = $in{'cat'};
63         &write_file("$config_directory/webmin.cats", \%cats);
64         &unlock_file("$config_directory/webmin.cats");
65         }
66
67 &webmin_log("clone", undef, $in{'mod'}, { 'desc' => $minfo{'desc'},
68                                           'dst' => $dst,
69                                           'dstdesc' => $in{'desc'} });
70 &flush_webmin_caches();
71 &redirect("index.cgi?refresh=1");
72