class VulnerabilityDialog(wx.Dialog):
  def __init__(self,parent,parameters):
    wx.Dialog.__init__(self,parent,parameters.id(),parameters.label(),style=wx.DEFAULT_DIALOG_STYLE|wx.MAXIMIZE_BOX|wx.THICK_FRAME|wx.RESIZE_BORDER,size=(500,400))

    self.theVulnerabilityId = -1
    self.theName = ''
    self.theType = ''
    self.theDescription = ''
    self.theTags = []
    self.theEnvironmentProperties = []
    self.panel = 0
    self.buildControls(parameters)
    self.theCommitVerb = 'Add'

  def buildControls(self,parameters): 
    mainSizer = wx.BoxSizer(wx.VERTICAL)
    self.panel = VulnerabilityPanel(self)
    self.panel.buildControls(parameters.createFlag())
    mainSizer.Add(self.panel,1,wx.EXPAND)
    self.SetSizer(mainSizer)
    wx.EVT_BUTTON(self,armid.VULNERABILITY_BUTTONCOMMIT_ID,self.onCommit)

  def load(self,vulnerability):
    self.theVulnerabilityId = vulnerability.id()
    self.panel.loadControls(vulnerability)
    self.theCommitVerb = 'Edit'

  def onCommit(self,evt):
    nameCtrl = self.FindWindowById(armid.VULNERABILITY_TEXTNAME_ID)
    tagCtrl = self.FindWindowById(armid.VULNERABILITY_TAGS_ID)
    typeCtrl = self.FindWindowById(armid.VULNERABILITY_COMBOTYPE_ID)
    dnCtrl = self.FindWindowById(armid.VULNERABILITY_TEXTDESCRIPTION_ID)
    environmentCtrl = self.FindWindowById(armid.VULNERABILITY_PANELENVIRONMENT_ID)

    self.theName = nameCtrl.GetValue()
    if (self.theCommitVerb == 'Add'):
      b = Borg()
      try:
        b.dbProxy.nameCheck(self.theName,'vulnerability')
      except ARM.ARMException,errorText:
        dlg = wx.MessageDialog(self,str(errorText),'Add vulnerability',wx.OK | wx.ICON_ERROR)
        dlg.ShowModal()
        dlg.Destroy()
        return

    self.theType = typeCtrl.GetValue()
    self.theTags = tagCtrl.tags()
    self.theDescription = dnCtrl.GetValue()
    self.theEnvironmentProperties = environmentCtrl.environmentProperties()

    commitLabel = self.theCommitVerb + ' vulnerability'

    if len(self.theName) == 0:
      dlg = wx.MessageDialog(self,'Vulnerability name cannot be empty',commitLabel,wx.OK) 
      dlg.ShowModal()
      dlg.Destroy()
      return
    if len(self.theType) == 0:
      dlg = wx.MessageDialog(self,'Vulnerability type cannot be empty',commitLabel,wx.OK) 
      dlg.ShowModal()
      dlg.Destroy()
      return
    elif len(self.theDescription) == 0:
      dlg = wx.MessageDialog(self,'Vulnerability description cannot be empty',commitLabel,wx.OK) 
      dlg.ShowModal()
      dlg.Destroy()
      return
    else:
      for environmentProperties in self.theEnvironmentProperties:
        if len(environmentProperties.severity()) == 0:
          errorTxt = 'No severity associated with environment ' + environmentProperties.name()
          dlg = wx.MessageDialog(self,errorTxt,commitLabel,wx.OK)
          dlg.ShowModal()
          dlg.Destroy()
          return
      self.EndModal(armid.VULNERABILITY_BUTTONCOMMIT_ID)
Beispiel #2
0
class VulnerabilityDialog(wx.Dialog):
    def __init__(self, parent, parameters):
        wx.Dialog.__init__(self,
                           parent,
                           parameters.id(),
                           parameters.label(),
                           style=wx.DEFAULT_DIALOG_STYLE | wx.MAXIMIZE_BOX
                           | wx.THICK_FRAME | wx.RESIZE_BORDER,
                           size=(500, 400))

        self.theVulnerabilityId = -1
        self.theName = ''
        self.theType = ''
        self.theDescription = ''
        self.theTags = []
        self.theEnvironmentProperties = []
        self.panel = 0
        self.buildControls(parameters)
        self.theCommitVerb = 'Add'

    def buildControls(self, parameters):
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        self.panel = VulnerabilityPanel(self)
        self.panel.buildControls(parameters.createFlag())
        mainSizer.Add(self.panel, 1, wx.EXPAND)
        self.SetSizer(mainSizer)
        wx.EVT_BUTTON(self, armid.VULNERABILITY_BUTTONCOMMIT_ID, self.onCommit)

    def load(self, vulnerability):
        self.theVulnerabilityId = vulnerability.id()
        self.panel.loadControls(vulnerability)
        self.theCommitVerb = 'Edit'

    def onCommit(self, evt):
        nameCtrl = self.FindWindowById(armid.VULNERABILITY_TEXTNAME_ID)
        tagCtrl = self.FindWindowById(armid.VULNERABILITY_TAGS_ID)
        typeCtrl = self.FindWindowById(armid.VULNERABILITY_COMBOTYPE_ID)
        dnCtrl = self.FindWindowById(armid.VULNERABILITY_TEXTDESCRIPTION_ID)
        environmentCtrl = self.FindWindowById(
            armid.VULNERABILITY_PANELENVIRONMENT_ID)

        self.theName = nameCtrl.GetValue()
        if (self.theCommitVerb == 'Add'):
            b = Borg()
            try:
                b.dbProxy.nameCheck(self.theName, 'vulnerability')
            except ARM.ARMException, errorText:
                dlg = wx.MessageDialog(self, str(errorText),
                                       'Add vulnerability',
                                       wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
                return

        self.theType = typeCtrl.GetValue()
        self.theTags = tagCtrl.tags()
        self.theDescription = dnCtrl.GetValue()
        self.theEnvironmentProperties = environmentCtrl.environmentProperties()

        commitLabel = self.theCommitVerb + ' vulnerability'

        if len(self.theName) == 0:
            dlg = wx.MessageDialog(self, 'Vulnerability name cannot be empty',
                                   commitLabel, wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
            return
        if len(self.theType) == 0:
            dlg = wx.MessageDialog(self, 'Vulnerability type cannot be empty',
                                   commitLabel, wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
            return
        elif len(self.theDescription) == 0:
            dlg = wx.MessageDialog(
                self, 'Vulnerability description cannot be empty', commitLabel,
                wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
            return
        else:
            for environmentProperties in self.theEnvironmentProperties:
                if len(environmentProperties.severity()) == 0:
                    errorTxt = 'No severity associated with environment ' + environmentProperties.name(
                    )
                    dlg = wx.MessageDialog(self, errorTxt, commitLabel, wx.OK)
                    dlg.ShowModal()
                    dlg.Destroy()
                    return
            self.EndModal(armid.VULNERABILITY_BUTTONCOMMIT_ID)