|
31 |
# /usr/share/common-licenses/AGPL-3; if not, see |
31 |
# /usr/share/common-licenses/AGPL-3; if not, see |
32 |
# <http://www.gnu.org/licenses/>. |
32 |
# <http://www.gnu.org/licenses/>. |
33 |
|
33 |
|
34 |
from subprocess import Popen, PIPE, STDOUT |
34 |
import ldap |
|
|
35 |
import socket |
36 |
import subprocess |
35 |
|
37 |
|
36 |
from univention.management.console.modules.diagnostic import Critical |
38 |
import univention.uldap |
|
|
39 |
from univention.management.console.modules.diagnostic import Critical, ProblemFixed |
37 |
|
40 |
|
38 |
from univention.lib.i18n import Translation |
41 |
from univention.lib.i18n import Translation |
39 |
_ = Translation('univention-management-console-module-diagnostic').translate |
42 |
_ = Translation('univention-management-console-module-diagnostic').translate |
|
42 |
description = _('No errors found.'), |
45 |
description = _('No errors found.'), |
43 |
|
46 |
|
44 |
|
47 |
|
45 |
def run(): |
48 |
def run_samba_tool_dbcheck_fix(): |
46 |
process = Popen(['samba-tool', 'dbcheck'], stdout=PIPE, stderr=STDOUT) |
49 |
if not is_service_active('Samba 4'): |
47 |
stdout, stderr = process.communicate() |
50 |
return |
48 |
if process.returncode: |
51 |
|
49 |
raise Critical('\n'.join([description, '', stdout])) |
52 |
cmd = ['samba-tool', 'dbcheck', '--fix', '--yes'] |
|
|
53 |
(success, output) = run_with_output(cmd) |
54 |
if success: |
55 |
fix_log = [_('`samba-tool dbcheck --fix --yes` failed.')] |
56 |
else: |
57 |
fix_log = [_('`samba-tool dbcheck --fix --yes` succeeded.')] |
58 |
fix_log.append(output) |
59 |
run(rerun=True, fix_log='\n'.join(fix_log)) |
60 |
|
61 |
|
62 |
actions = { |
63 |
'run_samba_tool_dbcheck_fix': run_samba_tool_dbcheck_fix |
64 |
} |
65 |
|
66 |
|
67 |
def is_service_active(service): |
68 |
lo = univention.uldap.getMachineConnection() |
69 |
raw_filter = '(&(univentionService=%s)(cn=%s))' |
70 |
filter_expr = ldap.filter.filter_format(raw_filter, (service, socket.gethostname())) |
71 |
for (dn, _attr) in lo.search(filter_expr, attr=['cn']): |
72 |
if dn is not None: |
73 |
return True |
74 |
return False |
75 |
|
76 |
|
77 |
def run_with_output(cmd): |
78 |
output = list() |
79 |
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
80 |
(stdout, stderr) = process.communicate() |
81 |
if stdout: |
82 |
output.append('\nSTDOUT:\n{}'.format(stdout)) |
83 |
if stderr: |
84 |
output.append('\nSTDERR:\n{}'.format(stderr)) |
85 |
return (process.returncode == 0, '\n'.join(output)) |
86 |
|
87 |
|
88 |
def run(rerun=False, fix_log=''): |
89 |
if not is_service_active('Samba 4'): |
90 |
return |
91 |
|
92 |
error_descriptions = list() |
93 |
if rerun and fix_log: |
94 |
error_descriptions.append(fix_log) |
95 |
|
96 |
buttons = [{ |
97 |
'action': 'run_samba_tool_dbcheck_fix', |
98 |
'label': _('Run `samba-tool dbcheck --fix --yes`'), |
99 |
}] |
100 |
|
101 |
cmd = ['samba-tool', 'dbcheck'] |
102 |
(success, output) = run_with_output(cmd) |
103 |
if not success: |
104 |
error = _('`samba-tool dbcheck` returned a problem with the local AD database.') |
105 |
error_descriptions.append(error) |
106 |
error_descriptions.append(output) |
107 |
if not rerun: |
108 |
fix = _('You can run `samba-tool dbcheck --fix` to fix the issue.') |
109 |
error_descriptions.append(fix) |
110 |
raise Critical(description='\n'.join(error_descriptions), buttons=buttons) |
111 |
|
112 |
if rerun: |
113 |
fixed = _('`samba-tool dbcheck` found no problems with the local AD database.') |
114 |
error_descriptions.append(fixed) |
115 |
error_descriptions.append(output) |
116 |
raise ProblemFixed(description='\n'.join(error_descriptions)) |
50 |
|
117 |
|
51 |
|
118 |
|
52 |
if __name__ == '__main__': |
119 |
if __name__ == '__main__': |
53 |
- |
|
|
54 |
samba_tool_dbcheck.py (po) |
120 |
samba_tool_dbcheck.py (po) |
55 |
-- |
|
|
56 |
.../umc/python/diagnostic/de.po | 36 ++++++++++++++++++++-- |
121 |
.../umc/python/diagnostic/de.po | 36 ++++++++++++++++++++-- |
57 |
1 file changed, 34 insertions(+), 2 deletions(-) |
122 |
1 file changed, 34 insertions(+), 2 deletions(-) |