Commit 6927c3c5 authored by Dominik Hebeler's avatar Dominik Hebeler

Changed auth to basic auth

parent 9cd8199b
......@@ -24,6 +24,7 @@ update(144.76.113.134):
- scp -P 63824 metager@metager3.de:~/blacklistDomains.txt config/
- scp -P 63824 metager@metager3.de:~/adBlacklistUrl.txt config/
- scp -P 63824 metager@metager3.de:~/adBlacklistDomains.txt config/
- scp -P 63824 metager@metager3.de:~/UsersSeeder.php database/seeds/
- touch storage/logs/laravel.log
- touch storage/logs/worker.log
- touch database/metager.sqlite
......@@ -33,6 +34,7 @@ update(144.76.113.134):
- npm install
- npm run production
- php artisan migrate --force
- php artisan db:seed --force
- php artisan requests:gather
- if [ -f ~/MetaGer/artisan ]; then php ~/MetaGer/artisan down;fi
- cd ~/
......@@ -65,6 +67,7 @@ update(metager2):
- scp -P 63824 metager@metager3.de:~/sumasEn.json config/
- scp -P 63824 metager@metager3.de:~/blacklistUrl.txt config/
- scp -P 63824 metager@metager3.de:~/blacklistDomains.txt config/
- scp -P 63824 metager@metager3.de:~/UsersSeeder.php database/seeds/
- touch storage/logs/laravel.log
- touch storage/logs/worker.log
- touch database/metager.sqlite
......@@ -74,6 +77,7 @@ update(metager2):
- npm install
- npm run production
- php artisan migrate --force
- php artisan db:seed --force
- php artisan requests:gather
- if [ -f ~/MetaGer/artisan ]; then php ~/MetaGer/artisan down;fi
- cd ~/
......
......@@ -94,7 +94,107 @@ class AdminInterface extends Controller
if (!is_int($days) || $days <= 0) {
$days = 28;
}
$logs = $this->getStats($days);
$oldLogs = [];
$rekordTag = 0;
$minCount = 0;
$rekordTagDate = "";
$size = 0;
$count = 0;
$now = Carbon::now()->subMinutes(Carbon::now()->minute % 5)->format('H:i');
if ($now === "00:00") {
$now = "00:05";
}
foreach ($logs as $key => $stats) {
if ($key === 0) {
// Log for today
$logToday = empty($stats->insgesamt->{$interface}) ? 0 : $stats->insgesamt->{$interface};
continue;
}
$insgesamt = empty($stats->insgesamt->{$interface}) ? 0 : $stats->insgesamt->{$interface};
$sameTime = empty($stats->time->{$now}->{$interface}) ? 0 : $stats->time->{$now}->{$interface};
if ($insgesamt > $rekordTag) {
$rekordTag = $insgesamt;
$rekordTagSameTime = $sameTime;
$rekordTagDate = Carbon::now()->subDays($key)->format('d.m.Y');
}
if ($minCount === 0 || $insgesamt < $minCount) {
$minCount = $insgesamt;
}
$oldLogs[$key]['sameTime'] = number_format(floatval($sameTime), 0, ",", ".");
$oldLogs[$key]['insgesamt'] = number_format(floatval($insgesamt), 0, ",", ".");
# Nun noch den median:
$count += $insgesamt;
$size++;
if ($size > 0) {
$oldLogs[$key]['median'] = number_format(floatval(round($count / $size)), 0, ",", ".");
}
}
if ($request->input('out', 'web') === "web") {
return view('admin.count')
->with('title', 'Suchanfragen - MetaGer')
->with('today', number_format(floatval($logToday), 0, ",", "."))
->with('oldLogs', $oldLogs)
->with('minCount', $minCount)
->with('rekordCount', number_format(floatval($rekordTag), 0, ",", "."))
->with('rekordTagSameTime', number_format(floatval($rekordTagSameTime), 0, ",", "."))
->with('rekordDate', $rekordTagDate)
->with('days', $days);
} else {
$result = "";
foreach ($oldLogs as $key => $value) {
$resultTmp = '"' . date("D, d M y", mktime(date("H"), date("i"), date("s"), date("m"), date("d") - $key, date("Y"))) . '",';
$resultTmp .= '"' . $value['sameTime'] . '",';
$resultTmp .= '"' . $value['insgesamt'] . '",';
$resultTmp .= '"' . $value['median'] . '"' . "\r\n";
$result = $resultTmp . $result;
}
return response($result, 200)
->header('Content-Type', 'text/csv')
->header('Content-Disposition', 'attachment; filename="count.csv"');
}
}
public function countGraphToday()
{
$stats = $this->getStats(0)[0];
$hourly = [];
$previous = 0;
$max = 0;
foreach ($stats->time as $time => $timeStats) {
$hour = intval(substr($time, 0, strpos($time, ":")));
if (empty($hourly[$hour])) {
$hourly[$hour] = 0;
}
$hourly[$hour] += $timeStats->all - $previous;
$previous = $timeStats->all;
if ($hourly[$hour] > $max) {
$max = $hourly[$hour];
}
}
$result = [
"insgesamt" => $stats->insgesamt->all,
"max" => $max,
"hourly" => $hourly,
];
return response()
->view('admin.countGraphToday', ["data" => $result], 200)
->header('Content-Type', "image/svg+xml");
}
private function getStats($days)
{
$maxDate = Carbon::createFromFormat('d.m.Y', "28.06.2016");
$selectedDate = Carbon::now()->subDays($days);
if ($maxDate > $selectedDate) {
......@@ -164,78 +264,20 @@ class AdminInterface extends Controller
} while ($removedOne === true);
}
$oldLogs = [];
$rekordTag = 0;
$minCount = 0;
$rekordTagDate = "";
$size = 0;
$count = 0;
$now = Carbon::now()->subMinutes(Carbon::now()->minute % 5)->format('H:i');
if ($now === "00:00") {
$now = "00:05";
}
$result = [];
foreach ($neededLogs as $key => $value) {
$countFile = $value["countFile"];
if (file_exists($countFile)) {
$stats = json_decode(file_get_contents($countFile));
if ($key === 0) {
// Log for today
$logToday = empty($stats->insgesamt->{$interface}) ? 0 : $stats->insgesamt->{$interface};
if (\file_exists($today["countFile"])) {
unlink($today["countFile"]);
}
continue;
}
$insgesamt = empty($stats->insgesamt->{$interface}) ? 0 : $stats->insgesamt->{$interface};
$sameTime = empty($stats->time->{$now}->{$interface}) ? 0 : $stats->time->{$now}->{$interface};
if ($insgesamt > $rekordTag) {
$rekordTag = $insgesamt;
$rekordTagSameTime = $sameTime;
$rekordTagDate = Carbon::now()->subDays($key)->format('d.m.Y');
}
if ($minCount === 0 || $insgesamt < $minCount) {
$minCount = $insgesamt;
}
$oldLogs[$key]['sameTime'] = number_format(floatval($sameTime), 0, ",", ".");
$oldLogs[$key]['insgesamt'] = number_format(floatval($insgesamt), 0, ",", ".");
# Nun noch den median:
$count += $insgesamt;
$size++;
if ($size > 0) {
$oldLogs[$key]['median'] = number_format(floatval(round($count / $size)), 0, ",", ".");
}
$result[$key] = json_decode(file_get_contents($countFile));
}
}
if ($request->input('out', 'web') === "web") {
return view('admin.count')
->with('title', 'Suchanfragen - MetaGer')
->with('today', number_format(floatval($logToday), 0, ",", "."))
->with('oldLogs', $oldLogs)
->with('minCount', $minCount)
->with('rekordCount', number_format(floatval($rekordTag), 0, ",", "."))
->with('rekordTagSameTime', number_format(floatval($rekordTagSameTime), 0, ",", "."))
->with('rekordDate', $rekordTagDate)
->with('days', $days);
} else {
$result = "";
foreach ($oldLogs as $key => $value) {
$resultTmp = '"' . date("D, d M y", mktime(date("H"), date("i"), date("s"), date("m"), date("d") - $key, date("Y"))) . '",';
$resultTmp .= '"' . $value['sameTime'] . '",';
$resultTmp .= '"' . $value['insgesamt'] . '",';
$resultTmp .= '"' . $value['median'] . '"' . "\r\n";
$result = $resultTmp . $result;
}
return response($result, 200)
->header('Content-Type', 'text/csv')
->header('Content-Disposition', 'attachment; filename="count.csv"');
if (\file_exists($today["countFile"])) {
unlink($today["countFile"]);
}
return $result;
}
public function check()
......
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('home');
}
}
<?php
namespace App\Http\Middleware;
use Closure;
class RefererCheck
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$refererCorrect = env('referer_check');
$referer = $request->server('HTTP_REFERER');
if ($refererCorrect !== $referer && "https://metager.de/admin/count" !== $referer) {
abort(401, 'Unauthorized');
} else {
return $next($request);
}
}
}
......@@ -15,6 +15,7 @@ scp -P 63824 metager@metager3.de:~/blacklistUrl.txt config/
scp -P 63824 metager@metager3.de:~/blacklistDomains.txt config/
scp -P 63824 metager@metager3.de:~/adBlacklistUrl.txt config/
scp -P 63824 metager@metager3.de:~/adBlacklistDomains.txt config/
scp -P 63824 metager@metager3.de:~/UsersSeeder.php database/seeds/
touch storage/logs/laravel.log
touch storage/logs/worker.log
touch database/metager.sqlite
......@@ -23,4 +24,5 @@ chmod -R 777 storage
chmod -R 777 bootstrap/cache
npm install
npm run production
php artisan migrate --force
\ No newline at end of file
php artisan migrate --force
php artisan db:seed --force
\ No newline at end of file
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
......@@ -11,6 +11,6 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// $this->call(UsersTableSeeder::class);
$this->call(UsersSeeder::class);
}
}
<?php
use Illuminate\Database\Seeder;
class UsersSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
}
}
<?xml version='1.0' encoding='utf-8'?>
@php ($width = 400)
@php ($height = 100)
@php ($padding = 3)
@php ($paddingArrow = 4)
@php ($startX = 20)
@php ($startY = $height-20)
@php ($entryCount = sizeof($data["hourly"]))
@php ($drawWidth = $width - $padding - $paddingArrow - $startX)
@php ($widthPerElement = $drawWidth / (sizeof($data["hourly"]) * 2))
@php ($heightPerSearch = ($startY - $padding - $paddingArrow) / $data["max"])
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="auto" viewBox="0 0 400 100">
<!-- Y-Achse -->
<path d="m{{$startX}} {{$startY}} L{{$startX}} {{$padding}} L{{$startX-1}} {{$padding}} L{{$startX}} {{$padding-1}} L{{$startX+1}} {{$padding}} L{{$startX}} {{$padding}}z" fill="#333" stroke="#333" stroke-width=".7" />
<text x="{{ $startX + 4}}" y="{{ $padding + $paddingArrow - 2 }}" style="font-size: .3em;" fill="rgba(0,0,0,.5)">
X(Abfragen)
</text>
<!-- Skalierung Y-Achse -->
@for($i = 0; $i < 10; $i++)
<line x1="{{$startX-1}}" y1="{{ ($padding+$paddingArrow) + (($startY-($padding+$paddingArrow)) * ($i/10.0)) }}" x2="{{$startX+1}}" y2="{{ ($padding+$paddingArrow) + (($startY-($padding+$paddingArrow)) * ($i/10.0)) }}" fill="#333" stroke="#333" stroke-width=".7" />
<line x1="{{$startX}}" y1="{{ ($padding+$paddingArrow) + (($startY-($padding+$paddingArrow)) * ($i/10.0)) }}" x2="{{$width-$padding-$paddingArrow}}" y2="{{ ($padding+$paddingArrow) + (($startY-($padding+$paddingArrow)) * ($i/10.0)) }}" fill="#777" stroke="#777" stroke-width=".2" />
<text x="{{$startX - 15}}" y="{{ ($padding+$paddingArrow) + (($startY-($padding+$paddingArrow)) * ($i/10.0)) + 2 }}" style="font-size: .3em;">
@php ($value = round($data["max"] - $i * ($data["max"] / 10.0)))
@if($value >= 1000)
@php($value = round($value / 100.0) / 10.0 . "k" )
@endif
{{ $value }}
</text>
@endfor
@for($i = 0; $i < $entryCount; $i++)
<rect x="{{ $startX + ($widthPerElement * $i * 2) + $widthPerElement}}" y="{{ $startY - ($heightPerSearch * $data["hourly"][$i]) }}" width="{{ $widthPerElement }}" height="{{ ($heightPerSearch * $data["hourly"][$i]) }}" style="fill:rgb(255,127,0); stroke-width:0;" />
<text x="{{ $startX + ($widthPerElement * 1.4) + (($width - $padding - $paddingArrow - $startX - ($widthPerElement * 2)) * ($i/($entryCount-1)))}}" y="{{$startY + 6}}" style="font-size: .3em;" >
{{ number_format($i, 0, ",", ".") }}
</text>
@endfor
<!-- X-Achse -->
<path d="m{{$startX}} {{$startY}} L{{$width-$padding}} {{$startY}} L{{$width-$padding}} {{$startY-1}} L{{$width-($padding-1)}} {{$startY}} L{{$width-$padding}} {{$startY+1}} L{{$width-$padding}} {{$startY}}z" fill="#333" stroke="#333" stroke-width=".5" />
<text x="{{ $width - 4}}" y="{{ $startY + 3}}" style="font-size: .3em;" fill="rgba(0,0,0,.5)" writing-mode="tb">
Y(h)
</text>
</svg>
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Dashboard</div>
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
You are logged in!
</div>
</div>
</div>
</div>
</div>
@endsection
......@@ -167,9 +167,10 @@ Route::group(
->with('request', $this->input('request', 'GET'));
});
Route::group(['middleware' => ['referer.check'], 'prefix' => 'admin'], function () {
Route::group(['middleware' => ['auth.basic'], 'prefix' => 'admin'], function () {
Route::get('/', 'AdminInterface@index');
Route::match(['get', 'post'], 'count', 'AdminInterface@count');
Route::get('count/graphtoday.svg', 'AdminInterface@countGraphToday');
Route::get('check', 'AdminInterface@check');
Route::get('engines', 'AdminInterface@engines');
});
......@@ -235,3 +236,7 @@ Route::group(
});
});
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
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