public function delete($id)
 {
     RecentActivities::createActivity("Blocked IP " . Blocking::where('id', $id)->pluck('ip_address') . " deleted by User ID:" . Auth::user()->id . " User Name:" . Auth::user()->name);
     Blocking::where('id', $id)->delete();
     Session::flash('success_msg', trans('msgs.ip_deleted_success'));
     return Redirect::to('/blocking/all');
 }
Ejemplo n.º 2
0
<?php

App::before(function ($request) {
    if (Session::has('client_ip')) {
        //check ip_address in blocking table
        $blocking = Blocking::where('ip_address', Session::get('client_ip'))->first();
        if (!empty($blocking)) {
            if ($blocking->should_block_web_access) {
                return trans('msgs.you_dont_have_website_access');
            }
            $path = $request->path();
            if ($path == "login" && $blocking->should_block_login) {
                return trans('msgs.you_dont_have_login_access');
            }
            if ($path == "customer/tickets" && $blocking->should_block_tickets) {
                return trans('msgs.you_dont_have_tickets_access');
            }
        }
    }
});
Route::filter('has_permission', function ($route, $request, $permission) {
    if (Auth::check()) {
        if (!\KodeInfo\Utilities\Utils::canViewBackend(Auth::user()->id)) {
            Auth::logout();
            Session::flush();
            Session::flash('error_msg', trans('msgs.access_denied_escalate_rights'));
            return Redirect::to('/login');
        }
        if (!Permissions::hasPermission($permission)) {
            $permission_obj = Permissions::where('key', $permission)->pluck('text');
            Session::flash('error_msg', trans('msgs.access_denied_escalate_rights', ['permission_obj' => $permission_obj]));
 public function start()
 {
     $response = [];
     $response['token'] = 0;
     if (Input::has('ip')) {
         //check ip_address in blocking table
         $blocking = Blocking::where('ip_address', Input::get('ip'))->first();
         if (!empty($blocking)) {
             if ($blocking->should_block_chat || $blocking->should_block_web_access) {
                 $response['blocked'] = 1;
                 $response['errors'] = trans('msgs.your_ip_blocked_by_admin_contact_support');
             }
         }
     } else {
         $response['blocked'] = 1;
         $response['errors'] = trans('msgs.your_ip_blocked_by_admin_contact_support');
     }
     $response['blocked'] = 0;
     $v_data = ["email" => Input::get('email'), "name" => Input::get('name'), "company_id" => Input::get('company_id'), "domain" => Input::get('domain'), "department" => Input::get('department'), "message" => Input::get('message')];
     $v_rules = ["email" => 'required|email', "name" => 'required', "company_id" => 'required', "domain" => 'required', "department" => 'required', "message" => 'required'];
     $v = Validator::make($v_data, $v_rules);
     if ($v->passes()) {
         $request_check = Company::where('id', Input::get('company_id'))->where('domain', Input::get('domain'))->get();
         if (sizeof($request_check) <= 0) {
             return $this->send(['result' => 0, 'errors' => trans('msgs.invalid_request_check_id_and_domain')]);
         }
         $company_customers = CompanyCustomers::where('company_id', Input::get('company_id'))->lists('customer_id');
         $user = null;
         if (sizeof($company_customers)) {
             $user = User::whereIn('id', $company_customers)->where('email', Input::get('email'))->first();
         }
         $operator_online = Company::operatorsOnline(Input::get('company_id'));
         $success_msg = trans('msgs.thanks_for_contacting_will_get_back');
         $response['is_online'] = $operator_online;
         $repo = new KodeInfo\Repo\MessageRepo();
         if (!empty($user) && !is_null($user)) {
             //user exists
             $count = OnlineUsers::where('user_id', $user->id)->first();
             if (sizeof($count) > 0) {
                 //user already online
                 $token = OnlineUsers::getToken();
                 if ($operator_online > 0) {
                     $response['token'] = $token;
                 }
                 $response['result'] = 1;
                 $response['user_id'] = $user->id;
                 $response['thread_id'] = $count->thread_id;
                 $response['success_msg'] = $success_msg;
                 return $this->send($response);
             } else {
                 $token = OnlineUsers::getToken();
                 $thread = $repo->createNewThread($user->id, Input::get("message"), true);
                 if ($response['is_online']) {
                     $online_user = new OnlineUsers();
                     $online_user->user_id = $user->id;
                     $online_user->thread_id = $thread['thread_id'];
                     $online_user->operator_id = 0;
                     $online_user->company_id = Input::get('company_id');
                     $online_user->department_id = Input::get('department');
                     $online_user->locked_by_operator = 0;
                     $online_user->requested_on = \Carbon\Carbon::now();
                     $online_user->token = $token;
                     $online_user->save();
                 }
                 $country = DB::table('countries')->where('countryCode', Input::get('country'))->first();
                 $geo_info = new ThreadGeoInfo();
                 $geo_info->thread_id = $thread['thread_id'];
                 $geo_info->ip_address = Input::get('ip');
                 $geo_info->country_code = Input::get('country');
                 $geo_info->country = !empty($country) ? $country->countryName : "";
                 $geo_info->provider = Input::get('provider');
                 $geo_info->current_page = Input::get('page');
                 $geo_info->all_pages = json_encode(['pages' => [Input::get('page')]]);
                 $geo_info->save();
                 if (!$response['is_online']) {
                     $this->convertToTicket($thread['thread_id'], $thread['msg_id'], $user, "", Input::get('message'), Input::get('department'), Input::get('company_id'));
                 }
                 if ($operator_online > 0) {
                     $response['token'] = $token;
                 }
                 $response['result'] = 1;
                 $response['user_id'] = $user->id;
                 $response['thread_id'] = $thread['thread_id'];
                 $response['success_msg'] = $success_msg;
                 return $this->send($response);
             }
         } else {
             $password = Str::random();
             //Is user in users table then get id and put in company-customers table
             $user = User::where('email', Input::get('email'))->first();
             if (!empty($user)) {
                 $company_customer = new CompanyCustomers();
                 $company_customer->company_id = Input::get('company_id');
                 $company_customer->customer_id = $user->id;
                 $company_customer->save();
             } else {
                 $user = $this->userManager->createUser(["name" => Input::get('name'), "email" => Input::get('email'), "password" => $password, "password_confirmation" => $password], 'customer', false);
                 $user->avatar = "/assets/images/default-avatar.jpg";
                 $user->save();
                 $user->getActivationCode();
                 $company_customer = new CompanyCustomers();
                 $company_customer->company_id = Input::get('company_id');
                 $company_customer->customer_id = $user->id;
                 $company_customer->save();
                 $this->mailer->welcome($user->email, $user->name, User::getWelcomeFields(false, $user->id, $password, $company_customer->company_id));
                 $this->mailer->activate($user->email, $user->name, User::getActivateFields(false, $user->id, $company_customer->company_id));
             }
             $token = OnlineUsers::getToken();
             $thread = $repo->createNewThread($user->id, Input::get("message"), true);
             if ($response['is_online']) {
                 $online_user = new OnlineUsers();
                 $online_user->user_id = $user->id;
                 $online_user->thread_id = $thread['thread_id'];
                 $online_user->operator_id = 0;
                 $online_user->company_id = Input::get('company_id');
                 $online_user->department_id = Input::get('department');
                 $online_user->locked_by_operator = 0;
                 $online_user->requested_on = \Carbon\Carbon::now();
                 $online_user->token = $token;
                 $online_user->save();
             }
             $country = DB::table('countries')->where('countryCode', Input::get('country'))->first();
             $geo_info = new ThreadGeoInfo();
             $geo_info->thread_id = $thread['thread_id'];
             $geo_info->ip_address = Input::get('ip');
             $geo_info->country_code = Input::get('country');
             $geo_info->country = !empty($country) ? $country->countryName : "";
             $geo_info->provider = Input::get('provider');
             $geo_info->current_page = Input::get('page');
             $geo_info->all_pages = json_encode(['pages' => [Input::get('page')]]);
             $geo_info->save();
             if (!$response['is_online']) {
                 $this->convertToTicket($thread['thread_id'], $thread['msg_id'], $user, "", Input::get('message'), Input::get('department'), Input::get('company_id'));
             }
             if ($operator_online > 0) {
                 $response['token'] = $token;
             }
             $response['result'] = 1;
             $response['user_id'] = $user->id;
             $response['thread_id'] = $thread['thread_id'];
             $response['success_msg'] = $success_msg;
             return $this->send($response);
         }
     } else {
         return $this->send(['result' => 0, 'errors' => Utils::buildMessages($v->messages()->all())]);
     }
 }