-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from cazacutudor/device-rekey
Implement rekey functionality
- Loading branch information
Showing
8 changed files
with
149 additions
and
21 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const log = require('../lib/utils/log') | ||
const utils = require('../lib/utils/utils') | ||
const find = require('../lib/commands/find') | ||
const rekey = require('../lib/commands/rekey') | ||
const install = require('../lib/commands/install') | ||
const package = require('../lib/commands/package') | ||
const properties = require('../lib/utils/properties') | ||
const program = require('../lib/utils/log-commander') | ||
|
||
program | ||
.arguments('[roku]') | ||
.option( | ||
'-r, --roku <name|id|ip>', | ||
'Specify a roku. Ignored if passed as argument.' | ||
) | ||
.option('-a, --auth <user:pass>', 'Set username and password for roku.') | ||
.parse(process.argv) | ||
|
||
let args = program.args | ||
let roku = args[0] || program.roku || properties.defaults.roku | ||
|
||
try { | ||
var auth = program.auth || properties.rokus[roku]['auth'] | ||
if (typeof(auth) === 'string') { | ||
auth = { | ||
user: auth.split(':')[0], | ||
pass: auth.split(':')[1] | ||
} | ||
} | ||
} catch (e) { | ||
log.error('no auth defined for roku: ' + roku) | ||
process.exit(-1) | ||
} | ||
|
||
let options = { | ||
flavor: 'main', | ||
roku, | ||
auth, | ||
name: '' | ||
} | ||
for (let key in options) { | ||
if (!options[key] && key != 'name') { | ||
log.error('%s options is undefined') | ||
log.pretty('error', 'options:', options) | ||
process.exit(-1) | ||
} | ||
} | ||
|
||
if (program['verbose']) { | ||
log.level = 'verbose' | ||
} | ||
|
||
if (program['debug']) { | ||
log.level = 'debug' | ||
} | ||
|
||
find.findDeviceBySerialNo(utils.getUsn(options), 5, ip => { | ||
ip ? rekey.rekey(options, ip) : null | ||
}) |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const fs = require('fs') | ||
const request = require('request') | ||
const log = require('../utils/log') | ||
const properties = require('../utils/properties') | ||
|
||
function rekey(options, ip) { | ||
if (properties.packageReference == null) { | ||
log.error("packageReference field is missing (ukor.properties)") | ||
return | ||
} | ||
|
||
const form = { | ||
mysubmit: 'Rekey', | ||
passwd: properties.packageKey, | ||
archive: fs.createReadStream(properties.packageReference) | ||
} | ||
|
||
options.auth.sendImmediately = false | ||
request.post( | ||
{ | ||
url: 'http://' + ip + '/plugin_inspect', | ||
formData: form, | ||
auth: options.auth | ||
}, | ||
(error, response, body) => { | ||
if (error || !body) { | ||
log.error('Rekey device falied:') | ||
log.error(error) | ||
} else { | ||
result = parseBody(body) | ||
|
||
if (result[0].indexOf('Success') !== -1) { | ||
log.info(`The device was rekeyed with: ${properties.packageKey}`) | ||
} else { | ||
log.error('Falied to rekey'); | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
||
function parseBody(body) { | ||
return body.match(/<font color=\"red\">(.*?)<\/font>/g) | ||
} | ||
|
||
module.exports = { | ||
rekey | ||
} |
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
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