-
Notifications
You must be signed in to change notification settings - Fork 4
/
Module.php
265 lines (235 loc) · 11.1 KB
/
Module.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
/**
* This code is licensed under AGPLv3 license or Afterlogic Software License
* if commercial version of the product was purchased.
* For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
*/
namespace Aurora\Modules\FilesWebclient;
use Aurora\System\Application;
use Aurora\System\Utils;
/**
* This module displays the web interface for managing files.
*
* @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
* @license https://afterlogic.com/products/common-licensing Afterlogic Software License
* @copyright Copyright (c) 2023, Afterlogic Corp.
*
* @property Settings $oModuleSettings
*
* @package Modules
*/
class Module extends \Aurora\System\Module\AbstractWebclientModule
{
/**
*
* @var \Aurora\Modules\Min\Module
*/
protected $oMinModuleDecorator = null;
/**
*
* @var \Aurora\Modules\Files\Module
*/
protected $oFilesModuleDecorator = null;
/**
* @var array
*/
protected $aRequireModules = ['Files', 'Min'];
/***** private functions *****/
/**
* Initializes Files Module.
*
* @ignore
*/
public function init()
{
$this->oFilesModuleDecorator = \Aurora\Modules\Files\Module::Decorator();
$this->oMinModuleDecorator = \Aurora\Modules\Min\Module::Decorator();
$this->AddEntry('files-pub', 'EntryPub');
}
/**
* @return Module
*/
public static function getInstance()
{
return parent::getInstance();
}
/**
* @return Module
*/
public static function Decorator()
{
return parent::Decorator();
}
/**
* @return Settings
*/
public function getModuleSettings()
{
return $this->oModuleSettings;
}
/***** private functions *****/
/***** public functions *****/
/**
* @ignore
*/
public function EntryPub()
{
\Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous);
$sResult = '';
try {
/** @var \Aurora\Modules\Files\Module */
$oFilesModule = \Aurora\Api::GetModule('Files');
$sHash = (string) \Aurora\System\Router::getItemByIndex(1, '');
$sAction = (string) \Aurora\System\Router::getItemByIndex(2, 'download');
$bSecure = \Aurora\System\Router::getItemByIndex(3, '') === 'secure';
$bList = (!empty($sAction) && $sAction === 'list');
$sPassword = $bSecure ? rawurldecode(\Aurora\System\Router::getItemByIndex(4, '')) : '';
$aHash = $this->oMinModuleDecorator->GetMinByHash($sHash);
$sType = isset($aHash['Type']) ? $aHash['Type'] : '';
$sPath = isset($aHash['Path']) ? $aHash['Path'] : '';
$sName = isset($aHash['Name']) ? $aHash['Name'] : '';
$sFullPath = \ltrim($sPath, '/') . '/' . \ltrim($sName, '/');
$sResourceId = $sType . '/' . \ltrim($sFullPath, '/');
if (isset($aHash['UserId'])) {
$aArgs = [
'UserId' => $aHash['UserId'],
'ResourceType' => 'file',
'ResourceId' => $sResourceId,
'Action' => $sAction
];
$this->broadcastEvent('AddToActivityHistory', $aArgs);
}
if ($bList) {
if ($this->oMinModuleDecorator) {
$mResult = null;
$this->broadcastEvent(
'FileEntryPub',
$aHash,
$mResult
);
if ($mResult) {
$sResult = $mResult;
} else {
if (\is_array($aHash) && isset($aHash['IsFolder']) && $aHash['IsFolder']) {
//executing this method to check access to the Files module methods
$oFilesModule->GetPublicFiles($sHash, $sPath);
$oApiIntegrator = \Aurora\System\Managers\Integrator::getInstance();
if ($oApiIntegrator) {
$oCoreClientModule = \Aurora\System\Api::GetModule('CoreWebclient');
if ($oCoreClientModule instanceof \Aurora\System\Module\AbstractModule) {
$sResult = \file_get_contents($oCoreClientModule->GetPath() . '/templates/Index.html');
if (\is_string($sResult)) {
$oSettings = &\Aurora\System\Api::GetSettings();
$sFrameOptions = $oSettings->XFrameOptions;
if (0 < \strlen($sFrameOptions)) {
@\header('X-Frame-Options: ' . $sFrameOptions);
}
$aConfig = array(
'public_app' => true,
'modules_list' => $oApiIntegrator->GetModulesForEntry('FilesWebclient')
);
$sResult = \strtr($sResult, array(
'{{AppVersion}}' => Application::GetVersion(),
'{{IntegratorDir}}' => $oApiIntegrator->isRtl() ? 'rtl' : 'ltr',
'{{IntegratorLinks}}' => $oApiIntegrator->buildHeadersLink(),
'{{IntegratorBody}}' => $oApiIntegrator->buildBody($aConfig)
));
}
}
}
} elseif ($aHash && isset($aHash['__hash__'], $aHash['Name'], $aHash['Size'])) {
$sUrl = (bool) $this->oModuleSettings->ServerUseUrlRewrite ? '/download/' : '?/files-pub/';
$sUrlRewriteBase = (string) $this->oModuleSettings->ServerUrlRewriteBase;
if (!empty($sUrlRewriteBase)) {
$sUrlRewriteBase = '<base href="' . $sUrlRewriteBase . '" />';
}
$oModuleManager = \Aurora\System\Api::GetModuleManager();
$sTheme = $oModuleManager->getModuleConfigValue('CoreWebclient', 'Theme');
$sResult = \file_get_contents($this->GetPath() . '/templates/FilesPub.html');
if (\is_string($sResult)) {
$sResult = \strtr($sResult, array(
'{{Url}}' => $sUrl . $aHash['__hash__'],
'{{FileName}}' => $aHash['Name'],
'{{FileSize}}' => Utils::GetFriendlySize($aHash['Size']),
'{{FileType}}' => Utils::GetFileExtension($aHash['Name']),
'{{BaseUrl}}' => $sUrlRewriteBase,
'{{Theme}}' => $sTheme,
));
} else {
\Aurora\System\Api::Log('Empty template.', \Aurora\System\Enums\LogLevel::Error);
}
} else {
throw new \Aurora\System\Exceptions\ApiException(
\Aurora\System\Notifications::MethodAccessDenied
);
}
}
}
} else {
\header('Cache-Control: no-cache', true);
if ($this->oMinModuleDecorator) {
if (isset($aHash['__hash__'])
&& ((isset($aHash['IsFolder']) && (bool) $aHash['IsFolder'] === false) || !isset($aHash['IsFolder']))
&& (!isset($aHash['Password']) || (isset($aHash['Password']) && $sPassword && Utils::EncryptValue($sPassword) === $aHash['Password']))
&& isset($aHash['Type']) && isset($aHash['Path']) && isset($aHash['Name'])
) {
$bskipCheckUserRoleStatus = \Aurora\Api::skipCheckUserRole(true);
$this->oFilesModuleDecorator->getRawFile(
null,
$aHash['Type'],
$aHash['Path'],
$aHash['Name'],
$sHash,
$sAction
);
\Aurora\Api::skipCheckUserRole($bskipCheckUserRoleStatus);
$aArgs = [
'UserId' => $aHash['UserId'],
'ResourceType' => 'file',
'ResourceId' => $sResourceId,
'Action' => $sAction . '-finish'
];
$this->broadcastEvent('AddToActivityHistory', $aArgs);
} else {
$aArgs = [
'UserId' => $aHash['UserId'],
'ResourceType' => 'file',
'ResourceId' => $sResourceId,
'Action' => 'wrong-password'
];
$this->broadcastEvent('AddToActivityHistory', $aArgs);
throw new \Aurora\System\Exceptions\ApiException(
\Aurora\System\Notifications::MethodAccessDenied
);
}
}
}
} catch (\Aurora\System\Exceptions\ApiException $oEx) {
$oModuleManager = \Aurora\System\Api::GetModuleManager();
$sTheme = $oModuleManager->getModuleConfigValue('CoreWebclient', 'Theme');
$sResult = \file_get_contents($this->GetPath() . '/templates/NotFound.html');
$sResult = \strtr($sResult, array(
'{{NotFound}}' => $oFilesModule->i18N('INFO_NOTFOUND'),
'{{Theme}}' => $sTheme,
));
\Aurora\Api::LogException($oEx);
}
\Aurora\Modules\CoreWebclient\Module::Decorator()->SetHtmlOutputHeaders();
return $sResult;
}
public function GetSettings()
{
\Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous);
$aModuleSettings = array(
'EditFileNameWithoutExtension' => $this->oModuleSettings->EditFileNameWithoutExtension,
'ShowCommonSettings' => $this->oModuleSettings->ShowCommonSettings,
'ServerUrlRewriteBase' => $this->oModuleSettings->ServerUrlRewriteBase,
'ServerUseUrlRewrite' => $this->oModuleSettings->ServerUseUrlRewrite,
'ShowFilesApps' => $this->oModuleSettings->ShowFilesApps,
'BottomLeftCornerLinks' => $this->oModuleSettings->BottomLeftCornerLinks,
'PublicLinksEnabled' => $this->oModuleSettings->PublicLinksEnabled,
'FilesSortBy' => $this->oModuleSettings->FilesSortBy
);
return $aModuleSettings;
}
}