Fixed Broken Shit
This commit is contained in:
45
user/plugins/yourls-pseudonymize-master/README.textile
Normal file
45
user/plugins/yourls-pseudonymize-master/README.textile
Normal file
@ -0,0 +1,45 @@
|
||||
h1. YOURLS Pseudonymize Plugin
|
||||
|
||||
This plugin "pseudonymizes" the IP addresses so that it is in line with the German privacy laws.
|
||||
|
||||
This effectively means, that the last segment of an IP address is changed into a 0 ("zero"), thus removed.
|
||||
|
||||
*IPv4 and IPv6 addresses are supported.*
|
||||
|
||||
*NOTE*: Requires PHP >= 5.2.0 due to "filter_var":http://php.net/manual/en/function.filter-var.php usage.
|
||||
|
||||
h2. Download
|
||||
|
||||
Latest version: <a href="https://raw.github.com/ubicoo/yourls-pseudonymize/master/plugin.php">plugin.php</a>
|
||||
|
||||
h2. Install
|
||||
|
||||
Copy plugin.php to *YOURLS_HOME*/user/plugins/yourls-pseudonymize folder and activate via the admin menu.
|
||||
|
||||
h2. Support
|
||||
|
||||
<a href="http://blog.yourls.org/forums/topic/yourls-pseudonymize-plugin/">Discuss about this plugin</a> in the YOURLS forum.
|
||||
|
||||
<a href="https://github.com/ubicoo/yourls-pseudonymize/issues/new">File an issue</a> right here on the GitHub project home.
|
||||
|
||||
h2. MIT License
|
||||
|
||||
Copyright (c) 2010 Ubicoo - http://www.ubicoo.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
34
user/plugins/yourls-pseudonymize-master/plugin.php
Normal file
34
user/plugins/yourls-pseudonymize-master/plugin.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Pseudonymize Plugin
|
||||
Plugin URI: http://github.com/ubicoo/yourls-pseudonymize
|
||||
Description: Pseudonymize IP addresses (remove last segment). Supports IPv4 and IPv6.
|
||||
Version: 1.1
|
||||
Author: Ubicoo
|
||||
Author URI: http://www.ubicoo.com
|
||||
*/
|
||||
|
||||
|
||||
yourls_add_filter( 'get_IP', 'ubicoo_pseudonymize_IP' );
|
||||
|
||||
function ubicoo_pseudonymize_IP( $ip ) {
|
||||
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
$segments = explode(":", $ip);
|
||||
$segments[count($segments)-1] = 0;
|
||||
|
||||
$pseudo_IP = implode(":", $segments);
|
||||
|
||||
# FIXME: also handle IPv4 addresses at the end of IPv6, like ::ffff:127.0.0.1
|
||||
|
||||
} elseif(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
||||
$segments = explode(".", $ip);
|
||||
$segments[3] = 0;
|
||||
|
||||
$pseudo_IP = implode(".", $segments);
|
||||
} else {
|
||||
$pseudo_IP = $ip;
|
||||
}
|
||||
|
||||
return $pseudo_IP;
|
||||
}
|
||||
|
36
user/plugins/yourls-pseudonymize-master/tests.php
Normal file
36
user/plugins/yourls-pseudonymize-master/tests.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
require_once 'plugin.php';
|
||||
|
||||
function yourls_add_filter($a, $b) { }
|
||||
|
||||
$fixture = array();
|
||||
$fixture[] = array('127.0.0.1' => '127.0.0.0');
|
||||
$fixture[] = array('192.0.43.10' => '192.0.43.0'); // example.com
|
||||
$fixture[] = array('::1' => '::0');
|
||||
$fixture[] = array('::ffff:127.0.0.1' => '::ffff:127.0.0.0');
|
||||
$fixture[] = array('::ffff:192.0.43.10' => '::ffff:192.0.43.0');
|
||||
$fixture[] = array('2001:0db8:85a3:0000:0000:8a2e:0370:7334' => '2001:0db8:85a3:0000:0000:8a2e:0370:0');
|
||||
|
||||
|
||||
$success = TRUE;
|
||||
echo "Running tests...\n";
|
||||
|
||||
for ($i = 0; $i <= count($fixture)-1; $i++) {
|
||||
foreach ($fixture[$i] as $actual => $expected) {
|
||||
$success &= assertEquals($expected, ubicoo_pseudonymize_IP( $actual ), $actual);
|
||||
}
|
||||
}
|
||||
|
||||
echo "Tests " . ($success ? "succeeded" : "failed") .".\n";
|
||||
|
||||
|
||||
function assertEquals($expected, $actualAfter, $actualBefore)
|
||||
{
|
||||
echo " Checking $actualBefore => $expected ? ... ";
|
||||
if ($actualAfter !== $expected) {
|
||||
echo "FAILED - was $actualAfter\n";
|
||||
return FALSE;
|
||||
}
|
||||
echo "OK\n";
|
||||
return TRUE;
|
||||
}
|
Reference in New Issue
Block a user