1<?php 2/** 3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 4 * @author Andreas Gohr <andi@splitbrain.org> 5 */ 6 7class admin_plugin_ipban extends DokuWiki_Admin_Plugin 8{ 9 10 /** @inheritDoc */ 11 function forAdminOnly() 12 { 13 return false; 14 } 15 16 /** @inheritDoc */ 17 function getMenuSort() 18 { 19 return 41; 20 } 21 22 /** @inheritDoc */ 23 function handle() 24 { 25 global $conf; 26 global $INPUT; 27 28 $ip = trim($INPUT->str('ip')); 29 if ($ip) { 30 require_once(__DIR__ . '/ip-lib/ip-lib.php'); 31 $range = \IPLib\Factory::rangeFromString($ip); 32 if ($range === null) { 33 msg($this->getLang('badrange'), -1); 34 } else { 35 $newban = $ip . "\t" . time() . "\t" . $INPUT->server->str('REMOTE_USER'); 36 $cause = trim(preg_replace('/[\n\r\t]+/', '', $INPUT->str('cause'))); 37 $newban .= "\t" . $cause . "\n"; 38 io_savefile($conf['cachedir'] . '/ipbanplugin.txt', $newban, true); 39 } 40 41 } 42 43 $delip = $INPUT->extract('delip')->str('delip'); 44 if ($delip) { 45 $delip = preg_quote($delip, '/'); 46 47 io_deleteFromFile( 48 $conf['cachedir'] . '/ipbanplugin.txt', 49 '/^' . $delip . '\t/', 50 true 51 ); 52 } 53 } 54 55 /** @inheritDoc */ 56 function html() 57 { 58 global $conf; 59 60 echo $this->locale_xhtml('intro'); 61 62 echo '<form method="post" action="">'; 63 echo '<table class="inline" width="100%">'; 64 echo '<tr>'; 65 echo '<th>' . $this->getLang('ip') . '</th>'; 66 echo '<th>' . $this->getLang('date') . '</th>'; 67 echo '<th>' . $this->getLang('by') . '</th>'; 68 echo '<th>' . $this->getLang('cause') . '</th>'; 69 echo '<th>' . $this->getLang('del') . '</th>'; 70 echo '</tr>'; 71 $bans = @file($conf['cachedir'] . '/ipbanplugin.txt'); 72 if (is_array($bans)) { 73 foreach ($bans as $ban) { 74 $fields = explode("\t", $ban); 75 echo '<tr>'; 76 echo '<td>' . hsc($fields[0]) . '</td>'; 77 echo '<td>' . strftime($conf['dformat'], $fields[1]) . '</td>'; 78 echo '<td>' . hsc($fields[2]) . '</td>'; 79 echo '<td>' . hsc($fields[3]) . '</td>'; 80 echo '<td><input type="submit" name="delip[' . $fields[0] . ']" value="' . $this->getLang('del') . '" class="button" /></td>'; 81 echo '</tr>'; 82 } 83 } 84 echo '<tr>'; 85 echo '<th colspan="6">'; 86 echo '<div>' . $this->getLang('newban') . ':</div>'; 87 echo '<label for="plg__ipban_ip">' . $this->getLang('ip') . ':</label>'; 88 echo '<input type="text" name="ip" id="plg__ipban_ip" class="edit" /> '; 89 echo '<label for="plg__ipban_cause">' . $this->getLang('cause') . ':</label>'; 90 echo '<input type="text" name="cause" id="plg__ipban_cause" class="edit" /> '; 91 echo '<input type="submit" class="button" value="' . $this->getLang('ban') . '" />'; 92 echo '</th>'; 93 echo '</tr>'; 94 echo '</table>'; 95 echo '</form>'; 96 97 } 98 99} 100