Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/mirrorlist.php
blob: d4ba6eafc7ee2d90aeac010f815b496949f2c55c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
require_once "init.php";

include BASE . "/lib/mysql.php";
include BASE . "/lib/style.php";

# as in mirrors.php (increased again, eliminated some legit mirrors!)
$cutoff = 7*24*60*60;

$filter =
  '`mirror_statuses`.`active`' .
  " AND `mirror_statuses`.`last_sync`>UNIX_TIMESTAMP(NOW())-$cutoff";

$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');

# archinstall sends no country, so we can not take this as a hint here whether
# we come via the form or not
if ( count($_GET) > 1 ) {

  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 || strpos($request, "&country=") === false ) {
    // country us all or doesn't exist (archinsetall) => do not filter by country
  } else {
    $filter .= ' AND `mirror_statuses`.`country_code` IN (';
    foreach ($countries as $country)
      if (strpos($request, '&country=' . $country['country_code'] . '&') !== false)
        $filter .= '"' . $country['country_code'] . '",';
    $filter .= '"")';
  }

  if (array_key_exists('ip_version', $_GET)) {
    $filter .= ' AND (0';
    foreach ($ip_versions as $ip_version)
      if (strpos($request, '&ip_version=' . $ip_version . '&') !== false)
        $filter .= ' OR `mirror_statuses`.`ipv' . $ip_version . '`';
    $filter .= ')';
  }

  $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();