Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / console / controller / DarkConsoleDataController.php
blobcae183fbaeb33afb6f79324330aa6092bd94627d
1 <?php
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() {
14 return true;
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);
26 if (!$result) {
27 return new Aphront400Response();
30 try {
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();
44 $output = array();
45 $output['tabs'] = $result['tabs'];
46 $output['panel'] = array();
48 foreach ($result['data'] as $class => $data) {
49 try {
50 $obj = newv($class, array());
51 $obj->setData($data);
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(
62 'str_replace',
63 $cookie_value,
64 '(session-key)',
65 $panel);
69 $output['panel'][$class] = $panel;
70 } catch (Exception $ex) {
71 $output['panel'][$class] = 'error';
75 return id(new AphrontAjaxResponse())->setContent($output);