commit 0461b1037736d5272eb72356d53c2db198a4a9aa
parent 079e0b5b2ba5141b35e0d937901e6c73b597b5f4
Author: Nixx <nixx@firemail.cc>
Date: Thu, 27 May 2021 19:02:42 +0100
Vast simplification, as we don't need all that much
Diffstat:
M | README | | | 25 | +------------------------ |
M | webring.php | | | 57 | ++++++++------------------------------------------------- |
2 files changed, 9 insertions(+), 73 deletions(-)
diff --git a/README b/README
@@ -1,39 +1,16 @@
# CODE FOR THE LAINCHAN.ORG UNOFFICIAL WEBRING
## URL Documentation:
-- Go to next site with webring.php?go=next
-- Go to previous site with webring.php?go=prev
-- Go to random site with webring.php?go=random
- Use the clearnet webring with webring.php?route=clearnet
- Use the onion webring with webring.php?route=onion
-For example, to go to a random site on the onion webring:
-'webring.php?go=random&route=onion'
-
This could quite easily accomodate more networks, such as I2P, but
currently I don't see a strong enough need.
-Defaults: random, clearnet
+Defaults: clearnet
## File Documentation:
- 'webring.php' is the script file itself
- 'webring.txt' holds all of the clearnet domains
- 'webring_onion.txt' holds all of the onion domains
-- 'webring_domain.conf' sets your clearnet domain{1}
-- 'webring_onion_domain.conf' sets your onion domain{1}
-
-{1} These files are optional, PHP can read your HTTP host automatically.
-
- You may consider setting it if for example, you want to peform 'prev'
- and 'next' on the onion webring relative to your onion site, from
- within your clearnet site.
-
- You **MUST** set this file if the link to your site is not the web
- root - e.g. exampletilde.org/~user/.
-
- As shown above, include the domain, path, and ending slash, but
- exclude the protocol. Nothing else should be in the file.
-
-If your site isn't listed in webring.txt/webring_onion.txt, then the
-'prev' and 'next' operations will not be possible.
diff --git a/webring.php b/webring.php
@@ -15,70 +15,29 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-// Default to 'random' if unset
-$go = isset($_GET['go']) ? strtolower($_GET['go']) : 'random';
-// Check we're using 'prev', 'next', or 'random' - if not, die
-$valid_go = array('prev', 'next', 'random');
-if(!in_array($go, $valid_go)) die('ERROR(1): Invalid operation \''.$go.'\'.');
-
-// Get domain from file if file exists, otherwise use $_SERVER
-// Setting the domain in a file also allows you to use 'prev' or 'next' relative to a mirror of your site, without being on that mirror
-$domainclearconf = 'webring_domain.conf';
-$domainclear = file_exists($domainclearconf) ? trim(file_get_contents($domainclearconf)) : $_SERVER['HTTP_HOST'];
-if(empty($domainclear)) die('ERROR(2): File \''.$domainclearconf.'\' exists but is empty - either write to or remove it.');
-// Again, for Tor
-$domainonionconf = 'webring_onion_domain.conf';
-$domainonion = file_exists($domainonionconf) ? trim(file_get_contents($domainonionconf)) : $_SERVER['HTTP_HOST'];
-if(empty($domainonion)) die('ERROR(2): File \''.$domainonionconf.'\' exists but is empty - either write to or remove it.');
-
// Use separate files for clearnet and onion sites - this could be extended further to other networks
$route = isset($_GET['route']) ? strtolower($_GET['route']) : 'clearnet';
$valid_route = array('clearnet', 'onion');
-if(!in_array($route, $valid_route)) die('ERROR(3): Invalid network \''.$route.'\'.');
+if(!in_array($route, $valid_route)) die('ERROR(1): Invalid network \''.$route.'\'.');
+// Use the appropriate file for the network
if($route == 'clearnet'){
$file = 'webring.txt';
- $domain = $domainclear;
}elseif($route == 'onion'){
$file = 'webring_onion.txt';
- $domain = $domainonion;
}else{
- die('ERROR(4): Something went wrong while reading the network \''.$route.'\'.');
+ die('ERROR(2): Something went wrong while reading the network \''.$route.'\'.');
}
+
// If file doesn't exist, die
-if(!file_exists($file)) die('ERROR(5): File \''.$file.'\' not found.');
+if(!file_exists($file)) die('ERROR(3): File \''.$file.'\' not found.');
// The 'file' function reads an array from a file, separated by newlines
$list = file($file);
-
-// Get the position of the first occurence of our domain name
-// Rather than use a function such as array_search(), the loop is necessary to trim each item from the text file
+// Find the length
$length = count($list);
-for($i = 0; $i < $length; $i++){
- if(strcmp($domain, trim($list[$i])) == 0){
- $position = $i;
- break;
- }
-}
-// If not found, die
-if(!isset($position) && $go != 'random') die('ERROR(6): Domain \''.$domain.'\' not found in file \''.$file.'\' - only the \'random\' operation is available.');
-if($go == 'prev'){
- $redirkey = $position - 1;
- // If we're in the first position, loop around to the last position
- if($redirkey < 0) $redirkey = $length - 1;
-}elseif($go == 'next'){
- $redirkey = $position + 1;
- // If we're in the last position, loop around to the first position
- if($redirkey > $length - 1) $redirkey = 0;
-}elseif($go == 'random'){
- // Loop to ensure we don't redirect to ourselves
- // WARNING: This could loop forever if there is only one item in $list
- do{
- $redirkey = rand(0, $length - 1);
- }while($redirkey == $position);
-}else{
- die('ERROR(7): Something went wrong while reading the operation \''.$go.'\'.');
-}
+// Get a random position
+$redirkey = rand(0, $length - 1);
// Finally, do the redirect - presumes HTTP will redirect to HTTPS where applicable
header('Location: http://'.$list[$redirkey]);