Skip to content
Snippets Groups Projects
FeedbackController.php 4.27 KiB
Newer Older
<?php
namespace App\Http\Controllers;

use App\Feedback;
use Barryvdh\Debugbar\Facade;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;

class FeedbackController extends Controller
{

    public function __construct()
    {
        // Uncomment to require authentication
        $this->middleware('admin');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            // 'name' => 'required|string|regex:/^[a-zA-Z0-9\s-\.]+$/|max:255'
        ]);
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view("feedback.index", ["feedback" => Feedback::all()->sortBy("created_at")]);
    }

    /**
     * Show the form for creating a new resource.
     * We use the same view for create and update => provide an empty Feedback.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view("feedback.edit", ["feedback" => new Feedback()]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validator($request->all())->validate();

        $feedback = new Feedback();
        // $feedback->name = $request->name;
        $feedback->save();
        return redirect(action('FeedbackController@index'));
    }

    /**
     * Display the specified resource.
     *
     * @param  Feedback $feedback     * @return \Illuminate\Http\Response
     */
    public function show(Feedback $feedback)
    {
        Facade::info($feedback);
        return view("feedback.show", ["feedback" => $feedback]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  Feedback $feedback     * @return \Illuminate\Http\Response
     */
    public function edit(Feedback $feedback)
    {
        return view("feedback.edit", ["feedback" => $feedback]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  Feedback $feedback     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Feedback $feedback)
    {
        $this->validator($request->all())->validate();

        // $feedback->name = $request->name;
        $feedback->save();
        return redirect(action('FeedbackController@index'));
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        Feedback::find($id)->delete();
        return redirect(action("FeedbackController@index"));
    }
    public function populate()
        $instance = Mark::get();
        $data = $instance->findEvidence("agregation.wowa");
        //var_dump($data);

        foreach ($data as $el) {
            $this->addFeedbackInDatabase($el);
        }
        return redirect(action("FeedbackController@index"));
    }
    private function addFeedbackInDatabase($element)
    {
        set_time_limit(120);
Alex's avatar
Alex committed
        $file = fopen('./../webshell_expected_new_version.csv', 'r');
        $feedback = new Feedback();
        $feedback->report_id = $element->id;
        $i = 0;
        while (($line = fgetcsv($file)) !== false) {
            if ($line[0] == $element->subject['id']) {
                //var_dump($line[1]);
                if ($line[1] == "0") {
                    //var_dump($el->subject['name']);
                    $feedback->is_true_alert = false;
                } elseif ($line[1] == "1") {
                    //var_dump($el->subject['name']);
                    $feedback->is_true_alert = true;
        fclose($file);
        $feedback->user_id = Auth::id();
        $feedback->save();

    public function dropFeedbacks()
    {
        Feedback::truncate();
        return redirect(action("FeedbackController@index"));
    }