# Path: celerynode/api.py
# def api_hostScan(hostsList, ports, arguments='-Pn -sV', queue="master"):
#     """
#     hosts: 192.168.1.1-192.168.1.128,192.168.1.129-192.168.1.130
#     arguments: -Pn -sV
#     """
#     hostsList = hostsList.split(",")
#     for hostsQ in hostsList:
#         if hostsQ.find("|") != -1:
#             hosts, queue = hostsQ.split("|")
#         else:
#             hosts, queue = (hostsQ, "master")
#         ipList = get_ip_list(hosts)
#         for v in ipList:
#             hostScan.apply_async(args=[v, ports, arguments, queue], queue=queue)
#     return True
# 
# def api_vulPoc(task_id, task_name, netloc, pluginInfo):
#     # .json payload
#     # for v in netlocList
#     for item_netloc in netloc:
#         vulPocCheck.apply_async(args=[task_id, task_name, item_netloc, pluginInfo, item_netloc["queue"]], queue=item_netloc["queue"])
# 
# def api_vulScript(task_id, task_name, netloc, pfileName, passDic):
#     #.py scripts
#     # for v in netlocList
#     for item_netloc in netloc:
#         vulScriptCheck.apply_async(args=[task_id, task_name, item_netloc, pfileName, passDic, item_netloc["queue"]], queue=item_netloc["queue"])


import json
import os
import sys
import re
import uuid
from datetime import datetime
from urllib import unquote, urlopen, urlretrieve, quote
from flask import request, render_template, session, jsonify
from flask import redirect, url_for, make_response
from werkzeug.utils import secure_filename
from vulscan import vulScan
from common import cleanPostData
from lib.Login import logincheck
from es import Es
from Index import app
from celerynode.api import api_hostScan, api_vulPoc, api_vulScript
from redispool import getStrictRedis
    username = request.json.get('username')
    password = request.json.get('password')

    if username == app.config.get('USERNAME') and password == app.config.get('PASSWORD'):
        session['login'] = 'loginsuccess'
        return jsonify({"message":"ok"})
    else:
        return jsonify({"message":"error"})

@app.route('/loginOut', methods=['post'])
@logincheck
def loginOut():
    session['login'] = ''
    return jsonify({"message":"ok"})

@app.route('/')
@logincheck
def Index():
    return render_template('index.html')

@app.errorhandler(404)
def page_not_found(error):
    return render_template('error.html'), 404

@app.route('/setHostScan', methods=['post'])
@logincheck
def setHostScan():
    defaultConfig = es.get_scan_config()
    value = cleanPostData(request.json.get("scan_hosts"))
    hostsList, ports = (value, defaultConfig["scanPorts"])

# Path: celerynode/api.py
# def api_hostScan(hostsList, ports, arguments='-Pn -sV', queue="master"):
#     """
#     hosts: 192.168.1.1-192.168.1.128,192.168.1.129-192.168.1.130
#     arguments: -Pn -sV
#     """
#     hostsList = hostsList.split(",")
#     for hostsQ in hostsList:
#         if hostsQ.find("|") != -1:
#             hosts, queue = hostsQ.split("|")
#         else:
#             hosts, queue = (hostsQ, "master")
#         ipList = get_ip_list(hosts)
#         for v in ipList:
#             hostScan.apply_async(args=[v, ports, arguments, queue], queue=queue)
#     return True
# 
# def api_vulPoc(task_id, task_name, netloc, pluginInfo):
#     # .json payload
#     # for v in netlocList
#     for item_netloc in netloc:
#         vulPocCheck.apply_async(args=[task_id, task_name, item_netloc, pluginInfo, item_netloc["queue"]], queue=item_netloc["queue"])
# 
# def api_vulScript(task_id, task_name, netloc, pfileName, passDic):
#     #.py scripts
#     # for v in netlocList
#     for item_netloc in netloc:
#         vulScriptCheck.apply_async(args=[task_id, task_name, item_netloc, pfileName, passDic, item_netloc["queue"]], queue=item_netloc["queue"])


# Path: server/Routes.py
import json
import os
import sys
import re
import uuid
from datetime import datetime
from urllib import unquote, urlopen, urlretrieve, quote
from flask import request, render_template, session, jsonify
from flask import redirect, url_for, make_response
from werkzeug.utils import secure_filename
from vulscan import vulScan
from common import cleanPostData
from lib.Login import logincheck
from es import Es
from Index import app
from celerynode.api import api_hostScan, api_vulPoc, api_vulScript
from redispool import getStrictRedis

    username = request.json.get('username')
    password = request.json.get('password')

    if username == app.config.get('USERNAME') and password == app.config.get('PASSWORD'):
        session['login'] = 'loginsuccess'
        return jsonify({"message":"ok"})
    else:
        return jsonify({"message":"error"})

@app.route('/loginOut', methods=['post'])
@logincheck
def loginOut():
    session['login'] = ''
    return jsonify({"message":"ok"})

@app.route('/')
@logincheck
def Index():
    return render_template('index.html')

@app.errorhandler(404)
def page_not_found(error):
    return render_template('error.html'), 404

@app.route('/setHostScan', methods=['post'])
@logincheck
def setHostScan():
    defaultConfig = es.get_scan_config()
    value = cleanPostData(request.json.get("scan_hosts"))
    hostsList, ports = (value, defaultConfig["scanPorts"])

    if api_hostScan(hostsList=hostsList, ports=ports):