M3M1P0.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 M3M1P0 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. }
  33. protected function defaultProductOptions(){
  34. foreach (Product::ofProxmoxCloud()->get() as $product){
  35. $setting = ProductConfiguration::firstOrNew([
  36. 'product_id' => $product->id,
  37. 'setting' => 'permissionVirtualNetwork'
  38. ]);
  39. $setting->value = 'on';
  40. $setting->save();
  41. }
  42. }
  43. protected function changePackegeCloud(){
  44. $file = \ModulesGarden\ProxmoxAddon\Core\ModuleConstants::getFullPathWhmcs('modules', 'servers','ProxmoxCloudVps', 'core') . DIRECTORY_SEPARATOR . 'Bootstrap.php';
  45. if(!file_exists($file))
  46. {
  47. return;
  48. }
  49. include_once $file;
  50. if (!function_exists('ModuleBuildParams'))
  51. {
  52. require_once ModuleConstants::getFullPathWhmcs('includes') . DIRECTORY_SEPARATOR . "modulefunctions.php";
  53. }
  54. foreach (Hosting::ofProxmoxCloudAndStatusActiveAndSuspended()->get() as $hosting) {
  55. $params = \ModuleBuildParams($hosting->id);
  56. \ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl('whmcsParams')->setParams($params);
  57. $controller = new \ModulesGarden\Servers\ProxmoxCloudVps\App\Http\Actions\ChangePackage();
  58. $result = $controller->execute($params);
  59. if($result != 'success'){
  60. $msg = sprintf('Module Change Package Failed - Service ID: %s - Error: %s', $hosting->id, $result);
  61. logActivity( $msg );
  62. }
  63. }
  64. }
  65. public function ipAddressesForCloud(){
  66. try
  67. {
  68. $query = DB::table("proxmoxcloud_ips")->where('vid', '0');
  69. foreach ($query->get() as $entery)
  70. {
  71. if(!Hosting::ofId($entery->hid)->activeAndSuspended()->count()){
  72. continue;
  73. }
  74. if (VmIpAddress::ofHostingId($entery->hid)->ofIp($entery->ip)->count()) {
  75. continue;
  76. }
  77. //public ip only
  78. if(!filter_var($entery->ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)){
  79. continue;
  80. }
  81. $entity = new VmIpAddress();
  82. $entery->hosting_id = $entery->hid;
  83. $entery->server_id = $entery->sid;
  84. $entery->vm_id = null;
  85. $entity->fill((array)$entery)
  86. ->save();
  87. }
  88. }
  89. catch (\Exception $ex)
  90. {
  91. if (!preg_match("/doesn\'t/", $ex->getMessage()))
  92. {
  93. throw $ex;
  94. }
  95. }
  96. }
  97. }