Changeset 172 for trunk


Ignore:
Timestamp:
11/29/11 16:52:25 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

VegaDNS import tool should be complete.

  • User import tweaked to set permissions correctly
  • Domains and domain records imported
  • Default records imported. Note Vega 1.1.5/6 does not seem to keep multiple sets of default records; subgroups will not inherit these records
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/vega-import.pl

    r171 r172  
    3333$newdbh->{PrintError} = 1;
    3434$newdbh->{PrintWarn} = 1;
     35initGlobals($newdbh);
     36
     37my %vegatypes = ('S' => 'SOA', 'N' => 'NS', 'A' => 'A', 'T' => 'TXT',
     38        'V' => 'SRV', 'P' => 'PTR', 'M' => 'MX', 'C' => 'CNAME' );
    3539
    3640if ($mode eq 'replace') {
    3741  print "WARNING:  Using 'replace' will **DELETE** all existing group,\n".
    38         "user, domain, and record data.  Once started this cannot be\n".
    39         "reversed.  Enter 'yes' to proceed: ";
     42        "user, domain, and record data in DeepNet DNS Administrator.\n".
     43        "Once started this cannot be reversed.  Enter 'yes' to proceed: ";
    4044  my $resp = <STDIN>;
    4145  chomp $resp;
     
    7478        "self_edit,group_edit,group_create,group_delete,domain_edit,domain_create,domain_delete,record_edit,".
    7579        "record_create,record_delete FROM user_permissions WHERE user_id=?");
     80my $domget = $vegadbh->prepare("SELECT domain_id,domain,description,status FROM domains WHERE group_id=?");
     81my $recget = $vegadbh->prepare("SELECT record_id,host,type,val,distance,weight,port,ttl,description ".
     82        "FROM records WHERE domain_id=?");
     83my $defrecget = $vegadbh->prepare("SELECT record_id, group_id, host, type, val, distance, weight, port, ttl, ".
     84        "description FROM default_records WHERE group_id=?");
    7685
    7786my $newgrp = $newdbh->prepare("INSERT INTO groups (group_id,parent_group_id,group_name,permission_id) ".
     
    8493my $newuser = $newdbh->prepare("INSERT INTO users (user_id, group_id, username, password, firstname, ".
    8594        "lastname, phone, type, status, permission_id, inherit_perm) VALUES (?,?,?,?,?,?,?,?,?,?,'f')");
    86 my $newuserpset = $newdbh->prepare("INSERT INTO permissions (self_edit, group_create, ".
     95my $newuserpset = $newdbh->prepare("INSERT INTO permissions (admin, self_edit, group_create, ".
    8796        "group_edit, group_delete, user_create, user_edit, user_delete, domain_create, domain_edit, ".
    8897        "domain_delete, record_create, record_edit, record_delete, user_id) ".
    89         "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
     98        "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
     99my $newdom = $newdbh->prepare("INSERT INTO domains (domain_id, domain, group_id, description, status) VALUES ".
     100        "(?,?,?,?,?)");
     101my $newrec = $newdbh->prepare("INSERT INTO records (domain_id,record_id,host,type,val,distance,weight,port,".
     102        "ttl,description) VALUES (?,?,?,?,?,?,?,?,?,?)");
     103my $newdefrec = $newdbh->prepare("INSERT INTO default_records (record_id,group_id,host,type,val,distance,".
     104        "weight,port,ttl,description) VALUES (?,?,?,?,?,?,?,?,?,?)");
    90105
    91106my $foo = qq(
     
    140155  $userget->execute($grpid);
    141156  while (my $user = $userget->fetchrow_hashref) {
     157    # fiddle user data
     158    $user->{account_type} = 'S' if $user->{account_type} eq 'senior_admin';
     159    $user->{account_type} = 'u' if $user->{account_type} eq 'user';
     160    $user->{status} = ($user->{status} eq 'active' ? 1 : 0);
    142161    $userpget->execute($user->{user_id}) or warn "failed permission get on ".$user->{user_id}."\n";
    143162    my $oldp = $userpget->fetchrow_hashref;
    144163    # de-nullify
    145     foreach my $permtype ('self_edit', 'group_create', 'group_edit', 'group_delete', 'user_create',
     164    foreach my $permtype ('admin', 'self_edit', 'group_create', 'group_edit', 'group_delete', 'user_create',
    146165        'user_edit', 'user_delete', 'domain_create', 'domain_edit', 'domain_delete', 'record_create',
    147166        'record_edit', 'record_delete') {
    148167      $oldp->{$permtype} = 'f' if !defined($oldp->{$permtype});
    149168    }
    150     $newuserpset->execute($oldp->{self_edit}, $oldp->{group_create}, $oldp->{group_edit}, $oldp->{group_delete},
     169    $newuserpset->execute(($user->{account_type} eq 'S' ? 't' : 'f'), $oldp->{self_edit},
     170        $oldp->{group_create}, $oldp->{group_edit}, $oldp->{group_delete},
    151171        $oldp->{user_create}, $oldp->{user_edit}, $oldp->{user_delete},
    152172        $oldp->{domain_create}, $oldp->{domain_edit}, $oldp->{domain_delete},
     
    155175    $newpid->execute;
    156176    my ($pid) = $newpid->fetchrow_array;
    157     # fiddle user data
    158     $user->{account_type} = 'S' if $user->{account_type} eq 'senior_admin';
    159     $user->{account_type} = 'u' if $user->{account_type} eq 'user';
    160     $user->{status} = ($user->{status} eq 'active' ? 1 : 0);
    161177    $newuser->execute($user->{user_id}, $user->{group_id}, $user->{email}, $user->{password},
    162178        $user->{first_name}, $user->{last_name}, $user->{phone}, $user->{account_type}, $user->{status}, $pid)
    163179        or warn "  new user ".$user->{email}." (".$user->{user_id}.") failed: ".$newuser->errstr."\n";
    164     print " user ".$user->{email}." (".$user->{user_id}.")\n";
    165   }
    166 
    167 
    168 }
     180    print "  user ".$user->{email}." (".$user->{user_id}.")\n";
     181  }
     182  print " done\n";
     183
     184 ## Domains
     185  print " domains: \n";
     186  $domget->execute($grpid);
     187  while (my ($id,$dom,$desc,$status) = $domget->fetchrow_array) {
     188    $status = ($status eq 'active' ? 1 : 0);
     189    $newdom->execute($id, $dom, $grpid, $desc, $status);
     190    print "  domain $dom ($id)\n";
     191    $recget->execute($id);
     192    while (my @rec = $recget->fetchrow_array) {
     193      $rec[2] = $reverse_typemap{$vegatypes{$rec[2]}};
     194      $rec[4] = 0 if !$rec[4];
     195      $rec[5] = 0 if !$rec[5];
     196      $rec[6] = 0 if !$rec[6];
     197      $newrec->execute($id,@rec);
     198    }
     199  }
     200  print " done\n";
     201
     202 ## Default records
     203  print " default records: ";
     204  $defrecget->execute($grpid);
     205  while (my @rec = $defrecget->fetchrow_array) {
     206    $rec[3] = $reverse_typemap{$vegatypes{$rec[3]}};
     207    $rec[5] = 0 if !$rec[5];
     208    $rec[6] = 0 if !$rec[6];
     209    $rec[7] = 0 if !$rec[7];
     210    $newdefrec->execute(@rec);
     211  }
     212  print " done\n";
     213}
Note: See TracChangeset for help on using the changeset viewer.