Advertisement
Guest User

ucms

a guest
Feb 20th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. function ver()
  2.   return 0.1
  3. end
  4.  
  5. function errors(_iError)
  6.   if(_iError == nil) then
  7.     _iError = 503
  8.   end
  9.  
  10.   if(_iError ~= 0) then
  11.     if(_iError == 403) then
  12.       gui.windowSimple({"Brak uprawnien", "", "", "", "[ENTER] Kontynuuj"})
  13.     elseif(_iError == 401) then
  14.       gui.windowSimple({"Brak uprawnien", "podano bledne dane", "", "", "[ENTER] Kontynuuj"})
  15.     elseif(_iError == 408) then
  16.       gui.windowSimple({"Twoja sesja wygasla", "zaloguj sie ponownie", "", "", "[ENTER] Kontynuuj"})
  17.     elseif(_iError == 503) then
  18.       gui.windowSimple({"Usluga chwilowo niedostepna", "", "", "", "[ENTER] Kontynuuj"})
  19.     else
  20.       gui.windowSimple({"Wystapil blad", "", "", "", "[ENTER] Kontynuuj"})
  21.     end
  22.     listener.waitEnter()
  23.   end
  24.  
  25.   return _iError
  26. end
  27.  
  28. function session(_sUcmsRoot, _sUsername, _sKey)
  29.   local data = {}
  30.   local arr = nil
  31.   gui.windowSimple({"", "", "Pobieranie danych...", "", ""})
  32.   data = net.httpToArray(_sUcmsRoot.."p/api/ucms_session&lite=1&username=".._sUsername.."&session=".._sKey)
  33.   arr = json.decode(data[1])
  34.   data = nil
  35.   ucms.errors(arr.ucms_error)
  36.   if(arr.ucms_error ~= 0) then
  37.     arr = false
  38.   end
  39.   return arr
  40. end
  41.  
  42. function login(_sUcmsRoot)
  43.   while true do
  44.     local username = nil
  45.     local password = nil
  46.     username = gui.windowSimpleInput({"Login:", "", ""}, 27, nil, true)
  47.     password = gui.windowSimpleInput({"Haslo:", "", ""}, 27, true, true)
  48.    
  49.     if username == nil or password == nil then
  50.       gui.windowSimple({"Podano bledne dane", "", "", "", "[ENTER] Zaloguj"})
  51.       listener.waitEnter()
  52.     else
  53.       gui.windowSimple({"", "Trwa logowanie...", "", "Prosze czekac", ""})
  54.       password = sha256.sha256(password)
  55.       while true do
  56.         local data = {}
  57.         local arr = nil
  58.         data = net.httpToArray(_sUcmsRoot.."p/api/ucms_login&lite=1&username="..username.."&password="..password)
  59.         arr = json.decode(data[1])
  60.         if(arr.ucms_error == 0) then
  61.           gui.windowSimple({"", "Zalogowano", "", "", "[ENTER] Kontynuuj"})
  62.           listener.waitEnter()
  63.         else
  64.           ucms.errors(arr.ucms_error)
  65.           data = nil
  66.           arr = false
  67.         end
  68.         return arr
  69.       end
  70.     end
  71.   end
  72. end
  73.  
  74. function query(_sUcmsRoot, _oObject, _sApiOption, _sParameters)
  75.   local data = {}
  76.   local arr = nil
  77.   if(_oObject.username == nil) then
  78.     _oObject.username = ""
  79.   end
  80.  
  81.   if(_oObject.session == nil) then
  82.     _oObject.session = ""
  83.   end
  84.  
  85.   gui.windowSimple({"", "", "Pobieranie danych...", "", ""})
  86.   data = net.httpToArray(_sUcmsRoot.."p/api/".._sApiOption.."&lite=1&username=".._oObject.username.."&session=".._oObject.key.._sParameters)
  87.   arr = json.decode(data[1])
  88.   data = nil
  89.  
  90.   ucms.errors(arr.ucms_error)
  91.   if(arr.ucms_error ~= 0) then
  92.     _oObject.ucms_error = arr.ucms_error
  93.     arr = _oObject
  94.   end
  95.   return arr
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement