コード例 #1
0
ファイル: audit.py プロジェクト: lianchi/pro-box
    def post(cls, content, dirname):
        ret_value = -1
        host = Config().local_ip.encode("utf-8")
        hostId = HostId.get_host_id(Config().root_dir).encode("utf-8")
        pluginId = dirname.encode("utf-8")

        data = {
            "host": host,
            "hostId": hostId,
            "pluginId": pluginId,
            "data": content
        }
        params = urllib.urlencode({"data": data})
        host = Config().control_ip + ":" + Config().control_port
        try:
            conn = httplib.HTTPConnection(host)
            headers = {"Content-Type": "application/x-www-form-urlencoded"}
            conn.request(method="POST",
                         url=Config().control_audit_api,
                         body=params,
                         headers=headers)
            response = conn.getresponse()
        except Exception, e:
            print "Audit: NO RESPONSE"
            Config.p(e.message)
            return ret_value
コード例 #2
0
ファイル: heatbeat.py プロジェクト: lianchi/pro-box
    def post(cls, plugins_info):
        print 'call heartbeat...'
        ret_value = -1
        #add registe status
        if cls.registeState() == 0:
            print "Unregisted Container"
            return ret_value

        host = Config().control_ip + ":" + Config().control_port
        host_id = HostId.get_host_id(Config().root_dir)
        all_plugs = cls.loop_dir()

        for plug_info in plugins_info:
            plug_id = str(plug_info['id'])
            if all_plugs.has_key(plug_id):
                all_plugs[plug_id]['status'] = "1"
                #all_plugs[plug_id]['policyId'] = plug_info['policyId']

        plug_list = []
        for k, v in all_plugs.items():
            plug_list.append(v)

        data = {
            "host": Config().local_ip.encode('utf-8'),
            "hostId": host_id,
            "dataType": "heartbeat",
            "data": plug_list
        }
        Config.p(data)
        #print "send:",data
        params = urllib.urlencode({"data": data})
        headers = {"Content-Type": "application/x-www-form-urlencoded"}
        try:
            conn = httplib.HTTPConnection(host)
            conn.request(method="POST",
                         url=Config().heartbeat_api,
                         body=params,
                         headers=headers)
        except Exception, e:
            Config.p(e.message)
            return ret_value
コード例 #3
0
ファイル: audit.py プロジェクト: lianchi/pro-box
                dataList = data.split(":")
                infoList = [
                    str(dataList[0]), dataList[1].decode('utf-8'),
                    dataList[2].decode('utf-8'), dataList[2].decode('utf-8'),
                    dataList[3].decode('utf-8'), dataList[5].decode('utf-8'),
                    plugname, dataList[4].decode('utf-8')
                ]
                print infoList

                record = doc.createElement('log')
                root.appendChild(record)

                hostID = doc.createElement('hostID')
                record.appendChild(hostID)
                text = doc.createTextNode(
                    HostId.get_host_id(Config().root_dir).encode("utf-8"))
                hostID.appendChild(text)

                hostIP = doc.createElement('hostIP')
                record.appendChild(hostIP)
                text = doc.createTextNode(Config().local_ip.encode("utf-8"))
                hostIP.appendChild(text)

                auditType = doc.createElement('type')
                record.appendChild(auditType)
                text = doc.createTextNode(cls.op[infoList[0]])
                auditType.appendChild(text)

                genTime = doc.createElement('gentime')
                record.appendChild(genTime)
                text = doc.createTextNode(infoList[1])
コード例 #4
0
    def post(cls, policy_list):
        ret_value = -1
        #print policy_list

        for policy in policy_list:
            plugin_id = policy['pluginId'].encode('utf-8')
            #比较hash,判断插件是否有更新

            pluginHash = policy['pluginHash'].encode('utf-8')
            if len(pluginHash) == 0:
                continue
            cls.hashGet(plugin_id, pluginHash)

            # for policy_one in policy['policyId']:
            #     if policy_one['status'] == 'delete':
            #         policy_id = policy_one['id'].encode('utf-8') + ":000000"

            for policy_one in policy['policyId']:
                policy_id = policy_one['id'].encode('utf-8')
                if policy_one['status'] == 'delete':
                    policy_id = policy_one['id'].encode('utf-8') + ":000000"

                host_id = HostId.get_host_id(Config().root_dir)
                local_ip = Config().local_ip.encode('utf-8')

                data = {
                    "host": local_ip,
                    "hostId": host_id,
                    "pluginId": plugin_id,
                    "policyId": policy_id
                }

                params = urllib.urlencode({"data": data})
                host = Config().control_ip + ":" + Config().control_port

                try:
                    conn = httplib.HTTPConnection(host)
                    headers = {
                        "Content-Type": "application/x-www-form-urlencoded"
                    }
                    conn.request(method="POST",
                                 url=Config().control_policy_api,
                                 body=params,
                                 headers=headers)
                except Exception, e:
                    Config.p(e.message)
                    return ret_value

                try:
                    response = conn.getresponse()
                except Exception, e:
                    Config.p(e.message)
                    return ret_value

                if response.status == 200:
                    response_value = response.read()
                    json_data = eval(response_value)

                    #res_policy_id = json_data['policyId']
                    res_plugin_id = json_data['pluginId']
                    res_content = json_data['data']
                    print res_content
                    policy_dir = Config.root_dir + "plugs/" + res_plugin_id + "/policy/"
                    plugin_dir = Config.root_dir + "plugs/" + res_plugin_id + "/"
                    if os.path.exists(plugin_dir) is False:
                        continue

                    if os.path.exists(policy_dir) is False:
                        os.makedirs(policy_dir)

                    convertedDict = xmltodict.parse(res_content)
                    data = convertedDict['root']
                    policyId = data['@policyId']
                    #policyName =  data['@policyName']
                    policyType = data['@policyType']

                    if policyType == "6":
                        FileOp.parseFileOpConfig(data, plugin_dir)
                    else:
                        policy_file = policy_dir + res_plugin_id + ".xml"
                        file_obj = open(policy_file, 'w+')
                        file_obj.write(res_content)
                        file_obj.close()
                        ret_value = 0

                    resource = {}
                    resource["id"] = policyId
                    resource["hashcode"] = policy_one['hashcode']
                    hashFile = policy_dir + "md5"
                    try:
                        f = open(hashFile, "w+")
                        f.write(json.dumps(resource))
                        f.close()
                    except Exception, e:
                        pass
コード例 #5
0
ファイル: main.py プロジェクト: lianchi/pro-box
def hello():
    return HostId.get_host_id()
コード例 #6
0
ファイル: main.py プロジェクト: lianchi/pro-box
    Config.root_dir = '/opt/sebox/'
    for op, value in opts:
        if op == "-r":
            rootDir = value
        elif op == "-h":
            usage()
            sys.exit(-1)
    if Config.root_dir[len(Config.root_dir) - 1] != '/':
        Config.root_dir = Config.root_dir + "/"

    Config().init_config()
    Config().init_logger('sebox')

    MyQueue.init_queue()

    HostId.init_host_id(Config().root_dir)

    t1 = threading.Thread(target=local_heartbeat, args=())
    t1.setDaemon(True)
    t1.start()

    t2 = threading.Thread(target=send_heartbeat, args=())
    t2.setDaemon(True)
    t2.start()

    t3 = threading.Thread(target=send_audit, args=())
    t3.setDaemon(True)
    t3.start()

    # t4 = threading.Thread(target=getSystemInfo, args=())
    # t4.setDaemon(True)
コード例 #7
0
ファイル: register.py プロジェクト: lianchi/pro-box
class Reg:
    def __init__(self):
        pass

    @classmethod
    def regitsger(cls, data):
        data["host"] = Config().local_ip.encode('utf-8')
        data["mac"] = cls.get_mac_address()
        return cls.post(data)

    @classmethod
    def post(cls, data):
        response_value = ""
        harddiscserinum = "12312355"
        params = urllib.urlencode({"data": data})
        host = Config().control_ip + ":" + Config().control_port
        try:
            conn = httplib.HTTPConnection(host)
            headers = {"Content-Type": "application/x-www-form-urlencoded"}
            conn.request(method="POST",
                         url=Config().register_api,
                         body=params,
                         headers=headers)
            response = conn.getresponse()
        except Exception, e:
            Config.p(e.message)
            return response_value
        if response.status == 200:
            response_value = response.read()
            json_data = eval(response_value)
            print json_data
            Config.p(json_data["hostId"])
            if json_data["result"] == 'waiting':
                #cache
                cacheFile = Config().root_dir + "self/cache"
                data["result"] = "waiting"
                print data
                f = open(cacheFile, "w+")
                f.write(json.dumps(data))
                f.close()
            if json_data["result"] == 'success' and len(
                    json_data['hostId']) > 0:
                HostId.save_host_id(Config().root_dir, json_data["hostId"])
                db = Config().root_dir + "self/sebox.db"
                connDB = sqlite3.connect(db)
                cursor = connDB.cursor()
                cursor.execute("update boxinfo set status=1")
                infoList = [
                    data['username'].decode('utf-8'),
                    data['account'].decode('utf-8'),
                    data['org'].decode('utf-8'), data['mail'].decode('utf-8'),
                    data['host'],
                    Reg.get_mac_address(), harddiscserinum, json_data["hostId"]
                ]
                cursor.execute(
                    "insert into register(username,account,org,mail,host,mac,harddiscserinum,hostid) values (?,?,?,?,?,?,?,?)",
                    infoList)
                connDB.commit()
                cursor.close()
                connDB.close()
                cacheFile = Config().root_dir + "self/cache"
                try:
                    os.remove(cacheFile)
                except OSError, e:
                    print "No Cache File."