ProductProvider.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. <?php
  2. /**********************************************************************
  3. * ProxmoxVPS 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\Admin\Product\Providers;
  20. use MGProvision\Proxmox\v2\models\Node;
  21. use MGProvision\Proxmox\v2\repository\ClusterResourcesRepository;
  22. use MGProvision\Proxmox\v2\repository\FileRepository;
  23. use MGProvision\Proxmox\v2\repository\NodeRepository;
  24. use MGProvision\Proxmox\v2\repository\StorageRepository;
  25. use ModulesGarden\ProxmoxAddon\App\Models\CloudInitScript;
  26. use ModulesGarden\ProxmoxAddon\App\Models\IpAddress;
  27. use ModulesGarden\ProxmoxAddon\App\Models\ProductConfiguration;
  28. use ModulesGarden\ProxmoxAddon\App\Models\Whmcs\Product;
  29. use ModulesGarden\ProxmoxAddon\App\Repositories\Vps\ProductConfigurationRepository;
  30. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  31. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  32. use ModulesGarden\Servers\ProxmoxVps\App\Enum\JobPeriod;
  33. use ModulesGarden\Servers\ProxmoxVps\App\UI\Admin\Product\Forms\MainForm;
  34. use ModulesGarden\Servers\ProxmoxVps\Core\FileReader\Reader\Json;
  35. use ModulesGarden\Servers\ProxmoxVps\Core\Models\Whmcs\EmailTemplate;
  36. use ModulesGarden\Servers\ProxmoxVps\Core\ModuleConstants;
  37. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\AdminArea;
  38. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  39. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\Forms\Fields\Switcher;
  40. use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl;
  41. class ProductProvider extends BaseDataProvider implements AdminArea
  42. {
  43. use ApiService;
  44. use ProductService;
  45. private $productId;
  46. /**
  47. * @var ProductConfigurationRepository
  48. */
  49. protected $configuration;
  50. /**
  51. * @var Node
  52. */
  53. private $node;
  54. /**
  55. * ProductConfigurationProvider constructor.
  56. * @param $productId
  57. */
  58. public function __construct($productId)
  59. {
  60. if (!is_numeric($productId))
  61. {
  62. throw new \InvalidArgumentException("The product id must be definded.");
  63. }
  64. $this->configuration = new ProductConfigurationRepository($productId);
  65. $this->productId = $productId;
  66. }
  67. public function isSupportedModule()
  68. {
  69. return Product::where("id", $this->configuration->getProductId())
  70. ->where("servertype", "proxmoxVPS")->count() == 1;
  71. }
  72. public function read()
  73. {
  74. foreach ($this->configuration->all() as $key => $value)
  75. {
  76. //multiselect
  77. if (is_array($value))
  78. {
  79. $this->data[sprintf("customconfigoption[%s][]", $key)] = $value;
  80. continue;
  81. }
  82. $this->data[sprintf("customconfigoption[%s]", $key)] = $value;
  83. }
  84. $this->initApi();
  85. $this->defaultRead();
  86. if (!$this->configuration->getVirtualization() || $this->configuration->isQemu())
  87. {
  88. //kvm
  89. $this->qemuRead();
  90. }
  91. else
  92. {
  93. //lxc
  94. $this->lxcRead();
  95. }
  96. }
  97. private function initApi()
  98. {
  99. $lang = sl("lang");
  100. $product = Product::where("id", $this->productId)->firstOrFail();
  101. sl("whmcsParams")->setParams($product->getParams());
  102. }
  103. private function defaultRead()
  104. {
  105. $lang = sl("lang");
  106. //Virtualization
  107. $this->availableValues["customconfigoption[virtualization]"] = ["qemu" => $lang->tr("KVM"), "lxc" => $lang->tr("LXC")];
  108. //Default Node
  109. $this->availableValues["customconfigoption[defaultNode]"] = ["serverNode" => $lang->tr('Server-Node'), "autoNode" => $lang->tr('Auto-Node')];
  110. $nodeRepository = new NodeRepository();
  111. $nodeRepository->setApi($this->api());
  112. $nodeRepository->findOnline(true);
  113. foreach ($nodeRepository->fetch() as $node)
  114. {
  115. $this->availableValues["customconfigoption[defaultNode]"][$node->getNode()] = $node->getNode();
  116. }
  117. //realm
  118. foreach ($this->api()->get("/access/domains") as $d)
  119. {
  120. if (!$d['realm'])
  121. {
  122. continue;
  123. }
  124. $this->availableValues["customconfigoption[realm]"][$d['realm']] = $lang->tr($d['comment']);
  125. }
  126. //userRole
  127. foreach ($this->api()->get("/access/roles") as $r)
  128. {
  129. if (!$r['roleid'])
  130. {
  131. continue;
  132. }
  133. $this->availableValues["customconfigoption[userRole]"][$r['roleid']] = $lang->tr($r['roleid']);
  134. }
  135. //welcomeEmailTemplateId
  136. $this->availableValues["customconfigoption[welcomeEmailTemplateId]"][0] = "";
  137. foreach (EmailTemplate::where('type', "product")->pluck("name", "id")->all() as $key => $value)
  138. {
  139. $this->availableValues["customconfigoption[welcomeEmailTemplateId]"][$key] = $value;
  140. }
  141. //reinstallEmailTemplateId
  142. $this->availableValues["customconfigoption[reinstallEmailTemplateId]"][0] = "";
  143. foreach (EmailTemplate::where('type', "product")->pluck("name", "id")->all() as $key => $value)
  144. {
  145. $this->availableValues["customconfigoption[reinstallEmailTemplateId]"][$key] = $value;
  146. }
  147. //upgradeNotificationTemplateId
  148. $this->availableValues["customconfigoption[serviceCreationFailedTemplateId]"][0] = "";
  149. foreach (EmailTemplate::where('type', "admin")->where("custom", 1)->pluck("name", "id")->all() as $key => $value)
  150. {
  151. $this->availableValues["customconfigoption[serviceCreationFailedTemplateId]"][$key] = $value;
  152. }
  153. //upgradeNotificationTemplateId
  154. $this->availableValues["customconfigoption[upgradeNotificationTemplateId]"] = $this->availableValues["customconfigoption[serviceCreationFailedTemplateId]"];
  155. //loadBalancerOnUpgrade
  156. $this->availableValues["customconfigoption[loadBalancerOnUpgrade]"] = ['0' => $lang->tr('None'), "block" => $lang->tr("Block"), "migrate" => $lang->tr("Migrate")];
  157. //backupStorage
  158. if (in_array($this->configuration->getDefaultNode(), $this->availableValues["customconfigoption[defaultNode]"]))
  159. {
  160. $this->node = new Node($this->configuration->getDefaultNode());
  161. }
  162. else
  163. {//"Auto-Node" or 'Server-Node' or empty
  164. $servePrivateIP = $this->getServerPrivateIpAddress();
  165. $serverIp = $servePrivateIP ? $servePrivateIP : $this->getWhmcsParamByKey('serverip');
  166. $this->node = $nodeRepository->findWithHostOrIp($this->getWhmcsParamByKey('serverhostname'), $serverIp );
  167. }
  168. $this->node->setApi($this->api());
  169. $storageRepository = new StorageRepository();
  170. $storageRepository->findByNodes([$this->node->getNode()])
  171. ->findEnabed();
  172. foreach ($storageRepository->fetch() as $entity)
  173. {
  174. if (!in_array("backup", $entity->getContentAsArray()))
  175. {
  176. continue;
  177. }
  178. $this->availableValues["customconfigoption[backupStorage]"] [$entity->getStorage()] = $lang->tr($entity->getStorage());
  179. }
  180. //clusterState
  181. $this->availableValues["customconfigoption[clusterState]"] = ['' => "", 'started' => $lang->tr('Started'), 'stopped' => $lang->tr('Stopped'), 'enabled' => $lang->tr('Enabled'), 'disabled' => $lang->tr('Disabled'), 'ignored' => $lang->tr('Ignored')];
  182. //firewallInterfaces
  183. $this->availableValues["customconfigoption[firewallInterfaces][]"] = ["venet" => $lang->tr("venet"), "eth" => $lang->tr("eth\d+")];
  184. //clusterGroup
  185. $this->availableValues["customconfigoption[clusterGroup]"] = ['' => ""];
  186. foreach ($this->api()->get('/cluster/ha/groups') as $g)
  187. {
  188. $this->availableValues["customconfigoption[clusterGroup]"][$g['group']] = ucfirst($g['group']);
  189. }
  190. //suspensionAction
  191. $this->availableValues["customconfigoption[suspensionAction]"] = ['0' => $lang->tr('Default'), "stop" => $lang->tr('Stop VM'), 'shutdown' => $lang->tr('Shutdown VM')];
  192. if ($this->configuration()->isQemu())
  193. {
  194. $this->availableValues["customconfigoption[suspensionAction]"]["suspend"] = $lang->tr("Pause VM");
  195. $this->availableValues["customconfigoption[suspensionAction]"]["hibernate"] = $lang->tr("Hibernate VM");
  196. }
  197. //tag
  198. $this->availableValues["customconfigoption[tags][]"];
  199. foreach (IpAddress::select("tag")->whereNotNull("tag")->where("tag", ">", 0)->groupBy("tag")->pluck("tag")->all() as $tag)
  200. {
  201. $this->availableValues["customconfigoption[tags][]"][$tag] = $tag;
  202. }
  203. //pool
  204. $this->availableValues["customconfigoption[pool]"]=[""];
  205. foreach ($this->api()->get('/pools') as $pool)
  206. {
  207. $this->availableValues["customconfigoption[pool]"][$pool['poolid']] = $lang->tr($pool['poolid']);
  208. }
  209. //permissionSnapshotJobPeriod
  210. $this->availableValues["customconfigoption[permissionSnapshotJobPeriod][]"] = [
  211. JobPeriod::HOURLY => $lang->tr(JobPeriod::HOURLY),
  212. JobPeriod::DAILY => $lang->tr(JobPeriod::DAILY )
  213. ];
  214. //permissionFirewalOptions
  215. $this->availableValues["customconfigoption[permissionFirewalOptions][]"] = [
  216. "enable" => $lang->abtr("Enable/Disable Firewall"),
  217. "dhcp" => $lang->abtr("DHCP"),
  218. "radv" => $lang->abtr("Allow Router Advertisement"),
  219. "ndp" => $lang->abtr("NDP"),
  220. "macfilter" => $lang->abtr("MAC Filter"),
  221. "ipfilter" => $lang->abtr("IP Filter"),
  222. ];
  223. }
  224. /**
  225. * KVM
  226. */
  227. private function qemuRead()
  228. {
  229. $lang = sl("lang");
  230. //ostype
  231. $ostype = new Json('ostype.json', ModuleConstants::getFullPathWhmcs('modules', 'addons', 'proxmoxAddon', 'storage', 'app'));
  232. foreach ($ostype->get() as $k => $ostype)
  233. {
  234. $this->availableValues["customconfigoption[ostype]"][$k] = $lang->tr($ostype);
  235. }
  236. //hotplug
  237. $this->availableValues["customconfigoption[hotplug][]"] = [ "disk" => $lang->tr('disk'), "network" => $lang->tr('network'), "usb" => $lang->tr('usb'), "cpu" => $lang->tr('cpu'), "memory" => $lang->tr('memory')];
  238. //keyboard
  239. $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')];
  240. //vga
  241. $this->availableValues["customconfigoption[vga]"] = [
  242. "std" => $lang->tr("Standard VGA"),
  243. "cirrus" => $lang->tr("Cirrus Logic"),
  244. "vmware" => $lang->tr("VMWare"),
  245. "serial0" => $lang->tr("Serial terminal 0"),
  246. "serial1" => $lang->tr("Serial terminal 1"),
  247. "serial2" => $lang->tr("Serial terminal 2"),
  248. "serial3" => $lang->tr("Serial terminal 3"),
  249. "qxl" => $lang->tr("SPICE"),
  250. "qxl2" => $lang->tr("SPICE dual monitor"),
  251. "qxl3" => $lang->tr("SPICE three monitor"),
  252. "qxl4" => $lang->tr("SPICE four monitor"),
  253. ];
  254. //clientNameForContainer
  255. $this->availableValues["customconfigoption[clientNameForContainer]"] = [
  256. 0 => 'No',
  257. "emptyHostnameOnly" => 'Yes [only when hostname is empty]',
  258. "overwriteHostname" => 'Yes [overwrite hostname] ',
  259. "overwriteHostnameWithPrefix" => 'Yes [overwrite hostname with container prefix and service id] ',
  260. ];
  261. //cloneMode
  262. $this->availableValues["customconfigoption[cloneMode]"] = ['1' => $lang->tr('Full Clone'), "0" => $lang->tr("Linked Clone")];
  263. //diskStorage images (Disk Images)
  264. $storageRepository = new StorageRepository();
  265. $storageRepository->findByNodes([$this->node->getNode()])
  266. ->findEnabed();
  267. foreach ($storageRepository->fetch() as $entity)
  268. {
  269. if (!in_array("images", $entity->getContentAsArray()))
  270. {
  271. continue;
  272. }
  273. $this->availableValues["customconfigoption[diskStorage]"] [$entity->getStorage()] = $lang->tr($entity->getStorage());
  274. $this->availableValues["customconfigoption[additionalDiskStorage]"] [$entity->getStorage()] = $lang->tr($entity->getStorage());
  275. }
  276. //diskType
  277. $this->availableValues["customconfigoption[diskType]"] = ["ide" => $lang->tr('IDE'), "sata" => $lang->tr('SATA'), "virtio" => $lang->tr('VIRTIO'), "scsi" => $lang->tr('SCSI')];
  278. //diskFormat
  279. $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)')];
  280. //diskCache
  281. $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')];
  282. //scsihw
  283. $this->availableValues["customconfigoption[scsihw]"] = [
  284. '0' => $lang->abtr('Default (LSI 53C895A)'),
  285. "lsi" => $lang->abtr('LSI 53C895A'),
  286. "lsi53c810" => $lang->abtr('LSI 53C810'),
  287. 'virtio-scsi-pci' => $lang->abtr('VirtIO SCSI'),
  288. "virtio-scsi-single" => $lang->abtr('VirtIO SCSI single'),
  289. 'megasas' => $lang->abtr('MegaRAID SAS 8708EM2'),
  290. "pvscsi" => $lang->abtr('VMware PVSCSI'),
  291. ];
  292. //additionalDiskStorage
  293. $this->availableValues["customconfigoption[additionalDiskStorage]"] = $this->availableValues["customconfigoption[diskStorage]"];
  294. //additionalDiskType
  295. $this->availableValues["customconfigoption[additionalDiskType][]"] = $this->availableValues["customconfigoption[diskType]"];
  296. //additionalDiskFormat
  297. $this->availableValues["customconfigoption[additionalDiskFormat][]"] = $this->availableValues["customconfigoption[diskFormat]"];
  298. if($this->configuration->getAdditionalDiskStorage() && preg_match("/lvm/", $this->configuration->getAdditionalDiskStorage() )){
  299. $this->disabledList["customconfigoption[additionalDiskFormat][]"] = ['qcow2', 'vmdk'];
  300. }
  301. //additionalDiskCache
  302. $this->availableValues["customconfigoption[additionalDiskCache]"] = $this->availableValues["customconfigoption[diskCache]"];
  303. //networkModel
  304. $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')];
  305. //bridge
  306. foreach ($this->api()->get("/nodes/{$this->node->getNode()}/network") as $network)
  307. {
  308. if (!in_array($network['type'], ['bridge', 'OVSBridge']))
  309. {
  310. continue;
  311. }
  312. $this->availableValues["customconfigoption[bridge]"] [$network['iface']] = $lang->tr($network['iface']);
  313. }
  314. ksort($this->availableValues["customconfigoption[bridge]"]);
  315. //privateBridge
  316. $this->availableValues["customconfigoption[privateBridge]"] = ['0' => ""] + (array) $this->availableValues["customconfigoption[bridge]"];
  317. //networkPrivateModel
  318. $this->availableValues["customconfigoption[networkPrivateModel]"] = $this->availableValues["customconfigoption[networkModel]"];
  319. //bootDevice1
  320. $this->availableValues["customconfigoption[bootDevice1]"] = ['', 'c' => $lang->tr('Hard Disk'), 'd' => $lang->tr('CD-ROM'), 'n' => $lang->tr('Network')];
  321. //bootDevice2
  322. $this->availableValues["customconfigoption[bootDevice2]"] = $this->availableValues["customconfigoption[bootDevice1]"];
  323. //bootDevice3
  324. $this->availableValues["customconfigoption[bootDevice3]"] = $this->availableValues["customconfigoption[bootDevice1]"];
  325. //permissionOsTemplates
  326. $clusterResourcesRepository = new ClusterResourcesRepository();
  327. $clusterResourcesRepository->setApi($this->api());
  328. $clusterResourcesRepository->findKvmTemplate();
  329. foreach ($clusterResourcesRepository->fetch() as $resurce)
  330. {
  331. if (preg_match('/^custom[0-9]*/', $resurce->getName()))
  332. {
  333. continue;
  334. }
  335. $this->availableValues["customconfigoption[permissionOsTemplates][]"][$resurce->getName()] = $lang->tr($resurce->getName());
  336. }
  337. //osTemplate
  338. $this->availableValues["customconfigoption[osTemplate]"] = ['0' => ""] + (array) $this->availableValues["customconfigoption[permissionOsTemplates][]"];
  339. //permissionIsoImage
  340. $fileRepository = new FileRepository();
  341. $fileRepository->setApi($this->api());
  342. $fileRepository->findIso();
  343. $fileRepository->findByNode($this->node);
  344. $fileRepository->findByStorages($storageRepository->fetchAsArray());
  345. foreach ($fileRepository->fetch() as $file)
  346. {
  347. $this->availableValues["customconfigoption[permissionIsoImages][]"][$file->getVolid()] = $lang->tr($file->getFriendlyName());
  348. }
  349. //isoImage
  350. $this->availableValues["customconfigoption[isoImage]"] = ["none" => $lang->tr("None")] + (array)$this->availableValues["customconfigoption[permissionIsoImages][]"];
  351. //memoryUnit
  352. $this->availableValues["customconfigoption[memoryUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB")];
  353. //diskUnit
  354. $this->availableValues["customconfigoption[diskUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB"), "tb" => $lang->tr("TB")];
  355. //additionalDiskUnit
  356. $this->availableValues["customconfigoption[additionalDiskUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB"), "tb" => $lang->tr("TB")];
  357. //cdromType
  358. $this->availableValues["customconfigoption[cdromType]"] = $this->availableValues["customconfigoption[diskType]"];
  359. //bios
  360. $this->availableValues["customconfigoption[bios]"] = [
  361. '0' => "",
  362. 'seabios' => $lang->tr('SeaBIOS'),
  363. 'ovmf' => $lang->tr('OVMF (UEFI)')
  364. ];
  365. //cloudInitScript
  366. $this->availableValues["customconfigoption[cloudInitScript]"] =
  367. CloudInitScript::pluck('name','id')->prepend("",0)->toArray();
  368. //machine
  369. $jsonData = new Json('machine.json', ModuleConstants::getFullPathWhmcs('modules', 'addons', 'proxmoxAddon', 'storage', 'app'));
  370. foreach ($jsonData->get() as $k => $name)
  371. {
  372. $this->availableValues["customconfigoption[machine]"][$k] = $lang->tr($name);
  373. }
  374. //cpu
  375. $jsonData = new Json('cpu.json', ModuleConstants::getFullPathWhmcs('modules', 'addons', 'proxmoxAddon', 'storage', 'app'));
  376. foreach ($jsonData->get() as $k => $name)
  377. {
  378. $this->availableValues["customconfigoption[cpu]"][$k] = $lang->tr($name);
  379. }
  380. }
  381. /**
  382. * LXC
  383. */
  384. private function lxcRead()
  385. {
  386. $lang = sl("lang");
  387. //storage
  388. $storageRepository = new StorageRepository();
  389. $storageRepository->findByNodes([$this->node->getNode()])
  390. ->findEnabed();
  391. foreach ($storageRepository->fetch() as $storage)
  392. {
  393. if (!in_array("rootdir", $storage->getContentAsArray()))
  394. {
  395. continue;
  396. }
  397. $this->availableValues["customconfigoption[storage]"][$storage->getStorage()] = $lang->tr($storage->getStorage());
  398. }
  399. //arch
  400. $this->availableValues["customconfigoption[arch]"] = ['0' => "", 'amd64' => $lang->tr("AMD64"), $lang->tr("i386") => $lang->tr("i386")];
  401. //cmode
  402. $this->availableValues["customconfigoption[cmode]"] = ['0' => "", 'shell' => $lang->tr("shell"), "console" => $lang->tr("console"), "tty" => $lang->tr("tty")];
  403. //ostype
  404. $this->availableValues["customconfigoption[ostype]"] = ['0' => "", 'debian' => $lang->tr("Debian"), "ubuntu" => $lang->tr("Ubuntu"), "centos" => $lang->tr("centos"), "archlinux" => $lang->tr("Archlinux")];
  405. //osTemplate
  406. $fileRepository = new FileRepository();
  407. $fileRepository->setApi($this->api());
  408. $fileRepository->findLxcTemplates();
  409. $fileRepository->findByNode($this->node);
  410. $fileRepository->findByStorages($storageRepository->fetchAsArray());
  411. foreach ($fileRepository->fetch() as $file)
  412. {
  413. $this->availableValues["customconfigoption[osTemplate]"][$file->getVolid()] = $lang->tr($file->getFriendlyName());
  414. }
  415. //memoryUnit
  416. $this->availableValues["customconfigoption[memoryUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB")];
  417. //diskUnit
  418. $this->availableValues["customconfigoption[diskUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB"), "tb" => $lang->tr("TB")];
  419. //additionalDiskUnit
  420. $this->availableValues["customconfigoption[additionalDiskUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB"), "tb" => $lang->tr("TB")];
  421. //persimonOsTemplates
  422. $this->availableValues["customconfigoption[permissionOsTemplates][]"] = $this->availableValues["customconfigoption[osTemplate]"];
  423. //mountPointStorage
  424. foreach ($storageRepository->fetch() as $entity)
  425. {
  426. if (!in_array("rootdir", $entity->getContentAsArray()))
  427. {
  428. continue;
  429. }
  430. $this->availableValues["customconfigoption[mountPointStorage]"][$entity->getStorage()] = $lang->tr($entity->getStorage());
  431. }
  432. //mountPointAcl
  433. $this->availableValues["customconfigoption[mountPointAcl]"] = ["default" => $lang->tr('Default'), "1" => $lang->tr("On"), "0" => $lang->tr("Off")];
  434. //ipv4NetworkMode
  435. $this->availableValues["customconfigoption[ipv4NetworkMode]"] = ["static" => $lang->tr('Static'), "dhcp" => $lang->tr("DHCP")];
  436. //ipv6NetworkMode
  437. $this->availableValues["customconfigoption[ipv6NetworkMode]"] = ["static" => $lang->tr('Static'), "dhcp" => $lang->tr("DHCP"), "slaac" => $lang->tr("SLAAC")];
  438. //swapUnit
  439. $this->availableValues["customconfigoption[swapUnit]"] = ['mb' => $lang->tr("MB"), "gb" => $lang->tr("GB"), "tb" => $lang->tr("TB")];
  440. //bridge
  441. foreach ($this->api()->get("/nodes/{$this->node->getNode()}/network") as $network)
  442. {
  443. if (!in_array($network['type'], ['bridge', 'OVSBridge']))
  444. {
  445. continue;
  446. }
  447. $this->availableValues["customconfigoption[bridge]"] [$network['iface']] = $lang->tr($network['iface']);
  448. }
  449. ksort($this->availableValues["customconfigoption[bridge]"]);
  450. //privateBridge
  451. $this->availableValues["customconfigoption[privateBridge]"] = ['0' => ""] + (array) $this->availableValues["customconfigoption[bridge]"];
  452. }
  453. public function update()
  454. {
  455. $this->loadRequestObj();
  456. if (empty($this->request->get('customconfigoption')))
  457. {
  458. return;
  459. }
  460. try{
  461. $form = new MainForm();
  462. $switcherFields = $form->getSwitcherFields();
  463. $values = $this->request->get('customconfigoption');
  464. foreach ($values as $k => $v)
  465. {
  466. if (in_array($k, $switcherFields))
  467. {
  468. unset($switcherFields[array_search($k, $switcherFields)]);
  469. }
  470. }
  471. foreach ($switcherFields as $switch)
  472. {
  473. $values[$switch] = "off";
  474. }
  475. }catch (\Exception $ex){
  476. //login to proxmox host failed
  477. }
  478. //delete
  479. $this->configuration->flush();
  480. sleep(1);
  481. //save
  482. $this->configuration->fill((array)$values)
  483. ->save();
  484. }
  485. public function delete()
  486. {
  487. $this->configuration->flush();
  488. }
  489. public function replicate($replicateProductId){
  490. $_SESSION['proxmoxVPS']= null;
  491. if(ProductConfiguration::ofProductId($this->productId)->count()){
  492. return;
  493. }
  494. /**
  495. * @var $entity ProductConfiguration
  496. */
  497. foreach (ProductConfiguration::ofProductId($replicateProductId)->get() as $entity)
  498. {
  499. $newEntity = new ProductConfiguration();
  500. $newEntity->setting = $entity->setting;
  501. $newEntity->value = $entity->value;
  502. $newEntity->product_id = $this->productId;
  503. $newEntity->save();
  504. }
  505. }
  506. }