Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(!defined("IN_MYBB"))
- {
- die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
- }
- $plugins->add_hook("member_do_register_end", "A2detector_run");
- function A2detector_info()
- {
- return array(
- "name" => "A2detector",
- "description" => "detected two or more users with the same IP.",
- "website" => "http://www.mybb-es.com",
- "author" => "Edson Ordaz",
- "authorsite" => "mailto:nicedo_eeos@hotmail.com",
- "version" => "1.1",
- "compatibility" => "16*",
- "guid" => "14b83bd42b5afd3cfbb6b36685a8020c",
- //Information - Edson Ordaz
- "codenamegroup" => "A2 Detector",
- "codename" => "aedetector"
- );
- }
- function A2detector_activate()
- {
- global $db, $cache;
- $info = A2detector_info();
- $setting_group = array(
- 'name' => $info['codename'],
- 'title' => $info['codenamegroup'],
- 'description' => "detected two or more users with the same IP.",
- 'disporder' => 1,
- 'isdefault' => 0,
- );
- $db->insert_query('settinggroups', $setting_group);
- $group = $db->insert_id();
- $settings = array(
- $info['codename'].'_subject' => array('Title PM', 'Enter the title of PM.', 'textarea', 'Double counting has been detected'),
- $info['codename'].'_body' => array('Body PM', 'Enter the message of PM. Can use<br /><b><font color=red>{numip}</font></b> to show the number of IPs detected.<br /><b><font color=red>{ip}</font></b> to show the IP.<br /><b><font color=red>{names}</font></b> To show the user name.', 'textarea', 'This is an automatic message {bbname} appreciate you not be answered.
- ------------------------------------------------
- There have been {numip} with the same IP. Your IP is {ip} and the users are:
- {names}.
- ------------------------------------------------'),
- $info['codename'].'_sender' => array('Remitters users?', 'Enter the UID of the user that will be displayed as the sender PM.', 'text', '1'),
- $info['codename'].'_recipient' => array('User to send?', 'Enter the uids of the users who receive the PM (Separate with a comma).', 'text', '1'),
- );
- $i = 1;
- foreach($settings as $name => $sinfo)
- {
- $insert_array = array(
- 'name' => $name,
- 'title' => $db->escape_string($sinfo[0]),
- 'description' => $db->escape_string($sinfo[1]),
- 'optionscode' => $db->escape_string($sinfo[2]),
- 'value' => $db->escape_string($sinfo[3]),
- 'gid' => $group,
- 'disporder' => $i,
- 'isdefault' => 0,
- );
- $db->insert_query('settings', $insert_array);
- $i++;
- }
- rebuild_settings();
- $cache->update('a2detector_errors', 0);
- }
- function A2detector_deactivate()
- {
- global $db;
- $info = A2detector_info();
- $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='{$info['codename']}'");
- $db->delete_query("settings","name LIKE '{$info['codename']}_%'");
- $db->delete_query("datacache", "title='a2detector_errors'");
- }
- function A2detector_run()
- {
- global $mybb, $session, $db;
- $query_rows = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE regip='{$session->ipaddress}'");
- $counts_ips = $db->num_rows($query_rows);
- if($counts_ips > 1)
- {
- $names = array();
- $query = $db->simple_select("users", "*", "regip='{$session->ipaddress}' or lastip='{$session->ipaddress}' or longregip='".my_ip2long($session->ipaddress)."' or longlastip='".my_ip2long($session->ipaddress)."'");
- while($users = $db->fetch_array($query))
- {
- $names[] = "[url={$mybb->settings['bburl']}/member.php?action=profile&uid={$users['uid']}][b]{$users['username']}[/b][/url]";
- }
- send_mp_a2detector($names,$counts_ips);
- }
- }
- function send_mp_a2detector($users,$numsip)
- {
- global $session,$mybb;
- require_once MYBB_ROOT."inc/datahandlers/pm.php";
- $pmhandler = new PMDataHandler();
- $usernames = implode(",", $users);
- $message = $mybb->settings['aedetector_body'];
- $message = str_replace('{bbname}', $mybb->settings['bbname'], $message);
- $message = str_replace('{names}', $usernames, $message);
- $message = str_replace('{numip}', $numsip, $message);
- $message = str_replace('{ip}', $session->ipaddress, $message);
- $toidsexplode = explode(",",$mybb->settings['aedetector_recipient']);
- $pm = array(
- "subject" => $mybb->settings['aedetector_subject'],
- "message" => $message,
- "icon" => -1,
- "fromid" => intval($mybb->settings['aedetector_sender']),
- "toid" => array_map("intval",$toidsexplode),
- "do" => '',
- "pmid" => ''
- );
- $pm['options'] = array(
- "signature" => 1,
- "disablesmilies" => 0,
- "savecopy" => 0,
- "readreceipt" => 0
- );
- $pm['saveasdraft'] = 0;
- $pmhandler->admin_override = 1;
- $pmhandler->set_data($pm);
- if($pmhandler->validate_pm())
- {
- $pmhandler->insert_pm();
- }
- else
- {
- a2detector_handle_error(&$pmhandler);
- }
- }
- function a2detector_handle_error(&$pmhandler)
- {
- global $cache;
- $errors = $cache->read("rss2post_errors");
- if($errors === false)
- {
- $errors = '';
- }
- $errors .= 'Date: ' . gmdate('r') . "\n";
- $datahandler_errors = $pmhandler->get_errors();
- ob_start();
- print_r($datahandler_errors);
- $errors .= ob_get_clean();
- $errors .= "\n\n===========================================\n\n";
- $cache->update('a2detector_errors', $errors);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement