Commit 43252b26 authored by Malcolm Blaney's avatar Malcolm Blaney

Reader->PurgeCache wasn't working because there weren't any image

files listed in the first 100 files. Fixed by also piping output
through grep. Made some formatting changes to micropub and microsub
endpoints but no real updates. Added a flag in user.php so that
admin can still log in as other users and not modify their last
visit timestamp.
parent f745e7b8
Pipeline #38031226 passed with stage
in 1 minute and 10 seconds
......@@ -1192,7 +1192,7 @@ class Reader extends Base {
}
$mysqli->close();
if ($xml_url_query === '') {
return ['content' => '', 'more' => false];
return $microsub ? [] : ['content' => '', 'more' => false];
}
$key = $this->owner . '-' . $this->user->page;
......@@ -1637,22 +1637,22 @@ class Reader extends Base {
// Convert $count to bytes to match strlen result.
$count *= 1000000;
$handle = popen('/bin/ls -1ur ' . $cache_dir .
' | /usr/bin/head -n 100', 'r');
while ($file = trim(fgets($handle))) {
// Only match image files in the cache. Note that *.spi can't be used
// above as a filter because it creates too many arguments. Also if the
// loop is broken while there is still data to read, then pclose() will
// report a broken pipe, so pipe through head to limit results and
// continue reading even though total has been reached.
if ($total > $count || strpos($file, '.spi') === false) continue;
$image = unserialize(file_get_contents($cache_dir . '/' . $file));
' | /bin/grep spi | /usr/bin/head -n 1000', 'r');
while ($file = fgets($handle)) {
// Matching image files in the cache using grep (*.spi can't be used as an
// argument to ls because it creates too many arguments). Also if the loop
// is broken while there is still data to read, pclose() will report a
// broken pipe, so pipe through head to limit results and continue reading
// even though total has been reached.
if ($total > $count) continue;
$image = unserialize(file_get_contents($cache_dir . '/' . trim($file)));
if (isset($image['body'])) {
$total += strlen($image['body']);
// Only the body is removed to save space, the headers are kept so that
// the original file can be fetched by the image handler if required.
unset($image['body']);
file_put_contents($cache_dir . '/' . $file, serialize($image));
file_put_contents($cache_dir . '/' . trim($file), serialize($image));
}
}
pclose($handle);
......
......@@ -60,6 +60,7 @@ if (!preg_match('/^https?:\/\/' . $_SERVER['SERVER_NAME'] . '/', $me)) {
header('HTTP/1.1 403 Forbidden');
exit;
}
if (!isset($_FILES['file'])) {
log_db('media_endpoint.php 3: File not found.');
header('HTTP/1.1 400 Bad Request');
......
......@@ -97,12 +97,12 @@ if ($result = $mysqli->query($query)) {
$result->close();
}
else {
log_db('micropub.php 3: ' . $mysqli->error);
log_db('micropub.php 1: ' . $mysqli->error);
}
$mysqli->close();
if (!preg_match('/^https?:\/\/' . $_SERVER['SERVER_NAME'] . '/', $me)) {
log_db('micropub.php 4: Couldn\'t match ' . $_SERVER['SERVER_NAME'] .
log_db('micropub.php 2: Couldn\'t match ' . $_SERVER['SERVER_NAME'] .
' in: ' . $me);
header('HTTP/1.1 403 Forbidden');
exit;
......@@ -157,7 +157,7 @@ if ($content_type === 'application/json') {
$type = $data['type'][0];
}
else {
log_db('micropub.php 1: JSON data type not found.');
log_db('micropub.php 3: JSON data type not found.');
header('HTTP/1.1 400 Bad Request');
exit;
}
......@@ -167,7 +167,7 @@ else if (isset($_POST['h']) &&
$type = 'h-' . $_POST['h'];
}
else {
log_db('micropub.php 2: POST data type not found.');
log_db('micropub.php 4: POST data type not found.');
header('HTTP/1.1 400 Bad Request');
exit;
}
......@@ -307,7 +307,7 @@ else {
$content['data'] .= photo_html($photo_list);
}
if (count($content) === 0) {
log_db('micropub.php 7: No content found.');
log_db('micropub.php 8: No content found.');
header('HTTP/1.1 400 Bad Request');
exit;
}
......
......@@ -62,14 +62,20 @@ if (!preg_match('/^https?:\/\/' . $_SERVER['SERVER_NAME'] . '/', $me)) {
exit;
}
if (isset($_GET['action']) && $_GET['action'] === 'channels') {
if (!isset($_GET['action'])) {
log_db('microsub.php 3: action not set.');
header('HTTP/1.1 400 Bad Request');
exit;
}
$action = $_GET['action'];
if ($action === 'channels') {
header('Content-Type: application/json');
echo json_encode(['channels' =>
[['uid' => 'notifications', 'name' => 'Notifications'],
['uid' => 'home', 'name' => 'Home']]]);
}
if (isset($_GET['action']) && $_GET['action'] === 'timeline') {
else if ($action === 'timeline') {
include 'functions/copy_page.php';
include 'functions/microformats.php';
include 'functions/new_module.php';
......@@ -89,7 +95,7 @@ if (isset($_GET['action']) && $_GET['action'] === 'timeline') {
$reader = new Module($user, $owner, 'reader');
if (!$reader->IsInstalled()) {
header('HTTP/1.1 500 Internal Server Error');
log_db('microsub.php 3: Reader module is not installed.');
log_db('microsub.php 4: Reader module is not installed.');
exit;
}
......
......@@ -48,6 +48,7 @@ class User {
return;
}
$set_last_visit = true;
// Check if a (possibly different) user is trying to log in.
if (isset($_POST['user'])) {
$mysqli = connect_db();
......@@ -62,10 +63,12 @@ class User {
if (isset($_POST['email'])) {
$this->emailReset = true;
}
// If the admin user is currently logged in, let them log in as anyone.
// If the admin user is currently logged in, let them log in as anyone
// but don't update the last visit timestamp for the user.
else if (isset($_SESSION['user']) && $_SESSION['user'] === 'admin') {
$this->loggedIn = true;
$this->defaultPage = true;
$set_last_visit = false;
}
else if ($this->Valid()) {
$this->loggedIn = true;
......@@ -106,8 +109,8 @@ class User {
}
if ($this->loggedIn) {
if ($set_last_visit) $this->SetLastVisit();
$this->SetGroup();
$this->SetLastVisit();
$this->Settings();
$this->config->SetUser($this->name);
setcookie('user', $this->name, time() + 3600 * 24 * 7, '/');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment