aboutsummaryrefslogtreecommitdiff
blob: 861ba95a22bd693113913a39c4e9172dd373bbf0 (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
<?php
/**
 *  Regions.
 *  @package mirror
 *  @subpackage admin
 */
require_once('./cfg/init.php');
require_once(LIB.'/auth.php');  // auth functions
require_once(LIB.'/forms.php'); // form library
ob_start();

try{

if (!empty($_GET['os'])&&!empty($_GET['product'])) {
    // clean in os and product strings
    $os_name = trim(strtolower(filter_input(INPUT_GET,'os')));
    $product_name = trim(strtolower(filter_input(INPUT_GET,'product')));
    // get os and product IDs
    $os_id = DB::name_to_id('mirror_os','os_id','os_name',$os_name);
    $product_id = DB::name_to_id('mirror_products','product_id','product_name',$product_name);
}
if (!empty($_GET['os_id'])&&!empty($_GET['product_id'])) {
    $os_id = intval(filter_input(INPUT_GET, 'os_id', FILTER_SANITIZE_NUMBER_INT));
    $product_id = intval(filter_input(INPUT_GET, 'product_id', FILTER_SANITIZE_NUMBER_INT));
}

if (!empty($os_id)&&!empty($product_id)) {

    $mirrors = DB::get("
        SELECT DISTINCT
			mirror_baseurl, location_path
        FROM 
            mirror_mirrors 
        INNER JOIN
            mirror_location_mirror_map
        ON
            mirror_location_mirror_map.mirror_id = mirror_mirrors.mirror_id
        INNER JOIN
            mirror_locations
        ON
            mirror_location_mirror_map.location_id = mirror_locations.location_id
        WHERE
            mirror_locations.os_id = ? AND
            mirror_locations.product_id = ? AND
            mirror_location_mirror_map.location_active = '1' AND
            mirror_mirrors.mirror_active = '1'
		ORDER BY
			mirror_rating DESC, mirror_baseurl
        ", PDO::FETCH_ASSOC, null, [$os_id, $product_id]);

    header("Content-type: text/plain;");
    foreach ($mirrors as $mirror) {
		$b = $mirror['mirror_baseurl'];
		$l = $mirror['location_path'];
		if($l[0] == '/' && substr($b,-1) == '/') {
			$b = substr($b, 0, -1);
		}
        echo $b.$l."\n";
    }
    exit;

} else {

    $title = 'Mirror Listing';
    require_once(HEADER);
    echo '<h1>Mirror List</h1>';
    echo '<p>Use this form to get a list of all mirrors serving up active files
    for the selected Product/OS.</p>';
    form_start('list','list','get','./index-list.php');
    echo '<div>';
    form_label('Product', 'product','label-small');
    form_select('product_id','product','',Mirror::get_products_select(),$_GET['product_id']);
    echo ' [<a href="admin/products.php">edit products</a>]';
    echo '</div><br />';

    echo '<div>';
    form_label('OS', 'os','label-small');
    form_select('os_id','os','',Mirror::get_oss_select(),$_GET['os_id']);
    echo ' [<a href="admin/os.php">edit operating systems</a>]';
    echo '</div><br />';
    form_submit('submit','','button1','Update');
    form_end();
    require_once(FOOTER);
}

} catch (Exception $ex) {
	header("Status: 500", true, 500);
	echo "An unexpected error has occurred.";
	trigger_error($ex->getMessage() . ' ' . $ex->getTraceAsString(), E_USER_WARNING);
}