Skip to content
This repository has been archived by the owner on Mar 13, 2019. It is now read-only.

Adds CrawlerDetect to prevent expiring links for Bots #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
'locale' => $app['i18n_service']->getLocale($config['locale']),
));

// Add Crawler Detect
$app['crawlerDetect'] = $app->share(
function() {
return new Jaybizzle\CrawlerDetect\CrawlerDetect;
}
);

// Register the yaml translations
$app['translator'] = $app->share($app->extend('translator', function(Silex\Translator $translator, $app) {
$translator->addLoader('yaml', new Symfony\Component\Translation\Loader\YamlFileLoader());
Expand Down
2 changes: 2 additions & 0 deletions app/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ view_password.view: Passwort Anzeigen
view_password.expires: Dieser Eintrag erlischt in
view_password.delete: Löschen
view_password.expired: Dieser Eintrag ist erloschen!

view_crawler.info: Ein Kennwort wurde mit Ihnen geteilt, als Sicherheitsmaßnahme ist die Vorschau deaktiviert.
2 changes: 2 additions & 0 deletions app/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ view_password.view: View Password
view_password.expires: This listing will be removed in
view_password.delete: Delete
view_password.expired: The requested record has expired!

view_crawler.info: A password has been shared with you, as a security measure the preview is disabled.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"codegyre/robo": "^0.5.4",
"patchwork/jsqueeze": "^2.0",
"natxet/CssMin": "^3.0",
"phpseclib/phpseclib": "^2.0"
"phpseclib/phpseclib": "^2.0",
"jaybizzle/crawler-detect": "1.*"
},
"autoload": {
"psr-0": {
Expand Down
6 changes: 6 additions & 0 deletions src/App/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public function viewLinkAction($hash)
*/
public function viewPasswordAction($hash)
{
// check if the page is loaded by a crawler, e.g. a Slack of Whatsapp preview
$crawlerDetect = $this->app['crawlerDetect'];
if ($crawlerDetect->isCrawler()) {
return $this->twig->render('view_crawler.twig');
}

$credentials = $this->getCredentials($hash);

return $this->twig->render('view_password.twig', array(
Expand Down
10 changes: 10 additions & 0 deletions src/App/views/view_crawler.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends 'layout.twig' %}
{% block title %}{{ 'app.name'|trans }} - {{ 'view_password.view'|trans }}{% endblock %}

{% block content %}
<div class="row">
<div class="col-sm-12 col-md-6 col-md-offset-3 page-container">
<div id="crawlerDetect"><span class="glyphicon glyphicon-eye-open"></span> {{ 'view_crawler.info'|trans }} </div>
</div>
</div>
{% endblock %}
1 change: 1 addition & 0 deletions vendor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ silex
symfony
twig
webmozart
jaybizzle