Bug fixes

This commit is contained in:
dignajar 2015-08-12 17:15:17 -03:00
parent a82243939f
commit 1f0e439b3d
5 changed files with 42 additions and 8 deletions

View File

@ -24,7 +24,7 @@
} }
echo '<tr>'; echo '<tr>';
echo '<td>'.($Page->parentKey()?NO_PARENT_CHAR:'').'<a href="'.HTML_PATH_ADMIN_ROOT.'edit-page/'.$Page->key().'">'.($Page->published()?'':'['.$Language->g('Draft').'] ').($Page->title()?$Page->title():'['.$Language->g('Empty title').'] ').'</a></td>'; echo '<td>'.($Page->parentKey()?NO_PARENT_CHAR:'').'<a href="'.HTML_PATH_ADMIN_ROOT.'edit-page/'.$Page->key().'">'.($Page->published()?'':'<span class="label label-outline label-red smaller">'.$Language->g('Draft').'</span> ').($Page->title()?$Page->title():'<span class="label label-outline label-blue smaller">'.$Language->g('Empty title').'</span> ').'</a></td>';
echo '<td>'.$parentTitle.'</td>'; echo '<td>'.$parentTitle.'</td>';
echo '</tr>'; echo '</tr>';
} }

View File

@ -16,7 +16,7 @@
foreach($posts as $Post) foreach($posts as $Post)
{ {
echo '<tr>'; echo '<tr>';
echo '<td><a href="'.HTML_PATH_ADMIN_ROOT.'edit-post/'.$Post->key().'">'.($Post->published()?'':'<span class="label label-outline label-red smaller">'.$Language->g('Draft').'</span> ').($Post->title()?$Post->title():'['.$Language->g('Empty title').'] ').'</a></td>'; echo '<td><a href="'.HTML_PATH_ADMIN_ROOT.'edit-post/'.$Post->key().'">'.($Post->published()?'':'<span class="label label-outline label-red smaller">'.$Language->g('Draft').'</span> ').($Post->title()?$Post->title():'<span class="label label-outline label-blue smaller">'.$Language->g('Empty title').'</span> ').'</a></td>';
echo '<td>'.$Post->dateCreated().'</td>'; echo '<td>'.$Post->dateCreated().'</td>';
echo '<td>'.$Post->timeago().'</td>'; echo '<td>'.$Post->timeago().'</td>';
echo '</tr>'; echo '</tr>';

View File

@ -3,12 +3,12 @@
<?php <?php
foreach($themes as $theme) foreach($themes as $theme)
{ {
$installed = ''; $installedCSS = '';
if($theme['dirname']==$Site->theme()) { if($theme['dirname']==$Site->theme()) {
$installed = 'themeBoxInstalled'; $installedCSS = 'themeBoxInstalled';
} }
echo '<div class="themeBox '.$installed.'">'; echo '<div class="themeBox '.$installedCSS.'">';
echo '<p class="name">'.$theme['name'].'</p>'; echo '<p class="name">'.$theme['name'].'</p>';
echo '<p>'.$theme['description'].'</p>'; echo '<p>'.$theme['description'].'</p>';

View File

@ -22,7 +22,7 @@
echo '<td><a href="'.HTML_PATH_ADMIN_ROOT.'edit-user/'.$username.'">'.$username.'</a></td>'; echo '<td><a href="'.HTML_PATH_ADMIN_ROOT.'edit-user/'.$username.'">'.$username.'</a></td>';
echo '<td>'.$field['firstName'].'</td>'; echo '<td>'.$field['firstName'].'</td>';
echo '<td>'.$field['lastName'].'</td>'; echo '<td>'.$field['lastName'].'</td>';
echo '<td>'.$field['role'].'</td>'; echo '<td>a'.$field['role'].'</td>';
echo '<td>'.$field['email'].'</td>'; echo '<td>'.$field['email'].'</td>';
echo '<td>'.Date::format($field['registered'], '%d %B').'</td>'; echo '<td>'.Date::format($field['registered'], '%d %B').'</td>';
echo '</tr>'; echo '</tr>';

View File

@ -4,7 +4,8 @@ class Security extends dbJSON
{ {
private $dbFields = array( private $dbFields = array(
'minutesBlocked'=>5, 'minutesBlocked'=>5,
'numberFailures'=>10 'numberFailuresAllowed'=>10,
'blackList'=>array('numberFailures', 'lastFailure')
); );
function __construct() function __construct()
@ -12,14 +13,47 @@ class Security extends dbJSON
parent::__construct(PATH_DATABASES.'security.php'); parent::__construct(PATH_DATABASES.'security.php');
} }
public function isBlocked()
{
$ip = $this->getUserIp();
if(!isset($this->db['blackList'][$ip])) {
return false;
}
$currentTime = time();
$userBlack = $this->db['blackList'][$ip];
$numberFailures = $userBlack['numberFailures'];
$lastFailure = $userBlack['lastFailure'];
// Check if the IP is expired, then is not blocked.
if($currentTime > $lastFailure + $this->db['minutesBlocked']) {
return false;
}
// The IP has more failures than number of failures, then the IP is blocked.
if($numberFailures >= $this->db['numberFailuresAllowed']) {
return true;
}
// Otherwise the IP is not blocked.
return false;
}
public function addLoginFail() public function addLoginFail()
{ {
$ip = $this->getUserIp(); $ip = $this->getUserIp();
$currentTime = time();
$numberFailures = 1;
if(isset($this->db['blackList'][$ip])) {
$numberFailures = $userBlack['numberFailures'];
$numberFailures = $numberFailures + 1;
}
$this->db['blackList'][$ip] = array('lastFailure'=>$currentTime, 'numberFailures'=>$numberFailures);
// Save the database // Save the database
$this->db[$ip] = (int)$this->db[$ip] + 1;
if( $this->save() === false ) { if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.'); Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false; return false;