StartpageController.php 4.41 KB
Newer Older
Dominik Hebeler's avatar
Dominik Hebeler committed
1 2 3 4
<?php

namespace App\Http\Controllers;

5
use App;
6
use DB;
7
use Illuminate\Http\Request;
8
use Jenssegers\Agent\Agent;
9
use LaravelLocalization;
10
use Log;
11
use Response;
Dominik Hebeler's avatar
Dominik Hebeler committed
12 13 14 15 16 17 18 19 20

class StartpageController extends Controller
{
    /**
     * Load Startpage accordingly to the given URL-Parameter and Mobile
     *
     * @param  int  $id
     * @return Response
     */
21

22
    public function loadStartPage(Request $request)
23 24
    {
        $focusPages = [];
25
        $theme = "default";
26

27
        $optionParams = ['param_sprueche', 'param_newtab', 'param_maps', 'param_autocomplete', 'param_lang', 'param_key'];
28 29 30 31 32 33 34 35 36 37
        $option_values = [];

        foreach ($optionParams as $param) {
            $value = $request->input($param);
            if ($value) {
                $option_values[$param] = $value;
            }
        }

        $autocomplete = 'on';
38
        if (in_array('autocomplete', array_keys($option_values))) {
39 40 41
            $autocomplete = $option_values['autocomplete'];
        }

42
        $lang = LaravelLocalization::getCurrentLocale();
43
        if ($lang === 'de' || $lang === "en") {
44 45
            $lang = 'all';
        }
46

47 48
        # Sponsorenlinks
        $sponsors = [];
49
        try {
50
            $sponsors = DB::table('sponsorenlinks')->where('langcode', 'de')->orderByRaw('LENGTH(linktext)', 'ASC')->get();
Dominik Hebeler's avatar
Dominik Hebeler committed
51
            DB::disconnect('mysql');
52
        } catch (\Illuminate\Database\QueryException $e) {
53 54
            Log::info($e);
        }
55

56 57 58
        return view('index')
            ->with('title', trans('titles.index'))
            ->with('homeIcon')
59 60
            ->with('browser', (new Agent())->browser())
            ->with('navbarFocus', 'suche')
61
            ->with('focus', $request->input('focus', 'web'))
62
            ->with('time', $request->input('param_time', '1500'))
63 64
            ->with('request', $request->input('request', 'GET'))
            ->with('option_values', $option_values)
65
            ->with('autocomplete', $autocomplete)
66
            ->with('sponsors', $sponsors)
67
            ->with('pluginmodal', $request->input('plugin-modal', 'off'));
68 69
    }

70
    public function loadPage($subpage)
71
    {
72 73
        /* TODO CSS und Titel laden
        $css = array(
74
        'datenschutz' => 'privacy.css',
75 76 77
        );

        if (in_array($subpage, $css)) {
78
        return view($subpage, [ 'title' => 'Datenschutz Richtlinien', 'css' => $css[$subpage]]);
79
        } else {
80
        return view($subpage, [ 'title' => 'Datenschutz Richtlinien']);
81 82
        }*/
        return view($subpage, ['title' => 'Datenschutz Richtlinien']);
83 84 85 86 87 88
    }

    public function loadLocalPage($locale = "de", $subpage = "datenschutz")
    {
        \App::setLocale($locale);
        return loadPage($subpage);
Dominik Hebeler's avatar
Dominik Hebeler committed
89
    }
90

91
    public function loadPlugin($locale = "de")
92
    {
93
        $link = action('MetaGerSearch@search', []);
94 95

        $response = Response::make(
96 97
            view('plugin')
                ->with('link', $link)
98
                ->with('hostname', gethostname())
99
            , "200");
100
        $response->header('Content-Type', "application/opensearchdescription+xml");
101 102
        return $response;
    }
103

104 105
    public function berlin(Request $request)
    {
106
        $link = "";
107
        $password = "";
Dominik Hebeler's avatar
Dominik Hebeler committed
108
        if ($request->filled('eingabe')) {
109 110
            $password = getenv('berlin');
            $password = md5($request->input('eingabe') . " -host:userpage.fu-berlin.de" . $password);
111
            $link = "/meta/meta.ger3?eingabe=" . $request->input('eingabe') . " -host:userpage.fu-berlin.de&focus=web&password=" . $password . "&encoding=utf8&lang=all&site=fu-berlin.de&quicktips=off&out=results-with-style";
112 113 114 115 116 117
        }
        return view('berlin')
            ->with('title', 'Testseite für die FU-Berlin')
            ->with('link', $link)
            ->with('password', $password);
    }
Dominik Hebeler's avatar
Dominik Hebeler committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

    public function testTor()
    {
        if ($this->IsTorExitPoint()) {
            die(var_dump("Willkommen Tor"));
        } else {
            die(var_dump("Willkommen Normal"));
        }
    }

    private function IsTorExitPoint()
    {
        if (gethostbyname($this->ReverseIPOctets($_SERVER['REMOTE_ADDR']) . "." . $_SERVER['SERVER_PORT'] . "." . $this->ReverseIPOctets($_SERVER['SERVER_ADDR']) . ".ip-port.exitlist.torproject.org") == "127.0.0.2") {
            return true;
        } else {
            return false;
        }
    }
    private function ReverseIPOctets($inputip)
    {
        $ipoc = explode(".", $inputip);
        return $ipoc[3] . "." . $ipoc[2] . "." . $ipoc[1] . "." . $ipoc[0];
    }

142
}