Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
// Check if the application is in maintenance mode...
4
if (! file_exists($down = __DIR__.'/down')) {
5
    return;
6
}
7
 
8
// Decode the "down" file's JSON...
9
$data = json_decode(file_get_contents($down), true);
10
 
11
// Allow framework to handle request if no prerendered template...
12
if (! isset($data['template'])) {
13
    return;
14
}
15
 
16
// Allow framework to handle request if request URI is in the exclude list...
17
if (isset($data['except'])) {
18
    $uri = parse_url($_SERVER['REQUEST_URI'])['path'];
19
 
20
    $uri = rawurldecode($uri !== '/' ? trim($uri, '/') : $uri);
21
 
22
    foreach ((array) $data['except'] as $except) {
23
        $except = $except !== '/' ? trim($except, '/') : $except;
24
 
25
        if ($except == $uri) {
26
            return;
27
        }
28
 
29
        $except = preg_quote($except, '#');
30
 
31
        $except = str_replace('\*', '.*', $except);
32
 
33
        if (preg_match('#^'.$except.'\z#u', $uri) === 1) {
34
            return;
35
        }
36
    }
37
}
38
 
39
// Allow framework to handle maintenance mode bypass route...
40
if (isset($data['secret']) && $_SERVER['REQUEST_URI'] === '/'.$data['secret']) {
41
    return;
42
}
43
 
44
// Determine if maintenance mode bypass cookie is valid...
45
if (isset($_COOKIE['laravel_maintenance']) && isset($data['secret'])) {
46
    $payload = json_decode(base64_decode($_COOKIE['laravel_maintenance']), true);
47
 
48
    if (is_array($payload) &&
49
        is_numeric($payload['expires_at'] ?? null) &&
50
        isset($payload['mac']) &&
51
        hash_equals(hash_hmac('sha256', $payload['expires_at'], $data['secret']), $payload['mac']) &&
52
        (int) $payload['expires_at'] >= time()) {
53
        return;
54
    }
55
}
56
 
57
// Redirect to the proper path if necessary...
58
if (isset($data['redirect']) && $_SERVER['REQUEST_URI'] !== $data['redirect']) {
59
    http_response_code(302);
60
    header('Location: '.$data['redirect']);
61
 
62
    exit;
63
}
64
 
65
// Output the prerendered template...
66
http_response_code($data['status'] ?? 503);
67
 
68
if (isset($data['retry'])) {
69
    header('Retry-After: '.$data['retry']);
70
}
71
 
72
if (isset($data['refresh'])) {
73
    header('Refresh: '.$data['refresh']);
74
}
75
 
76
echo $data['template'];
77
 
78
exit;