add libnss-extrausers for debian/ubuntu users
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
72
scripts/classes/class.Extrausers.php
Normal file
72
scripts/classes/class.Extrausers.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2017 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2017-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Cron
|
||||
*
|
||||
*/
|
||||
class Extrausers
|
||||
{
|
||||
|
||||
public static function generateFiles(&$cronlog)
|
||||
{
|
||||
// passwd
|
||||
$passwd = '/var/lib/extrausers/passwd';
|
||||
$sql = "SELECT username,'x' as password,uid,gid,'Froxlor User' as comment,homedir,shell FROM ftp_users WHERE login_enabled = 'Y' ORDER BY uid ASC";
|
||||
self::_generateFile($passwd, $sql, $cronlog);
|
||||
|
||||
// group
|
||||
$group = '/var/lib/extrausers/group';
|
||||
$sql = "SELECT groupname,'x' as password,gid,members FROM ftp_groups ORDER BY gid ASC";
|
||||
self::_generateFile($group, $sql, $cronlog);
|
||||
|
||||
// shadow
|
||||
$shadow = '/var/lib/extrausers/shadow';
|
||||
$sql = "SELECT username,password FROM ftp_users ORDER BY gid ASC";
|
||||
self::_generateFile($shadow, $sql, $cronlog);
|
||||
}
|
||||
|
||||
private static function _generateFile($file, $query, &$cronlog)
|
||||
{
|
||||
$type = basename($file);
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Creating ' . $type . ' file');
|
||||
|
||||
if (! file_exists($file)) {
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, $type . ' file does not yet exist');
|
||||
@mkdir(dirname($file), 0750, true);
|
||||
touch($file);
|
||||
}
|
||||
|
||||
$data_sel_stmt = Database::query($query);
|
||||
$data_content = "";
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Writing ' . $data_sel_stmt->rowCount() . ' entries to ' . $type . ' file');
|
||||
while ($u = $data_sel_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
switch ($type) {
|
||||
case 'passwd':
|
||||
$line = $u['username'] . ':' . $u['password'] . ':' . $u['uid'] . ':' . $u['gid'] . ':' . $u['comment'] . ':' . $u['homedir'] . ':' . $u['shell'] . PHP_EOL;
|
||||
break;
|
||||
case 'group':
|
||||
$line = $u['groupname'] . ':' . $u['password'] . ':' . $u['gid'] . ':' . $u['members'] . PHP_EOL;
|
||||
break;
|
||||
case 'shadow':
|
||||
$line = $u['username'] . ':' . $u['password'] . ':' . floor(time() / 86400 - 1) . ':0:99999:7:::' . PHP_EOL;
|
||||
break;
|
||||
}
|
||||
$data_content .= $line;
|
||||
}
|
||||
if (file_put_contents($file, $data_content) !== false) {
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Succesfully wrote ' . $type . ' file');
|
||||
} else {
|
||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Error when writing ' . $type . ' file entries');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user