This commit is contained in:
2019-02-06 00:49:12 +03:00
commit 8dbb1bb605
4796 changed files with 506072 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
#!/usr/bin/perl
# remote user id of user to clean
my $ru_id = 491;
# database connection
my $queue_db = "livejournal";
my $queue_host = "localhost";
my $queue_login = "lj";
my $queue_pass = "lj-upyri";
use strict; # preventing my program from doing bad things
use DBI; # http://dbi.perl.org
$| = 1; # unbuffered (almost) output
my $dbh = DBI->connect(
"DBI:mysql:$queue_db:$queue_host",
$queue_login, $queue_pass,
{RaiseError => 0, AutoCommit => 1}
) || die "Can't open database connection: $DBI::errstr";
my $sth = $dbh->prepare("select * from ljr_remote_users where ru_id = $ru_id");
$sth->execute;
while (my $row = $sth->fetchrow_hashref) {
if ($row->{created_comments_maxid} > 0) {
die "User has created comments. Cannot clean cached comments (IMPLEMENT THIS!)\n";
}
my $sth1 = $dbh->prepare("select * from ljr_cached_users where ru_id = $ru_id");
$sth1->execute();
my $row1 = $sth1->fetchrow_hashref;
print
"You're about to delete cached comments for user [" .
$row1->{remote_username} . "].\n" .
"Please confirm by typing their username: "
;
while (<>) {
my $iu = $_;
if ($iu =~ /\s*(.*)\s*/) {
$iu = $1;
}
if ($iu ne $row1->{remote_username}) {
die "You have to learn to type letters to use this tool.\n";
}
last;
}
$sth1->finish;
print "deleting cached comprops...\n";
$sth1 = $dbh->prepare("select * from ljr_cached_comments where ru_id = $ru_id");
$sth1->execute();
while ($row1 = $sth1->fetchrow_hashref) {
my $sth2 = $dbh->prepare(
"delete from ljr_cached_comprops where cc_id = " . $row1->{cc_id}
);
$sth2->execute();
$sth2->finish;
print ".";
}
$sth1->finish;
print "deleting cached comments...\n";
$sth1 = $dbh->prepare(
"delete from ljr_cached_comments where ru_id = " . $ru_id
);
$sth1->execute();
$sth1->finish;
print "resetting cached counters...\n";
$sth1 = $dbh->prepare(
"update ljr_cached_users
set remote_meta_maxid = 0, cached_comments_maxid = 0
where ru_id = " . $ru_id);
$sth1->execute();
$sth1->finish;
}
$sth->finish;
$dbh->disconnect;

View File

@@ -0,0 +1,94 @@
#!/usr/bin/perl
# database connection
my $queue_db = "livejournal";
my $queue_host = "localhost";
my $queue_login = "lj";
my $queue_pass = "lj-upyri";
use strict; # preventing my program from doing bad things
use DBI; # http://dbi.perl.org
$| = 1; # unbuffered (almost) output
my $dbh = DBI->connect(
"DBI:mysql:$queue_db:$queue_host",
$queue_login, $queue_pass,
{RaiseError => 0, AutoCommit => 1}
) || die "Can't open database connection: $DBI::errstr";
my $username;
my $new_identity;
my $sth = $dbh->prepare(
"select * from identitymap where idtype='O' and identity like 'http://www.livejournal.com/%'");
$sth->execute;
while (my $row = $sth->fetchrow_hashref) {
$username = "";
if ($row->{"identity"} =~ /\/users\/(.+[^\/])\/??/ || $row->{"identity"} =~ /\/\~(.+[^\/])\/??/) {
my $new_id;
my $old_email;
my $new_email;
my $sth2;
$username = $1;
$new_identity = "";
if ($username =~ /^_/ || $username =~ /_$/) {
$new_identity = "http://users.livejournal.com/" . $username . "/";
}
else {
$new_identity = "http://" . $username . ".livejournal.com/";
}
$sth2 = $dbh->prepare("select email from user where userid = " . $row->{"userid"});
$sth2->execute;
if (my $row1 = $sth2->fetchrow_hashref) {
$old_email = $row1->{"email"};
}
$sth2->finish;
$sth2 = $dbh->prepare(
"select * from identitymap where idtype='O' and identity ='" . $new_identity . "'");
$sth2->execute();
if (my $row1 = $sth2->fetchrow_hashref) {
$new_id = $row1->{"userid"};
my $sth3 = $dbh->prepare("select email from user where userid = " . $new_id);
$sth3->execute;
if (my $row2 = $sth3->fetchrow_hashref) {
$new_email = $row2->{"email"};
}
$sth3->finish;
print
$username . "(" .
$row->{"userid"} . ", " . $old_email . "):(" .
$new_id . "," . $new_email . ")\n";
}
$sth2->finish;
if (!$new_id) {
$sth2 = $dbh->prepare(
"update identitymap set identity = '" . $new_identity . "' " .
"where idtype='O' and userid = " . $row->{"userid"}
);
$sth2->execute();
$sth2->finish;
}
else {
if (!$new_email) {
$sth2 = $dbh->prepare("update user set email = '" . $old_email . "' " .
"where userid = " . $new_id);
$sth2->execute();
$sth2->finish;
}
}
}
}
$sth->finish;
$dbh->disconnect;

View File

@@ -0,0 +1,113 @@
#!/usr/bin/perl
use strict;
require "$ENV{'LJHOME'}/cgi-bin/ljlib.pl";
require "$ENV{'LJHOME'}/cgi-bin/talklib.pl";
# remote user id of user to clean
my $ru_id = 27850;
# database connection
my $queue_db = "livejournal";
my $queue_host = "localhost";
my $queue_login = "lj";
my $queue_pass = "lj-upyri";
use strict; # preventing my program from doing bad things
use DBI; # http://dbi.perl.org
$| = 1; # unbuffered (almost) output
my $dbh = DBI->connect(
"DBI:mysql:$queue_db:$queue_host",
$queue_login, $queue_pass,
{RaiseError => 0, AutoCommit => 1}
) || die "Can't open database connection: $DBI::errstr";
my $sth = $dbh->prepare("select * from ljr_remote_users where ru_id = $ru_id");
$sth->execute;
while (my $row = $sth->fetchrow_hashref) {
if (! $row->{ru_id}) {
die "User not found.\n";
}
my $sth1 = $dbh->prepare("select * from ljr_cached_users where ru_id = $ru_id");
$sth1->execute();
my $row1 = $sth1->fetchrow_hashref;
print
"You're about to delete user [" .
$row1->{remote_username} . "].\n" .
"Please confirm by typing their username: "
;
while (<>) {
my $iu = $_;
if ($iu =~ /\s*(.*)\s*/) { $iu = $1; }
if ($iu ne $row1->{remote_username}) {
die "You have to learn to type letters to use this tool.\n";
}
last;
}
$sth1->finish;
print "deleting cached comprops and remote comments...\n";
$sth1 = $dbh->prepare("select * from ljr_cached_comments where ru_id = $ru_id");
$sth1->execute();
while ($row1 = $sth1->fetchrow_hashref) {
my $sth2 = $dbh->prepare("delete from ljr_cached_comprops where cc_id = " . $row1->{cc_id});
$sth2->execute();
$sth2->finish;
$sth2 = $dbh->prepare("delete from ljr_remote_comments where cc_id = " . $row1->{cc_id});
$sth2->execute();
$sth2->finish;
print ".";
}
$sth1->finish;
print "deleting cached comments...\n";
$sth1 = $dbh->prepare("delete from ljr_cached_comments where ru_id = $ru_id");
$sth1->execute();
$sth1->finish;
print "deleting ljr_cached_userpics...\n";
$sth1 = $dbh->prepare("delete from ljr_cached_userpics where ru_id = $ru_id");
$sth1->execute();
$sth1->finish;
print "deleting ljr_cached_users...\n";
$sth1 = $dbh->prepare("delete from ljr_cached_users where ru_id = $ru_id");
$sth1->execute();
$sth1->finish;
print "deleting local entries...\n";
my $lu;
$sth1 = $dbh->prepare("select * from ljr_remote_entries where ru_id = $ru_id");
$sth1->execute();
while ($row1 = $sth1->fetchrow_hashref) {
$lu = LJ::load_userid($row1->{"local_journalid"}) unless $lu;
LJ::delete_entry($lu, $row1->{"local_jitemid"});
}
$sth1->finish;
print "deleting ljr_remote_entries...\n";
$sth1 = $dbh->prepare("delete from ljr_remote_entries where ru_id = $ru_id");
$sth1->execute();
$sth1->finish;
print "deleting ljr_remote_userpics...\n";
$sth1 = $dbh->prepare("delete from ljr_remote_userpics where ru_id = $ru_id");
$sth1->execute();
$sth1->finish;
}
$sth->finish;
$sth = $dbh->prepare("delete from ljr_remote_users where ru_id = $ru_id");
$sth->execute;
$sth->finish;
$dbh->disconnect;

View File

@@ -0,0 +1,26 @@
#!/usr/bin/perl -w
use strict;
use Simple; # corrected LJ::Simple
use XML::Parser;
require "$ENV{'LJHOME'}/cgi-bin/ljlib.pl";
require "$ENV{'LJHOME'}/cgi-bin/talklib.pl";
require "ljr-defaults.pl";
require "ljr-links.pl";
require LJR::Distributed;
require "ipics.pl";
#require "ijournal.pl";
#require "icomments.pl";
my $e = import_pics(
"http://www.livejournal.com",
"sharlei",
"",
"imp_5204",
"", 1);
print $e->{errtext} ."\n" if $e->{err};

View File

@@ -0,0 +1,50 @@
#!/usr/bin/perl -w
#
# replaces text in all journal entries. use with caution.
#
BEGIN {
$ENV{'LJHOME'} = "/home/lj-admin/lj";
};
use strict;
use lib $ENV{'LJHOME'}."/cgi-bin";
require "$ENV{'LJHOME'}/cgi-bin/ljlib.pl";
my $dbh = LJ::get_dbh("master");
my ($journal, $from_text, $to_text, $do) = @ARGV;
die("usage: $0 journal_name from_text to_text")
unless $journal && $from_text && $to_text;
$do = 'no' unless $do;
my $u = LJ::load_user($journal);
die("Invalid journal [$journal]") unless $u;
print "Loaded: $u->{'name'} [$u->{'userid'}] \n";
my $sth = $dbh->prepare("select * from logtext2 where journalid = ?");
$sth->execute($u->{'userid'});
while (my $r = $sth->fetchrow_hashref()) {
if ($r->{'event'} =~ /$from_text/) {
print "journal entry [$r->{'jitemid'}] matches\n";
# print "journal entry [$r->{'jitemid'}] matches:\n$r->{'event'}\n";
$r->{'event'} =~ s/$from_text/$to_text/g;
# print "replaced:\n$r->{'event'}\n\n";
if ($do eq 'process') {
$dbh->do("UPDATE logtext2 set event = ? where journalid=? and jitemid=?",
undef, $r->{'event'}, $r->{'journalid'}, $r->{'jitemid'});
if ($dbh->err) {
die("Error while updating entry [$r->{'jitemid'}]: " . $dbh->errstr);
}
}
}
}
print "do not forget to restart memcache" if $do eq 'process';
print "finished\n";

View File

@@ -0,0 +1,53 @@
#!/usr/bin/perl -w
#
# converts s1usercache and s1stylecache blob fields
# which store Storable::freeze data from ::freeze to ::nfreeze
#
# 14oct07 petya@nigilist.ru
# initial revision
#
sub convert {
my ($dbh, $table, $unique, $field) = @_;
print "convert $table.$field ($unique)\n";
my $sql = "select * from $table;";
my $sth = $dbh->prepare($sql) or die "preparing: ", $dbh->errstr;
$sth->execute or die "executing: ", $dbh->errstr;
while (my $row = $sth->fetchrow_hashref) {
if ($row->{"$field"}) {
my $obj = Storable::thaw($row->{"$field"});
if ($obj) {
print $row->{"$unique"} . "\n";
$dbh->do("UPDATE $table SET $field=? WHERE $unique=?", undef,
Storable::nfreeze($obj), $row->{"$unique"}) ||
die "Error updating $table. Unique id: " . $row->{"$unique"} . "\n";
}
}
}
print "\n";
}
use strict;
use DBI;
use Storable;
$ENV{'LJHOME'} = "/home/lj-admin";
do $ENV{'LJHOME'} . "/lj/cgi-bin/ljconfig.pl";
my $host = $LJ::DBINFO{'master'}->{'host'};
my $user = $LJ::DBINFO{'master'}->{'user'};
my $pwd = $LJ::DBINFO{'master'}->{'pass'};
my $db = "prod_livejournal";
$| = 1; # turn off buffered output
# connect to the database.
my $dbh = DBI->connect( "DBI:mysql:mysql_socket=/tmp/mysql.sock;hostname=$host;port=3306;database=$db", $user, $pwd)
or die "Connecting : $DBI::errstr\n ";
#convert ($dbh, "s1stylecache", "styleid", "vars_stor");
#convert ($dbh, "s1usercache", "userid", "color_stor");
#convert ($dbh, "s1usercache", "userid", "override_stor");

View File

@@ -0,0 +1,128 @@
#!/usr/bin/perl
use strict;
use XMLRPC::Lite;
use Digest::MD5 qw(md5_hex);
use DBI;
use Time::Local;
use lib "$ENV{'LJHOME'}/cgi-bin";
do $ENV{'LJHOME'} . "/cgi-bin/ljconfig.pl";
require "$ENV{'LJHOME'}/cgi-bin/ljlib.pl";
use LJR::Viewuserstandalone;
use LJR::Gate;
use LJR::Distributed;
#
#îÁÓÔÒÏÊËÉ
#
#ó×ÏÊÓÔ×Á ÓÏÅÄÉÎÅÎÉÑ Ó ÂÁÚÏÊ
my $qhost = $LJ::DBINFO{'master'}->{'host'};
my $quser = $LJ::DBINFO{'master'}->{'user'};
my $qpass = $LJ::DBINFO{'master'}->{'pass'};
my $qsock = $LJ::DBINFO{'master'}->{'sock'};
my $qport = $LJ::DBINFO{'master'}->{'port'};
my $dbh = DBI->connect(
"DBI:mysql:mysql_socket=$qsock;hostname=$qhost;port=$qport;database=prod_ljgate",
$quser, $qpass, ) || die localtime(time) . ": Can't connect to database\n";
my $dbhljr = DBI->connect(
"DBI:mysql:mysql_socket=$qsock;hostname=$qhost;port=$qport;database=prod_livejournal",
$quser, $qpass, ) || die localtime(time) . ": Can't connect to database\n";
my $get_our = sub {
my ($userid) = @_;
my $sqh = $dbh->prepare("SELECT * FROM our_user where userid=?");
$sqh->execute($userid);
my $res = $sqh->fetchrow_hashref;
$sqh->finish;
return $res;
};
my $get_alien = sub {
my ($userid) = @_;
my $sqh = $dbh->prepare("SELECT * FROM alien where alienid=?");
$sqh->execute($userid);
my $res = $sqh->fetchrow_hashref;
$sqh->finish;
return $res;
};
my $get_lj_user = sub {
my ($user) = @_;
$user =~ s/\-/\_/g;
my $sqh = $dbhljr->prepare("SELECT * FROM user where user=?");
$sqh->execute($user);
my $res = $sqh->fetchrow_hashref;
$sqh->finish;
return $res;
};
my $count_gated_records = sub {
my ($userid) = @_;
my $sqh = $dbh->prepare("SELECT count(*) FROM rlj_lj_id where userid=?");
$sqh->execute($userid);
my ($res) = $sqh->fetchrow_array;
$sqh->finish;
return $res;
};
my $sqh = $dbh->prepare("SELECT userid,alienid FROM rlj2lj");
$sqh->execute;
my $result;
while ($result = $sqh->fetchrow_hashref) {
my $our = $get_our->($result->{'userid'});
my $alien = $get_alien->($result->{'alienid'});
if ($our && $alien && $alien->{'alienpass'}) {
my $ljuser = $get_lj_user->($our->{'our_user'});
my $ru = LJR::Distributed::get_remote_server("www.livejournal.com");
die $ru->{"errtext"} if $ru->{"err"};
$ru->{'username'} = $alien->{'alien'};
$ru = LJR::Distributed::get_cached_user($ru);
die $ru->{"errtext"} if $ru->{"err"};
print
$our->{'our_user'} .
" -> " .
$alien->{'alien'} . " ($ru->{'ru_id'}) " . "pass: " . $alien->{'alienpass'} .
"\n"
;
my $r = LJR::Distributed::update_export_settings($our->{'our_user'}, $ru->{'ru_id'}, $alien->{'alienpass'});
die $r->{'errtext'} if $r->{'err'};
if ($ljuser) {
print "ljr id: " . $ljuser->{'userid'};
}
else {
print "ljr id: error";
}
print "; ";
my $gated_records = $count_gated_records->($our->{'userid'});
print $gated_records;
print "\n";
# my $xmlrpc = LJR::Gate::Authenticate ("www.livejournal.com",
# $alien->{'alien'}, $alien->{'alienpass'});
# if ($xmlrpc->{'err_text'}) {
# print "err\n";
# }
# else {
# print "ok\n";
# }
}
else {
print
$result->{'userid'} . "($our->{'our_user'})" . " -> " .
$result->{'alienid'} . "($alien->{'alien'})" . "\n"
;
}
}
$sqh->finish;
$dbh->disconnect;
$dbhljr->disconnect;