M3M0P0.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Configuration\Addon\Update\Patch;
  3. use Illuminate\Database\Capsule\Manager as DB;
  4. use ModulesGarden\ProxmoxAddon\App\Configuration\Addon\Update\DefaultPatch;
  5. use ModulesGarden\ProxmoxAddon\App\Models\ProductConfiguration;
  6. use ModulesGarden\ProxmoxAddon\App\Models\VirtualInterface;
  7. use ModulesGarden\ProxmoxAddon\App\Models\VmIpAddress;
  8. use ModulesGarden\ProxmoxAddon\App\Models\Whmcs\Hosting;
  9. use ModulesGarden\ProxmoxAddon\App\Models\Whmcs\Product;
  10. use ModulesGarden\ProxmoxAddon\Core\Helper;
  11. use ModulesGarden\ProxmoxAddon\Core\ModuleConstants;
  12. /**
  13. * Description of M2M6P0
  14. *
  15. */
  16. class M3M0P0 extends DefaultPatch
  17. {
  18. public function execute()
  19. {
  20. if ($this->runSchema())
  21. {
  22. Helper\sl('logger')
  23. ->addDebug("Correctly installed update {$this->getVersion()} .", []);
  24. }
  25. else
  26. {
  27. Helper\sl('errorManager')
  28. ->addError(self::class, "Incorrectly installed update {$this->getVersion()} .", []);
  29. }
  30. //data
  31. $this->up();
  32. //Proxmox Cloud import vms
  33. $this->vms();
  34. //ip addresses not assigned
  35. $this->ipAddressesForCloud();
  36. //proxmoxcloud_private_interfaces
  37. //proxmoxcloud_private_networks
  38. $this->productCloud();
  39. $this->defaultProductOptions();
  40. //users
  41. $this->usersCloud();
  42. //assign ip adresses
  43. $this->changePackegeCloud();
  44. }
  45. protected function defaultProductOptions(){
  46. foreach (Product::ofProxmoxCloud()->get() as $product){
  47. $setting = ProductConfiguration::firstOrNew([
  48. 'product_id' => $product->id,
  49. 'setting' => 'permissionVirtualNetwork'
  50. ]);
  51. $setting->value = 'on';
  52. $setting->save();
  53. }
  54. }
  55. protected function changePackegeCloud(){
  56. $file = \ModulesGarden\ProxmoxAddon\Core\ModuleConstants::getFullPathWhmcs('modules', 'servers','ProxmoxCloudVps', 'core') . DIRECTORY_SEPARATOR . 'Bootstrap.php';
  57. if(!file_exists($file))
  58. {
  59. return;
  60. }
  61. include_once $file;
  62. if (!function_exists('ModuleBuildParams'))
  63. {
  64. require_once ModuleConstants::getFullPathWhmcs('includes') . DIRECTORY_SEPARATOR . "modulefunctions.php";
  65. }
  66. foreach (Hosting::ofProxmoxCloudAndStatusActiveAndSuspended()->get() as $hosting) {
  67. $params = \ModuleBuildParams($hosting->id);
  68. \ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl('whmcsParams')->setParams($params);
  69. $controller = new \ModulesGarden\Servers\ProxmoxCloudVps\App\Http\Actions\ChangePackage();
  70. $result = $controller->execute($params);
  71. if($result != 'success'){
  72. $msg = sprintf('Module Change Package Failed - Service ID: %s - Error: %s', $hosting->id, $result);
  73. logActivity( $msg );
  74. }
  75. }
  76. }
  77. public function ipAddressesForCloud(){
  78. try
  79. {
  80. $query = DB::table("proxmoxcloud_ips")->where('vid', '0');
  81. foreach ($query->get() as $entery)
  82. {
  83. if(!Hosting::ofId($entery->hid)->activeAndSuspended()->count()){
  84. continue;
  85. }
  86. if (VmIpAddress::ofHostingId($entery->hid)->ofIp($entery->ip)->count()) {
  87. continue;
  88. }
  89. //public ip only
  90. if(!filter_var($entery->ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)){
  91. continue;
  92. }
  93. $entity = new VmIpAddress();
  94. $entery->hosting_id = $entery->hid;
  95. $entery->server_id = $entery->sid;
  96. $entery->vm_id = null;
  97. $entity->fill((array)$entery)
  98. ->save();
  99. }
  100. }
  101. catch (\Exception $ex)
  102. {
  103. if (!preg_match("/doesn\'t/", $ex->getMessage()))
  104. {
  105. throw $ex;
  106. }
  107. }
  108. }
  109. }