Compare commits

...

4 Commits

Author SHA1 Message Date
a20e0004d2
Update testloader.js
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
2024-07-01 01:46:54 +09:00
c0e2b7731a
Update catproxy.js 2024-07-01 01:29:24 +09:00
2f974727d6
Update jsonrpc2.js 2024-07-01 01:27:51 +09:00
c91e01e13d
Update and rename caterpillar.js to catproxy.js 2024-07-01 00:53:58 +09:00
3 changed files with 51 additions and 27 deletions

View File

@ -1,14 +1,11 @@
// caterpillar.js // catproxy.js
// Integration with [Caterpillar Proxy](https://github.com/gnh1201/caterpillar) project // Caterpillar Proxy Integration for WelsonJS framework
// https://github.com/gnh1201/welsonjs // https://github.com/gnh1201/welsonjs
// https://github.com/gnh1201/caterpillar
var JSONRPC2 = require("lib/jsonrpc2"); var JSONRPC2 = require("lib/jsonrpc2");
function Caterpillar(url) { function CatProxyClient(url) {
var rpc = JSONRPC2.create(url); var env = {"target": url, "method": ""};
var env = {
"target": "http://localhost/",
"method": ""
};
this.set_env = function(k, v) { this.set_env = function(k, v) {
env[k] = v || null; env[k] = v || null;
@ -36,11 +33,13 @@ function Caterpillar(url) {
} }
} }
this.exec = function() { this.exec = function() {
var args = arguments; var args = Array.from(arguments);
var rpc = JSONRPC2.create(env.target);
var result;
if (env.method == "relay_mysql_query") { if (env.method == "relay_mysql_query") {
var query = arguments.join(' '); var query = args.join(' ');
rpc.invoke(env.method, { result = rpc.invoke(env.method, {
"hostname": env.mysql_hostname, "hostname": env.mysql_hostname,
"username": env.mysql_username, "username": env.mysql_username,
"password": env.mysql_password, "password": env.mysql_password,
@ -49,20 +48,22 @@ function Caterpillar(url) {
"charset": env.mysql_charset, "charset": env.mysql_charset,
"query": query "query": query
}, null); }, null);
return; } else {
result = rpc.invoke(env.method, {}, null);
} }
rpc.invoke(env.method, {}, null); return result;
} }
} }
function create(url) { function create(url) {
return new Caterpillar(url); return new CatProxyClient(url);
} }
exports.create = create; exports.create = create;
exports.CatProxyClient = CatProxyClient;
exports.VERSIONINFO = "Caterpillar Proxy Integration (caterpillar.js) version 0.1.1"; exports.VERSIONINFO = "Caterpillar Proxy Integration (caterpillar.js) version 0.1.3";
exports.AUTHOR = "abuse@catswords.net"; exports.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;

View File

@ -1,16 +1,23 @@
// jsonrpc2.js // jsonrpc2.js
// JSON-RPC 2.0 wrapper for WelsonJS framework
// Namhyeon Go <abuse@catswords.net> // Namhyeon Go <abuse@catswords.net>
// https://github.com/gnh1201/welsonjs // https://github.com/gnh1201/welsonjs
var HTTP = require("lib/http"); var HTTP = require("lib/http");
function jsonrpc2(url) { function jsonrpc2(url) {
this.url = url; this.url = url;
this.userAgent = "php-httpproxy/0.1.5 (Client; WelsonJS; abuse@catswords.net)";
this.setUserAgent = function(agent) {
this.userAgent = agent;
};
this.invoke = function(method, params, id) { this.invoke = function(method, params, id) {
var result; var result;
var response = HTTP.create("MSXML") var response = HTTP.create("MSXML")
.setContentType("application/json") .setContentType("application/json")
.setDataType("json") .setDataType("json")
.setRequestBody(encode(method, params, id)) .setUserAgent(this.userAgent)
.setRequestBody(wrap(method, params, id))
.open("POST", this.url) .open("POST", this.url)
.send() .send()
.responseBody .responseBody
@ -29,23 +36,23 @@ function jsonrpc2(url) {
} }
} }
function encode(method, params, id) { function wrap(method, params, id) {
return JSON.stringify({ return {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"method": method, "method": method,
"params": params, "params": params,
"id": id "id": id
}); };
} }
function create(url) { function create(url) {
return new jsonrpc2(url); return new jsonrpc2(url);
} }
exports.encode = encode; exports.wrap = wrap;
exports.create = create; exports.create = create;
exports.VERSIONINFO = "JSON-RPC 2.0 Interface (jsonrpc2.js) version 0.1.2"; exports.VERSIONINFO = "JSON-RPC 2.0 wrapper (jsonrpc2.js) version 0.1.4";
exports.AUTHOR = "abuse@catswords.net"; exports.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;

View File

@ -797,12 +797,12 @@ var test_implements = {
excel.open("data\\example.xlsx"); // Open a Excel window excel.open("data\\example.xlsx"); // Open a Excel window
}, },
"open_excel_new": function() { "open_excel_new": function() {
var Office = require("lib/msoffice"); var Office = require("lib/msoffice");
var excel = new Office.Excel(); // Create a Excel instance var excel = new Office.Excel(); // Create a Excel instance
excel.open(); // Open a Excel window excel.open(); // Open a Excel window
}, },
"open_excel_with_chatgpt": function() { "open_excel_with_chatgpt": function() {
// Load libraries // Load libraries
@ -843,13 +843,13 @@ var test_implements = {
powerpoint.open("data\\example.pptx"); // Open a PowerPoint window powerpoint.open("data\\example.pptx"); // Open a PowerPoint window
}, },
"open_powerpoint_new": function() { "open_powerpoint_new": function() {
var Office = require("lib/msoffice"); var Office = require("lib/msoffice");
var powerpoint = new Office.PowerPoint(); // Create a PowerPoint instance var powerpoint = new Office.PowerPoint(); // Create a PowerPoint instance
powerpoint.open(); // Open a PowerPoint window powerpoint.open(); // Open a PowerPoint window
}, },
"open_word_file": function() { "open_word_file": function() {
var Office = require("lib/msoffice"); // Load libraries var Office = require("lib/msoffice"); // Load libraries
var word = new Office.Word(); // Create an Word instance var word = new Office.Word(); // Create an Word instance
@ -971,6 +971,22 @@ var test_implements = {
"domparser_test": function() { "domparser_test": function() {
console.log(typeof DOMParser); console.log(typeof DOMParser);
},
// https://github.com/gnh1201/caterpillar
"catproxy_test": function() {
var client = require('lib/catproxy');
function main(args) {
var worker = client.create("http://locahost:5555");
worker.set_method("relay_mysql_query");
worker.set_env("mysql_username", "adminer");
worker.set_env("mysql_password", "changeme");
worker.set_env("mysql_database", "dummydb");
var result = worker.exec("select * from authors limit 3");
console.log(JSON.stringify(result));
}
} }
}; };