Exemplo n.º 1
0
Arquivo: Log.php Projeto: nabble/ajde
 /**
  * @param Throwable $exception
  */
 public static function logException($exception)
 {
     $type = Ajde_Exception_Handler::getTypeDescription($exception);
     $level = Ajde_Exception_Handler::getExceptionLevelMap($exception);
     $channel = Ajde_Exception_Handler::getExceptionChannelMap($exception);
     $trace = strip_tags(Ajde_Exception_Handler::trace($exception, Ajde_Exception_Handler::EXCEPTION_TRACE_ONLY));
     Ajde_Log::_($exception->getMessage(), $channel, $level, $type, sprintf('%s on line %s', $exception->getFile(), $exception->getLine()), $trace);
 }
Exemplo n.º 2
0
 public function compress()
 {
     $compressed = $this->minify($this->_contents);
     if (CssMin::hasErrors()) {
         $errors = CssMin::getErrors();
         Ajde_Log::log(var_export($errors, true));
     }
     return $compressed;
 }
Exemplo n.º 3
0
 public function beforeInvoke($allowed = [])
 {
     if (!in_array($this->getAction(), array_merge($this->_allowedActions, $allowed)) && $this->hasAccess() === false) {
         Ajde_Log::_('ACL firewall hit', Ajde_Log::CHANNEL_SECURITY, Ajde_Log::LEVEL_INFORMATIONAL, implode(PHP_EOL, Ajde_Acl::$log));
         Ajde::app()->getRequest()->set('message', trans('You may not have the required permission to view this page'));
         Ajde::app()->getResponse()->dieOnCode(Ajde_Http_Response::RESPONSE_TYPE_UNAUTHORIZED);
     } else {
         return true;
     }
 }
Exemplo n.º 4
0
 protected function ping($url, $port = 80, $timeout = 6)
 {
     $host = parse_url($url, PHP_URL_HOST);
     $fsock = fsockopen($host, $port, $errno, $errstr, $timeout);
     if (!$fsock) {
         Ajde_Log::log('Ping for ' . $host . ':' . $port . ' (timeout=' . $timeout . ') failed');
         return false;
     } else {
         return true;
     }
 }
Exemplo n.º 5
0
 public function publish()
 {
     $tweet = $this->getTitle();
     if ($url = $this->getUrl()) {
         $tweet = substr($tweet, 0, 140 - strlen($url) - 5) . '... ' . $url;
     }
     while ($curlength = iconv_strlen(htmlspecialchars($tweet, ENT_QUOTES, 'UTF-8'), 'UTF-8') >= 140) {
         $tweet = substr($tweet, 0, -1);
     }
     try {
         $response = $this->_twitter->post('statuses/update', ['status' => $tweet]);
     } catch (Exception $e) {
         Ajde_Log::log($response);
         Ajde_Exception_Log::logException($e);
         return false;
     }
     if ($response->user && $response->user->id && $response->id_str) {
         return sprintf('http://twitter.com/%s/status/%s', $response->user->id, $response->id_str);
     } else {
         return false;
     }
 }
Exemplo n.º 6
0
 public function updatePayment()
 {
     // PHP 4.1
     // read the post from PayPal system and add 'cmd'
     $req = 'cmd=_notify-validate';
     $post = Ajde_Http_Request::globalPost();
     foreach ($post as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     // post back to PayPal system to validate
     $header = '';
     $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= 'Content-Length: ' . strlen($req) . "\r\n\r\n";
     $fp = fsockopen($this->isSandbox() ? 'ssl://www.sandbox.paypal.com' : 'ssl://www.paypal.com', 443, $errno, $errstr, 30);
     // assign posted variables to local variables
     $item_name = issetor($post['item_name']);
     $item_number = issetor($post['item_number']);
     $payment_status = issetor($post['payment_status']);
     $payment_amount = issetor($post['mc_gross']);
     $payment_currency = issetor($post['mc_currency']);
     $txn_id = issetor($post['txn_id']);
     $receiver_email = issetor($post['receiver_email']);
     $payer_email = issetor($post['payer_email']);
     $secret = issetor($post['custom']);
     $transaction = new TransactionModel();
     $changed = false;
     if (!$fp) {
         // HTTP ERROR
     } else {
         fwrite($fp, $header . $req);
         while (!feof($fp)) {
             $res = fgets($fp, 1024);
             if (strcmp($res, 'VERIFIED') == 0) {
                 if (!$transaction->loadByField('secret', $secret)) {
                     Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
                     return ['success' => false, 'transaction' => null];
                 }
                 // check the payment_status is Completed
                 // accept Pending from PayPal (eChecks?)
                 $acceptPending = true;
                 if ($payment_status == 'Completed' || $acceptPending && $payment_status == 'Pending') {
                     $details = 'AMOUNT: ' . $payment_amount . PHP_EOL . 'CURRENCY: ' . $payment_currency . PHP_EOL . 'PAYER_EMAIL: ' . $payer_email . PHP_EOL . 'RECEIVER_EMAIL: ' . $receiver_email . PHP_EOL . 'TXN_ID: ' . $txn_id . PHP_EOL;
                     // update transaction only once
                     if ($transaction->payment_status != 'completed') {
                         $transaction->payment_details = $details;
                         $transaction->payment_status = 'completed';
                         $transaction->save();
                         $changed = true;
                     }
                     // Write pending to Log
                     if ($payment_status == 'Pending') {
                         Ajde_Log::log('Status is Pending but accepting now. PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
                     }
                     return ['success' => true, 'changed' => $changed, 'transaction' => $transaction];
                 } else {
                     if ($transaction->payment_status != 'refused') {
                         $transaction->payment_status = 'refused';
                         $transaction->save();
                         $changed = true;
                     }
                     Ajde_Log::log('Status is not Completed but ' . $payment_status . ' for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
                 }
                 // check that txn_id has not been previously processed
                 // check that receiver_email is your Primary PayPal email
                 // check that payment_amount/payment_currency are correct
                 // process payment
             } else {
                 if (strcmp($res, 'INVALID') == 0) {
                     if (!$transaction->loadByField('secret', $secret)) {
                         // secret not found anyway
                         $transaction = null;
                         Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
                     } else {
                         // log for manual investigation
                         if ($transaction->payment_status != 'refused') {
                             $transaction->payment_status = 'refused';
                             $transaction->save();
                             $changed = true;
                         }
                         Ajde_Log::log('Validation failed for PayPal payment with txn id ' . $txn_id);
                     }
                 }
             }
         }
         fclose($fp);
     }
     return ['success' => false, 'changed' => $changed, 'transaction' => $transaction];
 }
Exemplo n.º 7
0
 public function updatePayment()
 {
     // PHP 4.1
     // read the post from PayPal system and add 'cmd'
     $req = 'cmd=_notify-validate';
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     // post back to PayPal system to validate
     $header = '';
     $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
     $fp = fsockopen($this->isSandbox() ? 'ssl://www.sandbox.paypal.com' : 'ssl://www.paypal.com', 443, $errno, $errstr, 30);
     // assign posted variables to local variables
     $item_name = $_POST['item_name'];
     $item_number = $_POST['item_number'];
     $payment_status = $_POST['payment_status'];
     $payment_amount = $_POST['mc_gross'];
     $payment_currency = $_POST['mc_currency'];
     $txn_id = $_POST['txn_id'];
     $receiver_email = $_POST['receiver_email'];
     $payer_email = $_POST['payer_email'];
     Ajde_Model::register('shop');
     $secret = $_POST['custom'];
     $transaction = new TransactionModel();
     if (!$transaction->loadByField('secret', $secret)) {
         Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
     }
     if (!$fp) {
         // HTTP ERROR
     } else {
         fputs($fp, $header . $req);
         while (!feof($fp)) {
             $res = fgets($fp, 1024);
             if (strcmp($res, "VERIFIED") == 0) {
                 // check the payment_status is Completed
                 if ($payment_status == 'Completed') {
                     $details = 'AMOUNT: ' . $payment_amount . PHP_EOL . 'CURRENCY: ' . $payment_currency . PHP_EOL . 'PAYER_EMAIL: ' . $payer_email . PHP_EOL . 'RECEIVER_EMAIL: ' . $receiver_email . PHP_EOL . 'TXN_ID: ' . $txn_id . PHP_EOL;
                     $transaction->payment_details = $details;
                     $transaction->payment_status = 'completed';
                     $transaction->save();
                 } else {
                     $transaction->payment_status = 'refused';
                     $transaction->save();
                     Ajde_Log::log('Status is not Completed but ' . $payment_status . ' for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret);
                 }
                 // check that txn_id has not been previously processed
                 // check that receiver_email is your Primary PayPal email
                 // check that payment_amount/payment_currency are correct
                 // process payment
             } else {
                 if (strcmp($res, "INVALID") == 0) {
                     // log for manual investigation
                     $transaction->payment_status = 'refused';
                     $transaction->save();
                     Ajde_Log::log('Validation failed for PayPal payment with txn id ' . $txn_id);
                 }
             }
         }
         fclose($fp);
     }
 }
Exemplo n.º 8
0
 public static function logException(Exception $exception)
 {
     $trace = strip_tags(Ajde_Exception_Handler::trace($exception, Ajde_Exception_Handler::EXCEPTION_TRACE_LOG));
     Ajde_Log::log($trace);
 }
Exemplo n.º 9
0
 /**
  * @param TransactionItemModel $transaction
  *
  * @deprecated use mailUser
  *
  * @throws Ajde_Core_Exception_Deprecated
  * @throws Ajde_Exception
  * @throws Exception
  * @throws phpmailerException
  */
 public function mailUserDeprecated(TransactionItemModel $transaction)
 {
     throw new Ajde_Core_Exception_Deprecated();
     $mailer = new Ajde_Mailer();
     $mailer->IsMail();
     // use php mail()
     $mailer->AddAddress($transaction->email, $transaction->name);
     $mailer->From = config('app.email');
     $mailer->FromName = config('app.title');
     $mailer->Subject = 'Your order';
     $mailer->Body = '<h2>Your order on ' . config('app.title') . '</h2>' . '<p>Thank you for shopping with us. We will ship your items as soon as possible if you chose for delivery.<br/>' . 'To view the status of your order, please click this link:</p>' . '<p><a href=\'' . config('app.rootUrl') . 'shop/transaction:view/' . $transaction->secret . '.html\'>View your order status</a></p>' . '<p>Hope to welcome you again soon on <a href=\'' . config('app.rootUrl') . '\'>' . config('app.title') . '</a></p>';
     $mailer->IsHTML(true);
     if (!$mailer->Send()) {
         Ajde_Log::log('Mail to ' . $transaction->email . ' failed');
     }
 }
Exemplo n.º 10
0
 private function sendRequest($request, $asRaw = false)
 {
     if (self::$_debug) {
         Ajde_Log::log('INPUT DATA: ' . var_export($request, true));
     }
     $xml = self::buildXML($request);
     $url = fsockopen('ssl://' . self::$_api_url, 443);
     if ($url === false) {
         return ['success' => false, 'response' => 'iDeal foutmelding: Kan niet verbinden'];
     }
     $data = $xml->saveXML();
     $length = strlen($data);
     if (self::$_debug) {
         Ajde_Log::log('REQUEST XML: ' . var_export($data, true));
     }
     $post = 'GET ' . self::$_api_path . " HTTP/1.0\n";
     $post .= "Content-Length: {$length}\n";
     $post .= "Content-Type: text/xml\n";
     $post .= "Connection: Close\n\n";
     $post .= "{$data}\n\n";
     fwrite($url, $post);
     $response = '';
     while (!feof($url)) {
         $response .= fgets($url, 1024);
     }
     fclose($url);
     if (self::$_debug) {
         Ajde_Log::log('RESPONSE DATA: ' . var_export($response, true));
     }
     if ($asRaw) {
         $contentLenght = strpos($response, PHP_EOL . 'Content-Length:') + 1;
         $nextLine = strpos($response, PHP_EOL, $contentLenght);
         $result = trim(substr($response, $nextLine));
     } else {
         if (strpos($response, '<?xml') === false) {
             return ['success' => false, 'response' => 'iDeal foutmelding: Ongeldig antwoord'];
         }
         $start = strpos($response, '<?xml');
         $response = substr($response, $start);
         $xml = new DOMDocument();
         $xml->loadXML($response);
         $result = simplexml_import_dom($xml);
         if (self::$_debug) {
             Ajde_Log::log('OUTPUT XML: ' . var_export($result, true));
         }
         if ($result->error) {
             return ['success' => false, 'response' => "iDeal foutmelding ({$result->error}): " . self::getError($result->error)];
         }
     }
     return ['success' => true, 'response' => $result];
 }
Exemplo n.º 11
0
 public function updatePayment()
 {
     $payment = false;
     $mollie = new Mollie_API_Client();
     $mollie->setApiKey($this->getApiKey());
     $transaction = new TransactionModel();
     $changed = false;
     // see if we are here for the webhook or user return url
     $mollie_id = Ajde::app()->getRequest()->getPostParam('id', false);
     // from webhook
     $order_id = Ajde::app()->getRequest()->getParam('order_id', false);
     // from user request
     if (!$mollie_id && $order_id) {
         // load from order_id
         $transaction->loadByField('secret', $order_id);
         $mollie_id = $transaction->payment_providerid;
         try {
             $payment = $mollie->payments->get($mollie_id);
         } catch (Mollie_API_Exception $e) {
             Ajde_Exception_Log::logException($e);
             $payment = false;
         }
     } else {
         if ($mollie_id) {
             // laod from mollie transaction id
             try {
                 $payment = $mollie->payments->get($mollie_id);
                 $order_id = $payment->metadata->order_id;
                 $transaction->loadByField('secret', $order_id);
             } catch (Mollie_API_Exception $e) {
                 Ajde_Exception_Log::logException($e);
                 $payment = false;
             }
         }
     }
     if (!$payment || !$mollie_id || !$order_id || !$transaction->hasLoaded()) {
         Ajde_Log::log('Could not find transaction for Mollie payment for mollie id ' . $mollie_id . ' and transaction secret ' . $order_id);
         return ['success' => false, 'changed' => $changed, 'transaction' => $transaction];
     }
     // what to return?
     $paid = false;
     $payment_details = $payment->details;
     if (is_object($payment_details) || is_array($payment_details)) {
         $payment_details = json_encode($payment_details);
     }
     // save details
     $details = 'PAYMENT STATUS: ' . (string) $payment->status . PHP_EOL . 'PAYMENT AMOUNT: ' . (string) $payment->amount . PHP_EOL . 'PAYMENT AT: ' . (string) $payment->paidDatetime . PHP_EOL . 'CANCELLED AT: ' . (string) $payment->cancelledDatetime . PHP_EOL . 'EXPIRED AT: ' . (string) $payment->expiredDatetime . PHP_EOL . 'PAYER DETAILS: ' . (string) $payment_details;
     $transaction->payment_details = $details;
     switch ($payment->status) {
         case 'open':
             if ($transaction->payment_status != 'requested') {
                 $transaction->payment_status = 'requested';
                 $transaction->save();
                 $changed = true;
             }
             break;
         case 'paidout':
         case 'paid':
             $paid = true;
             // update transaction only once
             if ($transaction->payment_status != 'completed') {
                 $transaction->paid();
                 $changed = true;
             }
             break;
         case 'cancelled':
             // update transaction only once
             if ($transaction->payment_status != 'cancelled') {
                 $transaction->payment_status = 'cancelled';
                 $transaction->save();
                 $changed = true;
             }
             break;
         case 'expired':
             // update transaction only once
             if ($transaction->payment_status != 'refused') {
                 $transaction->payment_status = 'refused';
                 $transaction->save();
                 $changed = true;
             }
             break;
     }
     return ['success' => $paid, 'changed' => $changed, 'transaction' => $transaction];
 }
Exemplo n.º 12
0
Arquivo: Curl.php Projeto: nabble/ajde
 /**
  * @param string      $url
  * @param bool|string $toFile
  * @param bool|array  $header
  *
  * @throws Exception
  *
  * @return string
  */
 public static function get($url, $toFile = false, $header = false)
 {
     $output = false;
     $debug = false;
     if ($debug) {
         Ajde_Log::_('cURL URL', Ajde_Log::CHANNEL_INFO, Ajde_Log::LEVEL_INFORMATIONAL, $url);
     }
     try {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         // The URL to fetch. This can also be set when initializing a session with curl_init().
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         // TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
         // The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
         // The maximum number of seconds to allow cURL functions to execute.
         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36');
         // The contents of the "User-Agent: " header to be used in a HTTP request.
         curl_setopt($ch, CURLOPT_ENCODING, '');
         // The contents of the "Accept-Encoding: " header. This enables decoding of the response. Supported encodings are "identity", "deflate", and "gzip". If an empty string, "", is set, a header containing all supported encoding types is sent.
         curl_setopt($ch, CURLOPT_AUTOREFERER, true);
         // TRUE to automatically set the Referer: field in requests where it follows a Location: redirect.
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         // FALSE to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2).
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
         curl_setopt($ch, CURLOPT_COOKIEFILE, '');
         if ($toFile !== false) {
             // @TODO We need SAFE_MODE to be off
             if (ini_get('safe_mode')) {
                 throw new Ajde_Exception('SAFE_MODE must be off when downloading files');
             }
             $fp = fopen($toFile, 'w+');
             //This is the file where we save the information
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
             curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
             // The maximum amount of HTTP redirections to follow. Use this option alongside CURLOPT_FOLLOWLOCATION.
             curl_setopt($ch, CURLOPT_TIMEOUT, 300);
             curl_setopt($ch, CURLOPT_FILE, $fp);
             // write curl response to file
             curl_setopt($ch, CURLINFO_HEADER_OUT, true);
             if ($header) {
                 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
             }
             curl_exec($ch);
             fclose($fp);
             $output = true;
             $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
             if ($debug) {
                 $verbose = curl_getinfo($ch);
             }
             if ($debug) {
                 Ajde_Log::_('cURL result', Ajde_Log::CHANNEL_INFO, Ajde_Log::LEVEL_INFORMATIONAL, var_export($verbose, true));
             }
             curl_close($ch);
             if (substr($http_status, 0, 1 == '4')) {
                 return false;
             }
         } else {
             // Not possible in SAFE_MODE
             // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set).
             // curl_setopt($ch, CURLOPT_HEADER, false);		// TRUE to include the header in the output.
             // curl_setopt($ch, CURLOPT_MAXREDIRS, 10);		// The maximum amount of HTTP redirections to follow. Use this option alongside CURLOPT_FOLLOWLOCATION.
             $output = self::_curl_exec_follow($ch, 10, false);
             if ($debug) {
                 $verbose = curl_getinfo($ch);
             }
             if ($debug) {
                 Ajde_Log::_('cURL result', Ajde_Log::CHANNEL_INFO, Ajde_Log::LEVEL_INFORMATIONAL, var_export($verbose, true));
             }
             curl_close($ch);
         }
     } catch (Exception $e) {
         throw $e;
     }
     return $output;
 }
Exemplo n.º 13
0
 public function log($ident, $module)
 {
     Ajde_Log::_('Language key [' . $module . '.' . $ident . '] not found for language [' . Ajde_Lang::getInstance()->getLang() . ']', Ajde_Log::CHANNEL_INFO, Ajde_Log::LEVEL_DEBUG, '', '', strip_tags(Ajde_Exception_Handler::trace(new Ajde_Exception(), Ajde_Exception_Handler::EXCEPTION_TRACE_ONLY)));
 }