Hello ,
I’m current developing a module and I’m stuck. I wanted to create a cgi page that acts as a pseudo terminal interfacing with a local rcon-client .
Here is what should happen:
- Upon opening the page, the executable
$rcon{"bin"}
should be run and every output should be routed to a<pre>
tag, and if the process gets terminated (by any means) output that. - The user is offered a text input and a “send” button to submit a command. (Alternatively the user should be able to write inside the pseudo terminal)
- All output should be preserved as long as the user is on the page
- The process should be exited when the user leaves the page
Here is what I’ve got so far:
I’ve got the form and will probably use javascript to hook into it, since a POST refreshes the page and the output gets deleted. I’ve seen the proc
lib and I’m not sure how to exactly get the pty_process_exec
going, basically being stuck at the first step (I tested a little bit with wait_for
around, but i’m not sure)
#!/usr/bin/perl
# custom_rcon.cgi
# Webinterface for rcon terminal
require "./paldmin-ui-lib.pl";
require "./paldmin-lib.pl";
require "./rcon-lib.pl";
ReadParse();
ui_print_unbuffered_header($text{"glop_rcon"}, $text{"index_title"}, "");
if (defined $rcon{"msg"}{"content"}) {
alert_box($rcon{"msg"}{"type"}, "", $rcon{"msg"}{"content"});
ui_print_footer("", $text{"index_return"});
exit;
} elsif (!foreign_installed("proc")) {
alert_box($rcon{"msg"}{"type"}, "", $text{"custom_missing_proc"});
ui_print_footer("", $text{"index_return"});
exit;
} elsif (!$rcon{"valid"}) {
ui_print_footer("", $text{"index_return"});
exit;
}
collapsible_box("info", $text{"info"}, $text{"custom_info"});
# Command Block
print ui_subheading($text{"glop_rcon_cc"});
print ui_textbox("msg", undef, 40, (!$rcon{"valid"}));
# How to hook the button to syswrite ?
print ui_button(
$text{"send"},
"cmd",
(!$rcon{"valid"}),
"onClick='alert(\"Test\");'"
);
print $text{"index_broadcast_desc"};
print "<br/><br/>";
foreign_require("proc");
proc::clean_environment();
my ($fh, $fpid) = proc::pty_process_exec($rcon{"bin"}, 0, 0);
proc::reset_environment();
# What exactly goes here?
print "<pre>";
print "FH:".$fh." - PID: ".$fpid."<br/>";
print "</pre>";
ui_print_footer("", $text{"index_return"});
1;
Any help is appreciated
KR