index : website | |
Archlinux32 website - obsolete | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | mirrorlist/index.php | 221 |
diff --git a/mirrorlist/index.php b/mirrorlist/index.php new file mode 100644 index 0000000..3feadf2 --- /dev/null +++ b/mirrorlist/index.php @@ -0,0 +1,221 @@ +<?php +require_once "../init.php"; + +include BASE . "/lib/mysql.php"; +include BASE . "/lib/style.php"; + +$filter = '1'; + //'`mirror_statuses`.`active`' . + //' AND `mirror_statuses`.`last_sync`>UNIX_TIMESTAMP(NOW())-7*24*60*60'; + +$result = mysql_run_query( + 'SELECT DISTINCT ' . + '`mirror_statuses`.`country_code`,' . + '`mirror_statuses`.`country`' . + ' FROM `mirror_statuses`' . + ' WHERE ' . $filter . + ' ORDER BY `mirror_statuses`.`country`' +); +$countries = array( + array( + 'country_code' => 'all', + 'country' => 'All' + ) +); +while ($row = $result -> fetch_assoc()) + $countries[] = $row; + +$result = mysql_run_query( + 'SELECT DISTINCT ' . + '`mirror_statuses`.`protocol`' . + ' FROM `mirror_statuses`' . + ' WHERE ' . $filter . + ' ORDER BY `mirror_statuses`.`protocol`' +); +$protocols = array( +); +while ($row = $result -> fetch_assoc()) + $protocols[] = $row['protocol']; + +$ip_versions = array('4', '6'); + +if (array_key_exists('country', $_GET)) { + + if (array_key_exists('use_mirror_status', $_GET)) + $order = '(`mirror_statuses`.`start`-`mirror_statuses`.`last_sync`) DESC'; + else + $order = + '`mirror_statuses`.`country`,' . + 'SUBSTRING(' . + '`mirror_statuses`.`url`,' . + '1+CHAR_LENGTH(`mirror_statuses`.`protocol`)' . + '),' . + '`mirror_statuses`.`protocol`'; + + $request = '&' . preg_replace(',^.*/\?,', '', $_SERVER['REQUEST_URI']) . '&'; + if (array_key_exists('protocol', $_GET)) { + $filter .= ' AND `mirror_statuses`.`protocol` IN ('; + foreach ($protocols as $protocol) + if (strpos($request, '&protocol=' . $protocol . '&') !== false) + $filter .= '"' . $protocol . '",'; + $filter .= '"")'; + } + + if (strpos($request, '&country=all&') === false) { + $filter .= ' AND `mirror_statuses`.`country_code` IN ('; + foreach ($countries as $country) + if (strpos($request, '&country=' . $country['country_code'] . '&') !== false) + $filter .= '"' . $country['country_code'] . '",'; + $filter .= '"")'; + } + + foreach ($ip_versions as $ip_version) + if (strpos($request, '&ip_version=' . $ip_version . '&') !== false) + $filter .= ' AND `mirror_statuses`.`ipv' . $ip_version . '`'; + + $result = mysql_run_query( + 'SELECT DISTINCT ' . + ' `mirror_statuses`.`country`,' . + ' `mirror_statuses`.`url`' . + ' FROM `mirror_statuses`' . + ' WHERE ' . $filter . + ' ORDER BY ' . $order + ); + while ($row = $result -> fetch_assoc()) + $mirrors[] = $row; + + header('Content-Type: text/plain'); + + print "##\n"; + print "## Arch Linux 32 repository mirrorlist\n"; + print "## Generated on " . date('Y-m-d') . "\n"; + print "##\n"; + + $last_country = 'Mordor'; + foreach ($mirrors as $mirror) { + if ($mirror['country'] != $last_country) { + print "\n"; + print "## " . $mirror['country'] . "\n"; + $last_country = $mirror['country']; + } + print "#Server = " . $mirror['url'] . '$arch/$repo/' . "\n"; + } + + die(); +} + +print_header('Pacman Mirrorlist Generator', 'home'); + +?> + <div id="mirrorlist-gen" class="box"> + <h2> + Pacman Mirrorlist Generator + </h2> + <p> + This page generates the most up-to-date mirrorlist possible for Arch Linux 32. + The data used here comes straight from the developers' internal mirror database used to track mirror availability and tiering. + There are two main options: + get a mirrorlist with every available mirror, or get a mirrorlist tailored to your geography. + </p> + <h3> + Mirrorlist with all available mirrors + </h3> + <p> + An up-to-date mirrorlist is available containing all currently active mirrors, optionally filtering by protocol. + These URLs requires no GET or POST parameters so they can be fetched from the command line if desired. + <p> + <ul> + <li><a href="?country=all">All mirrors</a></li> + <li><a href="?country=all&protocol=http">All mirrors, HTTP only</a></li> + <li><a href="?country=all&protocol=https">All mirrors, HTTPS only</a></li> + </ul> + <h3> + Customized by country mirrorlist + </h3> + <p> + The following form can generate a custom up-to-date + <a href="https://wiki.archlinux.org/index.php/Pacman" title="ArchWiki: Pacman">pacman</a> + mirrorlist based on geography and desired protocol(s). + Simply replace the contents of + <code>/etc/pacman.d/mirrorlist</code> + with your generated list. + Additionally, the mirror status data can be incorporated into the generated mirror list and used to only list up to date mirrors. + </p> + <form id="list-generator" method="get"> + <div> + <label for="id_country"> + Country: + </label> + <select name="country" size="12" id="id_country" multiple> +<?php + +foreach ($countries as $country) { + print " <option value=\"" . $country['country_code'] . "\""; + if ($country['country_code'] == 'all') + print " selected"; + print ">"; + print $country['country']; + print "</option>\n"; +} + +?> + </select> + </div> + <div> + <label> + Protocol: + </label> + <ul id="id_protocol"> +<?php + +$count = 0; +foreach ($protocols as $protocol) { + print " <li>\n"; + print " <label for=\"id_protocol_" . $count . "\">\n"; + print " <input type=\"checkbox\" name=\"protocol\" value=\"" . $protocol . "\" id=\"id_protocol_" . $count . "\" checked>\n"; + print " " . $protocol . "\n"; + print " </label>\n"; + print " </li>\n"; + $count ++; +} + +?> + </ul> + </div> + <div> + <label> + IP version: + </label> + <ul id="id_ip_version"> +<?php + +$count = 0; +foreach ($ip_versions as $ip_version) { + print " <li>\n"; + print " <label for=\"id_ip_version_" . $count . "\">\n"; + print " <input type=\"checkbox\" name=\"ip_version\" value=\"" . $ip_version . "\" id=\"id_ip_version_" . $count . "\" checked>\n"; + print " IPv" . $ip_version . "\n"; + print " </label>\n"; + print " </li>\n"; + $count ++; +} + +?> + </ul> + </div> + <div> + <label for="id_use_mirror_status"> + Use mirror status: + </label> + <input type="checkbox" name="use_mirror_status" id="id_use_mirror_status"> + </div> + <p> + <label> + </label> + <input type="submit" value="Generate List"> + </p> + </form> + </div> +<?php + +print_footer(); |