From b9cef2f38f87c2fab51c28af33fa688f30d39138 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 26 Jan 2019 12:17:52 -0800 Subject: command line tool for managing site admins --- util/admins | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 util/admins (limited to 'util/admins') diff --git a/util/admins b/util/admins new file mode 100755 index 000000000..22fd2fb4f --- /dev/null +++ b/util/admins @@ -0,0 +1,64 @@ +#!/usr/bin/env php +' . PHP_EOL; + exit(1); +} + + + +require_once('include/cli_startup.php'); +require_once('include/zot.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 + util/admins remove + +EndOfOutput; + return; +} + +if($argc == 1) { + $r = q("select account_id, account_roles, account_email from account"); + 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') { + $r = q("select account_id, account_roles, account_email from account where (account_roles & 4096) > 0"); + 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])) { + $r = q("update account set account_roles = (account_roles | 4096) where account_id = %d", + intval($argv[2]) + ); +} + +if($argc > 2 && $argv[1] === 'remove' && intval($argv[2])) { + $r = q("update account set account_roles = (account_roles - 4096) where account_id = %d and (account_roles & 4096) > 0", + intval($argv[2]) + ); +} -- cgit v1.2.3 From 535f0f45c9dbeb737d5bc888ccbd95fd01fb6e43 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 26 Jan 2019 12:55:12 -0800 Subject: cleanup of cli admin tool --- util/admins | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'util/admins') diff --git a/util/admins b/util/admins index 22fd2fb4f..3c7f0e83e 100755 --- a/util/admins +++ b/util/admins @@ -1,18 +1,14 @@ #!/usr/bin/env php ' . PHP_EOL; + echo 'Run admins from the top level Hubzilla web directory, as util/admins ' . PHP_EOL; exit(1); } require_once('include/cli_startup.php'); -require_once('include/zot.php'); cli_startup(); -- cgit v1.2.3