Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/RELENG_2_4_4' into factory-RELEN…
Browse files Browse the repository at this point in the history
…G_2_4_4
  • Loading branch information
jim-p committed Oct 31, 2018
2 parents 9e968e0 + 1f7ea9c commit 531aaac
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/etc/inc/system.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1156,10 +1156,34 @@ EOD;
$sighup = false;
}

$sshguard_whitelist = array();
if (!empty($config['system']['sshguard_whitelist'])) {
$sshguard_whitelist = explode(' ',
$config['system']['sshguard_whitelist']);
}

$sshguard_config = array();
$sshguard_config[] = 'BACKEND="/usr/local/libexec/sshg-fw-pf"' . "\n";
/* XXX Add a GUI option to user to define it? */
$sshguard_config[] = 'DETECTION_TIME=3600' . "\n";
if (!empty($config['system']['sshguard_threshold'])) {
$sshguard_config[] = 'THRESHOLD=' .
$config['system']['sshguard_threshold'] . "\n";
}
if (!empty($config['system']['sshguard_blocktime'])) {
$sshguard_config[] = 'BLOCK_TIME=' .
$config['system']['sshguard_blocktime'] . "\n";
}
if (!empty($config['system']['sshguard_detection_time'])) {
$sshguard_config[] = 'DETECTION_TIME=' .
$config['system']['sshguard_detection_time'] . "\n";
}
if (!empty($sshguard_whitelist)) {
@file_put_contents("/usr/local/etc/sshguard.whitelist",
implode(PHP_EOL, $sshguard_whitelist));
$sshguard_config[] =
'WHITELIST_FILE=/usr/local/etc/sshguard.whitelist' . "\n";
} else {
unlink_if_exists("/usr/local/etc/sshguard.whitelist");
}
file_put_contents("/usr/local/etc/sshguard.conf", $sshguard_config);

if (!$sighup) {
Expand Down
4 changes: 4 additions & 0 deletions src/etc/inc/upgrade_config.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5492,9 +5492,13 @@ function upgrade_173_to_174() {
*/
function upgrade_174_to_175() {
global $config;
init_config_arr(array('ipsec', 'phase1'));
if (is_array($config['ipsec']['phase1'])) {
$a_phase1 = &$config['ipsec']['phase1'];
foreach($a_phase1 as &$phase1) {
if (empty($phase1)) {
continue;
}
$item = array();
$item['encryption-algorithm'] = $phase1['encryption-algorithm'];
$item['hash-algorithm'] = $phase1['hash-algorithm'];
Expand Down
114 changes: 114 additions & 0 deletions src/usr/local/www/system_advanced_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
$pconfig['sshdkeyonly'] = $config['system']['ssh']['sshdkeyonly'];
$pconfig['sshdagentforwarding'] = isset($config['system']['ssh']['sshdagentforwarding']);
$pconfig['quietlogin'] = isset($config['system']['webgui']['quietlogin']);
$pconfig['sshguard_threshold'] = $config['system']['sshguard_threshold'] ?? '';
$pconfig['sshguard_blocktime'] = $config['system']['sshguard_blocktime'] ?? '';
$pconfig['sshguard_detection_time'] = $config['system']['sshguard_detection_time'] ?? '';
$pconfig['sshguard_whitelist'] = $config['system']['sshguard_whitelist'] ?? '';

$a_cert =& $config['cert'];
$certs_available = false;
Expand Down Expand Up @@ -108,6 +112,26 @@
}
}

$whitelist_addresses = array();
for ($i = 0; isset($_POST['address' . $i]); $i++) {
/* Ignore blank fields */
if (empty($_POST['address' . $i])) {
continue;
}

$whitelist_address = $_POST['address' . $i] . '/' .
$_POST['address_subnet'. $i];

if (!is_subnet($whitelist_address)) {
$input_errors[] = sprintf(gettext(
"Invalid subnet '%s' added to Login Protection Whitelist"),
$whitelist_address);
break;
}
$whitelist_addresses[] = $whitelist_address;
}
$pconfig['sshguard_whitelist'] = implode(' ', $whitelist_addresses);

ob_flush();
flush();

Expand Down Expand Up @@ -299,11 +323,36 @@
}
}

$restart_sshguard = false;
if (update_if_changed("login protection threshold",
$config['system']['sshguard_threshold'],
$pconfig['sshguard_threshold'])) {
$restart_sshguard = true;
}
if (update_if_changed("login protection blocktime",
$config['system']['sshguard_blocktime'],
$pconfig['sshguard_blocktime'])) {
$restart_sshguard = true;
}
if (update_if_changed("login protection detection_time",
$config['system']['sshguard_detection_time'],
$pconfig['sshguard_detection_time'])) {
$restart_sshguard = true;
}
if (update_if_changed("login protection whitelist",
$config['system']['sshguard_whitelist'],
$pconfig['sshguard_whitelist'])) {
$restart_sshguard = true;
}

write_config();

$changes_applied = true;
$retval = 0;
$retval |= filter_configure();
if ($restart_sshguard) {
$retval |= system_syslogd_start(true);
}

if ($restart_webgui) {
$extra_save_msg = sprintf("<br />" . gettext("One moment...redirecting to %s in 20 seconds."), $url);
Expand Down Expand Up @@ -542,6 +591,71 @@
['min' => 1, 'max' => 65535, 'placeholder' => 22]
))->setHelp('Note: Leave this blank for the default of 22.');

$form->add($section);
$section = new Form_Section('Login Protection');

$section->addinput(new form_input(
'sshguard_threshold',
'Threshold',
'number',
$pconfig['sshguard_threshold'],
['min' => 10, 'step' => 10, 'placeholder' => 30]
))->setHelp('Block attackers when their cumulative attack score exceeds '.
'threshold. Most attacks have a score of 10.');

$section->addinput(new form_input(
'sshguard_blocktime',
'Blocktime',
'number',
$pconfig['sshguard_blocktime'],
['min' => 10, 'step' => 10, 'placeholder' => 120]
))->setHelp('Block attackers for initially blocktime seconds after exceeding '.
'threshold. Subsequent blocks increase by a factor of 1.5.%s'.
'Attacks are unblocked at random intervals, so actual block '.
'times will be longer.', '<br />');

$section->addinput(new form_input(
'sshguard_detection_time',
'Detection time',
'number',
$pconfig['sshguard_detection_time'],
['min' => 10, 'step' => 10, 'placeholder' => 1800]
))->setHelp('Remember potential attackers for up to detection_time seconds '.
'before resetting their score.');

$counter = 0;
$addresses = explode(' ', $pconfig['sshguard_whitelist']);

while ($counter < count($addresses)) {
list($address, $address_subnet) = explode("/", $addresses[$counter]);

$group = new Form_Group($counter == 0 ? 'Whitelist' : '');
$group->addClass('repeatable');

$group->add(new Form_IpAddress(
'address' . $counter,
'Address',
$address,
'BOTH'
))->addMask('address_subnet' . $counter, $address_subnet)->setWidth(4);

$group->add(new Form_Button(
'deleterow' . $counter,
'Delete',
null,
'fa-trash'
))->addClass('btn-warning');

$section->add($group);
$counter++;
}

$section->addInput(new Form_Button(
'addrow',
'Add whitelist',
null,
'fa-plus'
))->addClass('btn-success addbtn');

$form->add($section);
$section = new Form_Section('Serial Communications');
Expand Down

0 comments on commit 531aaac

Please sign in to comment.