This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Rewrite Curl to LUA?
#2
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
Reply


Messages In This Thread
Rewrite Curl to LUA? - by zoltan - 14.09.2017, 15:14
RE: Rewrite Curl to LUA? - by admin - 15.09.2017, 07:37
RE: Rewrite Curl to LUA? - by zoltan - 15.09.2017, 16:01
RE: Rewrite Curl to LUA? - by DGrandes - 21.08.2018, 08:38
RE: Rewrite Curl to LUA? - by admin - 21.08.2018, 12:06
RE: Rewrite Curl to LUA? - by DGrandes - 22.08.2018, 07:24

Forum Jump: