2 # Start the Ajaxterm webserver on a random port, then print an iframe for
3 # a URL that proxies to it
5 BEGIN { push(@INC, ".."); };
10 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
13 $python = &has_command("python");
15 &ui_print_endpage(&text('index_epython', "<tt>python</tt>"));
19 &get_miniserv_config(\%miniserv);
20 $port = $miniserv{'port'} + 1;
21 $proto = getprotobyname('tcp');
22 socket(TEST, PF_INET, SOCK_STREAM, $proto) ||
23 &error("Socket failed : $!");
24 setsockopt(TEST, SOL_SOCKET, SO_REUSEADDR, pack("l", 1));
26 last if (bind(TEST, sockaddr_in($port, INADDR_ANY)));
31 # Run the Ajaxterm webserver
34 chdir("$module_root_directory/ajaxterm");
35 $logfile = $ENV{'WEBMIN_VAR'}.'/ajaxterm.log';
36 untie(*STDIN); open(STDIN, "</dev/null");
37 untie(*STDOUT); open(STDOUT, ">$logfile");
38 untie(*STDERR); open(STDERR, ">$logfile");
39 $shell = &has_command("bash") ||
40 &has_command("sh") || "/bin/sh";
41 @uinfo = getpwnam("root");
42 $home = $uinfo[7] || "/";
43 $shell = "$shell -c ".quotemeta("cd '$home' ; exec $shell");
44 exec($python, "ajaxterm.py", "--port", $port, "--log",
45 $config{'autologin'} ? ("--command", $shell) : ( ));
49 # Wait for it to come up
53 &open_socket("localhost", $port, TEST2, \$err);
57 &error(&text('index_estart', 30, $port));
65 print "<iframe src=$gconfig{'webprefix'}/$module_name/proxy.cgi/$port/ ",
66 "width=700 height=500 frameborder=0></iframe><br>\n";
67 print "<input type=button onClick='window.open(\"proxy.cgi/$port/\", \"ajaxterm\", \"toolbar=no,menubar=no,scrollbars=no,resizable=yes,width=700,height=500\")' value='$text{'index_popup'}'><p>\n";
68 print &text('index_credits', 'http://antony.lesuisse.org/software/ajaxterm/'),
72 # Fork process that checks for inactivity
74 untie(*STDIN); close(STDIN);
75 untie(*STDOUT); close(STDOUT);
76 untie(*STDERR); close(STDERR);
77 $statfile = "$ENV{'WEBMIN_VAR'}/ajaxterm/$port";
79 my @st = stat($statfile);
80 if (@st && time() - $st[9] > $config{'timeout'}) {
95 &ui_print_footer("/", $text{'index'});