mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-10-30 12:31:17 +00:00
Update powershell.js
This commit is contained in:
parent
4867faab16
commit
8b1722cedb
|
|
@ -4,27 +4,33 @@
|
||||||
|
|
||||||
var SHELL = require("lib/shell");
|
var SHELL = require("lib/shell");
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
// new powershell interface
|
|
||||||
|
|
||||||
function PowershellInterface() {
|
function PowershellInterface() {
|
||||||
this.type = -1;
|
this.execType = "ps1";
|
||||||
|
this.dataType = -1;
|
||||||
this.target = null;
|
this.target = null;
|
||||||
|
|
||||||
|
this.setExecType = function(execType;) {
|
||||||
|
this.execType = execType;
|
||||||
|
};
|
||||||
|
|
||||||
this.load = function(script) {
|
this.load = function(script) {
|
||||||
this.target = script;
|
this.target = script;
|
||||||
this.type = 0;
|
this.dataType = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.loadCommand = function(command) {
|
||||||
|
this.target = command;
|
||||||
|
this.dataType = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.loadFile = function(filename) {
|
this.loadFile = function(filename) {
|
||||||
this.target = filename;
|
this.target = filename;
|
||||||
this.type = 1;
|
this.dataType = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.loadRemoteUrl = function(url) {
|
this.loadUrl = function(url) {
|
||||||
this.target = url;
|
this.target = url;
|
||||||
this.type = 2;
|
this.dataType = 3;
|
||||||
};
|
};
|
||||||
|
|
||||||
// For example:
|
// For example:
|
||||||
|
|
@ -40,77 +46,99 @@ function PowershellInterface() {
|
||||||
switch (scheme) {
|
switch (scheme) {
|
||||||
case 'http':
|
case 'http':
|
||||||
case 'https':
|
case 'https':
|
||||||
this.loadRemoteUrl(target);
|
this.loadUrl(target);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'file':
|
case 'file':
|
||||||
|
this.loadFile(target);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'data':
|
||||||
this.load(target);
|
this.load(target);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
console.error("Invalid scheme");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.exec = function() {
|
this.exec = function(args) {
|
||||||
switch (this.type) {
|
if (this.execType != "ps1") {
|
||||||
case 2:
|
console.warn("The execType is not set 'ps1'. Will be forward this request to the default shell.");
|
||||||
// todo
|
SHELL.exec(this.target);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// default arguments
|
||||||
|
var cmd = [
|
||||||
|
"powershell.exe",
|
||||||
|
"-NoProfile",
|
||||||
|
"-ExecutionPolicy",
|
||||||
|
"ByPass",
|
||||||
|
"-nologo"
|
||||||
|
];
|
||||||
|
|
||||||
|
switch (this.dataType) {
|
||||||
|
case 3: // dataType: URL(3)
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: // dataType: file(2)
|
||||||
|
cmd.push("-file");
|
||||||
|
cmd.push(scriptName + ".ps1");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1: // dataType: command(1)
|
||||||
|
cmd.push("-Command");
|
||||||
|
if (typeof this.target === "string") {
|
||||||
|
cmd.push("& {" + cmd + "}");
|
||||||
|
} else {
|
||||||
|
cmd.push("& {" + SHELL.build(cmd) + "}");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0: // dataType: script(0)
|
||||||
// todo
|
// todo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0:
|
|
||||||
// todo
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof(cmd) !== "undefined") {
|
||||||
|
cmd = cmd.concat(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SHELL.exec(cmd);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.runAs = function() {
|
||||||
|
if (this.execType != "ps1") {
|
||||||
|
console.warn("The execType is not set 'ps1'. Will be forward this request to the default shell.");
|
||||||
|
return execCommand("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.build(this.target)) + "\" -Verb RunAs");
|
||||||
|
} else {
|
||||||
|
return execCommand("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.build(cmd)) + "\" -Verb RunAs");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
function execScript(scriptName, args) {
|
function execScript(scriptName, args) {
|
||||||
var cmd = [
|
return (new PowershellInterface()).loadFile(scriptName).exec(args);
|
||||||
"powershell.exe",
|
|
||||||
"-NoProfile",
|
|
||||||
"-ExecutionPolicy",
|
|
||||||
"ByPass",
|
|
||||||
"-nologo",
|
|
||||||
"-file",
|
|
||||||
scriptName + ".ps1"
|
|
||||||
];
|
|
||||||
|
|
||||||
if (typeof(cmd) !== "undefined") {
|
|
||||||
cmd = cmd.concat(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
return SHELL.exec(cmd);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function execCommand(cmd) {
|
function execCommand(cmd) {
|
||||||
return SHELL.exec([
|
return (new PowershellInterface()).loadCommand(cmd).exec();
|
||||||
"powershell.exe",
|
|
||||||
"-NoProfile",
|
|
||||||
"-ExecutionPolicy",
|
|
||||||
"ByPass",
|
|
||||||
"-nologo",
|
|
||||||
"-Command",
|
|
||||||
"& {" + cmd + "}"
|
|
||||||
]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function runAs(cmd) {
|
function runAs(cmd) {
|
||||||
return execCommand("Start-Process cmd \"/q /c " + SHELL.addslashes(SHELL.makeCmdLine(cmd)) + "\" -Verb RunAs");
|
return (new PowershellInterface()).setExecType("cmd").runAs();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.execScript = execScript;
|
exports.execScript = execScript;
|
||||||
exports.execCommand = execCommand;
|
exports.execCommand = execCommand;
|
||||||
exports.runAs = runAs;
|
exports.runAs = runAs;
|
||||||
|
|
||||||
exports.VERSIONINFO = "Powershell (powershell.js) version 0.1.1";
|
exports.VERSIONINFO = "Powershell (powershell.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;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user