*/ if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'admin.php'); class admin_plugin_iptrust extends DokuWiki_Admin_Plugin { /** * Return some info */ function getInfo() { return array( 'author' => 'Andriy Lesyuk', 'email' => 'andriy.lesyuk@softjourn.com', 'date' => '2009-04-09', 'name' => 'IPTrust Admin Plugin', 'desc' => 'Lets admin to specify which IPs to trust.' ); } /** * This functionality should be available only ot administrator */ function forAdminOnly() { return false; } /** * Handles user request */ function handle() { if (isset($_REQUEST['ip']) && ($_REQUEST['ip'] != '')) { if (preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $_REQUEST['ip']) && (ip2long($_REQUEST['ip']) !== false)) { $ip = long2ip(ip2long($_REQUEST['ip'])); $ips = @file(DOKU_CONF.'iptrust.conf', FILE_SKIP_EMPTY_LINES); if ($ips && (sizeof($ips) > 0)) { if (in_array($ip."\n", $ips)) { msg($this->getLang('already'), -1); return; } } io_saveFile(DOKU_CONF.'iptrust.conf', $ip."\n", true); } else { msg($this->getLang('invalid_ip'), -1); } } elseif (isset($_REQUEST['delete']) && is_array($_REQUEST['delete']) && (sizeof($_REQUEST['delete']) > 0)) { $ips = @file(DOKU_CONF.'iptrust.conf', FILE_SKIP_EMPTY_LINES); if ($ips && (sizeof($ips) > 0)) { $count = sizeof($ips); foreach ($_REQUEST['delete'] as $ip => $dummy) { if (preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip) && (ip2long($ip) !== false)) { $ip = long2ip(ip2long($ip)); $i = array_search($ip."\n", $ips); if ($i !== false) { array_splice($ips, $i, 1); } } else { msg($this->getLang('invalid_ip'), -1); break; } } if (sizeof($ips) < $count) { io_saveFile(DOKU_CONF.'iptrust.conf', join('', $ips)); } } else { msg($this->getLang('failed'), -1); } } elseif (isset($_REQUEST['add']) && is_array($_REQUEST['add']) && (sizeof($_REQUEST['add']) > 0)) { $ips = @file(DOKU_CONF.'iptrust.conf', FILE_SKIP_EMPTY_LINES); foreach ($_REQUEST['add'] as $ip => $dummy) { if (preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip) && (ip2long($ip) !== false)) { $ip = long2ip(ip2long($ip)); if ($ips && (sizeof($ips) > 0)) { if (in_array($ip."\n", $ips)) { msg($this->getLang('already'), -1); return; } } io_saveFile(DOKU_CONF.'iptrust.conf', $ip."\n", true); } } } elseif (isset($_REQUEST['clear'])) { if (file_exists($conf['cachedir'].'/iptrust')) { @unlink($conf['cachedir'].'/iptrust'); } } } /** * Shows edit form */ function html() { global $conf; print $this->locale_xhtml('intro'); print $this->locale_xhtml('list'); ptln("