mirror of
https://github.com/gnh1201/caterpillar.git
synced 2025-07-12 23:43:11 +00:00
Compare commits
6 Commits
c407739e12
...
b8fa3e6722
Author | SHA1 | Date | |
---|---|---|---|
b8fa3e6722 | |||
0c393a1338 | |||
243cadd5d0 | |||
d671daaf46 | |||
17f1753c1c | |||
ac7bfccdf3 |
|
@ -9,17 +9,18 @@
|
||||||
* Updated at: 2024-06-25
|
* Updated at: 2024-06-25
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define("PHP_HTTPPROXY_VERSION", "0.1.5.22");
|
define("PHP_HTTPPROXY_VERSION", "0.1.5.23");
|
||||||
define("DEFAULT_SOCKET_TIMEOUT", 1);
|
define("DEFAULT_SOCKET_TIMEOUT", 1);
|
||||||
define("STATEFUL_SOCKET_TIMEOUT", 30);
|
define("STATEFUL_SOCKET_TIMEOUT", 30);
|
||||||
define("MAX_EXECUTION_TIME", 0);
|
define("MAX_EXECUTION_TIME", 0);
|
||||||
|
define("DEFAULT_USER_AGENT", $_SERVER['HTTP_USER_AGENT'] . '</p><hr><p>php-httpproxy/' . PHP_HTTPPROXY_VERSION . ' (Server; PHP ' . phpversion() . '; Caterpillar; abuse@catswords.net)');
|
||||||
|
|
||||||
header('Access-Control-Allow-Origin: *');
|
header('Access-Control-Allow-Origin: *');
|
||||||
header('Access-Control-Allow-Methods: *');
|
header('Access-Control-Allow-Methods: *');
|
||||||
header("Access-Control-Allow-Headers: *");
|
header("Access-Control-Allow-Headers: *");
|
||||||
|
|
||||||
if (strpos($_SERVER['HTTP_USER_AGENT'], "php-httpproxy/") !== 0 && strpos($_SERVER['HTTP_X_USER_AGENT'], "php-httpproxy/") !== 0) {
|
if (strpos($_SERVER['HTTP_USER_AGENT'], "php-httpproxy/") !== 0 && strpos($_SERVER['HTTP_X_USER_AGENT'], "php-httpproxy/") !== 0) {
|
||||||
exit('<!DOCTYPE html><html><head><title>It works!</title><meta charset="utf-8"></head><body><h1>It works!</h1><p><a href="https://github.com/gnh1201/caterpillar">Download the client</a></p><p>' . $_SERVER['HTTP_USER_AGENT'] . '</p><hr><p>php-httpproxy/' . PHP_HTTPPROXY_VERSION . ' (Server; PHP ' . phpversion() . '; Caterpillar; abuse@catswords.net)</p></body></html>');
|
exit('<!DOCTYPE html><html><head><title>It works!</title><meta charset="utf-8"></head><body><h1>It works!</h1><p><a href="https://github.com/gnh1201/caterpillar">Download the client</a></p><p>' . DEFAULT_USER_AGENT . '</p></body></html>');
|
||||||
}
|
}
|
||||||
|
|
||||||
ini_set("default_socket_timeout", DEFAULT_SOCKET_TIMEOUT); // must be. because of `feof()` works
|
ini_set("default_socket_timeout", DEFAULT_SOCKET_TIMEOUT); // must be. because of `feof()` works
|
||||||
|
@ -386,12 +387,13 @@ function relay_dns_get_record($params) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function relay_get_geolocation() {
|
function relay_fetch_url($params) {
|
||||||
$url = "https://ipapi.co/json/";
|
$url = $params['url'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, DEFAULT_USER_AGENT);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
@ -412,13 +414,12 @@ function relay_get_geolocation() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
$data = json_decode($response, true);
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
"success" => true,
|
"success" => true,
|
||||||
"result" => array(
|
"result" => array(
|
||||||
"status" => 200,
|
"status" => 200,
|
||||||
"data" => $data
|
"data" => $response
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
@ -433,6 +434,24 @@ function relay_get_geolocation() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function relay_get_geolocation() {
|
||||||
|
$result = relay_fetch_url(array(
|
||||||
|
"url" => "http://ip-api.com/json"
|
||||||
|
));
|
||||||
|
if ($result['success']) {
|
||||||
|
return array(
|
||||||
|
"success" => true,
|
||||||
|
"result" => array(
|
||||||
|
"status" => 200,
|
||||||
|
"data" => json_decode($result['result']['data'], true)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function relay_invoke_method($params) {
|
function relay_invoke_method($params) {
|
||||||
$callback = $params['callback'];
|
$callback = $params['callback'];
|
||||||
$args = (is_array($params['args']) ? $params['args'] : array());
|
$args = (is_array($params['args']) ? $params['args'] : array());
|
||||||
|
@ -537,8 +556,17 @@ if ($context['jsonrpc'] == "2.0") {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "relay_fetch_url":
|
||||||
|
$result = relay_fetch_url($context['params']);
|
||||||
|
if ($result['success']) {
|
||||||
|
echo jsonrpc2_result_encode($result['result'], $context['id']);
|
||||||
|
} else {
|
||||||
|
echo jsonrpc2_error_encode($result['error'], $context['id']);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "relay_get_geolocation":
|
case "relay_get_geolocation":
|
||||||
$result = relay_get_geolocation();
|
$result = relay_get_geolocation($context['params']);
|
||||||
if ($result['success']) {
|
if ($result['success']) {
|
||||||
echo jsonrpc2_result_encode($result['result'], $context['id']);
|
echo jsonrpc2_result_encode($result['result'], $context['id']);
|
||||||
} else {
|
} else {
|
||||||
|
|
103
console.html
103
console.html
|
@ -4,7 +4,8 @@
|
||||||
<title>Caterpillar Proxy Web Console</title>
|
<title>Caterpillar Proxy Web Console</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
|
<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"/>
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/2.42.0/css/jquery.terminal.min.css" rel="stylesheet" type="text/css">
|
||||||
|
<link href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" rel="stylesheet" type="text/css">
|
||||||
<style type="text/css">/*<!--<![CDATA[*/
|
<style type="text/css">/*<!--<![CDATA[*/
|
||||||
body {
|
body {
|
||||||
background: #2e8d36 url(https://pub-1a7a176eea68479cb5423e44273657ad.r2.dev/bg.jpg) no-repeat;
|
background: #2e8d36 url(https://pub-1a7a176eea68479cb5423e44273657ad.r2.dev/bg.jpg) no-repeat;
|
||||||
|
@ -34,17 +35,26 @@
|
||||||
<h1>Caterpillar Proxy Web Console</h1>
|
<h1>Caterpillar Proxy Web Console</h1>
|
||||||
<p>Download an worker script of <a href="https://github.com/gnh1201/caterpillar">Caterpillar Proxy</a>.</p>
|
<p>Download an worker script of <a href="https://github.com/gnh1201/caterpillar">Caterpillar Proxy</a>.</p>
|
||||||
<div id="console"></div>
|
<div id="console"></div>
|
||||||
|
<div id="map"></div>
|
||||||
<p><a href="https://github.com/gnh1201/caterpillar">Fork me. gnh1201/caterpillar (GitHub)</a></p>
|
<p><a href="https://github.com/gnh1201/caterpillar">Fork me. gnh1201/caterpillar (GitHub)</a></p>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" type="text/javascript"></script>
|
||||||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/2.42.0/js/jquery.terminal.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/2.42.0/js/jquery.terminal.min.js" type="text/javascript" ></script>
|
||||||
|
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" type="text/javascript"></script>
|
||||||
<script type="text/javascript">//<!--<![CDATA[
|
<script type="text/javascript">//<!--<![CDATA[
|
||||||
var env = {
|
var env = {
|
||||||
"target": "http://localhost/",
|
"target": "http://localhost/",
|
||||||
"method": "",
|
"method": "",
|
||||||
"filename": null
|
"filename": null
|
||||||
};
|
};
|
||||||
|
var set_default_env = function(_env) {
|
||||||
|
for (k in _env) {
|
||||||
|
if (!(k in env)) {
|
||||||
|
env[k] = _env[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
var pretty_jsonify = function(data) {
|
var pretty_jsonify = function(data) {
|
||||||
return JSON.stringify(data, null, 4);
|
return JSON.stringify(data, null, 4);
|
||||||
};
|
};
|
||||||
|
@ -124,6 +134,25 @@
|
||||||
if (env.filename != null) {
|
if (env.filename != null) {
|
||||||
download_text(env.filename, text);
|
download_text(env.filename, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// method(relay_get_geolocation)
|
||||||
|
if (env.method == "relay_get_geolocation") {
|
||||||
|
var geodata = responseData.result.data;
|
||||||
|
|
||||||
|
term.echo('', {
|
||||||
|
finalize: function($div) {
|
||||||
|
$div.children().last().append($("#map").css("height", "130px"));
|
||||||
|
map.setView([geodata.lat, geodata.lon], 13);
|
||||||
|
var circle = L.circle([geodata.lat, geodata.lon], {
|
||||||
|
color: 'red',
|
||||||
|
fillColor: '#f03',
|
||||||
|
fillOpacity: 0.5,
|
||||||
|
radius: 500
|
||||||
|
}).addTo(map);
|
||||||
|
term.echo();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
term.echo(error);
|
term.echo(error);
|
||||||
|
@ -144,21 +173,25 @@
|
||||||
if (k == "method") {
|
if (k == "method") {
|
||||||
this.set_prompt('method([[b;red;black]' + env.method + '])> ');
|
this.set_prompt('method([[b;red;black]' + env.method + '])> ');
|
||||||
|
|
||||||
|
// method(relay_sendmail)
|
||||||
|
if (env.method == "relay_sendmail") {
|
||||||
|
set_default_env({
|
||||||
|
"mail_to": "noreply@example.org",
|
||||||
|
"mail_from": "noreply@example.org",
|
||||||
|
"mail_subject": "Important Message from System Administrator"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// method(relay_mysql_query)
|
||||||
if (env.method == "relay_mysql_query") {
|
if (env.method == "relay_mysql_query") {
|
||||||
var _env = {
|
set_default_env({
|
||||||
"mysql_hostname": "localhost",
|
"mysql_hostname": "localhost",
|
||||||
"mysql_username": "root",
|
"mysql_username": "root",
|
||||||
"mysql_password": "",
|
"mysql_password": null,
|
||||||
"mysql_database": "mysql",
|
"mysql_database": null,
|
||||||
"mysql_port": "3306",
|
"mysql_port": "3306",
|
||||||
"mysql_charset": "utf8"
|
"mysql_charset": "utf8"
|
||||||
};
|
});
|
||||||
|
|
||||||
for (k in _env) {
|
|
||||||
if (!(k in env)) {
|
|
||||||
env[k] = _env[k];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -207,10 +240,38 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// method(relay_fetch_url)
|
||||||
|
if (env.method == "relay_fetch_url") {
|
||||||
|
if (args.length < 1) {
|
||||||
|
this.echo("Please set a URL");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonrpc2_request(this, env.method, {
|
||||||
|
"url": args[0]
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// method(relay_sendmail)
|
||||||
|
if (env.method == "relay_sendmail") {
|
||||||
|
this.echo("From: " + env.mail_from + "\r\nTo: " + env.mail_to + "\r\nSubject: " + env.mail_subject);
|
||||||
|
this.read("Enter your message:\r\n", function(message) {
|
||||||
|
jsonrpc2_request(this, env.method, {
|
||||||
|
"to": env.mail_to,
|
||||||
|
"from": env.mail_from,
|
||||||
|
"subject": env.mail_subject,
|
||||||
|
"message": message
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// method(relay_mysql_query)
|
// method(relay_mysql_query)
|
||||||
if (env.method == "relay_mysql_query") {
|
if (env.method == "relay_mysql_query") {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
this.read("Enter MySQL query:\r\n", function(query) {
|
var do_query = function(query) {
|
||||||
jsonrpc2_request(_this, env.method, {
|
jsonrpc2_request(_this, env.method, {
|
||||||
"hostname": env.mysql_hostname,
|
"hostname": env.mysql_hostname,
|
||||||
"username": env.mysql_username,
|
"username": env.mysql_username,
|
||||||
|
@ -220,7 +281,13 @@
|
||||||
"charset": env.mysql_charset,
|
"charset": env.mysql_charset,
|
||||||
"query": query
|
"query": query
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if (args.length < 1) {
|
||||||
|
this.read("Enter MySQL query:\r\n", do_query);
|
||||||
|
} else {
|
||||||
|
do_query(args.join(' '));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,6 +301,12 @@
|
||||||
checkArity: false
|
checkArity: false
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var map = L.map('map');
|
||||||
|
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
|
maxZoom: 19,
|
||||||
|
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
||||||
|
}).addTo(map);
|
||||||
//]]>--></script>
|
//]]>--></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user