ptreport

Revision 2 as of 2008-02-17 21:41:45

Clear message

Include(UbuntuPentest/Header)

bash alpha version

# anteater V 0.1 Alpha
# (C) 2008 Ubuntu Pentest, Emanuele Gentili
# Authors
# Emanuele Gentili <emgent@emanuele-gentili.com>
# Giorgio Carlo Gigli Tos <gionnyboss@gmail.com>
# GPLv2, see /usr/share/common-licenses/GPL

import sys
import os
from stat import *
import re

class Application():
        NAME = "anteater.py"
        VERSION = 0.1
        AUTHORS = \
                        "Emanuele Gentili (emgent)\n" \
                        + "Giorgio Carlo Gili Tos (GionnyBoss)"

        LICENSE = "This is free software. You may redistribute copies of it under the terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n" \
                        + "There is NO WARRANTY, to the extent permitted by law."

        cocFilename = "coc.txt"
        editor = "nano"


        def __init__(self):

                self.__getOptions()

                # Displaying code of conduct
                os.system("more " + self.cocFilename)

                while True:
                        reply = self.__getLine("Do you accept Ubuntu Code of Conduct? [y,n] ")
                        if re.match("^\s*y\s*$", reply, re.IGNORECASE):
                                break
                        elif re.match("^\s*n\s*$", reply, re.IGNORECASE):
                                sys.exit("You did not accept Ubuntu Code of Conduct.\nExiting application...")

                self.start()

        # Get command line options
        def __getOptions(self):

                from optparse import OptionParser

                usage = self.NAME + " [OPTION]..."
                version = self.NAME + " " + str(self.VERSION) + "\n" + self.LICENSE + "\n\nWritten by " + self.AUTHORS
                description = "Application description"

                parser = OptionParser(usage=usage, version=version, description=description)
                parser.add_option("-e", "--editor", action="store", type="string", default="nano", help="command of the editor to use to edit your bug report [default: %default]", metavar="EDITOR")
                (options, args) = parser.parse_args()

                self.editor = options.editor
                # Checking if editor exists in path
                pathDirs = os.environ['PATH'].split(":")

                editorValid = False
                for dir in pathDirs:
                        file = os.path.join(dir, self.editor)
                        if os.path.isfile(file):
                                mode = os.stat(file)[ST_MODE]
                                # Checking if file is executable to Others
                                # TODO - Think if there is a better way to do this.
                                if (S_IMODE(mode) & S_IXOTH) == S_IXOTH:
                                        editorValid = True
                                        break

                if not editorValid:
                        sys.exit(self.NAME + ": specified editor `" + self.editor + "' is not in your path")

        def __getLine(self, text):

                try:
                        line = raw_input(text)
                except (EOFError, KeyboardInterrupt):
                        print ""
                        self.quit("Aborted by user")
                return line

        def start(self):
                launchpadID = self.__getLine("Please insert your Launchpad ID: ")
                ip = self.__getLine("Please insert your current IP: ")
                platformName = self.__getLine("Please, enter the name of the platform where you make pt: ")

                reportFilename = platformName + "-report.txt"

                # Opening coc file for reading and report file for writing
                cockFile = open(self.cocFilename, 'r')
                reportFile = open(reportFilename, 'w')
                # Writing coc file content to reportFile
                reportFile.write(cockFile.read())
                # Closing coc file
                cockFile.close()
                # Writing report intestation
                reportFile.write("Ubuntu Pentest Evangelist Informations:\n" \
                                + "USER: https://edge.launchpad.net/~" + launchpadID + "\n" \
                                + "IP: " + ip + "\n" \
                                + "* Starting Report for " + platformName + ":\n")
                # Closing report file
                reportFile.close()

                os.system(self.editor + " " + reportFilename)

                # gpg sign
                os.system("gpg --clearsign " + platformName + "-report.txt")

                # Deleting report file and renaming signed report file to report file name
                try:
                        os.remove(reportFilename)
                except OSError:
                        sys.exit(self.NAME + ": cannot remove `" + reportFilename + "'")
                try:
                        os.rename(reportFilename + ".asc", reportFilename)
                except OSError:
                        sys.exit(self.NAME + ": cannot rename file `" + reportFilename + ".asc' to `" + reportFilename + "'")

                # launchpd sending bug ... (we will add python-launchpad-bugs script for automated open bugs)

        def quit(self, msg):
                sys.exit(msg)

# ------------------------------------------------------------------------------
# Application START

if __name__ == "__main__":
        application = Application()