From cb1c3303d3cbff37056c473238726e080827994d Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Fri, 13 Apr 2018 17:04:51 +0200 Subject: packages/pkginfo.php: WIP --- packages/pkginfo.php | 380 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 380 insertions(+) create mode 100644 packages/pkginfo.php diff --git a/packages/pkginfo.php b/packages/pkginfo.php new file mode 100644 index 0000000..3e57725 --- /dev/null +++ b/packages/pkginfo.php @@ -0,0 +1,380 @@ +\n" . $extra_message; + die(); + }; + + function die_500($message) { + throw_http_error(500, "Internal Server Error", $message); + }; + + $json_content = json_decode( + file_get_contents( + "https://pkgapi.arch32.tyzoid.com/package/".$_GET["repo"].":".$_GET["pkgname"] + ), + true + ); + + if (!isset($json_content["package"])) + throw_http_error(404, "Package Not Found In Sync Database"); + + $json_content = $json_content["package"]; + + $mysql = new mysqli("localhost", "webserver", "empty", "buildmaster"); + if ($mysql->connect_error) + die_500("Connection to database failed: " . $mysql->connect_error); + + if (! $mysql_result = $mysql -> query( + "SELECT DISTINCT " . + "`binary_packages`.`id`," . + "`binary_packages`.`pkgname`," . + "`package_sources`.`pkgbase`," . + "CONCAT(" . + "IF(`binary_packages`.`epoch`=\"0\",\"\",CONCAT(`binary_packages`.`epoch`,\":\"))," . + "`binary_packages`.`pkgver`,\"-\"," . + "`binary_packages`.`pkgrel`,\".\"," . + "`binary_packages`.`sub_pkgrel`" . + ") AS `version`," . + "`repositories`.`stability` AS `repo_stability`," . + "`repositories`.`name` AS `repo`," . + "`architectures`.`name` AS `arch`" . + " FROM `binary_packages`" . + " JOIN `architectures` ON `binary_packages`.`architecture`=`architectures`.`id`" . + " JOIN `repositories` ON `binary_packages`.`repository`=`repositories`.`id`" . + " JOIN `build_assignments` ON `binary_packages`.`build_assignment`=`build_assignments`.`id`" . + " JOIN `package_sources` ON `build_assignments`.`package_source`=`package_sources`.`id`" . + " WHERE `binary_packages`.`pkgname`=from_base64(\"" . base64_encode($_GET["pkgname"]) . "\")" . + " AND `architectures`.`name`=from_base64(\"" . base64_encode($_GET["arch"]) . "\")" . + " AND `repositories`.`name`=from_base64(\"" . base64_encode($_GET["repo"]) . "\")" + )) + die_500("Query failed: " . $mysql->error); + + if ($mysql_result -> num_rows != 1) + throw_http_error(404, "Package Not Found In Buildmaster's Database"); + + $mysql_content = $mysql_result -> fetch_assoc(); + + $same_keys = array ( + array("mysql" => "pkgname", "json" => "Name"), + array("mysql" => "version", "json" => "Version"), + array("mysql" => "repo", "json" => "Repository"), + array("mysql" => "arch", "json" => "Architecture") + ); + + foreach ($same_keys as $same_key) + if ($mysql_content[$same_key["mysql"]] != $json_content[$same_key["json"]]) + die_500("Inconsistency in Database found:
\n" . + "buildmaster[" . $same_key["mysql"] . "] != repositories[" . $same_key["json"] . "]:
\n" . + "\"" . $mysql_content[$same_key["mysql"]] . "\" != \"" . $json_content[$same_key["json"]] . "\""); + + // query _all_ dependencies + + if (! $mysql_result = $mysql -> query( + "SELECT DISTINCT " . + "`dependency_types`.`name` AS `dependency_type`," . + "GROUP_CONCAT(" . + "CONCAT(\"[\",`install_target_providers`.`id`,\"]: \",\"{\\n\"," . + "\" \\\"repo\\\": \\\"\",`repositories`.`name`,\"\\\",\\n\"," . + "\" \\\"arch\\\": \\\"\",`architectures`.`name`,\"\\\",\\n\"," . + "\" \\\"pkgname\\\": \\\"\",`binary_packages`.`pkgname`,\"\\\"\\n\"," . + "\"}\"" . + ")) AS `deps`," . + "`install_targets`.`name` AS `install_target`" . + " FROM `dependencies`" . + " JOIN `dependency_types` ON `dependency_types`.`id`=`dependencies`.`dependency_type`" . + " JOIN `install_targets` ON `install_targets`.`id`=`dependencies`.`depending_on`" . + " AND `install_targets`.`name` NOT IN (\"base\",\"base-devel\")" . + " LEFT JOIN (" . + "`install_target_providers`" . + " JOIN `binary_packages` ON `install_target_providers`.`package`=`binary_packages`.`id`" . + " JOIN `architectures` ON `binary_packages`.`architecture`=`architectures`.`id`" . + " JOIN `repositories` ON `binary_packages`.`repository`=`repositories`.`id`" . + " JOIN `repository_stability_relations` ON `repository_stability_relations`.`more_stable`=`repositories`.`stability`" . + " AND `repository_stability_relations`.`less_stable`=" . $mysql_content["repo_stability"] . + ") ON `install_target_providers`.`install_target`=`dependencies`.`depending_on`" . + " WHERE `dependencies`.`dependent`=" . $mysql_content["id"] . + " GROUP BY `install_targets`.`id`" + )) + die_500("Query failed: " . $mysql->error); + + $dependencies = array(); + while ($row = $mysql_result -> fetch_assoc()) + $dependencies[] = $row; + + function dependency_is_runtime($dep) { + return $dep["dependency_type"]=="run"; + }; + + function dependency_extract_name($dep) { + return $dep["install_target"]; + }; + + $dep_it = array_map("dependency_extract_name", array_filter( $dependencies, "dependency_is_runtime")); + $dep_errors = implode( + ", ", + array_diff( + array_merge($dep_it,$json_content["Depends On"]), + array_intersect($dep_it,$json_content["Depends On"]) + ) + ); + +// if ($dep_errors != "") +// die_500("Dependencies differ: " . $dep_errors); + + // query dependent packages + + if (! $mysql_result = $mysql -> query( + "SELECT " . + "`dependency_types`.`name` AS `dependency_type`," . + "`repositories`.`name` AS `repos`," . + "`architectures`.`name` AS `archs`," . + "`binary_packages`.`pkgname` AS `pkgnames`" . + " FROM `install_target_providers`" . + " JOIN `install_targets` ON `install_targets`.`id`=`install_target_providers`.`install_target`" . + " JOIN `dependencies` ON `install_target_providers`.`install_target`=`dependencies`.`depending_on`" . + " JOIN `dependency_types` ON `dependency_types`.`id`=`dependencies`.`dependency_type`" . + " JOIN `binary_packages` ON `dependencies`.`dependent`=`binary_packages`.`id`" . + " JOIN `architectures` ON `binary_packages`.`architecture`=`architectures`.`id`" . + " JOIN `repositories` ON `binary_packages`.`repository`=`repositories`.`id`" . + " JOIN `repository_stability_relations` ON `repository_stability_relations`.`less_stable`=`repositories`.`stability`" . + " AND `repository_stability_relations`.`more_stable`=" . $mysql_content["repo_stability"] . + " WHERE `install_target_providers`.`package`=" . $mysql_content["id"] . + " GROUP BY `install_targets`.`id`" + )) + die_500("Query failed: " . $mysql->error); + + $dependent = array(); + while ($row = $mysql_result -> fetch_assoc()) + $dependent[] = $row; + + $content = array_merge($mysql_content,$json_content); + +?> + + + + + + Arch Linux 32 - <?php print $content["Name"] . " " . $content["Version"] . " (" . $content["Architecture"]; ?>) + + + + + + +
+ + +
+
+
+ +
+ + + +
+

+ + + +
+ "/> + "/> + "/> + "/> + "/> + "/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Architecture:" + title="Browse packages for architecture">
Repository:" + title="Browse the repository">
Description:
Upstream URL:
License(s):
Package Size:
Installed Size:
Build Date:
+
+ +
+ +
+

has the following dependencies"> + Dependencies ()

+
    +\n"; + var_dump($dep["deps"]); +// var_dump(json_decode($dep["dep"],true)); + continue; + if (isset($dep["pkgname"])) { + if ($dep["pkgname"]!=$dep["install_target"]) { + print $dep["install_target"]; + print " ("; + } + print "".$dep["pkgname"].""; + if ($dep["pkgname"]!=$dep["install_target"]) + print ")"; + print "\n"; + } else { + print "not satisfiable dependency: \"" . $dep["install_target"] . "\"\n"; + } + if ($dep["dependency_type"]=="make") + print " (make)\n"; + print "\n"; + } + die(); +?> + +
+
+ + +
+

+ Required By (0)

+ +
+ +
+

+ Package Contents

+ +
+
+
+ + + +
+ + + + -- cgit v1.2.3-70-g09d2