Newer
Older
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
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
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,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
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
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class system{
var $FILE = '/root/ispconfig/scripts/lib/classes/ispconfig_system.lib.php';
var $server_id;
var $server_conf;
var $data;
/**
* Construct for this class
*
* @return system
*/
public function system(){
//global $go_info;
//$this->server_id = $go_info['isp']['server_id'];
//$this->server_conf = $go_info['isp']['server_conf'];
$this->server_conf['passwd_datei'] = '/etc/passwd';
$this->server_conf['shadow_datei'] = '/etc/shadow';
$this->server_conf['group_datei'] = '/etc/group';
}
/**
* Get the hostname from the server
*
* @return string
*/
public function hostname(){
$dist = $this->server_conf['dist'];
$hostname = ob_get_contents();
ob_end_clean();
$hostname = trim($hostname);
ob_start();
if(!strstr($dist, 'freebsd')){
passthru('dnsdomainname');
}
$domainname = ob_get_contents();
ob_end_clean();
$domainname = trim($domainname);
if($domainname != ""){
if(!strstr($hostname, $domainname)) $hostname .= ".".$domainname;
}
return $hostname;
}
/**
* Add an user to the system
*
*/
public function adduser($user_username, $uid, $gid, $username, $homedir, $shell, $passwort = '*'){
global $app;
if($this->is_user($user_username)){
return false;
} else {
if(trim($user_username) != '') {
$user_datei = $this->server_conf['passwd_datei'];
$shadow_datei = $this->server_conf['shadow_datei'];
$shell = realpath($shell);
if(trim($passwort) == '') $passwort = '*';
$new_user = "\n$user_username:x:$uid:$gid:$username:$homedir:$shell\n";
$app->log->msg('USER: '.$new_user);
$app->file->af($user_datei, $new_user);
if($shadow_datei == '/etc/shadow'){
$datum = time();
$tage = floor($datum/86400);
$new_passwd = "\n$user_username:$passwort:$tage:0:99999:7:::\n";
} else {
$new_passwd = "\n$user_username:$passwort:$uid:$gid::0:0:$username:$homedir:$shell\n";
}
$app->file->af($shadow_datei, $new_passwd);
// TB: leere Zeilen entfernen
$app->file->remove_blank_lines($shadow_datei);
$app->file->remove_blank_lines($user_datei);
// TB: user Sortierung deaktiviert
//$this->order_users_groups();
if($shadow_datei != '/etc/shadow'){
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
$app->file->af($shadow_datei, "\n");
// TB: leere Zeilen entfernen
$app->file->remove_blank_lines($shadow_datei);
$app->log->caselog("pwd_mkdb $shadow_datei &> /dev/null", $this->FILE, __LINE__);
}
return true;
}
}
}
/**
* Update users when someone edit it
*
*/
function updateuser($user_username, $uid, $gid, $username, $homedir, $shell, $passwort = '*'){
//* First delete the users
$this->deluser($user_username);
//* Add the user again
$this->adduser($user_username, $uid, $gid, $username, $homedir, $shell, $passwort);
}
/**
* Lock the user
*
*/
function deactivateuser($user_username){
$passwort = str_rot13($this->getpasswd($user_username));
$user_attr = $this->get_user_attributes($user_username);
$uid = $user_attr['uid'];
$gid = $user_attr['gid'];
$username = $user_attr['name'];
$homedir = $user_attr['homedir'];
$shell = '/dev/null';
$this->deluser($user_username);
$this->adduser($user_username, $uid, $gid, $username, $homedir, $shell, $passwort);
}
/**
* Delete a user from the system
*
*/
function deluser($user_username){
global $app;
if($this->is_user($user_username)){
$user_datei = $this->server_conf['passwd_datei'];
$shadow_datei = $this->server_conf['shadow_datei'];
$users = $app->file->rf($user_datei);
$lines = explode("\n", $users);
if(is_array($lines)){
$num_lines = sizeof($lines);
for($i=0;$i<$num_lines;$i++){
if(trim($lines[$i]) != ''){
list($f1,) = explode(':', $lines[$i]);
if($f1 != $user_username) $new_lines[] = $lines[$i];
}
}
$new_users = implode("\n", $new_lines);
$app->file->wf($user_datei, $new_users);
unset($new_lines);
unset($lines);
unset($new_users);
}
$app->file->remove_blank_lines($user_datei);
$passwds = $app->file->rf($shadow_datei);
$lines = explode("\n", $passwds);
if(is_array($lines)){
$num_lines = sizeof($lines);
for($i=0;$i<$num_lines;$i++){
if(trim($lines[$i]) != ''){
list($f1,) = explode(':', $lines[$i]);
if($f1 != $user_username) $new_lines[] = $lines[$i];
}
}
$new_passwds = implode("\n", $new_lines);
$app->file->wf($shadow_datei, $new_passwds);
unset($new_lines);
unset($lines);
unset($new_passwds);
}
$app->file->remove_blank_lines($shadow_datei);
$group_file = $app->file->rf($this->server_conf['group_datei']);
$group_file_lines = explode("\n", $group_file);
foreach($group_file_lines as $group_file_line){
if(trim($group_file_line) != ''){
list($f1, $f2, $f3, $f4) = explode(':', $group_file_line);
$group_users = explode(',', str_replace(' ', '', $f4));
if(in_array($user_username, $group_users)){
$g_users = array();
foreach($group_users as $group_user){
Loading full blame...