def logresponse(self, response, imei):
        """ Prints the response on the log """
        issuccess = True
        imeidata = "Imei " + imei
        status = "not know"
        logconsole(response, "i")

        result_search = re.search('<imei>(.+?)</imei>', response)
        if result_search:
            response_code = result_search.group(1)
            res_code = "Imei " + response_code + " " + imeidata
            logconsole("Resp code" + res_code, "i")
        else:
            notfound = "<imei> not found"
            logconsole(notfound, "e")
            issuccess = False

        result_search = re.search('<status>(.+?)</status>', response)
        if result_search:
            status = result_search.group(1)
            logconsole("Status: " + status, "i")
        else:
            notfound = "<status> not found"
            logconsole(notfound, "e")
            issuccess = False

        return issuccess, status
Example #2
0
def blockhandset(compiledfile):
    """ Force Imei """
    logconsole(Colors.OKGREEN + " -----------Block Handset Service----------- " +
               Colors.ENDC, "i")
    blckhandset = BlockHadset()


    return blckhandset.run(compiledfile)
Example #3
0
def forceimei(compiledfile):
    """ Force Imei """
    logconsole(Colors.OKGREEN + " -----------FORCE IMEI SERVICE----------- " +
               Colors.ENDC, "i")
    forceimeiob = ForceImei()


    return forceimeiob.run(compiledfile)
Example #4
0
def handsetstatus(imeifile):
    """ Handset validation call """
    logconsole(Colors.OKGREEN + " -----------HANDSET VALIDATION FILE GEN----------- " +
               Colors.ENDC, "i")
    hadstatus = HandsetStatus()


    return hadstatus.run(imeifile)
Example #5
0
def querydb():
    """
    Query the Detection list table from Handset DB
    in order to list the imei to block
     """
    logconsole(Colors.OKGREEN + " -----------DATABASE QUERY FILE GEN----------- " +
               Colors.ENDC, "i")
    querydatab = Querydb()


    return querydatab.run()
Example #6
0
def main():
    """ Main function """
    issuccess = True
    logging.basicConfig(filename=LOG_ROUTE, level=logging.DEBUG)

    if os.path.isfile(LOG_ROUTE):
        with open(LOG_ROUTE, 'w'):
            pass

    logconsole("************** Init Program **************", "i")


    if querydb():
        print Colors.OKGREEN + "Querydb status true" + Colors.ENDC
    else:
        issuccess = False

    imeifile = imeifileload()


    if issuccess:
        if handsetstatus(imeifile):
            print Colors.OKGREEN + "Handset status true" + Colors.ENDC
        else:
            issuccess = False
            print  Colors.FAIL + "Handset status FALSE" + Colors.ENDC
        imeifile.close()


    compiledfile = compiledfileload()
    if issuccess:
        if forceimei(compiledfile):
            print Colors.OKGREEN + "Force IMEI status true" + Colors.ENDC
        else:
            issuccess = False
            print  Colors.FAIL + "Force IMEI status FALSE" + Colors.ENDC
    compiledfile.close()


    compiledfile = compiledfileload()
    if issuccess:
        if blockhandset(compiledfile):
            print Colors.OKGREEN + "BLOCKHANDSET status true" + Colors.ENDC
        else:
            issuccess = False
            print  Colors.FAIL + "BLOCKHANDSET status FALSE" + Colors.ENDC

    compiledfile.close()
    def run(self, compiledfile):
        """ Loads imei file """
        compiled_file = compiledfile
        reader = csv.reader(compiled_file)

        row = 0
        errorcount = 0
        total = 0

        for row in reader:
            reporttype = ""
            imei = row[0]
            msisdn = row[2]
            date = row[5]

            if row[4] == "UNREGISTERED_IMEI":
                reporttype = "AUTOMATIC_BLOCKING_HANDSET_NOT_REGISTERED"
            elif row[4] == "INVALID_IMEI":
                reporttype = "AUTOMATIC_BLOCKING_IMEI_INVALID"

            date = re.sub(" ", "T", date)

            logconsole("BlockHadset: Calling service with: ", "i")
            logconsole(
                "Imei " + imei + " Msisdn " + msisdn + " treatement " +
                reporttype + " planbldate " + date, "i")

            body = self.buildmessage(row[0], row[2], reporttype)
            logconsole(body, "i")

            response = shootsoap(body, SERVICE_ACTION_HANDSET)
            if not self.logresponse(response, imei, msisdn):
                errorcount += 1

            total += 1
            logconsole(
                "********************************************************************",
                "i")

        finishmsg = "Finished with " + str(errorcount) + " errors / " + str(
            total)

        logconsole(finishmsg, "i")

        if errorcount == 0:
            return True
        else:
            return False
Example #8
0
    def run(self):
        """ Write line """
        if os.path.isfile(IMEI_ROUTE):
            with open(IMEI_ROUTE, 'w'):
                pass
        db_query_fout = open(IMEI_ROUTE, "w")

        invalidimeiquery, unregimeiquery = self.buildqueries()

        total = 0
        isnotempty = False
        print invalidimeiquery
        try:
            conn = psycopg2.connect(host=HOST,
                                    port=PORT,
                                    dbname=DBNAME,
                                    user=USER,
                                    password=PASSWORD)
            cur = conn.cursor()

            cur.execute(invalidimeiquery)

            if cur.rowcount:
                rows = cur.fetchall()
                for row in rows:
                    total += 1
                    db_query_fout.write(",".join([str(col)
                                                  for col in row]) + "\n")
                isnotempty = True
            else:
                logconsole("Invalid imei query 0 data", "i")

            cur.execute(unregimeiquery)
            if cur.rowcount:
                rows = cur.fetchall()
                for row in rows:
                    total += 1
                    db_query_fout.write(",".join([str(col)
                                                  for col in row]) + "\n")
                isnotempty = True
            else:
                logconsole("unregistered imei query 0 data", "i")

            logconsole(
                "Finished creating file with " + str(total) + " entries", "i")

            return isnotempty

        except psycopg2.DatabaseError, error:
            print "Can't connect to handset bruh %s" % error
            logconsole("Can't connect to handset bruh %s" % error, "e")
Example #9
0
    def logresponse(self, response, imei, msisdn):
        """ Prints the response on the log """
        isforced = True
        imeidata = "Imei " + imei + " Msisdn " + msisdn
        logconsole(response, "i")

        result_search = re.search('<responseCode>(.+?)</responseCode>',
                                  response)
        if result_search:
            response_code = result_search.group(1)
            res_code = "Code " + response_code + " " + imeidata
            logconsole("Resp code" + res_code, "i")
            if response_code != '0':
                logconsole(res_code, "e")
                isforced = False
        else:
            notfound = "<responseCode> not found"
            logconsole(notfound, "e")

        return isforced
Example #10
0
    def run(self, imeifile):
        """ Loads imei file """
        imei_file = imeifile
        reader = csv.reader(imei_file)

        row = 0
        errorcount = 0
        total = 0

        for row in reader:

            imei = row[0]
            msisdn = row[2]

            logconsole("ForceImei: Calling service with: ", "i")
            logconsole("Imei " + imei + " Msisdn " + msisdn, "i")

            body = self.buildmessage(imei, msisdn)

            response = shootsoap(body, SERVICE_ACTION_MANAGEMENT)
            if not self.logresponse(response, imei, msisdn):
                errorcount += 1

            total += 1

            logconsole(
                "********************************************************************",
                "i")

        finishmsg = "Finished with " + str(errorcount) + " errors / " + str(
            total)

        logconsole(finishmsg, "i")

        if errorcount == 0:
            return True
        else:
            return False
    def run(self, imeifile):
        """ Loads imei file """
        if os.path.isfile(REGIS_ONLY_FILE):
            with open(REGIS_ONLY_FILE, 'w'):
                pass
        comp_file_reg = open(REGIS_ONLY_FILE, "w")

        imei_file = imeifile
        reader = csv.reader(imei_file)

        total = 0
        row = 0
        errorcount = 0
        status = ""
        registeredtoothercounter = 0
        blacklistedcounter = 0
        othercounter = 0
        registeredcounter = 0

        for row in reader:

            imei = row[0]
            logconsole("HANDSETSTATUS: Calling service with: ", "i")
            logconsole("Imei " + imei, "i")

            body = self.buildmessage(imei)
            response = shootsoap(body, SERVICE_ACTION_MANAGEMENT)

            issuccess, status = self.logresponse(response, imei)

            if not issuccess:
                errorcount += 1

            if status == "REGISTERED_TO_OTHER":
                registeredtoothercounter += 1
                if row[4] == "INVALID_IMEI":
                    comp_file_reg.write(",".join(row) + "\n")
            elif status == "BLACKLISTED":
                blacklistedcounter += 1
            elif status == "UNREGISTERED":
                print row
                comp_file_reg.write(",".join(row) + "\n")
                registeredcounter += 1
            else:
                logconsole("UNKNOWN STATUS. CHECK IT DUDE", "e")
                othercounter += 1

            total += 1
            logconsole(
                "********************************************************************",
                "i")

        finishmsg = ("Finished with " + str(errorcount) + " errors \n" +
                     "REGISTERED_TO_OTHER: " + str(registeredtoothercounter) +
                     " | BLACKLISTED: " + str(blacklistedcounter) +
                     " | UNREGISTERED: " + str(registeredcounter) +
                     " | OTHER: " + str(othercounter))
        logconsole(finishmsg, "i")
        comp_file_reg.close()

        if errorcount == 0:
            return True
        else:
            return False