Skip to content

Commit 8a5eae0

Browse files
author
Till Brehm
committed
Merge branch '6703-shelluser-dedupe-code' into 'develop'
Sync common code between shelluser_jailkit_plugin and shelluser_base_plugin See merge request ispconfig/ispconfig3!1898
2 parents 46a238a + 761977b commit 8a5eae0

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

server/plugins-available/shelluser_base_plugin.inc.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
class shelluser_base_plugin {
3232

33+
//* $plugin_name and $class_name have to be the same then the name of this class
3334
var $plugin_name = 'shelluser_base_plugin';
3435
var $class_name = 'shelluser_base_plugin';
3536
var $min_uid = 499;
@@ -67,7 +68,7 @@ function onLoad() {
6768

6869
}
6970

70-
71+
//* This function is called, when a shell user is inserted in the database
7172
function insert($event_name, $data) {
7273
global $app, $conf;
7374

@@ -190,6 +191,7 @@ function insert($event_name, $data) {
190191
}
191192
}
192193

194+
//* This function is called, when a shell user is updated in the database
193195
function update($event_name, $data) {
194196
global $app, $conf;
195197

@@ -471,11 +473,12 @@ private function _setup_ssh_rsa() {
471473
if (!file_exists($sshkeys)){
472474
// add root's key
473475
$app->file->mkdirs($sshdir, '0700');
476+
474477
if(is_file('/root/.ssh/authorized_keys')) $app->system->file_put_contents($sshkeys, $app->system->file_get_contents('/root/.ssh/authorized_keys'));
475478

476479
// Remove duplicate keys
477480
$existing_keys = @file($sshkeys, FILE_IGNORE_NEW_LINES);
478-
$new_keys = explode("\n", $userkey);
481+
$new_keys = (!is_null($userkey))?explode("\n", $userkey):array();
479482
if(is_array($existing_keys)) {
480483
$final_keys_arr = @array_merge($existing_keys, $new_keys);
481484
} else {
@@ -497,6 +500,9 @@ private function _setup_ssh_rsa() {
497500

498501
//* Get the keys
499502
$existing_keys = file($sshkeys, FILE_IGNORE_NEW_LINES);
503+
if(!$existing_keys) {
504+
$existing_keys = array();
505+
}
500506
$new_keys = explode("\n", $sshrsa);
501507
$old_keys = explode("\n", $this->data['old']['ssh_rsa']);
502508

server/plugins-available/shelluser_jailkit_plugin.inc.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ function insert($event_name, $data) {
101101

102102

103103
if($app->system->is_user($data['new']['puser'])) {
104+
104105
// Get the UID of the parent user
105106
$uid = intval($app->system->getuid($data['new']['puser']));
106107
if($uid > $this->min_uid) {
@@ -159,7 +160,6 @@ function insert($event_name, $data) {
159160
} else {
160161
$app->log("Skipping insertion of user:".$data['new']['username'].", parent user ".$data['new']['puser']." does not exist.", LOGLEVEL_WARN);
161162
}
162-
163163
}
164164

165165
//* This function is called, when a shell user is updated in the database
@@ -518,19 +518,18 @@ private function _setup_ssh_rsa() {
518518
//Generate ssh-rsa-keys
519519
$app->uses('functions');
520520
$app->functions->generate_ssh_key($id, $username);
521-
522521
$app->log("ssh-rsa keypair generated for ".$username, LOGLEVEL_DEBUG);
523522
};
524523

525524
if (!file_exists($sshkeys)){
526525
// add root's key
527-
$app->file->mkdirs($sshdir, '0755');
526+
$app->file->mkdirs($sshdir, '0700');
528527
$authorized_keys_template = $this->jailkit_config['jailkit_chroot_authorized_keys_template'];
529528
if(is_file($authorized_keys_template)) $app->system->file_put_contents($sshkeys, $app->system->file_get_contents($authorized_keys_template));
530529

531530
// Remove duplicate keys
532531
$existing_keys = @file($sshkeys, FILE_IGNORE_NEW_LINES);
533-
$new_keys = (!is_null($userkey))?explode("\n", $userkey):'';
532+
$new_keys = (!is_null($userkey))?explode("\n", $userkey):array();
534533
if(is_array($existing_keys)) {
535534
$final_keys_arr = @array_merge($existing_keys, $new_keys);
536535
} else {
@@ -545,10 +544,11 @@ private function _setup_ssh_rsa() {
545544
$final_keys = implode("\n", array_flip(array_flip($new_final_keys_arr))) . "\n";
546545

547546
// add the user's key
548-
file_put_contents($sshkeys, $final_keys);
547+
$app->system->file_put_contents($sshkeys, $final_keys);
549548
$app->file->remove_blank_lines($sshkeys);
550549
$app->log("ssh-rsa authorisation keyfile created in ".$sshkeys, LOGLEVEL_DEBUG);
551550
}
551+
552552
//* Get the keys
553553
$existing_keys = file($sshkeys, FILE_IGNORE_NEW_LINES);
554554
if(!$existing_keys) {
@@ -589,7 +589,6 @@ private function _setup_ssh_rsa() {
589589

590590
// set proper file permissions
591591
$app->system->exec_safe("chown -R ?:? ?", $this->data['new']['puser'], $this->data['new']['pgroup'], $sshdir);
592-
$app->system->exec_safe("chmod 700 ?", $sshdir);
593592
$app->system->exec_safe("chmod 600 ?", $sshkeys);
594593

595594
}

0 commit comments

Comments
 (0)