Finished off ajaxterm module
authorJamie Cameron <jcameron@webmin.com>
Tue, 1 Sep 2009 21:01:52 +0000 (14:01 -0700)
committerJamie Cameron <jcameron@webmin.com>
Tue, 1 Sep 2009 21:01:52 +0000 (14:01 -0700)
ajaxterm/\ [new file with mode: 0644]
ajaxterm/ajaxterm/ajaxterm.css
ajaxterm/ajaxterm/qweb.pyc [new file with mode: 0644]
ajaxterm/config [new file with mode: 0644]
ajaxterm/config.info [new file with mode: 0644]
ajaxterm/index.cgi
ajaxterm/lang/en [new file with mode: 0644]
ajaxterm/module.info
ajaxterm/proxy.cgi

diff --git a/ajaxterm/\ b/ajaxterm/\
new file mode 100644 (file)
index 0000000..5dbd2e8
--- /dev/null
@@ -0,0 +1,23 @@
+#!/usr/local/bin/perl
+# Start the Ajaxterm webserver on a random port, then print an iframe for
+# a URL that proxies to it
+
+BEGIN { push(@INC, ".."); };
+use WebminCore;
+use Socket;
+&init_config();
+
+&ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
+
+# Check for python
+if (!&has_command("python")) {
+       &ui_print_endpage(&text('index_epython', "<tt>python</tt>"));
+       }
+
+# Pick a free port
+&get_miniserv_config(\%miniserv);
+
+# Show the iframe
+
+&ui_print_footer("/", $text{'index'});
+
index b9a5f87..8042fb2 100644 (file)
@@ -58,7 +58,7 @@ pre.term span.b5  { background-color: #b0b; }
 pre.term span.b6  { background-color: #0bb; }
 pre.term span.b7  { background-color: #bbb; }
 
-body { background-color: #888; }
+body { background-color: #ffffff; }
 #term {
        float: left;
 }
diff --git a/ajaxterm/ajaxterm/qweb.pyc b/ajaxterm/ajaxterm/qweb.pyc
new file mode 100644 (file)
index 0000000..5e1bf09
Binary files /dev/null and b/ajaxterm/ajaxterm/qweb.pyc differ
diff --git a/ajaxterm/config b/ajaxterm/config
new file mode 100644 (file)
index 0000000..6091b45
--- /dev/null
@@ -0,0 +1 @@
+timeout=120
diff --git a/ajaxterm/config.info b/ajaxterm/config.info
new file mode 100644 (file)
index 0000000..7472cef
--- /dev/null
@@ -0,0 +1 @@
+timeout=Idle timeout before closing connection,0,5,,seconds
index ee7d27f..11b5eac 100755 (executable)
@@ -10,7 +10,8 @@ use Socket;
 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
 
 # Check for python
-if (!&has_command("python")) {
+$python = &has_command("python");
+if (!$python) {
        &ui_print_endpage(&text('index_epython', "<tt>python</tt>"));
        }
 
@@ -28,14 +29,24 @@ while(1) {
 close(TEST);
 
 # Run the Ajaxterm webserver
-system("cd $module_root_directory/ajaxterm ; python ajaxterm.py --port $port --log >/tmp/ajaxterm.out 2>&1 </dev/null &");
+$pid = fork();
+if (!$pid) {
+       chdir("$module_root_directory/ajaxterm");
+       untie(*STDIN); open(STDIN, "</dev/null");
+       #untie(*STDOUT); open(STDOUT, ">/dev/null");
+       #untie(*STDERR); open(STDERR, ">/dev/null");
+       untie(*STDOUT); open(STDOUT, ">/tmp/ajaxterm.out");
+       untie(*STDERR); open(STDERR, ">/tmp/ajaxterm.out");
+       exec($python, "ajaxterm.py", "--port", $port, "--log");
+       exit(1);
+       }
 
 # Wait for it to come up
 $try = 0;
 while(1) {
        my $err;
        &open_socket("localhost", $port, TEST2, \$err);
-       last if ($err);
+       last if (!$err);
        $try++;
        if ($try > 30) {
                &error(&text('index_estart', 30, $port));
@@ -45,8 +56,34 @@ while(1) {
 close(TEST2);
 
 # Show the iframe
+print "<center>\n";
 print "<iframe src=$gconfig{'webprefix'}/$module_name/proxy.cgi/$port/ ",
-      "width=100% height=90%></iframe>\n";
+      "width=580 height=420 frameborder=0></iframe><br>\n";
+print "<input type=button onClick='window.open(\"proxy.cgi/$port/\", \"ajaxterm\", \"toolbar=no,menubar=no,scrollbars=no,resizable=yes,width=580,height=420\")' value='$text{'index_popup'}'>\n";
+print "</center>\n";
+
+# Fork process that checks for inactivity
+if (!fork()) {
+       untie(*STDIN); close(STDIN);
+       untie(*STDOUT); close(STDOUT);
+       untie(*STDERR); close(STDERR);
+       $statfile = "$ENV{'WEBMIN_VAR'}/$module_name/$port";
+       while(1) {
+               my @st = stat($statfile);
+               if (@st && time() - $st[9] > $config{'timeout'}) {
+                       # No activity
+                       last;
+                       }
+               if (!kill(0, $pid)) {
+                       # Dead
+                       last;
+                       }
+               sleep(10);
+               }
+       unlink($statfile);
+       kill('KILL', $pid);
+       exit(0);
+       }
 
 &ui_print_footer("/", $text{'index'});
 
diff --git a/ajaxterm/lang/en b/ajaxterm/lang/en
new file mode 100644 (file)
index 0000000..472a76d
--- /dev/null
@@ -0,0 +1,4 @@
+index_title=Text Login
+index_epython=Ajaxterm requires Python to run, but the $1 command was not found on your system.
+index_estart=Ajaxterm did not start accepting connections on port $2 after $1 seconds.
+index_popup=Open in separate window ..
index cc40db9..41be6f8 100644 (file)
@@ -1,2 +1,2 @@
-desc=AJAX Login
+desc=Text Login
 name=ajaxterm
index 89c47e7..02377a3 100755 (executable)
@@ -45,3 +45,11 @@ while($buf = &read_http_connection($con, 1024)) {
         }
 &close_http_connection($con);
 
+# Touch status file to indicate it is still running
+$statusdir = $ENV{'WEBMIN_VAR'}."/".$module_name;
+if (!-d $statusdir) {
+       &make_dir($statusdir, 0700);
+       }
+&open_tempfile(TOUCH, ">$statusdir/$port", 0, 1);
+&close_tempfile(TOUCH);
+