]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/utils/conv4.pl
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
230 if ($oldflags & 0x20) { # +f
234 if ($oldflags & 0x8000) { # +p
238 if ($oldflags & 0x80000) { # +t
242 if ($oldflags & 0x400000) { # +w
246 if ($oldflags & 0x400) { # +k: maps to forcemode +k
250 if ($oldflags & 0x800) { # +l: maps to forcemode +l
254 return ($forcemodes, $newflags);
258 open USERLIST
, "users" or die "Unable to open user list";
282 my $suspendreason="";
290 } elsif ($state == 1) {
292 } elsif ($state == 2) {
294 } elsif ($state == 3) {
296 } elsif ($state == 4) {
298 } elsif ($state == 5) {
300 } elsif ($state == 6) {
302 } elsif ($state == 7) {
304 } elsif ($state == 8) {
306 } elsif ($state == 9) {
308 } elsif ($state == 10) {
310 } elsif ($state == 11) {
312 } elsif ($state == 12) {
314 } elsif ($state == 13) {
316 # print "Got user $username [$userid]\n";
318 if ($globalauth >= 900) {
321 if ($globalauth > 10 and $globalauth < 900) {
324 if ($globalauth >= 1000) {
327 if ($nuflags & 8) { # No auth limit
330 if ($nuflags & 64) { # No delete
333 if ($nuflags & 1) { # Has trust
336 if (exists $suspends{$username}) {
337 my $ar=$suspends{$username};
338 $created=0; # Q doesn't have created time for auths so default it to 0
339 if ($$ar[0] == 7) { # never authed - copy the "last auth" time into "created time".
341 $lastauth=0; # new Q uses lastauth=0 to indicate an unused account
342 } elsif ($$ar[0] == 5) { # delayed gline
344 } elsif ($$ar[0] == 6) { # instant gline
346 } elsif ($$ar[0] == 1) { # public
349 print "Suspend reason $$ar[0] found!\n";
353 $suspendtime=$$ar[2];
355 $suspendreason=doquote
($$ar[4]);
363 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";
364 $users{irc_lc
($username)}=$userid;
367 unless ($usercount % 1000) {
370 my $fname=sprintf("users-%03d.csv",$usercount/1000);
371 open USERS
, ">$fname";
372 print SQL
"COPY users FROM '${pathname}${fname}' DELIMITER ',';\n";
375 if (not defined $chans{irc_lc
($_)}) {
376 print "Error: unknown channel $_\n";
379 $chan=$chans{irc_lc
($_)};
382 } elsif ($state == 14) {
385 $realflags=map_chanlevflags
($flags);
386 my $idstr=$userid.".".$chan;
387 unless (exists $chanusers{$idstr}) {
388 print CHANUSERS
"$userid,$chan,$realflags,0,0,\n";
390 if (!($chanusercount % 10000)) {
392 my $fname=sprintf("chanusers-%03d.csv",$chanusercount/10000);
393 open CHANUSERS
, ">$fname";
394 print SQL
"COPY chanusers FROM '${pathname}${fname}' DELIMITER ',';\n";
396 $chanusers{$idstr}=1;
408 sub map_chanlevflags
{
413 if ($oldflags & 0x1) { # +a
417 if ($oldflags & 0x2) { # +b
421 if ($oldflags & 0x1000) { # +m
425 if ($oldflags & 0x2000) { # +n
429 if ($oldflags & 0x4000) { # +o
433 if ($oldflags & 0x200000) { # +v
437 if ($oldflags & 0x80000) { # +t
441 if ($newflags & 0x2000) {
443 } elsif ($newflags & 0x1000) {
453 open LDB
, "accounts.0" or die "Error opening lightweight database";
477 /^--- End of/ && ($state=1);
478 } elsif ($state==1) {
479 /^(.+?) (.+?) (.+?) (\d+) (\d+) (\d+)$/ or next;
481 $addedby=getuserid
($2);
482 $founder=getuserid
($3);
492 if (defined $chans{irc_lc
($channame)}) {
493 $curchanid=$chans{irc_lc
($channame)};
494 print "Duplicate channel $channame, merging chanlev\n";
497 unless ($chanid % 1000) {
512 } elsif ($flags & 0x20) {
517 } elsif ($state==2) {
518 /^(\S+) (.+)$/ or next;
520 $suspendby = $users{irc_lc
($1)};
521 if (not defined $suspendby) {
524 $suspendreason=doquote
($2);
532 } elsif ($state==3) {
534 $welcome=doquote
($_);
536 } elsif ($state==10) {
539 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";
540 if (($chanid % 1000)==0) {
542 my $fname=sprintf("chans-%03d.csv",$chanid/1000);
543 open CHANS
, ">$fname";
544 print SQL
"COPY channels FROM '${pathname}${fname}' DELIMITER ',';\n";
549 /^(\S+)\s+(\S+)$/ or next;
552 $userid=getuserid
($1);
554 if ($ocuflags =~ /a/) {
557 if ($ocuflags =~ /g/) {
560 if ($ocuflags =~ /m/) {
563 if ($ocuflags =~ /n/) {
566 if ($ocuflags =~ /o/) {
569 if ($ocuflags =~ /v/) {
573 my $idstr=$userid.".".$curchanid;
574 unless (exists $chanusers{$idstr}) {
575 $chanusers{$idstr}=1;
576 print CHANUSERS
"$userid,$curchanid,$cuflags,0,0,\n";
578 if (!($chanusercount % 10000)) {
580 my $fname=sprintf("chanusers-%03d.csv",$chanusercount/10000);
581 open CHANUSERS
, ">$fname";
582 print SQL
"COPY chanusers FROM '${pathname}${fname}' DELIMITER ',';\n";
585 print "Suppressing duplicate chanuser: $idstr\n";
596 $incoming = lc $incoming;
597 $incoming =~ tr/\[\]\|~ÆÁÀÜÐÄÅÖ/\{\}\\^æáàüðäåö/;
606 $userid=$users{irc_lc
($username)};
607 if (not defined $userid) {
608 print ORPHANS irc_lc
($username)."\n";
620 for (split //, $instr) {
623 } elsif ($_ eq "\\") {