Users.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (Sep 19, 2018)
  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\ProxmoxAddon\App\Cron;
  20. use ModulesGarden\ProxmoxAddon as main;
  21. use ModulesGarden\ProxmoxAddon\Core\CommandLine\Command;
  22. use ModulesGarden\ProxmoxAddon\Core\CommandLine\Hypervisor;
  23. use Symfony\Component\Console\Input\InputInterface;
  24. use Symfony\Component\Console\Output\OutputInterface;
  25. use Symfony\Component\Console\Style\SymfonyStyle;
  26. use ModulesGarden\ProxmoxAddon\App\Enum\Vps;
  27. use ModulesGarden\ProxmoxAddon\App\Enum\Cloud;
  28. /**
  29. * Description of Users
  30. *
  31. * @author Pawel Kopec <pawelk@modulesgardne.com>
  32. */
  33. class Users extends Command
  34. {
  35. /**
  36. * Command name
  37. * @var string
  38. */
  39. protected $name = 'users';
  40. /**
  41. * Command description
  42. * @var string
  43. */
  44. protected $description = '';
  45. /**
  46. * Command help text
  47. * @var string
  48. */
  49. protected $help = '';
  50. protected function process(InputInterface $input, OutputInterface $output, SymfonyStyle $io)
  51. {
  52. $io->title('Synchronize users: Starting');
  53. if (!function_exists('ModuleBuildParams'))
  54. {
  55. require_once ROOTDIR . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . "modulefunctions.php";
  56. }
  57. //Get Hostings
  58. $h = (new main\Core\Models\Whmcs\Hosting)->getTable();
  59. $s = (new main\Core\Models\Whmcs\Server)->getTable();
  60. $hostings = main\Core\Models\Whmcs\Hosting::select("{$h}.*")
  61. ->rightJoin($s, "{$h}.server", '=', "{$s}.id")
  62. ->where("{$h}.domainstatus", "Active")
  63. ->whereIn("{$s}.type", ["proxmoxVPS", "ProxmoxCloudVps"])
  64. ->orderBy("{$h}.server");
  65. $i = 0;
  66. foreach ($hostings->get() as $hosting)
  67. {
  68. /* @var $hosting main\Core\Models\Whmcs\Hosting */
  69. $i++;
  70. $output->writeln(sprintf("Synchronize hosting: %s", $hosting->id));
  71. try
  72. {
  73. $params = \ModuleBuildParams($hosting->id);
  74. if ($params['moduletype'] == "proxmoxVPS")
  75. {
  76. if (!$params['customfields'][Vps\CustomField::VMID])
  77. {
  78. throw new \Exception("Custom Field \"vmid\" is empty");
  79. }
  80. if (!$params['customfields'][Vps\CustomField::NODE])
  81. {
  82. throw new \Exception("Custom Field \"node\" is empty");
  83. }
  84. \ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl("whmcsParams")->setParams($params);
  85. $controler = new \ModulesGarden\Servers\ProxmoxVps\App\Http\Actions\ChangeUserRole();
  86. $controler->execute($params);
  87. }
  88. else
  89. {
  90. if ($params['moduletype'] == "ProxmoxCloudVps")
  91. {
  92. \ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl("whmcsParams")->setParams($params);
  93. $controler = new \ModulesGarden\Servers\ProxmoxCloudVps\App\Http\Actions\ChangeUserRole();
  94. $controler->execute($params);
  95. }
  96. }
  97. $output->writeln(sprintf("Hosting: %s has been synchronized", $hosting->id));
  98. }
  99. catch (\Exception $ex)
  100. {
  101. if ($hosting)
  102. {
  103. $io->error("Hosting Id #{$hosting->id}, " . $ex->getMessage());
  104. }
  105. else
  106. {
  107. $io->error($ex->getMessage());
  108. }
  109. }
  110. (new Hypervisor($this->getName(), $input->getOptions()))
  111. ->ping();
  112. }
  113. $output->writeln("");
  114. $io->success([
  115. sprintf("Synchronize hostings: %s Entries Processed.", $i),
  116. "Synchronize hostings: Done"
  117. ]);
  118. }
  119. }