@@ -15,26 +15,26 @@ |
||
15 | 15 | |
16 | 16 | class RegenerateStylesheetsTask extends ConsoleTaskBase |
17 | 17 | { |
18 | - const RESOURCES_GENERATED = 'resources/generated'; |
|
18 | + const RESOURCES_GENERATED = 'resources/generated'; |
|
19 | 19 | |
20 | - public function execute() |
|
21 | - { |
|
22 | - $scss = new Compiler(); |
|
23 | - $scss->setImportPaths('resources/scss'); |
|
20 | + public function execute() |
|
21 | + { |
|
22 | + $scss = new Compiler(); |
|
23 | + $scss->setImportPaths('resources/scss'); |
|
24 | 24 | |
25 | - if (!$this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
26 | - $scss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\Compressed'); |
|
27 | - $scss->setSourceMap(Compiler::SOURCE_MAP_INLINE); |
|
28 | - } |
|
25 | + if (!$this->getSiteConfiguration()->getDebuggingTraceEnabled()) { |
|
26 | + $scss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\Compressed'); |
|
27 | + $scss->setSourceMap(Compiler::SOURCE_MAP_INLINE); |
|
28 | + } |
|
29 | 29 | |
30 | - if (!is_dir(self::RESOURCES_GENERATED)) { |
|
31 | - mkdir(self::RESOURCES_GENERATED); |
|
32 | - } |
|
30 | + if (!is_dir(self::RESOURCES_GENERATED)) { |
|
31 | + mkdir(self::RESOURCES_GENERATED); |
|
32 | + } |
|
33 | 33 | |
34 | - foreach (['bootstrap-main', 'bootstrap-alt'] as $file) { |
|
35 | - file_put_contents( |
|
36 | - self::RESOURCES_GENERATED . '/' . $file . '.css', |
|
37 | - $scss->compile('/*! Do not edit this auto-generated file! */ @import "' . $file . '";')); |
|
38 | - } |
|
39 | - } |
|
34 | + foreach (['bootstrap-main', 'bootstrap-alt'] as $file) { |
|
35 | + file_put_contents( |
|
36 | + self::RESOURCES_GENERATED . '/' . $file . '.css', |
|
37 | + $scss->compile('/*! Do not edit this auto-generated file! */ @import "' . $file . '";')); |
|
38 | + } |
|
39 | + } |
|
40 | 40 | } |
@@ -33,8 +33,8 @@ |
||
33 | 33 | |
34 | 34 | foreach (['bootstrap-main', 'bootstrap-alt'] as $file) { |
35 | 35 | file_put_contents( |
36 | - self::RESOURCES_GENERATED . '/' . $file . '.css', |
|
37 | - $scss->compile('/*! Do not edit this auto-generated file! */ @import "' . $file . '";')); |
|
36 | + self::RESOURCES_GENERATED.'/'.$file.'.css', |
|
37 | + $scss->compile('/*! Do not edit this auto-generated file! */ @import "'.$file.'";')); |
|
38 | 38 | } |
39 | 39 | } |
40 | 40 | } |
@@ -62,15 +62,15 @@ |
||
62 | 62 | |
63 | 63 | $usedToken = null; |
64 | 64 | foreach ($scratchTokens as $scratchToken) { |
65 | - if (password_verify($data, $scratchToken)){ |
|
65 | + if (password_verify($data, $scratchToken)) { |
|
66 | 66 | $usedToken = $scratchToken; |
67 | 67 | SessionAlert::quick("Hey, it looks like you used a scratch token to log in. Would you like to change your multi-factor authentication configuration?", 'alert-warning'); |
68 | - WebRequest::setPostLoginRedirect($this->getConfiguration()->getBaseUrl() . "/internal.php/multiFactor"); |
|
68 | + WebRequest::setPostLoginRedirect($this->getConfiguration()->getBaseUrl()."/internal.php/multiFactor"); |
|
69 | 69 | break; |
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
73 | - if($usedToken === null) { |
|
73 | + if ($usedToken === null) { |
|
74 | 74 | return false; |
75 | 75 | } |
76 | 76 |
@@ -62,7 +62,7 @@ |
||
62 | 62 | |
63 | 63 | $usedToken = null; |
64 | 64 | foreach ($scratchTokens as $scratchToken) { |
65 | - if (password_verify($data, $scratchToken)){ |
|
65 | + if (password_verify($data, $scratchToken)) { |
|
66 | 66 | $usedToken = $scratchToken; |
67 | 67 | SessionAlert::quick("Hey, it looks like you used a scratch token to log in. Would you like to change your multi-factor authentication configuration?", 'alert-warning'); |
68 | 68 | WebRequest::setPostLoginRedirect($this->getConfiguration()->getBaseUrl() . "/internal.php/multiFactor"); |
@@ -20,136 +20,136 @@ |
||
20 | 20 | |
21 | 21 | class ScratchTokenCredentialProvider extends CredentialProviderBase |
22 | 22 | { |
23 | - /** @var EncryptionHelper */ |
|
24 | - private $encryptionHelper; |
|
25 | - /** @var array the tokens generated in the last generation round. */ |
|
26 | - private $generatedTokens; |
|
27 | - |
|
28 | - /** |
|
29 | - * ScratchTokenCredentialProvider constructor. |
|
30 | - * |
|
31 | - * @param PdoDatabase $database |
|
32 | - * @param SiteConfiguration $configuration |
|
33 | - */ |
|
34 | - public function __construct(PdoDatabase $database, SiteConfiguration $configuration) |
|
35 | - { |
|
36 | - parent::__construct($database, $configuration, 'scratch'); |
|
37 | - $this->encryptionHelper = new EncryptionHelper($configuration); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Validates a user-provided credential |
|
42 | - * |
|
43 | - * @param User $user The user to test the authentication against |
|
44 | - * @param string $data The raw credential data to be validated |
|
45 | - * |
|
46 | - * @return bool |
|
47 | - * @throws ApplicationLogicException|OptimisticLockFailedException |
|
48 | - */ |
|
49 | - public function authenticate(User $user, $data) |
|
50 | - { |
|
51 | - if (is_array($data)) { |
|
52 | - return false; |
|
53 | - } |
|
54 | - |
|
55 | - $storedData = $this->getCredentialData($user->getId()); |
|
56 | - |
|
57 | - if ($storedData === null) { |
|
58 | - throw new ApplicationLogicException('Credential data not found'); |
|
59 | - } |
|
60 | - |
|
61 | - $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
62 | - |
|
63 | - $usedToken = null; |
|
64 | - foreach ($scratchTokens as $scratchToken) { |
|
65 | - if (password_verify($data, $scratchToken)){ |
|
66 | - $usedToken = $scratchToken; |
|
67 | - SessionAlert::quick("Hey, it looks like you used a scratch token to log in. Would you like to change your multi-factor authentication configuration?", 'alert-warning'); |
|
68 | - WebRequest::setPostLoginRedirect($this->getConfiguration()->getBaseUrl() . "/internal.php/multiFactor"); |
|
69 | - break; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - if($usedToken === null) { |
|
74 | - return false; |
|
75 | - } |
|
76 | - |
|
77 | - $scratchTokens = array_diff($scratchTokens, [$usedToken]); |
|
78 | - |
|
79 | - $storedData->setData($this->encryptionHelper->encryptData(serialize($scratchTokens))); |
|
80 | - $storedData->save(); |
|
81 | - |
|
82 | - return true; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param User $user The user the credential belongs to |
|
87 | - * @param int $factor The factor this credential provides |
|
88 | - * @param string $data Unused. |
|
89 | - * |
|
90 | - * @throws OptimisticLockFailedException |
|
91 | - */ |
|
92 | - public function setCredential(User $user, $factor, $data) |
|
93 | - { |
|
94 | - $plaintextScratch = array(); |
|
95 | - $storedScratch = array(); |
|
96 | - for ($i = 0; $i < 5; $i++) { |
|
97 | - $token = Base32::encodeUpper(openssl_random_pseudo_bytes(10)); |
|
98 | - $plaintextScratch[] = $token; |
|
99 | - |
|
100 | - $storedScratch[] = password_hash( |
|
101 | - $token, |
|
102 | - PasswordCredentialProvider::PASSWORD_ALGO, |
|
103 | - array('cost' => PasswordCredentialProvider::PASSWORD_COST) |
|
104 | - ); |
|
105 | - } |
|
106 | - |
|
107 | - $storedData = $this->getCredentialData($user->getId(), null); |
|
108 | - |
|
109 | - if ($storedData !== null) { |
|
110 | - $storedData->delete(); |
|
111 | - } |
|
112 | - |
|
113 | - $storedData = $this->createNewCredential($user); |
|
114 | - |
|
115 | - $storedData->setData($this->encryptionHelper->encryptData(serialize($storedScratch))); |
|
116 | - $storedData->setFactor($factor); |
|
117 | - $storedData->setVersion(1); |
|
118 | - $storedData->setPriority(9); |
|
119 | - |
|
120 | - $storedData->save(); |
|
121 | - $this->generatedTokens = $plaintextScratch; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Gets the count of remaining valid tokens |
|
126 | - * |
|
127 | - * @param int $userId |
|
128 | - * |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function getRemaining($userId) |
|
132 | - { |
|
133 | - $storedData = $this->getCredentialData($userId); |
|
134 | - |
|
135 | - if ($storedData === null) { |
|
136 | - return 0; |
|
137 | - } |
|
138 | - |
|
139 | - $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
140 | - |
|
141 | - return count($scratchTokens); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @return array |
|
146 | - */ |
|
147 | - public function getTokens() |
|
148 | - { |
|
149 | - if ($this->generatedTokens != null) { |
|
150 | - return $this->generatedTokens; |
|
151 | - } |
|
152 | - |
|
153 | - return array(); |
|
154 | - } |
|
23 | + /** @var EncryptionHelper */ |
|
24 | + private $encryptionHelper; |
|
25 | + /** @var array the tokens generated in the last generation round. */ |
|
26 | + private $generatedTokens; |
|
27 | + |
|
28 | + /** |
|
29 | + * ScratchTokenCredentialProvider constructor. |
|
30 | + * |
|
31 | + * @param PdoDatabase $database |
|
32 | + * @param SiteConfiguration $configuration |
|
33 | + */ |
|
34 | + public function __construct(PdoDatabase $database, SiteConfiguration $configuration) |
|
35 | + { |
|
36 | + parent::__construct($database, $configuration, 'scratch'); |
|
37 | + $this->encryptionHelper = new EncryptionHelper($configuration); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Validates a user-provided credential |
|
42 | + * |
|
43 | + * @param User $user The user to test the authentication against |
|
44 | + * @param string $data The raw credential data to be validated |
|
45 | + * |
|
46 | + * @return bool |
|
47 | + * @throws ApplicationLogicException|OptimisticLockFailedException |
|
48 | + */ |
|
49 | + public function authenticate(User $user, $data) |
|
50 | + { |
|
51 | + if (is_array($data)) { |
|
52 | + return false; |
|
53 | + } |
|
54 | + |
|
55 | + $storedData = $this->getCredentialData($user->getId()); |
|
56 | + |
|
57 | + if ($storedData === null) { |
|
58 | + throw new ApplicationLogicException('Credential data not found'); |
|
59 | + } |
|
60 | + |
|
61 | + $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
62 | + |
|
63 | + $usedToken = null; |
|
64 | + foreach ($scratchTokens as $scratchToken) { |
|
65 | + if (password_verify($data, $scratchToken)){ |
|
66 | + $usedToken = $scratchToken; |
|
67 | + SessionAlert::quick("Hey, it looks like you used a scratch token to log in. Would you like to change your multi-factor authentication configuration?", 'alert-warning'); |
|
68 | + WebRequest::setPostLoginRedirect($this->getConfiguration()->getBaseUrl() . "/internal.php/multiFactor"); |
|
69 | + break; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + if($usedToken === null) { |
|
74 | + return false; |
|
75 | + } |
|
76 | + |
|
77 | + $scratchTokens = array_diff($scratchTokens, [$usedToken]); |
|
78 | + |
|
79 | + $storedData->setData($this->encryptionHelper->encryptData(serialize($scratchTokens))); |
|
80 | + $storedData->save(); |
|
81 | + |
|
82 | + return true; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param User $user The user the credential belongs to |
|
87 | + * @param int $factor The factor this credential provides |
|
88 | + * @param string $data Unused. |
|
89 | + * |
|
90 | + * @throws OptimisticLockFailedException |
|
91 | + */ |
|
92 | + public function setCredential(User $user, $factor, $data) |
|
93 | + { |
|
94 | + $plaintextScratch = array(); |
|
95 | + $storedScratch = array(); |
|
96 | + for ($i = 0; $i < 5; $i++) { |
|
97 | + $token = Base32::encodeUpper(openssl_random_pseudo_bytes(10)); |
|
98 | + $plaintextScratch[] = $token; |
|
99 | + |
|
100 | + $storedScratch[] = password_hash( |
|
101 | + $token, |
|
102 | + PasswordCredentialProvider::PASSWORD_ALGO, |
|
103 | + array('cost' => PasswordCredentialProvider::PASSWORD_COST) |
|
104 | + ); |
|
105 | + } |
|
106 | + |
|
107 | + $storedData = $this->getCredentialData($user->getId(), null); |
|
108 | + |
|
109 | + if ($storedData !== null) { |
|
110 | + $storedData->delete(); |
|
111 | + } |
|
112 | + |
|
113 | + $storedData = $this->createNewCredential($user); |
|
114 | + |
|
115 | + $storedData->setData($this->encryptionHelper->encryptData(serialize($storedScratch))); |
|
116 | + $storedData->setFactor($factor); |
|
117 | + $storedData->setVersion(1); |
|
118 | + $storedData->setPriority(9); |
|
119 | + |
|
120 | + $storedData->save(); |
|
121 | + $this->generatedTokens = $plaintextScratch; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Gets the count of remaining valid tokens |
|
126 | + * |
|
127 | + * @param int $userId |
|
128 | + * |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function getRemaining($userId) |
|
132 | + { |
|
133 | + $storedData = $this->getCredentialData($userId); |
|
134 | + |
|
135 | + if ($storedData === null) { |
|
136 | + return 0; |
|
137 | + } |
|
138 | + |
|
139 | + $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
140 | + |
|
141 | + return count($scratchTokens); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @return array |
|
146 | + */ |
|
147 | + public function getTokens() |
|
148 | + { |
|
149 | + if ($this->generatedTokens != null) { |
|
150 | + return $this->generatedTokens; |
|
151 | + } |
|
152 | + |
|
153 | + return array(); |
|
154 | + } |
|
155 | 155 | } |
@@ -22,567 +22,567 @@ |
||
22 | 22 | */ |
23 | 23 | class WebRequest |
24 | 24 | { |
25 | - /** |
|
26 | - * @var \Waca\Providers\GlobalState\IGlobalStateProvider Provides access to the global state. |
|
27 | - */ |
|
28 | - private static $globalStateProvider; |
|
29 | - |
|
30 | - /** |
|
31 | - * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public static function wasPosted() |
|
35 | - { |
|
36 | - return self::method() === 'POST'; |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Gets the HTTP Method used |
|
41 | - * @return string|null |
|
42 | - */ |
|
43 | - public static function method() |
|
44 | - { |
|
45 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
46 | - |
|
47 | - if (isset($server['REQUEST_METHOD'])) { |
|
48 | - return $server['REQUEST_METHOD']; |
|
49 | - } |
|
50 | - |
|
51 | - return null; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public static function isHttps() |
|
59 | - { |
|
60 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
61 | - |
|
62 | - if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
63 | - if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
64 | - // Client <=> Proxy is encrypted |
|
65 | - return true; |
|
66 | - } |
|
67 | - else { |
|
68 | - // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
69 | - return false; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - if (isset($server['HTTPS'])) { |
|
74 | - if ($server['HTTPS'] === 'off') { |
|
75 | - // ISAPI on IIS breaks the spec. :( |
|
76 | - return false; |
|
77 | - } |
|
78 | - |
|
79 | - if ($server['HTTPS'] !== '') { |
|
80 | - // Set to a non-empty value |
|
81 | - return true; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - return false; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Gets the path info |
|
90 | - * |
|
91 | - * @return array Array of path info segments |
|
92 | - */ |
|
93 | - public static function pathInfo() |
|
94 | - { |
|
95 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
96 | - if (!isset($server['PATH_INFO'])) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $exploded = explode('/', $server['PATH_INFO']); |
|
101 | - |
|
102 | - // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
103 | - // with a / |
|
104 | - return array_values(array_filter($exploded)); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Gets the remote address of the web request |
|
109 | - * @return null|string |
|
110 | - */ |
|
111 | - public static function remoteAddress() |
|
112 | - { |
|
113 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
114 | - |
|
115 | - if (isset($server['REMOTE_ADDR'])) { |
|
116 | - return $server['REMOTE_ADDR']; |
|
117 | - } |
|
118 | - |
|
119 | - return null; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Gets the remote address of the web request |
|
124 | - * @return null|string |
|
125 | - */ |
|
126 | - public static function httpHost() |
|
127 | - { |
|
128 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
129 | - |
|
130 | - if (isset($server['HTTP_HOST'])) { |
|
131 | - return $server['HTTP_HOST']; |
|
132 | - } |
|
133 | - |
|
134 | - return null; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Gets the XFF header contents for the web request |
|
139 | - * @return null|string |
|
140 | - */ |
|
141 | - public static function forwardedAddress() |
|
142 | - { |
|
143 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
144 | - |
|
145 | - if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
146 | - return $server['HTTP_X_FORWARDED_FOR']; |
|
147 | - } |
|
148 | - |
|
149 | - return null; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Sets the global state provider. |
|
154 | - * |
|
155 | - * Almost guaranteed this is not the method you want in production code. |
|
156 | - * |
|
157 | - * @param \Waca\Providers\GlobalState\IGlobalStateProvider $globalState |
|
158 | - */ |
|
159 | - public static function setGlobalStateProvider($globalState) |
|
160 | - { |
|
161 | - self::$globalStateProvider = $globalState; |
|
162 | - } |
|
163 | - |
|
164 | - #region POST variables |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $key |
|
168 | - * |
|
169 | - * @return null|string |
|
170 | - */ |
|
171 | - public static function postString($key) |
|
172 | - { |
|
173 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
174 | - if (!array_key_exists($key, $post)) { |
|
175 | - return null; |
|
176 | - } |
|
177 | - |
|
178 | - if ($post[$key] === "") { |
|
179 | - return null; |
|
180 | - } |
|
181 | - |
|
182 | - return (string)$post[$key]; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @param string $key |
|
187 | - * |
|
188 | - * @return null|string |
|
189 | - */ |
|
190 | - public static function postEmail($key) |
|
191 | - { |
|
192 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
193 | - if (!array_key_exists($key, $post)) { |
|
194 | - return null; |
|
195 | - } |
|
196 | - |
|
197 | - $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
198 | - |
|
199 | - if ($filteredValue === false) { |
|
200 | - return null; |
|
201 | - } |
|
202 | - |
|
203 | - return (string)$filteredValue; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @param string $key |
|
208 | - * |
|
209 | - * @return int|null |
|
210 | - */ |
|
211 | - public static function postInt($key) |
|
212 | - { |
|
213 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
214 | - if (!array_key_exists($key, $post)) { |
|
215 | - return null; |
|
216 | - } |
|
217 | - |
|
218 | - $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
219 | - |
|
220 | - if ($filteredValue === null) { |
|
221 | - return null; |
|
222 | - } |
|
223 | - |
|
224 | - return (int)$filteredValue; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @param string $key |
|
229 | - * |
|
230 | - * @return bool |
|
231 | - */ |
|
232 | - public static function postBoolean($key) |
|
233 | - { |
|
234 | - $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
235 | - if (!array_key_exists($key, $get)) { |
|
236 | - return false; |
|
237 | - } |
|
238 | - |
|
239 | - // presence of parameter only |
|
240 | - if ($get[$key] === "") { |
|
241 | - return true; |
|
242 | - } |
|
243 | - |
|
244 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
245 | - return false; |
|
246 | - } |
|
247 | - |
|
248 | - return true; |
|
249 | - } |
|
250 | - |
|
251 | - #endregion |
|
252 | - |
|
253 | - #region GET variables |
|
254 | - |
|
255 | - /** |
|
256 | - * @param string $key |
|
257 | - * |
|
258 | - * @return bool |
|
259 | - */ |
|
260 | - public static function getBoolean($key) |
|
261 | - { |
|
262 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
263 | - if (!array_key_exists($key, $get)) { |
|
264 | - return false; |
|
265 | - } |
|
266 | - |
|
267 | - // presence of parameter only |
|
268 | - if ($get[$key] === "") { |
|
269 | - return true; |
|
270 | - } |
|
271 | - |
|
272 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
273 | - return false; |
|
274 | - } |
|
275 | - |
|
276 | - return true; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * @param string $key |
|
281 | - * |
|
282 | - * @return int|null |
|
283 | - */ |
|
284 | - public static function getInt($key) |
|
285 | - { |
|
286 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
287 | - if (!array_key_exists($key, $get)) { |
|
288 | - return null; |
|
289 | - } |
|
290 | - |
|
291 | - $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
292 | - |
|
293 | - if ($filteredValue === null) { |
|
294 | - return null; |
|
295 | - } |
|
296 | - |
|
297 | - return (int)$filteredValue; |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * @param string $key |
|
302 | - * |
|
303 | - * @return null|string |
|
304 | - */ |
|
305 | - public static function getString($key) |
|
306 | - { |
|
307 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
308 | - if (!array_key_exists($key, $get)) { |
|
309 | - return null; |
|
310 | - } |
|
311 | - |
|
312 | - if ($get[$key] === "") { |
|
313 | - return null; |
|
314 | - } |
|
315 | - |
|
316 | - return (string)$get[$key]; |
|
317 | - } |
|
318 | - |
|
319 | - #endregion |
|
320 | - |
|
321 | - /** |
|
322 | - * Sets the logged-in user to the specified user. |
|
323 | - * |
|
324 | - * @param User $user |
|
325 | - */ |
|
326 | - public static function setLoggedInUser(User $user) |
|
327 | - { |
|
328 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
329 | - |
|
330 | - $session['userID'] = $user->getId(); |
|
331 | - unset($session['partialLogin']); |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Sets the post-login redirect |
|
336 | - * |
|
337 | - * @param string|null $uri The URI to redirect to |
|
338 | - */ |
|
339 | - public static function setPostLoginRedirect($uri = null) |
|
340 | - { |
|
341 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
342 | - |
|
343 | - if ($uri === null) { |
|
344 | - $uri = self::requestUri(); |
|
345 | - } |
|
346 | - |
|
347 | - $session['returnTo'] = $uri; |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * @return string|null |
|
352 | - */ |
|
353 | - public static function requestUri() |
|
354 | - { |
|
355 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
356 | - |
|
357 | - if (isset($server['REQUEST_URI'])) { |
|
358 | - return $server['REQUEST_URI']; |
|
359 | - } |
|
360 | - |
|
361 | - return null; |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * Clears the post-login redirect |
|
366 | - * @return string |
|
367 | - */ |
|
368 | - public static function clearPostLoginRedirect() |
|
369 | - { |
|
370 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
371 | - if (array_key_exists('returnTo', $session)) { |
|
372 | - $path = $session['returnTo']; |
|
373 | - unset($session['returnTo']); |
|
374 | - |
|
375 | - return $path; |
|
376 | - } |
|
377 | - |
|
378 | - return null; |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * @return string|null |
|
383 | - */ |
|
384 | - public static function serverName() |
|
385 | - { |
|
386 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
387 | - |
|
388 | - if (isset($server['SERVER_NAME'])) { |
|
389 | - return $server['SERVER_NAME']; |
|
390 | - } |
|
391 | - |
|
392 | - return null; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * You probably only want to deal with this through SessionAlert. |
|
397 | - * @return void |
|
398 | - */ |
|
399 | - public static function clearSessionAlertData() |
|
400 | - { |
|
401 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
402 | - if (array_key_exists('alerts', $session)) { |
|
403 | - unset($session['alerts']); |
|
404 | - } |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * You probably only want to deal with this through SessionAlert. |
|
409 | - * |
|
410 | - * @return string[] |
|
411 | - */ |
|
412 | - public static function getSessionAlertData() |
|
413 | - { |
|
414 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
415 | - if (array_key_exists('alerts', $session)) { |
|
416 | - return $session['alerts']; |
|
417 | - } |
|
418 | - |
|
419 | - return array(); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * You probably only want to deal with this through SessionAlert. |
|
424 | - * |
|
425 | - * @param string[] $data |
|
426 | - */ |
|
427 | - public static function setSessionAlertData($data) |
|
428 | - { |
|
429 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
430 | - $session['alerts'] = $data; |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * You probably only want to deal with this through TokenManager. |
|
435 | - * |
|
436 | - * @return string[] |
|
437 | - */ |
|
438 | - public static function getSessionTokenData() |
|
439 | - { |
|
440 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
441 | - if (array_key_exists('tokens', $session)) { |
|
442 | - return $session['tokens']; |
|
443 | - } |
|
444 | - |
|
445 | - return array(); |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * You probably only want to deal with this through TokenManager. |
|
450 | - * |
|
451 | - * @param string[] $data |
|
452 | - */ |
|
453 | - public static function setSessionTokenData($data) |
|
454 | - { |
|
455 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
456 | - $session['tokens'] = $data; |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * @param string $key |
|
461 | - * |
|
462 | - * @return mixed |
|
463 | - */ |
|
464 | - public static function getSessionContext($key) |
|
465 | - { |
|
466 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
467 | - |
|
468 | - if (!isset($session['context'])) { |
|
469 | - $session['context'] = array(); |
|
470 | - } |
|
471 | - |
|
472 | - if (!isset($session['context'][$key])) { |
|
473 | - return null; |
|
474 | - } |
|
475 | - |
|
476 | - return $session['context'][$key]; |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * @param string $key |
|
481 | - * @param mixed $data |
|
482 | - */ |
|
483 | - public static function setSessionContext($key, $data) |
|
484 | - { |
|
485 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
486 | - |
|
487 | - if (!isset($session['context'])) { |
|
488 | - $session['context'] = array(); |
|
489 | - } |
|
490 | - |
|
491 | - $session['context'][$key] = $data; |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * @return int|null |
|
496 | - */ |
|
497 | - public static function getSessionUserId() |
|
498 | - { |
|
499 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
500 | - |
|
501 | - return isset($session['userID']) ? (int)$session['userID'] : null; |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * @param User $user |
|
506 | - */ |
|
507 | - public static function setOAuthPartialLogin(User $user) |
|
508 | - { |
|
509 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
510 | - $session['oauthPartialLogin'] = $user->getId(); |
|
511 | - } |
|
512 | - |
|
513 | - /** |
|
514 | - * @return int|null |
|
515 | - */ |
|
516 | - public static function getOAuthPartialLogin() |
|
517 | - { |
|
518 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
519 | - |
|
520 | - return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null; |
|
521 | - } |
|
522 | - |
|
523 | - public static function setAuthPartialLogin($userId, $stage) |
|
524 | - { |
|
525 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
526 | - $session['authPartialLoginId'] = $userId; |
|
527 | - $session['authPartialLoginStage'] = $stage; |
|
528 | - } |
|
529 | - |
|
530 | - public static function getAuthPartialLogin() |
|
531 | - { |
|
532 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
533 | - |
|
534 | - $userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null; |
|
535 | - $stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null; |
|
536 | - |
|
537 | - return array($userId, $stage); |
|
538 | - } |
|
539 | - |
|
540 | - public static function clearAuthPartialLogin() |
|
541 | - { |
|
542 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
543 | - unset($session['authPartialLoginId']); |
|
544 | - unset($session['authPartialLoginStage']); |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * @return null|string |
|
549 | - */ |
|
550 | - public static function userAgent() |
|
551 | - { |
|
552 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
553 | - |
|
554 | - if (isset($server['HTTP_USER_AGENT'])) { |
|
555 | - return $server['HTTP_USER_AGENT']; |
|
556 | - } |
|
557 | - |
|
558 | - return null; |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * @return null|string |
|
563 | - */ |
|
564 | - public static function scriptName() |
|
565 | - { |
|
566 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
567 | - |
|
568 | - if (isset($server['SCRIPT_NAME'])) { |
|
569 | - return $server['SCRIPT_NAME']; |
|
570 | - } |
|
571 | - |
|
572 | - return null; |
|
573 | - } |
|
574 | - |
|
575 | - /** |
|
576 | - * @return null|string |
|
577 | - */ |
|
578 | - public static function origin() |
|
579 | - { |
|
580 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
581 | - |
|
582 | - if (isset($server['HTTP_ORIGIN'])) { |
|
583 | - return $server['HTTP_ORIGIN']; |
|
584 | - } |
|
585 | - |
|
586 | - return null; |
|
587 | - } |
|
25 | + /** |
|
26 | + * @var \Waca\Providers\GlobalState\IGlobalStateProvider Provides access to the global state. |
|
27 | + */ |
|
28 | + private static $globalStateProvider; |
|
29 | + |
|
30 | + /** |
|
31 | + * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public static function wasPosted() |
|
35 | + { |
|
36 | + return self::method() === 'POST'; |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Gets the HTTP Method used |
|
41 | + * @return string|null |
|
42 | + */ |
|
43 | + public static function method() |
|
44 | + { |
|
45 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
46 | + |
|
47 | + if (isset($server['REQUEST_METHOD'])) { |
|
48 | + return $server['REQUEST_METHOD']; |
|
49 | + } |
|
50 | + |
|
51 | + return null; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public static function isHttps() |
|
59 | + { |
|
60 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
61 | + |
|
62 | + if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
63 | + if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
64 | + // Client <=> Proxy is encrypted |
|
65 | + return true; |
|
66 | + } |
|
67 | + else { |
|
68 | + // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
69 | + return false; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + if (isset($server['HTTPS'])) { |
|
74 | + if ($server['HTTPS'] === 'off') { |
|
75 | + // ISAPI on IIS breaks the spec. :( |
|
76 | + return false; |
|
77 | + } |
|
78 | + |
|
79 | + if ($server['HTTPS'] !== '') { |
|
80 | + // Set to a non-empty value |
|
81 | + return true; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + return false; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Gets the path info |
|
90 | + * |
|
91 | + * @return array Array of path info segments |
|
92 | + */ |
|
93 | + public static function pathInfo() |
|
94 | + { |
|
95 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
96 | + if (!isset($server['PATH_INFO'])) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $exploded = explode('/', $server['PATH_INFO']); |
|
101 | + |
|
102 | + // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
103 | + // with a / |
|
104 | + return array_values(array_filter($exploded)); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Gets the remote address of the web request |
|
109 | + * @return null|string |
|
110 | + */ |
|
111 | + public static function remoteAddress() |
|
112 | + { |
|
113 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
114 | + |
|
115 | + if (isset($server['REMOTE_ADDR'])) { |
|
116 | + return $server['REMOTE_ADDR']; |
|
117 | + } |
|
118 | + |
|
119 | + return null; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Gets the remote address of the web request |
|
124 | + * @return null|string |
|
125 | + */ |
|
126 | + public static function httpHost() |
|
127 | + { |
|
128 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
129 | + |
|
130 | + if (isset($server['HTTP_HOST'])) { |
|
131 | + return $server['HTTP_HOST']; |
|
132 | + } |
|
133 | + |
|
134 | + return null; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Gets the XFF header contents for the web request |
|
139 | + * @return null|string |
|
140 | + */ |
|
141 | + public static function forwardedAddress() |
|
142 | + { |
|
143 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
144 | + |
|
145 | + if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
146 | + return $server['HTTP_X_FORWARDED_FOR']; |
|
147 | + } |
|
148 | + |
|
149 | + return null; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Sets the global state provider. |
|
154 | + * |
|
155 | + * Almost guaranteed this is not the method you want in production code. |
|
156 | + * |
|
157 | + * @param \Waca\Providers\GlobalState\IGlobalStateProvider $globalState |
|
158 | + */ |
|
159 | + public static function setGlobalStateProvider($globalState) |
|
160 | + { |
|
161 | + self::$globalStateProvider = $globalState; |
|
162 | + } |
|
163 | + |
|
164 | + #region POST variables |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $key |
|
168 | + * |
|
169 | + * @return null|string |
|
170 | + */ |
|
171 | + public static function postString($key) |
|
172 | + { |
|
173 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
174 | + if (!array_key_exists($key, $post)) { |
|
175 | + return null; |
|
176 | + } |
|
177 | + |
|
178 | + if ($post[$key] === "") { |
|
179 | + return null; |
|
180 | + } |
|
181 | + |
|
182 | + return (string)$post[$key]; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @param string $key |
|
187 | + * |
|
188 | + * @return null|string |
|
189 | + */ |
|
190 | + public static function postEmail($key) |
|
191 | + { |
|
192 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
193 | + if (!array_key_exists($key, $post)) { |
|
194 | + return null; |
|
195 | + } |
|
196 | + |
|
197 | + $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
198 | + |
|
199 | + if ($filteredValue === false) { |
|
200 | + return null; |
|
201 | + } |
|
202 | + |
|
203 | + return (string)$filteredValue; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @param string $key |
|
208 | + * |
|
209 | + * @return int|null |
|
210 | + */ |
|
211 | + public static function postInt($key) |
|
212 | + { |
|
213 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
214 | + if (!array_key_exists($key, $post)) { |
|
215 | + return null; |
|
216 | + } |
|
217 | + |
|
218 | + $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
219 | + |
|
220 | + if ($filteredValue === null) { |
|
221 | + return null; |
|
222 | + } |
|
223 | + |
|
224 | + return (int)$filteredValue; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @param string $key |
|
229 | + * |
|
230 | + * @return bool |
|
231 | + */ |
|
232 | + public static function postBoolean($key) |
|
233 | + { |
|
234 | + $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
235 | + if (!array_key_exists($key, $get)) { |
|
236 | + return false; |
|
237 | + } |
|
238 | + |
|
239 | + // presence of parameter only |
|
240 | + if ($get[$key] === "") { |
|
241 | + return true; |
|
242 | + } |
|
243 | + |
|
244 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
245 | + return false; |
|
246 | + } |
|
247 | + |
|
248 | + return true; |
|
249 | + } |
|
250 | + |
|
251 | + #endregion |
|
252 | + |
|
253 | + #region GET variables |
|
254 | + |
|
255 | + /** |
|
256 | + * @param string $key |
|
257 | + * |
|
258 | + * @return bool |
|
259 | + */ |
|
260 | + public static function getBoolean($key) |
|
261 | + { |
|
262 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
263 | + if (!array_key_exists($key, $get)) { |
|
264 | + return false; |
|
265 | + } |
|
266 | + |
|
267 | + // presence of parameter only |
|
268 | + if ($get[$key] === "") { |
|
269 | + return true; |
|
270 | + } |
|
271 | + |
|
272 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
273 | + return false; |
|
274 | + } |
|
275 | + |
|
276 | + return true; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * @param string $key |
|
281 | + * |
|
282 | + * @return int|null |
|
283 | + */ |
|
284 | + public static function getInt($key) |
|
285 | + { |
|
286 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
287 | + if (!array_key_exists($key, $get)) { |
|
288 | + return null; |
|
289 | + } |
|
290 | + |
|
291 | + $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
292 | + |
|
293 | + if ($filteredValue === null) { |
|
294 | + return null; |
|
295 | + } |
|
296 | + |
|
297 | + return (int)$filteredValue; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * @param string $key |
|
302 | + * |
|
303 | + * @return null|string |
|
304 | + */ |
|
305 | + public static function getString($key) |
|
306 | + { |
|
307 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
308 | + if (!array_key_exists($key, $get)) { |
|
309 | + return null; |
|
310 | + } |
|
311 | + |
|
312 | + if ($get[$key] === "") { |
|
313 | + return null; |
|
314 | + } |
|
315 | + |
|
316 | + return (string)$get[$key]; |
|
317 | + } |
|
318 | + |
|
319 | + #endregion |
|
320 | + |
|
321 | + /** |
|
322 | + * Sets the logged-in user to the specified user. |
|
323 | + * |
|
324 | + * @param User $user |
|
325 | + */ |
|
326 | + public static function setLoggedInUser(User $user) |
|
327 | + { |
|
328 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
329 | + |
|
330 | + $session['userID'] = $user->getId(); |
|
331 | + unset($session['partialLogin']); |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Sets the post-login redirect |
|
336 | + * |
|
337 | + * @param string|null $uri The URI to redirect to |
|
338 | + */ |
|
339 | + public static function setPostLoginRedirect($uri = null) |
|
340 | + { |
|
341 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
342 | + |
|
343 | + if ($uri === null) { |
|
344 | + $uri = self::requestUri(); |
|
345 | + } |
|
346 | + |
|
347 | + $session['returnTo'] = $uri; |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * @return string|null |
|
352 | + */ |
|
353 | + public static function requestUri() |
|
354 | + { |
|
355 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
356 | + |
|
357 | + if (isset($server['REQUEST_URI'])) { |
|
358 | + return $server['REQUEST_URI']; |
|
359 | + } |
|
360 | + |
|
361 | + return null; |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * Clears the post-login redirect |
|
366 | + * @return string |
|
367 | + */ |
|
368 | + public static function clearPostLoginRedirect() |
|
369 | + { |
|
370 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
371 | + if (array_key_exists('returnTo', $session)) { |
|
372 | + $path = $session['returnTo']; |
|
373 | + unset($session['returnTo']); |
|
374 | + |
|
375 | + return $path; |
|
376 | + } |
|
377 | + |
|
378 | + return null; |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * @return string|null |
|
383 | + */ |
|
384 | + public static function serverName() |
|
385 | + { |
|
386 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
387 | + |
|
388 | + if (isset($server['SERVER_NAME'])) { |
|
389 | + return $server['SERVER_NAME']; |
|
390 | + } |
|
391 | + |
|
392 | + return null; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * You probably only want to deal with this through SessionAlert. |
|
397 | + * @return void |
|
398 | + */ |
|
399 | + public static function clearSessionAlertData() |
|
400 | + { |
|
401 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
402 | + if (array_key_exists('alerts', $session)) { |
|
403 | + unset($session['alerts']); |
|
404 | + } |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * You probably only want to deal with this through SessionAlert. |
|
409 | + * |
|
410 | + * @return string[] |
|
411 | + */ |
|
412 | + public static function getSessionAlertData() |
|
413 | + { |
|
414 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
415 | + if (array_key_exists('alerts', $session)) { |
|
416 | + return $session['alerts']; |
|
417 | + } |
|
418 | + |
|
419 | + return array(); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * You probably only want to deal with this through SessionAlert. |
|
424 | + * |
|
425 | + * @param string[] $data |
|
426 | + */ |
|
427 | + public static function setSessionAlertData($data) |
|
428 | + { |
|
429 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
430 | + $session['alerts'] = $data; |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * You probably only want to deal with this through TokenManager. |
|
435 | + * |
|
436 | + * @return string[] |
|
437 | + */ |
|
438 | + public static function getSessionTokenData() |
|
439 | + { |
|
440 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
441 | + if (array_key_exists('tokens', $session)) { |
|
442 | + return $session['tokens']; |
|
443 | + } |
|
444 | + |
|
445 | + return array(); |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * You probably only want to deal with this through TokenManager. |
|
450 | + * |
|
451 | + * @param string[] $data |
|
452 | + */ |
|
453 | + public static function setSessionTokenData($data) |
|
454 | + { |
|
455 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
456 | + $session['tokens'] = $data; |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * @param string $key |
|
461 | + * |
|
462 | + * @return mixed |
|
463 | + */ |
|
464 | + public static function getSessionContext($key) |
|
465 | + { |
|
466 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
467 | + |
|
468 | + if (!isset($session['context'])) { |
|
469 | + $session['context'] = array(); |
|
470 | + } |
|
471 | + |
|
472 | + if (!isset($session['context'][$key])) { |
|
473 | + return null; |
|
474 | + } |
|
475 | + |
|
476 | + return $session['context'][$key]; |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * @param string $key |
|
481 | + * @param mixed $data |
|
482 | + */ |
|
483 | + public static function setSessionContext($key, $data) |
|
484 | + { |
|
485 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
486 | + |
|
487 | + if (!isset($session['context'])) { |
|
488 | + $session['context'] = array(); |
|
489 | + } |
|
490 | + |
|
491 | + $session['context'][$key] = $data; |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * @return int|null |
|
496 | + */ |
|
497 | + public static function getSessionUserId() |
|
498 | + { |
|
499 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
500 | + |
|
501 | + return isset($session['userID']) ? (int)$session['userID'] : null; |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * @param User $user |
|
506 | + */ |
|
507 | + public static function setOAuthPartialLogin(User $user) |
|
508 | + { |
|
509 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
510 | + $session['oauthPartialLogin'] = $user->getId(); |
|
511 | + } |
|
512 | + |
|
513 | + /** |
|
514 | + * @return int|null |
|
515 | + */ |
|
516 | + public static function getOAuthPartialLogin() |
|
517 | + { |
|
518 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
519 | + |
|
520 | + return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null; |
|
521 | + } |
|
522 | + |
|
523 | + public static function setAuthPartialLogin($userId, $stage) |
|
524 | + { |
|
525 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
526 | + $session['authPartialLoginId'] = $userId; |
|
527 | + $session['authPartialLoginStage'] = $stage; |
|
528 | + } |
|
529 | + |
|
530 | + public static function getAuthPartialLogin() |
|
531 | + { |
|
532 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
533 | + |
|
534 | + $userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null; |
|
535 | + $stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null; |
|
536 | + |
|
537 | + return array($userId, $stage); |
|
538 | + } |
|
539 | + |
|
540 | + public static function clearAuthPartialLogin() |
|
541 | + { |
|
542 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
543 | + unset($session['authPartialLoginId']); |
|
544 | + unset($session['authPartialLoginStage']); |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * @return null|string |
|
549 | + */ |
|
550 | + public static function userAgent() |
|
551 | + { |
|
552 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
553 | + |
|
554 | + if (isset($server['HTTP_USER_AGENT'])) { |
|
555 | + return $server['HTTP_USER_AGENT']; |
|
556 | + } |
|
557 | + |
|
558 | + return null; |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * @return null|string |
|
563 | + */ |
|
564 | + public static function scriptName() |
|
565 | + { |
|
566 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
567 | + |
|
568 | + if (isset($server['SCRIPT_NAME'])) { |
|
569 | + return $server['SCRIPT_NAME']; |
|
570 | + } |
|
571 | + |
|
572 | + return null; |
|
573 | + } |
|
574 | + |
|
575 | + /** |
|
576 | + * @return null|string |
|
577 | + */ |
|
578 | + public static function origin() |
|
579 | + { |
|
580 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
581 | + |
|
582 | + if (isset($server['HTTP_ORIGIN'])) { |
|
583 | + return $server['HTTP_ORIGIN']; |
|
584 | + } |
|
585 | + |
|
586 | + return null; |
|
587 | + } |
|
588 | 588 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $userSearchRequest = WebRequest::getString('usersearch'); |
41 | 41 | if ($userSearchRequest !== null) { |
42 | 42 | $searchedUser = User::getByUsername($userSearchRequest, $database); |
43 | - if($searchedUser !== false) { |
|
43 | + if ($searchedUser !== false) { |
|
44 | 44 | $this->redirect('statistics/users', 'detail', ['user' => $searchedUser->getId()]); |
45 | 45 | return; |
46 | 46 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | continue; |
135 | 135 | } |
136 | 136 | |
137 | - $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0; |
|
137 | + $newValue = WebRequest::postBoolean('role-'.$name) ? 1 : 0; |
|
138 | 138 | if ($newValue !== $r['active']) { |
139 | 139 | if ($newValue === 0) { |
140 | 140 | $delete[] = $r['object']; |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $user->save(); |
178 | 178 | |
179 | 179 | $this->getNotificationHelper()->userRolesEdited($user, $reason); |
180 | - SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
180 | + SessionAlert::quick('Roles changed for user '.htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
181 | 181 | |
182 | 182 | $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
183 | 183 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | Logger::suspendedUser($database, $user, $reason); |
231 | 231 | |
232 | 232 | $this->getNotificationHelper()->userSuspended($user, $reason); |
233 | - SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
233 | + SessionAlert::quick('Suspended user '.htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
234 | 234 | |
235 | 235 | // send email |
236 | 236 | $this->sendStatusChangeEmail( |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | Logger::declinedUser($database, $user, $reason); |
292 | 292 | |
293 | 293 | $this->getNotificationHelper()->userDeclined($user, $reason); |
294 | - SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
294 | + SessionAlert::quick('Declined user '.htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
295 | 295 | |
296 | 296 | // send email |
297 | 297 | $this->sendStatusChangeEmail( |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | Logger::approvedUser($database, $user); |
347 | 347 | |
348 | 348 | $this->getNotificationHelper()->userApproved($user); |
349 | - SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
349 | + SessionAlert::quick('Approved user '.htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
350 | 350 | |
351 | 351 | // send email |
352 | 352 | $this->sendStatusChangeEmail( |
@@ -24,556 +24,556 @@ |
||
24 | 24 | */ |
25 | 25 | class PageUserManagement extends InternalPageBase |
26 | 26 | { |
27 | - /** @var string */ |
|
28 | - private $adminMailingList = '[email protected]'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Main function for this page, when no specific actions are called. |
|
32 | - */ |
|
33 | - protected function main() |
|
34 | - { |
|
35 | - $this->setHtmlTitle('User Management'); |
|
36 | - |
|
37 | - $database = $this->getDatabase(); |
|
38 | - $currentUser = User::getCurrent($database); |
|
39 | - |
|
40 | - $userSearchRequest = WebRequest::getString('usersearch'); |
|
41 | - if ($userSearchRequest !== null) { |
|
42 | - $searchedUser = User::getByUsername($userSearchRequest, $database); |
|
43 | - if($searchedUser !== false) { |
|
44 | - $this->redirect('statistics/users', 'detail', ['user' => $searchedUser->getId()]); |
|
45 | - return; |
|
46 | - } |
|
47 | - } |
|
48 | - |
|
49 | - // A bit hacky, but it's better than my last solution of creating an object for each user and passing that to |
|
50 | - // the template. I still don't have a particularly good way of handling this. |
|
51 | - OAuthUserHelper::prepareTokenCountStatement($database); |
|
52 | - |
|
53 | - if (WebRequest::getBoolean("showAll")) { |
|
54 | - $this->assign("showAll", true); |
|
55 | - |
|
56 | - $suspendedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_SUSPENDED)->fetch(); |
|
57 | - $this->assign("suspendedUsers", $suspendedUsers); |
|
58 | - |
|
59 | - $declinedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch(); |
|
60 | - $this->assign("declinedUsers", $declinedUsers); |
|
61 | - |
|
62 | - UserSearchHelper::get($database)->getRoleMap($roleMap); |
|
63 | - } |
|
64 | - else { |
|
65 | - $this->assign("showAll", false); |
|
66 | - $this->assign("suspendedUsers", array()); |
|
67 | - $this->assign("declinedUsers", array()); |
|
68 | - |
|
69 | - UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap); |
|
70 | - } |
|
71 | - |
|
72 | - $newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch(); |
|
73 | - $normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch(); |
|
74 | - $adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch(); |
|
75 | - $checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch(); |
|
76 | - $toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch(); |
|
77 | - $this->assign('newUsers', $newUsers); |
|
78 | - $this->assign('normalUsers', $normalUsers); |
|
79 | - $this->assign('adminUsers', $adminUsers); |
|
80 | - $this->assign('checkUsers', $checkUsers); |
|
81 | - $this->assign('toolRoots', $toolRoots); |
|
82 | - |
|
83 | - $this->assign('roles', $roleMap); |
|
84 | - |
|
85 | - $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
86 | - |
|
87 | - $this->assign('canApprove', $this->barrierTest('approve', $currentUser)); |
|
88 | - $this->assign('canDecline', $this->barrierTest('decline', $currentUser)); |
|
89 | - $this->assign('canRename', $this->barrierTest('rename', $currentUser)); |
|
90 | - $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser)); |
|
91 | - $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser)); |
|
92 | - $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser)); |
|
93 | - |
|
94 | - $this->setTemplate("usermanagement/main.tpl"); |
|
95 | - } |
|
96 | - |
|
97 | - #region Access control |
|
98 | - |
|
99 | - /** |
|
100 | - * Action target for editing the roles assigned to a user |
|
101 | - */ |
|
102 | - protected function editRoles() |
|
103 | - { |
|
104 | - $this->setHtmlTitle('User Management'); |
|
105 | - $database = $this->getDatabase(); |
|
106 | - $userId = WebRequest::getInt('user'); |
|
107 | - |
|
108 | - /** @var User $user */ |
|
109 | - $user = User::getById($userId, $database); |
|
110 | - |
|
111 | - if ($user === false) { |
|
112 | - throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
113 | - } |
|
114 | - |
|
115 | - $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database)); |
|
116 | - |
|
117 | - // Dual-mode action |
|
118 | - if (WebRequest::wasPosted()) { |
|
119 | - $this->validateCSRFToken(); |
|
120 | - |
|
121 | - $reason = WebRequest::postString('reason'); |
|
122 | - if ($reason === false || trim($reason) === '') { |
|
123 | - throw new ApplicationLogicException('No reason specified for roles change'); |
|
124 | - } |
|
125 | - |
|
126 | - /** @var UserRole[] $delete */ |
|
127 | - $delete = array(); |
|
128 | - /** @var string[] $delete */ |
|
129 | - $add = array(); |
|
130 | - |
|
131 | - foreach ($roleData as $name => $r) { |
|
132 | - if ($r['allowEdit'] !== 1) { |
|
133 | - // not allowed, to touch this, so ignore it |
|
134 | - continue; |
|
135 | - } |
|
136 | - |
|
137 | - $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0; |
|
138 | - if ($newValue !== $r['active']) { |
|
139 | - if ($newValue === 0) { |
|
140 | - $delete[] = $r['object']; |
|
141 | - } |
|
142 | - |
|
143 | - if ($newValue === 1) { |
|
144 | - $add[] = $name; |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - // Check there's something to do |
|
150 | - if ((count($add) + count($delete)) === 0) { |
|
151 | - $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
152 | - SessionAlert::warning('No changes made to roles.'); |
|
153 | - |
|
154 | - return; |
|
155 | - } |
|
156 | - |
|
157 | - $removed = array(); |
|
158 | - |
|
159 | - /** @var UserRole $d */ |
|
160 | - foreach ($delete as $d) { |
|
161 | - $removed[] = $d->getRole(); |
|
162 | - $d->delete(); |
|
163 | - } |
|
164 | - |
|
165 | - foreach ($add as $x) { |
|
166 | - $a = new UserRole(); |
|
167 | - $a->setUser($user->getId()); |
|
168 | - $a->setRole($x); |
|
169 | - $a->setDatabase($database); |
|
170 | - $a->save(); |
|
171 | - } |
|
172 | - |
|
173 | - Logger::userRolesEdited($database, $user, $reason, $add, $removed); |
|
174 | - |
|
175 | - // dummy save for optimistic locking. If this fails, the entire txn will roll back. |
|
176 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
177 | - $user->save(); |
|
178 | - |
|
179 | - $this->getNotificationHelper()->userRolesEdited($user, $reason); |
|
180 | - SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
181 | - |
|
182 | - $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
183 | - |
|
184 | - return; |
|
185 | - } |
|
186 | - else { |
|
187 | - $this->assignCSRFToken(); |
|
188 | - $this->setTemplate('usermanagement/roleedit.tpl'); |
|
189 | - $this->assign('user', $user); |
|
190 | - $this->assign('roleData', $roleData); |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Action target for suspending users |
|
196 | - * |
|
197 | - * @throws ApplicationLogicException |
|
198 | - */ |
|
199 | - protected function suspend() |
|
200 | - { |
|
201 | - $this->setHtmlTitle('User Management'); |
|
202 | - |
|
203 | - $database = $this->getDatabase(); |
|
204 | - |
|
205 | - $userId = WebRequest::getInt('user'); |
|
206 | - |
|
207 | - /** @var User $user */ |
|
208 | - $user = User::getById($userId, $database); |
|
209 | - |
|
210 | - if ($user === false) { |
|
211 | - throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.'); |
|
212 | - } |
|
213 | - |
|
214 | - if ($user->isSuspended()) { |
|
215 | - throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.'); |
|
216 | - } |
|
217 | - |
|
218 | - // Dual-mode action |
|
219 | - if (WebRequest::wasPosted()) { |
|
220 | - $this->validateCSRFToken(); |
|
221 | - $reason = WebRequest::postString('reason'); |
|
222 | - |
|
223 | - if ($reason === null || trim($reason) === "") { |
|
224 | - throw new ApplicationLogicException('No reason provided'); |
|
225 | - } |
|
226 | - |
|
227 | - $user->setStatus(User::STATUS_SUSPENDED); |
|
228 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
229 | - $user->save(); |
|
230 | - Logger::suspendedUser($database, $user, $reason); |
|
231 | - |
|
232 | - $this->getNotificationHelper()->userSuspended($user, $reason); |
|
233 | - SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
234 | - |
|
235 | - // send email |
|
236 | - $this->sendStatusChangeEmail( |
|
237 | - 'Your WP:ACC account has been suspended', |
|
238 | - 'usermanagement/emails/suspended.tpl', |
|
239 | - $reason, |
|
240 | - $user, |
|
241 | - User::getCurrent($database)->getUsername() |
|
242 | - ); |
|
243 | - |
|
244 | - $this->redirect('userManagement'); |
|
245 | - |
|
246 | - return; |
|
247 | - } |
|
248 | - else { |
|
249 | - $this->assignCSRFToken(); |
|
250 | - $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
251 | - $this->assign('user', $user); |
|
252 | - $this->assign('status', 'Suspended'); |
|
253 | - $this->assign("showReason", true); |
|
254 | - |
|
255 | - if (WebRequest::getString('preload')) { |
|
256 | - $this->assign('preload', WebRequest::getString('preload')); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Entry point for the decline action |
|
263 | - * |
|
264 | - * @throws ApplicationLogicException |
|
265 | - */ |
|
266 | - protected function decline() |
|
267 | - { |
|
268 | - $this->setHtmlTitle('User Management'); |
|
269 | - |
|
270 | - $database = $this->getDatabase(); |
|
271 | - |
|
272 | - $userId = WebRequest::getInt('user'); |
|
273 | - $user = User::getById($userId, $database); |
|
274 | - |
|
275 | - if ($user === false) { |
|
276 | - throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.'); |
|
277 | - } |
|
278 | - |
|
279 | - if (!$user->isNewUser()) { |
|
280 | - throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.'); |
|
281 | - } |
|
282 | - |
|
283 | - // Dual-mode action |
|
284 | - if (WebRequest::wasPosted()) { |
|
285 | - $this->validateCSRFToken(); |
|
286 | - $reason = WebRequest::postString('reason'); |
|
287 | - |
|
288 | - if ($reason === null || trim($reason) === "") { |
|
289 | - throw new ApplicationLogicException('No reason provided'); |
|
290 | - } |
|
291 | - |
|
292 | - $user->setStatus(User::STATUS_DECLINED); |
|
293 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
294 | - $user->save(); |
|
295 | - Logger::declinedUser($database, $user, $reason); |
|
296 | - |
|
297 | - $this->getNotificationHelper()->userDeclined($user, $reason); |
|
298 | - SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
299 | - |
|
300 | - // send email |
|
301 | - $this->sendStatusChangeEmail( |
|
302 | - 'Your WP:ACC account has been declined', |
|
303 | - 'usermanagement/emails/declined.tpl', |
|
304 | - $reason, |
|
305 | - $user, |
|
306 | - User::getCurrent($database)->getUsername() |
|
307 | - ); |
|
308 | - |
|
309 | - $this->redirect('userManagement'); |
|
310 | - |
|
311 | - return; |
|
312 | - } |
|
313 | - else { |
|
314 | - $this->assignCSRFToken(); |
|
315 | - $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
316 | - $this->assign('user', $user); |
|
317 | - $this->assign('status', 'Declined'); |
|
318 | - $this->assign("showReason", true); |
|
319 | - } |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Entry point for the approve action |
|
324 | - * |
|
325 | - * @throws ApplicationLogicException |
|
326 | - */ |
|
327 | - protected function approve() |
|
328 | - { |
|
329 | - $this->setHtmlTitle('User Management'); |
|
330 | - |
|
331 | - $database = $this->getDatabase(); |
|
332 | - |
|
333 | - $userId = WebRequest::getInt('user'); |
|
334 | - $user = User::getById($userId, $database); |
|
335 | - |
|
336 | - if ($user === false) { |
|
337 | - throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.'); |
|
338 | - } |
|
339 | - |
|
340 | - if ($user->isActive()) { |
|
341 | - throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.'); |
|
342 | - } |
|
343 | - |
|
344 | - // Dual-mode action |
|
345 | - if (WebRequest::wasPosted()) { |
|
346 | - $this->validateCSRFToken(); |
|
347 | - $user->setStatus(User::STATUS_ACTIVE); |
|
348 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
349 | - $user->save(); |
|
350 | - Logger::approvedUser($database, $user); |
|
351 | - |
|
352 | - $this->getNotificationHelper()->userApproved($user); |
|
353 | - SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
354 | - |
|
355 | - // send email |
|
356 | - $this->sendStatusChangeEmail( |
|
357 | - 'Your WP:ACC account has been approved', |
|
358 | - 'usermanagement/emails/approved.tpl', |
|
359 | - null, |
|
360 | - $user, |
|
361 | - User::getCurrent($database)->getUsername() |
|
362 | - ); |
|
363 | - |
|
364 | - $this->redirect("userManagement"); |
|
365 | - |
|
366 | - return; |
|
367 | - } |
|
368 | - else { |
|
369 | - $this->assignCSRFToken(); |
|
370 | - $this->setTemplate("usermanagement/changelevel-reason.tpl"); |
|
371 | - $this->assign("user", $user); |
|
372 | - $this->assign("status", "Active"); |
|
373 | - $this->assign("showReason", false); |
|
374 | - } |
|
375 | - } |
|
376 | - |
|
377 | - #endregion |
|
378 | - |
|
379 | - #region Renaming / Editing |
|
380 | - |
|
381 | - /** |
|
382 | - * Entry point for the rename action |
|
383 | - * |
|
384 | - * @throws ApplicationLogicException |
|
385 | - */ |
|
386 | - protected function rename() |
|
387 | - { |
|
388 | - $this->setHtmlTitle('User Management'); |
|
389 | - |
|
390 | - $database = $this->getDatabase(); |
|
391 | - |
|
392 | - $userId = WebRequest::getInt('user'); |
|
393 | - $user = User::getById($userId, $database); |
|
394 | - |
|
395 | - if ($user === false) { |
|
396 | - throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.'); |
|
397 | - } |
|
398 | - |
|
399 | - // Dual-mode action |
|
400 | - if (WebRequest::wasPosted()) { |
|
401 | - $this->validateCSRFToken(); |
|
402 | - $newUsername = WebRequest::postString('newname'); |
|
403 | - |
|
404 | - if ($newUsername === null || trim($newUsername) === "") { |
|
405 | - throw new ApplicationLogicException('The new username cannot be empty'); |
|
406 | - } |
|
407 | - |
|
408 | - if (User::getByUsername($newUsername, $database) != false) { |
|
409 | - throw new ApplicationLogicException('The new username already exists'); |
|
410 | - } |
|
411 | - |
|
412 | - $oldUsername = $user->getUsername(); |
|
413 | - $user->setUsername($newUsername); |
|
414 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
415 | - |
|
416 | - $user->save(); |
|
417 | - |
|
418 | - $logEntryData = serialize(array( |
|
419 | - 'old' => $oldUsername, |
|
420 | - 'new' => $newUsername, |
|
421 | - )); |
|
422 | - |
|
423 | - Logger::renamedUser($database, $user, $logEntryData); |
|
424 | - |
|
425 | - SessionAlert::quick("Changed User " |
|
426 | - . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8') |
|
427 | - . " name to " |
|
428 | - . htmlentities($newUsername, ENT_COMPAT, 'UTF-8')); |
|
429 | - |
|
430 | - $this->getNotificationHelper()->userRenamed($user, $oldUsername); |
|
431 | - |
|
432 | - // send an email to the user. |
|
433 | - $this->assign('targetUsername', $user->getUsername()); |
|
434 | - $this->assign('toolAdmin', User::getCurrent($database)->getUsername()); |
|
435 | - $this->assign('oldUsername', $oldUsername); |
|
436 | - $this->assign('mailingList', $this->adminMailingList); |
|
437 | - |
|
438 | - $this->getEmailHelper()->sendMail( |
|
439 | - $user->getEmail(), |
|
440 | - 'Your username on WP:ACC has been changed', |
|
441 | - $this->fetchTemplate('usermanagement/emails/renamed.tpl'), |
|
442 | - array('Reply-To' => $this->adminMailingList) |
|
443 | - ); |
|
444 | - |
|
445 | - $this->redirect("userManagement"); |
|
446 | - |
|
447 | - return; |
|
448 | - } |
|
449 | - else { |
|
450 | - $this->assignCSRFToken(); |
|
451 | - $this->setTemplate('usermanagement/renameuser.tpl'); |
|
452 | - $this->assign('user', $user); |
|
453 | - } |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Entry point for the edit action |
|
458 | - * |
|
459 | - * @throws ApplicationLogicException |
|
460 | - */ |
|
461 | - protected function editUser() |
|
462 | - { |
|
463 | - $this->setHtmlTitle('User Management'); |
|
464 | - |
|
465 | - $database = $this->getDatabase(); |
|
466 | - |
|
467 | - $userId = WebRequest::getInt('user'); |
|
468 | - $user = User::getById($userId, $database); |
|
469 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
470 | - |
|
471 | - if ($user === false) { |
|
472 | - throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
473 | - } |
|
474 | - |
|
475 | - // Dual-mode action |
|
476 | - if (WebRequest::wasPosted()) { |
|
477 | - $this->validateCSRFToken(); |
|
478 | - $newEmail = WebRequest::postEmail('user_email'); |
|
479 | - $newOnWikiName = WebRequest::postString('user_onwikiname'); |
|
480 | - |
|
481 | - if ($newEmail === null) { |
|
482 | - throw new ApplicationLogicException('Invalid email address'); |
|
483 | - } |
|
484 | - |
|
485 | - if (!$oauth->isFullyLinked()) { |
|
486 | - if (trim($newOnWikiName) == "") { |
|
487 | - throw new ApplicationLogicException('New on-wiki username cannot be blank'); |
|
488 | - } |
|
489 | - |
|
490 | - $user->setOnWikiName($newOnWikiName); |
|
491 | - } |
|
492 | - |
|
493 | - $user->setEmail($newEmail); |
|
494 | - |
|
495 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
496 | - |
|
497 | - $user->save(); |
|
498 | - |
|
499 | - Logger::userPreferencesChange($database, $user); |
|
500 | - $this->getNotificationHelper()->userPrefChange($user); |
|
501 | - SessionAlert::quick('Changes to user\'s preferences have been saved'); |
|
502 | - |
|
503 | - $this->redirect("userManagement"); |
|
504 | - |
|
505 | - return; |
|
506 | - } |
|
507 | - else { |
|
508 | - $this->assignCSRFToken(); |
|
509 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
510 | - $this->getSiteConfiguration()); |
|
511 | - $this->setTemplate('usermanagement/edituser.tpl'); |
|
512 | - $this->assign('user', $user); |
|
513 | - $this->assign('oauth', $oauth); |
|
514 | - } |
|
515 | - } |
|
516 | - |
|
517 | - #endregion |
|
518 | - |
|
519 | - /** |
|
520 | - * Sends a status change email to the user. |
|
521 | - * |
|
522 | - * @param string $subject The subject of the email |
|
523 | - * @param string $template The smarty template to use |
|
524 | - * @param string|null $reason The reason for performing the status change |
|
525 | - * @param User $user The user affected |
|
526 | - * @param string $toolAdminUsername The tool admin's username who is making the edit |
|
527 | - */ |
|
528 | - private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername) |
|
529 | - { |
|
530 | - $this->assign('targetUsername', $user->getUsername()); |
|
531 | - $this->assign('toolAdmin', $toolAdminUsername); |
|
532 | - $this->assign('actionReason', $reason); |
|
533 | - $this->assign('mailingList', $this->adminMailingList); |
|
534 | - |
|
535 | - $this->getEmailHelper()->sendMail( |
|
536 | - $user->getEmail(), |
|
537 | - $subject, |
|
538 | - $this->fetchTemplate($template), |
|
539 | - array('Reply-To' => $this->adminMailingList) |
|
540 | - ); |
|
541 | - } |
|
542 | - |
|
543 | - /** |
|
544 | - * @param UserRole[] $activeRoles |
|
545 | - * |
|
546 | - * @return array |
|
547 | - */ |
|
548 | - private function getRoleData($activeRoles) |
|
549 | - { |
|
550 | - $availableRoles = $this->getSecurityManager()->getRoleConfiguration()->getAvailableRoles(); |
|
551 | - |
|
552 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
553 | - $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles); |
|
554 | - |
|
555 | - $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null); |
|
556 | - |
|
557 | - $roleData = array(); |
|
558 | - foreach ($availableRoles as $role => $data) { |
|
559 | - $intersection = array_intersect($data['editableBy'], $userRoles); |
|
560 | - |
|
561 | - $roleData[$role] = $initialValue; |
|
562 | - $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0; |
|
563 | - $roleData[$role]['description'] = $data['description']; |
|
564 | - } |
|
565 | - |
|
566 | - foreach ($activeRoles as $role) { |
|
567 | - if (!isset($roleData[$role->getRole()])) { |
|
568 | - // This value is no longer available in the configuration, allow changing (aka removing) it. |
|
569 | - $roleData[$role->getRole()] = $initialValue; |
|
570 | - $roleData[$role->getRole()]['allowEdit'] = 1; |
|
571 | - } |
|
572 | - |
|
573 | - $roleData[$role->getRole()]['object'] = $role; |
|
574 | - $roleData[$role->getRole()]['active'] = 1; |
|
575 | - } |
|
576 | - |
|
577 | - return $roleData; |
|
578 | - } |
|
27 | + /** @var string */ |
|
28 | + private $adminMailingList = '[email protected]'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Main function for this page, when no specific actions are called. |
|
32 | + */ |
|
33 | + protected function main() |
|
34 | + { |
|
35 | + $this->setHtmlTitle('User Management'); |
|
36 | + |
|
37 | + $database = $this->getDatabase(); |
|
38 | + $currentUser = User::getCurrent($database); |
|
39 | + |
|
40 | + $userSearchRequest = WebRequest::getString('usersearch'); |
|
41 | + if ($userSearchRequest !== null) { |
|
42 | + $searchedUser = User::getByUsername($userSearchRequest, $database); |
|
43 | + if($searchedUser !== false) { |
|
44 | + $this->redirect('statistics/users', 'detail', ['user' => $searchedUser->getId()]); |
|
45 | + return; |
|
46 | + } |
|
47 | + } |
|
48 | + |
|
49 | + // A bit hacky, but it's better than my last solution of creating an object for each user and passing that to |
|
50 | + // the template. I still don't have a particularly good way of handling this. |
|
51 | + OAuthUserHelper::prepareTokenCountStatement($database); |
|
52 | + |
|
53 | + if (WebRequest::getBoolean("showAll")) { |
|
54 | + $this->assign("showAll", true); |
|
55 | + |
|
56 | + $suspendedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_SUSPENDED)->fetch(); |
|
57 | + $this->assign("suspendedUsers", $suspendedUsers); |
|
58 | + |
|
59 | + $declinedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch(); |
|
60 | + $this->assign("declinedUsers", $declinedUsers); |
|
61 | + |
|
62 | + UserSearchHelper::get($database)->getRoleMap($roleMap); |
|
63 | + } |
|
64 | + else { |
|
65 | + $this->assign("showAll", false); |
|
66 | + $this->assign("suspendedUsers", array()); |
|
67 | + $this->assign("declinedUsers", array()); |
|
68 | + |
|
69 | + UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap); |
|
70 | + } |
|
71 | + |
|
72 | + $newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch(); |
|
73 | + $normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch(); |
|
74 | + $adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch(); |
|
75 | + $checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch(); |
|
76 | + $toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch(); |
|
77 | + $this->assign('newUsers', $newUsers); |
|
78 | + $this->assign('normalUsers', $normalUsers); |
|
79 | + $this->assign('adminUsers', $adminUsers); |
|
80 | + $this->assign('checkUsers', $checkUsers); |
|
81 | + $this->assign('toolRoots', $toolRoots); |
|
82 | + |
|
83 | + $this->assign('roles', $roleMap); |
|
84 | + |
|
85 | + $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
86 | + |
|
87 | + $this->assign('canApprove', $this->barrierTest('approve', $currentUser)); |
|
88 | + $this->assign('canDecline', $this->barrierTest('decline', $currentUser)); |
|
89 | + $this->assign('canRename', $this->barrierTest('rename', $currentUser)); |
|
90 | + $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser)); |
|
91 | + $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser)); |
|
92 | + $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser)); |
|
93 | + |
|
94 | + $this->setTemplate("usermanagement/main.tpl"); |
|
95 | + } |
|
96 | + |
|
97 | + #region Access control |
|
98 | + |
|
99 | + /** |
|
100 | + * Action target for editing the roles assigned to a user |
|
101 | + */ |
|
102 | + protected function editRoles() |
|
103 | + { |
|
104 | + $this->setHtmlTitle('User Management'); |
|
105 | + $database = $this->getDatabase(); |
|
106 | + $userId = WebRequest::getInt('user'); |
|
107 | + |
|
108 | + /** @var User $user */ |
|
109 | + $user = User::getById($userId, $database); |
|
110 | + |
|
111 | + if ($user === false) { |
|
112 | + throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
113 | + } |
|
114 | + |
|
115 | + $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database)); |
|
116 | + |
|
117 | + // Dual-mode action |
|
118 | + if (WebRequest::wasPosted()) { |
|
119 | + $this->validateCSRFToken(); |
|
120 | + |
|
121 | + $reason = WebRequest::postString('reason'); |
|
122 | + if ($reason === false || trim($reason) === '') { |
|
123 | + throw new ApplicationLogicException('No reason specified for roles change'); |
|
124 | + } |
|
125 | + |
|
126 | + /** @var UserRole[] $delete */ |
|
127 | + $delete = array(); |
|
128 | + /** @var string[] $delete */ |
|
129 | + $add = array(); |
|
130 | + |
|
131 | + foreach ($roleData as $name => $r) { |
|
132 | + if ($r['allowEdit'] !== 1) { |
|
133 | + // not allowed, to touch this, so ignore it |
|
134 | + continue; |
|
135 | + } |
|
136 | + |
|
137 | + $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0; |
|
138 | + if ($newValue !== $r['active']) { |
|
139 | + if ($newValue === 0) { |
|
140 | + $delete[] = $r['object']; |
|
141 | + } |
|
142 | + |
|
143 | + if ($newValue === 1) { |
|
144 | + $add[] = $name; |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + // Check there's something to do |
|
150 | + if ((count($add) + count($delete)) === 0) { |
|
151 | + $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
152 | + SessionAlert::warning('No changes made to roles.'); |
|
153 | + |
|
154 | + return; |
|
155 | + } |
|
156 | + |
|
157 | + $removed = array(); |
|
158 | + |
|
159 | + /** @var UserRole $d */ |
|
160 | + foreach ($delete as $d) { |
|
161 | + $removed[] = $d->getRole(); |
|
162 | + $d->delete(); |
|
163 | + } |
|
164 | + |
|
165 | + foreach ($add as $x) { |
|
166 | + $a = new UserRole(); |
|
167 | + $a->setUser($user->getId()); |
|
168 | + $a->setRole($x); |
|
169 | + $a->setDatabase($database); |
|
170 | + $a->save(); |
|
171 | + } |
|
172 | + |
|
173 | + Logger::userRolesEdited($database, $user, $reason, $add, $removed); |
|
174 | + |
|
175 | + // dummy save for optimistic locking. If this fails, the entire txn will roll back. |
|
176 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
177 | + $user->save(); |
|
178 | + |
|
179 | + $this->getNotificationHelper()->userRolesEdited($user, $reason); |
|
180 | + SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
181 | + |
|
182 | + $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
183 | + |
|
184 | + return; |
|
185 | + } |
|
186 | + else { |
|
187 | + $this->assignCSRFToken(); |
|
188 | + $this->setTemplate('usermanagement/roleedit.tpl'); |
|
189 | + $this->assign('user', $user); |
|
190 | + $this->assign('roleData', $roleData); |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Action target for suspending users |
|
196 | + * |
|
197 | + * @throws ApplicationLogicException |
|
198 | + */ |
|
199 | + protected function suspend() |
|
200 | + { |
|
201 | + $this->setHtmlTitle('User Management'); |
|
202 | + |
|
203 | + $database = $this->getDatabase(); |
|
204 | + |
|
205 | + $userId = WebRequest::getInt('user'); |
|
206 | + |
|
207 | + /** @var User $user */ |
|
208 | + $user = User::getById($userId, $database); |
|
209 | + |
|
210 | + if ($user === false) { |
|
211 | + throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.'); |
|
212 | + } |
|
213 | + |
|
214 | + if ($user->isSuspended()) { |
|
215 | + throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.'); |
|
216 | + } |
|
217 | + |
|
218 | + // Dual-mode action |
|
219 | + if (WebRequest::wasPosted()) { |
|
220 | + $this->validateCSRFToken(); |
|
221 | + $reason = WebRequest::postString('reason'); |
|
222 | + |
|
223 | + if ($reason === null || trim($reason) === "") { |
|
224 | + throw new ApplicationLogicException('No reason provided'); |
|
225 | + } |
|
226 | + |
|
227 | + $user->setStatus(User::STATUS_SUSPENDED); |
|
228 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
229 | + $user->save(); |
|
230 | + Logger::suspendedUser($database, $user, $reason); |
|
231 | + |
|
232 | + $this->getNotificationHelper()->userSuspended($user, $reason); |
|
233 | + SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
234 | + |
|
235 | + // send email |
|
236 | + $this->sendStatusChangeEmail( |
|
237 | + 'Your WP:ACC account has been suspended', |
|
238 | + 'usermanagement/emails/suspended.tpl', |
|
239 | + $reason, |
|
240 | + $user, |
|
241 | + User::getCurrent($database)->getUsername() |
|
242 | + ); |
|
243 | + |
|
244 | + $this->redirect('userManagement'); |
|
245 | + |
|
246 | + return; |
|
247 | + } |
|
248 | + else { |
|
249 | + $this->assignCSRFToken(); |
|
250 | + $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
251 | + $this->assign('user', $user); |
|
252 | + $this->assign('status', 'Suspended'); |
|
253 | + $this->assign("showReason", true); |
|
254 | + |
|
255 | + if (WebRequest::getString('preload')) { |
|
256 | + $this->assign('preload', WebRequest::getString('preload')); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Entry point for the decline action |
|
263 | + * |
|
264 | + * @throws ApplicationLogicException |
|
265 | + */ |
|
266 | + protected function decline() |
|
267 | + { |
|
268 | + $this->setHtmlTitle('User Management'); |
|
269 | + |
|
270 | + $database = $this->getDatabase(); |
|
271 | + |
|
272 | + $userId = WebRequest::getInt('user'); |
|
273 | + $user = User::getById($userId, $database); |
|
274 | + |
|
275 | + if ($user === false) { |
|
276 | + throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.'); |
|
277 | + } |
|
278 | + |
|
279 | + if (!$user->isNewUser()) { |
|
280 | + throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.'); |
|
281 | + } |
|
282 | + |
|
283 | + // Dual-mode action |
|
284 | + if (WebRequest::wasPosted()) { |
|
285 | + $this->validateCSRFToken(); |
|
286 | + $reason = WebRequest::postString('reason'); |
|
287 | + |
|
288 | + if ($reason === null || trim($reason) === "") { |
|
289 | + throw new ApplicationLogicException('No reason provided'); |
|
290 | + } |
|
291 | + |
|
292 | + $user->setStatus(User::STATUS_DECLINED); |
|
293 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
294 | + $user->save(); |
|
295 | + Logger::declinedUser($database, $user, $reason); |
|
296 | + |
|
297 | + $this->getNotificationHelper()->userDeclined($user, $reason); |
|
298 | + SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
299 | + |
|
300 | + // send email |
|
301 | + $this->sendStatusChangeEmail( |
|
302 | + 'Your WP:ACC account has been declined', |
|
303 | + 'usermanagement/emails/declined.tpl', |
|
304 | + $reason, |
|
305 | + $user, |
|
306 | + User::getCurrent($database)->getUsername() |
|
307 | + ); |
|
308 | + |
|
309 | + $this->redirect('userManagement'); |
|
310 | + |
|
311 | + return; |
|
312 | + } |
|
313 | + else { |
|
314 | + $this->assignCSRFToken(); |
|
315 | + $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
316 | + $this->assign('user', $user); |
|
317 | + $this->assign('status', 'Declined'); |
|
318 | + $this->assign("showReason", true); |
|
319 | + } |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Entry point for the approve action |
|
324 | + * |
|
325 | + * @throws ApplicationLogicException |
|
326 | + */ |
|
327 | + protected function approve() |
|
328 | + { |
|
329 | + $this->setHtmlTitle('User Management'); |
|
330 | + |
|
331 | + $database = $this->getDatabase(); |
|
332 | + |
|
333 | + $userId = WebRequest::getInt('user'); |
|
334 | + $user = User::getById($userId, $database); |
|
335 | + |
|
336 | + if ($user === false) { |
|
337 | + throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.'); |
|
338 | + } |
|
339 | + |
|
340 | + if ($user->isActive()) { |
|
341 | + throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.'); |
|
342 | + } |
|
343 | + |
|
344 | + // Dual-mode action |
|
345 | + if (WebRequest::wasPosted()) { |
|
346 | + $this->validateCSRFToken(); |
|
347 | + $user->setStatus(User::STATUS_ACTIVE); |
|
348 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
349 | + $user->save(); |
|
350 | + Logger::approvedUser($database, $user); |
|
351 | + |
|
352 | + $this->getNotificationHelper()->userApproved($user); |
|
353 | + SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
354 | + |
|
355 | + // send email |
|
356 | + $this->sendStatusChangeEmail( |
|
357 | + 'Your WP:ACC account has been approved', |
|
358 | + 'usermanagement/emails/approved.tpl', |
|
359 | + null, |
|
360 | + $user, |
|
361 | + User::getCurrent($database)->getUsername() |
|
362 | + ); |
|
363 | + |
|
364 | + $this->redirect("userManagement"); |
|
365 | + |
|
366 | + return; |
|
367 | + } |
|
368 | + else { |
|
369 | + $this->assignCSRFToken(); |
|
370 | + $this->setTemplate("usermanagement/changelevel-reason.tpl"); |
|
371 | + $this->assign("user", $user); |
|
372 | + $this->assign("status", "Active"); |
|
373 | + $this->assign("showReason", false); |
|
374 | + } |
|
375 | + } |
|
376 | + |
|
377 | + #endregion |
|
378 | + |
|
379 | + #region Renaming / Editing |
|
380 | + |
|
381 | + /** |
|
382 | + * Entry point for the rename action |
|
383 | + * |
|
384 | + * @throws ApplicationLogicException |
|
385 | + */ |
|
386 | + protected function rename() |
|
387 | + { |
|
388 | + $this->setHtmlTitle('User Management'); |
|
389 | + |
|
390 | + $database = $this->getDatabase(); |
|
391 | + |
|
392 | + $userId = WebRequest::getInt('user'); |
|
393 | + $user = User::getById($userId, $database); |
|
394 | + |
|
395 | + if ($user === false) { |
|
396 | + throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.'); |
|
397 | + } |
|
398 | + |
|
399 | + // Dual-mode action |
|
400 | + if (WebRequest::wasPosted()) { |
|
401 | + $this->validateCSRFToken(); |
|
402 | + $newUsername = WebRequest::postString('newname'); |
|
403 | + |
|
404 | + if ($newUsername === null || trim($newUsername) === "") { |
|
405 | + throw new ApplicationLogicException('The new username cannot be empty'); |
|
406 | + } |
|
407 | + |
|
408 | + if (User::getByUsername($newUsername, $database) != false) { |
|
409 | + throw new ApplicationLogicException('The new username already exists'); |
|
410 | + } |
|
411 | + |
|
412 | + $oldUsername = $user->getUsername(); |
|
413 | + $user->setUsername($newUsername); |
|
414 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
415 | + |
|
416 | + $user->save(); |
|
417 | + |
|
418 | + $logEntryData = serialize(array( |
|
419 | + 'old' => $oldUsername, |
|
420 | + 'new' => $newUsername, |
|
421 | + )); |
|
422 | + |
|
423 | + Logger::renamedUser($database, $user, $logEntryData); |
|
424 | + |
|
425 | + SessionAlert::quick("Changed User " |
|
426 | + . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8') |
|
427 | + . " name to " |
|
428 | + . htmlentities($newUsername, ENT_COMPAT, 'UTF-8')); |
|
429 | + |
|
430 | + $this->getNotificationHelper()->userRenamed($user, $oldUsername); |
|
431 | + |
|
432 | + // send an email to the user. |
|
433 | + $this->assign('targetUsername', $user->getUsername()); |
|
434 | + $this->assign('toolAdmin', User::getCurrent($database)->getUsername()); |
|
435 | + $this->assign('oldUsername', $oldUsername); |
|
436 | + $this->assign('mailingList', $this->adminMailingList); |
|
437 | + |
|
438 | + $this->getEmailHelper()->sendMail( |
|
439 | + $user->getEmail(), |
|
440 | + 'Your username on WP:ACC has been changed', |
|
441 | + $this->fetchTemplate('usermanagement/emails/renamed.tpl'), |
|
442 | + array('Reply-To' => $this->adminMailingList) |
|
443 | + ); |
|
444 | + |
|
445 | + $this->redirect("userManagement"); |
|
446 | + |
|
447 | + return; |
|
448 | + } |
|
449 | + else { |
|
450 | + $this->assignCSRFToken(); |
|
451 | + $this->setTemplate('usermanagement/renameuser.tpl'); |
|
452 | + $this->assign('user', $user); |
|
453 | + } |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Entry point for the edit action |
|
458 | + * |
|
459 | + * @throws ApplicationLogicException |
|
460 | + */ |
|
461 | + protected function editUser() |
|
462 | + { |
|
463 | + $this->setHtmlTitle('User Management'); |
|
464 | + |
|
465 | + $database = $this->getDatabase(); |
|
466 | + |
|
467 | + $userId = WebRequest::getInt('user'); |
|
468 | + $user = User::getById($userId, $database); |
|
469 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
470 | + |
|
471 | + if ($user === false) { |
|
472 | + throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
473 | + } |
|
474 | + |
|
475 | + // Dual-mode action |
|
476 | + if (WebRequest::wasPosted()) { |
|
477 | + $this->validateCSRFToken(); |
|
478 | + $newEmail = WebRequest::postEmail('user_email'); |
|
479 | + $newOnWikiName = WebRequest::postString('user_onwikiname'); |
|
480 | + |
|
481 | + if ($newEmail === null) { |
|
482 | + throw new ApplicationLogicException('Invalid email address'); |
|
483 | + } |
|
484 | + |
|
485 | + if (!$oauth->isFullyLinked()) { |
|
486 | + if (trim($newOnWikiName) == "") { |
|
487 | + throw new ApplicationLogicException('New on-wiki username cannot be blank'); |
|
488 | + } |
|
489 | + |
|
490 | + $user->setOnWikiName($newOnWikiName); |
|
491 | + } |
|
492 | + |
|
493 | + $user->setEmail($newEmail); |
|
494 | + |
|
495 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
496 | + |
|
497 | + $user->save(); |
|
498 | + |
|
499 | + Logger::userPreferencesChange($database, $user); |
|
500 | + $this->getNotificationHelper()->userPrefChange($user); |
|
501 | + SessionAlert::quick('Changes to user\'s preferences have been saved'); |
|
502 | + |
|
503 | + $this->redirect("userManagement"); |
|
504 | + |
|
505 | + return; |
|
506 | + } |
|
507 | + else { |
|
508 | + $this->assignCSRFToken(); |
|
509 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
510 | + $this->getSiteConfiguration()); |
|
511 | + $this->setTemplate('usermanagement/edituser.tpl'); |
|
512 | + $this->assign('user', $user); |
|
513 | + $this->assign('oauth', $oauth); |
|
514 | + } |
|
515 | + } |
|
516 | + |
|
517 | + #endregion |
|
518 | + |
|
519 | + /** |
|
520 | + * Sends a status change email to the user. |
|
521 | + * |
|
522 | + * @param string $subject The subject of the email |
|
523 | + * @param string $template The smarty template to use |
|
524 | + * @param string|null $reason The reason for performing the status change |
|
525 | + * @param User $user The user affected |
|
526 | + * @param string $toolAdminUsername The tool admin's username who is making the edit |
|
527 | + */ |
|
528 | + private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername) |
|
529 | + { |
|
530 | + $this->assign('targetUsername', $user->getUsername()); |
|
531 | + $this->assign('toolAdmin', $toolAdminUsername); |
|
532 | + $this->assign('actionReason', $reason); |
|
533 | + $this->assign('mailingList', $this->adminMailingList); |
|
534 | + |
|
535 | + $this->getEmailHelper()->sendMail( |
|
536 | + $user->getEmail(), |
|
537 | + $subject, |
|
538 | + $this->fetchTemplate($template), |
|
539 | + array('Reply-To' => $this->adminMailingList) |
|
540 | + ); |
|
541 | + } |
|
542 | + |
|
543 | + /** |
|
544 | + * @param UserRole[] $activeRoles |
|
545 | + * |
|
546 | + * @return array |
|
547 | + */ |
|
548 | + private function getRoleData($activeRoles) |
|
549 | + { |
|
550 | + $availableRoles = $this->getSecurityManager()->getRoleConfiguration()->getAvailableRoles(); |
|
551 | + |
|
552 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
553 | + $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles); |
|
554 | + |
|
555 | + $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null); |
|
556 | + |
|
557 | + $roleData = array(); |
|
558 | + foreach ($availableRoles as $role => $data) { |
|
559 | + $intersection = array_intersect($data['editableBy'], $userRoles); |
|
560 | + |
|
561 | + $roleData[$role] = $initialValue; |
|
562 | + $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0; |
|
563 | + $roleData[$role]['description'] = $data['description']; |
|
564 | + } |
|
565 | + |
|
566 | + foreach ($activeRoles as $role) { |
|
567 | + if (!isset($roleData[$role->getRole()])) { |
|
568 | + // This value is no longer available in the configuration, allow changing (aka removing) it. |
|
569 | + $roleData[$role->getRole()] = $initialValue; |
|
570 | + $roleData[$role->getRole()]['allowEdit'] = 1; |
|
571 | + } |
|
572 | + |
|
573 | + $roleData[$role->getRole()]['object'] = $role; |
|
574 | + $roleData[$role->getRole()]['active'] = 1; |
|
575 | + } |
|
576 | + |
|
577 | + return $roleData; |
|
578 | + } |
|
579 | 579 | } |
@@ -13,136 +13,136 @@ |
||
13 | 13 | |
14 | 14 | class PageXffDemo extends InternalPageBase |
15 | 15 | { |
16 | - use RequestData; |
|
17 | - |
|
18 | - /** |
|
19 | - * @inheritDoc |
|
20 | - */ |
|
21 | - protected function main() |
|
22 | - { |
|
23 | - $this->setTemplate('xffdemo.tpl'); |
|
24 | - |
|
25 | - // requestHasForwardedIp == false |
|
26 | - // requestProxyData |
|
27 | - // requestRealIp == proxy |
|
28 | - // requestForwardedIp == xff header |
|
29 | - // forwardedOrigin == top of the chain, assuming xff is trusted |
|
30 | - |
|
31 | - |
|
32 | - $this->assign('demo2', [ |
|
33 | - [ |
|
34 | - 'trust' => true, |
|
35 | - 'trustedlink' => true, |
|
36 | - 'ip' => '172.16.0.164', |
|
37 | - 'routable' => false, |
|
38 | - |
|
39 | - ],[ |
|
40 | - 'trust' => true, |
|
41 | - 'ip' => '198.51.100.123', |
|
42 | - 'routable' => true, |
|
43 | - 'rdns' => 'trustedproxy.example.com', |
|
44 | - |
|
45 | - ],[ |
|
46 | - 'trust' => true, |
|
47 | - 'ip' => '192.0.2.1', |
|
48 | - 'routable' => true, |
|
49 | - 'rdns' => 'client.users.example.org', |
|
50 | - 'location' => [ |
|
51 | - 'cityName' => 'San Francisco', |
|
52 | - 'regionName' => 'California', |
|
53 | - 'countryName' => 'United States' |
|
54 | - ], |
|
55 | - 'showlinks' => true |
|
56 | - ] |
|
57 | - ]); |
|
58 | - |
|
59 | - $this->assign('demo3', [ |
|
60 | - [ |
|
61 | - 'trust' => true, |
|
62 | - 'trustedlink' => true, |
|
63 | - 'ip' => '172.16.0.164', |
|
64 | - 'routable' => false, |
|
65 | - |
|
66 | - ],[ |
|
67 | - 'trust' => false, |
|
68 | - 'ip' => '198.51.100.234', |
|
69 | - 'routable' => true, |
|
70 | - 'rdns' => 'sketchyproxy.example.com', |
|
71 | - 'showlinks' => true |
|
72 | - |
|
73 | - ],[ |
|
74 | - 'trust' => false, |
|
75 | - 'ip' => '192.0.2.1', |
|
76 | - 'routable' => true, |
|
77 | - 'rdns' => 'client.users.example.org', |
|
78 | - 'location' => [ |
|
79 | - 'cityName' => 'San Francisco', |
|
80 | - 'regionName' => 'California', |
|
81 | - 'countryName' => 'United States' |
|
82 | - ], |
|
83 | - 'showlinks' => true |
|
84 | - ] |
|
85 | - ]); |
|
86 | - |
|
87 | - $this->assign('demo4', [ |
|
88 | - [ |
|
89 | - 'trust' => true, |
|
90 | - 'trustedlink' => true, |
|
91 | - 'ip' => '172.16.0.164', |
|
92 | - 'routable' => false, |
|
93 | - |
|
94 | - ],[ |
|
95 | - 'trust' => true, |
|
96 | - 'ip' => '198.51.100.123', |
|
97 | - 'routable' => true, |
|
98 | - 'rdns' => 'trustedproxy.example.com', |
|
99 | - ],[ |
|
100 | - 'trust' => false, |
|
101 | - 'ip' => '198.51.100.234', |
|
102 | - 'routable' => true, |
|
103 | - 'rdns' => 'sketchyproxy.example.com', |
|
104 | - 'showlinks' => true |
|
105 | - ], [ |
|
106 | - 'trust' => false, |
|
107 | - 'trustedlink' => true, |
|
108 | - 'ip' => '198.51.100.124', |
|
109 | - 'routable' => true, |
|
110 | - 'rdns' => 'trustedproxy2.example.com', |
|
111 | - 'showlinks' => true |
|
112 | - ],[ |
|
113 | - 'trust' => false, |
|
114 | - 'ip' => '192.0.2.1', |
|
115 | - 'routable' => true, |
|
116 | - 'rdns' => 'client.users.example.org', |
|
117 | - 'location' => [ |
|
118 | - 'cityName' => 'San Francisco', |
|
119 | - 'regionName' => 'California', |
|
120 | - 'countryName' => 'United States' |
|
121 | - ], |
|
122 | - 'showlinks' => true |
|
123 | - ] |
|
124 | - ]); |
|
125 | - |
|
126 | - $this->assign('demo1', [ |
|
127 | - [ |
|
128 | - 'trust' => true, |
|
129 | - 'trustedlink' => true, |
|
130 | - 'ip' => '172.16.0.164', |
|
131 | - 'routable' => false, |
|
132 | - |
|
133 | - ], [ |
|
134 | - 'trust' => true, |
|
135 | - 'trustedlink' => true, |
|
136 | - 'ip' => '192.0.2.1', |
|
137 | - 'routable' => true, |
|
138 | - 'rdns' => 'client.users.example.org', |
|
139 | - 'location' => [ |
|
140 | - 'cityName' => 'San Francisco', |
|
141 | - 'regionName' => 'California', |
|
142 | - 'countryName' => 'United States' |
|
143 | - ], |
|
144 | - 'showlinks' => true |
|
145 | - ] |
|
146 | - ]); |
|
147 | - } |
|
16 | + use RequestData; |
|
17 | + |
|
18 | + /** |
|
19 | + * @inheritDoc |
|
20 | + */ |
|
21 | + protected function main() |
|
22 | + { |
|
23 | + $this->setTemplate('xffdemo.tpl'); |
|
24 | + |
|
25 | + // requestHasForwardedIp == false |
|
26 | + // requestProxyData |
|
27 | + // requestRealIp == proxy |
|
28 | + // requestForwardedIp == xff header |
|
29 | + // forwardedOrigin == top of the chain, assuming xff is trusted |
|
30 | + |
|
31 | + |
|
32 | + $this->assign('demo2', [ |
|
33 | + [ |
|
34 | + 'trust' => true, |
|
35 | + 'trustedlink' => true, |
|
36 | + 'ip' => '172.16.0.164', |
|
37 | + 'routable' => false, |
|
38 | + |
|
39 | + ],[ |
|
40 | + 'trust' => true, |
|
41 | + 'ip' => '198.51.100.123', |
|
42 | + 'routable' => true, |
|
43 | + 'rdns' => 'trustedproxy.example.com', |
|
44 | + |
|
45 | + ],[ |
|
46 | + 'trust' => true, |
|
47 | + 'ip' => '192.0.2.1', |
|
48 | + 'routable' => true, |
|
49 | + 'rdns' => 'client.users.example.org', |
|
50 | + 'location' => [ |
|
51 | + 'cityName' => 'San Francisco', |
|
52 | + 'regionName' => 'California', |
|
53 | + 'countryName' => 'United States' |
|
54 | + ], |
|
55 | + 'showlinks' => true |
|
56 | + ] |
|
57 | + ]); |
|
58 | + |
|
59 | + $this->assign('demo3', [ |
|
60 | + [ |
|
61 | + 'trust' => true, |
|
62 | + 'trustedlink' => true, |
|
63 | + 'ip' => '172.16.0.164', |
|
64 | + 'routable' => false, |
|
65 | + |
|
66 | + ],[ |
|
67 | + 'trust' => false, |
|
68 | + 'ip' => '198.51.100.234', |
|
69 | + 'routable' => true, |
|
70 | + 'rdns' => 'sketchyproxy.example.com', |
|
71 | + 'showlinks' => true |
|
72 | + |
|
73 | + ],[ |
|
74 | + 'trust' => false, |
|
75 | + 'ip' => '192.0.2.1', |
|
76 | + 'routable' => true, |
|
77 | + 'rdns' => 'client.users.example.org', |
|
78 | + 'location' => [ |
|
79 | + 'cityName' => 'San Francisco', |
|
80 | + 'regionName' => 'California', |
|
81 | + 'countryName' => 'United States' |
|
82 | + ], |
|
83 | + 'showlinks' => true |
|
84 | + ] |
|
85 | + ]); |
|
86 | + |
|
87 | + $this->assign('demo4', [ |
|
88 | + [ |
|
89 | + 'trust' => true, |
|
90 | + 'trustedlink' => true, |
|
91 | + 'ip' => '172.16.0.164', |
|
92 | + 'routable' => false, |
|
93 | + |
|
94 | + ],[ |
|
95 | + 'trust' => true, |
|
96 | + 'ip' => '198.51.100.123', |
|
97 | + 'routable' => true, |
|
98 | + 'rdns' => 'trustedproxy.example.com', |
|
99 | + ],[ |
|
100 | + 'trust' => false, |
|
101 | + 'ip' => '198.51.100.234', |
|
102 | + 'routable' => true, |
|
103 | + 'rdns' => 'sketchyproxy.example.com', |
|
104 | + 'showlinks' => true |
|
105 | + ], [ |
|
106 | + 'trust' => false, |
|
107 | + 'trustedlink' => true, |
|
108 | + 'ip' => '198.51.100.124', |
|
109 | + 'routable' => true, |
|
110 | + 'rdns' => 'trustedproxy2.example.com', |
|
111 | + 'showlinks' => true |
|
112 | + ],[ |
|
113 | + 'trust' => false, |
|
114 | + 'ip' => '192.0.2.1', |
|
115 | + 'routable' => true, |
|
116 | + 'rdns' => 'client.users.example.org', |
|
117 | + 'location' => [ |
|
118 | + 'cityName' => 'San Francisco', |
|
119 | + 'regionName' => 'California', |
|
120 | + 'countryName' => 'United States' |
|
121 | + ], |
|
122 | + 'showlinks' => true |
|
123 | + ] |
|
124 | + ]); |
|
125 | + |
|
126 | + $this->assign('demo1', [ |
|
127 | + [ |
|
128 | + 'trust' => true, |
|
129 | + 'trustedlink' => true, |
|
130 | + 'ip' => '172.16.0.164', |
|
131 | + 'routable' => false, |
|
132 | + |
|
133 | + ], [ |
|
134 | + 'trust' => true, |
|
135 | + 'trustedlink' => true, |
|
136 | + 'ip' => '192.0.2.1', |
|
137 | + 'routable' => true, |
|
138 | + 'rdns' => 'client.users.example.org', |
|
139 | + 'location' => [ |
|
140 | + 'cityName' => 'San Francisco', |
|
141 | + 'regionName' => 'California', |
|
142 | + 'countryName' => 'United States' |
|
143 | + ], |
|
144 | + 'showlinks' => true |
|
145 | + ] |
|
146 | + ]); |
|
147 | + } |
|
148 | 148 | } |
@@ -36,13 +36,13 @@ discard block |
||
36 | 36 | 'ip' => '172.16.0.164', |
37 | 37 | 'routable' => false, |
38 | 38 | |
39 | - ],[ |
|
39 | + ], [ |
|
40 | 40 | 'trust' => true, |
41 | 41 | 'ip' => '198.51.100.123', |
42 | 42 | 'routable' => true, |
43 | 43 | 'rdns' => 'trustedproxy.example.com', |
44 | 44 | |
45 | - ],[ |
|
45 | + ], [ |
|
46 | 46 | 'trust' => true, |
47 | 47 | 'ip' => '192.0.2.1', |
48 | 48 | 'routable' => true, |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | 'ip' => '172.16.0.164', |
64 | 64 | 'routable' => false, |
65 | 65 | |
66 | - ],[ |
|
66 | + ], [ |
|
67 | 67 | 'trust' => false, |
68 | 68 | 'ip' => '198.51.100.234', |
69 | 69 | 'routable' => true, |
70 | 70 | 'rdns' => 'sketchyproxy.example.com', |
71 | 71 | 'showlinks' => true |
72 | 72 | |
73 | - ],[ |
|
73 | + ], [ |
|
74 | 74 | 'trust' => false, |
75 | 75 | 'ip' => '192.0.2.1', |
76 | 76 | 'routable' => true, |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | 'ip' => '172.16.0.164', |
92 | 92 | 'routable' => false, |
93 | 93 | |
94 | - ],[ |
|
94 | + ], [ |
|
95 | 95 | 'trust' => true, |
96 | 96 | 'ip' => '198.51.100.123', |
97 | 97 | 'routable' => true, |
98 | 98 | 'rdns' => 'trustedproxy.example.com', |
99 | - ],[ |
|
99 | + ], [ |
|
100 | 100 | 'trust' => false, |
101 | 101 | 'ip' => '198.51.100.234', |
102 | 102 | 'routable' => true, |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | 'routable' => true, |
110 | 110 | 'rdns' => 'trustedproxy2.example.com', |
111 | 111 | 'showlinks' => true |
112 | - ],[ |
|
112 | + ], [ |
|
113 | 113 | 'trust' => false, |
114 | 114 | 'ip' => '192.0.2.1', |
115 | 115 | 'routable' => true, |
@@ -152,7 +152,7 @@ |
||
152 | 152 | { |
153 | 153 | $user = User::getById($id, $database); |
154 | 154 | |
155 | - if ($user === false || $user->isCommunityUser()) { |
|
155 | + if ($user === false || $user->isCommunityUser()) { |
|
156 | 156 | throw new ApplicationLogicException("Password reset failed. Please try again."); |
157 | 157 | } |
158 | 158 |
@@ -22,208 +22,208 @@ |
||
22 | 22 | |
23 | 23 | class PageForgotPassword extends InternalPageBase |
24 | 24 | { |
25 | - /** |
|
26 | - * Main function for this page, when no specific actions are called. |
|
27 | - * |
|
28 | - * This is the forgotten password reset form |
|
29 | - * @category Security-Critical |
|
30 | - */ |
|
31 | - protected function main() |
|
32 | - { |
|
33 | - if (WebRequest::wasPosted()) { |
|
34 | - $this->validateCSRFToken(); |
|
35 | - $username = WebRequest::postString('username'); |
|
36 | - $email = WebRequest::postEmail('email'); |
|
37 | - $database = $this->getDatabase(); |
|
38 | - |
|
39 | - if ($username === null || trim($username) === "" || $email === null || trim($email) === "") { |
|
40 | - throw new ApplicationLogicException("Both username and email address must be specified!"); |
|
41 | - } |
|
42 | - |
|
43 | - $user = User::getByUsername($username, $database); |
|
44 | - $this->sendResetMail($user, $email); |
|
45 | - |
|
46 | - SessionAlert::success('<strong>Your password reset request has been completed.</strong> If the details you have provided match our records, you should receive an email shortly.'); |
|
47 | - |
|
48 | - $this->redirect('login'); |
|
49 | - } |
|
50 | - else { |
|
51 | - $this->assignCSRFToken(); |
|
52 | - $this->setTemplate('forgot-password/forgotpw.tpl'); |
|
53 | - } |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Sends a reset email if the user is authenticated |
|
58 | - * |
|
59 | - * @param User|boolean $user The user located from the database, or false. Doesn't really matter, since we do the |
|
60 | - * check anyway within this method and silently skip if we don't have a user. |
|
61 | - * @param string $email The provided email address |
|
62 | - */ |
|
63 | - private function sendResetMail($user, $email) |
|
64 | - { |
|
65 | - // If the user isn't found, or the email address is wrong, skip sending the details silently. |
|
66 | - if (!$user instanceof User) { |
|
67 | - return; |
|
68 | - } |
|
69 | - |
|
70 | - if (strtolower($user->getEmail()) === strtolower($email)) { |
|
71 | - $clientIp = $this->getXffTrustProvider() |
|
72 | - ->getTrustedClientIp(WebRequest::remoteAddress(), WebRequest::forwardedAddress()); |
|
73 | - |
|
74 | - $this->cleanExistingTokens($user); |
|
75 | - |
|
76 | - $hash = Base32::encodeUpper(openssl_random_pseudo_bytes(30)); |
|
77 | - |
|
78 | - $encryptionHelper = new EncryptionHelper($this->getSiteConfiguration()); |
|
79 | - |
|
80 | - $cred = new Credential(); |
|
81 | - $cred->setDatabase($this->getDatabase()); |
|
82 | - $cred->setFactor(-1); |
|
83 | - $cred->setUserId($user->getId()); |
|
84 | - $cred->setType('reset'); |
|
85 | - $cred->setData($encryptionHelper->encryptData($hash)); |
|
86 | - $cred->setVersion(0); |
|
87 | - $cred->setDisabled(0); |
|
88 | - $cred->setTimeout(new DateTimeImmutable('+ 1 hour')); |
|
89 | - $cred->setPriority(9); |
|
90 | - $cred->save(); |
|
91 | - |
|
92 | - $this->assign("user", $user); |
|
93 | - $this->assign("hash", $hash); |
|
94 | - $this->assign("remoteAddress", $clientIp); |
|
95 | - |
|
96 | - $emailContent = $this->fetchTemplate('forgot-password/reset-mail.tpl'); |
|
97 | - |
|
98 | - $this->getEmailHelper()->sendMail($user->getEmail(), "WP:ACC password reset", $emailContent); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Entry point for the reset action |
|
104 | - * |
|
105 | - * This is the reset password part of the form. |
|
106 | - * @category Security-Critical |
|
107 | - */ |
|
108 | - protected function reset() |
|
109 | - { |
|
110 | - $si = WebRequest::getString('si'); |
|
111 | - $id = WebRequest::getString('id'); |
|
112 | - |
|
113 | - if ($si === null || trim($si) === "" || $id === null || trim($id) === "") { |
|
114 | - throw new ApplicationLogicException("Link not valid, please ensure it has copied correctly"); |
|
115 | - } |
|
116 | - |
|
117 | - $database = $this->getDatabase(); |
|
118 | - $user = $this->getResettingUser($id, $database, $si); |
|
119 | - |
|
120 | - // Dual mode |
|
121 | - if (WebRequest::wasPosted()) { |
|
122 | - $this->validateCSRFToken(); |
|
123 | - try { |
|
124 | - $this->doReset($user); |
|
125 | - $this->cleanExistingTokens($user); |
|
126 | - } |
|
127 | - catch (ApplicationLogicException $ex) { |
|
128 | - SessionAlert::error($ex->getMessage()); |
|
129 | - $this->redirect('forgotPassword', 'reset', array('si' => $si, 'id' => $id)); |
|
130 | - |
|
131 | - return; |
|
132 | - } |
|
133 | - } |
|
134 | - else { |
|
135 | - $this->assignCSRFToken(); |
|
136 | - $this->assign('user', $user); |
|
137 | - $this->setTemplate('forgot-password/forgotpwreset.tpl'); |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Gets the user resetting their password from the database, or throwing an exception if that is not possible. |
|
143 | - * |
|
144 | - * @param integer $id The ID of the user to retrieve |
|
145 | - * @param PdoDatabase $database The database object to use |
|
146 | - * @param string $si The reset hash provided |
|
147 | - * |
|
148 | - * @return User |
|
149 | - * @throws ApplicationLogicException |
|
150 | - */ |
|
151 | - private function getResettingUser($id, $database, $si) |
|
152 | - { |
|
153 | - $user = User::getById($id, $database); |
|
154 | - |
|
155 | - if ($user === false || $user->isCommunityUser()) { |
|
156 | - throw new ApplicationLogicException("Password reset failed. Please try again."); |
|
157 | - } |
|
158 | - |
|
159 | - $statement = $database->prepare("SELECT * FROM credential WHERE type = 'reset' AND user = :user;"); |
|
160 | - $statement->execute([':user' => $user->getId()]); |
|
161 | - |
|
162 | - /** @var Credential $credential */ |
|
163 | - $credential = $statement->fetchObject(Credential::class); |
|
164 | - |
|
165 | - $statement->closeCursor(); |
|
166 | - |
|
167 | - if ($credential === false) { |
|
168 | - throw new ApplicationLogicException("Password reset failed. Please try again."); |
|
169 | - } |
|
170 | - |
|
171 | - $credential->setDatabase($database); |
|
172 | - |
|
173 | - $encryptionHelper = new EncryptionHelper($this->getSiteConfiguration()); |
|
174 | - if ($encryptionHelper->decryptData($credential->getData()) != $si) { |
|
175 | - throw new ApplicationLogicException("Password reset failed. Please try again."); |
|
176 | - } |
|
177 | - |
|
178 | - if ($credential->getTimeout() < new DateTimeImmutable()) { |
|
179 | - $credential->delete(); |
|
180 | - throw new ApplicationLogicException("Password reset token expired. Please try again."); |
|
181 | - } |
|
182 | - |
|
183 | - return $user; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Performs the setting of the new password |
|
188 | - * |
|
189 | - * @param User $user The user to set the password for |
|
190 | - * |
|
191 | - * @throws ApplicationLogicException |
|
192 | - */ |
|
193 | - private function doReset(User $user) |
|
194 | - { |
|
195 | - $pw = WebRequest::postString('pw'); |
|
196 | - $pw2 = WebRequest::postString('pw2'); |
|
197 | - |
|
198 | - if ($pw !== $pw2) { |
|
199 | - throw new ApplicationLogicException('Passwords do not match!'); |
|
200 | - } |
|
201 | - |
|
202 | - $passwordCredentialProvider = new PasswordCredentialProvider($user->getDatabase(), $this->getSiteConfiguration()); |
|
203 | - $passwordCredentialProvider->setCredential($user, 1, $pw); |
|
204 | - |
|
205 | - SessionAlert::success('You may now log in!'); |
|
206 | - $this->redirect('login'); |
|
207 | - } |
|
208 | - |
|
209 | - protected function isProtectedPage() |
|
210 | - { |
|
211 | - return false; |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @param $user |
|
216 | - */ |
|
217 | - private function cleanExistingTokens($user): void |
|
218 | - { |
|
219 | - // clean out existing reset tokens |
|
220 | - $statement = $this->getDatabase()->prepare("SELECT * FROM credential WHERE type = 'reset' AND user = :user;"); |
|
221 | - $statement->execute([':user' => $user->getId()]); |
|
222 | - $existing = $statement->fetchAll(PdoDatabase::FETCH_CLASS, Credential::class); |
|
223 | - |
|
224 | - foreach ($existing as $c) { |
|
225 | - $c->setDatabase($this->getDatabase()); |
|
226 | - $c->delete(); |
|
227 | - } |
|
228 | - } |
|
25 | + /** |
|
26 | + * Main function for this page, when no specific actions are called. |
|
27 | + * |
|
28 | + * This is the forgotten password reset form |
|
29 | + * @category Security-Critical |
|
30 | + */ |
|
31 | + protected function main() |
|
32 | + { |
|
33 | + if (WebRequest::wasPosted()) { |
|
34 | + $this->validateCSRFToken(); |
|
35 | + $username = WebRequest::postString('username'); |
|
36 | + $email = WebRequest::postEmail('email'); |
|
37 | + $database = $this->getDatabase(); |
|
38 | + |
|
39 | + if ($username === null || trim($username) === "" || $email === null || trim($email) === "") { |
|
40 | + throw new ApplicationLogicException("Both username and email address must be specified!"); |
|
41 | + } |
|
42 | + |
|
43 | + $user = User::getByUsername($username, $database); |
|
44 | + $this->sendResetMail($user, $email); |
|
45 | + |
|
46 | + SessionAlert::success('<strong>Your password reset request has been completed.</strong> If the details you have provided match our records, you should receive an email shortly.'); |
|
47 | + |
|
48 | + $this->redirect('login'); |
|
49 | + } |
|
50 | + else { |
|
51 | + $this->assignCSRFToken(); |
|
52 | + $this->setTemplate('forgot-password/forgotpw.tpl'); |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Sends a reset email if the user is authenticated |
|
58 | + * |
|
59 | + * @param User|boolean $user The user located from the database, or false. Doesn't really matter, since we do the |
|
60 | + * check anyway within this method and silently skip if we don't have a user. |
|
61 | + * @param string $email The provided email address |
|
62 | + */ |
|
63 | + private function sendResetMail($user, $email) |
|
64 | + { |
|
65 | + // If the user isn't found, or the email address is wrong, skip sending the details silently. |
|
66 | + if (!$user instanceof User) { |
|
67 | + return; |
|
68 | + } |
|
69 | + |
|
70 | + if (strtolower($user->getEmail()) === strtolower($email)) { |
|
71 | + $clientIp = $this->getXffTrustProvider() |
|
72 | + ->getTrustedClientIp(WebRequest::remoteAddress(), WebRequest::forwardedAddress()); |
|
73 | + |
|
74 | + $this->cleanExistingTokens($user); |
|
75 | + |
|
76 | + $hash = Base32::encodeUpper(openssl_random_pseudo_bytes(30)); |
|
77 | + |
|
78 | + $encryptionHelper = new EncryptionHelper($this->getSiteConfiguration()); |
|
79 | + |
|
80 | + $cred = new Credential(); |
|
81 | + $cred->setDatabase($this->getDatabase()); |
|
82 | + $cred->setFactor(-1); |
|
83 | + $cred->setUserId($user->getId()); |
|
84 | + $cred->setType('reset'); |
|
85 | + $cred->setData($encryptionHelper->encryptData($hash)); |
|
86 | + $cred->setVersion(0); |
|
87 | + $cred->setDisabled(0); |
|
88 | + $cred->setTimeout(new DateTimeImmutable('+ 1 hour')); |
|
89 | + $cred->setPriority(9); |
|
90 | + $cred->save(); |
|
91 | + |
|
92 | + $this->assign("user", $user); |
|
93 | + $this->assign("hash", $hash); |
|
94 | + $this->assign("remoteAddress", $clientIp); |
|
95 | + |
|
96 | + $emailContent = $this->fetchTemplate('forgot-password/reset-mail.tpl'); |
|
97 | + |
|
98 | + $this->getEmailHelper()->sendMail($user->getEmail(), "WP:ACC password reset", $emailContent); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Entry point for the reset action |
|
104 | + * |
|
105 | + * This is the reset password part of the form. |
|
106 | + * @category Security-Critical |
|
107 | + */ |
|
108 | + protected function reset() |
|
109 | + { |
|
110 | + $si = WebRequest::getString('si'); |
|
111 | + $id = WebRequest::getString('id'); |
|
112 | + |
|
113 | + if ($si === null || trim($si) === "" || $id === null || trim($id) === "") { |
|
114 | + throw new ApplicationLogicException("Link not valid, please ensure it has copied correctly"); |
|
115 | + } |
|
116 | + |
|
117 | + $database = $this->getDatabase(); |
|
118 | + $user = $this->getResettingUser($id, $database, $si); |
|
119 | + |
|
120 | + // Dual mode |
|
121 | + if (WebRequest::wasPosted()) { |
|
122 | + $this->validateCSRFToken(); |
|
123 | + try { |
|
124 | + $this->doReset($user); |
|
125 | + $this->cleanExistingTokens($user); |
|
126 | + } |
|
127 | + catch (ApplicationLogicException $ex) { |
|
128 | + SessionAlert::error($ex->getMessage()); |
|
129 | + $this->redirect('forgotPassword', 'reset', array('si' => $si, 'id' => $id)); |
|
130 | + |
|
131 | + return; |
|
132 | + } |
|
133 | + } |
|
134 | + else { |
|
135 | + $this->assignCSRFToken(); |
|
136 | + $this->assign('user', $user); |
|
137 | + $this->setTemplate('forgot-password/forgotpwreset.tpl'); |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Gets the user resetting their password from the database, or throwing an exception if that is not possible. |
|
143 | + * |
|
144 | + * @param integer $id The ID of the user to retrieve |
|
145 | + * @param PdoDatabase $database The database object to use |
|
146 | + * @param string $si The reset hash provided |
|
147 | + * |
|
148 | + * @return User |
|
149 | + * @throws ApplicationLogicException |
|
150 | + */ |
|
151 | + private function getResettingUser($id, $database, $si) |
|
152 | + { |
|
153 | + $user = User::getById($id, $database); |
|
154 | + |
|
155 | + if ($user === false || $user->isCommunityUser()) { |
|
156 | + throw new ApplicationLogicException("Password reset failed. Please try again."); |
|
157 | + } |
|
158 | + |
|
159 | + $statement = $database->prepare("SELECT * FROM credential WHERE type = 'reset' AND user = :user;"); |
|
160 | + $statement->execute([':user' => $user->getId()]); |
|
161 | + |
|
162 | + /** @var Credential $credential */ |
|
163 | + $credential = $statement->fetchObject(Credential::class); |
|
164 | + |
|
165 | + $statement->closeCursor(); |
|
166 | + |
|
167 | + if ($credential === false) { |
|
168 | + throw new ApplicationLogicException("Password reset failed. Please try again."); |
|
169 | + } |
|
170 | + |
|
171 | + $credential->setDatabase($database); |
|
172 | + |
|
173 | + $encryptionHelper = new EncryptionHelper($this->getSiteConfiguration()); |
|
174 | + if ($encryptionHelper->decryptData($credential->getData()) != $si) { |
|
175 | + throw new ApplicationLogicException("Password reset failed. Please try again."); |
|
176 | + } |
|
177 | + |
|
178 | + if ($credential->getTimeout() < new DateTimeImmutable()) { |
|
179 | + $credential->delete(); |
|
180 | + throw new ApplicationLogicException("Password reset token expired. Please try again."); |
|
181 | + } |
|
182 | + |
|
183 | + return $user; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Performs the setting of the new password |
|
188 | + * |
|
189 | + * @param User $user The user to set the password for |
|
190 | + * |
|
191 | + * @throws ApplicationLogicException |
|
192 | + */ |
|
193 | + private function doReset(User $user) |
|
194 | + { |
|
195 | + $pw = WebRequest::postString('pw'); |
|
196 | + $pw2 = WebRequest::postString('pw2'); |
|
197 | + |
|
198 | + if ($pw !== $pw2) { |
|
199 | + throw new ApplicationLogicException('Passwords do not match!'); |
|
200 | + } |
|
201 | + |
|
202 | + $passwordCredentialProvider = new PasswordCredentialProvider($user->getDatabase(), $this->getSiteConfiguration()); |
|
203 | + $passwordCredentialProvider->setCredential($user, 1, $pw); |
|
204 | + |
|
205 | + SessionAlert::success('You may now log in!'); |
|
206 | + $this->redirect('login'); |
|
207 | + } |
|
208 | + |
|
209 | + protected function isProtectedPage() |
|
210 | + { |
|
211 | + return false; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @param $user |
|
216 | + */ |
|
217 | + private function cleanExistingTokens($user): void |
|
218 | + { |
|
219 | + // clean out existing reset tokens |
|
220 | + $statement = $this->getDatabase()->prepare("SELECT * FROM credential WHERE type = 'reset' AND user = :user;"); |
|
221 | + $statement->execute([':user' => $user->getId()]); |
|
222 | + $existing = $statement->fetchAll(PdoDatabase::FETCH_CLASS, Credential::class); |
|
223 | + |
|
224 | + foreach ($existing as $c) { |
|
225 | + $c->setDatabase($this->getDatabase()); |
|
226 | + $c->delete(); |
|
227 | + } |
|
228 | + } |
|
229 | 229 | } |
@@ -18,62 +18,62 @@ |
||
18 | 18 | |
19 | 19 | class PageLog extends PagedInternalPageBase |
20 | 20 | { |
21 | - /** |
|
22 | - * Main function for this page, when no specific actions are called. |
|
23 | - */ |
|
24 | - protected function main() |
|
25 | - { |
|
26 | - $this->setHtmlTitle('Logs'); |
|
27 | - |
|
28 | - $filterUser = WebRequest::getString('filterUser'); |
|
29 | - $filterAction = WebRequest::getString('filterAction'); |
|
30 | - $filterObjectType = WebRequest::getString('filterObjectType'); |
|
31 | - $filterObjectId = WebRequest::getInt('filterObjectId'); |
|
32 | - |
|
33 | - $database = $this->getDatabase(); |
|
34 | - |
|
35 | - if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) { |
|
36 | - $filterObjectType = null; |
|
37 | - } |
|
38 | - |
|
39 | - $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
40 | - |
|
41 | - $logSearch = LogSearchHelper::get($database); |
|
42 | - |
|
43 | - if ($filterUser !== null) { |
|
44 | - $userObj = User::getByUsername($filterUser, $database); |
|
45 | - if ($userObj !== false) { |
|
46 | - $logSearch->byUser($userObj->getId()); |
|
47 | - } else { |
|
48 | - $logSearch->byUser(-1); |
|
49 | - } |
|
50 | - } |
|
51 | - if ($filterAction !== null) { |
|
52 | - $logSearch->byAction($filterAction); |
|
53 | - } |
|
54 | - if ($filterObjectType !== null) { |
|
55 | - $logSearch->byObjectType($filterObjectType); |
|
56 | - } |
|
57 | - if ($filterObjectId !== null) { |
|
58 | - $logSearch->byObjectId($filterObjectId); |
|
59 | - } |
|
60 | - |
|
61 | - $this->setSearchHelper($logSearch); |
|
62 | - $this->setupLimits(); |
|
63 | - |
|
64 | - /** @var Log[] $logs */ |
|
65 | - $logs = $logSearch->getRecordCount($count)->fetch(); |
|
66 | - |
|
67 | - list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
68 | - |
|
69 | - $this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId)); |
|
70 | - |
|
71 | - $this->assign("logs", $logData); |
|
72 | - $this->assign("users", $users); |
|
73 | - |
|
74 | - $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase())); |
|
75 | - $this->assign('allObjectTypes', LogHelper::getObjectTypes()); |
|
76 | - |
|
77 | - $this->setTemplate("logs/main.tpl"); |
|
78 | - } |
|
21 | + /** |
|
22 | + * Main function for this page, when no specific actions are called. |
|
23 | + */ |
|
24 | + protected function main() |
|
25 | + { |
|
26 | + $this->setHtmlTitle('Logs'); |
|
27 | + |
|
28 | + $filterUser = WebRequest::getString('filterUser'); |
|
29 | + $filterAction = WebRequest::getString('filterAction'); |
|
30 | + $filterObjectType = WebRequest::getString('filterObjectType'); |
|
31 | + $filterObjectId = WebRequest::getInt('filterObjectId'); |
|
32 | + |
|
33 | + $database = $this->getDatabase(); |
|
34 | + |
|
35 | + if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) { |
|
36 | + $filterObjectType = null; |
|
37 | + } |
|
38 | + |
|
39 | + $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
40 | + |
|
41 | + $logSearch = LogSearchHelper::get($database); |
|
42 | + |
|
43 | + if ($filterUser !== null) { |
|
44 | + $userObj = User::getByUsername($filterUser, $database); |
|
45 | + if ($userObj !== false) { |
|
46 | + $logSearch->byUser($userObj->getId()); |
|
47 | + } else { |
|
48 | + $logSearch->byUser(-1); |
|
49 | + } |
|
50 | + } |
|
51 | + if ($filterAction !== null) { |
|
52 | + $logSearch->byAction($filterAction); |
|
53 | + } |
|
54 | + if ($filterObjectType !== null) { |
|
55 | + $logSearch->byObjectType($filterObjectType); |
|
56 | + } |
|
57 | + if ($filterObjectId !== null) { |
|
58 | + $logSearch->byObjectId($filterObjectId); |
|
59 | + } |
|
60 | + |
|
61 | + $this->setSearchHelper($logSearch); |
|
62 | + $this->setupLimits(); |
|
63 | + |
|
64 | + /** @var Log[] $logs */ |
|
65 | + $logs = $logSearch->getRecordCount($count)->fetch(); |
|
66 | + |
|
67 | + list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
68 | + |
|
69 | + $this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId)); |
|
70 | + |
|
71 | + $this->assign("logs", $logData); |
|
72 | + $this->assign("users", $users); |
|
73 | + |
|
74 | + $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase())); |
|
75 | + $this->assign('allObjectTypes', LogHelper::getObjectTypes()); |
|
76 | + |
|
77 | + $this->setTemplate("logs/main.tpl"); |
|
78 | + } |
|
79 | 79 | } |
@@ -44,7 +44,8 @@ |
||
44 | 44 | $userObj = User::getByUsername($filterUser, $database); |
45 | 45 | if ($userObj !== false) { |
46 | 46 | $logSearch->byUser($userObj->getId()); |
47 | - } else { |
|
47 | + } |
|
48 | + else { |
|
48 | 49 | $logSearch->byUser(-1); |
49 | 50 | } |
50 | 51 | } |
@@ -14,68 +14,68 @@ |
||
14 | 14 | |
15 | 15 | abstract class JsonApiPageBase extends ApiPageBase implements IJsonApiAction |
16 | 16 | { |
17 | - /** |
|
18 | - * Main function for this page, when no specific actions are called. |
|
19 | - * |
|
20 | - * @return void |
|
21 | - * @throws ApiException |
|
22 | - */ |
|
23 | - final protected function main() |
|
24 | - { |
|
25 | - if (headers_sent()) { |
|
26 | - throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
27 | - } |
|
17 | + /** |
|
18 | + * Main function for this page, when no specific actions are called. |
|
19 | + * |
|
20 | + * @return void |
|
21 | + * @throws ApiException |
|
22 | + */ |
|
23 | + final protected function main() |
|
24 | + { |
|
25 | + if (headers_sent()) { |
|
26 | + throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
27 | + } |
|
28 | 28 | |
29 | - // javascript access control |
|
30 | - $httpOrigin = WebRequest::origin(); |
|
29 | + // javascript access control |
|
30 | + $httpOrigin = WebRequest::origin(); |
|
31 | 31 | |
32 | - if ($httpOrigin !== null) { |
|
33 | - $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
32 | + if ($httpOrigin !== null) { |
|
33 | + $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
34 | 34 | |
35 | - if (in_array($httpOrigin, $CORSallowed)) { |
|
36 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
37 | - } |
|
38 | - } |
|
35 | + if (in_array($httpOrigin, $CORSallowed)) { |
|
36 | + header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
37 | + } |
|
38 | + } |
|
39 | 39 | |
40 | - $responseData = $this->runApiPage(); |
|
40 | + $responseData = $this->runApiPage(); |
|
41 | 41 | |
42 | - ob_end_clean(); |
|
43 | - print($responseData); |
|
44 | - ob_start(); |
|
45 | - } |
|
42 | + ob_end_clean(); |
|
43 | + print($responseData); |
|
44 | + ob_start(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Method that runs API action |
|
49 | - * |
|
50 | - * @return object|array The modified API document |
|
51 | - */ |
|
52 | - public abstract function executeApiAction(); |
|
47 | + /** |
|
48 | + * Method that runs API action |
|
49 | + * |
|
50 | + * @return object|array The modified API document |
|
51 | + */ |
|
52 | + public abstract function executeApiAction(); |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - final public function runApiPage() |
|
58 | - { |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + final public function runApiPage() |
|
58 | + { |
|
59 | 59 | |
60 | - try { |
|
61 | - $apiDocument = $this->executeApiAction(); |
|
62 | - } |
|
63 | - catch (ApiException $ex) { |
|
64 | - $apiDocument = [ |
|
65 | - 'error' => $ex->getMessage(), |
|
66 | - ]; |
|
67 | - } |
|
60 | + try { |
|
61 | + $apiDocument = $this->executeApiAction(); |
|
62 | + } |
|
63 | + catch (ApiException $ex) { |
|
64 | + $apiDocument = [ |
|
65 | + 'error' => $ex->getMessage(), |
|
66 | + ]; |
|
67 | + } |
|
68 | 68 | |
69 | - $data = json_encode($apiDocument, JSON_UNESCAPED_UNICODE); |
|
69 | + $data = json_encode($apiDocument, JSON_UNESCAPED_UNICODE); |
|
70 | 70 | |
71 | - $targetVar = WebRequest::getString('targetVariable'); |
|
72 | - if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
|
73 | - $data = $targetVar . ' = ' . $data . ';'; |
|
74 | - header("Content-Type: text/javascript"); |
|
75 | - } else { |
|
76 | - header("Content-Type: application/json"); |
|
77 | - } |
|
71 | + $targetVar = WebRequest::getString('targetVariable'); |
|
72 | + if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
|
73 | + $data = $targetVar . ' = ' . $data . ';'; |
|
74 | + header("Content-Type: text/javascript"); |
|
75 | + } else { |
|
76 | + header("Content-Type: application/json"); |
|
77 | + } |
|
78 | 78 | |
79 | - return $data; |
|
80 | - } |
|
79 | + return $data; |
|
80 | + } |
|
81 | 81 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
34 | 34 | |
35 | 35 | if (in_array($httpOrigin, $CORSallowed)) { |
36 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
36 | + header("Access-Control-Allow-Origin: ".$httpOrigin); |
|
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | $targetVar = WebRequest::getString('targetVariable'); |
72 | 72 | if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
73 | - $data = $targetVar . ' = ' . $data . ';'; |
|
73 | + $data = $targetVar.' = '.$data.';'; |
|
74 | 74 | header("Content-Type: text/javascript"); |
75 | 75 | } else { |
76 | 76 | header("Content-Type: application/json"); |
@@ -72,7 +72,8 @@ |
||
72 | 72 | if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
73 | 73 | $data = $targetVar . ' = ' . $data . ';'; |
74 | 74 | header("Content-Type: text/javascript"); |
75 | - } else { |
|
75 | + } |
|
76 | + else { |
|
76 | 77 | header("Content-Type: application/json"); |
77 | 78 | } |
78 | 79 |
@@ -14,20 +14,20 @@ discard block |
||
14 | 14 | |
15 | 15 | class PageU2FLogin extends LoginCredentialPageBase |
16 | 16 | { |
17 | - protected function providerSpecificSetup() |
|
18 | - { |
|
19 | - $this->assign('showSignIn', false); |
|
20 | - $this->setTemplate('login/u2f.tpl'); |
|
17 | + protected function providerSpecificSetup() |
|
18 | + { |
|
19 | + $this->assign('showSignIn', false); |
|
20 | + $this->setTemplate('login/u2f.tpl'); |
|
21 | 21 | |
22 | - if ($this->partialUser === null) { |
|
23 | - throw new ApplicationLogicException("U2F cannot be first-stage authentication"); |
|
24 | - } |
|
22 | + if ($this->partialUser === null) { |
|
23 | + throw new ApplicationLogicException("U2F cannot be first-stage authentication"); |
|
24 | + } |
|
25 | 25 | |
26 | - $u2f = new U2FCredentialProvider($this->getDatabase(), $this->getSiteConfiguration()); |
|
27 | - $authData = json_encode($u2f->getAuthenticationData($this->partialUser)); |
|
26 | + $u2f = new U2FCredentialProvider($this->getDatabase(), $this->getSiteConfiguration()); |
|
27 | + $authData = json_encode($u2f->getAuthenticationData($this->partialUser)); |
|
28 | 28 | |
29 | - $this->addJs('/vendor/yubico/u2flib-server/examples/assets/u2f-api.js'); |
|
30 | - $this->setTailScript($this->getCspManager()->getNonce(), <<<JS |
|
29 | + $this->addJs('/vendor/yubico/u2flib-server/examples/assets/u2f-api.js'); |
|
30 | + $this->setTailScript($this->getCspManager()->getNonce(), <<<JS |
|
31 | 31 | var request = {$authData}; |
32 | 32 | u2f.sign(request, function(data) { |
33 | 33 | document.getElementById('authenticate').value=JSON.stringify(data); |
@@ -35,19 +35,19 @@ discard block |
||
35 | 35 | document.getElementById('loginForm').submit(); |
36 | 36 | }); |
37 | 37 | JS |
38 | - ); |
|
38 | + ); |
|
39 | 39 | |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - protected function getProviderCredentials() |
|
43 | - { |
|
44 | - $authenticate = WebRequest::postString("authenticate"); |
|
45 | - $request = WebRequest::postString("request"); |
|
42 | + protected function getProviderCredentials() |
|
43 | + { |
|
44 | + $authenticate = WebRequest::postString("authenticate"); |
|
45 | + $request = WebRequest::postString("request"); |
|
46 | 46 | |
47 | - if ($authenticate === null || $authenticate === "" || $request === null || $request === "") { |
|
48 | - throw new ApplicationLogicException("No authentication specified"); |
|
49 | - } |
|
47 | + if ($authenticate === null || $authenticate === "" || $request === null || $request === "") { |
|
48 | + throw new ApplicationLogicException("No authentication specified"); |
|
49 | + } |
|
50 | 50 | |
51 | - return array(json_decode($authenticate), json_decode($request), 'u2f'); |
|
52 | - } |
|
51 | + return array(json_decode($authenticate), json_decode($request), 'u2f'); |
|
52 | + } |
|
53 | 53 | } |