from general import *
from A5.outdated_scan import OutdatedScan
from A5.detailed_error import DetailedError
from configparser import ConfigParser


class mainSecMisconf:

    def __init__(self, url, path):
        self.url = url
        self.path = path
        self.log = list()
        self.log_csv = list()
        self.url_login = list()

        config = ConfigParser()
        config.read('/opt/asetulweb/config.ini')
        db = str(config.get('settings', 'db'))
        self.list_url = file_to_set(path + "/crawled.txt")
        self.db_login = file_to_list(db + "db/db_login.txt")

        self.boot()

    def boot(self):
        self.log.append("result scanning system")
        scan = OutdatedScan(self.url)
        for output in scan.return_output():
            self.log.append(output)
        for output in scan.return_output_cvs():
            data = ["Outdated System", output]
            self.log_csv.append(data)

        self.log.append(" ")
        self.log.append("result detailed errors")
        det = DetailedError(self.path)
        for output in det.return_output():
            self.log.append(output)

    def return_output(self):
        output = self.log
        return output

    def return_output_cvs(self):
        output = self.log_csv
        return output
