package IIfe7ed66bde3aa68899b7883eab4be165::mod_SMF; use strict; use base 'JinPluginBaseExtScript'; use DBI; use Digest::SHA1 qw(sha1_hex); use Digest::MD5 qw(md5_hex); sub init { my $this = shift()->SUPER::init(@_); return $this->msg('error.missing_config') if grep { ! $this->{$_} } qw/dbhost dbname dbuser/; $this->{dbh} = DBI->connect("DBI:mysql:$this->{dbname}:$this->{dbhost}", $this->{dbuser}, $this->{dbpass}) or return $this->msg('error.connect_db', $DBI::errstr); my $sth = $this->sql('show tables like ?', "$this->{tblprefix}members"); return $this->msg('error.tables_not_found', $this->{tblprefix}) unless $sth->rows > 0; return; } sub addUser { my $this = shift; my $user = shift; my $script_uid = $this->_get_script_uid($user); if ($script_uid) { $this->updateUser($user); } else { my $memberName = $this->getUsernameForUser($user); my $regOptions = { memberName => $memberName, emailAddress => "$user->{email}", passwd => sha1_hex(lc($memberName).$user->{passwd}), passwordSalt => substr(md5_hex(rand()), 0, 4), posts => 0, dateRegistered => time(), memberIP => "$ENV{REMOTE_ADDR}", memberIP2 => "$ENV{REMOTE_ADDR}", validation_code => "", realName => "$user->{name}", personalText => "", pm_email_notify => 1, ID_THEME => 0, ID_POST_GROUP => 4, lngfile => "", buddy_list => "", pm_ignore_list => "", messageLabels => "", personalText => "", websiteTitle => "", websiteUrl => "", location => "", ICQ => "", AIM => "", YIM => "", MSN => "", timeFormat => "", signature => "", avatar => "", usertitle => "", secretQuestion => "", secretAnswer => "", additionalGroups => "", smileySet => "", }; my @f = keys %$regOptions; $this->sql("INSERT INTO $this->{tblprefix}members SET " . join(',', map { "$_=?" } @f), map { $regOptions->{$_} } @f) or return; $script_uid = $this->_get_script_uid($user); $this->fixScriptUID($user, $script_uid); } return $script_uid; } sub updateUser { my $this = shift; my $user = shift; if (my $script_uid = $this->_get_script_uid($user)) { my $memberName = $this->getUsernameForUser($user); $this->sql( "UPDATE $this->{tblprefix}members SET memberName=?,emailAddress=?,passwd=?,realName=? WHERE ID_MEMBER=?", $memberName, $user->{email}, sha1_hex(lc($memberName) . $user->{passwd}), $user->{name}, $script_uid, ) or return; $this->fixScriptUID($user, $script_uid); } else { $this->addUser($user); } return; } sub deleteUser { my $this = shift; my $user = shift; my $script_uid = $this->_get_script_uid($user) or return; my @queries = ( "DELETE FROM $this->{tblprefix}members WHERE ID_MEMBER=?", "UPDATE $this->{tblprefix}messages SET ID_MEMBER = 0 WHERE ID_MEMBER=?", "UPDATE $this->{tblprefix}polls  SET ID_MEMBER = 0 WHERE ID_MEMBER=?", "UPDATE $this->{tblprefix}topics  SET ID_MEMBER_STARTED = 0 WHERE ID_MEMBER_STARTED=?", "UPDATE $this->{tblprefix}topics  SET ID_MEMBER_UPDATED = 0 WHERE ID_MEMBER_UPDATED=?", "UPDATE $this->{tblprefix}log_actions  SET ID_MEMBER = 0 WHERE ID_MEMBER=?", "UPDATE $this->{tblprefix}log_banned  SET ID_MEMBER = 0 WHERE ID_MEMBER=?", "UPDATE $this->{tblprefix}log_errors  SET ID_MEMBER = 0 WHERE ID_MEMBER=?", "DELETE FROM $this->{tblprefix}log_boards WHERE ID_MEMBER=?", "DELETE FROM $this->{tblprefix}log_mark_read WHERE ID_MEMBER=?", "DELETE FROM $this->{tblprefix}log_notify WHERE ID_MEMBER=?", "DELETE FROM $this->{tblprefix}log_online WHERE ID_MEMBER=?", "DELETE FROM $this->{tblprefix}log_polls WHERE ID_MEMBER=?", "DELETE FROM $this->{tblprefix}log_topics WHERE ID_MEMBER=?", "DELETE FROM $this->{tblprefix}collapsed_categories WHERE ID_MEMBER=?", "UPDATE $this->{tblprefix}personal_messages SET ID_MEMBER_FROM = 0 WHERE ID_MEMBER_FROM=?", "DELETE FROM $this->{tblprefix}moderators WHERE ID_MEMBER=?", "DELETE FROM $this->{tblprefix}ban_items WHERE ID_MEMBER=?", "DELETE FROM $this->{tblprefix}themes WHERE ID_MEMBER=?", ); for (@queries) { $this->sql($_, $script_uid) or return; } $this->sql("DELETE FROM $this->{tblprefix}log_karma WHERE ID_TARGET=? OR ID_EXECUTOR=?", $script_uid, $script_uid) or return; $this->fixScriptUID($user, undef); return; } sub suspendUser { my $this = shift; my $user = shift; $this->deleteUser($user); return; } sub getUsernameForUser { my $this = shift; my $user = shift; $user->{email}; } sub _get_script_uid { my $this = shift; my $user = shift; my $script_uid = $this->getScriptUID($user); if ($script_uid) { my $sth = $this->sql("SELECT ID_MEMBER FROM $this->{tblprefix}members WHERE ID_MEMBER=?", $script_uid) or return; if (! $sth->rows > 0) { $script_uid = undef; $this->fixScriptUID($user, undef); } } for my $un ($this->getUsernameForUser($user), 'user'.$user->id) { my $sth = $this->sql("SELECT ID_MEMBER FROM $this->{tblprefix}members WHERE memberName=?", $un) or return; if ($sth->rows > 0) { $script_uid = $sth->fetchrow_array; last; } } $script_uid; } 1;