Codebase list osrframework / 2a83a63
Improve the installation of config files Sophie Brun 6 years ago
5 changed file(s) with 104 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
0 #!/bin/sh
1
2 set -e
3
4 if [ "$1" = "configure" ] && [ -n "$2" ]; then
5 python /usr/lib/python2.7/dist-packages/osrframework/utils/upgrade_config.py
6 fi
7
8 #DEBHELPER#
0 --- /dev/null
1 +++ b/osrframework/utils/upgrade_config.py
2 @@ -0,0 +1,12 @@
3 +# !/usr/bin/python
4 +
5 +import os
6 +import shutil
7 +
8 +import osrframework.utils.configuration as configuration
9 +
10 +if __name__ == "__main__":
11 + if os.path.exists(configuration.getConfigPath()["appPath"]):
12 + for confdir in ["default", "plugins", "server", "transforms"]:
13 + shutil.rmtree(os.path.join(configuration.getConfigPath()["appPath"], confdir), True)
14 + configuration.initialize_config_files()
15 --- a/osrframework/utils/configuration.py
16 +++ b/osrframework/utils/configuration.py
17 @@ -40,8 +40,10 @@ def initialize_config_files():
18 for dirconf in ["default", "plugins", "server"]:
19 shutil.copytree(os.path.join('/etc/osrframework',dirconf), os.path.join(LOCAL_CONFIG_DIR, dirconf))
20
21 - # Create directory data
22 - os.mkdir(getConfigPath()["appPathData"])
23 + # Create directory data if it doesn't exist (we keep it at the
24 + # upgrade)
25 + if not os.path.exists(getConfigPath()["appPathData"]):
26 + os.mkdir(getConfigPath()["appPathData"])
27
28 # Create directory Transforms before copy *.py files
29 os.mkdir(LOCAL_CONFIG_TRANSFORMS_DIR)
0 Description: create real temporary directory
1 Don't create a ./tmp/* directory in the dir from where you run the
2 command. Create a real temporay directory using tempfile in Python.
3 Author: Sophie Brun <[email protected]>
4 Last-Update: 2017-09-19
5 ---
6 This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
7 --- a/osrframework/transforms/lib/configure_maltego.py
8 +++ b/osrframework/transforms/lib/configure_maltego.py
9 @@ -24,6 +24,7 @@ import os
10 import zipfile
11 import argparse
12 import shutil, errno
13 +import tempfile
14
15 import osrframework
16 import osrframework.utils.configuration as configuration
17 @@ -104,10 +105,12 @@ def zip(pathFolder=None):
18 zf.close()
19
20 # After everything, deleting the previously created folder
21 - try:
22 - shutil.rmtree(pathFolder)
23 - except:
24 - pass
25 + # folder is created in configureMaltego function / it's removed in
26 + # configureMaltego function too
27 + #try:
28 + # shutil.rmtree(pathFolder)
29 + #except:
30 + # pass
31
32 return filePath
33
34 @@ -118,7 +121,7 @@ def configureMaltego(transformsConfigFol
35 settingsFile = "osrframework-maltego-settings" + "_" + VERSION
36
37 # Defining the full path to the folder in which the configuration files will be created
38 - dst=os.path.join("./", "tmp", settingsFile)
39 + dst=os.path.join(tempfile.mkdtemp(), settingsFile)
40
41 # copying anything in the config folder
42 copyAnything(src=base, dst=dst)
43 @@ -145,8 +148,8 @@ def configureMaltego(transformsConfigFol
44 print "Moving the .mtz file to the backup folder: " + os.path.join(backupPath, fileName)
45 shutil.copy2(filePath, backupPath)
46
47 - # Remove tmp files.
48 - shutil.rmtree(os.path.join("./", "tmp"))
49 + # Remove tmp files and directories
50 + shutil.rmtree(dst)
51
52 if __name__ == "__main__":
53 parser = argparse.ArgumentParser(description='configure_maltego.py - A function to automatically generate Maltego configuration files.', prog='configure_maltego.py', epilog="", add_help=False)
88 This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
99 --- a/osrframework/utils/configuration.py
1010 +++ b/osrframework/utils/configuration.py
11 @@ -22,8 +22,54 @@
11 @@ -22,8 +22,52 @@
1212
1313 import os
1414 import sys
1919 +
2020 +def initialize_config_files():
2121 + """
22 + Function to create and initialize the configration files and
22 + Function to create and initialize the configuration files and
2323 + directories.
2424 + """
2525 + LOCAL_CONFIG_DIR = getConfigPath()["appPath"]
2626 + LOCAL_CONFIG_TRANSFORMS_DIR = getConfigPath()["appPathTransforms"]
2727 + INSTALL_PATH = '/usr/lib/python2.7/dist-packages/osrframework'
2828 +
29 + if os.path.exists(LOCAL_CONFIG_DIR):
30 + return
31 +
3229 + # Copy default config file into osrframework local config
33 + shutil.copytree('/etc/osrframework', LOCAL_CONFIG_DIR)
30 + for dirconf in ["default", "plugins", "server"]:
31 + shutil.copytree(os.path.join('/etc/osrframework',dirconf), os.path.join(LOCAL_CONFIG_DIR, dirconf))
3432 +
3533 + # Create directory data
3634 + os.mkdir(getConfigPath()["appPathData"])
4543 + shutil.copy((os.path.join(INSTALL_PATH, f)), LOCAL_CONFIG_TRANSFORMS_DIR)
4644 +
4745 + # Copy default config files for the user
48 + for f in ["accounts.cfg", "api_keys.cfg", "browser.cfg", "general.cfg"]:
46 + for f in ["browser.cfg", "general.cfg"]:
4947 + shutil.copy((os.path.join(getConfigPath()["appPathDefaults"], f)),LOCAL_CONFIG_DIR)
5048 +
5149 + # Configure maltego
6361 def changePermissionsRecursively(path, uid, gid):
6462 """
6563 Function to recursively change the user id and group id. It sets 700
66 @@ -84,9 +130,10 @@ def getConfigPath(configFileName = None)
64 @@ -84,9 +128,10 @@ def getConfigPath(configFileName = None)
6765 }
6866
6967 # Creating them if they don't exist
7775
7876 return paths
7977
80 @@ -100,6 +147,7 @@ def returnListOfConfigurationValues(util
78 @@ -100,6 +145,8 @@ def returnListOfConfigurationValues(util
8179 '''
8280
8381 VALUES = {}
84 + initialize_config_files()
82 + if not os.path.exists(getConfigPath()["appPath"]):
83 + initialize_config_files()
8584
8685 # If a api_keys.cfg has not been found, creating it by copying from default
8786 configPath = os.path.join(getConfigPath()["appPath"], "general.cfg")
44 upgrade-installation.patch
55 fix-exit-function.patch
66 initalize-config.patch
7 add-script-config-upgrade.patch
78 drop-check-updates.patch
9 create-real-temporary-dir.patch