mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 04:50:55 +01:00
7f11e8d740
Summary: Small step forward which improves existing stuff or lays groudwork for future stuff: - Currently, to check for email verification, we have to single-query the email address on every page. Instead, denoramlize it into the user object. - Migrate all the existing users. - When the user verifies an email, mark them as `isEmailVerified` if the email is their primary email. - Just make the checks look at the `isEmailVerified` field. - Add a new check, `isUserActivated()`, to cover email-verified plus disabled. Currently, a non-verified-but-not-disabled user could theoretically use Conduit over SSH, if anyone deployed it. Tighten that up. - Add an `isApproved` flag, which is always true for now. In a future diff, I want to add a default-on admin approval queue for new accounts, to prevent configuration mistakes. The way it will work is: - When the queue is enabled, registering users are created with `isApproved = false`. - Admins are sent an email, "[Phabricator] New User Approval (alincoln)", telling them that a new user is waiting for approval. - They go to the web UI and approve the user. - Manually-created accounts are auto-approved. - The email will have instructions for disabling the queue. I think this queue will be helpful for new installs and give them peace of mind, and when you go to disable it we have a better opportunity to warn you about exactly what that means. Generally, I want to improve the default safety of registration, since if you just blindly coast through the path of least resistance right now your install ends up pretty open, and realistically few installs are on VPNs. Test Plan: - Ran migration, verified `isEmailVerified` populated correctly. - Created a new user, checked DB for verified (not verified). - Verified, checked DB (now verified). - Used Conduit, People, Diffusion. Reviewers: btrahan Reviewed By: btrahan CC: chad, aran Differential Revision: https://secure.phabricator.com/D7572
108 lines
2.8 KiB
PHP
Executable file
108 lines
2.8 KiB
PHP
Executable file
#!/usr/bin/env php
|
|
<?php
|
|
|
|
$root = dirname(dirname(dirname(__FILE__)));
|
|
require_once $root.'/scripts/__init_script__.php';
|
|
|
|
// First, figure out the authenticated user.
|
|
$args = new PhutilArgumentParser($argv);
|
|
$args->setTagline('receive SSH requests');
|
|
$args->setSynopsis(<<<EOSYNOPSIS
|
|
**ssh-exec** --phabricator-ssh-user __user__ [--ssh-command __commmand__]
|
|
Receive SSH requests.
|
|
EOSYNOPSIS
|
|
);
|
|
|
|
$args->parse(
|
|
array(
|
|
array(
|
|
'name' => 'phabricator-ssh-user',
|
|
'param' => 'username',
|
|
),
|
|
array(
|
|
'name' => 'ssh-command',
|
|
'param' => 'command',
|
|
),
|
|
));
|
|
|
|
try {
|
|
$user_name = $args->getArg('phabricator-ssh-user');
|
|
if (!strlen($user_name)) {
|
|
throw new Exception("No username.");
|
|
}
|
|
|
|
$user = id(new PhabricatorUser())->loadOneWhere(
|
|
'userName = %s',
|
|
$user_name);
|
|
if (!$user) {
|
|
throw new Exception("Invalid username.");
|
|
}
|
|
|
|
if (!$user->isUserActivated()) {
|
|
throw new Exception(pht("Your account is not activated."));
|
|
}
|
|
|
|
if ($args->getArg('ssh-command')) {
|
|
$original_command = $args->getArg('ssh-command');
|
|
} else {
|
|
$original_command = getenv('SSH_ORIGINAL_COMMAND');
|
|
}
|
|
|
|
// Now, rebuild the original command.
|
|
$original_argv = id(new PhutilShellLexer())
|
|
->splitArguments($original_command);
|
|
if (!$original_argv) {
|
|
throw new Exception("No interactive logins.");
|
|
}
|
|
$command = head($original_argv);
|
|
array_unshift($original_argv, 'phabricator-ssh-exec');
|
|
|
|
$original_args = new PhutilArgumentParser($original_argv);
|
|
|
|
$workflows = array(
|
|
new ConduitSSHWorkflow(),
|
|
new DiffusionSSHSubversionServeWorkflow(),
|
|
new DiffusionSSHMercurialServeWorkflow(),
|
|
new DiffusionSSHGitUploadPackWorkflow(),
|
|
new DiffusionSSHGitReceivePackWorkflow(),
|
|
);
|
|
|
|
$workflow_names = mpull($workflows, 'getName', 'getName');
|
|
if (empty($workflow_names[$command])) {
|
|
throw new Exception("Invalid command.");
|
|
}
|
|
|
|
$workflow = $original_args->parseWorkflows($workflows);
|
|
$workflow->setUser($user);
|
|
|
|
$sock_stdin = fopen('php://stdin', 'r');
|
|
if (!$sock_stdin) {
|
|
throw new Exception("Unable to open stdin.");
|
|
}
|
|
|
|
$sock_stdout = fopen('php://stdout', 'w');
|
|
if (!$sock_stdout) {
|
|
throw new Exception("Unable to open stdout.");
|
|
}
|
|
|
|
$sock_stderr = fopen('php://stderr', 'w');
|
|
if (!$sock_stderr) {
|
|
throw new Exception("Unable to open stderr.");
|
|
}
|
|
|
|
$socket_channel = new PhutilSocketChannel(
|
|
$sock_stdin,
|
|
$sock_stdout);
|
|
$error_channel = new PhutilSocketChannel(null, $sock_stderr);
|
|
$metrics_channel = new PhutilMetricsChannel($socket_channel);
|
|
$workflow->setIOChannel($metrics_channel);
|
|
$workflow->setErrorChannel($error_channel);
|
|
|
|
$err = $workflow->execute($original_args);
|
|
|
|
$metrics_channel->flush();
|
|
$error_channel->flush();
|
|
} catch (Exception $ex) {
|
|
fwrite(STDERR, "phabricator-ssh-exec: ".$ex->getMessage()."\n");
|
|
exit(1);
|
|
}
|