web.php 12.9 KB
Newer Older
Dominik Hebeler's avatar
Dominik Hebeler committed
1
2
<?php

3
use Illuminate\Support\Facades\Redis;
4
use Jenssegers\Agent\Agent;
Dominik Hebeler's avatar
Dominik Hebeler committed
5
use Prometheus\RenderTextFormat;
6
use Illuminate\Http\Request;
Dominik Hebeler's avatar
Dominik Hebeler committed
7
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
8

Dominik Hebeler's avatar
Dominik Hebeler committed
9
10
/*
|--------------------------------------------------------------------------
11
| Web Routes
Dominik Hebeler's avatar
Dominik Hebeler committed
12
13
|--------------------------------------------------------------------------
|
14
15
16
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
Dominik Hebeler's avatar
Dominik Hebeler committed
17
|
18
 */
19
20
21
22
23
24
25
26
27
28
29

Route::get("robots.txt", function(Request $request){
    $responseData = "";
    if(App::environment("production")){
        $responseData = view("robots.production");
    }else{
        $responseData = view("robots.development");
    }
    return response($responseData, 200, ["Content-Type" => "text/plain"]);
});

Dominik Hebeler's avatar
Dominik Hebeler committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/** ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP **/

Route::get('/', 'StartpageController@loadStartPage')->name("startpage")->middleware("removekey");

Route::get('asso', function () {
    return view('assoziator.asso')
        ->with('title', trans('titles.asso'))
        ->with('navbarFocus', 'dienste')
        ->with('css', [mix('css/asso/style.css')])
        ->with('darkcss', [mix('css/asso/dark.css')]);
});

Route::get('asso/meta.ger3', 'Assoziator@asso')->middleware('browserverification:assoresults', 'humanverification')->name("assoresults");

Route::get('impressum', function () {
    return view('impressum')
        ->with('title', trans('titles.impressum'))
        ->with('navbarFocus', 'kontakt');
});
Route::get('impressum.html', function () {
    return redirect(url('impressum'));
});

Route::get('about', function () {
    return view('about')
        ->with('title', trans('titles.about'))
        ->with('navbarFocus', 'info');
});
Route::get('team', function () {
    return view('team.team')
        ->with('title', trans('titles.team'))
        ->with('navbarFocus', 'kontakt');
});
Route::get('team/pubkey-wsb', function () {
    return view('team.pubkey-wsb')
        ->with('title', trans('titles.team'))
        ->with('navbarFocus', 'kontakt');
});

Route::get('kontakt/{url?}', function ($url = "") {
    return view('kontakt.kontakt')
        ->with('title', trans('titles.kontakt'))
        ->with('navbarFocus', 'kontakt')
        ->with('url', $url);
})->name("contact");

Route::post('kontakt', 'MailController@contactMail');

Route::get('tor', function () {
    return view('tor')
        ->with('title', 'tor hidden service - MetaGer')
        ->with('navbarFocus', 'dienste');
});
Route::get('spende', function () {
    return view('spende.spende')
        ->with('title', trans('titles.spende'))
        ->with('js', [mix('/js/donation.js')])
        ->with('navbarFocus', 'foerdern');
})->name("spende");

Route::get('spende/danke/{data}', function ($data) {
    return view('spende.danke')
        ->with('title', trans('titles.spende'))
        ->with('navbarFocus', 'foerdern')
        ->with('css', [mix('/css/spende/danke.css')])
        ->with('data', unserialize(base64_decode($data)));
})->name("danke");
Route::get('partnershops', function () {
    return view('spende.partnershops')
        ->with('title', trans('titles.partnershops'))
        ->with('navbarFocus', 'foerdern');
});

Route::get('beitritt', function () {
    if (LaravelLocalization::getCurrentLocale() === "de") {
        return response()->download(storage_path('app/public/aufnahmeantrag-de.pdf'), "SUMA-EV_Beitrittsformular_" . (new \DateTime())->format("Y_m_d") . ".pdf", ["Content-Type" => "application/pdf"]);
    } else {
        return response()->download(storage_path('app/public/aufnahmeantrag-en.pdf'), "SUMA-EV_Membershipform_" . (new \DateTime())->format("Y_m_d") . ".pdf", ["Content-Type" => "application/pdf"]);
    }
})->name("beitritt");

Route::get('bform1.htm', function () {
    return redirect('beitritt');
});

Route::post('spende', 'MailController@donation');

Route::get('datenschutz', function () {
    return view('datenschutz/datenschutz')
        ->with('title', trans('titles.datenschutz'))
        ->with('navbarFocus', 'datenschutz');
});

Route::get('transparency', function () {
    return view('transparency')
         ->with('title', trans('titles.transparency'))
         ->with('navbarFocus', 'info');
});

Route::get('search-engine', function () {
    return view('search-engine')
         ->with('title', trans('titles.search-engine'))
         ->with('navbarFocus', 'info');
});

Route::get('hilfe', function () {
    return view('hilfe')
        ->with('title', trans('titles.hilfe'))
        ->with('navbarFocus', 'hilfe');
});

Route::get('hilfe/faktencheck', function () {
    return view('faktencheck')
        ->with('title', trans('titles.faktencheck'))
        ->with('navbarFocus', 'hilfe');
});

Route::get('faq', function () {
    return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), '/hilfe'));
});

Route::get('widget', function () {
    return view('widget.widget')
        ->with('title', trans('titles.widget'))
        ->with('navbarFocus', 'dienste');
});

Route::get('sitesearch', 'SitesearchController@loadPage');

Route::get('websearch', function () {
    return view('widget.websearch')
        ->with('title', trans('titles.websearch'))
        ->with('navbarFocus', 'dienste')
        ->with('template', view('widget.websearch-template')->render());
});

Route::get('zitat-suche', 'ZitatController@zitatSuche');

Route::get('jugendschutz', function () {
    return view('jugendschutz')
        ->with('title', trans('titles.jugendschutz'));
});

Route::get('ad-info', function () {
    return view('ad-info')
        ->with('title', trans('titles.ad-info'));
});

Route::get('age.xml', function () {
    $response = Response::make(file_get_contents(resource_path('age/age.xml')));
    $response->header('Content-Type', "application/xml");
    return $response;
});

Route::get('age-de.xml', function () {
    $response = Response::make(file_get_contents(resource_path('age/age-de.xml')));
    $response->header('Content-Type', "application/xml");
    return $response;
});

Route::get('plugin', function (Request $request) {
    return view('plugin-page')
        ->with('title', trans('titles.plugin'))
        ->with('navbarFocus', 'dienste')
        ->with('agent', new Agent())
195
        ->with('request', $request->input('request', 'GET'))
Dominik Hebeler's avatar
Dominik Hebeler committed
196
197
198
199
200
        ->with('browser', (new Agent())->browser());
});

Route::group(['middleware' => ['auth.basic'], 'prefix' => 'admin'], function () {
    Route::get('/', 'AdminInterface@index');
201
    Route::match(['get', 'post'], 'count', 'AdminInterface@count');
Dominik Hebeler's avatar
Dominik Hebeler committed
202
    Route::get('timings', 'MetaGerSearch@searchTimings');
203
    Route::get('count/graphtoday.svg', 'AdminInterface@countGraphToday');
Dominik Hebeler's avatar
Dominik Hebeler committed
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
    Route::get('engine/stats.json', 'AdminInterface@engineStats');
    Route::get('check', 'AdminInterface@check');
    Route::get('engines', 'AdminInterface@engines');
    Route::get('ip', function (Request $request) {
        dd($request->ip(), $_SERVER["AGENT"]);
    });
    Route::get('bot', 'HumanVerification@botOverview');
    Route::post('bot', 'HumanVerification@botOverviewChange');
    Route::group(['prefix' => 'spam'], function () {
        Route::get('/', 'AdminSpamController@index');
        Route::post('/', 'AdminSpamController@ban');
        Route::get('jsonQueries', 'AdminSpamController@jsonQueries');
        Route::post('queryregexp', 'AdminSpamController@queryregexp');
        Route::post('deleteRegexp', 'AdminSpamController@deleteRegexp');
    });
    Route::get('stress', 'Stresstest@index');
    Route::get('stress/verify', 'Stresstest@index')->middleware('browserverification', 'humanverification');
    Route::get('adgoal', 'AdgoalTestController@index')->name("adgoal-index");
    Route::post('adgoal', 'AdgoalTestController@post')->name("adgoal-generate");
    Route::post('adgoal/generate-urls', 'AdgoalTestController@generateUrls')->name("adgoal-urls");
});

Route::get('settings', function () {
    return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), '/'));
});

Route::match(['get', 'post'], 'meta/meta.ger3', 'MetaGerSearch@search')->middleware('removekey', 'browserverification', 'humanverification', 'useragentmaster')->name("resultpage");

Route::get('meta/loadMore', 'MetaGerSearch@loadMore');
Route::post('img/cat.png', 'HumanVerification@remove');
Route::get('verify/metager/{id}/{uid}', ['as' => 'captcha', 'uses' => 'HumanVerification@captcha']);
Route::get('r/metager/{mm}/{pw}/{url}', ['as' => 'humanverification', 'uses' => 'HumanVerification@removeGet']);
Route::post('img/dog.jpg', 'HumanVerification@whitelist');
Route::get('index.css', 'HumanVerification@browserVerification');
Route::get('index.js', function (Request $request) {
    $key = $request->input("id", "");

    // Verify that key is a md5 checksum
    if (!preg_match("/^[a-f0-9]{32}$/", $key)) {
        abort(404);
    }

246
247
    Redis::connection(config('cache.stores.redis.connection'))->rpush("js" . $key, true);
    Redis::connection(config('cache.stores.redis.connection'))->expire($key, 30);
Dominik Hebeler's avatar
Dominik Hebeler committed
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

    return response("", 200)->header("Content-Type", "application/javascript");
});

Route::get('meta/picture', 'Pictureproxy@get');
Route::get('clickstats', 'LogController@clicklog');
Route::get('pluginClose', 'LogController@pluginClose');
Route::get('pluginInstall', 'LogController@pluginInstall');

Route::get('qt', 'MetaGerSearch@quicktips');
Route::get('tips', 'MetaGerSearch@tips');
Route::get('/plugins/opensearch.xml', 'StartpageController@loadPlugin');
Route::get('owi', function () {
    return redirect('https://metager.de/klassik/en/owi/');
});
Route::get('MG20', function () {
    return redirect('https://metager.de/klassik/MG20');
});
Route::get('databund', function () {
    return redirect('https://metager.de/klassik/databund');
});
Route::get('languages', 'LanguageController@createOverview');
Route::get('synoptic/{exclude?}/{chosenFile?}', 'LanguageController@createSynopticEditPage');
Route::post('synoptic/{exclude?}/{chosenFile?}', 'LanguageController@processSynopticPageInput');
Route::get('languages/edit/{from}/{to}/{exclude?}/{email?}', 'LanguageController@createEditPage');
Route::post('languages/edit/{from}/{to}/{exclude?}/{email?}', 'MailController@sendLanguageFile');

Route::group(['prefix' => 'app'], function () {
    Route::get('/', function () {
        return view('app')
            ->with('title', trans('titles.app'))
            ->with('navbarFocus', 'dienste');
    });
    Route::get('metager', function () {
        return response()->streamDownload(function () {
            $fh = null;
            try {
                $fh = fopen("https://gitlab.metager.de/open-source/app-en/-/raw/latest/app/release_manual/app-release_manual.apk", "r");
                while (!feof($fh)) {
                    echo(fread($fh, 1024));
                }
            } catch (\Exception $e) {
290
                abort(404);
Dominik Hebeler's avatar
Dominik Hebeler committed
291
292
293
294
            } finally {
                if ($fh != null) {
                    fclose($fh);
                }
295
            }
Dominik Hebeler's avatar
Dominik Hebeler committed
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
        }, 'MetaGerSearch.apk', ["Content-Type" => "application/vnd.android.package-archive"]);
    });
    Route::get('maps', function () {
        return response()->streamDownload(function () {
            $fh = null;
            try {
                $fh = fopen("https://gitlab.metager.de/open-source/metager-maps-android/raw/latest/app/release/app-release.apk?inline=false", "r");
                while (!feof($fh)) {
                    echo(fread($fh, 1024));
                }
            } catch (\Exception $e) {
                abort(404);
            } finally {
                if ($fh != null) {
                    fclose($fh);
311
312
                }
            }
Dominik Hebeler's avatar
Dominik Hebeler committed
313
314
315
316
317
318
319
320
321
322
        }, 'MetaGerMaps.apk', ["Content-Type" => "application/vnd.android.package-archive"]);
    });

    Route::get('maps/version', function () {
        $filePath = config("metager.metager.maps.version");
        $fileContents = file_get_contents($filePath);
        return response($fileContents, 200)
            ->header('Content-Type', 'text/plain');
    });
});
323

Dominik Hebeler's avatar
Dominik Hebeler committed
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
Route::get('metrics', function (Request $request) {
    // Only allow access to metrics from within our network
    $ip = $request->ip();
    $allowedNetworks = [
        "10.",
        "172.",
        "192.",
        "127.0.0.1",
    ];

    $allowed = false;
    foreach($allowedNetworks as $part){
        if(stripos($ip, $part) === 0){
            $allowed = true;
        }
    }
340

Dominik Hebeler's avatar
Dominik Hebeler committed
341
342
343
344
345
    if(!$allowed){
        abort(401);
    }
    
    $registry = \Prometheus\CollectorRegistry::getDefault();
346

Dominik Hebeler's avatar
Dominik Hebeler committed
347
348
    $renderer = new RenderTextFormat();
    $result = $renderer->render($registry->getMetricFamilySamples());
Dominik Hebeler's avatar
Dominik Hebeler committed
349

Dominik Hebeler's avatar
Dominik Hebeler committed
350
351
352
353
354
355
356
357
358
    return response($result, 200)
        ->header('Content-Type', RenderTextFormat::MIME_TYPE);
});

Route::group(['prefix' => 'health-check'], function () {
    Route::get('liveness', 'HealthcheckController@liveness');
    Route::get('liveness-scheduler', 'HealthcheckController@livenessScheduler');
    Route::get('liveness-worker', 'HealthcheckController@livenessWorker');
});