Kaynağa Gözat

fixed elxr use

master
Pradeep Bhaskaran 4 yıl önce
ebeveyn
işleme
ad05f20506
2 değiştirilmiş dosya ile 70 ekleme ve 49 silme
  1. 57
    42
      index.js
  2. 13
    7
      windowselevate.hta

+ 57
- 42
index.js Dosyayı Görüntüle

@@ -2,6 +2,15 @@
// --------------
// elxr
// A cli tool for elixr.

// PB : TODO --
// runas bypass non elevated tasks when we request privelege
// runas message is always error needs to be fixed.
// runas wait needs to be parallelized.
// suppress elevation check error messages
// support runas lauched directly from shell.
// pass in environment in hta to shellexecute.

const { existsSync } = require('fs');
const fs = require('fs')
const { spawn, spawnSync } = require('child_process');
@@ -163,8 +172,10 @@ var elevatedRunasRepos = [
]

var productionRepos = [
'elixir-config-production'
'elixir-config-production'
]
var productionIsAllowed = true;
if(productionIsAllowed) gitRepos = gitRepos.concat(productionRepos)

var env = Object.assign({}, process.env); // Shallow clone it.
var __runcmd = function(label){
@@ -274,18 +285,15 @@ var __runcmd = function(label){
// PB : TODO -- Convert all the cli args back to string.
var namedArgs = [];
Object.keys(processedArgs).forEach((v)=>{ v!='_' ? namedArgs.push('--'+v+'='+processedArgs[v]) : null; })
var cargs = `${processedArgs.debug ? '--inspect-brk' : ''} --inspect-brk elxr ${processedArgs._.join(' ')} ${namedArgs.join(' ') } --runas=true`
console.log('Requesting Elevated Privileges for : ' + `node ${cargs}`)
//console.log(' namedArgs : ' + namedArgs)
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._); args.push('--runas')
var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
nodeShellExec('MSHTA', [`"${args.join('" "')}"`]
, {
inherit : true
,
shell: true
// ,
inherit : true
, shell: true
, env: process.env
, runas : true
, runas : 'self'
, title : `runas`
}
).then(()=>{
@@ -526,10 +534,15 @@ var __runcmd = function(label){
, 'use' : ()=>{

var runconfig = { NODE_ENV : process.env.NODE_ENV }
try {
runconfig = Object.assign(runconfig, require('../run.js'))
} catch(e) { }
if(runconfig.NODE_ENV === process.env.NODE_ENV && processedArgs._[1] && runconfig.use === processedArgs._[1]) return;
try { runconfig = Object.assign(runconfig, require('../run.js')) } catch(e) { }
if((!processedArgs.runas || processedArgs.runas !== 'self') &&
runconfig.NODE_ENV && runconfig.NODE_ENV === (process.env.NODE_ENV || runconfig.NODE_ENV) &&
processedArgs._[1] && runconfig.use === processedArgs._[1]) {
console.log(`No change detected. Already using requested specs : ${runconfig.NODE_ENV} ${runconfig.use}`)
if(processedArgs.runas) { fs.writeFileSync('run.done', 'success') }
return
}

var tasks = [
()=>{
@@ -549,41 +562,43 @@ var __runcmd = function(label){
else return Promise.resolve(true);
}
];
any(tasks)
if(!processedArgs.runas) return op['runas']()

process.env.NODE_ENV = process.env.NODE_ENV || 'development';
runconfig.NODE_ENV = process.env.NODE_ENV = process.env.NODE_ENV || runconfig.NODE_ENV || 'development';
if(processedArgs._[1] && runconfig.use !== processedArgs._[1]) runconfig.use = processedArgs._[1];
if(!runconfig.use) { throw 'unspecifed use not allowed. Please specify chess instance name.' }

// console.log(process.env.cwd)
fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig))
tasks = [
()=>{
// Use junctions to avoid npm package issues
var p = nodeShellExec('mklink', ['/J', 'config', runconfig.use + '-' + process.env.NODE_ENV + '-config'], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
}
];
if(processedArgs._[1]) {
tasks.concat(
[
()=>{
var p = nodeShellExec('mklink', ['/D', 'data', runconfig.use + '-data'], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
}
]
)
}
any(tasks).then(()=>{
fs.writeFileSync('run.done', 'success')
if(!processedArgs.runas) return op['runas']()

tasks = [
()=>{
// Use junctions to avoid npm package issues
var p = nodeShellExec('mklink', ['/J', 'config', runconfig.use + '-config' + '-' + process.env.NODE_ENV ], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
}
];
if(processedArgs._[1]) {
tasks = tasks.concat(
[
()=>{
var p = nodeShellExec('mklink', ['/D', 'data', runconfig.use + '-data'], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
}
]
)
}
return any(tasks).then(()=>{
fs.writeFileSync('run.done', 'success')
}).catch(()=>{
fs.writeFileSync('run.done', 'error')
})
}).catch(()=>{
fs.writeFileSync('run.done', 'error')
})

+ 13
- 7
windowselevate.hta Dosyayı Görüntüle

@@ -21,17 +21,22 @@
var args = windowselevate.commandLine.split('"').slice(3);
// alert(args)
var processedArgs = { _ : [] }
var namedArgs = [];
for(var item in args){
// alert(args[item].charAt(0))
args[item] ? args[item].charAt(0) === '-' ? processedArgs[args[item].slice(2)] = args[item].split('=')[1] || true : processedArgs._.push(args[item]) : null
if(args[item].charAt(0) === '-'){
namedArgs.push(args[item])
var split = args[item].split('=');
processedArgs[split[0].slice(2)] = split[1] || true;
}
else processedArgs._.push(args[item]);
}
// args = args.forEach(function(item){ })
// alert('processedArgs._ : ' + processedArgs._);
// alert(processedArgs.runas);
var namedArgs = [];
// Object.keys(processedArgs).forEach( function(v){ v!='_' ? namedArgs.push('--'+v+'='+processedArgs[v]) : null; })
var cargs = (processedArgs.debug ? '--inspect-brk' : '') + ' elxr ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' ') + ' ' + ' --runas=true';
// PB : TODO -- Convert all the cli args back to string.
var cargs = (processedArgs.debug ? '--inspect-brk=9228' : '') + ' elxr ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' ');
// alert(cargs)
var shell = new ActiveXObject('shell.application');
shell.ShellExecute('node', cargs, '', 'runas', 1);
var fso = new ActiveXObject('Scripting.FileSystemObject');
@@ -40,18 +45,19 @@
document.body.style.backgroundColor = 'black';
document.body.style.fontFamily = 'arial';
var log = document.createElement('div');
log.innerHTML='Please Wait';
function l(msg){ log.innerHTML+= msg; };
log.style.color = 'blue';
log.style.width = '95%';
log.id = 'log';
document.body.appendChild(log);
log.innerHTML='Please Wait';
l('<Br/>Current config : ')
l('<Br/>NODE_ENV = ' + NODE_ENV)
l('<Br/>cmd = ' + processedArgs._[0])
processedArgs._[1] === 'use' ? l('<Br/>using = ' + processedArgs._[2]) : null;
l('<Br/><Br/>')
var timer = function(){
l('.');
if(fso.FileExists("run.done")) close();

Loading…
İptal
Kaydet