and_cesbo

xProxy auth_request stat

Jun 25th, 2014
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. server_host = "billing.local"
  2. server_port = 80
  3.  
  4. function send_session_info(content)
  5.     http_request({
  6.         host = server_host,
  7.         port = server_port,
  8.         method = "POST",
  9.         path = "/stat/",
  10.         headers = {
  11.             "User-Agent: Astra",
  12.             "Host: " .. server_host,
  13.             "Content-Type: application/json",
  14.             "Content-Length: " .. #content,
  15.             "Connection: close",
  16.         },
  17.         content = content,
  18.         callback = function(self, response)
  19.             if response.code ~= 200 then
  20.                 log.error("[xProxy] failed to send stat")
  21.             end
  22.         end,
  23.     })
  24. end
  25.  
  26. function auth_request(client_id, request, auth_callback)
  27.     if not request then
  28.         send_session_info(json.encode({
  29.             session = client_id,
  30.             status = "stop",
  31.         }))
  32.         return
  33.     end
  34.  
  35.     local client_address = request.headers['x-real-ip']
  36.     if not client_address then client_address = request.addr end
  37.  
  38.     send_session_info(json.encode({
  39.         session = client_id,
  40.         status = "start",
  41.         channel = request.path,
  42.         client = client_address,
  43.     }))
  44.  
  45.     http_request({
  46.         host = server_host,
  47.         port = server_port,
  48.         path = "/auth" .. request.path,
  49.         headers = {
  50.             "User-Agent: Astra",
  51.             "Host: " .. server_host,
  52.             "X-Real-IP: " .. client_address,
  53.             "Connection: close",
  54.         },
  55.         callback = function(self, response)
  56.             if response.code == 200 then
  57.                 auth_callback(true)
  58.             else
  59.                 auth_callback("http://streamer.local:8000/404")
  60.             end
  61.         end,
  62.     })
  63. end
Advertisement
Add Comment
Please, Sign In to add comment