ServiceActions.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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\ProxmoxCloudVps\App\UI\Home\Pages;
  20. use ModulesGarden\ProxmoxAddon\App\Models\KeyPair;
  21. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  22. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  23. use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\UrlServiceHelper;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\DeleteVmButton;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\CloneVmButton;
  26. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\MigrateButton;
  27. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\RebootButton;
  28. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\RedirectButton;
  29. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\ShutdownButton;
  30. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\SshKeyButton;
  31. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\StartButton;
  32. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\StopButton;
  33. use ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\BuildUrl;
  34. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Builder\BaseContainer;
  35. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
  36. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  37. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\isAdmin;
  38. class ServiceActions extends BaseContainer implements ClientArea, AdminArea
  39. {
  40. use ProductService;
  41. use ApiService;
  42. public function initContent()
  43. {
  44. $this->initIds('serviceActions');
  45. //Start
  46. if (isAdmin() || $this->configuration()->isPermissionStart())
  47. {
  48. $this->addButton(new StartButton("startButton"));
  49. }
  50. //Reboot
  51. if (isAdmin() || $this->configuration()->isPermissionReboot())
  52. {
  53. $this->addButton(new RebootButton("rebootButon"));
  54. }
  55. //Stop
  56. if (isAdmin() || $this->configuration()->isPermissionStop())
  57. {
  58. $this->addButton(new StopButton("stopButton"));
  59. }
  60. //Shutdown
  61. if (isAdmin() || $this->configuration()->isPermissionShutdown())
  62. {
  63. $this->addButton(new ShutdownButton("shutdownButton"));
  64. }
  65. //noVNC
  66. $serviceUrl = new UrlServiceHelper();
  67. if (isAdmin() || $this->configuration()->isPermissionNovnc())
  68. {
  69. $redirectButton = new RedirectButton('novnc');
  70. $redirectButton->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . 'novnc.png');
  71. $redirectButton->addHtmlAttribute("onclick", "window.open('{$serviceUrl->getNoVncConsoleUrl()}', '', 'width=900,height=700'); return false;");
  72. $redirectButton->setHref("#");
  73. $redirectButton->setIcon('lu-zmdi lu-zmdi-fullscreen');
  74. $this->addButton($redirectButton);
  75. }
  76. $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm();
  77. //Spice Console
  78. if (isAdmin() || $this->configuration()->isPermissionSpice())
  79. {
  80. $redirectButton = new RedirectButton('spice');
  81. $redirectButton->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . 'spice.png');
  82. $redirectButton->setHref($serviceUrl->getSpiceConsoleUrl());
  83. if($vm->getVmid()!=0 || !$vm->hasSpiceproxy()){
  84. $redirectButton->addHtmlAttribute("disabled",true);
  85. }
  86. $redirectButton->setIcon('lu-zmdi lu-zmdi-fullscreen');
  87. $this->addButton($redirectButton);
  88. }
  89. //Xterm.js Console
  90. if (isAdmin() || $this->configuration()->isPermissionXtermjs())
  91. {
  92. $redirectButton = new RedirectButton('xtermjs');
  93. $redirectButton->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . 'xtermjs.png');
  94. $redirectButton->addHtmlAttribute("onclick", "window.open('{$serviceUrl->getXTermConsoleUrl()}', '', 'width=900,height=700'); return false;");
  95. $redirectButton->setIcon('lu-zmdi lu-zmdi-fullscreen');
  96. $this->addButton($redirectButton);
  97. }
  98. //Migration
  99. if (isAdmin())
  100. {
  101. $this->addButton(new MigrateButton());
  102. }
  103. //ssh key lxc only
  104. $keyPair = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVmModel()->keyPair;
  105. if( $keyPair instanceof KeyPair){
  106. $this->addButton(new SshKeyButton());
  107. }
  108. //Clone VM
  109. if($vm->isRunning()) {
  110. $this->addButton(new CloneVmButton('cloneVmButton'));
  111. } else {
  112. $cloneVmButton = new RedirectButton('cloneVmButton');
  113. $cloneVmButton->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . 'cloneButton.png');
  114. $url ="clientarea.php?action=productdetails&id={$this->getWhmcsParamByKey('serviceid')}&modop=custom&a=management&mg-page=vm&mg-action=clone&vm={$this->getRequestValue('vm', false)}";
  115. $cloneVmButton->setHref($url);
  116. $cloneVmButton->setIcon('lu-zmdi lu-zmdi-copy');
  117. $this->addButton($cloneVmButton);
  118. }
  119. //Delete VM
  120. $this->addButton(new DeleteVmButton('deleteVmButton'));
  121. $this->customTplVars['buttonSyle'] = $this->configuration()->getButtonSyle();
  122. }
  123. }