2 # Proxy an Ajaxterm request to the real port
4 BEGIN { push(@INC, ".."); };
7 # Since this script is run on every keypress, init_config is intentionally
8 # not called to reduce startup time.
12 $ENV{'PATH_INFO'} =~ /^\/(\d+)(.*)$/ ||
13 &error("Missing or invalid PATH_INFO");
17 $meth = $ENV{'REQUEST_METHOD'};
19 # Connect to the Ajaxterm server, send HTTP request
20 $con = &make_http_connection("localhost", $port, 0, $meth, $path);
21 &error($con) if (!ref($con));
22 &write_http_connection($con, "Host: localhost\r\n");
23 &write_http_connection($con, "User-agent: Webmin\r\n");
24 $cl = $ENV{'CONTENT_LENGTH'};
25 &write_http_connection($con, "Content-length: $cl\r\n") if ($cl);
26 &write_http_connection($con, "Content-type: $ENV{'CONTENT_TYPE'}\r\n")
27 if ($ENV{'CONTENT_TYPE'});
28 &write_http_connection($con, "\r\n");
30 &read_fully(STDIN, \$post, $cl);
31 &write_http_connection($con, $post);
34 # read back the headers
35 $dummy = &read_http_connection($con);
37 ($headline = &read_http_connection($con)) =~ s/\r|\n//g;
39 $headline =~ /^(\S+):\s+(.*)$/ || &error("Bad header");
41 $headers .= $headline."\n";
46 while($buf = &read_http_connection($con, 1024)) {
49 &close_http_connection($con);
51 # Touch status file to indicate it is still running
52 $statusdir = $ENV{'WEBMIN_VAR'}."/ajaxterm";
54 &make_dir($statusdir, 0700);
56 &open_tempfile(TOUCH, ">$statusdir/$port", 0, 1);
57 &close_tempfile(TOUCH);