Path: blob/master/src/applications/config/check/PhabricatorPathSetupCheck.php
12256 views
<?php12final class PhabricatorPathSetupCheck extends PhabricatorSetupCheck {34public function getDefaultGroup() {5return self::GROUP_OTHER;6}78protected function executeChecks() {9// NOTE: We've already appended `environment.append-paths`, so we don't10// need to explicitly check for it.11$path = getenv('PATH');1213if (!$path) {14$summary = pht(15'The environmental variable %s is empty. This server will not '.16'be able to execute some commands.',17'$PATH');1819$message = pht(20"The environmental variable %s is empty. This server needs to execute ".21"some system commands, like `%s`, `%s`, `%s`, and `%s`. To execute ".22"these commands, the binaries must be available in the webserver's ".23"%s. You can set additional paths in configuration.",24'$PATH',25'svn',26'git',27'hg',28'diff',29'$PATH');3031$this32->newIssue('config.environment.append-paths')33->setName(pht('%s Not Set', '$PATH'))34->setSummary($summary)35->setMessage($message)36->addPhabricatorConfig('environment.append-paths');3738// Bail on checks below.39return;40}4142// Users are remarkably industrious at misconfiguring software. Try to43// catch mistaken configuration of PATH.4445$path_parts = explode(PATH_SEPARATOR, $path);46$bad_paths = array();47foreach ($path_parts as $path_part) {48if (!strlen($path_part)) {49continue;50}5152$message = null;53$not_exists = false;54foreach (Filesystem::walkToRoot($path_part) as $part) {55if (!Filesystem::pathExists($part)) {56$not_exists = $part;57// Walk up so we can tell if this is a readability issue or not.58continue;59} else if (!is_dir(Filesystem::resolvePath($part))) {60$message = pht(61"The PATH component '%s' (which resolves as the absolute path ".62"'%s') is not usable because '%s' is not a directory.",63$path_part,64Filesystem::resolvePath($path_part),65$part);66} else if (!is_readable($part)) {67$message = pht(68"The PATH component '%s' (which resolves as the absolute path ".69"'%s') is not usable because '%s' is not readable.",70$path_part,71Filesystem::resolvePath($path_part),72$part);73} else if ($not_exists) {74$message = pht(75"The PATH component '%s' (which resolves as the absolute path ".76"'%s') is not usable because '%s' does not exist.",77$path_part,78Filesystem::resolvePath($path_part),79$not_exists);80} else {81// Everything seems good.82break;83}8485if ($message !== null) {86break;87}88}8990if ($message === null) {91if (!phutil_is_windows() && !@file_exists($path_part.'/.')) {92$message = pht(93"The PATH component '%s' (which resolves as the absolute path ".94"'%s') is not usable because it is not traversable (its '%s' ".95"permission bit is not set).",96$path_part,97Filesystem::resolvePath($path_part),98'+x');99}100}101102if ($message !== null) {103$bad_paths[$path_part] = $message;104}105}106107if ($bad_paths) {108foreach ($bad_paths as $path_part => $message) {109$digest = substr(PhabricatorHash::weakDigest($path_part), 0, 8);110111$this112->newIssue('config.PATH.'.$digest)113->setName(pht('%s Component Unusable', '$PATH'))114->setSummary(115pht(116'A component of the configured PATH can not be used by '.117'the webserver: %s',118$path_part))119->setMessage(120pht(121"The configured PATH includes a component which is not usable. ".122"This server will be unable to find or execute binaries located ".123"here:".124"\n\n".125"%s".126"\n\n".127"The user that the webserver runs as must be able to read all ".128"the directories in PATH in order to make use of them.",129$message))130->addPhabricatorConfig('environment.append-paths');131}132}133134}135}136137138