@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class DarkConsoleDataController extends PhabricatorController {
4
5 public function shouldRequireLogin() {
6 return !PhabricatorEnv::getEnvConfig('darkconsole.always-on');
7 }
8
9 public function shouldRequireEnabledUser() {
10 return !PhabricatorEnv::getEnvConfig('darkconsole.always-on');
11 }
12
13 public function shouldAllowPartialSessions() {
14 return true;
15 }
16
17 public function handleRequest(AphrontRequest $request) {
18 $viewer = $request->getViewer();
19 $key = $request->getURIData('key');
20
21 $cache = new PhabricatorKeyValueDatabaseCache();
22 $cache = new PhutilKeyValueCacheProfiler($cache);
23 $cache->setProfiler(PhutilServiceProfiler::getInstance());
24
25 $result = $cache->getKey('darkconsole:'.$key);
26 if (!$result) {
27 return new Aphront400Response();
28 }
29
30 try {
31 $result = phutil_json_decode($result);
32 } catch (PhutilJSONParserException $ex) {
33 return new Aphront400Response();
34 }
35
36 if ($result['vers'] != DarkConsoleCore::STORAGE_VERSION) {
37 return new Aphront400Response();
38 }
39
40 if ($result['user'] != $viewer->getPHID()) {
41 return new Aphront400Response();
42 }
43
44 $output = array();
45 $output['tabs'] = $result['tabs'];
46 $output['panel'] = array();
47
48 foreach ($result['data'] as $class => $data) {
49 try {
50 $obj = newv($class, array());
51 $obj->setData($data);
52 $obj->setRequest($request);
53
54 $panel = $obj->renderPanel();
55
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);
66 }
67 }
68
69 $output['panel'][$class] = $panel;
70 } catch (Exception $ex) {
71 $output['panel'][$class] = 'error';
72 }
73 }
74
75 return id(new AphrontAjaxResponse())->setContent($output);
76 }
77
78}