[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/console/controller/ -> DarkConsoleDataController.php (source)

   1  <?php
   2  
   3  final class DarkConsoleDataController extends PhabricatorController {
   4  
   5    private $key;
   6  
   7    public function shouldRequireLogin() {
   8      return !PhabricatorEnv::getEnvConfig('darkconsole.always-on');
   9    }
  10  
  11    public function shouldRequireEnabledUser() {
  12      return !PhabricatorEnv::getEnvConfig('darkconsole.always-on');
  13    }
  14  
  15    public function shouldAllowPartialSessions() {
  16      return true;
  17    }
  18  
  19    public function willProcessRequest(array $data) {
  20      $this->key = $data['key'];
  21    }
  22  
  23    public function processRequest() {
  24      $request = $this->getRequest();
  25      $user = $request->getUser();
  26  
  27      $cache = new PhabricatorKeyValueDatabaseCache();
  28      $cache = new PhutilKeyValueCacheProfiler($cache);
  29      $cache->setProfiler(PhutilServiceProfiler::getInstance());
  30  
  31      $result = $cache->getKey('darkconsole:'.$this->key);
  32      if (!$result) {
  33        return new Aphront400Response();
  34      }
  35  
  36      $result = json_decode($result, true);
  37  
  38      if (!is_array($result)) {
  39        return new Aphront400Response();
  40      }
  41  
  42      if ($result['vers'] != DarkConsoleCore::STORAGE_VERSION) {
  43        return new Aphront400Response();
  44      }
  45  
  46      if ($result['user'] != $user->getPHID()) {
  47        return new Aphront400Response();
  48      }
  49  
  50      $output = array();
  51      $output['tabs'] = $result['tabs'];
  52      $output['panel'] = array();
  53  
  54      foreach ($result['data'] as $class => $data) {
  55        try {
  56          $obj = newv($class, array());
  57          $obj->setData($data);
  58          $obj->setRequest($request);
  59  
  60          $panel = $obj->renderPanel();
  61  
  62          // Because cookie names can now be prefixed, wipe out any cookie value
  63          // with the session cookie name anywhere in its name.
  64          $pattern = '('.preg_quote(PhabricatorCookies::COOKIE_SESSION).')';
  65          foreach ($_COOKIE as $cookie_name => $cookie_value) {
  66            if (preg_match($pattern, $cookie_name)) {
  67              $panel = PhutilSafeHTML::applyFunction(
  68                'str_replace',
  69                $cookie_value,
  70                '(session-key)',
  71                $panel);
  72            }
  73          }
  74  
  75          $output['panel'][$class] = $panel;
  76        } catch (Exception $ex) {
  77          $output['panel'][$class] = 'error';
  78        }
  79      }
  80  
  81      return id(new AphrontAjaxResponse())->setContent($output);
  82    }
  83  
  84  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1