dns: Reduce ttls
[sks-keyservers-pool.git] / sks-keyservers.net / status-srv / tor.php
blobbb8dafc9019f6b190aefb200e420972796ea7fb9
1 <?
2 /*
3 * status-srv/tor.php: The Onion Router balancing
4 * Copyright (C) 2015 Kristian Fiskerstrand
5 *
6 * This file is part of SKS Keyserver Pool (http://sks-keyservers.net)
7 *
8 * The Author can be reached by electronic mail at kf@sumptuouscapital.com
9 * Communication using OpenPGP is preferred - a copy of the public key 0x0B7F8B60E3EDFAE3
10 * is available in all the common keyservers or in hkp://pool.sks-keyservers.net
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 require("sks.inc.php");
27 require("sks-status.inc.php");
29 header("Content-type: text/plain");
30 $servers = unserialize(file_get_contents(dirname(__FILE__)."/sks_cache.serialized"));
31 $serverarr = $servers->get_servers();
33 $status_collection = unserialize(file_get_contents(dirname(__FILE__)."/sks_cache_status_collection.serialized"));
34 $servercolarr = $status_collection->get_servers();
36 sort($serverarr);
38 $array_of_all_online_servers = array();
39 $array_of_selected_servers = array();
41 // Server selection
42 foreach($serverarr as $server)
44 if(!(isset($servercolarr[$server->get_hostname()]['last_status']) && $servercolarr[$server->get_hostname()]['last_status']==1))
45 continue;
47 if(!$server->get_is_reverse_proxy())
48 continue;
50 if(!$server->get_tor_addresse())
51 continue;
53 $array_of_all_online_servers[] = array($server->get_hostname(), $server->get_tor_addresse());
56 // Select only 10 random servers
57 if(count($array_of_all_online_servers)>10)
59 $server_keys = array_rand($array_of_all_online_servers,10);
60 foreach($server_keys as $id)
62 $array_of_selected_servers[] = $array_of_all_online_servers[$id];
65 else
67 $array_of_selected_servers = $array_of_all_online_servers;
70 echo "# Auto-generated OnionBalance Config File\n";
71 echo "# Updated: ".(date("Y-m-d H:i"))." UTC\n";
72 echo "services:\n";
73 echo "- instances:\n";
75 foreach($array_of_selected_servers as $server)
77 $server_addr = substr($server[1], 0, strlen($server[1])-6);
79 echo " - address: {$server_addr}\n name: {$server[0]}\n";
81 echo " key: jirk5u4osbsr34t5.key\n";