def getspammeremails(): mainDb = shivadbconfig.dbconnectmain() notify = server.shivaconf.getboolean('notification', 'enabled') whitelist = "SELECT `recipients` from `whitelist`" try: mainDb.execute(whitelist) record = mainDb.fetchone() if ((record is None) or (record[0] is None)): server.whitelist_ids['spammers_email'] = [] else: server.whitelist_ids['spammers_email'] = ( record[0].encode('utf-8')).split(",")[-100:] server.whitelist_ids['spammers_email'] = list( set(server.whitelist_ids['spammers_email'])) logging.info("[+] Pushtodb Module: whitelist recipients:") for key, value in server.whitelist_ids.items(): logging.info("key: %s, value: %s" % (key, value)) mainDb.close() except mdb.Error, e: logging.critical( "[-] Error (Module shivapushtodb.py) - some issue obtaining whitelist: %s" % e) if notify is True: shivanotifyerrors.notifydeveloper( "[-] Error (Module shivapushtodb.py) - getspammeremails %s" % e)
def getspammeremails(): mainDb = shivadbconfig.dbconnectmain() notify = server.shivaconf.getboolean('notification', 'enabled') whitelist = "SELECT `recipients` from `whitelist`" try: mainDb.execute(whitelist) record = mainDb.fetchone() if ((record is None) or (record[0] is None)): server.whitelist_ids['spammers_email'] = [] else: server.whitelist_ids['spammers_email'] = (record[0].encode('utf-8')).split(",")[-100:] server.whitelist_ids['spammers_email'] = list(set(server.whitelist_ids['spammers_email'])) logging.info("[+] Pushtodb Module: whitelist recipients:") for key, value in server.whitelist_ids.items(): logging.info("key: %s, value: %s" % (key, value)) mainDb.close() except mdb.Error, e: logging.critical("[-] Error (Module shivapushtodb.py) - some issue obtaining whitelist: %s" % e) if notify is True: shivanotifyerrors.notifydeveloper("[-] Error (Module shivapushtodb.py) - getspammeremails %s" % e)
def start(self, one_shot=False): """ Start simply loops indefinitely sleeping and pulling messages off for processing when they are available. If you give one_shot=True it will run once rather than do a big while loop with a sleep. """ """setup web interface and api""" if not one_shot: web.main() """ remove possible lock file from previous learning """ learning.free_learning_lock() logging.info("Queue receiver started on queue dir %s" % (self.queue_dir)) logging.debug("Sleeping for %d seconds..." % self.sleep) shivascheduler.schedule() inq = queue.Queue(self.queue_dir) # Get email-id's of spammers. Mail must get relayed to them. mainDb = shivadbconfig.dbconnectmain() whitelist = "SELECT `recipients` from `whitelist`" try: mainDb.execute(whitelist) record = mainDb.fetchone() global whitelist_ids if ((record is None) or (record[0] is None)): whitelist_ids['spammers_email'] = [] else: whitelist_ids['spammers_email'] = (record[0].encode('utf-8')).split(",")[-100:] whitelist_ids['spammers_email'] = list(set(whitelist_ids['spammers_email'])) logging.info("[+] server Module: whitelist recipients:") for key, value in whitelist_ids.items(): logging.info("key: %s, value: %s" % (key, value)) mainDb.close() except mdb.Error, e: logging.critical("[-] Error (Module server.py) - some issue obtaining whitelist: %s" % e)
def start(self, one_shot=False): """ Start simply loops indefinitely sleeping and pulling messages off for processing when they are available. If you give one_shot=True it will run once rather than do a big while loop with a sleep. """ """setup web interface and api""" if not one_shot: web.main() """ remove possible lock file from previous learning """ learning.free_learning_lock() logging.info("Queue receiver started on queue dir %s" % (self.queue_dir)) logging.debug("Sleeping for %d seconds..." % self.sleep) shivascheduler.schedule() inq = queue.Queue(self.queue_dir) # Get email-id's of spammers. Mail must get relayed to them. mainDb = shivadbconfig.dbconnectmain() whitelist = "SELECT `recipients` from `whitelist`" try: mainDb.execute(whitelist) record = mainDb.fetchone() global whitelist_ids if ((record is None) or (record[0] is None)): whitelist_ids['spammers_email'] = [] else: whitelist_ids['spammers_email'] = ( record[0].encode('utf-8')).split(",")[-100:] whitelist_ids['spammers_email'] = list( set(whitelist_ids['spammers_email'])) logging.info("[+] server Module: whitelist recipients:") for key, value in whitelist_ids.items(): logging.info("key: %s, value: %s" % (key, value)) mainDb.close() except mdb.Error, e: logging.critical( "[-] Error (Module server.py) - some issue obtaining whitelist: %s" % e)
shivanotifyerrors.notifydeveloper("[-] Error (Module shivamaindb.py) - checkRelayDate %s" % e) if len(mainDb.fetchall()) >= 1: update_relay = "UPDATE `relay` SET `lastRelayed` = '" + str(mailFields['relayTime']) + "', totalRelayed = totalRelayed + '" + str(mailFields['relayCounter']) + "' WHERE `spam_id` = '" + str(mainid) + "' AND `date` = '" + str(relayDate) + "'" try: mainDb.execute(update_relay) except mdb.Error, e: logging.error("[-] Error (Module shivamaindb.py) - update_relay %s" % e) if notify is True: shivanotifyerrors.notifydeveloper("[-] Error (Module shivamaindb.py) - update_relay %s" % e) else: insert_relay = "INSERT INTO `relay`(`date`, `firstRelayed`, `lastRelayed`, `totalRelayed`, `spam_id`, `sensorID`) VALUES ('" + str(relayDate) + "', '" + str(mailFields['relayTime']) + "', '" + str(mailFields['relayTime']) + "', '" + str(mailFields['relayCounter']) + "', '" + str(mainid) + "', '" + str(mailFields['sensorID']) + "')" try: mainDb.execute(insert_relay) except mdb.Error, e: logging.error("[-] Error (Module shivamaindb.py) - insert_relay %s" % e) if notify is True: shivanotifyerrors.notifydeveloper("[-] Error (Module shivamaindb.py) - insert_relay %s" % e) if __name__ == '__main__': tempDb = shivadbconfig.dbconnect() mainDb = shivadbconfig.dbconnectmain() notify = server.shivaconf.getboolean('notification', 'enabled') phishing_report = server.shivaconf.getboolean('analyzer', 'send_phishing_report') # time.sleep(200) # Giving time to hpfeeds module to complete the task. logging.basicConfig(filename='logs/maindb.log',level=logging.DEBUG,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') main()