/** * Load data from Request form fields. * * @return boolean true if loaded data seems valid. */ function load_from_Request() { global $Messages; $aipr_status = param('aipr_status', 'string', true); $this->set('status', $aipr_status, true); $aipr_IPv4start = param('aipr_IPv4start', 'string', true); param_check_regexp('aipr_IPv4start', '#^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$#i', T_('Please enter a correct IP range start')); $aipr_IPv4start = ip2int($aipr_IPv4start); $this->set('IPv4start', $aipr_IPv4start); $aipr_IPv4end = param('aipr_IPv4end', 'string', true); param_check_regexp('aipr_IPv4end', '#^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$#i', T_('Please enter a correct IP range end')); $aipr_IPv4end = ip2int($aipr_IPv4end); $this->set('IPv4end', $aipr_IPv4end); // start timestamp: param_date('aipr_IP_timestamp', T_('Please enter a valid Date.'), true); $this->set('IP_datetime', form_date(get_param('aipr_IP_timestamp'))); if ($aipr_IPv4start > $aipr_IPv4end) { $Messages->add(T_('IP range start must be less than IP range end'), 'error'); } if (!param_errors_detected()) { // Check IPs for inside in other ranges if ($ip_range = get_ip_range($aipr_IPv4start, $aipr_IPv4end, $this->ID)) { $admin_url; $Messages->add(sprintf(T_('IP range already exists with params: %s - <a %s>Edit this range</a>'), int2ip($ip_range->aipr_IPv4start) . ' - ' . int2ip($ip_range->aipr_IPv4end), 'href="' . $admin_url . '?ctrl=antispam&tab3=ipranges&action=iprange_edit&iprange_ID=' . $ip_range->aipr_ID . '"'), 'error'); } } return !param_errors_detected(); }
/** * Insert object into DB based on previously recorded changes * * Triggers the plugin event AfterUserInsert. * * @param boolean TRUE to automatically create new blog if group has permission * @return boolean true on success */ function dbinsert($create_auto_blog = true) { global $Plugins, $DB; $DB->begin(); if ($result = parent::dbinsert()) { // We could insert the user object.. // Add new fields: if (!empty($this->new_fields)) { $sql = 'INSERT INTO T_users__fields( uf_user_ID, uf_ufdf_ID, uf_varchar ) VALUES (' . $this->ID . ', ' . implode('), (' . $this->ID . ', ', $this->new_fields) . ' )'; $DB->query($sql, 'Insert new fields'); // Reset new fields in object: $this->new_fields = array(); } // Notify plugins: // A user could be created also in another DB (to synchronize it with b2evo) $Plugins->trigger_event('AfterUserInsert', $params = array('User' => &$this)); $Group =& $this->get_Group(); if ($create_auto_blog && $Group->check_perm('perm_getblog', 'allowed')) { // automatically create new blog for this user // TODO: sam2kb> Create a blog only when this user is validated! $new_Blog = new Blog(NULL); $shortname = $this->get('login'); $new_Blog->set('owner_user_ID', $this->ID); $new_Blog->set('shortname', $shortname); $new_Blog->set('name', $shortname . '\'s blog'); $new_Blog->set('locale', $this->get('locale')); $new_Blog->set('urlname', urltitle_validate($shortname, $shortname, $new_Blog->ID, false, 'blog_urlname', 'blog_ID', 'T_blogs', $this->get('locale'))); // Defines blog settings by its kind. $Plugins->trigger_event('InitCollectionKinds', array('Blog' => &$new_Blog, 'kind' => 'std')); $new_Blog->create(); } /* Save IP Range -- start */ $ip = int2ip(ip2int($_SERVER['REMOTE_ADDR'])); // Convert IPv6 to IPv4 if (preg_match('#^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$#i', $ip)) { // Check IP for correct format $ip_24bit_start = ip2int(preg_replace('#\\.\\d{1,3}$#i', '.0', $ip)); $ip_24bit_end = ip2int(preg_replace('#\\.\\d{1,3}$#i', '.255', $ip)); if ($iprange = get_ip_range($ip_24bit_start, $ip_24bit_end)) { // Update ip range $DB->query('UPDATE T_antispam__iprange SET aipr_user_count = ' . $DB->quote($iprange->aipr_user_count + 1) . ' WHERE aipr_ID = ' . $DB->quote($iprange->aipr_ID)); } else { // Insert new ip range $DB->query('INSERT INTO T_antispam__iprange ( aipr_IPv4start, aipr_IPv4end, aipr_user_count ) VALUES ( ' . $DB->quote($ip_24bit_start) . ', ' . $DB->quote($ip_24bit_end) . ', ' . $DB->quote('1') . ' ) '); } } /* Save IP Range -- end */ } $DB->commit(); return $result; }
/** * Load data from Request form fields. * * @return boolean true if loaded data seems valid. */ function load_from_Request() { global $Messages; $aipr_status = param('aipr_status', 'string', true); $this->set('status', $aipr_status, true); $aipr_IPv4start = param('aipr_IPv4start', 'string', true); param_check_regexp('aipr_IPv4start', '#^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$#i', T_('Please enter a correct IP range start')); $aipr_IPv4start = ip2int($aipr_IPv4start); $this->set('IPv4start', $aipr_IPv4start); $aipr_IPv4end = param('aipr_IPv4end', 'string', true); param_check_regexp('aipr_IPv4end', '#^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$#i', T_('Please enter a correct IP range end')); $aipr_IPv4end = ip2int($aipr_IPv4end); $this->set('IPv4end', $aipr_IPv4end); if ($aipr_IPv4start > $aipr_IPv4end) { $Messages->add(T_('IP range start must be less than IP range end'), 'error'); } if (!param_errors_detected()) { // Check IPs for inside in other ranges if ($ip_range = get_ip_range($aipr_IPv4start, $aipr_IPv4end, $this->ID)) { $Messages->add(sprintf(T_('IP range already exists with params: %s'), int2ip($ip_range->aipr_IPv4start) . ' - ' . int2ip($ip_range->aipr_IPv4end)), 'error'); } } return !param_errors_detected(); }
$json['data'] = array(); if (!db_connect()) { $json['result'] = false; $json['error'] = 'database'; break; } if ($res = QuerySql("SELECT DISTINCT IP FROM \n\t\t(SELECT IP \n\t\tFROM `BASE_TABLE`, `GEO_TABLE` \n\t\tWHERE (`GEO_TABLE`.`quadkey` >> 32) IN {$quadkeys} AND\n\t\t\t\t`BASE_TABLE`.`BSSID` = `GEO_TABLE`.`BSSID` \n\t\t\t\tAND (`GEO_TABLE`.`quadkey` IS NOT NULL) \n\t\t\t\tAND (`GEO_TABLE`.`latitude` BETWEEN {$lat1} AND {$lat2} AND `GEO_TABLE`.`longitude` BETWEEN {$lon1} AND {$lon2}) \n\t\t\t\tAND (IP != 0 AND IP != -1) \n\t\tUNION SELECT WANIP \n\t\tFROM `BASE_TABLE`, `GEO_TABLE` \n\t\tWHERE (`GEO_TABLE`.`quadkey` >> 32) IN {$quadkeys} AND\n\t\t\t\t`BASE_TABLE`.`BSSID` = `GEO_TABLE`.`BSSID` \n\t\t\t\tAND (`GEO_TABLE`.`quadkey` IS NOT NULL) \n\t\t\t\tAND (`GEO_TABLE`.`latitude` BETWEEN {$lat1} AND {$lat2} AND `GEO_TABLE`.`longitude` BETWEEN {$lon1} AND {$lon2}) \n\t\t\t\tAND (WANIP != 0 AND WANIP != -1)\n\t\t) IPTable ORDER BY CAST(IP AS UNSIGNED INTEGER)")) { } require 'ipext.php'; $last_upper = 0; while ($row = $res->fetch_row()) { $ip = (int) $row[0]; if (compare_ip($ip, $last_upper) <= 0) { continue; } $ip_range = get_ip_range($db, $ip); if (is_null($ip_range)) { continue; } $last_upper = $ip_range['endIP']; $json['data'][] = array('range' => pretty_range($ip_range['startIP'], $ip_range['endIP']), 'netname' => $ip_range['netname'], 'descr' => $ip_range['descr'], 'country' => $ip_range['country']); } $res->close(); usort($json['data'], function ($a, $b) { return strcmp($a['descr'], $b['descr']); }); array_unique($json['data'], SORT_REGULAR); $db->close(); break; // Определение устройства по MAC // Определение устройства по MAC
/** * Increase a counter in DB antispam ip range table * * @param string Counter name: 'user', 'contact_email' */ function antispam_increase_counter($counter_name) { switch ($counter_name) { case 'user': $field_name = 'aipr_user_count'; break; case 'contact_email': $field_name = 'aipr_contact_email_count'; break; default: debug_die('Wrong antispam counter name'); } foreach (get_ip_list() as $ip) { if ($ip === '') { // Skip an empty continue; } $ip = int2ip(ip2int($ip)); // Convert IPv6 to IPv4 if (preg_match('#^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$#i', $ip)) { // Check IP for correct format $ip_24bit_start = ip2int(preg_replace('#\\.\\d{1,3}$#i', '.0', $ip)); $ip_24bit_end = ip2int(preg_replace('#\\.\\d{1,3}$#i', '.255', $ip)); global $DB; if ($iprange = get_ip_range($ip_24bit_start, $ip_24bit_end)) { // Update ip range $DB->query('UPDATE T_antispam__iprange SET ' . $field_name . ' = ' . $field_name . ' + 1 WHERE aipr_ID = ' . $DB->quote($iprange->aipr_ID)); } else { // Insert new ip range $DB->query('INSERT INTO T_antispam__iprange ( aipr_IPv4start, aipr_IPv4end, ' . $field_name . ' ) VALUES ( ' . $DB->quote($ip_24bit_start) . ', ' . $DB->quote($ip_24bit_end) . ', 1 ) '); } } } }