Skip to content

Commit

Permalink
[REDESIGN] Add interpreter version checker
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav WEB committed Jan 11, 2017
1 parent 6efc3b2 commit 4487f64
Show file tree
Hide file tree
Showing 12 changed files with 26,431 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ logs/
opendoor.egg-info/
/dist/
/syslog/exceptions.log
/tmp/
6 changes: 6 additions & 0 deletions src/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def __init__(self):
"""

try :

interpreter = package.check_interpreter()

if True != interpreter:
raise SrcError(tpl.error(key='unsupported', actual=interpreter.get('actual'), expected=interpreter.get('expected')))

self.ioargs = args().get_arguments()
except LibError as e:
raise SrcError(tpl.error(e.message))
Expand Down
21 changes: 18 additions & 3 deletions src/core/helper/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,36 @@
Development Team: Stanislav Menshov
"""

from distutils.version import LooseVersion
from distutils.version import LooseVersion, StrictVersion

class Helper:
"""Helper class"""

@staticmethod
def is_less(arg1, arg2):
"""
Compare two numbers
Compare two numbers (< less)
:param int arg1:
:param int arg2:
:return: bool
"""
if LooseVersion(arg1) < LooseVersion(arg2):
if StrictVersion(arg1) < StrictVersion(arg2):
return True
else:
return False

@staticmethod
def is_more(arg1, arg2):
"""
Compare two numbers (more >)
:param int arg1:
:param int arg2:
:return: bool
"""

if StrictVersion(arg1) > StrictVersion(arg2):
return True
else:
return False
Expand Down
8 changes: 5 additions & 3 deletions src/core/system/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ def execute(command):
try:
pr = subprocess.Popen(command, cwd=os.getcwd(),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

(out, error) = pr.communicate()
return (out, error)

except subprocess.CalledProcessError as e:
if error:
raise OSError(error.strip())

return out
except (subprocess.CalledProcessError, OSError) as e:
raise SystemError(e)
14 changes: 14 additions & 0 deletions src/core/system/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""

import sys
import platform

class System:
"""System class"""
Expand Down Expand Up @@ -55,4 +56,17 @@ def writeln(msg):

sys.stdout.write('{0}\n'.format(msg))

@staticmethod
def version():
"""
Interpreter version
:return: string
"""

version = platform.python_version().split(".")

return "{0}.{1}".format(version[0], version[1])



3 changes: 1 addition & 2 deletions src/lib/browser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ def _process(self):
"""

if self._total_lines() == self.count_in_queue():
tpl.info("\r")
tpl.info(key='scanning', host=self._host)
# self.join_to_queue()
else:
self._debug_progress(self.count_in_queue(), self._total_lines())
pass
pass
2 changes: 2 additions & 0 deletions src/lib/package/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Config:
'cvsupdate' : '/usr/bin/git pull origin master',
'cvslog' : '/usr/bin/git log --oneline -n 1',
'cfg' : 'setup.cfg',
'required_version': '2.7',
'examples' : """
Examples:
Expand All @@ -37,6 +38,7 @@ class Config:
python ./opendoor.py --host "http://joomla-ua.org" --threads 10 --proxy
python ./opendoor.py --host "https://joomla-ua.org" --threads 10 --delay 10
python ./opendoor.py --host "http://joomla-ua.org" --threads 10 --delay 10 --rest 10
python ./opendoor.py --host "http://joomla-ua.org" --random-list --threads 10 --delay 10 --rest 10
python ./opendoor.py --host "https://joomla-ua.org" --threads 10 --delay 10 --rest 10 --debug 1
python ./opendoor.py --host "http://joomla-ua.org" --threads 10 --delay 10 --rest 10 --debug 1 --log
""",
Expand Down
52 changes: 37 additions & 15 deletions src/lib/package/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Development Team: Stanislav Menshov
"""

from src.core import process, filesystem, helper
from src.core import process, filesystem, helper, sys
from src.core import SystemError, FileSystemError
from src.lib import tpl

Expand All @@ -28,6 +28,28 @@ class Package:

remote_version = None

@staticmethod
def check_interpreter():
"""
Get interpreter version
:return: dict or bool
"""

expected_version = Config.params.get('required_version')
actual_version = sys.version()

if True is helper.is_less(expected_version, actual_version)\
or True is helper.is_more(expected_version, actual_version):

return {
'status' : False,
'actual' : actual_version,
'expected' : expected_version
}
else:
return True

@staticmethod
def examples():
"""
Expand All @@ -36,7 +58,7 @@ def examples():
:return: None
"""

tpl.message(Config.params['examples'])
tpl.message(Config.params.get('examples'))

@staticmethod
def banner():
Expand All @@ -49,7 +71,7 @@ def banner():

try:

banner = Config.params['banner'].format(
banner = Config.params.get('banner').format(
tpl.line('Directories: {0}'.format(Package.__directories_count()), color='blue'),
tpl.line('Subdomains: {0}'.format(Package.__subdomains_count()), color='blue'),
tpl.line('Browsers: {0}'.format(Package.__browsers_count()), color='blue'),
Expand All @@ -71,7 +93,7 @@ def version():

try:

version = Config.params['version'].format(
version = Config.params.get('version').format(
Package.__app_name(),
Package.__current_version(),
Package.__remote_version(),
Expand All @@ -93,11 +115,11 @@ def update():
"""

try:
status = process.execute(Config.params['cvsupdate'])
status = process.execute(Config.params.get('cvsupdate'))
upd_status = tpl.line(status[0], color='green')
upd_reason = tpl.line(status[1], color='black')

banner = Config.params['update'].format(
banner = Config.params.get('update').format(
status=upd_status,
reasons=upd_reason)

Expand All @@ -116,7 +138,7 @@ def local_version():
"""

try :
config = filesystem.readcfg(Config.params['cfg'])
config = filesystem.readcfg(Config.params.get('cfg'))
return config.get('info', 'version')
except FileSystemError as e:
raise LibError(e)
Expand All @@ -131,7 +153,7 @@ def __app_name():
"""

try :
config = filesystem.readcfg(Config.params['cfg'])
config = filesystem.readcfg(Config.params.get('cfg'))
return config.get('info', 'name')
except FileSystemError as e:
raise LibError(e)
Expand All @@ -148,7 +170,7 @@ def __remote_version():
if None is Package.remote_version:

try:
config = filesystem.readcfg(Config.params['cfg'])
config = filesystem.readcfg(Config.params.get('cfg'))
request_uri = config.get('info', 'setup')
result = process.execute('curl -sb GET {uri}'.format(uri=request_uri))
raw = filesystem.readraw(result[0])
Expand Down Expand Up @@ -191,7 +213,7 @@ def __repo():
"""

try :
config = filesystem.readcfg(Config.params['cfg'])
config = filesystem.readcfg(Config.params.get('cfg'))
return config.get('info', 'repository')
except FileSystemError as e:
raise LibError(e)
Expand All @@ -206,7 +228,7 @@ def __license():
"""

try :
config = filesystem.readcfg(Config.params['cfg'])
config = filesystem.readcfg(Config.params.get('cfg'))
return config.get('info', 'license')
except FileSystemError as e:
raise LibError(e)
Expand All @@ -221,7 +243,7 @@ def __directories_count():
"""

try :
config = filesystem.readcfg(Config.params['cfg'])
config = filesystem.readcfg(Config.params.get('cfg'))
filename = config.get('opendoor', 'directories')
count = filesystem.read(filename).__len__()
return count
Expand All @@ -239,7 +261,7 @@ def __subdomains_count():
"""

try :
config = filesystem.readcfg(Config.params['cfg'])
config = filesystem.readcfg(Config.params.get('cfg'))
filename = config.get('opendoor', 'subdomains')
count = filesystem.read(filename).__len__()

Expand All @@ -258,7 +280,7 @@ def __browsers_count():
"""

try :
config = filesystem.readcfg(Config.params['cfg'])
config = filesystem.readcfg(Config.params.get('cfg'))
filename = config.get('opendoor', 'useragents')
count = filesystem.read(filename).__len__()

Expand All @@ -277,7 +299,7 @@ def __proxies_count():
"""

try :
config = filesystem.readcfg(Config.params['cfg'])
config = filesystem.readcfg(Config.params.get('cfg'))
filename = config.get('opendoor', 'proxies')
count = filesystem.read(filename).__len__()

Expand Down
2 changes: 1 addition & 1 deletion src/lib/reader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .config import Config
from src.core import process
from src.core import filesystem
from src.core import FileSystemError
from src.core import FileSystemError , SystemError
from ...lib.exceptions import LibError

class Reader():
Expand Down
1 change: 1 addition & 0 deletions src/lib/tpl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Config:
"""Config class"""

templates = {
'unsupported': 'Your version v {actual} is not supported by this application. Please consider v{expected}',
'abort' : 'Session canceled',
'use_log' : 'Use --log param to store your scan results',
'logged' : 'The {host} has been stored. Press ENTER to rescan or CTRL+C to exit: ',
Expand Down
4 changes: 3 additions & 1 deletion src/lib/tpl/tpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ def progress(count, total):

percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
bar = '[%s] %s%s' % (bar, percents, '%')
bar = '[%s] %s/%s %s%s' % (bar, count+1, total, percents, '%')
Tpl.line_log(bar, status='debug')
if count+1 == total:
Tpl.message("\n")

@staticmethod
def __format_message(key, **args):
Expand Down
Loading

0 comments on commit 4487f64

Please sign in to comment.