Exemplo n.º 1
0
 public static function execute($parameters)
 {
     $curl = curl_init($parameters['server']['scheme'] . '://' . $parameters['server']['host'] . $parameters['server']['path'] . (isset($parameters['server']['query']) ? '?' . $parameters['server']['query'] : ''));
     $curl_options = array(CURLOPT_PORT => $parameters['server']['port'], CURLOPT_HEADER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_FORBID_REUSE => true, CURLOPT_FRESH_CONNECT => true, CURLOPT_FOLLOWLOCATION => false);
     if (!empty($parameters['header'])) {
         $curl_options[CURLOPT_HTTPHEADER] = $parameters['header'];
     }
     if (!empty($parameters['certificate'])) {
         $curl_options[CURLOPT_SSLCERT] = $parameters['certificate'];
     }
     if ($parameters['method'] == 'post') {
         $curl_options[CURLOPT_POST] = true;
         $curl_options[CURLOPT_POSTFIELDS] = $parameters['parameters'];
     }
     curl_setopt_array($curl, $curl_options);
     $result = curl_exec($curl);
     $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     curl_close($curl);
     list($headers, $body) = explode("\r\n\r\n", $result, 2);
     if ($http_code == 301 || $http_code == 302) {
         if (!isset($parameters['redir_counter']) || $parameters['redir_counter'] < 6) {
             if (!isset($parameters['redir_counter'])) {
                 $parameters['redir_counter'] = 0;
             }
             $matches = array();
             preg_match('/(Location:|URI:)(.*?)\\n/i', $headers, $matches);
             $redir_url = trim(array_pop($matches));
             $parameters['redir_counter']++;
             $redir_params = array('url' => $redir_url, 'method' => $parameters['method'], 'redir_counter', $parameters['redir_counter']);
             $body = \osCommerce\OM\Core\HttpRequest::getResponse($redir_params, 'Curl');
         }
     }
     return $body;
 }
 public static function execute()
 {
     $OSCOM_Cache = Registry::get('Cache');
     $result = array('entries' => array());
     if ($OSCOM_Cache->read('coreupdate-availablepackages', 360)) {
         $versions = $OSCOM_Cache->getCache();
     } else {
         $versions = HttpRequest::getResponse(array('url' => 'http://www.oscommerce.com/version/online_merchant/3', 'method' => 'get'));
         $OSCOM_Cache->write($versions);
     }
     $versions_array = explode("\n", $versions);
     $counter = 0;
     foreach ($versions_array as $v) {
         $v_info = explode('|', $v);
         if (version_compare(OSCOM::getVersion(), $v_info[0], '<')) {
             $result['entries'][] = array('key' => $counter, 'version' => $v_info[0], 'date' => DateTime::getShort(DateTime::fromUnixTimestamp(DateTime::getTimestamp($v_info[1], 'Ymd'))), 'announcement' => $v_info[2], 'update_package' => isset($v_info[3]) ? $v_info[3] : null);
             $counter++;
         }
     }
     usort($result['entries'], function ($a, $b) {
         return version_compare($a['version'], $b['version'], '>');
     });
     $result['total'] = count($result['entries']);
     return $result;
 }
 public static function execute($version = null)
 {
     if (empty($version)) {
         $link = CoreUpdate::getAvailablePackageInfo('update_package');
     } else {
         $versions = CoreUpdate::getAvailablePackages();
         foreach ($versions['entries'] as $v) {
             if ($v['version'] == $version) {
                 $link = $v['update_package'];
                 break;
             }
         }
     }
     $response = HttpRequest::getResponse(array('url' => $link, 'parameters' => 'check=true'));
     return file_put_contents(OSCOM::BASE_DIRECTORY . 'Work/CoreUpdate/update.phar', $response);
 }
 protected function doExpressCheckoutPayment($parameters)
 {
     if (MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_TRANSACTION_SERVER == 'Live') {
         $api_url = 'https://api-3t.paypal.com/nvp';
     } else {
         $api_url = 'https://api-3t.sandbox.paypal.com/nvp';
     }
     $params = array('VERSION' => $this->_api_version, 'METHOD' => 'DoExpressCheckoutPayment', 'PAYMENTACTION' => MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_TRANSACTION_METHOD == 'Sale' || strlen(MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_API_USERNAME) < 1 ? 'Sale' : 'Authorization', 'BUTTONSOURCE' => 'osCommerce30_Default_EC');
     if (strlen(MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_API_USERNAME) > 0) {
         $params['USER'] = MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_API_USERNAME;
         $params['PWD'] = MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_API_PASSWORD;
         $params['SIGNATURE'] = MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_API_SIGNATURE;
     } else {
         $params['SUBJECT'] = MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_SELLER_ACCOUNT;
     }
     if (is_array($parameters) && !empty($parameters)) {
         $params = array_merge($params, $parameters);
     }
     $post_string = '';
     foreach ($params as $key => $value) {
         $post_string .= $key . '=' . urlencode(utf8_encode(trim($value))) . '&';
     }
     $post_string = substr($post_string, 0, -1);
     $response = HttpRequest::getResponse(array('url' => $api_url, 'parameters' => $post_string));
     $response_array = array();
     parse_str($response, $response_array);
     if ($response_array['ACK'] != 'Success' && $response_array['ACK'] != 'SuccessWithWarning') {
         $this->sendDebugEmail();
     }
     return $response_array;
 }
Exemplo n.º 5
0
    public static function initialize() {
      header('Content-Type: application/json; charset=utf-8');
      header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
      header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
      header('Cache-Control: no-store, no-cache, must-revalidate');
      header('Cache-Control: post-check=0, pre-check=0', false);
      header('Pragma: no-cache');

      try {
        if ( empty($_GET) ) {
          throw new \Exception(self::STATUS_NO_MODULE);
        } elseif ( count($_GET) < 3 ) {
          throw new \Exception(self::STATUS_NO_ACTION);
        }

        $site = HTML::sanitize(basename(key(array_slice($_GET, 1, 1, true))));
        $application = HTML::sanitize(basename(key(array_slice($_GET, 2, 1,  true))));

        if ( !OSCOM::siteExists($site) ) {
          throw new \Exception(self::STATUS_CLASS_NONEXISTENT);
        }

        OSCOM::setSite($site);

        if ( !OSCOM::siteApplicationExists($application) ) {
          throw new \Exception(self::STATUS_CLASS_NONEXISTENT);
        }

        OSCOM::setSiteApplication($application);

        ob_start( function($buffer) {
          foreach ( headers_list() as $h ) {
            if ( stripos($h, 'Location:') !== false ) {
              header_remove('Location');

              \osCommerce\OM\Core\HttpRequest::setResponseCode(403);

              $buffer = json_encode(array('rpcStatus' => constant('osCommerce\\OM\\Core\\Site\\RPC\\Controller::STATUS_REDIRECT_DETECTED')));

              break;
            }
          }

          return $buffer;
        });

        call_user_func(array('osCommerce\\OM\\Core\\Site\\' . $site . '\\Controller', 'initialize'));

        ob_end_flush();

        if ( !call_user_func(array('osCommerce\\OM\\Core\\Site\\' . $site . '\\Controller', 'hasAccess'), $application)) {
          throw new \Exception(self::STATUS_NO_ACCESS);
        }

        $rpc_called = false;

        $rpc = array('RPC');

        for ( $i = 3, $n = count($_GET); $i < $n; $i++ ) {
          $subrpc = HTML::sanitize(basename(key(array_slice($_GET, $i, 1, true))));

          if ( self::siteApplicationRPCExists(implode('\\', $rpc) . '\\' . $subrpc) ) {
            call_user_func(array('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Application\\' . OSCOM::getSiteApplication() . '\\' . implode('\\', $rpc) . '\\' . $subrpc, 'execute'));

            $rpc[] = $subrpc;

            $rpc_called = true;
          } else {
            break;
          }
        }

        if ( $rpc_called === false ) {
          throw new \Exception(self::STATUS_NO_ACTION);
        }
      } catch ( \Exception $e ) {
        HttpRequest::setResponseCode(403);

        echo json_encode(array('rpcStatus' => $e->getMessage()));
      }

      exit;
    }