Skip to content

Instantly share code, notes, and snippets.

@stephdl
Last active November 23, 2018 09:45
Show Gist options
  • Save stephdl/02c972d4553073215ffe707d32dd13cd to your computer and use it in GitHub Desktop.
Save stephdl/02c972d4553073215ffe707d32dd13cd to your computer and use it in GitHub Desktop.
delete-all-users
#!/usr/bin/php
<?php
echo "Are you sure you want to delete all users ? Type 'yes' to continue: ";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if(trim($line) != 'yes'){
echo "ABORTING!\n";
exit;
}
fclose($handle);
echo "\n";
echo "Thank you, continuing...\n";
$array1 = json_decode(exec('/usr/libexec/nethserver/list-users'));
foreach ( $array1 as $key => $values) {
if (preg_match('/^administrator@/',$key) || preg_match('/^admin@/',$key)){
continue;
}
exec ("/usr/sbin/e-smith/signal-event user-delete $key",$output, $return_var);
if ($return_var !== 0) {
echo "ERROR: the user $key has not been deleted\n";
}
else {
echo "The user $key has been deleted\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment