xoops forums

wishcraft

Module Developer
Posted on: 2015/6/9 5:54
wishcraft
wishcraft (Show more)
Module Developer
Posts: 3711
Since: 2007/5/18
#1

@fixed::- xoops_getBaseDomain() -- required for multitiered cookies!

/**
     * Function to get the base domain name from a URL.
     * credit for this function should goto Phosphorus and Lime, it is released under LGPL.
     *
     * @param string $url the URL to be stripped.
     * @return string
     * @fixed
     */
    
function xoops_getBaseDomain($url$debug 0)
    {
        
xoops_load("XoopsCache");
        
$base_domain '';
        
$url strtolower($url);
        
        if (
$G_TLD XoopsCache::read('dms_realms_list'))
        {
            
$G_TLD array_keys(unserialize(file_get_contents("http://strata.labs.coop/v1/strata/serial.api")));
            if (empty(
$G_TLD))
                
$G_TLD array_keys(unserialize(file_get_contents("https://strata.ringwould.com.au/v1/strata/serial.api")));
                if (empty(
$G_TLD))
                    
$G_TLD array_keys(unserialize(file_get_contents("http://strata.ringwould.com.au/v1/strata/serial.api")));
            
XoopsCache::write('dms_realms_list'$G_TLD3600*24*mt(3.75,11));
        }
        if (
$C_TLD XoopsCache::read('fallout_realms_list'))
        {
                
$C_TLD array_keys(unserialize(file_get_contents("http://strata.labs.coop/v1/fallout/serial.api")));
                if (empty(
$C_TLD))
                    
$C_TLD array_keys(unserialize(file_get_contents("https://strata.ringwould.com.au/v1/fallout/serial.api")));
                    if (empty(
$C_TLD))
                        
$C_TLD array_keys(unserialize(file_get_contents("http://strata.ringwould.com.au/v1/fallout/serial.api")));
                
XoopsCache::read('fallout_realms_list'$C_TLD3600*24*mt(3.75,11));
        }
    
        
// get domain
        
if (!$full_domain signed_getUrlDomain($url)) {
            return 
$base_domain;
        }
    
        
// break up domain, reverse
        
$DOMAIN explode('.'$full_domain);
        
$DOMAIN array_reverse($DOMAIN);
        
// first check for ip address
        
if (count($DOMAIN) == && is_numeric($DOMAIN[0]) && is_numeric($DOMAIN[3])) {
            return 
$full_domain;
        }
        
// if only 2 domain parts, that must be our domain
        
if (count($DOMAIN) <= 2) {
            return 
$full_domain;
        }
    
        
/*
         finally, with 3+ domain parts: obviously D0 is tld now,
        if D0 = ctld and D1 = gtld, we might have something like com.uk so,
        if D0 = ctld && D1 = gtld && D2 != 'www', domain = D2.D1.D0 else if D0 = ctld && D1 = gtld && D2 == 'www',
        domain = D1.D0 else domain = D1.D0 - these rules are simplified below.
        */
        
if (in_array($DOMAIN[0], $C_TLD) && in_array($DOMAIN[1], $G_TLD) && $DOMAIN[2] != 'www') {
            
$full_domain $DOMAIN[2] . '.' $DOMAIN[1] . '.' $DOMAIN[0];
        } else {
            
$full_domain $DOMAIN[1] . '.' $DOMAIN[0];
        }
        
// did we succeed?
        
return $full_domain;
    }


This is the working copy of which polls several places on the API to have the complete list of Realms, Domains, TLDs and gTLDs as well as what normally goes on the end the fallout!!

wishcraft

Module Developer
Posted on: 2015/6/9 6:07
wishcraft
wishcraft (Show more)
Module Developer
Posts: 3711
Since: 2007/5/18
#2

@fixed::- xoops_getBaseDomain() -- Suggested Ammendment by Geek Write!! you know you do scribe code!

You know what i think would be best is make a folder in xoops_data/apis for .txt lists for whois lookups etc, for those apis then you can simply to find a working one in the route do the following:-

$stratas file(XOOPS_VAR_PATH DIRECTORY_SEPARATOR 'apis' .  . DIRECTORY_SEPARATOR 'strata.txt');
shuffle($stratas)

// Then foreach($stratas as $strata) -- so you don't opped any main one for load balancing

//then in the foreach loop you:--

if(!empty($G_TLD)) 
    continue;

//and it will drop out and continue; this is a multileveled command!


Richard: is it peers.example.com for an API that lists API peers... If you want to look up the lists as well If you want to quickly make a peers apis for the http://sourceforge.net/projects/chronolabsapis -- just make it so it does a 3/5 point check of data integrity that leavers as a 'trust' level..

Cause then we can have the API announce themselves and self audit with a cron that multiple peers.xoops.org ie. peers.labs.coop that go around spot checking the simulcasting.

Just leave the fonts one, today I bought a new intel 64bit computer and will be picking it up and putting releases.ubuntu.com on in a few days and fonts.labs.coop -- will be changing dramatically to version 2.0..

wishcraft

Module Developer
Posted on: 2015/6/9 7:43
wishcraft
wishcraft (Show more)
Module Developer
Posts: 3711
Since: 2007/5/18
#3

Re: @fixed::- xoops_getBaseDomain() =--= *.peers.xoops.org - 301 Hop to an API

Richard:-

Yeah that is right for example fonts.peers.xoops.org or time.peers.xoops.org etc; will hop with a 301 - Permanently Moved with a .htaccess and header("Location: ") with the post and get passed in the header as well to hop to randomly on of the peers to delegate the data..

Just make some means of looking around on the peers api for checksum (md5); like accessing a font and passing it on with a callback!!

geekwright

Quite a regular
Posted on: 2015/6/10 21:32
geekwright
geekwright (Show more)
Quite a regular
Posts: 277
Since: 2010/10/15
#4

Re: @fixed::- xoops_getBaseDomain() -- required for multitiered cookies!

Interesting points.

In 2.6, getBaseDomain() uses the public suffix list to parse the smallest registrable domain from a URL. There is an update script already, so keeping that up to date with a cron job is trivial. With a constant explosion of new TLDs and IDNs, this is a big issue, and https://publicsuffix.org/ is a valuable resource with industry wide acceptance. That an DNS lookups, and you've got what is needed.

Better control over the cookie domain, and the ability to serve assets from different domains are also in the works. A lot of the building blocks for more complex infrastructures are already going into place.

The idea of some generic mirror/peer list management built on that is interesting, although we want to make sure we are not just reinventing a CDN, and are actually adding value to the application portion of the stack. Writing a load balancing mechanism in PHP is probably not going to achieve the optimal result, just because of where it is in the stack when it is called, for example.

Interesting ideas, thanks.

wishcraft

Module Developer
Posted on: 2015/6/24 2:14
wishcraft
wishcraft (Show more)
Module Developer
Posts: 3711
Since: 2007/5/18
#5

Re: @fixed::- xoops_getBaseDomain() -- required for multitiered cookies!

This is the finite improved version for this function the following are required:-

data/stratas.diz
http://strata.api.hempembassy.net
https://strata.ringwould.com.au
http://strata.labs.coop


The following constant is required:
define("API_FILE_IO_STRATA"__DIR__ DIRECTORY_SEPARATOR 'data' DIRECTORY_SEPARATOR 'stratas.diz');


The following is the functions for XOOPS
if (!function_exists("getURIData")) {

    
/* function getURIData()
     *
    *     Get a supporting domain system for the API
    * @author         Simon Roberts (Chronolabs) simon@labs.coop
    *
    * @return         float()
    */
    
function getURIData($uri ''$timeout 25$connectout 25)
    {
        if (!
function_exists("curl_init"))
        {
            return 
file_get_contents($uri);
        }
        if (!
$btt curl_init($uri)) {
            return 
false;
        }
        
curl_setopt($bttCURLOPT_HEADER0);
        
curl_setopt($bttCURLOPT_POST0);
        
curl_setopt($bttCURLOPT_CONNECTTIMEOUT$connectout);
        
curl_setopt($bttCURLOPT_TIMEOUT$timeout);
        
curl_setopt($bttCURLOPT_RETURNTRANSFERtrue);
        
curl_setopt($bttCURLOPT_VERBOSEfalse);
        
curl_setopt($bttCURLOPT_SSL_VERIFYHOSTfalse);
        
curl_setopt($bttCURLOPT_SSL_VERIFYPEERfalse);
        
$data curl_exec($btt);
        
curl_close($btt);
        return 
$data;
    }
}

if (!
function_exists("getBaseDomain")) {
    
/**
     * getBaseDomain
     * 
     * @param string $url
     * @return string|unknown
     */
    
function getBaseDomain($url)
    {
        
        static 
$strata$fallout$stratas;

        
xoops_load('XoopsCache');

        if (empty(
$strata))
        {
            if (!
$strata XoopsCache::read('internets_stratas'))
            {
                if (empty(
$stratas))
                    
$stratas file(API_FILE_IO_STRATA);
                
shuffle($stratas);
                
$attempts 0;
                while(empty(
$strata) || $attempts < (count($strata) * 1.65))
                {
                    
$attempts++;
                    
$strata array_keys(unserialize(getURIData($stratas[mt_rand(0count($stratas)-1)] ."/v1/strata/serial.api"1519)));
                }
                if (!empty(
$strata))
                    
XoopsCache::write('internets_stratas'$strata3600*24*mt(3.75,11));
            }
        }
        if (empty(
$fallout))
        {
            if (!
$fallout XoopsCache::read('internets_fallouts'))
            {
                if (empty(
$stratas))
                    
$stratas file(API_FILE_IO_STRATA);
                
shuffle($stratas);
                
$attempts 0;
                while(empty(
$fallout) || $attempts < (count($strata) * 1.65))
                {
                    
$attempts++;
                    
$fallout array_keys(unserialize(getURIData($stratas[mt_rand(0count($stratas)-1)] ."/v1/fallout/serial.api"1519)));
                }
                if (!empty(
$fallout))
                    
XoopsCache::write('internets_fallouts'$fallout3600*24*mt(3.75,11));
            }
        }
        
        
// Get Full Hostname
        
$url strtolower($url);
        
$hostname parse_url($urlPHP_URL_HOST);
        if (!
filter_var($hostnameFILTER_VALIDATE_IP) === true
            return 
$hostname;
    
        
// break up domain, reverse
        
$elements explode('.'$hostname);
        
$elements array_reverse($elements);
        
        
// Returns Base Domain
        
if (in_array($elements[0], $fallout) && in_array($elements[1], $strata))
            return 
$elements[2] . '.' $elements[1] . '.' $elements[0];
        elseif (
in_array($elements[0], $fallout) || in_array($elements[0], $strata))
            return 
$elements[1] . '.' $elements[0];
        
        
// Nothing Found
        
return $hostname;
    }
}