mirror of
https://github.com/gnh1201/caterpillar.git
synced 2024-11-26 15:31:45 +00:00
106 lines
4.0 KiB
HTML
106 lines
4.0 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>Caterpillar Proxy Web Console</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/2.42.0/css/jquery.terminal.min.css" rel="stylesheet"/>
|
|
</head>
|
|
<body>
|
|
<h1>Caterpillar Proxy Web Console</h1>
|
|
<div id="console"></div>
|
|
<p>https://github.com/gnh1201/caterpillar</p>
|
|
|
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
|
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/2.42.0/js/jquery.terminal.min.js"></script>
|
|
<script type="text/javascript">//<!--<![CDATA[
|
|
var env = {
|
|
"target": "http://localhost/",
|
|
"method": ""
|
|
};
|
|
var jsonrpc2_request = function(term, method, params) {
|
|
var requestData = {
|
|
jsonrpc: "2.0",
|
|
method: method,
|
|
params: params,
|
|
id: null
|
|
};
|
|
|
|
$.ajax({
|
|
url: env.target,
|
|
type: 'POST',
|
|
contentType: 'application/json',
|
|
dataType: 'json',
|
|
data: JSON.stringify(requestData),
|
|
beforeSend: function(xhr) {
|
|
xhr.setRequestHeader("X-User-Agent", "php-httpproxy/0.1.5 (Client; WebConsole; abuse@catswords.net)");
|
|
},
|
|
success: function(response) {
|
|
if (typeof response.result.data === "object") {
|
|
term.echo(JSON.stringify(response.result.data));
|
|
} else {
|
|
term.echo(response.result.data);
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
term.echo(error);
|
|
}
|
|
});
|
|
};
|
|
|
|
jQuery(function($, undefined) {
|
|
$('#console').terminal({
|
|
set: function(k, v) {
|
|
if (k == "env") {
|
|
this.echo("env is the reserved word");
|
|
return;
|
|
}
|
|
|
|
env[k] = v;
|
|
|
|
if (k == "method") {
|
|
this.set_prompt('method([[b;red;black]' + env.method + '])> ');
|
|
}
|
|
},
|
|
show: function(k) {
|
|
var v = env[k];
|
|
|
|
if (typeof env[k] === "object") {
|
|
this.echo(JSON.stringify(v));
|
|
} else if (k == "env") {
|
|
this.echo(JSON.stringify(env));
|
|
} else {
|
|
this.echo(v);
|
|
}
|
|
},
|
|
do: function(...args) {
|
|
if (env.method == "") {
|
|
this.echo("Please set a method");
|
|
return;
|
|
}
|
|
|
|
if (env.method == "relay_invoke_method") {
|
|
if (args.length < 1) {
|
|
this.echo("Please set a callback");
|
|
return;
|
|
}
|
|
|
|
jsonrpc2_request(this, env.method, {
|
|
"callback": args[0],
|
|
"args": args.slice(1)
|
|
});
|
|
return;
|
|
}
|
|
|
|
jsonrpc2_request(this, env.method, {});
|
|
}
|
|
}, {
|
|
height: 480,
|
|
width: 640,
|
|
prompt: '> ',
|
|
checkArity: false
|
|
});
|
|
});
|
|
//]]>--></script>
|
|
</body>
|
|
</html>
|