]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/utils/conv4.pl
466b6bca756d4dcdcb7bd2a329f517ee4bcac22b
6 my $pathname="/home/q9test/database/";
19 open BANS
, ">bans.csv";
20 open CHANS
, ">chans-000.csv";
21 open USERS
, ">users-000.csv";
22 open CHANUSERS
, ">chanusers-000.csv";
23 open ORPHANS
, ">orphanlist";
24 open SQL
, ">load.sql";
26 print SQL
"TRUNCATE TABLE channels;\n";
27 print SQL
"TRUNCATE TABLE users;\n";
28 print SQL
"TRUNCATE TABLE bans;\n";
29 print SQL
"TRUNCATE TABLE chanusers;\n";
30 print SQL
"COPY users FROM '${pathname}users-000.csv' DELIMITER ',';\n";
31 print SQL
"COPY channels FROM '${pathname}chans-000.csv' DELIMITER ',';\n";
32 print SQL
"COPY chanusers FROM '${pathname}chanusers-000.csv' DELIMITER ',';\n";
33 print SQL
"COPY bans FROM '${pathname}bans.csv' DELIMITER ',';\n";
35 print "Converting Q channels..";
37 print "\nConverting Q users..";
40 print "\nConverting L channels..";
43 sub loadsuspendusers
{
44 open SUSPLIST
, "suspended_users" or die "Unable to open suspended users list";
87 die "suspended_users format errar!";
90 $suspends{$name} = [ $type, $who, $stime, $exp, $reason ];
99 open CHANLIST
, "channels" or die "Unable to open channel list";
131 } elsif ($state==1) {
133 } elsif ($state==2) {
135 } elsif ($state==3) {
137 } elsif ($state==4) {
139 } elsif ($state==5) {
141 } elsif ($state==6) {
143 } elsif ($state==7) {
145 } elsif ($state==8) {
147 if ($suspendreason eq "!") { $suspendreason = ""; }
148 } elsif ($state==9) {
150 } elsif ($state==10) {
152 } elsif ($state==11) {
154 if ($lasttopic eq "!") { $lasttopic = ""; }
155 } elsif ($state==12) {
157 if ($welcome eq "!") { $welcome = ""; }
158 } elsif ($state==13) {
160 if ($key eq "!") { $key=""; }
161 if (length $key > 23) { $key=""; }
162 } elsif ($state==14) {
164 unless($limit =~ /^\d+$/) { $limit=0; }
165 if ($limit > 9999) { $limit = 9999; }
166 } elsif ($state==15) {
168 } elsif ($state==16) {
170 } elsif ($state==17) {
172 } elsif ($state==18) {
174 } elsif ($state==19) {
177 if ($banstr ne "!") {
178 print BANS
"$banid,$chanid,$banby,".doquote
($banstr).",0,\n";
181 if (!($banid % 1000)) {
183 my $fname=sprintf("bans-%03d.csv",$banid/1000);
184 open BANS
, ">$fname";
185 print SQL
"COPY bans FROM '${pathname}${fname}' DELIMITER ',';\n";
188 ($forcemodes, $realflags)=map_chanflags
($flags);
190 $realflags |= 0x4000;
192 $welcome = doquote
($welcome);
193 $lasttopic = doquote
($lasttopic);
194 print CHANS
"$chanid,".doquote
($cname).",$realflags,$forcemodes,0,$limit,10,0,$firstjoin,$lastjoin,$firstjoin,0,$owner,$addby,$suspendby,$suspendtime,$type,$joincount,$joincount,0,0,$welcome,$lasttopic,".doquote
($key).",".doquote
($suspendreason).",,0\n";
195 if (($chanid % 1000)==0) {
197 my $fname=sprintf("chans-%03d.csv",$chanid/1000);
198 open CHANS
, ">$fname";
199 print SQL
"COPY channels FROM '${pathname}${fname}' DELIMITER ',';\n";
201 $chans{irc_lc
($cname)}=$chanid;
203 unless ($chanid % 1000) {
221 if ($oldflags & 0x02) { # +b
225 if ($oldflags & 0x04) { # +c
229 if ($oldflags & 0x20) { # +f
233 if ($oldflags & 0x8000) { # +p
237 if ($oldflags & 0x80000) { # +t
241 if ($oldflags & 0x400000) { # +w
245 if ($oldflags & 0x400) { # +k: maps to forcemode +k
249 if ($oldflags & 0x800) { # +l: maps to forcemode +l
253 return ($forcemodes, $newflags);
257 open USERLIST
, "users" or die "Unable to open user list";
281 my $suspendreason="";
289 } elsif ($state == 1) {
291 } elsif ($state == 2) {
293 } elsif ($state == 3) {
295 } elsif ($state == 4) {
297 } elsif ($state == 5) {
299 } elsif ($state == 6) {
301 } elsif ($state == 7) {
303 } elsif ($state == 8) {
305 } elsif ($state == 9) {
307 } elsif ($state == 10) {
309 } elsif ($state == 11) {
311 } elsif ($state == 12) {
313 } elsif ($state == 13) {
315 # print "Got user $username [$userid]\n";
317 if ($globalauth >= 900) {
320 if ($globalauth > 10 and $globalauth < 900) {
323 if ($globalauth >= 1000) {
326 if ($nuflags & 8) { # No auth limit
329 if ($nuflags & 64) { # No delete
332 if ($nuflags & 1) { # Has trust
335 if (exists $suspends{$username}) {
336 my $ar=$suspends{$username};
337 $created=0; # Q doesn't have created time for auths so default it to 0
338 if ($$ar[0] == 7) { # never authed - copy the "last auth" time into "created time".
340 $lastauth=0; # new Q uses lastauth=0 to indicate an unused account
341 } elsif ($$ar[0] == 5) { # delayed gline
343 } elsif ($$ar[0] == 6) { # instant gline
345 } elsif ($$ar[0] == 1) { # public
348 print "Suspend reason $$ar[0] found!\n";
352 $suspendtime=$$ar[2];
354 $suspendreason=doquote
($$ar[4]);
362 print USERS
"$userid,".doquote
($username).",$created,$lastauth,$lastemailrq,$uflags,0,$suspendwho,$suspendexp,$suspendtime,$lockuntil,".doquote
($password).",".doquote
($emailaddr).",".doquote
($lastemail).",".doquote
("${lastusername}\@${lasthostname}").",".$suspendreason.",,\n";
363 $users{irc_lc
($username)}=$userid;
366 unless ($usercount % 1000) {
369 my $fname=sprintf("users-%03d.csv",$usercount/1000);
370 open USERS
, ">$fname";
371 print SQL
"COPY users FROM '${pathname}${fname}' DELIMITER ',';\n";
374 if (not defined $chans{irc_lc
($_)}) {
375 print "Error: unknown channel $_\n";
378 $chan=$chans{irc_lc
($_)};
381 } elsif ($state == 14) {
384 $realflags=map_chanlevflags
($flags);
385 my $idstr=$userid.".".$chan;
386 unless (exists $chanusers{$idstr}) {
387 print CHANUSERS
"$userid,$chan,$realflags,0,0,\n";
389 if (!($chanusercount % 10000)) {
391 my $fname=sprintf("chanusers-%03d.csv",$chanusercount/10000);
392 open CHANUSERS
, ">$fname";
393 print SQL
"COPY chanusers FROM '${pathname}${fname}' DELIMITER ',';\n";
395 $chanusers{$idstr}=1;
407 sub map_chanlevflags
{
412 if ($oldflags & 0x1) { # +a
416 if ($oldflags & 0x2) { # +b
420 if ($oldflags & 0x1000) { # +m
424 if ($oldflags & 0x2000) { # +n
428 if ($oldflags & 0x4000) { # +o
432 if ($oldflags & 0x200000) { # +v
436 if ($oldflags & 0x80000) { # +t
440 if ($newflags & 0x2000) {
442 } elsif ($newflags & 0x1000) {
452 open LDB
, "accounts.0" or die "Error opening lightweight database";
476 /^--- End of/ && ($state=1);
477 } elsif ($state==1) {
478 /^(.+?) (.+?) (.+?) (\d+) (\d+) (\d+)$/ or next;
480 $addedby=getuserid
($2);
481 $founder=getuserid
($3);
491 if (defined $chans{irc_lc
($channame)}) {
492 $curchanid=$chans{irc_lc
($channame)};
493 print "Duplicate channel $channame, merging chanlev\n";
496 unless ($chanid % 1000) {
511 } elsif ($flags & 0x20) {
516 } elsif ($state==2) {
517 /^(\S+) (.+)$/ or next;
519 $suspendby = $users{irc_lc
($1)};
520 if (not defined $suspendby) {
523 $suspendreason=doquote
($2);
531 } elsif ($state==3) {
533 $welcome=doquote
($_);
535 } elsif ($state==10) {
538 print CHANS
"$curchanid,".doquote
($channame).",$cflags,$forcemodes,0,0,10,0,$added,$lastused,$added,0,$founder,$addedby,$suspendby,0,0,0,0,0,0,$welcome,,,$suspendreason,,0\n";
539 if (($chanid % 1000)==0) {
541 my $fname=sprintf("chans-%03d.csv",$chanid/1000);
542 open CHANS
, ">$fname";
543 print SQL
"COPY channels FROM '${pathname}${fname}' DELIMITER ',';\n";
548 /^(\S+)\s+(\S+)$/ or next;
551 $userid=getuserid
($1);
553 if ($ocuflags =~ /a/) {
556 if ($ocuflags =~ /g/) {
559 if ($ocuflags =~ /m/) {
562 if ($ocuflags =~ /n/) {
565 if ($ocuflags =~ /o/) {
568 if ($ocuflags =~ /v/) {
572 my $idstr=$userid.".".$curchanid;
573 unless (exists $chanusers{$idstr}) {
574 $chanusers{$idstr}=1;
575 print CHANUSERS
"$userid,$curchanid,$cuflags,0,0,\n";
577 if (!($chanusercount % 10000)) {
579 my $fname=sprintf("chanusers-%03d.csv",$chanusercount/10000);
580 open CHANUSERS
, ">$fname";
581 print SQL
"COPY chanusers FROM '${pathname}${fname}' DELIMITER ',';\n";
584 print "Suppressing duplicate chanuser: $idstr\n";
595 $incoming = lc $incoming;
596 $incoming =~ tr/\[\]\|~ÆÁÀÜÐÄÅÖ/\{\}\\^æáàüðäåö/;
605 $userid=$users{irc_lc
($username)};
606 if (not defined $userid) {
607 print ORPHANS irc_lc
($username)."\n";
619 for (split //, $instr) {
622 } elsif ($_ eq "\\") {