Commit 8cc6b5a4 authored by Marius Burkard's avatar Marius Burkard

Merge branch 'master' into 'master'

Fix #4808 Load the existing keys without new line, so array_search can find the…

Closes #4808

See merge request ispconfig/ispconfig3!653
parents 5812c6c0 693e4b93
...@@ -461,7 +461,7 @@ class shelluser_base_plugin { ...@@ -461,7 +461,7 @@ class shelluser_base_plugin {
if(is_file('/root/.ssh/authorized_keys')) $app->system->file_put_contents($sshkeys, $app->system->file_get_contents('/root/.ssh/authorized_keys')); if(is_file('/root/.ssh/authorized_keys')) $app->system->file_put_contents($sshkeys, $app->system->file_get_contents('/root/.ssh/authorized_keys'));
// Remove duplicate keys // Remove duplicate keys
$existing_keys = @file($sshkeys); $existing_keys = @file($sshkeys, FILE_IGNORE_NEW_LINES);
$new_keys = explode("\n", $userkey); $new_keys = explode("\n", $userkey);
$final_keys_arr = @array_merge($existing_keys, $new_keys); $final_keys_arr = @array_merge($existing_keys, $new_keys);
$new_final_keys_arr = array(); $new_final_keys_arr = array();
...@@ -479,7 +479,7 @@ class shelluser_base_plugin { ...@@ -479,7 +479,7 @@ class shelluser_base_plugin {
} }
//* Get the keys //* Get the keys
$existing_keys = file($sshkeys); $existing_keys = file($sshkeys, FILE_IGNORE_NEW_LINES);
$new_keys = explode("\n", $sshrsa); $new_keys = explode("\n", $sshrsa);
$old_keys = explode("\n", $this->data['old']['ssh_rsa']); $old_keys = explode("\n", $this->data['old']['ssh_rsa']);
...@@ -487,7 +487,9 @@ class shelluser_base_plugin { ...@@ -487,7 +487,9 @@ class shelluser_base_plugin {
if(is_array($old_keys)) { if(is_array($old_keys)) {
foreach($old_keys as $key => $val) { foreach($old_keys as $key => $val) {
$k = array_search(trim($val), $existing_keys); $k = array_search(trim($val), $existing_keys);
unset($existing_keys[$k]); if ($k !== false) {
unset($existing_keys[$k]);
}
} }
} }
......
...@@ -480,7 +480,7 @@ class shelluser_jailkit_plugin { ...@@ -480,7 +480,7 @@ class shelluser_jailkit_plugin {
if(is_file('/root/.ssh/authorized_keys')) $app->system->file_put_contents($sshkeys, $app->system->file_get_contents('/root/.ssh/authorized_keys')); if(is_file('/root/.ssh/authorized_keys')) $app->system->file_put_contents($sshkeys, $app->system->file_get_contents('/root/.ssh/authorized_keys'));
// Remove duplicate keys // Remove duplicate keys
$existing_keys = @file($sshkeys); $existing_keys = @file($sshkeys, FILE_IGNORE_NEW_LINES);
$new_keys = explode("\n", $userkey); $new_keys = explode("\n", $userkey);
$final_keys_arr = @array_merge($existing_keys, $new_keys); $final_keys_arr = @array_merge($existing_keys, $new_keys);
$new_final_keys_arr = array(); $new_final_keys_arr = array();
...@@ -497,7 +497,7 @@ class shelluser_jailkit_plugin { ...@@ -497,7 +497,7 @@ class shelluser_jailkit_plugin {
$this->app->log("ssh-rsa authorisation keyfile created in ".$sshkeys, LOGLEVEL_DEBUG); $this->app->log("ssh-rsa authorisation keyfile created in ".$sshkeys, LOGLEVEL_DEBUG);
} }
//* Get the keys //* Get the keys
$existing_keys = file($sshkeys); $existing_keys = file($sshkeys, FILE_IGNORE_NEW_LINES);
$new_keys = explode("\n", $sshrsa); $new_keys = explode("\n", $sshrsa);
$old_keys = explode("\n", $this->data['old']['ssh_rsa']); $old_keys = explode("\n", $this->data['old']['ssh_rsa']);
...@@ -505,7 +505,9 @@ class shelluser_jailkit_plugin { ...@@ -505,7 +505,9 @@ class shelluser_jailkit_plugin {
if(is_array($old_keys)) { if(is_array($old_keys)) {
foreach($old_keys as $key => $val) { foreach($old_keys as $key => $val) {
$k = array_search(trim($val), $existing_keys); $k = array_search(trim($val), $existing_keys);
unset($existing_keys[$k]); if ($k !== false) {
unset($existing_keys[$k]);
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment