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 |
13712
|
aaronmk
|
# remove linewraps: x_-_.y@url -> x.y@url
|
16 |
13711
|
aaronmk
|
# the _ are needed to work in Google spreadsheets
|
17 |
|
|
$path = str_replace('_-_', '', $path);
|
18 |
|
|
|
19 |
13720
|
aaronmk
|
# remove insertion comments: [c]x[d]@url -> x@url
|
20 |
13718
|
aaronmk
|
# use [] because in writing, [] denotes insertion
|
21 |
13723
|
aaronmk
|
# insertion indicates that the semantic meaning of the [] portion also
|
22 |
|
|
# applies, even though it's not included in the linked term name
|
23 |
13710
|
aaronmk
|
# can't use : for this because Firefox will not update the "password" for
|
24 |
|
|
# the website with the new value after the :
|
25 |
13718
|
aaronmk
|
$path = preg_replace('/\[.*?\]/', '', $path);
|
26 |
13702
|
aaronmk
|
|
27 |
13733
|
aaronmk
|
# remove deletion comments: (-c_-)x@url -> c_x@url
|
28 |
13720
|
aaronmk
|
# use () because in editing, () denotes something to remove
|
29 |
13733
|
aaronmk
|
# the -...- indicate strikethrough (deletion)
|
30 |
13720
|
aaronmk
|
# deletion indicates that the semantic meaning of the () portion does not
|
31 |
|
|
# apply, even though it's included in the linked term name
|
32 |
13733
|
aaronmk
|
$path = preg_replace('/\(-([^)]*?)-\)/', '$1', $path);
|
33 |
13720
|
aaronmk
|
|
34 |
13695
|
aaronmk
|
# translate reverse @-paths into forward .-paths
|
35 |
13701
|
aaronmk
|
$path = implode(".", array_reverse(explode("@", $path)));
|
36 |
|
|
|
37 |
|
|
return $path;
|
38 |
13695
|
aaronmk
|
}
|
39 |
13614
|
aaronmk
|
|
40 |
|
|
if (!isset($_SERVER["PHP_AUTH_USER"])) # browser first omits Authorization
|
41 |
|
|
{
|
42 |
|
|
header('WWW-Authenticate: Basic realm="please leave username/password blank or as filled in"');
|
43 |
|
|
}
|
44 |
|
|
else
|
45 |
|
|
{
|
46 |
13668
|
aaronmk
|
$dest = preg_replace('!\b/!', "./", $_SERVER["SCRIPT_URI"])."?";
|
47 |
|
|
# append trailing . to host to prevent infinite redirect loop
|
48 |
13665
|
aaronmk
|
if ($_SERVER["PHP_AUTH_USER"] !== "") # prepend to query string
|
49 |
13694
|
aaronmk
|
$dest .= "."/*force dotpath*/.user2path(login__from_env());
|
50 |
13665
|
aaronmk
|
$dest .= $_SERVER["QUERY_STRING"];
|
51 |
13625
|
aaronmk
|
|
52 |
|
|
header("Location: ".$dest);
|
53 |
13614
|
aaronmk
|
}
|
54 |
|
|
?>
|