| 64 |
#stat_up_error(); |
#stat_up_error(); |
| 65 |
function dir_ctrl($dirs) { |
function dir_ctrl($dirs) { |
| 66 |
foreach ($dirs as $dir) { |
foreach ($dirs as $dir) { |
| 67 |
if (!is_dir($dir)) exec("mkdir -m 755 -p $dir") or die('Error creating basic dirs\n'); |
if (!is_dir($dir)) exec("mkdir -m 0740 -p $dir",$output,$res); |
| 68 |
|
if ($res!=0) die("Error creating basic dir: $dir\n"); |
| 69 |
} |
} |
| 70 |
} |
} |
| 71 |
function ext_watch ($file,$pkg,$version){ |
function ext_watch ($file,$pkg,$version){ |
| 162 |
$filename=$dirs[sources_dir] . "/$dist/$section/Sources.gz"; |
$filename=$dirs[sources_dir] . "/$dist/$section/Sources.gz"; |
| 163 |
print "\nI'm parsing $dist/$section => Sources.gz\n"; |
print "\nI'm parsing $dist/$section => Sources.gz\n"; |
| 164 |
# 1 Pacchetto - 2 versione - 3 np - 4 Directory - 5 md5 |
# 1 Pacchetto - 2 versione - 3 np - 4 Directory - 5 md5 |
| 165 |
$regexp="/Package:\s($initial.*)[^a]Binary:\s(.+)[^a]Version:\s(\d+:)?(.+)[^a]Priority.+Maintainer:.+<([^>]+)>[^a].+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+)\s(\d+)\s" . '\1\S+' . "\.diff\.gz[^a](Uploaders:\s(.+)[^a])?/Ssi"; |
| 166 |
$zp = gzopen($filename, "r") or die("Could not open $filename"); |
$zp = gzopen($filename, "r") or die("Could not open $filename"); |
| 167 |
$extracted="/tmp/$dist_$section_Sources.gz"; |
$extracted="/tmp/$dist_$section_Sources.gz"; |
| 168 |
exec("gzip -c -d $filename > $extracted"); |
exec("gzip -c -d $filename > $extracted"); |
| 169 |
$sourcesize=filesize($extracted); |
$sourcesize=filesize($extracted); |
| 170 |
|
unlink($extracted); |
| 171 |
if(filesize($filename)>20) { |
if(filesize($filename)>20) { |
| 172 |
while (!gzeof($zp)) { |
while (!gzeof($zp)) { |
| 173 |
$line=''; |
$line=''; |
| 176 |
$buff1 .= $line; |
$buff1 .= $line; |
| 177 |
} |
} |
| 178 |
if (preg_match($regexp,$buff1,$matches)) { |
if (preg_match($regexp,$buff1,$matches)) { |
| 179 |
# print("Pacchetto => $matches[1]\nVersione => $matches[4]\nDirectory => $matches[5]\nMD5 => $matches[6]\n"); |
if ($matches[10]) { |
| 180 |
# print "REPLACE INTO pkgs (name,version,dir,md5_diff) VALUES ($matches[1],$matches[3],$matches[4],$matches[5])"; |
$matches[10]=iconv("ISO-8859-1","UTF-8",$matches[10]); |
| 181 |
|
$matches[10]=addslashes($matches[10]); |
| 182 |
|
} |
| 183 |
@pg_exec($db,"INSERT INTO pkgs_atsrc (name,dist) VALUES ('$matches[1]','$dist')") OR DIE("Temp table pkgs_atsrc query error"); |
@pg_exec($db,"INSERT INTO pkgs_atsrc (name,dist) VALUES ('$matches[1]','$dist')") OR DIE("Temp table pkgs_atsrc query error"); |
| 184 |
$rst=@pg_exec($db, "INSERT INTO pkgs (name,version,maint,dir,md5_atsource,bytes,dist,section) VALUES ('$matches[1]','$matches[4]','$matches[5]','$matches[6]','$matches[7]','$matches[8]','$dist','$section')") ; |
$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]')") ; |
| 185 |
if (!$rst) { |
if (!$rst) { |
| 186 |
$rst=@pg_exec($db, "UPDATE pkgs SET name='$matches[1]',version='$matches[4]',maint='$matches[5]',dir='$matches[6]',md5_atsource='$matches[7]',bytes='$matches[8]',dist='$dist',section='$section' WHERE name='$matches[1]' AND dist='$dist'") OR DIE ("\nDb adding error =>" . pg_errormessage() . "\n"); |
$rst=@pg_exec($db, "UPDATE pkgs SET name='$matches[1]',version='$matches[4]',maint='$matches[5]',dir='$matches[6]',md5_atsource='$matches[7]',bytes='$matches[8]',dist='$dist',section='$section',uploaders='$matches[10]' WHERE name='$matches[1]' AND dist='$dist'") OR DIE ("\nDb adding error =>" . pg_errormessage() . "\n"); |
| 187 |
# if ($rst) print "\rUpdated $matches[1]" ." "; |
} |
|
} |
|
| 188 |
$bin_names=split(",", $matches[2]); |
$bin_names=split(",", $matches[2]); |
| 189 |
foreach ($bin_names as $bin_name) { |
foreach ($bin_names as $bin_name) { |
| 190 |
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"); |
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"); |
| 191 |
$rst=@pg_exec($db, "INSERT INTO binpkgs (name,bin_name,dist) VALUES ('$matches[1]','" . trim($bin_name) . "','$dist')") ; |
$rst=@pg_exec($db, "INSERT INTO binpkgs (name,bin_name,dist) VALUES ('$matches[1]','" . trim($bin_name) . "','$dist')") ; |
|
# if (!$rst) { |
|
|
# $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 "; |
|
|
# } |
|
| 192 |
} |
} |
| 193 |
} |
} |
| 194 |
else { |
else { |
| 195 |
preg_match("/Package:\s(.+)[^a]Binary/im",$buff1,$matches); |
preg_match("/Package:\s(.+)[^a]Binary/im",$buff1,$matches); |
|
#print $matches[1] . "- " . strncmp($initial,$matches[1],strlen($initial)) . "\n"; |
|
| 196 |
if(strncmp($initial,$matches[1],strlen($initial))<0) break; |
if(strncmp($initial,$matches[1],strlen($initial))<0) break; |
| 197 |
} |
} |
| 198 |
$left=$sourcesize-gztell($zp); |
$left=$sourcesize-gztell($zp); |
| 199 |
print "\rSource file Left => $left"; |
print "\rSource file Left => $left"; |
| 200 |
$buff1=""; |
$buff1=""; |
| 201 |
unset($matches); |
unset($matches); |
|
# unset($matches); |
|
|
# if (strcmp($init,substr($matches[1],0,strlen($init)))<=0) break; |
|
| 202 |
} |
} |
| 203 |
} |
} |
| 204 |
gzclose($zp) ; |
gzclose($zp) ; |
| 249 |
$localfile=$dirs[sources_dir] . "/$dist/$section/Sources.gz"; |
$localfile=$dirs[sources_dir] . "/$dist/$section/Sources.gz"; |
| 250 |
$remotefile=remote_dist_dir($dist) . "/$dist/$section/source/Sources.gz"; |
$remotefile=remote_dist_dir($dist) . "/$dist/$section/source/Sources.gz"; |
| 251 |
$sources_info=md5_source($section,$dist); |
$sources_info=md5_source($section,$dist); |
| 252 |
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); |
| 253 |
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); |
| 254 |
if (!file_exists($localfile) OR md5_of_file($localfile)!=$sources_info[md5]) { |
if (!file_exists($localfile) OR md5_of_file($localfile)!=$sources_info[md5]) { |
| 255 |
|
print "Downloading $remotefile Bytes $sources_info[bytes]=> "; |
| 256 |
print "Downloading $remotefile Bytes $sources_info[bytes]=> "; |
if (ftp_get($conn_id,$localfile,$remotefile,FTP_BINARY)) { |
| 257 |
if (ftp_get($conn_id,$localfile,$remotefile,FTP_BINARY)) { |
print "Done\n"; |
| 258 |
print "Done\n"; |
if(md5_of_file($localfile)==$sources_info[md5]) print "MD5 => OK\n"; |
| 259 |
if(md5_of_file($localfile)==$sources_info[md5]) print "MD5 => OK\n"; |
} |
| 260 |
} |
else { |
| 261 |
else { |
unlink("$localfile"); |
| 262 |
unlink("$localfile"); |
print "Fail\n"; |
| 263 |
print "Fail\n"; |
die ("Error in source file"); |
| 264 |
die ("Error in source file"); |
} |
| 265 |
} |
} |
|
} |
|
| 266 |
} |
} |
| 267 |
|
ftp_quit($conn_id); |
| 268 |
} |
} |
|
ftp_quit($conn_id); |
|
| 269 |
} |
} |
| 270 |
function md5_source($section,$dist) { |
function md5_source($section,$dist) { |
| 271 |
global $mirrors; |
global $mirrors; |
| 283 |
global $dirs,$dbconn; |
global $dirs,$dbconn; |
| 284 |
$db = @pg_connect($dbconn) or die(pg_last_notice()); |
$db = @pg_connect($dbconn) or die(pg_last_notice()); |
| 285 |
if (!pg_table_exists($db,"pkgs")){ |
if (!pg_table_exists($db,"pkgs")){ |
| 286 |
pg_exec($db, "CREATE TABLE pkgs (id serial PRIMARY KEY,name text,version text,maint 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('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('Error creating table pkgs\n'); |
| 287 |
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('Errore creating index - ' . pg_last_error($db)); |
| 288 |
$sw=true; |
$sw=true; |
| 289 |
} |
} |
| 324 |
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"; |
| 325 |
} |
} |
| 326 |
function remote_dist_dir($dist) { |
function remote_dist_dir($dist) { |
| 327 |
if ($dist=="non-US") return "/debian-non-US/dists/unstable/"; |
if ($dist=="non-US") return "/debian-non-US/dists/unstable"; |
| 328 |
else return "/debian/dists"; |
else return "/debian/dists"; |
| 329 |
} |
} |
| 330 |
function clear_db(&$db) { |
function clear_db(&$db) { |
| 412 |
global $dirs,$dbconn; |
global $dirs,$dbconn; |
| 413 |
check_db(); |
check_db(); |
| 414 |
$db = pg_connect($dbconn) ; |
$db = pg_connect($dbconn) ; |
| 415 |
$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"); |
$rsql=pg_exec($db, "SELECT pkgs.name,pkgs.dist,up_version,version,watch FROM pkgs WHERE watch is not null AND name LIKE '$initial%' ORDER BY name DESC"); |
| 416 |
$tot=pg_numrows($rsql); |
$tot=pg_numrows($rsql); |
| 417 |
while ($res_array=pg_fetch_array($rsql)) { |
while ($res_array=pg_fetch_array($rsql)) { |
| 418 |
$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']); |
| 437 |
print "\n"; |
print "\n"; |
| 438 |
pg_close($db); |
pg_close($db); |
| 439 |
} |
} |
| 440 |
|
function check_url ($url) { |
| 441 |
|
$url_p = parse_url ($url); |
| 442 |
|
if (isset ($url_p["host"])) $host = $url_p["host"]; |
| 443 |
|
else return false; |
| 444 |
|
preg_match("/(http|ftp)/",$host,$matches); |
| 445 |
|
if ($matches[1]=='http') $fp = fsockopen ($host, 80, $errno, $errstr, 10); |
| 446 |
|
elseif ($matches[1]=='ftp') $fp2 = fsockopen ($host, 21, $errno, $errstr, 10); |
| 447 |
|
if (!$fp AND !$fp2) return false; |
| 448 |
|
else return true; |
| 449 |
|
} |
| 450 |
function keep_remote ($localfile,$remotefile) { |
function keep_remote ($localfile,$remotefile) { |
| 451 |
# $url_p = parse_url ($remotefile); |
#if (!check_url($remotefile)) return false; |
|
# if (isset ($url_p["host"])) |
|
|
# { $host = $url_p["host"]; } |
|
|
# else return false; |
|
|
# preg_match("/(http|ftp)/",$host,$matches); |
|
|
# if ($matches[1]=='http') $fp = fsockopen ($host, 80, $errno, $errstr, 10); |
|
|
# elseif ($matches[1]=='ftp') $fp2 = fsockopen ($host, 21, $errno, $errstr, 10); |
|
|
# if (!$fp AND !$fp2) return false; |
|
| 452 |
$rfp = @fopen ($remotefile, "rb"); |
$rfp = @fopen ($remotefile, "rb"); |
| 453 |
if (!$rfp) { |
if (!$rfp) { |
| 454 |
return false; |
return false; |
| 457 |
ini_set ( "memory_limit", "100M"); |
ini_set ( "memory_limit", "100M"); |
| 458 |
while ($data = fread($rfp, 1024*8)) { |
while ($data = fread($rfp, 1024*8)) { |
| 459 |
$bytes+=1024*8; |
$bytes+=1024*8; |
| 460 |
print "Downlaoding $remotefile: $bytes\r"; |
#print "Downlaoding $remotefile: $bytes\r"; |
| 461 |
fwrite($lfp, $data); |
fwrite($lfp, $data); |
| 462 |
} |
} |
| 463 |
ini_set ( "memory_limit", "15M"); |
ini_set ( "memory_limit", "15M"); |
| 595 |
} |
} |
| 596 |
if (!$res) { |
if (!$res) { |
| 597 |
$notmatch++; |
$notmatch++; |
| 598 |
pg_exec($db, "UPDATE pkgs SET wwiz='" . addslashes($contents) . "', wwiz_type='notmatch', up_url='', up_changes='' where name='" . $res_array[name] . "' AND dist='" . $res_array[dist] ."'"); |
pg_exec($db, "UPDATE pkgs SET wwiz='" . addslashes($contents) . "', wwiz_type='notmatch', up_url='', up_changes='',keep_changes='f' where name='" . $res_array[name] . "' AND dist='" . $res_array[dist] ."'"); |
| 599 |
} |
} |
| 600 |
else { |
else { |
| 601 |
$watch="version=2\n" . |
$watch="version=2\n" . |
| 602 |
$matches[1] . $space . $res_array["name"] . "-([\d+\.]+|\d+)\.tar(\.gz|\.bz2) debian uupdate"; |
$matches[1] . $space . $res_array["name"] . "-([\d+\.]+|\d+)(\.tar|\.tgz)(\.gz|\.bz2|) debian uupdate"; |
| 603 |
$uscan_res=uscan_foo($res_array['name'] ,$res_array['version'],$watch); |
$uscan_res=uscan_foo($res_array['name'] ,$res_array['version'],$watch); |
| 604 |
if ($uscan_res[1] AND !$uscan_res[0]) { |
if ($uscan_res[1] AND !$uscan_res[0]) { |
| 605 |
pg_exec($db, "UPDATE pkgs SET wwiz='" . addslashes($uscan_res[1]) . "', wwiz_type='error', up_url='', up_changes='' where name='" . $res_array[name] . "' AND dist='" . $res_array[dist] ."'"); |
pg_exec($db, "UPDATE pkgs SET wwiz='" . addslashes($uscan_res[1]) . "', wwiz_type='error', up_url='', up_changes='', keep_changes='f' where name='" . $res_array[name] . "' AND dist='" . $res_array[dist] ."'"); |
| 606 |
$errors++; |
$errors++; |
| 607 |
} |
} |
| 608 |
else { |
else { |