private static function sendData($data) { $pest = new \PestJSON(Functions::BASE_URL); try { $pest->post('/import/orders.json', $data); } catch (\Pest_Json_Decode $e) { // can be safely ignored } }
public function getTokens($options) { // Generate merchant hash code $hash = \HashGenerator::generate($this->veritrans->merchant_id, $this->veritrans->merchant_hash_key, $this->veritrans->order_id); // populate parameters for the post request $data = array('version' => $this->veritrans->version, 'merchant_id' => $this->veritrans->merchant_id, 'merchanthash' => $hash, 'order_id' => $this->veritrans->order_id, 'billing_different_with_shipping' => $this->veritrans->billing_different_with_shipping, 'required_shipping_address' => $this->veritrans->required_shipping_address, 'email' => $this->veritrans->email, 'first_name' => $this->_sanitize($this->veritrans->first_name, 'name'), 'last_name' => $this->_sanitize($this->veritrans->last_name, 'name'), 'postal_code' => $this->_sanitize($this->veritrans->postal_code, 'postalCode'), 'address1' => $this->_sanitize($this->veritrans->address1, 'address'), 'address2' => $this->_sanitize($this->veritrans->address2, 'address'), 'city' => $this->_sanitize($this->veritrans->city, 'city'), 'country_code' => $this->_sanitize($this->veritrans->country_code, 'countryCode'), 'phone' => $this->_sanitize($this->veritrans->phone, 'phone'), 'finish_payment_return_url' => $this->veritrans->finish_payment_return_url, 'unfinish_payment_return_url' => $this->veritrans->unfinish_payment_return_url, 'error_payment_return_url' => $this->veritrans->error_payment_return_url); if ($this->veritrans->required_shipping_address && $this->veritrans->billing_different_with_shipping) { $data = array_merge($data, array('shipping_first_name' => $this->_sanitize($this->veritrans->shipping_first_name, 'name'), 'shipping_last_name' => $this->_sanitize($this->veritrans->shipping_last_name, 'name'), 'shipping_address1' => $this->_sanitize($this->veritrans->shipping_address1, 'address'), 'shipping_address2' => $this->_sanitize($this->veritrans->shipping_address2, 'address'), 'shipping_city' => $this->_sanitize($this->veritrans->shipping_city, 'city'), 'shipping_country_code' => $this->_sanitize($this->veritrans->shipping_country_code, 'countryCode'), 'shipping_postal_code' => $this->_sanitize($this->veritrans->shipping_postal_code, 'postalCode'), 'shipping_phone' => $this->_sanitize($this->veritrans->shipping_phone, 'phone'))); } else { if ($this->veritrans->required_shipping_address && !$this->veritrans->billing_different_with_shipping) { $data = array_merge($data, array('shipping_first_name' => $this->_sanitize($this->veritrans->first_name, 'name'), 'shipping_last_name' => $this->_sanitize($this->veritrans->last_name, 'name'), 'shipping_address1' => $this->_sanitize($this->veritrans->address1, 'address'), 'shipping_address2' => $this->_sanitize($this->veritrans->address2, 'address'), 'shipping_city' => $this->_sanitize($this->veritrans->city, 'city'), 'shipping_country_code' => $this->_sanitize($this->veritrans->country_code, 'countryCode'), 'shipping_postal_code' => $this->_sanitize($this->veritrans->postal_code, 'postalCode'), 'shipping_phone' => $this->_sanitize($this->veritrans->phone, 'phone'))); } } $optional_features = array('enable_3d_secure', 'bank', 'installment_terms', 'promo_bins', 'point_banks', 'payment_methods', 'installment_banks'); foreach ($optional_features as $feature) { if (!is_null($this->veritrans->{$feature})) { $data[$feature] = $this->veritrans->{$feature}; } } // Populate items $data['repeat_line'] = 0; foreach ($this->veritrans->items as $item) { $item_id[] = $this->_sanitize($item['item_id'], 'itemId'); $item_name1[] = $this->_sanitize($item['item_name1'], 'itemName'); $item_name2[] = $this->_sanitize($item['item_name2'], 'itemName'); $price[] = $this->_sanitize($item['price'], 'price'); $quantity[] = $item['quantity']; $data['repeat_line']++; } $data['item_id'] = $item_id; $data['item_name1'] = $item_name1; $data['item_name2'] = $item_name2; $data['price'] = $price; $data['quantity'] = $quantity; // Call Veritrans API try { $pest = new \PestJSON(''); $result = $pest->post(self::REQUEST_KEY_URL, $data); } catch (Exception $e) { throw $e; } // Check result if (!empty($result['token_merchant'])) { // OK return $result; } else { // Veritrans doesn't return tokens $this->veritrans->errors = $result['errors']; return false; } }
function webcheck() { try { //Connect to internal webservice $pest = new PestJSON('http://127.0.0.1:5380'); $result = $pest->get('/api/v1.0/status'); } catch (Exception $e) { return '<img style="vertical-align: middle;" src="/images/red_button.png"> Status: OFFLINE'; } if ($result['status'] == 'ERROR') { return '<img style="vertical-align: middle;" src="/images/yellow_button.png"> Status: ERROR'; } elseif ($result['status'] == 'GOOD') { return '<img style="vertical-align: middle;" src="/images/green_button.png"> Status: ONLINE'; } }
public function __construct($base_url = DEV_URL) { parent::__construct($base_url); //$this->mode = $this->content = array(); $this->cart = array(); }
/** * Connect to ARI. * * @param string $address Example ws://localhost:8088/ari/events?api_key=username:password&app=stasis_app_name */ public function connect($address) { $components = parse_url($address); $host = $components['host']; $port = $components['port']; $path = $components['path']; $query = $components['query']; $queryParts = []; parse_str($query, $queryParts); $this->stasisApplicationName = $queryParts['app']; $apiKey = $queryParts['api_key']; list($username, $password) = explode(':', $apiKey); $this->endpoint = new PestJSON('http://' . $host . ':' . $port . dirname($path)); $this->endpoint->setupAuth($username, $password, 'basic'); $this->wsClient = new WebSocket($address, $this->eventLoop, $this->logger); $this->wsClient->on("message", function (WebSocketMessage $rawMessage) { $message = new Message($rawMessage->getData()); $eventType = '\\phparia\\Events\\' . $message->getType(); if (class_exists($eventType)) { $event = new $eventType($this, $rawMessage->getData()); } else { $this->logger->warn("Event: '{$eventType}' not implemented"); // @todo Create a generic event for any that are not implemented return; } // Emit the specific event (just to get it back to where it came from) if ($event instanceof IdentifiableEventInterface) { $this->logger->notice("Emitting ID event: {$event->getEventId()}"); $this->wsClient->emit($event->getEventId(), array('event' => $event)); } // Emit the general event $this->logger->notice("Emitting event: {$message->getType()}"); $this->wsClient->emit($message->getType(), array('event' => $event)); }); }
function webstatus() { //Connect to internal webservice try { //Connect to internal webservice $pest = new PestJSON('http://127.0.0.1:5380'); $result = $pest->get('/api/v1.0/status'); } catch (Exception $e) { $error_msg = $e->getMessage(); $error_class = get_class($e); return "<p><font color=\"red\"><strong>Internal web service error: {$error_class} - {$error_msg}</strong></font></p>"; } if ($result['status'] == 'ERROR') { $error_msg = $result['error']; return "<p><font color=\"red\"><strong>ERROR: {$error_msg}</strong></font></p>"; } elseif ($result['status'] == 'GOOD') { return "<p><strong>System status: Online</strong></p>"; } }
/** * {@inheritDoc} **/ public function changeStatus($id, $status, $comment = '') { $statusId = $this->convertStatusToId($status); $params = ['issue' => ['status_id' => $statusId, 'notes' => '<pre>' . $comment . '</pre>']]; try { $this->client->put("/issues/{$id}.json", $params); } catch (\Exception $ex) { return false; } return true; }
/** * Request a token from the OAuth server * * @param string $code An authorization code provided by the OAuth server * @param string $tokenType Type of token being requested (IDENTITY_TOKEN|API_TOKEN) * * @return void Updates session variables * * @throws OAuthNegotiator_Exception TOKEN_RESPONSE if a token no token is received or on any other uanticipated response from the OAuth server **/ private function requestToken($code, $tokenType) { $authApi = new PestJSON("{$_SESSION[self::SESSION][self::OAUTH_ENDPOINT]}"); try { $response = $authApi->post('token', array(self::CLIENT_ID => $_SESSION[self::SESSION][self::CLIENT_ID], self::REDIRECT_URI => $_SESSION[self::SESSION][self::REDIRECT_URI], self::STATE => self::$SCOPES[$tokenType][self::TOKEN_PROVIDED], self::CLIENT_SECRET => $_SESSION[self::SESSION][self::CLIENT_SECRET], self::CODE => $code)); } catch (Pest_ServerError $e) { echo $e->getMessage(); exit; } if ($response) { if (isset($response['access_token'])) { $_SESSION[self::SESSION][self::TOKEN] = $response['access_token']; return true; } else { throw new OAuthNegotiator_Exception('Access token not received', OAuthNegotiator_Exception::TOKEN_RESPONSE); } } else { throw new OAuthNegotiator_Exception('Unexpected OAuth response', OAuthNegotiator_Exception::TOKEN_RESPONSE); } }
} //Update login user if ($_POST['login_user'] != $login_user) { $sth = $dbcore->prepare("UPDATE EMAIL SET LOGIN_USER = ? WHERE ID = '0'"); $sth->bindParam(1, $_POST['login_user']); $sth->execute(); $updates .= '"Login User" '; } // Update auth password if ($_POST["password"] != "nochange" && strlen($_POST["password"]) > 0) { // do passwords match ? if ($_POST["password"] != $_POST["password2"]) { throw new Exception('Passwords do not match!'); } //Connect to internal webservice $pest = new PestJSON('http://127.0.0.1:5380'); $authhash = $pest->post('/api/v1.0/crypto/encrypt/', array('string' => $_POST["password"])); // insert into DB $sth = $dbcore->prepare("UPDATE EMAIL SET LOGIN_PASS = ? WHERE ID = '0'"); $sth->bindParam(1, $authhash['result']); $sth->execute(); $updates .= '"Login User Password" '; } //Reset vars to new (or keep as old) values // If exception happens on any item new values // will get thrown out (never makes it here) $enabled = $_POST['enabled']; $sender = $_POST['sender']; $sender_title = $_POST['sender_title']; $recipients = $_POST['recipients']; $subject = $_POST['subject'];
public static function pageSlurp() { require_once CART66_PATH . "/models/Pest.php"; require_once CART66_PATH . "/models/PestJSON.php"; $page_id = Cart66Common::postVal('page_id'); $page = get_page($page_id); $slurp_url = get_permalink($page->ID); $html = false; $job_id = $slurp_url; if (wp_update_post(array('ID' => $page->ID, 'post_status' => 'publish'))) { $access_key = Cart66Setting::getValue('mijireh_access_key'); $rest = new PestJSON(MIJIREH_CHECKOUT); $rest->setupAuth($access_key, ''); $data = array('url' => $slurp_url, 'page_id' => $page->ID, 'return_url' => add_query_arg('task', 'mijireh_page_slurp', $slurp_url)); try { $response = $rest->post('/api/1/slurps', $data); $job_id = $response['job_id']; } catch (Pest_Unauthorized $e) { header('Bad Request', true, 400); die; } } else { $job_id = 'did not update post successfully'; } echo $job_id; die; }
/** * Update or Add Let's Encrypt * @param string $host The hostname (MUST BE A VALID FQDN) * @param boolean $staging Whether to use the staging server or not * @return boolean True if success, false if not */ public function updateLE($host, $countryCode = 'US', $state = 'Wisconsin', $staging = false) { $countryCode = !empty($countryCode) ? $countryCode : 'US'; $state = !empty($state) ? $state : 'Wisconsin'; $location = $this->PKCS->getKeysLocation(); $logger = new Certman\Logger(); $host = basename($host); $needsgen = false; $certfile = $location . "/" . $host . "/cert.pem"; if (!file_exists($certfile)) { // We don't have a cert, so we need to request one. $needsgen = true; } else { // We DO have a certificate. $certdata = openssl_x509_parse(file_get_contents($certfile)); // If it expires in less than a month, we want to renew it. $renewafter = $certdata['validTo_time_t'] - 86400 * 30; if (time() > $renewafter) { // Less than a month left, we need to renew. $needsgen = true; } } //check freepbx.org first if ($needsgen) { $basePathCheck = "/.freepbx-known"; if (!file_exists($this->FreePBX->Config->get("AMPWEBROOT") . $basePathCheck)) { $mkdirok = @mkdir($this->FreePBX->Config->get("AMPWEBROOT") . $basePathCheck, 0777); if (!$mkdirok) { throw new \Exception("Unable to create directory " . $this->FreePBX->Config->get("AMPWEBROOT") . $basePathCheck); } } $token = bin2hex(openssl_random_pseudo_bytes(16)); $pathCheck = $basePathCheck . "/" . $token; file_put_contents($this->FreePBX->Config->get("AMPWEBROOT") . $pathCheck, $token); $pest = new \PestJSON('http://mirror1.freepbx.org'); $pest->curl_opts[CURLOPT_FOLLOWLOCATION] = true; $thing = $pest->get('/lechecker.php', array('host' => $host, 'path' => $pathCheck, 'token' => $token)); if (empty($thing)) { throw new \Exception("No valid response from http://mirror1.freepbx.org"); } if (!$thing['status']) { throw new \Exception($thing['message']); } @unlink($this->FreePBX->Config->get("AMPWEBROOT") . $pathCheck); } //Now check let's encrypt if ($needsgen) { $le = new \Analogic\ACME\Lescript($location, $this->FreePBX->Config->get("AMPWEBROOT"), $logger); if ($staging) { $le->ca = 'https://acme-staging.api.letsencrypt.org'; } $le->countryCode = $countryCode; $le->state = $state; $le->initAccount(); $le->signDomains(array($host)); } if (file_exists($location . "/" . $host)) { copy($location . "/" . $host . "/private.pem", $location . "/" . $host . ".key"); //webserver.key copy($location . "/" . $host . "/chain.pem", $location . "/" . $host . "-ca-bundle.crt"); //ca-bundle.crt copy($location . "/" . $host . "/cert.pem", $location . "/" . $host . ".crt"); //webserver.crt $key = file_get_contents($location . "/" . $host . ".key"); $cert = file_get_contents($location . "/" . $host . ".crt"); $bundle = file_get_contents($location . "/" . $host . "-ca-bundle.crt"); file_put_contents($location . "/" . $host . ".pem", $key . "\n" . $cert . "\n" . $bundle); //should the chain be in here?? chmod($location . "/" . $host . ".crt", 0600); chmod($location . "/" . $host . ".key", 0600); chmod($location . "/" . $host . ".pem", 0600); chmod($location . "/" . $host . "-ca-bundle.crt", 0600); } return true; }
public function pullOrder($order_number) { $access_key = Cart66Setting::getValue('mijireh_access_key'); $rest = new PestJSON(MIJIREH_CHECKOUT); $rest->setupAuth($access_key, ''); $order_data = $rest->get('/api/1/orders/' . $order_number); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] GETTING MIJIREH ORDER: " . print_r($order_data, true)); return $order_data; }
private function send($endpoint, $operation, $request) { $pest = new PestJSON($this->url); $pest->setupAuth($this->username, $this->password); $pest->curl_opts[CURLOPT_FOLLOWLOCATION] = false; // Not supported on hosts running safe_mode! $pest->curl_opts[CURLOPT_HTTPHEADER] = "Content-Type: application/json"; $pest->curl_opts[CURLOPT_USERAGENT] = $this->USER_AGENT . " (v" . $this->CLIENT_VERSION . ")"; $response = ""; try { // Send request to rest service switch ($operation) { case $this->OP_PUT: $response = $pest->put("/{$endpoint}", $request); break; case $this->OP_GET: $response = $pest->get("/{$endpoint}", $request); break; case $this->OP_POST: $response = $pest->post("/{$endpoint}", $request); break; case $this->OP_DELETE: $response = $pest->delete("/{$endpoint}", $request); break; } } catch (Exception $e) { echo "Caught exception when sending request : " . $e->getMessage(); } return $response; }
} else { $error = "Login Failed."; } } else { // other user login // What auth mode is set ? $sth = $dbh->prepare("SELECT MODE FROM AUTH"); $sth->execute(); $mode = $sth->fetchColumn(); switch ($mode) { case "ad": // AD auth mode // Make ad call to API require_once '/opt/f5backup/ui/include/PestJSON.php'; $data = array('user' => $_POST["username"], 'passwd' => $_POST["password"]); $pest = new PestJSON('http://127.0.0.1:5380'); $auth = $pest->post('/api/v1.0/adauth/authenticate/', $data); // Valid login if ($auth['result'] == "True") { // Get auth groups $sth = $dbh->query("SELECT STRING,ROLE FROM AUTHGROUPS ORDER BY ORD"); $sth->execute(); $groups = $sth->fetchAll(); //lowercase memberOf array $membership = array_map("strtolower", $auth['memberOf']); //loop through list until match is found foreach ($groups as $i) { $string = strtolower($i['STRING']); // If auth group is in user's group membership allow login if (preg_grep("/{$string}/", $membership)) { $login = 1;
/** * @return Pest rest client used to speak to the Sweet Tooth Platform * */ protected function getRestClient() { if ($this->_restClient) { return $this->_restClient; } $baseUrl = $this->getApiBaseUrl(); $pest = new PestJSON($baseUrl); $pest->setupAuth($this->apiKey, $this->apiSecret); $this->_restClient = $pest; return $this->_restClient; }