/** * {@inheritDoc} **/ public function getIssues($statuses, $offset = 0, $limit = 500, $sort = 'id') { $statusIds = $this->convertStatusesToIds($statuses); $chunkLimit = 100; $offsetDelta = 5; if ($chunkLimit > 100) { throw new \LogicException('Redmine only supports fetching of 100 issues per query'); } if ($chunkLimit <= $offsetDelta) { throw new \LogicException('Limit can not be less than offsetDelta'); } $params = $this->predefinedParams + ['status_id' => implode('|', $statusIds), 'sort' => $sort, 'limit' => $chunkLimit, 'offset' => $offset]; $isEnough = false; $result = []; do { $chunk = $this->client->get($this->baseUrl, $params); if (isset($chunk['issues']) && count($chunk['issues']) > 0) { foreach ($chunk['issues'] as $issue) { if (isset($result[$issue['id']])) { continue; } $branches = []; $date = '20990101'; foreach ($issue['custom_fields'] as $customField) { $matches = []; if (!empty($customField['value']) && preg_match("/Branch \\((.*)\\)/", $customField['name'], $matches)) { $branch = trim($customField['value']); $branches[$matches[1]] = $branch; $currentDate = substr($branch, 4, 8); //get date from the branch if ($currentDate < $date) { $date = $currentDate; } } } $result[$issue['id']] = ['id' => $issue['id'], 'author' => isset($issue['author']['name']) ? $issue['author']['name'] : 'UNKNOWN', 'asignee' => isset($issue['assigned_to']['name']) ? $issue['assigned_to']['name'] : 'UNKNOWN', 'subject' => $issue['subject'], 'status' => $this->statusIdsFlipped[$issue['status']['id']], 'date' => empty($branches) ? null : date('Y-m-d', strtotime($date)), 'branches' => $branches, 'issueTracker' => $this]; } if ($offset === 0) { $offset = $chunkLimit - $offsetDelta; } else { $offset += $chunkLimit; } $params['offset'] = $offset; } if (count($chunk['issues']) !== $chunkLimit) { $isEnough = true; } elseif (count($result) >= $limit - $offsetDelta) { $isEnough = true; } } while (!$isEnough); return $result; }
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'; } }
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>"; } }
/** * 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; }