Skip to content

Commit

Permalink
Merge pull request #212 from nemoload/config_dir
Browse files Browse the repository at this point in the history
Store wfuzz configuration according to XDG Base Directory Specification
  • Loading branch information
xmendez authored Aug 30, 2020
2 parents 4f22d29 + 08e5c8b commit 763d856
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/wfuzz/facade.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .helpers.file_func import get_home, get_path
from .helpers.file_func import get_home, get_path, get_config_dir
from .helpers.obj_factory import Singleton
from . import __version__ as version
from .externals.moduleman.registrant import MulRegistrant
Expand All @@ -17,7 +17,16 @@

class Settings(SettingsBase):
def get_config_file(self):
return os.path.join(get_home(check=True), "wfuzz.ini")
config_file = "wfuzz.ini"

config = os.path.join(get_config_dir(check=False), config_file)
legacy_config = os.path.join(get_home(check=False), config_file)

if os.path.exists(config):
return config
elif os.path.exists(legacy_config):
return legacy_config
return os.path.join(get_config_dir(check=True), config_file)

def set_defaults(self):
return dict(
Expand Down
12 changes: 10 additions & 2 deletions src/wfuzz/helpers/file_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ def get_filter_help_file():

return filter_help_text

def create_dir(dir_path):
if not os.path.exists(dir_path):
os.makedirs(dir_path)

def get_home(check=False, directory=None):
path = os.path.join(os.path.expanduser("~"), ".wfuzz")
if check:
if not os.path.exists(path):
os.makedirs(path)
create_dir(path)

return os.path.join(path, directory) if directory else path

def get_config_dir(check=False):
config_dir = os.environ.get('XDG_CONFIG_HOME') or os.path.join(os.path.expanduser("~"), ".config")
wfuzz_config_dir = os.path.join(config_dir, "wfuzz")
if check:
create_dir(wfuzz_config_dir)
return wfuzz_config_dir

def get_path(directory=None):
abspath = os.path.abspath(__file__)
Expand Down

0 comments on commit 763d856

Please sign in to comment.