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 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; }
} 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; }