index.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class HestiaChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin {
  3. public function Init() {
  4. $this->addHook("main.fabrica", "MainFabrica");
  5. }
  6. /**
  7. * @param string $sName
  8. * @param mixed $oProvider
  9. */
  10. public function MainFabrica($sName, &$oProvider) {
  11. switch ($sName) {
  12. case "change-password":
  13. $sHost = \trim($this->Config()->Get("plugin", "hestia_host", ""));
  14. $iPort = (int) $this->Config()->Get("plugin", "hestia_port", 8083);
  15. if (!empty($sHost) && 0 < $iPort) {
  16. include_once __DIR__ . "/HestiaChangePasswordDriver.php";
  17. $oProvider = new HestiaChangePasswordDriver();
  18. $oProvider->SetLogger(
  19. $this->Manager()
  20. ->Actions()
  21. ->Logger(),
  22. );
  23. $oProvider->SetConfig($sHost, $iPort);
  24. $oProvider->SetAllowedEmails(
  25. \strtolower(\trim($this->Config()->Get("plugin", "allowed_emails", ""))),
  26. );
  27. }
  28. break;
  29. }
  30. }
  31. /**
  32. * @return array
  33. */
  34. public function configMapping() {
  35. return [
  36. \RainLoop\Plugins\Property::NewInstance("hestia_host")
  37. ->SetLabel("Hestia Host")
  38. ->SetDefaultValue("")
  39. ->SetDescription("Ex: localhost or domain.com"),
  40. \RainLoop\Plugins\Property::NewInstance("hestia_port")
  41. ->SetLabel("Hestia Port")
  42. ->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
  43. ->SetDefaultValue(8083),
  44. \RainLoop\Plugins\Property::NewInstance("allowed_emails")
  45. ->SetLabel("Allowed emails")
  46. ->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
  47. ->SetDescription(
  48. "Allowed emails, space as delimiter, wildcard supported. Example: user1@domain1.net user2@domain1.net *@domain2.net",
  49. )
  50. ->SetDefaultValue("*"),
  51. ];
  52. }
  53. }