Commit 396f0e67 authored by tbrehm's avatar tbrehm
Browse files

Fixed linebreaks.

parent e9d22351
<?php <?php
/* /*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met: are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors * Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without may be used to endorse or promote products derived from this software without
specific prior written permission. specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
class shelluser_base_plugin { class shelluser_base_plugin {
var $plugin_name = 'shelluser_base_plugin'; var $plugin_name = 'shelluser_base_plugin';
var $class_name = 'shelluser_base_plugin'; var $class_name = 'shelluser_base_plugin';
var $min_uid = 499; var $min_uid = 499;
//* This function is called during ispconfig installation to determine //* This function is called during ispconfig installation to determine
// if a symlink shall be created for this plugin. // if a symlink shall be created for this plugin.
function onInstall() { function onInstall() {
global $conf; global $conf;
if($conf['services']['web'] == true) { if($conf['services']['web'] == true) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
/* /*
This function is called when the plugin is loaded This function is called when the plugin is loaded
*/ */
function onLoad() { function onLoad() {
global $app; global $app;
/* /*
Register for the events Register for the events
*/ */
$app->plugins->registerEvent('shell_user_insert',$this->plugin_name,'insert'); $app->plugins->registerEvent('shell_user_insert',$this->plugin_name,'insert');
$app->plugins->registerEvent('shell_user_update',$this->plugin_name,'update'); $app->plugins->registerEvent('shell_user_update',$this->plugin_name,'update');
$app->plugins->registerEvent('shell_user_delete',$this->plugin_name,'delete'); $app->plugins->registerEvent('shell_user_delete',$this->plugin_name,'delete');
} }
function insert($event_name,$data) { function insert($event_name,$data) {
global $app, $conf; global $app, $conf;
$app->uses('system'); $app->uses('system');
if($app->system->is_user($data['new']['puser'])) { if($app->system->is_user($data['new']['puser'])) {
// Get the UID of the parent user // Get the UID of the parent user
$uid = intval($app->system->getuid($data['new']['puser'])); $uid = intval($app->system->getuid($data['new']['puser']));
if($uid > $this->min_uid) { if($uid > $this->min_uid) {
$command = 'useradd'; $command = 'useradd';
$command .= ' --home '.escapeshellcmd($data['new']['dir']); $command .= ' --home '.escapeshellcmd($data['new']['dir']);
$command .= ' --gid '.escapeshellcmd($data['new']['pgroup']); $command .= ' --gid '.escapeshellcmd($data['new']['pgroup']);
$command .= ' --non-unique '; $command .= ' --non-unique ';
$command .= ' --password '.escapeshellcmd($data['new']['password']); $command .= ' --password '.escapeshellcmd($data['new']['password']);
$command .= ' --shell '.escapeshellcmd($data['new']['shell']); $command .= ' --shell '.escapeshellcmd($data['new']['shell']);
$command .= ' --uid '.escapeshellcmd($uid); $command .= ' --uid '.escapeshellcmd($uid);
$command .= ' '.escapeshellcmd($data['new']['username']); $command .= ' '.escapeshellcmd($data['new']['username']);
exec($command); exec($command);
$app->log("Added shelluser: ".$data['new']['username'],LOGLEVEL_DEBUG); $app->log("Added shelluser: ".$data['new']['username'],LOGLEVEL_DEBUG);
//* Disable shell user temporarily if we use jailkit //* Disable shell user temporarily if we use jailkit
if($data['new']['chroot'] == 'jailkit') { if($data['new']['chroot'] == 'jailkit') {
$command = 'usermod -L '.escapeshellcmd($data['new']['username']); $command = 'usermod -L '.escapeshellcmd($data['new']['username']);
exec($command); exec($command);
$app->log("Disabling shelluser temporarily: ".$command,LOGLEVEL_DEBUG); $app->log("Disabling shelluser temporarily: ".$command,LOGLEVEL_DEBUG);
} }
} else { } else {
$app->log("UID = $uid for shelluser:".$data['new']['username']." not allowed.",LOGLEVEL_ERROR); $app->log("UID = $uid for shelluser:".$data['new']['username']." not allowed.",LOGLEVEL_ERROR);
} }
} else { } else {
$app->log("Skippung insert of user:".$data['new']['username'].", parent user ".$data['new']['puser']." does not exist.",LOGLEVEL_WARN); $app->log("Skippung insert of user:".$data['new']['username'].", parent user ".$data['new']['puser']." does not exist.",LOGLEVEL_WARN);
} }
} }
function update($event_name,$data) { function update($event_name,$data) {
global $app, $conf; global $app, $conf;
$app->uses('system'); $app->uses('system');
if($app->system->is_user($data['new']['puser'])) { if($app->system->is_user($data['new']['puser'])) {
// Get the UID of the parent user // Get the UID of the parent user
$uid = intval($app->system->getuid($data['new']['puser'])); $uid = intval($app->system->getuid($data['new']['puser']));
if($uid > $this->min_uid) { if($uid > $this->min_uid) {
// Check if the user that we want to update exists, if not, we insert it // Check if the user that we want to update exists, if not, we insert it
if($app->system->is_user($data['old']['username'])) { if($app->system->is_user($data['old']['username'])) {
$command = 'usermod'; $command = 'usermod';
$command .= ' --home '.escapeshellcmd($data['new']['dir']); $command .= ' --home '.escapeshellcmd($data['new']['dir']);
$command .= ' --gid '.escapeshellcmd($data['new']['pgroup']); $command .= ' --gid '.escapeshellcmd($data['new']['pgroup']);
// $command .= ' --non-unique '; // $command .= ' --non-unique ';
$command .= ' --password '.escapeshellcmd($data['new']['password']); $command .= ' --password '.escapeshellcmd($data['new']['password']);
if($data['new']['chroot'] != 'jailkit') $command .= ' --shell '.escapeshellcmd($data['new']['shell']); if($data['new']['chroot'] != 'jailkit') $command .= ' --shell '.escapeshellcmd($data['new']['shell']);
// $command .= ' --uid '.escapeshellcmd($uid); // $command .= ' --uid '.escapeshellcmd($uid);
$command .= ' --login '.escapeshellcmd($data['new']['username']); $command .= ' --login '.escapeshellcmd($data['new']['username']);
$command .= ' '.escapeshellcmd($data['old']['username']); $command .= ' '.escapeshellcmd($data['old']['username']);
exec($command); exec($command);
// $app->log("Updated shelluser: $command ",LOGLEVEL_DEBUG); // $app->log("Updated shelluser: $command ",LOGLEVEL_DEBUG);
$app->log("Updated shelluser: ".$data['old']['username'],LOGLEVEL_DEBUG); $app->log("Updated shelluser: ".$data['old']['username'],LOGLEVEL_DEBUG);
} else { } else {
// The user does not exist, so we insert it now // The user does not exist, so we insert it now
$this->insert($event_name,$data); $this->insert($event_name,$data);
} }
} else { } else {
$app->log("UID = $uid for shelluser:".$data['new']['username']." not allowed.",LOGLEVEL_ERROR); $app->log("UID = $uid for shelluser:".$data['new']['username']." not allowed.",LOGLEVEL_ERROR);
} }
} else { } else {
$app->log("Skippung update for user:".$data['new']['username'].", parent user ".$data['new']['puser']." does not exist.",LOGLEVEL_WARN); $app->log("Skippung update for user:".$data['new']['username'].", parent user ".$data['new']['puser']." does not exist.",LOGLEVEL_WARN);
} }
} }
function delete($event_name,$data) { function delete($event_name,$data) {
global $app, $conf; global $app, $conf;
$app->uses('system'); $app->uses('system');
if($app->system->is_user($data['old']['username'])) { if($app->system->is_user($data['old']['username'])) {
// Get the UID of the user // Get the UID of the user
$userid = intval($app->system->getuid($data['old']['username'])); $userid = intval($app->system->getuid($data['old']['username']));
if($userid > $this->min_uid) { if($userid > $this->min_uid) {
$command = 'userdel -f'; $command = 'userdel -f';
$command .= ' '.escapeshellcmd($data['old']['username']); $command .= ' '.escapeshellcmd($data['old']['username']);
exec($command); exec($command);
$app->log("Deleted shelluser: ".$data['old']['username'],LOGLEVEL_DEBUG); $app->log("Deleted shelluser: ".$data['old']['username'],LOGLEVEL_DEBUG);
} else { } else {
$app->log("UID = $userid for shelluser:".$data['old']['username']." not allowed.",LOGLEVEL_ERROR); $app->log("UID = $userid for shelluser:".$data['old']['username']." not allowed.",LOGLEVEL_ERROR);
} }
} else { } else {
$app->log("User:".$data['new']['username']." does not exist in in /etc/passwd, skipping delete.",LOGLEVEL_WARN); $app->log("User:".$data['new']['username']." does not exist in in /etc/passwd, skipping delete.",LOGLEVEL_WARN);
} }
} }
} // end class } // end class
?> ?>
\ No newline at end of file
<?php <?php
/* /*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met: are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors * Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without may be used to endorse or promote products derived from this software without
specific prior written permission. specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
class shelluser_jailkit_plugin { class shelluser_jailkit_plugin {
//* $plugin_name and $class_name have to be the same then the name of this class //* $plugin_name and $class_name have to be the same then the name of this class
var $plugin_name = 'shelluser_jailkit_plugin'; var $plugin_name = 'shelluser_jailkit_plugin';
var $class_name = 'shelluser_jailkit_plugin'; var $class_name = 'shelluser_jailkit_plugin';
//* This function is called during ispconfig installation to determine //* This function is called during ispconfig installation to determine
// if a symlink shall be created for this plugin. // if a symlink shall be created for this plugin.
function onInstall() { function onInstall() {
global $conf; global $conf;
if($conf['services']['web'] == true) { if($conf['services']['web'] == true) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
/* /*
This function is called when the plugin is loaded This function is called when the plugin is loaded
*/ */
function onLoad() { function onLoad() {
global $app; global $app;
/* /*
Register for the events Register for the events
*/ */
$app->plugins->registerEvent('shell_user_insert',$this->plugin_name,'insert'); $app->plugins->registerEvent('shell_user_insert',$this->plugin_name,'insert');
$app->plugins->registerEvent('shell_user_update',$this->plugin_name,'update'); $app->plugins->registerEvent('shell_user_update',$this->plugin_name,'update');
$app->plugins->registerEvent('shell_user_delete',$this->plugin_name,'delete'); $app->plugins->registerEvent('shell_user_delete',$this->plugin_name,'delete');
} }
//* This function is called, when a shell user is inserted in the database //* This function is called, when a shell user is inserted in the database
function insert($event_name,$data) { function insert($event_name,$data) {
global $app, $conf; global $app, $conf;
$app->uses('system'); $app->uses('system');
if($app->system->is_user($data['new']['username'])) { if($app->system->is_user($data['new']['username'])) {
/** /**
* Setup Jailkit Chroot System If Enabled * Setup Jailkit Chroot System If Enabled
*/ */
if ($data['new']['chroot'] == "jailkit") if ($data['new']['chroot'] == "jailkit")
{ {
// load the server configuration options // load the server configuration options
$app->uses("getconf"); $app->uses("getconf");
$this->data = $data; $this->data = $data;
$this->app = $app; $this->app = $app;
$this->jailkit_config = $app->getconf->get_server_config($conf["server_id"], 'jailkit'); $this->jailkit_config = $app->getconf->get_server_config($conf["server_id"], 'jailkit');
$this->_setup_jailkit_chroot(); $this->_setup_jailkit_chroot();
$command .= 'usermod -U '.escapeshellcmd($data['new']['username']); $command .= 'usermod -U '.escapeshellcmd($data['new']['username']);
exec($command); exec($command);
$this->_add_jailkit_user(); $this->_add_jailkit_user();
} }
$app->log("Jailkit Plugin -> insert username:".$data['new']['username'],LOGLEVEL_DEBUG); $app->log("Jailkit Plugin -> insert username:".$data['new']['username'],LOGLEVEL_DEBUG);
} else { } else {
$app->log("Jailkit Plugin -> insert username:".$data['new']['username']." skipped, the user does not exist.",LOGLEVEL_WARN); $app->log("Jailkit Plugin -> insert username:".$data['new']['username']." skipped, the user does not exist.",LOGLEVEL_WARN);
} }
} }
//* This function is called, when a shell user is updated in the database //* This function is called, when a shell user is updated in the database
function update($event_name,$data) { function update($event_name,$data) {
global $app, $conf; global $app, $conf;
$app->uses('system'); $app->uses('system');
if($app->system->is_user($data['new']['username'])) { if($app->system->is_user($data['new']['username'])) {
/** /**
* Setup Jailkit Chroot System If Enabled * Setup Jailkit Chroot System If Enabled
*/ */
if ($data['new']['chroot'] == "jailkit") if ($data['new']['chroot'] == "jailkit")
{ {
// load the server configuration options // load the server configuration options
$app->uses("getconf"); $app->uses("getconf");
$this->data = $data; $this->data = $data;
$this->app = $app; $this->app = $app;
$this->jailkit_config = $app->getconf->get_server_config($conf["server_id"], 'jailkit'); $this->jailkit_config = $app->getconf->get_server_config($conf["server_id"], 'jailkit');
$this->_setup_jailkit_chroot(); $this->_setup_jailkit_chroot();
$this->_add_jailkit_user(); $this->_add_jailkit_user();
} }
$app->log("Jailkit Plugin -> update username:".$data['new']['username'],LOGLEVEL_DEBUG); $app->log("Jailkit Plugin -> update username:".$data['new']['username'],LOGLEVEL_DEBUG);
} else { } else {
$app->log("Jailkit Plugin -> update username:".$data['new']['username']." skipped, the user does not exist.",LOGLEVEL_WARN); $app->log("Jailkit Plugin -> update username:".$data['new']['username']." skipped, the user does not exist.",LOGLEVEL_WARN);
} }
} }
//* This function is called, when a shell user is deleted in the database //* This function is called, when a shell user is deleted in the database
/** /**
* TODO: Remove chroot user home and from the chroot passwd file * TODO: Remove chroot user home and from the chroot passwd file
*/ */
function delete($event_name,$data) { function delete($event_name,$data) {
global $app, $conf; global $app, $conf;
$app->uses('system'); $app->uses('system');
if ($data['old']['chroot'] == "jailkit") if ($data['old']['chroot'] == "jailkit")
{ {
$app->uses("getconf"); $app->uses("getconf");
$this->jailkit_config = $app->getconf->get_server_config($conf["server_id"], 'jailkit'); $this->jailkit_config = $app->getconf->get_server_config($conf["server_id"], 'jailkit');
$jailkit_chroot_userhome = $this->_get_home_dir($data['old']['username']); $jailkit_chroot_userhome = $this->_get_home_dir($data['old']['username']);
//commented out proved to be dangerous on config errors //commented out proved to be dangerous on config errors
//exec('rm -rf '.$data['old']['dir'].$jailkit_chroot_userhome); //exec('rm -rf '.$data['old']['dir'].$jailkit_chroot_userhome);