Ejemplo n.º 1
0
 public function push($token, $data, $params)
 {
     try {
         $url = 'https://' . $this->config['host'];
         $fields = array('registration_ids' => array($token), 'data' => array_merge($data, ['data' => $params]));
         $headers = array('Authorization: key=' . $this->config['key'], 'Content-Type: application/json');
         // Open connection
         $ch = curl_init();
         // Set the url, number of POST vars, POST data
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         // Disabling SSL Certificate support temporarly
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
         // Execute post
         $result = curl_exec($ch);
         if ($result === FALSE) {
             Log::error('Curl failed: ' . curl_error($ch));
             return false;
         }
         // Close connection
         curl_close($ch);
         return true;
     } catch (Exception $e) {
         Log::error($e);
         return false;
     }
 }
Ejemplo n.º 2
0
 /**
  * Listens for and stores PayPal IPN requests.
  *
  * @throws InvalidIpnException
  *
  * @return IpnOrder
  */
 public function getOrder()
 {
     $ipnMessage = null;
     $listenerBuilder = new ListenerBuilder();
     if ($this->getEnvironment() == 'sandbox') {
         $listenerBuilder->useSandbox();
         // use PayPal sandbox
     }
     $listener = $listenerBuilder->build();
     $listener->onVerified(function (MessageVerifiedEvent $event) {
         $ipnMessage = $event->getMessage();
         Log::info('IPN message verified - ' . $ipnMessage);
         $this->order = $this->store($ipnMessage);
     });
     $listener->onInvalid(function (MessageInvalidEvent $event) {
         $report = $event->getMessage();
         Log::warning('Paypal returned invalid for ' . $report);
     });
     $listener->onVerificationFailure(function (MessageVerificationFailureEvent $event) {
         $error = $event->getError();
         // Something bad happend when trying to communicate with PayPal!
         Log::error('Paypal verification error - ' . $error);
     });
     $listener->listen();
     return $this->order;
 }
Ejemplo n.º 3
0
 /**
  * Create a user and return response
  *
  * @param array $data
  * @param CreatorListenerInterface $listener
  * @return mixed
  */
 public function create(array $data, CreatorListenerInterface $listener)
 {
     $valid = $this->userValidator->isValid($data);
     if (!$valid) {
         return $listener->onCreateFail($this->userValidator->getMessages());
     }
     $groups = empty($data['roles']) ? [] : $data['roles'];
     $data = $this->filterData($data);
     if ($this->auth->check()) {
         $user = $this->auth->user();
         $data['creator_id'] = $user->id;
     }
     try {
         $data['activated'] = true;
         $user = $this->userRepo->create($data);
         $this->events->fire('user.created', array($user));
         if (Sentry::getUser()->hasAnyAccess(['user.change_groups'])) {
             $this->groupRepo->addGroupsToUser($user, $groups);
         }
         return $listener->onCreateSuccess();
     } catch (InvalidArgumentException $e) {
         Log::error($e->getMessage());
         return $listener->onCreateFail([Lang::get('messages.operation_error')]);
     }
 }
 /**
  * Update the profile based on the form submission
  * @param ProfileUpdateRequest $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update(ProfileUpdateRequest $request)
 {
     $contact = $this->getContact();
     $contact->setName($request->input('name'));
     $contact->setRole($request->input('role'));
     $contact->setEmailAddress($request->input('email_address'));
     try {
         $work = $contact->getPhoneNumber(PhoneNumber::WORK);
         $work->setNumber(preg_replace("/[^0-9]/", "", $request->input('work_phone')));
         $contact->setPhoneNumber($work);
         $mobile = $contact->getPhoneNumber(PhoneNumber::MOBILE);
         $mobile->setNumber(preg_replace("/[^0-9]/", "", $request->input('mobile_phone')));
         $contact->setPhoneNumber($mobile);
         $home = $contact->getPhoneNumber(PhoneNumber::HOME);
         $home->setNumber(preg_replace("/[^0-9]/", "", $request->input('home_phone')));
         $contact->setPhoneNumber($home);
         $fax = $contact->getPhoneNumber(PhoneNumber::FAX);
         $fax->setNumber(preg_replace("/[^0-9]/", "", $request->input('fax')));
         $contact->setPhoneNumber($fax);
     } catch (Exception $e) {
         return redirect()->back()->withErrors($e->getMessage());
     }
     $contactController = new ContactController();
     try {
         $contactController->updateContact($contact);
     } catch (Exception $e) {
         Log::error($e->getMessage());
         return redirect()->back()->withErrors(trans("errors.failedToUpdateProfile"));
     }
     $this->clearProfileCache();
     return redirect()->action("ProfileController@show")->with('success', trans("profile.profileUpdated"));
 }
Ejemplo n.º 5
0
 /**
  * Report and log an exception.
  *
  * @author Morten Rugaard <*****@*****.**>
  * @author Rasmus Ebbesen <*****@*****.**>
  *
  * @param  Exception $e
  * @throws Exception
  */
 public function report(Exception $e)
 {
     try {
         if (class_exists('\\Nodes\\Bugsnag\\ServiceProvider')) {
             if (\Nodes\Bugsnag\ServiceProvider::VERSION == '1.0') {
                 if ($e instanceof NodesException && $e->getReport()) {
                     app('nodes.bugsnag')->notifyException($e, $e->getMeta(), $e->getSeverity());
                 } elseif (!$e instanceof NodesException) {
                     app('nodes.bugsnag')->notifyException($e, null, 'error');
                 }
             } elseif (\Nodes\Bugsnag\ServiceProvider::VERSION == '2.0') {
                 if ($e instanceof NodesException && $e->getReport()) {
                     app('nodes.bugsnag')->notifyException($e, function (\Bugsnag\Report $report) use($e) {
                         $report->setMetaData($e->getMeta(), true);
                         $report->setSeverity($e->getSeverity());
                     });
                 } elseif (!$e instanceof NodesException) {
                     app('nodes.bugsnag')->notifyException($e, function (\Bugsnag\Report $report) {
                         $report->setSeverity('error');
                     });
                 }
             }
         }
     } catch (\Throwable $e) {
         // Do nothing
     }
     Log::error($e);
 }
Ejemplo n.º 6
0
 /**
  * Report or log an exception.
  *
  * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
  *
  * @param  \Exception  $e
  * @return void
  */
 public function report(Exception $e)
 {
     if ($this->shouldReport($e)) {
         Log::error($e);
     }
     parent::report($e);
 }
Ejemplo n.º 7
0
 protected function downloadFileInWindowsNT(TFFile $file)
 {
     $client = new Client();
     try {
         $response = $client->get($file->source, ['verify' => false]);
     } catch (\Exception $e) {
         $error = 'TFDownloader: Downloading file failed, url is %s, msg is %s.';
         $error = sprintf($error, $file->source, $e->getMessage());
         Log::error($error);
         $file->state = 'error';
         $file->error = $error;
         $file->save();
         return;
     }
     if ($response->getStatusCode() == 200) {
         $location = 'file/' . $file->name;
         Storage::put($location, $response->getBody());
         $file->state = 'downloaded';
         $file->location = $location;
         $file->save();
         return;
     } else {
         $error = 'TFDownloader: Bad HTTP response code in downloading videos, url is %s, status code is %d.';
         $error = sprintf($error, $file->source, $response->getStatusCode());
         Log::error($error);
         $file->state = 'error';
         $file->error = $error;
         $file->save();
         return;
     }
 }
Ejemplo n.º 8
0
 static function e($arg, $trace = false)
 {
     Log::error(print_r($arg, true));
     if ($trace) {
         Log::error(print_r(debug_backtrace()));
     }
 }
Ejemplo n.º 9
0
 /**
  * 客户端接收数据
  * 状态码说明  (1 交易完成 0 交易失败)
  */
 public function receive($result)
 {
     $result = $this->filterParameter($result);
     $return['status'] = 0;
     if ($result) {
         $return = array();
         $v_oid = trim($result['v_oid']);
         $v_pmode = trim($result['v_pmode']);
         $v_pstatus = trim($result['v_pstatus']);
         $v_pstring = trim($result['v_pstring']);
         $v_amount = trim($result['v_amount']);
         $v_moneytype = trim($result['v_moneytype']);
         $remark1 = isset($result['remark1']) ? trim($result['remark1']) : '';
         $remark2 = isset($result['remark2']) ? trim($result['remark2']) : '';
         $v_md5str = trim($result['v_md5str']);
         $md5string = strtoupper(md5($v_oid . $v_pstatus . $v_amount . $v_moneytype . $this->_config['key']));
         if ($v_md5str == $md5string) {
             $return['oid'] = $v_oid;
             $return['data'] = $v_pmode;
             $return['note'] = '支付方式:' . $v_pmode . '支付结果信息:' . $v_pstring;
             if ($v_pstatus == '20') {
                 $return['status'] = 1;
             } else {
                 Log::error(date('m-d H:i:s') . '| chinabank order=' . $v_oid . ' status=' . $v_pstatus);
             }
         } else {
             Log::error(date('m-d H:i:s') . '| chinabank  order=' . $v_oid . ' 非法sign');
         }
     } else {
         Log::error(date('m-d H:i:s') . '| chinabank no return!' . "\r\n");
     }
     return $return;
 }
Ejemplo n.º 10
0
 /**
  * @param \Onyx\Destiny\Objects\Hash $hash
  * @param string $index
  * @return bool
  */
 public static function saveImageLocally($hash, $index = 'extra')
 {
     // BUG: Can't use variable object indexes implicitly
     // $hash->{$index} should work but doesn't
     // map the index explicitly with the attributes dumped into $bug
     $bug = $hash->getAttributes();
     $url = "https://bungie.net" . $bug[$index];
     $name = $index != 'extra' ? '_bg' : null;
     $name = $hash->hash . $name;
     // Make sure we aren't trying to save something that isn't an image
     // We only need this check because we cheat and store all hash related objects
     // in one table. This means we have crazy cheats to get things done.
     if (strlen($bug[$index]) < 5) {
         return false;
     }
     $location = public_path('uploads/thumbs/');
     $filename = $name . "." . pathinfo($bug[$index], PATHINFO_EXTENSION);
     if (File::isFile($location . $filename)) {
         return true;
     }
     if ($hash instanceof Hash) {
         $manager = new ImageManager();
         try {
             $img = $manager->make($url);
             $img->save($location . $filename);
         } catch (NotReadableException $e) {
             Log::error('Could not download: ' . $url);
         }
         return true;
     }
 }
Ejemplo n.º 11
0
 public static function getBadRequstView($msg)
 {
     if (!empty($msg)) {
         Log::error($msg);
     }
     return response('错误的输入,3秒后返回。' . '<script>setTimeout(function(){history.back()},3000)' . '</script>', 400);
 }
Ejemplo n.º 12
0
 public function sendError()
 {
     $config = config($this->confPath);
     $output = '';
     $file = $this->e->getFile();
     $line = $this->e->getLine();
     $trace = $this->e->getTrace();
     try {
         if (file_exists($file)) {
             $f = file($file);
             $line = (int) $line;
             for ($i = $line - 5; $i <= $line + 5; $i++) {
                 if (isset($f[$i])) {
                     $output .= $i + 1 . ": " . $f[$i];
                 }
             }
         } else {
             if (is_array($trace) && !empty($trace)) {
                 $elem = current($trace);
                 if (is_array($elem)) {
                     if (isset($elem['file']) && isset($elem['line'])) {
                         $file = file($elem['file']);
                         $line = (int) $elem['line'];
                         for ($i = $line - 5; $i <= $line + 5; $i++) {
                             if (isset($file[$i])) {
                                 $output .= $i + 1 . ": " . $file[$i];
                             }
                         }
                     }
                 }
             }
         }
     } catch (\Exception $e) {
         Log::error('Email:Error:Reporting: ' . $e->getMessage());
     }
     try {
         $request = array();
         $request['fullUrl'] = request()->fullUrl();
         $request['input_get'] = isset($_GET) ? $_GET : null;
         $request['input_post'] = isset($_POST) ? $_POST : null;
         $request['session'] = session()->all();
         $request['cookie'] = request()->cookie();
         $request['file'] = request()->file();
         $request['header'] = request()->header();
         $request['server'] = request()->server();
         $request['output'] = $output;
         $request['json'] = request()->json();
         $request['request_format'] = request()->format();
         $request['error'] = $this->e->getTraceAsString();
         $request['subject_line'] = $this->e->getMessage();
         $request['error_line'] = $line;
         $request['error_file'] = $file;
         $request['class_name'] = get_class($this->e);
         $request['reported_by'] = isset($config['reported_by']) ? $config['reported_by'] : 'LaravelErrorMailer';
         $data = ['tempData' => $request];
         $this->exec($data);
     } catch (Exception $e) {
         Log::error('Email:Error:Reporting: ' . $e->getMessage());
     }
 }
Ejemplo n.º 13
0
 public function update($data)
 {
     $response = new ApiResponse();
     $status = 200;
     $mission = Mission::find(\Request::get('id'));
     if ($mission == null) {
         $response->status = 'error';
         $response->message = ['id' => '', 'code' => 'mission_not_found', 'description' => 'The mission was not found'];
         $status = 400;
     } else {
         $mission = $this->sanitize($data, $mission);
         try {
             $this->radicalIntegrationManager->updateMission($mission);
         } catch (RadicalApiException $e) {
             Log::error($e);
             //For now ingore, see [CIT-380]
             //                $response->status = 'error';
             //                $response->message = $e->getMessage();
             //                $status = 500;
         }
         $mission->save();
         $response->status = 'success';
         $response->message = $mission->id;
     }
     return \Response::json($response, $status);
 }
Ejemplo n.º 14
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     Log::info('infoメッセージ');
     Log::debug('debugメッセージ');
     Log::warning('warningメッセージ');
     Log::error('errorメッセージ');
     return view('welcome');
 }
Ejemplo n.º 15
0
 /**
  * Handle the event.
  *
  * @param  ErrorOccurredEvent $event
  *
  */
 public function handle(ErrorOccurredEvent $event)
 {
     Log::error('Event occurred: ' . $event->statusCode);
     $data['statusCode'] = $event->statusCode;
     $subject = $event->statusCode . ' exception occurred in ' . $this->appName . ' project';
     $headers = $event->headers['user-agent'][0];
     Artisan::call('emails:send', ['type' => $this->type, 'name' => $this->emailToName, 'email' => $this->emailToAddress, '--subject' => $subject, '--caption' => $event->message, '--fullUrl' => $event->fullUrl, '--headers' => $headers, '--parentClass' => $event->parentClass, '--exceptionTrace' => $event->exception]);
 }
Ejemplo n.º 16
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     if (\Request::ajax()) {
         return view('ajax.aircraftShow', ['aircraft' => Aircraft::find($id)]);
     } else {
         Log::error('AircraftController@show no ajax request');
         abort(403, 'Unauthorized action.');
     }
 }
Ejemplo n.º 17
0
 private function tweet($message)
 {
     try {
         $this->twitter->postTweet(['status' => $message]);
         Log::info('Successfully tweeted: ' . $message);
     } catch (Exception $e) {
         Log::error($e->getMessage());
     }
 }
Ejemplo n.º 18
0
 /**
  * Blindly creates a new result key/value row
  *
  * @param string $resultId An identifier to associate with this result. A job or process id for instance
  * @param array  $result   The "result" to publish (i.e. associate value with key $resultId)
  *
  * @return JobResult
  */
 public function publishResult($resultId, $result = [])
 {
     try {
         return JobResult::create(['result_id_text' => $resultId, 'result_text' => $result]);
     } catch (\Exception $_ex) {
         /** @noinspection PhpUndefinedMethodInspection */
         Log::error('exception creating job result row: ' . $_ex->getMessage());
         return false;
     }
 }
Ejemplo n.º 19
0
 public function token(Guard $auth)
 {
     try {
         $accessToken = $auth->facebookAuth(Input::get('code'));
         return response()->json(['user' => ['name' => Auth::user()->name, 'facebookId' => Auth::user()->facebookId, 'id' => Auth::user()->id], 'token_type' => 'bearer', 'access_token' => $accessToken]);
     } catch (\Exception $e) {
         Log::error("Exception occured, code: " . $e->getCode() . " with message: " . $e->getMessage());
     }
     return response('Bad request.', 400);
 }
Ejemplo n.º 20
0
 /**
  * Obtain the user information from Google.
  *
  * @return Response
  */
 public function handleProviderCallback()
 {
     try {
         $user = Socialite::with('google2')->user();
     } catch (ClientException $e) {
         Log::error($e->getResponse()->getBody()->getContents());
     }
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect('/');
 }
Ejemplo n.º 21
0
 /**
  * @param $text
  */
 public function post($text)
 {
     $text = urlencode($text);
     $url = "https://slack.com/api/chat.postMessage?token={$this->apiKey}&channel=%23{$this->channel}&text={$text}";
     $result = file_get_contents($url);
     $resultObject = json_decode($result);
     if ($resultObject->ok === false) {
         Log::error($url);
         Log::error($result);
     }
 }
Ejemplo n.º 22
0
 private function resetPin()
 {
     $sv = new StoredValue();
     $resetResponse = $sv->changePin($this->card_number);
     if ($resetResponse->getErrorCode() != 0) {
         Log::error('unable to reset pin');
         //discard or retry
     }
     Log::notice('pin after reset while sending purchase mail ' . $resetResponse->getCardPin());
     return $resetResponse->getCardPin();
 }
 /**
  * Send a raw message with Mandrill.
  *
  * @param MandrillMailMessage $message The message to send.
  *
  * @return bool True if email sent, false if sending message rejected, or invalid message.
  */
 public function send(MandrillMailMessage $message)
 {
     $result = MandrillMailer::send($message->constructMessageForMandrill());
     if (is_array($result) && count($result) > 0) {
         self::$info = reset($result);
         if (in_array(self::$info['status'], ['rejected', 'invalid'])) {
             Log::error(sprintf('Could not send email message to %s, reject_reason: %s', self::$info['email'], self::$info['reject_reason']));
             return false;
         }
     }
     return true;
 }
 public function healthcheck($checkType)
 {
     try {
         // fire a check event
         //   for other handlers
         Event::fire('consul-health.http.check', $checkType);
     } catch (Exception $e) {
         Log::error('Health check failed: ' . $e->getMessage());
         return new Response('failed', 500);
     }
     return new Response('ok', 200);
 }
Ejemplo n.º 25
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function handle()
 {
     $tag = $this->filesystem->get(base_path() . '/VERSION.md');
     $includeFile = base_path('resources/views/includes/page') . '/version.blade.php';
     $time = date('Y-m-d H:i:s');
     $content = '{{--GENERATED: ' . $time . '--}}' . PHP_EOL . 'version: ' . $tag . PHP_EOL;
     try {
         $this->filesystem->put($includeFile, $content);
     } catch (\Exception $e) {
         Log::error('Error while trying to create blade version file: ' . $e->getMessage());
     }
 }
Ejemplo n.º 26
0
 public function sendNotification($destination, $view, $data)
 {
     try {
         $servicePhone = $this->getOption('twilio.phone_number');
         $phone = array_get($destination, 'phone');
         $content = View::make($view, $data);
         $sms_message = $this->client->account->sms_messages->create($servicePhone, $phone, $content->render());
     } catch (\Exception $e) {
         Log::error($e->getMessage());
         throw $e;
     }
 }
Ejemplo n.º 27
0
 private function setCssfile()
 {
     preg_match_all("'<link rel=\"stylesheet\" href=\"(.*?)\">'si", $this->html, $files);
     if (isset($files[1]) && !empty($files[1])) {
         $allCssFiles = $files[1];
         if (empty($allCssFiles[0])) {
             Log::error('AsyncCss: Css file can not be parsed - Cachekey:' . $this->cacheKey);
             return false;
         }
         $this->cssfile = $allCssFiles[0];
         return true;
     }
 }
Ejemplo n.º 28
0
 /**
  * Delete file and thumbs.
  *
  * @param string $fieldname
  * @param Model  $model
  *
  * @return void
  */
 private function deleteFile($fieldname, Model $model)
 {
     $filename = $model->getOriginal($fieldname);
     if (empty($filename)) {
         return;
     }
     $file = '/uploads/' . $model->getTable() . '/' . $filename;
     try {
         Croppa::delete($file);
         File::delete(public_path() . $file);
     } catch (Exception $e) {
         Log::error($e->getMessage());
     }
 }
Ejemplo n.º 29
0
 protected function runCmd($cmd)
 {
     $output = [];
     $returnVal = 0;
     exec($cmd, $output, $returnVal);
     if ($returnVal == 0) {
         return true;
     } else {
         $error = 'TFZipper: zip failed, cmd is "%s", returnVal is %s';
         $error = sprintf($error, $cmd, $returnVal);
         Log::error($error);
         return false;
     }
 }
Ejemplo n.º 30
0
 /**
  * Send broadcast data
  *
  * @param string $jsonDataToSend JSON'ified string we'll receive from ZeroMQ
  */
 public function broadcastData($jsonDataToSend)
 {
     $entryData = json_decode($jsonDataToSend, true);
     $subscribedTopics = $this->getSubscribedTopics();
     if (empty($entryData['topic_id'])) {
         Log::error('There is no topic_id key in the enty data.');
         return;
     }
     if (isset($subscribedTopics[$entryData['topic_id']])) {
         $topic = $subscribedTopics[$entryData['topic_id']];
         // re-send the data to all the clients subscribed to that category
         $topic->broadcast($entryData);
     }
 }