Skip to content

Commit

Permalink
New features and Bug Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Anof-cyber authored Apr 18, 2022
1 parent 5b46552 commit c3694f2
Showing 1 changed file with 143 additions and 46 deletions.
189 changes: 143 additions & 46 deletions PentestMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from java.awt import BorderLayout, FlowLayout
from javax import swing
from java import awt
import java.lang.Short
from java.lang import Short
from javax.swing import JMenuItem
import csv
from java.lang import String, Integer, Comparable
Expand Down Expand Up @@ -87,19 +87,20 @@ def registerExtenderCallbacks(self, callbacks):
# Creating a Import button in CheckList Tab

self.buttonPanel = swing.JPanel()
self.buttonPanel.setPreferredSize(Dimension(0, 30))

#self.buttonPanel.setPreferredSize(Dimension(0, 30))
# adding the import button with onclick action which refers to the function below
self.buttonPanel.add(swing.JButton(
"Import CheckList", actionPerformed=self.importchecklist))
self.buttonPanel.add(Box.createRigidArea(Dimension(35, 0)))
#self.firstTab.add(Box.createRigidArea(Dimension(35, 0)))
self.buttonPanel.add(swing.JButton(
"Create CheckList", actionPerformed=self.createtestcases))
self.firstTab.add(self.buttonPanel, BorderLayout.PAGE_START)

# Creating a tab in CheckList tab which will show the data from the import checlist
self.tablePanel = swing.JPanel()
layout = GroupLayout(self.tablePanel)
self.tablePanel.setLayout(layout)
#layout = GroupLayout(self.tablePanel)
#self.tablePanel.setLayout(layout)
self.colNames = ('Sr', 'Test-Cases')
self.data = [['', ''], ]
self.dataModel = CustomDefaultTableModelHosts(None, self.colNames)
Expand All @@ -109,11 +110,11 @@ def registerExtenderCallbacks(self, callbacks):
self.scrollPane = JScrollPane(self.table)
X_BASE2 = 200 # send to leff
# 3rd one send to right
self.scrollPane.setBounds(X_BASE2 + 100, 40, 1200, 800)
self.scrollPane.setPreferredSize(Dimension(1500, 500))
#self.scrollPane.setBounds(X_BASE2 + 100, 80, 1200, 800)
#self.scrollPane.setPreferredSize(Dimension(1500, 500))
self.scrollPane.getViewport().setView((self.table))
self.tablePanel.add(self.scrollPane)
self.firstTab.add(self.tablePanel, BorderLayout.CENTER)
#self.tablePanel.add(self.scrollPane)
self.firstTab.add(self.scrollPane, BorderLayout.CENTER)

# Creating Second Tab
self.secondTab = swing.JPanel()
Expand All @@ -123,21 +124,21 @@ def registerExtenderCallbacks(self, callbacks):

# creating UI for button and button in api mapper tab
self.buttonPanel2 = swing.JPanel()
self.buttonPanel2.setPreferredSize(Dimension(0, 30))
#self.buttonPanel2.setPreferredSize(Dimension(0, 30))

# adding the import button with onclick action which refers to the function below
self.buttonPanel2.add(swing.JButton(
"Save Project", actionPerformed=self.savelogger))
self.buttonPanel2.add(Box.createRigidArea(Dimension(35, 0)))
#self.buttonPanel2.add(Box.createRigidArea(Dimension(35, 0)))
self.buttonPanel2.add(swing.JButton(
"Load Project", actionPerformed=self.importlogger))
self.secondTab.add(self.buttonPanel2, BorderLayout.PAGE_START)


# Creating a UI for table in api mapper tab
self.tablePanel2 = swing.JPanel((FlowLayout(FlowLayout.LEADING, 50, 50)))
layout = GroupLayout(self.tablePanel2)
self.tablePanel2.setLayout(layout)
self.tablePanel2 = swing.JPanel()
#layout = BorderLayout.CENTER(self.tablePanel2)
#self.tablePanel2.setLayout(layout)


# not in use still not removed
Expand Down Expand Up @@ -168,11 +169,11 @@ def registerExtenderCallbacks(self, callbacks):
# allowed colum size for api mapper tab/table
self.logTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
self.logTable.getTableHeader().setReorderingAllowed(False)
self.logTable.getColumnModel().getColumn(0).setPreferredWidth(100)
self.logTable.getColumnModel().getColumn(1).setPreferredWidth(600)
self.logTable.getColumnModel().getColumn(2).setPreferredWidth(100)
self.logTable.getColumnModel().getColumn(3).setPreferredWidth(800)
self.logTable.getColumnModel().getColumn(4).setPreferredWidth(300)
self.logTable.getColumnModel().getColumn(0).setPreferredWidth(25)
self.logTable.getColumnModel().getColumn(1).setPreferredWidth(400)
self.logTable.getColumnModel().getColumn(2).setPreferredWidth(50)
self.logTable.getColumnModel().getColumn(3).setPreferredWidth(750)
self.logTable.getColumnModel().getColumn(4).setPreferredWidth(142)
self.logTable.setRowSelectionAllowed(True)

#adding a right click menu in the table in api mapper
Expand All @@ -183,10 +184,10 @@ def registerExtenderCallbacks(self, callbacks):
# Creating a scroller for table in api mapper and also width hight for table
self.scrollPane2 = JScrollPane(self.logTable)
X_BASE3 = 1 # send to leff
self.scrollPane2.setBounds(X_BASE3 + 10, 20, 1900, 570) # 3rd one send to right
self.scrollPane2.setPreferredSize(Dimension(1500, 700))
#self.scrollPane2.setBounds(X_BASE3 + 10, 20, 1900, 570) # 3rd one send to right
#self.scrollPane2.setPreferredSize(Dimension(1500, 700))
self.scrollPane2.getViewport().setView((self.logTable))
self.tablePanel2.add(self.scrollPane2)
#self.tablePanel2.add(self.scrollPane2, BorderLayout.WEST)



Expand Down Expand Up @@ -233,7 +234,7 @@ def registerExtenderCallbacks(self, callbacks):

#spl.setTopComponent(self.tablePanel2)
#spl.setBottomComponent(self.editor_view) - replaced with left right
spl.setLeftComponent(self.tablePanel2)
spl.setLeftComponent(self.scrollPane2)
spl.setRightComponent(self.editor_view)
#spl.setBottomComponent(editorviews(self)) -replaced with left right

Expand All @@ -255,13 +256,14 @@ def registerExtenderCallbacks(self, callbacks):

# creating the button and button location and width in vulnerability tab
self.buttonPanel4 = swing.JPanel()
self.buttonPanel4.setPreferredSize(Dimension(0, 30))
#self.buttonPanel4.setPreferredSize(Dimension(0, 30))
# adding the import button with onclick action which refers to the function below
self.buttonPanel4.add(swing.JButton(
"Import Vulnerabilities", actionPerformed=self.importvulnerability))
self.buttonPanel4.add(Box.createRigidArea(Dimension(35, 0)))

#self.buttonPanel4.add(Box.createRigidArea(Dimension(35, 0)))
self.buttonPanel4.add(swing.JButton(
"Export Vulnerabilities", actionPerformed=self.exportvulnerability))
self.buttonPanel4.add(swing.JButton(
"Import Vulnerabilities", actionPerformed=self.importvulnerability))

# adding the button in vulnerability tab
self.ThirdTab.add(self.buttonPanel4, BorderLayout.PAGE_START)
Expand All @@ -270,8 +272,8 @@ def registerExtenderCallbacks(self, callbacks):

# creating the UI pannel for vulnerability tab --> table
self.tablePanel3 = swing.JPanel()
layout = GroupLayout(self.tablePanel3)
self.tablePanel3.setLayout(layout)
#layout = GroupLayout(self.tablePanel3)
#self.tablePanel3.setLayout(layout)


# Creating a jcombobox that will show the selection option, and adding and none or empty item for selection
Expand Down Expand Up @@ -309,38 +311,95 @@ def registerExtenderCallbacks(self, callbacks):
self.tablePanel3.add(self.scrollPane3)

# adding the table UI to vulnerability tab
self.ThirdTab.add(self.tablePanel3, BorderLayout.CENTER)
self.ThirdTab.add(self.scrollPane3, BorderLayout.CENTER)


self.FourthTab = swing.JPanel()
self.FourthTab.layout = BorderLayout()
self.tabbedPane.addTab("Config", self.FourthTab)
self.buttonPanel5 = swing.JPanel()
self.buttonPanel5.add(JLabel("Select Directory for Auto Save"))
self.buttonPanel5.add(swing.JButton(
"ChooseDirectory", actionPerformed=self.Autosavepath))
self.autosavepath = JLabel()
#autosavepath.setText("helloworld")
self.buttonPanel5.add(self.autosavepath)
self.timeperid = JLabel("Set Time Interval for Autosave (Minutes):")
self.buttonPanel5.add(Box.createRigidArea(Dimension(35, 0)))
self.timeperid.setBounds(170,600,100,40)
self.timerbox = JTextField(5)
#self.timerbox.setText("30")

layout = javax.swing.GroupLayout(self.buttonPanel5)
self.buttonPanel5.setLayout(layout)

jButton1 = swing.JButton("ChooseDirectory", actionPerformed=self.Autosavepath)
jLabel1 = javax.swing.JLabel()
button1 = swing.JButton("ChooseDirectory", actionPerformed=self.Autosavepath)
self.autosavepath = javax.swing.JLabel();
self.timeperid = javax.swing.JLabel();
self.timerbox = javax.swing.JTextField(5);
jLabel4 = javax.swing.JLabel();
button2 = swing.JButton("ChooseDirectory", actionPerformed=self.Autosavepath2)

self.saveconfigbutton = swing.JButton("Save Config", actionPerformed=self.saveautoconfigdata)
self.buttonPanel5.add(self.timeperid)
self.buttonPanel5.add(self.timerbox)
self.buttonPanel5.add(self.saveconfigbutton)
self.FourthTab.add(self.buttonPanel5,BorderLayout.PAGE_START)
jLabel1.setText("Select the Auto Save Output Directory")

self.timeperid.setText("Set the Time Interval for Auto Save");

self.timerbox.setText("self.timerbox");

jLabel4.setText("Select Auto Load Checklist File")

layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(layout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(self.autosavepath))
.addComponent(jLabel4)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(self.saveconfigbutton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(self.timeperid)))
.addComponent(self.autosavepath)
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(self.timerbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(button2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(button1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(530, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(self.autosavepath))
.addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(self.timeperid)
.addComponent(self.timerbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(button2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(16, 16, 16)
.addComponent(self.saveconfigbutton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(self.autosavepath)
.addContainerGap(348, Short.MAX_VALUE))
);



self.FourthTab.add(self.buttonPanel5)#,BorderLayout.NORTH)
#self.FourthTab.add(self.buttonPanel6, BorderLayout.PAGE_START)
#self.FourthTab.add(self.buttonPanel7,BoxLayout.Y_AXIS)

self.path = callbacks.loadExtensionSetting('path')
self.time = callbacks.loadExtensionSetting('time')
self.checklistpath = callbacks.loadExtensionSetting('checklistpath')
self.timerbox.setText(self.time)
self.autosavepath.setText(self.path)

self.callbacks.printOutput(self.time)
self.callbacks.printOutput(self.path)

self.autoloadchecklist = 0
self.autosavelocation = 0
self.extensionload = True
if self.time == None:
Expand All @@ -355,6 +414,26 @@ def registerExtenderCallbacks(self, callbacks):
else:
pass

if not self.checklistpath == None:
self.comboBox.removeAllItems()
self.comboBox.addItem(None)
self.dataModel.setRowCount(0)
with open(self.checklistpath, 'rb') as f:
reader2 = csv.reader(f, delimiter=',')
#self.data1 = list(reader)
for rows in reader2:
SR = rows[0]
title = rows[1]
obj = [SR,title]
#checklistlog.append(title)
#rowsss = self.dataModel.getRowCount()
#self.callbacks.printOutput(str(rowsss))
self.dataModel.addRow(obj)
self.comboBox.addItem(str(title))
f.close()



#while self.extensionload == True:

#self.t = Timer(int(self.time) * 60, self.timer)
Expand Down Expand Up @@ -425,18 +504,36 @@ def Autosavepath(self,e):
#self.callbacks.printOutput(str(self.filepath2))
return str(self.autosavelocation)



def Autosavepath2(self,e):

chooseFile = JFileChooser()
filter = FileNameExtensionFilter("csv files", ["csv"])
chooseFile.addChoosableFileFilter(filter)

ret = chooseFile.showDialog(self.tab, "Choose file")
if ret == JFileChooser.APPROVE_OPTION:
fileLoad = chooseFile.getSelectedFile()
self.autoloadchecklist = fileLoad.getAbsolutePath()
return str(self.autoloadchecklist)

def saveautoconfigdata(self,e):
#path = self.Autosavepath
#self.callbacks.printOutput(str(path))
if self.autoloadchecklist == 0:
self.autoloadchecklist = None
if self.autosavelocation == 0:
self.autosavepath.setText("Please select the valid path!")
else:
#self.t.cancel()
#self.t.join()
self.callbacks.printOutput(str(self.autosavelocation))
self.callbacks.printOutput(str(self.autoloadchecklist))
self.callbacks.printOutput(str(self.timerbox.getText()))
self.callbacks.saveExtensionSetting("path", str(self.autosavelocation))
self.callbacks.saveExtensionSetting("time", self.timerbox.getText())
self.callbacks.saveExtensionSetting("checklistpath", str(self.autoloadchecklist))
self.autosavepath.setText(str(self.autosavelocation))
self.path = self.callbacks.loadExtensionSetting('path')
self.time = self.callbacks.loadExtensionSetting('time')
Expand Down

0 comments on commit c3694f2

Please sign in to comment.