Skip to content

Commit

Permalink
Fix vulnerabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitri Popov committed Oct 6, 2021
1 parent 80f065d commit 23429b1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 120 deletions.
9 changes: 9 additions & 0 deletions SECURITY.md
@@ -0,0 +1,9 @@
# Security Policy

## Supported versions

The code in the `main` branch supported with security updates.

## Reporting a vulnerability

Please report security issues and vulnerabilities to dmpop@linux.com
33 changes: 19 additions & 14 deletions index.php
Expand Up @@ -96,9 +96,14 @@ function read_gps_location($file)

// Check whether the required directories exist
if (!file_exists($photo_dir) || !file_exists($photo_dir . 'tims')) {
mkdir($photo_dir, 0777, true);
mkdir($photo_dir . 'tims', 0777, true);
echo ('<h3>Add photos to the <strong>photos</strong> directory, then refresh this page.</h3>');
echo ("<h1 style='margin-top: 2em;'><mark>Directory doesn't exist</mark></h1>
<div style='display: flex; justify-content: center; line-height: 1.5;'>
<ul>
<li>Create <u>$photo_dir</u> and <u>" . $photo_dir . "tims</u> directories.</li>
<li>Add photos to the <u>$photo_dir</u> directory.</li>
<li>Refresh this page.</li>
</ul></div>");
exit;
}

// Get file info
Expand Down Expand Up @@ -204,7 +209,7 @@ function read_gps_location($file)
}

if ($file_count < 1) {
echo ('<h3>Add photos to the <strong>photos</strong> directory, then refresh this page.</h3>');
echo ("<h2 style='margin-top: 2em;'>Add photos to the <u>photos</u> directory, then refresh this page.</h2>");
}

if (!isset($_GET["all"])) {
Expand All @@ -220,14 +225,14 @@ function read_gps_location($file)
$file = $files[$i];
$tim = $photo_dir . 'tims/' . basename($file);
$file_path = pathinfo($file);
echo '<a href="index.php?all=1&photo=' . $file . '&d=' . $sub_photo_dir . '"><img src="' . $tim . '" alt="' . $file_path['filename'] . '" title="' . $file_path['filename'] . '"></a>';
echo '<a href="index.php?all=1&photo=' . $file . '&d=' . strip_tags($sub_photo_dir) . '"><img src="' . $tim . '" alt="' . $file_path['filename'] . '" title="' . $file_path['filename'] . '"></a>';
}
} else {
for ($i = $offset; $i < $max; $i++) {
$file = $files[$i];
$tim = $photo_dir . 'tims/' . basename($file);
$file_path = pathinfo($file);
echo '<a href="index.php?all=1&photo=' . $file . '&d=' . $sub_photo_dir . '"><img src="' . $tim . '" alt="' . $file_path['filename'] . '" title="' . $file_path['filename'] . '"></a>';
echo '<a href="index.php?all=1&photo=' . $file . '&d=' . strip_tags($sub_photo_dir) . '"><img src="' . $tim . '" alt="' . $file_path['filename'] . '" title="' . $file_path['filename'] . '"></a>';
}
}
echo "</div>";
Expand All @@ -242,16 +247,16 @@ function show_pagination($current_page, $last_page, $sub_photo_dir)
{
echo '<div class="center">';
if ($current_page != 1 && isset($_GET["photo"]) == '') {
echo '<a color: #e3e3e3;" href="?page=' . "1" . '&d=' . $sub_photo_dir . '"><img style="margin-right:1em;" src="svg/arrow-top-left-o.svg"/></a> ';
echo '<a color: #e3e3e3;" href="?page=' . "1" . '&d=' . strip_tags($sub_photo_dir) . '"><img style="margin-right:1em;" src="svg/arrow-top-left-o.svg"/></a> ';
}
if ($current_page > 1 && isset($_GET["photo"]) == '') {
echo '<a color: #e3e3e3;" href="?page=' . ($current_page - 1) . '&d=' . $sub_photo_dir . '"><img style="margin-right:1em;" src="svg/arrow-left-o.svg"/></a> ';
echo '<a color: #e3e3e3;" href="?page=' . ($current_page - 1) . '&d=' . strip_tags($sub_photo_dir) . '"><img style="margin-right:1em;" src="svg/arrow-left-o.svg"/></a> ';
}
if ($current_page < $last_page && isset($_GET["photo"]) == '') {
echo '<a color: #e3e3e3;" href="?page=' . ($current_page + 1) . '&d=' . $sub_photo_dir . '"><img style="margin-right:1em;" src="svg/arrow-right-o.svg"/></a>';
echo '<a color: #e3e3e3;" href="?page=' . ($current_page + 1) . '&d=' . strip_tags($sub_photo_dir) . '"><img style="margin-right:1em;" src="svg/arrow-right-o.svg"/></a>';
}
if ($current_page != $last_page && isset($_GET["photo"]) == '') {
echo ' <a style="color: #e3e3e3;" href="?page=' . ($last_page) . '&d=' . $sub_photo_dir . '"><img src="svg/arrow-top-right-o.svg"/></a>';
echo ' <a style="color: #e3e3e3;" href="?page=' . ($last_page) . '&d=' . strip_tags($sub_photo_dir) . '"><img src="svg/arrow-top-right-o.svg"/></a>';
}
echo '</div>';
}
Expand Down Expand Up @@ -282,21 +287,21 @@ function show_pagination($current_page, $last_page, $sub_photo_dir)

// If there is only one photo in the album, show the home navigation link
if ($file_count == 1) {
echo "<div class='center'><a href='" . basename($_SERVER['PHP_SELF']) . '?d=' . $sub_photo_dir . "' accesskey='g'><img src='svg/home.svg'/></a></div>";
echo "<div class='center'><a href='" . basename($_SERVER['PHP_SELF']) . '?d=' . strip_tags($sub_photo_dir) . "' accesskey='g'><img src='svg/home.svg'/></a></div>";
}
// Disable the Previous link if this is the FIRST photo
elseif (empty($files[$key - 1])) {
echo "<div class='center'><a href='" . basename($_SERVER['PHP_SELF']) . '?d=' . $sub_photo_dir . "' accesskey='g'><img style='margin-right:1em;' src='svg/home.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $files[$key + 1] . '&d=' . $sub_photo_dir . "' accesskey='n'><img style='margin-right:1em;' src='svg/arrow-right-o.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $last_photo . '&d=' . $sub_photo_dir . "' accesskey='l'><img src='svg/arrow-top-right-o.svg'/></a></div>";
echo "<div class='center'><a href='" . basename($_SERVER['PHP_SELF']) . '?d=' . strip_tags($sub_photo_dir) . "' accesskey='g'><img style='margin-right:1em;' src='svg/home.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $files[$key + 1] . '&d=' . strip_tags($sub_photo_dir) . "' accesskey='n'><img style='margin-right:1em;' src='svg/arrow-right-o.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $last_photo . '&d=' . strip_tags($sub_photo_dir) . "' accesskey='l'><img src='svg/arrow-top-right-o.svg'/></a></div>";
}
// Disable the Next link if this is the LAST photo
elseif (empty($files[$key + 1])) {
echo "<div class='center'><a href='" . basename($_SERVER['PHP_SELF']) . '?d=' . $sub_photo_dir . "' accesskey='g'><img style='margin-right:1em;' src='svg/home.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $first_photo . '&d=' . $sub_photo_dir . "' accesskey='f'><img style='margin-right:1em;' src='svg/arrow-top-left-o.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . '?d=' . $sub_photo_dir . "&photo=" . $files[$key - 1] . "' accesskey='p'><img style='margin-right:1em;' src='svg/arrow-left-o.svg'/></a></div>";
echo "<div class='center'><a href='" . basename($_SERVER['PHP_SELF']) . '?d=' . strip_tags($sub_photo_dir) . "' accesskey='g'><img style='margin-right:1em;' src='svg/home.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $first_photo . '&d=' . strip_tags($sub_photo_dir) . "' accesskey='f'><img style='margin-right:1em;' src='svg/arrow-top-left-o.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . '?d=' . strip_tags($sub_photo_dir) . "&photo=" . $files[$key - 1] . "' accesskey='p'><img style='margin-right:1em;' src='svg/arrow-left-o.svg'/></a></div>";
}
// Show all navigation links
else {

echo "<div class='center'>
<a href='" . basename($_SERVER['PHP_SELF']) . '?d=' . $sub_photo_dir . "' accesskey='g'><img style='margin-right:1em;' src='svg/home.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $first_photo . '&d=' . $sub_photo_dir . "' accesskey='f'><img style='margin-right:1em;' src='svg/arrow-top-left-o.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $files[$key - 1] . '&d=' . $sub_photo_dir . "' accesskey='p'><img style='margin-right:1em;' src='svg/arrow-left-o.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $files[$key + 1] . '&d=' . $sub_photo_dir . "' accesskey='n'><img style='margin-right:1em;' src='svg/arrow-right-o.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $last_photo . '&d=' . $sub_photo_dir . "' accesskey='l'><img src='svg/arrow-top-right-o.svg'/></a></div>";
<a href='" . basename($_SERVER['PHP_SELF']) . '?d=' . strip_tags($sub_photo_dir) . "' accesskey='g'><img style='margin-right:1em;' src='svg/home.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $first_photo . '&d=' . strip_tags($sub_photo_dir) . "' accesskey='f'><img style='margin-right:1em;' src='svg/arrow-top-left-o.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $files[$key - 1] . '&d=' . strip_tags($sub_photo_dir) . "' accesskey='p'><img style='margin-right:1em;' src='svg/arrow-left-o.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $files[$key + 1] . '&d=' . strip_tags($sub_photo_dir) . "' accesskey='n'><img style='margin-right:1em;' src='svg/arrow-right-o.svg'/></a><a href='" . basename($_SERVER['PHP_SELF']) . "?photo=" . $last_photo . '&d=' . strip_tags($sub_photo_dir) . "' accesskey='l'><img src='svg/arrow-top-right-o.svg'/></a></div>";
}

// Check whether the localized description file matching the browser language exists
Expand Down
106 changes: 0 additions & 106 deletions upload.php

This file was deleted.

0 comments on commit 23429b1

Please sign in to comment.