PHP scripts that deal with new URL style. default tip
authorRyan C. Gordon <icculus@icculus.org>
Sat, 27 May 2017 13:48:17 -0400
changeset 93 7f693fc30b66
parent 92 326264bec634
PHP scripts that deal with new URL style.

Eventually we should dump index.php and just have the perl script do it. Laziness.
index.php
old-finger-url-redirect.php
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/index.php	Sat May 27 13:48:17 2017 -0400
@@ -0,0 +1,31 @@
+<?php
+$arg = preg_replace('/\A\/finger\//', '', $_SERVER['REQUEST_URI']);
+$arg = 'user=' . preg_replace('/\?/', '&', $arg);
+
+putenv("SERVER_NAME=${_SERVER['SERVER_NAME']}");
+putenv("QUERY_STRING=$arg");
+putenv("GATEWAY_INTERFACE=1");
+putenv("HTTP_USER_AGENT=${_SERVER['HTTP_USER_AGENT']}");
+putenv("ICCULUSFINGER_ALTURL=1");
+
+$io = popen('/webspace/icculus.org/finger/finger.pl', 'r');
+if ($io === FALSE) {
+    header('HTTP/1.0 500 Internal Server Error');
+    header('Content-Type: text/plain; charset=UTF-8');
+    print("Internal server error, try again later, please!\n");
+    exit(0);
+}
+
+while (($line = fgets($io)) !== FALSE) {
+    $line = preg_replace('/[\r\n]*\Z/', '', $line);
+    if ($line == '')
+        break;
+    header($line);
+}
+
+fpassthru($io);
+
+pclose($io);
+exit(0);
+
+?>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/old-finger-url-redirect.php	Sat May 27 13:48:17 2017 -0400
@@ -0,0 +1,21 @@
+<?php
+$vhost = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'icculus.org';
+$user = isset($_REQUEST['user']) ? $_REQUEST['user'] : '';
+
+$args = '';
+if (isset($_REQUEST) && (count($_REQUEST) > 0)) {
+    $ch = '?';
+    foreach ($_REQUEST as $key => $val) {
+        if ($key == 'user') {
+            continue;
+        }
+        $args .= "$ch$key=$val";
+        $ch = '&';
+    }
+}
+
+$url = "https://$vhost/finger/$user$args";
+header("Location: $url", true, 301);
+print("<html><head><title>Moved Permanently</title></head><body><center>\nThis URL has moved to <a href='$url'>\n\n$url\n\n</a></center></body></html>\n");
+exit(0);
+?>