@@ -12,99 +12,99 @@ |
||
| 12 | 12 | |
| 13 | 13 | class ValidationError |
| 14 | 14 | { |
| 15 | - const NAME_EMPTY = "name_empty"; |
|
| 16 | - const NAME_EXISTS = "name_exists"; |
|
| 17 | - const NAME_EXISTS_SUL = "name_exists"; |
|
| 18 | - const NAME_NUMONLY = "name_numonly"; |
|
| 19 | - const NAME_INVALIDCHAR = "name_invalidchar"; |
|
| 20 | - const NAME_SANITISED = "name_sanitised"; |
|
| 21 | - const EMAIL_EMPTY = "email_empty"; |
|
| 22 | - const EMAIL_WIKIMEDIA = "email_wikimedia"; |
|
| 23 | - const EMAIL_INVALID = "email_invalid"; |
|
| 24 | - const EMAIL_MISMATCH = "email_mismatch"; |
|
| 25 | - const OPEN_REQUEST_NAME = "open_request_name"; |
|
| 26 | - const BANNED = "banned"; |
|
| 27 | - const BANNED_TOR = "banned_tor"; |
|
| 28 | - /** |
|
| 29 | - * @var array Error text for the above |
|
| 30 | - */ |
|
| 31 | - private static $errorText = array( |
|
| 32 | - self::NAME_EMPTY => 'You\'ve not chosen a username!', |
|
| 33 | - self::NAME_EXISTS => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
| 34 | - . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
| 35 | - . '[[User:example]] would become [[User:Example]].', |
|
| 36 | - self::NAME_EXISTS_SUL => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
| 37 | - . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
| 38 | - . '[[User:example]] would become [[User:Example]].', |
|
| 39 | - self::NAME_NUMONLY => 'The username you chose is invalid: it consists entirely of numbers. Please retry ' |
|
| 40 | - . 'with a valid username.', |
|
| 41 | - self::NAME_INVALIDCHAR => 'There appears to be an invalid character in your username. Please note that the ' |
|
| 42 | - . 'following characters are not allowed: <code># @ / < > [ ] | { }</code>', |
|
| 43 | - self::NAME_SANITISED => 'Your requested username has been automatically adjusted due to technical ' |
|
| 44 | - . 'restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.', |
|
| 45 | - self::EMAIL_EMPTY => 'You need to supply an email address.', |
|
| 46 | - self::EMAIL_WIKIMEDIA => 'Please provide your email address here.', |
|
| 47 | - self::EMAIL_INVALID => 'Invalid E-mail address supplied. Please check you entered it correctly.', |
|
| 48 | - self::EMAIL_MISMATCH => 'The email addresses you entered do not match. Please try again.', |
|
| 49 | - self::OPEN_REQUEST_NAME => 'There is already an open request with this name in this system.', |
|
| 50 | - self::BANNED => 'I\'m sorry, but you are currently banned from requesting accounts using this tool. ' |
|
| 51 | - . 'However, you can still send an email to [email protected] to request an account.', |
|
| 52 | - self::BANNED_TOR => 'Tor exit nodes are currently banned from using this tool due to excessive abuse. ' |
|
| 53 | - . 'Please note that Tor is also currently banned from editing Wikipedia.', |
|
| 54 | - ); |
|
| 55 | - /** |
|
| 56 | - * Summary of $errorCode |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - private $errorCode; |
|
| 60 | - /** |
|
| 61 | - * Summary of $isError |
|
| 62 | - * @var bool |
|
| 63 | - */ |
|
| 64 | - private $isError; |
|
| 15 | + const NAME_EMPTY = "name_empty"; |
|
| 16 | + const NAME_EXISTS = "name_exists"; |
|
| 17 | + const NAME_EXISTS_SUL = "name_exists"; |
|
| 18 | + const NAME_NUMONLY = "name_numonly"; |
|
| 19 | + const NAME_INVALIDCHAR = "name_invalidchar"; |
|
| 20 | + const NAME_SANITISED = "name_sanitised"; |
|
| 21 | + const EMAIL_EMPTY = "email_empty"; |
|
| 22 | + const EMAIL_WIKIMEDIA = "email_wikimedia"; |
|
| 23 | + const EMAIL_INVALID = "email_invalid"; |
|
| 24 | + const EMAIL_MISMATCH = "email_mismatch"; |
|
| 25 | + const OPEN_REQUEST_NAME = "open_request_name"; |
|
| 26 | + const BANNED = "banned"; |
|
| 27 | + const BANNED_TOR = "banned_tor"; |
|
| 28 | + /** |
|
| 29 | + * @var array Error text for the above |
|
| 30 | + */ |
|
| 31 | + private static $errorText = array( |
|
| 32 | + self::NAME_EMPTY => 'You\'ve not chosen a username!', |
|
| 33 | + self::NAME_EXISTS => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
| 34 | + . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
| 35 | + . '[[User:example]] would become [[User:Example]].', |
|
| 36 | + self::NAME_EXISTS_SUL => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
| 37 | + . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
| 38 | + . '[[User:example]] would become [[User:Example]].', |
|
| 39 | + self::NAME_NUMONLY => 'The username you chose is invalid: it consists entirely of numbers. Please retry ' |
|
| 40 | + . 'with a valid username.', |
|
| 41 | + self::NAME_INVALIDCHAR => 'There appears to be an invalid character in your username. Please note that the ' |
|
| 42 | + . 'following characters are not allowed: <code># @ / < > [ ] | { }</code>', |
|
| 43 | + self::NAME_SANITISED => 'Your requested username has been automatically adjusted due to technical ' |
|
| 44 | + . 'restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.', |
|
| 45 | + self::EMAIL_EMPTY => 'You need to supply an email address.', |
|
| 46 | + self::EMAIL_WIKIMEDIA => 'Please provide your email address here.', |
|
| 47 | + self::EMAIL_INVALID => 'Invalid E-mail address supplied. Please check you entered it correctly.', |
|
| 48 | + self::EMAIL_MISMATCH => 'The email addresses you entered do not match. Please try again.', |
|
| 49 | + self::OPEN_REQUEST_NAME => 'There is already an open request with this name in this system.', |
|
| 50 | + self::BANNED => 'I\'m sorry, but you are currently banned from requesting accounts using this tool. ' |
|
| 51 | + . 'However, you can still send an email to [email protected] to request an account.', |
|
| 52 | + self::BANNED_TOR => 'Tor exit nodes are currently banned from using this tool due to excessive abuse. ' |
|
| 53 | + . 'Please note that Tor is also currently banned from editing Wikipedia.', |
|
| 54 | + ); |
|
| 55 | + /** |
|
| 56 | + * Summary of $errorCode |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + private $errorCode; |
|
| 60 | + /** |
|
| 61 | + * Summary of $isError |
|
| 62 | + * @var bool |
|
| 63 | + */ |
|
| 64 | + private $isError; |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Summary of __construct |
|
| 68 | - * |
|
| 69 | - * @param string $errorCode |
|
| 70 | - * @param bool $isError |
|
| 71 | - */ |
|
| 72 | - public function __construct($errorCode, $isError = true) |
|
| 73 | - { |
|
| 74 | - $this->errorCode = $errorCode; |
|
| 75 | - $this->isError = $isError; |
|
| 76 | - } |
|
| 66 | + /** |
|
| 67 | + * Summary of __construct |
|
| 68 | + * |
|
| 69 | + * @param string $errorCode |
|
| 70 | + * @param bool $isError |
|
| 71 | + */ |
|
| 72 | + public function __construct($errorCode, $isError = true) |
|
| 73 | + { |
|
| 74 | + $this->errorCode = $errorCode; |
|
| 75 | + $this->isError = $isError; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Summary of getErrorCode |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function getErrorCode() |
|
| 83 | - { |
|
| 84 | - return $this->errorCode; |
|
| 85 | - } |
|
| 78 | + /** |
|
| 79 | + * Summary of getErrorCode |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function getErrorCode() |
|
| 83 | + { |
|
| 84 | + return $this->errorCode; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @return string |
|
| 89 | - * @throws Exception |
|
| 90 | - */ |
|
| 91 | - public function getErrorMessage() |
|
| 92 | - { |
|
| 93 | - $text = self::$errorText[$this->errorCode]; |
|
| 87 | + /** |
|
| 88 | + * @return string |
|
| 89 | + * @throws Exception |
|
| 90 | + */ |
|
| 91 | + public function getErrorMessage() |
|
| 92 | + { |
|
| 93 | + $text = self::$errorText[$this->errorCode]; |
|
| 94 | 94 | |
| 95 | - if ($text == null) { |
|
| 96 | - throw new Exception('Unknown validation error'); |
|
| 97 | - } |
|
| 95 | + if ($text == null) { |
|
| 96 | + throw new Exception('Unknown validation error'); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - return $text; |
|
| 100 | - } |
|
| 99 | + return $text; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Summary of isError |
|
| 104 | - * @return bool |
|
| 105 | - */ |
|
| 106 | - public function isError() |
|
| 107 | - { |
|
| 108 | - return $this->isError; |
|
| 109 | - } |
|
| 102 | + /** |
|
| 103 | + * Summary of isError |
|
| 104 | + * @return bool |
|
| 105 | + */ |
|
| 106 | + public function isError() |
|
| 107 | + { |
|
| 108 | + return $this->isError; |
|
| 109 | + } |
|
| 110 | 110 | } |
@@ -12,80 +12,80 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Token |
| 14 | 14 | { |
| 15 | - /** @var string */ |
|
| 16 | - private $tokenData; |
|
| 17 | - /** @var string */ |
|
| 18 | - private $context; |
|
| 19 | - /** @var DateTimeImmutable */ |
|
| 20 | - private $generationTimestamp; |
|
| 21 | - /** @var DateTimeImmutable */ |
|
| 22 | - private $usageTimestamp; |
|
| 23 | - /** @var bool */ |
|
| 24 | - private $used; |
|
| 15 | + /** @var string */ |
|
| 16 | + private $tokenData; |
|
| 17 | + /** @var string */ |
|
| 18 | + private $context; |
|
| 19 | + /** @var DateTimeImmutable */ |
|
| 20 | + private $generationTimestamp; |
|
| 21 | + /** @var DateTimeImmutable */ |
|
| 22 | + private $usageTimestamp; |
|
| 23 | + /** @var bool */ |
|
| 24 | + private $used; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Token constructor. |
|
| 28 | - * |
|
| 29 | - * @param string $tokenData |
|
| 30 | - * @param string $context |
|
| 31 | - */ |
|
| 32 | - public function __construct($tokenData, $context) |
|
| 33 | - { |
|
| 34 | - $this->tokenData = $tokenData; |
|
| 35 | - $this->context = $context; |
|
| 36 | - $this->generationTimestamp = new DateTimeImmutable(); |
|
| 37 | - $this->usageTimestamp = null; |
|
| 38 | - $this->used = false; |
|
| 39 | - } |
|
| 26 | + /** |
|
| 27 | + * Token constructor. |
|
| 28 | + * |
|
| 29 | + * @param string $tokenData |
|
| 30 | + * @param string $context |
|
| 31 | + */ |
|
| 32 | + public function __construct($tokenData, $context) |
|
| 33 | + { |
|
| 34 | + $this->tokenData = $tokenData; |
|
| 35 | + $this->context = $context; |
|
| 36 | + $this->generationTimestamp = new DateTimeImmutable(); |
|
| 37 | + $this->usageTimestamp = null; |
|
| 38 | + $this->used = false; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return DateTimeImmutable |
|
| 43 | - */ |
|
| 44 | - public function getGenerationTimestamp() |
|
| 45 | - { |
|
| 46 | - return $this->generationTimestamp; |
|
| 47 | - } |
|
| 41 | + /** |
|
| 42 | + * @return DateTimeImmutable |
|
| 43 | + */ |
|
| 44 | + public function getGenerationTimestamp() |
|
| 45 | + { |
|
| 46 | + return $this->generationTimestamp; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 52 | - public function getContext() |
|
| 53 | - { |
|
| 54 | - return $this->context; |
|
| 55 | - } |
|
| 49 | + /** |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | + public function getContext() |
|
| 53 | + { |
|
| 54 | + return $this->context; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public function getTokenData() |
|
| 61 | - { |
|
| 62 | - return $this->tokenData; |
|
| 63 | - } |
|
| 57 | + /** |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public function getTokenData() |
|
| 61 | + { |
|
| 62 | + return $this->tokenData; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Returns a value indicating whether the token has already been used or not |
|
| 67 | - * |
|
| 68 | - * @return boolean |
|
| 69 | - */ |
|
| 70 | - public function isUsed() |
|
| 71 | - { |
|
| 72 | - return $this->used; |
|
| 73 | - } |
|
| 65 | + /** |
|
| 66 | + * Returns a value indicating whether the token has already been used or not |
|
| 67 | + * |
|
| 68 | + * @return boolean |
|
| 69 | + */ |
|
| 70 | + public function isUsed() |
|
| 71 | + { |
|
| 72 | + return $this->used; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Marks the token as used |
|
| 77 | - */ |
|
| 78 | - public function markAsUsed() |
|
| 79 | - { |
|
| 80 | - $this->used = true; |
|
| 81 | - $this->usageTimestamp = new DateTimeImmutable(); |
|
| 82 | - } |
|
| 75 | + /** |
|
| 76 | + * Marks the token as used |
|
| 77 | + */ |
|
| 78 | + public function markAsUsed() |
|
| 79 | + { |
|
| 80 | + $this->used = true; |
|
| 81 | + $this->usageTimestamp = new DateTimeImmutable(); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @return DateTimeImmutable |
|
| 86 | - */ |
|
| 87 | - public function getUsageTimestamp() |
|
| 88 | - { |
|
| 89 | - return $this->usageTimestamp; |
|
| 90 | - } |
|
| 84 | + /** |
|
| 85 | + * @return DateTimeImmutable |
|
| 86 | + */ |
|
| 87 | + public function getUsageTimestamp() |
|
| 88 | + { |
|
| 89 | + return $this->usageTimestamp; |
|
| 90 | + } |
|
| 91 | 91 | } |
| 92 | 92 | \ No newline at end of file |
@@ -13,91 +13,91 @@ |
||
| 13 | 13 | |
| 14 | 14 | class TokenManager |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Validates a CSRF token |
|
| 18 | - * |
|
| 19 | - * @param string $data The token data string itself |
|
| 20 | - * @param string|null $context Token context for extra validation |
|
| 21 | - * |
|
| 22 | - * @return bool |
|
| 23 | - */ |
|
| 24 | - public function validateToken($data, $context = null) |
|
| 25 | - { |
|
| 26 | - if (!is_string($data) || strlen($data) === 0) { |
|
| 27 | - // Nothing to validate |
|
| 28 | - return false; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $tokens = WebRequest::getSessionTokenData(); |
|
| 32 | - |
|
| 33 | - // if the token doesn't exist, then it's not valid |
|
| 34 | - if (!array_key_exists($data, $tokens)) { |
|
| 35 | - return false; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** @var Token $token */ |
|
| 39 | - $token = unserialize($tokens[$data]); |
|
| 40 | - |
|
| 41 | - if ($token->getTokenData() !== $data) { |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if ($token->getContext() !== $context) { |
|
| 46 | - return false; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if ($token->isUsed()) { |
|
| 50 | - return false; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // mark the token as used, and save it back to the session |
|
| 54 | - $token->markAsUsed(); |
|
| 55 | - $this->storeToken($token); |
|
| 56 | - |
|
| 57 | - return true; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param string|null $context An optional context for extra validation |
|
| 62 | - * |
|
| 63 | - * @return Token |
|
| 64 | - */ |
|
| 65 | - public function getNewToken($context = null) |
|
| 66 | - { |
|
| 67 | - $token = new Token($this->generateTokenData(), $context); |
|
| 68 | - $this->storeToken($token); |
|
| 69 | - |
|
| 70 | - return $token; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Stores a token in the session data |
|
| 75 | - * |
|
| 76 | - * @param Token $token |
|
| 77 | - */ |
|
| 78 | - private function storeToken(Token $token) |
|
| 79 | - { |
|
| 80 | - $tokens = WebRequest::getSessionTokenData(); |
|
| 81 | - $tokens[$token->getTokenData()] = serialize($token); |
|
| 82 | - WebRequest::setSessionTokenData($tokens); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Generates a security token |
|
| 87 | - * |
|
| 88 | - * @return string |
|
| 89 | - * @throws Exception |
|
| 90 | - * |
|
| 91 | - * @category Security-Critical |
|
| 92 | - */ |
|
| 93 | - private function generateTokenData() |
|
| 94 | - { |
|
| 95 | - $genBytes = openssl_random_pseudo_bytes(33); |
|
| 96 | - |
|
| 97 | - if ($genBytes !== false) { |
|
| 98 | - return base64_encode($genBytes); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - throw new Exception('Unable to generate secure token.'); |
|
| 102 | - } |
|
| 16 | + /** |
|
| 17 | + * Validates a CSRF token |
|
| 18 | + * |
|
| 19 | + * @param string $data The token data string itself |
|
| 20 | + * @param string|null $context Token context for extra validation |
|
| 21 | + * |
|
| 22 | + * @return bool |
|
| 23 | + */ |
|
| 24 | + public function validateToken($data, $context = null) |
|
| 25 | + { |
|
| 26 | + if (!is_string($data) || strlen($data) === 0) { |
|
| 27 | + // Nothing to validate |
|
| 28 | + return false; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $tokens = WebRequest::getSessionTokenData(); |
|
| 32 | + |
|
| 33 | + // if the token doesn't exist, then it's not valid |
|
| 34 | + if (!array_key_exists($data, $tokens)) { |
|
| 35 | + return false; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** @var Token $token */ |
|
| 39 | + $token = unserialize($tokens[$data]); |
|
| 40 | + |
|
| 41 | + if ($token->getTokenData() !== $data) { |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if ($token->getContext() !== $context) { |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if ($token->isUsed()) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // mark the token as used, and save it back to the session |
|
| 54 | + $token->markAsUsed(); |
|
| 55 | + $this->storeToken($token); |
|
| 56 | + |
|
| 57 | + return true; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param string|null $context An optional context for extra validation |
|
| 62 | + * |
|
| 63 | + * @return Token |
|
| 64 | + */ |
|
| 65 | + public function getNewToken($context = null) |
|
| 66 | + { |
|
| 67 | + $token = new Token($this->generateTokenData(), $context); |
|
| 68 | + $this->storeToken($token); |
|
| 69 | + |
|
| 70 | + return $token; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Stores a token in the session data |
|
| 75 | + * |
|
| 76 | + * @param Token $token |
|
| 77 | + */ |
|
| 78 | + private function storeToken(Token $token) |
|
| 79 | + { |
|
| 80 | + $tokens = WebRequest::getSessionTokenData(); |
|
| 81 | + $tokens[$token->getTokenData()] = serialize($token); |
|
| 82 | + WebRequest::setSessionTokenData($tokens); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Generates a security token |
|
| 87 | + * |
|
| 88 | + * @return string |
|
| 89 | + * @throws Exception |
|
| 90 | + * |
|
| 91 | + * @category Security-Critical |
|
| 92 | + */ |
|
| 93 | + private function generateTokenData() |
|
| 94 | + { |
|
| 95 | + $genBytes = openssl_random_pseudo_bytes(33); |
|
| 96 | + |
|
| 97 | + if ($genBytes !== false) { |
|
| 98 | + return base64_encode($genBytes); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + throw new Exception('Unable to generate secure token.'); |
|
| 102 | + } |
|
| 103 | 103 | } |
| 104 | 104 | \ No newline at end of file |
@@ -15,42 +15,42 @@ |
||
| 15 | 15 | |
| 16 | 16 | class PublicRequestRouter extends RequestRouter |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Gets the route map to be used by this request router. |
|
| 20 | - * |
|
| 21 | - * @return array |
|
| 22 | - */ |
|
| 23 | - protected function getRouteMap() |
|
| 24 | - { |
|
| 25 | - return array( |
|
| 26 | - // Page showing a message stating the request has been submitted to our internal queues |
|
| 27 | - 'requestSubmitted' => |
|
| 28 | - array( |
|
| 29 | - 'class' => PageRequestSubmitted::class, |
|
| 30 | - 'actions' => array(), |
|
| 31 | - ), |
|
| 32 | - // Page showing a message stating that email confirmation is required to continue |
|
| 33 | - 'emailConfirmationRequired' => |
|
| 34 | - array( |
|
| 35 | - 'class' => PageEmailConfirmationRequired::class, |
|
| 36 | - 'actions' => array(), |
|
| 37 | - ), |
|
| 38 | - // Action page which handles email confirmation |
|
| 39 | - 'confirmEmail' => |
|
| 40 | - array( |
|
| 41 | - 'class' => PageConfirmEmail::class, |
|
| 42 | - 'actions' => array(), |
|
| 43 | - ), |
|
| 44 | - ); |
|
| 45 | - } |
|
| 18 | + /** |
|
| 19 | + * Gets the route map to be used by this request router. |
|
| 20 | + * |
|
| 21 | + * @return array |
|
| 22 | + */ |
|
| 23 | + protected function getRouteMap() |
|
| 24 | + { |
|
| 25 | + return array( |
|
| 26 | + // Page showing a message stating the request has been submitted to our internal queues |
|
| 27 | + 'requestSubmitted' => |
|
| 28 | + array( |
|
| 29 | + 'class' => PageRequestSubmitted::class, |
|
| 30 | + 'actions' => array(), |
|
| 31 | + ), |
|
| 32 | + // Page showing a message stating that email confirmation is required to continue |
|
| 33 | + 'emailConfirmationRequired' => |
|
| 34 | + array( |
|
| 35 | + 'class' => PageEmailConfirmationRequired::class, |
|
| 36 | + 'actions' => array(), |
|
| 37 | + ), |
|
| 38 | + // Action page which handles email confirmation |
|
| 39 | + 'confirmEmail' => |
|
| 40 | + array( |
|
| 41 | + 'class' => PageConfirmEmail::class, |
|
| 42 | + 'actions' => array(), |
|
| 43 | + ), |
|
| 44 | + ); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Gets the default route if no explicit route is requested. |
|
| 49 | - * |
|
| 50 | - * @return callable |
|
| 51 | - */ |
|
| 52 | - protected function getDefaultRoute() |
|
| 53 | - { |
|
| 54 | - return array(PageRequestAccount::class, 'main'); |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * Gets the default route if no explicit route is requested. |
|
| 49 | + * |
|
| 50 | + * @return callable |
|
| 51 | + */ |
|
| 52 | + protected function getDefaultRoute() |
|
| 53 | + { |
|
| 54 | + return array(PageRequestAccount::class, 'main'); |
|
| 55 | + } |
|
| 56 | 56 | } |
| 57 | 57 | \ No newline at end of file |
@@ -18,9 +18,9 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | interface IRequestRouter |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @return IRoutedTask |
|
| 23 | - * @throws Exception |
|
| 24 | - */ |
|
| 25 | - public function route(); |
|
| 21 | + /** |
|
| 22 | + * @return IRoutedTask |
|
| 23 | + * @throws Exception |
|
| 24 | + */ |
|
| 25 | + public function route(); |
|
| 26 | 26 | } |
| 27 | 27 | \ No newline at end of file |
@@ -13,36 +13,36 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class AutoLoader |
| 15 | 15 | { |
| 16 | - public static function load($class) |
|
| 17 | - { |
|
| 18 | - // handle namespaces sensibly |
|
| 19 | - if (strpos($class, "Waca") !== false) { |
|
| 20 | - // strip off the initial namespace |
|
| 21 | - $class = str_replace("Waca\\", "", $class); |
|
| 16 | + public static function load($class) |
|
| 17 | + { |
|
| 18 | + // handle namespaces sensibly |
|
| 19 | + if (strpos($class, "Waca") !== false) { |
|
| 20 | + // strip off the initial namespace |
|
| 21 | + $class = str_replace("Waca\\", "", $class); |
|
| 22 | 22 | |
| 23 | - // swap backslashes for forward slashes to map to directory names |
|
| 24 | - $class = str_replace("\\", "/", $class); |
|
| 25 | - } |
|
| 23 | + // swap backslashes for forward slashes to map to directory names |
|
| 24 | + $class = str_replace("\\", "/", $class); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - $paths = array( |
|
| 28 | - __DIR__ . '/' . $class . ".php", |
|
| 29 | - __DIR__ . '/DataObjects/' . $class . ".php", |
|
| 30 | - __DIR__ . '/Providers/' . $class . ".php", |
|
| 31 | - __DIR__ . '/Providers/Interfaces/' . $class . ".php", |
|
| 32 | - __DIR__ . '/Validation/' . $class . ".php", |
|
| 33 | - __DIR__ . '/Helpers/' . $class . ".php", |
|
| 34 | - __DIR__ . '/Helpers/Interfaces/' . $class . ".php", |
|
| 35 | - __DIR__ . '/' . $class . ".php", |
|
| 36 | - ); |
|
| 27 | + $paths = array( |
|
| 28 | + __DIR__ . '/' . $class . ".php", |
|
| 29 | + __DIR__ . '/DataObjects/' . $class . ".php", |
|
| 30 | + __DIR__ . '/Providers/' . $class . ".php", |
|
| 31 | + __DIR__ . '/Providers/Interfaces/' . $class . ".php", |
|
| 32 | + __DIR__ . '/Validation/' . $class . ".php", |
|
| 33 | + __DIR__ . '/Helpers/' . $class . ".php", |
|
| 34 | + __DIR__ . '/Helpers/Interfaces/' . $class . ".php", |
|
| 35 | + __DIR__ . '/' . $class . ".php", |
|
| 36 | + ); |
|
| 37 | 37 | |
| 38 | - foreach ($paths as $file) { |
|
| 39 | - if (file_exists($file)) { |
|
| 40 | - require_once($file); |
|
| 41 | - } |
|
| 38 | + foreach ($paths as $file) { |
|
| 39 | + if (file_exists($file)) { |
|
| 40 | + require_once($file); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - if (class_exists($class)) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 43 | + if (class_exists($class)) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -10,77 +10,77 @@ |
||
| 10 | 10 | |
| 11 | 11 | class StringFunctions |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Formats a string to be used as a username. |
|
| 15 | - * |
|
| 16 | - * @param $username |
|
| 17 | - * |
|
| 18 | - * @return string |
|
| 19 | - */ |
|
| 20 | - public function formatAsUsername($username) |
|
| 21 | - { |
|
| 22 | - // trim whitespace from the ends |
|
| 23 | - $uname = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $username); |
|
| 13 | + /** |
|
| 14 | + * Formats a string to be used as a username. |
|
| 15 | + * |
|
| 16 | + * @param $username |
|
| 17 | + * |
|
| 18 | + * @return string |
|
| 19 | + */ |
|
| 20 | + public function formatAsUsername($username) |
|
| 21 | + { |
|
| 22 | + // trim whitespace from the ends |
|
| 23 | + $uname = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $username); |
|
| 24 | 24 | |
| 25 | - // convert first char to uppercase |
|
| 26 | - $uname = $this->ucfirst($uname); |
|
| 25 | + // convert first char to uppercase |
|
| 26 | + $uname = $this->ucfirst($uname); |
|
| 27 | 27 | |
| 28 | - // replace spaces with underscores |
|
| 29 | - $uname = mb_ereg_replace("[ ]+", "_", $uname); |
|
| 28 | + // replace spaces with underscores |
|
| 29 | + $uname = mb_ereg_replace("[ ]+", "_", $uname); |
|
| 30 | 30 | |
| 31 | - // trim underscores from the end |
|
| 32 | - $uname = mb_ereg_replace("[_]+$", "", $uname); |
|
| 31 | + // trim underscores from the end |
|
| 32 | + $uname = mb_ereg_replace("[_]+$", "", $uname); |
|
| 33 | 33 | |
| 34 | - return $uname; |
|
| 35 | - } |
|
| 34 | + return $uname; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Formats a string to be used as an email (specifically strips whitespace |
|
| 39 | - * from the beginning/end of the Email, as well as immediately before/after |
|
| 40 | - * the @ in the Email). |
|
| 41 | - * |
|
| 42 | - * @param $email |
|
| 43 | - * |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - public static function formatAsEmail($email) |
|
| 47 | - { |
|
| 48 | - // trim whitespace from the ends |
|
| 49 | - $newemail = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $email); |
|
| 37 | + /** |
|
| 38 | + * Formats a string to be used as an email (specifically strips whitespace |
|
| 39 | + * from the beginning/end of the Email, as well as immediately before/after |
|
| 40 | + * the @ in the Email). |
|
| 41 | + * |
|
| 42 | + * @param $email |
|
| 43 | + * |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + public static function formatAsEmail($email) |
|
| 47 | + { |
|
| 48 | + // trim whitespace from the ends |
|
| 49 | + $newemail = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $email); |
|
| 50 | 50 | |
| 51 | - // trim whitespace from around the email address |
|
| 52 | - $newemail = mb_ereg_replace("[ \t]+@", "@", $newemail); |
|
| 53 | - $newemail = mb_ereg_replace("@[ \t]+", "@", $newemail); |
|
| 51 | + // trim whitespace from around the email address |
|
| 52 | + $newemail = mb_ereg_replace("[ \t]+@", "@", $newemail); |
|
| 53 | + $newemail = mb_ereg_replace("@[ \t]+", "@", $newemail); |
|
| 54 | 54 | |
| 55 | - return $newemail; |
|
| 56 | - } |
|
| 55 | + return $newemail; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Returns true if a string is a multibyte string |
|
| 60 | - * |
|
| 61 | - * @param string $string |
|
| 62 | - * |
|
| 63 | - * @return bool |
|
| 64 | - */ |
|
| 65 | - public function isMultibyte($string) |
|
| 66 | - { |
|
| 67 | - return strlen($string) !== mb_strlen($string); |
|
| 68 | - } |
|
| 58 | + /** |
|
| 59 | + * Returns true if a string is a multibyte string |
|
| 60 | + * |
|
| 61 | + * @param string $string |
|
| 62 | + * |
|
| 63 | + * @return bool |
|
| 64 | + */ |
|
| 65 | + public function isMultibyte($string) |
|
| 66 | + { |
|
| 67 | + return strlen($string) !== mb_strlen($string); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Make a string's first character uppercase |
|
| 72 | - * |
|
| 73 | - * @param string $string |
|
| 74 | - * |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public function ucfirst($string) |
|
| 78 | - { |
|
| 79 | - if (ord($string) < 128) { |
|
| 80 | - return ucfirst($string); |
|
| 81 | - } |
|
| 82 | - else { |
|
| 83 | - return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); |
|
| 84 | - } |
|
| 85 | - } |
|
| 70 | + /** |
|
| 71 | + * Make a string's first character uppercase |
|
| 72 | + * |
|
| 73 | + * @param string $string |
|
| 74 | + * |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public function ucfirst($string) |
|
| 78 | + { |
|
| 79 | + if (ord($string) < 128) { |
|
| 80 | + return ucfirst($string); |
|
| 81 | + } |
|
| 82 | + else { |
|
| 83 | + return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -13,14 +13,14 @@ |
||
| 13 | 13 | |
| 14 | 14 | class UpdateTorExitTask extends ConsoleTaskBase |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - public function execute() |
|
| 20 | - { |
|
| 21 | - TorExitProvider::regenerate( |
|
| 22 | - $this->getDatabase(), |
|
| 23 | - $this->getHttpHelper(), |
|
| 24 | - $this->getSiteConfiguration()->getTorExitPaths()); |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + public function execute() |
|
| 20 | + { |
|
| 21 | + TorExitProvider::regenerate( |
|
| 22 | + $this->getDatabase(), |
|
| 23 | + $this->getHttpHelper(), |
|
| 24 | + $this->getSiteConfiguration()->getTorExitPaths()); |
|
| 25 | + } |
|
| 26 | 26 | } |
| 27 | 27 | \ No newline at end of file |
@@ -16,152 +16,152 @@ |
||
| 16 | 16 | |
| 17 | 17 | class RecreateTrustedIpTableTask extends ConsoleTaskBase |
| 18 | 18 | { |
| 19 | - public function execute() |
|
| 20 | - { |
|
| 21 | - |
|
| 22 | - echo "Fetching file...\n"; |
|
| 23 | - |
|
| 24 | - $htmlfile = file($this->getSiteConfiguration()->getXffTrustedHostsFile(), |
|
| 25 | - FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
| 26 | - |
|
| 27 | - $ip = array(); |
|
| 28 | - $iprange = array(); |
|
| 29 | - $dnsdomain = array(); |
|
| 30 | - |
|
| 31 | - echo "Sorting file...\n"; |
|
| 32 | - $this->readFile($htmlfile, $iprange, $ip, $dnsdomain); |
|
| 33 | - |
|
| 34 | - echo "Exploding CIDRs...\n"; |
|
| 35 | - $this->explodeCidrs($iprange, $ip); |
|
| 36 | - |
|
| 37 | - echo "Resolving DNS...\n"; |
|
| 38 | - $this->resolveDns($dnsdomain, $ip); |
|
| 39 | - |
|
| 40 | - echo "Uniq-ing array...\n"; |
|
| 41 | - |
|
| 42 | - $ip = array_unique($ip); |
|
| 43 | - |
|
| 44 | - $database = $this->getDatabase(); |
|
| 45 | - |
|
| 46 | - $database->exec('DELETE FROM xfftrustcache;'); |
|
| 47 | - |
|
| 48 | - $insert = $database->prepare('INSERT INTO xfftrustcache (ip) VALUES (:ip);'); |
|
| 49 | - |
|
| 50 | - $this->doInserts($ip, $insert); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param string[] $dnsDomains the DNS domains to resolve |
|
| 55 | - * @param string[] $ipAddresses existing array of IPs to add to |
|
| 56 | - */ |
|
| 57 | - protected function resolveDns($dnsDomains, &$ipAddresses) |
|
| 58 | - { |
|
| 59 | - foreach ($dnsDomains as $domain) { |
|
| 60 | - $ipList = gethostbynamel($domain); |
|
| 61 | - |
|
| 62 | - if ($ipList === false) { |
|
| 63 | - echo "Invalid DNS name $domain\n"; |
|
| 64 | - continue; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - foreach ($ipList as $ipAddress) { |
|
| 68 | - $ipAddresses[] = $ipAddress; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // don't DoS |
|
| 72 | - usleep(10000); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param $iprange |
|
| 78 | - * @param $ip |
|
| 79 | - */ |
|
| 80 | - protected function explodeCidrs($iprange, &$ip) |
|
| 81 | - { |
|
| 82 | - foreach ($iprange as $r) { |
|
| 83 | - $ips = $this->getXffTrustProvider()->explodeCidr($r); |
|
| 84 | - |
|
| 85 | - foreach ($ips as $i) { |
|
| 86 | - $ip[] = $i; |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param $htmlfile |
|
| 93 | - * @param $iprange |
|
| 94 | - * @param $ip |
|
| 95 | - * @param $dnsdomain |
|
| 96 | - */ |
|
| 97 | - protected function readFile($htmlfile, &$iprange, &$ip, &$dnsdomain) |
|
| 98 | - { |
|
| 99 | - foreach ($htmlfile as $line_num => $rawline) { |
|
| 100 | - // remove the comments |
|
| 101 | - $hashPos = strpos($rawline, '#'); |
|
| 102 | - if ($hashPos !== false) { |
|
| 103 | - $line = substr($rawline, 0, $hashPos); |
|
| 104 | - } |
|
| 105 | - else { |
|
| 106 | - $line = $rawline; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $line = trim($line); |
|
| 110 | - |
|
| 111 | - // this was a comment or empty line... |
|
| 112 | - if ($line == "") { |
|
| 113 | - continue; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - // match a regex of an CIDR range: |
|
| 117 | - $ipcidr = '@' . RegexConstants::IPV4 . RegexConstants::IPV4_CIDR . '@'; |
|
| 118 | - if (preg_match($ipcidr, $line) === 1) { |
|
| 119 | - $iprange[] = $line; |
|
| 120 | - continue; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $ipnoncidr = '@' . RegexConstants::IPV4 . '@'; |
|
| 124 | - if (preg_match($ipnoncidr, $line) === 1) { |
|
| 125 | - $ip[] = $line; |
|
| 126 | - continue; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // it's probably a DNS name. |
|
| 130 | - $dnsdomain[] = $line; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @param array $ip |
|
| 136 | - * @param PDOStatement $insert |
|
| 137 | - * |
|
| 138 | - * @throws Exception |
|
| 139 | - */ |
|
| 140 | - protected function doInserts($ip, PDOStatement $insert) |
|
| 141 | - { |
|
| 142 | - $successful = true; |
|
| 143 | - |
|
| 144 | - foreach ($ip as $i) { |
|
| 145 | - if (count($i) > 15) { |
|
| 146 | - echo "Rejected $i\n"; |
|
| 147 | - $successful = false; |
|
| 148 | - |
|
| 149 | - continue; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - try { |
|
| 153 | - $insert->execute(array(':ip' => $i)); |
|
| 154 | - } |
|
| 155 | - catch (PDOException $ex) { |
|
| 156 | - echo "Exception on $i :\n"; |
|
| 157 | - echo $ex->getMessage(); |
|
| 158 | - $successful = false; |
|
| 159 | - break; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (!$successful) { |
|
| 164 | - throw new Exception('Encountered errors during transaction processing'); |
|
| 165 | - } |
|
| 166 | - } |
|
| 19 | + public function execute() |
|
| 20 | + { |
|
| 21 | + |
|
| 22 | + echo "Fetching file...\n"; |
|
| 23 | + |
|
| 24 | + $htmlfile = file($this->getSiteConfiguration()->getXffTrustedHostsFile(), |
|
| 25 | + FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
| 26 | + |
|
| 27 | + $ip = array(); |
|
| 28 | + $iprange = array(); |
|
| 29 | + $dnsdomain = array(); |
|
| 30 | + |
|
| 31 | + echo "Sorting file...\n"; |
|
| 32 | + $this->readFile($htmlfile, $iprange, $ip, $dnsdomain); |
|
| 33 | + |
|
| 34 | + echo "Exploding CIDRs...\n"; |
|
| 35 | + $this->explodeCidrs($iprange, $ip); |
|
| 36 | + |
|
| 37 | + echo "Resolving DNS...\n"; |
|
| 38 | + $this->resolveDns($dnsdomain, $ip); |
|
| 39 | + |
|
| 40 | + echo "Uniq-ing array...\n"; |
|
| 41 | + |
|
| 42 | + $ip = array_unique($ip); |
|
| 43 | + |
|
| 44 | + $database = $this->getDatabase(); |
|
| 45 | + |
|
| 46 | + $database->exec('DELETE FROM xfftrustcache;'); |
|
| 47 | + |
|
| 48 | + $insert = $database->prepare('INSERT INTO xfftrustcache (ip) VALUES (:ip);'); |
|
| 49 | + |
|
| 50 | + $this->doInserts($ip, $insert); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param string[] $dnsDomains the DNS domains to resolve |
|
| 55 | + * @param string[] $ipAddresses existing array of IPs to add to |
|
| 56 | + */ |
|
| 57 | + protected function resolveDns($dnsDomains, &$ipAddresses) |
|
| 58 | + { |
|
| 59 | + foreach ($dnsDomains as $domain) { |
|
| 60 | + $ipList = gethostbynamel($domain); |
|
| 61 | + |
|
| 62 | + if ($ipList === false) { |
|
| 63 | + echo "Invalid DNS name $domain\n"; |
|
| 64 | + continue; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + foreach ($ipList as $ipAddress) { |
|
| 68 | + $ipAddresses[] = $ipAddress; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // don't DoS |
|
| 72 | + usleep(10000); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param $iprange |
|
| 78 | + * @param $ip |
|
| 79 | + */ |
|
| 80 | + protected function explodeCidrs($iprange, &$ip) |
|
| 81 | + { |
|
| 82 | + foreach ($iprange as $r) { |
|
| 83 | + $ips = $this->getXffTrustProvider()->explodeCidr($r); |
|
| 84 | + |
|
| 85 | + foreach ($ips as $i) { |
|
| 86 | + $ip[] = $i; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @param $htmlfile |
|
| 93 | + * @param $iprange |
|
| 94 | + * @param $ip |
|
| 95 | + * @param $dnsdomain |
|
| 96 | + */ |
|
| 97 | + protected function readFile($htmlfile, &$iprange, &$ip, &$dnsdomain) |
|
| 98 | + { |
|
| 99 | + foreach ($htmlfile as $line_num => $rawline) { |
|
| 100 | + // remove the comments |
|
| 101 | + $hashPos = strpos($rawline, '#'); |
|
| 102 | + if ($hashPos !== false) { |
|
| 103 | + $line = substr($rawline, 0, $hashPos); |
|
| 104 | + } |
|
| 105 | + else { |
|
| 106 | + $line = $rawline; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $line = trim($line); |
|
| 110 | + |
|
| 111 | + // this was a comment or empty line... |
|
| 112 | + if ($line == "") { |
|
| 113 | + continue; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + // match a regex of an CIDR range: |
|
| 117 | + $ipcidr = '@' . RegexConstants::IPV4 . RegexConstants::IPV4_CIDR . '@'; |
|
| 118 | + if (preg_match($ipcidr, $line) === 1) { |
|
| 119 | + $iprange[] = $line; |
|
| 120 | + continue; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $ipnoncidr = '@' . RegexConstants::IPV4 . '@'; |
|
| 124 | + if (preg_match($ipnoncidr, $line) === 1) { |
|
| 125 | + $ip[] = $line; |
|
| 126 | + continue; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // it's probably a DNS name. |
|
| 130 | + $dnsdomain[] = $line; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @param array $ip |
|
| 136 | + * @param PDOStatement $insert |
|
| 137 | + * |
|
| 138 | + * @throws Exception |
|
| 139 | + */ |
|
| 140 | + protected function doInserts($ip, PDOStatement $insert) |
|
| 141 | + { |
|
| 142 | + $successful = true; |
|
| 143 | + |
|
| 144 | + foreach ($ip as $i) { |
|
| 145 | + if (count($i) > 15) { |
|
| 146 | + echo "Rejected $i\n"; |
|
| 147 | + $successful = false; |
|
| 148 | + |
|
| 149 | + continue; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + try { |
|
| 153 | + $insert->execute(array(':ip' => $i)); |
|
| 154 | + } |
|
| 155 | + catch (PDOException $ex) { |
|
| 156 | + echo "Exception on $i :\n"; |
|
| 157 | + echo $ex->getMessage(); |
|
| 158 | + $successful = false; |
|
| 159 | + break; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if (!$successful) { |
|
| 164 | + throw new Exception('Encountered errors during transaction processing'); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | 167 | } |
| 168 | 168 | \ No newline at end of file |