#!/usr/bin/env python
# -*- coding: utf-8 -*

import os
import subprocess
import sys

from .useful.useful import run_cmd


class Exploit:
    """
    Uses the linux exploit suggester tool
    https://github.com/mzet-/linux-exploit-suggester
    """
    def __init__(self):
        """
        From original code, replace "\n" by "\\n", otherwise, the copy won't work
        """
        try:
            with open('beroot/modules/useful/linux-exploit-suggester.sh', 'rb') as file:
                self.code = file.read()
        except OSError:
            self.code = None

    def run(self):
        """
        Run linux exploit suggester tool
        """
        if 'linux' in sys.platform and self.code is not None:
            output, err = run_cmd(self.code)
            if output.strip():
                return output.decode()
