diff options
author | zotlabs <mike@macgirvin.com> | 2019-01-26 12:17:52 -0800 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2019-01-26 12:17:52 -0800 |
commit | b9cef2f38f87c2fab51c28af33fa688f30d39138 (patch) | |
tree | 49e3dc3dfec06e81e79f22f9f0da06dfdba61b66 /util | |
parent | 2fa274de1e567665c5fd3d25e382557eb4325d83 (diff) | |
download | volse-hubzilla-b9cef2f38f87c2fab51c28af33fa688f30d39138.tar.gz volse-hubzilla-b9cef2f38f87c2fab51c28af33fa688f30d39138.tar.bz2 volse-hubzilla-b9cef2f38f87c2fab51c28af33fa688f30d39138.zip |
command line tool for managing site admins
Diffstat (limited to 'util')
-rwxr-xr-x | util/admins | 64 |
1 files changed, 64 insertions, 0 deletions
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 + +// Red pconfig utility + + +if(!file_exists('include/cli_startup.php')) { + echo 'Run pconfig from the top level Hubzilla web directory, as util/pconfig <args>' . 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 <account_id> + util/admins remove <account_id> + +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]) + ); +} |