/[dehs]/trunk/dehs_pg.php
ViewVC logotype

Contents of /trunk/dehs_pg.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 131 - (hide annotations) (download)
Fri Apr 18 23:47:44 2008 UTC (5 years, 1 month ago) by atomo64-guest
File size: 47504 byte(s)
Fix wget call because -N together with -O is useless
1 evaso-guest 5 #!/usr/bin/php4 -q
2 atomo64-guest 54 <?php
3 evaso-guest 5 /*
4 atomo64-guest 54
5     Originally written by Stefano Fabri <bluefuture@nospam@email.it>
6     Copyright 2004, Stefano Fabri
7 atomo64-guest 105 Copyright 2007, 2008 by Raphael Geissert <atomo64@gmail.com>
8 atomo64-guest 54
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13    
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     GNU General Public License for more details.
18    
19     You should have received a copy of the GNU General Public License
20     along with this program; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 evaso-guest 5 */
23 atomo64-guest 54
24 evaso-guest 5 // stabilire una connessione
25     #ini_set ( "error_reporting", "E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR");
26     ini_set ("html_errors", "off");
27     set_time_limit(0);
28 evaso-guest 34 ini_set ( "memory_limit", "40M");
29 evaso-guest 13 #print_R($_SERVER);
30     require "dehs.config.inc";
31 atomo64-guest 122 require "events.class.php";
32 evaso-guest 5 dir_ctrl($dirs);
33 evaso-guest 13 if (!function_exists('file_get_contents')) {
34 atomo64-guest 54 function file_get_contents($filename) {
35     if (!($file = fopen($filename,"rb"))) return false;
36     else {
37     $contents = "";
38     do {
39     $data = fread($file, 4096);
40     if (strlen($data) == 0) {
41     break;
42     }
43     $contents .= $data;
44     } while (true);
45     fclose($file);
46     return $contents;
47     }
48     }
49     }
50    
51     if (!function_exists('file_put_contents')) {
52     function file_put_contents($filename, $content, $flags = 0) {
53     if (!($file = fopen($filename,$flags))) return false;
54     else {
55     $n = fwrite($file, $content);
56     fclose($file);
57     return true;
58     }
59     }
60     }
61    
62 atomo64-guest 76 if (in_array("-db_add",$argv)) db_add((!empty($argv[2])?$argv[2]:''), false);
63     elseif (in_array("-db_query",$argv)) db_query($argv[2],(!empty($argv[3])?$argv[3]:'%') );
64 atomo64-guest 59 elseif (in_array("-dl_diffs",$argv) || in_array("-keep_diff",$argv)) dl_diffs($argv[2]);
65 atomo64-guest 64 elseif (in_array("-keep_sources",$argv) || in_array("-download_sources",$argv)) download_sources();
66 atomo64-guest 54 elseif (in_array("-db_popcon",$argv)) db_popcon($argv[2]);
67 atomo64-guest 122 elseif (in_array("-dl_popcon",$argv) || in_array("-keep_popcon",$argv)) dl_popcon();
68 atomo64-guest 85 elseif (in_array("-db_upstream",$argv)) db_upstream((!empty($argv[2])?$argv[2]:'%'));
69 atomo64-guest 54 elseif (in_array("-update_all",$argv)) update_all();
70 atomo64-guest 64 elseif (in_array("-update_new",$argv)) update_new();
71 atomo64-guest 65 elseif (in_array("-update_bogus",$argv)) update_bogus();
72 atomo64-guest 54 elseif (in_array("-check_db",$argv)) check_db();
73     elseif (in_array("-dehsqa_db",$argv)) dehsqa_db();
74     elseif (in_array("-clear_db",$argv)) clear_db();
75     elseif (in_array("-db_up_error",$argv)) db_up_error();
76 atomo64-guest 85 elseif (in_array("-up_changes",$argv)) up_changes((!empty($argv[2])?$argv[2]:'%'), true);
77     elseif (in_array("-watchf",$argv) || in_array("-wwiz",$argv)) watch_wizard((!empty($argv[2])?$argv[2]:'%'));
78 atomo64-guest 54 elseif (in_array("-kb_total",$argv)) print "Diff
79 evaso-guest 5 #stat_up_error();
80     #stat_up_error();to download Kb => " . kb_total($argv[2]) . "\n" ;
81 atomo64-guest 54 elseif (in_array("-watch_stat",$argv)) watch_stat();
82     else print "Command $argv[1] not found\n";
83 evaso-guest 5 #stat_up_error();
84     function dir_ctrl($dirs) {
85 atomo64-guest 54 foreach ($dirs as $dir) {
86     if (!is_dir($dir)) exec("mkdir -m 0740 -p " . escapeshellarg($dir), $output, $res);
87     if ($res != 0) die_status("Error creating basic dir: $dir\n");
88     }
89 evaso-guest 5 }
90 atomo64-guest 54 function ext_watch ($file,$pkg,$version) {
91     if (!file_exists($file)) return "";
92     $zp=gzopen($file,"r") or die_status("Fail to open $file");
93     while (!gzeof($zp)) {
94     $line = gzgets ($zp,4096);
95 atomo64-guest 59 if (preg_match('/\+\+\+\s.+\/debian\/watch$/',$line)) {
96 atomo64-guest 54 $line = gzgets ($zp,4096);
97     preg_match ("/.+\+\d+\,(\d+)\s/",$line,$watch_lenght);
98     for ($i = 1; $i <= $watch_lenght[1]; $i++) {
99     $line=gzgets ($zp,4096);
100     $watch .=substr($line,1);
101 evaso-guest 5 }
102 atomo64-guest 54 break;
103 evaso-guest 5 }
104 atomo64-guest 54 }
105     if ($watch!=null) return $watch;
106     else return NULL;
107 evaso-guest 5 }
108     function ftp_cn($login,$password,$ftp_server) {
109 atomo64-guest 54 $conn_id = @ftp_connect($ftp_server) or die_status("Error: Cannot contact ftp server $ftp_server\n");
110     // login con user name e password
111     ftp_pasv($conn_id,1);
112     $login_result = ftp_login($conn_id, "anonymous","bo@bo.org");
113     // controllo della connessione
114     if ((!$conn_id) || (!$login_result)) {
115 evaso-guest 5 echo "Ftp connection failed!\n";
116     echo "Failed connection to $ftp_server\n";
117 atomo64-guest 49 die_status();
118 evaso-guest 5 } else {
119     return $conn_id;
120     }
121     }
122 atomo64-guest 59 function dl_diffs($initial = '') {
123 atomo64-guest 54 global $dirs,$dbconn,$mirrors;
124     check_db();
125     $conn_normal=ftp_cn("anonymous","bo@bo.org",$mirrors['unstable']);
126     #$conn_non_us=ftp_cn("anonymous","bo@bo.org",$mirrors["non-US"]);
127     $db = pg_pconnect($dbconn) ;
128     $rsql=pg_exec($db, "SELECT * FROM pkgs WHERE name like '$initial%' AND (md5_diff!=md5_atsource or md5_diff is null)") OR die_status("Error in diff query\n");
129     $total=pg_numrows($rsql);
130     $btotal=byte_total($db,$initial);
131     print "Total Diff to downlaod Kb => " . number_format ($btotal/1024, 2, ",",".") . "\n";
132     while ($res_array=pg_fetch_array($rsql)) {
133     #if ($res_array['dist']=='non-US') $conn_id = $conn_non_us;
134     #else
135     $conn_id = $conn_normal;
136 atomo64-guest 95 if ($localfile=download_diff($conn_id,$res_array[name],$res_array[version],$res_array['dir'],$res_array[md5_diff],$res_array[md5_atsource],$res_array[bytes],$res_array[dist])) {
137 atomo64-guest 54 $watch=ext_watch($localfile,$res_array[name],$res_array[version]);
138     unlink($localfile);
139     if ($watch!=NULL) {
140     $watch=iconv("ISO-8859-1","UTF-8",$watch);
141 atomo64-guest 66 $watch= pg_escape_string($watch);
142 atomo64-guest 54 pg_exec($db, "UPDATE pkgs SET watch='" . $watch . "', md5_diff='" . $res_array[md5_atsource] . "' where name='" . $res_array[name] . "' AND dist='" . $res_array[dist] ."'") or die_status("Query error");
143     }
144     else pg_exec($db, "UPDATE pkgs SET watch=NULL, md5_diff='" . $res_array[md5_atsource] . "' where name='" . $res_array[name] . "' AND dist='" . $res_array[dist] ."'") or die_status("Errore nella query");
145     }
146     $btotal=$btotal-$res_array['bytes'];
147     number_format ($btotal/1024, 2, ",",".");
148     print "\rDiffs left => " . $total-- . " Bytes left => " . number_format ($btotal/1024, 2, ",",".") . " - " . $res_array[name];
149     }
150     ftp_quit($conn_normal);
151     pg_close($db);
152     return "Fatto\n";
153     }
154 atomo64-guest 95 function download_diff(&$conn_id,$pkg,$version,$directory,$md5_diff,$md5_atsource,$diff_kb,$dist) {
155 atomo64-guest 54 global $dirs,$mirrors;
156     $localfile=$dirs[diffs_dir] . "/$pkg" . "_" . "$version.diff.gz";
157     #if ($dist=="non-US") $remotefile="/debian-non-US/$directory/$pkg" . "_" . "$version.diff.gz";
158     #else
159     $remotefile="/debian/$directory/$pkg" . "_" . "$version.diff.gz";
160     #print "$localfile - $remotefile\n";
161     if (ftp_get($conn_id,$localfile,$remotefile,FTP_BINARY)) {
162     # print "$pkg Diff.gz => Downloaded\n";
163     if(md5_of_file($localfile)==$md5_atsource) {
164     #print "MD5 => OK\n";
165     #unlink($localfile);
166     return $localfile;
167     }
168     }
169     print "Download Diff.gz of package $pkg => Fallito\n";
170     return false;
171 evaso-guest 5 }
172 atomo64-guest 102 function db_add($initial='') {
173 atomo64-guest 54 global $dirs,$dists,$dbconn;
174     check_db();
175 atomo64-guest 64 download_sources();
176 atomo64-guest 54
177 atomo64-guest 65 $db = pg_pconnect($dbconn) or die_status(pg_last_error($db));
178 atomo64-guest 54 pg_exec($db, "CREATE TEMP TABLE pkgs_atsrc (name text,dist text)") or die_status('Error creating temp table pkgs_atsrc');
179     pg_exec($db, "CREATE UNIQUE INDEX idxdis on pkgs_atsrc (name,dist)") or die_status('Error creating index on temp table');
180     pg_exec($db, "CREATE TEMP TABLE bin_atsrc (name text,bin_name text, dist text)") or die_status('Error creating temp table pkgs_atsrc');
181     pg_exec($db, "CREATE UNIQUE INDEX idxbis on bin_atsrc (name,bin_name,dist)") or die_status('Error creating index on temp table bin_atsrc');
182    
183     foreach ($dists as $dist=>$sections) {
184 evaso-guest 5 foreach ($sections as $section) {
185 atomo64-guest 54 $filename=$dirs['sources_dir'] . "/$dist/$section/Sources.gz";
186     print "\nI'm parsing $dist/$section => Sources.gz\n";
187     # 1 Pacchetto - 2 versione - 3 np - 4 Directory - 5 md5
188 atomo64-guest 129 $regexp="/Package:\s($initial.*)[^a]Binary:\s(.+)[^a]Version:\s(\d+:)?(.+)[^a]Priority.+Maintainer:.+<([^>]+)>[^a].+Directory:\s(.+)[^a]Files:.+\s(\S{32})\s(\d+)\s" . '\1\S+' . "\.diff\.gz[^a](Uploaders:\s(.+)[^a])?(Dm-Upload-Allowed:\s(.+)[^a])?(Homepage:\s(.+)[^a])?(Vcs-Browser:\s(.+)[^a])?(Vcs-([A-Z][a-z]+):\s(.+)[^a])?(Checksums-\S+:\s(.+)[^a])?/Ssi";
189 atomo64-guest 54 $zp = gzopen($filename, "r") or die_status("Could not open $filename");
190     $extracted=tempnam("/tmp/", "$dist_$section_Sources");
191     exec("gzip -c -d $filename > $extracted");
192     $sourcesize=filesize($extracted);
193     unlink($extracted);
194     if(filesize($filename)>20) {
195     while (!gzeof($zp)) {
196     $line='';
197     while ($line!="\n") {
198     $line = gzgets ($zp,4096) ;
199     $buff1 .= $line;
200     }
201     if (preg_match($regexp,$buff1,$matches)) {
202 atomo64-guest 64 if ($matches[5]) {
203     $matches[5]=iconv("ISO-8859-1","UTF-8",$matches[5]);
204     $matches[5]=pg_escape_string($matches[5]);
205     }
206 atomo64-guest 54 if ($matches[10]) {
207     $matches[10]=iconv("ISO-8859-1","UTF-8",$matches[10]);
208 atomo64-guest 64 $matches[10]=pg_escape_string($matches[10]);
209 evaso-guest 5 }
210 atomo64-guest 54 @pg_exec($db,"INSERT INTO pkgs_atsrc (name,dist) VALUES ('$matches[1]','$dist')") OR die_status("Temp table pkgs_atsrc query error");
211 atomo64-guest 128 $rst=@pg_exec($db, "INSERT INTO pkgs (name,version,dversionmangled,maint,dir,md5_atsource,bytes,dist,section,uploaders,homepage,vcs_browser,vcs_type,vcs) VALUES ('$matches[1]','$matches[4]','$matches[4]','$matches[5]','$matches[6]','$matches[7]','$matches[8]','$dist','$section','$matches[10]','$matches[14]','$matches[16]','$matches[18]','$matches[19]')");
212 atomo64-guest 54 if (!$rst) {
213 atomo64-guest 92 $rsql=pg_exec($db, "SELECT pkgs.version FROM pkgs WHERE name='$matches[1]' AND dist='$dist';");
214     $version = $matches[4]; // just for safety
215     while ($res_array=pg_fetch_array($rsql)) {
216     $version = $res_array['version'];
217     }
218     $extra = '';
219     if ($version != $matches[4]) {
220     // only update the dversionmangled field if the versions differ
221     $extra = ",dversionmangled='$matches[4]'";
222 atomo64-guest 121 // and reset wwiz_type
223     $extra = ",wwiz_type=NULL";
224 atomo64-guest 92 }
225 atomo64-guest 128 $rst=@pg_exec($db, "UPDATE pkgs SET name='$matches[1]',version='$matches[4]'$extra,maint='$matches[5]',dir='$matches[6]',md5_atsource='$matches[7]',bytes='$matches[8]',dist='$dist',section='$section',uploaders='$matches[10]',homepage='$matches[14]',vcs_browser='$matches[16]',vcs_type='$matches[18]',vcs='$matches[19]' WHERE name='$matches[1]' AND dist='$dist'") OR die_status("\nDb adding error =>" . pg_last_error() . "\n");
226 atomo64-guest 54 }
227     $bin_names=split(",", $matches[2]);
228     foreach ($bin_names as $bin_name) {
229     pg_exec($db,"INSERT INTO bin_atsrc (name,bin_name,dist) VALUES ('$matches[1]','" . trim($bin_name) . "','$dist')") OR die_status("Temp table pkgs_atsrc query error");
230     $rst=@pg_exec($db, "INSERT INTO binpkgs (name,bin_name,dist) VALUES ('$matches[1]','" . trim($bin_name) . "','$dist')") ;
231     }
232     }
233     else {
234     preg_match("/Package:\s(.+)[^a]Binary/im",$buff1,$matches);
235     if(strncmp($initial,$matches[1],strlen($initial))<0) break;
236     }
237     $left=$sourcesize-gztell($zp);
238     print "\rSource file Left => $left";
239     $buff1="";
240     unset($matches);
241     }
242 evaso-guest 5 }
243     gzclose($zp) ;
244     }
245 atomo64-guest 54 }
246 atomo64-guest 102 clear_db($db);
247 atomo64-guest 54 pg_close($db);
248 evaso-guest 5 }
249 atomo64-guest 72 function db_query($pkg,$dist='%') {
250 atomo64-guest 54 global $dirs,$dbconn;
251 atomo64-guest 65 $db = pg_pconnect($dbconn ) or die_status(pg_last_error($db));
252 atomo64-guest 122 $rsql=pg_exec($db, "SELECT * FROM pkgs
253     WHERE name='$pkg' AND dist LIKE '$dist';");
254 atomo64-guest 72 while ($res_array=pg_fetch_array($rsql)) {
255 atomo64-guest 54 print "Package=> " . $res_array['name'] . "\n";
256     print "Version => " . $res_array['version'] . "\n";
257 atomo64-guest 73 print "Mangled version => " . $res_array['dversionmangled'] . "\n";
258 atomo64-guest 54 print "Diff MD5 Downloaded => " . $res_array['md5_diff'] . "\n";
259     print "Diff MD5 at Sources => " . $res_array['md5_atsource'] . "\n";
260     print "Distribution => " . $res_array['dist'] . "\n";
261     print "Section => " . $res_array['section'] . "\n";
262     print "KBytes => " . number_format ( $res_array['bytes']/1024, 2, ",",".") . "\n";
263 atomo64-guest 122 print "Pop Inst=>" . $res_array['pop_inst'] . "\n";
264 evaso-guest 5 if ($res_array['watch']) {
265 atomo64-guest 54 $uscan_res=uscan_foo($res_array['name'] ,$res_array['version'],$res_array['watch']);
266 atomo64-guest 121 print "Version Upstream => " . $uscan_res['uversion'] . "\n";
267 atomo64-guest 72 print "Watch => " . trim($res_array['watch'])."\n";
268 atomo64-guest 121 print "Watch Warnings => " . $uscan_res['warnings'];
269 evaso-guest 5 }
270     else print "Watch => Not present" . "\n";
271 atomo64-guest 58 if ($res_array['wwiz_type']) {
272     $uscan_res=uscan_foo($res_array['name'] ,$res_array['version'],$res_array['wwiz']);
273 atomo64-guest 121 print "WWiz Upstream => " . $uscan_res['uversion'] . "\n";
274 atomo64-guest 72 print "WWiz => " . $res_array['wwiz']."\n";
275 atomo64-guest 121 print "WWiz Warings => " . $uscan_res['warnings'];
276 atomo64-guest 58 }
277     print "\n";
278 atomo64-guest 54 }
279 atomo64-guest 72 if (pg_numrows($rsql)==0) echo "Package=> " . $pkg . "\nNot found\n!!";
280 atomo64-guest 54 pg_close($db);
281 evaso-guest 5 }
282 atomo64-guest 54 function byte_total(&$db,$initial) {
283     global $dirs;
284     $rsql=pg_exec ($db,"Select sum(bytes) as totbytes FROM pkgs WHERE name like '$initial%' AND (md5_diff!=md5_atsource or md5_diff is null)");
285     $res_array=pg_fetch_array($rsql);
286     return $res_array[totbytes] ;
287 evaso-guest 5 }
288 atomo64-guest 64 function download_sources () {
289 atomo64-guest 54 global $dirs,$dists,$mirrors;
290     foreach ($dists as $dist=>$sections) {
291     $server=$mirrors[$dist];
292     $conn_id = ftp_cn("anonymous","bo@bo.org",$server);
293     foreach ($sections as $section) {
294     $localfile=$dirs[sources_dir] . "/$dist/$section/Sources.gz";
295     $remotefile=remote_dist_dir($dist) . "/$dist/$section/source/Sources.gz";
296     $sources_info=md5_source($section,$dist);
297     if (!file_exists ($dirs[sources_dir] . "/$dist/")) mkdir ( $dirs[sources_dir] . "/$dist",0740);
298     if (!file_exists ($dirs[sources_dir] . "/$dist/$section")) mkdir ($dirs[sources_dir] . "/$dist/$section",0740);
299     if (!file_exists($localfile) OR md5_of_file($localfile)!=$sources_info[md5]) {
300     print "Downloading $remotefile Bytes $sources_info[bytes]=> ";
301     if (ftp_get($conn_id,$localfile,$remotefile,FTP_BINARY)) {
302     print "Done\n";
303     if(md5_of_file($localfile)==$sources_info[md5]) print "MD5 => OK\n";
304 atomo64-guest 59 else print "MD5 => no match\n";
305 atomo64-guest 54 }
306     else {
307 atomo64-guest 59 unlink($localfile);
308 atomo64-guest 54 print "Fail\n";
309     die_status ("Error in source file");
310     }
311     }
312 evaso-guest 5 }
313 atomo64-guest 54 ftp_quit($conn_id);
314     }
315 evaso-guest 5 }
316     function md5_source($section,$dist) {
317 atomo64-guest 54 global $mirrors;
318     $relase=file_get_contents ("ftp://$mirrors[$dist]" . remote_dist_dir($dist) . "/$dist/Release") or die_status("Failed to check MD5 of sources");
319     preg_match ("/\s([^\s]+)\s+(\d+)\s$section\/source\/Sources\.gz/i", $relase,$matches);
320     return array("md5"=>$matches[1],"bytes"=>$matches[2]);
321     # 183dea9ca3c2e35ffd6cf5eee9501c21 2941637 main/binary-i386/Packages.gz
322 evaso-guest 5 }
323 atomo64-guest 54
324 atomo64-guest 118 function vers_conv($debvers, $extendedConv = true) {
325 atomo64-guest 54 // Strip off the epoch
326     $pos = strpos($debvers, ':');
327     if ( $pos !== FALSE) {
328     $debvers = substr($debvers, $pos+1);
329     }
330 evaso-guest 45
331 atomo64-guest 54 // strip off the Debian revision (look from the back of the string)
332     $pos = strrpos($debvers, '-');
333     if ( $pos !== FALSE) {
334     $debvers = substr($debvers, 0, $pos);
335     }
336 evaso-guest 45
337 atomo64-guest 116 if ($extendedConv) {
338     // strip off repacking indicators
339     $debvers = preg_replace("/[-.+~]?(ds|dfsg|debian)(.*)/i", "", $debvers);
340     }
341    
342 atomo64-guest 54 return $debvers;
343 evaso-guest 5 }
344     function check_db() {
345 atomo64-guest 54 global $dirs,$dbconn;
346 atomo64-guest 64 $db = pg_pconnect($dbconn) or die_status(1/*pg_last_notice($db)*/);
347 atomo64-guest 95 if (!pg_table_exists($db, "pkgs")) {
348 atomo64-guest 122 pg_exec($db, "CREATE TABLE pkgs (id serial PRIMARY KEY,name text,version text, dversionmangled text,maint text, uploaders text, dir text,watch text,md5_diff text,md5_atsource text,bytes numeric,dist text,section text,up_version text,up_changes text, up_url text,watch_warn text,updated bool, keep_changes bool, wwiz text,wwiz_version text, wwiz_type text, lastcheck timestamp, homepage text, vcs text, vcs_type text, vcs_browser text, lastupvsdebsync timestamp, pop_inst numeric,pop_vote numeric)") or die_status('Error creating table pkgs\n');
349 atomo64-guest 54 pg_exec($db, "CREATE UNIQUE INDEX idxname on pkgs (name,dist)") or die_status('Errore creating index - ' . pg_last_error($db));
350 atomo64-guest 95 pg_exec($db, "CREATE INDEX checkx on pkgs (lastcheck)") or die_status('Errore creating index - ' . pg_last_error($db));
351 atomo64-guest 122 pg_exec($db, "CREATE INDEX maintx on pkgs (maint)") or die_status('Errore creating index - ' . pg_last_error($db));
352 atomo64-guest 54 $sw=true;
353     }
354 atomo64-guest 95 if (!pg_table_exists($db, "binpkgs")) {
355 atomo64-guest 54 pg_exec($db, "CREATE TABLE binpkgs (id serial PRIMARY KEY, name text,bin_name text,dist text, pop_inst numeric,pop_vote numeric, up_error numeric,avg_error_date numeric)") or die_status('Error creating table binpkgs\n');
356     pg_exec($db, "CREATE UNIQUE INDEX idxbin on binpkgs (name,bin_name,dist)") or die_status('Errore creating index - ' . pg_last_error($db));
357     $sw=true;
358     }
359 atomo64-guest 95 if (!pg_table_exists($db, "events")) {
360 atomo64-guest 122 pg_exec($db, "CREATE TABLE events (id serial PRIMARY KEY, name text,type text, dist text, stamp timestamp, content text)") or die_status('Error creating table events\n');
361     pg_exec($db, "CREATE UNIQUE INDEX idxevents on events (name,dist,content)") or die_status('Error creating index - ' . pg_last_error($db));
362     pg_exec($db, "CREATE INDEX pkgxeventtype on events (name,type,dist)") or die_status('Error creating index - ' . pg_last_error($db));
363 atomo64-guest 78 $sw=true;
364 atomo64-guest 95 }
365 atomo64-guest 122 if (!pg_table_exists($db, "stamps")) {
366     pg_exec($db, "CREATE TABLE stamps (type text PRIMARY KEY, stamp timestamp, pid text)") or die_status('Error creating table stamps\n');
367     $sw=true;
368     }
369 atomo64-guest 54 #if (!pg_table_exists($db,"upstream")){
370     # pg_exec($db, "CREATE TABLE upstream (name text,dist text,up_version text,watch_warn text,updated bool)") or die_status('Errore nel creare la tabella');
371     # pg_exec($db, "CREATE UNIQUE INDEX idxupstrm on upstream (name,dist)") or die_status('Errore nel creare gli indici ' . pg_last_error($db));
372     # $sw=true;
373     #}
374     pg_close($db);
375     if($sw) return $sw;
376     else return false;
377 evaso-guest 5 }
378     function pg_table_exists (&$dblink, $table) {
379 atomo64-guest 54 $sql = "SELECT relname as tbl FROM pg_class WHERE relname = '$table'";
380     if ($res = pg_exec ($dblink, $sql)) {
381     return pg_numrows($res) > 0;
382     } else {
383     return false; // or throw exception
384     }
385     }
386 evaso-guest 5
387    
388     function watch_stat() {
389 atomo64-guest 54 global $dirs,$dbconn;
390 atomo64-guest 65 $db = pg_pconnect($dbconn) or die_status(pg_last_error($db));
391 atomo64-guest 54 $rsql=pg_exec ($db,"Select count(name) as totwatch FROM pkgs WHERE watch!=''");
392     $tot_watch=pg_fetch_array($rsql);
393     print "Total packages with Watch =>$tot_watch[0]\n";
394     $rsql=pg_exec ($db,"Select count(name) as totwatch FROM pkgs WHERE watch IS NULL");
395     $tot_nowatch=pg_fetch_array($rsql);
396     pg_close($db);
397     print "Totale packages without Watch => $tot_nowatch[0]\n";
398     print "Watch presence rate => " . number_format ($tot_watch[0]/($tot_nowatch[0]+$tot_watch[0])*100, 2, ",",".") . "%\n";
399 evaso-guest 5 }
400     function remote_dist_dir($dist) {
401 atomo64-guest 54 #if ($dist=="non-US") return "/debian-non-US/dists/unstable";
402     #else
403     return "/debian/dists";
404 evaso-guest 5 }
405 atomo64-guest 102 function clear_db(&$db) {
406 atomo64-guest 54 #global $dbconn;
407     #if (check_db()) die_status("Il Database era vuoto\n");
408 atomo64-guest 64 #download_sources();
409 atomo64-guest 54 #$db = pg_pconnect($dbconn) or die_status(pg_result_error($db));
410     $sql1= "Delete from binpkgs where id NOT IN
411 evaso-guest 5 (select id FROM binpkgs INNER JOIN bin_atsrc USING (name,bin_name,dist))" ;
412 atomo64-guest 54 $sql2= "Delete from pkgs where id NOT IN (select id FROM pkgs INNER JOIN pkgs_atsrc USING (name,dist))" ;
413 atomo64-guest 102 $sql3= "UPDATE pkgs SET wwiz=NULL, wwiz_type=NULL, wwiz_version=NULL WHERE watch IS NOT NULL and watch!=''" ;
414     $sql4= "UPDATE pkgs SET up_changes=NULL WHERE updated='1'";
415     if(pg_exec($db,$sql1) && pg_exec($db,$sql2) && pg_exec($db,$sql3) && pg_exec($db,$sql4)) {
416 atomo64-guest 85 print "Db clear complete\n";
417     }
418 evaso-guest 5 }
419     function db_popcon($initial='') {
420 atomo64-guest 54 global $dirs,$dbconn;
421 atomo64-guest 65 $db = pg_pconnect($dbconn) or die_status(pg_last_error($db));
422 atomo64-guest 122 $filename=$dirs[popcon_dir] . "/popcon.db";
423     $popcon_db = dba_open("$filename", 'r-', 'db4');
424    
425 atomo64-guest 124 $rsql = pg_exec($db, "SELECT name FROM pkgs");
426 atomo64-guest 122
427     while ($res_array=pg_fetch_array($rsql)) {
428     $package = $res_array['name'];
429    
430 atomo64-guest 126 if (!dba_exists('si:' . $package, $popcon_db)) {
431 atomo64-guest 122 continue;
432 atomo64-guest 54 }
433 atomo64-guest 122
434 atomo64-guest 126 $inst = dba_fetch("si:$package", $popcon_db);
435     $vote = dba_fetch("sv:$package", $popcon_db);
436 atomo64-guest 122
437     @pg_exec($db, "UPDATE pkgs SET pop_inst='$inst',pop_vote='$vote' WHERE name='$package'");
438 atomo64-guest 54 }
439 atomo64-guest 122
440     dba_close($popcon_db);
441 atomo64-guest 54 @pg_close($db);
442 evaso-guest 5 }
443 atomo64-guest 59 function dl_popcon() {
444 atomo64-guest 54 global $dirs,$dbconn;
445 atomo64-guest 122
446 atomo64-guest 131 $localtempdir=$dirs[popcon_dir] . "/new";
447     dir_ctrl($localtempdir);
448    
449 atomo64-guest 122 $localfile=$dirs[popcon_dir] . "/popcon.db";
450     $remotefile='http://qa.debian.org/data/popcon/popcon.db';
451    
452     $return = 0;
453 atomo64-guest 123 $output = null;
454 atomo64-guest 131 exec('cd ' . escapeshellarg($localtempdir) . ' && ' .
455     '/usr/bin/wget -qNc ' . escapeshellarg($remotefile), $output, $return);
456 atomo64-guest 122
457     if ($return != 0) {
458     echo __FUNCTION__ . "wget exited with status $return!\n";
459     return false;
460     }
461    
462 atomo64-guest 131 return copy($localtempdir . '/popcon.db', $localfile);
463 evaso-guest 5 }
464 atomo64-guest 102 function is_updated ($up_vers,$debian_vers, $dversionAsIs = false) {
465 atomo64-guest 97 if ($up_vers=='') return 1;
466 atomo64-guest 102
467 atomo64-guest 116 $extendedConv = true;
468    
469 atomo64-guest 102 if ($up_vers === $debian_vers) $dversionAsIs = true;
470    
471 atomo64-guest 116 if (strpos(strtolower($up_vers), 'dfsg') !== false && strpos(strtolower($debian_vers), 'dfsg') !== false) {
472     $extendedConv = false;
473     }
474 atomo64-guest 102
475 atomo64-guest 119 passthru("dpkg --compare-versions ".escapeshellarg($up_vers)." le " . escapeshellarg($dversionAsIs?$debian_vers:vers_conv($debian_vers, $extendedConv)),$great);
476 atomo64-guest 116
477 atomo64-guest 97 return (int)!($great);
478 evaso-guest 17 }
479 atomo64-guest 99 function db_upstream($initial='%', $checkStamps = false, $limit = null) {
480     global $dirs, $dbconn, $minimumAge;
481    
482 atomo64-guest 54 check_db();
483 atomo64-guest 64 $db = pg_pconnect($dbconn) ;
484 atomo64-guest 95 events::DB($db);
485 atomo64-guest 99
486     $postWHERE = '';
487     if ($checkStamps) {
488     $postWHERE = "AND (lastcheck<='".sqldate(time() - ($minimumAge*24*3600))."' OR lastcheck IS NULL)";
489     }
490    
491     $postORDER = '';
492     if ($limit !== null && is_int($limit)) {
493     $postORDER = 'LIMIT ' . $limit;
494     }
495    
496     $rsql=pg_exec($db, "SELECT id, name,dist,up_version,version,watch,lastupvsdebsync FROM pkgs WHERE watch is not null AND name LIKE '$initial' $postWHERE ORDER BY lastcheck DESC $postORDER");
497 atomo64-guest 54 $tot=pg_numrows($rsql);
498 atomo64-guest 99
499 atomo64-guest 54 while ($res_array=pg_fetch_array($rsql)) {
500 atomo64-guest 95
501 atomo64-guest 54 $uscan_res=uscan_foo($res_array['name'],$res_array['version'],$res_array['watch']);
502 atomo64-guest 95
503 atomo64-guest 121 #print $uscan_res['uversion'] . "\n Name => $res_array[name]\n";
504 atomo64-guest 95 $version = $res_array['version'];
505     $dversionmangled = $res_array['version'];
506     $lastupvsdebsync = $res_array['lastupvsdebsync'];
507 atomo64-guest 110 $mangle = true;
508 atomo64-guest 95
509 atomo64-guest 121 print "\rVersion=>" . $uscan_res['dversion'];
510     if ($uscan_res['dversion']!=null) $version=$uscan_res['dversion'];
511     if ($uscan_res['dversionmangled']!=null && $uscan_res['dversionmangled'] != vers_conv($res_array['version'])) {
512     $dversionmangled=$uscan_res['dversionmangled'];
513 atomo64-guest 110 $mangle = false;
514     }
515 atomo64-guest 95
516 atomo64-guest 121 $up_url=iconv("ISO-8859-1","UTF-8",$uscan_res['uurl']);
517     $up_version=iconv("ISO-8859-1","UTF-8",$uscan_res['uversion']);
518 atomo64-guest 116
519 atomo64-guest 121 $updated = $uscan_res['updated'];
520 atomo64-guest 95
521     /*if (!$updated)*/ {
522 atomo64-guest 121 $updated=is_updated($uscan_res['uversion'], $dversionmangled, !$mangle);
523 atomo64-guest 76 }
524    
525 atomo64-guest 70 if (!$updated) {
526 atomo64-guest 121 events::newVersion($res_array['name'], $res_array['version'], $uscan_res['uversion'], $res_array['dist'], $up_url);
527 atomo64-guest 95 } else {
528     $lastupvsdebsync = sqldate();
529 atomo64-guest 70 }
530    
531 atomo64-guest 107 if ($lastupvsdebsync === null) {
532     $lastupvsdebsync = sqldate(0);
533     }
534    
535 atomo64-guest 121 if ($uscan_res['uversion']!=$res_array[up_version]) ($keep_changes=1);
536 atomo64-guest 54 else $keep_changes=0;
537 atomo64-guest 95
538 atomo64-guest 66 $watch_warn='';
539 atomo64-guest 121 if($uscan_res['warnings'] != null) {
540     $watch_warn=pg_escape_string(iconv("ISO-8859-1","UTF-8", $uscan_res['warnings']));
541 atomo64-guest 66 }
542 atomo64-guest 95
543     pg_exec($db, "UPDATE pkgs SET up_version='" . pg_escape_string($up_version) . "', dversionmangled='".pg_escape_string($dversionmangled)."',up_url='" . pg_escape_string($up_url) . "', watch_warn='" . $watch_warn . "',keep_changes='$keep_changes', wwiz_version=NULL, wwiz_type=NULL, wwiz=NULL, updated='$updated', lastcheck=now(), lastupvsdebsync='$lastupvsdebsync' WHERE id=$res_array[id]") or die_status("Error in update pkgs upstream");
544 atomo64-guest 121 #print "\rUpdated " . $res_array['name'] . " => $updated Up Version => ". $uscan_res['uversion'];
545 atomo64-guest 78 print "\t Upstream left => " . $tot --;
546 atomo64-guest 54 # }
547     # else print "Added ". $res_array['name'] ."\n";
548     # if ($great==0) {
549    
550     # print "Package=> " . $res_array['name'] . "\n";
551     # print "Version => " . $res_array['version'] . "\n";
552 atomo64-guest 121 # print "Upstream Ver=> " . $uscan_res['uversion'] . "\n";
553     #print "Watch warings=> " . $uscan_res['warnings'] . "\n";
554 atomo64-guest 54 # }
555     }
556     print "\n";
557     pg_close($db);
558 evaso-guest 5 }
559 evaso-guest 20 function check_url ($url) {
560 atomo64-guest 54 $url_p = parse_url ($url);
561     if (isset ($url_p["host"])) $host = $url_p["host"];
562     else return false;
563     preg_match("/(http|ftp)/",$host,$matches);
564     if ($matches[1]=='http') $fp = fsockopen ($host, 80, $errno, $errstr, 5);
565     elseif ($matches[1]=='ftp') $fp2 = fsockopen ($host, 21, $errno, $errstr, 5);
566     if (!$fp AND !$fp2) return false;
567     else return true;
568 evaso-guest 20 }
569 evaso-guest 17 function keep_remote ($localfile,$remotefile) {
570 atomo64-guest 54 if (!check_url($remotefile)) return false;
571     # $rfp = @fopen ($remotefile, "r");
572     # if (!$rfp) {
573     # return false;
574     # }
575     # fclose($rfp);
576     # $lfp = fopen ($localfile, "w");
577     # stream_set_blocking($rfp,0);
578     # ini_set ( "memory_limit", "100M");
579     # while (!feof($rfp)) {
580     # $data = fread($rfp, 8192);
581     # $bytes+=8192;
582     # print "Downlaoding $remotefile: $bytes\r";
583     # fwrite($lfp, $data);
584     # } while (true);
585     # ini_set ( "memory_limit", "15M");
586    
587     if (!copy($remotefile, $localfile)) {
588     echo "Copia di $file non riuscita ...\n";
589     return false;
590     }
591     # fclose($lfp);
592     # fclose($rfp);
593    
594     return true;
595 evaso-guest 44 }
596 atomo64-guest 59 function up_changes($src_name='%', $force = false) {
597     global $dbconn, $fetchUpstreamChanges;
598    
599     if (!$fetchUpstreamChanges && !$force) {
600 atomo64-guest 95 //print "\nSkipping download of upstream sources to grab changelogs\n";
601 atomo64-guest 59 return;
602     }
603    
604 atomo64-guest 54 $changes_files=array("CHANGES","NEWS","Changelog","ChangeLog","changelog");
605 evaso-guest 44 $db = pg_pconnect($dbconn) ;
606 atomo64-guest 85 $rsql=pg_exec($db, "SELECT id,up_url FROM pkgs WHERE up_url!='' AND keep_changes='t' AND name LIKE '$src_name'");
607 atomo64-guest 54 $tot=pg_numrows($rsql);
608     while ($res_array=pg_fetch_array($rsql)) {
609     $localfile=tempnam("/tmp/", "dehs-" . $res_array[id] . ".tar.gz");
610     print "I'm downloading $res_array[up_url]\r";
611     $res=keep_remote($localfile,$res_array['up_url']);
612     print "UPDATE pkgs SET up_changes='', keep_changes='f' WHERE id=$res_array[id]";
613     if (!$res) {
614     pg_exec($db, "UPDATE pkgs SET up_changes='', keep_changes='f' WHERE id=$res_array[id]");
615     $notdown++;
616     $tot--;
617     print "Packages Left: " . $tot-- . " Found: $found Not found: $notfound Not Down: $notdown\r";
618     #print "\n Not Downlaoded: $res_array[up_url]\n";
619     unlink($localfile);
620     continue;
621     }
622     foreach($changes_files as $filename) {
623 atomo64-guest 59 $command="tar --wildcards -zxOf " . $localfile . " *$filename 2>/dev/null";
624 atomo64-guest 54 exec($command,$up_changes,$cmdres);
625     $up_changes=rtrim(implode("\n",$up_changes));
626     if ($cmdres==0 AND strlen($up_changes)>20) {
627     $sw=true;
628     $conv_res=iconv("ISO-8859-1","UTF-8",$up_changes);
629     if ($conv_res) $up_changes=$conv_res;
630 atomo64-guest 66 $up_changes=pg_escape_string($up_changes);
631 atomo64-guest 54 $up_changes_sql="UPDATE pkgs SET up_changes='$up_changes', keep_changes='f' WHERE id=$res_array[id]";
632     pg_exec($db,$up_changes_sql);
633     #print "\nFound $filename on $res_array[up_url]\n";
634     $found++;
635     break;
636     }
637     }
638     if (!$sw) {
639     pg_exec($db, "UPDATE pkgs SET up_changes='', keep_changes='f' WHERE id=$res_array[id]");
640     #print "\n Not Found any on $res_array[up_url]\n";
641     $notfound++;
642     }
643     unlink($localfile);
644     print "Packages Left: " . $tot-- . " Found: $found Not found: $notfound Not Down: $notdown\r";
645     }
646     pg_close($db);
647 evaso-guest 17 }
648 evaso-guest 5 function uscan_foo($name,$version,$watch){
649 atomo64-guest 46 global $base, $uscan;
650 atomo64-guest 54
651 evaso-guest 43 $tmpnam=tempnam('/tmp/', $name.'_watch');
652 evaso-guest 42 $fw=fopen($tmpnam,"w");
653 atomo64-guest 54 fwrite($fw,$watch);
654     fclose($fw);
655    
656     $uscan_res=shell_exec("$uscan --dehs --package $name --upstream-version " . escapeshellarg(vers_conv($version)) . " --watchfile $tmpnam 2>/dev/null 2>&1");
657    
658 evaso-guest 43 unlink($tmpnam);
659 atomo64-guest 54
660     $p = xml_parser_create();
661     xml_parse_into_struct($p, $uscan_res, $vals, $index);
662     xml_parser_free($p);
663    
664     $upstream=$vals[$index['UPSTREAM-VERSION'][0]][value];
665     $up_url=$vals[$index['UPSTREAM-URL'][0]][value];
666     $deb_vers=$vals[$index['DEBIAN-UVERSION'][0]][value];
667 atomo64-guest 73 $deb_mangled_vers=$vals[$index['DEBIAN-MANGLED-UVERSION'][0]][value];
668 atomo64-guest 54 $warnings=$vals[$index['WARNINGS'][0]][value];
669     $updated=$vals[$index['STATUS'][0]][value];
670    
671 atomo64-guest 95 if ($updated=="up to date") $updated=1;
672     else $updated=0;
673 atomo64-guest 54
674     if ($upstream=='') $upstream=null;
675     if ($up_url=='') $up_url=null;
676     if ($deb_vers=='') $deb_vers=null;
677     if ($warnings=='') $warnings=null;
678 atomo64-guest 73 if ($deb_mangled_vers=='') $deb_mangled_vers=null;
679 atomo64-guest 54
680 atomo64-guest 121 $ret = array();
681     $ret['uversion'] = $upstream;
682     $ret['warnings'] = $warnings;
683     $ret['uurl'] = $up_url;
684     $ret['dversion'] = $deb_vers;
685     $ret['dversionmangled'] = $deb_mangled_vers;
686     $ret['updated'] = $updated;
687    
688     return $ret;
689 atomo64-guest 54 }
690 evaso-guest 5 function db_up_error() {
691     global $dbconn;
692 atomo64-guest 54 check_db();
693 atomo64-guest 64 $db = pg_pconnect($dbconn) ;
694 atomo64-guest 54 $bugurl="http://bugs.debian.org/cgi-bin/pkgreport.cgi?which=tag&data=upstream&archive=no&show_list_header=no&pend-exc=done";
695 atomo64-guest 59 print "\nDownloading bugs list =>";
696 atomo64-guest 54 $ferrors=file_get_contents($bugurl) or die_status ("I can't keep error page from bugs.debian.org");
697     print "Done\n";
698     $ferrors=explode("<li>",$ferrors);
699     $totline=count($ferrors);
700     #$errors[]=array();
701     #array_pop($errors);
702 atomo64-guest 59 print "Total lines => $totline\n";
703 atomo64-guest 54 foreach ($ferrors as $line) {
704     # print $line . "\n";
705 atomo64-guest 59 if (preg_match("/Package:.+?>([^<]+)<\/a>.+<strong>((\d+)\syear\sand\s|)(\d+)\sdays/sS",$line,$matches)) {
706 atomo64-guest 54 $errors[$matches[1]][err_tot]++;
707     $errors[$matches[1]][days]+=$matches[3]*365+$matches[4];
708     #if ($matches[3]) print "Anni $matches[3]";
709     #print "Giorni $matches[4]\n";
710     }
711 atomo64-guest 59 print "\rLines left => " . $totline--;
712 atomo64-guest 54 }
713     #arsort($errors);
714     $total=count($errors);
715 atomo64-guest 59 foreach ($errors as $pkg_name=>$value) {
716     pg_exec($db, "UPDATE binpkgs SET up_error=" . $value[err_tot] . ",avg_error_date=" . $value[days]/$value[err_tot] . " WHERE bin_name='$pkg_name'") or die_status("Error in upstream bug query");
717 atomo64-guest 54 #print "Pkg: $error Errori: $value[err_tot] Average Days: " . $value[days]/$value[err_tot] . "\n";
718 atomo64-guest 59 print "\rBugs left => " . $total--;
719 atomo64-guest 54 }
720     pg_close($db);
721 evaso-guest 5 }
722 atomo64-guest 99 function watch_wizard($src_name='%', $checkStamps = false, $limit = null){
723     global $dirs,$dbconn,$sfIgnore,$watchFileExts,$watchFileDversionMangle,$watchFormat,$minimumAge;
724 atomo64-guest 54 $db = pg_pconnect($dbconn) or die_status ("Db error");
725     $checked=$errors=$notfound=$verok=$notmatch=0;
726    
727 atomo64-guest 62 // prepare some stuff that needs to be done once per run
728 atomo64-guest 73 $opts = array();
729     $exts = '';
730     $dvmanglers = '';
731 atomo64-guest 62
732     foreach ($watchFileExts as $ext) {
733     $exts .= $ext . '|';
734     }
735     unset($ext);
736    
737 atomo64-guest 73 if ($exts != '') {
738     $opts[] = 'uversionmangle=s/\.(' . substr($exts, 0, -1) . ')$//i';
739 atomo64-guest 84 $exts = '(' . $exts . ')';
740 atomo64-guest 62 }
741    
742 atomo64-guest 73 foreach ($watchFileDversionMangle as $dvmangler) {
743     $dvmanglers .= $dvmangler . '|';
744     }
745     unset($dvmangler);
746    
747     if ($dvmanglers != '') {
748     $opts[] = 'dversionmangle=s/[-.+~]?(' . substr($dvmanglers, 0, -1) . ')(.*)$//i';
749     }
750    
751 atomo64-guest 84 $opts[] = 'pasv';
752    
753 atomo64-guest 73 if (is_array($opts)) {
754     $_opts = '';
755     foreach ($opts as $opt) {
756     $_opts .= $opt . ',';
757     }
758     $opts = '';
759     if ($_opts != ',') {
760     $opts = 'opts=' . substr($_opts, 0, -1) . ' \\';
761     }
762     }
763    
764 atomo64-guest 99 $postWHERE = '';
765     if ($checkStamps) {
766 atomo64-guest 121 $postWHERE = "AND (lastcheck<='".sqldate(time() - ($minimumAge*24*3600))."' OR lastcheck IS NULL)"
767 atomo64-guest 122 . " AND wwiz_type!='no_cright' AND wwiz_type!='notmatch'";
768 atomo64-guest 99 }
769    
770     $postORDER = '';
771     if ($limit !== null && is_int($limit)) {
772     $postORDER = 'LIMIT ' . $limit;
773     }
774    
775 atomo64-guest 122 $sqlstring="SELECT name,version,dversionmangled,section,dist, wwiz_version FROM pkgs
776 atomo64-guest 99 WHERE (watch IS NULL OR watch='') AND name LIKE '$src_name' $postWHERE ORDER BY lastcheck DESC $postORDER";
777 atomo64-guest 71 $rsql=pg_exec($db, $sqlstring);
778    
779 atomo64-guest 54 while ($res_array=pg_fetch_array($rsql)) {
780    
781     if (substr($res_array["name"],0,3)=='lib')
782     $initial=substr($res_array["name"],0,4);
783     else
784     $initial=substr($res_array["name"],0,1);
785    
786     $url="http://packages.debian.org/changelogs/pool/" .
787     $res_array["section"] . "/" .
788     $initial . "/" .
789     $res_array["name"] ."/" .
790     $res_array["name"] . "_" .
791     $res_array["version"] . "/copyright";
792     $contents=@file_get_contents($url) or '';
793     $generatedWatches = array();
794    
795     if (!$contents) {
796     $url="http://packages.debian.org/changelogs/pool/" .
797     $res_array["section"] . "/" .
798     $initial . "/" .
799     $res_array["name"] ."/" .
800     $res_array["name"] . "_" .
801     $res_array["version"] . "/" . $res_array["name"] . ".copyright";
802     $contents=@file_get_contents($url) or '';
803     }
804    
805 atomo64-guest 73 if (!$contents) {
806     $url="http://packages.debian.org/changelogs/pool/" .
807     $res_array["section"] . "/" .
808     $initial . "/" .
809     $res_array["name"] ."/" .
810     "current/copyright";
811     $contents=@file_get_contents($url) or '';
812     }
813    
814 atomo64-guest 54 if ($contents) {
815    
816     if (preg_match ('/(sf\.net|sourceforge\.net)/i', $contents, $matches) ||
817     (preg_match ('/([\w\-]+)\.(sf\.net|sourceforge\.net)/i', $contents, $matches)
818     && !in_array($matches[1], $sfIgnore))) {
819     preg_match("/([^\d]+)/",$res_array['name'],$dmatches);
820     $depured_debian_name=$dmatches[1];
821     /*$matches[1]="ftp://download.sf.net/pub/sourceforge/" . substr($depured_debian_name,0,1) . "/" . substr($depured_debian_name,0,2) . "/" . $depured_debian_name . "/";*/
822 atomo64-guest 62 $generatedWatches[]=array('url'=>"http://sf.net/" . $depured_debian_name . "/");
823 atomo64-guest 54 $generatedWatches[]=array('url'=>"http://sf.net/" . $depured_debian_name . "/",'name'=>$depured_debian_name);
824    
825     }
826    
827 atomo64-guest 67 if (preg_match ('#((ftp://|http://|https://)\S+(html|htm|/(?(?=.+(tar|tgz|zip|gz|bz2))|[^>\s\)\a]+)))#i',$contents,$matches)) {
828 atomo64-guest 54 $final=substr($matches[1],-1);
829     if ($final=='.') {
830     $matches[1]=substr($matches[1],0,-1);
831     $final=substr($matches[1],-1);
832     }
833 atomo64-guest 58 if ($matches[2]=="http://" || $matches[2]=="https://") {
834 atomo64-guest 54 $space=' ' . "(?:.*/)?";
835     } elseif ($final!='/') {
836     $matches[1].='/';
837     }
838 atomo64-guest 59 $generatedWatches[]=array('url' => preg_replace("#((http|https|ftp)://.+):(.*)#i",'$1' . '$3', $matches[1],1), 'space' => $space);
839 atomo64-guest 54 }
840    
841 atomo64-guest 67 if (preg_match ('#((ftp|http)\.\S+(html|htm|/(?(?=.+(tar|tgz|zip|gz|bz2))|[^>\s\)\a]+)))#i',$contents,$matches)) {
842 atomo64-guest 54 $final=substr($matches[1],-1);
843     if ($final=='.') {
844     $matches[1]=substr($matches[1],0,-1);
845     $final=substr($matches[1],-1);
846     }
847     $space = '';
848     if ($matches[2]=="http") {
849     $space=' ' . "(?:.*/)?";
850     } elseif ($final!='/') {
851     $matches[1].='/';
852     }
853 atomo64-guest 59 $generatedWatches[]=array('url'=>preg_replace('#(http|ftp)\.(.+)#i','$1://$0', $matches[1],1), 'space'=>$space);
854 atomo64-guest 54 }
855    
856     if (empty($generatedWatches)) {
857     $notmatch++;
858     $contents=iconv("ISO-8859-1","UTF-8",$contents);
859 atomo64-guest 121 pg_exec($db, "UPDATE pkgs SET wwiz_version=NULL, wwiz='" . pg_escape_string($contents) . "', wwiz_type='notmatch', up_url='', up_changes='', lastcheck=now(), keep_changes='f' where name='" . pg_escape_string($res_array[name]) . "' AND dist='" . $res_array[dist] ."'");
860 atomo64-guest 54
861     } else {
862    
863 atomo64-guest 56 $defs = array('name' => $res_array['name'], 'url' => '', 'space' => '');
864 atomo64-guest 54
865     foreach ($generatedWatches as $tWatch) {
866    
867 atomo64-guest 59 if (!is_array($tWatch)) {
868     $tWatch = array($tWatch);
869     }
870    
871 atomo64-guest 54 $tWatch = array_merge($defs, $tWatch);
872    
873 atomo64-guest 62 $watch = sprintf($watchFormat, $tWatch['url'], $tWatch['space'], $tWatch['name'], $exts, $opts);
874 atomo64-guest 54
875 atomo64-guest 62 $uscan_res=uscan_foo($res_array['name'] ,$res_array['version'],$watch);
876 atomo64-guest 54
877 atomo64-guest 121 if ($uscan_res['uversion'] && levenshtein($uscan_res['uversion'], $res_array['version']) < strlen($res_array['version'])) {
878 atomo64-guest 71 break;
879 atomo64-guest 54 }
880     }
881    
882 atomo64-guest 121 if ($uscan_res['warnings'] && !$uscan_res['uversion']) {
883     pg_exec($db, "UPDATE pkgs SET wwiz_version=NULL, wwiz='" . pg_escape_string($uscan_res['warnings']) . "', wwiz_type='error', up_url='', up_changes='', lastcheck=now(), keep_changes='f' where name='" . pg_escape_string($res_array[name]) . "' AND dist='" . $res_array[dist] ."'");
884 atomo64-guest 54 $errors++;
885     } else {
886     $verok++;
887 atomo64-guest 121 if ($uscan_res['uversion'] != $res_array['wwiz_version']) {
888 atomo64-guest 54 $keep_changes = 1;
889     } else {
890     $keep_changes = 0;
891     }
892 atomo64-guest 76
893     $dversionmangled = $res_array[version];
894 atomo64-guest 121 if ($uscan_res['dversionmangled']!=null && $uscan_res['dversionmangled'] != vers_conv($res_array['version'])) $dversionmangled=$uscan_res['dversionmangled'];
895 atomo64-guest 76
896 atomo64-guest 121 $updated = $uscan_res['updated'];
897 atomo64-guest 95 /*if ($updated)*/ {
898 atomo64-guest 121 $updated = is_updated($uscan_res['uversion'], $dversionmangled, $dversionmangled != $uscan_res['dversionmangled']);
899 atomo64-guest 76 }
900 atomo64-guest 70
901 atomo64-guest 78 /*if (!$updated) {
902 atomo64-guest 121 events::newVersion($res_array['name'], $res_array['version'], $uscan_res['uversion'], $res_array['dist']);
903 atomo64-guest 78 }*/
904 atomo64-guest 70
905 atomo64-guest 121 pg_exec($db, "UPDATE pkgs SET wwiz='" . pg_escape_string($watch) ."', wwiz_type='watch', wwiz_version='" . pg_escape_string($uscan_res['uversion']) . "',dversionmangled='".pg_escape_string($dversionmangled)."', up_url='" . pg_escape_string($uscan_res['uurl']) . "', keep_changes='$keep_changes', updated='$updated', lastcheck=now() where name='" . pg_escape_string($res_array[name]) . "' AND dist='" . $res_array[dist] ."'");
906 atomo64-guest 54 }
907     }
908     } else {
909     $notfound++;
910     pg_exec($db, "UPDATE pkgs SET wwiz_version=NULL, wwiz_type='no_cright' where name='" . pg_escape_string($res_array['name']) . "' AND dist='" . $res_array['dist'] ."'");
911     }
912     print "Package checked: " . $checked++ .
913     " OK: $verok Error: $errors Not Matched: $notmatch\r";
914     }
915     print "\nCopyright files not found: $notfound\n";
916 atomo64-guest 59 print "Automatic generated watch file failures: $errors\n";
917 atomo64-guest 54 pg_close($db);
918 evaso-guest 13 }
919 evaso-guest 26 function dbqa_conn ($dbname,$mode) {
920 atomo64-guest 54 $id = dba_open($dbname, $mode, "db4");
921     if (!$id) {
922     die_status("dba_open failed\n");
923     }
924     return $id;
925 evaso-guest 26 }
926     function dehsqa_db () {
927 atomo64-guest 54 global $dirs,$dbconn;
928     $dir1='/org/alioth.debian.org/chroot/home/groups/dehs/htdocs/';
929     $dir2="/org/qa.debian.org/data/dehs/";
930     $dists=array("unstable","experimental");
931     foreach ($dists as $dist) {
932     $id=dbqa_conn($dir1 . "dehs_qa_" . $dist . ".db",'n');
933     $db = pg_pconnect($dbconn) or die_status ("Db error");
934 atomo64-guest 106 $sql="SELECT name, id, up_version, wwiz_version, watch, wwiz_type, watch_warn, version, dversionmangled, updated FROM pkgs WHERE dist='$dist'";
935 atomo64-guest 54 $rsql=pg_exec($db, $sql);
936     while($res_array=pg_fetch_array($rsql)) {
937    
938 atomo64-guest 63 if (!$res_array[watch]) { if ($res_array['wwiz_type']==null) $version="N/A"; else $version='-';}
939 atomo64-guest 54 elseif (!$res_array[up_version]) $version="Error";
940     else $version=$res_array[up_version];
941    
942     if ($res_array['wwiz_type']=="watch") $wwiz=$res_array['wwiz_version'];
943     else $wwiz=$res_array[wwiz_type];
944    
945 atomo64-guest 106 $updated = $res_array['updated']? 'yes' : 'no';
946    
947 atomo64-guest 54 $xml="<data><id>$res_array[id]</id>" .
948     "<up_version>$version</up_version>" .
949 atomo64-guest 73 "<dversion>$res_array[version]</dversion>" .
950     "<dversionmangled>$res_array[dversionmangled]</dversionmangled>" .
951 atomo64-guest 106 "<updated>$updated</updated>" .
952 atomo64-guest 54 "<wwiz>$wwiz</wwiz>" .
953     "</data>";
954     $value=addslashes($xml);
955     dba_replace($res_array[name],$xml,$id);
956     }
957     dba_optimize($id);
958     dba_close($id);
959     pg_close($db);
960     }
961 evaso-guest 26 }
962     function md5_of_file($inFile) {
963 atomo64-guest 54 if (file_exists($inFile)) {
964     return md5_file($inFile);
965     } else {
966     return false;
967     }
968 evaso-guest 26 }
969 evaso-guest 5 function update_all() {
970 atomo64-guest 111 global $email, $timeStamp_basedCheck;
971 atomo64-guest 54 $intime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
972 atomo64-guest 85 echo __FUNCTION__ . ' started the ' . $intime . "\n";
973 atomo64-guest 54 db_add();
974 atomo64-guest 59 dl_diffs();
975 atomo64-guest 54 db_up_error();
976 atomo64-guest 99 db_upstream('%', in_array('all', $timeStamp_basedCheck));
977     watch_wizard('%', in_array('all', $timeStamp_basedCheck));
978 atomo64-guest 54 up_changes();
979     dehsqa_db();
980     $endtime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
981     $messaggio="Dehs executed successful\nBegin: $intime\nEnd: $endtime";
982     mail($email, "DEHS report", $messaggio,
983     "From: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" .
984     "Reply-To: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" .
985     "X-Mailer: PHP/" . phpversion());
986 evaso-guest 5 }
987 atomo64-guest 64 function update_new() {
988     global $email_all;
989     $intime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
990 atomo64-guest 85 echo __FUNCTION__ . ' started the ' . $intime . "\n";
991 atomo64-guest 102 db_add();
992 atomo64-guest 64
993     global $dbconn;
994     check_db();
995     $db = pg_pconnect($dbconn);
996 atomo64-guest 114 $sql="SELECT name FROM pkgs WHERE (md5_diff!=md5_atsource or md5_diff is null) or (lastcheck is null and watch is not null)";
997 atomo64-guest 64 $rsql=pg_exec($db, $sql);
998     $res_array=pg_fetch_all($rsql);
999     pg_close($db);
1000    
1001     dl_diffs();
1002     db_up_error();
1003     if ($res_array !== false) {
1004     foreach ($res_array as $entry) {
1005     db_upstream($entry['name']);
1006     up_changes($entry['name']);
1007 atomo64-guest 69 watch_wizard($entry['name']);
1008 atomo64-guest 64 }
1009     dehsqa_db();
1010     }
1011     $endtime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
1012     $messaggio="Dehs executed successful\nBegin: $intime\nPackages processed: ".((!is_array($res_array))?'none':count($res_array))."\nEnd: $endtime";
1013     mail($email_all, "DEHS update_new report", $messaggio,
1014     "From: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" .
1015     "Reply-To: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" .
1016     "X-Mailer: PHP/" . phpversion());
1017     }
1018 atomo64-guest 65 function update_bogus() {
1019 atomo64-guest 66 global $email_all,$dbconn;
1020 atomo64-guest 65 $intime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
1021 atomo64-guest 85 echo __FUNCTION__ . ' started the ' . $intime . "\n";
1022 atomo64-guest 65 check_db();
1023     $db = pg_pconnect($dbconn);
1024     $sql="SELECT name FROM pkgs WHERE up_version='' AND watch!=''";
1025     $rsql=pg_exec($db, $sql);
1026     $res_array=pg_fetch_all($rsql);
1027 atomo64-guest 77 $orig_count = ((!is_array($res_array))?0:count($res_array));
1028 atomo64-guest 65 if ($res_array !== false) {
1029     foreach ($res_array as $entry) {
1030     db_upstream($entry['name']);
1031     up_changes($entry['name']);
1032     }
1033     dehsqa_db();
1034     }
1035 atomo64-guest 77 $sql="SELECT COUNT(name) FROM pkgs WHERE up_version='' AND watch!=''";
1036     $rsql=pg_exec($db, $sql);
1037     $res_array=pg_fetch_array($rsql);
1038     $new_count = (int)$res_array[0];
1039     pg_close($db);
1040 atomo64-guest 65 $endtime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
1041 atomo64-guest 77 $messaggio="Dehs executed successful\nBegin: $intime\n".
1042     "Packages processed: $orig_count\n" .
1043     "New bogus watches count: $new_count\nEnd: $endtime";
1044 atomo64-guest 65 mail($email_all, "DEHS update_bogus report", $messaggio,
1045     "From: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" .
1046     "Reply-To: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" .
1047     "X-Mailer: PHP/" . phpversion());
1048     }
1049 atomo64-guest 49 function die_status($msg = '', $status = 1) {
1050 atomo64-guest 54 if (empty($msg)) {
1051     die($status);
1052     } else if (is_int($msg) && $status == 1 /* default */) {
1053     die($msg);
1054     } else {
1055 atomo64-guest 113 fwrite(STDERR, $msg);
1056 atomo64-guest 54 die($status);
1057     }
1058 atomo64-guest 49 }
1059 atomo64-guest 70
1060 atomo64-guest 95 function sqldate($timestamp=null) {
1061     if ($timestamp===null) $timestamp=time();
1062     return gmdate("Y-m-d H:i:s", $timestamp);
1063     }
1064    
1065 atomo64-guest 46 ?>

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5