ServiceActions.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS Product developed. (26.03.19)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace ModulesGarden\Servers\ProxmoxVps\App\UI\Home\Pages;
  20. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  21. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  22. use ModulesGarden\ProxmoxAddon\App\Services\Vps\UrlService;
  23. use ModulesGarden\Servers\ProxmoxVps\App\Helpers\UrlServiceHelper;
  24. use ModulesGarden\Servers\ProxmoxVps\App\UI\Home\Buttons\MigrateButton;
  25. use ModulesGarden\Servers\ProxmoxVps\App\UI\Home\Buttons\RebootButton;
  26. use ModulesGarden\Servers\ProxmoxVps\App\UI\Home\Buttons\RedirectButton;
  27. use ModulesGarden\Servers\ProxmoxVps\App\UI\Home\Buttons\ShutdownButton;
  28. use ModulesGarden\Servers\ProxmoxVps\App\UI\Home\Buttons\StartButton;
  29. use ModulesGarden\Servers\ProxmoxVps\App\UI\Home\Buttons\StopButton;
  30. use ModulesGarden\Servers\ProxmoxVps\Core\Helper\BuildUrl;
  31. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Builder\BaseContainer;
  32. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\AdminArea;
  33. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\ClientArea;
  34. use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\isAdmin;
  35. class ServiceActions extends BaseContainer implements ClientArea, AdminArea
  36. {
  37. use ProductService;
  38. use ApiService;
  39. public function initContent()
  40. {
  41. $this->initIds('serviceActions');
  42. //Start
  43. if (isAdmin() || $this->configuration()->isPermissionStart())
  44. {
  45. $this->addButton(new StartButton("startButton"));
  46. }
  47. //Reboot
  48. if (isAdmin() || $this->configuration()->isPermissionReboot())
  49. {
  50. $this->addButton(new RebootButton("rebootButon"));
  51. }
  52. //Stop
  53. if (isAdmin() || $this->configuration()->isPermissionStop())
  54. {
  55. $this->addButton(new StopButton("stopButton"));
  56. }
  57. //Shutdown
  58. if (isAdmin() || $this->configuration()->isPermissionShutdown())
  59. {
  60. $this->addButton(new ShutdownButton("shutdownButton"));
  61. }
  62. //noVNC
  63. $serviceUrl = new UrlServiceHelper();
  64. if (isAdmin() || $this->configuration()->isPermissionNovnc())
  65. {
  66. $redirectButton = new RedirectButton('novnc');
  67. $redirectButton->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . 'novnc.png');
  68. $redirectButton->addHtmlAttribute("onclick", "window.open('{$serviceUrl->getNoVncConsoleUrl()}', '', 'width=900,height=700'); return false;");
  69. $redirectButton->setHref("#");
  70. $this->addButton($redirectButton);
  71. }
  72. //Spice Console
  73. if (isAdmin() || $this->configuration()->isPermissionSpice())
  74. {
  75. $redirectButton = new RedirectButton('spice');
  76. $redirectButton->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . 'spice.png');
  77. $redirectButton->setHref($serviceUrl->getSpiceConsoleUrl());
  78. if(!$this->hasVm() || !$this->vm()->hasSpiceproxy()){
  79. $redirectButton->addHtmlAttribute("disabled",true);
  80. }
  81. $this->addButton($redirectButton);
  82. }
  83. //Xterm.js Console
  84. if (isAdmin() || $this->configuration()->isPermissionXtermjs())
  85. {
  86. $redirectButton = new RedirectButton('xtermjs');
  87. $redirectButton->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . 'xtermjs.png');
  88. $redirectButton->addHtmlAttribute("onclick", "window.open('{$serviceUrl->getXTermConsoleUrl()}', '', 'width=900,height=700'); return false;");
  89. $this->addButton($redirectButton);
  90. }
  91. //Migration
  92. if (isAdmin())
  93. {
  94. $this->addButton(new MigrateButton());
  95. }
  96. }
  97. }