-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathboot.php
More file actions
108 lines (92 loc) · 2.36 KB
/
boot.php
File metadata and controls
108 lines (92 loc) · 2.36 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* OpenTHC Chat Bootstrap
*/
error_reporting(E_ALL & ~E_NOTICE);
define('APP_ROOT', __DIR__);
require_once(__DIR__ . '/vendor/autoload.php');
\OpenTHC\Config::init(__DIR__);
/**
* Database Conneciton
*/
function _dbc()
{
static $dbc;
if (empty($dbc)) {
$dsn = \OpenTHC\Config::get('database/chat/dsn');
$dbc = new \Edoceo\Radix\DB\SQL($dsn);
}
return $dbc;
}
/**
*
*/
function _mm_client(string $tok = '')
{
$cfg = \OpenTHC\Config::get('mattermost');
// $jar = new \GuzzleHttp\Cookie\CookieJar();
$arg = [
'base_uri' => sprintf('%s/api/v4/', $cfg['origin']),
'allow_redirects' => false,
'connect_timeout' => 4.20,
'http_errors' => false,
// 'cookies' => $jar,
];
if ( ! empty($tok)) {
$arg['headers'] = [
'authorization' => sprintf('Bearer %s', $tok)
];
}
$ghc = new \GuzzleHttp\Client($arg);
return $ghc;
}
/**
* oAuth Provider Factory
*/
function _oauth_provider($s)
{
$cfg = \OpenTHC\Config::get('openthc/sso');
$url = sprintf('https://%s/auth/back?_=%s', $_SERVER['SERVER_NAME'], $s);
$url = trim($url, '?');
$ocp = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => $cfg['client-id'],
'clientSecret' => $cfg['client-sk'],
'redirectUri' => $url,
'urlAuthorize' => sprintf('%s/oauth2/authorize', $cfg['origin']),
'urlAccessToken' => sprintf('%s/oauth2/token', $cfg['origin']),
'urlResourceOwnerDetails' => sprintf('%s/oauth2/profile', $cfg['origin']),
'verify' => true
]);
return $ocp;
}
/**
* Copied from www-com Project
* Wrapper to Draw Friendly JavaScript Redirector
* Have to go this way so that SameSite=Strict works properly
* @see https://www.nogginbox.co.uk/blog/strict-cookies-not-sent-by-request
*/
function doJavaScriptRedirect($url) : void
{
// breaks the reverse proxy
// header('cache-control', 'no-store');
$html = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<meta http-equiv="cache-control" content="no-store">
<title>Redirecting...</title>
</head>
<body>
<script>
window.localStorage.setItem('__landingPageSeen__', true);
window.localStorage.setItem('debug', undefined);
window.localStorage.setItem('was_notified_of_login', true)
window.localStorage.setItem('__announcement__Preview Mode: Email notifications have not been configured.', true);
</script>
<script>window.location = "$url";</script>
</body>
</html>
HTML;
__exit_html($html);
}