3 # Show the shell user interface
6 require './shell-lib.pl';
7 %access = &get_module_acl();
8 &ReadParseMime() if ($ENV{'REQUEST_METHOD'} ne 'GET');
9 &ui_print_header(undef, $text{'index_title'}, "", undef,
10 $module_info{'usermin'} ? 0 : 1, 1,
12 "onLoad='window.scroll(0, 10000); document.forms[0].cmd.focus()'");
14 $prevfile = "$module_config_directory/previous.$remote_user";
15 if ($in{'clearcmds'}) {
16 &lock_file($prevfile);
18 &unlock_file($prevfile);
22 open(PREVFILE, $prevfile);
23 chop(@previous = <PREVFILE>);
26 $cmd = $in{'doprev'} ? $in{'pcmd'} : $in{'cmd'};
32 if ($gconfig{'os_type'} eq 'windows') {
33 # Initial directory is c:/
37 # Initial directory is user's home
38 local @uinfo = getpwnam($access{'user'} || $remote_user);
39 $pwd = scalar(@uinfo) && -d $uinfo[7] ? $uinfo[7] : "/";
43 $history = &un_urlize($in{'history'});
45 # Execute the latest command
48 $history .= "<b>> ".&html_escape($cmd, 1)."</b>\n";
49 if ($cmd =~ /^cd\s+"([^"]+)"\s*(;?\s*(.*))$/ ||
50 $cmd =~ /^cd\s+'([^']+)'\s*(;?\s*(.*))$/ ||
51 $cmd =~ /^cd\s+([^; ]*)\s*(;?\s*(.*))$/) {
54 $history .= &html_escape("$1: $!\n", 1);
58 $pwd = &get_current_dir();
62 local $user = $access{'user'} || $remote_user;
63 &clean_environment() if ($config{'clear_envs'});
64 delete($ENV{'SCRIPT_NAME'}); # So that called Webmin
65 # programs get the right
66 # module, not this one!
67 if (&supports_users()) {
68 $out = &backquote_logged(
69 &command_as_user($user, 0, $cmd)." 2>&1");
72 $out = &backquote_logged("($cmd) 2>&1");
74 &reset_environment() if ($config{'clear_envs'});
75 $out = &html_escape($out, 1);
78 @previous = &unique(@previous, $fullcmd);
79 &lock_file($prevfile);
80 &open_tempfile(PREVFILE, ">>$prevfile");
81 &print_tempfile(PREVFILE, $fullcmd,"\n");
82 &close_tempfile(PREVFILE);
83 &unlock_file($prevfile);
84 &webmin_log("run", undef, undef, { 'cmd' => $fullcmd });
88 # Show the history and command input
90 print &ui_table_start($text{'shell_history'}, "width=100%", 2);
91 print &ui_table_row(undef, "<pre>$history</pre>", 2);
92 print &ui_table_end();
96 print "$text{'index_desc'}<br>\n";
97 print &ui_form_start("index.cgi", "form-data");
99 print "<table width=100%><tr>\n";
102 print "<td width=10%>",&ui_submit($text{'index_ok'}),"</td>\n";
103 print "<td>",&ui_textbox("cmd", undef, 50, 0, undef,
104 "style='width:100%'"),"</td>\n";
105 print "<td align=right width=10%>",&ui_submit($text{'index_clear'}, "clear"),
109 print &ui_hidden("pwd", $pwd);
110 print &ui_hidden("history", &urlize($history));
111 foreach $p (@previous) {
112 print &ui_hidden("previous", $p);
115 # Previous command menu
118 print "<td width=10%>",&ui_submit($text{'index_pok'}, "doprev"),
120 print "<td>",&ui_select("pcmd", undef,
121 [ reverse(@previous) ]);
122 print "<input type=button name=movecmd ",
123 "value='$text{'index_edit'}' ",
124 "onClick='cmd.value = pcmd.options[pcmd.selectedIndex].value'>\n";
126 print "<td align=right width=10%>",
127 &ui_submit($text{'index_clearcmds'}, "clearcmds"),"</td>\n";
131 print &ui_form_end();
133 &ui_print_footer("/", $text{'index'});