# -*- coding: utf-8 -*-1# This program is free software; you can redistribute it and/or modify2# it under the terms of the GNU General Public License as published by3# the Free Software Foundation; either version 2 of the License, or4# (at your option) any later version.5#6# This program is distributed in the hope that it will be useful,7# but WITHOUT ANY WARRANTY; without even the implied warranty of8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9# GNU General Public License for more details.10#11# You should have received a copy of the GNU General Public License12# along with this program; if not, write to the Free Software13# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,14# MA 02110-1301, USA.15#16# Author: Mauro Soria1718from defusedcsv import csv1920from lib.core.decorators import locked21from lib.report.factory import BaseReport, FileReportMixin222324class CSVReport(FileReportMixin, BaseReport):25__format__ = "csv"26__extension__ = "csv"2728def new(self):29return [["URL", "Status", "Size", "Content Type", "Redirection"]]3031def parse(self, file):32with open(file) as fh:33rows = list(csv.reader(fh, delimiter=",", quotechar='"'))34# Not a dirsearch CSV report35if rows[0] != self.new()[0]:36raise Exception3738return rows3940@locked41def save(self, file, result):42rows = self.parse(file)43rows.append([result.url, result.status, result.length, result.type, result.redirect])44self.write(file, rows)4546def write(self, file, rows):47with open(file, "w") as fh:48writer = csv.writer(fh, delimiter=",", quotechar='"')49for row in rows:50writer.writerow(row)515253