function GetMyIp() { Checks(); $sock = new sockets(); if ($sock->GET_INFO("DoNotResolvInternetIP") == 1) { $ip = $sock->GET_INFO("PublicIPAddress"); if ($ip != null) { return $ip; } } $time = file_time_min("/usr/share/artica-postfix/ressources/logs/web/myIP.conf"); if ($time < 60) { return trim(@file_get_contents("/usr/share/artica-postfix/ressources/logs/web/myIP.conf")); } @unlink("/usr/share/artica-postfix/ressources/logs/web/myIP.conf"); include_once "HTTP/Request.php"; include_once 'Net/DNSBL.php'; $ini = new Bs_IniHandler(); $sock = new sockets(); $datas = $sock->GET_INFO("ArticaProxySettings"); $ini->loadString($datas); $ArticaProxyServerEnabled = $ini->_params["PROXY"]["ArticaProxyServerEnabled"]; $ArticaProxyServerName = $ini->_params["PROXY"]["ArticaProxyServerName"]; $ArticaProxyServerPort = $ini->_params["PROXY"]["ArticaProxyServerPort"]; $ArticaProxyServerUsername = $ini->_params["PROXY"]["ArticaProxyServerUsername"]; $ArticaProxyServerUserPassword = $ini->_params["PROXY"]["ArticaProxyServerUserPassword"]; $ArticaCompiledProxyUri = $ini->_params["PROXY"]["ArticaCompiledProxyUri"]; $req = new HTTP_Request("http://www.artica.fr/my-ip.php"); $req->setURL("http://www.artica.fr/my-ip.php"); $req->setMethod(HTTP_REQUEST_METHOD_GET); if ($ArticaProxyServerEnabled == "yes") { $req->setProxy($ArticaProxyServerName, $ArticaProxyServerPort, $ArticaProxyServerUsername, $ArticaProxyServerUserPassword); } $req->sendRequest(); $code = $req->getResponseCode(); $datas = trim($req->getResponseBody()); writelogs("http://www.artica.fr/my-ip.php -> ({$datas})"); if (preg_match("#([0-9\\.]+)#", $datas, $re)) { $myip = $re[1]; writelogs("http://www.artica.fr/my-ip.php -> {$code} ({$datas})"); } else { writelogs("Unable to preg_match datas...."); } if ($myip != null) { @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/myIP.conf", $myip); @chmod("/usr/share/artica-postfix/ressources/logs/web/myIP.conf", 775); $sock->SET_INFO("PublicIPAddress", $myip); } }
/** * Retrieves a file from cache if it exists, otherwise retrieve from net, * add to cache, and return from cache. * * @param string URL to WSDL * @param array proxy parameters * @param int expected MD5 of WSDL URL * @access public * @return string data */ function get($wsdl_fname, $proxy_params = array(), $cache = 0) { $cachename = $md5_wsdl = $file_data = ''; if ($this->_cacheUse) { // Try to retrieve WSDL from cache $cachename = $this->_cacheDir() . '/' . md5($wsdl_fname) . ' .wsdl'; if (file_exists($cachename) && ($file_data = file_get_contents($cachename))) { $md5_wsdl = md5($file_data); if ($cache) { if ($cache != $md5_wsdl) { return $this->_raiseSoapFault('WSDL Checksum error!', $wsdl_fname); } } else { $fi = stat($cachename); $cache_mtime = $fi[8]; if ($cache_mtime + $this->_cacheMaxAge < time()) { // Expired, refetch. $md5_wsdl = ''; } } } } // Not cached or not using cache. Retrieve WSDL from URL if (!$md5_wsdl) { // Is it a local file? if (strpos($wsdl_fname, 'file://') === 0) { $wsdl_fname = substr($wsdl_fname, 7); if (!file_exists($wsdl_fname)) { return $this->_raiseSoapFault('Unable to read local WSDL file', $wsdl_fname); } $file_data = file_get_contents($wsdl_fname); } elseif (!preg_match('|^https?://|', $wsdl_fname)) { return $this->_raiseSoapFault('Unknown schema of WSDL URL', $wsdl_fname); } else { $uri = explode('?', $wsdl_fname); $rq = new HTTP_Request($uri[0], $proxy_params); // the user agent HTTP_Request uses fouls things up if (isset($uri[1])) { $rq->addRawQueryString($uri[1]); } if (isset($proxy_params['proxy_host']) && isset($proxy_params['proxy_port']) && isset($proxy_params['proxy_user']) && isset($proxy_params['proxy_pass'])) { $rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port'], $proxy_params['proxy_user'], $proxy_params['proxy_pass']); } elseif (isset($proxy_params['proxy_host']) && isset($proxy_params['proxy_port'])) { $rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port']); } $result = $rq->sendRequest(); if (PEAR::isError($result)) { return $this->_raiseSoapFault("Unable to retrieve WSDL {$wsdl_fname}," . $rq->getResponseCode(), $wsdl_fname); } $file_data = $rq->getResponseBody(); if (!$file_data) { return $this->_raiseSoapFault("Unable to retrieve WSDL {$wsdl_fname}, no http body", $wsdl_fname); } } $md5_wsdl = md5($file_data); if ($this->_cacheUse) { $fp = fopen($cachename, "wb"); fwrite($fp, $file_data); fclose($fp); } } if ($this->_cacheUse && $cache && $cache != $md5_wsdl) { return $this->_raiseSoapFault('WSDL Checksum error!', $wsdl_fname); } return $file_data; }
/** * Retrieves a file from cache if it exists, otherwise retreive from net, * add to cache, and return from cache. * * @param string URL to WSDL * @param array proxy parameters * @param int expected MD5 of WSDL URL * @access public * @return string data */ function get($wsdl_fname, $proxy_params = array(), $cache = 0) { $cachename = $md5_wsdl = $file_data = ''; if ($this->_cacheUse) { // Try to retrieve WSDL from cache $cachename = SOAP_WSDL_Cache::_cacheDir() . '/' . md5($wsdl_fname) . ' .wsdl'; if (file_exists($cachename)) { $wf = fopen($cachename, 'rb'); if ($wf) { // Reading cached file $file_data = fread($wf, filesize($cachename)); $md5_wsdl = md5($file_data); fclose($wf); } if ($cache) { if ($cache != $md5_wsdl) { return $this->_raiseSoapFault('WSDL Checksum error!', $wsdl_fname); } } else { $fi = stat($cachename); $cache_mtime = $fi[8]; //print cache_mtime, time() if ($cache_mtime + $this->_cacheMaxAge < time()) { // expired $md5_wsdl = ''; // refetch } } } } if (!$md5_wsdl) { // Not cached or not using cache. Retrieve WSDL from URL // is it a local file? // this section should be replace by curl at some point if (!preg_match('/^(https?|file):\\/\\//', $wsdl_fname)) { if (!file_exists($wsdl_fname)) { return $this->_raiseSoapFault("Unable to read local WSDL {$wsdl_fname}", $wsdl_fname); } if (function_exists('file_get_contents')) { $file_data = file_get_contents($wsdl_fname); } else { $file_data = implode('', file($wsdl_fname)); } } else { $uri = explode('?', $wsdl_fname); $rq = new HTTP_Request($uri[0], $proxy_params); // the user agent HTTP_Request uses fouls things up if (isset($uri[1])) { $rq->addRawQueryString($uri[1]); } if (isset($proxy_params['proxy_host']) && isset($proxy_params['proxy_port']) && isset($proxy_params['proxy_user']) && isset($proxy_params['proxy_pass'])) { $rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port'], $proxy_params['proxy_user'], $proxy_params['proxy_pass']); } elseif (isset($proxy_params['proxy_host']) && isset($proxy_params['proxy_port'])) { $rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port']); } $result = $rq->sendRequest(); if (PEAR::isError($result)) { return $this->_raiseSoapFault("Unable to retrieve WSDL {$wsdl_fname}," . $rq->getResponseCode(), $wsdl_fname); } $file_data = $rq->getResponseBody(); if (!$file_data) { return $this->_raiseSoapFault("Unable to retrieve WSDL {$wsdl_fname}, no http body", $wsdl_fname); } } $md5_wsdl = md5($file_data); if ($this->_cacheUse) { $fp = fopen($cachename, "wb"); fwrite($fp, $file_data); fclose($fp); } } if ($this->_cacheUse && $cache && $cache != $md5_wsdl) { return $this->_raiseSoapFault("WSDL Checksum error!", $wsdl_fname); } return $file_data; }
function export_datas_to_repo() { $file = "/etc/artica-postfix/smtp.hacks.export.db"; if (!is_file($file)) { echo "{$file} no such file\n"; return; } include_once "HTTP/Request.php"; $ini = new Bs_IniHandler(); $sock = new sockets(); $datas = $sock->GET_INFO("ArticaProxySettings"); $ini->loadString($datas); $ArticaProxyServerEnabled = $ini->_params["PROXY"]["ArticaProxyServerEnabled"]; $ArticaProxyServerName = $ini->_params["PROXY"]["ArticaProxyServerName"]; $ArticaProxyServerPort = $ini->_params["PROXY"]["ArticaProxyServerPort"]; $ArticaProxyServerUsername = $ini->_params["PROXY"]["ArticaProxyServerUsername"]; $ArticaProxyServerUserPassword = $ini->_params["PROXY"]["ArticaProxyServerUserPassword"]; $req = new HTTP_Request("http://www.articatech.net/smtphack-import.php"); $req->setURL("http://www.articatech.net/smtphack-import.php"); $req->setMethod('POST'); if ($ArticaProxyServerEnabled == "yes") { $req->setProxy($ArticaProxyServerName, $ArticaProxyServerPort, $ArticaProxyServerUsername, $ArticaProxyServerUserPassword); } $req->addPostData('xyz', time()); $result = $req->addFile('smtp-hack-file', $file, 'multipart/form-data'); // $req->sendRequest(); if (PEAR::isError($result)) { echo $result->getMessage(); } else { $response = $req->sendRequest(); if (PEAR::isError($response)) { echo $response->getMessage(); return false; } if (preg_match("#SUCCESS#", $req->getResponseBody())) { if ($GLOBALS["DEBUG"]) { echo "Central server success\n" . $req->getResponseBody() . "\n"; } return true; } if ($GLOBALS["DEBUG"]) { echo "Central server failed\n" . $req->getResponseBody() . "\n"; } } }