Exemplo n.º 1
0
    def openvas_settings(self, ipaddress, openvas_user, openvas_password):
        """
        Save OpenVAS Settings into Setting files.
        :param ipaddress:
        :param username:
        :param passwrod:
        :return:
        """

        all_openvas = openvas_setting_db.objects.all()
        all_openvas.delete()

        openvas_settings = openvas_setting_db(host=ipaddress,
                                              user=openvas_user,
                                              password=openvas_password)
        openvas_settings.save()
        try:
            with open(self.setting_file, 'r+') as f:
                sig_ov_user = signing.dumps(openvas_user)
                sig_ov_pass = signing.dumps(openvas_password)
                sig_ov_ip = signing.dumps(ipaddress)
                data = json.load(f)
                data['open_vas_user'] = sig_ov_user
                data['open_vas_pass'] = sig_ov_pass
                data['open_vas_ip'] = sig_ov_ip
                f.seek(0)
                json.dump(data, f, indent=4)
                f.truncate()

        except Exception as e:
            return e
        return f.close()
Exemplo n.º 2
0
    def openvas_settings(self, openvas_host, openvas_port, openvas_enabled, openvas_user, openvas_password):
        """
        Save OpenVAS Settings into Setting files.
        :param host:
        :param port:
        :param enabled:
        :param username:
        :param passwrod:
        :return:
        """

        all_openvas = openvas_setting_db.objects.all()
        all_openvas.delete()

        openvas_settings = openvas_setting_db(host=openvas_host,
                                              port=openvas_port,
                                              enabled=openvas_enabled,
                                              user=openvas_user,
                                              password=openvas_password
                                              )
        openvas_settings.save()
        try:
            with open(self.setting_file, 'r+') as f:
                sig_ov_user = signing.dumps(openvas_user)
                sig_ov_pass = signing.dumps(openvas_password)
                sig_ov_host = signing.dumps(openvas_host)
                sig_ov_port = signing.dumps(openvas_port)
                sig_ov_enabled = signing.dumps(openvas_enabled)
                data = json.load(f)
                data['open_vas_user'] = sig_ov_user
                data['open_vas_pass'] = sig_ov_pass
                data['open_vas_host'] = sig_ov_host
                data['open_vas_port'] = sig_ov_port
                data['open_vas_enabled'] = sig_ov_enabled
                f.seek(0)
                json.dump(data, f, indent=4)
                f.truncate()

        except Exception as e:
            return e
        return f.close()