@@ -17,151 +17,151 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Log extends DataObject |
| 19 | 19 | { |
| 20 | - /** @var int */ |
|
| 21 | - private $objectid; |
|
| 22 | - /** @var string */ |
|
| 23 | - private $objecttype; |
|
| 24 | - /** @var int */ |
|
| 25 | - private $user; |
|
| 26 | - /** @var string */ |
|
| 27 | - private $action; |
|
| 28 | - private $timestamp; |
|
| 29 | - /** @var string|null */ |
|
| 30 | - private $comment; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @throws Exception |
|
| 34 | - */ |
|
| 35 | - public function save() |
|
| 36 | - { |
|
| 37 | - if ($this->isNew()) { |
|
| 38 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 20 | + /** @var int */ |
|
| 21 | + private $objectid; |
|
| 22 | + /** @var string */ |
|
| 23 | + private $objecttype; |
|
| 24 | + /** @var int */ |
|
| 25 | + private $user; |
|
| 26 | + /** @var string */ |
|
| 27 | + private $action; |
|
| 28 | + private $timestamp; |
|
| 29 | + /** @var string|null */ |
|
| 30 | + private $comment; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @throws Exception |
|
| 34 | + */ |
|
| 35 | + public function save() |
|
| 36 | + { |
|
| 37 | + if ($this->isNew()) { |
|
| 38 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 39 | 39 | INSERT INTO log (objectid, objecttype, user, action, timestamp, comment) |
| 40 | 40 | VALUES (:id, :type, :user, :action, CURRENT_TIMESTAMP(), :comment); |
| 41 | 41 | SQL |
| 42 | - ); |
|
| 43 | - |
|
| 44 | - $statement->bindValue(":id", $this->objectid); |
|
| 45 | - $statement->bindValue(":type", $this->objecttype); |
|
| 46 | - $statement->bindValue(":user", $this->user); |
|
| 47 | - $statement->bindValue(":action", $this->action); |
|
| 48 | - $statement->bindValue(":comment", $this->comment); |
|
| 49 | - |
|
| 50 | - if ($statement->execute()) { |
|
| 51 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 52 | - } |
|
| 53 | - else { |
|
| 54 | - throw new Exception($statement->errorInfo()); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - else { |
|
| 58 | - throw new Exception("Updating logs is not available"); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @throws Exception |
|
| 64 | - */ |
|
| 65 | - public function delete() |
|
| 66 | - { |
|
| 67 | - throw new Exception("Deleting logs is not available."); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return int |
|
| 72 | - */ |
|
| 73 | - public function getObjectId() |
|
| 74 | - { |
|
| 75 | - return $this->objectid; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Summary of setObjectId |
|
| 80 | - * |
|
| 81 | - * @param int $objectId |
|
| 82 | - */ |
|
| 83 | - public function setObjectId($objectId) |
|
| 84 | - { |
|
| 85 | - $this->objectid = $objectId; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function getObjectType() |
|
| 92 | - { |
|
| 93 | - return $this->objecttype; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Summary of setObjectType |
|
| 98 | - * |
|
| 99 | - * @param string $objectType |
|
| 100 | - */ |
|
| 101 | - public function setObjectType($objectType) |
|
| 102 | - { |
|
| 103 | - $this->objecttype = $objectType; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return int |
|
| 108 | - */ |
|
| 109 | - public function getUser() |
|
| 110 | - { |
|
| 111 | - return $this->user; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Summary of setUser |
|
| 116 | - * |
|
| 117 | - * @param User $user |
|
| 118 | - */ |
|
| 119 | - public function setUser(User $user) |
|
| 120 | - { |
|
| 121 | - $this->user = $user->getId(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @return string |
|
| 126 | - */ |
|
| 127 | - public function getAction() |
|
| 128 | - { |
|
| 129 | - return $this->action; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Summary of setAction |
|
| 134 | - * |
|
| 135 | - * @param string $action |
|
| 136 | - */ |
|
| 137 | - public function setAction($action) |
|
| 138 | - { |
|
| 139 | - $this->action = $action; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @return DateTimeImmutable |
|
| 144 | - */ |
|
| 145 | - public function getTimestamp() |
|
| 146 | - { |
|
| 147 | - return new DateTimeImmutable($this->timestamp); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @return string|null |
|
| 152 | - */ |
|
| 153 | - public function getComment() |
|
| 154 | - { |
|
| 155 | - return $this->comment; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Summary of setComment |
|
| 160 | - * |
|
| 161 | - * @param string $comment |
|
| 162 | - */ |
|
| 163 | - public function setComment($comment) |
|
| 164 | - { |
|
| 165 | - $this->comment = $comment; |
|
| 166 | - } |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + $statement->bindValue(":id", $this->objectid); |
|
| 45 | + $statement->bindValue(":type", $this->objecttype); |
|
| 46 | + $statement->bindValue(":user", $this->user); |
|
| 47 | + $statement->bindValue(":action", $this->action); |
|
| 48 | + $statement->bindValue(":comment", $this->comment); |
|
| 49 | + |
|
| 50 | + if ($statement->execute()) { |
|
| 51 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 52 | + } |
|
| 53 | + else { |
|
| 54 | + throw new Exception($statement->errorInfo()); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + else { |
|
| 58 | + throw new Exception("Updating logs is not available"); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @throws Exception |
|
| 64 | + */ |
|
| 65 | + public function delete() |
|
| 66 | + { |
|
| 67 | + throw new Exception("Deleting logs is not available."); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return int |
|
| 72 | + */ |
|
| 73 | + public function getObjectId() |
|
| 74 | + { |
|
| 75 | + return $this->objectid; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Summary of setObjectId |
|
| 80 | + * |
|
| 81 | + * @param int $objectId |
|
| 82 | + */ |
|
| 83 | + public function setObjectId($objectId) |
|
| 84 | + { |
|
| 85 | + $this->objectid = $objectId; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function getObjectType() |
|
| 92 | + { |
|
| 93 | + return $this->objecttype; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Summary of setObjectType |
|
| 98 | + * |
|
| 99 | + * @param string $objectType |
|
| 100 | + */ |
|
| 101 | + public function setObjectType($objectType) |
|
| 102 | + { |
|
| 103 | + $this->objecttype = $objectType; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return int |
|
| 108 | + */ |
|
| 109 | + public function getUser() |
|
| 110 | + { |
|
| 111 | + return $this->user; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Summary of setUser |
|
| 116 | + * |
|
| 117 | + * @param User $user |
|
| 118 | + */ |
|
| 119 | + public function setUser(User $user) |
|
| 120 | + { |
|
| 121 | + $this->user = $user->getId(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @return string |
|
| 126 | + */ |
|
| 127 | + public function getAction() |
|
| 128 | + { |
|
| 129 | + return $this->action; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Summary of setAction |
|
| 134 | + * |
|
| 135 | + * @param string $action |
|
| 136 | + */ |
|
| 137 | + public function setAction($action) |
|
| 138 | + { |
|
| 139 | + $this->action = $action; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @return DateTimeImmutable |
|
| 144 | + */ |
|
| 145 | + public function getTimestamp() |
|
| 146 | + { |
|
| 147 | + return new DateTimeImmutable($this->timestamp); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @return string|null |
|
| 152 | + */ |
|
| 153 | + public function getComment() |
|
| 154 | + { |
|
| 155 | + return $this->comment; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Summary of setComment |
|
| 160 | + * |
|
| 161 | + * @param string $comment |
|
| 162 | + */ |
|
| 163 | + public function setComment($comment) |
|
| 164 | + { |
|
| 165 | + $this->comment = $comment; |
|
| 166 | + } |
|
| 167 | 167 | } |
@@ -54,7 +54,7 @@ |
||
| 54 | 54 | final protected function setUpSmarty() |
| 55 | 55 | { |
| 56 | 56 | $this->smarty = new Smarty(); |
| 57 | - $this->smarty->addPluginsDir($this->getSiteConfiguration()->getFilePath() . '/smarty-plugins'); |
|
| 57 | + $this->smarty->addPluginsDir($this->getSiteConfiguration()->getFilePath().'/smarty-plugins'); |
|
| 58 | 58 | |
| 59 | 59 | $this->assign('currentUser', User::getCommunity()); |
| 60 | 60 | $this->assign('loggedIn', false); |
@@ -15,89 +15,89 @@ |
||
| 15 | 15 | |
| 16 | 16 | trait TemplateOutput |
| 17 | 17 | { |
| 18 | - /** @var Smarty */ |
|
| 19 | - private $smarty; |
|
| 20 | - /** @var string Extra JavaScript to include at the end of the page's execution */ |
|
| 21 | - private $tailScript; |
|
| 18 | + /** @var Smarty */ |
|
| 19 | + private $smarty; |
|
| 20 | + /** @var string Extra JavaScript to include at the end of the page's execution */ |
|
| 21 | + private $tailScript; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @return SiteConfiguration |
|
| 25 | - */ |
|
| 26 | - protected abstract function getSiteConfiguration(); |
|
| 23 | + /** |
|
| 24 | + * @return SiteConfiguration |
|
| 25 | + */ |
|
| 26 | + protected abstract function getSiteConfiguration(); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Include extra JavaScript at the end of the page's execution |
|
| 30 | - * |
|
| 31 | - * @param $script string JavaScript to include at the end of the page |
|
| 32 | - */ |
|
| 33 | - final protected function setTailScript($script) |
|
| 34 | - { |
|
| 35 | - $this->tailScript = $script; |
|
| 36 | - } |
|
| 28 | + /** |
|
| 29 | + * Include extra JavaScript at the end of the page's execution |
|
| 30 | + * |
|
| 31 | + * @param $script string JavaScript to include at the end of the page |
|
| 32 | + */ |
|
| 33 | + final protected function setTailScript($script) |
|
| 34 | + { |
|
| 35 | + $this->tailScript = $script; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Assigns a Smarty variable |
|
| 40 | - * |
|
| 41 | - * @param array|string $name the template variable name(s) |
|
| 42 | - * @param mixed $value the value to assign |
|
| 43 | - */ |
|
| 44 | - final protected function assign($name, $value) |
|
| 45 | - { |
|
| 46 | - $this->smarty->assign($name, $value); |
|
| 47 | - } |
|
| 38 | + /** |
|
| 39 | + * Assigns a Smarty variable |
|
| 40 | + * |
|
| 41 | + * @param array|string $name the template variable name(s) |
|
| 42 | + * @param mixed $value the value to assign |
|
| 43 | + */ |
|
| 44 | + final protected function assign($name, $value) |
|
| 45 | + { |
|
| 46 | + $this->smarty->assign($name, $value); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Sets up the variables used by the main Smarty base template. |
|
| 51 | - * |
|
| 52 | - * This list is getting kinda long. |
|
| 53 | - */ |
|
| 54 | - final protected function setUpSmarty() |
|
| 55 | - { |
|
| 56 | - $this->smarty = new Smarty(); |
|
| 57 | - $this->smarty->addPluginsDir($this->getSiteConfiguration()->getFilePath() . '/smarty-plugins'); |
|
| 49 | + /** |
|
| 50 | + * Sets up the variables used by the main Smarty base template. |
|
| 51 | + * |
|
| 52 | + * This list is getting kinda long. |
|
| 53 | + */ |
|
| 54 | + final protected function setUpSmarty() |
|
| 55 | + { |
|
| 56 | + $this->smarty = new Smarty(); |
|
| 57 | + $this->smarty->addPluginsDir($this->getSiteConfiguration()->getFilePath() . '/smarty-plugins'); |
|
| 58 | 58 | |
| 59 | - $this->assign('currentUser', User::getCommunity()); |
|
| 60 | - $this->assign('loggedIn', false); |
|
| 61 | - $this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl()); |
|
| 62 | - $this->assign('mediawikiScriptPath', $this->getSiteConfiguration()->getMediawikiScriptPath()); |
|
| 59 | + $this->assign('currentUser', User::getCommunity()); |
|
| 60 | + $this->assign('loggedIn', false); |
|
| 61 | + $this->assign('baseurl', $this->getSiteConfiguration()->getBaseUrl()); |
|
| 62 | + $this->assign('mediawikiScriptPath', $this->getSiteConfiguration()->getMediawikiScriptPath()); |
|
| 63 | 63 | |
| 64 | - $this->assign('siteNoticeText', ''); |
|
| 65 | - $this->assign('toolversion', Environment::getToolVersion()); |
|
| 64 | + $this->assign('siteNoticeText', ''); |
|
| 65 | + $this->assign('toolversion', Environment::getToolVersion()); |
|
| 66 | 66 | |
| 67 | - // default these |
|
| 68 | - $this->assign('onlineusers', array()); |
|
| 69 | - $this->assign('typeAheadBlock', ''); |
|
| 70 | - $this->assign('extraJs', array()); |
|
| 71 | - $this->assign('extraCss', array()); |
|
| 67 | + // default these |
|
| 68 | + $this->assign('onlineusers', array()); |
|
| 69 | + $this->assign('typeAheadBlock', ''); |
|
| 70 | + $this->assign('extraJs', array()); |
|
| 71 | + $this->assign('extraCss', array()); |
|
| 72 | 72 | |
| 73 | - // nav menu access control |
|
| 74 | - $this->assign('nav__canRequests', false); |
|
| 75 | - $this->assign('nav__canLogs', false); |
|
| 76 | - $this->assign('nav__canUsers', false); |
|
| 77 | - $this->assign('nav__canSearch', false); |
|
| 78 | - $this->assign('nav__canStats', false); |
|
| 79 | - $this->assign('nav__canBan', false); |
|
| 80 | - $this->assign('nav__canEmailMgmt', false); |
|
| 81 | - $this->assign('nav__canWelcomeMgmt', false); |
|
| 82 | - $this->assign('nav__canSiteNoticeMgmt', false); |
|
| 83 | - $this->assign('nav__canUserMgmt', false); |
|
| 84 | - $this->assign('nav__canViewRequest', false); |
|
| 85 | - $this->assign('nav__canJobQueue', false); |
|
| 73 | + // nav menu access control |
|
| 74 | + $this->assign('nav__canRequests', false); |
|
| 75 | + $this->assign('nav__canLogs', false); |
|
| 76 | + $this->assign('nav__canUsers', false); |
|
| 77 | + $this->assign('nav__canSearch', false); |
|
| 78 | + $this->assign('nav__canStats', false); |
|
| 79 | + $this->assign('nav__canBan', false); |
|
| 80 | + $this->assign('nav__canEmailMgmt', false); |
|
| 81 | + $this->assign('nav__canWelcomeMgmt', false); |
|
| 82 | + $this->assign('nav__canSiteNoticeMgmt', false); |
|
| 83 | + $this->assign('nav__canUserMgmt', false); |
|
| 84 | + $this->assign('nav__canViewRequest', false); |
|
| 85 | + $this->assign('nav__canJobQueue', false); |
|
| 86 | 86 | |
| 87 | - $this->assign('page', $this); |
|
| 88 | - } |
|
| 87 | + $this->assign('page', $this); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Fetches a rendered Smarty template |
|
| 92 | - * |
|
| 93 | - * @param $template string Template file path, relative to /templates/ |
|
| 94 | - * |
|
| 95 | - * @return string Templated HTML |
|
| 96 | - */ |
|
| 97 | - final protected function fetchTemplate($template) |
|
| 98 | - { |
|
| 99 | - $this->assign('tailScript', $this->tailScript); |
|
| 90 | + /** |
|
| 91 | + * Fetches a rendered Smarty template |
|
| 92 | + * |
|
| 93 | + * @param $template string Template file path, relative to /templates/ |
|
| 94 | + * |
|
| 95 | + * @return string Templated HTML |
|
| 96 | + */ |
|
| 97 | + final protected function fetchTemplate($template) |
|
| 98 | + { |
|
| 99 | + $this->assign('tailScript', $this->tailScript); |
|
| 100 | 100 | |
| 101 | - return $this->smarty->fetch($template); |
|
| 102 | - } |
|
| 101 | + return $this->smarty->fetch($template); |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -17,25 +17,25 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Session |
| 19 | 19 | { |
| 20 | - public static function start() |
|
| 21 | - { |
|
| 22 | - ini_set('session.cookie_httponly', 1); |
|
| 20 | + public static function start() |
|
| 21 | + { |
|
| 22 | + ini_set('session.cookie_httponly', 1); |
|
| 23 | 23 | |
| 24 | - if (WebRequest::isHttps()) { |
|
| 25 | - ini_set('session.cookie_secure', 1); |
|
| 26 | - } |
|
| 24 | + if (WebRequest::isHttps()) { |
|
| 25 | + ini_set('session.cookie_secure', 1); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - session_start(); |
|
| 29 | - } |
|
| 28 | + session_start(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public static function destroy() |
|
| 32 | - { |
|
| 33 | - session_destroy(); |
|
| 34 | - } |
|
| 31 | + public static function destroy() |
|
| 32 | + { |
|
| 33 | + session_destroy(); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public static function restart() |
|
| 37 | - { |
|
| 38 | - self::destroy(); |
|
| 39 | - self::start(); |
|
| 40 | - } |
|
| 36 | + public static function restart() |
|
| 37 | + { |
|
| 38 | + self::destroy(); |
|
| 39 | + self::start(); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -96,7 +96,7 @@ |
||
| 96 | 96 | |
| 97 | 97 | $statement = $this->getDatabase()->prepare($query); |
| 98 | 98 | $statement->bindValue(":username", $this->user->getUsername()); |
| 99 | - $statement->bindValue(":date", date('Y-m-d') . "%"); |
|
| 99 | + $statement->bindValue(":date", date('Y-m-d')."%"); |
|
| 100 | 100 | $statement->execute(); |
| 101 | 101 | $today = $statement->fetchColumn(); |
| 102 | 102 | $statement->closeCursor(); |
@@ -20,47 +20,47 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class CountAction extends XmlApiPageBase implements IXmlApiAction |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * The target user |
|
| 25 | - * @var User $user |
|
| 26 | - */ |
|
| 27 | - private $user; |
|
| 23 | + /** |
|
| 24 | + * The target user |
|
| 25 | + * @var User $user |
|
| 26 | + */ |
|
| 27 | + private $user; |
|
| 28 | 28 | |
| 29 | - public function executeApiAction(DOMElement $apiDocument) |
|
| 30 | - { |
|
| 31 | - $username = WebRequest::getString('user'); |
|
| 32 | - if ($username === null) { |
|
| 33 | - throw new ApiException("Please specify a username"); |
|
| 34 | - } |
|
| 29 | + public function executeApiAction(DOMElement $apiDocument) |
|
| 30 | + { |
|
| 31 | + $username = WebRequest::getString('user'); |
|
| 32 | + if ($username === null) { |
|
| 33 | + throw new ApiException("Please specify a username"); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - $userElement = $this->document->createElement("user"); |
|
| 37 | - $userElement->setAttribute("name", $username); |
|
| 38 | - $apiDocument->appendChild($userElement); |
|
| 36 | + $userElement = $this->document->createElement("user"); |
|
| 37 | + $userElement->setAttribute("name", $username); |
|
| 38 | + $apiDocument->appendChild($userElement); |
|
| 39 | 39 | |
| 40 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
| 40 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
| 41 | 41 | |
| 42 | - if ($user === false) { |
|
| 43 | - $userElement->setAttribute("missing", "true"); |
|
| 42 | + if ($user === false) { |
|
| 43 | + $userElement->setAttribute("missing", "true"); |
|
| 44 | 44 | |
| 45 | - return $apiDocument; |
|
| 46 | - } |
|
| 45 | + return $apiDocument; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - $this->user = $user; |
|
| 48 | + $this->user = $user; |
|
| 49 | 49 | |
| 50 | - $userElement->setAttribute("level", $this->user->getStatus()); |
|
| 51 | - $userElement->setAttribute("created", $this->getAccountsCreated()); |
|
| 50 | + $userElement->setAttribute("level", $this->user->getStatus()); |
|
| 51 | + $userElement->setAttribute("created", $this->getAccountsCreated()); |
|
| 52 | 52 | |
| 53 | - $userElement->setAttribute("today", $this->getToday()); |
|
| 53 | + $userElement->setAttribute("today", $this->getToday()); |
|
| 54 | 54 | |
| 55 | - // Let the IRC bot handle the result of this. |
|
| 56 | - $this->fetchAdminData($userElement); |
|
| 55 | + // Let the IRC bot handle the result of this. |
|
| 56 | + $this->fetchAdminData($userElement); |
|
| 57 | 57 | |
| 58 | - return $apiDocument; |
|
| 59 | - } |
|
| 58 | + return $apiDocument; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - private function getAccountsCreated() |
|
| 62 | - { |
|
| 63 | - $query = <<<QUERY |
|
| 61 | + private function getAccountsCreated() |
|
| 62 | + { |
|
| 63 | + $query = <<<QUERY |
|
| 64 | 64 | SELECT COUNT(*) AS count |
| 65 | 65 | FROM log |
| 66 | 66 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | AND user.username = :username; |
| 72 | 72 | QUERY; |
| 73 | 73 | |
| 74 | - $statement = $this->getDatabase()->prepare($query); |
|
| 75 | - $statement->execute(array(":username" => $this->user->getUsername())); |
|
| 76 | - $result = $statement->fetchColumn(); |
|
| 77 | - $statement->closeCursor(); |
|
| 74 | + $statement = $this->getDatabase()->prepare($query); |
|
| 75 | + $statement->execute(array(":username" => $this->user->getUsername())); |
|
| 76 | + $result = $statement->fetchColumn(); |
|
| 77 | + $statement->closeCursor(); |
|
| 78 | 78 | |
| 79 | - return $result; |
|
| 80 | - } |
|
| 79 | + return $result; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - private function getToday() |
|
| 83 | - { |
|
| 84 | - $query = <<<QUERY |
|
| 82 | + private function getToday() |
|
| 83 | + { |
|
| 84 | + $query = <<<QUERY |
|
| 85 | 85 | SELECT |
| 86 | 86 | COUNT(*) AS count |
| 87 | 87 | FROM log |
@@ -93,99 +93,99 @@ discard block |
||
| 93 | 93 | AND user.username = :username; |
| 94 | 94 | QUERY; |
| 95 | 95 | |
| 96 | - $statement = $this->getDatabase()->prepare($query); |
|
| 97 | - $statement->bindValue(":username", $this->user->getUsername()); |
|
| 98 | - $statement->bindValue(":date", date('Y-m-d') . "%"); |
|
| 99 | - $statement->execute(); |
|
| 100 | - $today = $statement->fetchColumn(); |
|
| 101 | - $statement->closeCursor(); |
|
| 102 | - |
|
| 103 | - return $today; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - private function fetchAdminData(DOMElement $userElement) |
|
| 107 | - { |
|
| 108 | - $query = "SELECT COUNT(*) AS count FROM log WHERE log.user = :userid AND log.action = :action;"; |
|
| 109 | - |
|
| 110 | - $statement = $this->getDatabase()->prepare($query); |
|
| 111 | - $statement->bindValue(":userid", $this->user->getId()); |
|
| 112 | - $statement->bindValue(":action", "Suspended"); |
|
| 113 | - $statement->execute(); |
|
| 114 | - $sus = $statement->fetchColumn(); |
|
| 115 | - $userElement->setAttribute("suspended", $sus); |
|
| 116 | - $statement->closeCursor(); |
|
| 117 | - |
|
| 118 | - $statement->bindValue(":action", "Promoted"); |
|
| 119 | - $statement->execute(); |
|
| 120 | - $pro = $statement->fetchColumn(); |
|
| 121 | - $userElement->setAttribute("promoted", $pro); |
|
| 122 | - $statement->closeCursor(); |
|
| 123 | - |
|
| 124 | - $statement->bindValue(":action", "Approved"); |
|
| 125 | - $statement->execute(); |
|
| 126 | - $app = $statement->fetchColumn(); |
|
| 127 | - $userElement->setAttribute("approved", $app); |
|
| 128 | - $statement->closeCursor(); |
|
| 129 | - |
|
| 130 | - $statement->bindValue(":action", "Demoted"); |
|
| 131 | - $statement->execute(); |
|
| 132 | - $dem = $statement->fetchColumn(); |
|
| 133 | - $userElement->setAttribute("demoted", $dem); |
|
| 134 | - $statement->closeCursor(); |
|
| 135 | - |
|
| 136 | - $statement->bindValue(":action", "Declined"); |
|
| 137 | - $statement->execute(); |
|
| 138 | - $dec = $statement->fetchColumn(); |
|
| 139 | - $userElement->setAttribute("declined", $dec); |
|
| 140 | - $statement->closeCursor(); |
|
| 141 | - |
|
| 142 | - $statement->bindValue(":action", "Renamed"); |
|
| 143 | - $statement->execute(); |
|
| 144 | - $rnc = $statement->fetchColumn(); |
|
| 145 | - $userElement->setAttribute("renamed", $rnc); |
|
| 146 | - $statement->closeCursor(); |
|
| 147 | - |
|
| 148 | - $statement->bindValue(":action", "Edited"); |
|
| 149 | - $statement->execute(); |
|
| 150 | - $mec = $statement->fetchColumn(); |
|
| 151 | - $userElement->setAttribute("edited", $mec); |
|
| 152 | - $statement->closeCursor(); |
|
| 153 | - |
|
| 154 | - $statement->bindValue(":action", "Prefchange"); |
|
| 155 | - $statement->execute(); |
|
| 156 | - $pcc = $statement->fetchColumn(); |
|
| 157 | - $userElement->setAttribute("prefchange", $pcc); |
|
| 158 | - $statement->closeCursor(); |
|
| 159 | - |
|
| 160 | - // Combine all three actions affecting Welcome templates into one count. |
|
| 161 | - $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
| 96 | + $statement = $this->getDatabase()->prepare($query); |
|
| 97 | + $statement->bindValue(":username", $this->user->getUsername()); |
|
| 98 | + $statement->bindValue(":date", date('Y-m-d') . "%"); |
|
| 99 | + $statement->execute(); |
|
| 100 | + $today = $statement->fetchColumn(); |
|
| 101 | + $statement->closeCursor(); |
|
| 102 | + |
|
| 103 | + return $today; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + private function fetchAdminData(DOMElement $userElement) |
|
| 107 | + { |
|
| 108 | + $query = "SELECT COUNT(*) AS count FROM log WHERE log.user = :userid AND log.action = :action;"; |
|
| 109 | + |
|
| 110 | + $statement = $this->getDatabase()->prepare($query); |
|
| 111 | + $statement->bindValue(":userid", $this->user->getId()); |
|
| 112 | + $statement->bindValue(":action", "Suspended"); |
|
| 113 | + $statement->execute(); |
|
| 114 | + $sus = $statement->fetchColumn(); |
|
| 115 | + $userElement->setAttribute("suspended", $sus); |
|
| 116 | + $statement->closeCursor(); |
|
| 117 | + |
|
| 118 | + $statement->bindValue(":action", "Promoted"); |
|
| 119 | + $statement->execute(); |
|
| 120 | + $pro = $statement->fetchColumn(); |
|
| 121 | + $userElement->setAttribute("promoted", $pro); |
|
| 122 | + $statement->closeCursor(); |
|
| 123 | + |
|
| 124 | + $statement->bindValue(":action", "Approved"); |
|
| 125 | + $statement->execute(); |
|
| 126 | + $app = $statement->fetchColumn(); |
|
| 127 | + $userElement->setAttribute("approved", $app); |
|
| 128 | + $statement->closeCursor(); |
|
| 129 | + |
|
| 130 | + $statement->bindValue(":action", "Demoted"); |
|
| 131 | + $statement->execute(); |
|
| 132 | + $dem = $statement->fetchColumn(); |
|
| 133 | + $userElement->setAttribute("demoted", $dem); |
|
| 134 | + $statement->closeCursor(); |
|
| 135 | + |
|
| 136 | + $statement->bindValue(":action", "Declined"); |
|
| 137 | + $statement->execute(); |
|
| 138 | + $dec = $statement->fetchColumn(); |
|
| 139 | + $userElement->setAttribute("declined", $dec); |
|
| 140 | + $statement->closeCursor(); |
|
| 141 | + |
|
| 142 | + $statement->bindValue(":action", "Renamed"); |
|
| 143 | + $statement->execute(); |
|
| 144 | + $rnc = $statement->fetchColumn(); |
|
| 145 | + $userElement->setAttribute("renamed", $rnc); |
|
| 146 | + $statement->closeCursor(); |
|
| 147 | + |
|
| 148 | + $statement->bindValue(":action", "Edited"); |
|
| 149 | + $statement->execute(); |
|
| 150 | + $mec = $statement->fetchColumn(); |
|
| 151 | + $userElement->setAttribute("edited", $mec); |
|
| 152 | + $statement->closeCursor(); |
|
| 153 | + |
|
| 154 | + $statement->bindValue(":action", "Prefchange"); |
|
| 155 | + $statement->execute(); |
|
| 156 | + $pcc = $statement->fetchColumn(); |
|
| 157 | + $userElement->setAttribute("prefchange", $pcc); |
|
| 158 | + $statement->closeCursor(); |
|
| 159 | + |
|
| 160 | + // Combine all three actions affecting Welcome templates into one count. |
|
| 161 | + $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
| 162 | 162 | SELECT |
| 163 | 163 | COUNT(*) AS count |
| 164 | 164 | FROM log |
| 165 | 165 | WHERE log.user = :userid |
| 166 | 166 | AND log.action IN ('CreatedTemplate', 'EditedTemplate', 'DeletedTemplate'); |
| 167 | 167 | SQL |
| 168 | - ); |
|
| 168 | + ); |
|
| 169 | 169 | |
| 170 | - $combinedquery->bindValue(":userid", $this->user->getId()); |
|
| 171 | - $combinedquery->execute(); |
|
| 172 | - $dtc = $combinedquery->fetchColumn(); |
|
| 173 | - $userElement->setAttribute("welctempchange", $dtc); |
|
| 174 | - $combinedquery->closeCursor(); |
|
| 170 | + $combinedquery->bindValue(":userid", $this->user->getId()); |
|
| 171 | + $combinedquery->execute(); |
|
| 172 | + $dtc = $combinedquery->fetchColumn(); |
|
| 173 | + $userElement->setAttribute("welctempchange", $dtc); |
|
| 174 | + $combinedquery->closeCursor(); |
|
| 175 | 175 | |
| 176 | - // Combine both actions affecting Email templates into one count. |
|
| 177 | - $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
| 176 | + // Combine both actions affecting Email templates into one count. |
|
| 177 | + $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
| 178 | 178 | SELECT COUNT(*) AS count |
| 179 | 179 | FROM log |
| 180 | 180 | WHERE log.user = :userid |
| 181 | 181 | AND log.action IN ('CreatedEmail', 'EditedEmail'); |
| 182 | 182 | SQL |
| 183 | - ); |
|
| 184 | - |
|
| 185 | - $combinedquery->bindValue(":userid", $this->user->getId()); |
|
| 186 | - $combinedquery->execute(); |
|
| 187 | - $cec = $combinedquery->fetchColumn(); |
|
| 188 | - $userElement->setAttribute("emailtempchange", $cec); |
|
| 189 | - $combinedquery->closeCursor(); |
|
| 190 | - } |
|
| 183 | + ); |
|
| 184 | + |
|
| 185 | + $combinedquery->bindValue(":userid", $this->user->getId()); |
|
| 186 | + $combinedquery->execute(); |
|
| 187 | + $cec = $combinedquery->fetchColumn(); |
|
| 188 | + $userElement->setAttribute("emailtempchange", $cec); |
|
| 189 | + $combinedquery->closeCursor(); |
|
| 190 | + } |
|
| 191 | 191 | } |
@@ -15,11 +15,11 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class ApiException extends Exception |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @param string $message |
|
| 20 | - */ |
|
| 21 | - public function __construct($message) |
|
| 22 | - { |
|
| 23 | - $this->message = $message; |
|
| 24 | - } |
|
| 18 | + /** |
|
| 19 | + * @param string $message |
|
| 20 | + */ |
|
| 21 | + public function __construct($message) |
|
| 22 | + { |
|
| 23 | + $this->message = $message; |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -22,77 +22,77 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class CachedApiAntispoofProvider implements IAntiSpoofProvider |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @var PdoDatabase |
|
| 27 | - */ |
|
| 28 | - private $database; |
|
| 29 | - /** |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 32 | - private $mediawikiWebServiceEndpoint; |
|
| 33 | - /** |
|
| 34 | - * @var HttpHelper |
|
| 35 | - */ |
|
| 36 | - private $httpHelper; |
|
| 25 | + /** |
|
| 26 | + * @var PdoDatabase |
|
| 27 | + */ |
|
| 28 | + private $database; |
|
| 29 | + /** |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | + private $mediawikiWebServiceEndpoint; |
|
| 33 | + /** |
|
| 34 | + * @var HttpHelper |
|
| 35 | + */ |
|
| 36 | + private $httpHelper; |
|
| 37 | 37 | |
| 38 | - public function __construct(PdoDatabase $database, $mediawikiWebServiceEndpoint, HttpHelper $httpHelper) |
|
| 39 | - { |
|
| 40 | - $this->database = $database; |
|
| 41 | - $this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint; |
|
| 42 | - $this->httpHelper = $httpHelper; |
|
| 43 | - } |
|
| 38 | + public function __construct(PdoDatabase $database, $mediawikiWebServiceEndpoint, HttpHelper $httpHelper) |
|
| 39 | + { |
|
| 40 | + $this->database = $database; |
|
| 41 | + $this->mediawikiWebServiceEndpoint = $mediawikiWebServiceEndpoint; |
|
| 42 | + $this->httpHelper = $httpHelper; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function getSpoofs($username) |
|
| 46 | - { |
|
| 47 | - /** @var AntiSpoofCache $cacheResult */ |
|
| 48 | - $cacheResult = AntiSpoofCache::getByUsername($username, $this->database); |
|
| 49 | - if ($cacheResult == false) { |
|
| 50 | - // get the data from the API |
|
| 51 | - $data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, array( |
|
| 52 | - 'action' => 'antispoof', |
|
| 53 | - 'format' => 'php', |
|
| 54 | - 'username' => $username, |
|
| 55 | - )); |
|
| 45 | + public function getSpoofs($username) |
|
| 46 | + { |
|
| 47 | + /** @var AntiSpoofCache $cacheResult */ |
|
| 48 | + $cacheResult = AntiSpoofCache::getByUsername($username, $this->database); |
|
| 49 | + if ($cacheResult == false) { |
|
| 50 | + // get the data from the API |
|
| 51 | + $data = $this->httpHelper->get($this->mediawikiWebServiceEndpoint, array( |
|
| 52 | + 'action' => 'antispoof', |
|
| 53 | + 'format' => 'php', |
|
| 54 | + 'username' => $username, |
|
| 55 | + )); |
|
| 56 | 56 | |
| 57 | - $cacheEntry = new AntiSpoofCache(); |
|
| 58 | - $cacheEntry->setDatabase($this->database); |
|
| 59 | - $cacheEntry->setUsername($username); |
|
| 60 | - $cacheEntry->setData($data); |
|
| 61 | - $cacheEntry->save(); |
|
| 57 | + $cacheEntry = new AntiSpoofCache(); |
|
| 58 | + $cacheEntry->setDatabase($this->database); |
|
| 59 | + $cacheEntry->setUsername($username); |
|
| 60 | + $cacheEntry->setData($data); |
|
| 61 | + $cacheEntry->save(); |
|
| 62 | 62 | |
| 63 | - $cacheResult = $cacheEntry; |
|
| 64 | - } |
|
| 65 | - else { |
|
| 66 | - $data = $cacheResult->getData(); |
|
| 67 | - } |
|
| 63 | + $cacheResult = $cacheEntry; |
|
| 64 | + } |
|
| 65 | + else { |
|
| 66 | + $data = $cacheResult->getData(); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $result = unserialize($data); |
|
| 69 | + $result = unserialize($data); |
|
| 70 | 70 | |
| 71 | - if (!isset($result['antispoof']) || !isset($result['antispoof']['result'])) { |
|
| 72 | - $cacheResult->delete(); |
|
| 71 | + if (!isset($result['antispoof']) || !isset($result['antispoof']['result'])) { |
|
| 72 | + $cacheResult->delete(); |
|
| 73 | 73 | |
| 74 | - if (isset($result['error']['info'])) { |
|
| 75 | - throw new Exception("Unrecognised API response to query: " . $result['error']['info']); |
|
| 76 | - } |
|
| 74 | + if (isset($result['error']['info'])) { |
|
| 75 | + throw new Exception("Unrecognised API response to query: " . $result['error']['info']); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - throw new Exception("Unrecognised API response to query."); |
|
| 79 | - } |
|
| 78 | + throw new Exception("Unrecognised API response to query."); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - if ($result['antispoof']['result'] == "pass") { |
|
| 82 | - // All good here! |
|
| 83 | - return array(); |
|
| 84 | - } |
|
| 81 | + if ($result['antispoof']['result'] == "pass") { |
|
| 82 | + // All good here! |
|
| 83 | + return array(); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - if ($result['antispoof']['result'] == "conflict") { |
|
| 87 | - // we've got conflicts, let's do something with them. |
|
| 88 | - return $result['antispoof']['users']; |
|
| 89 | - } |
|
| 86 | + if ($result['antispoof']['result'] == "conflict") { |
|
| 87 | + // we've got conflicts, let's do something with them. |
|
| 88 | + return $result['antispoof']['users']; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - if ($result['antispoof']['result'] == "error") { |
|
| 92 | - // we've got conflicts, let's do something with them. |
|
| 93 | - throw new Exception("Encountered error while getting result: " . $result['antispoof']['error']); |
|
| 94 | - } |
|
| 91 | + if ($result['antispoof']['result'] == "error") { |
|
| 92 | + // we've got conflicts, let's do something with them. |
|
| 93 | + throw new Exception("Encountered error while getting result: " . $result['antispoof']['error']); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - throw new Exception("Unrecognised API response to query."); |
|
| 97 | - } |
|
| 96 | + throw new Exception("Unrecognised API response to query."); |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $cacheResult->delete(); |
| 73 | 73 | |
| 74 | 74 | if (isset($result['error']['info'])) { |
| 75 | - throw new Exception("Unrecognised API response to query: " . $result['error']['info']); |
|
| 75 | + throw new Exception("Unrecognised API response to query: ".$result['error']['info']); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | throw new Exception("Unrecognised API response to query."); |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | if ($result['antispoof']['result'] == "error") { |
| 92 | 92 | // we've got conflicts, let's do something with them. |
| 93 | - throw new Exception("Encountered error while getting result: " . $result['antispoof']['error']); |
|
| 93 | + throw new Exception("Encountered error while getting result: ".$result['antispoof']['error']); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | throw new Exception("Unrecognised API response to query."); |
@@ -22,156 +22,156 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class XffTrustProvider implements IXffTrustProvider |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * Array of IP addresses which are TRUSTED proxies |
|
| 27 | - * @var string[] |
|
| 28 | - */ |
|
| 29 | - private $trustedCache = array(); |
|
| 30 | - /** |
|
| 31 | - * Array of IP addresses which are UNTRUSTED proxies |
|
| 32 | - * @var string[] |
|
| 33 | - */ |
|
| 34 | - private $untrustedCache = array(); |
|
| 35 | - /** @var PDOStatement */ |
|
| 36 | - private $trustedQuery; |
|
| 37 | - /** |
|
| 38 | - * @var PdoDatabase |
|
| 39 | - */ |
|
| 40 | - private $database; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Creates a new instance of the trust provider |
|
| 44 | - * |
|
| 45 | - * @param string[] $squidIpList List of IP addresses to pre-approve |
|
| 46 | - * @param PdoDatabase $database |
|
| 47 | - */ |
|
| 48 | - public function __construct($squidIpList, PdoDatabase $database) |
|
| 49 | - { |
|
| 50 | - $this->trustedCache = $squidIpList; |
|
| 51 | - $this->database = $database; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Returns a value if the IP address is a trusted proxy |
|
| 56 | - * |
|
| 57 | - * @param string $ip |
|
| 58 | - * |
|
| 59 | - * @return bool |
|
| 60 | - */ |
|
| 61 | - public function isTrusted($ip) |
|
| 62 | - { |
|
| 63 | - if (in_array($ip, $this->trustedCache)) { |
|
| 64 | - return true; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - if (in_array($ip, $this->untrustedCache)) { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if ($this->trustedQuery === null) { |
|
| 72 | - $query = "SELECT COUNT(id) FROM xfftrustcache WHERE ip = :ip;"; |
|
| 73 | - $this->trustedQuery = $this->database->prepare($query); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $this->trustedQuery->execute(array(":ip" => $ip)); |
|
| 77 | - $result = $this->trustedQuery->fetchColumn(); |
|
| 78 | - $this->trustedQuery->closeCursor(); |
|
| 79 | - |
|
| 80 | - if ($result == 0) { |
|
| 81 | - $this->untrustedCache[] = $ip; |
|
| 82 | - |
|
| 83 | - return false; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if ($result >= 1) { |
|
| 87 | - $this->trustedCache[] = $ip; |
|
| 88 | - |
|
| 89 | - return true; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // something weird has happened if we've got here. |
|
| 93 | - // default to untrusted. |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Gets the last trusted IP in the proxy chain. |
|
| 99 | - * |
|
| 100 | - * @param string $ip The IP address from REMOTE_ADDR |
|
| 101 | - * @param string $proxyIp The contents of the XFF header. |
|
| 102 | - * |
|
| 103 | - * @return string Trusted source IP address |
|
| 104 | - */ |
|
| 105 | - public function getTrustedClientIp($ip, $proxyIp) |
|
| 106 | - { |
|
| 107 | - $clientIpAddress = $ip; |
|
| 108 | - if ($proxyIp) { |
|
| 109 | - $ipList = explode(",", $proxyIp); |
|
| 110 | - $ipList[] = $clientIpAddress; |
|
| 111 | - $ipList = array_reverse($ipList); |
|
| 112 | - |
|
| 113 | - foreach ($ipList as $ipNumber => $ipAddress) { |
|
| 114 | - if ($this->isTrusted(trim($ipAddress)) && $ipNumber < (count($ipList) - 1)) { |
|
| 115 | - continue; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $clientIpAddress = $ipAddress; |
|
| 119 | - break; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $clientIpAddress; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Takes an array( "low" => "high" ) values, and returns true if $needle is in at least one of them. |
|
| 128 | - * |
|
| 129 | - * @param array $haystack |
|
| 130 | - * @param string $ip |
|
| 131 | - * |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - public function ipInRange($haystack, $ip) |
|
| 135 | - { |
|
| 136 | - $needle = ip2long($ip); |
|
| 137 | - |
|
| 138 | - foreach ($haystack as $low => $high) { |
|
| 139 | - if (ip2long($low) <= $needle && ip2long($high) >= $needle) { |
|
| 140 | - return true; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return false; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Explodes a CIDR range into an array of addresses |
|
| 149 | - * |
|
| 150 | - * @param string $range A CIDR-format range |
|
| 151 | - * |
|
| 152 | - * @return array An array containing every IP address in the range |
|
| 153 | - */ |
|
| 154 | - public function explodeCidr($range) |
|
| 155 | - { |
|
| 156 | - $cidrData = explode('/', $range); |
|
| 157 | - |
|
| 158 | - if (!isset($cidrData[1])) { |
|
| 159 | - return array($range); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $blow = ( |
|
| 163 | - str_pad(decbin(ip2long($cidrData[0])), 32, "0", STR_PAD_LEFT) & |
|
| 164 | - str_pad(str_pad("", $cidrData[1], "1"), 32, "0") |
|
| 165 | - ); |
|
| 166 | - $bhigh = ($blow | str_pad(str_pad("", $cidrData[1], "0"), 32, "1")); |
|
| 167 | - |
|
| 168 | - $list = array(); |
|
| 169 | - |
|
| 170 | - $bindecBHigh = bindec($bhigh); |
|
| 171 | - for ($x = bindec($blow); $x <= $bindecBHigh; $x++) { |
|
| 172 | - $list[] = long2ip($x); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return $list; |
|
| 176 | - } |
|
| 25 | + /** |
|
| 26 | + * Array of IP addresses which are TRUSTED proxies |
|
| 27 | + * @var string[] |
|
| 28 | + */ |
|
| 29 | + private $trustedCache = array(); |
|
| 30 | + /** |
|
| 31 | + * Array of IP addresses which are UNTRUSTED proxies |
|
| 32 | + * @var string[] |
|
| 33 | + */ |
|
| 34 | + private $untrustedCache = array(); |
|
| 35 | + /** @var PDOStatement */ |
|
| 36 | + private $trustedQuery; |
|
| 37 | + /** |
|
| 38 | + * @var PdoDatabase |
|
| 39 | + */ |
|
| 40 | + private $database; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Creates a new instance of the trust provider |
|
| 44 | + * |
|
| 45 | + * @param string[] $squidIpList List of IP addresses to pre-approve |
|
| 46 | + * @param PdoDatabase $database |
|
| 47 | + */ |
|
| 48 | + public function __construct($squidIpList, PdoDatabase $database) |
|
| 49 | + { |
|
| 50 | + $this->trustedCache = $squidIpList; |
|
| 51 | + $this->database = $database; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Returns a value if the IP address is a trusted proxy |
|
| 56 | + * |
|
| 57 | + * @param string $ip |
|
| 58 | + * |
|
| 59 | + * @return bool |
|
| 60 | + */ |
|
| 61 | + public function isTrusted($ip) |
|
| 62 | + { |
|
| 63 | + if (in_array($ip, $this->trustedCache)) { |
|
| 64 | + return true; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + if (in_array($ip, $this->untrustedCache)) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if ($this->trustedQuery === null) { |
|
| 72 | + $query = "SELECT COUNT(id) FROM xfftrustcache WHERE ip = :ip;"; |
|
| 73 | + $this->trustedQuery = $this->database->prepare($query); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $this->trustedQuery->execute(array(":ip" => $ip)); |
|
| 77 | + $result = $this->trustedQuery->fetchColumn(); |
|
| 78 | + $this->trustedQuery->closeCursor(); |
|
| 79 | + |
|
| 80 | + if ($result == 0) { |
|
| 81 | + $this->untrustedCache[] = $ip; |
|
| 82 | + |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if ($result >= 1) { |
|
| 87 | + $this->trustedCache[] = $ip; |
|
| 88 | + |
|
| 89 | + return true; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // something weird has happened if we've got here. |
|
| 93 | + // default to untrusted. |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Gets the last trusted IP in the proxy chain. |
|
| 99 | + * |
|
| 100 | + * @param string $ip The IP address from REMOTE_ADDR |
|
| 101 | + * @param string $proxyIp The contents of the XFF header. |
|
| 102 | + * |
|
| 103 | + * @return string Trusted source IP address |
|
| 104 | + */ |
|
| 105 | + public function getTrustedClientIp($ip, $proxyIp) |
|
| 106 | + { |
|
| 107 | + $clientIpAddress = $ip; |
|
| 108 | + if ($proxyIp) { |
|
| 109 | + $ipList = explode(",", $proxyIp); |
|
| 110 | + $ipList[] = $clientIpAddress; |
|
| 111 | + $ipList = array_reverse($ipList); |
|
| 112 | + |
|
| 113 | + foreach ($ipList as $ipNumber => $ipAddress) { |
|
| 114 | + if ($this->isTrusted(trim($ipAddress)) && $ipNumber < (count($ipList) - 1)) { |
|
| 115 | + continue; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $clientIpAddress = $ipAddress; |
|
| 119 | + break; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $clientIpAddress; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Takes an array( "low" => "high" ) values, and returns true if $needle is in at least one of them. |
|
| 128 | + * |
|
| 129 | + * @param array $haystack |
|
| 130 | + * @param string $ip |
|
| 131 | + * |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + public function ipInRange($haystack, $ip) |
|
| 135 | + { |
|
| 136 | + $needle = ip2long($ip); |
|
| 137 | + |
|
| 138 | + foreach ($haystack as $low => $high) { |
|
| 139 | + if (ip2long($low) <= $needle && ip2long($high) >= $needle) { |
|
| 140 | + return true; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Explodes a CIDR range into an array of addresses |
|
| 149 | + * |
|
| 150 | + * @param string $range A CIDR-format range |
|
| 151 | + * |
|
| 152 | + * @return array An array containing every IP address in the range |
|
| 153 | + */ |
|
| 154 | + public function explodeCidr($range) |
|
| 155 | + { |
|
| 156 | + $cidrData = explode('/', $range); |
|
| 157 | + |
|
| 158 | + if (!isset($cidrData[1])) { |
|
| 159 | + return array($range); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $blow = ( |
|
| 163 | + str_pad(decbin(ip2long($cidrData[0])), 32, "0", STR_PAD_LEFT) & |
|
| 164 | + str_pad(str_pad("", $cidrData[1], "1"), 32, "0") |
|
| 165 | + ); |
|
| 166 | + $bhigh = ($blow | str_pad(str_pad("", $cidrData[1], "0"), 32, "1")); |
|
| 167 | + |
|
| 168 | + $list = array(); |
|
| 169 | + |
|
| 170 | + $bindecBHigh = bindec($bhigh); |
|
| 171 | + for ($x = bindec($blow); $x <= $bindecBHigh; $x++) { |
|
| 172 | + $list[] = long2ip($x); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return $list; |
|
| 176 | + } |
|
| 177 | 177 | } |
@@ -20,40 +20,40 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class CachedRDnsLookupProvider implements IRDnsProvider |
| 22 | 22 | { |
| 23 | - private $database; |
|
| 23 | + private $database; |
|
| 24 | 24 | |
| 25 | - public function __construct(PdoDatabase $database) |
|
| 26 | - { |
|
| 27 | - $this->database = $database; |
|
| 28 | - } |
|
| 25 | + public function __construct(PdoDatabase $database) |
|
| 26 | + { |
|
| 27 | + $this->database = $database; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function getReverseDNS($address) |
|
| 31 | - { |
|
| 32 | - $address = trim($address); |
|
| 30 | + public function getReverseDNS($address) |
|
| 31 | + { |
|
| 32 | + $address = trim($address); |
|
| 33 | 33 | |
| 34 | - // lets look in our cache database first. |
|
| 35 | - $rDns = RDnsCache::getByAddress($address, $this->database); |
|
| 34 | + // lets look in our cache database first. |
|
| 35 | + $rDns = RDnsCache::getByAddress($address, $this->database); |
|
| 36 | 36 | |
| 37 | - if ($rDns instanceof RDnsCache) { |
|
| 38 | - // touch cache timer |
|
| 39 | - $rDns->save(); |
|
| 37 | + if ($rDns instanceof RDnsCache) { |
|
| 38 | + // touch cache timer |
|
| 39 | + $rDns->save(); |
|
| 40 | 40 | |
| 41 | - return $rDns->getData(); |
|
| 42 | - } |
|
| 41 | + return $rDns->getData(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // OK, it's not there, let's do an rDNS lookup. |
|
| 45 | - $result = @ gethostbyaddr($address); |
|
| 44 | + // OK, it's not there, let's do an rDNS lookup. |
|
| 45 | + $result = @ gethostbyaddr($address); |
|
| 46 | 46 | |
| 47 | - if ($result !== false) { |
|
| 48 | - $rDns = new RDnsCache(); |
|
| 49 | - $rDns->setDatabase($this->database); |
|
| 50 | - $rDns->setAddress($address); |
|
| 51 | - $rDns->setData($result); |
|
| 52 | - $rDns->save(); |
|
| 47 | + if ($result !== false) { |
|
| 48 | + $rDns = new RDnsCache(); |
|
| 49 | + $rDns->setDatabase($this->database); |
|
| 50 | + $rDns->setAddress($address); |
|
| 51 | + $rDns->setData($result); |
|
| 52 | + $rDns->save(); |
|
| 53 | 53 | |
| 54 | - return $result; |
|
| 55 | - } |
|
| 54 | + return $result; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - return null; |
|
| 58 | - } |
|
| 57 | + return null; |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -18,35 +18,35 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class GlobalStateProvider implements IGlobalStateProvider |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public function &getServerSuperGlobal() |
|
| 25 | - { |
|
| 26 | - return $_SERVER; |
|
| 27 | - } |
|
| 21 | + /** |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public function &getServerSuperGlobal() |
|
| 25 | + { |
|
| 26 | + return $_SERVER; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - public function &getGetSuperGlobal() |
|
| 33 | - { |
|
| 34 | - return $_GET; |
|
| 35 | - } |
|
| 29 | + /** |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + public function &getGetSuperGlobal() |
|
| 33 | + { |
|
| 34 | + return $_GET; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @return array |
|
| 39 | - */ |
|
| 40 | - public function &getPostSuperGlobal() |
|
| 41 | - { |
|
| 42 | - return $_POST; |
|
| 43 | - } |
|
| 37 | + /** |
|
| 38 | + * @return array |
|
| 39 | + */ |
|
| 40 | + public function &getPostSuperGlobal() |
|
| 41 | + { |
|
| 42 | + return $_POST; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 48 | - public function &getSessionSuperGlobal() |
|
| 49 | - { |
|
| 50 | - return $_SESSION; |
|
| 51 | - } |
|
| 45 | + /** |
|
| 46 | + * @return array |
|
| 47 | + */ |
|
| 48 | + public function &getSessionSuperGlobal() |
|
| 49 | + { |
|
| 50 | + return $_SESSION; |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |