def statusReport(self, path, response): """ @brief Given URL Path Response Status Report @pattern [23:59:59] Status Code (e.g. 302) - File Size (e.g. 222 B) - /php -> Target URL """ with self.mutex: contentLength = None status = response.status # Check Blacklist if status in self.blacklists and path in self.blacklists[status]: return # Format Messages try: size = int(response.headers['content-length']) except (KeyError, ValueError): size = len(response.body) finally: contentLength = FileUtils.sizeIEC(size) if self.basePath is None: showPath = urllib.parse.urljoin("/", path) else: showPath = urllib.parse.urljoin("/", self.basePath) showPath = urllib.parse.urljoin(showPath, path) # Concatenate The URL Response Report Message message = '[{0}] {1} - {2} - {3}'.format( time.strftime('%H:%M:%S'), status, contentLength.rjust(6, ' '), showPath) # HTTP Response Code List if status == 200: # OK message = Fore.GREEN + message + Style.RESET_ALL elif status == 401: # Unauthorized message = Fore.YELLOW + message + Style.RESET_ALL elif status == 403: # Forbidden message = Fore.RED + message + Style.RESET_ALL # Check If Redirect --> Response Code # 301 (Moved Permanently), 302 (Found -> Moved temporarily"), 307 (Temporary Redirect) elif (status in [301, 302, 307]) and ('location' in [ h.lower() for h in response.headers ]): message = Fore.CYAN + message + Style.RESET_ALL message += ' -> {0}'.format(response.headers['location']) self.newLine(message)
def recording(self): # Override """ @report_pattern HTTP Response Status Code + Package Size + URL + Path """ record = '' # self.pathList.append((path, status, contentLength)) for path, status, contentLength in self.pathList: record += '{0} '.format(status) record += '{0} '.format( FileUtils.sizeIEC(contentLength).rjust(6, ' ')) record += '{0}://{1}:{2}/'.format(self.protocol, self.host, self.port) record += ('{0}\n'.format(path) if self.basePath is '' else '{0}/{1}\n'.format(self.basePath, path)) return record