Exemplo n.º 1
0
def importSecurityPatterns(importFile, session_id=None):
  parser = xml.sax.make_parser()
  handler = SecurityPatternContentHandler()
  parser.setContentHandler(handler)
  parser.setEntityResolver(handler)
  parser.parse(importFile)
  taps = handler.assets()
  spps = handler.patterns()
  noOfTaps = len(taps)
  noOfSpps = len(spps)

  b = Borg()
  db_proxy = b.get_dbproxy()

  msgStr = 'No patterns imported'
  if (noOfTaps > 0):
    tapId = 0;
    db_proxy.deleteSecurityPattern(-1)
    db_proxy.deleteTemplateAsset(-1)
    for tap in taps:
      tap.setId(tapId)
      db_proxy.addTemplateAsset(tap)
      tapId += 1

    if (noOfSpps > 0):
      spId = 0;
      db_proxy.deleteSecurityPattern(-1)
      for sp in spps:
        sp.setId(spId)
        db_proxy.addSecurityPattern(sp)
        spId += 1
      msgStr =  'Imported ' + str(noOfTaps) + ' template assets and ' + str(noOfSpps) + ' security patterns'
  return msgStr
Exemplo n.º 2
0
def importSecurityPatterns(importFile, session_id=None):
    parser = xml.sax.make_parser()
    handler = SecurityPatternContentHandler()
    parser.setContentHandler(handler)
    parser.setEntityResolver(handler)
    parser.parse(importFile)
    taps = handler.assets()
    spps = handler.patterns()
    noOfTaps = len(taps)
    noOfSpps = len(spps)

    b = Borg()
    db_proxy = b.get_dbproxy()

    msgStr = 'No patterns imported'
    if (noOfTaps > 0):
        tapId = 0
        db_proxy.deleteSecurityPattern(-1)
        db_proxy.deleteTemplateAsset(-1)
        for tap in taps:
            tap.setId(tapId)
            db_proxy.addTemplateAsset(tap)
            tapId += 1

        if (noOfSpps > 0):
            spId = 0
            db_proxy.deleteSecurityPattern(-1)
            for sp in spps:
                sp.setId(spId)
                db_proxy.addSecurityPattern(sp)
                spId += 1
            msgStr = 'Imported ' + str(
                noOfTaps) + ' template assets and ' + str(
                    noOfSpps) + ' security patterns'
    return msgStr
Exemplo n.º 3
0
def importSecurityPatternsFile(importFile, session_id=None):
    try:
        parser = xml.sax.make_parser()
        handler = SecurityPatternContentHandler()
        parser.setContentHandler(handler)
        parser.setEntityResolver(handler)
        parser.parse(importFile)
        taps = handler.assets()
        spps = handler.patterns()
        vts = handler.metricTypes()
        return importSecurityPatterns(taps, spps, vts, session_id)
    except xml.sax.SAXException, e:
        raise ARMException("Error parsing" + importFile + ": " +
                           e.getMessage())
Exemplo n.º 4
0
def importSecurityPatterns(importFile,session_id=None):
  try:
    parser = xml.sax.make_parser()
    handler = SecurityPatternContentHandler()
    parser.setContentHandler(handler)
    parser.setEntityResolver(handler)
    parser.parse(importFile)
    taps = handler.assets()
    spps = handler.patterns()
    vts = handler.metricTypes()
    noOfTaps = len(taps)
    noOfSpps = len(spps)

    b = Borg()
    db_proxy = b.get_dbproxy(session_id)

    msgStr = 'No patterns imported'
    if (noOfTaps > 0):
      tapId = 0;
      db_proxy.deleteSecurityPattern(-1)
      db_proxy.deleteTemplateAsset(-1)

      for vt in vts:
        db_proxy.addValueType(vt)

      for tap in taps:
        tap.setId(tapId)
        db_proxy.addTemplateAsset(tap)
        tapId += 1

      if (noOfSpps > 0):
        spId = 0;
        db_proxy.deleteSecurityPattern(-1)
        for sp in spps:
          sp.setId(spId)
          db_proxy.addSecurityPattern(sp)
          spId += 1
        msgStr =  'Imported ' + str(noOfTaps) + ' template assets and ' + str(noOfSpps) + ' security patterns'
    return msgStr
  except xml.sax.SAXException, e:
    raise ARMException("Error parsing" + importFile + ": " + e.getMessage())
Exemplo n.º 5
0
def importSecurityPatterns(importFile,session_id=None):
  try:
    parser = xml.sax.make_parser()
    handler = SecurityPatternContentHandler()
    parser.setContentHandler(handler)
    parser.setEntityResolver(handler)
    parser.parse(importFile)
    taps = handler.assets()
    spps = handler.patterns()
    vts = handler.metricTypes()
    noOfTaps = len(taps)
    noOfSpps = len(spps)

    b = Borg()
    db_proxy = b.get_dbproxy(session_id)

    msgStr = 'No patterns imported'
    if (noOfTaps > 0):
      tapId = 0;
      db_proxy.deleteSecurityPattern(-1)
      db_proxy.deleteTemplateAsset(-1)

      for vt in vts:
        db_proxy.addValueType(vt)

      for tap in taps:
        tap.setId(tapId)
        db_proxy.addTemplateAsset(tap)
        tapId += 1

      if (noOfSpps > 0):
        spId = 0;
        db_proxy.deleteSecurityPattern(-1)
        for sp in spps:
          sp.setId(spId)
          db_proxy.addSecurityPattern(sp)
          spId += 1
        msgStr =  'Imported ' + str(noOfTaps) + ' template assets and ' + str(noOfSpps) + ' security patterns'
    return msgStr
  except xml.sax.SAXException, e:
    raise ARMException("Error parsing" + importFile + ": " + e.getMessage())