/** * 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!'); }
/** * Send a test notification * * @return Redirect */ public function sendTestNotification() { $user = User::find(Auth::id()); // If user found if ($user) { if ($user->pushbullet_api_key && $user->pushbullet_device) { // If api key and device are defined $pushbullet = new PHPushbullet($user->pushbullet_api_key); $message = 'This is a test notification from Mail Tracker'; $pushbullet->device($user->pushbullet_device)->note('Mail Tracker', $message); Session::flash('pushbullet_info', 'Test notification sent to ' . $user->pushbullet_device . '!'); } else { Session::flash('pushbullet_error', 'Please verify Pushbullet settings.'); } } // Return to user profile return Redirect::action('Admin\\AdminUserController@edit'); }
/** * pushes a report from the given account to the devices * @param $reportTitle * @param $reportBody * @param $account */ public function pushReport($reportTitle, $reportBody, $account) { $pushKeys = $this->getPushBulletKeys(); foreach ($pushKeys as $pushKey) { if ($pushKey['accounts'] == null || in_array($account, $pushKey['accounts'])) { $pushBullet = new PHPushbullet($pushKey['key']); if ($pushKey['devices'] == null) { // pushes to all of the devices foreach ($pushBullet->devices() as $device) { $pushBullet->device($device->iden)->note($reportTitle, $reportBody); } } else { // pushes to selected devices foreach ($pushKey['devices'] as $device) { $pushBullet->device($device)->note($reportTitle, $reportBody); } } } } }