OpenSRS.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Libs\Api;
  3. use ModulesGarden\ProxmoxAddon\App\Libs\Api\OpenSRS\Request;
  4. use ModulesGarden\ProxmoxAddon\Core\Api\AbstractApi;
  5. use ModulesGarden\ProxmoxAddon\Core\Helper;
  6. use ModulesGarden\ProxmoxAddon\Core\ModuleConstants;
  7. use Mso\IdnaConvert\IdnaConvert;
  8. /**
  9. * Description of OpenSRS
  10. *
  11. * @author Rafał Ossowski <rafal.os@modulesgarden.com>
  12. */
  13. class OpenSRS extends AbstractApi
  14. {
  15. const METHOD_API_CHECK_ONE_DOMAIN = 'CheckOneDomain';
  16. const METHOD_API_CHECK_MORE_DOMAINS = 'CheckMoreDomains';
  17. protected $defineFields = [
  18. 'OSRS_USERNAME' => '', // get with db
  19. 'OSRS_KEY' => '', // get with db
  20. 'CRYPT_TYPE' => 'ssl',
  21. 'OSRS_HOST' => '', // get with db
  22. 'OSRS_SSL_PORT' => '55443',
  23. 'OSRS_PROTOCOL' => 'XCP',
  24. 'OSRS_VERSION' => 'XML:0.1',
  25. 'OSRS_DEBUG' => 0, // static field
  26. 'SRS_SPIN_COUNT' => 0, // get with db
  27. 'OSRS_FASTLOOKUP_PORT' => '51000',
  28. 'MAIL_HOST' => 'https://admin.hostedemail.com',
  29. 'MAIL_USERNAME' => '', // null
  30. 'MAIL_PASSWORD' => '', // null
  31. 'MAIL_ENV' => 'LIVE',
  32. 'MAIL_CLIENT' => 'OpenSRS PHP Toolkit',
  33. 'APP_MAIL_HOST' => 'ssl://admin.hostedemail.com',
  34. 'APP_MAIL_USERNAME' => '', // null
  35. 'APP_MAIL_PASSWORD' => '', // null
  36. 'APP_MAIL_DOMAIN' => '', // null
  37. 'APP_MAIL_PORT' => '4449',
  38. 'APP_MAIL_PORTWAIT' => '10'
  39. ];
  40. protected $settings;
  41. protected $request;
  42. /**
  43. * @var IdnaConvert
  44. */
  45. protected $idnaConvert;
  46. public function __construct(IdnaConvert $idnaConvert)
  47. {
  48. $this->idnaConvert = $idnaConvert;
  49. }
  50. public function setSettings($settings)
  51. {
  52. $this->settings = $settings;
  53. $this->loadDefine();
  54. $this->request = Helper\di(Request::class);
  55. return $this;
  56. }
  57. protected function loadDefine()
  58. {
  59. $register = Helper\sl('register');
  60. $this->defineFields['OSRS_USERNAME'] = $this->settings['username'];
  61. $this->defineFields['OSRS_KEY'] = $this->settings['privateKey'];
  62. $this->defineFields['OSRS_HOST'] = $this->settings['hostname'];
  63. $this->defineFields['SRS_SPIN_COUNT'] = $this->settings['spinnerCount'];
  64. foreach ($this->defineFields as $defineName => $value)
  65. {
  66. if ($register->isRegister($defineName) === false)
  67. {
  68. $register->register($defineName, $value);
  69. }
  70. }
  71. }
  72. public function checkOneDomain($record)
  73. {
  74. return $this->callToMethod(self::METHOD_API_CHECK_ONE_DOMAIN, $record);
  75. }
  76. protected function callToMethod($name, $params = null)
  77. {
  78. $namespace = "\\" . ModuleConstants::getRootNamespace() . "\App\Libs\Api\OpenSRS\Method\\" . $name;
  79. return (new $namespace($this->request, $this->settings, $this->idnaConvert))->execute($params);
  80. }
  81. public function checkMoreDomain($records)
  82. {
  83. return $this->callToMethod(self::METHOD_API_CHECK_MORE_DOMAINS, $records);
  84. }
  85. }