You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 line
5.0 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.core.server.func import Action, Tasks
  17. from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate
  18. from calculate.lib.cl_template import TemplatesError
  19. from calculate.lib.utils.files import FilesError
  20. from calculate.lib.datavars import VariableError
  21. from calculate.server.variables.action import Actions
  22. from ..unix import UnixError, Unix
  23. from calculate.ldap.ldap import LdapError, Ldap
  24. from calculate.ldap.utils.cl_ldap_setup import MetaTasks
  25. from calculate.ldap.utils.cl_ldap_setup import ClLdapSetupAction
  26. from calculate.server.server import ServerError
  27. _ = lambda x: x
  28. setLocalTranslate('cl_unix3', sys.modules[__name__])
  29. __ = getLazyLocalTranslate(_)
  30. class ClUnixSetupAction(Action):
  31. """
  32. Действие обновление конфигурационных файлов
  33. """
  34. # ошибки, которые отображаются без подробностей
  35. native_error = (FilesError,
  36. TemplatesError,
  37. VariableError,
  38. ServerError,
  39. UnixError,
  40. LdapError)
  41. successMessage = None
  42. failedMessage = __("Failed to configure Unix server!")
  43. interruptMessage = __("Unix server configuration manually interrupted")
  44. stop_tasks = [
  45. ]
  46. meta_tasks = MetaTasks("Unix")
  47. uninstall_tasks = [
  48. {'name': 'clear_creds',
  49. 'method': 'Server.clear_service_data("unix")'
  50. },
  51. {'name': 'unset_ldap',
  52. 'method': 'Server.service_uninstall("unix")'
  53. },
  54. ]
  55. # список задач для действия
  56. tasks = [
  57. {'name': 'set_ldif',
  58. 'method': 'Unix.set_ldap_connection('
  59. 'ldap.ld_admin_dn,ldap.ld_admin_pw)',
  60. },
  61. {'name': 'remove_service',
  62. 'condition': lambda Get: (Get('cl_unix_remove_set') == 'on' or
  63. Get('server.sr_unix_set') != 'on')
  64. },
  65. {'name': 'remove_only',
  66. 'message': _("Removing Unix service"),
  67. 'condition': lambda Get: (Get('cl_unix_remove_set') == 'on' and
  68. Get('server.sr_unix_set') == 'on')
  69. },
  70. {'name': 'setup_service',
  71. 'condition': lambda Get: Get('server.sr_unix_set') != 'on'
  72. },
  73. {'name': 'remove_service:remove_old_db',
  74. 'method': 'Unix.remove_ldap_branch(ld_unix_dn)',
  75. 'condition': lambda Get: Get('server.sr_unix_set') == 'on'
  76. },
  77. {'name': 'remove_service:uninstall',
  78. 'tasks': uninstall_tasks,
  79. 'condition': lambda Get: Get('server.sr_unix_set') == 'on'
  80. },
  81. {'name': 'setup_service:apply_ldif',
  82. 'tasks': meta_tasks.ldif_task("ldap.ld_admin_dn,ldap.ld_admin_pw",
  83. Actions.Setup)
  84. },
  85. {'name': 'setup_service:set_unix',
  86. 'method': 'Server.service_install("unix")'
  87. },
  88. {'name': 'generate_password',
  89. 'message': _("Create new password for Unix service"),
  90. 'method': 'Unix.generate_password(ld_unix_bind_dn,'
  91. 'ld_unix_hash,"Unix")',
  92. 'condition': lambda Get: Get('cl_unix_pw_generate_set') == 'on'
  93. },
  94. {'name': 'templates',
  95. 'message': __("System configuration"),
  96. 'method': 'Server.applyTemplates(install.cl_source,'
  97. 'False,True,None,True,True)',
  98. },
  99. {'name': 'restart_slapd',
  100. 'message': __("Restarting LDAP service"),
  101. 'method': 'Server.restart_service("%s")' % Ldap.Service.LDAP,
  102. },
  103. {'name': 'save_creds',
  104. 'method': 'Server.save_service_data("unix",'
  105. 'ld_unix_bind_dn,ld_unix_pw)',
  106. 'condition': lambda Get: Get('cl_unix_remove_set') != 'on'
  107. },
  108. {'name': 'success',
  109. 'message': __("Unix server configured!"),
  110. 'condition': lambda Get: Get('cl_unix_remove_set') != 'on',
  111. 'depend': (Tasks.success() & Tasks.hasnot("failed"))
  112. },
  113. {'name': 'success',
  114. 'message': __("Unix server removed!"),
  115. 'condition': lambda Get: Get('cl_unix_remove_set') == 'on',
  116. 'depend': (Tasks.success() & Tasks.hasnot("failed"))
  117. }
  118. # {'name': 'save_data',
  119. # 'method': 'Unix.save_variables()'
  120. # }
  121. ]
  122. ClLdapSetupAction.register_stop(stop_tasks)
  123. ClLdapSetupAction.register_uninstall(uninstall_tasks)