#!/tvbin/tivosh # vim: ft=tcl ai si # -*- TCL -*- # $Id: cmd.itcl,v 1.3 2002/08/08 20:32:38 aarons Exp $ proc action_command {chan path env} { global db global cancelreasons global tzoffset set q "" puts $chan [html_start "Run Command"] eval $env if {[string index $path 0] == "/"} { set path [string range $path 1 end] } puts $chan { } if { $q != "" } { set cmd $q } else { regsub -all {(%20|,)} $path " " cmd } puts $chan [html_form_start "GET" "/command" {onSubmit="hideShorts(this)" name="command"}] set canned "{}" if {$cmd != "" } { lappend canned $cmd } foreach c "{ps ax} {tnlited 23 /bin/bash --login &}" { if {$c != $cmd} { lappend canned $c } } set cmdIn [html_form_text 1 35 "q" $q] append cmdIn [html_form_input "submit" "submit" "Execute"] puts $chan [html_table_start "" "" ""] puts $chan [tr "" [th "Command"] [th "$cmdIn"]] # A popup menu of prebuilt commands to possibly be modified. # Use javascript to display it so that it doesn't show up if it won't work. set sel [html_form_select "canned" $canned $canned $cmd {onChange="setCommand(this)"}] set sel [tr "" [td "Shortcuts"] [td $sel]] regsub -all "\"" $sel {\"} sel puts $chan "" puts $chan [html_table_end] puts $chan [html_form_end] if {$cmd != "" } { puts $chan [html_table_start "" "Previous command" ""] puts $chan [tr "" [th "Command"]] puts $chan [tr "" [td $cmd]] set cmd "exec $cmd" set x [catch {eval $cmd} output] set output [htmlEncode $output] if {$x != 0} { puts $chan [tr "" [th "Status"]] puts $chan [tr "" [td "Failed"]] } puts $chan [tr "" [th "Output"]] puts $chan [tr "" [td "
$output"]] puts $chan [html_table_end] } puts $chan [html_end] } register_module "command" "Command" "Run shell commands"