diff --git a/.htaccess b/.htaccess index c3bfcc7..87ea14e 100755 --- a/.htaccess +++ b/.htaccess @@ -8,45 +8,37 @@ ## RewriteEngine On -RewriteCond %{HTTP_HOST} ([a-z0-9]){1,64}.(localhost|snails.email)$ +RewriteCond %{HTTP_HOST} !([a-z0-9]){1,64}.(localhost|snails.email)$ +RewriteRule ^$ ./index.php?action=jump&subdomain=1 [L,NC,QSA] + +RewriteEngine On +RewriteCond %{HTTP_HOST} !([a-z0-9]){1,64}.(localhost|snails.email)$ +RewriteCond %{REQUEST_URI} ^(php|json|serial|xml)$ +RewriteRule ^(php|json|serial|xml)$ ./index.php?response=$1&action=data&subdomain=1 [L,NC,QSA] + +RewriteEngine On +RewriteCond %{HTTP_HOST} !(.*?).([a-z0-9]){1,64}.(localhost|snails.email)$ RewriteCond %{REQUEST_URI} ^assets/(media|css|jquery|images)/(.*?)$ RewriteRule ^/(media|css|jquery|images)/(.*?)/(.*?)/(.*?)$ ./assets/$1/$2/$3/$4 [L,NC,QSA] RewriteRule ^/(media|css|jquery|images)/(.*?)/(.*?)$ ./assets/$1/$2/$3 [L,NC,QSA] RewriteRule ^/(media|css|jquery|images)/(.*?)$ ./assets/$1/$2 [L,NC,QSA] RewriteEngine On -RewriteCond %{HTTP_HOST} ([a-z0-9]){1,64}.(localhost|snails.email)$ -RewriteCond %{REQUEST_URI} !^(favicon|icon|url).(ico|png|api)$ -RewriteCond %{REQUEST_URI} !^(.*?)assets(.*?)$ -RewriteCond %{REQUEST_URI} !^(php|json|serial|xml)/(.*?)$ +RewriteCond %{HTTP_HOST} !(.*?).([a-z0-9]){1,64}.(localhost|snails.email)$ RewriteCond %{REQUEST_URI} ^([a-z0-9]{2})/(.*?)$ RewriteRule ^([a-z0-9]{2})/url.api$ ./index.php?action=url [L,NC,QSA] RewriteRule ^([a-z0-9]{2})/(.*?)$ ./index.php?action=jump&item=$2&version=$1 [L,NC,QSA] RewriteEngine On -RewriteCond %{HTTP_HOST} ([a-z0-9]){1,64}.(localhost|snails.email)$ -RewriteCond %{REQUEST_URI} !^(.*?)assets(.*?)$ -RewriteCond %{REQUEST_URI} !^([a-z0-9]{2})/(.*?)$ -RewriteCond %{REQUEST_URI} !^(php|json|serial|xml)/(.*?)$ +RewriteCond %{HTTP_HOST} !(.*?).([a-z0-9]){1,64}.(localhost|snails.email)$ RewriteCond %{REQUEST_URI} ^(favicon|icon|url).(ico|png|api)$ RewriteRule ^favicon.ico$ ./assets/images/favicon.ico [L,NC,QSA] RewriteRule ^icon.png$ ./assets/images/icon.png [L,NC,QSA] RewriteRule ^url.api$ ./index.php?action=url [L,NC,QSA] RewriteEngine On -RewriteCond %{HTTP_HOST} ([a-z0-9]){1,64}.(localhost|snails.email)$ -RewriteCond %{REQUEST_URI} !^(.*?)assets(.*?)$ -RewriteCond %{REQUEST_URI} !^([a-z0-9]{2})/(.*?)$ -RewriteCond %{REQUEST_URI} !^(favicon|icon|url).(ico|png|api)$ +RewriteCond %{HTTP_HOST} !(.*?).([a-z0-9]){1,64}.(localhost|snails.email)$ RewriteCond %{REQUEST_URI} ^(php|json|serial|xml)/(.*?)$ RewriteRule ^(php|json|serial|xml)/(.*?)$ ./index.php?action=data&response=$1&item=$2 [L,NC,QSA] -RewriteEngine On -RewriteCond %{HTTP_HOST} (.*?).([a-z0-9]){1,64}.(localhost|snails.email)$ -RewriteCond %{REQUEST_URI} ^(php|json|serial|xml)$ -RewriteRule ^(php|json|serial|xml)$ ./index.php?response=$1&action=data&subdomain=1 [L,NC,QSA] - -RewriteEngine On -RewriteCond %{HTTP_HOST} (.*?).([a-z0-9]){1,64}.(localhost|snails.email)$ -RewriteRule ^$ ./index.php?action=jump&subdomain=1 [L,NC,QSA] diff --git a/assets/index.html b/assets/index.html new file mode 100755 index 0000000..2c5cdd3 --- /dev/null +++ b/assets/index.html @@ -0,0 +1 @@ + diff --git a/class/index.html b/class/index.html new file mode 100755 index 0000000..2c5cdd3 --- /dev/null +++ b/class/index.html @@ -0,0 +1 @@ + diff --git a/class/myip.php b/class/myip.php new file mode 100755 index 0000000..c26ca8c --- /dev/null +++ b/class/myip.php @@ -0,0 +1,259 @@ + + * @version 1.0.3 + * @description A REST Services API that returns either or both or all IPv4, IPv6 addresses of a caller! + * @link http://internetfounder.wordpress.com + * @link https://github.com/Chronolabs-Cooperative/MyIP-API-PHP + * @link https://sourceforge.net/p/chronolabs-cooperative + * @link https://facebook.com/ChronolabsCoop + * @link https://twitter.com/ChronolabsCoop + * + */ + +require_once dirname(__DIR__) . DS . 'include' . DS . 'functions.php'; + +/** + * MyIP REST Service Class Factory + * + * @author Simon Roberts + * @package myip + * @subpackage api + */ +class myip { + + /** + * Current Key for the item + * + * @var string + */ + var $key = 'MYIP0000000AAAA0XXXAAAAX000XAA'; + + /** + * Current Callers IP Address + * + * @var string + */ + var $ip = NULL; + + /** + * Current Callers NetBIOS Address + * + * @var string + */ + var $netbios = NULL; + + /** + * __construct() + * + * Constructor + */ + function __construct() + { + session_start(); + $this->ip = getIP(true); + $this->netbios = getNetbios(); + } + + /** + * Querying Function for retrieving api Results + * + * @param unknown $mode + * @param unknown $format + * @return number[]|array|NULL[]|][[]|boolean[]|[[]|array|][[[]|][[]|][][[]|boolean|][[]|array|boolean|][[]|array|][][[]|array + */ + public function query($mode, $format) + { + switch ($mode) + { + default: + case "myip": + return self::yonkMyIP($format); + break; + case "allmyip": + return self::yonkAllMyIP($format); + break; + case "myipv4": + return self::yonkMyIPv4($format); + break; + case "myipv6": + return self::yonkMyIPv6($format); + break; + } + return array(); + } + + /** + * Gets all the NetBIOS IPv4/Ipv6 Addresses of the caller to the api + * + * @param unknown $format + * @return number[]|string[][]|NULL[]|string[][]|string[][][]|number[][]|NULL[][] + */ + private function yonkMyIP($format) + { + $typal = validateDomain($this->netbios)?'netbios':(validateIPv4($this->netbios)?'ipv4':(validateIPv6($this->netbios)?'ipv6':'unknown')); + $sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix('history') . "` WHERE `typal` LIKE '$typal' and `value` LIKE '" . $this->netbios . '"'; + $result = $GLOBALS['APIDB']->queryF($sql); + if (!$record = $GLOBALS['APIDB']->fetchArray($result)) + { + $field = validateIPv4($this->ip)?'ipv4':'ipv6'; + $sql = "INSERT INTO `" . $GLOBALS['APIDB']->prefix('history') . "` (`hits`, `typal`, `value`, `$field`, `created`, `queried`) VALUES('1', '$typal', '".$this->netbios."','".$this->ip."', UNIX_TIMESTAMP(), UNIX_TIMESTAMP())"; + if (!$GLOBALS['APIDB']->queryF($sql)) + die("SQL Failed: $sql"); + $record = array('hits' => 1, 'hid' => $GLOBALS['APIDB']->getInsertId()); + } else { + $sql = "UPDATE `" . $GLOBALS['APIDB']->prefix('history') . "` `hits` = `hits` + 1, `queried` = UNIX_TIMESTAMP() WHERE `hid` = '". $record['hid'] . "'"; + if (!$GLOBALS['APIDB']->queryF($sql)) + die("SQL Failed: $sql"); + $record['hits']++; + } + switch ($format) + { + case "txt": + case "html": + return array('key' => ($this->key + $record['hid']), 'hits' => $record['hits'], 'ip-address'=>array($this->ip), 'ip-type' => array(validateIPv4($this->ip)?'IPv4':'IPv6'), 'netbios' => array($this->netbios)); + break; + default: + return array(($this->key + $record['hid'])=>array('hits' => $record['hits'], 'ip'=>array('address'=>$this->ip, 'type' => validateIPv4($this->ip)?'IPv4':'IPv6'), 'netbios' => $this->netbios)); + break; + } + + } + + /** + * Gets all the NetBIOS DNS IPV4 + Ipv6 Addresses as well as the Calling Address + * + * @param unknown $format + * @return boolean[]|][[][]|array[]|][][[][]|string[][][]|number[][][]|string[][][][]|number[][]|NULL[][]|boolean[]|][[][]|array[]|][][[][]|string[][][]|number[][][]|string[][][][]|number[][]|NULL[][] + */ + private function yonkAllMyIP($format) + { + $return = array(); + $return['caller'] = self::yonkMyIP($format); + $return['ipv4'] = self::yonkMyIPv4($format); + $return['ipv6'] = self::yonkMyIPv6($format); + switch ($format) + { + case "txt": + case "html": + $result = array(); + foreach($return as $key => $values) + foreach($values as $field => $value) + $result["$key-$field"] = $value; + return $result; + break; + default: + return $return; + break; + } + } + + /** + * Gets all the NetBIOS DNS Ipv4 Addresses only + * + * @param unknown $format + * @return boolean|unknown[][][]|string[][][]|string[][]|number[][]|NULL[][] + */ + private function yonkMyIPv4($format) + { + $return = array(); + + foreach(getHostByNamel($this->netbios) as $ipv4) + { + $field = validateIPv4($ipv4)?'ipv4':'ipv6'; + $typal = validateDomain($this->netbios)?'netbios':(validateIPv4($this->netbios)?'ipv4':(validateIPv6($this->netbios)?'ipv6':'unknown')); + $sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix('history') . "` WHERE `$field` LIKE '$ipv4' AND `typal` LIKE '$typal' and `value` LIKE '" . $this->netbios . '"'; + $result = $GLOBALS['APIDB']->queryF($sql); + if (!$record = $GLOBALS['APIDB']->fetchArray($result)) + { + + $sql = "INSERT INTO `" . $GLOBALS['APIDB']->prefix('history') . "` (`hits`, `typal`, `value`, `$field`, `created`, `queried`) VALUES('1', '$typal', '".$this->netbios."','".$ipv4."', UNIX_TIMESTAMP(), UNIX_TIMESTAMP())"; + if (!$GLOBALS['APIDB']->queryF($sql)) + die("SQL Failed: $sql"); + $record = array('hits' => 1, 'hid' => $GLOBALS['APIDB']->getInsertId()); + } else { + $sql = "UPDATE `" . $GLOBALS['APIDB']->prefix('history') . "` `hits` = `hits` + 1, `queried` = UNIX_TIMESTAMP() WHERE `hid` = '". $record['hid'] . "'"; + if (!$GLOBALS['APIDB']->queryF($sql)) + die("SQL Failed: $sql"); + $record['hits']++; + } + switch ($format) + { + case "txt": + case "html": + $return[] = array('key' => ($this->key + $record['hid']), 'hits' => $record['hits'], 'ip-address'=>array($ipv4), 'ip-type' => array(validateIPv4($ipv4)?'IPv4':'IPv6'), 'netbios' => array($this->netbios)); + break; + default: + $return[($this->key + $record['hid'])] = array('hits' => $record['hits'], 'ip'=>array('address'=>$ipv4, 'type' => validateIPv4($ipv4)?'IPv4':'IPv6'), 'netbios' => $this->netbios); + break; + } + } + return empty($return)?false:$return; + } + + /** + * Gets all the NetBIOS DNS Ipv6 Addresses only + * + * @param string $format + * @return boolean|unknown[][][]|string[][][]|string[][]|number[][]|NULL[][]|boolean[][][]|unknown[][][][] + */ + private function yonkMyIPv6($format) + { + $return = array(); + foreach(getHostByNamel6($this->netbios, false) as $ipv6) + { + $field = validateIPv6($ipv6)?'ipv6':'ipv4'; + $typal = validateDomain($this->netbios)?'netbios':(validateIPv4($this->netbios)?'ipv4':(validateIPv6($this->netbios)?'ipv6':'unknown')); + $sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix('history') . "` WHERE `$field` LIKE '$ipv6' AND `typal` LIKE '$typal' and `value` LIKE '" . $this->netbios . '"'; + $result = $GLOBALS['APIDB']->queryF($sql); + if (!$record = $GLOBALS['APIDB']->fetchArray($result)) + { + + $sql = "INSERT INTO `" . $GLOBALS['APIDB']->prefix('history') . "` (`hits`, `typal`, `value`, `$field`, `created`, `queried`) VALUES('1', '$typal', '".$this->netbios."','".$ipv6."', UNIX_TIMESTAMP(), UNIX_TIMESTAMP())"; + if (!$GLOBALS['APIDB']->queryF($sql)) + die("SQL Failed: $sql"); + $record = array('hits' => 1, 'hid' => $GLOBALS['APIDB']->getInsertId()); + } else { + $sql = "UPDATE `" . $GLOBALS['APIDB']->prefix('history') . "` `hits` = `hits` + 1, `queried` = UNIX_TIMESTAMP() WHERE `hid` = '". $record['hid'] . "'"; + if (!$GLOBALS['APIDB']->queryF($sql)) + die("SQL Failed: $sql"); + $record['hits']++; + } + switch ($format) + { + case "txt": + case "html": + $return[] = array('key' => ($this->key + $record['hid']), 'hits' => $record['hits'], 'ip-address'=>array($ipv6), 'ip-type' => array(validateIPv4($ipv6)?'IPv4':'IPv6'), 'netbios' => array($this->netbios)); + break; + default: + $return[($this->key + $record['hid'])] = array('hits' => $record['hits'], 'ip'=>array('address'=>$ipv6, 'type' => validateIPv4($ipv6)?'IPv4':'IPv6'), 'netbios' => $this->netbios); + break; + } + } + return empty($return)?false:$return; + } + + + /** + * __destruct() + * Destructor + */ + function __destruct() { + + } + +} diff --git a/crons/index.html b/crons/index.html new file mode 100755 index 0000000..2c5cdd3 --- /dev/null +++ b/crons/index.html @@ -0,0 +1 @@ + diff --git a/crons/jump-deploy-calling.php b/crons/jump-deploy-calling.php new file mode 100755 index 0000000..18cdf43 --- /dev/null +++ b/crons/jump-deploy-calling.php @@ -0,0 +1,46 @@ + + * @version 2.2.1 + * @subpackage deploy-jump-api + * @description Cron Job for Calling to Short Link Deployment API + * @link https://github.com/Chronolabs-Cooperative/Deploy-Jump-API-PHP + * @link https://github.com/Chronolabs-Cooperative/Jump-API-PHP + */ + + include_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'deployment.php'; + require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'apiconfig.php'; + require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'functions.php'; + + + if (constant('API_DEPLOYMENT_CALLING') == true) { + if (!is_file($callfile = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . API_HOSTNAME . '.calling.json')) + $calls = array(); + else + $calls = json_decode(file_get_contents($callfile), true); + + if (count($calls) > 0) + foreach($calls as $type => $typals) + foreach($typals as $hash => $actions) + foreach($actions as $time => $values) { + $authkey = json_decode(getURIData(API_DEPLOYMENT_AUTH_URL, 25, 25, array('username' => API_DEPLOYMENT_USERNAME, 'password' => API_DEPLOYMENT_PASSWORD, 'format' => 'json')), true); + @getURIData(sprintf(API_DEPLOYMENT_CALLBACK_FUNCTION_MODAL_URL, $authkey['authkey'], $type, str_replace('.', '-', $values['hostname'])), 180, 180, array_merge(array('type' => $type, 'hostname' => $hostname, 'time' => $time, 'key' => $hash, 'format' => 'json'), $values)); + unset($calls[$type][$hash][$time]); + writeRawFile($callfile, json_encode($calls)); + $calls = json_decode(file_get_contents($callfile), true); + } + + } diff --git a/data/index.html b/data/index.html index 990cbd6..2c5cdd3 100755 --- a/data/index.html +++ b/data/index.html @@ -1 +1 @@ - \ No newline at end of file + diff --git a/deployment.php b/deployment.php new file mode 100755 index 0000000..5db613e --- /dev/null +++ b/deployment.php @@ -0,0 +1,39 @@ + + * @version 2.2.1 + * @subpackage shortening-url + * @description Short Link URIs API + * @link http://internetfounder.wordpress.com + * @link http://sourceoforge.net/projects/chronolabsapis/files/jump.labs.coop + * @link https://github.com/Chronolabs-Cooperative/Jump-API-PHP + */ + +/** + * + * @var constants + */ +define("API_DEPLOYMENT_URL", 'http://deploy.jump.snails.email'); +define("API_DEPLOYMENT_AUTH_URL", API_DEPLOYMENT_URL . '/v1/auth.api'); +define("API_DEPLOYMENT_CALLBACK_FUNCTION_URL", API_DEPLOYMENT_URL . '/v1/%s/%s/callback.api'); +define("API_DEPLOYMENT_CALLBACK_FUNCTION_MODAL_URL", API_DEPLOYMENT_URL . '/v1/%s/%s/%s/callback.api'); +define("API_DEPLOYMENT_CALLING", false); +define("API_DEPLOYMENT_JUMPAPI_HOSTNAMES", 'https://raw.githubusercontent.com/Chronolabs-Cooperative/Jump-API-PHP/master/services.txt'); + +// define("API_DEPLOYMENT_CALLING", true); +// define("API_DEPLOYMENT_USERNAME", ''); +// define("API_DEPLOYMENT_PASSWORD", ''); + diff --git a/functions.php b/functions.php index 6c17277..8b72b45 100755 --- a/functions.php +++ b/functions.php @@ -221,46 +221,69 @@ function apiLoadLanguage($definition = 'help', $language = 'english') if (!function_exists("getURIData")) { - - /** - * getURIData() ~ get data from a URI/URL - * - * @param string $uri - * @param array $posts - * @param getURIData $headers - * @param integer $timeout - * @param integer $connectout - * @return string - */ - function getURIData($uri = '', $posts = array(), $headers = array(), $timeout = 36, $connectout = 44) - { - if (!function_exists("curl_init")) - { - return file_get_contents($uri); - } - if (!$btt = curl_init($uri)) { - return false; - } - if (count($headers)) { - curl_setopt($btt, CURLOPT_HEADER, true); - curl_setopt($btt, CURLOPT_HEADERS, $headers); - } else - curl_setopt($btt, CURLOPT_HEADER, 0); - if (count($posts)) { - curl_setopt($btt, CURLOPT_POST, true); - curl_setopt($btt, CURLOPT_POSTFIELDS, http_build_query($posts)); - } else - curl_setopt($btt, CURLOPT_POST, 0); - curl_setopt($btt, CURLOPT_CONNECTTIMEOUT, $connectout); - curl_setopt($btt, CURLOPT_TIMEOUT, $timeout); - curl_setopt($btt, CURLOPT_RETURNTRANSFER, true); - curl_setopt($btt, CURLOPT_VERBOSE, false); - curl_setopt($btt, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($btt, CURLOPT_SSL_VERIFYPEER, false); - $data = curl_exec($btt); - curl_close($btt); - return $data; - } + + /* function yonkURIData() + * + * Get a supporting domain system for the API + * @author Simon Roberts (Chronolabs) simon@labs.coop + * + * @return float() + */ + function getURIData($uri = '', $timeout = 25, $connectout = 25, $post = array(), $headers = array()) + { + if (!function_exists("curl_init")) + { + die("Install PHP Curl Extension ie: $ sudo apt-get install php-curl -y"); + } + $GLOBALS['php-curl'][md5($uri)] = array(); + if (!$btt = curl_init($uri)) { + return false; + } + if (count($post)==0 || empty($post)) + curl_setopt($btt, CURLOPT_POST, false); + else { + $uploadfile = false; + foreach($post as $field => $value) + if (substr($value , 0, 1) == '@' && !file_exists(substr($value , 1, strlen($value) - 1))) + unset($post[$field]); + else + $uploadfile = true; + curl_setopt($btt, CURLOPT_POST, true); + curl_setopt($btt, CURLOPT_POSTFIELDS, http_build_query($post)); + + if (!empty($headers)) + foreach($headers as $key => $value) + if ($uploadfile==true && substr($value, 0, strlen('Content-Type:')) == 'Content-Type:') + unset($headers[$key]); + if ($uploadfile==true) + $headers[] = 'Content-Type: multipart/form-data'; + } + if (count($headers)==0 || empty($headers)) + curl_setopt($btt, CURLOPT_HEADER, false); + else { + curl_setopt($btt, CURLOPT_HEADER, true); + curl_setopt($btt, CURLOPT_HTTPHEADER, $headers); + } + curl_setopt($btt, CURLOPT_CONNECTTIMEOUT, $connectout); + curl_setopt($btt, CURLOPT_TIMEOUT, $timeout); + curl_setopt($btt, CURLOPT_RETURNTRANSFER, true); + curl_setopt($btt, CURLOPT_VERBOSE, false); + curl_setopt($btt, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($btt, CURLOPT_SSL_VERIFYPEER, false); + $data = curl_exec($btt); + $GLOBALS['php-curl'][md5($uri)]['http']['posts'] = $post; + $GLOBALS['php-curl'][md5($uri)]['http']['headers'] = $headers; + $GLOBALS['php-curl'][md5($uri)]['http']['code'] = curl_getinfo($btt, CURLINFO_HTTP_CODE); + $GLOBALS['php-curl'][md5($uri)]['header']['size'] = curl_getinfo($btt, CURLINFO_HEADER_SIZE); + $GLOBALS['php-curl'][md5($uri)]['header']['value'] = curl_getinfo($btt, CURLINFO_HEADER_OUT); + $GLOBALS['php-curl'][md5($uri)]['size']['download'] = curl_getinfo($btt, CURLINFO_SIZE_DOWNLOAD); + $GLOBALS['php-curl'][md5($uri)]['size']['upload'] = curl_getinfo($btt, CURLINFO_SIZE_UPLOAD); + $GLOBALS['php-curl'][md5($uri)]['content']['length']['download'] = curl_getinfo($btt, CURLINFO_CONTENT_LENGTH_DOWNLOAD); + $GLOBALS['php-curl'][md5($uri)]['content']['length']['upload'] = curl_getinfo($btt, CURLINFO_CONTENT_LENGTH_UPLOAD); + $GLOBALS['php-curl'][md5($uri)]['content']['type'] = curl_getinfo($btt, CURLINFO_CONTENT_TYPE); + curl_close($btt); + return $data; + } } @@ -537,53 +560,212 @@ function whitelistGetNetBIOSIP() { } } -if (!function_exists("whitelistGetIP")) { +if (!function_exists("getIP")) { + + /* function whitelistGetIP() + * + * get the True IPv4/IPv6 address of the client using the API + * @author Simon Roberts (Chronolabs) simon@labs.coop + * + * @param boolean $asString Whether to return an address or network long integer + * + * @return mixed + */ + function getIP($asString = true){ + // Gets the proxy ip sent by the user + $proxy_ip = ''; + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $proxy_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } else + if (!empty($_SERVER['HTTP_X_FORWARDED'])) { + $proxy_ip = $_SERVER['HTTP_X_FORWARDED']; + } else + if (! empty($_SERVER['HTTP_FORWARDED_FOR'])) { + $proxy_ip = $_SERVER['HTTP_FORWARDED_FOR']; + } else + if (!empty($_SERVER['HTTP_FORWARDED'])) { + $proxy_ip = $_SERVER['HTTP_FORWARDED']; + } else + if (!empty($_SERVER['HTTP_VIA'])) { + $proxy_ip = $_SERVER['HTTP_VIA']; + } else + if (!empty($_SERVER['HTTP_X_COMING_FROM'])) { + $proxy_ip = $_SERVER['HTTP_X_COMING_FROM']; + } else + if (!empty($_SERVER['HTTP_COMING_FROM'])) { + $proxy_ip = $_SERVER['HTTP_COMING_FROM']; + } + if (!empty($proxy_ip) && $is_ip = preg_match('/^([0-9]{1,3}.){3,3}[0-9]{1,3}/', $proxy_ip, $regs) && count($regs) > 0) { + $the_IP = $regs[0]; + } else { + $the_IP = $_SERVER['REMOTE_ADDR']; + } + $the_IP = ($asString) ? $the_IP : ip2long($the_IP); + return $the_IP; + } +} - /* function whitelistGetIP() - * - * get the True IPv4/IPv6 address of the client using the API - * @author Simon Roberts (Chronolabs) simon@labs.coop - * - * @param $asString boolean Whether to return an address or network long integer - * - * @return mixed - */ - function whitelistGetIP($asString = true){ - // Gets the proxy ip sent by the user - $proxy_ip = ''; - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { - $proxy_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; - } else - if (!empty($_SERVER['HTTP_X_FORWARDED'])) { - $proxy_ip = $_SERVER['HTTP_X_FORWARDED']; - } else - if (! empty($_SERVER['HTTP_FORWARDED_FOR'])) { - $proxy_ip = $_SERVER['HTTP_FORWARDED_FOR']; - } else - if (!empty($_SERVER['HTTP_FORWARDED'])) { - $proxy_ip = $_SERVER['HTTP_FORWARDED']; - } else - if (!empty($_SERVER['HTTP_VIA'])) { - $proxy_ip = $_SERVER['HTTP_VIA']; - } else - if (!empty($_SERVER['HTTP_X_COMING_FROM'])) { - $proxy_ip = $_SERVER['HTTP_X_COMING_FROM']; - } else - if (!empty($_SERVER['HTTP_COMING_FROM'])) { - $proxy_ip = $_SERVER['HTTP_COMING_FROM']; - } - if (!empty($proxy_ip) && $is_ip = preg_match('/^([0-9]{1,3}.){3,3}[0-9]{1,3}/', $proxy_ip, $regs) && count($regs) > 0) { - $the_IP = $regs[0]; - } else { - $the_IP = $_SERVER['REMOTE_ADDR']; - } - - $the_IP = ($asString) ? $the_IP : ip2long($the_IP); - return $the_IP; - } + +if (!function_exists("getNetbios")) { + + /* function whitelistGetIP() + * + * get the True IPv4/IPv6 address of the client using the API + * @author Simon Roberts (Chronolabs) simon@labs.coop + * + * @param boolean $asString Whether to return an address or network long integer + * + * @return mixed + */ + function getNetbios() { + // Gets the proxy ip sent by the user + $proxy_ip = ''; + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $proxy_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } else + if (!empty($_SERVER['HTTP_X_FORWARDED'])) { + $proxy_ip = $_SERVER['HTTP_X_FORWARDED']; + } else + if (! empty($_SERVER['HTTP_FORWARDED_FOR'])) { + $proxy_ip = $_SERVER['HTTP_FORWARDED_FOR']; + } else + if (!empty($_SERVER['HTTP_FORWARDED'])) { + $proxy_ip = $_SERVER['HTTP_FORWARDED']; + } else + if (!empty($_SERVER['HTTP_VIA'])) { + $proxy_ip = $_SERVER['HTTP_VIA']; + } else + if (!empty($_SERVER['HTTP_X_COMING_FROM'])) { + $proxy_ip = $_SERVER['HTTP_X_COMING_FROM']; + } else + if (!empty($_SERVER['HTTP_COMING_FROM'])) { + $proxy_ip = $_SERVER['HTTP_COMING_FROM']; + } + if (!empty($proxy_ip) && $is_ip = preg_match('/^([0-9]{1,3}.){3,3}[0-9]{1,3}/', $proxy_ip, $regs) && count($regs) > 0) { + $the_IP = $regs[0]; + } else { + $the_IP = $_SERVER['REMOTE_ADDR']; + } + return gethostbyaddr($the_IP); + } +} + +/** + * get A + AAAA record for $host + * + * if $try_a is true, if AAAA fails, it tries for A the first match found is returned otherwise returns false + * + * @param host string netbios networking name\ + * @param try_a boolean try for A Record inclusive of AAAA Records + * + * return array + */ +if (!function_exists("getHostByName6")) { + function getHostByName6($host, $try_a = false) { + $dns6 = dns_get_record($host, DNS_AAAA); + if ($try_a == true) { + $dns4 = getHostByName($host); + $dns = array_merge($dns4, $dns6); + } + else { $dns = $dns6; } + if ($dns == false) { return false; } + else { return $dns; } + } } +/** + * get A + AAAA record IPv4/IPv6 Addresses for $host + * + * if $try_a is true, if AAAA fails, it tries for A the first match found is returned otherwise returns false + * + * @param host string netbios networking name + * @param try_a boolean try for A Record inclusive of AAAA Records + * + * return array + */ +if (!function_exists("getHostByNamel6")) { + function getHostByNamel6($host, $try_a = false) { + + $dns6 = dns_get_record($host, DNS_AAAA); + if ($try_a == true) { + $dns4 = getHostByName($host); + $dns = array_merge($dns4, $dns6); + } + else { $dns = $dns6; } + $ip6 = array(); + $ip4 = array(); + foreach ($dns as $record) { + if ($record["type"] == "A") { + $ip4[] = $record["ip"]; + } + if ($record["type"] == "AAAA") { + $ip6[] = $record["ipv6"]; + } + } + if (count($ip6) < 1) { + if ($try_a == true) { + if (count($ip4) < 1) { + return false; + } + else { + return $ip4; + } + } + else { + return false; + } + } + else { + return $ip6; + } + } +} + +/** + * get A record for $host + * + * if $try_a is true, if AAAA fails, it tries for A the first match found is returned otherwise returns false + * + * @param host string netbios networking name + * + * return array + */ +if (!function_exists("getHostByName")) { + function getHostByName($host) { + $dns = dns_get_record($host, DNS_A); + if ($dns == false) { return false; } + else { return $dns; } + } +} + +/** + * get A record IPv4 Addresses for $host + * + * if $try_a is true, if AAAA fails, it tries for A the first match found is returned otherwise returns false + * + * @param host string netbios networking name + * + * return array + */ +if (!function_exists("getHostByNamel")) { + function getHostByNamel($host) { + $dns4 = getHostByName($host); + $ip4 = array(); + foreach ($dns4 as $record) { + if ($record["type"] == "A") { + $ip4[] = $record["ip"]; + } + } + if (count($ip4) < 1) { + return false; + } + else { + return $ip4; + } + } +} + /** * * @param unknown_type $url @@ -611,18 +793,44 @@ function jumpShortenURL($url = '') $referee = $crc->calc($url); } } - if (!is_file($file = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . basename(__DIR__) . '.json')) - $jumps = array(); + if (!is_file($jumpfile = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . API_HOSTNAME . '.json')) + $jumps = array(); + else + $jumps = json_decode(file_get_contents($jumpfile), true); + + if (!is_file($emailfile = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . API_HOSTNAME . '.emails.json')) + $emails = array(); + else + $emails = json_decode(file_get_contents($emailfile), true); + + if (constant('API_DEPLOYMENT_CALLING') == true) { + require_once dirname(__DIR__) . DS . 'class' . DS . 'myip.php'; + $myip = new myip(); + $ipdata = $myip->query('allmyip', 'json'); + if (!is_file($callfile = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . API_HOSTNAME . '.calling.json')) + $calls = array(); else - $jumps = json_decode(file_get_contents($file), true); - foreach($jumps as $finger => $values) - { - if (isset($values['last']) && isset($values['inactive'])) - if ($values['last'] + $values['inactive'] < microtime(true)) - unset($jumps[$finger]); - } - $result = $jumps[$hash = md5($url.$referee.microtime(true))] = array("created" => microtime(true), "last" => microtime(true), 'inactive' => (API_DROP_DAYS_INACTIVE * (3600 * 24)), "short" => API_PROTOCOL.API_HOSTNAME.'/v2/'.$referee, "domain" => API_PROTOCOL.$referee.'.'.API_HOSTNAME, 'url' => $url, 'referee' => $referee, 'timezone' => date_default_timezone_get(), 'data' => array('php' => API_PROTOCOL.API_HOSTNAME.'/php/'.$referee, 'json' => API_PROTOCOL.API_HOSTNAME.'/json/'.$referee, 'serial' => API_PROTOCOL.API_HOSTNAME.'/serial/'.$referee, 'xml' => API_PROTOCOL.API_HOSTNAME.'/xml/'.$referee)); - writeRawFile($file, json_encode($jumps)); + $calls = json_decode(file_get_contents($callfile), true); + } + foreach($jumps as $finger => $values) + { + if (isset($values['last']) && isset($values['inactive'])) + if ($values['last'] + $values['inactive'] < microtime(true)) { + $calls['expire'][$finger][time()] = array_merge(array('ipdata' => $ipdata), $emails[$finger], $jumps[$finger], array('hostname' => parse_url(API_URL, PHP_URL_HOST))); + unset($jumps[$finger]); + unset($emails[$finger]); + } + } + $result = $jumps[$hash = md5($url.$referee.microtime(true))] = array("created" => microtime(true), "last" => microtime(true), 'inactive' => (API_DROP_DAYS_INACTIVE * (3600 * 24)), "short" => API_PROTOCOL.API_HOSTNAME.'/v2/'.$referee . (isset($_REQUEST['username']) && !empty($_REQUEST['username']) ? '?' . $_REQUEST['username'] :''), "domain" => API_PROTOCOL.$referee.'.'.API_HOSTNAME . (isset($_REQUEST['username']) && !empty($_REQUEST['username']) ? '/?' . $_REQUEST['username'] :''), 'url' => $url, 'referee' => $referee, 'timezone' => date_default_timezone_get(), 'data' => array('php' => API_PROTOCOL.API_HOSTNAME.'/php/'.$referee, 'json' => API_PROTOCOL.API_HOSTNAME.'/json/'.$referee, 'serial' => API_PROTOCOL.API_HOSTNAME.'/serial/'.$referee, 'xml' => API_PROTOCOL.API_HOSTNAME.'/xml/'.$referee)); + $emails[$hash] = array('username' => $_REQUEST['username'], 'email' => $_REQUEST['email'], 'callback-hits' => $_REQUEST['callback-hits'], 'callback-stats' => $_REQUEST['callback-stats'], 'callback-reports' => $_REQUEST['callback-reports'], 'callback-expires' => $_REQUEST['callback-expires']); + if (constant('API_DEPLOYMENT_CALLING') == true) { + $calls['create'][$hash][time()] = array_merge(array('ipdata' => $ipdata), $emails[$hash], $jumps[$hash], array('hostname' => parse_url(API_URL, PHP_URL_HOST))); + } + writeRawFile($jumpfile, json_encode($jumps)); + writeRawFile($emailfile, json_encode($emails)); + if (constant('API_DEPLOYMENT_CALLING') == true) { + writeRawFile($callfile, json_encode($calls)); + } return $result; } @@ -637,15 +845,35 @@ function jumpFromShortenURL($hash = '') $hostname = array_reverse(explode('.', $_SERVER['HTTP_HOST'])); if (!is_dir(API_PATH_IO_REFEREE)) mkdirSecure(API_PATH_IO_REFEREE, 0777); - if (!is_file($file = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . basename(__DIR__) . '.json')) - $jumps = array(); - else - $jumps = json_decode(file_get_contents($file), true); + + if (!is_file($jumpfile = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . API_HOSTNAME . '.json')) + $jumps = array(); + else + $jumps = json_decode(file_get_contents($jumpfile), true); + + if (!is_file($emailfile = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . API_HOSTNAME . '.emails.json')) + $emails = array(); + else + $emails = json_decode(file_get_contents($emailfile), true); + + if (constant('API_DEPLOYMENT_CALLING') == true) { + require_once dirname(__DIR__) . DS . 'class' . DS . 'myip.php'; + $myip = new myip(); + $ipdata = $myip->query('allmyip', 'json'); + if (!is_file($callfile = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . API_HOSTNAME . '.calling.json')) + $calls = array(); + else + $calls = json_decode(file_get_contents($callfile), true); + } + foreach($jumps as $finger => $values) { if (isset($values['last']) && isset($values['inactive'])) - if ($values['last'] + $values['inactive'] < microtime(true)) - unset($jumps[$finger]); + if ($values['last'] + $values['inactive'] < microtime(true)) { + $calls['expire'][$finger][time()] = array_merge(array('ipdata' => $ipdata), $emails[$finger], $jumps[$finger], array('hostname' => parse_url(API_URL, PHP_URL_HOST))); + unset($jumps[$finger]); + unset($emails[$finger]); + } } foreach($jumps as $finger => $values) { @@ -656,7 +884,14 @@ function jumpFromShortenURL($hash = '') else $jumps[$finger]['hits']++; $jumps[$finger]['last'] = microtime(true); - writeRawFile($file, json_encode($jumps)); + writeRawFile($jumpfile, json_encode($jumps)); + if (constant('API_DEPLOYMENT_CALLING') == true) { + $calls['hit'][$finger][microtime(true)] = array_merge(array('ipdata' => $ipdata), $emails[$hash], $jumps[$hash], array('hostname' => parse_url(API_URL, PHP_URL_HOST))); + } + writeRawFile($emailfile, json_encode($emails)); + if (constant('API_DEPLOYMENT_CALLING') == true) { + writeRawFile($callfile, json_encode($calls)); + } // Redirect to ensourced URI header( "HTTP/1.1 301 Moved Permanently" ); @@ -666,7 +901,7 @@ function jumpFromShortenURL($hash = '') } } - writeRawFile($file, json_encode($jumps)); + writeRawFile($jumpfile, json_encode($jumps)); // Redirect to ensourced URI header( "HTTP/1.1 301 Moved Permanently" ); @@ -681,23 +916,51 @@ function jumpFromShortenURL($hash = '') */ function dataFromShortenURL($hash = '') { - $hostname = array_reverse(explode('.', $_SERVER['HTTP_HOST'])); + if (!is_dir(API_PATH_IO_REFEREE)) mkdirSecure(API_PATH_IO_REFEREE, 0777); - if (!is_file($file = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . basename(__DIR__) . '.json')) + + if (!is_file($jumpfile = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . API_HOSTNAME . '.json')) $jumps = array(); else - $jumps = json_decode(file_get_contents($file), true); + $jumps = json_decode(file_get_contents($jumpfile), true); + + if (!is_file($emailfile = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . API_HOSTNAME . '.emails.json')) + $emails = array(); + else + $emails = json_decode(file_get_contents($emailfile), true); + + if (constant('API_DEPLOYMENT_CALLING') == true) { + require_once dirname(__DIR__) . DS . 'class' . DS . 'myip.php'; + $myip = new myip(); + $ipdata = $myip->query('allmyip', 'json'); + if (!is_file($callfile = API_PATH_IO_REFEREE . DIRECTORY_SEPARATOR . API_HOSTNAME . '.calling.json')) + $calls = array(); + else + $calls = json_decode(file_get_contents($callfile), true); + } + foreach($jumps as $finger => $values) { if (isset($values['last']) && isset($values['inactive'])) - if ($values['last'] + $values['inactive'] < microtime(true)) + if ($values['last'] + $values['inactive'] < microtime(true)) { + $calls['expire'][$finger][time()] = array_merge(array('ipdata' => $ipdata), $emails[$finger], $jumps[$finger], array('hostname' => parse_url(API_URL, PHP_URL_HOST))); unset($jumps[$finger]); + unset($emails[$finger]); + } } + writeRawFile($jumpfile, json_encode($jumps)); + writeRawFile($emailfile, json_encode($emails)); foreach($jumps as $finger => $values) { if (strtolower($values['referee']) == strtolower($hash)) { + if (constant('API_DEPLOYMENT_CALLING') == true) { + $calls['data'][$finger][microtime(true)] = array_merge(array('ipdata' => $ipdata), $emails[$finger], $jumps[$finger], array('hostname' => parse_url(API_URL, PHP_URL_HOST))); + } + if (constant('API_DEPLOYMENT_CALLING') == true) { + writeRawFile($callfile, json_encode($calls)); + } return $values; } } diff --git a/index.php b/index.php index f18f80d..4081794 100755 --- a/index.php +++ b/index.php @@ -25,6 +25,7 @@ define('MAXIMUM_QUERIES', 56); ini_set('memory_limit', '32M'); + include_once __DIR__ . DIRECTORY_SEPARATOR . 'deployment.php'; require_once __DIR__ . DIRECTORY_SEPARATOR . 'apiconfig.php'; require_once __DIR__ . DIRECTORY_SEPARATOR . 'functions.php'; @@ -38,7 +39,6 @@ } elseif (($action == 'jump' || $action == 'data') && !empty($_REQUEST['item'])) $item = $_REQUEST['item']; - http_response_code(200); switch ($action) { default: if (function_exists("http_response_code")) @@ -57,6 +57,14 @@ } $response = (isset($_REQUEST['response'])?$_REQUEST['response']:'raw'); + if (function_exists("http_response_code")) + if (isset($data['code']) && !empty($data['code'])) { + http_response_code($data['code']); + unset($data['code']); + } else { + http_response_code(201);; + } + // Send Responses switch ($response) { diff --git a/language/english/apis-labs.coop.html b/language/english/apis-labs.coop.html index 6bb9710..af808c5 100755 --- a/language/english/apis-labs.coop.html +++ b/language/english/apis-labs.coop.html @@ -1,6 +1,6 @@ -
+

Git/SVN Resources

The following URL is the location of this project on GitHub.com: https://github.com/Chronolabs-Cooperative/Jump-API-PHP; you will be able to join as well as contribute to this API through this resource!

-

Download the Source Code

-

A lot of our source-code is open and stored on sourceforge.net - you will find the api source code in it's own private project here:- sourceforge.net/projects/chronolabsapis!

+

Download the Source Code

+

A lot of our source-code is open and stored on sourceforge.net - you will find the api source code in it's own private project here:- https://sourceforge.net/projects/chronolabs-cooperative/!

diff --git a/language/english/help.php b/language/english/help.php index 25e904a..fe5c42e 100755 --- a/language/english/help.php +++ b/language/english/help.php @@ -22,7 +22,7 @@ * @link https://github.com/Chronolabs-Cooperative/Jump-API-PHP */ -if (strlen($theip = whitelistGetIP(true))==0) +if (strlen($theip = getIP(true))==0) $theip = "127.0.0.1"; $data = ''; @@ -123,8 +123,14 @@
- - +
+ + +
+
+
+
+
Example of Form:-
@@ -135,8 +141,14 @@
 		<label for="response-serial">Response formated PHP Serialisation </label><input type="radio" name="response" id="response-serial" value="serial"/>
 		<label for="response-xml">Response formated XML </label><input type="radio" name="response" id="response-xml" value="xml"/><br/>
 		<label for="url">URL/URI to shorten</label><input type="textbox" name="url" id="url" value="http://" size="36" maxlen="5000"/>
-                <label for="custom">Custom Referee Prefer</label><input type="textbox" name="custom" id="custom" value="" size="12" maxlen="128"/>
-		<input type"submit" id="submit" Value="Shorten URI/URL" />
+        <label for="custom">Custom Referee Prefer</label><input type="textbox" name="custom" id="custom" value="" size="12" maxlen="128"/><br/>
+		<label for="username">Username on ''</label><input type="textbox" name="username" id="username" value="" size="24" maxlen="64"/>
+		<label for="email">Your/Telephanist Contact Email</label><input type="textbox" name="email" id="email" value="" size="24" maxlen="200"/>
+		<br/ ><label for="callback-hits">Call Back URL for Hits</label><input type="textbox" name="callback-hits" id="callback-hits" value="" size="44" maxlen="200" />
+		<br/ ><label for="callback-stats">Call Back URL for Statistics</label><input type="textbox" name="callback-stats" id="callback-stats" value="" size="44" maxlen="200" />
+		<br/ ><label for="callback-reports">Call Back URL for Reports</label><input type="textbox" name="callback-reports" id="callback-reports" value="" size="44" maxlen="200" />
+		<br/ ><label for="callback-expires">Call Back URL for Expiry</label><input type="textbox" name="callback-expires" id="callback-expires" value="" size="44" maxlen="200" />
+		<br/ ><input type"submit" id="submit" Value="Shorten URI/URL" />
 	</form>
 		


@@ -192,7 +204,7 @@ function getURIData($uri = '', $timeout = 25, $connectout = 25, $post_data = arr
 
 
- +

Shortening URL Services Operate on the following URLs

The following URL can be used to Shortening a URL, they are the following domains with this API on it:-