index.php
author Ryan C. Gordon <icculus@icculus.org>
Sat, 27 May 2017 13:48:17 -0400
changeset 93 7f693fc30b66
permissions -rw-r--r--
PHP scripts that deal with new URL style.

Eventually we should dump index.php and just have the perl script do it. Laziness.
icculus@93
     1
<?php
icculus@93
     2
$arg = preg_replace('/\A\/finger\//', '', $_SERVER['REQUEST_URI']);
icculus@93
     3
$arg = 'user=' . preg_replace('/\?/', '&', $arg);
icculus@93
     4
icculus@93
     5
putenv("SERVER_NAME=${_SERVER['SERVER_NAME']}");
icculus@93
     6
putenv("QUERY_STRING=$arg");
icculus@93
     7
putenv("GATEWAY_INTERFACE=1");
icculus@93
     8
putenv("HTTP_USER_AGENT=${_SERVER['HTTP_USER_AGENT']}");
icculus@93
     9
putenv("ICCULUSFINGER_ALTURL=1");
icculus@93
    10
icculus@93
    11
$io = popen('/webspace/icculus.org/finger/finger.pl', 'r');
icculus@93
    12
if ($io === FALSE) {
icculus@93
    13
    header('HTTP/1.0 500 Internal Server Error');
icculus@93
    14
    header('Content-Type: text/plain; charset=UTF-8');
icculus@93
    15
    print("Internal server error, try again later, please!\n");
icculus@93
    16
    exit(0);
icculus@93
    17
}
icculus@93
    18
icculus@93
    19
while (($line = fgets($io)) !== FALSE) {
icculus@93
    20
    $line = preg_replace('/[\r\n]*\Z/', '', $line);
icculus@93
    21
    if ($line == '')
icculus@93
    22
        break;
icculus@93
    23
    header($line);
icculus@93
    24
}
icculus@93
    25
icculus@93
    26
fpassthru($io);
icculus@93
    27
icculus@93
    28
pclose($io);
icculus@93
    29
exit(0);
icculus@93
    30
icculus@93
    31
?>