forked from srobo/srobo-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
79 lines (64 loc) · 1.73 KB
/
upload.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
<?php
if (version_compare(PHP_VERSION, '5.3.3') < 0)
{
header('HTTP/1.1 501 Not Implemented');
header('Content-type: text/plain');
echo 'This server does not have PHP 5.3.3 or later installed.' . "\n";
exit();
}
error_reporting(E_ALL | E_STRICT);
ob_start();
// includes
require_once('include/main.php');
try
{
$config = Configuration::getInstance();
if ($config->getConfig('require_ssl') && empty($_SERVER['HTTPS']))
{
header('HTTP/1.1 403 Forbidden');
header('Content-type: text/plain');
echo "Unencrypted HTTP not allowed, please use HTTPS.\n";
exit();
}
// If the user is not logged in bail
$auth = AuthBackend::getInstance();
$token = getDefaultTokenStrategy()->getAuthToken();
if (!$auth->validateAuthToken($token))
{
header('HTTP/1.1 403 Forbidden');
header('Content-type: text/plain');
echo "You need to be logged in.\n";
exit();
}
$input = Input::getInstance();
$output = Output::getInstance();
if (!isset($_POST['_command']))
{
throw new Exception(E_MALFORMED_REQUEST, "No request type specified");
}
$input->setRequest($_POST['_command']);
unset($_POST['_command']);
foreach ($_POST as $key => $value)
{
$input->setInput($key, $value);
}
$mm = ModuleManager::getInstance();
$mm->importModules(false); // core modules only
$modname = $input->getRequestModule();
$commandName = $input->getRequestCommand();
$mm->dispatchCommand($modname, $commandName);
}
catch (Exception $e)
{
ide_log_exception($e);
$output->setOutput('error', parts_for_output($e);
}
if ($config->getConfig('debug'))
{
$output->setOutput('debug', explode("\n", ob_get_contents()));
}
ob_end_clean();
$data = $output->encodeOutput();
header('Content-type: text/plain');
header('Content-length: ' . strlen($data));
echo $data;