Projekt

Allgemein

Profil

GX-Bug #69878 » ShopOfflineApplicationTopExtender.inc.php

Example Implementation from IT Recht - Wilken Haase, 18.07.2022 13:48

 
1
<?php
2
/* --------------------------------------------------------------
3
   ShopOfflineApplicationTopExtender.inc.php 2022-06-08
4
   Gambio GmbH
5
   http://www.gambio.de
6
   Copyright (c) 2022 Gambio GmbH
7
   Released under the GNU General Public License (Version 2)
8
   [http://www.gnu.org/licenses/gpl-2.0.html]
9
   --------------------------------------------------------------
10
*/
11

    
12
MainFactory::load_class('ShopOfflinePageHelper');
13

    
14
class ShopOfflineApplicationTopExtender extends ShopOfflineApplicationTopExtender_parent
15
{
16
    /**
17
     * Proceed.
18
     */
19
    public function proceed()
20
    {
21
        parent::proceed();
22
        
23
        if (ShopOfflinePageHelper::pageRebuildNeeded()) {
24
            ShopOfflinePageHelper::rebuildShopOfflinePage();
25
        }
26
        
27
        if ($this->toShowOfflineMessage()) {
28
            header('HTTP/1.1 503 Service Temporarily Unavailable', true, 503);
29
            header('Retry-After: 3600');
30
            header('Cache-Control: no-cache');
31
            header('Content-Type: text/html; charset=' . $_SESSION['language_charset']);
32
            echo $this->getOfflinePageHtml();
33
            exit;
34
        }
35
        
36
        define('SHOP_OFFLINE', !$this->releaseInfoMatchInstalledVersion());
37
    }
38
    
39
    
40
    /**
41
     * @return bool
42
     */
43
    protected function toShowOfflineMessage()
44
    {
45
        return !$this->userLoggedIn()
46
               && $this->shopIsOffline()
47
               && !$this->attemptLogin()
48
               && !$this->updaterRequest()
49
               && !$this->cssRequest()
50
               && !$this->gambioHubRequest()
51
               && !$this->gambioStoreRequest()
52
               && !$this->cronJobRequest()
53
               && !$this->apiRequest()
54
               && !$this->callbackRequest();
55
    }
56
    
57
    
58
    /**
59
     * @return string
60
     */
61
    protected function getGxShopVersion()
62
    {
63
        $gx_version = null;
64
        
65
        include DIR_FS_CATALOG . 'release_info.php';
66
        
67
        return $gx_version;
68
    }
69
    
70
    
71
    /**
72
     * @return string|null
73
     */
74
    protected function getInstalledShopVersion()
75
    {
76
        // do not use gm_get_conf() to avoid caching problems
77
        $query  = 'SELECT `value` FROM `gx_configurations` WHERE `key` = "gm_configuration/INSTALLED_VERSION" LIMIT 1';
78
        $result = xtc_db_query($query);
79
        
80
        if (1 === xtc_db_num_rows($result)) {
81
            $row              = xtc_db_fetch_array($result);
82
            $installedVersion = $row['value'];
83
        }
84
        
85
        return isset($installedVersion) ? $installedVersion : null;
86
    }
87
    
88
    
89
    /**
90
     * @return bool
91
     */
92
    protected function shopIsOffline()
93
    {
94
        return 'checked' === gm_get_conf('GM_SHOP_OFFLINE');
95
    }
96
    
97
    
98
    /**
99
     * @return bool
100
     */
101
    protected function userLoggedIn()
102
    {
103
        return '0' === $_SESSION['customers_status']['customers_status_id'];
104
    }
105
    
106
    
107
    /**
108
     * @return bool
109
     */
110
    protected function releaseInfoMatchInstalledVersion()
111
    {
112
        return $this->getGxShopVersion() === $this->getInstalledShopVersion();
113
    }
114
    
115
    
116
    /**
117
     * Checks if login is attempted.
118
     *
119
     * @return bool True if login is attempted.
120
     */
121
    protected function attemptLogin()
122
    {
123
        return isset($_POST['email_address'], $_POST['password'])
124
               || isset($_POST['2fa_token'], $_POST['cid'], $_POST['cemail'], $_POST['cpassword']);
125
    }
126
    
127
    
128
    /**
129
     * Returns true if the current request comes from GambioHub e.g (shop.php?do=shopinfo).
130
     *
131
     * @return bool
132
     */
133
    protected function gambioHubRequest()
134
    {
135
        if ('shop.php' !== basename(gm_get_env_info('SCRIPT_NAME'))) {
136
            return false;
137
        }
138
        
139
        $hubRequest = (string)array_search('shopinfo', array_map('strtolower', $_GET), true);
140
        
141
        return !empty($hubRequest);
142
    }
143
    
144
    
145
    /**
146
     * Returns true if the current request comes from stylesheet request.
147
     *
148
     * @return bool
149
     */
150
    protected function cssRequest()
151
    {
152
        if ('dynamic_theme_style.css.php' !== basename(gm_get_env_info('SCRIPT_NAME'))) {
153
            return false;
154
        }
155
        
156
        return true;
157
    }
158
    
159
    /**
160
     * Returns true if the current request comes from updater request.
161
     *
162
     * @return bool
163
     */
164
    protected function updaterRequest()
165
    {
166
        if (strpos(gm_get_env_info('SCRIPT_NAME'),'gambio_updater/request_port.php') === false) {
167
            return false;
168
        }
169
        
170
        return true;
171
    }
172
    
173
    /**
174
     * @return string
175
     */
176
    protected function getOfflinePageHtml()
177
    {
178
        return ShopOfflinePageHelper::getShopOfflineHtml();
179
    }
180
    
181
    
182
    /**
183
     * @return bool
184
     */
185
    protected function gambioStoreRequest()
186
    {
187
        if ('shop.php' !== basename(gm_get_env_info('SCRIPT_NAME'))) {
188
            return false;
189
        }
190
        
191
        return isset($_GET['do']) && $_GET['do'] === 'GambioStoreCallback/verify';
192
    }
193
	
194
	
195
	/**
196
	 * @return bool
197
	 */
198
    protected function apiRequest()
199
	{
200
		return 'api.php' === basename(gm_get_env_info('SCRIPT_NAME'));
201
	}
202
    
203
    
204
    /**
205
     * @return bool
206
     */
207
	protected function cronJobRequest(): bool
208
    {
209
        $isShopPhpScript = basename(gm_get_env_info('SCRIPT_NAME')) === 'shop.php';
210
        
211
        if ($isShopPhpScript && isset($_GET['do'])) {
212
            
213
            return 0 === strpos($_GET['do'], 'Cronjob');
214
        }
215
        
216
        return false;
217
    }
218

    
219

    
220
    /**
221
     * @return bool
222
     */
223
    protected function callbackRequest(): bool
224
    {
225
        return array_key_exists(basename(gm_get_env_info('SCRIPT_NAME')), [
226
            'magnaCallback.php' => true,
227
            'api-it-recht-kanzlei.php' => true,
228
        ]);
229
    }
230
}
    (1-1/1)