diff --git a/cron/cron-lib.pl b/cron/cron-lib.pl index c99bab047..145770907 100755 --- a/cron/cron-lib.pl +++ b/cron/cron-lib.pl @@ -19,8 +19,7 @@ use WebminCore; $env_support = $config{'vixie_cron'}; if ($module_info{'usermin'}) { $single_user = $remote_user; - &switch_to_remote_user() - if (!getvar('cron_no_switch_to_remote_user')); + &switch_to_remote_user(); &create_user_config_dirs(); $range_cmd = "$user_module_config_directory/range.pl"; $hourly_only = 0; diff --git a/xterm/index.cgi b/xterm/index.cgi index 90bf3d73c..6fdb8a630 100755 --- a/xterm/index.cgi +++ b/xterm/index.cgi @@ -184,12 +184,9 @@ my @uinfo = getpwnam($user); my $dir = $in{'dir'}; # Launch the shell server on the allocated port -setvar('cron_no_switch_to_remote_user', 1) - if (&get_product_name() eq 'usermin'); -&foreign_require("cron"); my $shellserver_cmd = "$module_config_directory/shellserver.pl"; if (!-r $shellserver_cmd) { - &cron::create_wrapper($shellserver_cmd, $module_name, "shellserver.pl"); + &create_wrapper_local($shellserver_cmd, $module_name, "shellserver.pl"); } my $tmpdir = &tempname_dir(); $ENV{'SESSION_ID'} = $main::session_id; diff --git a/xterm/websockets-lib-funcs.pl b/xterm/websockets-lib-funcs.pl index f431198e3..7abc2b045 100644 --- a/xterm/websockets-lib-funcs.pl +++ b/xterm/websockets-lib-funcs.pl @@ -97,4 +97,47 @@ if (@clean) { &unlock_file(&get_miniserv_config_file()); } +# create_wrapper_local(wrapper-path, module, script) +# Export from Cron module to create a wrapper script +sub create_wrapper_local +{ +local $perl_path = &get_perl_path(); +&open_tempfile(CMD, ">$_[0]"); +&print_tempfile(CMD, <) { + \$root = \$1 if (/^root=(.*)/); + } +close(CONF); +\$root || die "No root= line found in $config_directory/miniserv.conf"; +\$ENV{'PERLLIB'} = "\$root"; +\$ENV{'WEBMIN_CONFIG'} = "$ENV{'WEBMIN_CONFIG'}"; +\$ENV{'WEBMIN_VAR'} = "$ENV{'WEBMIN_VAR'}"; +delete(\$ENV{'MINISERV_CONFIG'}); +EOF + ); +if ($gconfig{'os_type'} eq 'windows') { + # On windows, we need to chdir to the drive first, and use system + &print_tempfile(CMD, "if (\$root =~ /^([a-z]:)/i) {\n"); + &print_tempfile(CMD, " chdir(\"\$1\");\n"); + &print_tempfile(CMD, " }\n"); + &print_tempfile(CMD, "chdir(\"\$root/$_[1]\");\n"); + &print_tempfile(CMD, "exit(system(\"\$root/$_[1]/$_[2]\", \@ARGV));\n"); + } +else { + # Can use exec on Unix systems + if ($_[1]) { + &print_tempfile(CMD, "chdir(\"\$root/$_[1]\");\n"); + &print_tempfile(CMD, "exec(\"\$root/$_[1]/$_[2]\", \@ARGV) || die \"Failed to run \$root/$_[1]/$_[2] : \$!\";\n"); + } + else { + &print_tempfile(CMD, "chdir(\"\$root\");\n"); + &print_tempfile(CMD, "exec(\"\$root/$_[2]\", \@ARGV) || die \"Failed to run \$root/$_[2] : \$!\";\n"); + } + } +&close_tempfile(CMD); +chmod(0755, $_[0]); +} + 1; \ No newline at end of file