]>
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 chanserv.channels;\n";
27 print SQL
"TRUNCATE TABLE chanserv.users;\n";
28 print SQL
"TRUNCATE TABLE chanserv.bans;\n";
29 print SQL
"TRUNCATE TABLE chanserv.chanusers;\n";
30 print SQL
"COPY chanserv.users FROM '${pathname}users-000.csv' DELIMITER ',';\n";
31 print SQL
"COPY chanserv.channels FROM '${pathname}chans-000.csv' DELIMITER ',';\n";
32 print SQL
"COPY chanserv.chanusers FROM '${pathname}chanusers-000.csv' DELIMITER ',';\n";
33 print SQL
"COPY chanserv.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 chanserv.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 chanserv.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 # 20-900 get +h, 900+ get +o
319 if ($globalauth >= 900) {
322 if ($globalauth >=20 and $globalauth < 900) {
325 # 997-999 get +a, 1000 gets +d
326 if ($globalauth >= 997 and $globalauth < 1000) {
329 if ($globalauth >= 1000) {
332 if ($nuflags & 8) { # No auth limit
335 if ($nuflags & 64) { # No delete
338 if ($nuflags & 1) { # Has trust
341 if (exists $suspends{$username}) {
342 my $ar=$suspends{$username};
343 $created=0; # Q doesn't have created time for auths so default it to 0
344 if ($$ar[0] == 7) { # never authed - copy the "last auth" time into "created time".
346 $lastauth=0; # new Q uses lastauth=0 to indicate an unused account
347 } elsif ($$ar[0] == 5) { # delayed gline
349 } elsif ($$ar[0] == 6) { # instant gline
351 } elsif ($$ar[0] == 1) { # public
354 print "Suspend reason $$ar[0] found!\n";
358 $suspendtime=$$ar[2];
360 $suspendreason=doquote
($$ar[4]);
368 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";
369 $users{irc_lc
($username)}=$userid;
372 unless ($usercount % 1000) {
375 my $fname=sprintf("users-%03d.csv",$usercount/1000);
376 open USERS
, ">$fname";
377 print SQL
"COPY chanserv.users FROM '${pathname}${fname}' DELIMITER ',';\n";
380 if (not defined $chans{irc_lc
($_)}) {
381 print "Error: unknown channel $_\n";
384 $chan=$chans{irc_lc
($_)};
387 } elsif ($state == 14) {
390 $realflags=map_chanlevflags
($flags);
391 my $idstr=$userid.".".$chan;
392 unless (exists $chanusers{$idstr}) {
393 print CHANUSERS
"$userid,$chan,$realflags,0,0,\n";
395 if (!($chanusercount % 10000)) {
397 my $fname=sprintf("chanusers-%03d.csv",$chanusercount/10000);
398 open CHANUSERS
, ">$fname";
399 print SQL
"COPY chanserv.chanusers FROM '${pathname}${fname}' DELIMITER ',';\n";
401 $chanusers{$idstr}=1;
413 sub map_chanlevflags
{
418 if ($oldflags & 0x1) { # +a
422 if ($oldflags & 0x2) { # +b
426 if ($oldflags & 0x1000) { # +m
430 if ($oldflags & 0x2000) { # +n
434 if ($oldflags & 0x4000) { # +o
438 if ($oldflags & 0x200000) { # +v
442 if ($oldflags & 0x80000) { # +t
446 if ($newflags & 0x2000) {
448 } elsif ($newflags & 0x1000) {
458 open LDB
, "accounts.0" or die "Error opening lightweight database";
482 /^--- End of/ && ($state=1);
483 } elsif ($state==1) {
484 /^(.+?) (.+?) (.+?) (\d+) (\d+) (\d+)$/ or next;
486 $addedby=getuserid
($2);
487 $founder=getuserid
($3);
497 if (defined $chans{irc_lc
($channame)}) {
498 $curchanid=$chans{irc_lc
($channame)};
499 print "Duplicate channel $channame, merging chanlev\n";
502 unless ($chanid % 1000) {
517 } elsif ($flags & 0x20) {
522 } elsif ($state==2) {
523 /^(\S+) (.+)$/ or next;
525 $suspendby = $users{irc_lc
($1)};
526 if (not defined $suspendby) {
529 $suspendreason=doquote
($2);
537 } elsif ($state==3) {
539 $welcome=doquote
($_);
541 } elsif ($state==10) {
544 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";
545 if (($chanid % 1000)==0) {
547 my $fname=sprintf("chans-%03d.csv",$chanid/1000);
548 open CHANS
, ">$fname";
549 print SQL
"COPY chanserv.channels FROM '${pathname}${fname}' DELIMITER ',';\n";
554 /^(\S+)\s+(\S+)$/ or next;
557 $userid=getuserid
($1);
559 if (($ocuflags =~ /g/) && ($ocuflags =~ /v/)) {
562 if (($ocuflags =~ /a/) && ($ocuflags =~ /o/)) {
566 if ($ocuflags =~ /m/) {
569 if ($ocuflags =~ /n/) {
572 if ($ocuflags =~ /o/) {
575 if ($ocuflags =~ /v/) {
579 my $idstr=$userid.".".$curchanid;
580 unless (exists $chanusers{$idstr}) {
581 $chanusers{$idstr}=1;
582 print CHANUSERS
"$userid,$curchanid,$cuflags,0,0,\n";
584 if (!($chanusercount % 10000)) {
586 my $fname=sprintf("chanusers-%03d.csv",$chanusercount/10000);
587 open CHANUSERS
, ">$fname";
588 print SQL
"COPY chanserv.chanusers FROM '${pathname}${fname}' DELIMITER ',';\n";
591 print "Suppressing duplicate chanuser: $idstr\n";
602 $incoming = lc $incoming;
603 $incoming =~ tr/\[\]\|~ÆÁÀÜÐÄÅÖ/\{\}\\^æáàüðäåö/;
612 $userid=$users{irc_lc
($username)};
613 if (not defined $userid) {
614 print ORPHANS irc_lc
($username)."\n";
626 for (split //, $instr) {
629 } elsif ($_ eq "\\") {