<commit_before>group_list = [
  ['admin', true],
  ['reseller', true],
  ['user', true]
]
group_list.each do |group|
  Group.new(name: group[0],
            enabled: group[1]).save
end

user_list = [
  ['Admin', 'admin', 'secret', true, 'admin'],
  ['<NAME>', 'fox', 'geheim', true, 'admin'],
  ['<NAME>', 'max', 'muster', true, 'user'],
  ['Customer 1', 'customer1', 'customer1', true, 'user'],
  ['Customer 2', 'customer2', 'customer2', true, 'user'],
  ['Customer 3', 'customer3', 'customer3', true, 'user'],
  ['Reseller 1', 'reseller1', 'reseller1', true, 'reseller',
   %w(customer1 customer2 customer3)],
  ['Customer 4', 'customer4', 'customer4', true, 'user'],
  ['Customer 5', 'customer5', 'customer5', true, 'user'],
  ['Reseller 2', 'reseller2', 'reseller2', true, 'reseller',
   %w(customer4 customer5)]
]
user_list.each do |user|
  g = Group.first(name: user[4])
  u = User.new(name: user[0],
               login: user[1],
               password: <PASSWORD>[2],
               enabled: user[3],
               group: g)

  if g.name == 'reseller'
    user[5].each do |client|
      u.customers << User.first(login: client)
    end
  end
  u.save
end

domain_list = [
  ['foobar.com', true, true, true, 'admin'],
  ['foxxx0.de', true, true, true, 'fox'],
  ['example.net', true, true, true, 'max'],
  ['herpderp.org', true, true, true, 'customer1'],
  ['schalala.net', true, true, true, 'customer2'],
  ['everything.eu', true, true, true, 'customer3'],
  ['archlinux.sexy', true, true, true, 'reseller1'],
  ['kernel.org', true, true, true, 'reseller1'],
  ['serious.business', true, true, true, 'customer4'],
  ['big.company', true, true, true, 'customer5']
]
domain_list.each do |domain|
  Domain.new(name: domain[0],
             mail_enabled: domain[1],
             dns_enabled: domain[2],
             enabled: domain[3],
             user: User.first(login: domain[4])).save
end

mailaccount_list = [
  ['<EMAIL>', 'topsecret!', 1_048_576, 'Dwarf', true, false],
  ['<EMAIL>', 'penis', 10_485_760, 'Smurf', true, true],
  ['<EMAIL>', 'senf1979', 1_048_576, 'Myself', false, true],
  ['<EMAIL>', 'folldohf', 10_485_760, 'Nagios', true, true],
  ['<EMAIL>', 'derp1234', 269_715_200, '<NAME>', true, true],
  ['<EMAIL>', '9876543210', 10_485_760, '<NAME>', true, true],
  ['<EMAIL>', '!abcd?', 536_870_912, '<NAME>', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Customer 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Foo Customer 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Bar Customer 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Customer 2', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Herp Customer 2', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Derp Customer 2', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Customer 3', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Me Customer 3', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'He Customer 3', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'She Customer 3', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Reseller 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Reseller 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Reseller 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Reseller 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Support Reseller 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Customer 4', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Sarah Customer 4', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Customer 4', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Customer 5', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Carl Customer 5', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Steven Customer 5', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Customer 5', true, true]
]
mailaccount_list.each do |mailaccount|
  MailAccount.new(email: mailaccount[0],
                  password: <PASSWORD>(mailaccount[1]),
                  receiving_enabled: mailaccount[4],
                  quota: mailaccount[2],
                  enabled: mailaccount[5],
                  domain: Domain.first(name: mailaccount[0].split('@')[1]),
                  realname: mailaccount[3]).save
end

mailalias_mailaccount_list = [
  ['<EMAIL>', %w(<EMAIL> <EMAIL> <EMAIL>)],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['reseller<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>']
]
mailalias_mailaccount_list.each do |mals_macc|
  MailAlias.new(
    address: mals_macc[0],
    enabled: true,
    domain: Domain.first(name: mals_macc[0].split('@')[1])
  ).save
  [*mals_macc[1]].each do |macc|
    acc = MailAccount.first(email: macc)
    acc.mail_aliases << MailAlias.first(address: mals_macc[0])
    acc.save
  end
end

mailsource_mailaccount_list = [
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', %w(<EMAIL> <EMAIL> <EMAIL>)],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>']
]
mailsource_mailaccount_list.each do |msrc_macc|
  MailSource.new(address: msrc_macc[0],
                 enabled: true,
                 domain: Domain.first(name: msrc_macc[0].split('@')[1])).save
  [*msrc_macc[1]].each do |macc|
    acc = MailAccount.first(email: macc)
    acc.mail_sources << MailSource.first(address: msrc_macc[0])
    acc.save
  end
end

# DKIM keys
Domain.all.each do |d|
  dkim = Dkim.new(domain: d, enabled: true)
  dkim.selector = 'mail'
  dkim.private_key = <<-EOF
-----BEGIN RSA PRIVATE KEY-----
some random private characters.......
-----END RSA PRIVATE KEY-----
EOF
  dkim.public_key = <<-EOF
-----BEGIN PUBLIC KEY-----
some random public characters.......
-----END PUBLIC KEY-----
EOF
  dkim.save
end

# DKIM author <-> key assignment
Dkim.all.each do |dk|
  DkimSigning.new(author: dk.domain.name,
                  dkim: dk,
                  enabled: true).save
end

php_rt_list = [
  ['none', '0.0'],
  ['php56', '5.6.22'],
  ['php7', '7.0.7']
]
php_rt_list.each do |php_rt|
  PhpRuntime.new(name: php_rt[0],
                 version: php_rt[1],
                 enabled: true).save
end

ipv4_list = [
  ['127.0.0.1', User.all.map(&:login)],
  ['10.1.1.1', User.all.map(&:login)],
  ['10.2.2.2', %w(customer1 customer2)],
  ['10.2.2.3', %w(customer3)],
  ['10.3.3.3', %w(reseller2 customer4)],
  ['10.4.4.4', %w(max)]
]
ipv4_list.each do |ipv4|
  users = User.all(id: 0)
  ipv4[1].each do |u|
    users.concat(User.all(login: u))
  end
  Ipv4Address.new(address: IPAddr.new(ipv4[0]),
                  enabled: true,
                  users: users).save
end

ipv6_list = [
  ['::1', User.all.map(&:login)],
  ['fe80::dead:beef', User.all.map(&:login)],
  ['fe80::beef:1', %w(reseller1 customer1 customer2)],
  ['fe80::beef:2', %w(reseller1)],
  ['fe80::beef:3', %w(reseller2 customer4)],
  ['fe80::beef:4', %w(max)]
]
ipv6_list.each do |ipv6|
  users = User.all(id: 0)
  ipv6[1].each { |u| users.concat(User.all(login: u)) }
  Ipv6Address.new(address: IPAddr.new(ipv6[0]),
                  enabled: true,
                  users: users).save
end

vhost_list = [
  ['foxxx0.de', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'fox'],
  ['ipv4.foxxx0.de', :vhost, '10.1.1.1', '::1', true, 'php7', true, 'fox'],
  ['ipv6.foxxx0.de', :vhost, '127.0.0.1', 'fe80::dead:beef', true, 'php7', true, 'fox'],
  ['paste.foxxx0.de', :vhost, '10.1.1.1', 'fe80::dead:beef', true, 'php7', true, 'fox'],
  ['p.foxxx0.de', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'paste.foxxx0.de', true, 'fox'],
  ['blog.foxxx0.de', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'fox'],
  ['example.net', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'max'],
  ['mail.example.net', :vhost, '10.4.4.4', 'fe80::beef:4', true, 'php56', true, 'max'],
  ['webmail.example.net', :alias, :permanent, '10.4.4.4', 'fe80::beef:4', 'mail.example.net', true, 'max'],
  ['herpderp.org', :vhost, '10.1.1.1', 'fe80::beef:1', false, 'none', true, 'customer1'],
  ['test.herpderp.org', :vhost, '10.2.2.2', 'fe80::beef:1', false, 'none', true, 'customer1'],
  ['sub.herpderp.org', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'customer1'],
  ['schalala.net', :vhost, '10.2.2.2', 'fe80::beef:1', false, 'none', true, 'customer2'],
  ['test.schalala.net', :vhost, '10.2.2.2', 'fe80::dead:beef', false, 'none', true, 'customer2'],
  ['sub.schalala.net', :vhost, '10.1.1.1', 'fe80::beef:1', false, 'none', true, 'customer2'],
  ['everything.eu', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'customer3'],
  ['foo.everything.eu', :vhost, '10.2.2.3', 'fe80::dead:beef', false, 'none', true, 'customer3'],
  ['serious.business', :vhost, '10.3.3.3', 'fe80::beef:3', false, 'none', true, 'customer4'],
  ['big.company', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'customer5'],
  ['archlinux.sexy', :vhost, '10.2.2.3', 'fe80::beef:2', false, 'none', true, 'reseller1'],
  ['kernel.org', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'reseller1'],
  ['herp.herpderp.org', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'sub.herpderp.org', true, 'customer1'],
  ['derp.herpderp.org', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'sub.herpderp.org', true, 'customer1'],
  ['merp.herpderp.org', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'test.herpderp.org', true, 'customer1'],
  ['blerp.herpderp.org', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'test.herpderp.org', true, 'customer1'],
  ['bar.schalala.net', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'schalala.net', true, 'customer2'],
  ['xyz.schalala.net', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'schalala.net', true, 'customer2'],
  ['bla.everything.eu', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'everything.eu', true, 'customer3'],
  ['funny.serious.business', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'serious.business', true, 'customer4'],
  ['little.big.company', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'big.company', true, 'customer5'],
  ['cdn.archlinux.sexy', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'archlinux.sexy', true, 'reseller1'],
  ['login.herpderp.org', :alias, :temporary, '10.1.1.1', 'fe80::dead:beef', 'herpderp.org', true, 'customer1'],
  ['hodor.herpderp.org', :alias, :temporary, '10.1.1.1', 'fe80::dead:beef', 'herpderp.org', true, 'customer1'],
  ['moved.herpderp.org', :alias, :permanent, '10.1.1.1', 'fe80::dead:beef', 'herpderp.org', true, 'customer1'],
  ['gone.herpderp.org', :alias, :permanent, '10.1.1.1', 'fe80::dead:beef', 'herpderp.org', true, 'customer1'],
  ['cdn.kernel.org', :alias, :temporary, '10.1.1.1', 'fe80::dead:beef', 'archlinux.sexy', true, 'reseller1'],
  ['svn.kernel.org', :alias, :permanent, '10.1.1.1', 'fe80::dead:beef', 'kernel.org', true, 'reseller1']
]
vhost_list.each do |vhost|
  case vhost[1]
  when :alias
    parent_vhost = Vhost.first(fqdn: vhost[5])
    Vhost.create(fqdn: vhost[0],
                 type: :alias,
                 redirect_type: vhost[2],
                 ipv4_address: Ipv4Address.first(address: vhost[3]),
                 ipv6_address: Ipv6Address.first(address: vhost[4]),
                 php_enabled: false,
                 php_runtime: PhpRuntime.first(name: 'none'),
                 os_uid: parent_vhost.os_uid,
                 os_gid: parent_vhost.os_uid,
                 parent: parent_vhost,
                 enabled: vhost[6],
                 user: User.first(login: vhost[7]))
  when :vhost
    vhost_basedir = '/srv/http/vhost'
    u = User.first(login: vhost[7])
    v = Vhost.create(fqdn: vhost[0],
                     type: :vhost,
                     ipv4_address: Ipv4Address.first(address: vhost[2]),
                     ipv6_address: Ipv6Address.first(address: vhost[3]),
                     php_enabled: vhost[4],
                     php_runtime: PhpRuntime.first(name: vhost[5]),
                     enabled: vhost[6],
                     user: u)
    v.document_root = "#{vhost_basedir}/client#{u.id}/web#{v.id}/htdocs"
    v.os_uid = "c#{u.id}web#{v.id}"
    v.os_gid = "c#{u.id}web#{v.id}"
    v.save
  end
end

# '1test!sftplogin?' = {md5}f5NspiyFx2u8dxbZARAcjQ==
sftp_user_list = [
  [1, 'c1web5-1', '{md5}f5NspiyFx2u8dxbZARAcjQ==',
   '/srv/http/vhost/blog.foxxx0.de', true, 5]
]
sftp_user_list.each do |sftp_user|
  SftpUser.new(id: sftp_user[0],
               username: sftp_user[1],
               password: <PASSWORD>],
               homedir: sftp_user[3],
               enabled: sftp_user[4],
               vhost_id: sftp_user[5]).save
end

# create the 4 necessary views
adapter = DataMapper.repository(:default).adapter
case adapter.options[:adapter].upcase
when 'POSTGRES'
  # dkim_lookup
  adapter.execute('CREATE OR REPLACE VIEW "dkim_lookup"
    AS
      SELECT
        "dkims"."id" AS "id",
        "domains"."name" AS "domain_name",
        "dkims"."selector" AS "selector",
        "dkims"."private_key" AS "private_key"
      FROM ("domains"
        LEFT JOIN "dkims"
          ON "dkims"."domain_id" = "domains"."id"
          AND "domains"."enabled" = TRUE)
      WHERE "dkims"."enabled" = TRUE;')<commit_msg>add some more SftpUsers<commit_after>group_list = [
  ['admin', true],
  ['reseller', true],
  ['user', true]
]
group_list.each do |group|
  Group.new(name: group[0],
            enabled: group[1]).save
end

user_list = [
  ['Admin', 'admin', 'secret', true, 'admin', nil],
  ['<NAME>', 'fox', 'geheim', true, 'admin', nil],
  ['<NAME>', 'max', 'muster', true, 'user', nil],
  ['Reseller 1', 'reseller1', 'reseller1', true, 'reseller', nil],
  ['Customer 1', 'customer1', 'customer1', true, 'user', 'reseller1'],
  ['Customer 2', 'customer2', 'customer2', true, 'user', 'reseller1'],
  ['Customer 3', 'customer3', 'customer3', true, 'user', 'reseller1'],
  ['Reseller 2', 'reseller2', 'reseller2', true, 'reseller', nil],
  ['Customer 4', 'customer4', 'customer4', true, 'user', 'reseller2'],
  ['Customer 5', 'customer5', 'customer5', true, 'user', 'reseller2']
]
user_list.each do |user|
  g = Group.first(name: user[4])
  u = User.create(name: user[0],
                  login: user[1],
                  password: user[2],
                  enabled: user[3],
                  group: g)
  next if user[5].nil?
  u.reseller_id = User.first(login: user[5]).id
  u.save
end

domain_list = [
  ['foobar.com', true, true, true, 'admin'],
  ['foxxx0.de', true, true, true, 'fox'],
  ['example.net', true, true, true, 'max'],
  ['herpderp.org', true, true, true, 'customer1'],
  ['schalala.net', true, true, true, 'customer2'],
  ['everything.eu', true, true, true, 'customer3'],
  ['archlinux.sexy', true, true, true, 'reseller1'],
  ['kernel.<EMAIL>', true, true, true, 'reseller1'],
  ['serious.business', true, true, true, 'customer4'],
  ['big.company', true, true, true, 'customer5']
]
domain_list.each do |domain|
  Domain.new(name: domain[0],
             mail_enabled: domain[1],
             dns_enabled: domain[2],
             enabled: domain[3],
             user: User.first(login: domain[4])).save
end

mailaccount_list = [
  ['<EMAIL>', 'topsecret!', 1_048_576, 'Dwarf', true, false],
  ['<EMAIL>', 'penis', 10_485_760, 'Smurf', true, true],
  ['<EMAIL>', 'senf1979', 1_048_576, 'Myself', false, true],
  ['<EMAIL>', 'folldohf', 10_485_760, 'Nagios', true, true],
  ['<EMAIL>', 'derp1234', 269_715_200, '<NAME>', true, true],
  ['<EMAIL>', '9876543210', 10_485_760, '<NAME>', true, true],
  ['<EMAIL>', '!abcd?', 536_870_912, '<NAME>', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Customer 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Foo Customer 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Bar Customer 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Customer 2', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Herp Customer 2', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Derp Customer 2', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Customer 3', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Me Customer 3', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'He Customer 3', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'She Customer 3', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Reseller 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Reseller 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Reseller 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Reseller 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Support Reseller 1', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Customer 4', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Sarah Customer 4', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Customer 4', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Test Customer 5', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Carl Customer 5', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Steven Customer 5', true, true],
  ['<EMAIL>', '1234', 1_048_576, 'Customer 5', true, true]
]
mailaccount_list.each do |mailaccount|
  MailAccount.new(email: mailaccount[0],
                  password: <PASSWORD>[1]),
                  receiving_enabled: mailaccount[4],
                  quota: mailaccount[2],
                  enabled: mailaccount[5],
                  domain: Domain.first(name: mailaccount[0].split('@')[1]),
                  realname: mailaccount[3]).save
end

mailalias_mailaccount_list = [
  ['<EMAIL>', %w(<EMAIL> <EMAIL> <EMAIL>)],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>']
]
mailalias_mailaccount_list.each do |mals_macc|
  MailAlias.new(
    address: mals_macc[0],
    enabled: true,
    domain: Domain.first(name: mals_macc[0].split('@')[1])
  ).save
  [*mals_macc[1]].each do |macc|
    acc = MailAccount.first(email: macc)
    acc.mail_aliases << MailAlias.first(address: mals_macc[0])
    acc.save
  end
end

mailsource_mailaccount_list = [
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', %w(<EMAIL> <EMAIL> <EMAIL>)],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>'],
  ['<EMAIL>', '<EMAIL>']
]
mailsource_mailaccount_list.each do |msrc_macc|
  MailSource.new(address: msrc_macc[0],
                 enabled: true,
                 domain: Domain.first(name: msrc_macc[0].split('@')[1])).save
  [*msrc_macc[1]].each do |macc|
    acc = MailAccount.first(email: macc)
    acc.mail_sources << MailSource.first(address: msrc_macc[0])
    acc.save
  end
end

# DKIM keys
Domain.all.each do |d|
  dkim = Dkim.new(domain: d, enabled: true)
  dkim.selector = 'mail'
  dkim.private_key = <<-EOF
-----BEGIN RSA PRIVATE KEY-----
some random private characters.......
-----END RSA PRIVATE KEY-----
EOF
  dkim.public_key = <<-EOF
-----BEGIN PUBLIC KEY-----
some random public characters.......
-----END PUBLIC KEY-----
EOF
  dkim.save
end

# DKIM author <-> key assignment
Dkim.all.each do |dk|
  DkimSigning.new(author: dk.domain.name,
                  dkim: dk,
                  enabled: true).save
end

php_rt_list = [
  ['none', '0.0'],
  ['php56', '5.6.22'],
  ['php7', '7.0.7']
]
php_rt_list.each do |php_rt|
  PhpRuntime.new(name: php_rt[0],
                 version: php_rt[1],
                 enabled: true).save
end

ipv4_list = [
  ['127.0.0.1', User.all.map(&:login)],
  ['10.1.1.1', User.all.map(&:login)],
  ['10.2.2.2', %w(customer1 customer2)],
  ['10.2.2.3', %w(customer3)],
  ['10.3.3.3', %w(reseller2 customer4)],
  ['10.4.4.4', %w(max)]
]
ipv4_list.each do |ipv4|
  users = User.all(id: 0)
  ipv4[1].each do |u|
    users.concat(User.all(login: u))
  end
  Ipv4Address.new(address: IPAddr.new(ipv4[0]),
                  enabled: true,
                  users: users).save
end

ipv6_list = [
  ['::1', User.all.map(&:login)],
  ['fe80::dead:beef', User.all.map(&:login)],
  ['fe80::beef:1', %w(reseller1 customer1 customer2)],
  ['fe80::beef:2', %w(reseller1)],
  ['fe80::beef:3', %w(reseller2 customer4)],
  ['fe80::beef:4', %w(max)]
]
ipv6_list.each do |ipv6|
  users = User.all(id: 0)
  ipv6[1].each { |u| users.concat(User.all(login: u)) }
  Ipv6Address.new(address: IPAddr.new(ipv6[0]),
                  enabled: true,
                  users: users).save
end

vhost_list = [
  ['foxxx0.de', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'fox'],
  ['ipv4.foxxx0.de', :vhost, '10.1.1.1', '::1', true, 'php7', true, 'fox'],
  ['ipv6.foxxx0.de', :vhost, '127.0.0.1', 'fe80::dead:beef', true, 'php7', true, 'fox'],
  ['paste.foxxx0.de', :vhost, '10.1.1.1', 'fe80::dead:beef', true, 'php7', true, 'fox'],
  ['p.foxxx0.de', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'paste.foxxx0.de', true, 'fox'],
  ['blog.foxxx0.de', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'fox'],
  ['example.net', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'max'],
  ['mail.example.net', :vhost, '10.4.4.4', 'fe80::beef:4', true, 'php56', true, 'max'],
  ['webmail.example.net', :alias, :permanent, '10.4.4.4', 'fe80::beef:4', 'mail.example.net', true, 'max'],
  ['herpderp.org', :vhost, '10.1.1.1', 'fe80::beef:1', false, 'none', true, 'customer1'],
  ['test.herpderp.org', :vhost, '10.2.2.2', 'fe80::beef:1', false, 'none', true, 'customer1'],
  ['sub.herpderp.org', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'customer1'],
  ['schalala.net', :vhost, '10.2.2.2', 'fe80::beef:1', false, 'none', true, 'customer2'],
  ['test.schalala.net', :vhost, '10.2.2.2', 'fe80::dead:beef', false, 'none', true, 'customer2'],
  ['sub.schalala.net', :vhost, '10.1.1.1', 'fe80::beef:1', false, 'none', true, 'customer2'],
  ['everything.eu', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'customer3'],
  ['foo.everything.eu', :vhost, '10.2.2.3', 'fe80::dead:beef', false, 'none', true, 'customer3'],
  ['serious.business', :vhost, '10.3.3.3', 'fe80::beef:3', false, 'none', true, 'customer4'],
  ['big.company', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'customer5'],
  ['archlinux.sexy', :vhost, '10.2.2.3', 'fe80::beef:2', false, 'none', true, 'reseller1'],
  ['kernel.org', :vhost, '10.1.1.1', 'fe80::dead:beef', false, 'none', true, 'reseller1'],
  ['herp.herpderp.org', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'sub.herpderp.org', true, 'customer1'],
  ['derp.herpderp.org', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'sub.herpderp.org', true, 'customer1'],
  ['merp.herpderp.org', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'test.herpderp.org', true, 'customer1'],
  ['blerp.herpderp.org', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'test.herpderp.org', true, 'customer1'],
  ['bar.schalala.net', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'schalala.net', true, 'customer2'],
  ['xyz.schalala.net', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'schalala.net', true, 'customer2'],
  ['bla.everything.eu', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'everything.eu', true, 'customer3'],
  ['funny.serious.business', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'serious.business', true, 'customer4'],
  ['little.big.company', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'big.company', true, 'customer5'],
  ['cdn.archlinux.sexy', :alias, :none, '10.1.1.1', 'fe80::dead:beef', 'archlinux.sexy', true, 'reseller1'],
  ['login.herpderp.org', :alias, :temporary, '10.1.1.1', 'fe80::dead:beef', 'herpderp.org', true, 'customer1'],
  ['hodor.herpderp.org', :alias, :temporary, '10.1.1.1', 'fe80::dead:beef', 'herpderp.org', true, 'customer1'],
  ['moved.herpderp.org', :alias, :permanent, '10.1.1.1', 'fe80::dead:beef', 'herpderp.org', true, 'customer1'],
  ['gone.herpderp.org', :alias, :permanent, '10.1.1.1', 'fe80::dead:beef', 'herpderp.org', true, 'customer1'],
  ['cdn.kernel.org', :alias, :temporary, '10.1.1.1', 'fe80::dead:beef', 'archlinux.sexy', true, 'reseller1'],
  ['svn.kernel.org', :alias, :permanent, '10.1.1.1', 'fe80::dead:beef', 'kernel.org', true, 'reseller1']
]
vhost_list.each do |vhost|
  case vhost[1]
  when :alias
    parent_vhost = Vhost.first(fqdn: vhost[5])
    Vhost.create(fqdn: vhost[0],
                 type: :alias,
                 redirect_type: vhost[2],
                 ipv4_address: Ipv4Address.first(address: vhost[3]),
                 ipv6_address: Ipv6Address.first(address: vhost[4]),
                 php_enabled: false,
                 php_runtime: PhpRuntime.first(name: 'none'),
                 os_uid: parent_vhost.os_uid,
                 os_gid: parent_vhost.os_uid,
                 parent: parent_vhost,
                 enabled: vhost[6],
                 user: User.first(login: vhost[7]))
  when :vhost
    vhost_basedir = '/srv/http/vhost/clients'
    u = User.first(login: vhost[7])
    v = Vhost.create(fqdn: vhost[0],
                     type: :vhost,
                     ipv4_address: Ipv4Address.first(address: vhost[2]),
                     ipv6_address: Ipv6Address.first(address: vhost[3]),
                     php_enabled: vhost[4],
                     php_runtime: PhpRuntime.first(name: vhost[5]),
                     enabled: vhost[6],
                     user: u)
    v.document_root = "#{vhost_basedir}/client#{u.id}/web#{v.id}/htdocs"
    v.os_uid = "c#{u.id}web#{v.id}"
    v.os_gid = "c#{u.id}web#{v.id}"
    v.save
  end
end

# '1test!sftplogin?' = {md5}f5NspiyFx2u8dxbZARAcjQ==
sftp_user_list = [
  ['{md5}f5NspiyFx2u8dxbZARAcjQ==', 'blog.foxxx0.de', true],
  ['{md5}f5NspiyFx2u8dxbZARAcjQ==', 'mail.example.net', true],
  ['{md5}f5NspiyFx2u8dxbZARAcjQ==', 'herpderp.org', true],
  ['{md5}f5NspiyFx2u8dxbZARAcjQ==', 'sub.herpderp.org', true],
  ['{md5}f5NspiyFx2u8dxbZARAcjQ==', 'test.schalala.net', true],
  ['{md5}f5NspiyFx2u8dxbZARAcjQ==', 'foo.everything.eu', true],
  ['{md5}f5NspiyFx2u8dxbZARAcjQ==', 'serious.business', true],
  ['{md5}f5NspiyFx2u8dxbZARAcjQ==', 'big.company', true],
  ['{md5}f5NspiyFx2u8dxbZARAcjQ==', 'archlinux.sexy', true],
  ['{md5}f5NspiyFx2u8dxbZARAcjQ==', 'kernel.org', true]
]
sftp_user_list.each do |sftp_user|
  v = Vhost.first(fqdn: sftp_user[1])
  u_home = v.document_root.gsub(%r{/htdocs}, '')
  u = SftpUser.create(username: SecureRandom.hex(8),
                      homedir: u_home,
                      password: <PASSWORD>[0],
                      vhost: v,
                      enabled: sftp_user[2])
  u.username = "#{v.os_uid}-#{u.id}"
  u.save
end

# create the 4 necessary views
adapter = DataMapper.repository(:default).adapter
case adapter.options[:adapter].upcase
when 'POSTGRES'
  # dkim_lookup
  adapter.execute('CREATE OR REPLACE VIEW "dkim_lookup"
    AS
      SELECT
        "dkims"."id" AS "id",
        "domains"."name" AS "domain_name",
        "dkims"."selector" AS "selector",
        "dkims"."private_key" AS "private_key"
      FROM ("domains"
        LEFT JOIN "dkims"
          ON "dkims"."domain_id" = "domains"."id"
          AND "domains"."enabled" = TRUE)
      WHERE "dkims"."enabled" = TRUE;')
{'fraction_non_alphanumeric': 0.25713152414636564, 'fraction_numerical': 0.056886920305424256, 'mean_word_length': 3.747959824231011, 'pattern_counts': {'":': 0, '<': 425, '<?xml version=': 0, '>': 407, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 86, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7447566', 'n_tokens_mistral': 13310, 'n_tokens_neox': 12654, 'n_words': 2435}