mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-12 04:31:04 +00:00
fix
This commit is contained in:
parent
20571168c8
commit
7baa3a5657
8
app.js
8
app.js
|
@ -67,7 +67,7 @@ var console = {
|
|||
};
|
||||
|
||||
if (typeof(CreateObject) !== "function") {
|
||||
var CreateObject = function(progId, serverName) {
|
||||
var CreateObject = function(progId, serverName, callback) {
|
||||
var progIds = [];
|
||||
var _CreateObject = function(p, s) {
|
||||
if (typeof(WScript) !== "undefined") {
|
||||
|
@ -85,7 +85,11 @@ if (typeof(CreateObject) !== "function") {
|
|||
|
||||
for (var i = 0; i < progIds.length; i++) {
|
||||
try {
|
||||
return _CreateObject(progIds[i], serverName);
|
||||
var obj = _CreateObject(progIds[i], serverName);
|
||||
if (typeof(callback) === "function") {
|
||||
callback(obj, progIds[i]);
|
||||
}
|
||||
return obj;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
};
|
||||
|
|
322
app/index.js
322
app/index.js
|
@ -1,5 +1,5 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// WebPage
|
||||
// index.js
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
var CONFIG = require("lib/config");
|
||||
var FILE = require("lib/file");
|
||||
|
@ -10,239 +10,105 @@ var SHELL = require("lib/shell");
|
|||
var LDPlayer = require("lib/ldplayer");
|
||||
var NoxPlayer = require("lib/noxplayer");
|
||||
|
||||
var apiUrl = CONFIG.readConfig("/ApiUrl").first().getText();
|
||||
var token, userId;
|
||||
var apiUrl = CONFIG.readConfig("/ApiUrl").first().getText();
|
||||
|
||||
var servers = [];
|
||||
var applications = [];
|
||||
|
||||
var assignStaticIP = function() {
|
||||
SHELL.runWindow("cscript app.js shadow");
|
||||
};
|
||||
|
||||
var showLocalApplications = function() {
|
||||
var localApplications = [];
|
||||
|
||||
// LDPlayer
|
||||
var LDPList = LDPlayer.getList();
|
||||
for (var i = 0; i < LDPList.length; i++) {
|
||||
localApplications.push({
|
||||
name: "LDPlayer",
|
||||
uniqueId: LDPList[i].title
|
||||
});
|
||||
}
|
||||
|
||||
// NoxPlayer
|
||||
var NoxPList = NoxPlayer.getList();
|
||||
for (var i = 0; i < NoxPList.length; i++) {
|
||||
localApplications.push({
|
||||
name: "NoxPlayer",
|
||||
uniqueId: NoxPList[i].hostname
|
||||
});
|
||||
}
|
||||
|
||||
// Chrome
|
||||
localApplications.push({
|
||||
name: "Chrome",
|
||||
uniqueId: "John"
|
||||
});
|
||||
localApplications.push({
|
||||
name: "Chrome",
|
||||
uniqueId: "James"
|
||||
});
|
||||
localApplications.push({
|
||||
name: "Chrome",
|
||||
uniqueId: "Jasmine"
|
||||
});
|
||||
|
||||
var template = $("#listview_applications .template");
|
||||
for (var i = 0; i < servers.length; i++) {
|
||||
template.find("select").append($("<option/>").attr({
|
||||
value: servers[i].data.id
|
||||
}).text(servers[i].data.ipaddress));
|
||||
}
|
||||
|
||||
for (var i = 0; i < localApplications.length; i++) {
|
||||
var serverId = "";
|
||||
var getAssignedServers = function() {
|
||||
var assignedServers = [];
|
||||
var onSuccess = function(res) {
|
||||
return;
|
||||
|
||||
var entry = template.clone();
|
||||
entry.find("a.title").text(localApplications[i].uniqueId + " (" + localApplications[i].name + ")");
|
||||
entry.find("select").data("application-name", localApplications[i].name);
|
||||
entry.find("select").data("application-unique-id", localApplications[i].uniqueId);
|
||||
|
||||
for (var k = 0; k < applications.length; k++) {
|
||||
if (applications[k].name == localApplications[i].name
|
||||
&& applications[k].uniqueId == localApplications[i].uniqueId
|
||||
&& applications[k].createdBy == userId)
|
||||
{
|
||||
entry.find("select").data("application-id", applications[i].id);
|
||||
serverId = applications[k].server;
|
||||
break;
|
||||
for (var i = 0; i < res.data.length; i++) {
|
||||
if (res.data[i].assigned_to == userId) {
|
||||
assignedServers.push(res.data[i].server);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
entry.find("select").change(function() {
|
||||
if ($(this).val() != "") {
|
||||
var data = {
|
||||
"status": "published",
|
||||
"name": $(this).data("application-name"),
|
||||
"unique_id": $(this).data("application-unique-id"),
|
||||
"created_by": userId,
|
||||
"server": $(this).val()
|
||||
};
|
||||
var applicationId = $(this).data("application-id");
|
||||
|
||||
var req, res;
|
||||
var onSuccess = function(res) {
|
||||
if ("error" in res) {
|
||||
console.error(res.error.message);
|
||||
} else {
|
||||
console.log("반영되었습니다.");
|
||||
}
|
||||
};
|
||||
|
||||
if (applicationId) {
|
||||
req = $.ajax({
|
||||
type: "PATCH",
|
||||
url: apiUrl + "/netsolid/items/applications/" + applicationId,
|
||||
data: JSON.stringify(data),
|
||||
contentType: 'application/json-patch+json',
|
||||
success: onSuccess
|
||||
});
|
||||
} else {
|
||||
req = HTTP.post(apiUrl + "/netsolid/items/applications", JSON.stringify(data), {
|
||||
"Content-Type": "application/json"
|
||||
});
|
||||
res = JSON.parse(req.responseText);
|
||||
onSuccess(res);
|
||||
}
|
||||
|
||||
showApplications();
|
||||
}
|
||||
}).val(serverId);
|
||||
entry.appendTo("#listview_applications");
|
||||
}
|
||||
|
||||
template.css("display", "none");
|
||||
HTTP.create()
|
||||
.setHeaders({
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Authorization": "bearer " + token,
|
||||
//"Pragma": "no-cache",
|
||||
//"Cache-Control": "no-cache",
|
||||
"If-Modified-Since": "Sat, 1 Jan 2000 00:00:00 GMT"
|
||||
})
|
||||
//.get(apiUrl + "/netsolid/items/assignedservers", onSuccess)
|
||||
;
|
||||
};
|
||||
|
||||
var showApplications = function() {
|
||||
var xmlStrings = [];
|
||||
var getMyServers = function() {
|
||||
var assignedServers = getAssignedServers();
|
||||
|
||||
return;
|
||||
|
||||
|
||||
var onSuccess = function(res) {
|
||||
var template = $("#listview_servers .template");
|
||||
|
||||
var req = HTTP.get(apiUrl + "/netsolid/items/applications", "", {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Authorization": "bearer " + token,
|
||||
//"Pragma": "no-cache",
|
||||
//"Cache-Control": "no-cache",
|
||||
"If-Modified-Since": "Sat, 1 Jan 2000 00:00:00 GMT"
|
||||
});
|
||||
var res = JSON.parse(req.responseText);
|
||||
|
||||
xmlStrings.push('<?xml version="1.0" encoding="UTF-8"?>');
|
||||
xmlStrings.push("<StaticIP>");
|
||||
for (var i = 0; i < res.data.length; i++) {
|
||||
xmlStrings.push("<Item>");
|
||||
xmlStrings.push("<Name>" + res.data[i].name + "</Name>");
|
||||
xmlStrings.push("<UniqueID>" + res.data[i].unique_id + "</UniqueID>");
|
||||
for (var k = 0; k < servers.length; k++) {
|
||||
if (servers[k].data.id == res.data[i].server) {
|
||||
xmlStrings.push("<IPAddress>" + servers[k].data.ipaddress + "</IPAddress>");
|
||||
applications.push({
|
||||
id: res.data[i].id,
|
||||
name: res.data[i].name,
|
||||
uniqueId: res.data[i].unique_id,
|
||||
server: res.data[i].server,
|
||||
ipAddress: servers[k].data.ipaddress,
|
||||
createdBy: userId
|
||||
for (var i = 0; i < res.data.length; i++) {
|
||||
if (assignedServers.indexOf(res.data[i].id) > -1) {
|
||||
var entry = template.clone();
|
||||
entry.find("a.title").text(res.data[i].ipaddress);
|
||||
entry.find("div.description").text(res.data[i].name);
|
||||
entry.appendTo("#listview_servers");
|
||||
|
||||
servers.push({
|
||||
"data": res.data[i],
|
||||
"entry": entry
|
||||
});
|
||||
}
|
||||
}
|
||||
xmlStrings.push("</Item>");
|
||||
}
|
||||
xmlStrings.push("</StaticIP>");
|
||||
|
||||
FILE.writeFile("staticip.xml", xmlStrings.join("\r\n"), "utf-8");
|
||||
};
|
||||
|
||||
var getAssignedServers = function() {
|
||||
var assignedServers = [];
|
||||
|
||||
var req = HTTP.get(apiUrl + "/netsolid/items/assignedservers", "", {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Authorization": "bearer " + token,
|
||||
//"Pragma": "no-cache",
|
||||
//"Cache-Control": "no-cache",
|
||||
"If-Modified-Since": "Sat, 1 Jan 2000 00:00:00 GMT"
|
||||
});
|
||||
|
||||
var res = JSON.parse(req.responseText);
|
||||
|
||||
for (var i = 0; i < res.data.length; i++) {
|
||||
if (res.data[i].assigned_to == userId) {
|
||||
assignedServers.push(res.data[i].server);
|
||||
}
|
||||
}
|
||||
|
||||
return assignedServers;
|
||||
};
|
||||
|
||||
var showServers = function() {
|
||||
OldBrowser.setContent(FILE.readFile("app\\servers.html", "utf-8"));
|
||||
|
||||
var assignedServers = getAssignedServers();
|
||||
var req = HTTP.get(apiUrl + "/netsolid/items/servers", "", {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Authorization": "bearer " + token
|
||||
});
|
||||
var res = JSON.parse(req.responseText);
|
||||
var template = $("#listview_servers .template");
|
||||
|
||||
for (var i = 0; i < res.data.length; i++) {
|
||||
if (assignedServers.indexOf(res.data[i].id) > -1) {
|
||||
var entry = template.clone();
|
||||
entry.find("a.title").text(res.data[i].ipaddress);
|
||||
entry.find("div.description").text(res.data[i].name);
|
||||
entry.appendTo("#listview_servers");
|
||||
|
||||
servers.push({
|
||||
"data": res.data[i],
|
||||
"entry": entry
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
template.css("display", "none");
|
||||
|
||||
document.getElementById("btn_logout").onclick = function() {
|
||||
if (FILE.fileExists("token.txt")) {
|
||||
token = FILE.deleteFile("token.txt")
|
||||
}
|
||||
|
||||
if (FILE.fileExists("userid.txt")) {
|
||||
userId = FILE.deleteFile("userid.txt");
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
template.css("display", "none");
|
||||
|
||||
document.getElementById("btn_logout").onclick = function() {
|
||||
if (FILE.fileExists("token.txt")) {
|
||||
token = FILE.deleteFile("token.txt")
|
||||
}
|
||||
|
||||
if (FILE.fileExists("userid.txt")) {
|
||||
userId = FILE.deleteFile("userid.txt");
|
||||
}
|
||||
|
||||
exit(0);
|
||||
};
|
||||
|
||||
var pingTest = function() {
|
||||
for (var i = 0; i < servers.length; i++) {
|
||||
var responseTime = SYS.ping(servers[i].data.ipaddress);
|
||||
servers[i].entry.find("span.ping").text(responseTime + " ms");
|
||||
}
|
||||
};
|
||||
document.getElementById("btn_pingtest").onclick = pingTest;
|
||||
setInterval(pingTest, 5000);
|
||||
pingTest();
|
||||
|
||||
showApplications();
|
||||
|
||||
document.getElementById("btn_assign").onclick = function() {
|
||||
showApplications();
|
||||
assignStaticIP();
|
||||
};
|
||||
};
|
||||
|
||||
var pingTest = function() {
|
||||
for (var i = 0; i < servers.length; i++) {
|
||||
var responseTime = SYS.pingTest(servers[i].data.ipaddress);
|
||||
servers[i].entry.find("span.ping").text(responseTime + " ms");
|
||||
}
|
||||
};
|
||||
document.getElementById("btn_pingtest").onclick = pingTest;
|
||||
setInterval(pingTest, 5000);
|
||||
pingTest();
|
||||
return;
|
||||
|
||||
showApplications();
|
||||
|
||||
document.getElementById("btn_assign").onclick = function() {
|
||||
showApplications();
|
||||
assignStaticIP();
|
||||
};
|
||||
HTTP.create()
|
||||
.setHeaders({
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Authorization": "Bearer " + token
|
||||
})
|
||||
.get(apiUrl + "/netsolid/items/servers", onSuccess)
|
||||
;
|
||||
};
|
||||
|
||||
|
||||
if (FILE.fileExists("token.txt")) {
|
||||
token = FILE.readFile("token.txt", "utf-8");
|
||||
}
|
||||
|
@ -252,8 +118,8 @@ if (FILE.fileExists("userid.txt")) {
|
|||
}
|
||||
|
||||
if (typeof(token) !== "undefined") {
|
||||
showServers();
|
||||
showLocalApplications();
|
||||
OldBrowser.setContent(FILE.readFile("app\\servers.html", "utf-8"));
|
||||
getMyServers();
|
||||
} else {
|
||||
OldBrowser.setContent(FILE.readFile("app\\login.html", "utf-8"));
|
||||
|
||||
|
@ -267,20 +133,20 @@ if (typeof(token) !== "undefined") {
|
|||
"password": document.getElementById("txt_password").value
|
||||
};
|
||||
|
||||
var req = HTTP.post(apiUrl + "/netsolid/auth/authenticate", JSON.stringify(credential), {
|
||||
"Content-Type": "application/json"
|
||||
});
|
||||
HTTP.create()
|
||||
.setContentType("application/json")
|
||||
.setRequestBody(credential)
|
||||
.post(apiUrl + "/netsolid/auth/authenticate", function(res) {
|
||||
if ("error" in res) {
|
||||
console.error(res.error.message);
|
||||
} else if ("data" in res) {
|
||||
console.log("ok");
|
||||
FILE.writeFile("token.txt", res.data.token, "utf-8");
|
||||
FILE.writeFile("userid.txt", res.data.user.id, "utf-8");
|
||||
|
||||
var res = JSON.parse(req.responseText);
|
||||
|
||||
if ("error" in res) {
|
||||
console.error(res.error.message);
|
||||
} else if ("data" in res) {
|
||||
console.log("ok");
|
||||
FILE.writeFile("token.txt", res.data.token, "utf-8");
|
||||
FILE.writeFile("userid.txt", res.data.user.id, "utf-8");
|
||||
|
||||
window.location.reload();
|
||||
}
|
||||
window.location.reload();
|
||||
}
|
||||
})
|
||||
;
|
||||
};
|
||||
}
|
||||
|
|
296
lib/http.js
296
lib/http.js
|
@ -2,127 +2,183 @@
|
|||
// HTTP API
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.VERSIONINFO = "HTTP Lib (http.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
//var WINSOCK = require("lib/winsock");
|
||||
|
||||
var HTTPObject = function() {
|
||||
this.interface = null;
|
||||
this.contentType = "application/octet-stream";
|
||||
this.requestBody = "";
|
||||
this.responseBody = null;
|
||||
this.method = "";
|
||||
this.headers = {};
|
||||
this.dataType = "";
|
||||
|
||||
this.create = function() {
|
||||
this.interface = CreateObject([
|
||||
"Microsoft.XMLHTTP"
|
||||
"WinHttp.WinHttpRequest.5.1",
|
||||
"Msxml2.XMLHTTP",
|
||||
"Msxml2.XMLHTTP.7.0",
|
||||
"Msxml2.XMLHTTP.6.0",
|
||||
"Msxml2.XMLHTTP.5.O",
|
||||
"Msxml2.XMLHTTP.4.O",
|
||||
"Msxml2.XMLHTTP.3.O",
|
||||
"Msxml2.XMLHTTP.2.6"
|
||||
], function(obj, progId) {
|
||||
switch (progId) {
|
||||
case "WinHttp.WinHttpRequest.5.1":
|
||||
obj.setTimeouts(30000, 30000, 30000, 0);
|
||||
break;
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
this.isJSONRequest = function() {
|
||||
return (this.contentType === "application/json");
|
||||
};
|
||||
|
||||
this.isJSONResponse = function() {
|
||||
if (this.dataType === "json") {
|
||||
return true;
|
||||
} else {
|
||||
var headers = this.getHeaders();
|
||||
for (var key in headers) {
|
||||
var _k = key.toLowerCase();
|
||||
var _v = headers[key].toLowerCase();
|
||||
if (_k === "content-type" && _v === "application/json") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
this.setMethod = function(method) {
|
||||
this.method = method;
|
||||
};
|
||||
|
||||
this.setDataType = function(type) {
|
||||
this.dataType = type;
|
||||
return this;
|
||||
};
|
||||
|
||||
this.setContentType = function(type) {
|
||||
this.contentType = type;
|
||||
return this;
|
||||
};
|
||||
|
||||
this.setRequestBody = function(data) {
|
||||
this.requestBody = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
this.setResponseBody = function(data) {
|
||||
this.responseBody = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
this.setHeader = function(key, value) {
|
||||
this.header[key] = value;
|
||||
return this;
|
||||
};
|
||||
|
||||
this.setHeaders = function(headers) {
|
||||
var headers = (typeof(headers) !== "undefined") ? headers : {};
|
||||
for (var key in headers) {
|
||||
var value = headers[key];
|
||||
this.setHeader(key, value);
|
||||
if (key.toLowerCase() == "content-type") {
|
||||
this.contentType = value.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
this.getHeader = function(key) {
|
||||
return this.interface.getResponseHeader(key);
|
||||
};
|
||||
|
||||
this.getHeaders = function() {
|
||||
var raw = this.interface.getAllResponseHeaders();
|
||||
|
||||
return raw.split(/[\r\n]+/).filter(function(s) {
|
||||
return s.trim().length > 0;
|
||||
}).map(function(s) {
|
||||
return s.trim().split(": ");
|
||||
}).reduce(function(acc, c) {
|
||||
acc[c[0].trim()] = c[1].trim();
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
|
||||
this.open = function(method, url, isAsync) {
|
||||
this.setMethod(method.toUpperCase());
|
||||
|
||||
switch (this.method) {
|
||||
case "POST":
|
||||
this.interface.open(method, url, isAsync);
|
||||
break;
|
||||
|
||||
case "GET":
|
||||
this.interface.open(method, url, isAsync);
|
||||
break;
|
||||
|
||||
case "PATCH":
|
||||
console.error("Not supported yet: " + method); // TODO
|
||||
break;
|
||||
|
||||
default:
|
||||
console.error("Not supported HTTP method: " + method);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
this.send = function(callback) {
|
||||
this.setHeader("Content-Type", this.contentType);
|
||||
|
||||
for (var key in headers) {
|
||||
this.instance.setRequestHeader(key, headers[key]);
|
||||
}
|
||||
|
||||
if (this.isJSONRequest() && typeof(this.requestBody) === "object") {
|
||||
this.interface.send(JSON.stringify(this.requestBody));
|
||||
} else {
|
||||
this.interface.send(this.requestBody);
|
||||
}
|
||||
|
||||
if (this.isJSONResponse()) {
|
||||
this.setResponseBody(JSON.parse(this.interface.responseText));
|
||||
} else {
|
||||
this.setResponseBody(this.interface.responseText);
|
||||
}
|
||||
|
||||
if (typeof(callback) === "function") {
|
||||
callback(this.responseBody);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
this.post = function(url, callback) {
|
||||
return this.open("POST", url, false).send(callback);
|
||||
};
|
||||
|
||||
this.get = function(url, callback) {
|
||||
return;
|
||||
//return this.open("GET", url, false).send(callback);
|
||||
};
|
||||
|
||||
this.create();
|
||||
};
|
||||
|
||||
exports.create = function() {
|
||||
var http;
|
||||
|
||||
try {
|
||||
http = CreateObject("Microsoft.XMLHTTP");
|
||||
} catch(e) {
|
||||
http = CreateObject("WinHttp.WinHttpRequest.5.1");
|
||||
http.setTimeouts(30000, 30000, 30000, 0);
|
||||
}
|
||||
|
||||
return http;
|
||||
}
|
||||
|
||||
exports.addHeaders = function(http, headers) {
|
||||
var headers = (typeof(headers) !== "undefined") ? headers : {};
|
||||
|
||||
var content = false;
|
||||
for (var key in headers) {
|
||||
var value = headers[key];
|
||||
|
||||
http.setRequestHeader(key, value);
|
||||
if (key.toUpperCase() == "CONTENT-TYPE") {
|
||||
content = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!content) {
|
||||
http.setRequestHeader("Content-Type", "application/octet-stream");
|
||||
}
|
||||
return (new HTTPObject());
|
||||
};
|
||||
|
||||
exports.post = function(url, data, headers) {
|
||||
var data = (typeof(data) !== "undefined") ? data : "";
|
||||
|
||||
var http = exports.create();
|
||||
|
||||
http.open("POST", url, false);
|
||||
exports.addHeaders(http, headers);
|
||||
http.send(data);
|
||||
|
||||
return http;
|
||||
};
|
||||
|
||||
exports.get = function(url, data, headers) {
|
||||
var data = (typeof(data) !== "undefined") ? data : "";
|
||||
var http = exports.create();
|
||||
|
||||
http.open("GET", url, false);
|
||||
exports.addHeaders(http, headers);
|
||||
http.send(data);
|
||||
|
||||
return http;
|
||||
};
|
||||
|
||||
/**
|
||||
* Upload a file, off zombie, to stager
|
||||
*
|
||||
* @param filepath - the full path to the file to send
|
||||
* @param header_uuid - a unique identifier for this file
|
||||
* @param header_key - optional HTTP header tag to send uuid over
|
||||
*
|
||||
* @return object - the HTTP object
|
||||
*
|
||||
**/
|
||||
exports.upload = function(filepath, header_uuid, header_key) {
|
||||
var key = (typeof(header_key) !== "undefined") ? header_key : "ETag";
|
||||
|
||||
var data = $.file.readBinary(filepath);
|
||||
|
||||
// we must replace null bytes or MS will cut off the body
|
||||
data = data.replace(/\\/g, "\\\\");
|
||||
data = data.replace(/\0/g, "\\0");
|
||||
|
||||
var headers = {};
|
||||
headers[key] = header_uuid;
|
||||
|
||||
return $.work.report(data, headers);
|
||||
};
|
||||
|
||||
exports.download = function(filepath, header_uuid, header_key) {
|
||||
var key = (typeof(header_key) !== "undefined") ? header_key : "ETag";
|
||||
|
||||
var headers = {};
|
||||
headers[key] = header_uuid;
|
||||
|
||||
return exports.downloadEx("POST", $.work.make_url(), headers, filepath);
|
||||
};
|
||||
|
||||
exports.downloadEx = function(verb, url, headers, path) {
|
||||
if (verb == "GET") {
|
||||
var http = exports.get(url, headers);
|
||||
} else {
|
||||
var http = exports.post(url, "", headers);
|
||||
}
|
||||
|
||||
var stream = LIB.CreateObject("Adodb.Stream");
|
||||
stream.Type = 1;
|
||||
stream.Open();
|
||||
stream.Write(http.responseBody);
|
||||
|
||||
var data = exports.bin2str(stream);
|
||||
$.file.write(path, data);
|
||||
};
|
||||
|
||||
exports.bin2str = function(stream) {
|
||||
stream.Flush();
|
||||
stream.Position = 0;
|
||||
|
||||
var bin = stream.Read();
|
||||
var rs = LIB.CreateObject("Adodb.RecordSet");
|
||||
rs.Fields.Append("temp", 201, stream.Size);
|
||||
|
||||
rs.Open();
|
||||
rs.AddNew();
|
||||
rs("temp").AppendChunk(bin);
|
||||
rs.Update();
|
||||
var data = rs.GetString();
|
||||
rs.Close();
|
||||
return data.substring(0, data.length - 1);
|
||||
};
|
||||
exports.VERSIONINFO = "HTTP Lib (http.js) version 0.2";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
|
10
lib/std.js
10
lib/std.js
|
@ -79,13 +79,13 @@ exports.require = global.require;
|
|||
// Emulate Server.CreateObject
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.CreateObject = function(progId, serverName) {
|
||||
exports.CreateObject = function(progId, serverName, callback) {
|
||||
var progIds = [];
|
||||
var _CreateObject = function(p, s) {
|
||||
if (typeof(WScript) !== "undefined") {
|
||||
return WScript.CreateObject(p, s);
|
||||
} else {
|
||||
return new ActiveXObject(p, s);
|
||||
return new ActiveXObject(p);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -97,7 +97,11 @@ exports.CreateObject = function(progId, serverName) {
|
|||
|
||||
for (var i = 0; i < progIds.length; i++) {
|
||||
try {
|
||||
return _CreateObject(progIds[i], serverName);
|
||||
var obj = _CreateObject(progIds[i], serverName);
|
||||
if (typeof(callback) === "function") {
|
||||
callback(obj, progIds[i]);
|
||||
}
|
||||
return obj;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
};
|
||||
|
|
|
@ -192,10 +192,10 @@ exports.createShortcut = function(shoutcutName, fileName) {
|
|||
link.Save();
|
||||
};
|
||||
|
||||
exports.pingTest = function(remoteAddr) {
|
||||
exports.ping = function(address) {
|
||||
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
|
||||
var query = "Select * From win32_PingStatus where address='" + remoteAddr + "'";
|
||||
|
||||
var query = "Select * From win32_PingStatus where address='" + address + "'";
|
||||
|
||||
var colItems = wmi.ExecQuery(query);
|
||||
var enumItems = new Enumerator(colItems);
|
||||
var objItem = enumItems.item();
|
||||
|
|
|
@ -1 +1 @@
|
|||
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwiZXhwIjoxNjA0NTY1NDQ4LCJ0dGwiOjIwLCJ0eXBlIjoiYXV0aCIsImtleSI6Ijg1N2NlZDg1LTMzOWEtNDViNS04YTQ5LTJjOGM0YmE4ZDVmNCIsInByb2plY3QiOiJuZXRzb2xpZCJ9.1kpN2lnVJs_grRtSKMhIFVxdDsOnttr5IaQ8SEKVISA
|
||||
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwiZXhwIjoxNjA0OTk3NTc5LCJ0dGwiOjIwLCJ0eXBlIjoiYXV0aCIsImtleSI6Ijg1N2NlZDg1LTMzOWEtNDViNS04YTQ5LTJjOGM0YmE4ZDVmNCIsInByb2plY3QiOiJuZXRzb2xpZCJ9.MXF1Pn7YveGVL7i-UpQGG64ARJu-CCQxbSUU-N38XOw
|
Loading…
Reference in New Issue
Block a user