protected function getInput() { $this->app = JFactory::getApplication(); $this->db = JFactory::getDbo(); $this->formfields = $this->form->getFieldset(); $blacklistnets = array(); $blacklistaddresses = array(); $blacklistinputarray=AdminExileHelper::ipArray($this->_getField('blacklist')); $gmp = AdminExileHelper::gmp(); require_once(JPATH_PLUGINS.'/system/adminexile/classes/'.($gmp?'IPv6Net.class.php':'simplecidr.class.php')); foreach($blacklistinputarray as $blacklistitem) { $blacklistitem = trim($blacklistitem); if(preg_match('/\//',$blacklistitem)) { try{ $blacklistnets[$blacklistitem]=$gmp?(new IPv6Net($blacklistitem)):SimpleCIDR::getInstance($blacklistitem); } catch (Exception $e) { error_log("AdminExile cannot process ".$blacklistitem." due to:".$e->getMessage()); $blacklistaddresses[trim($blacklistitem)]=$blacklistitem; } } else { $blacklistaddresses[trim($blacklistitem)]=$blacklistitem; } } $query = $this->db->getQuery(true); $query->select('*')->from('#__plg_system_adminexile')->where('penalty = 0')->order('lastattempt DESC'); $this->db->setQuery($query); $blocked = $this->db->loadObjectList(); $return=array(); $return[]='<h3 style="float:left;clear:left;">'.($gmp?JText::_('PLG_SYS_ADMINEXILE_IPV46'):JText::_('PLG_SYS_ADMINEXILE_IPV4')).'</h3>'; $attempts = new stdClass(); foreach($blocked as $match) { if(in_array($match->ip,$blacklistaddresses)) { $attempts->{$match->ip} = new stdClass(); $attempts->{$match->ip}->lastattempt = $match->lastattempt; $attempts->{$match->ip}->firstattempt = $match->firstattempt; $attempts->{$match->ip}->attempts = $match->attempts; } else { foreach(array_keys($blacklistnets) as $key) { if($blacklistnets[$key]->contains(trim((string)$match->ip))) { if(!property_exists($attempts,$key)) { $attempts->$key = new stdClass(); $attempts->$key->attempts = 0; $attempts->$key->addresses = new stdClass(); } $attempts->$key->addresses->{$match->ip}->lastattempt = $match->lastattempt; $attempts->$key->addresses->{$match->ip}->firstattempt = $match->firstattempt; $attempts->$key->addresses->{$match->ip}->attempts = $match->attempts; $attempts->$key->attempts += $match->attempts; } } } } JFactory::getDocument()->addScriptDeclaration('window.plg_sys_adminexile_blacklist = '.json_encode($attempts).';'); return implode("\n",$return); }
protected function getInput() { $options = array(); $joomla = array('JACTION_DELETE'); $messages = array('INVALIDASCII','INVALIDCHAR','NOTNUMERIC'); $chars = array('DOLLAR','AMPERSAND','PLUS','COMMA','FORWARDSLASH','COLON','SEMICOLON','EQUALS','QUESTION','AT','SPACE','QUOTE','LESSTHAN','GREATERTHAN','POUND','PERCENT','LEFTCURLY','RIGHTCURLY','PIPE','BACKSLASH','CARAT','TILDE','LEFTBRACKET','RIGHTBRACKET','GRAVE'); $buttons = array('EDIT_IP','DELETE_IP','CLEAR_IP'); $popups = array('NEW_IPV4','NEW_IPV46','DUPLICATE_ADDRESS','INVALID_ADDRESS'); $table = array('IP','ACTIONS','ATTEMPTS','LASTATTEMPT','OPTIONS'); foreach($messages as $string) JText::script('PLG_SYS_ADMINEXILE_MESSAGE_'.$string); foreach($chars as $string) JText::script('PLG_SYS_ADMINEXILE_CHAR_'.$string); foreach($buttons as $string) JText::script('PLG_SYS_ADMINEXILE_BUTTON_'.$string); foreach($popups as $string) JText::script('PLG_SYS_ADMINEXILE_POPUP_'.$string); foreach($table as $string) JText::script('PLG_SYS_ADMINEXILE_TH_'.$string); foreach($joomla as $string) JText::script($string); $options['version']=JVERSION; $options['gmp']=AdminExileHelper::gmp(); JHtml::_('behavior.framework',true); $doc = JFactory::getDocument(); $doc->addScriptDeclaration("\n".'window.plg_sys_adminexile_config = '.json_encode($options).';'."\n"); $doc->addScript(JURI::root(true).'/media/plg_system_adminexile/admin.js'); return; }
private function _blackwhite($ip) { $whitelistnet = array(); $blacklistnet = array(); $whitelist = array(); $blacklist = array(); foreach (array('whitelist', 'blacklist') as $list) { $listnet = $list . 'net'; $listdefault = JText::_('PLG_SYS_ADMINEXILE_DEFAULT_'.strtoupper($list)); $listvalue = $this->params->get($list, $listdefault); ${$list} = AdminExileHelper::ipArray($listvalue); foreach (${$list} as $key => $item) { $item = trim($item); if (preg_match('/\//', $item)) { unset(${$list}[$key]); array_push(${$listnet}, $item); } else { ${$list}[$key] = $item; } } } if (in_array($ip, $whitelist)) return true; if (in_array($ip, $blacklist)) return $ip; if (count(array_merge($whitelistnet, $blacklistnet))) { $requires = array('IPv6Net'=>'IPv6Net','simplecidr'=>'SimpleCIDR'); $require = $this->_gmp ? 'IPv6Net' : 'simplecidr'; if(!class_exists($requires[$require])) require_once(JPATH_PLUGINS.'/system/adminexile/classes/'.$require.'.class.php'); foreach ($whitelistnet as $net) { $ipnet = $this->_bwnet($net); if ($ipnet && $ipnet->contains($ip)) return true; } foreach ($blacklistnet as $net) { $ipnet = $this->_bwnet($net); if ($ipnet && $ipnet->contains($ip)) return $net; } } return false; }