3 final class DarkConsoleDataController
extends PhabricatorController
{
5 public function shouldRequireLogin() {
6 return !PhabricatorEnv
::getEnvConfig('darkconsole.always-on');
9 public function shouldRequireEnabledUser() {
10 return !PhabricatorEnv
::getEnvConfig('darkconsole.always-on');
13 public function shouldAllowPartialSessions() {
17 public function handleRequest(AphrontRequest
$request) {
18 $viewer = $request->getViewer();
19 $key = $request->getURIData('key');
21 $cache = new PhabricatorKeyValueDatabaseCache();
22 $cache = new PhutilKeyValueCacheProfiler($cache);
23 $cache->setProfiler(PhutilServiceProfiler
::getInstance());
25 $result = $cache->getKey('darkconsole:'.$key);
27 return new Aphront400Response();
31 $result = phutil_json_decode($result);
32 } catch (PhutilJSONParserException
$ex) {
33 return new Aphront400Response();
36 if ($result['vers'] != DarkConsoleCore
::STORAGE_VERSION
) {
37 return new Aphront400Response();
40 if ($result['user'] != $viewer->getPHID()) {
41 return new Aphront400Response();
45 $output['tabs'] = $result['tabs'];
46 $output['panel'] = array();
48 foreach ($result['data'] as $class => $data) {
50 $obj = newv($class, array());
52 $obj->setRequest($request);
54 $panel = $obj->renderPanel();
56 // Because cookie names can now be prefixed, wipe out any cookie value
57 // with the session cookie name anywhere in its name.
58 $pattern = '('.preg_quote(PhabricatorCookies
::COOKIE_SESSION
).')';
59 foreach ($_COOKIE as $cookie_name => $cookie_value) {
60 if (preg_match($pattern, $cookie_name)) {
61 $panel = PhutilSafeHTML
::applyFunction(
69 $output['panel'][$class] = $panel;
70 } catch (Exception
$ex) {
71 $output['panel'][$class] = 'error';
75 return id(new AphrontAjaxResponse())->setContent($output);