/[web]/data/lib/Mageia/Data/Cron/Releases.php
ViewVC logotype

Contents of /data/lib/Mageia/Data/Cron/Releases.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1525 - (show annotations) (download)
Mon Jul 30 00:03:15 2012 UTC (11 years, 8 months ago) by rda
File size: 3488 byte(s)
add libraries
1 <?php
2 /**
3 */
4
5 class Mageia_Data_Cron_Releases extends Mageia_Data_Cron
6 {
7 function __construct($spec, $ts, $appdir, $logtmpdir) { parent::__construct($spec, $ts, $appdir, $logtmpdir); }
8
9 /**
10 * Convert access_log from releases.mageia.org into a digested, resolved log
11 * aimed to be published.
12 *
13 * For instance, it will convert:
14 *
15 * 79.246.71.12 - - [01/Apr/2012:04:03:15 +0200] "GET /api/a/i586?product=Default&version=1&mgaonline_version=2.77.29 HTTP/1.1" 200 283 "-" "curl/7.21.5 (i586-mageia-linux-gnu) libcurl/7.21.5 OpenSSL/1.0.0d zlib/1.2.5 libidn/1.19 libssh2/1.2.8"
16 *
17 * into:
18 *
19 * 2012-04-01 06 1 i586 EU FR Ile-de-France Paris
20 * (date / hour / version / arch / continent / country / region / city)
21 *
22 * with one line = one HTTP GET request.
23 */
24 function digest_log($infile = 'php://stdin', $outfile = 'php://stdout')
25 {
26 echo "Digest. ";
27
28 $source = 'releases';
29 $cache = array();
30
31 require_once realpath($this->appdir . '/lib/maxmind/geoip/geoip.inc.php');
32 require_once realpath($this->appdir . '/lib/maxmind/geoip/geoipcity.inc.php');
33
34 $gi = geoip_open(realpath($this->appdir . '/lib/maxmind/geoip/GeoLiteCityv6.dat'), GEOIP_STANDARD);
35 $infile = fopen($infile, 'r');
36 $outfile = fopen($outfile, 'w');
37
38 while (!feof($infile)) {
39
40 $s = fgets($infile);
41 $s = trim($s);
42
43 if ($s == '')
44 continue;
45
46 $s = explode(' ', $s);
47 $ip = $s[0];
48
49 // NOTE (rda) dates are local time, not UTC here.
50 // FIXME (rda) change dates to UTC
51 // that involves getting logs of the day before, and filtering _after_ conversion.
52 $sdate = str_replace(array('[', ']'), '', $s[3] . ' ' . $s[4]);
53 $sdate2 = explode(':', $sdate);
54 $date = $sdate2[0];
55 $date2 = date('Y-m-d', strtotime($sdate)); // N for week day, or Y-m-d
56 $time = date('H', strtotime($sdate));
57 $date = $date2;
58
59 $query = $s[6];
60 $url = parse_url($query);
61 parse_str($url['query'], $query);
62
63 $arch = end(explode('/', $url['path']));
64 $vers = $query['version'];
65
66 if ($vers == '')
67 continue;
68
69 if (strpos($ip, ':') === false)
70 $ip = '::' . $ip;
71
72 $record = geoip_record_by_addr_v6($gi, $ip);
73
74 //global $GEOIP_REGION_NAME;
75
76 $rec = array(
77 'country' => $record->country_code,
78 'region' => $GEOIP_REGION_NAME[$record->country_code][$record->region],
79 'city' => $record->city,
80 'code' => $record->postal_code,
81 'area' => $record->area_code,
82 'continent' => $record->continent_code
83 );
84
85 $data = array(
86 $date,
87 $time,
88 $vers,
89 $arch,
90 $rec['continent'],
91 $rec['country'],
92 mb_convert_encoding($rec['region'], 'ASCII'),
93 mb_convert_encoding($rec['city'], 'ASCII')
94 );
95 $ret = implode(" ", $data) . "\n";
96 fputs($outfile, $ret, mb_strlen($ret, 'utf-8'));
97 }
98 fclose($outfile);
99 fclose($infile);
100 geoip_close($gi);
101 }
102 }

  ViewVC Help
Powered by ViewVC 1.1.30