diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/console.php | 21 | ||||
-rwxr-xr-x | scripts/setconfig.php | 98 | ||||
-rwxr-xr-x | scripts/xmppdaemon.php | 20 |
3 files changed, 112 insertions, 27 deletions
diff --git a/scripts/console.php b/scripts/console.php index 210d2b6b2..329caf472 100755 --- a/scripts/console.php +++ b/scripts/console.php @@ -73,7 +73,7 @@ function read_input_line($prompt) */ function readline_emulation($prompt) { - if(file_exists(trim(shell_exec('which bash')))) { + if(CONSOLE_INTERACTIVE && file_exists(trim(shell_exec('which bash')))) { $encPrompt = escapeshellarg($prompt); $command = "read -er -p $encPrompt && echo \"\$REPLY\""; $encCommand = escapeshellarg($command); @@ -103,7 +103,9 @@ function readline_emulation($prompt) if (feof(STDIN)) { return false; } - print $prompt; + if (CONSOLE_INTERACTIVE) { + print $prompt; + } return fgets(STDIN); } @@ -123,13 +125,16 @@ function console_help() print "Type ctrl+D or enter 'exit' to exit.\n"; } - -print "StatusNet interactive PHP console... type ctrl+D or enter 'exit' to exit.\n"; -$prompt = common_config('site', 'name') . '> '; +if (CONSOLE_INTERACTIVE) { + print "StatusNet interactive PHP console... type ctrl+D or enter 'exit' to exit.\n"; + $prompt = common_config('site', 'name') . '> '; +} while (!feof(STDIN)) { $line = read_input_line($prompt); if ($line === false) { - print "\n"; + if (CONSOLE_INTERACTIVE) { + print "\n"; + } break; } elseif ($line !== '') { try { @@ -154,5 +159,7 @@ while (!feof(STDIN)) { print get_class($e) . ": " . $e->getMessage() . "\n"; } } - print "\n"; + if (CONSOLE_INTERACTIVE) { + print "\n"; + } } diff --git a/scripts/setconfig.php b/scripts/setconfig.php new file mode 100755 index 000000000..b102f99b1 --- /dev/null +++ b/scripts/setconfig.php @@ -0,0 +1,98 @@ +#!/usr/bin/env php +<?php +/* + * StatusNet - a distributed open-source microblogging tool + * Copyright (C) 2008, 2009, StatusNet, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'd'; +$longoptions = array('delete'); + +$helptext = <<<END_OF_SETCONFIG_HELP +setconfig.php [options] [section] [setting] <value> +With three args, set the setting to the value. +With two args, just show the setting. +With -d, delete the setting. + + [section] section to use (required) + [setting] setting to use (required) + <value> value to set (optional) + + -d --delete delete the setting (no value) + +END_OF_SETCONFIG_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +if (count($args) < 2 || count($args) > 3) { + show_help(); + exit(1); +} + +$section = $args[0]; +$setting = $args[1]; + +if (count($args) == 3) { + $value = $args[2]; +} else { + $value = null; +} + +try { + + if (have_option('d', 'delete')) { // Delete + if (count($args) != 2) { + show_help(); + exit(1); + } + + if (have_option('v', 'verbose')) { + print "Deleting setting $section/$setting..."; + } + + $setting = Config::pkeyGet(array('section' => $section, + 'setting' => $setting)); + + if (empty($setting)) { + print "Not found.\n"; + } else { + $result = $setting->delete(); + if ($result) { + print "DONE.\n"; + } else { + print "ERROR.\n"; + } + } + } else if (count($args) == 2) { // show + if (have_option('v', 'verbose')) { + print "$section/$setting = "; + } + $value = common_config($section, $setting); + print "$value\n"; + } else { // set + if (have_option('v', 'verbose')) { + print "Setting $section/$setting..."; + } + Config::save($section, $setting, $value); + print "DONE.\n"; + } + +} catch (Exception $e) { + print $e->getMessage() . "\n"; + exit(1); +} diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index e52e2a6af..20105b602 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -195,17 +195,6 @@ class XMPPDaemon extends Daemon } else if ($this->is_otr($pl['body'])) { $this->log(LOG_INFO, 'Ignoring OTR from ' . $from); return; - } else if ($this->is_direct($pl['body'])) { - $this->log(LOG_INFO, 'Got a direct message ' . $from); - - preg_match_all('/d[\ ]*([a-z0-9]{1,64})/', $pl['body'], $to); - - $to = preg_replace('/^d([\ ])*/', '', $to[0][0]); - $body = preg_replace('/d[\ ]*('. $to .')[\ ]*/', '', $pl['body']); - - $this->log(LOG_INFO, 'Direct message from '. $user->nickname . ' to ' . $to); - - $this->add_direct($user, $body, $to, $from); } else { $this->log(LOG_INFO, 'Posting a notice from ' . $user->nickname); @@ -284,15 +273,6 @@ class XMPPDaemon extends Daemon } } - function is_direct($txt) - { - if (strtolower(substr($txt, 0, 2))=='d ') { - return true; - } else { - return false; - } - } - function from_site($address, $msg) { $text = '['.common_config('site', 'name') . '] ' . $msg; |