gboolean fill_http_addr_html(void *key, qstats_t * val, struct evbuffer *buf) { char addrbuf[INET6_ADDRSTRLEN]; thrash_inet_ntop(val->s6addr, addrbuf, sizeof(addrbuf)), evbuffer_add_printf(buf, "<tr><td onclick=\"ipMouse('%s');\">%s</td>", addrbuf, addrbuf); #ifdef WITH_GEOIP if(gi) evbuffer_add_printf(buf, "<td>%s</td>", blankprint(GeoIP_country_name_by_ipnum_v6(gi, *(geoipv6_t*)&(val->s6addr)))); #endif evbuffer_add_printf(buf, "<td>%d</td>", val->connections); if (val->timeout.ev_timeout.tv_sec == 0) { evbuffer_add_printf(buf, "<td>N/A</td>"); } else { evbuffer_add_printf(buf, "<td>%d</td>", event_remaining_seconds(&val->timeout)); } evbuffer_add_printf(buf, "<td>%s</td>", blankprint(val->reason)); if (http_password) evbuffer_add_printf(buf, "<td><a href=\"action?action=removeAddr&key=%s\">Remove</a> <a href=\"action?action=blockAddr&key=%s\">Block</a></td>", (char*)key, (char*)key); evbuffer_add_printf(buf, "</tr>"); return FALSE; }
/* * Country lookups are performed if the previous lookup was from a * different IP address than the current, or was for a search of a * different subtype. */ static const char * country_lookup(GeoIP *db, dns_geoip_subtype_t subtype, unsigned int family, isc_uint32_t ipnum, const geoipv6_t *ipnum6) { geoip_state_t *prev_state = NULL; const char *text = NULL; REQUIRE(db != NULL); #ifndef HAVE_GEOIP_V6 /* no IPv6 support? give up now */ if (family == AF_INET6) return (NULL); #endif prev_state = get_state_for(family, ipnum, ipnum6); if (prev_state != NULL && prev_state->subtype == subtype) text = prev_state->text; if (text == NULL) { switch (subtype) { case dns_geoip_country_code: if (family == AF_INET) text = GeoIP_country_code_by_ipnum(db, ipnum); #ifdef HAVE_GEOIP_V6 else text = GeoIP_country_code_by_ipnum_v6(db, *ipnum6); #endif break; case dns_geoip_country_code3: if (family == AF_INET) text = GeoIP_country_code3_by_ipnum(db, ipnum); #ifdef HAVE_GEOIP_V6 else text = GeoIP_country_code3_by_ipnum_v6(db, *ipnum6); #endif break; case dns_geoip_country_name: if (family == AF_INET) text = GeoIP_country_name_by_ipnum(db, ipnum); #ifdef HAVE_GEOIP_V6 else text = GeoIP_country_name_by_ipnum_v6(db, *ipnum6); #endif break; default: INSIST(0); } set_state(family, ipnum, ipnum6, subtype, NULL, NULL, NULL, text, 0); } return (text); }
const char *NET_GeoIP_Country( const netadr_t *from ) { switch ( from->type ) { case NA_IP: return geoip_data_4 ? GeoIP_country_name_by_ipnum( geoip_data_4, htonl( *(uint32_t *)from->ip ) ) : nullptr; case NA_IP6: return geoip_data_6 ? GeoIP_country_name_by_ipnum_v6( geoip_data_6, *(struct in6_addr *)from->ip6 ) : nullptr; default: return nullptr; } }
gboolean fill_http_urihost_html(void *key, qstats_t * val, struct evbuffer *buf, char *type) { char *semi; char addrbuf[INET6_ADDRSTRLEN]; thrash_inet_ntop(val->s6addr, addrbuf, sizeof(addrbuf)), evbuffer_add_printf(buf, "<tr><td onclick=\"ipMouse('%s');\">%s</td>", addrbuf, addrbuf); #ifdef WITH_GEOIP if(gi) evbuffer_add_printf(buf, "<td>%s</td>", blankprint(GeoIP_country_name_by_ipnum_v6(gi, *(geoipv6_t*)&(val->s6addr)))); #endif evbuffer_add_printf(buf, "<td>%d</td>", val->connections); if (val->timeout.ev_timeout.tv_sec == 0) { evbuffer_add_printf(buf, "<td>N/A</td>"); } else { evbuffer_add_printf(buf, "<td>%d</td>", event_remaining_seconds(&val->timeout)); } evbuffer_add_printf(buf, "<td>%s</td>", blankprint(val->reason)); /* Print up to 80 chars of the uri or host */ semi = strchr(key, ';'); if (semi) { gchar *escaped = g_markup_escape_text(semi+1, MIN(80, strlen(semi+1))); evbuffer_add_printf(buf, "<td>%s</td>", escaped); g_free(escaped); } else evbuffer_add_printf(buf, "<td></td>"); if (http_password) { char *ukey = g_uri_escape_string(key, 0, 0); evbuffer_add_printf(buf, "<td><a href=\"action?action=remove%s&key=%s\">Remove</a> <a href=\"action?action=block%s&key=%s\">Block</a></td>", type, (char*)ukey, type, (char*)ukey); g_free(ukey); } evbuffer_add_printf(buf, "</tr>"); return FALSE; }
gboolean fill_http_blocks_html(void *key, blocked_node_t * val, struct evbuffer *buf) { char addr[INET6_ADDRSTRLEN]; thrash_inet_ntop(val->s6addr, addr, sizeof(addr)); evbuffer_add_printf(buf, "<tr><td onclick=\"ipMouse('%s');\">%s</td>", addr, addr); #ifdef WITH_GEOIP if(gi) evbuffer_add_printf(buf, "<td>%s</td>", blankprint(GeoIP_country_name_by_ipnum_v6(gi, *(geoipv6_t*)&(val->s6addr)))); #endif inet_ntop(AF_INET, &(val->first_seen_addr), addr, sizeof(addr)); evbuffer_add_printf(buf, "<td>%s</td><td>%d</td>", addr, val->count); if (val->count == 0) { evbuffer_add_printf(buf, "<td>%s</td> ", "N/A"); } else if (val->avg_distance_usec == 0) { evbuffer_add_printf(buf, "<td>%s</td>", "Infinite"); } else { struct timeval now_tv; evutil_gettimeofday(&now_tv, NULL); uint64_t arrival_gap = (now_tv.tv_sec - val->last_time.tv_sec) * 1000000 + (now_tv.tv_usec - val->last_time.tv_usec); double avg_distance_usec = (val->avg_distance_usec * (velocity_num - 1) + arrival_gap) / velocity_num; evbuffer_add_printf(buf, "<td>%.3f</td>", (double)1000000.0/avg_distance_usec); } if (val->timeout.ev_timeout.tv_sec == 0) { evbuffer_add_printf(buf, "<td>N/A</td>"); } else { evbuffer_add_printf(buf, "<td>%d</td>", event_remaining_seconds(&val->timeout)); } if (val->hard_timeout.ev_timeout.tv_sec == 0) { evbuffer_add_printf(buf, "<td>N/A</td>"); } else { evbuffer_add_printf(buf, "<td>%d</td>", event_remaining_seconds(&val->hard_timeout)); } if (val->recent_block_timeout.ev_timeout.tv_sec == 0) { evbuffer_add_printf(buf, "<td>N/A</td>"); } else { evbuffer_add_printf(buf, "<td>%d</td>", event_remaining_seconds(&val->recent_block_timeout)); } evbuffer_add_printf(buf, "<td>%s</td>", blankprint(val->reason)); if (http_password) { char addrbuf[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, val->s6addr, addrbuf, sizeof(addrbuf)); evbuffer_add_printf(buf, "<td><a href=\"action?action=removeHolddown&key=%s\">Unblock</a></td>", addrbuf); } evbuffer_add_printf(buf, "</tr>"); return FALSE; }