1 |
13614
|
aaronmk
|
<?php
|
2 |
13694
|
aaronmk
|
function login__from_env()
|
3 |
|
|
{
|
4 |
|
|
return $_SERVER["PHP_AUTH_USER"]
|
5 |
|
|
.($_SERVER["PHP_AUTH_PW"] !== "" ? ":".$_SERVER["PHP_AUTH_PW"] : "");
|
6 |
|
|
}
|
7 |
|
|
|
8 |
13614
|
aaronmk
|
function user2path($user) # multiple @ and nested . OK: a@b.c@url -> url?b.c.a
|
9 |
13695
|
aaronmk
|
{
|
10 |
13701
|
aaronmk
|
$path = $user;
|
11 |
|
|
|
12 |
13698
|
aaronmk
|
# remove padding used to visually separate elements:__x__@y__@url -> x@y@url
|
13 |
13701
|
aaronmk
|
$path = preg_replace('/\b__|__\b/', '', $path);
|
14 |
|
|
|
15 |
14113
|
aaronmk
|
# remove category comments: x+y@url -> y@url
|
16 |
14115
|
aaronmk
|
# this special syntax is shorter than [x]_-_y@url
|
17 |
14113
|
aaronmk
|
# a UI can replace + with ' ' to produce a linewrap
|
18 |
|
|
# can't use : for this because Firefox will not update the "password" for
|
19 |
|
|
# the website with the new value after the :
|
20 |
14114
|
aaronmk
|
$path = preg_replace('/^.*?\+/', '', $path);
|
21 |
14113
|
aaronmk
|
|
22 |
13720
|
aaronmk
|
# remove insertion comments: [c]x[d]@url -> x@url
|
23 |
13718
|
aaronmk
|
# use [] because in writing, [] denotes insertion
|
24 |
13723
|
aaronmk
|
# insertion indicates that the semantic meaning of the [] portion also
|
25 |
|
|
# applies, even though it's not included in the linked term name
|
26 |
13718
|
aaronmk
|
$path = preg_replace('/\[.*?\]/', '', $path);
|
27 |
13702
|
aaronmk
|
|
28 |
13733
|
aaronmk
|
# remove deletion comments: (-c_-)x@url -> c_x@url
|
29 |
13720
|
aaronmk
|
# use () because in editing, () denotes something to remove
|
30 |
13733
|
aaronmk
|
# the -...- indicate strikethrough (deletion)
|
31 |
13720
|
aaronmk
|
# deletion indicates that the semantic meaning of the () portion does not
|
32 |
|
|
# apply, even though it's included in the linked term name
|
33 |
13733
|
aaronmk
|
$path = preg_replace('/\(-([^)]*?)-\)/', '$1', $path);
|
34 |
13720
|
aaronmk
|
|
35 |
13695
|
aaronmk
|
# translate reverse @-paths into forward .-paths
|
36 |
13701
|
aaronmk
|
$path = implode(".", array_reverse(explode("@", $path)));
|
37 |
|
|
|
38 |
|
|
return $path;
|
39 |
13695
|
aaronmk
|
}
|
40 |
13614
|
aaronmk
|
|
41 |
|
|
if (!isset($_SERVER["PHP_AUTH_USER"])) # browser first omits Authorization
|
42 |
|
|
{
|
43 |
13739
|
aaronmk
|
header('WWW-Authenticate: Basic realm="'
|
44 |
|
|
.'please leave username/password blank or as filled in. '
|
45 |
|
|
.'**IMPORTANT**: to visit the homepage of this site, you should always '
|
46 |
|
|
.'append \".\": \"'.$_SERVER["HTTP_HOST"].'.\" "');
|
47 |
13614
|
aaronmk
|
}
|
48 |
|
|
else
|
49 |
|
|
{
|
50 |
13668
|
aaronmk
|
$dest = preg_replace('!\b/!', "./", $_SERVER["SCRIPT_URI"])."?";
|
51 |
|
|
# append trailing . to host to prevent infinite redirect loop
|
52 |
13665
|
aaronmk
|
if ($_SERVER["PHP_AUTH_USER"] !== "") # prepend to query string
|
53 |
13694
|
aaronmk
|
$dest .= "."/*force dotpath*/.user2path(login__from_env());
|
54 |
13665
|
aaronmk
|
$dest .= $_SERVER["QUERY_STRING"];
|
55 |
13625
|
aaronmk
|
|
56 |
|
|
header("Location: ".$dest);
|
57 |
13614
|
aaronmk
|
}
|
58 |
|
|
?>
|