BaseService.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Services;
  3. use MGProvision\Proxmox\v2 as proxmox;
  4. use ModulesGarden\ProxmoxAddon as main;
  5. /**
  6. * Doe labels datatable controler
  7. *
  8. */
  9. trait BaseService
  10. {
  11. private $serverId;
  12. /**
  13. *
  14. * @var main\Core\Models\Whmcs\Server
  15. */
  16. private $server;
  17. private $api;
  18. /**
  19. *
  20. * @return proxmox\Api
  21. */
  22. public function getApi()
  23. {
  24. if ($this->api)
  25. {
  26. return $this->api;
  27. }
  28. $host = $this->getServer()->ipaddress ? $this->getServer()->ipaddress : $this->getServer()->hostname;
  29. if(is_numeric($this->getServer()->port)){
  30. $host .=":".$this->getServer()->port;
  31. }
  32. $password = html_entity_decode(decrypt($this->getServer()->password),ENT_QUOTES);
  33. return $this->api = new proxmox\Api($host, $this->getServer()->username, $this->getServer()->accesshash,$password );
  34. }
  35. /**
  36. *
  37. * @return main\Core\Models\Whmcs\Server
  38. */
  39. public function getServer()
  40. {
  41. if ($this->server)
  42. {
  43. return $this->server;
  44. }
  45. return $this->server = main\Core\Models\Whmcs\Server::findOrFail($this->getServerId());
  46. }
  47. public function getServerId()
  48. {
  49. return $this->serverId;
  50. }
  51. public function setServerId($serverId)
  52. {
  53. $this->serverId = $serverId;
  54. return $this;
  55. }
  56. }