Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionServeController.php
<?php | <?php | ||||
final class DiffusionServeController extends DiffusionController { | final class DiffusionServeController extends DiffusionController { | ||||
protected function shouldLoadDiffusionRequest() { | public function isVCSRequest(AphrontRequest $request) { | ||||
return false; | $identifier = $this->getRepositoryIdentifierFromRequest($request); | ||||
} | if ($identifier === null) { | ||||
public static function isVCSRequest(AphrontRequest $request) { | |||||
if (!self::getCallsign($request)) { | |||||
return null; | return null; | ||||
} | } | ||||
$content_type = $request->getHTTPHeader('Content-Type'); | $content_type = $request->getHTTPHeader('Content-Type'); | ||||
$user_agent = idx($_SERVER, 'HTTP_USER_AGENT'); | $user_agent = idx($_SERVER, 'HTTP_USER_AGENT'); | ||||
$vcs = null; | $vcs = null; | ||||
if ($request->getExists('service')) { | if ($request->getExists('service')) { | ||||
Show All 23 Lines | if ($request->getExists('service')) { | ||||
if ($dav->getDomain() === 'subversion.tigris.org') { | if ($dav->getDomain() === 'subversion.tigris.org') { | ||||
$vcs = PhabricatorRepositoryType::REPOSITORY_TYPE_SVN; | $vcs = PhabricatorRepositoryType::REPOSITORY_TYPE_SVN; | ||||
} | } | ||||
} | } | ||||
return $vcs; | return $vcs; | ||||
} | } | ||||
private static function getCallsign(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$uri = $request->getRequestURI(); | $identifier = $this->getRepositoryIdentifierFromRequest($request); | ||||
$regex = '@^/diffusion/(?P<callsign>[A-Z]+)(/|$)@'; | |||||
$matches = null; | |||||
if (!preg_match($regex, (string)$uri, $matches)) { | |||||
return null; | |||||
} | |||||
return $matches['callsign']; | |||||
} | |||||
protected function processDiffusionRequest(AphrontRequest $request) { | |||||
$callsign = self::getCallsign($request); | |||||
// If authentication credentials have been provided, try to find a user | // If authentication credentials have been provided, try to find a user | ||||
// that actually matches those credentials. | // that actually matches those credentials. | ||||
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { | if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { | ||||
$username = $_SERVER['PHP_AUTH_USER']; | $username = $_SERVER['PHP_AUTH_USER']; | ||||
$password = new PhutilOpaqueEnvelope($_SERVER['PHP_AUTH_PW']); | $password = new PhutilOpaqueEnvelope($_SERVER['PHP_AUTH_PW']); | ||||
$viewer = $this->authenticateHTTPRepositoryUser($username, $password); | $viewer = $this->authenticateHTTPRepositoryUser($username, $password); | ||||
Show All 22 Lines | if (!$allow_public) { | ||||
pht('Public and authenticated HTTP access are both forbidden.')); | pht('Public and authenticated HTTP access are both forbidden.')); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
try { | try { | ||||
$repository = id(new PhabricatorRepositoryQuery()) | $repository = id(new PhabricatorRepositoryQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withCallsigns(array($callsign)) | ->withIdentifiers(array($identifier)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$repository) { | if (!$repository) { | ||||
return new PhabricatorVCSResponse( | return new PhabricatorVCSResponse( | ||||
404, | 404, | ||||
pht('No such repository exists.')); | pht('No such repository exists.')); | ||||
} | } | ||||
} catch (PhabricatorPolicyException $ex) { | } catch (PhabricatorPolicyException $ex) { | ||||
if ($viewer->isLoggedIn()) { | if ($viewer->isLoggedIn()) { | ||||
▲ Show 20 Lines • Show All 540 Lines • Show Last 20 Lines |