Beispiel #1
0
def getrptbase(vname):
    filepath = DNSMinerHome
    thisCfgDict = cfgparse_dm.opencfg(sitecfg,'SectionThree')
    rptbase = thisCfgDict['reportbase']
    filepath = filepath +  rptbase + "/" + vname
    # need a little hook to make directory if not there
    return filepath
Beispiel #2
0
def genRPZtraffic(dlist,wlist):
    thisCfgDict = cfgparse_dm.opencfg(dbcfg,'SectionThree')
    usertemp = thisCfgDict['dmtemp']
    plog = usertemp + "/proveitRPZ.log"
    thisfh = openlogfile(plog)
    RDTYPE=['A','MX','NS','A','A','AAAA','TXT','MX','A','A','A','AAAA','A','A']
    while True:
        thisint = (randint(0,499))
        ldns=getldns(thisint)
        thishost = genrandhost(wlist)
        thisdom = dlist[thisint]
        fqdn = thishost + "." + thisdom
        domobj = dns.name.from_text(fqdn.strip())
        thisfh.write(logts() + ": Test_generated: " + fqdn + "\n")
        # Just going with A records for now,
        #randrd = 'dns.rdatatype.' + random.choice(RDTYPE)
        req = dns.message.make_query(domobj, dns.rdatatype.A, dns.rdataclass.IN)
        try:
            resp = dns.query.udp(req,ldns)
            if len(resp.answer) == 0:
                print " do it again "
                sleep(2)
                resp = dns.query.udp(req,ldns)
            if len(resp.answer) == 0:
                thisfh.write(logts() + ": Test_result: no response " + fqdn + "\n")
            else:
                respstr = str(resp.answer)
                thisfh.write(logts() + ": Test_result: " + respstr + "\n")
            print resp.answer
        except DNSException as ex:
            thisfh.write(logts() + ": Test_exception: " + ex + "\n")
            print ex
        sleep(randint(randlow,randhigh))
    thisfh.close()
    return
def dbTblInsert(insertdict,dbtable):
    # by default config parser converts keys to lowercase , https://docs.python.org/2/library/configparser.html
    thisCfgDict = cfgparse_dm.opencfg(dbcfg,'SectionOne')
    adminVar = thisCfgDict['databaseuser']
    adminPwd= thisCfgDict['databasepwd']
    ivDBName = thisCfgDict['databasename']
    var = 'Record inserted successfully'

    columnlist = []
    valuelist = []
    for key, value in insertdict.iteritems():
        #print "Column: " + key
        columnlist.append(key)
        #print "Value: " + value
        valuelist.append(value)
    valstring ="','".join(valuelist)  # need the ticks for sql insert to work in mysql
    colstring =",".join(columnlist)
    sqlStrI = "INSERT INTO " + dbtable + "(" + colstring +") VALUES ('" + valstring +"');"
    #print sqlStrI
    try:
        dbcon = mdb.connect('localhost',adminVar,adminPwd,ivDBName)
        #print "connected"
    except mdb.Error, e:
        print e.args[0]
        sys.exit(1)
def getfibrpz():
    # parsse the config file to figure out the location of the RPZ files,  look for the newest and return a lsit with file path and file name
    thisCfgDict = cfgparse_dm.opencfg(sitecfg,'SectionThree')
    fibpath = thisCfgDict['fibhome']
    newest = 19992359
    thisrpz = ''
    rpzlist = os.listdir(fibpath)
    retlist = [fibpath,thisrpz]

    for fname in rpzlist:
        fname = fname.strip()
        if fname.endswith(".rpz"):
            fnamesplit = fname.split('-')
            try:
                fnamedate = int(fnamesplit[0])
                if fnamedate > newest:
                    newest = fnamedate
                    thisrpz = fname
            except:
                print "rpz file not in expected format"
                sys.exc_clear()
            filepaths = []
            # expecting yyyymmdd-*.rpz
            if len(thisrpz) > 11 :
                retlist[1]=thisrpz
            else:
                print "Sorry, unable to find a usable RPZ file, please debug"
    return retlist
Beispiel #5
0
def getreportparams():
    thisCfgDict = cfgparse_dm.opencfg(sitecfg,'SectionThree')
    rptbase = thisCfgDict['reportbase']
    rptbase =  DNSMinerHome + "/" + rptbase
    rptsfx = mkserial() # these will be new every 24 hours
    retlist =  [rptbase, rptsfx]
    return retlist
def getindexlist(lbdays):
    thisCfgDict = cfgparse_dm.opencfg(sitecfg,'SectionThree')
    idxpre = thisCfgDict['lsindexprefix']
    idxlist = []
    while lbdays > 0:
        d = date.today() - timedelta(days=lbdays)
        chrtrans = maketrans("-",".")
        idxsfx = str(d).translate(chrtrans)
        idxname = idxpre + "-" + idxsfx
        idxlist.append(idxname)
        lbdays = lbdays - 1
    return idxlist
Beispiel #7
0
def getOrgID():
    thisCfgDict = cfgparse_dm.opencfg(dbcfg,'SectionOne')
    adminVar = thisCfgDict['databaseuser']
    adminPwd= thisCfgDict['databasepwd']
    ivDBName = thisCfgDict['databasename']
    #debug
    print "collecing org IDs"
    oidrows = []
    try:
        dbcon = mdb.connect('localhost',adminVar,adminPwd,ivDBName)
        #print "connected"
    except mdb.Error, e:
        print e.args[0]
        sys.exit(1)
Beispiel #8
0
def loadtable(sortedlist):
    print "checking credentials supplied"
    # by default config parser converts keys to lowercase , https://docs.python.org/2/library/configparser.html
    thisCfgDict = cfgparse_dm.opencfg(sitecfg,'SectionOne')
    adminVar = thisCfgDict['databaseuser']
    adminPwd= thisCfgDict['databasepwd']
    ivDBName = thisCfgDict['databasename']

    try:
        dbcon = mdb.connect('localhost',adminVar,adminPwd,ivDBName)
        print "connected " + time.ctime()
    except mdb.Error, e:
        print e.args[0]
        sys.exit(1)
Beispiel #9
0
def genrpzheader(vname):
    thisCfgDict = cfgparse_dm.opencfg(dbcfg,'SectionThree')
    rpzns = thisCfgDict['minebossnameserver']
    zadmin = thisCfgDict['rpzadmin']
    zserial = mkserial(0) # these will be new every 24 hours
    rpzname = vname + ".rpz"
    line0 = "; zone file " + rpzname + "\n"
    line1 = "$TTL 5m; keep TTL short to get some time stamping which can be helpful scoping incidents\n"
    line2 = "$ORIGIN " + rpzname + ".\n"
    # Seems to be an issue with notify slaves failing, reduced the refresh so we get 5 turns an hour, RFC says 20 mins lowest
    # but since there are only 3 devices polling it's still only 15 zontransders and hour.
    line3 = "@\tSOA " + rpzns + ".\t" + zadmin + " (" + zserial + " 12m 5m 7d 2h)\n"
    line4 = "\tNS " + rpzns + ".\n"
    line5 = "; divert entire domains to an internal host running the user warning/monitoring app\n"
    headerstring = line0 + line1 + line2 + line3 + line4 + line5
    return headerstring
def checkauthn(checkinput):
    print "checking credentials supplied"
    # by default config parser converts keys to lowercase , https://docs.python.org/2/library/configparser.html
    thisCfgDict = cfgparse_dm.opencfg(dbcfg,'SectionOne')
    adminVar = thisCfgDict['databaseuser']
    adminPwd= thisCfgDict['databasepwd']
    ivDBName = thisCfgDict['databasename']
    contactEmail = checkinput[0]
    clearpasswd = checkinput[1]

    authzlist = [False,8287]
    try:
        dbcon = mdb.connect('localhost',adminVar,adminPwd,ivDBName)
        #print "connected"
    except mdb.Error, e:
        print e.args[0]
        sys.exit(1)
Beispiel #11
0
def getreportparams():
    thisCfgDict = cfgparse_dm.opencfg(sitecfg,'SectionThree')
    rptbase = thisCfgDict['reportbase']
    rptbase =  DNSMinerHome  + rptbase
    return rptbase
def getreportparams():
    thisCfgDict = cfgparse_dm.opencfg(sitecfg,'SectionThree')
    rptbase = thisCfgDict['dmhome']
    rptbase = rptbase + "/var/reports"
    return rptbase
Beispiel #13
0
def getAppOwnerInfo():
    thisCfgDict = cfgparse_dm.opencfg(dbcfg,'SectionFour')
    dnsmgid = thisCfgDict['dmgid']
    mbuid = thisCfgDict['aouid']
    uinfo=[mbuid,dnsmgid]
    return uinfo
Beispiel #14
0
def getrpzbase():
    thisCfgDict = cfgparse_dm.opencfg(dbcfg,'SectionThree')
    dirbase = thisCfgDict['rpzbase']
    return dirbase
Beispiel #15
0
def getTIListsrc():
    thisCfgDict = cfgparse_dm.opencfg(sitecfg,'SectionThree')
    thisfibhome = thisCfgDict['fibhome']
    listbase = thisfibhome + "/lists/"
    return  listbase