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