#!/usr/bin/perl -w
my
$VERSION
=
'0.08'
;
my
$BASE
;
BEGIN {
$BASE
=
'../../cgi-bin'
;
}
use
lib (
"$BASE/lib"
,
"$BASE/plugins"
);
my
%names
;
my
$config
=
"$BASE/config/settings.ini"
;
my
$mech
= WWW::Mechanize->new();
$mech
->agent_alias(
'Linux Mozilla'
);
my
$crypt
= Crypt::Lite->new(
debug
=> 0,
encoding
=>
'hex8'
);
Labyrinth::Globals::LoadSettings(
$config
);
Labyrinth::Globals::DBConnect();
my
$yapc
=
$settings
{icode};
my
$key
=
$settings
{yapc_name};
my
$api
=
$settings
{actapi_pass};
my
$fmt
=
$settings
{actapi_users};
my
$names
=
$settings
{tutor_names};
for
my
$pattern
(
@$names
) {
my
(
$k
,
$v
) =
split
(
'='
,
$pattern
);
$names
{
$k
} =
$v
;
}
my
$url
=
sprintf
$fmt
,
$yapc
,
$api
;
$mech
->get(
$url
);
unless
(
$mech
->success) {
print
"FAIL: url=$url\n"
;
exit
;
}
my
$data
= from_json(
$mech
->content());
my
(
$found
,
$saved
,
$reset
,
$total
) = (0,0,0,0);
my
%users
;
for
my
$user
(
@$data
) {
for
my
$name
(
keys
%names
) {
next
unless
(
$user
->{full_name} =~ /
$name
/);
$user
->{full_name} =
$names
{
$name
};
}
my
$name
= encode_entities(
$user
->{full_name});
my
$nick
= encode_entities(
$user
->{nick_name});
$users
{
$user
->{email}} = 1;
my
@rows
;
@rows
=
$dbi
->GetQuery(
'hash'
,
'FindUserByAct'
,
$user
->{user_id})
if
(
$user
->{user_id});
@rows
=
$dbi
->GetQuery(
'hash'
,
'FindUser'
,
$user
->{email})
unless
(
@rows
);
if
(
@rows
) {
if
(!
$rows
[0]->{actuserid} ||
$rows
[0]->{actuserid} == 0) {
$dbi
->DoQuery(
'UpdateActUser'
,
$user
->{user_id},
$rows
[0]->{userid});
}
if
(
$rows
[0]->{userid} > 2) {
my
@keys
=
$dbi
->GetQuery(
'hash'
,
'GetUserCode'
,
$rows
[0]->{userid});
$dbi
->DoQuery(
'ConfirmUser'
,1,
$rows
[0]->{userid});
$found
++;
}
next
;
}
my
$str
= $$ .
$user
->{email} .
time
();
my
$code
= sha1_hex(
$crypt
->encrypt(
$str
,
$key
));
$user
->{user_id} ||= 0;
my
$userid
=
$dbi
->IDQuery(
'NewUser'
,
$user
->{email},
$nick
,
$name
,
$user
->{email},
$user
->{user_id});
$dbi
->DoQuery(
'ConfirmUser'
,1,
$userid
);
$dbi
->DoQuery(
'SaveUserCode'
,
$code
,
$userid
);
print
"SAVED: $name <$user->{email}> => $code/$userid/$user->{user_id}\n"
;
$saved
++;
}
my
@users
=
$dbi
->GetQuery(
'hash'
,
'AllUsers'
);
print
"FOUND: $found\n"
;
print
"SAVED: $saved\n"
;
print
"RESET: $reset\n"
;
print
"TOTAL: "
.(
scalar
@users
).
"\n"
;