|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// Starting point, handle incoming request and hand over to more specific handler |
|
4
|
|
|
|
|
5
|
|
|
namespace SSpkS; |
|
6
|
|
|
|
|
7
|
|
|
use \SSpkS\Handler\BrowserAllPackagesListHandler; |
|
8
|
|
|
use \SSpkS\Handler\BrowserDeviceListHandler; |
|
9
|
|
|
use \SSpkS\Handler\BrowserPackageListHandler; |
|
10
|
|
|
use \SSpkS\Handler\NotFoundHandler; |
|
11
|
|
|
use \SSpkS\Handler\SynologyHandler; |
|
12
|
|
|
|
|
13
|
|
|
class Handler |
|
14
|
|
|
{ |
|
15
|
|
|
private $config; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct(\SSpkS\Config $config) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->config = $config; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function handle() |
|
23
|
|
|
{ |
|
24
|
|
|
// TODO: Probably walk through all known handlers and query them whether they're |
|
25
|
|
|
// responsible/capable for answering the request or not. Take the best match. |
|
26
|
|
|
|
|
27
|
|
|
if (isset($_REQUEST['unique']) && substr($_REQUEST['unique'], 0, 8) == 'synology') { |
|
28
|
|
|
$handler = new SynologyHandler($this->config); |
|
29
|
|
|
} elseif (isset($this->config->site['redirectindex']) && !empty($this->config->site['redirectindex'])) { |
|
30
|
|
|
header('Location: '.$this->config->site['redirectindex']); |
|
31
|
|
|
die(); |
|
32
|
|
|
} elseif ($_SERVER['REQUEST_METHOD'] == 'GET') { |
|
33
|
|
|
// GET-request, probably browser --> show HTML |
|
34
|
|
|
$arch = trim($_GET['arch']); |
|
35
|
|
|
$fullList = trim($_GET['fulllist']); |
|
36
|
|
|
|
|
37
|
|
|
if ($arch) { |
|
38
|
|
|
// Architecture is set --> show packages for that arch |
|
39
|
|
|
$handler = new BrowserPackageListHandler($this->config); |
|
40
|
|
|
} elseif ($fullList) { |
|
41
|
|
|
// No architecture, but full list of packages requested --> show simple list |
|
42
|
|
|
$handler = new BrowserAllPackagesListHandler($this->config); |
|
43
|
|
|
} else { |
|
44
|
|
|
// Nothing specific requested --> show models overview |
|
45
|
|
|
$handler = new BrowserDeviceListHandler($this->config); |
|
46
|
|
|
} |
|
47
|
|
|
} else { |
|
48
|
|
|
$handler = new NotFoundHandler($this->config); |
|
49
|
|
|
} |
|
50
|
|
|
$handler->handle(); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|