3 # Clone an existing module under a new name
5 require './webmin-lib.pl';
7 &error_setup($text{'clone_err'});
9 # Symlink the code directory
11 %minfo = &get_module_info($src);
16 } while(-d "../$dst");
17 symlink($src, "../$dst") || &error(&text('clone_elink', $!));
19 # Symlink in the theme directory
20 if ($gconfig{'theme'}) {
21 unlink("../$gconfig{'theme'}/$dst");
22 symlink($src, "../$gconfig{'theme'}/$dst");
25 mkdir("$config_directory/$dst", 0700);
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'");
32 # Copy the config directory
33 $out = `( (cd $config_directory/$src ; tar cf - .) | (cd $config_directory/$dst ; tar xpf -) ) 2>&1`;
35 &error(&text('clone_ecopy', $out));
37 $in{'desc'} = &text('clone_desc', $minfo{'desc'}) if (!$in{'desc'});
39 &open_tempfile(CLONE, ">$config_directory/$dst/clone");
40 &print_tempfile(CLONE, "desc=$in{'desc'}\n");
41 &close_tempfile(CLONE);
43 # Delete .lock files from the config directory
44 system("(find '$config_directory/$dst' -name '*.lock' | xargs rm -f) >/dev/null 2>&1");
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);
54 &print_tempfile(ACL, "$u: ",join(' ', @mods),"\n");
58 if ($in{'cat'} ne '*') {
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");
67 &webmin_log("clone", undef, $in{'mod'}, { 'desc' => $minfo{'desc'},
69 'dstdesc' => $in{'desc'} });
70 &flush_webmin_caches();
71 &redirect("index.cgi?refresh=1");