mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-07-17 22:18:11 +00:00
Compare commits
4 Commits
137793cd77
...
a20e0004d2
Author | SHA1 | Date | |
---|---|---|---|
a20e0004d2 | |||
c0e2b7731a | |||
2f974727d6 | |||
c91e01e13d |
|
@ -1,14 +1,11 @@
|
|||
// caterpillar.js
|
||||
// Integration with [Caterpillar Proxy](https://github.com/gnh1201/caterpillar) project
|
||||
// https://github.com/gnh1201/welsonjs
|
||||
// catproxy.js
|
||||
// Caterpillar Proxy Integration for WelsonJS framework
|
||||
// https://github.com/gnh1201/welsonjs
|
||||
// https://github.com/gnh1201/caterpillar
|
||||
var JSONRPC2 = require("lib/jsonrpc2");
|
||||
|
||||
function Caterpillar(url) {
|
||||
var rpc = JSONRPC2.create(url);
|
||||
var env = {
|
||||
"target": "http://localhost/",
|
||||
"method": ""
|
||||
};
|
||||
function CatProxyClient(url) {
|
||||
var env = {"target": url, "method": ""};
|
||||
|
||||
this.set_env = function(k, v) {
|
||||
env[k] = v || null;
|
||||
|
@ -36,11 +33,13 @@ function Caterpillar(url) {
|
|||
}
|
||||
}
|
||||
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") {
|
||||
var query = arguments.join(' ');
|
||||
rpc.invoke(env.method, {
|
||||
var query = args.join(' ');
|
||||
result = rpc.invoke(env.method, {
|
||||
"hostname": env.mysql_hostname,
|
||||
"username": env.mysql_username,
|
||||
"password": env.mysql_password,
|
||||
|
@ -49,20 +48,22 @@ function Caterpillar(url) {
|
|||
"charset": env.mysql_charset,
|
||||
"query": query
|
||||
}, null);
|
||||
return;
|
||||
} else {
|
||||
result = rpc.invoke(env.method, {}, null);
|
||||
}
|
||||
|
||||
rpc.invoke(env.method, {}, null);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
function create(url) {
|
||||
return new Caterpillar(url);
|
||||
return new CatProxyClient(url);
|
||||
}
|
||||
|
||||
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.global = global;
|
||||
exports.require = global.require;
|
|
@ -1,16 +1,23 @@
|
|||
// jsonrpc2.js
|
||||
// JSON-RPC 2.0 wrapper for WelsonJS framework
|
||||
// Namhyeon Go <abuse@catswords.net>
|
||||
// https://github.com/gnh1201/welsonjs
|
||||
var HTTP = require("lib/http");
|
||||
|
||||
function jsonrpc2(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) {
|
||||
var result;
|
||||
var response = HTTP.create("MSXML")
|
||||
.setContentType("application/json")
|
||||
.setDataType("json")
|
||||
.setRequestBody(encode(method, params, id))
|
||||
.setUserAgent(this.userAgent)
|
||||
.setRequestBody(wrap(method, params, id))
|
||||
.open("POST", this.url)
|
||||
.send()
|
||||
.responseBody
|
||||
|
@ -29,23 +36,23 @@ function jsonrpc2(url) {
|
|||
}
|
||||
}
|
||||
|
||||
function encode(method, params, id) {
|
||||
return JSON.stringify({
|
||||
function wrap(method, params, id) {
|
||||
return {
|
||||
"jsonrpc": "2.0",
|
||||
"method": method,
|
||||
"params": params,
|
||||
"id": id
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function create(url) {
|
||||
return new jsonrpc2(url);
|
||||
}
|
||||
|
||||
exports.encode = encode;
|
||||
exports.wrap = wrap;
|
||||
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.global = global;
|
||||
exports.require = global.require;
|
||||
|
|
|
@ -797,12 +797,12 @@ var test_implements = {
|
|||
excel.open("data\\example.xlsx"); // Open a Excel window
|
||||
},
|
||||
|
||||
"open_excel_new": function() {
|
||||
"open_excel_new": function() {
|
||||
var Office = require("lib/msoffice");
|
||||
|
||||
var excel = new Office.Excel(); // Create a Excel instance
|
||||
excel.open(); // Open a Excel window
|
||||
},
|
||||
},
|
||||
|
||||
"open_excel_with_chatgpt": function() {
|
||||
// Load libraries
|
||||
|
@ -843,13 +843,13 @@ var test_implements = {
|
|||
powerpoint.open("data\\example.pptx"); // Open a PowerPoint window
|
||||
},
|
||||
|
||||
"open_powerpoint_new": function() {
|
||||
"open_powerpoint_new": function() {
|
||||
var Office = require("lib/msoffice");
|
||||
|
||||
var powerpoint = new Office.PowerPoint(); // Create a PowerPoint instance
|
||||
powerpoint.open(); // Open a PowerPoint window
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
"open_word_file": function() {
|
||||
var Office = require("lib/msoffice"); // Load libraries
|
||||
var word = new Office.Word(); // Create an Word instance
|
||||
|
@ -971,6 +971,22 @@ var test_implements = {
|
|||
|
||||
"domparser_test": function() {
|
||||
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));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user