diff options
author | Zach Copley <zach@controlyourself.ca> | 2009-06-23 14:29:46 -0700 |
---|---|---|
committer | Zach Copley <zach@controlyourself.ca> | 2009-06-23 14:29:46 -0700 |
commit | f04a54ed2f70686d67ed50da21bde61c55b07696 (patch) | |
tree | d4dbfac2a98e35b6f47696f787a3c2aa551f51ab /scripts | |
parent | 31325f0995bb61413b07f166d253b13fb27d085d (diff) | |
parent | 2d3e990ed47ee1c7130e1febabe7133884a85c80 (diff) |
Merge branch '0.8.x' of git@gitorious.org:laconica/dev into 0.8.x
* '0.8.x' of git@gitorious.org:laconica/dev: (61 commits)
Using default theme design values (it was previously set to identica
Updated default colour theme and IE6 colours for transparent values
chmod +x delete_status_network.sh
rm -Rf, not rmdir
script to delete a status network
chmod allsites.php
script to show all sites on a network
use different name for connection and database
use /etc/laconica/setup.cfg instead of local file
other base directories
On XHR notice post, calls NoticeAttachment to trigger thumbnail and
oembed and thumbnail don't need sequences
add innodb by default to status networks
pwgen not pwdgen
make pwgen command configurable
a little sql script to drop full-text index and use innodb for profile and notice
remove common_debug from newnotice
append uploads to content rather than showing them double
use a subclass for single notice items to show attachments
make file command configurable
...
Diffstat (limited to 'scripts')
29 files changed, 659 insertions, 453 deletions
diff --git a/scripts/allsites.php b/scripts/allsites.php new file mode 100755 index 000000000..d6768c278 --- /dev/null +++ b/scripts/allsites.php @@ -0,0 +1,40 @@ +#!/usr/bin/env php +<?php +/* + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2009, Control Yourself, 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/>. + */ + +# Abort if called from a web server + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$helptext = <<<ENDOFHELP +allsites.php - list all sites configured for multi-site use + +returns the nickname of each site configured for multi-site use + +ENDOFHELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +$sn = new Status_network(); + +if ($sn->find()) { + while ($sn->fetch()) { + print "$sn->nickname\n"; + } +}
\ No newline at end of file diff --git a/scripts/commandline.inc b/scripts/commandline.inc new file mode 100644 index 000000000..4a7757fb9 --- /dev/null +++ b/scripts/commandline.inc @@ -0,0 +1,138 @@ +<?php +/* + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2008, 2009, Control Yourself, 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/>. + */ + +// -*- mode: php -*- + +# Abort if called from a web server + +if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { + print "This script must be run from the command line\n"; + exit(); +} + +define('LACONICA', true); + +// Set various flags so we don't time out on long-running processes + +ini_set("max_execution_time", "0"); +ini_set("max_input_time", "0"); +set_time_limit(0); +mb_internal_encoding('UTF-8'); + +// Add extlib to our path so we can get Console_Getopt + +$_extra_path = array(INSTALLDIR.'/extlib/'); + +set_include_path(implode(PATH_SEPARATOR, $_extra_path) . PATH_SEPARATOR . get_include_path()); + +require_once 'Console/Getopt.php'; + +// Note: $shortoptions and $longoptions should be pre-defined! + +$_default_shortoptions = 'qvhc:s:p:'; + +$_default_longoptions = array('quiet', 'verbose', 'help', 'conf=', 'server=', 'path='); + +if (isset($shortoptions)) { + $shortoptions .= $_default_shortoptions; +} else { + $shortoptions = $_default_shortoptions; +} + +if (isset($longoptions)) { + $longoptions = array_merge($longoptions, $_default_longoptions); +} else { + $longoptions = $_default_longoptions; +} + +$parser = new Console_Getopt(); + +list($options, $args) = $parser->getopt($argv, $shortoptions, $longoptions); + +function show_help() +{ + global $helptext; + + $_default_help_text = <<<END_OF_DEFAULT +General options: + + -q --quiet Quiet (little output) + -v --verbose Verbose (lots of output) + -c --conf=<filename> Use <filename> as config file + -s --server=<name> Use <name> as server name + -p --path=<path> Use <path> as path name + -h --help Show this message and quit. + +END_OF_DEFAULT; + if (isset($helptext)) { + print $helptext; + } + print $_default_help_text; + exit(0); +} + +foreach ($options as $option) { + + switch ($option[0]) { + case '--server': + case 's': + $server = $option[1]; + break; + + case '--path': + case 'p': + $path = $option[1]; + break; + + case '--conf': + case 'c': + $conffile = $option[1]; + break; + + case '--help': + case 'h': + show_help(); + } +} + +require_once INSTALLDIR . '/lib/common.php'; + +set_error_handler('common_error_handler'); + +function have_option($str) +{ + global $options; + foreach ($options as $option) { + if ($option[0] == $str) { + return true; + } + } + return false; +} + +function get_option_value($str) +{ + global $options; + foreach ($options as $option) { + if ($option[0] == $str) { + return $option[1]; + } + } + return null; +}
\ No newline at end of file diff --git a/scripts/decache.php b/scripts/decache.php index b18eaa2cd..90e1ec63c 100644 --- a/scripts/decache.php +++ b/scripts/decache.php @@ -18,35 +18,26 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(1); -} - -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); +$helptext = <<<ENDOFHELP +USAGE: decache.php <table> <id> [<column>] +Clears the cache for the object in table <table> with id <id> +If <column> is specified, use that instead of 'id' +ENDOFHELP; -if ($argc < 3 || $argc > 4) { - print "USAGE: decache.php <table> <id> [<column>]\n"; - print "Clears the cache for the object in table <table> with id <id>.\n\n"; - print "If <column> is specified, use that instead of 'id'\n"; - exit(1); +require_once INSTALLDIR.'/scripts/commandline.inc'; + +if (count($args) < 2 || count($args) > 3) { + show_help(); } -$table = $argv[1]; -$id = $argv[2]; -if ($argc > 3) { - $column = $argv[3]; +$table = $args[0]; +$id = $args[1]; +if (count($args) > 2) { + $column = $args[2]; } else { - $colum = 'id'; + $column = 'id'; } $object = Memcached_DataObject::staticGet($table, $column, $id); diff --git a/scripts/delete_status_network.sh b/scripts/delete_status_network.sh new file mode 100755 index 000000000..32187382c --- /dev/null +++ b/scripts/delete_status_network.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +source /etc/laconica/setup.cfg + +export nickname=$1 + +export database=$nickname$DBBASE + +# Create the db + +mysqladmin -h $DBHOST -u $ADMIN --password=$ADMINPASS -f drop $database + +mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB << ENDOFCOMMANDS + +delete from status_network where nickname = '$nickname'; + +ENDOFCOMMANDS + +for top in $AVATARBASE $FILEBASE $BACKGROUNDBASE; do + rm -Rf $top/$nickname +done diff --git a/scripts/enjitqueuehandler.php b/scripts/enjitqueuehandler.php index c28bbe01d..05e1d9366 100755 --- a/scripts/enjitqueuehandler.php +++ b/scripts/enjitqueuehandler.php @@ -18,24 +18,27 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/mail.php'); -require_once(INSTALLDIR . '/lib/queuehandler.php'); +$shortoptions = 'i::'; +$longoptions = array('id::'); + +$helptext = <<<END_OF_ENJIT_HELP +Daemon script for watching new notices and posting to enjit. + + -i --id Identity (default none) + +END_OF_ENJIT_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +require_once INSTALLDIR . '/lib/mail.php'; +require_once INSTALLDIR . '/lib/queuehandler.php'; set_error_handler('common_error_handler'); class EnjitQueueHandler extends QueueHandler { - function transport() { return 'enjit'; @@ -60,7 +63,6 @@ class EnjitQueueHandler extends QueueHandler return "skipped"; } - # # Build an Atom message from the notice # @@ -93,8 +95,8 @@ class EnjitQueueHandler extends QueueHandler $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); - - curl_setopt($ch, CURLOPT_HEADER, 1); + + curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1) ; curl_setopt($ch, CURLOPT_POSTFIELDS, $data); @@ -103,7 +105,7 @@ class EnjitQueueHandler extends QueueHandler # # curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); # curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); - # curl_setopt($ch, CURLOPT_VERBOSE, 1); + # curl_setopt($ch, CURLOPT_VERBOSE, 1); $result = curl_exec($ch); @@ -115,13 +117,18 @@ class EnjitQueueHandler extends QueueHandler return $code; } - } -mb_internal_encoding('UTF-8'); - -$id = ($argc > 1) ? $argv[1] : null; +if (have_option('-i')) { + $id = get_option_value('-i'); +} else if (have_option('--id')) { + $id = get_option_value('--id'); +} else if (count($args) > 0) { + $id = $args[0]; +} else { + $id = null; +} $handler = new EnjitQueueHandler($id); diff --git a/scripts/facebookqueuehandler.php b/scripts/facebookqueuehandler.php index a505e8ecc..05a35577f 100755 --- a/scripts/facebookqueuehandler.php +++ b/scripts/facebookqueuehandler.php @@ -18,29 +18,30 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/facebookutil.php'); -require_once(INSTALLDIR . '/lib/queuehandler.php'); +$shortoptions = 'i::'; +$longoptions = array('id::'); + +$helptext = <<<END_OF_FACEBOOK_HELP +Daemon script for pushing new notices to Facebook. + + -i --id Identity (default none) + +END_OF_FACEBOOK_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; -set_error_handler('common_error_handler'); +require_once INSTALLDIR . '/lib/facebookutil.php'; +require_once INSTALLDIR . '/lib/queuehandler.php'; class FacebookQueueHandler extends QueueHandler { - function transport() { return 'facebook'; } - + function start() { $this->log(LOG_INFO, "INITIALIZE"); @@ -51,20 +52,22 @@ class FacebookQueueHandler extends QueueHandler { return facebookBroadcastNotice($notice); } - + function finish() { } } -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); - -mb_internal_encoding('UTF-8'); - -$id = ($argc > 1) ? $argv[1] : null; +if (have_option('i')) { + $id = get_option_value('i'); +} else if (have_option('--id')) { + $id = get_option_value('--id'); +} else if (count($args) > 0) { + $id = $args[0]; +} else { + $id = null; +} $handler = new FacebookQueueHandler($id); diff --git a/scripts/fixup_conversations.php b/scripts/fixup_conversations.php index d4a47cfee..2cfa422e6 100755 --- a/scripts/fixup_conversations.php +++ b/scripts/fixup_conversations.php @@ -18,16 +18,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); +require_once INSTALLDIR.'/scripts/commandline.inc'; common_log(LOG_INFO, 'Fixing up conversations.'); @@ -72,8 +65,3 @@ while ($notice->fetch()) { print ".\n"; } - -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); diff --git a/scripts/fixup_utf8.php b/scripts/fixup_utf8.php index 169376091..8c9a9127f 100644 --- a/scripts/fixup_utf8.php +++ b/scripts/fixup_utf8.php @@ -19,21 +19,18 @@ */ # Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(1); -} - -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); -require_once('DB.php'); +$helptext = <<<ENDOFHELP +fixup_utf8.php <maxdate> <maxid> <minid> + +Fixup records in a database that stored the data incorrectly (pre-0.7.4 for Laconica). + +ENDOFHELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; +require_once 'DB.php'; class UTF8FixerUpper { @@ -356,9 +353,9 @@ class UTF8FixerUpper } } -$max_date = ($argc > 1) ? $argv[1] : null; -$max_id = ($argc > 2) ? $argv[2] : null; -$min_id = ($argc > 3) ? $argv[3] : null; +$max_date = (count($args) > 0) ? $args[0] : null; +$max_id = (count($args) > 1) ? $args[1] : null; +$min_id = (count($args) > 2) ? $args[2] : null; $fixer = new UTF8FixerUpper(array('max_date' => $max_date, 'max_notice' => $max_id, diff --git a/scripts/getpiddir.php b/scripts/getpiddir.php index d29c95cb0..9927cc6d9 100755 --- a/scripts/getpiddir.php +++ b/scripts/getpiddir.php @@ -18,15 +18,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); +$helptext = <<<ENDOFHELP +getpiddir.php - print out the currently configured PID directory + +ENDOFHELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; -echo common_config('daemon','piddir'); +echo common_config('daemon', 'piddir'); diff --git a/scripts/getvaliddaemons.php b/scripts/getvaliddaemons.php index a45ff79ab..198ea8fb9 100755 --- a/scripts/getvaliddaemons.php +++ b/scripts/getvaliddaemons.php @@ -25,16 +25,14 @@ * daemon names. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); +$helptext = <<<ENDOFHELP +getvaliddaemons.php - print out the currently configured PID directory + +ENDOFHELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; if(common_config('xmpp','enabled')) { echo "xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php "; diff --git a/scripts/inbox_users.php b/scripts/inbox_users.php index 6d3656d2e..4883fea20 100755 --- a/scripts/inbox_users.php +++ b/scripts/inbox_users.php @@ -20,59 +20,55 @@ # Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); +$helptext = <<<ENDOFHELP +inbox_users.php <idfile> -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); +Update users to use inbox table. Listed in an ID file, default 'ids.txt'. -require_once(INSTALLDIR . '/lib/common.php'); +ENDOFHELP; -$id_file = ($argc > 1) ? $argv[1] : 'ids.txt'; +require_once INSTALLDIR.'/scripts/commandline.inc'; + +$id_file = (count($args) > 1) ? $args[0] : 'ids.txt'; common_log(LOG_INFO, 'Updating user inboxes.'); $ids = file($id_file); foreach ($ids as $id) { - + $user = User::staticGet('id', $id); if (!$user) { common_log(LOG_WARNING, 'No such user: ' . $id); continue; } - + if ($user->inboxed) { common_log(LOG_WARNING, 'Already inboxed: ' . $id); continue; } - + common_log(LOG_INFO, 'Updating inbox for user ' . $user->id); - + $user->query('BEGIN'); - + $old_inbox = new Notice_inbox(); $old_inbox->user_id = $user->id; - + $result = $old_inbox->delete(); - + if (is_null($result) || $result === false) { common_log_db_error($old_inbox, 'DELETE', __FILE__); continue; } $old_inbox->free(); - + $inbox = new Notice_inbox(); - + $result = $inbox->query('INSERT INTO notice_inbox (user_id, notice_id, created) ' . 'SELECT ' . $user->id . ', notice.id, notice.created ' . 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' . @@ -80,30 +76,30 @@ foreach ($ids as $id) { 'AND notice.created >= subscription.created ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' . 'FROM notice_inbox ' . - 'WHERE user_id = ' . $user->id . ' ' . + 'WHERE user_id = ' . $user->id . ' ' . 'AND notice_id = notice.id) ' . 'ORDER BY notice.created DESC ' . 'LIMIT 0, 1000'); - + if (is_null($result) || $result === false) { common_log_db_error($inbox, 'INSERT', __FILE__); continue; } - + $orig = clone($user); $user->inboxed = 1; $result = $user->update($orig); - + if (!$result) { common_log_db_error($user, 'UPDATE', __FILE__); continue; } - + $user->query('COMMIT'); - + $inbox->free(); unset($inbox); - + if ($cache) { $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id . ';last')); diff --git a/scripts/jabberqueuehandler.php b/scripts/jabberqueuehandler.php index 130be6e04..a44993236 100755 --- a/scripts/jabberqueuehandler.php +++ b/scripts/jabberqueuehandler.php @@ -18,24 +18,26 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/jabber.php'); -require_once(INSTALLDIR . '/lib/xmppqueuehandler.php'); +$shortoptions = 'r::'; +$longoptions = array('resource::'); + +$helptext = <<<END_OF_JABBER_HELP +Daemon script for pushing new notices to Jabber users. + + -r --resource Jabber Resource ID (default to config) -set_error_handler('common_error_handler'); +END_OF_JABBER_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +require_once INSTALLDIR . '/lib/common.php'; +require_once INSTALLDIR . '/lib/jabber.php'; +require_once INSTALLDIR . '/lib/xmppqueuehandler.php'; class JabberQueueHandler extends XmppQueueHandler { - var $conn = null; function transport() @@ -61,12 +63,15 @@ if (common_config('xmpp','enabled')==false) { exit(); } -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); - -$resource = ($argc > 1) ? $argv[1] : (common_config('xmpp','resource') . '-queuehandler'); +if (have_option('r')) { + $resource = get_option_value('r'); +} else if (have_option('--resource')) { + $resource = get_option_value('--resource'); +} else if (count($args) > 0) { + $resource = $args[0]; +} else { + $resource = null; +} $handler = new JabberQueueHandler($resource); diff --git a/scripts/maildaemon.php b/scripts/maildaemon.php index ccc1eef52..cfb11a36f 100755 --- a/scripts/maildaemon.php +++ b/scripts/maildaemon.php @@ -18,16 +18,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); +$helptext = <<<END_OF_HELP +Script for converting mail messages into notices. Takes message body +as STDIN. + +END_OF_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + require_once(INSTALLDIR . '/lib/mail.php'); require_once('Mail/mimeDecode.php'); @@ -36,7 +36,6 @@ require_once('Mail/mimeDecode.php'); class MailerDaemon { - function __construct() { } diff --git a/scripts/ombqueuehandler.php b/scripts/ombqueuehandler.php index 5fe7cf01d..1587192b6 100755 --- a/scripts/ombqueuehandler.php +++ b/scripts/ombqueuehandler.php @@ -18,29 +18,33 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/omb.php'); -require_once(INSTALLDIR . '/lib/queuehandler.php'); +$shortoptions = 'i::'; +$longoptions = array('id::'); + +$helptext = <<<END_OF_OMB_HELP +Daemon script for pushing new notices to OpenMicroBlogging subscribers. + + -i --id Identity (default none) + +END_OF_OMB_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +require_once INSTALLDIR . '/lib/omb.php'; +require_once INSTALLDIR . '/lib/queuehandler.php'; set_error_handler('common_error_handler'); class OmbQueueHandler extends QueueHandler { - + function transport() { return 'omb'; } - + function start() { $this->log(LOG_INFO, "INITIALIZE"); @@ -56,7 +60,7 @@ class OmbQueueHandler extends QueueHandler return omb_broadcast_remote_subscribers($notice); } } - + function finish() { } @@ -68,12 +72,15 @@ class OmbQueueHandler extends QueueHandler } } -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); - -$id = ($argc > 1) ? $argv[1] : null; +if (have_option('i')) { + $id = get_option_value('i'); +} else if (have_option('--id')) { + $id = get_option_value('--id'); +} else if (count($args) > 0) { + $id = $args[0]; +} else { + $id = null; +} $handler = new OmbQueueHandler($id); diff --git a/scripts/pingqueuehandler.php b/scripts/pingqueuehandler.php index f57752cd2..23678ea4b 100644 --- a/scripts/pingqueuehandler.php +++ b/scripts/pingqueuehandler.php @@ -18,20 +18,22 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/ping.php'); -require_once(INSTALLDIR . '/lib/queuehandler.php'); +$shortoptions = 'i::'; +$longoptions = array('id::'); + +$helptext = <<<END_OF_PING_HELP +Daemon script for pushing new notices to ping servers. + + -i --id Identity (default none) -set_error_handler('common_error_handler'); +END_OF_PING_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +require_once INSTALLDIR . '/lib/ping.php'; +require_once INSTALLDIR . '/lib/queuehandler.php'; class PingQueueHandler extends QueueHandler { @@ -52,12 +54,15 @@ class PingQueueHandler extends QueueHandler { } } -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); - -$id = ($argc > 1) ? $argv[1] : NULL; +if (have_option('i')) { + $id = get_option_value('i'); +} else if (have_option('--id')) { + $id = get_option_value('--id'); +} else if (count($args) > 0) { + $id = $args[0]; +} else { + $id = null; +} $handler = new PingQueueHandler($id); diff --git a/scripts/publicqueuehandler.php b/scripts/publicqueuehandler.php index c0452cbee..58ecc1745 100755 --- a/scripts/publicqueuehandler.php +++ b/scripts/publicqueuehandler.php @@ -18,29 +18,31 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/jabber.php'); -require_once(INSTALLDIR . '/lib/xmppqueuehandler.php'); +$shortoptions = 'r::'; +$longoptions = array('resource::'); + +$helptext = <<<END_OF_PUBLIC_HELP +Daemon script for pushing new notices to public XMPP subscribers. + + -r --resource Jabber Resource ID + +END_OF_PUBLIC_HELP; -set_error_handler('common_error_handler'); +require_once INSTALLDIR.'/scripts/commandline.inc'; + +require_once INSTALLDIR . '/lib/jabber.php'; +require_once INSTALLDIR . '/lib/xmppqueuehandler.php'; class PublicQueueHandler extends XmppQueueHandler { - + function transport() { return 'public'; } - + function handle_notice($notice) { try { @@ -59,12 +61,15 @@ if (common_config('xmpp','enabled')==false) { exit(); } -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); - -$resource = ($argc > 1) ? $argv[1] : (common_config('xmpp','resource') . '-public'); +if (have_option('r')) { + $resource = get_option_value('r'); +} else if (have_option('--resource')) { + $resource = get_option_value('--resource'); +} else if (count($args) > 0) { + $resource = $args[0]; +} else { + $resource = null; +} $handler = new PublicQueueHandler($resource); diff --git a/scripts/reportsnapshot.php b/scripts/reportsnapshot.php index e332d856c..c644b557f 100644 --- a/scripts/reportsnapshot.php +++ b/scripts/reportsnapshot.php @@ -18,20 +18,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(1); -} +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); +$helptext = <<<END_OF_SNAPSHOT_HELP +Batch script for sending snapshot information about this installation to devs. -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); +END_OF_SNAPSHOT_HELP; -require_once(INSTALLDIR . '/lib/common.php'); +require_once INSTALLDIR.'/scripts/commandline.inc'; Snapshot::check(); diff --git a/scripts/setpassword.php b/scripts/setpassword.php index c417f741a..b70689f03 100755 --- a/scripts/setpassword.php +++ b/scripts/setpassword.php @@ -18,30 +18,23 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(1); -} +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); +$helptext = <<<END_OF_PASSWORD_HELP +setpassword.php <username> <password> -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); +Sets the password of user with name <username> to <password> -require_once(INSTALLDIR . '/lib/common.php'); +END_OF_PASSWORD_HELP; -if ($argc != 3) { - print "USAGE: setpassword.php <username> <password>\n"; - print "Sets the password of user with name <username> to <password>\n"; - exit(1); +require_once INSTALLDIR.'/scripts/commandline.inc'; + +if (count($args) < 2) { + show_help(); } -$nickname = $argv[1]; -$password = $argv[2]; +$nickname = $args[0]; +$password = $args[1]; if (mb_strlen($password) < 6) { print "Password must be 6 characters or more.\n"; diff --git a/scripts/setup.cfg.sample b/scripts/setup.cfg.sample index 450b9c30a..8d03b06f5 100644 --- a/scripts/setup.cfg.sample +++ b/scripts/setup.cfg.sample @@ -1,12 +1,14 @@ # CONFIGURATION FILE for setup_status_network.sh -# Base database name; full name will include nickname - -export DBHOST=masterdb.example.net +export DBHOST=localhost +export DBHOSTNAME=masterdb.example.net export DBBASE=_example_net export USERBASE=_example_net export ADMIN=root export ADMINPASS=yourpassword export SITEDB=example_net_site export AVATARBASE=/var/www/avatar.example.net +export BACKGROUNDBASE=/var/www/background.example.net +export FILEBASE=/var/www/file.example.net +export PWDGEN="pwgen 20" diff --git a/scripts/setup_status_network.sh b/scripts/setup_status_network.sh index e1d14593f..17440640e 100755 --- a/scripts/setup_status_network.sh +++ b/scripts/setup_status_network.sh @@ -1,11 +1,11 @@ #!/bin/bash -source ./setup.cfg +source /etc/laconica/setup.cfg export nickname=$1 export sitename=$2 -export password=`pwgen 20` +export password=`$PWDGEN` export database=$nickname$DBBASE export username=$nickname$USERBASE @@ -13,7 +13,7 @@ export username=$nickname$USERBASE mysqladmin -h $DBHOST -u $ADMIN --password=$ADMINPASS create $database -for f in laconica.sql sms_carrier.sql foreign_services.sql notice_source.sql; do +for f in laconica.sql innodb.sql sms_carrier.sql foreign_services.sql notice_source.sql; do mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $database < ../db/$f; done @@ -22,9 +22,11 @@ mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB << ENDOFCOMMANDS GRANT INSERT,SELECT,UPDATE,DELETE ON $database.* TO '$username'@'localhost' IDENTIFIED BY '$password'; GRANT INSERT,SELECT,UPDATE,DELETE ON $database.* TO '$username'@'%' IDENTIFIED BY '$password'; INSERT INTO status_network (nickname, dbhost, dbuser, dbpass, dbname, sitename, created) -VALUES ('$nickname', '$DBHOST', '$username', '$password', '$database', '$sitename', now()); +VALUES ('$nickname', '$DBHOSTNAME', '$username', '$password', '$database', '$sitename', now()); ENDOFCOMMANDS -mkdir $AVATARBASE/$nickname -chmod a+w $AVATARBASE/$nickname +for top in $AVATARBASE $FILEBASE $BACKGROUNDBASE; do + mkdir $top/$nickname + chmod a+w $top/$nickname +done diff --git a/scripts/sitemap.php b/scripts/sitemap.php index 39eb859bb..88ca2ba7a 100755 --- a/scripts/sitemap.php +++ b/scripts/sitemap.php @@ -1,10 +1,37 @@ +#!/usr/bin/env php <?php +/* + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2008, 2009, Control Yourself, 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__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/util.php'); +$shortoptions = 'f:d:u:'; + +$helptext = <<<END_OF_SITEMAP_HELP +Script for creating sitemaps files per http://sitemaps.org/ + + -f <indexfile> Use <indexfile> as output file + -d <outputdir> Use <outputdir> for new sitemaps + -u <outputurl> Use <outputurl> as root for URLs + +END_OF_SITEMAP_HELP; + +require_once INSTALLDIR . '/scripts/commandline.inc'; $output_paths = parse_args(); @@ -13,11 +40,11 @@ notices_map(); user_map(); index_map(); -# ------------------------------------------------------------------------------ -# Main functions: get data out and turn them into sitemaps -# ------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ +// Main functions: get data out and turn them into sitemaps +// ------------------------------------------------------------------------------ -# Generate index sitemap of all other sitemaps. +// Generate index sitemap of all other sitemaps. function index_map() { global $output_paths; @@ -26,7 +53,7 @@ function index_map() foreach (glob("$output_dir*.xml") as $file_name) { - # Just the file name please. + // Just the file name please. $file_name = preg_replace("|$output_dir|", '', $file_name); $index_urls .= sitemap( @@ -40,7 +67,7 @@ function index_map() write_file($output_paths['index_file'], sitemapindex($index_urls)); } -# Generate sitemap of standard site elements. +// Generate sitemap of standard site elements. function standard_map() { global $output_paths; @@ -61,7 +88,7 @@ function standard_map() ) ); - $docs = array('about', 'faq', 'contact', 'im', 'openid', 'openmublog', + $docs = array('about', 'faq', 'contact', 'im', 'openid', 'openmublog', 'privacy', 'source', 'badge'); foreach($docs as $title) { @@ -79,7 +106,7 @@ function standard_map() write_file($urlset_path, urlset($standard_map_urls)); } -# Generate sitemaps of all notices. +// Generate sitemaps of all notices. function notices_map() { global $output_paths; @@ -93,14 +120,14 @@ function notices_map() while ($notices->fetch()) { - # Maximum 50,000 URLs per sitemap file. + // Maximum 50,000 URLs per sitemap file. if ($notice_count == 50000) { $notice_count = 0; $map_count++; } - # remote notices have an URL - + // remote notices have an URL + if (!$notices->url && $notices->uri) { $notice = array( 'url' => ($notices->uri) ? $notices->uri : common_local_url('shownotice', array('notice' => $notices->id)), @@ -114,11 +141,11 @@ function notices_map() } } - # Make full sitemaps from the lists and save them. + // Make full sitemaps from the lists and save them. array_to_map($notice_list, 'notice'); } -# Generate sitemaps of all users. +// Generate sitemaps of all users. function user_map() { global $output_paths; @@ -132,7 +159,7 @@ function user_map() while ($users->fetch()) { - # Maximum 50,000 URLs per sitemap file. + // Maximum 50,000 URLs per sitemap file. if ($user_count == 50000) { $user_count = 0; $map_count++; @@ -140,7 +167,7 @@ function user_map() $user_args = array('nickname' => $users->nickname); - # Define parameters for generating <url></url> elements. + // Define parameters for generating <url></url> elements. $user = array( 'url' => common_local_url('showstream', $user_args), 'changefreq' => 'daily', @@ -183,8 +210,8 @@ function user_map() 'priority' => '0.5', ); - # Construct a <url></url> element for each user facet and add it - # to our existing list of those. + // Construct a <url></url> element for each user facet and add it + // to our existing list of those. $user_list[$map_count] .= url($user); $user_rss_list[$map_count] .= url($user_rss); $all_list[$map_count] .= url($all); @@ -196,9 +223,9 @@ function user_map() $user_count++; } - # Make full sitemaps from the lists and save them. - # Possible factoring: put all the lists into a master array, thus allowing - # calling with single argument (i.e., array_to_map('user')). + // Make full sitemaps from the lists and save them. + // Possible factoring: put all the lists into a master array, thus allowing + // calling with single argument (i.e., array_to_map('user')). array_to_map($user_list, 'user'); array_to_map($user_rss_list, 'user_rss'); array_to_map($all_list, 'all'); @@ -208,14 +235,14 @@ function user_map() array_to_map($foaf_list, 'foaf'); } -# ------------------------------------------------------------------------------ -# XML generation functions -# ------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ +// XML generation functions +// ------------------------------------------------------------------------------ -# Generate a <url></url> element. +// Generate a <url></url> element. function url($url_args) { - $url = preg_replace('/&/', '&', $url_args['url']); # escape ampersands for XML + $url = preg_replace('/&/', '&', $url_args['url']); // escape ampersands for XML $lastmod = $url_args['lastmod']; $changefreq = $url_args['changefreq']; $priority = $url_args['priority']; @@ -246,7 +273,7 @@ function url($url_args) function sitemap($sitemap_args) { - $url = preg_replace('/&/', '&', $sitemap_args['url']); # escape ampersands for XML + $url = preg_replace('/&/', '&', $sitemap_args['url']); // escape ampersands for XML $lastmod = $sitemap_args['lastmod']; if (is_null($url)) { @@ -265,7 +292,7 @@ function sitemap($sitemap_args) return $sitemap_out; } -# Generate a <urlset></urlset> element. +// Generate a <urlset></urlset> element. function urlset($urlset_text) { $urlset = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . @@ -276,7 +303,7 @@ function urlset($urlset_text) return $urlset; } -# Generate a <urlset></urlset> element. +// Generate a <urlset></urlset> element. function sitemapindex($sitemapindex_text) { $sitemapindex = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . @@ -287,49 +314,31 @@ function sitemapindex($sitemapindex_text) return $sitemapindex; } -# Generate a sitemap from an array containing <url></url> elements and write it to a file. +// Generate a sitemap from an array containing <url></url> elements and write it to a file. function array_to_map($url_list, $filename_prefix) { global $output_paths; if ($url_list) { - # $map_urls is a long string containing concatenated <url></url> elements. + // $map_urls is a long string containing concatenated <url></url> elements. while (list($map_idx, $map_urls) = each($url_list)) { $urlset_path = $output_paths['output_dir'] . "$filename_prefix-$map_idx.xml"; - + write_file($urlset_path, urlset($map_urls)); } } } -# ------------------------------------------------------------------------------ -# Internal functions -# ------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------ +// Internal functions +// ------------------------------------------------------------------------------ -# Parse command line arguments. +// Parse command line arguments. function parse_args() { - $args = getopt('f:d:u:'); - - if (is_null($args[f]) && is_null($args[d]) && is_null($args[u])) { - error('Mandatory arguments: -f <index file path> -d <output directory path> -u <URL of sitemaps directory>'); - } - - if (is_null($args[f])) { - error('You must specify an index file name with the -f option.'); - } - - if (is_null($args[d])) { - error('You must specify a directory for the output file with the -d option.'); - } - - if (is_null($args[u])) { - error('You must specify a URL for the directory where the sitemaps will be kept with the -u option.'); - } - - $index_file = $args[f]; - $output_dir = $args[d]; - $output_url = $args[u]; + $index_file = get_option_value('f'); + $output_dir = get_option_value('d'); + $output_url = get_option_value('u'); if (file_exists($output_dir)) { if (is_writable($output_dir) === false) { @@ -348,7 +357,7 @@ function parse_args() return $paths; } -# Ensure paths end with a "/". +// Ensure paths end with a "/". function trailing_slash($path) { if (preg_match('/\/$/', $path) == 0) { @@ -358,7 +367,7 @@ function trailing_slash($path) return $path; } -# Write data to disk. +// Write data to disk. function write_file($path, $data) { if (is_null($path)) { @@ -376,7 +385,7 @@ function write_file($path, $data) } } -# Display an error message and exit. +// Display an error message and exit. function error ($error_msg) { if (is_null($error_msg)) { diff --git a/scripts/smsqueuehandler.php b/scripts/smsqueuehandler.php index 631719aa2..94b846d98 100755 --- a/scripts/smsqueuehandler.php +++ b/scripts/smsqueuehandler.php @@ -18,24 +18,25 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/mail.php'); -require_once(INSTALLDIR . '/lib/queuehandler.php'); +$shortoptions = 'i::'; +$longoptions = array('id::'); + +$helptext = <<<END_OF_SMS_HELP +Daemon script for pushing new notices to local subscribers using SMS. + + -i --id Identity (default none) + +END_OF_SMS_HELP; -set_error_handler('common_error_handler'); +require_once INSTALLDIR.'/scripts/commandline.inc'; + +require_once INSTALLDIR . '/lib/mail.php'; +require_once INSTALLDIR . '/lib/queuehandler.php'; class SmsQueueHandler extends QueueHandler { - function transport() { return 'sms'; @@ -51,18 +52,21 @@ class SmsQueueHandler extends QueueHandler { return mail_broadcast_notice_sms($notice); } - + function finish() { } } -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); - -$id = ($argc > 1) ? $argv[1] : null; +if (have_option('i')) { + $id = get_option_value('i'); +} else if (have_option('--id')) { + $id = get_option_value('--id'); +} else if (count($args) > 0) { + $id = $args[0]; +} else { + $id = null; +} $handler = new SmsQueueHandler($id); diff --git a/scripts/synctwitterfriends.php b/scripts/synctwitterfriends.php index 8a338f1b4..fe53ff44d 100755 --- a/scripts/synctwitterfriends.php +++ b/scripts/synctwitterfriends.php @@ -18,19 +18,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -// Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); // Uncomment this to get useful console output -//define('SCRIPT_DEBUG', true); -require_once(INSTALLDIR . '/lib/common.php'); +$helptext = <<<END_OF_TWITTER_HELP +Batch script for synching local friends with Twitter friends. + +END_OF_TWITTER_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; // Make a lockfile $lockfilename = lockFilename(); diff --git a/scripts/triminboxes.php b/scripts/triminboxes.php index 0d2eaeaf0..b2135d682 100644 --- a/scripts/triminboxes.php +++ b/scripts/triminboxes.php @@ -18,26 +18,37 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(1); -} +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); +$shortoptions = 'u::'; +$longoptions = array('start-user-id::'); -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); +$helptext = <<<END_OF_TRIM_HELP +Batch script for trimming notice inboxes to a reasonable size. + + -u <id> + --start-user-id=<id> User ID to start after. Default is all. -require_once(INSTALLDIR . '/lib/common.php'); +END_OF_TRIM_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +$id = null; + +if (have_option('u')) { + $id = get_option_value('u'); +} else if (have_option('--start-user-id')) { + $id = get_option_value('--start-user-id'); +} else { + $id = null; +} $user = new User(); -if ($argc > 1) { - $user->whereAdd('id > ' . $argv[1]); + +if (!empty($id)) { + $user->whereAdd('id > ' . $id); } + $cnt = $user->find(); while ($user->fetch()) { @@ -74,10 +85,10 @@ while ($user->fetch()) { $delay = 3.0 * ($finish - $start); print "Delaying $delay seconds..."; - + // Wait to let slaves catch up usleep($delay * 1000000); - + print "DONE.\n"; } diff --git a/scripts/twitterqueuehandler.php b/scripts/twitterqueuehandler.php index 6089b5c7d..00e735d98 100755 --- a/scripts/twitterqueuehandler.php +++ b/scripts/twitterqueuehandler.php @@ -18,29 +18,30 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/twitter.php'); -require_once(INSTALLDIR . '/lib/queuehandler.php'); +$shortoptions = 'i::'; +$longoptions = array('id::'); + +$helptext = <<<END_OF_ENJIT_HELP +Daemon script for pushing new notices to Twitter. + + -i --id Identity (default none) + +END_OF_ENJIT_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; -set_error_handler('common_error_handler'); +require_once INSTALLDIR . '/lib/twitter.php'; +require_once INSTALLDIR . '/lib/queuehandler.php'; class TwitterQueueHandler extends QueueHandler { - function transport() { return 'twitter'; } - + function start() { $this->log(LOG_INFO, "INITIALIZE"); @@ -51,20 +52,22 @@ class TwitterQueueHandler extends QueueHandler { return broadcast_twitter($notice); } - + function finish() { } } -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); - -mb_internal_encoding('UTF-8'); - -$id = ($argc > 1) ? $argv[1] : null; +if (have_option('i')) { + $id = get_option_value('i'); +} else if (have_option('--id')) { + $id = get_option_value('--id'); +} else if (count($args) > 0) { + $id = $args[0]; +} else { + $id = null; +} $handler = new TwitterQueueHandler($id); diff --git a/scripts/twitterstatusfetcher.php b/scripts/twitterstatusfetcher.php index 442435be1..5ffdda58f 100755 --- a/scripts/twitterstatusfetcher.php +++ b/scripts/twitterstatusfetcher.php @@ -18,22 +18,19 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -// Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); // Tune number of processes and how often to poll Twitter // XXX: Should these things be in config.php? define('MAXCHILDREN', 2); define('POLL_INTERVAL', 60); // in seconds -// Uncomment this to get useful logging -define('SCRIPT_DEBUG', true); +$helptext = <<<END_OF_TRIM_HELP +Batch script for retrieving Twitter messages from foreign service. + +END_OF_TRIM_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; require_once INSTALLDIR . '/lib/common.php'; require_once INSTALLDIR . '/lib/daemon.php'; @@ -626,10 +623,6 @@ class TwitterStatusFetcher extends Daemon } } -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); declare(ticks = 1); $fetcher = new TwitterStatusFetcher(); diff --git a/scripts/uncache_users.php b/scripts/uncache_users.php index e35ea81ea..b0b576eb4 100644 --- a/scripts/uncache_users.php +++ b/scripts/uncache_users.php @@ -17,32 +17,27 @@ * 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__) . '/..')); -# Abort if called from a web server - -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} +$helptext = <<<ENDOFHELP +uncache_users.php <idfile> -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); +Uncache users listed in an ID file, default 'ids.txt'. -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); +ENDOFHELP; -require_once(INSTALLDIR . '/lib/common.php'); +require_once INSTALLDIR.'/scripts/commandline.inc'; -$id_file = ($argc > 1) ? $argv[1] : 'ids.txt'; +$id_file = (count($args) > 1) ? $args[0] : 'ids.txt'; common_log(LOG_INFO, 'Updating user inboxes.'); $ids = file($id_file); +$memc = common_memcache(); + foreach ($ids as $id) { - + $user = User::staticGet('id', $id); if (!$user) { @@ -51,9 +46,7 @@ foreach ($ids as $id) { } $user->decache(); - - $memc = common_memcache(); - + $memc->delete(common_cache_key('user:notices_with_friends:'. $user->id)); $memc->delete(common_cache_key('user:notices_with_friends:'. $user->id . ';last')); } diff --git a/scripts/xmppconfirmhandler.php b/scripts/xmppconfirmhandler.php index 1fa361a36..883934fd6 100755 --- a/scripts/xmppconfirmhandler.php +++ b/scripts/xmppconfirmhandler.php @@ -18,33 +18,33 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/jabber.php'); -require_once(INSTALLDIR . '/lib/xmppqueuehandler.php'); +$shortoptions = 'r::'; +$longoptions = array('resource::'); + +$helptext = <<<END_OF_JABBER_HELP +Daemon script for pushing new confirmations to Jabber users. + + -r --resource Jabber Resource ID (default to config) + +END_OF_JABBER_HELP; -set_error_handler('common_error_handler'); +require_once INSTALLDIR.'/scripts/commandline.inc'; +require_once INSTALLDIR . '/lib/jabber.php'; +require_once INSTALLDIR . '/lib/xmppqueuehandler.php'; define('CLAIM_TIMEOUT', 1200); class XmppConfirmHandler extends XmppQueueHandler { - var $_id = 'confirm'; - + function class_name() { return 'XmppConfirmHandler'; } - + function run() { if (!$this->start()) { @@ -147,12 +147,15 @@ if (common_config('xmpp','enabled')==false) { exit(); } -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); - -$resource = ($argc > 1) ? $argv[1] : (common_config('xmpp', 'resource').'-confirm'); +if (have_option('r')) { + $resource = get_option_value('r'); +} else if (have_option('--resource')) { + $resource = get_option_value('--resource'); +} else if (count($args) > 0) { + $resource = $args[0]; +} else { + $resource = null; +} $handler = new XmppConfirmHandler($resource); diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index 528df5d2f..661631937 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -18,20 +18,23 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -# Abort if called from a web server -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/jabber.php'); -require_once(INSTALLDIR . '/lib/daemon.php'); +$shortoptions = 'r::'; +$longoptions = array('resource::'); + +$helptext = <<<END_OF_XMPP_HELP +Daemon script for receiving new notices from Jabber users. + + -r --resource Jabber Resource ID (default to config) -set_error_handler('common_error_handler'); +END_OF_XMPP_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +require_once INSTALLDIR . '/lib/common.php'; +require_once INSTALLDIR . '/lib/jabber.php'; +require_once INSTALLDIR . '/lib/daemon.php'; # This is kind of clunky; we create a class to call the global functions # in jabber.php, which create a new XMPP class. A more elegant (?) solution @@ -39,7 +42,6 @@ set_error_handler('common_error_handler'); class XMPPDaemon extends Daemon { - function XMPPDaemon($resource=null) { static $attrs = array('server', 'port', 'user', 'password', 'host'); @@ -321,12 +323,15 @@ if (common_config('xmpp','enabled')==false) { exit(); } -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); - -$resource = ($argc > 1) ? $argv[1] : (common_config('xmpp','resource') . '-listen'); +if (have_option('r')) { + $resource = get_option_value('r'); +} else if (have_option('--resource')) { + $resource = get_option_value('--resource'); +} else if (count($args) > 0) { + $resource = $args[0]; +} else { + $resource = null; +} $daemon = new XMPPDaemon($resource); |