Explorar el Código

Refactored elevated privilege execution

master
Pradeep Bhaskaran hace 4 años
padre
commit
67cbc7a7b7
Se han modificado 1 ficheros con 89 adiciones y 56 borrados
  1. 89
    56
      index.js

+ 89
- 56
index.js Ver fichero

@@ -84,6 +84,19 @@ function any(iterable, continueOnFailure) {
);
}

var isRunningElevated = ()=>{
return nodeShellExec( "fsutil", ["dirty", "query", "C:"], {
inherit : true, shell: true
, env: process.env
, title : `check privileged execution mode using fsutil dirty query C:`
}).then((exitcode)=>{
console.log('Elevated')
return true;
}).catch(()=>{
console.log('Not Elevated');
throw false;
});
}


var cli = 'elxr';
@@ -214,6 +227,23 @@ var __runcmd = function(label){
})
})
}
, 'runas' : ()=>{
return isRunningElevated().then(
() => op[ processedArgs.label || processedArgs._[0] || 'h']()
)
.catch(()=>{
console.log('Not Elevated');
console.log('Requesting Elevated Privileges')
nodeShellExec('MSHTA', [`javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('node', 'elxr ${processedArgs._[0]} ${processedArgs._[1]} ${processedArgs._[2]} --runas=true', '', 'runas', 1);close();`]
, {
// inherit : true
// , shell: true
env: process.env
, title : `runas`
}
);
})
}
, 'pull' : (label) => {
var env = Object.assign({}, process.env); // Shallow clone it.
// console.dir(env)
@@ -248,36 +278,12 @@ var __runcmd = function(label){
}
}

var isElevated;
try {
nodeShellExec( "fsutil", ["dirty", "query", "C:"], {
inherit : true, shell: true
, env: process.env
, title : `check privileged execution mode using fsutil dirty query C:`
}).then((exitcode)=>{
console.log('Elevated')
var isElevated = true;
console.dir(processedArgs._[1])
if(processedArgs._[1] === 'runas') elevatedRunasRepos.forEach(performPull);
else gitRepos.forEach(performPull);
}).catch(()=>{
console.log('Not Elevated');
gitRepos.forEach(performPull)
console.log('Requesting Elevated Privileges')
nodeShellExec('MSHTA', ["javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('node', 'elxr pull runas', '', 'runas', 1);close();"]
, {
// inherit : true
// , shell: true
env: process.env
, title : `runas`
}
);
});
// isElevated = true;
}
catch ( e ) {
console.error(e)
}
if(!processedArgs.runas) gitRepos.forEach(performPull)
return isRunningElevated().then(
()=> elevatedRunasRepos.forEach(performPull))
.catch(
() => op['runas']()
)
}
, 'npmi' : ()=>{
@@ -340,35 +346,62 @@ var __runcmd = function(label){
})
}
, 'use' : ()=>{
try {
var runconfig = require('./run.js')
if(processedArgs._[1] && runconfig.use === processedArgs._[1]) {
return;

if(!processedArgs.runas){
try {
var runconfig = require('./run.js')
if(processedArgs._[1] && runconfig.use === processedArgs._[1]) {
return;
}
else runconfig.use = processedArgs._[1];
fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig))
}
catch(e) {
runconfig = { use : processedArgs._[1] };
fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig))
}
else runconfig.use = processedArgs._[1];
fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig))
op['runas']()
}
catch(e) {
runconfig = { use : processedArgs._[1] };
fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig))
else {
var runconfig = require('../run.js')
console.log('runconfig.use : ' + runconfig.use)
var tasks = [
()=>{
var p = nodeShellExec('rm', ['config'], {
inherit : true, shell: true
, cwd : repo
, env: process.env
, title : `rm 'package-lock.json' for ${repo}`
}).catch((e)=>{ console.error(e) })
return p;
},
()=>{
var p = nodeShellExec('rm', ['data'], {
inherit : true, shell: true
, cwd : repo
, env: process.env
, title : `rm 'package-lock.json' for ${repo}`
}).catch((e)=>{ console.error(e) })
return p;
},
()=>{
var p = nodeShellExec('mklink', ['/D', 'data', runconfig.use + '-data'], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
},
()=>{
var p = nodeShellExec('mklink', ['/D', 'config', runconfig.use + '-config'], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
}
]
any(tasks)
}
var tasks = [
()=>{
var p = nodeShellExec('mklink', ['/D', 'data', 'data-' + runconfig.use], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
},
()=>{
var p = nodeShellExec('mklink', ['/D', 'config', 'config-' + runconfig.use], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
}
]
any(tasks)

// Antibiotic stewardship program.
// 1st use is fine.

Cargando…
Cancelar
Guardar