| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524 |
- <?php
- /**********************************************************************
- * ProxmoxVPS 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\ProxmoxVps\App\UI\Admin\Product\Providers;
- use MGProvision\Proxmox\v2\models\Node;
- use MGProvision\Proxmox\v2\repository\ClusterResourcesRepository;
- use MGProvision\Proxmox\v2\repository\FileRepository;
- use MGProvision\Proxmox\v2\repository\NodeRepository;
- use MGProvision\Proxmox\v2\repository\StorageRepository;
- use ModulesGarden\ProxmoxAddon\App\Models\CloudInitScript;
- use ModulesGarden\ProxmoxAddon\App\Models\IpAddress;
- use ModulesGarden\ProxmoxAddon\App\Models\ProductConfiguration;
- use ModulesGarden\ProxmoxAddon\App\Models\Whmcs\Product;
- use ModulesGarden\ProxmoxAddon\App\Repositories\Vps\ProductConfigurationRepository;
- use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
- use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
- use ModulesGarden\Servers\ProxmoxVps\App\Enum\JobPeriod;
- use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Forms\MainForm;
- use ModulesGarden\Servers\ProxmoxVps\Core\FileReader\Reader\Json;
- use ModulesGarden\Servers\ProxmoxVps\Core\Models\Whmcs\EmailTemplate;
- use ModulesGarden\Servers\ProxmoxVps\Core\ModuleConstants;
- use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\AdminArea;
- use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
- use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Switcher;
- use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl;
- class ProductProvider extends BaseDataProvider implements AdminArea
- {
- use ApiService;
- use ProductService;
- private $productId;
- /**
- * @var ProductConfigurationRepository
- */
- protected $configuration;
- /**
- * @var Node
- */
- private $node;
- /**
- * ProductConfigurationProvider constructor.
- * @param $productId
- */
- public function __construct($productId)
- {
- if (!is_numeric($productId))
- {
- throw new \InvalidArgumentException("The product id must be definded.");
- }
- $this->configuration = new ProductConfigurationRepository($productId);
- $this->productId = $productId;
- }
- public function isSupportedModule()
- {
- return Product::where("id", $this->configuration->getProductId())
- ->where("servertype", "proxmoxVPS")->count() == 1;
- }
- public function read()
- {
- foreach ($this->configuration->all() as $key => $value)
- {
- //multiselect
- if (is_array($value))
- {
- $this->data[sprintf("customconfigoption[%s][]", $key)] = $value;
- continue;
- }
- $this->data[sprintf("customconfigoption[%s]", $key)] = $value;
- }
- $this->initApi();
- $this->defaultRead();
- if (!$this->configuration->getVirtualization() || $this->configuration->isQemu())
- {
- //kvm
- $this->qemuRead();
- }
- else
- {
- //lxc
- $this->lxcRead();
- }
- }
- private function initApi()
- {
- $lang = sl("lang");
- $product = Product::where("id", $this->productId)->firstOrFail();
- sl("whmcsParams")->setParams($product->getParams());
- }
- private function defaultRead()
- {
- $lang = sl("lang");
- //Virtualization
- $this->availableValues["customconfigoption[virtualization]"] = ["qemu" => $lang->tr("KVM"), "lxc" => $lang->tr("LXC")];
- //Default Node
- $this->availableValues["customconfigoption[defaultNode]"] = ["serverNode" => $lang->tr('Server-Node'), "autoNode" => $lang->tr('Auto-Node')];
- $nodeRepository = new NodeRepository();
- $nodeRepository->setApi($this->api());
- $nodeRepository->findOnline(true);
- foreach ($nodeRepository->fetch() as $node)
- {
- $this->availableValues["customconfigoption[defaultNode]"][$node->getNode()] = $node->getNode();
- }
- //realm
- foreach ($this->api()->get("/access/domains") as $d)
- {
- if (!$d['realm'])
- {
- continue;
- }
- $this->availableValues["customconfigoption[realm]"][$d['realm']] = $lang->tr($d['comment']);
- }
- //userRole
- foreach ($this->api()->get("/access/roles") as $r)
- {
- if (!$r['roleid'])
- {
- continue;
- }
- $this->availableValues["customconfigoption[userRole]"][$r['roleid']] = $lang->tr($r['roleid']);
- }
- //welcomeEmailTemplateId
- $this->availableValues["customconfigoption[welcomeEmailTemplateId]"][0] = "";
- foreach (EmailTemplate::where('type', "product")->pluck("name", "id")->all() as $key => $value)
- {
- $this->availableValues["customconfigoption[welcomeEmailTemplateId]"][$key] = $value;
- }
- //reinstallEmailTemplateId
- $this->availableValues["customconfigoption[reinstallEmailTemplateId]"][0] = "";
- foreach (EmailTemplate::where('type', "product")->pluck("name", "id")->all() as $key => $value)
- {
- $this->availableValues["customconfigoption[reinstallEmailTemplateId]"][$key] = $value;
- }
- //upgradeNotificationTemplateId
- $this->availableValues["customconfigoption[serviceCreationFailedTemplateId]"][0] = "";
- foreach (EmailTemplate::where('type', "admin")->where("custom", 1)->pluck("name", "id")->all() as $key => $value)
- {
- $this->availableValues["customconfigoption[serviceCreationFailedTemplateId]"][$key] = $value;
- }
- //upgradeNotificationTemplateId
- $this->availableValues["customconfigoption[upgradeNotificationTemplateId]"] = $this->availableValues["customconfigoption[serviceCreationFailedTemplateId]"];
- //loadBalancerOnUpgrade
- $this->availableValues["customconfigoption[loadBalancerOnUpgrade]"] = ['0' => $lang->tr('None'), "block" => $lang->tr("Block"), "migrate" => $lang->tr("Migrate")];
- //backupStorage
- if (in_array($this->configuration->getDefaultNode(), $this->availableValues["customconfigoption[defaultNode]"]))
- {
- $this->node = new Node($this->configuration->getDefaultNode());
- }
- else
- {//"Auto-Node" or 'Server-Node' or empty
- $servePrivateIP = $this->getServerPrivateIpAddress();
- $serverIp = $servePrivateIP ? $servePrivateIP : $this->getWhmcsParamByKey('serverip');
- $this->node = $nodeRepository->findWithHostOrIp($this->getWhmcsParamByKey('serverhostname'), $serverIp );
- }
- $this->node->setApi($this->api());
- $storageRepository = new StorageRepository();
- $storageRepository->findByNodes([$this->node->getNode()])
- ->findEnabed();
- foreach ($storageRepository->fetch() as $entity)
- {
- if (!in_array("backup", $entity->getContentAsArray()))
- {
- continue;
- }
- $this->availableValues["customconfigoption[backupStorage]"] [$entity->getStorage()] = $lang->tr($entity->getStorage());
- }
- //clusterState
- $this->availableValues["customconfigoption[clusterState]"] = ['' => "", 'started' => $lang->tr('Started'), 'stopped' => $lang->tr('Stopped'), 'enabled' => $lang->tr('Enabled'), 'disabled' => $lang->tr('Disabled'), 'ignored' => $lang->tr('Ignored')];
- //firewallInterfaces
- $this->availableValues["customconfigoption[firewallInterfaces][]"] = ["venet" => $lang->tr("venet"), "eth" => $lang->tr("eth\d+")];
- //clusterGroup
- $this->availableValues["customconfigoption[clusterGroup]"] = ['' => ""];
- foreach ($this->api()->get('/cluster/ha/groups') as $g)
- {
- $this->availableValues["customconfigoption[clusterGroup]"][$g['group']] = ucfirst($g['group']);
- }
- //suspensionAction
- $this->availableValues["customconfigoption[suspensionAction]"] = ['0' => $lang->tr('Default'), "stop" => $lang->tr('Stop VM'), 'shutdown' => $lang->tr('Shutdown VM')];
- if ($this->configuration()->isQemu())
- {
- $this->availableValues["customconfigoption[suspensionAction]"]["suspend"] = $lang->tr("Pause VM");
- $this->availableValues["customconfigoption[suspensionAction]"]["hibernate"] = $lang->tr("Hibernate VM");
- }
- //tag
- $this->availableValues["customconfigoption[tags][]"];
- foreach (IpAddress::select("tag")->whereNotNull("tag")->where("tag", ">", 0)->groupBy("tag")->pluck("tag")->all() as $tag)
- {
- $this->availableValues["customconfigoption[tags][]"][$tag] = $tag;
- }
- //pool
- $this->availableValues["customconfigoption[pool]"]=[""];
- foreach ($this->api()->get('/pools') as $pool)
- {
- $this->availableValues["customconfigoption[pool]"][$pool['poolid']] = $lang->tr($pool['poolid']);
- }
- //permissionSnapshotJobPeriod
- $this->availableValues["customconfigoption[permissionSnapshotJobPeriod][]"] = [
- JobPeriod::HOURLY => $lang->tr(JobPeriod::HOURLY),
- JobPeriod::DAILY => $lang->tr(JobPeriod::DAILY )
- ];
- //permissionFirewalOptions
- $this->availableValues["customconfigoption[permissionFirewalOptions][]"] = [
- "enable" => $lang->abtr("Enable/Disable Firewall"),
- "dhcp" => $lang->abtr("DHCP"),
- "radv" => $lang->abtr("Allow Router Advertisement"),
- "ndp" => $lang->abtr("NDP"),
- "macfilter" => $lang->abtr("MAC Filter"),
- "ipfilter" => $lang->abtr("IP Filter"),
- ];
- }
- /**
- * KVM
- */
- private function qemuRead()
- {
- $lang = sl("lang");
- //ostype
- $ostype = new Json('ostype.json', ModuleConstants::getFullPathWhmcs('modules', 'addons', 'proxmoxAddon', 'storage', 'app'));
- foreach ($ostype->get() as $k => $ostype)
- {
- $this->availableValues["customconfigoption[ostype]"][$k] = $lang->tr($ostype);
- }
- //hotplug
- $this->availableValues["customconfigoption[hotplug][]"] = [ "disk" => $lang->tr('disk'), "network" => $lang->tr('network'), "usb" => $lang->tr('usb'), "cpu" => $lang->tr('cpu'), "memory" => $lang->tr('memory')];
- //keyboard
- $this->availableValues["customconfigoption[keyboard]"] = ['', 'pt' => $lang->tr('pt'), "tr" => $lang->tr('tr'), 'ja' => $lang->tr('ja'), 'es' => $lang->tr('es'), 'no' => $lang->tr('no'), 'is' => $lang->tr('is'), 'fr-ca' => $lang->tr('fr-ca'), 'fr' => $lang->tr('fr'), 'pt-br' => $lang->tr('pt-br'), 'da' => $lang->tr('da'), 'fr-ch' => $lang->tr('fr-ch'), 'sl' => $lang->tr('sl'), 'de-ch' => $lang->tr('de-ch'), 'en-gb' => $lang->tr('en-gb'), 'it' => $lang->tr('it'), 'en-us' => $lang->tr('en-us'), 'fr-be' => $lang->tr('fr-be'), 'hu' => $lang->tr('hu'), 'pl'=> $lang->tr('pl'), 'nl' => $lang->tr('nl'), 'mk' => $lang->tr('mk'), 'fi' => $lang->tr('fi'), 'lt' => $lang->tr('lt'), 'sv'=> $lang->tr('sv'), 'de' => $lang->tr('de')];
- //vga
- $this->availableValues["customconfigoption[vga]"] = [
- "std" => $lang->tr("Standard VGA"),
- "cirrus" => $lang->tr("Cirrus Logic"),
- "vmware" => $lang->tr("VMWare"),
- "serial0" => $lang->tr("Serial terminal 0"),
- "serial1" => $lang->tr("Serial terminal 1"),
- "serial2" => $lang->tr("Serial terminal 2"),
- "serial3" => $lang->tr("Serial terminal 3"),
- "qxl" => $lang->tr("SPICE"),
- "qxl2" => $lang->tr("SPICE dual monitor"),
- "qxl3" => $lang->tr("SPICE three monitor"),
- "qxl4" => $lang->tr("SPICE four monitor"),
- ];
- //clientNameForContainer
- $this->availableValues["customconfigoption[clientNameForContainer]"] = [
- 0 => 'No',
- "emptyHostnameOnly" => 'Yes [only when hostname is empty]',
- "overwriteHostname" => 'Yes [overwrite hostname] ',
- "overwriteHostnameWithPrefix" => 'Yes [overwrite hostname with container prefix and service id] ',
- ];
- //cloneMode
- $this->availableValues["customconfigoption[cloneMode]"] = ['1' => $lang->tr('Full Clone'), "0" => $lang->tr("Linked Clone")];
- //diskStorage images (Disk Images)
- $storageRepository = new StorageRepository();
- $storageRepository->findByNodes([$this->node->getNode()])
- ->findEnabed();
- foreach ($storageRepository->fetch() as $entity)
- {
- if (!in_array("images", $entity->getContentAsArray()))
- {
- continue;
- }
- $this->availableValues["customconfigoption[diskStorage]"] [$entity->getStorage()] = $lang->tr($entity->getStorage());
- $this->availableValues["customconfigoption[additionalDiskStorage]"] [$entity->getStorage()] = $lang->tr($entity->getStorage());
- }
- //diskType
- $this->availableValues["customconfigoption[diskType]"] = ["ide" => $lang->tr('IDE'), "sata" => $lang->tr('SATA'), "virtio" => $lang->tr('VIRTIO'), "scsi" => $lang->tr('SCSI')];
- //diskFormat
- $this->availableValues["customconfigoption[diskFormat]"] = ['raw' => $lang->tr('Raw disk image (raw)'), 'qcow2' => $lang->tr('QEMU image format (qcow2)'), 'vmdk' => $lang->tr('VM image format (vmdk)')];
- //diskCache
- $this->availableValues["customconfigoption[diskCache]"] = ['none' => $lang->tr('Default (No Cache)'), 'writethrough' => $lang->tr('Write Through'), 'writeback' => $lang->tr('Write Back'), 'unsafe' => $lang->tr('Write Back (Unsafe)'), 'directsync' => $lang->tr('Direct Sync')];
- //scsihw
- $this->availableValues["customconfigoption[scsihw]"] = [
- '0' => $lang->abtr('Default (LSI 53C895A)'),
- "lsi" => $lang->abtr('LSI 53C895A'),
- "lsi53c810" => $lang->abtr('LSI 53C810'),
- 'virtio-scsi-pci' => $lang->abtr('VirtIO SCSI'),
- "virtio-scsi-single" => $lang->abtr('VirtIO SCSI single'),
- 'megasas' => $lang->abtr('MegaRAID SAS 8708EM2'),
- "pvscsi" => $lang->abtr('VMware PVSCSI'),
- ];
- //additionalDiskStorage
- $this->availableValues["customconfigoption[additionalDiskStorage]"] = $this->availableValues["customconfigoption[diskStorage]"];
- //additionalDiskType
- $this->availableValues["customconfigoption[additionalDiskType][]"] = $this->availableValues["customconfigoption[diskType]"];
- //additionalDiskFormat
- $this->availableValues["customconfigoption[additionalDiskFormat][]"] = $this->availableValues["customconfigoption[diskFormat]"];
- if($this->configuration->getAdditionalDiskStorage() && preg_match("/lvm/", $this->configuration->getAdditionalDiskStorage() )){
- $this->disabledList["customconfigoption[additionalDiskFormat][]"] = ['qcow2', 'vmdk'];
- }
- //additionalDiskCache
- $this->availableValues["customconfigoption[additionalDiskCache]"] = $this->availableValues["customconfigoption[diskCache]"];
- //networkModel
- $this->availableValues["customconfigoption[networkModel]"] = ['e1000' => $lang->tr('e1000'), 'i82551' => $lang->tr('i82551'), 'i82557b' => $lang->tr('i82557b'), 'i82559er' => $lang->tr('i82559er'), 'ne2k_isa' => $lang->tr('ne2k_isa'), 'ne2k_pci' => $lang->tr('ne2k_pci'), 'pcnet' => $lang->tr('pcnet'), 'rtl8139' => $lang->tr('rtl8139'), 'virtio' => $lang->tr('virtio'), 'vmxnet3' => $lang->tr('vmxnet3')];
- //bridge
- foreach ($this->api()->get("/nodes/{$this->node->getNode()}/network") as $network)
- {
- if (!in_array($network['type'], ['bridge', 'OVSBridge']))
- {
- continue;
- }
- $this->availableValues["customconfigoption[bridge]"] [$network['iface']] = $lang->tr($network['iface']);
- }
- ksort($this->availableValues["customconfigoption[bridge]"]);
- //privateBridge
- $this->availableValues["customconfigoption[privateBridge]"] = ['0' => ""] + (array) $this->availableValues["customconfigoption[bridge]"];
- //networkPrivateModel
- $this->availableValues["customconfigoption[networkPrivateModel]"] = $this->availableValues["customconfigoption[networkModel]"];
- //bootDevice1
- $this->availableValues["customconfigoption[bootDevice1]"] = ['', 'c' => $lang->tr('Hard Disk'), 'd' => $lang->tr('CD-ROM'), 'n' => $lang->tr('Network')];
- //bootDevice2
- $this->availableValues["customconfigoption[bootDevice2]"] = $this->availableValues["customconfigoption[bootDevice1]"];
- //bootDevice3
- $this->availableValues["customconfigoption[bootDevice3]"] = $this->availableValues["customconfigoption[bootDevice1]"];
- //permissionOsTemplates
- $clusterResourcesRepository = new ClusterResourcesRepository();
- $clusterResourcesRepository->setApi($this->api());
- $clusterResourcesRepository->findKvmTemplate();
- foreach ($clusterResourcesRepository->fetch() as $resurce)
- {
- if (preg_match('/^custom[0-9]*/', $resurce->getName()))
- {
- continue;
- }
- $this->availableValues["customconfigoption[permissionOsTemplates][]"][$resurce->getName()] = $lang->tr($resurce->getName());
- }
- //osTemplate
- $this->availableValues["customconfigoption[osTemplate]"] = ['0' => ""] + (array) $this->availableValues["customconfigoption[permissionOsTemplates][]"];
- //permissionIsoImage
- $fileRepository = new FileRepository();
- $fileRepository->setApi($this->api());
- $fileRepository->findIso();
- $fileRepository->findByNode($this->node);
- $fileRepository->findByStorages($storageRepository->fetchAsArray());
- foreach ($fileRepository->fetch() as $file)
- {
- $this->availableValues["customconfigoption[permissionIsoImages][]"][$file->getVolid()] = $lang->tr($file->getFriendlyName());
- }
- //isoImage
- $this->availableValues["customconfigoption[isoImage]"] = ["none" => $lang->tr("None")] + (array)$this->availableValues["customconfigoption[permissionIsoImages][]"];
- //memoryUnit
- $this->availableValues["customconfigoption[memoryUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB")];
- //diskUnit
- $this->availableValues["customconfigoption[diskUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB"), "tb" => $lang->tr("TB")];
- //additionalDiskUnit
- $this->availableValues["customconfigoption[additionalDiskUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB"), "tb" => $lang->tr("TB")];
- //cdromType
- $this->availableValues["customconfigoption[cdromType]"] = $this->availableValues["customconfigoption[diskType]"];
- //bios
- $this->availableValues["customconfigoption[bios]"] = [
- '0' => "",
- 'seabios' => $lang->tr('SeaBIOS'),
- 'ovmf' => $lang->tr('OVMF (UEFI)')
- ];
- //cloudInitScript
- $this->availableValues["customconfigoption[cloudInitScript]"] =
- CloudInitScript::pluck('name','id')->prepend("",0)->toArray();
- //machine
- $jsonData = new Json('machine.json', ModuleConstants::getFullPathWhmcs('modules', 'addons', 'proxmoxAddon', 'storage', 'app'));
- foreach ($jsonData->get() as $k => $name)
- {
- $this->availableValues["customconfigoption[machine]"][$k] = $lang->tr($name);
- }
- //cpu
- $jsonData = new Json('cpu.json', ModuleConstants::getFullPathWhmcs('modules', 'addons', 'proxmoxAddon', 'storage', 'app'));
- foreach ($jsonData->get() as $k => $name)
- {
- $this->availableValues["customconfigoption[cpu]"][$k] = $lang->tr($name);
- }
- }
- /**
- * LXC
- */
- private function lxcRead()
- {
- $lang = sl("lang");
- //storage
- $storageRepository = new StorageRepository();
- $storageRepository->findByNodes([$this->node->getNode()])
- ->findEnabed();
- foreach ($storageRepository->fetch() as $storage)
- {
- if (!in_array("rootdir", $storage->getContentAsArray()))
- {
- continue;
- }
- $this->availableValues["customconfigoption[storage]"][$storage->getStorage()] = $lang->tr($storage->getStorage());
- }
- //arch
- $this->availableValues["customconfigoption[arch]"] = ['0' => "", 'amd64' => $lang->tr("AMD64"), $lang->tr("i386") => $lang->tr("i386")];
- //cmode
- $this->availableValues["customconfigoption[cmode]"] = ['0' => "", 'shell' => $lang->tr("shell"), "console" => $lang->tr("console"), "tty" => $lang->tr("tty")];
- //ostype
- $this->availableValues["customconfigoption[ostype]"] = ['0' => "", 'debian' => $lang->tr("Debian"), "ubuntu" => $lang->tr("Ubuntu"), "centos" => $lang->tr("centos"), "archlinux" => $lang->tr("Archlinux")];
- //osTemplate
- $fileRepository = new FileRepository();
- $fileRepository->setApi($this->api());
- $fileRepository->findLxcTemplates();
- $fileRepository->findByNode($this->node);
- $fileRepository->findByStorages($storageRepository->fetchAsArray());
- foreach ($fileRepository->fetch() as $file)
- {
- $this->availableValues["customconfigoption[osTemplate]"][$file->getVolid()] = $lang->tr($file->getFriendlyName());
- }
- //memoryUnit
- $this->availableValues["customconfigoption[memoryUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB")];
- //diskUnit
- $this->availableValues["customconfigoption[diskUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB"), "tb" => $lang->tr("TB")];
- //additionalDiskUnit
- $this->availableValues["customconfigoption[additionalDiskUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB"), "tb" => $lang->tr("TB")];
- //persimonOsTemplates
- $this->availableValues["customconfigoption[permissionOsTemplates][]"] = $this->availableValues["customconfigoption[osTemplate]"];
- //mountPointStorage
- foreach ($storageRepository->fetch() as $entity)
- {
- if (!in_array("rootdir", $entity->getContentAsArray()))
- {
- continue;
- }
- $this->availableValues["customconfigoption[mountPointStorage]"][$entity->getStorage()] = $lang->tr($entity->getStorage());
- }
- //mountPointAcl
- $this->availableValues["customconfigoption[mountPointAcl]"] = ["default" => $lang->tr('Default'), "1" => $lang->tr("On"), "0" => $lang->tr("Off")];
- //ipv4NetworkMode
- $this->availableValues["customconfigoption[ipv4NetworkMode]"] = ["static" => $lang->tr('Static'), "dhcp" => $lang->tr("DHCP")];
- //ipv6NetworkMode
- $this->availableValues["customconfigoption[ipv6NetworkMode]"] = ["static" => $lang->tr('Static'), "dhcp" => $lang->tr("DHCP"), "slaac" => $lang->tr("SLAAC")];
- //swapUnit
- $this->availableValues["customconfigoption[swapUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB"), "tb" => $lang->tr("TB")];
- //bridge
- foreach ($this->api()->get("/nodes/{$this->node->getNode()}/network") as $network)
- {
- if (!in_array($network['type'], ['bridge', 'OVSBridge']))
- {
- continue;
- }
- $this->availableValues["customconfigoption[bridge]"] [$network['iface']] = $lang->tr($network['iface']);
- }
- ksort($this->availableValues["customconfigoption[bridge]"]);
- //privateBridge
- $this->availableValues["customconfigoption[privateBridge]"] = ['0' => ""] + (array) $this->availableValues["customconfigoption[bridge]"];
- }
- public function update()
- {
- $this->loadRequestObj();
- if (empty($this->request->get('customconfigoption')))
- {
- return;
- }
- try{
- $form = new MainForm();
- $switcherFields = $form->getSwitcherFields();
- $values = $this->request->get('customconfigoption');
- foreach ($values as $k => $v)
- {
- if (in_array($k, $switcherFields))
- {
- unset($switcherFields[array_search($k, $switcherFields)]);
- }
- }
- foreach ($switcherFields as $switch)
- {
- $values[$switch] = "off";
- }
- }catch (\Exception $ex){
- //login to proxmox host failed
- }
- //delete
- $this->configuration->flush();
- sleep(1);
- //save
- $this->configuration->fill((array)$values)
- ->save();
- }
- public function delete()
- {
- $this->configuration->flush();
- }
- public function replicate($replicateProductId){
- $_SESSION['proxmoxVPS']= null;
- if(ProductConfiguration::ofProductId($this->productId)->count()){
- return;
- }
- /**
- * @var $entity ProductConfiguration
- */
- foreach (ProductConfiguration::ofProductId($replicateProductId)->get() as $entity)
- {
- $newEntity = new ProductConfiguration();
- $newEntity->setting = $entity->setting;
- $newEntity->value = $entity->value;
- $newEntity->product_id = $this->productId;
- $newEntity->save();
- }
- }
- }
|