loggingaggregator.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * This test class pretends to be an RSS aggregator. It logs notifications
  18. * from the cloud.
  19. *
  20. * @category Plugin
  21. * @package GNUsocial
  22. * @author Zach Copley <zach@status.net>
  23. * @copyright 2009 StatusNet, Inc.
  24. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  25. */
  26. defined('GNUSOCIAL') || die();
  27. /**
  28. * Dummy aggregator that acts as a proper notification handler. It
  29. * doesn't do anything but respond correctly when notified via
  30. * REST. Mostly, this is just and action I used to develop the plugin
  31. * and easily test things end-to-end. I'm leaving it in here as it
  32. * may be useful for developing the plugin further.
  33. *
  34. * @category Plugin
  35. * @package GNUsocial
  36. * @author Zach Copley <zach@status.net>
  37. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  38. */
  39. class LoggingAggregatorAction extends Action
  40. {
  41. public $challenge = null;
  42. public $url = null;
  43. /**
  44. * Initialization.
  45. *
  46. * @param array $args Web and URL arguments
  47. *
  48. * @return boolean false if user doesn't exist
  49. */
  50. public function prepare(array $args = [])
  51. {
  52. parent::prepare($args);
  53. $this->url = $this->arg('url');
  54. $this->challenge = $this->arg('challenge');
  55. common_debug("args = " . var_export($this->args, true));
  56. common_debug('url = ' . $this->url . ' challenge = ' . $this->challenge);
  57. return true;
  58. }
  59. /**
  60. * Handle the request
  61. *
  62. * @param array $args $_REQUEST data (unused)
  63. *
  64. * @return void
  65. */
  66. public function handle()
  67. {
  68. parent::handle();
  69. if (empty($this->url)) {
  70. // TRANS: Form validation error displayed when a URL parameter is missing.
  71. $this->showError(_m('A URL parameter is required.'));
  72. return;
  73. }
  74. if (!empty($this->challenge)) {
  75. // must be a GET
  76. if ($_SERVER['REQUEST_METHOD'] != 'GET') {
  77. // TRANS: Form validation error displayed when HTTP GET is not used.
  78. $this->showError(_m('This resource requires an HTTP GET.'));
  79. return;
  80. }
  81. header('Content-Type: text/xml');
  82. echo $this->challenge;
  83. } else {
  84. // must be a POST
  85. if ($_SERVER['REQUEST_METHOD'] != 'POST') {
  86. // TRANS: Form validation error displayed when HTTP POST is not used.
  87. $this->showError(_m('This resource requires an HTTP POST.'));
  88. return;
  89. }
  90. header('Content-Type: text/xml');
  91. echo "<notifyResult success='true' msg='Thanks for the update.' />\n";
  92. }
  93. $this->ip = $_SERVER['REMOTE_ADDR'];
  94. common_log(LOG_INFO, 'RSSCloud Logging Aggregator - ' .
  95. $this->ip . ' claims the feed at ' .
  96. $this->url . ' has been updated.');
  97. }
  98. /**
  99. * Show an XML error when things go badly
  100. *
  101. * @param string $msg the error message
  102. *
  103. * @return void
  104. */
  105. public function showError($msg)
  106. {
  107. http_response_code(400);
  108. header('Content-Type: text/xml');
  109. echo "<?xml version='1.0'?>\n";
  110. echo "<notifyResult success='false' msg='$msg' />\n";
  111. }
  112. }