From ccc715a11ebc74d27c0cab53add4538f2652e9ee Mon Sep 17 00:00:00 2001 From: Joe Cooper Date: Tue, 14 Jun 2016 01:59:36 -0700 Subject: [PATCH 1/3] strict/warnings but doesn't work...no idea why --- ajaxterm/index.cgi | 38 +++++++++++++++++++++++--------------- ajaxterm/proxy.cgi | 29 ++++++++++++++++++----------- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/ajaxterm/index.cgi b/ajaxterm/index.cgi index bc3ffd8f8..0187fae17 100755 --- a/ajaxterm/index.cgi +++ b/ajaxterm/index.cgi @@ -1,24 +1,31 @@ #!/usr/local/bin/perl # Start the Ajaxterm webserver on a random port, then print an iframe for # a URL that proxies to it +use strict; +use warnings; BEGIN { push(@INC, ".."); }; use WebminCore; use Socket; +our(%text, %config, %gconfig); +our $module_root_directory; +our $module_name; + &init_config(); &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1); # Check for python -$python = &has_command("python"); +my $python = &has_command("python"); if (!$python) { &ui_print_endpage(&text('index_epython', "python")); } # Pick a free port +my %miniserv; &get_miniserv_config(\%miniserv); -$port = $miniserv{'port'} + 1; -$proto = getprotobyname('tcp'); +my $port = $miniserv{'port'} + 1; +my $proto = getprotobyname('tcp'); socket(TEST, PF_INET, SOCK_STREAM, $proto) || &error("Socket failed : $!"); setsockopt(TEST, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)); @@ -29,17 +36,17 @@ while(1) { close(TEST); # Run the Ajaxterm webserver -$pid = fork(); +my $pid = fork(); if (!$pid) { chdir("$module_root_directory/ajaxterm"); - $logfile = $ENV{'WEBMIN_VAR'}.'/ajaxterm.log'; - untie(*STDIN); open(STDIN, "$logfile"); - untie(*STDERR); open(STDERR, ">$logfile"); - $shell = &has_command("bash") || + my $logfile = $ENV{'WEBMIN_VAR'}.'/ajaxterm.log'; + untie(*STDIN); open(*STDIN, "<", "/dev/null"); + untie(*STDOUT); open(*STDOUT, ">", $logfile); + untie(*STDERR); open(*STDERR, ">", $logfile); + my $shell = &has_command("bash") || &has_command("sh") || "/bin/sh"; - @uinfo = getpwnam("root"); - $home = $uinfo[7] || "/"; + my @uinfo = getpwnam("root"); + my $home = $uinfo[7] || "/"; $shell = "$shell -c ".quotemeta("cd '$home' ; exec $shell"); exec($python, "ajaxterm.py", "--port", $port, "--log", $config{'autologin'} ? ("--command", $shell) : ( )); @@ -47,10 +54,11 @@ if (!$pid) { } # Wait for it to come up -$try = 0; +my $try = 0; +my $TEST2; while(1) { my $err; - &open_socket("localhost", $port, TEST2, \$err); + &open_socket("localhost", $port, $TEST2, \$err); last if (!$err); $try++; if ($try > 30) { @@ -58,7 +66,7 @@ while(1) { } sleep(1); } -close(TEST2); +close($TEST2); # Show the iframe print "
\n"; @@ -74,7 +82,7 @@ if (!fork()) { untie(*STDIN); close(STDIN); untie(*STDOUT); close(STDOUT); untie(*STDERR); close(STDERR); - $statfile = "$ENV{'WEBMIN_VAR'}/ajaxterm/$port"; + my $statfile = "$ENV{'WEBMIN_VAR'}/ajaxterm/$port"; while(1) { my @st = stat($statfile); if (@st && time() - $st[9] > $config{'timeout'}) { diff --git a/ajaxterm/proxy.cgi b/ajaxterm/proxy.cgi index 29dc31d7a..13d9e4f1e 100755 --- a/ajaxterm/proxy.cgi +++ b/ajaxterm/proxy.cgi @@ -1,5 +1,7 @@ #!/usr/local/bin/perl # Proxy an Ajaxterm request to the real port +use strict; +use warnings; BEGIN { push(@INC, ".."); }; use WebminCore; @@ -11,29 +13,33 @@ use WebminCore; # Parse out port $ENV{'PATH_INFO'} =~ /^\/(\d+)(.*)$/ || &error("Missing or invalid PATH_INFO"); -$port = $1; -$path = $2; +my $port = $1; +my $path = $2; $| = 1; -$meth = $ENV{'REQUEST_METHOD'}; +my $meth = $ENV{'REQUEST_METHOD'}; # Connect to the Ajaxterm server, send HTTP request -$con = &make_http_connection("localhost", $port, 0, $meth, $path); +my $con = &make_http_connection("localhost", $port, 0, $meth, $path); &error($con) if (!ref($con)); &write_http_connection($con, "Host: localhost\r\n"); &write_http_connection($con, "User-agent: Webmin\r\n"); -$cl = $ENV{'CONTENT_LENGTH'}; +my $cl = $ENV{'CONTENT_LENGTH'}; &write_http_connection($con, "Content-length: $cl\r\n") if ($cl); &write_http_connection($con, "Content-type: $ENV{'CONTENT_TYPE'}\r\n") if ($ENV{'CONTENT_TYPE'}); &write_http_connection($con, "\r\n"); +my $post; if ($cl) { - &read_fully(STDIN, \$post, $cl); + &read_fully(\*STDIN, \$post, $cl); &write_http_connection($con, $post); } # read back the headers -$dummy = &read_http_connection($con); +my $dummy = &read_http_connection($con); +my %header; +my $headers; while(1) { + my $headline; ($headline = &read_http_connection($con)) =~ s/\r|\n//g; last if (!$headline); $headline =~ /^(\S+):\s+(.*)$/ || &error("Bad header"); @@ -43,16 +49,17 @@ while(1) { print $headers,"\n"; # read back contents -while($buf = &read_http_connection($con, 1024)) { +while(my $buf = &read_http_connection($con, 1024)) { print $buf; } &close_http_connection($con); # Touch status file to indicate it is still running -$statusdir = $ENV{'WEBMIN_VAR'}."/ajaxterm"; +my $statusdir = $ENV{'WEBMIN_VAR'}."/ajaxterm"; if (!-d $statusdir) { &make_dir($statusdir, 0700); } -&open_tempfile(TOUCH, ">$statusdir/$port", 0, 1); -&close_tempfile(TOUCH); +my $TOUCH; +&open_tempfile($TOUCH, ">$statusdir/$port", 0, 1); +&close_tempfile($TOUCH); From eb6b294bedf26f38c3f45d543b45a87014b2fce1 Mon Sep 17 00:00:00 2001 From: Joe Cooper Date: Thu, 16 Jun 2016 18:52:47 -0700 Subject: [PATCH 2/3] typo fix --- apache/apache-lib.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apache/apache-lib.pl b/apache/apache-lib.pl index 49ed4808a..a3dbfbe69 100755 --- a/apache/apache-lib.pl +++ b/apache/apache-lib.pl @@ -676,8 +676,8 @@ elsif (!$olddir && $newdir) { # Update the line numbers and filenames in a list of directives sub recursive_set_lines_files { -local ($dirs, $line, $file) = @_; -foreach my $d (@$dirs) { +my ($dirs, $line, $file) = @_; +foreach my $dir (@$dirs) { $dir->{'line'} = $line; $dir->{'file'} = $file; if ($dir->{'type'}) { From f818ead2dbea511131e1ce48c1b5f3ecb1aa0752 Mon Sep 17 00:00:00 2001 From: Joe Cooper Date: Thu, 16 Jun 2016 19:24:46 -0700 Subject: [PATCH 3/3] strict/warn --- ajaxterm/index.cgi | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ajaxterm/index.cgi b/ajaxterm/index.cgi index 0187fae17..47e5ad6f4 100755 --- a/ajaxterm/index.cgi +++ b/ajaxterm/index.cgi @@ -40,9 +40,9 @@ my $pid = fork(); if (!$pid) { chdir("$module_root_directory/ajaxterm"); my $logfile = $ENV{'WEBMIN_VAR'}.'/ajaxterm.log'; - untie(*STDIN); open(*STDIN, "<", "/dev/null"); - untie(*STDOUT); open(*STDOUT, ">", $logfile); - untie(*STDERR); open(*STDERR, ">", $logfile); + untie(*STDIN); open(STDIN, "<", "/dev/null"); + untie(*STDOUT); open(STDOUT, ">", $logfile); + untie(*STDERR); open(STDERR, ">", $logfile); my $shell = &has_command("bash") || &has_command("sh") || "/bin/sh"; my @uinfo = getpwnam("root"); @@ -55,10 +55,11 @@ if (!$pid) { # Wait for it to come up my $try = 0; -my $TEST2; +no strict "subs"; # TEST2 is weird. I dunno how to make it lexical without breaking. +no warnings; while(1) { my $err; - &open_socket("localhost", $port, $TEST2, \$err); + &open_socket("localhost", $port, TEST2, \$err); last if (!$err); $try++; if ($try > 30) { @@ -66,7 +67,9 @@ while(1) { } sleep(1); } -close($TEST2); +close(TEST2); +use strict "subs"; +use warnings; # Show the iframe print "
\n";