Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

132 righe
3.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Mir Calculate. http://www.calculate-linux.org
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import sys
  16. from calculate.lib.datavars import (ReadonlyVariable, Variable,
  17. VariableError)
  18. from calculate.ldap.variables.helpers import (HashHelper, RandomPasswordHelper,
  19. ServerEnvHelper)
  20. _ = lambda x: x
  21. from calculate.lib.cl_lang import (setLocalTranslate, getLazyLocalTranslate)
  22. setLocalTranslate('cl_unix3', sys.modules[__name__])
  23. __ = getLazyLocalTranslate(_)
  24. class VariableLdUnixLogin(ReadonlyVariable):
  25. """
  26. Имя администратор Unix сервера
  27. """
  28. value = "Unix"
  29. class VariableLdUnixDn(ReadonlyVariable):
  30. """
  31. DN сервиса
  32. """
  33. value_format = "ou={ld_unix_login},{ldap.ld_services_dn}"
  34. class VariableLdUnixBindDn(ServerEnvHelper, Variable):
  35. """
  36. Пароль root
  37. """
  38. service = "unix"
  39. parameter = "DN"
  40. @property
  41. def fallback_value(self):
  42. return self.Get('ld_unix_dn')
  43. class VariableLdUnixUsersDn(ReadonlyVariable):
  44. """
  45. DN пользователей сервиса
  46. """
  47. value_format = "ou=Users,{ld_unix_dn}"
  48. class VariableLdUnixGroupsDn(ReadonlyVariable):
  49. """
  50. DN групп сервиса
  51. """
  52. value_format = "ou=Groups,{ld_unix_dn}"
  53. class VariableLdUnixHash(HashHelper, ReadonlyVariable):
  54. """
  55. Хэш рут пароля
  56. """
  57. source = "ld_unix_pw"
  58. class VariableLdUnixPw(ServerEnvHelper, RandomPasswordHelper, Variable):
  59. """
  60. Пароль root
  61. """
  62. password_len = 9
  63. service = "unix"
  64. parameter = "PASS"
  65. @property
  66. def fallback_value(self):
  67. return RandomPasswordHelper.get(self)
  68. def get(self):
  69. if self.Get('cl_unix_pw_generate_set') == 'on':
  70. return RandomPasswordHelper.get(self)
  71. else:
  72. return super(VariableLdUnixPw, self).get()
  73. class VariableClUnixPwGenerateSet(Variable):
  74. """
  75. Перегенерировать пароль или нет
  76. """
  77. type = "bool"
  78. opt = ("-g", "--gen-password")
  79. value = "off"
  80. def init(self):
  81. self.label = _("Generate new service password")
  82. self.help = _("generate new service password")
  83. def uncompatible(self):
  84. if self.Get('server.sr_unix_set') != 'on':
  85. return "Unavailable for unconfigured Unix service"
  86. class VariableClUnixRemoveSet(Variable):
  87. """
  88. Удалить сервис Unix
  89. """
  90. type = "bool"
  91. guitype = "hidden"
  92. opt = ("-r", "--remove")
  93. value = "off"
  94. def init(self):
  95. self.label = _("Remove service")
  96. self.help = _("remove service")
  97. def check(self, value):
  98. if self.Get('server.sr_unix_set') != 'on':
  99. raise VariableError(
  100. _("Unix service has not been configured"))
  101. def uncompatible(self):
  102. if self.Get('server.sr_unix_set') != 'on':
  103. return "Unavailable for unconfigured Unix service"