BaseService.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. $this->api = new proxmox\Api($host, $this->getServer()->username, $this->getServer()->accesshash,$password );
  34. $this->api->debug(\ModulesGarden\ProxmoxAddon\App\Models\ModuleSettings::isDebug());
  35. return $this->api ;
  36. }
  37. /**
  38. *
  39. * @return main\Core\Models\Whmcs\Server
  40. */
  41. public function getServer()
  42. {
  43. if ($this->server)
  44. {
  45. return $this->server;
  46. }
  47. return $this->server = main\Core\Models\Whmcs\Server::findOrFail($this->getServerId());
  48. }
  49. public function getServerId()
  50. {
  51. return $this->serverId;
  52. }
  53. public function setServerId($serverId)
  54. {
  55. $this->serverId = $serverId;
  56. return $this;
  57. }
  58. }