@@ -, +, @@ samba_tool_dbcheck.py --- .../diagnostic/plugins/samba_tool_dbcheck.py | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 management/univention-management-console-module-diagnostic/umc/python/diagnostic/plugins/samba_tool_dbcheck.py --- a/management/univention-management-console-module-diagnostic/umc/python/diagnostic/plugins/samba_tool_dbcheck.py +++ a/management/univention-management-console-module-diagnostic/umc/python/diagnostic/plugins/samba_tool_dbcheck.py @@ -0,0 +1,54 @@ +#!/usr/bin/python2.7 +# coding: utf-8 +# +# Univention Management Console module: +# System Diagnosis UMC module +# +# Copyright 2016-2017 Univention GmbH +# +# http://www.univention.de/ +# +# All rights reserved. +# +# The source code of this program is made available +# under the terms of the GNU Affero General Public License version 3 +# (GNU AGPL V3) as published by the Free Software Foundation. +# +# Binary versions of this program provided by Univention to you as +# well as other copyrighted, protected or trademarked materials like +# Logos, graphics, fonts, specific documentations and configurations, +# cryptographic keys etc. are subject to a license agreement between +# you and Univention and not subject to the GNU AGPL V3. +# +# In the case you use this program under the terms of the GNU AGPL V3, +# the program is provided in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License with the Debian GNU/Linux or Univention distribution in file +# /usr/share/common-licenses/AGPL-3; if not, see +# . + +from subprocess import Popen, PIPE, STDOUT + +from univention.management.console.modules.diagnostic import Critical + +from univention.lib.i18n import Translation +_ = Translation('univention-management-console-module-diagnostic').translate + +title = _('Check local AD database for errors') +description = _('No errors found.'), + + +def run(): + process = Popen(['samba-tool', 'dbcheck'], stdout=PIPE, stderr=STDOUT) + stdout, stderr = process.communicate() + if process.returncode: + raise Critical('\n'.join([description, '', stdout])) + + +if __name__ == '__main__': + from univention.management.console.modules.diagnostic import main + main() -- samba_tool_dbcheck.py --- .../diagnostic/plugins/samba_tool_dbcheck.py | 81 ++++++++++++++++++++-- 1 file changed, 74 insertions(+), 7 deletions(-) --- a/management/univention-management-console-module-diagnostic/umc/python/diagnostic/plugins/samba_tool_dbcheck.py +++ a/management/univention-management-console-module-diagnostic/umc/python/diagnostic/plugins/samba_tool_dbcheck.py @@ -31,9 +31,12 @@ # /usr/share/common-licenses/AGPL-3; if not, see # . -from subprocess import Popen, PIPE, STDOUT +import ldap +import socket +import subprocess -from univention.management.console.modules.diagnostic import Critical +import univention.uldap +from univention.management.console.modules.diagnostic import Critical, ProblemFixed from univention.lib.i18n import Translation _ = Translation('univention-management-console-module-diagnostic').translate @@ -42,11 +45,75 @@ title = _('Check local AD database for errors') description = _('No errors found.'), -def run(): - process = Popen(['samba-tool', 'dbcheck'], stdout=PIPE, stderr=STDOUT) - stdout, stderr = process.communicate() - if process.returncode: - raise Critical('\n'.join([description, '', stdout])) +def run_samba_tool_dbcheck_fix(): + if not is_service_active('Samba 4'): + return + + cmd = ['samba-tool', 'dbcheck', '--fix', '--yes'] + (success, output) = run_with_output(cmd) + if success: + fix_log = [_('`samba-tool dbcheck --fix --yes` failed.')] + else: + fix_log = [_('`samba-tool dbcheck --fix --yes` succeeded.')] + fix_log.append(output) + run(rerun=True, fix_log='\n'.join(fix_log)) + + +actions = { + 'run_samba_tool_dbcheck_fix': run_samba_tool_dbcheck_fix +} + + +def is_service_active(service): + lo = univention.uldap.getMachineConnection() + raw_filter = '(&(univentionService=%s)(cn=%s))' + filter_expr = ldap.filter.filter_format(raw_filter, (service, socket.gethostname())) + for (dn, _attr) in lo.search(filter_expr, attr=['cn']): + if dn is not None: + return True + return False + + +def run_with_output(cmd): + output = list() + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + (stdout, stderr) = process.communicate() + if stdout: + output.append('\nSTDOUT:\n{}'.format(stdout)) + if stderr: + output.append('\nSTDERR:\n{}'.format(stderr)) + return (process.returncode == 0, '\n'.join(output)) + + +def run(rerun=False, fix_log=''): + if not is_service_active('Samba 4'): + return + + error_descriptions = list() + if rerun and fix_log: + error_descriptions.append(fix_log) + + buttons = [{ + 'action': 'run_samba_tool_dbcheck_fix', + 'label': _('Run `samba-tool dbcheck --fix --yes`'), + }] + + cmd = ['samba-tool', 'dbcheck'] + (success, output) = run_with_output(cmd) + if not success: + error = _('`samba-tool dbcheck` returned a problem with the local AD database.') + error_descriptions.append(error) + error_descriptions.append(output) + if not rerun: + fix = _('You can run `samba-tool dbcheck --fix` to fix the issue.') + error_descriptions.append(fix) + raise Critical(description='\n'.join(error_descriptions), buttons=buttons) + + if rerun: + fixed = _('`samba-tool dbcheck` found no problems with the local AD database.') + error_descriptions.append(fixed) + error_descriptions.append(output) + raise ProblemFixed(description='\n'.join(error_descriptions)) if __name__ == '__main__': -- samba_tool_dbcheck.py (po) --- .../umc/python/diagnostic/de.po | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) --- a/management/univention-management-console-module-diagnostic/umc/python/diagnostic/de.po +++ a/management/univention-management-console-module-diagnostic/umc/python/diagnostic/de.po @@ -2,8 +2,8 @@ msgid "" msgstr "" "Project-Id-Version: univention-management-console-module-diagnostic\n" -"Report-Msgid-Bugs-To: packages@univention.de\n" -"POT-Creation-Date: 2016-01-14 12:19+0100\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-06-01 18:00+0200\n" "PO-Revision-Date: \n" "Last-Translator: Univention GmbH \n" "Language-Team: Univention GmbH \n" @@ -27,6 +27,10 @@ msgstr "" msgid "Adjust to suggested limits" msgstr "An vorgeschlagene Limits anpassen" +#: umc/python/diagnostic/plugins/samba_tool_dbcheck.py:44 +msgid "Check local AD database for errors" +msgstr "Teste die locale AD Datenbank auf Fehler" + #: umc/python/diagnostic/plugins/gateway.py:11 msgid "Gateway is not reachable" msgstr "Gateway ist nicht erreichbar" @@ -97,6 +101,10 @@ msgstr "" msgid "Nameserver(s) are not responsive" msgstr "Nameserver sind nicht ansprechbar" +#: umc/python/diagnostic/plugins/samba_tool_dbcheck.py:45 +msgid "No errors found." +msgstr "Keine Fehler gefunden." + #: umc/python/diagnostic/plugins/package_status.py:11 msgid "Package status corrupt" msgstr "Paketstatus korrupt" @@ -129,6 +137,10 @@ msgstr "" msgid "Proxy server failure" msgstr "Proxy-Server-Fehler" +#: umc/python/diagnostic/plugins/samba_tool_dbcheck.py:98 +msgid "Run `samba-tool dbcheck --fix --yes`" +msgstr "Führe `samba-tool dbcheck --fix --yes` aus" + #: umc/python/diagnostic/plugins/ssh_connection.py:16 msgid "SSH connection to UCS server failed!" msgstr "SSH-Verbindung zu anderem UCS Server fehlgeschlagen!" @@ -260,6 +272,26 @@ msgstr "" "dass Authentifikations-Zugangsdaten (falls existierend) korrekt sind und die " "ACL's des Proxy-Servers nicht verbieten, Anfragen an %s zu stellen." +#: umc/python/diagnostic/plugins/samba_tool_dbcheck.py:108 +msgid "You can run `samba-tool dbcheck --fix` to fix the issue." +msgstr "Sie können `samba-tool dbcheck --fix` ausführen um die Probleme zu beheben." + +#: umc/python/diagnostic/plugins/samba_tool_dbcheck.py:55 +msgid "`samba-tool dbcheck --fix --yes` failed." +msgstr "`samba-tool dbcheck --fix --yes` ist fehlgeschlagen." + +#: umc/python/diagnostic/plugins/samba_tool_dbcheck.py:57 +msgid "`samba-tool dbcheck --fix --yes` succeeded." +msgstr "`samba-tool dbcheck --fix --yes` war erfolgreich." + +#: umc/python/diagnostic/plugins/samba_tool_dbcheck.py:113 +msgid "`samba-tool dbcheck` found no problems with the local AD database." +msgstr "`samba-tool dbcheck` hat keine Probleme mit der lokalen AD Datenbank gefunden." + +#: umc/python/diagnostic/plugins/samba_tool_dbcheck.py:104 +msgid "`samba-tool dbcheck` returned a problem with the local AD database." +msgstr "`samba-tool dbcheck` fand Probleme mit der lokalen AD Datenbank." + #: umc/python/diagnostic/plugins/package_status.py:28 msgid "some" msgstr "einigen" --