Skip to content
Snippets Groups Projects
Commit c479d528 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Merge branch 'development' into 'master'

Development

See merge request !1435
parents 4ceba14d 85267ea6
No related branches found
No related tags found
2 merge requests!1504Master,!1435Development
...@@ -24,6 +24,7 @@ update(144.76.113.134): ...@@ -24,6 +24,7 @@ update(144.76.113.134):
- scp -P 63824 metager@metager3.de:~/blacklistDomains.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:~/adBlacklistUrl.txt config/
- scp -P 63824 metager@metager3.de:~/adBlacklistDomains.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/laravel.log
- touch storage/logs/worker.log - touch storage/logs/worker.log
- touch database/metager.sqlite - touch database/metager.sqlite
...@@ -33,6 +34,7 @@ update(144.76.113.134): ...@@ -33,6 +34,7 @@ update(144.76.113.134):
- npm install - npm install
- npm run production - npm run production
- php artisan migrate --force - php artisan migrate --force
- php artisan db:seed --force
- php artisan requests:gather - php artisan requests:gather
- if [ -f ~/MetaGer/artisan ]; then php ~/MetaGer/artisan down;fi - if [ -f ~/MetaGer/artisan ]; then php ~/MetaGer/artisan down;fi
- cd ~/ - cd ~/
...@@ -65,6 +67,7 @@ update(metager2): ...@@ -65,6 +67,7 @@ update(metager2):
- scp -P 63824 metager@metager3.de:~/sumasEn.json config/ - scp -P 63824 metager@metager3.de:~/sumasEn.json config/
- scp -P 63824 metager@metager3.de:~/blacklistUrl.txt 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:~/blacklistDomains.txt config/
- scp -P 63824 metager@metager3.de:~/UsersSeeder.php database/seeds/
- touch storage/logs/laravel.log - touch storage/logs/laravel.log
- touch storage/logs/worker.log - touch storage/logs/worker.log
- touch database/metager.sqlite - touch database/metager.sqlite
...@@ -74,6 +77,7 @@ update(metager2): ...@@ -74,6 +77,7 @@ update(metager2):
- npm install - npm install
- npm run production - npm run production
- php artisan migrate --force - php artisan migrate --force
- php artisan db:seed --force
- php artisan requests:gather - php artisan requests:gather
- if [ -f ~/MetaGer/artisan ]; then php ~/MetaGer/artisan down;fi - if [ -f ~/MetaGer/artisan ]; then php ~/MetaGer/artisan down;fi
- cd ~/ - cd ~/
......
...@@ -94,7 +94,155 @@ class AdminInterface extends Controller ...@@ -94,7 +94,155 @@ class AdminInterface extends Controller
if (!is_int($days) || $days <= 0) { if (!is_int($days) || $days <= 0) {
$days = 28; $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");
}
public function engineStats()
{
$result = [];
$result["loadavg"] = sys_getloadavg();
// Memory Data
$data = explode("\n", trim(file_get_contents("/proc/meminfo")));
$meminfo = [];
foreach ($data as $line) {
list($key, $val) = explode(":", $line);
$meminfo[$key] = trim($val);
}
$conversions = [
"KB",
"MB",
"GB",
"TB",
];
$memAvailable = $meminfo["MemAvailable"];
$memAvailable = intval(explode(" ", $memAvailable)[0]);
$counter = 0;
while ($memAvailable > 1000) {
$memAvailable /= 1000.0;
$counter++;
}
$memAvailable = round($memAvailable);
$memAvailable .= " " . $conversions[$counter];
$result["memoryAvailable"] = $memAvailable;
$resultCount = 0;
$file = "/var/log/metager/mg3.log";
if (file_exists($file)) {
$fh = fopen($file, "r");
try {
while (fgets($fh) !== false) {
$resultCount++;
}
} finally {
fclose($fh);
}
}
$result["resultCount"] = number_format($resultCount, 0, ",", ".");
return response()->json($result);
}
private function getStats($days)
{
$maxDate = Carbon::createFromFormat('d.m.Y', "28.06.2016"); $maxDate = Carbon::createFromFormat('d.m.Y', "28.06.2016");
$selectedDate = Carbon::now()->subDays($days); $selectedDate = Carbon::now()->subDays($days);
if ($maxDate > $selectedDate) { if ($maxDate > $selectedDate) {
...@@ -164,78 +312,20 @@ class AdminInterface extends Controller ...@@ -164,78 +312,20 @@ class AdminInterface extends Controller
} while ($removedOne === true); } while ($removedOne === true);
} }
$oldLogs = []; $result = [];
$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 ($neededLogs as $key => $value) { foreach ($neededLogs as $key => $value) {
$countFile = $value["countFile"]; $countFile = $value["countFile"];
if (file_exists($countFile)) { if (file_exists($countFile)) {
$stats = json_decode(file_get_contents($countFile)); $result[$key] = 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, ",", ".");
}
} }
} }
if ($request->input('out', 'web') === "web") { if (\file_exists($today["countFile"])) {
return view('admin.count') unlink($today["countFile"]);
->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"');
} }
return $result;
} }
public function check() public function check()
......
<?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/ ...@@ -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:~/blacklistDomains.txt config/
scp -P 63824 metager@metager3.de:~/adBlacklistUrl.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:~/adBlacklistDomains.txt config/
scp -P 63824 metager@metager3.de:~/UsersSeeder.php database/seeds/
touch storage/logs/laravel.log touch storage/logs/laravel.log
touch storage/logs/worker.log touch storage/logs/worker.log
touch database/metager.sqlite touch database/metager.sqlite
...@@ -23,4 +24,12 @@ chmod -R 777 storage ...@@ -23,4 +24,12 @@ chmod -R 777 storage
chmod -R 777 bootstrap/cache chmod -R 777 bootstrap/cache
npm install npm install
npm run production npm run production
php artisan migrate --force php artisan migrate --force
\ No newline at end of file php artisan db:seed --force
php artisan requests:gather
if [ -f ~/MetaGer/artisan ]; then php ~/MetaGer/artisan down;fi
cd ~/
while [ -d ~/MetaGer ]; do rm -rf ~/MetaGer;done
mv MetaGer_neu MetaGer
sudo pkill --signal SIGHUP supervisord
php ~/MetaGer/artisan up
\ 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 ...@@ -11,6 +11,6 @@ class DatabaseSeeder extends Seeder
*/ */
public function run() 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: 6px;" fill="rgba(0,0,0,.5)">
Y(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: 6px;">
@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: 6px;" >
{{ 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: 6px;" fill="rgba(0,0,0,.5)" writing-mode="tb">
X(h)
</text>
</svg>
...@@ -167,9 +167,11 @@ Route::group( ...@@ -167,9 +167,11 @@ Route::group(
->with('request', $this->input('request', 'GET')); ->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::get('/', 'AdminInterface@index');
Route::match(['get', 'post'], 'count', 'AdminInterface@count'); Route::match(['get', 'post'], 'count', 'AdminInterface@count');
Route::get('count/graphtoday.svg', 'AdminInterface@countGraphToday');
Route::get('engine/stats.json', 'AdminInterface@engineStats');
Route::get('check', 'AdminInterface@check'); Route::get('check', 'AdminInterface@check');
Route::get('engines', 'AdminInterface@engines'); Route::get('engines', 'AdminInterface@engines');
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment