getConf('tba_lockfile'); $banned_f = $conf['cachedir'] . '/' . $this->getConf('tba_block_file'); /* Lock the file for writing */ $lockfh = fopen($lockf, 'w', false); if($lockfh === false) return; if(flock($lockfh, LOCK_EX) === false) { fclose($lockfh); return; } /* Open the file to search for the $ip to delete */ $content = file_get_contents($banned_f); if(empty($content)) { flock($lockfh, LOCK_UN); fclose($lockfh); msg(sprintf($this->getLang('del_ipnotfound'), $ip), -1); return; } else $blocked = @unserialize($content); /* Deal with the case of unserialize() failing */ if($blocked === false || !is_array($blocked)) { flock($lockfh, LOCK_UN); fclose($lockfh); return; } if(isset($blocked[$ip])) { /* Remove the banned IP */ unset($blocked[$ip]); /* Save the blocked-IP file */ io_saveFile($banned_f, serialize($blocked)); /* Remove any occurrence of this IP address in the tracker file */ $track_f = $conf['cachedir'] . '/' . $this->getConf('tba_iptime_file'); $content = file_get_contents($track_f); $user_tracker = null; if(empty($content)) $users_tracker = array(); else $users_tracker = @unserialize($content); if($users_tracker === false) $users_tracker = array(); if(isset($users_tracker[$ip])) unset($users_tracker[$ip]); io_saveFile($track_f, serialize($users_tracker)); msg(sprintf($this->getLang('del_success'), $ip), 1); } else msg(sprintf($this->getLang('del_ipnotfound'), $ip), -1); flock($lockfh, LOCK_UN); fclose($lockfh); } /** * output appropriate html */ function html() { global $conf; $banned_f = $conf['cachedir'] . '/' . $this->getConf('tba_block_file'); $bans = @file_get_contents($banned_f); if(empty($bans)) $bans = array(); else $bans = @unserialize($bans); /* Deal with the case of unserialize() failing */ if($bans === false) $bans = array(); /* Get the current time once and for all */ $curr_time = time(); $ban_time = $this->getConf('tba_block_time'); /* Remove IP which have their ban expired */ $new_bans = array(); foreach($bans as $ip => $block_timestamp) { if($block_timestamp + $ban_time < $curr_time) continue; $new_bans[$ip] = $block_timestamp; } $bans = $new_bans; /* Now fill the admin panel */ echo $this->locale_xhtml('admin_intro'); echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if(!empty($bans) && is_array($bans)) { foreach($bans as $ip => $block_timestamp) { $host = @gethostbyaddr($ip); if($host === false || $host === $ip) $host = '?'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } } else { echo ''; echo ''; echo ''; } echo '
'.$this->getLang('ip').''.$this->getLang('host').''.$this->getLang('date').''.$this->getLang('del').'
'.$ip.''.hsc($host).''.strftime($conf['dformat'], $block_timestamp).'
' . hsc($this->getLang('noban')) . '
'; echo ''; echo '
'; } }