main
Robert 2 years ago
parent 2f4b55048b
commit d7aae69381
  1. 39
      app/OS/neato_Ubuntu.php

@ -13,55 +13,55 @@ final class neato {
}
public static function is_installed($prog) {
public static function is_installed(string $prog) {
exec(self::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . self::get_bin . 'grep "install ok installed"', $out, $exit_code);
exec(self::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . self::get_bin . 'grep ^Version', $output, $code);
$version = str_replace('Version: ', '', $output[0]);
return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false];
}
public static function service($name, $action = 'restart') {
public static function service(string $name, string $action = 'restart') {
exec(self::get_super_user_bin . 'service ' . safe_cmd($name, $action), $output, $exit_code);
display($output);
check_for_error($exit_code, "Unable to {$action} Service called: {$name}");
return $exit_code;
}
public static function systemctl($name, $action = 'enable') {
public static function systemctl(string $name, string $action = 'enable') {
exec(self::get_bin . 'systemctl ' . safe_cmd($action, $name), $output, $exit_code);
check_for_error($exit_code, "Unable to {$action} Service called: {$name}");
return $exit_code;
}
public static function upgrade($prog) {
public static function upgrade(string $prog) {
exec(self::get_user_bin . 'apt-get upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code);
display($output);
check_for_error($exit_code, "Unable to upgrade: {$prog}");
return $exit_code;
}
public static function install($prog) {
public static function install(string $prog) {
exec(self::get_user_bin . 'apt-get install -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code);
display($output);
check_for_error($exit_code, "Unable to install: {$prog}");
return $exit_code;
}
public static function purge($prog) {
public static function purge(string $prog) {
exec(self::get_user_bin . 'apt-get --purge remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code);
display($output);
check_for_error($exit_code, "Unable to uninstall: {$prog}");
return $exit_code;
}
public static function uninstall($prog) {
public static function uninstall(string $prog) {
exec(self::get_user_bin . 'apt-get remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code);
display($output);
check_for_error($exit_code, "Unable to uninstall: {$prog}");
return $exit_code;
}
public static function add_repo($repo) {
public static function add_repo(string $repo) {
exec(self::get_user_bin . 'add-apt-repository -y -u ' . safe_cmd_quotes($repo) . stderr(), $output, $exit_code);
display($output); // -u = DO UPDATE once done...
check_for_error($exit_code, "Unable to uninstall: {$repo}");
@ -80,7 +80,7 @@ final class neato {
return $exit_code;
}
public static function no_sticky_bit($file) {
public static function no_sticky_bit(string $file) {
if (! file_exists($file)) {
return true;
}
@ -89,7 +89,7 @@ final class neato {
return $exit_code;
}
public static function chmod_on_folders($dir, $kind) {
public static function chmod_on_folders(string $dir, $kind) {
if (!is_dir($dir)) {
$exit_code = false;
} else {
@ -100,7 +100,7 @@ final class neato {
return $exit_code;
}
public static function chmod_on_files($dir, $kind) {
public static function chmod_on_files(string $dir, $kind) {
if (!is_dir($dir)) {
$exit_code = false;
} else {
@ -111,7 +111,7 @@ final class neato {
return $exit_code;
}
public static function write_protect_file($file) {
public static function write_protect_file(string $file) {
if (!is_file($file)) {
$exit_code = false;
} else {
@ -121,7 +121,7 @@ final class neato {
return $exit_code;
}
public static function unwrite_protect_file($file) {
public static function unwrite_protect_file(string $file) {
if (!is_file($file)) {
$exit_code = false;
} else {
@ -131,7 +131,7 @@ final class neato {
return $exit_code;
}
public static function userdel($username) {
public static function userdel(string $username) {
exec(self::get_super_user_bin . 'userdel ' . safe_cmd($username), $output, $exit_code);
if ($exit_code === true || $exit_code === 0) {
display(getTermColors("Deleted user account named: $username", ['color'=>'green']));
@ -140,13 +140,14 @@ final class neato {
return $exit_code;
}
public static function useradd($username) {
exec(self::get_super_user_bin . 'useradd ' . safe_cmd($username), $output, $exit_code);
public static function useradd(string $username, string $shell="/bin/bash", string $comment = "", string $groups="", string $homedir="") {
$dir = (empty($homedir)) ? " -m " : " -d " . safe_cmd($homedir);
exec(self::get_super_user_bin . 'useradd -s '. safe_cmd($shell) . $dir . ' -c '. safe_cmd($comment) .'-G'. safe_cmd($groups) . ' ' . safe_cmd($username), $output, $exit_code);
check_for_error($exit_code, "Unable to add new user: {$username}");
return $exit_code;
}
public static function lock_status($username) {
public static function lock_status(string $username) {
exec(self::get_user_bin . 'passwd -S ' . safe_cmd($username) . " | awk '{print $2}'", $output, $exit_code);
$sw = $output[0] ?? "";
switch ($sw) {
@ -159,14 +160,14 @@ final class neato {
return $exit_code;
}
public static function passwd($username) {
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}");
return $exit_code;
}
// Details about age of passwords
public static function chage($username) {
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}");
return $exit_code;

Loading…
Cancel
Save