@@ -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 |
@@ -16,55 +16,55 @@ |
||
| 16 | 16 | |
| 17 | 17 | class MigrateToRoles extends ConsoleTaskBase |
| 18 | 18 | { |
| 19 | - public function execute() |
|
| 20 | - { |
|
| 21 | - $communityUser = User::getCommunity(); |
|
| 19 | + public function execute() |
|
| 20 | + { |
|
| 21 | + $communityUser = User::getCommunity(); |
|
| 22 | 22 | |
| 23 | - $database = $this->getDatabase(); |
|
| 24 | - $statement = $database->query('SELECT id, status, checkuser FROM user;'); |
|
| 25 | - $update = $database->prepare("UPDATE user SET status = 'Active' WHERE id = :id;"); |
|
| 23 | + $database = $this->getDatabase(); |
|
| 24 | + $statement = $database->query('SELECT id, status, checkuser FROM user;'); |
|
| 25 | + $update = $database->prepare("UPDATE user SET status = 'Active' WHERE id = :id;"); |
|
| 26 | 26 | |
| 27 | - $users = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 27 | + $users = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
| 28 | 28 | |
| 29 | - foreach ($users as $user) { |
|
| 30 | - $toAdd = array('user'); |
|
| 29 | + foreach ($users as $user) { |
|
| 30 | + $toAdd = array('user'); |
|
| 31 | 31 | |
| 32 | - if($user['status'] === 'Admin'){ |
|
| 33 | - $toAdd[] = 'admin'; |
|
| 34 | - } |
|
| 32 | + if($user['status'] === 'Admin'){ |
|
| 33 | + $toAdd[] = 'admin'; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - if($user['checkuser'] == 1){ |
|
| 37 | - $toAdd[] = 'checkuser'; |
|
| 38 | - } |
|
| 36 | + if($user['checkuser'] == 1){ |
|
| 37 | + $toAdd[] = 'checkuser'; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - foreach ($toAdd as $x) { |
|
| 41 | - $a = new UserRole(); |
|
| 42 | - $a->setUser($user['id']); |
|
| 43 | - $a->setRole($x); |
|
| 44 | - $a->setDatabase($database); |
|
| 45 | - $a->save(); |
|
| 46 | - } |
|
| 40 | + foreach ($toAdd as $x) { |
|
| 41 | + $a = new UserRole(); |
|
| 42 | + $a->setUser($user['id']); |
|
| 43 | + $a->setRole($x); |
|
| 44 | + $a->setDatabase($database); |
|
| 45 | + $a->save(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - $logData = serialize(array( |
|
| 49 | - 'added' => $toAdd, |
|
| 50 | - 'removed' => array(), |
|
| 51 | - 'reason' => 'Initial migration' |
|
| 52 | - )); |
|
| 48 | + $logData = serialize(array( |
|
| 49 | + 'added' => $toAdd, |
|
| 50 | + 'removed' => array(), |
|
| 51 | + 'reason' => 'Initial migration' |
|
| 52 | + )); |
|
| 53 | 53 | |
| 54 | - $log = new Log(); |
|
| 55 | - $log->setDatabase($database); |
|
| 56 | - $log->setAction('RoleChange'); |
|
| 57 | - $log->setObjectId($user['id']); |
|
| 58 | - $log->setObjectType('User'); |
|
| 59 | - $log->setUser($communityUser); |
|
| 60 | - $log->setComment($logData); |
|
| 61 | - $log->save(); |
|
| 54 | + $log = new Log(); |
|
| 55 | + $log->setDatabase($database); |
|
| 56 | + $log->setAction('RoleChange'); |
|
| 57 | + $log->setObjectId($user['id']); |
|
| 58 | + $log->setObjectType('User'); |
|
| 59 | + $log->setUser($communityUser); |
|
| 60 | + $log->setComment($logData); |
|
| 61 | + $log->save(); |
|
| 62 | 62 | |
| 63 | - if($user['status'] === 'Admin' || $user['status'] === 'User'){ |
|
| 64 | - $update->execute(array('id' => $user['id'])); |
|
| 65 | - } |
|
| 66 | - } |
|
| 63 | + if($user['status'] === 'Admin' || $user['status'] === 'User'){ |
|
| 64 | + $update->execute(array('id' => $user['id'])); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $database->exec("UPDATE schemaversion SET version = 25;"); |
|
| 69 | - } |
|
| 68 | + $database->exec("UPDATE schemaversion SET version = 25;"); |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -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 |
@@ -10,21 +10,21 @@ |
||
| 10 | 10 | |
| 11 | 11 | abstract class PublicInterfacePageBase extends PageBase |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * PublicInterfaceInternalPageBase constructor. |
|
| 15 | - */ |
|
| 16 | - public function __construct() |
|
| 17 | - { |
|
| 18 | - $this->template = 'publicbase.tpl'; |
|
| 19 | - } |
|
| 13 | + /** |
|
| 14 | + * PublicInterfaceInternalPageBase constructor. |
|
| 15 | + */ |
|
| 16 | + public function __construct() |
|
| 17 | + { |
|
| 18 | + $this->template = 'publicbase.tpl'; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - final public function execute() |
|
| 22 | - { |
|
| 23 | - parent::execute(); |
|
| 24 | - } |
|
| 21 | + final public function execute() |
|
| 22 | + { |
|
| 23 | + parent::execute(); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - final public function finalisePage() |
|
| 27 | - { |
|
| 28 | - parent::finalisePage(); |
|
| 29 | - } |
|
| 26 | + final public function finalisePage() |
|
| 27 | + { |
|
| 28 | + parent::finalisePage(); |
|
| 29 | + } |
|
| 30 | 30 | } |
| 31 | 31 | \ No newline at end of file |
@@ -12,21 +12,21 @@ |
||
| 12 | 12 | |
| 13 | 13 | interface IRoutedTask extends ITask |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Sets the route the request will take. Only should be called from the request router. |
|
| 17 | - * |
|
| 18 | - * @param $routeName string |
|
| 19 | - * |
|
| 20 | - * @return void |
|
| 21 | - * |
|
| 22 | - * @throws Exception |
|
| 23 | - * @category Security-Critical |
|
| 24 | - */ |
|
| 25 | - public function setRoute($routeName); |
|
| 15 | + /** |
|
| 16 | + * Sets the route the request will take. Only should be called from the request router. |
|
| 17 | + * |
|
| 18 | + * @param $routeName string |
|
| 19 | + * |
|
| 20 | + * @return void |
|
| 21 | + * |
|
| 22 | + * @throws Exception |
|
| 23 | + * @category Security-Critical |
|
| 24 | + */ |
|
| 25 | + public function setRoute($routeName); |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Gets the name of the route that has been passed from the request router. |
|
| 29 | - * @return string |
|
| 30 | - */ |
|
| 31 | - public function getRouteName(); |
|
| 27 | + /** |
|
| 28 | + * Gets the name of the route that has been passed from the request router. |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 31 | + public function getRouteName(); |
|
| 32 | 32 | } |
| 33 | 33 | \ No newline at end of file |
@@ -10,8 +10,8 @@ |
||
| 10 | 10 | |
| 11 | 11 | class RegexConstants |
| 12 | 12 | { |
| 13 | - const IPV6_CIDR = '(?:/(?:12[0-8]|1[01][0-9]|[0-9]{1,2}))?'; |
|
| 14 | - const IPV4_CIDR = '(?:/(?:32|3[01]|[0-2]?[0-9]))?'; |
|
| 15 | - const IPV4 = '(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'; |
|
| 16 | - const IPV6 = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'; |
|
| 13 | + const IPV6_CIDR = '(?:/(?:12[0-8]|1[01][0-9]|[0-9]{1,2}))?'; |
|
| 14 | + const IPV4_CIDR = '(?:/(?:32|3[01]|[0-2]?[0-9]))?'; |
|
| 15 | + const IPV4 = '(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'; |
|
| 16 | + const IPV6 = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'; |
|
| 17 | 17 | } |
| 18 | 18 | \ No newline at end of file |
@@ -21,22 +21,22 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class ReadableException extends Exception |
| 23 | 23 | { |
| 24 | - use TemplateOutput; |
|
| 24 | + use TemplateOutput; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Returns a readable HTML error message that's displayable to the user using templates. |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - abstract public function getReadableError(); |
|
| 26 | + /** |
|
| 27 | + * Returns a readable HTML error message that's displayable to the user using templates. |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + abstract public function getReadableError(); |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @return SiteConfiguration |
|
| 34 | - */ |
|
| 35 | - protected function getSiteConfiguration() |
|
| 36 | - { |
|
| 37 | - // Uck. However, we have encountered an exception. |
|
| 38 | - global $siteConfiguration; |
|
| 32 | + /** |
|
| 33 | + * @return SiteConfiguration |
|
| 34 | + */ |
|
| 35 | + protected function getSiteConfiguration() |
|
| 36 | + { |
|
| 37 | + // Uck. However, we have encountered an exception. |
|
| 38 | + global $siteConfiguration; |
|
| 39 | 39 | |
| 40 | - return $siteConfiguration; |
|
| 41 | - } |
|
| 40 | + return $siteConfiguration; |
|
| 41 | + } |
|
| 42 | 42 | } |
| 43 | 43 | \ No newline at end of file |
@@ -21,13 +21,13 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class EnvironmentException extends Exception |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * EnvironmentException constructor. |
|
| 26 | - * |
|
| 27 | - * @param string $friendlyMessage |
|
| 28 | - */ |
|
| 29 | - public function __construct($friendlyMessage) |
|
| 30 | - { |
|
| 31 | - parent::__construct($friendlyMessage); |
|
| 32 | - } |
|
| 24 | + /** |
|
| 25 | + * EnvironmentException constructor. |
|
| 26 | + * |
|
| 27 | + * @param string $friendlyMessage |
|
| 28 | + */ |
|
| 29 | + public function __construct($friendlyMessage) |
|
| 30 | + { |
|
| 31 | + parent::__construct($friendlyMessage); |
|
| 32 | + } |
|
| 33 | 33 | } |
| 34 | 34 | \ No newline at end of file |
@@ -15,95 +15,95 @@ |
||
| 15 | 15 | |
| 16 | 16 | class UserRole extends DataObject |
| 17 | 17 | { |
| 18 | - /** @var int */ |
|
| 19 | - private $user; |
|
| 20 | - /** @var string */ |
|
| 21 | - private $role; |
|
| 18 | + /** @var int */ |
|
| 19 | + private $user; |
|
| 20 | + /** @var string */ |
|
| 21 | + private $role; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param int $userId |
|
| 25 | - * @param PdoDatabase $database |
|
| 26 | - * |
|
| 27 | - * @return UserRole[] |
|
| 28 | - */ |
|
| 29 | - public static function getForUser($userId, PdoDatabase $database) |
|
| 30 | - { |
|
| 31 | - $sql = 'SELECT * FROM userrole WHERE user = :user'; |
|
| 32 | - $statement = $database->prepare($sql); |
|
| 33 | - $statement->bindValue(':user', $userId); |
|
| 23 | + /** |
|
| 24 | + * @param int $userId |
|
| 25 | + * @param PdoDatabase $database |
|
| 26 | + * |
|
| 27 | + * @return UserRole[] |
|
| 28 | + */ |
|
| 29 | + public static function getForUser($userId, PdoDatabase $database) |
|
| 30 | + { |
|
| 31 | + $sql = 'SELECT * FROM userrole WHERE user = :user'; |
|
| 32 | + $statement = $database->prepare($sql); |
|
| 33 | + $statement->bindValue(':user', $userId); |
|
| 34 | 34 | |
| 35 | - $statement->execute(); |
|
| 35 | + $statement->execute(); |
|
| 36 | 36 | |
| 37 | - $result = array(); |
|
| 37 | + $result = array(); |
|
| 38 | 38 | |
| 39 | - /** @var Ban $v */ |
|
| 40 | - foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) { |
|
| 41 | - $v->setDatabase($database); |
|
| 42 | - $result[] = $v; |
|
| 43 | - } |
|
| 39 | + /** @var Ban $v */ |
|
| 40 | + foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) { |
|
| 41 | + $v->setDatabase($database); |
|
| 42 | + $result[] = $v; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - return $result; |
|
| 46 | - } |
|
| 45 | + return $result; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Saves a data object to the database, either updating or inserting a record. |
|
| 50 | - * |
|
| 51 | - * @throws Exception |
|
| 52 | - */ |
|
| 53 | - public function save() |
|
| 54 | - { |
|
| 55 | - if ($this->isNew()) { |
|
| 56 | - // insert |
|
| 57 | - $statement = $this->dbObject->prepare('INSERT INTO `userrole` (user, role) VALUES (:user, :role);' |
|
| 58 | - ); |
|
| 59 | - $statement->bindValue(":user", $this->user); |
|
| 60 | - $statement->bindValue(":role", $this->role); |
|
| 48 | + /** |
|
| 49 | + * Saves a data object to the database, either updating or inserting a record. |
|
| 50 | + * |
|
| 51 | + * @throws Exception |
|
| 52 | + */ |
|
| 53 | + public function save() |
|
| 54 | + { |
|
| 55 | + if ($this->isNew()) { |
|
| 56 | + // insert |
|
| 57 | + $statement = $this->dbObject->prepare('INSERT INTO `userrole` (user, role) VALUES (:user, :role);' |
|
| 58 | + ); |
|
| 59 | + $statement->bindValue(":user", $this->user); |
|
| 60 | + $statement->bindValue(":role", $this->role); |
|
| 61 | 61 | |
| 62 | - if ($statement->execute()) { |
|
| 63 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 64 | - } |
|
| 65 | - else { |
|
| 66 | - throw new Exception($statement->errorInfo()); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - else { |
|
| 70 | - // update |
|
| 71 | - throw new Exception('Updating roles is not available'); |
|
| 72 | - } |
|
| 73 | - } |
|
| 62 | + if ($statement->execute()) { |
|
| 63 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 64 | + } |
|
| 65 | + else { |
|
| 66 | + throw new Exception($statement->errorInfo()); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + else { |
|
| 70 | + // update |
|
| 71 | + throw new Exception('Updating roles is not available'); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - #region Properties |
|
| 75 | + #region Properties |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @return int |
|
| 79 | - */ |
|
| 80 | - public function getUser() |
|
| 81 | - { |
|
| 82 | - return $this->user; |
|
| 83 | - } |
|
| 77 | + /** |
|
| 78 | + * @return int |
|
| 79 | + */ |
|
| 80 | + public function getUser() |
|
| 81 | + { |
|
| 82 | + return $this->user; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @param int $user |
|
| 87 | - */ |
|
| 88 | - public function setUser($user) |
|
| 89 | - { |
|
| 90 | - $this->user = $user; |
|
| 91 | - } |
|
| 85 | + /** |
|
| 86 | + * @param int $user |
|
| 87 | + */ |
|
| 88 | + public function setUser($user) |
|
| 89 | + { |
|
| 90 | + $this->user = $user; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @return string |
|
| 95 | - */ |
|
| 96 | - public function getRole() |
|
| 97 | - { |
|
| 98 | - return $this->role; |
|
| 99 | - } |
|
| 93 | + /** |
|
| 94 | + * @return string |
|
| 95 | + */ |
|
| 96 | + public function getRole() |
|
| 97 | + { |
|
| 98 | + return $this->role; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @param string $role |
|
| 103 | - */ |
|
| 104 | - public function setRole($role) |
|
| 105 | - { |
|
| 106 | - $this->role = $role; |
|
| 107 | - } |
|
| 108 | - #endregion |
|
| 101 | + /** |
|
| 102 | + * @param string $role |
|
| 103 | + */ |
|
| 104 | + public function setRole($role) |
|
| 105 | + { |
|
| 106 | + $this->role = $role; |
|
| 107 | + } |
|
| 108 | + #endregion |
|
| 109 | 109 | } |