mirror of
https://github.com/gnh1201/caterpillar.git
synced 2024-11-26 15:31:45 +00:00
181 lines
7.5 KiB
HTML
181 lines
7.5 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>Caterpillar Proxy Web Console</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
|
|
<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><a href="https://github.com/gnh1201/caterpillar">Fork me. gnh1201/caterpillar (GitHub)</a></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": "",
|
|
"filename": null
|
|
};
|
|
var pretty_jsonify = function(data) {
|
|
return JSON.stringify(data, null, 4);
|
|
};
|
|
var download_text = function(filename, text) {
|
|
var element = document.createElement('a');
|
|
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
|
element.setAttribute('download', filename);
|
|
element.style.display = 'none';
|
|
document.body.appendChild(element);
|
|
element.click();
|
|
document.body.removeChild(element);
|
|
}
|
|
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) {
|
|
var text = "";
|
|
if ("error" in response) {
|
|
text = response.error.message;
|
|
} else {
|
|
if (typeof response.result.data === "object") {
|
|
text = pretty_jsonify(response.result.data);
|
|
} else {
|
|
text = response.result.data;
|
|
}
|
|
}
|
|
term.echo(text);
|
|
|
|
// save as a file
|
|
if (env.filename != null) {
|
|
download_text(env.filename, text);
|
|
}
|
|
},
|
|
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 || null;
|
|
|
|
if (k == "method") {
|
|
this.set_prompt('method([[b;red;black]' + env.method + '])> ');
|
|
|
|
if (env.method == "relay_mysql_query") {
|
|
var _env = {
|
|
"mysql_hostname": "localhost",
|
|
"mysql_username": "root",
|
|
"mysql_password": "",
|
|
"mysql_database": "mysql",
|
|
"mysql_port": "3306",
|
|
"mysql_charset": "utf8"
|
|
};
|
|
|
|
for (k in _env) {
|
|
if (!(k in env)) {
|
|
env[k] = _env[k];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
show: function(k) {
|
|
var v = env[k];
|
|
|
|
if (typeof env[k] === "object") {
|
|
this.echo(pretty_jsonify(v));
|
|
} else if (k == "env") {
|
|
this.echo(pretty_jsonify(env));
|
|
} else {
|
|
this.echo(v);
|
|
}
|
|
},
|
|
do: function(...args) {
|
|
if (env.method == "") {
|
|
this.echo("Please set a method");
|
|
return;
|
|
}
|
|
|
|
// method(relay_invoke_method)
|
|
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;
|
|
}
|
|
|
|
// method(relay_dns_get_record)
|
|
if (env.method == "relay_dns_get_record") {
|
|
if (args.length < 1) {
|
|
this.echo("Please set a hostname");
|
|
return;
|
|
}
|
|
|
|
jsonrpc2_request(this, env.method, {
|
|
"hostname": args[0]
|
|
});
|
|
|
|
return;
|
|
}
|
|
|
|
// method(relay_mysql_query)
|
|
if (env.method == "relay_mysql_query") {
|
|
var _this = this;
|
|
this.read("Enter MySQL query:\r\n", function(query) {
|
|
jsonrpc2_request(_this, env.method, {
|
|
"hostname": env.mysql_hostname,
|
|
"username": env.mysql_username,
|
|
"password": env.mysql_password,
|
|
"database": env.mysql_database,
|
|
"port": env.mysql_port,
|
|
"charset": env.mysql_charset,
|
|
"query": query
|
|
});
|
|
});
|
|
return;
|
|
}
|
|
|
|
// method(*)
|
|
jsonrpc2_request(this, env.method, {});
|
|
}
|
|
}, {
|
|
height: 480,
|
|
width: 640,
|
|
prompt: '> ',
|
|
checkArity: false
|
|
});
|
|
});
|
|
//]]>--></script>
|
|
</body>
|
|
</html>
|