-
Notifications
You must be signed in to change notification settings - Fork 2
/
LassoAuth.php
67 lines (59 loc) · 2.3 KB
/
LassoAuth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
class LassoAuth {
public static $auth = 'https://sso.indieweb.org/';
public static $wiki = 'https://indieweb.org/';
}
$wgAuthRemoteuserUserName = [
$_SERVER['REMOTE_USER']
];
$wgAuthRemoteuserRemoveAuthPagesAndLinks = false;
$wgAuthRemoteuserUserNameReplaceFilter = [
'/^https?:\/\//' => '', # remove http prefix
'/\/$/' => '', # remove trailing slash
'/' => ' ', # convert other slashes to spaces
];
#$wgAuthRemoteuserUserNameBlacklistFilter = [
$iwBlockedDomains = [
'/commentpara\.de/',
'/github\.io/',
'/wordpress\.com/',
'/blogspot\.com/',
'/livejournal\.com/',
'/indiewebcamp\.com/',
'/indieweb\.org/',
'/herokuapp\.com/',
'/jsbin\.com/',
];
// Recreated this hook from the Auth_Remoteuser extension in order to add a custom error message
$wgHooks['AuthRemoteuserFilterUserName'][] = function ( &$username ) use ( $iwBlockedDomains ) {
foreach ( $iwBlockedDomains as $pattern ) {
# If $pattern is no regex, create one from it.
if ( @preg_match( $pattern, null ) === false ) {
$pattern = str_replace( '\\', '\\\\', $pattern );
$pattern = str_replace( '/', '\\/', $pattern );
$pattern = "/$pattern/";
}
if ( preg_match( $pattern, $username ) ) {
return "This domain name is not allowed as a wiki username. See <a href=\"https://sso.indieweb.org/logout?url=https%3A%2F%2Findieweb.org%2Fblocked_subdomains\">blocked subdomains</a> for more info.<br><br><a href=\"https://sso.indieweb.org/logout?url=https%3A%2F%2Findieweb.org%2F\">Try Again</a> <iframe src=\"https://sso.indieweb.org/logout?url=https%3A%2F%2Findieweb.org%2F\" style=\"display:none;\"></iframe>";
}
}
};
$wgAuthRemoteuserUserUrls = [
'logout' => function($metadata) {
return LassoAuth::$auth.'logout?url='.urlencode(LassoAuth::$wiki);
}
];
$wgHooks['PersonalUrls'][] = function( array &$personal_urls, Title $title, SkinTemplate $skin ) {
if(isset($personal_urls['login'])) {
if(preg_match('/returnto=([^&]+)/', $personal_urls['login']['href'], $match)) {
$page = str_replace('+','_',$match[1]);
} else {
$page = '';
}
$personal_urls['login']['href'] = LassoAuth::$auth.'login?url='.urlencode(LassoAuth::$wiki.$page);
}
if(isset($personal_urls['logout'])) {
$personal_urls['logout']['text'] = 'Log Out';
}
return true;
};