| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS Product developed. (26.03.19)
- * *
- *
- * CREATED BY MODULESGARDEN -> http://modulesgarden.com
- * CONTACT -> contact@modulesgarden.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Pages;
- use ModulesGarden\ProxmoxAddon\App\Models\KeyPair;
- use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
- use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\UrlServiceHelper;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\DeleteVmButton;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\CloneVmButton;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\MigrateButton;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\RebootButton;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\RedirectButton;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\ShutdownButton;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\SshKeyButton;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\StartButton;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Home\Buttons\StopButton;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\BuildUrl;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Builder\BaseContainer;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
- use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\isAdmin;
- class ServiceActions extends BaseContainer implements ClientArea, AdminArea
- {
- use ProductService;
- use ApiService;
- public function initContent()
- {
- $this->initIds('serviceActions');
- //Start
- if (isAdmin() || $this->configuration()->isPermissionStart())
- {
- $this->addButton(new StartButton("startButton"));
- }
- //Reboot
- if (isAdmin() || $this->configuration()->isPermissionReboot())
- {
- $this->addButton(new RebootButton("rebootButon"));
- }
- //Stop
- if (isAdmin() || $this->configuration()->isPermissionStop())
- {
- $this->addButton(new StopButton("stopButton"));
- }
- //Shutdown
- if (isAdmin() || $this->configuration()->isPermissionShutdown())
- {
- $this->addButton(new ShutdownButton("shutdownButton"));
- }
- //noVNC
- $serviceUrl = new UrlServiceHelper();
- if (isAdmin() || $this->configuration()->isPermissionNovnc())
- {
- $redirectButton = new RedirectButton('novnc');
- $redirectButton->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . 'novnc.png');
- $redirectButton->addHtmlAttribute("onclick", "window.open('{$serviceUrl->getNoVncConsoleUrl()}', '', 'width=900,height=700'); return false;");
- $redirectButton->setHref("#");
- $redirectButton->setIcon('lu-zmdi lu-zmdi-fullscreen');
- $this->addButton($redirectButton);
- }
- $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm();
- //Spice Console
- if (isAdmin() || $this->configuration()->isPermissionSpice())
- {
- $redirectButton = new RedirectButton('spice');
- $redirectButton->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . 'spice.png');
- $redirectButton->setHref($serviceUrl->getSpiceConsoleUrl());
- if($vm->getVmid()!=0 || !$vm->hasSpiceproxy()){
- $redirectButton->addHtmlAttribute("disabled",true);
- }
- $redirectButton->setIcon('lu-zmdi lu-zmdi-fullscreen');
- $this->addButton($redirectButton);
- }
- //Xterm.js Console
- if (isAdmin() || $this->configuration()->isPermissionXtermjs())
- {
- $redirectButton = new RedirectButton('xtermjs');
- $redirectButton->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . 'xtermjs.png');
- $redirectButton->addHtmlAttribute("onclick", "window.open('{$serviceUrl->getXTermConsoleUrl()}', '', 'width=900,height=700'); return false;");
- $redirectButton->setIcon('lu-zmdi lu-zmdi-fullscreen');
- $this->addButton($redirectButton);
- }
- //Migration
- if (isAdmin())
- {
- $this->addButton(new MigrateButton());
- }
- //ssh key lxc only
- $keyPair = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVmModel()->keyPair;
- if( $keyPair instanceof KeyPair){
- $this->addButton(new SshKeyButton());
- }
- //Clone VM
- if($vm->isRunning()) {
- $this->addButton(new CloneVmButton('cloneVmButton'));
- } else {
- $cloneVmButton = new RedirectButton('cloneVmButton');
- $cloneVmButton->setImageUrl(BuildUrl::getAppAssetsURL() . DS . 'img' . DS . 'buttons' . DS . 'cloneButton.png');
- $url ="clientarea.php?action=productdetails&id={$this->getWhmcsParamByKey('serviceid')}&modop=custom&a=management&mg-page=vm&mg-action=clone&vm={$this->getRequestValue('vm', false)}";
- $cloneVmButton->setHref($url);
- $cloneVmButton->setIcon('lu-zmdi lu-zmdi-copy');
- $this->addButton($cloneVmButton);
- }
- //Delete VM
- $this->addButton(new DeleteVmButton('deleteVmButton'));
- $this->customTplVars['buttonSyle'] = $this->configuration()->getButtonSyle();
- }
- }
|