@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3$config_map = array(
4 'PhabricatorLDAPAuthProvider' => array(
5 'enabled' => 'ldap.auth-enabled',
6 'registration' => true,
7 'type' => 'ldap',
8 'domain' => 'self',
9 ),
10 'PhabricatorAuthProviderOAuthDisqus' => array(
11 'enabled' => 'disqus.auth-enabled',
12 'registration' => 'disqus.registration-enabled',
13 'permanent' => 'disqus.auth-permanent',
14 'oauth.id' => 'disqus.application-id',
15 'oauth.secret' => 'disqus.application-secret',
16 'type' => 'disqus',
17 'domain' => 'disqus.com',
18 ),
19 'PhabricatorFacebookAuthProvider' => array(
20 'enabled' => 'facebook.auth-enabled',
21 'registration' => 'facebook.registration-enabled',
22 'permanent' => 'facebook.auth-permanent',
23 'oauth.id' => 'facebook.application-id',
24 'oauth.secret' => 'facebook.application-secret',
25 'type' => 'facebook',
26 'domain' => 'facebook.com',
27 ),
28 'PhabricatorAuthProviderOAuthGitHub' => array(
29 'enabled' => 'github.auth-enabled',
30 'registration' => 'github.registration-enabled',
31 'permanent' => 'github.auth-permanent',
32 'oauth.id' => 'github.application-id',
33 'oauth.secret' => 'github.application-secret',
34 'type' => 'github',
35 'domain' => 'github.com',
36 ),
37 'PhabricatorAuthProviderOAuthGoogle' => array(
38 'enabled' => 'google.auth-enabled',
39 'registration' => 'google.registration-enabled',
40 'permanent' => 'google.auth-permanent',
41 'oauth.id' => 'google.application-id',
42 'oauth.secret' => 'google.application-secret',
43 'type' => 'google',
44 'domain' => 'google.com',
45 ),
46 'PhabricatorPasswordAuthProvider' => array(
47 'enabled' => 'auth.password-auth-enabled',
48 'enabled-default' => false,
49 'registration' => false,
50 'type' => 'password',
51 'domain' => 'self',
52 ),
53);
54
55foreach ($config_map as $provider_class => $spec) {
56 $enabled_key = idx($spec, 'enabled');
57 $enabled_default = idx($spec, 'enabled-default', false);
58 $enabled = PhabricatorEnv::getEnvConfigIfExists(
59 $enabled_key,
60 $enabled_default);
61
62 if (!$enabled) {
63 echo pht('Skipping %s (not enabled).', $provider_class)."\n";
64 // This provider was not previously enabled, so we can skip migrating it.
65 continue;
66 } else {
67 echo pht('Migrating %s...', $provider_class)."\n";
68 }
69
70 $registration_key = idx($spec, 'registration');
71 if ($registration_key === true) {
72 $registration = 1;
73 } else if ($registration_key === false) {
74 $registration = 0;
75 } else {
76 $registration = (int)PhabricatorEnv::getEnvConfigIfExists(
77 $registration_key,
78 true);
79 }
80
81 $unlink_key = idx($spec, 'permanent');
82 if (!$unlink_key) {
83 $unlink = 1;
84 } else {
85 $unlink = (int)(!PhabricatorEnv::getEnvConfigIfExists($unlink_key));
86 }
87
88 $config = id(new PhabricatorAuthProviderConfig())
89 ->setIsEnabled(1)
90 ->setShouldAllowLogin(1)
91 ->setShouldAllowRegistration($registration)
92 ->setShouldAllowLink(1)
93 ->setShouldAllowUnlink($unlink)
94 ->setProviderType(idx($spec, 'type'))
95 ->setProviderDomain(idx($spec, 'domain'))
96 ->setProviderClass($provider_class);
97
98 if (isset($spec['oauth.id'])) {
99 $config->setProperty(
100 PhabricatorAuthProviderOAuth::PROPERTY_APP_ID,
101 PhabricatorEnv::getEnvConfigIfExists(idx($spec, 'oauth.id')));
102 $config->setProperty(
103 PhabricatorAuthProviderOAuth::PROPERTY_APP_SECRET,
104 PhabricatorEnv::getEnvConfigIfExists(idx($spec, 'oauth.secret')));
105 }
106
107 switch ($provider_class) {
108 case 'PhabricatorFacebookAuthProvider':
109 $config->setProperty(
110 PhabricatorFacebookAuthProvider::KEY_REQUIRE_SECURE,
111 (int)PhabricatorEnv::getEnvConfigIfExists(
112 'facebook.require-https-auth'));
113 break;
114 case 'PhabricatorLDAPAuthProvider':
115
116 $ldap_map = array(
117 PhabricatorLDAPAuthProvider::KEY_HOSTNAME
118 => 'ldap.hostname',
119 PhabricatorLDAPAuthProvider::KEY_PORT
120 => 'ldap.port',
121 PhabricatorLDAPAuthProvider::KEY_DISTINGUISHED_NAME
122 => 'ldap.base_dn',
123 PhabricatorLDAPAuthProvider::KEY_SEARCH_ATTRIBUTES
124 => 'ldap.search_attribute',
125 PhabricatorLDAPAuthProvider::KEY_USERNAME_ATTRIBUTE
126 => 'ldap.username-attribute',
127 PhabricatorLDAPAuthProvider::KEY_REALNAME_ATTRIBUTES
128 => 'ldap.real_name_attributes',
129 PhabricatorLDAPAuthProvider::KEY_VERSION
130 => 'ldap.version',
131 PhabricatorLDAPAuthProvider::KEY_REFERRALS
132 => 'ldap.referrals',
133 PhabricatorLDAPAuthProvider::KEY_START_TLS
134 => 'ldap.start-tls',
135 PhabricatorLDAPAuthProvider::KEY_ANONYMOUS_USERNAME
136 => 'ldap.anonymous-user-name',
137 PhabricatorLDAPAuthProvider::KEY_ANONYMOUS_PASSWORD
138 => 'ldap.anonymous-user-password',
139 // Update the old "search first" setting to the newer but similar
140 // "always search" setting.
141 PhabricatorLDAPAuthProvider::KEY_ALWAYS_SEARCH
142 => 'ldap.search-first',
143 PhabricatorLDAPAuthProvider::KEY_ACTIVEDIRECTORY_DOMAIN
144 => 'ldap.activedirectory_domain',
145 );
146
147 $defaults = array(
148 'ldap.version' => 3,
149 'ldap.port' => 389,
150 );
151
152 foreach ($ldap_map as $pkey => $ckey) {
153 $default = idx($defaults, $ckey);
154 $config->setProperty(
155 $pkey,
156 PhabricatorEnv::getEnvConfigIfExists($ckey, $default));
157 }
158 break;
159 }
160
161 $config->save();
162}
163
164echo pht('Done.')."\n";