1 | <?php |
||
37 | class ProxyController extends Controller { |
||
38 | |||
39 | /** @var IURLGenerator */ |
||
40 | private $urlGenerator; |
||
41 | |||
42 | /** @var ISession */ |
||
43 | private $session; |
||
44 | |||
45 | /** @var IClientService */ |
||
46 | private $clientService; |
||
47 | |||
48 | /** @var string */ |
||
49 | private $referrer; |
||
50 | |||
51 | /** @var string */ |
||
52 | private $hostname; |
||
53 | |||
54 | /** |
||
55 | * @param string $appName |
||
56 | * @param IRequest $request |
||
57 | * @param IURLGenerator $urlGenerator |
||
58 | * @param ISession $session |
||
59 | * @param IClientService $clientService |
||
60 | */ |
||
61 | 5 | public function __construct($appName, IRequest $request, |
|
70 | |||
71 | /** |
||
72 | * @NoAdminRequired |
||
73 | * @NoCSRFRequired |
||
74 | * |
||
75 | * @param string $src |
||
76 | * |
||
77 | * @throws \Exception If the URL is not valid. |
||
78 | * @return TemplateResponse |
||
79 | */ |
||
80 | 5 | public function redirect($src) { |
|
81 | 5 | $authorizedRedirect = false; |
|
82 | |||
83 | 5 | if (strpos($src, 'http://') !== 0 && strpos($src, 'https://') !== 0) { |
|
84 | 1 | throw new Exception('URL is not valid.', 1); |
|
85 | } |
||
86 | |||
87 | // If the request has a referrer from this domain redirect the user without interaction |
||
88 | // this is there to prevent an open redirector. |
||
89 | // Since we can't prevent the referrer from being added with a HTTP only header we rely on an |
||
90 | // additional JS file here. |
||
91 | 4 | if (parse_url($this->referrer, PHP_URL_HOST) === $this->hostname) { |
|
92 | 2 | $authorizedRedirect = true; |
|
93 | 2 | } |
|
94 | |||
95 | $params = [ |
||
96 | 4 | 'authorizedRedirect' => $authorizedRedirect, |
|
97 | 4 | 'url' => $src, |
|
98 | 4 | 'urlHost' => parse_url($src, PHP_URL_HOST), |
|
99 | 4 | 'mailURL' => $this->urlGenerator->linkToRoute('mail.page.index'), |
|
100 | 4 | ]; |
|
101 | 4 | return new TemplateResponse($this->appName, 'redirect', $params, 'guest'); |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * @NoAdminRequired |
||
106 | * @NoCSRFRequired |
||
107 | * |
||
108 | * @param string $src |
||
109 | * |
||
110 | * TODO: Cache the proxied content to prevent unnecessary requests from the oC server |
||
111 | * The caching should also already happen in a cronjob so that the sender of the |
||
112 | * mail does not know whether the mail has been opened. |
||
113 | * |
||
114 | * @return ProxyDownloadResponse |
||
115 | */ |
||
116 | public function proxy($src) { |
||
124 | |||
125 | } |
||
126 |