Add config options for width and height

This commit is contained in:
Jamie Cameron
2022-10-22 23:17:21 -07:00
parent acec438536
commit 8cdd3eeeab
7 changed files with 34 additions and 13 deletions

View File

@@ -1 +1,3 @@
base_port=555
cols=80
rows=24

View File

@@ -1 +1,3 @@
base_port=Base port number for Websockets connections,0
base_port=Base port number for Websockets connections,0,5
cols=Terminal width in characters,0,5
rows=Terminal height in characters,0,5

View File

@@ -1,11 +1,12 @@
#!/usr/local/bin/perl
# Show a terminal that is connected to a Websockets server via Webmin proxying
# XXX clean up old proxy ports
# XXX permissions page
# XXX don't grant to new users
# XXX ACL to run as remote user
# XXX Virtualmin integration?
BEGIN { push(@INC, ".."); };
use WebminCore;
&init_config();
my %access = &get_module_acl();
require './xterm-lib.pl';
&ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0, undef,
"<link rel=stylesheet href=xterm.css>\n".
@@ -48,14 +49,23 @@ my $user = $access{'user'};
my $tmpdir = &tempname_dir();
$ENV{'SESSION_ID'} = $main::session_id;
&system_logged("$shellserver_cmd $port $user >$tmpdir/ws-$port.out 2>&1 </dev/null &");
sleep(2);
sleep(1);
# Open the terminal
print "<center>\n";
print &ui_table_start(undef, undef, 2);
print &ui_table_row(undef, "<div id=terminal></div>", 2);
print &ui_table_end();
print "</center>\n";
my $url = "wss://".$ENV{'HTTP_HOST'}.$wspath;
my $rows = $config{'rows'} || 24;
my $cols = $config{'cols'} || 80;
print <<EOF;
<div id="terminal"></div>
<script>
var term = new Terminal();
var term = new Terminal({
rows: $rows,
cols: $cols,
});
term.open(document.getElementById('terminal'));
var socket = new WebSocket('$url', 'binary');
var attachAddon = new AttachAddon.AttachAddon(socket);

View File

@@ -1,2 +1,2 @@
index_title=Websockets Shell
index_title=Interactive Shell
index_cpan=The Perl module <tt>$1</tt> needed to accept Websockets connections is not available, but you can install it automatically using Webmin's <a href='$2'>Perl Modules</a> module.

View File

@@ -1,3 +1,3 @@
desc=Websockets Shell
desc=Interactive Shell
name=xterm
longdesc=Access the shell on your system without the need for a separate SSH client, using XTerm over Websockets

View File

@@ -1,10 +1,9 @@
#!/usr/local/bin/perl
# Start a websocket server connected to a shell
BEGIN { push(@INC, ".."); };
use WebminCore;
require './xterm-lib.pl';
use Net::WebSocket::Server;
&init_config();
my ($port, $user) = @ARGV;
# Switch to the user we're running as
@@ -16,6 +15,7 @@ if ($user ne "root" && $<) {
# Run the user's shell in a sub-process
&foreign_require("proc");
$ENV{'TERM'} = 'vt100';
our ($shellfh, $pid) = &proc::pty_process_exec($uinfo[8]);
$pid || die "Failed to run shell $uinfo[8]";
print STDERR "shell process is $pid\n";

7
xterm/xterm-lib.pl Normal file
View File

@@ -0,0 +1,7 @@
# Common functions for the xterm module
BEGIN { push(@INC, ".."); };
use WebminCore;
&init_config();
our %access = &get_module_acl();