Advertisement
Guest User

Mybb_A2Detector

a guest
Sep 8th, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.15 KB | None | 0 0
  1. <?php
  2.  
  3. if(!defined("IN_MYBB"))
  4. {
  5.     die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  6. }
  7.  
  8. $plugins->add_hook("member_do_register_end", "A2detector_run");
  9.  
  10.  
  11. function A2detector_info()
  12. {
  13.     return array(
  14.         "name"          => "A2detector",
  15.         "description"   => "detected two or more users with the same IP.",
  16.         "website"       => "http://www.mybb-es.com",
  17.         "author"        => "Edson Ordaz",
  18.         "authorsite"    => "mailto:nicedo_eeos@hotmail.com",
  19.         "version"       => "1.1",
  20.         "compatibility"   => "16*",
  21.         "guid"          => "14b83bd42b5afd3cfbb6b36685a8020c",
  22.        
  23.         //Information - Edson Ordaz
  24.         "codenamegroup"   => "A2 Detector",
  25.         "codename"      => "aedetector"
  26.     );
  27. }
  28.  
  29. function A2detector_activate()
  30. {
  31.     global $db, $cache;
  32.     $info = A2detector_info();
  33.  
  34.     $setting_group = array(
  35.         'name' => $info['codename'],
  36.         'title' => $info['codenamegroup'],
  37.         'description' => "detected two or more users with the same IP.",
  38.         'disporder' => 1,
  39.         'isdefault' => 0,
  40.         );
  41.     $db->insert_query('settinggroups', $setting_group);
  42.     $group = $db->insert_id();
  43.    
  44.     $settings = array(
  45.         $info['codename'].'_subject' => array('Title PM', 'Enter the title of PM.', 'textarea', 'Double counting has been detected'),
  46.         $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.
  47.  
  48. ------------------------------------------------
  49. There have been {numip} with the same IP. Your IP is {ip} and the users are:
  50. {names}.
  51.  
  52. ------------------------------------------------'),
  53.         $info['codename'].'_sender' => array('Remitters users?', 'Enter the UID of the user that will be displayed as the sender PM.', 'text', '1'),
  54.         $info['codename'].'_recipient' => array('User to send?', 'Enter the uids of the users who receive the PM (Separate with a comma).', 'text', '1'),
  55.     );
  56.  
  57.     $i = 1;
  58.     foreach($settings as $name => $sinfo)
  59.     {
  60.         $insert_array = array(
  61.             'name' => $name,
  62.             'title' => $db->escape_string($sinfo[0]),
  63.             'description' => $db->escape_string($sinfo[1]),
  64.             'optionscode' => $db->escape_string($sinfo[2]),
  65.             'value' => $db->escape_string($sinfo[3]),
  66.             'gid' => $group,
  67.             'disporder' => $i,
  68.             'isdefault' => 0,
  69.             );
  70.         $db->insert_query('settings', $insert_array);
  71.         $i++;
  72.     }
  73.     rebuild_settings();
  74.     $cache->update('a2detector_errors', 0);
  75. }
  76.  
  77.  
  78. function A2detector_deactivate()
  79. {
  80.     global $db;
  81.     $info = A2detector_info();
  82.     $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='{$info['codename']}'");
  83.     $db->delete_query("settings","name LIKE '{$info['codename']}_%'");
  84.     $db->delete_query("datacache", "title='a2detector_errors'");
  85. }
  86.  
  87. function A2detector_run()
  88. {
  89.     global $mybb, $session, $db;
  90.    
  91.     $query_rows = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE regip='{$session->ipaddress}'");
  92.     $counts_ips = $db->num_rows($query_rows);
  93.     if($counts_ips > 1)
  94.     {
  95.         $names = array();
  96.         $query = $db->simple_select("users", "*", "regip='{$session->ipaddress}' or lastip='{$session->ipaddress}' or longregip='".my_ip2long($session->ipaddress)."' or longlastip='".my_ip2long($session->ipaddress)."'");
  97.         while($users = $db->fetch_array($query))
  98.         {
  99.             $names[] = "[url={$mybb->settings['bburl']}/member.php?action=profile&uid={$users['uid']}][b]{$users['username']}[/b][/url]";
  100.         }
  101.         send_mp_a2detector($names,$counts_ips);
  102.     }
  103. }
  104.  
  105. function send_mp_a2detector($users,$numsip)
  106. {
  107.     global $session,$mybb;
  108.     require_once MYBB_ROOT."inc/datahandlers/pm.php";
  109.     $pmhandler = new PMDataHandler();
  110.     $usernames = implode(",", $users);
  111.     $message = $mybb->settings['aedetector_body'];
  112.     $message = str_replace('{bbname}', $mybb->settings['bbname'], $message);
  113.     $message = str_replace('{names}', $usernames, $message);
  114.     $message = str_replace('{numip}', $numsip, $message);
  115.     $message = str_replace('{ip}', $session->ipaddress, $message);
  116.     $toidsexplode = explode(",",$mybb->settings['aedetector_recipient']);
  117.     $pm = array(
  118.         "subject" => $mybb->settings['aedetector_subject'],
  119.         "message" => $message,
  120.         "icon" => -1,
  121.         "fromid" => intval($mybb->settings['aedetector_sender']),
  122.         "toid" => array_map("intval",$toidsexplode),
  123.         "do" => '',
  124.         "pmid" => ''
  125.     ); 
  126.     $pm['options'] = array(
  127.         "signature" => 1,
  128.         "disablesmilies" => 0,
  129.         "savecopy" => 0,
  130.         "readreceipt" => 0
  131.     );
  132.     $pm['saveasdraft'] = 0;
  133.     $pmhandler->admin_override = 1;
  134.     $pmhandler->set_data($pm);
  135.     if($pmhandler->validate_pm())
  136.     {
  137.         $pmhandler->insert_pm();
  138.     }
  139.     else
  140.     {
  141.         a2detector_handle_error(&$pmhandler);
  142.     }
  143. }
  144.  
  145. function a2detector_handle_error(&$pmhandler)
  146. {
  147.     global $cache;
  148.     $errors = $cache->read("rss2post_errors"); 
  149.     if($errors === false)
  150.     {
  151.         $errors = '';
  152.     }                  
  153.    
  154.     $errors .= 'Date: ' . gmdate('r') . "\n";
  155.    
  156.     $datahandler_errors = $pmhandler->get_errors();
  157.     ob_start();
  158.     print_r($datahandler_errors);
  159.     $errors .= ob_get_clean();
  160.     $errors .= "\n\n===========================================\n\n";
  161.    
  162.     $cache->update('a2detector_errors', $errors);
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement