Compare commits

..

No commits in common. "a20e0004d20083e3af0dce3b51de59a1c1389f40" and "137793cd774841256a71805fec9badb0bb6add26" have entirely different histories.

3 changed files with 27 additions and 51 deletions

View File

@ -1,11 +1,14 @@
// catproxy.js // caterpillar.js
// Caterpillar Proxy Integration for WelsonJS framework // Integration with [Caterpillar Proxy](https://github.com/gnh1201/caterpillar) project
// 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 CatProxyClient(url) { function Caterpillar(url) {
var env = {"target": url, "method": ""}; var rpc = JSONRPC2.create(url);
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;
@ -33,13 +36,11 @@ function CatProxyClient(url) {
} }
} }
this.exec = function() { this.exec = function() {
var args = Array.from(arguments); var args = arguments;
var rpc = JSONRPC2.create(env.target);
var result;
if (env.method == "relay_mysql_query") { if (env.method == "relay_mysql_query") {
var query = args.join(' '); var query = arguments.join(' ');
result = rpc.invoke(env.method, { 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,
@ -48,22 +49,20 @@ function CatProxyClient(url) {
"charset": env.mysql_charset, "charset": env.mysql_charset,
"query": query "query": query
}, null); }, null);
} else { return;
result = rpc.invoke(env.method, {}, null);
} }
return result; rpc.invoke(env.method, {}, null);
} }
} }
function create(url) { function create(url) {
return new CatProxyClient(url); return new Caterpillar(url);
} }
exports.create = create; exports.create = create;
exports.CatProxyClient = CatProxyClient;
exports.VERSIONINFO = "Caterpillar Proxy Integration (caterpillar.js) version 0.1.3"; exports.VERSIONINFO = "Caterpillar Proxy Integration (caterpillar.js) version 0.1.1";
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,23 +1,16 @@
// 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")
.setUserAgent(this.userAgent) .setRequestBody(encode(method, params, id))
.setRequestBody(wrap(method, params, id))
.open("POST", this.url) .open("POST", this.url)
.send() .send()
.responseBody .responseBody
@ -36,23 +29,23 @@ function jsonrpc2(url) {
} }
} }
function wrap(method, params, id) { function encode(method, params, id) {
return { return JSON.stringify({
"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.wrap = wrap; exports.encode = encode;
exports.create = create; exports.create = create;
exports.VERSIONINFO = "JSON-RPC 2.0 wrapper (jsonrpc2.js) version 0.1.4"; exports.VERSIONINFO = "JSON-RPC 2.0 Interface (jsonrpc2.js) version 0.1.2";
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,22 +971,6 @@ 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));
}
} }
}; };