Beispiel #1
0
 /**
  * @route help
  */
 public function helpPage()
 {
     if ($this->isLoggedIn()) {
         $this->storeLensVar('showmenu', true);
         //
         $cabins = $this->getCabinNamespaces();
         // Get debug information.
         $helpInfo = ['cabins' => [], 'cabin_names' => \array_values($cabins), 'gears' => [], 'universal' => []];
         /**
          * This might reveal "sensitive" information. By default, it's
          * locked out of non-administrator users. You can grant access to
          * other users/groups via the Permissions menu.
          */
         if ($this->can('read')) {
             $state = State::instance();
             if (\is_readable(ROOT . '/config/gadgets.json')) {
                 $helpInfo['universal']['gadgets'] = \Airship\loadJSON(ROOT . '/config/gadgets.json');
             }
             if (\is_readable(ROOT . '/config/content_security_policy.json')) {
                 $helpInfo['universal']['content_security_policy'] = \Airship\loadJSON(ROOT . '/config/content_security_policy.json');
             }
             foreach ($cabins as $cabin) {
                 $cabinData = ['config' => \Airship\loadJSON(ROOT . '/Cabin/' . $cabin . '/manifest.json'), 'content_security_policy' => [], 'gadgets' => [], 'motifs' => [], 'user_motifs' => \Airship\LensFunctions\user_motif($this->getActiveUserId(), $cabin)];
                 $prefix = ROOT . '/Cabin/' . $cabin . '/config/';
                 if (\is_readable($prefix . 'gadgets.json')) {
                     $cabinData['gadgets'] = \Airship\loadJSON($prefix . 'gadgets.json');
                 }
                 if (\is_readable($prefix . 'motifs.json')) {
                     $cabinData['motifs'] = \Airship\loadJSON($prefix . 'motifs.json');
                 }
                 if (\is_readable($prefix . 'content_security_policy.json')) {
                     $cabinData['content_security_policy'] = \Airship\loadJSON($prefix . 'content_security_policy.json');
                 }
                 $helpInfo['cabins'][$cabin] = $cabinData;
             }
             $helpInfo['gears'] = [];
             foreach ($state->gears as $gear => $latestGear) {
                 $helpInfo['gears'][$gear] = \Airship\get_ancestors($latestGear);
             }
             // Only grab data likely to be pertinent to common issues:
             $keys = ['airship', 'auto-update', 'debug', 'guzzle', 'notary', 'rate-limiting', 'session_config', 'tor-only', 'twig_cache'];
             $helpInfo['universal']['config'] = \Airship\keySlice($state->universal, $keys);
             $helpInfo['php'] = ['halite' => Halite::VERSION, 'libsodium' => ['major' => \Sodium\library_version_major(), 'minor' => \Sodium\library_version_minor(), 'version' => \Sodium\version_string()], 'version' => \PHP_VERSION, 'versionid' => \PHP_VERSION_ID];
         }
         $this->lens('help', ['active_link' => 'bridge-link-help', 'airship' => \AIRSHIP_VERSION, 'helpInfo' => $helpInfo]);
     } else {
         // Not a registered user? Go read the docs. No info leaks for you!
         \Airship\redirect('https://github.com/paragonie/airship-docs');
     }
 }
Beispiel #2
0
 /**
  * @covers \Airship\keySlice()
  */
 public function testKeySlice()
 {
     $array = ['a' => true, 'b' => 12345, 'c' => 'testing', 'd' => 'delicious'];
     $this->assertSame(['a' => true], \Airship\keySlice($array, ['a']));
     $this->assertSame(['a' => true, 'c' => 'testing'], \Airship\keySlice($array, ['a', 'c']));
     $this->assertSame(['a' => true, 'c' => 'testing'], \Airship\keySlice($array, ['c', 'a']));
 }
Beispiel #3
0
 /**
  * Move a page
  *
  * @param array $page
  * @param array $post
  * @param string $cabin
  * @param string $dir
  * @return bool
  */
 protected function processMovePage(array $page, array $post, string $cabin, string $dir) : bool
 {
     if (\is_numeric($post['directory'])) {
         $post['cabin'] = $this->pg->getCabinForDirectory($post['directory']);
     } elseif (\is_string($post['directory'])) {
         // We're setting this to the root directory of a cabin
         $post['cabin'] = $post['directory'];
         $post['directory'] = 0;
     } else {
         // Invalid input.
         return false;
     }
     // Actually process the new page:
     if ($page['directory'] !== $post['directory'] || $page['cabin'] !== $post['cabin'] || $page['url'] !== $post['url']) {
         $this->pg->movePage((int) $page['pageid'], $post['url'], (int) $post['directory']);
         if (!empty($post['create_redirect'])) {
             $this->pg->createPageRedirect(\Airship\keySlice($page, ['cabin', 'directory', 'url']), \Airship\keySlice($post, ['cabin', 'directory', 'url']));
         }
         \Airship\redirect($this->airship_cabin_prefix . '/pages/' . $cabin, ['dir' => $dir]);
     }
     return false;
 }
Beispiel #4
0
 /**
  * Is this password too weak?
  *
  * @param array $post
  * @return bool
  */
 public function isPasswordWeak(array $post) : bool
 {
     $state = State::instance();
     if (!isset($this->zxcvbn)) {
         $this->zxcvbn = new Zxcvbn();
     }
     $pw = $post['passphrase'];
     $userdata = \Airship\keySlice($post, ['username', 'display_name', 'realname', 'email']);
     $strength = $this->zxcvbn->passwordStrength($pw, \array_values($userdata));
     $min = $state->universal['minimum_password_score'] ?? self::DEFAULT_MIN_SCORE;
     if ($min < 1 || $min > 4) {
         $min = self::DEFAULT_MIN_SCORE > 4 || self::DEFAULT_MIN_SCORE < 1 ? 4 : self::DEFAULT_MIN_SCORE;
     }
     return $strength['score'] < $min;
 }
Beispiel #5
0
 /**
  * Is this password too weak?
  *
  * @param array $post
  * @return bool
  */
 public function isPasswordWeak(array $post) : bool
 {
     $zxcvbn = new Zxcvbn();
     $pw = $post['passphrase'];
     $userdata = \Airship\keySlice($post, ['username', 'display_name', 'realname', 'email']);
     $strength = $zxcvbn->passwordStrength($pw, \array_values($userdata));
     return $strength['score'] < 3;
 }