2024-06-30 15:53:58 +00:00
|
|
|
// catproxy.js
|
2024-06-30 16:29:24 +00:00
|
|
|
// Caterpillar Proxy Integration for WelsonJS framework
|
|
|
|
// https://github.com/gnh1201/welsonjs
|
2024-06-26 08:07:52 +00:00
|
|
|
var JSONRPC2 = require("lib/jsonrpc2");
|
|
|
|
|
2024-06-30 15:53:58 +00:00
|
|
|
function CatProxyClient(url) {
|
2024-07-04 05:30:12 +00:00
|
|
|
var env = {
|
|
|
|
"target": "http://localhost:5555/jsonrpc2", // Check this: https://github.com/gnh1201/caterpillar
|
|
|
|
"method": ""
|
|
|
|
};
|
2024-06-26 08:07:52 +00:00
|
|
|
|
|
|
|
this.set_env = function(k, v) {
|
|
|
|
env[k] = v || null;
|
|
|
|
};
|
|
|
|
this.set_default_env = function(_env) {
|
|
|
|
for (k in _env) {
|
|
|
|
if (!(k in env)) {
|
|
|
|
env[k] = _env[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.set_method = function(method) {
|
|
|
|
this.set_env("method", method);
|
|
|
|
|
|
|
|
if (env.method == "relay_mysql_query") {
|
|
|
|
this.set_default_env({
|
|
|
|
"mysql_hostname": "localhost",
|
|
|
|
"mysql_username": "root",
|
|
|
|
"mysql_password": null,
|
|
|
|
"mysql_database": null,
|
|
|
|
"mysql_port": "3306",
|
|
|
|
"mysql_charset": "utf8"
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2024-07-04 05:58:14 +00:00
|
|
|
this.exec = function(params) {
|
2024-06-30 16:29:24 +00:00
|
|
|
var args = Array.from(arguments);
|
2024-06-30 15:53:58 +00:00
|
|
|
var rpc = JSONRPC2.create(env.target);
|
2024-06-30 16:29:24 +00:00
|
|
|
var result;
|
2024-06-26 08:07:52 +00:00
|
|
|
|
|
|
|
if (env.method == "relay_mysql_query") {
|
2024-06-30 16:29:24 +00:00
|
|
|
var query = args.join(' ');
|
|
|
|
result = rpc.invoke(env.method, {
|
2024-06-26 08:07:52 +00:00
|
|
|
"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
|
|
|
|
}, null);
|
2024-06-30 16:29:24 +00:00
|
|
|
} else {
|
2024-07-04 05:58:14 +00:00
|
|
|
result = rpc.invoke(env.method, params, null);
|
2024-06-26 08:07:52 +00:00
|
|
|
}
|
|
|
|
|
2024-06-30 16:29:24 +00:00
|
|
|
return result;
|
2024-06-26 08:07:52 +00:00
|
|
|
}
|
2024-07-04 05:30:12 +00:00
|
|
|
|
|
|
|
if (typeof url !== "undefined") {
|
|
|
|
this.set_env(url);
|
|
|
|
}
|
2024-06-26 08:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function create(url) {
|
2024-06-30 15:53:58 +00:00
|
|
|
return new CatProxyClient(url);
|
2024-06-26 08:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.create = create;
|
2024-06-30 15:53:58 +00:00
|
|
|
exports.CatProxyClient = CatProxyClient;
|
2024-06-26 08:07:52 +00:00
|
|
|
|
2024-07-04 05:58:29 +00:00
|
|
|
exports.VERSIONINFO = "Caterpillar Proxy Integration (caterpillar.js) version 0.1.5";
|
2024-06-26 08:07:52 +00:00
|
|
|
exports.AUTHOR = "abuse@catswords.net";
|
|
|
|
exports.global = global;
|
|
|
|
exports.require = global.require;
|