streams/util/admins

60 lines
1.4 KiB
Text
Raw Permalink Normal View History

2019-01-26 20:31:07 +00:00
#!/usr/bin/env php
<?php
if(!file_exists('include/cli_startup.php')) {
2019-01-27 20:39:28 +00:00
echo 'Run admins from the top level web directory, as util/admins <args>' . PHP_EOL;
2019-01-26 20:31:07 +00:00
exit(1);
}
require_once('include/cli_startup.php');
cli_startup();
$helpArgs = getopt('h', array('help'));
if (count($helpArgs) === 1) {
echo <<<'EndOfOutput'
adds, removes, or lists admins
Usage: util/admins
util/admins list
util/admins add <account_id>
util/admins remove <account_id>
EndOfOutput;
return;
}
if($argc == 1) {
2021-12-02 23:02:31 +00:00
$r = q('select account_id, account_roles, account_email from account');
2019-01-26 20:31:07 +00:00
if($r) {
foreach($r as $rr) {
echo sprintf('%4u %s %s', $rr['account_id'], $rr['account_email'],(($rr['account_roles'] & 4096) ? '*' : '')) . PHP_EOL;
}
}
}
if($argc > 1 && $argv[1] === 'list') {
2021-12-02 23:02:31 +00:00
$r = q('select account_id, account_roles, account_email from account where (account_roles & 4096) > 0');
2019-01-26 20:31:07 +00:00
if($r) {
foreach($r as $rr) {
echo sprintf('%4u %s %s', $rr['account_id'], $rr['account_email'],(($rr['account_roles'] & 4096) ? '*' : '')) . PHP_EOL;
}
}
}
if($argc > 2 && $argv[1] === 'add' && intval($argv[2])) {
2024-06-14 02:52:52 +00:00
$r = q('update account set account_roles = 4096, account_flags = 0 where account_id = %d',
2019-01-26 20:31:07 +00:00
intval($argv[2])
);
}
if($argc > 2 && $argv[1] === 'remove' && intval($argv[2])) {
2021-12-02 23:02:31 +00:00
$r = q('update account set account_roles = (account_roles - 4096) where account_id = %d and (account_roles & 4096) > 0',
2019-01-26 20:31:07 +00:00
intval($argv[2])
);
}