function main() { // operation is required if (!isset($_GET['operation'])) { exit('missing required paramter: operation'); } $fx = $_GET['operation']; $values = $_GET; unset($values['operation']); echo do_curl($fx, 1, $values); }
function get_from_jmx($protocol, $host, $port, $query) { $json_string = do_curl($protocol, $host, $port, '/jmx?qry=' . $query); if ($json_string === false) { return false; } $json_array = json_decode($json_string, true); if (empty($json_array['beans']) || empty($json_array['beans'][0])) { return false; } return $json_array['beans'][0]; }
function get_info($protocol, $host, $port) { $json_string = do_curl($protocol, $host, $port, '/ws/v1/node/info'); if ($json_string === false) { return false; } $json_array = json_decode($json_string, true); if (empty($json_array['nodeInfo'])) { return false; } return $json_array['nodeInfo']; }
function get_info($protocol, $host, $port, $path) { $json_string = do_curl($protocol, $host, $port, '/webhdfs/v1' . $path . '?op=GETCONTENTSUMMARY'); #echo $json_string; if ($json_string === false) { return false; } $json_array = json_decode($json_string, true); #echo $json_array['ContentSummary']; if (empty($json_array['ContentSummary'])) { return false; } return $json_array['ContentSummary']; }
function do_post($url, $postbody, $port = 80, $headers = NULL) { $retarr = array(); // Return value $curl_opts = array(CURLOPT_URL => $url, CURLOPT_PORT => $port, CURLOPT_POST => true, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_POSTFIELDS => $postbody, CURLOPT_RETURNTRANSFER => true); if ($headers) { $curl_opts[CURLOPT_HTTPHEADER] = $headers; } $response = do_curl($curl_opts); if (!empty($response)) { $retarr = $response; } return $retarr; }
function check_captcha2_validation() { $ip_address = $_SERVER['REMOTE_ADDR']; if (isset($_REQUEST['captcha2_validation_id'])) { $validation_id = $_REQUEST['captcha2_validation_id']; $check_validation_url = "http://sys.captcha2.com/check_validation.php?validation_id={$validation_id}&ip_address={$ip_address}"; $captcha2_result = do_curl($check_validation_url); if ($captcha2_result === false) { $captcha2_result = 'valid'; } } else { $captcha2_result = "invalid"; } return $captcha2_result; }
function themis_ci_message($client_id, $server_id, $server_key) { global $key_store; $endpoint = 'https://themis.cossacklabs.com/api/' . $client_id . '/'; $key_store[$server_id]['public_key'] = base64_decode($server_key); $key_store[$client_id]['public_key'] = base64_decode('VUVDMgAAAC2IRalnA7mIDaKlK5HvBz2woET8cc2dJQ3sOQMYQ/13TtUNofnQ'); $key_store[$client_id]['private_key'] = base64_decode('UkVDMgAAAC1whm6SAJ7vIP18Kq5QXgLd413DMjnb6Z5jAeiRgUeekMqMC0+x'); $headers = array(); $headers[] = 'Content-type: application/x-www-form-urlencoded'; $message = 'The best laid plans of mice and men go oft astray'; $message = base64_encode(phpthemis_secure_message_wrap($key_store[$client_id]['private_key'], $key_store[$server_id]['public_key'], $message)); $docbody = 'message=' . urlencode($message); $curl_ctx = curl_init(); $response = do_curl($curl_ctx, $endpoint, $headers, $docbody); $message = $response['curl_content']; $message = phpthemis_secure_message_unwrap($key_store[$client_id]['private_key'], $key_store[$server_id]['public_key'], $message); echo $message . "\n"; curl_close($curl_ctx); }
function quick_search($query, $startPage = 1, $xslt) { module_load_include('php', 'Fedora_Repository', 'ObjectHelper'); module_load_include('inc', 'Fedora_Repository', 'api/fedora_utils'); if (user_access('view fedora collection')) { $numberOfHistPerPage = variable_get('fedora_repository_advanced_block_hist', t('50')); $luceneQuery = null; $indexName = variable_get('fedora_index_name', 'DemoOnLucene'); $copyXMLFile = 'copyXml'; $query = trim($query); $query = htmlentities(urlencode($query)); $searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest'); $searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=' . $copyXMLFile . '&query=' . $query; $searchString .= '&hitPageSize=' . $numberOfHistPerPage . '&hitPageStart=' . $startPage; $searchUrl .= $searchString; $resultData = do_curl($searchUrl, 1); $output .= $this->applyLuceneXSLT($resultData, $startPage, $xslt, $query); return $output; } }
/** * Gets objects related to this item. It will query the object for a Query stream and use that as a itql query * or if there is no query stream it will use the default. If you pass a query to this method it will use the passed in query no matter what */ function getRelatedItems($pid, $itqlquery = NULL, $limit = NULL, $offset = NULL) { module_load_include('php', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); if (!isset($limit)) { $limit = 1000; } if (!isset($offset)) { $offset = 0; } global $user; if (!fedora_repository_access(OBJECTHELPER::$VIEW_FEDORA, $pid, $user)) { drupal_set_message(t("You do not have access to Fedora Objects within the attempted namespace or access to Fedora denied!"), 'error'); return ' '; } $objectHelper = new ObjectHelper(); $query_string = $itqlquery; if (!isset($query_string)) { $query_string = $objectHelper->getStream($pid, 'QUERY', 0); if ($query_string == null) { $query_string = 'select $object $title $content from <#ri> where ($object <dc:title> $title and $object <fedora-model:hasModel> $content and ($object <fedora-rels-ext:isMemberOfCollection> <info:fedora/' . $pid . '> or $object <fedora-rels-ext:isMemberOf> <info:fedora/' . $pid . '>) and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>) minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0> order by $title'; } } $query_string = htmlentities(urlencode($query_string)); $content = ''; $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); $url .= "?type=tuples&flush=true&format=Sparql&limit={$limit}&offset={$offset}&lang=itql&stream=on&query=" . $query_string; $content .= do_curl($url); return $content; }
function themis_ci_session_server($curl_ctx, $endpoint, $client_message) { $headers = array(); $headers[] = 'Content-type: application/x-www-form-urlencoded'; $docbody = 'message=' . urlencode(base64_encode($client_message)); $response = do_curl($curl_ctx, $endpoint, $headers, $docbody); $server_response = array('status' => $response['curl_ret'], 'message' => $response['curl_content']); return $server_response; }
$rss_desc = match('/<h3>(.*?)</', $html, 1); $balance = trim(match('/Avail Bal:(.*)/', $html, 1)); if (isset($_GET['type']) && $_GET['type'] == "pending") { $type = "Pending"; $trans = array(); $href = match('/\\/(cgi-bin.*?Pending)/', $html, 1); $phtml = do_curl($domain . $href); preg_match_all('/<br>(.*?)Pending.*?(-?\\$[0-9]+\\.[0-9][0-9])/ms', $phtml, $matches); for ($i = 0; $i < count($matches[1]); $i++) { $trans[] = array('description' => trim(strip_tags($matches[1][$i])), 'amount' => $matches[2][$i], 'date' => date("Y-m-d")); } } else { $type = "Cleared"; $trans = array(); $href = match('/\\/(cgi-bin.*?Cleared)/', $html, 1); $chtml = do_curl($domain . $href); preg_match_all('/txnid=[0-9]+">(.*?)<\\/a>.*?([0-9][0-9]\\/[0-9][0-9]\\/[0-9][0-9][0-9][0-9]).*?(-?\\$[0-9]+\\.[0-9][0-9])/ms', $chtml, $matches); for ($i = 0; $i < count($matches[1]); $i++) { $date = match('/([01][0-9]\\/[0-3][0-9])/', trim(strip_tags($matches[2][$i])), 1) . '/' . date('Y'); $trans[] = array('description' => trim(strip_tags($matches[1][$i])), 'amount' => $matches[3][$i], 'date' => date('Y-m-d', strtotime($date))); } } // And build the RSS feed $out = '<?xml version="1.0" encoding="utf-8"?>' . "\n"; $out .= '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">' . "\n"; $out .= "<channel>\n"; $out .= "<title>{$rss_title} {$type}</title>\n"; $out .= "<link>https://www.bankofamerica.com</link>\n"; $out .= "<description>{$rss_desc}</description>\n"; $out .= "<language>en-us</language>\n"; $out .= "<pubDate>" . date("D, d M Y H:i:s O", strtotime($posted[1][$i] . " 12:00pm")) . "</pubDate>\n";
function get_oembed_from_api($api_prefix, $ori_url) { if (empty($api_prefix) || empty($ori_url)) { return null; } //任玩堂的oEmbed的api格式 $api_regex = "%s?oembed=true&format=json&url=%s"; $api_url = sprintf($api_regex, $api_prefix, $ori_url); $res = do_curl($api_url); if (empty($res)) { return null; } preg_match("#{\".*\"}#ui", $res, $mm); $res_body = $mm[0]; if (empty($res_body)) { return null; } return $res_body; }
function custom_search($query, $startPage = 1, $xslt = '/xsl/advanced_search_results.xsl', $numberOfHistPerPage = 50) { module_load_include('php', 'Fedora_Repository', 'ObjectHelper'); module_load_include('inc', 'Fedora_Repository', 'api/fedora_utils'); if (user_access('view fedora collection')) { $numberOfHistPerPage = variable_get('fedora_repository_advanced_block_hist', t('50')); //$numberOfHistPerPage = '50';//hack for IR they do not want next button $luceneQuery = null; $indexName = variable_get('fedora_index_name', 'DemoOnLucene'); $copyXMLFile = 'copyXml'; // if($indexName=='ilives' || $indexName=='BasicIndex'){ // $copyXMLFile = 'copyXmliLives'; // } $query = trim($query); $query = htmlentities(urlencode($query)); $searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest'); $searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=' . $copyXMLFile . '&query=' . $query; $searchString .= '&hitPageSize=' . $numberOfHistPerPage . '&hitPageStart=' . $startPage; //$searchString = htmlentities($searchString); $searchUrl .= $searchString; //$objectHelper = new ObjectHelper(); $resultData = do_curl($searchUrl, 1); //var_dump($resultData);exit(0); // $doc = new DOMDocument(); // $doc->loadXML($resultData); $output .= $this->applyLuceneXSLT($resultData, $startPage, $xslt, $query); return $output; } }
// // Obviously, we're scraping Apple's website, so this could break at any time. // This script was last successfully tested on 10/29/2008. // // (It's totally possible that there's an Apple approved way of automatically // downloading your sales data, but if there is, I can't find it.) $un = '<your username>'; $pw = '<your password>'; do_curl('https://phobos.apple.com/WebObjects/MZLabel.woa/wa/default'); do_curl('https://phobos.apple.com/WebObjects/MZLabel.woa/wo/0.0.5.3.3.1.0.1', 'theAccountName=' . urlencode($un) . '&theAccountPW=' . urlencode($pw) . '&1.Continue.x=0&1.Continue.y=0&theAuxValue='); $html = do_curl('https://itts.apple.com/cgi-bin/WebObjects/Piano.woa'); $action = 'https://itts.apple.com' . match('/frmVendorPage(\'|").*?(\\/cgi-bin.*?)(\'|")/ms', $html, 2); $html = do_curl($action, '9.5=Summary&9.7=Daily&hiddenDayOrWeekSelection=Daily&hiddenSubmitTypeName=ShowDropDown'); $date = match('/value=(\'|")([0-9][0-9]\\/[0-9][0-9]\\/[0-9]{4})/ms', $html, 2); $action = 'https://itts.apple.com' . match('/frmVendorPage(\'|").*?(\\/cgi-bin.*?)(\'|")/ms', $html, 2); $gz = do_curl($action, "9.5=Summary&9.7=Daily&9.9.1=" . urlencode($date) . "&download=Download&hiddenDayOrWeekSelection=" . urlencode($date) . "&hiddenSubmitTypeName=Download"); $fn = tempnam(sys_get_temp_dir(), 'itunes'); file_put_contents($fn, $gz); readgzfile($fn); function do_curl($url, $post = null) { static $tmp = null; static $referer = ""; if (is_null($tmp)) { $tmp = tempnam(sys_get_temp_dir(), 'boa'); } $ch = curl_init($url); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; en-us) AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13"); curl_setopt($ch, CURLOPT_COOKIEFILE, $tmp); curl_setopt($ch, CURLOPT_COOKIEJAR, $tmp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
/** * Does a search using the "query" format followed by the Fedora REST APi. * * @param string $pattern to search for, including wildcards. * @param string $field The field to search on, e.g. pid, title, cDate. See http://www.fedora-commons.org/confluence/display/FCR30/REST+API#RESTAPI-findObjects for details * @param int $max_results not used at this time * @return Array of pid => title pairs that match the results */ static function find_objects_by_pattern($pattern = '*', $field = 'pid', $max_results = 100) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); $pattern = drupal_urlencode($pattern); $done = FALSE; $cursor = 0; $session_token = ''; $i = 0; $results = array(); while (!$done && $i < 5) { $i++; $url = variable_get('fedora_base_url', 'http://localhost:8080/fedora'); if ($cursor == 0) { $url .= "/objects?query={$field}~{$pattern}&pid=true&title=true&resultFormat=xml&maxResults={$max_results}"; } else { $url .= "/objects?pid=true&title=true&sessionToken={$session_token}&resultFormat=xml&maxResults={$max_results}"; } $resultxml = do_curl($url); libxml_use_internal_errors(TRUE); $resultelements = simplexml_load_string($resultxml); if ($resultelements === FALSE) { libxml_clear_errors(); break; } $cursor += count($resultelements->resultList->objectFields); if (count($resultelements->resultList->objectFields) < $max_results || count($resultelements->resultList->objectFields) == 0) { $done = TRUE; } foreach ($resultelements->resultList->objectFields as $obj) { $results[(string) $obj->pid] = (string) $obj->title; $cursor++; if ($cursor >= $max_results) { $done = TRUE; break; } } $session_token = $resultelements->listSession->token; $done = !empty($session_token); } return $results; }
if ($dbresult) { echo "<p>Creating backup in ".str_replace("\\","/",realpath($backup->backup_dir))."/{$backupname}</p>"; if (trim($_GET["backup"])=="") { echo "<p style='color:red;'>Error: \"SYNC SERVER ADDRESS\" not defined</p>"; } else if (!function_exists('curl_init')) { echo "<p style='color:red;'>Error: \"PHP cURL FUNCTION\" not active</p>"; } else { //$backupname = "sync.php"; $fl = $backup->backup_dir.$backupname; $fh = fopen($fl, "rb"); $fx = fread($fh, filesize($fl)); fclose($fh); $data = "name={$backupname}&file=".urlencode(base64_encode($fx)); $data = do_curl($_GET["backup"], $data); $path = pathinfo($_GET["backup"]); $done = intval($data)>0? $path['dirname']."/backup/".$backupname : ""; if ($done!="") { echo "<p>Uploaded backup to <a href='{$done}' target'_blank'>{$done}</a></p>"; } else { echo "<p style='color:red'>Failed uploading backup: <em>{$data}</em></p>"; } } } else { echo "<p style='color:red'>Failed creating backup: <em>{$backup->error}</em></p>"; } echo " </div>"; echo "</div>"; exit;
$cluster = $options['C']; $protocol = array_key_exists('S', $options) ? 'https' : 'http'; $query = "GET hosts\n"; $query .= "Filter: host_groups >= {$cluster}\n"; $query .= "Filter: host_groups >= yarn_rm\n"; $query .= "Columns: host_name\n"; $resourcemanagers = false; foreach ($hosts as $host) { $resourcemanagers = query_livestatus($host, $port, $query); if (!empty($resourcemanagers)) { break; } } $active = array(); foreach ($resourcemanagers as $rm_host) { $json_string = do_curl($protocol, $rm_host, $rm_port, '/jmx?qry=Hadoop:service=ResourceManager,name=ClusterMetrics'); if ($json_string === false || preg_match('/^This is standby RM/', $json_string)) { continue; } $json_array = json_decode($json_string, true); $object = $json_array['beans'][0]; if (count($object) != 0) { $active[] = $rm_host; } } if (sizeof($active) == 1) { echo $active[0] . PHP_EOL; exit(0); } if (sizeof($active) > 1) { echo 'CRITICAL: More than 1 active RM detected' . PHP_EOL;
/** * Returns an array of pids that match the query contained in teh collection * object's QUERY datastream or in the suppled $query parameter. * @param <type> $collection_pid * @param <type> $query * @param <type> $query_format R */ function get_related_items_as_xml($collection_pid, $relationship = array('isMemberOfCollection'), $limit = 10000, $offset = 0, $active_objects_only = TRUE) { module_load_include('php', 'fedora_repository', 'ObjectHelper'); $collection_item = new Fedora_Item($collection_pid); global $user; if (!fedora_repository_access(OBJECTHELPER::$VIEW_FEDORA, $pid, $user)) { drupal_set_message(t("You do not have access to Fedora Objects within the attempted namespace or access to Fedora denied!"), 'error'); return array(); } $query_string = 'select $object $title $content from <#ri> where ($object <dc:title> $title and $object <fedora-model:hasModel> $content and ('; $query_string .= $relationship; if (is_array($relationship)) { foreach ($relationship as $rel) { $query_string .= '$object <fedora-rels-ext:' . $rel . '> <info:fedora/' . $collection_pid . '>'; if (next($relationship)) { $query_string .= ' OR '; } } } elseif (is_string($relationship)) { $query_string .= '$object <fedora-rels-ext:' . $relationship . '> <info:fedora/' . $collection_pid . '>'; } else { return ''; } $query_string .= ') ' . ($active_objects_only ? 'and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>' : '') . ') minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0> order by $title'; $query_string = htmlentities(urlencode($query_string)); $content = ''; $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); $url .= "?type=tuples&flush=true&format=Sparql&limit={$limit}&offset={$offset}&lang=itql&stream=on&query=" . $query_string; $content .= do_curl($url); return $content; }