/** * Display the dashboard. * * @return Response */ public function showDashboard() { // Statistics $sent_email_nb = Email::where('user_id', Auth::id())->withTrashed()->count(); $active_email_nb = Email::where('user_id', Auth::id())->count(); $last_email = Email::with('email_trackings')->where('user_id', Auth::id())->get()->last(); if ($last_email) { $last_email_read_nb = $last_email->email_trackings->count(); } else { $last_email_read_nb = 0; } return View::make('admin.dashboard', array('sent_email_nb' => $sent_email_nb, 'active_email_nb' => $active_email_nb, 'last_email_read_nb' => $last_email_read_nb, 'last_email' => $last_email)); }
/** * Store a newly created resource in storage. * * @return Response */ public function track($id, $uniqid) { $email = Email::where('id', $id)->where('uniqid', $uniqid)->first(); // If email is found if ($email) { // Get data $ip = $_SERVER['REMOTE_ADDR']; $host = gethostbyaddr($ip); $user_agent = $_SERVER['HTTP_USER_AGENT']; $country = @geoip_country_name_by_name($ip); if (!$country) { $country = null; } $validator = EmailTracking::validate(array('ip' => $ip, 'host' => $host, 'user_agent' => $user_agent, 'country' => $country)); if ($validator->passes()) { $tracking = new EmailTracking(); $tracking->ip = $ip; $tracking->host = $host; $tracking->user_agent = $user_agent; $tracking->country = $country; $tracking->save(); $email->email_trackings()->save($tracking); // Attach tracking to email // Send pushbullet notification $user = $email->user; if ($user->pushbullet && $ip != env('IGNORE_IP', 'null')) { $pushbullet = new PHPushbullet($user->pushbullet_api_key); $message = 'Your email "' . $email->title . '" has been read by ' . $ip . ' (' . $host . ' - ' . $country . ').'; $pushbullet->device($user->pushbullet_device)->note($email->title, $message); } // Return pixel $response = Response::make(File::get(Config::get('mail_tracker.pixel_file'))); $response->header('Content-Type', 'image/gif'); return $response; } // Otherwise, log error abort(500, 'Something went wrong...'); } // Otherwise, exit abort(404, 'Email not found!'); }
/** * Generate file containing signature with tracking pixel * @param $id * @param $uniqid * @return mixed */ public function generate_signature($id, $uniqid) { $email = Email::where('user_id', Auth::id())->where('id', $id)->where('uniqid', $uniqid)->first(); // If email is found if ($email) { // Generate file $response = Response::make('<img src="' . action('EmailTrackingController@track', array($id, $uniqid)) . '" height="3" width="3" />'); $response->header('Content-Type', 'application/octet-stream'); return $response; } // Otherwise, exit abort(500, 'Email not found!'); }