]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Adding pp_lib/test_home_app.py and test-home
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 21 Mar 2017 15:21:14 +0000 (16:21 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 21 Mar 2017 15:21:14 +0000 (16:21 +0100)
pp_lib/test_home_app.py [new file with mode: 0644]
test-home [new file with mode: 0755]

diff --git a/pp_lib/test_home_app.py b/pp_lib/test_home_app.py
new file mode 100644 (file)
index 0000000..8fc25c2
--- /dev/null
@@ -0,0 +1,106 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@author: Frank Brehm
+@contact: frank.brehm@pixelpark.com
+@copyright: © 2017 by Frank Brehm, Berlin
+@summary: The module for the mk-home application object.
+"""
+from __future__ import absolute_import
+
+# Standard modules
+import sys
+import os
+import logging
+import logging.config
+import re
+import traceback
+import textwrap
+import pwd
+import copy
+
+# Third party modules
+import six
+
+# Own modules
+from .global_version import __version__ as __global_version__
+
+from .errors import FunctionNotImplementedError, PpAppError
+
+from .common import pp, terminal_can_colors, to_bytes, to_bool
+
+from .cfg_app import PpCfgAppError, PpConfigApplication
+
+__version__ = '0.1.1'
+LOG = logging.getLogger(__name__)
+
+
+# =============================================================================
+class PpTestHomeError(PpCfgAppError):
+    pass
+
+
+# =============================================================================
+class PpTestHomeApp(PpConfigApplication):
+    """
+    Class for the 'test-home' application to check for unnacessary home directories.
+    """
+
+    # /mnt/nfs
+    default_chroot_homedir = os.sep + os.path.join('mnt', 'nfs')
+    # /home
+    default_home_root = os.sep + 'home'
+
+    # /etc/pixelpark/exclude_homes
+    default_exlude_file = os.sep + os.path.join('etc', 'pixelpark', 'exclude_homes')
+
+    default_mail_recipients = [
+        'frank.brehm@pixelpark.com'
+    ]
+    default_mail_cc = [
+        'thomas.kotschok\@pixelpark.com',
+    ]
+
+    default_reply_to = 'frank.brehm@pixelpark.com'
+
+    # -------------------------------------------------------------------------
+    def __init__(self, appname=None, version=__version__):
+
+        self.chroot_homedir = self.default_chroot_homedir
+        self.home_root_abs = self.default_home_root
+        self.home_root_rel = os.path.relpath(self.home_root_abs, os.sep)
+
+        self.mail_recipients = copy.copy(self.default_mail_recipients)
+        self.mail_cc = copy.copy(self.default_mail_cc)
+        self.reply_to = self.default_reply_to
+
+        self.exclude_dirs = []
+        self.passwd_home_dirs = []
+
+        description = textwrap.dedent('''\
+            This scripts detects unnecessary home directories - without an
+            appropriate home directory in the passwd database and not excluded
+            in {!r}.
+            ''').strip().format(self.default_exlude_file)
+
+        super(PpTestHomeApp, self).__init__(
+            appname=appname, version=version, description=description,
+            cfg_stems='test-home'
+        )
+
+        self.initialized = True
+
+    # -------------------------------------------------------------------------
+    def _run(self):
+
+        LOG.info("Jetzt geht's los ...")
+
+# =============================================================================
+
+if __name__ == "__main__":
+
+    pass
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list
diff --git a/test-home b/test-home
new file mode 100755 (executable)
index 0000000..32eb03e
--- /dev/null
+++ b/test-home
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+
+# Standard modules
+import sys
+import os
+import logging
+import locale
+
+# own modules:
+cur_dir = os.getcwd()
+base_dir = cur_dir
+
+if sys.argv[0] != '' and sys.argv[0] != '-c':
+    cur_dir = os.path.dirname(sys.argv[0])
+if os.path.exists(os.path.join(cur_dir, 'pp_lib')):
+    sys.path.insert(0, os.path.abspath(cur_dir))
+
+from pp_lib.common import pp
+
+from pp_lib.test_home_app import PpTestHomeApp
+
+log = logging.getLogger(__name__)
+
+__author__ = 'Frank Brehm <frank.brehm@pixelpark.com>'
+__copyright__ = '(C) 2017 by Frank Brehm, Pixelpark GmbH, Berlin'
+
+appname = os.path.basename(sys.argv[0])
+
+locale.setlocale(locale.LC_ALL, '')
+
+app = PpTestHomeApp(appname=appname)
+app.initialized = True
+
+if app.verbose > 2:
+    print("{c}-Object:\n{a}".format(c=app.__class__.__name__, a=app))
+
+app()
+
+sys.exit(0)
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
+
+# vim: ts=4