2013-06-20 20:18:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$config_map = array(
|
2014-07-22 13:18:15 +02:00
|
|
|
'PhabricatorLDAPAuthProvider' => array(
|
2013-06-20 20:18:11 +02:00
|
|
|
'enabled' => 'ldap.auth-enabled',
|
|
|
|
'registration' => true,
|
|
|
|
'type' => 'ldap',
|
|
|
|
'domain' => 'self',
|
|
|
|
),
|
|
|
|
'PhabricatorAuthProviderOAuthDisqus' => array(
|
|
|
|
'enabled' => 'disqus.auth-enabled',
|
|
|
|
'registration' => 'disqus.registration-enabled',
|
|
|
|
'permanent' => 'disqus.auth-permanent',
|
|
|
|
'oauth.id' => 'disqus.application-id',
|
|
|
|
'oauth.secret' => 'disqus.application-secret',
|
|
|
|
'type' => 'disqus',
|
|
|
|
'domain' => 'disqus.com',
|
|
|
|
),
|
2014-07-22 13:18:15 +02:00
|
|
|
'PhabricatorFacebookAuthProvider' => array(
|
2013-06-20 20:18:11 +02:00
|
|
|
'enabled' => 'facebook.auth-enabled',
|
|
|
|
'registration' => 'facebook.registration-enabled',
|
|
|
|
'permanent' => 'facebook.auth-permanent',
|
|
|
|
'oauth.id' => 'facebook.application-id',
|
|
|
|
'oauth.secret' => 'facebook.application-secret',
|
|
|
|
'type' => 'facebook',
|
|
|
|
'domain' => 'facebook.com',
|
|
|
|
),
|
|
|
|
'PhabricatorAuthProviderOAuthGitHub' => array(
|
|
|
|
'enabled' => 'github.auth-enabled',
|
|
|
|
'registration' => 'github.registration-enabled',
|
|
|
|
'permanent' => 'github.auth-permanent',
|
|
|
|
'oauth.id' => 'github.application-id',
|
|
|
|
'oauth.secret' => 'github.application-secret',
|
|
|
|
'type' => 'github',
|
|
|
|
'domain' => 'github.com',
|
|
|
|
),
|
|
|
|
'PhabricatorAuthProviderOAuthGoogle' => array(
|
|
|
|
'enabled' => 'google.auth-enabled',
|
|
|
|
'registration' => 'google.registration-enabled',
|
|
|
|
'permanent' => 'google.auth-permanent',
|
|
|
|
'oauth.id' => 'google.application-id',
|
|
|
|
'oauth.secret' => 'google.application-secret',
|
|
|
|
'type' => 'google',
|
|
|
|
'domain' => 'google.com',
|
|
|
|
),
|
2014-07-22 13:18:15 +02:00
|
|
|
'PhabricatorPasswordAuthProvider' => array(
|
2013-06-20 20:18:11 +02:00
|
|
|
'enabled' => 'auth.password-auth-enabled',
|
2013-10-05 17:02:41 +02:00
|
|
|
'enabled-default' => false,
|
2013-06-20 20:18:11 +02:00
|
|
|
'registration' => false,
|
|
|
|
'type' => 'password',
|
|
|
|
'domain' => 'self',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($config_map as $provider_class => $spec) {
|
|
|
|
$enabled_key = idx($spec, 'enabled');
|
2013-06-20 20:20:41 +02:00
|
|
|
$enabled_default = idx($spec, 'enabled-default', false);
|
|
|
|
$enabled = PhabricatorEnv::getEnvConfigIfExists(
|
|
|
|
$enabled_key,
|
|
|
|
$enabled_default);
|
2013-06-20 20:18:11 +02:00
|
|
|
|
|
|
|
if (!$enabled) {
|
2015-05-22 09:27:56 +02:00
|
|
|
echo pht('Skipping %s (not enabled).', $provider_class)."\n";
|
2013-06-20 20:18:11 +02:00
|
|
|
// This provider was not previously enabled, so we can skip migrating it.
|
|
|
|
continue;
|
|
|
|
} else {
|
2015-05-22 09:27:56 +02:00
|
|
|
echo pht('Migrating %s...', $provider_class)."\n";
|
2013-06-20 20:18:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$registration_key = idx($spec, 'registration');
|
|
|
|
if ($registration_key === true) {
|
|
|
|
$registration = 1;
|
|
|
|
} else if ($registration_key === false) {
|
|
|
|
$registration = 0;
|
|
|
|
} else {
|
|
|
|
$registration = (int)PhabricatorEnv::getEnvConfigIfExists(
|
|
|
|
$registration_key,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$unlink_key = idx($spec, 'permanent');
|
|
|
|
if (!$unlink_key) {
|
|
|
|
$unlink = 1;
|
|
|
|
} else {
|
|
|
|
$unlink = (int)(!PhabricatorEnv::getEnvConfigIfExists($unlink_key));
|
|
|
|
}
|
|
|
|
|
|
|
|
$config = id(new PhabricatorAuthProviderConfig())
|
|
|
|
->setIsEnabled(1)
|
|
|
|
->setShouldAllowLogin(1)
|
|
|
|
->setShouldAllowRegistration($registration)
|
|
|
|
->setShouldAllowLink(1)
|
|
|
|
->setShouldAllowUnlink($unlink)
|
|
|
|
->setProviderType(idx($spec, 'type'))
|
|
|
|
->setProviderDomain(idx($spec, 'domain'))
|
|
|
|
->setProviderClass($provider_class);
|
|
|
|
|
|
|
|
if (isset($spec['oauth.id'])) {
|
|
|
|
$config->setProperty(
|
|
|
|
PhabricatorAuthProviderOAuth::PROPERTY_APP_ID,
|
|
|
|
PhabricatorEnv::getEnvConfigIfExists(idx($spec, 'oauth.id')));
|
|
|
|
$config->setProperty(
|
|
|
|
PhabricatorAuthProviderOAuth::PROPERTY_APP_SECRET,
|
|
|
|
PhabricatorEnv::getEnvConfigIfExists(idx($spec, 'oauth.secret')));
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($provider_class) {
|
2014-07-22 13:18:15 +02:00
|
|
|
case 'PhabricatorFacebookAuthProvider':
|
2013-06-20 20:18:11 +02:00
|
|
|
$config->setProperty(
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorFacebookAuthProvider::KEY_REQUIRE_SECURE,
|
2013-06-20 20:18:11 +02:00
|
|
|
(int)PhabricatorEnv::getEnvConfigIfExists(
|
|
|
|
'facebook.require-https-auth'));
|
|
|
|
break;
|
2014-07-22 13:18:15 +02:00
|
|
|
case 'PhabricatorLDAPAuthProvider':
|
2013-06-20 20:18:11 +02:00
|
|
|
|
|
|
|
$ldap_map = array(
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_HOSTNAME
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.hostname',
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_PORT
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.port',
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_DISTINGUISHED_NAME
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.base_dn',
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_SEARCH_ATTRIBUTES
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.search_attribute',
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_USERNAME_ATTRIBUTE
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.username-attribute',
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_REALNAME_ATTRIBUTES
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.real_name_attributes',
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_VERSION
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.version',
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_REFERRALS
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.referrals',
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_START_TLS
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.start-tls',
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_ANONYMOUS_USERNAME
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.anonymous-user-name',
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_ANONYMOUS_PASSWORD
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.anonymous-user-password',
|
2014-04-08 20:36:23 +02:00
|
|
|
// Update the old "search first" setting to the newer but similar
|
|
|
|
// "always search" setting.
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_ALWAYS_SEARCH
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.search-first',
|
2014-07-22 13:18:15 +02:00
|
|
|
PhabricatorLDAPAuthProvider::KEY_ACTIVEDIRECTORY_DOMAIN
|
2013-06-20 20:18:11 +02:00
|
|
|
=> 'ldap.activedirectory_domain',
|
|
|
|
);
|
|
|
|
|
|
|
|
$defaults = array(
|
|
|
|
'ldap.version' => 3,
|
|
|
|
'ldap.port' => 389,
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($ldap_map as $pkey => $ckey) {
|
|
|
|
$default = idx($defaults, $ckey);
|
|
|
|
$config->setProperty(
|
|
|
|
$pkey,
|
|
|
|
PhabricatorEnv::getEnvConfigIfExists($ckey, $default));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$config->save();
|
|
|
|
}
|
|
|
|
|
2015-05-22 09:27:56 +02:00
|
|
|
echo pht('Done.')."\n";
|