Commit d8aee736 authored by Phil Höfer's avatar Phil Höfer

Merge branch 'development' into '809-partnershop-symbol-und-seite-anpassen'

# Conflicts:
#   resources/assets/less/metager/result.less
parents ace2a9d5 dbf9c596
<?php
namespace App\Http\Controllers;
use File;
use Illuminate\Http\Request;
use PiwikTracker;
use Response;
class ImageController extends Controller
{
public function generateImage(Request $request)
{
/*
#Piwik Code
PiwikTracker::$URL = 'http://piwik.metager3.de';
$piwikTracker = new PiwikTracker($idSite = 1);
// Cookies ausschalten
$piwikTracker->disableCookieSupport();
$piwikTracker->deleteCookies();
$site = $request->input('site', '/');
// Sendet Tracker request per http
$piwikTracker->doTrackPageView($site);
*/
$path = public_path() . '/img/1px.png';
$fileType = File::type($path);
$response = Response::make(File::get($path), 200);
$response->header('Content-Type', $fileType);
return $response;
}
}
......@@ -20,6 +20,10 @@ class HumanVerification
*/
public function handle($request, Closure $next)
{
// The specific user
$user = null;
$newUser = true;
$update = true;
try {
$id = hash("sha512", $request->ip());
$uid = hash("sha512", $request->ip() . $_SERVER["AGENT"]);
......@@ -32,19 +36,36 @@ class HumanVerification
* might have to change it at some point.
*/
if ($request->filled('password') || $request->filled('key') || $request->filled('appversion') || !env('BOT_PROTECTION', false)) {
$update = false;
return $next($request);
}
// The specific user
$user = DB::table('humanverification')->where('uid', $uid)->first();
$createdAt = Carbon::now();
$unusedResultPages = 1;
$locked = false;
$users = DB::select('select * from humanverification where id = ?', [$id]);
# Lock out everyone in a Bot network
# Find out how many requests this IP has made
$sum = 0;
foreach($users as $userTmp){
if($uid == $userTmp->uid){
$user = ['uid' => $userTmp->uid,
'id' => $userTmp->id,
'unusedResultPages' => intval($userTmp->unusedResultPages),
'whitelist' => filter_var($userTmp->whitelist, FILTER_VALIDATE_BOOLEAN),
'whitelistCounter' => $userTmp->whitelistCounter,
'locked' => filter_var($userTmp->locked, FILTER_VALIDATE_BOOLEAN),
"lockedKey" => $userTmp->lockedKey,
'updated_at' => Carbon::now(),
];
$newUser = false;
}
if($userTmp->whitelist === 0)
$sum += $userTmp->unusedResultPages;
}
# If this user doesn't have an entry we will create one
if ($user === null) {
DB::table('humanverification')->insert(
$user =
[
'uid' => $uid,
'id' => $id,
......@@ -54,18 +75,9 @@ class HumanVerification
'locked' => false,
"lockedKey" => "",
'updated_at' => Carbon::now(),
]
);
# Insert the URL the user tries to reach
$url = url()->full();
DB::table('usedurls')->insert(['uid' => $uid, 'id' => $id, 'eingabe' => $request->input('eingabe', '')]);
$user = DB::table('humanverification')->where('uid', $uid)->first();
];
}
# Lock out everyone in a Bot network
# Find out how many requests this IP has made
$sum = DB::table('humanverification')->where('id', $id)->where('whitelist', false)->sum('unusedResultPages');
# A lot of automated requests are from websites that redirect users to our result page.
# We will detect those requests and put a captcha
$referer = URL::previous();
......@@ -81,16 +93,19 @@ class HumanVerification
}
// Defines if this is the only user using that IP Adress
$alone = DB::table('humanverification')->where('id', $id)->count() === 1;
if ((!$alone && $sum >= 50 && $user->whitelist !== 1) || $refererLock) {
DB::table('humanverification')->where('uid', $uid)->update(['locked' => true]);
$user->locked = 1;
$alone = true;
foreach($users as $userTmp){
if($userTmp->uid != $uid && !$userTmp->whitelist)
$alone = false;
}
if ((!$alone && $sum >= 50 && !$user["whitelist"]) || $refererLock) {
$user["locked"] = true;
}
# If the user is locked we will force a Captcha validation
if ($user->locked === 1) {
if ($user["locked"]) {
$captcha = Captcha::create("default", true);
DB::table('humanverification')->where('uid', $uid)->update(['lockedKey' => $captcha["key"]]);
$user["lockedKey"] = $captcha["key"];
return
new Response(
view('humanverification.captcha')
......@@ -101,11 +116,9 @@ class HumanVerification
);
}
$unusedResultPages = intval($user->unusedResultPages);
$unusedResultPages++;
$locked = false;
$user["unusedResultPages"]++;
if ($alone || $user->whitelist === 1) {
if ($alone || $user["whitelist"]) {
# This IP doesn't need verification yet
# The user currently isn't locked
......@@ -114,20 +127,46 @@ class HumanVerification
# If the user shows activity on our result page the counter will be deleted
# Maybe I'll add a ban if the user reaches 100
if ($unusedResultPages === 50 || $unusedResultPages === 75 || $unusedResultPages === 85 || $unusedResultPages >= 90) {
$locked = true;
if ($user["unusedResultPages"] === 50 || $user["unusedResultPages"] === 75 || $user["unusedResultPages"] === 85 || $user["unusedResultPages"] >= 90) {
$user["locked"] = true;
}
}
DB::table('humanverification')->where('uid', $uid)->update(['unusedResultPages' => $unusedResultPages, 'locked' => $locked]);
# Insert the URL the user tries to reach
DB::table('usedurls')->insert(['uid' => $uid, 'id' => $id, 'eingabe' => $request->input('eingabe', '')]);
} catch (\Illuminate\Database\QueryException $e) {
// Failure in contacting metager3.de
} finally {
// Update the user in the database
if($update){
if($newUser){
DB::table('humanverification')->insert(
[
'uid' => $user["uid"],
'id' => $user["id"],
'unusedResultPages' => $user['unusedResultPages'],
'whitelist' => $user["whitelist"],
'whitelistCounter' => $user["whitelistCounter"],
'locked' => $user["locked"],
"lockedKey" => $user["lockedKey"],
'updated_at' => $user["updated_at"],
]
);
}else{
DB::table('humanverification')->where('uid', $uid)->update(
[
'uid' => $user["uid"],
'id' => $user["id"],
'unusedResultPages' => $user['unusedResultPages'],
'whitelist' => $user["whitelist"],
'whitelistCounter' => $user["whitelistCounter"],
'locked' => $user["locked"],
"lockedKey" => $user["lockedKey"],
'updated_at' => $user["updated_at"],
]
);
}
}
}
if(isset($uid) && isset($unusedResultPages))
$request->request->add(['verification_id' => $uid, 'verification_count' => $unusedResultPages]);
$request->request->add(['verification_id' => $user["uid"], 'verification_count' => $user["unusedResultPages"]]);
return $next($request);
}
}
......@@ -1371,12 +1371,10 @@ class MetaGer
IP-Adress older than one day stored on our servers. (Except the ones who got banned in that short period of course) ;-)
*/
$logEntry .= " ip=" . $this->request->ip();
$logEntry .= " pid=" . getmypid();
$logEntry .= " ref=" . $this->request->header('Referer');
$logEntry .= " time=" . round((microtime(true) - $this->starttime), 2) . " serv=" . $this->fokus;
$logEntry .= " interface=" . LaravelLocalization::getCurrentLocale();
$logEntry .= " sprachfilter=" . $this->lang;
$logEntry .= " search=" . $this->eingabe;
# 2 Arten von Logs in einem wird die Anzahl der Abfragen an eine Suchmaschine gespeichert und in der anderen
# die Anzahl, wie häufig diese Ergebnisse geliefert hat.
......
......@@ -7,6 +7,7 @@ use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Support\ServiceProvider;
use Queue;
use Illuminate\Support\Facades\Redis;
use Request;
class AppServiceProvider extends ServiceProvider
{
......@@ -17,6 +18,17 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
/**
* metager.org is our english Domain
* We will change the Locale to en
*/
$host = Request::header("X_Forwarded_Host", "");
if(stripos($host, "metager.org") !== FALSE){
App::setLocale('en');
}
# Wir loggen im Redis-System für jede Sekunde des Tages, wie viele Worker aktiv am Laufen waren.
# Dies ist notwendig, damit wir mitbekommen können, ab welchem Zeitpunkt wir zu wenig Worker zur Verfügung haben.
Queue::before(function (JobProcessing $event) {
......
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"type": "project",
"require": {
......@@ -13,7 +16,6 @@
"laravelcollective/html": "^5.2.0",
"mcamara/laravel-localization": "^1.1",
"mews/captcha": "^2.2",
"piwik/piwik-php-tracker": "^1.0",
"predis/predis": "^1.1"
},
"require-dev": {
......@@ -40,8 +42,7 @@
},
"extra": {
"laravel": {
"dont-discover": [
]
"dont-discover": []
}
},
"scripts": {
......@@ -61,4 +62,4 @@
"sort-packages": true,
"optimize-autoloader": true
}
}
}
\ No newline at end of file
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class Usedurls extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('usedurls', function (Blueprint $table) {
$table->increments('number')->unique();
$table->string('uid');
$table->string('id');
$table->text('eingabe');
$table->timestamp('created_at');
$table->foreign('uid')->references('uid')->on('humanverification')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('usedurls');
}
}
......@@ -4300,7 +4300,8 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"aproba": {
"version": "1.1.1",
......@@ -4375,6 +4376,7 @@
"version": "2.10.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"hoek": "2.x.x"
}
......@@ -4544,6 +4546,7 @@
"version": "1.0.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"graceful-fs": "^4.1.2",
"inherits": "~2.0.0",
......@@ -4611,7 +4614,8 @@
"graceful-fs": {
"version": "4.1.11",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"har-schema": {
"version": "1.0.5",
......@@ -4798,12 +4802,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
......@@ -5093,6 +5099,7 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -16,7 +16,7 @@ $(document).ready(function () {
var search = getMetaTag('q') || '';
var locale = getMetaTag('l') || 'de';
// loadQuicktips(search, locale, sprueche) // load the quicktips
// loadQuicktips(search, locale, sprueche) // load the quicktips
});
/*
......@@ -25,11 +25,11 @@ function readLocaleFromUrl (defaultLocale) {
}
*/
function getURLParameter (name, defaultValue) {
function getURLParameter(name, defaultValue) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || defaultValue;
}
function getMetaTag (name) {
function getMetaTag(name) {
if (typeof $('meta[name="' + name + '"')[0] !== 'undefined') {
return $('meta[name="' + name + '"')[0].content || null;
} else {
......@@ -37,12 +37,12 @@ function getMetaTag (name) {
}
}
function activateJSOnlyContent () {
function activateJSOnlyContent() {
$('#searchplugin').removeClass('hide');
$('.js-only').removeClass('js-only');
}
function tabs () {
function tabs() {
$('#foki > li.tab-selector > a').each(function () {
if ($(this).attr('target') != '_blank') {
$(this).attr('href', '#' + $(this).attr('aria-controls'));
......@@ -68,10 +68,9 @@ function tabs () {
$('#search-delete-btn').removeClass('hidden');
}
function getDocumentReadyForUse (fokus, custom) {
function getDocumentReadyForUse(fokus, custom) {
if (typeof custom == 'undefined') custom = false;
activateJSOnlyContent();
clickLog();
popovers();
if (fokus === 'bilder') imageLoader();
if (custom) initialLoadContent(fokus);
......@@ -85,15 +84,15 @@ function getDocumentReadyForUse (fokus, custom) {
addListeners();
}
function addListeners () {
function addListeners() {
$('#search-delete-btn').click(resetSearchbar);
}
function resetSearchbar () {
function resetSearchbar() {
$('.search-input input').val('').focus();
}
function pluginInfo () {
function pluginInfo() {
if (localStorage) {
if (localStorage.getItem('pluginInfo') == 'off') $('#searchplugin').css('display', 'none');
$('#searchplugin').on('close.bs.alert', function () {
......@@ -106,7 +105,7 @@ function pluginInfo () {
}
}
function theme () {
function theme() {
if (localStorage) {
var theme = localStorage.getItem('theme');
if (theme != null) {
......@@ -120,20 +119,7 @@ function theme () {
}
}
function clickLog () {
$('.result a.title, .result div.link-link a').off();
$('.result a.title, .result div.link-link a').click(function () {
$.get('/clickstats', {
i: $('meta[name=p]').attr('content'),
s: $(this).attr('data-hoster'),
q: $('meta[name=q]').attr('content'),
p: $(this).attr('data-count'),
url: $(this).attr('href')
});
});
}
function botProtection () {
function botProtection() {
$('.result').find('a').click(function () {
var link = $(this).attr('href');
var newtab = false;
......@@ -143,7 +129,7 @@ function botProtection () {
$.ajax({
url: '/img/cat.jpg',
type: 'post',
data: { mm: $('meta[name=mm]').attr('content')},
data: { mm: $('meta[name=mm]').attr('content') },
timeout: 2000
})
.always(function () {
......@@ -157,7 +143,7 @@ function botProtection () {
});
}
function popovers () {
function popovers() {
$('[data-toggle=popover]').each(function (e) {
$(this).popover({
// html : true,
......@@ -167,14 +153,14 @@ function popovers () {
});
}
function pagination () {
function pagination() {
$('.pagination li:not(.active) > a').attr('href', '#');
$('.pagination li.disabled > a').removeAttr('href');
$('.pagination li:not(.active) > a').off();
$('.pagination li:not(.active) > a').click(paginationHandler);
}
function paginationHandler () {
function paginationHandler() {
var link = $(this).attr('data-href');
if (link.length == 0) {
return;
......@@ -191,7 +177,7 @@ function paginationHandler () {
});
}
function imageLoader () {
function imageLoader() {
if (typeof $('#container').masonry == 'undefined') {
return;
}
......@@ -206,7 +192,7 @@ function imageLoader () {
});
}
function eliminateHost (host) {
function eliminateHost(host) {
$('.result:not(.ad)').each(function (e) {
var host2 = $(this).find('.link-link > a').attr('data-host');
if (host2.indexOf(host) === 0) {
......@@ -215,7 +201,7 @@ function eliminateHost (host) {
});
}
function fokiChanger () {
function fokiChanger() {
$('#fokiChanger ul > li').click(function () {
document.location.href = $(this).attr('data-href');
});
......@@ -291,7 +277,7 @@ function fokiChanger () {
/**
* Loads the content for a given fokus
*/
function initialLoadContent (fokus) {
function initialLoadContent(fokus) {
var link = $('#' + fokus + 'TabSelector a').attr('data-href');
$.get(link, function (data) {
$('#' + fokus).html(data);
......
......@@ -163,7 +163,7 @@ function loadSavedResults() {
<div class="focus">\
<input id="savedResults" class="focus-radio hide" name="focus" value="container" form="searchForm" type="radio" required="">\
<label id="saved-results-label" class="focus-label" for="savedResults">\
<span class="glyphicon glyphicon-floppy-disk"></span>\
<i class="fas fa-save"></i>\
<span class="content">gespeicherte Ergebnisse</span>\
<span class="badge">' + results.length + '</span>\
</label>\
......
@import "./font-awesome/less/font-awesome.less";
@import "./font-awesome/fontawesome.less";
@import "./font-awesome/solid.less";
@import "./bootstrap/bootstrap.less";
@import "./metager/metager.less";
\ No newline at end of file
// Animated Icons
// --------------------------
.@{fa-css-prefix}-spin {
animation: fa-spin 2s infinite linear;
}
.@{fa-css-prefix}-pulse {
animation: fa-spin 1s infinite steps(8);
}