# Path: lib/core/data.py

# 
# Path: lib/utils/console.py
# def getTerminalSize():
#     import platform
#     current_os = platform.system()
#     tuple_xy = None
#     if current_os == 'Windows':
#         tuple_xy = _getTerminalSize_windows()
#         if tuple_xy is None:
#             tuple_xy = _getTerminalSize_tput()
#             # needed for window's python in cygwin's xterm!
#     if current_os == 'Linux' or current_os == 'Darwin' or current_os.startswith('CYGWIN'):
#         tuple_xy = _getTerminalSize_linux()
#     if tuple_xy is None:
#         print "default"
#         tuple_xy = (80, 25)  # default value
#     return tuple_xy
# 
# Path: lib/utils/versioncheck.py
# PYVERSION = sys.version.split()[0]
# 
# Path: lib/core/enums.py
# class POC_RESULT_STATUS:
#     FAIL = 0
#     SUCCESS = 1
#     RETRAY = 2
# 
# class ENGINE_MODE_STATUS:
#     THREAD = 9
#     GEVENT = 8


import threading
import time
import traceback
        import gevent
from lib.core.data import th, conf, logger, targetlist
from lib.utils.console import getTerminalSize #获取命令行窗口的宽度和高度
from lib.utils.versioncheck import PYVERSION
from lib.core.enums import POC_RESULT_STATUS, ENGINE_MODE_STATUS
        from gevent import monkey
        # It can quit with Ctrl-C
        while 1: #如果未扫描结束，主线程一直死循环等待，取决于线程数量和th.is_continue的值
            if th.thread_count > 0 and th.is_continue:
                time.sleep(0.01)
            else:
                break

    elif conf.ENGINE is ENGINE_MODE_STATUS.GEVENT: #协程模式conf.ENGINE=8
        monkey.patch_all()
        while th.queue.qsize() > 0 and th.is_continue:
            gevent.joinall([gevent.spawn(scan) for i in xrange(0, th.threads_num) if #生成10个concurrent
                            th.queue.qsize() > 0])

    if 'errmsg' in th:
        logger.error(th.errmsg)


def resultHandler(status, payload):
    truemsg = "The target '{}' is vulnerable".format(payload)
    falsemsg = "The target '{}' is NOT vulnerable".format(payload)
    if not status or status is POC_RESULT_STATUS.FAIL:
        targetlist.append([payload, status])
        logger.error(falsemsg)
        if th.thread_mode: th.output_lock.release()
        return
    elif status is POC_RESULT_STATUS.RETRAY:
        changeScanCount(-1)
        th.queue.put(payload)
        return
    elif status is True or status is POC_RESULT_STATUS.SUCCESS:

# Path: lib/core/data.py

# 
# Path: lib/utils/console.py
# def getTerminalSize():
#     import platform
#     current_os = platform.system()
#     tuple_xy = None
#     if current_os == 'Windows':
#         tuple_xy = _getTerminalSize_windows()
#         if tuple_xy is None:
#             tuple_xy = _getTerminalSize_tput()
#             # needed for window's python in cygwin's xterm!
#     if current_os == 'Linux' or current_os == 'Darwin' or current_os.startswith('CYGWIN'):
#         tuple_xy = _getTerminalSize_linux()
#     if tuple_xy is None:
#         print "default"
#         tuple_xy = (80, 25)  # default value
#     return tuple_xy
# 
# Path: lib/utils/versioncheck.py
# PYVERSION = sys.version.split()[0]
# 
# Path: lib/core/enums.py
# class POC_RESULT_STATUS:
#     FAIL = 0
#     SUCCESS = 1
#     RETRAY = 2
# 
# class ENGINE_MODE_STATUS:
#     THREAD = 9
#     GEVENT = 8


# Path: lib/controller/engine.py
import threading
import time
import traceback
        import gevent
from lib.core.data import th, conf, logger, targetlist
from lib.utils.console import getTerminalSize #获取命令行窗口的宽度和高度
from lib.utils.versioncheck import PYVERSION
from lib.core.enums import POC_RESULT_STATUS, ENGINE_MODE_STATUS
        from gevent import monkey

        # It can quit with Ctrl-C
        while 1: #如果未扫描结束，主线程一直死循环等待，取决于线程数量和th.is_continue的值
            if th.thread_count > 0 and th.is_continue:
                time.sleep(0.01)
            else:
                break

    elif conf.ENGINE is ENGINE_MODE_STATUS.GEVENT: #协程模式conf.ENGINE=8
        monkey.patch_all()
        while th.queue.qsize() > 0 and th.is_continue:
            gevent.joinall([gevent.spawn(scan) for i in xrange(0, th.threads_num) if #生成10个concurrent
                            th.queue.qsize() > 0])

    if 'errmsg' in th:
        logger.error(th.errmsg)


def resultHandler(status, payload):
    truemsg = "The target '{}' is vulnerable".format(payload)
    falsemsg = "The target '{}' is NOT vulnerable".format(payload)
    if not status or status is POC_RESULT_STATUS.FAIL:
        targetlist.append([payload, status])
        logger.error(falsemsg)
        if th.thread_mode: th.output_lock.release()
        return
    elif status is POC_RESULT_STATUS.RETRAY:
        changeScanCount(-1)
        th.queue.put(payload)
        return
    elif status is True or status is POC_RESULT_STATUS.SUCCESS:

        targetlist.append([payload, status])