Changeset 172
- Timestamp:
- 11/29/11 16:52:25 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/vega-import.pl
r171 r172 33 33 $newdbh->{PrintError} = 1; 34 34 $newdbh->{PrintWarn} = 1; 35 initGlobals($newdbh); 36 37 my %vegatypes = ('S' => 'SOA', 'N' => 'NS', 'A' => 'A', 'T' => 'TXT', 38 'V' => 'SRV', 'P' => 'PTR', 'M' => 'MX', 'C' => 'CNAME' ); 35 39 36 40 if ($mode eq 'replace') { 37 41 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: "; 40 44 my $resp = <STDIN>; 41 45 chomp $resp; … … 74 78 "self_edit,group_edit,group_create,group_delete,domain_edit,domain_create,domain_delete,record_edit,". 75 79 "record_create,record_delete FROM user_permissions WHERE user_id=?"); 80 my $domget = $vegadbh->prepare("SELECT domain_id,domain,description,status FROM domains WHERE group_id=?"); 81 my $recget = $vegadbh->prepare("SELECT record_id,host,type,val,distance,weight,port,ttl,description ". 82 "FROM records WHERE domain_id=?"); 83 my $defrecget = $vegadbh->prepare("SELECT record_id, group_id, host, type, val, distance, weight, port, ttl, ". 84 "description FROM default_records WHERE group_id=?"); 76 85 77 86 my $newgrp = $newdbh->prepare("INSERT INTO groups (group_id,parent_group_id,group_name,permission_id) ". … … 84 93 my $newuser = $newdbh->prepare("INSERT INTO users (user_id, group_id, username, password, firstname, ". 85 94 "lastname, phone, type, status, permission_id, inherit_perm) VALUES (?,?,?,?,?,?,?,?,?,?,'f')"); 86 my $newuserpset = $newdbh->prepare("INSERT INTO permissions ( self_edit, group_create, ".95 my $newuserpset = $newdbh->prepare("INSERT INTO permissions (admin, self_edit, group_create, ". 87 96 "group_edit, group_delete, user_create, user_edit, user_delete, domain_create, domain_edit, ". 88 97 "domain_delete, record_create, record_edit, record_delete, user_id) ". 89 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); 98 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); 99 my $newdom = $newdbh->prepare("INSERT INTO domains (domain_id, domain, group_id, description, status) VALUES ". 100 "(?,?,?,?,?)"); 101 my $newrec = $newdbh->prepare("INSERT INTO records (domain_id,record_id,host,type,val,distance,weight,port,". 102 "ttl,description) VALUES (?,?,?,?,?,?,?,?,?,?)"); 103 my $newdefrec = $newdbh->prepare("INSERT INTO default_records (record_id,group_id,host,type,val,distance,". 104 "weight,port,ttl,description) VALUES (?,?,?,?,?,?,?,?,?,?)"); 90 105 91 106 my $foo = qq( … … 140 155 $userget->execute($grpid); 141 156 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); 142 161 $userpget->execute($user->{user_id}) or warn "failed permission get on ".$user->{user_id}."\n"; 143 162 my $oldp = $userpget->fetchrow_hashref; 144 163 # 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', 146 165 'user_edit', 'user_delete', 'domain_create', 'domain_edit', 'domain_delete', 'record_create', 147 166 'record_edit', 'record_delete') { 148 167 $oldp->{$permtype} = 'f' if !defined($oldp->{$permtype}); 149 168 } 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}, 151 171 $oldp->{user_create}, $oldp->{user_edit}, $oldp->{user_delete}, 152 172 $oldp->{domain_create}, $oldp->{domain_edit}, $oldp->{domain_delete}, … … 155 175 $newpid->execute; 156 176 my ($pid) = $newpid->fetchrow_array; 157 # fiddle user data158 $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);161 177 $newuser->execute($user->{user_id}, $user->{group_id}, $user->{email}, $user->{password}, 162 178 $user->{first_name}, $user->{last_name}, $user->{phone}, $user->{account_type}, $user->{status}, $pid) 163 179 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.