Example #1
0
def snmp_info():
  d = {}
  snmp_a = []
  snmp_strings = SnmpString.query.all()
  snmp_users = None
  snmp_groups = None
  community_strings = None
  snmp_info_form = SnmpInfo(request.form)
  edit_snmp_info_form = EditSnmpInfo(request.form)

  if request.method == 'GET':
    for s in snmp_strings:
      if s.snmp_user_encrypted is None:
        d = {'id': s.id,
             'community_string': decrypt_string(s.community_string_encrypted.encode("utf-8"),
                                                s.community_string_encrypted_salt.encode("utf-8")),
             'snmp_user': None,
             'snmp_group': None}
      if s.community_string_encrypted is None:
        d = {'id': s.id,
             'snmp_user': decrypt_string(s.snmp_user_encrypted.encode("utf-8"),
                                         s.snmp_user_encrypted_salt.encode("utf-8")),
             'snmp_group': decrypt_string(s.snmp_group_encrypted.encode("utf-8"),
                                          s.snmp_group_encrypted_salt.encode("utf-8")),
             'community_string': None}
      snmp_a.append(d)

  if request.method == 'POST':

    if snmp_info_form.validate_on_submit():
      if snmp_info_form.strings.data:
        s = snmp_info_form.strings.data

        for community_string in s.split(','):
          cs = SnmpString(community_string=community_string)

          try:
            db.session.add(cs)
            db.session.commit()
          except IntegrityError as e:
            db.session.rollback()
            flash(e)

      return redirect(url_for('settings.snmp_info'))

  return render_template('snmp_info.html',
                         snmp_a=snmp_a,
                         community_string=community_strings,
                         snmp_user=snmp_users,
                         snmp_group=snmp_groups,
                         snmp_info_form=snmp_info_form,
                         edit_snmp_info_form=edit_snmp_info_form)
Example #2
0
def seed_db():

  # Add seed data to the database

  days_of_the_week = ['Sunday',
                      'Monday',
                      'Tuesday',
                      'Wednesday',
                      'Thursday',
                      'Friday',
                      'Saturday']

  schedule_types = ['Discovery',
                    'Vulnerability']

  snmp_strings = ['public',
                  'private']

  time_zones = ['International Date Line West',
                'Midway Island',
                'American Samoa',
                'Hawaii',
                'Alaska',
                'Pacific Time (US & Canada)',
                'Tijuana',
                'Mountain Time (US & Canada)',
                'Arizona',
                'Chihuahua',
                'Mazatlan',
                'Central Time (US & Canada)',
                'Saskatchewan',
                'Guadalajara',
                'Mexico City',
                'Monterrey',
                'Central America',
                'Eastern Time (US & Canada)',
                'Indiana (East)',
                'Bogota',
                'Lima',
                'Quito',
                'Atlantic Time (Canada)',
                'Caracas',
                'La Paz',
                'Santiago',
                'Newfoundland',
                'Brasilia',
                'Buenos Aires',
                'Montevideo',
                'Georgetown',
                'Greenland',
                'Mid-Atlantic',
                'Azores',
                'Cape Verde Is.',
                'Dublin',
                'Edinburgh',
                'Lisbon',
                'London',
                'Casablanca',
                'Monrovia',
                'UTC',
                'Belgrade',
                'Bratislava',
                'Budapest',
                'Ljubljana',
                'Prague',
                'Sarajevo',
                'Skopje',
                'Warsaw',
                'Zagreb',
                'Brussels',
                'Copenhagen',
                'Madrid',
                'Paris',
                'Amsterdam',
                'Berlin',
                'Bern',
                'Rome',
                'Stockholm',
                'Vienna',
                'West Central Africa',
                'Bucharest',
                'Cairo',
                'Helsinki',
                'Kyiv',
                'Riga',
                'Sofia',
                'Tallinn',
                'Vilnius',
                'Athens',
                'Istanbul',
                'Minsk',
                'Jerusalem',
                'Harare',
                'Pretoria',
                'Kaliningrad',
                'Moscow',
                'St. Petersburg',
                'Vtzolgograd',
                'Samara',
                'Kuwait',
                'Riyadh',
                'Nairobi',
                'Baghdad',
                'Tehran',
                'Abu Dhabi',
                'Muscat',
                'Baku',
                'Tbilisi',
                'Yerevan',
                'Kabul',
                'Ekaterinburg',
                'Islamabad',
                'Karachi',
                'Tashkent',
                'Chennai',
                'Kolkata',
                'Mumbai',
                'New Delhi',
                'Kathmandu',
                'Astana',
                'Dhaka',
                'Sri Jayawardenepura',
                'Almaty',
                'Novosibirsk',
                'Rtzangoon',
                'Bangkok',
                'Hanoi',
                'Jakarta',
                'Krasnoyarsk',
                'Beijing',
                'Chongqing',
                'Hong Kong',
                'Urumqi',
                'Kuala Lumpur',
                'Singapore',
                'Taipei',
                'Perth',
                'Irkutsk',
                'Ulaanbaatar',
                'Seoul',
                'Osaka',
                'Sapporo',
                'Tokyo',
                'Yakutsk',
                'Darwin',
                'Adelaide',
                'Canberra',
                'Melbourne',
                'Sydney',
                'Brisbane',
                'Hobart',
                'Vladivostok',
                'Guam',
                'Port Moresby',
                'Magadan',
                'Srednekolymsk',
                'Solomon Is.',
                'New Caledonia',
                'Fiji',
                'Kamchatka',
                'Marshall Is.',
                'Auckland',
                'Wellington',
                "Nuku'alofa",
                'Tokelau Is.',
                'Chatham Is.',
                'Samoa']

  default_admin = AppUser(username='******',
                          password='******',
                          email='*****@*****.**',
                          firstname='Admin',
                          lastname='Istrator',
                          phone='5558765309',
                          company='ACME, Inc.')

  strings = SnmpString.query.all()
  community_strings = list()

  if strings:
    for s in strings:
      community_string = decrypt_string(s.community_string_encrypted.encode("utf-8"),
                                        s.community_string_encrypted_salt.encode("utf-8"))
      if community_string.decode() not in community_strings:
        community_strings.append(community_string.decode())

  for element in snmp_strings:
    try:
      if element not in community_strings:
        c = SnmpString(community_string=element)
        db.session.add(c)
        db.session.commit()
    except IntegrityError:
      db.session.rollback()

  try:
    db.session.add(default_admin)
    db.session.commit()
  except IntegrityError:
    db.session.rollback()

  for element in days_of_the_week:
    try:
      d = DayOfTheWeek(name=element)
      db.session.add(d)
      db.session.commit()
    except IntegrityError:
      db.session.rollback()

  for element in schedule_types:
    try:
      sch = ScheduleType(name=element)
      db.session.add(sch)
      db.session.commit()
    except IntegrityError:
      db.session.rollback()

  for element in time_zones:
    try:
      tz = TimeZones(name=element)
      db.session.add(tz)
      db.session.commit()
    except IntegrityError:
      db.session.rollback()