-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcopy_package.php
More file actions
49 lines (49 loc) · 1.33 KB
/
copy_package.php
File metadata and controls
49 lines (49 loc) · 1.33 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
<?php
if (!empty($_GET['session_id'])) {
session_id($_GET['session_id']);
session_start();
}
define('MODX_API_MODE', true);
require 'index.php';
if ($_GET['auth']) {
exit($modx->toJSON(array(
'success' => true,
'message' => 'Вернули сессию',
'data' => array(
'session_name' => session_name(),
'session_id' => session_id()
),
)));
}
$url = $_GET['url'];
if (empty($url)) {
exit('Url not correct ' . $url);
}
$content = file_get_contents($url);
$cache = $modx->getCacheManager();
$filename = basename($url);
$path = MODX_CORE_PATH . 'packages/' . $filename;
/* @var modUser $User */
if (!$User = $modx->getObject('modUser', array('sudo' => 1))) {
exit('User not found');
}
if (!$User->isAuthenticated('mgr')) {
$User->addSessionContext('mgr');
}
if (!$User->isAuthenticated('mgr')) {
exit($modx->toJSON(array(
'success' => false,
'message' => 'Не удалось авторизоватсья',
'data' => array(
'is' => $User->isAuthenticated('mgr')
),
)));
}
if (file_exists($path)) {
unlink($path);
}
$cache->writeFile($path, $content);
/* @var modProcessorResponse $response */
$response = $modx->runProcessor('workspace/packages/scanlocal');
session_destroy();
exit($modx->toJSON($response->response));