Переглянути джерело

discover node path for privileged execution

production^2
Pradeep Bhaskaran 4 роки тому
джерело
коміт
8d3fad85ad
1 змінених файлів з 41 додано та 31 видалено
  1. 41
    31
      index.js

+ 41
- 31
index.js Переглянути файл

@@ -309,6 +309,7 @@ var __runcmd = function(label){
})
}
, 'runas' : ()=>{
console.log('Testing Elevation')
return isRunningElevated().then(
(isElevated) => {
if(isElevated) {
@@ -333,34 +334,41 @@ var __runcmd = function(label){
}
catch(e) { } //Ignore
// PB : TODO -- Convert all the cli args back to string.
var namedArgs = [];
Object.keys(processedArgs).forEach((v)=>{ v!='_' ? namedArgs.push('--'+v+'='+processedArgs[v]) : null; })
//console.log(' namedArgs : ' + namedArgs)
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
nodeShellExec('MSHTA', [`"${args.join('" "')}"`]
, {
inherit : true
, shell: true
, env: process.env
, runas : 'self'
, title : `runas`
}
).then(()=>{
// runas returned.
try {
var runaslog = JSON.parse('[ { "success" : true, "result" : "runas Log" }' + fs.readFileSync('run.log', { flags : 'a+'}) + ']');
runaslog.forEach((logEntry)=>{
logEntry.success ? (console.log(['success :' + logEntry.result]), console.log((logEntry.messages || []).join(' '))) : (console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' ')))
})
}
catch(e){
// Ignore nonexistent log
console.warn('Run log error probably was not created by runas : ' + e)
}
// Find node path to send to hta.
nodeShellExec('where', ['node']).then(r => {
console.log('result : ' + r)
// throw 'rrrrrrrrrrrrrrrrr'
// PB : TODO -- Convert all the cli args back to string.
var namedArgs = [];
Object.keys(processedArgs).forEach((v)=>{ v!='_' ? namedArgs.push('--'+v+'='+processedArgs[v]) : null; })
//console.log(' namedArgs : ' + namedArgs)
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
args.push('--nodepath='+r[r.length-1])
nodeShellExec('MSHTA', [`"${args.join('" "')}"`]
, {
inherit : true
, shell: true
, env: process.env
, runas : 'self'
, title : `runas`
}
).then(()=>{
// runas returned.
try {
var runaslog = JSON.parse('[ { "success" : true, "result" : "runas Log" }' + fs.readFileSync('run.log', { flags : 'a+'}) + ']');
runaslog.forEach((logEntry)=>{
logEntry.success ? (console.log(['success :' + logEntry.result]), console.log((logEntry.messages || []).join(' '))) : (console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' ')))
})
}
catch(e){
// Ignore nonexistent log
console.warn('Run log error probably was not created by runas : ' + e)
}
})
.catch(err => console.error('Elevation failed : ' + err));
})
.catch(err => console.error('Elevation failed : ' + err));
})
}
, 'push' : ()=>{
@@ -1067,9 +1075,11 @@ function nodeShellExec() {
if(opts.stdio !== 'ignore') {
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
child.on('error', (chunk) => { success = false; messages.push(chunk); /*console.error(chunk)*/ });
child.stderr.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
child.stdout.on('data', (chunk) => { chunk.trim() === '' ? null : messages.push(chunk); /* console.log('d: ' + chunk) */ });
child.on('error', (chunk) => { success = false; messages.push(chunk); /* console.error('e: ' + chunk) */ } );
child.stderr.on('data', (chunk) => { messages.push(chunk);
// console.error('stderr e: ' + chunk)
});
}
child.on('close', (code) => {
if(+code !== 0) success = false;
@@ -1086,7 +1096,7 @@ function nodeShellExec() {
}
}
if(code !== 0) return reject(code)
resolve(true)
resolve(messages)
});
}
else {

Завантаження…
Відмінити
Зберегти