| 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 by Raphael Geissert <atomo64@gmail.com> |
| 8 |
|
|
| 9 |
This program is free software; you can redistribute it and/or modify |
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 |
it under the terms of the GNU General Public License as published by |
| 58 |
} |
} |
| 59 |
} |
} |
| 60 |
|
|
| 61 |
if (in_array("-db_add",$argv)) db_add($argv[2]); |
if (in_array("-db_add",$argv)) db_add($argv[2], false); |
| 62 |
elseif (in_array("-db_query",$argv)) db_query($argv[2],$argv[3] ); |
elseif (in_array("-db_query",$argv)) db_query($argv[2],$argv[3] ); |
| 63 |
elseif (in_array("-dl_diffs",$argv) || in_array("-keep_diff",$argv)) dl_diffs($argv[2]); |
elseif (in_array("-dl_diffs",$argv) || in_array("-keep_diff",$argv)) dl_diffs($argv[2]); |
| 64 |
elseif (in_array("-keep_sources",$argv)) keep_sources(); |
elseif (in_array("-keep_sources",$argv) || in_array("-download_sources",$argv)) download_sources(); |
| 65 |
elseif (in_array("-db_popcon",$argv)) db_popcon($argv[2]); |
elseif (in_array("-db_popcon",$argv)) db_popcon($argv[2]); |
| 66 |
elseif (in_array("-dl_popcon",$argv) || in_array("-keep_popcon",$argv)) dl_popcon($argv[2]); |
elseif (in_array("-dl_popcon",$argv) || in_array("-keep_popcon",$argv)) dl_popcon($argv[2]); |
| 67 |
elseif (in_array("-db_upstream",$argv)) db_upstream($argv[2]); |
elseif (in_array("-db_upstream",$argv)) db_upstream($argv[2]); |
| 68 |
elseif (in_array("-update_all",$argv)) update_all(); |
elseif (in_array("-update_all",$argv)) update_all(); |
| 69 |
|
elseif (in_array("-update_new",$argv)) update_new(); |
| 70 |
elseif (in_array("-check_db",$argv)) check_db(); |
elseif (in_array("-check_db",$argv)) check_db(); |
| 71 |
elseif (in_array("-dehsqa_db",$argv)) dehsqa_db(); |
elseif (in_array("-dehsqa_db",$argv)) dehsqa_db(); |
| 72 |
elseif (in_array("-clear_db",$argv)) clear_db(); |
elseif (in_array("-clear_db",$argv)) clear_db(); |
| 167 |
print "Download Diff.gz of package $pkg => Fallito\n"; |
print "Download Diff.gz of package $pkg => Fallito\n"; |
| 168 |
return false; |
return false; |
| 169 |
} |
} |
| 170 |
function db_add($initial='') { |
function db_add($initial='', $clear_db = true) { |
| 171 |
global $dirs,$dists,$dbconn; |
global $dirs,$dists,$dbconn; |
| 172 |
check_db(); |
check_db(); |
| 173 |
keep_source(); |
download_sources(); |
| 174 |
|
|
| 175 |
$db = pg_connect($dbconn) or die_status(pg_errormessage($db)); |
$db = pg_pconnect($dbconn) or die_status(pg_errormessage($db)); |
| 176 |
pg_exec($db, "CREATE TEMP TABLE pkgs_atsrc (name text,dist text)") or die_status('Error creating temp table pkgs_atsrc'); |
pg_exec($db, "CREATE TEMP TABLE pkgs_atsrc (name text,dist text)") or die_status('Error creating temp table pkgs_atsrc'); |
| 177 |
pg_exec($db, "CREATE UNIQUE INDEX idxdis on pkgs_atsrc (name,dist)") or die_status('Error creating index on temp table'); |
pg_exec($db, "CREATE UNIQUE INDEX idxdis on pkgs_atsrc (name,dist)") or die_status('Error creating index on temp table'); |
| 178 |
pg_exec($db, "CREATE TEMP TABLE bin_atsrc (name text,bin_name text, dist text)") or die_status('Error creating temp table pkgs_atsrc'); |
pg_exec($db, "CREATE TEMP TABLE bin_atsrc (name text,bin_name text, dist text)") or die_status('Error creating temp table pkgs_atsrc'); |
| 197 |
$buff1 .= $line; |
$buff1 .= $line; |
| 198 |
} |
} |
| 199 |
if (preg_match($regexp,$buff1,$matches)) { |
if (preg_match($regexp,$buff1,$matches)) { |
| 200 |
|
if ($matches[5]) { |
| 201 |
|
$matches[5]=iconv("ISO-8859-1","UTF-8",$matches[5]); |
| 202 |
|
$matches[5]=pg_escape_string($matches[5]); |
| 203 |
|
} |
| 204 |
if ($matches[10]) { |
if ($matches[10]) { |
| 205 |
$matches[10]=iconv("ISO-8859-1","UTF-8",$matches[10]); |
$matches[10]=iconv("ISO-8859-1","UTF-8",$matches[10]); |
| 206 |
$matches[10]=addslashes($matches[10]); |
$matches[10]=pg_escape_string($matches[10]); |
| 207 |
} |
} |
| 208 |
@pg_exec($db,"INSERT INTO pkgs_atsrc (name,dist) VALUES ('$matches[1]','$dist')") OR die_status("Temp table pkgs_atsrc query error"); |
@pg_exec($db,"INSERT INTO pkgs_atsrc (name,dist) VALUES ('$matches[1]','$dist')") OR die_status("Temp table pkgs_atsrc query error"); |
| 209 |
$rst=@pg_exec($db, "INSERT INTO pkgs (name,version,maint,dir,md5_atsource,bytes,dist,section,uploaders) VALUES ('$matches[1]','$matches[4]','$matches[5]','$matches[6]','$matches[7]','$matches[8]','$dist','$section','$matches[10]')") ; |
$rst=@pg_exec($db, "INSERT INTO pkgs (name,version,maint,dir,md5_atsource,bytes,dist,section,uploaders) VALUES ('$matches[1]','$matches[4]','$matches[5]','$matches[6]','$matches[7]','$matches[8]','$dist','$section','$matches[10]')") ; |
| 229 |
gzclose($zp) ; |
gzclose($zp) ; |
| 230 |
} |
} |
| 231 |
} |
} |
| 232 |
|
if (!$clear_db) |
| 233 |
clear_db($db); |
clear_db($db); |
| 234 |
pg_close($db); |
pg_close($db); |
| 235 |
} |
} |
| 273 |
$res_array=pg_fetch_array($rsql); |
$res_array=pg_fetch_array($rsql); |
| 274 |
return $res_array[totbytes] ; |
return $res_array[totbytes] ; |
| 275 |
} |
} |
| 276 |
function keep_source () { |
function download_sources () { |
| 277 |
global $dirs,$dists,$mirrors; |
global $dirs,$dists,$mirrors; |
| 278 |
foreach ($dists as $dist=>$sections) { |
foreach ($dists as $dist=>$sections) { |
| 279 |
$server=$mirrors[$dist]; |
$server=$mirrors[$dist]; |
| 328 |
} |
} |
| 329 |
function check_db() { |
function check_db() { |
| 330 |
global $dirs,$dbconn; |
global $dirs,$dbconn; |
| 331 |
$db = pg_connect($dbconn) or die_status(1/*pg_last_notice($db)*/); |
$db = pg_pconnect($dbconn) or die_status(1/*pg_last_notice($db)*/); |
| 332 |
if (!pg_table_exists($db,"pkgs")){ |
if (!pg_table_exists($db,"pkgs")){ |
| 333 |
pg_exec($db, "CREATE TABLE pkgs (id serial PRIMARY KEY,name text,version 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)") or die_status('Error creating table pkgs\n'); |
pg_exec($db, "CREATE TABLE pkgs (id serial PRIMARY KEY,name text,version 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)") or die_status('Error creating table pkgs\n'); |
| 334 |
pg_exec($db, "CREATE UNIQUE INDEX idxname on pkgs (name,dist)") or die_status('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)); |
| 378 |
function clear_db(&$db) { |
function clear_db(&$db) { |
| 379 |
#global $dbconn; |
#global $dbconn; |
| 380 |
#if (check_db()) die_status("Il Database era vuoto\n"); |
#if (check_db()) die_status("Il Database era vuoto\n"); |
| 381 |
#keep_source(); |
#download_sources(); |
| 382 |
#$db = pg_pconnect($dbconn) or die_status(pg_result_error($db)); |
#$db = pg_pconnect($dbconn) or die_status(pg_result_error($db)); |
| 383 |
$sql1= "Delete from binpkgs where id NOT IN |
$sql1= "Delete from binpkgs where id NOT IN |
| 384 |
(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))" ; |
| 451 |
function db_upstream($initial='%') { |
function db_upstream($initial='%') { |
| 452 |
global $dirs,$dbconn; |
global $dirs,$dbconn; |
| 453 |
check_db(); |
check_db(); |
| 454 |
$db = pg_connect($dbconn) ; |
$db = pg_pconnect($dbconn) ; |
| 455 |
$rsql=pg_exec($db, "SELECT id, pkgs.name,pkgs.dist,up_version,version,watch FROM pkgs WHERE watch is not null AND name LIKE '$initial%' ORDER BY name DESC"); |
$rsql=pg_exec($db, "SELECT id, pkgs.name,pkgs.dist,up_version,version,watch FROM pkgs WHERE watch is not null AND name LIKE '$initial%' ORDER BY name DESC"); |
| 456 |
$tot=pg_numrows($rsql); |
$tot=pg_numrows($rsql); |
| 457 |
while ($res_array=pg_fetch_array($rsql)) { |
while ($res_array=pg_fetch_array($rsql)) { |
| 608 |
function db_up_error() { |
function db_up_error() { |
| 609 |
global $dbconn; |
global $dbconn; |
| 610 |
check_db(); |
check_db(); |
| 611 |
$db = pg_connect($dbconn) ; |
$db = pg_pconnect($dbconn) ; |
| 612 |
$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"; |
| 613 |
print "\nDownloading bugs list =>"; |
print "\nDownloading bugs list =>"; |
| 614 |
$ferrors=file_get_contents($bugurl) or die_status ("I can't keep error page from bugs.debian.org"); |
$ferrors=file_get_contents($bugurl) or die_status ("I can't keep error page from bugs.debian.org"); |
| 844 |
"From: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" . |
"From: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" . |
| 845 |
"Reply-To: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" . |
"Reply-To: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" . |
| 846 |
"X-Mailer: PHP/" . phpversion()); |
"X-Mailer: PHP/" . phpversion()); |
| 847 |
|
} |
| 848 |
|
function update_new() { |
| 849 |
|
global $email_all; |
| 850 |
|
$intime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2); |
| 851 |
|
db_add('',false); |
| 852 |
|
dl_popcon(); |
| 853 |
|
db_popcon(); |
| 854 |
|
|
| 855 |
|
global $dbconn; |
| 856 |
|
check_db(); |
| 857 |
|
$db = pg_pconnect($dbconn); |
| 858 |
|
$sql="SELECT name FROM pkgs WHERE (md5_diff!=md5_atsource or md5_diff is null)"; |
| 859 |
|
$rsql=pg_exec($db, $sql); |
| 860 |
|
$res_array=pg_fetch_all($rsql); |
| 861 |
|
pg_close($db); |
| 862 |
|
|
| 863 |
|
dl_diffs(); |
| 864 |
|
db_up_error(); |
| 865 |
|
if ($res_array !== false) { |
| 866 |
|
foreach ($res_array as $entry) { |
| 867 |
|
db_upstream($entry['name']); |
| 868 |
|
up_changes($entry['name']); |
| 869 |
|
} |
| 870 |
|
dehsqa_db(); |
| 871 |
|
} |
| 872 |
|
$endtime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2); |
| 873 |
|
$messaggio="Dehs executed successful\nBegin: $intime\nPackages processed: ".((!is_array($res_array))?'none':count($res_array))."\nEnd: $endtime"; |
| 874 |
|
mail($email_all, "DEHS update_new report", $messaggio, |
| 875 |
|
"From: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" . |
| 876 |
|
"Reply-To: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" . |
| 877 |
|
"X-Mailer: PHP/" . phpversion()); |
| 878 |
} |
} |
| 879 |
function die_status($msg = '', $status = 1) { |
function die_status($msg = '', $status = 1) { |
| 880 |
if (empty($msg)) { |
if (empty($msg)) { |