|
|
|
|
@ -8,8 +8,8 @@ trait linux_core { |
|
|
|
|
if (! file_exists($file)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
exec(self::get_user_bin . 'chmod -s ' . safe_cmd($file), $output, $exit_code); |
|
|
|
|
check_for_error($exit_code, "Unable to remove sticky bit with chmod: {$file}"); |
|
|
|
|
exec(self::get_user_bin . 'chmod -s ' . safeCmd($file), $output, $exit_code); |
|
|
|
|
checkForError($exit_code, "Unable to remove sticky bit with chmod: {$file}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -17,10 +17,10 @@ trait linux_core { |
|
|
|
|
if (!is_dir($dir)) { |
|
|
|
|
$exit_code = false; |
|
|
|
|
} else { |
|
|
|
|
$perm = get_perms($kind); |
|
|
|
|
exec(self::get_user_bin . 'find ' . safe_cmd($dir) . ' -type d -exec ' . self::get_bin . 'chmod ' . $perm . ' {} \;', $output, $exit_code); |
|
|
|
|
$perm = getPerms($kind); |
|
|
|
|
exec(self::get_user_bin . 'find ' . safeCmd($dir) . ' -type d -exec ' . self::get_bin . 'chmod ' . $perm . ' {} \;', $output, $exit_code); |
|
|
|
|
} |
|
|
|
|
check_for_error($exit_code, "Unable to chmod folders in: {$dir}"); |
|
|
|
|
checkForError($exit_code, "Unable to chmod folders in: {$dir}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -28,10 +28,10 @@ trait linux_core { |
|
|
|
|
if (!is_dir($dir)) { |
|
|
|
|
$exit_code = false; |
|
|
|
|
} else { |
|
|
|
|
$perm = get_perms($kind); |
|
|
|
|
exec(self::get_user_bin . 'find ' . safe_cmd($dir) . ' -type f -exec ' . self::get_bin . 'chmod ' . $perm . ' {} \;', $output, $exit_code); |
|
|
|
|
$perm = getPerms($kind); |
|
|
|
|
exec(self::get_user_bin . 'find ' . safeCmd($dir) . ' -type f -exec ' . self::get_bin . 'chmod ' . $perm . ' {} \;', $output, $exit_code); |
|
|
|
|
} |
|
|
|
|
check_for_error($exit_code, "Unable to chmod files in: {$dir}"); |
|
|
|
|
checkForError($exit_code, "Unable to chmod files in: {$dir}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -39,9 +39,9 @@ trait linux_core { |
|
|
|
|
if (!is_file($file)) { |
|
|
|
|
$exit_code = false; |
|
|
|
|
} else { |
|
|
|
|
exec(self::get_user_bin . 'chattr +i ' . safe_cmd($file), $output, $exit_code); |
|
|
|
|
exec(self::get_user_bin . 'chattr +i ' . safeCmd($file), $output, $exit_code); |
|
|
|
|
} |
|
|
|
|
check_for_error($exit_code, "Unable to write protect: {$file}"); |
|
|
|
|
checkForError($exit_code, "Unable to write protect: {$file}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -49,44 +49,44 @@ trait linux_core { |
|
|
|
|
if (!is_file($file)) { |
|
|
|
|
$exit_code = false; |
|
|
|
|
} else { |
|
|
|
|
exec(self::get_user_bin . 'chattr -i ' . safe_cmd($file), $output, $exit_code); |
|
|
|
|
exec(self::get_user_bin . 'chattr -i ' . safeCmd($file), $output, $exit_code); |
|
|
|
|
} |
|
|
|
|
check_for_error($exit_code, "Unable to un-write protect: {$file}"); |
|
|
|
|
checkForError($exit_code, "Unable to un-write protect: {$file}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function groupadd(string $groupname, int $gid = 0) { |
|
|
|
|
$group_id = ($gid > 0) ? "-g {$gid} " : ""; |
|
|
|
|
exec(self::get_super_user_bin . 'groupadd '. $group_id . safe_cmd($groupname), $output, $exit_code); |
|
|
|
|
exec(self::get_super_user_bin . 'groupadd '. $group_id . safeCmd($groupname), $output, $exit_code); |
|
|
|
|
if ($exit_code === 0) { |
|
|
|
|
display(getTermColors("Added new group named: $groupname", ['color'=>'green'])); |
|
|
|
|
} |
|
|
|
|
check_for_error($exit_code, "Unable to add new group: {$groupname}"); |
|
|
|
|
checkForError($exit_code, "Unable to add new group: {$groupname}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function userdel(string $username) { |
|
|
|
|
exec(self::get_super_user_bin . 'userdel ' . safe_cmd($username), $output, $exit_code); |
|
|
|
|
exec(self::get_super_user_bin . 'userdel ' . safeCmd($username), $output, $exit_code); |
|
|
|
|
if ($exit_code === 0) { |
|
|
|
|
display(getTermColors("Deleted user account named: $username", ['color'=>'green'])); |
|
|
|
|
} |
|
|
|
|
check_for_error($exit_code, "Unable to delete user: {$username}"); |
|
|
|
|
checkForError($exit_code, "Unable to delete user: {$username}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function useradd(string $username, int $uid = 0, string $shell="/bin/bash", string $comment = "", string $groups="", string $homedir="") { |
|
|
|
|
$user_id = ($uid > 0) ? "-u {$uid} " : ""; |
|
|
|
|
$dir = (empty($homedir)) ? " -m " : " -d " . safe_cmd($homedir); |
|
|
|
|
exec(self::get_super_user_bin . 'useradd '. $user_id . '-s '. safe_cmd($shell) . $dir . ' -c '. safe_cmd($comment) .'-G'. safe_cmd($groups) . ' ' . safe_cmd($username), $output, $exit_code); |
|
|
|
|
$dir = (empty($homedir)) ? " -m " : " -d " . safeCmd($homedir); |
|
|
|
|
exec(self::get_super_user_bin . 'useradd '. $user_id . '-s '. safeCmd($shell) . $dir . ' -c '. safeCmd($comment) .'-G'. safeCmd($groups) . ' ' . safeCmd($username), $output, $exit_code); |
|
|
|
|
if ($exit_code === 0) { |
|
|
|
|
display(getTermColors("Added new user account named: $username", ['color'=>'green'])); |
|
|
|
|
} |
|
|
|
|
check_for_error($exit_code, "Unable to add new user: {$username}"); |
|
|
|
|
checkForError($exit_code, "Unable to add new user: {$username}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function lock_status(string $username) { |
|
|
|
|
exec(self::get_user_bin . 'passwd -S ' . safe_cmd($username) . " | awk '{print $2}'", $output, $exit_code); |
|
|
|
|
exec(self::get_user_bin . 'passwd -S ' . safeCmd($username) . " | awk '{print $2}'", $output, $exit_code); |
|
|
|
|
$sw = $output[0] ?? ""; |
|
|
|
|
switch ($sw) { |
|
|
|
|
case "P": echo "Account is not locked"; break; |
|
|
|
|
@ -94,34 +94,34 @@ trait linux_core { |
|
|
|
|
case "L": echo "Account is Locked"; break; |
|
|
|
|
default: echo "Account does not exist?!"; break; |
|
|
|
|
} |
|
|
|
|
check_for_error($exit_code, "Unable to view account: {$username}"); |
|
|
|
|
checkForError($exit_code, "Unable to view account: {$username}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function passwd(string $username) { |
|
|
|
|
exec(self::get_user_bin . 'passwd ' . safe_cmd($username), $output, $exit_code); |
|
|
|
|
check_for_error($exit_code, "Unable to set user password: {$username}"); |
|
|
|
|
exec(self::get_user_bin . 'passwd ' . safeCmd($username), $output, $exit_code); |
|
|
|
|
checkForError($exit_code, "Unable to set user password: {$username}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Details about age of passwords |
|
|
|
|
public static function chage(string $username) { |
|
|
|
|
exec(self::get_user_bin . 'chage -l ' . safe_cmd($username), $output, $exit_code); |
|
|
|
|
check_for_error($exit_code, "Unable to view user password changes: {$username}"); |
|
|
|
|
exec(self::get_user_bin . 'chage -l ' . safeCmd($username), $output, $exit_code); |
|
|
|
|
checkForError($exit_code, "Unable to view user password changes: {$username}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
// yyyy-mm-dd |
|
|
|
|
public static function lock(string $username, string $expires_on="") { |
|
|
|
|
$exp = (! empty($expires_on)) ? "--expiredate ". safe_cmd($expires_on) . " " : ""; |
|
|
|
|
exec(self::get_super_user_bin . 'usermod -L '. $exp . safe_cmd($username), $output, $exit_code); |
|
|
|
|
check_for_error($exit_code, "Unable to Lock user account: {$username}"); |
|
|
|
|
$exp = (! empty($expires_on)) ? "--expiredate ". safeCmd($expires_on) . " " : ""; |
|
|
|
|
exec(self::get_super_user_bin . 'usermod -L '. $exp . safeCmd($username), $output, $exit_code); |
|
|
|
|
checkForError($exit_code, "Unable to Lock user account: {$username}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function unlock(string $username, string $expires_on="") { |
|
|
|
|
$exp = (! empty($expires_on)) ? "--expiredate ". safe_cmd($expires_on) . " " : "--expiredate '' "; |
|
|
|
|
exec(self::get_super_user_bin . 'usermod -U ' . $exp . safe_cmd($username), $output, $exit_code); |
|
|
|
|
check_for_error($exit_code, "Unable to Unlock user account: {$username}"); |
|
|
|
|
$exp = (! empty($expires_on)) ? "--expiredate ". safeCmd($expires_on) . " " : "--expiredate '' "; |
|
|
|
|
exec(self::get_super_user_bin . 'usermod -U ' . $exp . safeCmd($username), $output, $exit_code); |
|
|
|
|
checkForError($exit_code, "Unable to Unlock user account: {$username}"); |
|
|
|
|
return $exit_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|