Skip to content

Commit

Permalink
Path-related refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamJoan committed Aug 25, 2015
1 parent 1098e49 commit 29e95aa
Show file tree
Hide file tree
Showing 24 changed files with 103 additions and 104 deletions.
16 changes: 3 additions & 13 deletions droopescan
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
#!/usr/bin/env python
import dscan, sys, os
import sys, os
from dscan import droopescan

prev_cwd = os.getcwd()

p = os.path.dirname(dscan.__file__)
sys.path.append(p)
os.chdir(p)

import droopescan
if os.getenv('DROOPESCAN_PROFILE'):
import cProfile
cProfile.run("droopescan.main(prev_cwd)", sort="cumtime")
else:
droopescan.main(prev_cwd)
droopescan.main()
2 changes: 2 additions & 0 deletions dscan/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import os
PWD = os.path.dirname(__file__) + "/"
8 changes: 4 additions & 4 deletions dscan/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import print_function

from common.enum import Enumerate, ScanningMethod, colors, ValidOutputs, Verb
from common.functions import base_url, dict_combine, enum_list, file_len, in_enum, \
from dscan.common.enum import Enumerate, ScanningMethod, colors, ValidOutputs, Verb
from dscan.common.functions import base_url, dict_combine, enum_list, file_len, in_enum, \
is_string, md5_file, scan_http_status, strip_letters, strip_whitespace, \
template, repair_url, version_gt
from common.output import JsonOutput, ProgressBar, SmartFormatter, \
from dscan.common.output import JsonOutput, ProgressBar, SmartFormatter, \
StandardOutput, RequestsLogger
from common.versions import VersionsFile
from dscan.common.versions import VersionsFile
import logging

logging.basicConfig(level=logging.WARN)
Expand Down
10 changes: 6 additions & 4 deletions dscan/common/functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import print_function
from common.enum import colors, ScanningMethod
from dscan.common.enum import colors, ScanningMethod
from requests.exceptions import ConnectionError, ReadTimeout, ConnectTimeout, \
TooManyRedirects
import dscan
import hashlib
import pystache
import re
Expand Down Expand Up @@ -63,10 +64,11 @@ def scan_http_status(scanning_method):

def template(template_file, variables={}):
variables.update(colors)
f = open('common/template/' + template_file, 'r')
f = open(dscan.PWD + 'common/template/' + template_file, 'r')
template = f.read()

return pystache.render(template, variables)
renderer = pystache.Renderer(search_dirs=dscan.PWD)
return renderer.render(template, variables)

def strip_whitespace(s):
return re.sub(r'\s+', ' ', s)
Expand All @@ -81,7 +83,7 @@ def dict_combine(x, y):

def file_len(fname):
i = 0
with open(fname) as f:
with open(dscan.PWD + fname) as f:
for l in f:
i += 1

Expand Down
4 changes: 2 additions & 2 deletions dscan/common/output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import print_function
from common.functions import template, strip_whitespace
from common.enum import colors
from dscan.common.functions import template, strip_whitespace
from dscan.common.enum import colors
import argparse
import hashlib
import json
Expand Down
4 changes: 2 additions & 2 deletions dscan/common/plugins_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cement.core import handler
from common import file_len, VersionsFile
from plugins.internal.base_plugin import BasePlugin
from dscan.common import file_len, VersionsFile
from dscan.plugins.internal.base_plugin import BasePlugin
import subprocess

def plugins_get():
Expand Down
5 changes: 3 additions & 2 deletions dscan/common/release_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import print_function
from distutils.util import strtobool
import common.functions as f
import dscan.common.functions as f
import dscan
import os.path
import subprocess
import sys
Expand Down Expand Up @@ -115,7 +116,7 @@ def check_pypirc():
f.error('File "%s" does not exist.' % pypirc)

def read_first_line(file):
with open(file, 'r') as f:
with open(dscan.PWD + file, 'r') as f:
first_line = f.readline()

return first_line.strip()
Expand Down
12 changes: 6 additions & 6 deletions dscan/common/update_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
except:
pass

from common.functions import version_gt
from common.versions import VersionsFile
from dscan.common.functions import version_gt
from dscan.common.versions import VersionsFile
from datetime import datetime, timedelta
import common.functions
import common.versions
import dscan.common.functions as f
import dscan.common.versions as v
import os
import os.path
import requests
Expand Down Expand Up @@ -94,7 +94,7 @@ def github_repo_new(repo_url, plugin_name, versions_file, update_majors):
@return: a tuple containing (GitRepo, VersionsFile, GitRepo.tags_newer())
"""
gr = github_repo(repo_url, plugin_name)
vf = common.versions.VersionsFile(versions_file)
vf = v.VersionsFile(versions_file)
new_tags = gr.tags_newer(vf, update_majors)

return gr, vf, new_tags
Expand All @@ -110,7 +110,7 @@ def hashes_get(versions_file, base_path):
result = {}
for f in files:
try:
result[f] = common.functions.md5_file(base_path + f)
result[f] = f.md5_file(base_path + f)
except IOError:
# Not all files exist for all versions.
pass
Expand Down
8 changes: 6 additions & 2 deletions dscan/common/versions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import print_function
from dscan.common.functions import version_gt
import dscan
import pystache
import xml.etree.ElementTree as ET
from common.functions import version_gt

class VersionsFile():
et = None
Expand All @@ -10,7 +11,10 @@ class VersionsFile():
changelog_xpath = './files/changelog'

def __init__(self, xml_file):
self.et = ET.parse(xml_file)
"""
@param xml_file: path to the XML file relative to dscan.PWD
"""
self.et = ET.parse(dscan.PWD + xml_file)
self.root = self.et.getroot()

def files_get(self):
Expand Down
21 changes: 9 additions & 12 deletions dscan/droopescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from __future__ import print_function
from cement.core import backend, foundation, controller, handler
from cement.utils.misc import init_defaults
from common.functions import template, version_get
from plugins import Scan
import common, sys, signal
import droopescan
from dscan.common.functions import template, version_get
from dscan import common
from dscan.plugins import Scan
import dscan
import os
import sys

class DroopeScanBase(controller.CementBaseController):
class Meta:
Expand All @@ -34,15 +35,11 @@ class Meta:
label = 'droopescan'
base_controller = DroopeScanBase
exit_on_close = False
framework_logging = False
#framework_logging = False

def main(pwd):
defaults = init_defaults('DroopeScan', 'general')
defaults['general']['pwd'] = pwd

ds = DroopeScan("DroopeScan", plugin_config_dir="./plugins.d",
plugin_dir="./plugins", catch_signals=None,
config_defaults=defaults)
def main():
ds = DroopeScan("DroopeScan", plugin_config_dir=dscan.PWD + "./plugins.d",
plugin_dir=dscan.PWD + "./plugins", catch_signals=None)

handler.register(Scan)

Expand Down
6 changes: 3 additions & 3 deletions dscan/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from plugins.internal.scan import Scan
from plugins.internal.base_plugin import BasePlugin
from plugins.internal.human_base_plugin import HumanBasePlugin
from dscan.plugins.internal.scan import Scan
from dscan.plugins.internal.base_plugin import BasePlugin
from dscan.plugins.internal.human_base_plugin import HumanBasePlugin
8 changes: 4 additions & 4 deletions dscan/plugins/drupal.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from cement.core import handler, controller
from plugins import BasePlugin
from common.update_api import GitRepo
import common.update_api as ua
import common.versions
from dscan.plugins import BasePlugin
from dscan.common.update_api import GitRepo
import dscan.common.update_api as ua
import dscan.common.versions

class Drupal(BasePlugin):

Expand Down
2 changes: 1 addition & 1 deletion dscan/plugins/example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from cement.core import handler, controller
from plugins import BasePlugin
from dscan.plugins import BasePlugin
import common

class Example(BasePlugin):
Expand Down
2 changes: 1 addition & 1 deletion dscan/plugins/internal/base_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import print_function
from plugins.internal.base_plugin_internal import BasePluginInternal
from dscan.plugins.internal.base_plugin_internal import BasePluginInternal

class BasePlugin(BasePluginInternal):
'''
Expand Down
23 changes: 12 additions & 11 deletions dscan/plugins/internal/base_plugin_internal.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from __future__ import print_function
from cement.core import handler, controller
from copy import deepcopy
from common import ScanningMethod, StandardOutput, JsonOutput, \
from dscan.common import ScanningMethod, StandardOutput, JsonOutput, \
VersionsFile, RequestsLogger
from common import template, enum_list, dict_combine, base_url, file_len
from common.exceptions import FileEmptyException, CannotResumeException
from common.output import ProgressBar
from common.http import BlockAll
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from dscan.common.exceptions import FileEmptyException, CannotResumeException
from dscan.common.http import BlockAll
from dscan.common import template, enum_list, dict_combine, base_url, file_len
from dscan.common.output import ProgressBar
from dscan import common
from functools import partial
from os.path import dirname
from requests import Session
from functools import partial
import common
import common.functions as f
import dscan
import dscan.common.functions as f
import hashlib
import os
import re
Expand Down Expand Up @@ -87,7 +88,7 @@ def _threads(self, pargs):
return threads, threads_identify, threads_scan, threads_enumerate

def _options(self, pargs):
pwd = self.app.config.get('general', 'pwd')
pwd = os.getcwd()
if pargs.url_file != None:
url_file = self._path(pargs.url_file, pwd)
else:
Expand Down Expand Up @@ -569,7 +570,7 @@ def _error_determine_scanning(self, url, folder_resp, ok_200):

def plugins_get(self, amount=100000):
amount = int(amount)
with open(self.plugins_file) as f:
with open(dscan.PWD + self.plugins_file) as f:
i = 0
for plugin in f:
if i >= amount:
Expand All @@ -579,7 +580,7 @@ def plugins_get(self, amount=100000):

def themes_get(self, amount=100000):
amount = int(amount)
with open(self.themes_file) as f:
with open(dscan.PWD + self.themes_file) as f:
i = 0
for theme in f:
if i>= amount:
Expand Down
4 changes: 2 additions & 2 deletions dscan/plugins/internal/human_base_plugin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import print_function
from cement.core import handler, controller
from distutils.util import strtobool
import common.functions
import dscan.common.functions as f
import sys

class HumanBasePlugin(controller.CementBaseController):
def error(self, *args, **kwargs):
common.functions.error(*args, **kwargs)
f.error(*args, **kwargs)

def msg(self, msg, end='\n'):
print(msg, end=end)
21 changes: 11 additions & 10 deletions dscan/plugins/internal/scan.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from __future__ import print_function
from cement.core import controller
from collections import OrderedDict
from common.functions import template
from common.exceptions import CannotResumeException
from common import template
from concurrent.futures import ThreadPoolExecutor, as_completed
from copy import deepcopy
from plugins.internal.base_plugin import BasePlugin
from plugins.internal.base_plugin_internal import BasePluginInternal
import common
import common.functions as f
import common.plugins_util as pu
import common.versions as v
import gc
from datetime import datetime
from dscan.common.exceptions import CannotResumeException
from dscan.common.functions import template
from dscan.common import template
from dscan import common
from dscan.plugins.internal.base_plugin import BasePlugin
from dscan.plugins.internal.base_plugin_internal import BasePluginInternal
import dscan
import dscan.common.functions as f
import dscan.common.plugins_util as pu
import dscan.common.versions as v
import gc

class Scan(BasePlugin):

Expand Down
8 changes: 4 additions & 4 deletions dscan/plugins/joomla.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from cement.core import handler, controller
from common.update_api import GitRepo
from plugins import BasePlugin
import common.update_api as ua
import common.versions
from dscan.common.update_api import GitRepo
from dscan.plugins import BasePlugin
import dscan.common.update_api as ua
import dscan.common.versions

class Joomla(BasePlugin):
can_enumerate_plugins = False
Expand Down
8 changes: 4 additions & 4 deletions dscan/plugins/release.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from cement.core import handler, controller
from common import template
from common.plugins_util import Plugin, plugins_get
from plugins import HumanBasePlugin
from dscan.common import template
from dscan.common.plugins_util import Plugin, plugins_get
from dscan.plugins import HumanBasePlugin
from subprocess import call, check_output
import common.release_api as ra
import dscan.common.release_api as ra
import re
import sys, os

Expand Down
6 changes: 3 additions & 3 deletions dscan/plugins/silverstripe.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from cement.core import handler, controller
from plugins import BasePlugin
from concurrent.futures import ThreadPoolExecutor
from dscan import common
from dscan.plugins import BasePlugin
from requests.exceptions import ConnectionError
import common
import common.update_api as ua
import dscan.common.update_api as ua
import re
import requests
import sys
Expand Down
6 changes: 3 additions & 3 deletions dscan/plugins/stats.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from cement.core import handler, controller
from common.plugins_util import Plugin, plugins_get
from common.functions import version_get
from common import template
from dscan.common.plugins_util import Plugin, plugins_get
from dscan.common.functions import version_get
from dscan.common import template

class Stats(controller.CementBaseController):

Expand Down
Loading

0 comments on commit 29e95aa

Please sign in to comment.