Improve the installation of config files
Sophie Brun
6 years ago
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) |
8 | 8 | This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ |
9 | 9 | --- a/osrframework/utils/configuration.py |
10 | 10 | +++ b/osrframework/utils/configuration.py |
11 | @@ -22,8 +22,54 @@ | |
11 | @@ -22,8 +22,52 @@ | |
12 | 12 | |
13 | 13 | import os |
14 | 14 | import sys |
19 | 19 | + |
20 | 20 | +def initialize_config_files(): |
21 | 21 | + """ |
22 | + Function to create and initialize the configration files and | |
22 | + Function to create and initialize the configuration files and | |
23 | 23 | + directories. |
24 | 24 | + """ |
25 | 25 | + LOCAL_CONFIG_DIR = getConfigPath()["appPath"] |
26 | 26 | + LOCAL_CONFIG_TRANSFORMS_DIR = getConfigPath()["appPathTransforms"] |
27 | 27 | + INSTALL_PATH = '/usr/lib/python2.7/dist-packages/osrframework' |
28 | 28 | + |
29 | + if os.path.exists(LOCAL_CONFIG_DIR): | |
30 | + return | |
31 | + | |
32 | 29 | + # 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)) | |
34 | 32 | + |
35 | 33 | + # Create directory data |
36 | 34 | + os.mkdir(getConfigPath()["appPathData"]) |
45 | 43 | + shutil.copy((os.path.join(INSTALL_PATH, f)), LOCAL_CONFIG_TRANSFORMS_DIR) |
46 | 44 | + |
47 | 45 | + # 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"]: | |
49 | 47 | + shutil.copy((os.path.join(getConfigPath()["appPathDefaults"], f)),LOCAL_CONFIG_DIR) |
50 | 48 | + |
51 | 49 | + # Configure maltego |
63 | 61 | def changePermissionsRecursively(path, uid, gid): |
64 | 62 | """ |
65 | 63 | 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) | |
67 | 65 | } |
68 | 66 | |
69 | 67 | # Creating them if they don't exist |
77 | 75 | |
78 | 76 | return paths |
79 | 77 | |
80 | @@ -100,6 +147,7 @@ def returnListOfConfigurationValues(util | |
78 | @@ -100,6 +145,8 @@ def returnListOfConfigurationValues(util | |
81 | 79 | ''' |
82 | 80 | |
83 | 81 | VALUES = {} |
84 | + initialize_config_files() | |
82 | + if not os.path.exists(getConfigPath()["appPath"]): | |
83 | + initialize_config_files() | |
85 | 84 | |
86 | 85 | # If a api_keys.cfg has not been found, creating it by copying from default |
87 | 86 | configPath = os.path.join(getConfigPath()["appPath"], "general.cfg") |