Codebase list osrframework / db31709 debian / patches / initalize-config.patch
db31709

Tree @db31709 (Download .tar.gz)

initalize-config.patch @db31709raw · history · blame

From: Sophie Brun <[email protected]>
Date: Thu, 23 Jan 2020 10:21:00 +0100
Subject: Initialize the config directory and files

Last-Update: 2020-01-23

Upstream creates and initializes the ~/.config/OSRFramework in the
setup.py. We disable this for Kali and create a function
initialize_config_files to manage the creation and installation of all
the required files.
---
 osrframework/utils/configuration.py | 41 ++++++++++++++++++++++++++++++++++---
 1 file changed, 38 insertions(+), 3 deletions(-)

diff --git a/osrframework/utils/configuration.py b/osrframework/utils/configuration.py
index a75a21a..afc8b5e 100644
--- a/osrframework/utils/configuration.py
+++ b/osrframework/utils/configuration.py
@@ -19,12 +19,44 @@
 
 import os
 import sys
+import shutil
+import glob
 
 from configparser import ConfigParser
 
 import osrframework.utils.errors as errors
 
 
+def initialize_config_files():
+    """
+        Function to create and initialize the configuration files and
+        directories.
+    """
+    LOCAL_CONFIG_DIR = get_config_path()["appPath"]
+#    LOCAL_CONFIG_TRANSFORMS_DIR = get_config_path()["appPathTransforms"]
+    INSTALL_PATH = '/usr/lib/python3/dist-packages/osrframework'
+
+    # Copy default config file into osrframework local config
+    for dirconf in ["default", "plugins"]:
+        shutil.copytree(os.path.join('/etc/osrframework',dirconf), os.path.join(LOCAL_CONFIG_DIR, dirconf))
+
+    # Create directory data
+    os.mkdir(get_config_path()["appPathData"])
+
+    # Create directory Transforms before copy *.py files
+#    os.mkdir(LOCAL_CONFIG_TRANSFORMS_DIR)
+
+    # Copy *.py files in transforms directory
+#    for f in glob.glob(os.path.join(INSTALL_PATH, "transforms/[a-z]*.py")):
+#        shutil.copy(f, LOCAL_CONFIG_TRANSFORMS_DIR)
+#    for f in ["alias_generator.py", "entify.py", "phonefy.py", "searchfy.py", "mailfy.py", "usufy.py", "domainfy.py", "enumerate-profiles.py"]:
+#        shutil.copy((os.path.join(INSTALL_PATH, f)), LOCAL_CONFIG_TRANSFORMS_DIR)
+
+    # Copy default config files for the user
+    for f in ["browser.cfg", "general.cfg"]:
+        shutil.copy((os.path.join(get_config_path()["appPathDefaults"], f)),LOCAL_CONFIG_DIR)
+
+
 def change_permissions_recursively(path, uid, gid):
     """Function to recursively change the user id and group id
 
@@ -86,9 +118,10 @@ def get_config_path(config_file_name=None):
     }
 
     # Creating them if they don't exist
-    for path in paths.keys():
-        if not os.path.exists(paths[path]):
-            os.makedirs(paths[path])
+#Don't create them in Kali: initialize_config_files() will create them
+#    for path in paths.keys():
+#        if not os.path.exists(paths[path]):
+#            os.makedirs(paths[path])
 
     return paths
 
@@ -105,6 +138,8 @@ def get_configuration_values_for(util):
     """
 
     VALUES = {}
+    if not os.path.exists(get_config_path()["appPath"]):
+        initialize_config_files()
 
     # If a api_keys.cfg has not been found, creating it by copying from default
     configPath = os.path.join(get_config_path()["appPath"], "general.cfg")