Page MenuHomePhabricator

D7462.id16830.diff
No OneTemporary

D7462.id16830.diff

Index: resources/sql/patches/20131031.vcspassword.sql
===================================================================
--- /dev/null
+++ resources/sql/patches/20131031.vcspassword.sql
@@ -0,0 +1,9 @@
+CREATE TABLE {$NAMESPACE}_repository.repository_vcspassword
+(
+ id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ userPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
+ passwordHash VARCHAR(50) NOT NULL COLLATE utf8_bin,
+ dateCreated INT UNSIGNED NOT NULL,
+ dateModified INT UNSIGNED NOT NULL,
+ UNIQUE KEY `key_phid` (userPHID)
+) ENGINE=InnoDB, CHARSET utf8;
Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -534,6 +534,7 @@
'DiffusionSSHGitUploadPackWorkflow' => 'applications/diffusion/ssh/DiffusionSSHGitUploadPackWorkflow.php',
'DiffusionSSHGitWorkflow' => 'applications/diffusion/ssh/DiffusionSSHGitWorkflow.php',
'DiffusionSSHWorkflow' => 'applications/diffusion/ssh/DiffusionSSHWorkflow.php',
+ 'DiffusionSetPasswordController' => 'applications/diffusion/controller/DiffusionSetPasswordController.php',
'DiffusionSetupException' => 'applications/diffusion/exception/DiffusionSetupException.php',
'DiffusionStableCommitNameQuery' => 'applications/diffusion/query/stablecommitname/DiffusionStableCommitNameQuery.php',
'DiffusionSvnCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionSvnCommitParentsQuery.php',
@@ -1672,6 +1673,7 @@
'PhabricatorRepositoryTransaction' => 'applications/repository/storage/PhabricatorRepositoryTransaction.php',
'PhabricatorRepositoryTransactionQuery' => 'applications/repository/query/PhabricatorRepositoryTransactionQuery.php',
'PhabricatorRepositoryType' => 'applications/repository/constants/PhabricatorRepositoryType.php',
+ 'PhabricatorRepositoryVCSPassword' => 'applications/repository/storage/PhabricatorRepositoryVCSPassword.php',
'PhabricatorS3FileStorageEngine' => 'applications/files/engine/PhabricatorS3FileStorageEngine.php',
'PhabricatorSQLPatchList' => 'infrastructure/storage/patch/PhabricatorSQLPatchList.php',
'PhabricatorSSHWorkflow' => 'infrastructure/ssh/PhabricatorSSHWorkflow.php',
@@ -2726,6 +2728,7 @@
'DiffusionSSHGitUploadPackWorkflow' => 'DiffusionSSHGitWorkflow',
'DiffusionSSHGitWorkflow' => 'DiffusionSSHWorkflow',
'DiffusionSSHWorkflow' => 'PhabricatorSSHWorkflow',
+ 'DiffusionSetPasswordController' => 'DiffusionController',
'DiffusionSetupException' => 'AphrontUsageException',
'DiffusionStableCommitNameQuery' => 'DiffusionQuery',
'DiffusionSvnCommitParentsQuery' => 'DiffusionCommitParentsQuery',
@@ -4011,6 +4014,7 @@
'PhabricatorRepositoryTestCase' => 'PhabricatorTestCase',
'PhabricatorRepositoryTransaction' => 'PhabricatorApplicationTransaction',
'PhabricatorRepositoryTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+ 'PhabricatorRepositoryVCSPassword' => 'PhabricatorRepositoryDAO',
'PhabricatorS3FileStorageEngine' => 'PhabricatorFileStorageEngine',
'PhabricatorSSHWorkflow' => 'PhutilArgumentWorkflow',
'PhabricatorSavedQuery' =>
Index: src/applications/diffusion/application/PhabricatorApplicationDiffusion.php
===================================================================
--- src/applications/diffusion/application/PhabricatorApplicationDiffusion.php
+++ src/applications/diffusion/application/PhabricatorApplicationDiffusion.php
@@ -78,6 +78,7 @@
'hosting/' => 'DiffusionRepositoryEditHostingController',
'(?P<serve>serve)/' => 'DiffusionRepositoryEditHostingController',
),
+ 'password/' => 'DiffusionSetPasswordController',
),
// NOTE: This must come after the rule above; it just gives us a
Index: src/applications/diffusion/controller/DiffusionRepositoryController.php
===================================================================
--- src/applications/diffusion/controller/DiffusionRepositoryController.php
+++ src/applications/diffusion/controller/DiffusionRepositoryController.php
@@ -329,6 +329,8 @@
$view_uri = $this->getApplicationURI($repository->getCallsign().'/');
$edit_uri = $this->getApplicationURI($repository->getCallsign().'/edit/');
+ $password_uri =
+ $this->getApplicationURI($repository->getCallsign().'/password/');
$view = id(new PhabricatorActionListView())
->setUser($viewer)
@@ -348,6 +350,16 @@
->setWorkflow(!$can_edit)
->setDisabled(!$can_edit));
+ if ($repository->isHosted() && $repository->getServeOverHTTP()) {
+ $view->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Set HTTP Access Password'))
+ ->setIcon('lock')
+ ->setHref($password_uri)
+ ->setWorkflow(!$viewer->isLoggedIn())
+ ->setDisabled(!$viewer->isLoggedIn()));
+ }
+
return $view;
}
Index: src/applications/diffusion/controller/DiffusionSetPasswordController.php
===================================================================
--- /dev/null
+++ src/applications/diffusion/controller/DiffusionSetPasswordController.php
@@ -0,0 +1,104 @@
+<?php
+
+final class DiffusionSetPasswordController
+ extends DiffusionController {
+
+ public function processRequest() {
+ $request = $this->getRequest();
+ $user = $request->getUser();
+ $drequest = $this->diffusionRequest;
+ $repository = $drequest->getRepository();
+
+ $repository = id(new PhabricatorRepositoryQuery())
+ ->setViewer($user)
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ ))
+ ->withIDs(array($repository->getID()))
+ ->executeOne();
+
+ if (!$repository) {
+ return new Aphront404Response();
+ }
+
+ $return_uri = $this->getRepositoryControllerURI($repository, '');
+
+ $vcspassword = id(new PhabricatorRepositoryVCSPassword())
+ ->loadOneWhere(
+ 'userPHID = %s',
+ $user->getPHID());
+ if ($vcspassword === null) {
+ // Create new entry.
+ $vcspassword = id(new PhabricatorRepositoryVCSPassword());
+ $vcspassword->setUserPHID($user->getPHID());
+ }
+
+ $errors = array();
+
+ if ($request->isFormPost()) {
+ $newpassword = $request->getStr('password');
+
+ if (!$errors) {
+ $vcspassword->setPassword($newpassword);
+ $vcspassword->save();
+
+ return id(new AphrontRedirectResponse())->setURI($return_uri);
+ }
+ }
+
+ $crumbs = $this->buildApplicationCrumbs();
+ $crumbs->addCrumb(
+ id(new PhabricatorCrumbView())
+ ->setName(pht('Set Password')));
+
+ $title = pht('Set HTTP Password');
+
+ $error_view = null;
+ if ($errors) {
+ $error_view = id(new AphrontErrorView())
+ ->setTitle(pht('Form Errors'))
+ ->setErrors($errors);
+ }
+
+ $form = id(new AphrontFormView())
+ ->setUser($user)
+ ->appendRemarkupInstructions($this->getPasswordInstructions())
+ ->appendChild(
+ id(new AphrontFormTextControl())
+ ->setName('password')
+ ->setLabel(pht('New HTTP Access Password')))
+ ->appendChild(
+ id(new AphrontFormSubmitControl())
+ ->setValue(pht('Change Password'))
+ ->addCancelButton($return_uri));
+
+ $object_box = id(new PHUIObjectBoxView())
+ ->setHeaderText($title)
+ ->setForm($form)
+ ->setFormError($error_view);
+
+ return $this->buildApplicationPage(
+ array(
+ $crumbs,
+ $object_box,
+ ),
+ array(
+ 'title' => $title,
+ 'device' => true,
+ ));
+ }
+
+ private function getPasswordInstructions() {
+ return pht(<<<EOT
+To access this repository over HTTP, you must set a version control password.
+This password should not be the same as the password you use to login to your
+Phabricator account.
+
+**This password applies for all repositories available over HTTP.**
+
+EOT
+ );
+ }
+
+}
Index: src/applications/repository/storage/PhabricatorRepositoryVCSPassword.php
===================================================================
--- /dev/null
+++ src/applications/repository/storage/PhabricatorRepositoryVCSPassword.php
@@ -0,0 +1,20 @@
+<?php
+
+final class PhabricatorRepositoryVCSPassword extends PhabricatorRepositoryDAO {
+
+ protected $id;
+ protected $userPHID;
+ protected $passwordHash;
+
+ public function setPassword($newpassword) {
+ $this->setPasswordHash($this->hashPassword($newpassword));
+ }
+
+ /**
+ * Hash the password for comparison with entries in the DB.
+ */
+ public function hashPassword($password) {
+ return sha1($password);
+ }
+
+}
Index: src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
===================================================================
--- src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
+++ src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
@@ -1712,6 +1712,10 @@
'type' => 'sql',
'name' => $this->getPatchPath('20131026.commitstatus.sql'),
),
+ '20131031.vcspassword.sql' => array(
+ 'type' => 'sql',
+ 'name' => $this->getPatchPath('20131031.vcspassword.sql'),
+ ),
);
}
}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 3, 4:10 AM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6744061
Default Alt Text
D7462.id16830.diff (9 KB)

Event Timeline