public static function command($command, $post = array()) { $curl = new mycurl(PickPoint::$path . 'login'); $data = json_encode(array('Login' => PickPoint::$login, 'Password' => PickPoint::$password)); $curl->setPost($data); $curl->httpheader = array('Content-Type:application/json'); $curl->createCurl(); $json = json_decode($curl->__tostring()); $SessionId = $json->SessionId; try { $curl = new mycurl(PickPoint::$path . $command); $data = json_encode(array('Login' => PickPoint::$login, 'Password' => PickPoint::$password)); if (!empty($post)) { $curl->setPost($data); } $curl->httpheader = array('Content-Type:application/json'); $curl->createCurl(); $json = json_decode($curl->__tostring()); } catch (Exception $e) { print '<pre>'; print_r($e); } $curl = new mycurl(PickPoint::$path . 'logout'); $data = json_encode(array('SessionId' => $SessionId)); $curl->setPost($data); $curl->httpheader = array('Content-Type:application/json'); $curl->createCurl(); return $json; }
private function _runUnitTest($file) { $url = 'http://' . $_SERVER['HTTP_HOST'] . "/test-cases/" . $file; $mycurl = new mycurl($url); $mycurl->createCurl($url); return $mycurl->__toString(); }
public function generate($url) { if (!isset($this->domain)) { $this->domain = $url; $this->sitemap[] = $url; } echo 'CURLing ' . $url . "\n"; $MyCurl = new mycurl(); $MyCurl->createCurl($url); if ($MyCurl->getHttpStatus() === 200) { $string = $MyCurl->__tostring(); $aTags = $this->pregMatchAllATags($string); $aTags = $this->parseFollowLinksOnly($aTags[0]); $this->url_keyed_list[$url] = $aTags; foreach ($aTags as $aTag) { if (!in_array($aTag['href'], $this->sitemap)) { $this->sitemap[] = $aTag['href']; } } foreach ($this->url_keyed_list[$url] as $link) { if (isset($this->url_keyed_list[$link['href']])) { continue; } foreach ($this->non200s as $status => $list) { if (in_array($link['href'], $list)) { continue 2; } } $this->generate($link['href']); } } else { echo 'Http Status: ' . $MyCurl->getHttpStatus() . "\n"; echo 'CURL of ' . $url . " failed.\n"; if (!isset($this->non200s[$MyCurl->getHttpStatus()])) { $this->non200s[$MyCurl->getHttpStatus()] = array(); } $this->non200s[$MyCurl->getHttpStatus()][] = $url; if (in_array($url, $this->sitemap)) { $key = array_search($url, $this->sitemap); if ($key !== false) { unset($this->sitemap[$key]); } } return false; } echo 'Http Status: ' . $MyCurl->getHttpStatus() . "\n"; echo 'CURL of ' . $url . " completed.\n"; return true; }
function set_dyndns() { //https://username:password@www.dnsdynamic.org/api/?hostname=techno.ns360.info&myip=127.0.0.1 //https://username:password@dynupdate.no-ip.com/nic/update?hostname=mytest.testdomain.com&myip=1.2.3.4 $command = "/sbin/ifconfig tun1 | grep 'inet addr:' | cut -d: -f2 | awk '{ print \$1}'"; $localIP = exec($command); if ($localIP == "") { return; } $sql = "SELECT * FROM dyndns_settings "; $res = $this->settings['dbconn']->query($sql); $row = $res->fetch(PDO::FETCH_ASSOC); if ($row['DYNDNS_ENABLED'] == 0) { return; } $params = array(); $params['hostname'] = stripslashes($row['DYNDNS_HOSTNAME']); $params['myip'] = $localIP; $username = stripslashes($row['DYNDNS_USERNAME']); $password = stripslashes($row['DYNDNS_PASSWORD']); if ($username == "" || $password == "") { return; } $url = ""; if ($row['DYNDNS_COMPANY'] == "dyndns") { $url = "https://members.dyndns.org/nic/update"; } if ($row['DYNDNS_COMPANY'] == "noip") { $url = "https://dynupdate.no-ip.com/nic/update"; } if ($url == "") { return; } $url = $url . '?' . http_build_query($params, '', '&'); print_r($url); $user_agent = 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0'; $user_agent = "User-Agent: openmediavpn/0.0.1 edgar.pisani@gmail.com"; include_once "include/mycurl.php"; $curl = new mycurl($url); $curl->useAuth(true); //$curl->setCert(config::getMainIni('cert')); $curl->setName($username); $curl->setPass($password); $curl->setUserAgent($user_agent); $curl->createCurl(); $result = $curl->getWebPage(); $status = $curl->getHttpStatus(); $codes = explode(" ", $result); if ($codes[0] == "good" || $codes[0] == "nochg") { $row['DYNDNS_RETRIES'] = 0; } else { //after 3 retries the vpn will be disabled $row['DYNDNS_RETRIES']++; if ($row['DYNDNS_RETRIES'] >= 3) { $row['DYNDNS_ENABLED'] = 0; } } $sql = "UPDATE dyndns_settings SET DYNDNS_RETRIES=" . $row['DYNDNS_RETRIES'] . ",DYNDNS_ENABLED=" . $row['DYNDNS_ENABLED'] . ",DYNDNS_LASTRESPONSE='" . $codes[0] . "'"; print_r($sql); $res = $this->settings['dbconn']->query($sql); }
function rnPost($url, $data) { $curl = new mycurl($url); $curl->setPost($data); $curl->createCurl(); return $curl; }
public function createOrder($paid = 0) { $curl = new mycurl(Funcs::$conf['settings']['source'] . '/api/bill/user'); $post = array('token' => $_SESSION['iuser']['token'], 'user_id' => $_SESSION['iuser']['user_id']); $curl->setPost($post); $curl->createCurl(); $data = json_decode($curl->__tostring()); $sql = 'SELECT id FROM {{iusers}} WHERE code=\'' . $data->user_id . '\' AND author=0'; $iuser = DB::getOne($sql); if (!$iuser) { $sql = ' INSERT INTO {{iusers}} SET code=\'' . $data->user_id . '\', name=\'' . $data->name . '\', phone=\'' . $data->tel . '\' '; $iuser = DB::exec($sql); } $curl = new mycurl(Funcs::$conf['settings']['source'] . '/api/bill/payment'); $post = array('token' => $_SESSION['iuser']['token'], 'pay_id' => $_SESSION['iuser']['pay_id']); $curl->setPost($post); $curl->createCurl(); $data = json_decode($curl->__tostring()); if (!empty($data->goods)) { foreach ($data->goods as $item) { $sql = 'SELECT id FROM {{iusers}} WHERE code=\'' . $item->author_id . '\' AND author=1'; $author = DB::getOne($sql); if (!$author) { $sql = ' INSERT INTO {{iusers}} SET code=\'' . $item->author_id . '\', name=\'' . $item->name_author . '\', author=1 '; $author = DB::exec($sql); } $authorprice = round($item->amount - $item->amount / 100 * Funcs::$conf['settings']['comm'], 2); $sql = ' INSERT INTO {{orders}} SET iuser='******', author=' . $author . ', iuserprice=' . $item->amount . ', authorprice=' . $authorprice . ', payid=' . $_SESSION['iuser']['pay_id'] . ', paymentid=\'' . $_POST['paymentid'] . '\', commision=' . Funcs::$conf['settings']['comm'] . ', goodsid=\'' . $item->id . '\', goodsname=\'' . $item->name . '\', cdate=NOW(), paid=' . $paid . ' '; $orderid = DB::exec($sql); if ($paid == 1) { $sql = 'UPDATE {{iusers}} SET balance=balance+' . $authorprice . ' WHERE id=' . $author . ''; DB::exec($sql); $sql = 'UPDATE {{iusers}} SET balance=balance+' . $item->amount . ' WHERE id=' . $iuser . ''; DB::exec($sql); } } } }
function get_url($url) { $content = ''; $cur_time = time(); $filename = "requests/" . md5($url) . ".json"; //echo $filename; $getNew = FALSE; if (file_exists($filename)) { //echo '<br>file exists'; $file = basename($filename, ".json"); $old_time = filemtime($filename); //echo '<br> Prev time: '.$old_time; $mins = $cur_time - $old_time; //echo " -- ".$mins; if ($mins >= 300) { $getNew = TRUE; } else { $content = file_get_contents($filename); } } else { //echo '<br>file does not exists'; $getNew = TRUE; } if ($getNew) { //echo '<br> getting new'; $needLogin = TRUE; if ($needLogin) { //echo '<br>need login'; $login_url = 'http://www.reddit.com/api/login/username'; $curl = new mycurl(); $curl->setCookiFileLocation('requests/cookie.txt'); $data = array('api_type' => 'json', 'user' => 'ReillyKlevre', 'passwd' => 'password'); $curl->setPost($data); $curl->createCurl($login_url); if ($curl->getHttpStatus() != 200) { echo '<br>LOGIN ERROR > HTTP STATUS: ' . $curl->getHttpStatus(); exit; } } //echo '<br>after: '.$url; $curl = new mycurl(); $curl->setCookiFileLocation('requests/cookie.txt'); $curl->createCurl($url); if ($curl->getHttpStatus() != 200) { echo '<br>REDDIT_URL ' . $url . ' > HTTP STATUS: ' . $curl->getHttpStatus(); exit; } $content = $curl->__tostring(); if ($content) { $fp = fopen($filename, 'w'); fwrite($fp, $content); fclose($fp); } } return $content; }
private function sync_kpis() { $this->load->model('Kpis_model', 'kpis'); $url = API_URL . API_GET_KPIS_SERVICE; $user = API_AUTH__USER; $pass = API_AUTH_PASSE; $_mycurl = new mycurl($url, $user, $pass); $_mycurl->createCurl(); $result = (string) $_mycurl; //var_dump($result); log_message('error', "synch kpis : " . print_r($result, true)); //var_dump($_mycurl); //$result = getAllTerms(); $result = json_decode($result, true); foreach ($result as $obj) { $data = array(); if (empty($obj['termID']) && !empty($obj['termId'])) { $obj['termID'] = $obj['termId']; } $data['term_id'] = (string) $obj['termID']; $data['name'] = (string) $obj['name']; if (!empty($obj['description'])) { $data['description'] = (string) $obj['description']; } $data['decision_category'] = (string) $obj['decisionCategory']; $data['financial_category'] = (string) $obj['financialCategory']; if (empty($data['decision_category'])) { $data['decision_category'] = "uncategorized"; } if (empty($data['financial_category'])) { $data['financial_category'] = "uncategorized"; } if (!empty($data['term_id']) && $data['term_id'] != 0 && !empty($data['name'])) { $this->kpis->save($data); } } return "ok"; }
public function get_view_term_rule($entity_id, $term_id) { $this->url = REST_API_VIEW_TERM_RULE; $this->url = str_replace('{0}', API_TOKEN, $this->url); $this->url = str_replace('{1}', $entity_id, $this->url); $this->url = str_replace('{2}', $term_id, $this->url); log_message('debug', 'Api_model-drilldown url: ' . $this->url); // no cache on drilldown $this->benchmark->mark('Api_model-drilldown_start'); $_mycurl = new mycurl($this->url); $_mycurl->useAuth(false); $_mycurl->createCurl(); $result = (string) $_mycurl; $result = json_decode($result, true); $this->benchmark->mark('Api_model-drilldown_end'); log_message('debug', 'Api_model-drilldown: ' . $this->benchmark->elapsed_time('Api_model-drilldown_start', 'Api_model-drilldown_end')); return $result; }
curl_setopt($s, CURLOPT_HEADER, true); } if ($this->_noBody) { curl_setopt($s, CURLOPT_NOBODY, true); } if ($this->_binaryTransfer) { curl_setopt($s, CURLOPT_BINARYTRANSFER, true); } if ($this->_freshConnect) { curl_setopt($s, CURLOPT_FRESH_CONNECT, $this->_freshConnect); } curl_setopt($s, CURLOPT_USERAGENT, $this->_useragent); curl_setopt($s, CURLOPT_REFERER, $this->_referer); $this->_webpage = curl_exec($s); $this->_status = curl_getinfo($s, CURLINFO_HTTP_CODE); curl_close($s); } public function getHttpStatus() { return $this->_status; } public function __tostring() { return $this->_webpage; } } $url = "http://shortmsg.net"; $curl = new mycurl($url); $curl->createCurl(); echo $curl->__tostring(); echo $curl->getHttpStatus();
public function &sendRequest($url, $checkResultTag = false, &$filecontent = null, $filename = '') { $url = str_replace('#', '%23', $url); if (isset($this->serial) && !is_null($this->serial)) { $url = 'https://' . $this->apihost . '/api/?key=' . $this->apikey . '&target=' . $this->serial . '&' . $url; } else { $url = 'https://' . $this->apihost . '/api/?key=' . $this->apikey . '&' . $url; } if ($this->showApiCalls) { print "API call: \"" . $url . "\"\r\n"; } $c = new mycurl($url); if (!is_null($filecontent)) { $c->setInfile($filecontent, $filename); } if (!$c->createCurl()) { derr('Could not retrieve URL: ' . $url . ' because of the following error: ' . $c->last_error); } $xmlobj = new XmlArray(); if ($c->getHttpStatus() != 200) { derr('HTTP API ret: ' . $c->__tostring()); } $xmlarr = $xmlobj->load_string($c->__tostring()); if (!is_array($xmlarr)) { derr('API didnt return a XML string: ' . $c->__tostring()); } if (!isset($xmlarr['attributes']['status'])) { derr('XML response has no "status" field: ' . array_to_xml($xmlarr)); } if ($xmlarr['attributes']['status'] != 'success') { derr('API reported a failure: ' . $c->__tostring()); } if (!is_null($filecontent)) { return $xmlarr['children']; } if (!$checkResultTag) { return $xmlarr['children']; } //print_r( $xmlarr['children'] ); $cursor =& searchForName('name', 'result', $xmlarr['children']); if (is_null($cursor)) { derr('XML API response has no <result> field:' . $c->__tostring()); } if (is_null($cursor['children'])) { derr('XML API <result> has no content'); } return $cursor['children']; }
/** * @param string $parameters * @param bool $checkResultTag * @param string|null $filecontent * @param string $filename * @param Array $moreOptions * @return DomDocument */ public function sendRequest(&$parameters, $checkResultTag = false, &$filecontent = null, $filename = '', $moreOptions = array()) { $sendThroughPost = false; if (is_array($parameters)) { $sendThroughPost = true; } $host = $this->apihost; if ($this->port != 443) { $host .= ':' . $this->port; } if (isset($this->serial) && !is_null($this->serial)) { $finalUrl = 'https://' . $host . '/api/'; if (!$sendThroughPost) { $finalUrl .= '?key=' . $this->apikey . '&target=' . $this->serial; } } else { $finalUrl = 'https://' . $host . '/api/'; if (!$sendThroughPost) { $finalUrl .= '?key=' . $this->apikey; } } if (!$sendThroughPost) { $url = str_replace('#', '%23', $parameters); $finalUrl .= '&' . $parameters; } if (isset($moreOptions['timeout'])) { $timeout = $moreOptions['timeout']; } else { $timeout = 7; } $c = new mycurl($finalUrl, false, $timeout); if (array_key_exists('lowSpeedTime', $moreOptions)) { $c->_lowspeedtime = $moreOptions['lowSpeedTime']; } if (!is_null($filecontent)) { $c->setInfile($filecontent, $filename); } if ($sendThroughPost) { if (isset($this->serial) && !is_null($this->serial)) { $parameters['target'] = $this->serial; } $parameters['key'] = $this->apikey; $properParams = http_build_query($parameters); $c->setPost($properParams); } if ($this->showApiCalls) { if ($sendThroughPost) { $paramURl = '?'; foreach ($parameters as $paramIndex => &$param) { $paramURl .= '&' . $paramIndex . '=' . str_replace('#', '%23', $param); } print "API call through POST: \"" . $finalUrl . '?' . $paramURl . "\"\r\n"; } else { print "API call: \"" . $finalUrl . "\"\r\n"; } } if (!$c->createCurl()) { derr('Could not retrieve URL: ' . $finalUrl . ' because of the following error: ' . $c->last_error); } if ($c->getHttpStatus() != 200) { derr('HTTP API ret: ' . $c->__tostring()); } $xmlDoc = new DOMDocument(); if (!$xmlDoc->loadXML($c->__tostring(), LIBXML_PARSEHUGE)) { derr('Invalid xml input :' . $c->__tostring()); } $firstElement = DH::firstChildElement($xmlDoc); if ($firstElement === false) { derr('cannot find any child Element in xml'); } $statusAttr = DH::findAttribute('status', $firstElement); if ($statusAttr === false) { derr('XML response has no "status" field: ' . DH::dom_to_xml($firstElement)); } if ($statusAttr != 'success') { var_dump($statusAttr); derr('API reported a failure: "' . $statusAttr . "\"with the following addition infos: " . $firstElement->nodeValue); } if (!is_null($filecontent)) { return $xmlDoc; } if (!$checkResultTag) { return $xmlDoc; } //$cursor = &searchForName('name', 'result', $xmlarr['children']); $cursor = DH::findFirstElement('result', $firstElement); if ($cursor === false) { derr('XML API response has no <result> field', $xmlDoc); } DH::makeElementAsRoot($cursor, $xmlDoc); return $xmlDoc; }
protected function get_data_curl($entityID, $termID, $FYFQ, $specialFormat) { //first we attempt to get the data from the session //if no data is stored in the session, we get data from API $cacheKey = $this->get_cache_key($entityID, $termID, $FYFQ, $specialFormat); $use_cache = FALSE; if ($this->config->item('use_cache') === TRUE) { $use_cache = TRUE; $from_session = true; $result = $this->session->userdata($cacheKey); } if (empty($result)) { $url = API_URL . API_GET_DATA_SERVICE; $user = API_AUTH__USER; $pass = API_AUTH_PASSE; //var_dump($data); $this->benchmark->mark('Api_model-curl_start'); $_mycurl = new mycurl($url, $user, $pass); $_mycurl->setPost($cacheKey); $_mycurl->createCurl(); $result = (string) $_mycurl; $result = json_decode($result, true); $this->benchmark->mark('Api_model-curl_end'); log_message('debug', 'Api_model-curl: ' . $this->benchmark->elapsed_time('Api_model-curl_start', 'Api_model-curl_end')); //log_message('debug', 'Api_model-curl: json_decode: ' . print_r($result, true)); $from_session = false; } /* don't cache */ if ($use_cache === TRUE && !$from_session && !empty($result)) { $this->session->set_userdata($cacheKey, $result); } /* */ //var_dump($result); return $result; }