caterpillar/console.html

164 lines
6.8 KiB
HTML
Raw Normal View History

2024-06-20 07:48:52 +00:00
<!doctype html>
<html>
<head>
<title>Caterpillar Proxy Web Console</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2024-06-21 05:35:27 +00:00
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
2024-06-20 07:48:52 +00:00
<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>
2024-06-21 03:41:18 +00:00
<p><a href="https://github.com/gnh1201/caterpillar">Fork me. gnh1201/caterpillar (GitHub)</a></p>
2024-06-20 07:48:52 +00:00
<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": ""
};
2024-06-21 02:32:08 +00:00
var pretty_jsonify = function(data) {
return JSON.stringify(data, null, 4);
};
2024-06-20 07:48:52 +00:00
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',
2024-06-20 08:01:32 +00:00
dataType: 'json',
2024-06-20 07:48:52 +00:00
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) {
2024-06-21 03:41:18 +00:00
if ("error" in response) {
term.echo(response.error.message);
2024-06-20 08:01:32 +00:00
} else {
2024-06-21 03:41:18 +00:00
if (typeof response.result.data === "object") {
term.echo(pretty_jsonify(response.result.data));
} else {
term.echo(response.result.data);
}
2024-06-20 08:01:32 +00:00
}
2024-06-20 07:48:52 +00:00
},
error: function(xhr, status, error) {
term.echo(error);
}
});
};
jQuery(function($, undefined) {
$('#console').terminal({
set: function(k, v) {
2024-06-21 02:24:18 +00:00
if (k == "env") {
this.echo("env is the reserved word");
return;
}
2024-06-20 07:48:52 +00:00
env[k] = v;
2024-06-20 10:05:28 +00:00
if (k == "method") {
this.set_prompt('method([[b;red;black]' + env.method + '])> ');
2024-06-21 03:41:18 +00:00
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];
}
}
}
2024-06-20 10:05:28 +00:00
}
2024-06-20 07:48:52 +00:00
},
show: function(k) {
2024-06-21 02:24:18 +00:00
var v = env[k];
if (typeof env[k] === "object") {
2024-06-21 02:32:08 +00:00
this.echo(pretty_jsonify(v));
2024-06-21 02:24:18 +00:00
} else if (k == "env") {
2024-06-21 02:32:08 +00:00
this.echo(pretty_jsonify(env));
2024-06-21 02:24:18 +00:00
} else {
this.echo(v);
2024-06-20 07:48:52 +00:00
}
},
do: function(...args) {
if (env.method == "") {
this.echo("Please set a method");
return;
}
2024-06-21 03:41:18 +00:00
// method(relay_invoke_method)
2024-06-20 07:48:52 +00:00
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;
}
2024-06-21 03:41:18 +00:00
// 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(*)
2024-06-20 07:48:52 +00:00
jsonrpc2_request(this, env.method, {});
}
}, {
height: 480,
width: 640,
prompt: '> ',
checkArity: false
});
});
//]]>--></script>
</body>
</html>