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

Contents of /trunk/dehs_pg.php

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5