15.09.2017, 07:37
Try this:
Code:
username = 'xxx@xxx.xxx'
password = 'xxx'
serial = 'xxx'
https = require('ssl.https')
ltn12 = require('ltn12')
sha1 = require('encdec').sha1
json = require('json')
function dorequest(url, headers)
local tbl = {}
local res, err = https.request({
url = url,
headers = headers,
sink = ltn12.sink.table(tbl)
})
if res then
return table.concat(tbl)
else
return nil, err
end
end
res, err = dorequest('https://my.zipato.com/zipato-web/v2/user/init')
log('init', res, err)
if res then
data = json.decode(res)
password = sha1(password)
token = sha1(data.nonce .. password)
headers = {
['accept'] = 'application/json',
['cookie'] = 'JSESSIONID=' .. data.jsessionid .. ';',
}
url = 'https://my.zipato.com/zipato-web/v2/user/login?token=' .. token .. '&username=' .. username
res, err = dorequest(url, headers)
log('login', res, err)
if res then
url = 'https://my.zipato.com/zipato-web/v2/box/reboot/' .. serial
res, err = dorequest(url, headers)
log('reboot', res, err)
end
end