PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/code/classes/Daemon/QueryToHttp/Client.class.php

https://github.com/blekkzor/pinetd2
PHP | 42 lines | 32 code | 10 blank | 0 comment | 1 complexity | 1c868b077327b113111452a621569faf MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. namespace Daemon\QueryToHttp;
  3. class Client extends \pinetd\TCP\Client {
  4. private $ch;
  5. public function welcomeUser() {
  6. return true;
  7. }
  8. public function sendBanner() {
  9. $this->setMsgEnd('');
  10. }
  11. function shutdown() {
  12. }
  13. public function doResolve() {
  14. return;
  15. }
  16. protected function parseLine($lin) {
  17. $lin = rtrim($lin);
  18. if (is_null($this->ch)) {
  19. $this->ch = curl_init($this->IPC->getUrl());
  20. curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
  21. curl_setopt($this->ch, CURLOPT_HEADER, true);
  22. curl_setopt($this->ch, CURLOPT_HTTPHEADER, array('X-Remote-Ip' => $this->peer[0], 'X-Remote-Port' => $this->peer[1], 'X-Remote-Host' => $this->peer[2]) + $this->IPC->getHeaders());
  23. }
  24. curl_setopt($this->ch, CURLOPT_POSTFIELDS, http_build_query(array('input' => $lin)));
  25. $res = curl_exec($this->ch);
  26. $header_len = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
  27. $headers = substr($res, 0, $header_len);
  28. $res = substr($res, $header_len);
  29. $this->sendMsg($res);
  30. $this->close(); // TODO: check if a header contains X-Socket: close and only close if present
  31. }
  32. }