1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- define('INSTALLDIR', dirname(__DIR__));
- define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
- $shortoptions = 'i:n:o';
- $longoptions = array('id=', 'nickname=', 'owner');
- $helptext = <<<END_OF_USERROLE_HELP
- command.php [options] [command line]
- Perform commands on behalf of a user, such as sub, unsub, join, drop
- -i --id ID of the user
- -n --nickname nickname of the user
- -o --owner use the site owner
- END_OF_USERROLE_HELP;
- require_once INSTALLDIR . '/scripts/commandline.inc';
- function interpretCommand($user, $body)
- {
- $inter = new CommandInterpreter();
- $chan = new CLIChannel();
- $cmd = $inter->handle_command($user, $body);
- if ($cmd) {
- $cmd->execute($chan);
- return true;
- } else {
- $chan->error($user, "Not a valid command. Try 'help'?");
- return false;
- }
- }
- if (have_option('i', 'id')) {
- $id = get_option_value('i', 'id');
- $user = User::getKV('id', $id);
- if (empty($user)) {
- print "Can't find user with ID $id\n";
- exit(1);
- }
- } else if (have_option('n', 'nickname')) {
- $nickname = get_option_value('n', 'nickname');
- $user = User::getKV('nickname', $nickname);
- if (empty($user)) {
- print "Can't find user with nickname '$nickname'\n";
- exit(1);
- }
- } else if (have_option('o', 'owner')) {
- try {
- $user = User::siteOwner();
- } catch (ServerException $e) {
- print "Site has no owner.\n";
- exit(1);
- }
- } else {
- print "You must provide either an ID or a nickname.\n\n";
- print $helptext;
- exit(1);
- }
- interpretCommand($user, implode(' ', $args));
|