/** * Initializes an Evangelist, sets the username through the APIClient and also defines values for the user. * * @param string $username username of Repo to fetch * @param APIClient APIClient $api_client interface for APIClient to interact with */ public function __construct($username, APIClient $api_client) { $this->username = $username; //Set the username $api_client->setUsername($username); //Pass api_client instance to local property $this->api_client = $api_client; //define the value/level of the user with username above $this->defineValue(); }
/** * Push an event batch to the Connect API. * @param array $batch the batch to push * @return Response */ private function pushEventBatch($batch) { $eventBatch = []; foreach ($batch as $collection => $events) { $eventBatch[$collection] = array_map(function ($eventDetails) { $event = new Event($eventDetails); return $event->getDetails(); }, $events); } return $this->client->pushEventBatch($eventBatch); }
public function getContentType() { if ($this->contentType == null and $this->filePath != null) { $this->contentType = APIClient::getMimeType($this->filePath); } return $this->contentType; }
public static function getInstance() { if (!self::$_instance instanceof self) { self::$_instance = new self(MODULE_EM_API_TOKEN, MODULE_EM_SHOP_TOKEN, EasymarketingHelper::getWebsiteURL()); } return self::$_instance; }
/** * Re-subscribes an unsibscribed member using his/her ID. * REMARK: The number of rejoins per day is limited to avoid massive rejoins and illegal usage of this method. * * @param string $id The ID of the member. * * @return string The job ID of the unjoin, see getJobStatus(). * * @throws \Exception */ public function rejoinMemberById($id) { $parameters = ['memberId' => (string) $id]; $response = $this->apiClient->doCall('rejoinMemberById', $parameters); // if response is not valid if ($response == 0) { throw new \Exception('Invalid response'); } return (string) $response; }
public function signUrl($url) { $urlParts = parse_url($url); $pathAndQuery = $urlParts['path'] . (empty($urlParts['query']) ? "" : "?" . $urlParts['query']); $signature = base64_encode(hash_hmac("sha1", APIClient::encodeURI($pathAndQuery), $this->privateKey, true)); if (substr($signature, -1) == '=') { $signature = substr($signature, 0, -1); } $url = $url . (empty($urlParts['query']) ? '?' : '&') . 'signature=' . APIClient::encodeURIComponent($signature); return $url; }
/** * Send object * This method is used to send a Transactional Message to an email address. * The response indicates whether the send was successful. * * @param string $uniqueIdentifier * @param string $securityTag * @param string $email * @param array $dyn * @param array $content * @param string $type * @param string $sendDate * @param string $uidKey * * @return string * * @throws Exception */ public function sendObject($uniqueIdentifier, $securityTag, $email, array $dyn = null, array $content = null, $type = 'INSERT_UPDATE', $sendDate = null, $uidKey = 'email') { // List of valid type $allowedTypes = ['INSERT', 'UPDATE', 'INSERT_UPDATE', 'NOTHING']; // Check if type is valid if (!in_array($type, $allowedTypes)) { throw new \Exception('Invalid type (' . $type . '), allowed values are: ' . implode(', ', $allowedTypes) . '.'); } $parameters['sendrequest'] = ['email' => (string) $email, 'encrypt' => (string) $securityTag, 'random' => (string) $uniqueIdentifier, 'senddate' => null !== $sendDate ? (int) $sendDate : time(), 'synchrotype' => (string) $type, 'uidkey' => (string) $uidKey]; // Dynamic Personalization Parameters if (null !== $dyn) { foreach ($dyn as $key => $value) { $parameters['sendrequest']['dyn'] = ['entry' => ['key' => $key, 'value' => "<![CDATA[{$value}]]"]]; } } // Content Parameters if (null !== $content) { foreach ($content as $key => $value) { $parameters['sendrequest']['content'] = ['entry' => ['key' => $key, 'value' => "<![CDATA[{$value}]]"]]; } } return (string) $this->apiClient->doCall('sendObject', $parameters); }
/** * @see CommonGLPI::getMenuContent() * * @since version 0.85 **/ static function getMenuContent() { global $CFG_GLPI; $menu = array(); if (static::canView()) { $menu['title'] = _x('setup', 'General'); $menu['page'] = '/front/config.form.php'; $menu['options']['apiclient']['title'] = APIClient::getTypeName(Session::getPluralNumber()); $menu['options']['apiclient']['page'] = '/front/config.form.php?forcetab=Config$8'; $menu['options']['apiclient']['links']['search'] = '/front/config.form.php?forcetab=Config$8'; $menu['options']['apiclient']['links']['add'] = '/front/apiclient.form.php'; } if (count($menu)) { return $menu; } return false; }
public static function getPackageInfo() { if (is_null(self::$packageInfo)) { $filename = dirname(__FILE__) . "/composer.json"; if (!file_exists($filename)) { $filename = dirname(__FILE__) . "/../composer.json"; } $json = file_get_contents($filename); $jsonArray = json_decode($json, true); self::$packageInfo = array(); if (is_array($jsonArray)) { self::$packageInfo['version'] = $jsonArray['version']; self::$packageInfo['name'] = $jsonArray['name']; $pos = strpos(self::$packageInfo['name'], "/"); if ($pos !== false) { self::$packageInfo['name'] = substr(self::$packageInfo['name'], $pos + 1); } } } return self::$packageInfo; }
* WHMCS v6 Module for HugeServer Resellers * * @author HugeServer Networks, LLC - Development Team */ include_once 'config.php'; include "functions.php"; include "api.php"; include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '../../../configuration.php'; header("Cache-Control: no-cache, must-revalidate"); $db_conn = mysql_connect($db_host, $db_username, $db_password); if (!$db_conn) { throw new Exception('Unable to connect to DB'); } $db_select = @mysql_select_db($db_name, $db_conn); if (!$db_select) { throw new Exception('Unable to select WHMCS database'); } if (!isset($_GET['pid'])) { throw new Exception('Argument missing'); } $wid = trim(ion_decrypt($_GET['pid'])); $query = "SELECT ion_sid from ion_module WHERE whmcs_sid = '{$wid}'"; $result = mysql_query($query); if (mysql_num_rows($result) < 1 || strlen($wid) > 5) { die("not found"); } $sid = mysql_fetch_array($result)[0]; $period = isset($_GET['period']) ? $_GET['period'] : 'hour'; header('Content-Type: image/PNG'); echo APIClient::serverGraph(ION_API, array('serverID' => $sid, 'period' => $period, 'title' => $_GET['title']));
function getRemarketingData() { $response = APIClient::getInstance()->performRequest('google_remarketing_code'); if ($response['status'] == 200) { xtc_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value = '" . xtc_db_input($response['data']['user_id']) . "' WHERE configuration_key = 'MODULE_EM_REMARKETING_USER_ID'"); xtc_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value = '" . xtc_db_input($response['data']['code']) . "' WHERE configuration_key = 'MODULE_EM_REMARKETING_CODE'"); } }
/** * Retrieves a banner link by its order number. * * @param string $id The ID of the banner. * @param int $order The order number. * * @return array The Dynamic Content Block link */ public function getBannerLinkByOrder($id, $order) { $parameters = ['bannerId' => (string) $id, 'order' => (string) $order]; return (array) $this->apiClient->doCall('getBannerLinkByOrder', $parameters); }
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include "../inc/includes.php"; if (!isset($_GET["id"])) { $_GET["id"] = ""; } $client = new APIClient(); if (isset($_POST["add"])) { $client->check(-1, CREATE, $_POST); $client->add($_POST); Html::back(); } else { if (isset($_POST["update"])) { $client->check($_POST["id"], UPDATE); $client->update($_POST); Html::back(); } else { if (isset($_POST["purge"])) { $client->check($_POST["id"], PURGE); $client->delete($_POST); Html::redirect($CFG_GLPI["root_doc"] . "/front/config.form.php"); } else {
/** * Register an action on the post. You must provide an oauth_token with this method. * @param int $id The ID of the post. * @param string $action_id The ID of the action. * @param string $oauth_token The OAuth token provided from a user accreditation. * @return array */ public function do_action($id, $action_id, $oauth_token) { // Fetch response $response = $this->master->_request($this->resource . "/" . $id . "/" . $action_id . "?oauth_token=" . $oauth_token, NULL, OHC_API_METHOD_POST); // Throw an error if there is an error if ($response["success"] == FALSE) { throw new Exception($response["error"]); return FALSE; } // Return response data return $response["data"]; }
private function sign($url) { return APIClient::encodeURI($this->signer->signUrl($url)); }
<?php /** * WHMCS v6 Module for HugeServer Resellers * * @author HugeServer Networks, LLC - Development Team */ include "config.php"; require_once __DIR__ . "/functions.php"; include_once "api.php"; if (!isset($_GET['sid'])) { die('Argument missing'); } APIClient::$file = true; APIClient::$fileContentType = "application/x-java-jnlp-file"; APIClient::$fileName = "IPMI-{$_GET['hostname']}.jnlp"; $sid = (int) ion_decrypt($_GET['sid']); echo APIClient::serverIPMI(ION_API, array('serverID' => $sid));
<?php /** * WHMCS v6 Module for HugeServer Resellers * * @author HugeServer Networks, LLC - Development Team */ include "config.php"; require_once __DIR__ . "/functions.php"; include "api.php"; if (!isset($_GET['sid'])) { die('Argument missing'); } $sid = (int) trim(ion_decrypt($_GET['sid'])); $res = APIClient::serverReboot(ION_API, array('serverID' => $sid)); if ($res) { header("Location: " . $_SERVER['HTTP_REFERER'] . "&reboot=success"); } else { header("Location: " . $_SERVER['HTTP_REFERER'] . "&reboot=failed"); }
public static function __callStatic($method, $param) { if (!extension_loaded('curl')) { throw new Exception('cURL support is required', 1); } if (!isset($method)) { throw new Exception("Syntax Error", 3); } if (strpos($param[0], "-") != 0) { $key = str_replace('-', ':', $param[0]); } else { if (strpos($param[0], ":") == 0) { throw new Exception("API Key Not Correct", 2); } else { $key = $param[0]; } } $ch = curl_init(); if (isset($param[1]) && !(count($param[1]) == 1 && strpos(key($param[1]), 'ID') > 1)) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $param[1]); curl_setopt($ch, CURLOPT_URL, self::$url . $method); } else { if (isset($param[1])) { curl_setopt($ch, CURLOPT_URL, self::$url . $method . '/' . $param[1][key($param[1])]); } else { curl_setopt($ch, CURLOPT_URL, self::$url . $method); } } curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $key); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_MAXREDIRS, 2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); try { $result = curl_exec($ch); } catch (RestException $e) { throw new Exception(curl_error($ch), curl_errno($ch)); } if ($result === false) { curl_close($ch); throw new Exception(curl_error($ch), curl_errno($ch)); } if (self::$file) { header("Cache-Control: public"); header("Content-type: " . self::$fileContentType); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=" . self::$fileName); header("Content-Type: application/octet-stream; "); header("Content-Transfer-Encoding: binary"); self::$file = false; self::$fileName = 'file.txt'; self::$fileContentType = 'text/plain'; return $result; } if (strpos($result, "{") >= 0 && strpos($result, "{") < 10 || curl_getinfo($ch, CURLINFO_CONTENT_TYPE) == 'application/json') { return json_decode($result, true); } else { return $result; } }
/** * Retrieves a list of test groups. * * @return array The list of groups IDs. */ public function getClientTestGroups() { return (array) $this->apiClient->doCall('getClientTestGroups'); }
function ion_reboot($params) { $result = select_query('ion_module', 'ion_sid', array('whmcs_sid' => $params['serviceid'])); $ion_sid = 0; if (mysql_num_rows($result) > 0) { $ion_sid = mysql_fetch_array($result)[0]; } if ($ion_sid == 0) { return; } if (APIClient::serverReboot(ION_API, array('serverID' => $ion_sid))) { return 'success'; } else { return 'Error. please try again.'; } }
/** * Retrieves a list of all the trackable links in a banner. * * @param string $id The ID of the banner. * * @return array List of the trackable links. */ public function getAllBannerTrackableLinks($id) { $parameters = ['id' => (string) $id]; return (array) $this->apiClient->doCall('getAllBannerTrackableLinks', $parameters); }
/** * Upload file merge * This method uploads a file containing members and merges them with those in the member table. * * @param string $fileContent * @param string $filename * @param string $criteria * @param string $mapping * @param string $fileEncoding * @param string $separator * @param boolean $skipFirstLine * @param string $dateFormat * * @return string The ID of the upload job */ public function uploadFileMerge($fileContent, $filename, $criteria, $mapping, $fileEncoding = 'UTF-8', $separator = '|', $skipFirstLine = false, $dateFormat = 'mm/dd/yyyy') { $parameters['file'] = $fileContent; $parameters['mergeUpload'] = array('fileName' => (string) $filename, 'fileEncoding' => (string) $fileEncoding, 'separator' => (string) $separator, 'skipFirstLine' => $skipFirstLine, 'dateFormat' => (string) $dateFormat, 'criteria' => (string) $criteria, 'mapping' => $mapping); return (string) $this->apiClient->doCall('uploadFileMerge', $parameters); }
/** * Get an URL by his order * * @param string $messageId ID of the message. * @param int $order Order of the URL. * * @return array The URL parameters. */ public function getUrlByOrder($messageId, $order) { $parameters = ['messageId' => (string) $messageId, 'order' => (int) $order]; return (array) $this->apiClient->doCall('getUrlByOrder', $parameters); }
function rdns_hooks($vars) { if ($_GET['a'] != 'rdns') { return; } $var = array(); $var['menu'] = "<a href='clientarea.php?action=productdetails&id={$_GET['id']}'>{$vars['domain']}</a>"; $var['id'] = $_GET['id']; if (isset($_GET['ip'])) { $varp['rdns_ip'] = 'yes'; $var['menu'] = "<a href='clientarea.php?action=productdetails&id={$_GET['id']}'>{$vars['domain']}</a> / <a href='clientarea.php?action=productdetails&id={$_GET['id']}&modop=custom&a=rdns'>rDns</a>"; } else { $var['rdns_ip'] = 'no'; } if (isset($_POST['ip'], $_POST['ttl'], $_POST['content'])) { $ips = $_POST['ip']; $record = $_POST['content']; $ttl = $_POST['ttl']; $var['post'] = 'yes'; $arr = []; for ($i = 0; $i < count($ips); $i++) { $arr[$i]['ip'] = $ips[$i]; $arr[$i]['ttl'] = $ttl[$i]; $arr[$i]['content'] = $record[$i]; } $result = APIClient::setRDNS(ION_API, array('args' => json_encode($arr))); if (is_array($result)) { $var['error'] = 'failed'; $var['rdns_message'] = $result['error']['message']; } else { $var['error'] = 'success'; } $sid = $vars['sid']; $ips = APIClient::serverAllIPs(ION_API, array('serverID' => $sid)); $ipi = ''; $var['content'] = ''; foreach ($ips as $ip) { $ipi = APIClient::ipCalc(ION_API, array('ip' => $ip)); $var['content'] .= '<tr><td><a href="clientarea.php?action=productdetails&id=' . $_GET['id'] . '&modop=custom&a=rdns&ip=' . urlencode($ip) . '">' . $ip . '</a></td><td>' . correct($ipi['primary_IP'], $ip) . '</td><td>' . correct($ipi['last_IP'], $ip) . '</td></tr>'; } } else { if (isset($_GET['ip'])) { $sid = $vars['sid']; $ips = APIClient::serverAllIPs(ION_API, array('serverID' => $sid)); $flag = in_array($_GET['ip'], $ips); $var['ip'] = $_GET['ip']; $var['ip_decode'] = urlencode($_GET['ip']); if ($flag) { $rdns = APIClient::getRDNS(ION_API, array('ip' => $_GET['ip'])); if (isset($rdns['error'])) { $var['fetch'] = 'no'; } else { $var['fetch'] = 'yes'; $var['record'] = ''; foreach ($rdns as $k => $rr) { $var['record'] .= '<tr><td style="vert-align: middle;">' . $rr['ip'] . '<input type="hidden" value="' . $rr['ip'] . '" name="ip[]"></td>'; $var['record'] .= '<td><input class="form-control" style="width:90%;" type="text" value="' . ($rr['ttl'] != '' ? $rr['ttl'] : '14400') . '" name="ttl[]"></td>'; $var['record'] .= '<td><input type="text" value="' . $rr['content'] . '" name="content[]" style="width:90%;" class="form-control"></td></tr>'; } } } else { $var['error'] = 'access'; } } else { $sid = $vars['sid']; $ips = APIClient::serverAllIPs(ION_API, array('serverID' => $sid)); $ipi = ''; $var['content'] = ''; foreach ($ips as $ip) { $ipi = APIClient::ipCalc(ION_API, array('ip' => $ip)); $var['content'] .= '<tr><td><a href="clientarea.php?action=productdetails&id=' . $_GET['id'] . '&modop=custom&a=rdns&ip=' . urlencode($ip) . '">' . $ip . '</a></td><td>' . correct($ipi['primary_IP'], $ip) . '</td><td>' . correct($ipi['last_IP'], $ip) . '</td></tr>'; } } } return $var; }
/** * Counts the total number of distinct members in a segment (duplicate members are removed). * * @param string $id The ID of the segment. * * @return string The number of members. */ public function segmentationDistinctCount($id) { $parameters = ['id' => (string) $id]; return (string) $this->apiClient->doCall('segmentationDistinctCount', $parameters); }
/** * Retrieves a snapshot report. * * @param string $id The id of the campaign. * * @return array The campaign snapshot report data. */ public function getCampaignSnapshotReport($id) { $parameters = ['campaignId' => (string) $id]; return (array) $this->apiClient->doCall('getCampaignSnapshotReport', $parameters); }
/** * Log usage of the api into glpi historical or log files (defined by api config) * It stores the ip and the username of the current session. * * @param $endpoint string function called by api to log (default '') */ private function logEndpointUsage($endpoint = "") { $username = ""; if (isset($_SESSION['glpiname'])) { $username = "******" . $_SESSION['glpiname'] . ")"; } $apiclient = new APIClient(); if ($apiclient->getFromDB($this->apiclients_id)) { $changes[0] = 0; $changes[1] = ""; $changes[2] = "Enpoint '{$endpoint}' called by " . $this->iptxt . " {$username}"; switch ($apiclient->fields['dolog_method']) { case APIClient::DOLOG_HISTORICAL: Log::history($this->apiclients_id, 'APIClient', $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE); break; case APIClient::DOLOG_LOGS: Toolbox::logInFile("api", $changes[2] . "\n"); break; } } }
/** * Get the content of the download file * * @param type $fileID The ID of the export request * * @return string */ public function getDownloadFile($fileID) { $parameters = ['id' => (string) $fileID]; return (string) $this->apiClient->doCall('getDownloadFile', $parameters); }
/** * Retrieves a link report. * * @param string $campaignId The ID of the campaign * @param int $page The page to return * * @return array The paginated list of link response reports of the campaign. */ public function getLinkReport($campaignId, $page = 1) { $parameters = ['campaignId' => (string) $campaignId, 'page' => (int) $page]; return (array) $this->apiClient->doCall('getLinkReport', $parameters); }
/** * Get a list of not validated alternate senders. * * @return array The list of email addresses. */ public function getNotValidatedSenders() { return (array) $this->apiClient->doCall('getNotValidatedSenders'); }