def reset(ctype): ''' Sends a reset request for the image type for the GUI. ''' opener.open('%s/post/reset/%s' % ( config.get('Settings', 'dofler_address'), ctype), {})
def stat(proto, count): '''statistical api call. sends the json dictionary to the api for processing on the other end. ''' # Building the post data data = { 'proto': proto, 'count': count, } # And submitting the data to the dofler server. opener.open('%s/post/stats' % config.get('Settings', 'dofler_address'), urlencode(data))
def login(): '''Login api. Sends the appropriate information to get the signed cookie we need to be able to post to the API. ''' # Lets start off and pre-populate the information we know we need. data = { 'timestamp': str(time.time()), 'username': config.get('Settings', 'sensor_name'), } # Also lets pull the information we need from the config file. secret = config.get('Settings', 'sensor_secret') # Now we will hash everything together into one nice happy hex digest and # then add it to the post data :) data['md5hash'] = md5hash(data['username'], data['timestamp'], config.get('Settings', 'sensor_secret')) # Then lets send everything along to the API so that we can get the cookie # we need. response = opener.open('%s/login' % config.get('Settings', 'dofler_address'), urlencode(data))
def image(filename): '''image api call. sends the image filename to the dofler server to be parsed and added to the database. ''' if config.getboolean('Settings', 'client_validate'): try: image = Image.open(filename) except: return try: opener.open('%s/post/image' % config.get('Settings', 'dofler_address'), {'file': open(filename), 'filetype': filename.split('.')[-1]}) except: try: log.warn('Image %s upload failed. Size: %s kb' %\ (filename, os.path.getsize(filename) / 1024)) except: log.warn('Image %s doesnt exist. Cannot upload.' % filename)
def run(self): '''The service manager for the thread. This is where the child process is actually being spawned and maintained. ''' start = time.time() # Set the start timer interface = config.get('Parser: %s' % self.stanza, 'interface') timer = config.getint('Parser: %s' % self.stanza, 'timer') promisc = config.getboolean('Parser: %s' % self.stanza, 'promisc') # Replace the options in the command with the interface and promiscuous # settings as needed. cmd = self.cmd.replace('{INTERFACE}', interface)\ .replace('{PROMISC}', self.promisc[promisc]) # Yeah! Loops! while not self.breaker: # Here we actually start the child process and then run through the # output in a loop until either the process exits, the timer hits, # or someone sets the breaker flag. p = pexpect.spawn(cmd) while not self.breaker and (int(time.time()) - int(start)) < timer: try: line = p.readline() #print '%s:\t%s' % (self.stanza, line.strip('\r\n')) if line == '': if p.isalive(): time.sleep(0.1) else: break else: self.parse(line) except pexpect.TIMEOUT: pass # As we either broke out of the process or the timer hit, lets make # sure to terminate the process and reset the timer to the current # time. p.terminate() start = time.time()
def account(username, password, info, proto, parser): '''account api call. parses and uploads the account information specified to the dofler server. ''' # First thing, if the password is more than 3 characters in length, then # we will obfuscate it. We don't want to be completely brutal to the people # we just pwned ;) if len(password) >= 3: password = '******' % (password[:3], '*' * (len(password) - 3)) # Building the post data data = { 'username': username, 'password': password, 'info': info, 'proto': proto, 'parser': parser, } # And submitting the data to the dofler server. opener.open('%s/post/account' % config.get('Settings', 'dofler_address'), urlencode(data))
import logging from dofler.config import config _loglevels = { 'debug': logging.DEBUG, 'info': logging.INFO, 'warn': logging.WARNING, 'error': logging.ERROR, 'critical': logging.CRITICAL, } log = logging.getLogger('DoFler') # This is the console output handler if config.getboolean('Settings', 'log_to_console'): stderr = logging.StreamHandler() console_format = logging.Formatter('%(levelname)s %(message)s') stderr.setFormatter(console_format) log.setLevel(_loglevels[config.get('Settings', 'log_level')]) log.addHandler(stderr) # This is the file handler, and is optional. if config.getboolean('Settings', 'log_to_file'): hdlr = logging.FileHandler(config.get('Settings', 'log_file')) formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) log.setLevel(_loglevels[config.get('Settings', 'log_level')]) log.addHandler(hdlr)