Index: trunk/udplog/filters/MarchFilter.c |
— | — | @@ -0,0 +1,41 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | + |
| 5 | +char strategy[]="strategy.wikimedia.org"; |
| 6 | +char msg[]="March_2011_Update"; |
| 7 | + |
| 8 | +main() { |
| 9 | + char line[10240]; |
| 10 | + char title[10240]; |
| 11 | + char *urlstart, *urlend; |
| 12 | + char *t = 0; |
| 13 | + |
| 14 | + while (!feof(stdin)) { |
| 15 | + char *r; |
| 16 | + r=fgets(line, 10000, stdin); |
| 17 | + |
| 18 | + int pos=0; |
| 19 | + t = line; |
| 20 | + |
| 21 | + while(pos++<8) { |
| 22 | + if (!t) |
| 23 | + continue; |
| 24 | + t = strstr(t, " "); |
| 25 | + if (!t) |
| 26 | + continue; |
| 27 | + t++; |
| 28 | + } |
| 29 | + if (!t) |
| 30 | + continue; |
| 31 | + urlstart = t; |
| 32 | + urlend = strstr(urlstart, " "); |
| 33 | + strncpy(title, urlstart, urlend-urlstart); |
| 34 | + title[urlend-urlstart]=0; |
| 35 | + |
| 36 | + if ( strstr(title, strategy) && strstr(title, msg) |
| 37 | + ){ |
| 38 | + printf("%s", line); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | +} |
Property changes on: trunk/udplog/filters/MarchFilter.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 43 | + native |
Index: trunk/udplog/filters/brazil-filter.c |
— | — | @@ -0,0 +1,51 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | +#include <GeoIP.h> |
| 5 | + |
| 6 | +char countryCode[]="BR"; //BRAZIL |
| 7 | + |
| 8 | +main() { |
| 9 | + GeoIP * gi; |
| 10 | + char line[10240]; |
| 11 | + char ipaddr[10240]; //in case the packet is malformed and the IP address is actually not here, cheaper than running a check every loop |
| 12 | + char *ipaddrstart, *ipaddrend; |
| 13 | + char *t = 0; |
| 14 | + |
| 15 | + gi = GeoIP_new(GEOIP_MMAP_CACHE|GEOIP_CHECK_CACHE); |
| 16 | + |
| 17 | + //while input |
| 18 | + while (!feof(stdin)) { |
| 19 | + const char* localresult; |
| 20 | + char *r; |
| 21 | + r=fgets(line, 10000, stdin); |
| 22 | + |
| 23 | + int pos=0; |
| 24 | + t = line; |
| 25 | + |
| 26 | + //squid log 5th position, delimited by 4th space |
| 27 | + while(pos++<4) { |
| 28 | + if (!t) |
| 29 | + continue; |
| 30 | + t = strstr(t, " "); |
| 31 | + if (!t) |
| 32 | + continue; |
| 33 | + t++; |
| 34 | + } |
| 35 | + if (!t) |
| 36 | + continue; |
| 37 | + //buid IP address string |
| 38 | + ipaddrstart = t; |
| 39 | + ipaddrend = strstr(ipaddrstart, " "); |
| 40 | + strncpy(ipaddr, ipaddrstart, ipaddrend-ipaddrstart); |
| 41 | + ipaddr[ipaddrend-ipaddrstart]=0; |
| 42 | + |
| 43 | + //get entry for GeoIP, printif not null && matches |
| 44 | + localresult = GeoIP_country_code_by_addr(gi, ipaddr); |
| 45 | + if (localresult && strstr(localresult, countryCode) |
| 46 | + ){ |
| 47 | + printf("%s", line); |
| 48 | + //printf("%s \n", GeoIP_country_code_by_addr(gi, ipaddr)); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | +} |
Property changes on: trunk/udplog/filters/brazil-filter.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 53 | + native |
Index: trunk/udplog/filters/india-filter.c |
— | — | @@ -0,0 +1,50 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | +#include <GeoIP.h> |
| 5 | + |
| 6 | +char countryCode[]="IN"; //india |
| 7 | + |
| 8 | +main() { |
| 9 | + GeoIP * gi; |
| 10 | + char line[10240]; |
| 11 | + char ipaddr[10240]; //in case the packet is malformed and the IP address is actually not here, cheaper than running a check every loop |
| 12 | + char *ipaddrstart, *ipaddrend; |
| 13 | + char *t = 0; |
| 14 | + |
| 15 | + gi = GeoIP_new(GEOIP_MMAP_CACHE|GEOIP_CHECK_CACHE); |
| 16 | + |
| 17 | + //while input |
| 18 | + while (!feof(stdin)) { |
| 19 | + const char* localresult; |
| 20 | + char *r; |
| 21 | + r=fgets(line, 10000, stdin); |
| 22 | + |
| 23 | + int pos=0; |
| 24 | + t = line; |
| 25 | + |
| 26 | + //squid log 5th position, delimited by 4th space |
| 27 | + while(pos++<4) { |
| 28 | + if (!t) |
| 29 | + continue; |
| 30 | + t = strstr(t, " "); |
| 31 | + if (!t) |
| 32 | + continue; |
| 33 | + t++; |
| 34 | + } |
| 35 | + if (!t) |
| 36 | + continue; |
| 37 | + //buid IP address string |
| 38 | + ipaddrstart = t; |
| 39 | + ipaddrend = strstr(ipaddrstart, " "); |
| 40 | + strncpy(ipaddr, ipaddrstart, ipaddrend-ipaddrstart); |
| 41 | + ipaddr[ipaddrend-ipaddrstart]=0; |
| 42 | + |
| 43 | + //get entry for GeoIP, printif not null && matches |
| 44 | + localresult = GeoIP_country_code_by_addr(gi, ipaddr); |
| 45 | + if ( localresult && strstr(localresult, countryCode) |
| 46 | + ){ |
| 47 | + printf("%s", line); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | +} |
Property changes on: trunk/udplog/filters/india-filter.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 52 | + native |
Index: trunk/udplog/filters/indiaCampusEmbassadorBanners.c |
— | — | @@ -0,0 +1,41 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | + |
| 5 | +char url[]= "title=Special:BannerLoader&banner=AmbassadorsIndiaanon"; |
| 6 | +char url2[] = "title=Special:BannerLoader&banner=AmbassadorsIndiaLoggedIn"; |
| 7 | + |
| 8 | +main() { |
| 9 | + char line[10240]; |
| 10 | + char title[10240]; |
| 11 | + char *urlstart, *urlend; |
| 12 | + char *t = 0; |
| 13 | + |
| 14 | + while (!feof(stdin)) { |
| 15 | + char *r; |
| 16 | + r=fgets(line, 10000, stdin); |
| 17 | + |
| 18 | + int pos=0; |
| 19 | + t = line; |
| 20 | + |
| 21 | + while(pos++<8) { |
| 22 | + if (!t) |
| 23 | + continue; |
| 24 | + t = strstr(t, " "); |
| 25 | + if (!t) |
| 26 | + continue; |
| 27 | + t++; |
| 28 | + } |
| 29 | + if (!t) |
| 30 | + continue; |
| 31 | + urlstart = t; |
| 32 | + urlend = strstr(urlstart, " "); |
| 33 | + strncpy(title, urlstart, urlend-urlstart); |
| 34 | + title[urlend-urlstart]=0; |
| 35 | + |
| 36 | + if ( strstr(title, url) || strstr(title,url2) |
| 37 | + ){ |
| 38 | + printf("%s", line); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | +} |
Property changes on: trunk/udplog/filters/indiaCampusEmbassadorBanners.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 43 | + native |
Index: trunk/udplog/filters/countries-1.c |
— | — | @@ -0,0 +1,62 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | +#include <GeoIP.h> |
| 5 | +#include <GeoIPCity.h> |
| 6 | + |
| 7 | +char country1[]="CF"; |
| 8 | +char country2[]="CI"; |
| 9 | +char country3[]="CD"; |
| 10 | +char country4[]="GQ"; |
| 11 | + |
| 12 | +main() { |
| 13 | + GeoIP * gi; |
| 14 | + GeoIPRecord *gir; |
| 15 | + char line[10240]; |
| 16 | + char ipaddr[10240]; //in case the packet is malformed and the IP address is actually not here, cheaper than running a check every loop |
| 17 | + char *ipaddrstart, *ipaddrend; |
| 18 | + char *t = 0; |
| 19 | + |
| 20 | + gi = GeoIP_open("/var/log/squid/filters/GeoIPLibs/GeoIPCity.current.dat", GEOIP_INDEX_CACHE); |
| 21 | + |
| 22 | + //while input |
| 23 | + while (!feof(stdin)) { |
| 24 | + const char* localresult; |
| 25 | + char *r; |
| 26 | + r=fgets(line, 10000, stdin); |
| 27 | + |
| 28 | + int pos=0; |
| 29 | + t = line; |
| 30 | + |
| 31 | + //squid log 5th position, delimited by 4th space |
| 32 | + while(pos++<4) { |
| 33 | + if (!t) |
| 34 | + continue; |
| 35 | + t = strstr(t, " "); |
| 36 | + if (!t) |
| 37 | + continue; |
| 38 | + t++; |
| 39 | + } |
| 40 | + if (!t) |
| 41 | + continue; |
| 42 | + //buid IP address string |
| 43 | + ipaddrstart = t; |
| 44 | + ipaddrend = strstr(ipaddrstart, " "); |
| 45 | + strncpy(ipaddr, ipaddrstart, ipaddrend-ipaddrstart); |
| 46 | + ipaddr[ipaddrend-ipaddrstart]=0; |
| 47 | + |
| 48 | + //get entry for GeoIP, printif not null && matches |
| 49 | + gir = GeoIP_record_by_name(gi, ipaddr); |
| 50 | + localresult = gir->country_code; |
| 51 | + if ( gir && |
| 52 | + (strstr(localresult, country1) |
| 53 | + || strstr(localresult, country2) |
| 54 | + || strstr(localresult, country3) |
| 55 | + || strstr(localresult, country4) |
| 56 | + ) |
| 57 | + ){ |
| 58 | + printf("%s %s", localresult, line); |
| 59 | + GeoIPRecord_delete(gir); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | +} |
Property changes on: trunk/udplog/filters/countries-1.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 64 | + native |
Index: trunk/udplog/filters/countries-100.c |
— | — | @@ -0,0 +1,80 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | +#include <GeoIP.h> |
| 5 | +#include <GeoIPCity.h> |
| 6 | + |
| 7 | +char country1[]="BD"; |
| 8 | +char country2[]="LK"; |
| 9 | +char country3[]="BH"; |
| 10 | +char country4[]="IQ"; |
| 11 | +char country5[]="JO"; |
| 12 | +char country6[]="KE"; |
| 13 | +char country7[]="KW"; |
| 14 | +char country8[]="NG"; |
| 15 | +char country9[]="QA"; |
| 16 | +char country10[]="ZA"; |
| 17 | +char country11[]="SN"; |
| 18 | +char country12[]="TN"; |
| 19 | +char country13[]="UG"; |
| 20 | + |
| 21 | +main() { |
| 22 | + GeoIP * gi; |
| 23 | + GeoIPRecord *gir; |
| 24 | + char line[10240]; |
| 25 | + char ipaddr[10240]; //in case the packet is malformed and the IP address is actually not here, cheaper than running a check every loop |
| 26 | + char *ipaddrstart, *ipaddrend; |
| 27 | + char *t = 0; |
| 28 | + |
| 29 | + gi = GeoIP_open("/var/log/squid/filters/GeoIPLibs/GeoIPCity.current.dat", GEOIP_INDEX_CACHE); |
| 30 | + |
| 31 | + //while input |
| 32 | + while (!feof(stdin)) { |
| 33 | + const char* localresult; |
| 34 | + char *r; |
| 35 | + r=fgets(line, 10000, stdin); |
| 36 | + |
| 37 | + int pos=0; |
| 38 | + t = line; |
| 39 | + |
| 40 | + //squid log 5th position, delimited by 4th space |
| 41 | + while(pos++<4) { |
| 42 | + if (!t) |
| 43 | + continue; |
| 44 | + t = strstr(t, " "); |
| 45 | + if (!t) |
| 46 | + continue; |
| 47 | + t++; |
| 48 | + } |
| 49 | + if (!t) |
| 50 | + continue; |
| 51 | + //buid IP address string |
| 52 | + ipaddrstart = t; |
| 53 | + ipaddrend = strstr(ipaddrstart, " "); |
| 54 | + strncpy(ipaddr, ipaddrstart, ipaddrend-ipaddrstart); |
| 55 | + ipaddr[ipaddrend-ipaddrstart]=0; |
| 56 | + |
| 57 | + //get entry for GeoIP, printif not null && matches |
| 58 | + gir = GeoIP_record_by_name(gi, ipaddr); |
| 59 | + localresult = gir->country_code; |
| 60 | + if ( gir && |
| 61 | + (strstr(localresult, country1) |
| 62 | + || strstr(localresult, country2) |
| 63 | + || strstr(localresult, country3) |
| 64 | + || strstr(localresult, country4) |
| 65 | + || strstr(localresult, country5) |
| 66 | + || strstr(localresult, country6) |
| 67 | + || strstr(localresult, country7) |
| 68 | + || strstr(localresult, country8) |
| 69 | + || strstr(localresult, country9) |
| 70 | + || strstr(localresult, country10) |
| 71 | + || strstr(localresult, country11) |
| 72 | + || strstr(localresult, country12) |
| 73 | + || strstr(localresult, country13) |
| 74 | + ) |
| 75 | + ){ |
| 76 | + printf("%s %s", localresult, line); |
| 77 | + GeoIPRecord_delete(gir); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | +} |
Property changes on: trunk/udplog/filters/countries-100.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 82 | + native |
Index: trunk/udplog/filters/mobile-offline-meta.c |
— | — | @@ -0,0 +1,41 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | + |
| 5 | +char url[]= "http://meta.wikimedia.org/wiki/Offline_Projects"; |
| 6 | +char url2[] = "http://meta.wikimedia.org/wiki/Mobile_Projects"; |
| 7 | + |
| 8 | +main() { |
| 9 | + char line[10240]; |
| 10 | + char title[10240]; |
| 11 | + char *urlstart, *urlend; |
| 12 | + char *t = 0; |
| 13 | + |
| 14 | + while (!feof(stdin)) { |
| 15 | + char *r; |
| 16 | + r=fgets(line, 10000, stdin); |
| 17 | + |
| 18 | + int pos=0; |
| 19 | + t = line; |
| 20 | + |
| 21 | + while(pos++<8) { |
| 22 | + if (!t) |
| 23 | + continue; |
| 24 | + t = strstr(t, " "); |
| 25 | + if (!t) |
| 26 | + continue; |
| 27 | + t++; |
| 28 | + } |
| 29 | + if (!t) |
| 30 | + continue; |
| 31 | + urlstart = t; |
| 32 | + urlend = strstr(urlstart, " "); |
| 33 | + strncpy(title, urlstart, urlend-urlstart); |
| 34 | + title[urlend-urlstart]=0; |
| 35 | + |
| 36 | + if ( strstr(title, url) || strstr(title,url2) |
| 37 | + ){ |
| 38 | + printf("%s", line); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | +} |
Property changes on: trunk/udplog/filters/mobile-offline-meta.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 43 | + native |
Index: trunk/udplog/filters/editSurveyBanners.c |
— | — | @@ -0,0 +1,40 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | + |
| 5 | +char url[]= "http://wikimediafoundation.org/tracker/bannerImpression.php?req=css&surveyView=1"; |
| 6 | + |
| 7 | +main() { |
| 8 | + char line[10240]; |
| 9 | + char title[10240]; |
| 10 | + char *urlstart, *urlend; |
| 11 | + char *t = 0; |
| 12 | + |
| 13 | + while (!feof(stdin)) { |
| 14 | + char *r; |
| 15 | + r=fgets(line, 10000, stdin); |
| 16 | + |
| 17 | + int pos=0; |
| 18 | + t = line; |
| 19 | + |
| 20 | + while(pos++<8) { |
| 21 | + if (!t) |
| 22 | + continue; |
| 23 | + t = strstr(t, " "); |
| 24 | + if (!t) |
| 25 | + continue; |
| 26 | + t++; |
| 27 | + } |
| 28 | + if (!t) |
| 29 | + continue; |
| 30 | + urlstart = t; |
| 31 | + urlend = strstr(urlstart, " "); |
| 32 | + strncpy(title, urlstart, urlend-urlstart); |
| 33 | + title[urlend-urlstart]=0; |
| 34 | + |
| 35 | + if ( strstr(title, url) |
| 36 | + ){ |
| 37 | + printf("%s", line); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | +} |
Property changes on: trunk/udplog/filters/editSurveyBanners.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 42 | + native |
Index: trunk/udplog/filters/latlong-filter.c |
— | — | @@ -0,0 +1,58 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | +#include <GeoIP.h> |
| 5 | +#include <GeoIPCity.h> |
| 6 | + |
| 7 | +main() { |
| 8 | + GeoIP * gi; |
| 9 | + GeoIPRecord *gir; |
| 10 | + char line[10240]; |
| 11 | + char ipaddr[10240]; //in case the packet is malformed and the IP address is actually not here, cheaper than running a check every loop |
| 12 | + char *ipaddrstart, *ipaddrend; |
| 13 | + char *t = 0; |
| 14 | + |
| 15 | + //gi = GeoIP_new(GEOIP_MMAP_CACHE|GEOIP_CHECK_CACHE); |
| 16 | + |
| 17 | + gi = GeoIP_open("/var/log/squid/filters/GeoIPLibs/GeoIPCity.current.dat", GEOIP_INDEX_CACHE); |
| 18 | + |
| 19 | + |
| 20 | + //while input |
| 21 | + while (!feof(stdin)) { |
| 22 | + const char* localresult; |
| 23 | + char *r; |
| 24 | + r=fgets(line, 10000, stdin); |
| 25 | + |
| 26 | + int pos=0; |
| 27 | + t = line; |
| 28 | + |
| 29 | + //squid log 5th position, delimited by 4th space |
| 30 | + while(pos++<4) { |
| 31 | + if (!t) |
| 32 | + continue; |
| 33 | + t = strstr(t, " "); |
| 34 | + if (!t) |
| 35 | + continue; |
| 36 | + t++; |
| 37 | + } |
| 38 | + if (!t) |
| 39 | + continue; |
| 40 | + //buid IP address string |
| 41 | + ipaddrstart = t; |
| 42 | + ipaddrend = strstr(ipaddrstart, " "); |
| 43 | + strncpy(ipaddr, ipaddrstart, ipaddrend-ipaddrstart); |
| 44 | + ipaddr[ipaddrend-ipaddrstart]=0; |
| 45 | + |
| 46 | + //get geoip record result |
| 47 | + gir = GeoIP_record_by_name(gi, ipaddr); |
| 48 | + if ( gir ){ |
| 49 | + //printf("%s", line); |
| 50 | + printf("%s %f,%f %s", gir->country_code,gir->latitude, gir->longitude, line); |
| 51 | + //printf("%f %f \n", gir->latitude, gir->longitude); |
| 52 | + GeoIPRecord_delete(gir); |
| 53 | + } |
| 54 | + else{ |
| 55 | + printf("-200 -200 %s", line); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | +} |
Property changes on: trunk/udplog/filters/latlong-filter.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 60 | + native |
Index: trunk/udplog/filters/polishfavicons.c |
— | — | @@ -0,0 +1,41 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | + |
| 5 | +char url[]= "http://pl.wikimedia.org/w"; |
| 6 | +char url2[] = "avicon.ico"; |
| 7 | + |
| 8 | +main() { |
| 9 | + char line[10240]; |
| 10 | + char title[10240]; |
| 11 | + char *urlstart, *urlend; |
| 12 | + char *t = 0; |
| 13 | + |
| 14 | + while (!feof(stdin)) { |
| 15 | + char *r; |
| 16 | + r=fgets(line, 10000, stdin); |
| 17 | + |
| 18 | + int pos=0; |
| 19 | + t = line; |
| 20 | + |
| 21 | + while(pos++<8) { |
| 22 | + if (!t) |
| 23 | + continue; |
| 24 | + t = strstr(t, " "); |
| 25 | + if (!t) |
| 26 | + continue; |
| 27 | + t++; |
| 28 | + } |
| 29 | + if (!t) |
| 30 | + continue; |
| 31 | + urlstart = t; |
| 32 | + urlend = strstr(urlstart, " "); |
| 33 | + strncpy(title, urlstart, urlend-urlstart); |
| 34 | + title[urlend-urlstart]=0; |
| 35 | + |
| 36 | + if ( strstr(title, url) && strstr(title,url2) |
| 37 | + ){ |
| 38 | + printf("%s", line); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | +} |
Property changes on: trunk/udplog/filters/polishfavicons.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 43 | + native |
Index: trunk/udplog/filters/indiaCampusEmbassadorLandingPage.c |
— | — | @@ -0,0 +1,40 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | + |
| 5 | +char url[]="outreach.wikimedia.org/wiki/Wikipedia_Campus_Ambassador?from=banner"; |
| 6 | + |
| 7 | +main() { |
| 8 | + char line[10240]; |
| 9 | + char title[10240]; |
| 10 | + char *urlstart, *urlend; |
| 11 | + char *t = 0; |
| 12 | + |
| 13 | + while (!feof(stdin)) { |
| 14 | + char *r; |
| 15 | + r=fgets(line, 10000, stdin); |
| 16 | + |
| 17 | + int pos=0; |
| 18 | + t = line; |
| 19 | + |
| 20 | + while(pos++<8) { |
| 21 | + if (!t) |
| 22 | + continue; |
| 23 | + t = strstr(t, " "); |
| 24 | + if (!t) |
| 25 | + continue; |
| 26 | + t++; |
| 27 | + } |
| 28 | + if (!t) |
| 29 | + continue; |
| 30 | + urlstart = t; |
| 31 | + urlend = strstr(urlstart, " "); |
| 32 | + strncpy(title, urlstart, urlend-urlstart); |
| 33 | + title[urlend-urlstart]=0; |
| 34 | + |
| 35 | + if ( strstr(title, url) |
| 36 | + ){ |
| 37 | + printf("%s", line); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | +} |
Property changes on: trunk/udplog/filters/indiaCampusEmbassadorLandingPage.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 42 | + native |
Index: trunk/udplog/filters/countries-10.c |
— | — | @@ -0,0 +1,70 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | +#include <GeoIP.h> |
| 5 | +#include <GeoIPCity.h> |
| 6 | + |
| 7 | +char country1[]="KH"; |
| 8 | +char country2[]="BW"; |
| 9 | +char country3[]="CM"; |
| 10 | +char country4[]="MG"; |
| 11 | +char country5[]="ML"; |
| 12 | +char country6[]="MU"; |
| 13 | +char country7[]="NE"; |
| 14 | +char country8[]="VU"; |
| 15 | + |
| 16 | +main() { |
| 17 | + GeoIP * gi; |
| 18 | + GeoIPRecord *gir; |
| 19 | + char line[10240]; |
| 20 | + char ipaddr[10240]; //in case the packet is malformed and the IP address is actually not here, cheaper than running a check every loop |
| 21 | + char *ipaddrstart, *ipaddrend; |
| 22 | + char *t = 0; |
| 23 | + |
| 24 | + gi = GeoIP_open("/var/log/squid/filters/GeoIPLibs/GeoIPCity.current.dat", GEOIP_INDEX_CACHE); |
| 25 | + |
| 26 | + //while input |
| 27 | + while (!feof(stdin)) { |
| 28 | + const char* localresult; |
| 29 | + char *r; |
| 30 | + r=fgets(line, 10000, stdin); |
| 31 | + |
| 32 | + int pos=0; |
| 33 | + t = line; |
| 34 | + |
| 35 | + //squid log 5th position, delimited by 4th space |
| 36 | + while(pos++<4) { |
| 37 | + if (!t) |
| 38 | + continue; |
| 39 | + t = strstr(t, " "); |
| 40 | + if (!t) |
| 41 | + continue; |
| 42 | + t++; |
| 43 | + } |
| 44 | + if (!t) |
| 45 | + continue; |
| 46 | + //buid IP address string |
| 47 | + ipaddrstart = t; |
| 48 | + ipaddrend = strstr(ipaddrstart, " "); |
| 49 | + strncpy(ipaddr, ipaddrstart, ipaddrend-ipaddrstart); |
| 50 | + ipaddr[ipaddrend-ipaddrstart]=0; |
| 51 | + |
| 52 | + //get entry for GeoIP, printif not null && matches |
| 53 | + gir = GeoIP_record_by_name(gi, ipaddr); |
| 54 | + localresult = gir->country_code; |
| 55 | + if ( gir && |
| 56 | + (strstr(localresult, country1) |
| 57 | + || strstr(localresult, country2) |
| 58 | + || strstr(localresult, country3) |
| 59 | + || strstr(localresult, country4) |
| 60 | + || strstr(localresult, country5) |
| 61 | + || strstr(localresult, country6) |
| 62 | + || strstr(localresult, country7) |
| 63 | + || strstr(localresult, country8) |
| 64 | + ) |
| 65 | + ){ |
| 66 | + printf("%s %s", localresult, line); |
| 67 | + GeoIPRecord_delete(gir); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | +} |
Property changes on: trunk/udplog/filters/countries-10.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 72 | + native |
Index: trunk/udplog/filters/api-filter.c |
— | — | @@ -0,0 +1,40 @@ |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | + |
| 5 | +char apicall[]="/w/api.php"; |
| 6 | + |
| 7 | +main() { |
| 8 | + char line[10240]; |
| 9 | + char title[10240]; |
| 10 | + char *urlstart, *urlend; |
| 11 | + char *t = 0; |
| 12 | + |
| 13 | + while (!feof(stdin)) { |
| 14 | + char *r; |
| 15 | + r=fgets(line, 10000, stdin); |
| 16 | + |
| 17 | + int pos=0; |
| 18 | + t = line; |
| 19 | + |
| 20 | + while(pos++<8) { |
| 21 | + if (!t) |
| 22 | + continue; |
| 23 | + t = strstr(t, " "); |
| 24 | + if (!t) |
| 25 | + continue; |
| 26 | + t++; |
| 27 | + } |
| 28 | + if (!t) |
| 29 | + continue; |
| 30 | + urlstart = t; |
| 31 | + urlend = strstr(urlstart, " "); |
| 32 | + strncpy(title, urlstart, urlend-urlstart); |
| 33 | + title[urlend-urlstart]=0; |
| 34 | + |
| 35 | + if ( strstr(title, apicall) |
| 36 | + ){ |
| 37 | + printf("%s", line); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | +} |
Property changes on: trunk/udplog/filters/api-filter.c |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 42 | + native |