@@ -21,141 +21,141 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class SessionAlert |
| 23 | 23 | { |
| 24 | - private $message; |
|
| 25 | - private $title; |
|
| 26 | - private $type; |
|
| 27 | - private $closable; |
|
| 28 | - private $block; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @param string $message |
|
| 32 | - * @param string $title |
|
| 33 | - * @param string $type |
|
| 34 | - * @param bool $closable |
|
| 35 | - * @param bool $block |
|
| 36 | - */ |
|
| 37 | - public function __construct($message, $title, $type = "alert-info", $closable = true, $block = true) |
|
| 38 | - { |
|
| 39 | - $this->message = $message; |
|
| 40 | - $this->title = $title; |
|
| 41 | - $this->type = $type; |
|
| 42 | - $this->closable = $closable; |
|
| 43 | - $this->block = $block; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Shows a quick one-liner message |
|
| 48 | - * |
|
| 49 | - * @param string $message |
|
| 50 | - * @param string $type |
|
| 51 | - */ |
|
| 52 | - public static function quick($message, $type = "alert-info") |
|
| 53 | - { |
|
| 54 | - self::append(new SessionAlert($message, "", $type, true, false)); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param SessionAlert $alert |
|
| 59 | - */ |
|
| 60 | - public static function append(SessionAlert $alert) |
|
| 61 | - { |
|
| 62 | - $data = WebRequest::getSessionAlertData(); |
|
| 63 | - $data[] = serialize($alert); |
|
| 64 | - WebRequest::setSessionAlertData($data); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Shows a quick one-liner success message |
|
| 69 | - * |
|
| 70 | - * @param string $message |
|
| 71 | - */ |
|
| 72 | - public static function success($message) |
|
| 73 | - { |
|
| 74 | - self::append(new SessionAlert($message, "", "alert-success", true, true)); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Shows a quick one-liner warning message |
|
| 79 | - * |
|
| 80 | - * @param string $message |
|
| 81 | - * @param string $title |
|
| 82 | - */ |
|
| 83 | - public static function warning($message, $title = "Warning!") |
|
| 84 | - { |
|
| 85 | - self::append(new SessionAlert($message, $title, "alert-warning", true, true)); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Shows a quick one-liner error message |
|
| 90 | - * |
|
| 91 | - * @param string $message |
|
| 92 | - * @param string $title |
|
| 93 | - */ |
|
| 94 | - public static function error($message, $title = "Error!") |
|
| 95 | - { |
|
| 96 | - self::append(new SessionAlert($message, $title, "alert-error", true, true)); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Retrieves the alerts which have been saved to the session |
|
| 101 | - * @return array |
|
| 102 | - */ |
|
| 103 | - public static function getAlerts() |
|
| 104 | - { |
|
| 105 | - $alertData = array(); |
|
| 106 | - |
|
| 107 | - foreach (WebRequest::getSessionAlertData() as $a) { |
|
| 108 | - $alertData[] = unserialize($a); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $alertData; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Clears the alerts from the session |
|
| 116 | - */ |
|
| 117 | - public static function clearAlerts() |
|
| 118 | - { |
|
| 119 | - WebRequest::clearSessionAlertData(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return boolean |
|
| 124 | - */ |
|
| 125 | - public function isBlock() |
|
| 126 | - { |
|
| 127 | - return $this->block; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return boolean |
|
| 132 | - */ |
|
| 133 | - public function isClosable() |
|
| 134 | - { |
|
| 135 | - return $this->closable; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - public function getType() |
|
| 142 | - { |
|
| 143 | - return $this->type; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return string |
|
| 148 | - */ |
|
| 149 | - public function getTitle() |
|
| 150 | - { |
|
| 151 | - return $this->title; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function getMessage() |
|
| 158 | - { |
|
| 159 | - return $this->message; |
|
| 160 | - } |
|
| 24 | + private $message; |
|
| 25 | + private $title; |
|
| 26 | + private $type; |
|
| 27 | + private $closable; |
|
| 28 | + private $block; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @param string $message |
|
| 32 | + * @param string $title |
|
| 33 | + * @param string $type |
|
| 34 | + * @param bool $closable |
|
| 35 | + * @param bool $block |
|
| 36 | + */ |
|
| 37 | + public function __construct($message, $title, $type = "alert-info", $closable = true, $block = true) |
|
| 38 | + { |
|
| 39 | + $this->message = $message; |
|
| 40 | + $this->title = $title; |
|
| 41 | + $this->type = $type; |
|
| 42 | + $this->closable = $closable; |
|
| 43 | + $this->block = $block; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Shows a quick one-liner message |
|
| 48 | + * |
|
| 49 | + * @param string $message |
|
| 50 | + * @param string $type |
|
| 51 | + */ |
|
| 52 | + public static function quick($message, $type = "alert-info") |
|
| 53 | + { |
|
| 54 | + self::append(new SessionAlert($message, "", $type, true, false)); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param SessionAlert $alert |
|
| 59 | + */ |
|
| 60 | + public static function append(SessionAlert $alert) |
|
| 61 | + { |
|
| 62 | + $data = WebRequest::getSessionAlertData(); |
|
| 63 | + $data[] = serialize($alert); |
|
| 64 | + WebRequest::setSessionAlertData($data); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Shows a quick one-liner success message |
|
| 69 | + * |
|
| 70 | + * @param string $message |
|
| 71 | + */ |
|
| 72 | + public static function success($message) |
|
| 73 | + { |
|
| 74 | + self::append(new SessionAlert($message, "", "alert-success", true, true)); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Shows a quick one-liner warning message |
|
| 79 | + * |
|
| 80 | + * @param string $message |
|
| 81 | + * @param string $title |
|
| 82 | + */ |
|
| 83 | + public static function warning($message, $title = "Warning!") |
|
| 84 | + { |
|
| 85 | + self::append(new SessionAlert($message, $title, "alert-warning", true, true)); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Shows a quick one-liner error message |
|
| 90 | + * |
|
| 91 | + * @param string $message |
|
| 92 | + * @param string $title |
|
| 93 | + */ |
|
| 94 | + public static function error($message, $title = "Error!") |
|
| 95 | + { |
|
| 96 | + self::append(new SessionAlert($message, $title, "alert-error", true, true)); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Retrieves the alerts which have been saved to the session |
|
| 101 | + * @return array |
|
| 102 | + */ |
|
| 103 | + public static function getAlerts() |
|
| 104 | + { |
|
| 105 | + $alertData = array(); |
|
| 106 | + |
|
| 107 | + foreach (WebRequest::getSessionAlertData() as $a) { |
|
| 108 | + $alertData[] = unserialize($a); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $alertData; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Clears the alerts from the session |
|
| 116 | + */ |
|
| 117 | + public static function clearAlerts() |
|
| 118 | + { |
|
| 119 | + WebRequest::clearSessionAlertData(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return boolean |
|
| 124 | + */ |
|
| 125 | + public function isBlock() |
|
| 126 | + { |
|
| 127 | + return $this->block; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return boolean |
|
| 132 | + */ |
|
| 133 | + public function isClosable() |
|
| 134 | + { |
|
| 135 | + return $this->closable; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + public function getType() |
|
| 142 | + { |
|
| 143 | + return $this->type; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return string |
|
| 148 | + */ |
|
| 149 | + public function getTitle() |
|
| 150 | + { |
|
| 151 | + return $this->title; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function getMessage() |
|
| 158 | + { |
|
| 159 | + return $this->message; |
|
| 160 | + } |
|
| 161 | 161 | } |
@@ -17,17 +17,17 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | interface IApiAction extends IRoutedTask |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Method that runs API action |
|
| 22 | - * |
|
| 23 | - * @param DOMElement $apiDocument |
|
| 24 | - * |
|
| 25 | - * @return DOMElement The modified API document |
|
| 26 | - */ |
|
| 27 | - public function executeApiAction(DOMElement $apiDocument); |
|
| 20 | + /** |
|
| 21 | + * Method that runs API action |
|
| 22 | + * |
|
| 23 | + * @param DOMElement $apiDocument |
|
| 24 | + * |
|
| 25 | + * @return DOMElement The modified API document |
|
| 26 | + */ |
|
| 27 | + public function executeApiAction(DOMElement $apiDocument); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return string the XML, or false if an error occurred. |
|
| 31 | - */ |
|
| 32 | - public function runApiPage(); |
|
| 29 | + /** |
|
| 30 | + * @return string the XML, or false if an error occurred. |
|
| 31 | + */ |
|
| 32 | + public function runApiPage(); |
|
| 33 | 33 | } |
@@ -18,34 +18,34 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class HelpAction extends ApiPageBase implements IApiAction |
| 20 | 20 | { |
| 21 | - public function executeApiAction(DOMElement $apiDocument) |
|
| 22 | - { |
|
| 23 | - $helpElement = $this->getHelpElement(); |
|
| 24 | - $apiDocument->appendChild($helpElement); |
|
| 25 | - |
|
| 26 | - return $apiDocument; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Gets the help information |
|
| 31 | - * @return DOMElement |
|
| 32 | - */ |
|
| 33 | - protected function getHelpElement() |
|
| 34 | - { |
|
| 35 | - $helpInfo = "Help info goes here!"; |
|
| 36 | - |
|
| 37 | - $help = $this->document->createElement("help"); |
|
| 38 | - $helptext = $this->document->createElement("info", $helpInfo); |
|
| 39 | - $helpactions = $this->document->createElement("actions"); |
|
| 40 | - |
|
| 41 | - foreach (ApiRequestRouter::getActionList() as $action) { |
|
| 42 | - $actionElement = $this->document->createElement("action", $action); |
|
| 43 | - $helpactions->appendChild($actionElement); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $help->appendChild($helptext); |
|
| 47 | - $help->appendChild($helpactions); |
|
| 48 | - |
|
| 49 | - return $help; |
|
| 50 | - } |
|
| 21 | + public function executeApiAction(DOMElement $apiDocument) |
|
| 22 | + { |
|
| 23 | + $helpElement = $this->getHelpElement(); |
|
| 24 | + $apiDocument->appendChild($helpElement); |
|
| 25 | + |
|
| 26 | + return $apiDocument; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Gets the help information |
|
| 31 | + * @return DOMElement |
|
| 32 | + */ |
|
| 33 | + protected function getHelpElement() |
|
| 34 | + { |
|
| 35 | + $helpInfo = "Help info goes here!"; |
|
| 36 | + |
|
| 37 | + $help = $this->document->createElement("help"); |
|
| 38 | + $helptext = $this->document->createElement("info", $helpInfo); |
|
| 39 | + $helpactions = $this->document->createElement("actions"); |
|
| 40 | + |
|
| 41 | + foreach (ApiRequestRouter::getActionList() as $action) { |
|
| 42 | + $actionElement = $this->document->createElement("action", $action); |
|
| 43 | + $helpactions->appendChild($actionElement); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $help->appendChild($helptext); |
|
| 47 | + $help->appendChild($helpactions); |
|
| 48 | + |
|
| 49 | + return $help; |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -17,67 +17,67 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class StatusAction extends ApiPageBase implements IApiAction |
| 19 | 19 | { |
| 20 | - public function executeApiAction(DOMElement $apiDocument) |
|
| 21 | - { |
|
| 22 | - $statusElement = $this->document->createElement("status"); |
|
| 23 | - $apiDocument->appendChild($statusElement); |
|
| 20 | + public function executeApiAction(DOMElement $apiDocument) |
|
| 21 | + { |
|
| 22 | + $statusElement = $this->document->createElement("status"); |
|
| 23 | + $apiDocument->appendChild($statusElement); |
|
| 24 | 24 | |
| 25 | - $query = $this->getDatabase()->prepare(<<<SQL |
|
| 25 | + $query = $this->getDatabase()->prepare(<<<SQL |
|
| 26 | 26 | SELECT /* Api/StatusAction */ COUNT(*) AS count |
| 27 | 27 | FROM request |
| 28 | 28 | WHERE |
| 29 | 29 | status = :pstatus |
| 30 | 30 | AND emailconfirm = 'Confirmed'; |
| 31 | 31 | SQL |
| 32 | - ); |
|
| 32 | + ); |
|
| 33 | 33 | |
| 34 | - $availableRequestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 34 | + $availableRequestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 35 | 35 | |
| 36 | - foreach ($availableRequestStates as $key => $value) { |
|
| 37 | - $query->bindValue(":pstatus", $key); |
|
| 38 | - $query->execute(); |
|
| 39 | - $sus = $query->fetchColumn(); |
|
| 40 | - $statusElement->setAttribute($value['api'], $sus); |
|
| 41 | - $query->closeCursor(); |
|
| 42 | - } |
|
| 36 | + foreach ($availableRequestStates as $key => $value) { |
|
| 37 | + $query->bindValue(":pstatus", $key); |
|
| 38 | + $query->execute(); |
|
| 39 | + $sus = $query->fetchColumn(); |
|
| 40 | + $statusElement->setAttribute($value['api'], $sus); |
|
| 41 | + $query->closeCursor(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $query = $this->getDatabase()->prepare(<<<SQL |
|
| 44 | + $query = $this->getDatabase()->prepare(<<<SQL |
|
| 45 | 45 | SELECT /* Api/StatusAction */ COUNT(*) AS count |
| 46 | 46 | FROM ban |
| 47 | 47 | WHERE |
| 48 | 48 | (duration > UNIX_TIMESTAMP() OR duration = -1) |
| 49 | 49 | AND active = 1; |
| 50 | 50 | SQL |
| 51 | - ); |
|
| 51 | + ); |
|
| 52 | 52 | |
| 53 | - $query->execute(); |
|
| 54 | - $sus = $query->fetchColumn(); |
|
| 55 | - $statusElement->setAttribute("bans", $sus); |
|
| 56 | - $query->closeCursor(); |
|
| 53 | + $query->execute(); |
|
| 54 | + $sus = $query->fetchColumn(); |
|
| 55 | + $statusElement->setAttribute("bans", $sus); |
|
| 56 | + $query->closeCursor(); |
|
| 57 | 57 | |
| 58 | - $query = $this->getDatabase()->prepare(<<<SQL |
|
| 58 | + $query = $this->getDatabase()->prepare(<<<SQL |
|
| 59 | 59 | SELECT /* Api/StatusAction */ COUNT(*) AS count |
| 60 | 60 | FROM user WHERE status = :ulevel; |
| 61 | 61 | SQL |
| 62 | - ); |
|
| 63 | - $query->bindValue(":ulevel", "Admin"); |
|
| 64 | - $query->execute(); |
|
| 65 | - $sus = $query->fetchColumn(); |
|
| 66 | - $statusElement->setAttribute("useradmin", $sus); |
|
| 67 | - $query->closeCursor(); |
|
| 62 | + ); |
|
| 63 | + $query->bindValue(":ulevel", "Admin"); |
|
| 64 | + $query->execute(); |
|
| 65 | + $sus = $query->fetchColumn(); |
|
| 66 | + $statusElement->setAttribute("useradmin", $sus); |
|
| 67 | + $query->closeCursor(); |
|
| 68 | 68 | |
| 69 | - $query->bindValue(":ulevel", "User"); |
|
| 70 | - $query->execute(); |
|
| 71 | - $sus = $query->fetchColumn(); |
|
| 72 | - $statusElement->setAttribute("user", $sus); |
|
| 73 | - $query->closeCursor(); |
|
| 69 | + $query->bindValue(":ulevel", "User"); |
|
| 70 | + $query->execute(); |
|
| 71 | + $sus = $query->fetchColumn(); |
|
| 72 | + $statusElement->setAttribute("user", $sus); |
|
| 73 | + $query->closeCursor(); |
|
| 74 | 74 | |
| 75 | - $query->bindValue(":ulevel", "New"); |
|
| 76 | - $query->execute(); |
|
| 77 | - $sus = $query->fetchColumn(); |
|
| 78 | - $statusElement->setAttribute("usernew", $sus); |
|
| 79 | - $query->closeCursor(); |
|
| 75 | + $query->bindValue(":ulevel", "New"); |
|
| 76 | + $query->execute(); |
|
| 77 | + $sus = $query->fetchColumn(); |
|
| 78 | + $statusElement->setAttribute("usernew", $sus); |
|
| 79 | + $query->closeCursor(); |
|
| 80 | 80 | |
| 81 | - return $apiDocument; |
|
| 82 | - } |
|
| 81 | + return $apiDocument; |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -23,65 +23,65 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class MonitorAction extends ApiPageBase implements IApiAction |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @param DOMElement $apiDocument |
|
| 28 | - * |
|
| 29 | - * @return DOMElement |
|
| 30 | - */ |
|
| 31 | - public function executeApiAction(DOMElement $apiDocument) |
|
| 32 | - { |
|
| 33 | - $now = new DateTime(); |
|
| 26 | + /** |
|
| 27 | + * @param DOMElement $apiDocument |
|
| 28 | + * |
|
| 29 | + * @return DOMElement |
|
| 30 | + */ |
|
| 31 | + public function executeApiAction(DOMElement $apiDocument) |
|
| 32 | + { |
|
| 33 | + $now = new DateTime(); |
|
| 34 | 34 | |
| 35 | - $old = $this->getOldest(); |
|
| 36 | - $oldest = new DateTime($old); |
|
| 35 | + $old = $this->getOldest(); |
|
| 36 | + $oldest = new DateTime($old); |
|
| 37 | 37 | |
| 38 | - $new = $this->getNewest(); |
|
| 39 | - $newest = new DateTime($new); |
|
| 38 | + $new = $this->getNewest(); |
|
| 39 | + $newest = new DateTime($new); |
|
| 40 | 40 | |
| 41 | - $monitoringElement = $this->document->createElement("data"); |
|
| 42 | - $monitoringElement->setAttribute("date", $now->format('c')); |
|
| 43 | - $monitoringElement->setAttribute("oldest", $old === null ? null : $oldest->format('c')); |
|
| 44 | - $monitoringElement->setAttribute("newest", $new === null ? null : $newest->format('c')); |
|
| 45 | - $apiDocument->appendChild($monitoringElement); |
|
| 41 | + $monitoringElement = $this->document->createElement("data"); |
|
| 42 | + $monitoringElement->setAttribute("date", $now->format('c')); |
|
| 43 | + $monitoringElement->setAttribute("oldest", $old === null ? null : $oldest->format('c')); |
|
| 44 | + $monitoringElement->setAttribute("newest", $new === null ? null : $newest->format('c')); |
|
| 45 | + $apiDocument->appendChild($monitoringElement); |
|
| 46 | 46 | |
| 47 | - return $apiDocument; |
|
| 48 | - } |
|
| 47 | + return $apiDocument; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @return string|null |
|
| 52 | - */ |
|
| 53 | - private function getOldest() |
|
| 54 | - { |
|
| 55 | - $statement = $this->getDatabase() |
|
| 56 | - ->prepare("SELECT min(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
| 57 | - $successful = $statement->execute(array( |
|
| 58 | - ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
| 59 | - ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
| 60 | - )); |
|
| 50 | + /** |
|
| 51 | + * @return string|null |
|
| 52 | + */ |
|
| 53 | + private function getOldest() |
|
| 54 | + { |
|
| 55 | + $statement = $this->getDatabase() |
|
| 56 | + ->prepare("SELECT min(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
| 57 | + $successful = $statement->execute(array( |
|
| 58 | + ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
| 59 | + ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
| 60 | + )); |
|
| 61 | 61 | |
| 62 | - if (!$successful) { |
|
| 63 | - return null; |
|
| 64 | - } |
|
| 62 | + if (!$successful) { |
|
| 63 | + return null; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $result = $statement->fetchColumn(); |
|
| 66 | + $result = $statement->fetchColumn(); |
|
| 67 | 67 | |
| 68 | - return $result; |
|
| 69 | - } |
|
| 68 | + return $result; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - private function getNewest() |
|
| 75 | - { |
|
| 76 | - $statement = $this->getDatabase() |
|
| 77 | - ->prepare("SELECT max(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
| 78 | - $statement->execute(array( |
|
| 79 | - ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
| 80 | - ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
| 81 | - )); |
|
| 71 | + /** |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + private function getNewest() |
|
| 75 | + { |
|
| 76 | + $statement = $this->getDatabase() |
|
| 77 | + ->prepare("SELECT max(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
| 78 | + $statement->execute(array( |
|
| 79 | + ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
| 80 | + ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
| 81 | + )); |
|
| 82 | 82 | |
| 83 | - $result = $statement->fetchColumn(0); |
|
| 83 | + $result = $statement->fetchColumn(0); |
|
| 84 | 84 | |
| 85 | - return $result; |
|
| 86 | - } |
|
| 85 | + return $result; |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class UnknownAction extends HelpAction implements IApiAction |
| 18 | 18 | { |
| 19 | - public function executeApiAction(DOMElement $apiDocument) |
|
| 20 | - { |
|
| 21 | - $errorText = "Unknown API action specified."; |
|
| 22 | - $errorNode = $this->document->createElement("error", $errorText); |
|
| 23 | - $apiDocument->appendChild($errorNode); |
|
| 19 | + public function executeApiAction(DOMElement $apiDocument) |
|
| 20 | + { |
|
| 21 | + $errorText = "Unknown API action specified."; |
|
| 22 | + $errorNode = $this->document->createElement("error", $errorText); |
|
| 23 | + $apiDocument->appendChild($errorNode); |
|
| 24 | 24 | |
| 25 | - $helpElement = $this->getHelpElement(); |
|
| 26 | - $apiDocument->appendChild($helpElement); |
|
| 25 | + $helpElement = $this->getHelpElement(); |
|
| 26 | + $apiDocument->appendChild($helpElement); |
|
| 27 | 27 | |
| 28 | - return $apiDocument; |
|
| 29 | - } |
|
| 28 | + return $apiDocument; |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -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 | } |
@@ -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 | } |