blob: a36257ce8fd4421a529308c51df19e0679f0c8ed [file] [log] [blame]
Felix Meschberger9beb44e2008-08-07 19:15:29 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18function executeCommand(command) {
19 var xmlhttp = getXmlHttp();
20 if (!xmlhttp) {
21 return;
22 }
23
24 if (xmlhttp.readyState < 4) {
25 xmlhttp.abort();
26 }
27
28 var url = document.location;
29
30 xmlhttp.open("POST", url);
31
32 // set If-Modified-Since way back in the past to prevent
33 // using any content from the cache
34 xmlhttp.setRequestHeader("If-Modified-Since", new Date(0));
35 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
36
37 xmlhttp.onreadystatechange = updateConsole;
38
39 xmlhttp.send("command=" + encodeURIComponent(command));
40}
41
42function updateConsole() {
43 var xmlhttp = getXmlHttp();
44 if (!xmlhttp || xmlhttp.readyState != 4) {
45 return;
46 }
47
48 var result = xmlhttp.responseText;
49 if (!result) {
50 return;
51 }
52
53 var console = document.getElementById("console");
54
55 console.style.display = "";
56 console.innerHTML = console.innerHTML + result;
57
58 var consoleframe = document.getElementById("consoleframe");
59 consoleframe.scrollTop = console.scrollHeight;
60
61 document.forms["shellCommandForm"].elements["command"].value = "";
62
63 shellCommandFocus();
64}
65
66function clearConsole() {
67 var console = document.getElementById("console");
68
69 console.style.display = "none";
70 console.innerHTML = "";
71
72 var consoleframe = document.getElementById("consoleframe");
73 consoleframe.scrollTop = 0;
74
75 shellCommandFocus();
76}
77
78function shellCommandFocus() {
79 document.forms["shellCommandForm"].elements["command"].focus();
80}
81
82function runShellCommand() {
83 var command = document.forms["shellCommandForm"].elements["command"].value;
84
85 executeCommand(command);
86}