forked from LiveCarta/LiveCartaWP
Changed source root directory
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Calculate the effective registered domain of a fully qualified domain name.
|
||||
*
|
||||
* <@LICENSE>
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to you under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* </@LICENSE>
|
||||
*
|
||||
* Florian Sager, 25.07.2008, sager@agitos.de, http://www.agitos.de
|
||||
*/
|
||||
|
||||
/*
|
||||
* Remove subdomains from a signing domain to get the registered domain.
|
||||
*
|
||||
* dkim-reputation.org blocks signing domains on the level of registered domains
|
||||
* to rate senders who use e.g. a.spamdomain.tld, b.spamdomain.tld, ... under
|
||||
* the most common identifier - the registered domain - finally.
|
||||
*
|
||||
* This function returns NULL if $signingDomain is TLD itself
|
||||
*
|
||||
* $signingDomain has to be provided lowercase (!)
|
||||
*/
|
||||
|
||||
class regDomain {
|
||||
/* tld tree */
|
||||
protected $tldTree = array();
|
||||
|
||||
/* main function */
|
||||
public function getRegisteredDomain($signingDomain, $fallback = TRUE) {
|
||||
$signingDomainParts = explode('.', $signingDomain);
|
||||
|
||||
$result = $this->findRegisteredDomain($signingDomainParts, $this->tldTree);
|
||||
|
||||
if ($result===NULL || $result=="") {
|
||||
// this is an invalid domain name
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// assure there is at least 1 TLD in the stripped signing domain
|
||||
if (!strpos($result, '.')) {
|
||||
if ($fallback===FALSE) {
|
||||
return NULL;
|
||||
}
|
||||
$cnt = count($signingDomainParts);
|
||||
if ($cnt==1 || $signingDomainParts[$cnt-2]=="") return NULL;
|
||||
if (!$this->validDomainPart($signingDomainParts[$cnt-2]) || !$this->validDomainPart($signingDomainParts[$cnt-1])) return NULL;
|
||||
return $signingDomainParts[$cnt-2].'.'.$signingDomainParts[$cnt-1];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/* validate parts */
|
||||
public function validDomainPart($domPart) {
|
||||
// see http://www.register.com/domain-extension-rules.rcmx
|
||||
$len = strlen($domPart);
|
||||
|
||||
// not more than 63 characters
|
||||
if ($len>63) return FALSE;
|
||||
|
||||
// not less than 1 characters --> there are TLD-specific rules that could be considered additionally
|
||||
if ($len<1) return FALSE;
|
||||
|
||||
// Use only letters, numbers, or hyphen ("-")
|
||||
// not beginning or ending with a hypen (this is TLD specific, be aware!)
|
||||
if (!preg_match("/^([a-z0-9])(([a-z0-9-])*([a-z0-9]))*$/", $domPart)) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* recursive helper method */
|
||||
public function findRegisteredDomain($remainingSigningDomainParts, &$treeNode) {
|
||||
$sub = array_pop($remainingSigningDomainParts);
|
||||
|
||||
$result = NULL;
|
||||
if (isset($treeNode['!'])) {
|
||||
return '#';
|
||||
}
|
||||
|
||||
if (!$this->validDomainPart($sub)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (is_array($treeNode) && array_key_exists($sub, $treeNode)) {
|
||||
$result = $this->findRegisteredDomain($remainingSigningDomainParts, $treeNode[$sub]);
|
||||
} else if (is_array($treeNode) && array_key_exists('*', $treeNode)) {
|
||||
$result = $this->findRegisteredDomain($remainingSigningDomainParts, $treeNode['*']);
|
||||
} else {
|
||||
return $sub;
|
||||
}
|
||||
|
||||
// this is a hack 'cause PHP interpretes '' as NULL
|
||||
if ($result == '#') {
|
||||
return $sub;
|
||||
} else if (strlen($result)>0) {
|
||||
return $result.'.'.$sub;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* load tld tree into object */
|
||||
function __construct() {
|
||||
/* include tld tree data */
|
||||
include(dirname(__FILE__) . '/effectiveTLDs.inc.php');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Calculate the effective registered domain of a fully qualified domain name.
|
||||
*
|
||||
* <@LICENSE>
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to you under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* </@LICENSE>
|
||||
*
|
||||
* Florian Sager, 25.07.2008, sager@agitos.de, http://www.agitos.de
|
||||
*/
|
||||
|
||||
/*
|
||||
* Remove subdomains from a signing domain to get the registered domain.
|
||||
*
|
||||
* dkim-reputation.org blocks signing domains on the level of registered domains
|
||||
* to rate senders who use e.g. a.spamdomain.tld, b.spamdomain.tld, ... under
|
||||
* the most common identifier - the registered domain - finally.
|
||||
*
|
||||
* This function returns NULL if $signingDomain is TLD itself
|
||||
*
|
||||
* $signingDomain has to be provided lowercase (!)
|
||||
*/
|
||||
|
||||
/* pull in class */
|
||||
require_once (dirname ( __FILE__ ) . '/regDomain.class.php');
|
||||
|
||||
/* create global object */
|
||||
;
|
||||
function getRegisteredDomain($signingDomain, $fallback = TRUE) {
|
||||
/* pull in object */
|
||||
$regDomainObj = new regDomain ();
|
||||
/* return object method */
|
||||
return $regDomainObj->getRegisteredDomain ( $signingDomain, $fallback );
|
||||
}
|
||||
function validDomainPart($domPart) {
|
||||
/* pull in object */
|
||||
$regDomainObj = new regDomain ();
|
||||
/* return object method */
|
||||
return $regDomainObj->validDomainPart ( $domPart );
|
||||
}
|
||||
|
||||
// recursive helper method
|
||||
function findRegisteredDomain($remainingSigningDomainParts, &$treeNode) {
|
||||
/* pull in object */
|
||||
$regDomainObj = new regDomain ();
|
||||
/* return object method */
|
||||
return $regDomainObj->findRegisteredDomain ( $remainingSigningDomainParts, $treeNode );
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Calculate the effective registered domain of a fully qualified domain name.
|
||||
*
|
||||
* <@LICENSE>
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to you under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* </@LICENSE>
|
||||
*
|
||||
* Florian Sager, 25.07.2008, sager@agitos.de, http://www.agitos.de
|
||||
*/
|
||||
|
||||
require_once("effectiveTLDs.inc.php");
|
||||
require_once("regDomain.inc.php");
|
||||
|
||||
if ($_SERVER["argc"]<2) {
|
||||
print("test-regDomain.php <(fully-qualified-domain-name )+>\n");
|
||||
exit;
|
||||
}
|
||||
|
||||
// strip subdomains from every signing domain
|
||||
// char dom[] = "sub2.sub.registered.nom.ad";
|
||||
|
||||
$argc = $_SERVER["argc"];
|
||||
$argv = $_SERVER["argv"];
|
||||
|
||||
for ($i=1; $i<$argc; $i++) {
|
||||
|
||||
$registeredDomain = getRegisteredDomain($argv[$i], $tldTree);
|
||||
|
||||
if ( $registeredDomain === NULL ) {
|
||||
printf("error: %s\n", $argv[$i]);
|
||||
} else {
|
||||
printf("%s\n", $registeredDomain);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,56 @@
|
||||
===============================================
|
||||
Detection of registered domains by reg-dom libs
|
||||
===============================================
|
||||
|
||||
The reg-dom libs are available in C, Perl and PHP so far.
|
||||
|
||||
They include recent representations of the effective TLD list available at
|
||||
http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1
|
||||
and help to convert an arbitrary domain name to the registered domain name.
|
||||
|
||||
Sample use:
|
||||
dkim-reputation.org blocks signing domains on the level of registered domains
|
||||
to rate senders who use e.g. a.spamdomain.tld, b.spamdomain.tld, ... under
|
||||
the most common identifier - the registered domain - finally.
|
||||
Project page: http://www.dkim-reputation.org/regdom-libs/
|
||||
|
||||
Pseudo code:
|
||||
registeredDomain = getRegisteredDomain(ingoingDomain);
|
||||
|
||||
Return values:
|
||||
1) NULL if ingoingDomain is a TLD
|
||||
2) the registered domain name if TLD is known
|
||||
3) just <domain>.<tld> if <tld> is unknown
|
||||
This case was added to support new TLDs in outdated reg-dom libs
|
||||
by a certain likelihood. This fallback method is implemented in the
|
||||
last conversion step and can be simply commented out.
|
||||
|
||||
---
|
||||
|
||||
If you like to regenerate the effective TLD tree structure by yourself
|
||||
you can use the script generateEffectiveTLDs.php with the following parameters:
|
||||
|
||||
php generateEffectiveTLDs.php php > PHP/effectiveTLDs.inc.php
|
||||
php generateEffectiveTLDs.php perl > Perl/effectiveTLDs.pm
|
||||
php generateEffectiveTLDs.php c > C/tld-canon.h
|
||||
|
||||
|
||||
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to you under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at:
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# </@LICENSE>
|
||||
|
||||
|
||||
Florian Sager, 2009-02-05, sager@agitos.de, http://www.agitos.de
|
||||
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Florian Sager, 06.08.2008, sager@agitos.de, http://www.agitos.de
|
||||
*
|
||||
* Auto-Generate PHP array tree that contains all TLDs from the URL (see below);
|
||||
* The output has to be copied to reputation-libs/effectiveTLDs.inc.php
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
|
||||
DEFINE('URL', 'http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1');
|
||||
|
||||
$format = "php";
|
||||
if ($_SERVER['argc']>1) {
|
||||
if ($_SERVER['argv'][1] == "perl") {
|
||||
$format = "perl";
|
||||
} else if ($_SERVER['argv'][1] == "c") {
|
||||
$format = "c";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Does $search start with $startstring?
|
||||
*/
|
||||
function startsWith($search, $startstring) {
|
||||
return (substr($search, 0, strlen($startstring))==$startstring);
|
||||
}
|
||||
|
||||
/*
|
||||
* Does $search end with $endstring?
|
||||
*/
|
||||
function endsWith($search, $endstring) {
|
||||
return (substr($search, -strlen($endstring))==$endstring);
|
||||
}
|
||||
|
||||
|
||||
function buildSubdomain(&$node, $tldParts) {
|
||||
|
||||
$dom = trim(array_pop($tldParts));
|
||||
|
||||
$isNotDomain = FALSE;
|
||||
if (startsWith($dom, "!")) {
|
||||
$dom = substr($dom, 1);
|
||||
$isNotDomain = TRUE;
|
||||
}
|
||||
|
||||
if (!array_key_exists($dom, $node)) {
|
||||
if ($isNotDomain) {
|
||||
$node[$dom] = array("!" => "");
|
||||
} else {
|
||||
$node[$dom] = array();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$isNotDomain && count($tldParts)>0) {
|
||||
buildSubdomain($node[$dom], $tldParts);
|
||||
}
|
||||
}
|
||||
|
||||
function printNode($key, $valueTree, $isAssignment = false) {
|
||||
|
||||
global $format;
|
||||
|
||||
if ($isAssignment) {
|
||||
if ($format == "perl") {
|
||||
echo "$key = {";
|
||||
} else {
|
||||
echo "$key = array(";
|
||||
}
|
||||
} else {
|
||||
if (strcmp($key, "!")==0) {
|
||||
if ($format == "perl") {
|
||||
echo "'!' => {}";
|
||||
} else {
|
||||
echo "'!' => ''";
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if ($format == "perl") {
|
||||
echo "'$key' => {";
|
||||
} else {
|
||||
echo "'$key' => array(";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$keys = array_keys($valueTree);
|
||||
|
||||
for ($i=0; $i<count($keys); $i++) {
|
||||
|
||||
$key = $keys[$i];
|
||||
|
||||
printNode($key, $valueTree[$key]);
|
||||
|
||||
if ($i+1 != count($valueTree)) {
|
||||
echo ",\n";
|
||||
} else {
|
||||
"\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($format == "perl") {
|
||||
echo '}';
|
||||
} else {
|
||||
echo ')';
|
||||
}
|
||||
}
|
||||
|
||||
// sample: root(3:ac(5:com,edu,gov,net,ad(3:nom,co!,*)),de,com)
|
||||
|
||||
function printNode_C($key, $valueTree) {
|
||||
|
||||
echo "$key";
|
||||
|
||||
$keys = array_keys($valueTree);
|
||||
|
||||
if (count($keys)>0) {
|
||||
|
||||
if (strcmp($keys['!'], "!")==0) {
|
||||
echo "!";
|
||||
} else {
|
||||
|
||||
echo "(".count($keys).":";
|
||||
|
||||
for ($i=0; $i<count($keys); $i++) {
|
||||
|
||||
$key = $keys[$i];
|
||||
|
||||
// if (count($valueTree[$key])>0) {
|
||||
printNode_C($key, $valueTree[$key]);
|
||||
// }
|
||||
|
||||
if ($i+1 != count($valueTree)) {
|
||||
echo ",";
|
||||
}
|
||||
}
|
||||
|
||||
echo ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- main ---
|
||||
|
||||
error_reporting(E_ERROR);
|
||||
|
||||
$tldTree = array();
|
||||
$list = file_get_contents(URL);
|
||||
// $list = "bg\na.bg\n0.bg\n!c.bg\n";
|
||||
$lines = explode("\n", $list);
|
||||
$licence = TRUE;
|
||||
|
||||
if ($format == "php") echo "<?php\n";
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if ($line == "") {
|
||||
if ($licence) {
|
||||
$licence = FALSE;
|
||||
echo "\n";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (startsWith($line, "//")) {
|
||||
if ($licence) {
|
||||
if ($format == "perl") {
|
||||
echo "# ".substr($line, 2)."\n";
|
||||
} else {
|
||||
echo $line."\n";
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// this must be a TLD
|
||||
$tldParts = preg_split('\.', $line);
|
||||
buildSubdomain($tldTree, $tldParts);
|
||||
}
|
||||
|
||||
// print_r($tldTree);
|
||||
|
||||
/*
|
||||
$tldTree = array(
|
||||
'de' => array(), // test.agitos.de --> agitos.de
|
||||
'uk' => array(
|
||||
'co' => array(), // test.agitos.co.uk --> agitos.co.uk
|
||||
'xy' => array('!'), // test.agitos.xy.uk --> xy.uk
|
||||
'*' => array() // test.agitos.ab.uk --> agitos.ab.uk
|
||||
)
|
||||
);
|
||||
*/
|
||||
|
||||
if ($format == "c") {
|
||||
|
||||
echo "static const char tldString[] = \"";
|
||||
printNode_C("root", $tldTree);
|
||||
echo "\";\n\n";
|
||||
|
||||
} else {
|
||||
|
||||
if ($format == "perl") {
|
||||
print "package effectiveTLDs;\n\n";
|
||||
}
|
||||
printNode("\$tldTree", $tldTree, TRUE);
|
||||
echo ";\n";
|
||||
if ($format == "php") echo '?>' . "\n";
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user