diff options
| author | 2017-12-17 20:28:04 +0100 | |
|---|---|---|
| committer | 2017-12-17 20:28:04 +0100 | |
| commit | 60f56539c3f30fd3f7ba4f2a3570f7029ac93e5f (patch) | |
| tree | 1e78bfac7042dceb63898e2215db8fb0c1d7745d /p/api/pshb.php | |
| parent | ceda55c75b158fc1cf4813fe0f258527754b9289 (diff) | |
| parent | 0b1516af91792f86868689392f72ad4b6e32cdcf (diff) | |
Merge pull request #1720 from FreshRSS/dev
FreshRSS 1.9.0
Diffstat (limited to 'p/api/pshb.php')
| -rw-r--r-- | p/api/pshb.php | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/p/api/pshb.php b/p/api/pshb.php index ed8326cf5..57a7bb0dd 100644 --- a/p/api/pshb.php +++ b/p/api/pshb.php @@ -1,19 +1,19 @@ <?php -require('../../constants.php'); +require(__DIR__ . '/../../constants.php'); require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader -define('MAX_PAYLOAD', 3145728); +const MAX_PAYLOAD = 3145728; header('Content-Type: text/plain; charset=UTF-8'); header('X-Content-Type-Options: nosniff'); -function logMe($text) { - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); -} - $ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, MAX_PAYLOAD); -//logMe(print_r(array('_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, 'INPUT' => $ORIGINAL_INPUT), true)); +Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); +$system_conf = Minz_Configuration::get('system'); +$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!) + +//Minz_Log::debug(print_r(array('_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, 'INPUT' => $ORIGINAL_INPUT), true), PSHB_LOG); $key = isset($_GET['k']) ? substr($_GET['k'], 0, 128) : ''; if (!ctype_xdigit($key)) { @@ -24,31 +24,31 @@ chdir(PSHB_PATH); $canonical64 = @file_get_contents('keys/' . $key . '.txt'); if ($canonical64 === false) { if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] === 'unsubscribe') { - logMe('Warning: Accept unknown unsubscribe'); + Minz_Log::warning('Warning: Accept unknown unsubscribe', PSHB_LOG); header('Connection: close'); exit(isset($_REQUEST['hub_challenge']) ? $_REQUEST['hub_challenge'] : ''); } header('HTTP/1.1 404 Not Found'); - logMe('Warning: Feed key not found!: ' . $key); + Minz_Log::warning('Warning: Feed key not found!: ' . $key, PSHB_LOG); die('Feed key not found!'); } $canonical64 = trim($canonical64); if (!preg_match('/^[A-Za-z0-9_-]+$/D', $canonical64)) { header('HTTP/1.1 500 Internal Server Error'); - logMe('Error: Invalid key reference!: ' . $canonical64); + Minz_Log::error('Error: Invalid key reference!: ' . $canonical64, PSHB_LOG); die('Invalid key reference!'); } $hubFile = @file_get_contents('feeds/' . $canonical64 . '/!hub.json'); if ($hubFile === false) { header('HTTP/1.1 404 Not Found'); unlink('keys/' . $key . '.txt'); - logMe('Error: Feed info not found!: ' . $canonical64); + Minz_Log::error('Error: Feed info not found!: ' . $canonical64, PSHB_LOG); die('Feed info not found!'); } $hubJson = json_decode($hubFile, true); if (!$hubJson || empty($hubJson['key']) || $hubJson['key'] !== $key) { header('HTTP/1.1 500 Internal Server Error'); - logMe('Error: Invalid key cross-check!: ' . $key); + Minz_Log::error('Error: Invalid key cross-check!: ' . $key, PSHB_LOG); die('Invalid key cross-check!'); } chdir('feeds/' . $canonical64); @@ -56,7 +56,7 @@ $users = glob('*.txt', GLOB_NOSORT); if (empty($users)) { header('HTTP/1.1 410 Gone'); $url = base64url_decode($canonical64); - logMe('Warning: Nobody subscribes to this feed anymore!: ' . $url); + Minz_Log::warning('Warning: Nobody subscribes to this feed anymore!: ' . $url, PSHB_LOG); unlink('../../keys/' . $key . '.txt'); Minz_Configuration::register('system', DATA_PATH . '/config.php', @@ -101,10 +101,6 @@ if ($ORIGINAL_INPUT == '') { die('Missing XML payload!'); } -Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); -$system_conf = Minz_Configuration::get('system'); -$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!) - $simplePie = customSimplePie(); $simplePie->set_raw_data($ORIGINAL_INPUT); $simplePie->init(); @@ -115,7 +111,7 @@ $self = isset($links[0]) ? $links[0] : null; if ($self !== base64url_decode($canonical64)) { //header('HTTP/1.1 422 Unprocessable Entity'); - logMe('Warning: Self URL [' . $self . '] does not match registered canonical URL!: ' . base64url_decode($canonical64)); + Minz_Log::warning('Warning: Self URL [' . $self . '] does not match registered canonical URL!: ' . base64url_decode($canonical64), PSHB_LOG); //die('Self URL does not match registered canonical URL!'); $self = base64url_decode($canonical64); } @@ -124,7 +120,7 @@ $nb = 0; foreach ($users as $userFilename) { $username = basename($userFilename, '.txt'); if (!file_exists(USERS_PATH . '/' . $username . '/config.php')) { - logMe('Warning: Removing broken user link: ' . $username . ' for ' . $self); + Minz_Log::warning('Warning: Removing broken user link: ' . $username . ' for ' . $self, PSHB_LOG); unlink($userFilename); continue; } @@ -140,11 +136,11 @@ foreach ($users as $userFilename) { if ($updated_feeds > 0 || $feed != false) { $nb++; } else { - logMe('Warning: User ' . $username . ' does not subscribe anymore to ' . $self); + Minz_Log::warning('Warning: User ' . $username . ' does not subscribe anymore to ' . $self, PSHB_LOG); unlink($userFilename); } } catch (Exception $e) { - logMe('Error: ' . $e->getMessage() . ' for user ' . $username . ' and feed ' . $self); + Minz_Log::error('Error: ' . $e->getMessage() . ' for user ' . $username . ' and feed ' . $self, PSHB_LOG); } } @@ -153,12 +149,12 @@ unset($simplePie); if ($nb === 0) { header('HTTP/1.1 410 Gone'); - logMe('Warning: Nobody subscribes to this feed anymore after all!: ' . $self); + Minz_Log::warning('Warning: Nobody subscribes to this feed anymore after all!: ' . $self, PSHB_LOG); die('Nobody subscribes to this feed anymore after all!'); } elseif (!empty($hubJson['error'])) { $hubJson['error'] = false; file_put_contents('./!hub.json', json_encode($hubJson)); } -logMe('PubSubHubbub ' . $self . ' done: ' . $nb); +Minz_Log::notice('PubSubHubbub ' . $self . ' done: ' . $nb, PSHB_LOG); exit('Done: ' . $nb . "\n"); |
