Last active
May 10, 2017 06:29
-
-
Save dergachev/3cefbb6a82c68d2406fdfd779c7a8dea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] | |
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./js/ | |
./js/stopExecutionOnTimeout.js | |
./js/jquery.quovolver.js | |
./js/hello.html | |
./js/jquery.quovolver | |
./qss/ | |
./qss/index.html | |
./rss/ | |
./rss/sample.xml | |
./TOCs/ | |
./TOCs/c10140.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./js/ | |
./js/stopExecutionOnTimeout.js | |
./js/jquery.quovolver.js | |
./js/hello.html | |
./js/jquery.quovolver | |
./qss/ | |
./qss/index.html | |
./rss/ | |
./rss/sample.xml | |
./rss/BIO.xml | |
./rss/BIR.xml | |
./tex/ | |
./tex/index.html | |
./tex/Manual.pdf | |
./wol/ | |
./wol/html.php | |
./wol/lib.php | |
./wol/test.php | |
./wol/index.php | |
./wol/DEADJOE | |
./wol/wml.php | |
./wmicon.gif | |
./TOCs/ | |
./TOCs/c3126.html | |
./TOCs/c5303.html | |
./TOCs/c9913.html | |
./TOCs/c4097.html | |
./TOCs/c6274.html | |
./TOCs/c8451.html | |
./TOCs/c7235.html | |
./TOCs/c1509.html | |
./TOCs/c6019.html | |
./TOCs/c4902.html | |
./TOCs/c537.html | |
./TOCs/c1263.html | |
./TOCs/c5873.html | |
./TOCs/c1008.html | |
./TOCs/c5618.html | |
./TOCs/c10140.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
enforce_httpauth_user_pass('SECRET_USERNAME', 'SECRET_PASSWORD'); | |
$search_for = $_GET['q']; | |
$file = $_GET['filter'] == 1 ? 'files-filtered.txt' : 'files.txt'; | |
$domain = $_GET['domain'] ? $_GET['domain'] : 'http://press.princeton.edu'; | |
// optimized for blank queries | |
if(!$search_for) { | |
// the following line prevents the browser from parsing this as HTML, debug. | |
header('Content-Type: text/plain'); | |
readfile($file); | |
} | |
$matches = get_matching_string($file, $search_for); | |
print_array_as_links($matches, $domain); | |
/** | |
* Strips off leading "/" or "./". | |
**/ | |
function strip_leading_prefixes($line, $prefixes) { | |
foreach($prefixes as $prefix) { | |
if (strpos($line, $prefix) === 0) { | |
$line = substr($line, strlen($prefix)); | |
} | |
} | |
return $line; | |
} | |
/** | |
* Opens $file, returns an array of strings that start with $beginning. | |
**/ | |
function get_matching_string($file, $beginning) { | |
$matches = array(); | |
$fh = fopen($file, 'r') or die($php_errormsg); | |
while (!feof($fh)) { | |
$line = fgets($fh); | |
$line = trim($line); | |
$line = strip_leading_prefixes($line, array("/", "./")); | |
if (strpos($line, $beginning) === 0) { | |
$matches[] = trim($line); | |
} | |
} | |
fclose($fh); | |
return $matches; | |
} | |
/** | |
* Prints $matches wrapped in HTML <a> tags pointing to $domain. | |
**/ | |
function print_array_as_links($matches, $domain) { | |
foreach($matches as $match) { | |
print "<a href='$domain/$match'>$match</a><br />\n"; | |
} | |
} | |
function enforce_httpauth_user_pass($auth_user, $auth_password) { | |
if (!isset($_SERVER['PHP_AUTH_USER']) | |
|| $_SERVER['PHP_AUTH_USER'] != $auth_user | |
|| $_SERVER['PHP_AUTH_PW'] != $auth_password | |
){ | |
header("WWW-Authenticate: Basic realm=\"Secure Realm\""); | |
header("HTTP/1.0 401 Unauthorized"); | |
echo "Provide username + password please"; | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment