Created
January 12, 2017 09:34
-
-
Save Musinux/15b7dfe4cbffc0a98b861899c82bfacf to your computer and use it in GitHub Desktop.
CLI Add an instance to an user for guacamole
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var parseString = require('xml2js').parseString | |
var builder = new (require('xml2js').Builder)() | |
var fs = require('fs') | |
var argv = require('optimist') | |
.usage('Usage: $0 --input <input.xml> --name <machine-name>') | |
.options('hostname', {default: '@host'}) | |
.options('port', {default: '3389'}) | |
.options('serverLayout', {default: 'fr-fr-azerty'}) | |
.options('colorDepth', {default: '16'}) | |
.demand('name') | |
.argv | |
var filename = argv.input || 'user-mapping.xml' | |
var xmlFile = fs.readFileSync(filename) | |
// var inspect = require('util').inspect | |
parseString(xmlFile, function (err, result) { | |
if (err) throw err | |
var connection = { | |
'protocol': [(argv.protocol || 'rdp')], | |
'param': [ | |
{'_': (argv.hostname || '@host'), '$': {'name': 'hostname'}}, | |
{'_': (argv.port || '3389'), '$': {'name': 'port'}}, | |
{'_': (argv.serverLayout || 'fr-fr-azerty'), '$': {'name': 'server-layout'}}, | |
{'_': (argv.colorDepth || '16'), '$': {'name': 'color-depth'}} | |
], | |
'$': {'name': argv.name} | |
} | |
result['user-mapping']['authorize'][0]['connection'][1] = connection | |
var xml = builder.buildObject(result) | |
console.log(xml) | |
fs.writeFileSync(filename, xml) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment