ptreport
Differences between revisions 7 and 8
4382
Comment:
|
4390
|
Deletions are marked like this. | Additions are marked like this. |
Line 7: | Line 7: |
{{{ | {{{#!python |
anateater V 0.1 alpha [http://thc.emanuele-gentili.com/~emgent/anateater/anteater.py anateater.py]
1 #!/usr/bin/env python
2
3 # anteater V 0.1 Alpha
4 # (C) 2008 Ubuntu Pentest, Emanuele Gentili
5 # Authors
6 # Emanuele Gentili <emgent@emanuele-gentili.com>
7 # Giorgio Carlo Gigli Tos <gionnyboss@gmail.com>
8 # GPLv2, see /usr/share/common-licenses/GPL
9
10 import sys
11 import os
12 from stat import *
13 import re
14
15 class Application():
16 NAME = "anteater.py"
17 VERSION = 0.1
18 AUTHORS = \
19 "Emanuele Gentili (emgent)\n" \
20 + "Giorgio Carlo Gili Tos (GionnyBoss)"
21
22 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" \
23 + "There is NO WARRANTY, to the extent permitted by law."
24
25 cocFilename = "coc.txt"
26 editor = "nano"
27
28
29 def __init__(self):
30
31 self.__getOptions()
32
33 # Displaying code of conduct
34 os.system("more " + self.cocFilename)
35
36 while True:
37 reply = self.__getLine("Do you accept Ubuntu Code of Conduct? [y,n] ")
38 if re.match("^\s*y\s*$", reply, re.IGNORECASE):
39 break
40 elif re.match("^\s*n\s*$", reply, re.IGNORECASE):
41 sys.exit("You did not accept Ubuntu Code of Conduct.\nExiting application...")
42
43 self.start()
44
45 # Get command line options
46 def __getOptions(self):
47
48 from optparse import OptionParser
49
50 usage = self.NAME + " [OPTION]..."
51 version = self.NAME + " " + str(self.VERSION) + "\n" + self.LICENSE + "\n\nWritten by " + self.AUTHORS
52 description = "Application description"
53
54 parser = OptionParser(usage=usage, version=version, description=description)
55 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")
56 (options, args) = parser.parse_args()
57
58 self.editor = options.editor
59 # Checking if editor exists in path
60 pathDirs = os.environ['PATH'].split(":")
61
62 editorValid = False
63 for dir in pathDirs:
64 file = os.path.join(dir, self.editor)
65 if os.path.isfile(file):
66 mode = os.stat(file)[ST_MODE]
67 # Checking if file is executable to Others
68 # TODO - Think if there is a better way to do this.
69 if (S_IMODE(mode) & S_IXOTH) == S_IXOTH:
70 editorValid = True
71 break
72
73 if not editorValid:
74 sys.exit(self.NAME + ": specified editor `" + self.editor + "' is not in your path")
75
76 def __getLine(self, text):
77
78 try:
79 line = raw_input(text)
80 except (EOFError, KeyboardInterrupt):
81 print ""
82 self.quit("Aborted by user")
83 return line
84
85 def start(self):
86 launchpadID = self.__getLine("Please insert your Launchpad ID: ")
87 ip = self.__getLine("Please insert your current IP: ")
88 platformName = self.__getLine("Please, enter the name of the platform where you make pt: ")
89
90 reportFilename = platformName + "-report.txt"
91
92 # Opening coc file for reading and report file for writing
93 cockFile = open(self.cocFilename, 'r')
94 reportFile = open(reportFilename, 'w')
95 # Writing coc file content to reportFile
96 reportFile.write(cockFile.read())
97 # Closing coc file
98 cockFile.close()
99 # Writing report intestation
100 reportFile.write("Ubuntu Pentest Evangelist Informations:\n" \
101 + "USER: https://edge.launchpad.net/~" + launchpadID + "\n" \
102 + "IP: " + ip + "\n" \
103 + "* Starting Report for " + platformName + ":\n")
104 # Closing report file
105 reportFile.close()
106
107 os.system(self.editor + " " + reportFilename)
108
109 # gpg sign
110 os.system("gpg --clearsign " + platformName + "-report.txt")
111
112 # Deleting report file and renaming signed report file to report file name
113 try:
114 os.remove(reportFilename)
115 except OSError:
116 sys.exit(self.NAME + ": cannot remove `" + reportFilename + "'")
117 try:
118 os.rename(reportFilename + ".asc", reportFilename)
119 except OSError:
120 sys.exit(self.NAME + ": cannot rename file `" + reportFilename + ".asc' to `" + reportFilename + "'")
121
122 # launchpd sending bug ... (we will add python-launchpad-bugs script for automated open bugs)
123
124 def quit(self, msg):
125 sys.exit(msg)
126
127 # ------------------------------------------------------------------------------
128 # Application START
129
130 if __name__ == "__main__":
131 application = Application()
UbuntuPentest/ptreport (last edited 2008-08-06 16:40:37 by localhost)