summaryrefslogtreecommitdiff
path: root/_darcs/pristine/scripts
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-05-06 11:17:29 -0400
committerEvan Prodromou <evan@prodromou.name>2008-05-06 11:17:29 -0400
commit1d4f1f6bf6bd8313cbb51dbf61d675408171d1b8 (patch)
tree8c622e1c4c1cbfc78abe335c1a153e354f29eee4 /_darcs/pristine/scripts
parentd4fd1c505e14bdef4945e51d4f46a949d3abfb98 (diff)
add standard directories
Added some of the standard directories darcs-hash:20080506151729-84dde-563da8505e06a7302041c93ab157ced31165876c.gz
Diffstat (limited to '_darcs/pristine/scripts')
-rw-r--r--_darcs/pristine/scripts/cleardb.sh11
-rw-r--r--_darcs/pristine/scripts/enjitqueuehandler.php128
-rw-r--r--_darcs/pristine/scripts/fixup_hashtags.php46
-rw-r--r--_darcs/pristine/scripts/fixup_inboxes.php80
-rw-r--r--_darcs/pristine/scripts/fixup_notices_rendered.php50
-rw-r--r--_darcs/pristine/scripts/fixup_replies.php40
-rw-r--r--_darcs/pristine/scripts/getpiddir.php32
-rw-r--r--_darcs/pristine/scripts/inbox_users.php109
-rw-r--r--_darcs/pristine/scripts/jabberqueuehandler.php63
-rw-r--r--_darcs/pristine/scripts/maildaemon.php215
-rw-r--r--_darcs/pristine/scripts/ombqueuehandler.php74
-rw-r--r--_darcs/pristine/scripts/publicqueuehandler.php61
-rw-r--r--_darcs/pristine/scripts/rebuilddb.sh14
-rw-r--r--_darcs/pristine/scripts/setpassword.php68
-rw-r--r--_darcs/pristine/scripts/sitemap.php376
-rw-r--r--_darcs/pristine/scripts/smsqueuehandler.php64
-rw-r--r--_darcs/pristine/scripts/sphinx-cron.sh24
-rw-r--r--_darcs/pristine/scripts/sphinx-indexer.sh24
-rw-r--r--_darcs/pristine/scripts/sphinx.sh15
-rw-r--r--_darcs/pristine/scripts/startdaemons.sh31
-rw-r--r--_darcs/pristine/scripts/stopdaemons.sh43
-rw-r--r--_darcs/pristine/scripts/synctwitterfriends.php58
-rw-r--r--_darcs/pristine/scripts/update_pot.sh3
-rw-r--r--_darcs/pristine/scripts/update_translations.php66
-rw-r--r--_darcs/pristine/scripts/xmppconfirmhandler.php148
-rw-r--r--_darcs/pristine/scripts/xmppdaemon.php312
26 files changed, 2155 insertions, 0 deletions
diff --git a/_darcs/pristine/scripts/cleardb.sh b/_darcs/pristine/scripts/cleardb.sh
new file mode 100644
index 000000000..06690ed70
--- /dev/null
+++ b/_darcs/pristine/scripts/cleardb.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+export user=$1
+export password=$2
+export DB=$3
+export SCR=$4
+
+mysqladmin -u $user --password=$password -f drop $DB
+mysqladmin -u $user --password=$password create $DB
+mysql -u $user --password=$password $DB < $SCR
+
diff --git a/_darcs/pristine/scripts/enjitqueuehandler.php b/_darcs/pristine/scripts/enjitqueuehandler.php
new file mode 100644
index 000000000..8538ae09a
--- /dev/null
+++ b/_darcs/pristine/scripts/enjitqueuehandler.php
@@ -0,0 +1,128 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+set_error_handler('common_error_handler');
+
+class EnjitQueueHandler extends QueueHandler {
+
+ function transport() {
+ return 'enjit';
+ }
+
+ function start() {
+ $this->log(LOG_INFO, "Starting EnjitQueueHandler");
+ $this->log(LOG_INFO, "Broadcasting to ".common_config('enjit', 'apiurl'));
+ return true;
+ }
+
+ function handle_notice($notice) {
+
+ $profile = Profile::staticGet($notice->profile_id);
+
+ $this->log(LOG_INFO, "Posting Notice ".$notice->id." from ".$profile->nickname);
+
+ if ( ! $notice->is_local ) {
+ $this->log(LOG_INFO, "Skipping remote notice");
+ return "skipped";
+ }
+
+
+ #
+ # Build an Atom message from the notice
+ #
+ $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
+ $msg = $profile->nickname . ': ' . $notice->content;
+
+ $atom = "<entry xmlns='http://www.w3.org/2005/Atom'>\n";
+ $atom .= "<apisource>".common_config('enjit','source')."</apisource>\n";
+ $atom .= "<source>\n";
+ $atom .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n";
+ $atom .= "<link href='" . $profile->profileurl . "'/>\n";
+ $atom .= "<link rel='self' type='application/rss+xml' href='" . common_local_url('userrss', array('nickname' => $profile->nickname)) . "'/>\n";
+ $atom .= "<author><name>" . $profile->nickname . "</name></author>\n";
+ $atom .= "<icon>" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "</icon>\n";
+ $atom .= "</source>\n";
+ $atom .= "<title>" . htmlspecialchars($msg) . "</title>\n";
+ $atom .= "<summary>" . htmlspecialchars($msg) . "</summary>\n";
+ $atom .= "<link rel='alternate' href='" . $noticeurl . "' />\n";
+ $atom .= "<id>". $notice->uri . "</id>\n";
+ $atom .= "<published>".common_date_w3dtf($notice->created)."</published>\n";
+ $atom .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n";
+ $atom .= "</entry>\n";
+
+ $url = common_config('enjit', 'apiurl') . "/submit/". common_config('enjit','apikey');
+ $data = "msg=$atom";
+
+ #
+ # POST the message to $config['enjit']['apiurl']
+ #
+ $ch = curl_init();
+
+ curl_setopt($ch, CURLOPT_URL, $url);
+
+ curl_setopt($ch, CURLOPT_HEADER, 1);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1) ;
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+
+ # SSL and Debugging options
+ #
+ # curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+ # curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+ # curl_setopt($ch, CURLOPT_VERBOSE, 1);
+
+ $result = curl_exec($ch);
+
+ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE );
+
+ $this->log(LOG_INFO, "Response Code: $code");
+
+ curl_close($ch);
+
+ return $code;
+ }
+
+
+}
+
+mb_internal_encoding('UTF-8');
+
+$id = ($argc > 1) ? $argv[1] : NULL;
+
+$handler = new EnjitQueueHandler($id);
+
+if ($handler->start()) {
+ $handler->handle_queue();
+}
+
+$handler->finish();
diff --git a/_darcs/pristine/scripts/fixup_hashtags.php b/_darcs/pristine/scripts/fixup_hashtags.php
new file mode 100644
index 000000000..88f385798
--- /dev/null
+++ b/_darcs/pristine/scripts/fixup_hashtags.php
@@ -0,0 +1,46 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+common_log(LOG_INFO, 'Starting to do old notices.');
+
+$notice = new Notice();
+$cnt = $notice->find();
+
+while ($notice->fetch()) {
+ common_log(LOG_INFO, 'Getting tags for notice #' . $notice->id);
+ $notice->saveTags();
+ $original = clone($notice);
+ $notice->rendered = common_render_content($notice->content, $notice);
+ $result = $notice->update($original);
+ if (!$result) {
+ common_log_db_error($notice, 'UPDATE', __FILE__);
+ }
+}
diff --git a/_darcs/pristine/scripts/fixup_inboxes.php b/_darcs/pristine/scripts/fixup_inboxes.php
new file mode 100644
index 000000000..1715b0bc1
--- /dev/null
+++ b/_darcs/pristine/scripts/fixup_inboxes.php
@@ -0,0 +1,80 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
+ print "This script must be run from the command line\n";
+ exit();
+}
+
+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');
+
+$start_at = ($argc > 1) ? $argv[1] : NULL;
+
+common_log(LOG_INFO, 'Updating user inboxes.');
+
+$user = new User();
+
+if ($start_at) {
+ $user->whereAdd('id >= ' . $start_at);
+}
+
+$cnt = $user->find();
+$cache = common_memcache();
+
+while ($user->fetch()) {
+ common_log(LOG_INFO, 'Updating inbox for user ' . $user->id);
+ $user->query('BEGIN');
+ $inbox = new Notice_inbox();
+ $result = $inbox->query('INSERT LOW_PRIORITY 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 ' .
+ 'WHERE subscription.subscriber = ' . $user->id . ' ' .
+ 'AND notice.created >= subscription.created ' .
+ 'AND NOT EXISTS (SELECT user_id, notice_id ' .
+ 'FROM notice_inbox ' .
+ 'WHERE user_id = ' . $user->id . ' ' .
+ 'AND notice_id = notice.id)');
+ 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));
+ }
+}
diff --git a/_darcs/pristine/scripts/fixup_notices_rendered.php b/_darcs/pristine/scripts/fixup_notices_rendered.php
new file mode 100644
index 000000000..c6c925729
--- /dev/null
+++ b/_darcs/pristine/scripts/fixup_notices_rendered.php
@@ -0,0 +1,50 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+common_log(LOG_INFO, 'Starting to render old notices.');
+
+$start_at = ($argc > 1) ? $argv[1] : NULL;
+
+$notice = new Notice();
+if ($start_at) {
+ $notice->whereAdd('id >= ' . $start_at);
+}
+$cnt = $notice->find();
+
+while ($notice->fetch()) {
+ common_log(LOG_INFO, 'Pre-rendering notice #' . $notice->id);
+ $original = clone($notice);
+ $notice->rendered = common_render_content($notice->content, $notice);
+ $result = $notice->update($original);
+ if (!$result) {
+ common_log_db_error($notice, 'UPDATE', __FILE__);
+ }
+}
diff --git a/_darcs/pristine/scripts/fixup_replies.php b/_darcs/pristine/scripts/fixup_replies.php
new file mode 100644
index 000000000..6010e21d1
--- /dev/null
+++ b/_darcs/pristine/scripts/fixup_replies.php
@@ -0,0 +1,40 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+common_log(LOG_INFO, 'Starting to do old notices.');
+
+$notice = new Notice();
+$cnt = $notice->find();
+
+while ($notice->fetch()) {
+ common_log(LOG_INFO, 'Getting replies for notice #' . $notice->id);
+ common_save_replies($notice);
+}
diff --git a/_darcs/pristine/scripts/getpiddir.php b/_darcs/pristine/scripts/getpiddir.php
new file mode 100644
index 000000000..b4dda2254
--- /dev/null
+++ b/_darcs/pristine/scripts/getpiddir.php
@@ -0,0 +1,32 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+echo common_config('daemon','piddir');
diff --git a/_darcs/pristine/scripts/inbox_users.php b/_darcs/pristine/scripts/inbox_users.php
new file mode 100644
index 000000000..0543abb2a
--- /dev/null
+++ b/_darcs/pristine/scripts/inbox_users.php
@@ -0,0 +1,109 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+
+if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
+ print "This script must be run from the command line\n";
+ exit();
+}
+
+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');
+
+$id_file = ($argc > 1) ? $argv[1] : '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 ' .
+ 'WHERE subscription.subscriber = ' . $user->id . ' ' .
+ 'AND notice.created >= subscription.created ' .
+ 'AND now() - notice.created < ' . (7 * 24 * 3600) . ' ' .
+ 'AND NOT EXISTS (SELECT user_id, notice_id ' .
+ 'FROM notice_inbox ' .
+ 'WHERE user_id = ' . $user->id . ' ' .
+ 'AND notice_id = notice.id)');
+
+ 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));
+ }
+}
diff --git a/_darcs/pristine/scripts/jabberqueuehandler.php b/_darcs/pristine/scripts/jabberqueuehandler.php
new file mode 100644
index 000000000..59cdb94ad
--- /dev/null
+++ b/_darcs/pristine/scripts/jabberqueuehandler.php
@@ -0,0 +1,63 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+set_error_handler('common_error_handler');
+
+class JabberQueueHandler extends XmppQueueHandler {
+
+ var $conn = NULL;
+
+ function transport() {
+ return 'jabber';
+ }
+
+ function handle_notice($notice) {
+ try {
+ return jabber_broadcast_notice($notice);
+ } catch (XMPPHP_Exception $e) {
+ $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage());
+ exit(1);
+ }
+ }
+}
+
+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');
+
+$handler = new JabberQueueHandler($resource);
+
+$handler->runOnce(); \ No newline at end of file
diff --git a/_darcs/pristine/scripts/maildaemon.php b/_darcs/pristine/scripts/maildaemon.php
new file mode 100644
index 000000000..8b809f646
--- /dev/null
+++ b/_darcs/pristine/scripts/maildaemon.php
@@ -0,0 +1,215 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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('Mail/mimeDecode.php');
+
+# FIXME: we use both Mail_mimeDecode and mailparse
+# Need to move everything to mailparse
+
+class MailerDaemon {
+
+ function __construct() {
+ }
+
+ function handle_message($fname='php://stdin') {
+ list($from, $to, $msg) = $this->parse_message($fname);
+ if (!$from || !$to || !$msg) {
+ $this->error(NULL, _('Could not parse message.'));
+ }
+ common_log(LOG_INFO, "Mail from $from to $to: " .substr($msg, 0, 20));
+ $user = $this->user_from($from);
+ if (!$user) {
+ $this->error($from, _('Not a registered user.'));
+ return false;
+ }
+ if (!$this->user_match_to($user, $to)) {
+ $this->error($from, _('Sorry, that is not your incoming email address.'));
+ return false;
+ }
+ if (!$user->emailpost) {
+ $this->error($from, _('Sorry, no incoming email allowed.'));
+ return false;
+ }
+ $response = $this->handle_command($user, $from, $msg);
+ if ($response) {
+ return true;
+ }
+ $msg = $this->cleanup_msg($msg);
+ $this->add_notice($user, $msg);
+ }
+
+ function error($from, $msg) {
+ file_put_contents("php://stderr", $msg . "\n");
+ exit(1);
+ }
+
+ function user_from($from_hdr) {
+ $froms = mailparse_rfc822_parse_addresses($from_hdr);
+ if (!$froms) {
+ return NULL;
+ }
+ $from = $froms[0];
+ $addr = common_canonical_email($from['address']);
+ $user = User::staticGet('email', $addr);
+ if (!$user) {
+ $user = User::staticGet('smsemail', $addr);
+ }
+ return $user;
+ }
+
+ function user_match_to($user, $to_hdr) {
+ $incoming = $user->incomingemail;
+ $tos = mailparse_rfc822_parse_addresses($to_hdr);
+ foreach ($tos as $to) {
+ if (strcasecmp($incoming, $to['address']) == 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function handle_command($user, $from, $msg) {
+ $inter = new CommandInterpreter();
+ $cmd = $inter->handle_command($user, $msg);
+ if ($cmd) {
+ $cmd->execute(new MailChannel($from));
+ return true;
+ }
+ return false;
+ }
+
+ function respond($from, $to, $response) {
+
+ $headers['From'] = $to;
+ $headers['To'] = $from;
+ $headers['Subject'] = "Command complete";
+
+ return mail_send(array($from), $headers, $response);
+ }
+
+ function log($level, $msg) {
+ common_log($level, 'MailDaemon: '.$msg);
+ }
+
+ function add_notice($user, $msg) {
+ // should test
+ // $msg_shortened = common_shorten_links($msg);
+ // if (mb_strlen($msg_shortened) > 140) ERROR and STOP
+ $notice = Notice::saveNew($user->id, $msg, 'mail');
+ if (is_string($notice)) {
+ $this->log(LOG_ERR, $notice);
+ return;
+ }
+ common_broadcast_notice($notice);
+ $this->log(LOG_INFO,
+ 'Added notice ' . $notice->id . ' from user ' . $user->nickname);
+ }
+
+ function parse_message($fname) {
+ $contents = file_get_contents($fname);
+ $parsed = Mail_mimeDecode::decode(array('input' => $contents,
+ 'include_bodies' => true,
+ 'decode_headers' => true,
+ 'decode_bodies' => true));
+ if (!$parsed) {
+ return NULL;
+ }
+
+ $from = $parsed->headers['from'];
+
+ $to = $parsed->headers['to'];
+
+ $type = $parsed->ctype_primary . '/' . $parsed->ctype_secondary;
+
+ if ($parsed->ctype_primary == 'multipart') {
+ foreach ($parsed->parts as $part) {
+ if ($part->ctype_primary == 'text' &&
+ $part->ctype_secondary == 'plain') {
+ $msg = $part->body;
+ break;
+ }
+ }
+ } else if ($type == 'text/plain') {
+ $msg = $parsed->body;
+ } else {
+ $this->unsupported_type($type);
+ }
+
+ return array($from, $to, $msg);
+ }
+
+ function unsupported_type($type) {
+ $this->error(NULL, "Unsupported message type: " . $type);
+ }
+
+ function cleanup_msg($msg) {
+ $lines = explode("\n", $msg);
+
+ $output = '';
+
+ foreach ($lines as $line) {
+ // skip quotes
+ if (preg_match('/^\s*>.*$/', $line)) {
+ continue;
+ }
+ // skip start of quote
+ if (preg_match('/^\s*On.*wrote:\s*$/', $line)) {
+ continue;
+ }
+ // probably interesting to someone, not us
+ if (preg_match('/^\s*Sent via/', $line)) {
+ continue;
+ }
+ // skip everything after a sig
+ if (preg_match('/^\s*--+\s*$/', $line) ||
+ preg_match('/^\s*__+\s*$/', $line))
+ {
+ break;
+ }
+ // skip everything after Outlook quote
+ if (preg_match('/^\s*-+\s*Original Message\s*-+\s*$/', $line)) {
+ break;
+ }
+ // skip everything after weird forward
+ if (preg_match('/^\s*Begin\s+forward/', $line)) {
+ break;
+ }
+
+ $output .= ' ' . $line;
+ }
+
+ preg_replace('/\s+/', ' ', $output);
+ return trim($output);
+ }
+}
+
+$md = new MailerDaemon();
+$md->handle_message('php://stdin');
diff --git a/_darcs/pristine/scripts/ombqueuehandler.php b/_darcs/pristine/scripts/ombqueuehandler.php
new file mode 100644
index 000000000..1df816d14
--- /dev/null
+++ b/_darcs/pristine/scripts/ombqueuehandler.php
@@ -0,0 +1,74 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+set_error_handler('common_error_handler');
+
+class OmbQueueHandler extends QueueHandler {
+
+ function transport() {
+ return 'omb';
+ }
+
+ function start() {
+ $this->log(LOG_INFO, "INITIALIZE");
+ return true;
+ }
+
+ function handle_notice($notice) {
+ if ($this->is_remote($notice)) {
+ $this->log(LOG_DEBUG, 'Ignoring remote notice ' . $notice->id);
+ return true;
+ } else {
+ return omb_broadcast_remote_subscribers($notice);
+ }
+ }
+
+ function finish() {
+ }
+
+ function is_remote($notice) {
+ $user = User::staticGet($notice->profile_id);
+ return is_null($user);
+ }
+}
+
+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;
+
+$handler = new OmbQueueHandler($id);
+
+$handler->runOnce();
diff --git a/_darcs/pristine/scripts/publicqueuehandler.php b/_darcs/pristine/scripts/publicqueuehandler.php
new file mode 100644
index 000000000..b1ae1d581
--- /dev/null
+++ b/_darcs/pristine/scripts/publicqueuehandler.php
@@ -0,0 +1,61 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+set_error_handler('common_error_handler');
+
+class PublicQueueHandler extends XmppQueueHandler {
+
+ function transport() {
+ return 'public';
+ }
+
+ function handle_notice($notice) {
+ try {
+ return jabber_public_notice($notice);
+ } catch (XMPPHP_Exception $e) {
+ $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage());
+ die($e->getMessage());
+ }
+ }
+}
+
+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');
+
+$handler = new PublicQueueHandler($resource);
+
+$handler->runOnce();
diff --git a/_darcs/pristine/scripts/rebuilddb.sh b/_darcs/pristine/scripts/rebuilddb.sh
new file mode 100644
index 000000000..89bc6e252
--- /dev/null
+++ b/_darcs/pristine/scripts/rebuilddb.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+export user=$1
+export password=$2
+export DB=$3
+export SCR=$4
+
+mysqldump -u $user --password=$password -c -t --hex-blob $DB > /tmp/$DB.sql
+mysqladmin -u $user --password=$password -f drop $DB
+mysqladmin -u $user --password=$password create $DB
+mysql -u $user --password=$password $DB < $SCR
+mysql -u $user --password=$password $DB < /tmp/$DB.sql
+
+
diff --git a/_darcs/pristine/scripts/setpassword.php b/_darcs/pristine/scripts/setpassword.php
new file mode 100644
index 000000000..d694eed09
--- /dev/null
+++ b/_darcs/pristine/scripts/setpassword.php
@@ -0,0 +1,68 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+if ($argc != 3) {
+ print "USAGE: setpassword.php <username> <password>\n";
+ print "Sets the password of user with name <username> to <password>\n";
+ exit(1);
+}
+
+$nickname = $argv[1];
+$password = $argv[2];
+
+if (mb_strlen($password) < 6) {
+ print "Password must be 6 characters or more.\n";
+ exit(1);
+}
+
+$user = User::staticGet('nickname', $nickname);
+
+if (!$user) {
+ print "No such user '$nickname'.\n";
+ exit(1);
+}
+
+$original = clone($user);
+
+$user->password = common_munge_password($password, $user->id);
+
+if (!$user->update($original)) {
+ print "Error updating user '$nickname'.\n";
+ exit(1);
+} else {
+ print "Password for user '$nickname' updated.\n";
+ exit(0);
+}
diff --git a/_darcs/pristine/scripts/sitemap.php b/_darcs/pristine/scripts/sitemap.php
new file mode 100644
index 000000000..6b845beae
--- /dev/null
+++ b/_darcs/pristine/scripts/sitemap.php
@@ -0,0 +1,376 @@
+<?php
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+define('LACONICA', true);
+
+require_once(INSTALLDIR . '/lib/common.php');
+require_once(INSTALLDIR . '/lib/util.php');
+
+$output_paths = parse_args();
+
+standard_map();
+notices_map();
+user_map();
+index_map();
+
+# ------------------------------------------------------------------------------
+# Main functions: get data out and turn them into sitemaps
+# ------------------------------------------------------------------------------
+
+# Generate index sitemap of all other sitemaps.
+function index_map() {
+ global $output_paths;
+ $output_dir = $output_paths['output_dir'];
+ $output_url = $output_paths['output_url'];
+
+ foreach (glob("$output_dir*.xml") as $file_name) {
+
+ # Just the file name please.
+ $file_name = preg_replace("|$output_dir|", '', $file_name);
+
+ $index_urls .= sitemap(
+ array(
+ 'url' => $output_url . $file_name,
+ 'changefreq' => 'daily'
+ )
+ );
+ }
+
+ write_file($output_paths['index_file'], sitemapindex($index_urls));
+}
+
+# Generate sitemap of standard site elements.
+function standard_map() {
+ global $output_paths;
+
+ $standard_map_urls .= url(
+ array(
+ 'url' => common_local_url('public'),
+ 'changefreq' => 'daily',
+ 'priority' => '1',
+ )
+ );
+
+ $standard_map_urls .= url(
+ array(
+ 'url' => common_local_url('publicrss'),
+ 'changefreq' => 'daily',
+ 'priority' => '0.3',
+ )
+ );
+
+ $docs = array('about', 'faq', 'contact', 'im', 'openid', 'openmublog', 'privacy', 'source');
+
+ foreach($docs as $title) {
+ $standard_map_urls .= url(
+ array(
+ 'url' => common_local_url('doc', array('title' => $title)),
+ 'changefreq' => 'monthly',
+ 'priority' => '0.2',
+ )
+ );
+ }
+
+ $urlset_path = $output_paths['output_dir'] . 'standard.xml';
+
+ write_file($urlset_path, urlset($standard_map_urls));
+}
+
+# Generate sitemaps of all notices.
+function notices_map() {
+ global $output_paths;
+
+ $notices = DB_DataObject::factory('notice');
+
+ $notices->query('SELECT id, uri, url, modified FROM notice where is_local = 1');
+
+ $notice_count = 0;
+ $map_count = 1;
+
+ while ($notices->fetch()) {
+
+ # Maximum 50,000 URLs per sitemap file.
+ if ($notice_count == 50000) {
+ $notice_count = 0;
+ $map_count++;
+ }
+
+ # 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)),
+ 'lastmod' => common_date_w3dtf($notices->modified),
+ 'changefreq' => 'never',
+ 'priority' => '1',
+ );
+
+ $notice_list[$map_count] .= url($notice);
+ $notice_count++;
+ }
+ }
+
+ # Make full sitemaps from the lists and save them.
+ array_to_map($notice_list, 'notice');
+}
+
+# Generate sitemaps of all users.
+function user_map() {
+ global $output_paths;
+
+ $users = DB_DataObject::factory('user');
+
+ $users->query('SELECT id, nickname FROM user');
+
+ $user_count = 0;
+ $map_count = 1;
+
+ while ($users->fetch()) {
+
+ # Maximum 50,000 URLs per sitemap file.
+ if ($user_count == 50000) {
+ $user_count = 0;
+ $map_count++;
+ }
+
+ $user_args = array('nickname' => $users->nickname);
+
+ # Define parameters for generating <url></url> elements.
+ $user = array(
+ 'url' => common_local_url('showstream', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '1',
+ );
+
+ $user_rss = array(
+ 'url' => common_local_url('userrss', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '0.3',
+ );
+
+ $all = array(
+ 'url' => common_local_url('all', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '1',
+ );
+
+ $all_rss = array(
+ 'url' => common_local_url('allrss', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '0.3',
+ );
+
+ $replies = array(
+ 'url' => common_local_url('replies', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '1',
+ );
+
+ $replies_rss = array(
+ 'url' => common_local_url('repliesrss', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '0.3',
+ );
+
+ $foaf = array(
+ 'url' => common_local_url('foaf', $user_args),
+ 'changefreq' => 'weekly',
+ 'priority' => '0.5',
+ );
+
+ # 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);
+ $all_rss_list[$map_count] .= url($all_rss);
+ $replies_list[$map_count] .= url($replies);
+ $replies_rss_list[$map_count] .= url($replies_rss);
+ $foaf_list[$map_count] .= url($foaf);
+
+ $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')).
+ array_to_map($user_list, 'user');
+ array_to_map($user_rss_list, 'user_rss');
+ array_to_map($all_list, 'all');
+ array_to_map($all_rss_list, 'all_rss');
+ array_to_map($replies_list, 'replies');
+ array_to_map($replies_rss_list, 'replies_rss');
+ array_to_map($foaf_list, 'foaf');
+}
+
+# ------------------------------------------------------------------------------
+# XML generation functions
+# ------------------------------------------------------------------------------
+
+# Generate a <url></url> element.
+function url($url_args) {
+ $url = preg_replace('/&/', '&amp;', $url_args['url']); # escape ampersands for XML
+ $lastmod = $url_args['lastmod'];
+ $changefreq = $url_args['changefreq'];
+ $priority = $url_args['priority'];
+
+ if (is_null($url)) {
+ error("url() arguments require 'url' value.");
+ }
+
+ $url_out = "\t<url>\n";
+ $url_out .= "\t\t<loc>$url</loc>\n";
+
+ if ($changefreq) {
+ $url_out .= "\t\t<changefreq>$changefreq</changefreq>\n";
+ }
+
+ if ($lastmod) {
+ $url_out .= "\t\t<lastmod>$lastmod</lastmod>\n";
+ }
+
+ if ($priority) {
+ $url_out .= "\t\t<priority>$priority</priority>\n";
+ }
+
+ $url_out .= "\t</url>\n";
+
+ return $url_out;
+}
+
+function sitemap($sitemap_args) {
+ $url = preg_replace('/&/', '&amp;', $sitemap_args['url']); # escape ampersands for XML
+ $lastmod = $sitemap_args['lastmod'];
+
+ if (is_null($url)) {
+ error("url() arguments require 'url' value.");
+ }
+
+ $sitemap_out = "\t<sitemap>\n";
+ $sitemap_out .= "\t\t<loc>$url</loc>\n";
+
+ if ($lastmod) {
+ $sitemap_out .= "\t\t<lastmod>$lastmod</lastmod>\n";
+ }
+
+ $sitemap_out .= "\t</sitemap>\n";
+
+ return $sitemap_out;
+}
+
+# Generate a <urlset></urlset> element.
+function urlset($urlset_text) {
+ $urlset = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
+ '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" .
+ $urlset_text .
+ '</urlset>';
+
+ return $urlset;
+}
+
+# Generate a <urlset></urlset> element.
+function sitemapindex($sitemapindex_text) {
+ $sitemapindex = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
+ '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" .
+ $sitemapindex_text .
+ '</sitemapindex>';
+
+ return $sitemapindex;
+}
+
+# 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.
+ 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
+# ------------------------------------------------------------------------------
+
+# 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];
+
+ if (file_exists($output_dir)) {
+ if (is_writable($output_dir) === FALSE) {
+ error("$output_dir is not writable.");
+ }
+ } else {
+ error("output directory $output_dir does not exist.");
+ }
+
+ $paths = array(
+ 'index_file' => $index_file,
+ 'output_dir' => trailing_slash($output_dir),
+ 'output_url' => trailing_slash($output_url),
+ );
+
+ return $paths;
+}
+
+# Ensure paths end with a "/".
+function trailing_slash($path) {
+ if (preg_match('/\/$/', $path) == 0) {
+ $path .= '/';
+ }
+
+ return $path;
+}
+
+# Write data to disk.
+function write_file($path, $data) {
+ if (is_null($path)) {
+ error('No path specified for writing to.');
+ } elseif (is_null($data)) {
+ error('No data specified for writing.');
+ }
+
+ if (($fh_out = fopen($path,'w')) === FALSE) {
+ error("couldn't open $path for writing.");
+ }
+
+ if (fwrite($fh_out, $data) === FALSE) {
+ error("couldn't write to $path.");
+ }
+}
+
+# Display an error message and exit.
+function error ($error_msg) {
+ if (is_null($error_msg)) {
+ $error_msg = 'error() was called without any explanation!';
+ }
+
+ echo "Error: $error_msg\n";
+ exit(1);
+}
+
+?> \ No newline at end of file
diff --git a/_darcs/pristine/scripts/smsqueuehandler.php b/_darcs/pristine/scripts/smsqueuehandler.php
new file mode 100644
index 000000000..8f0d02d9b
--- /dev/null
+++ b/_darcs/pristine/scripts/smsqueuehandler.php
@@ -0,0 +1,64 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+set_error_handler('common_error_handler');
+
+class SmsQueueHandler extends QueueHandler {
+
+ function transport() {
+ return 'sms';
+ }
+
+ function start() {
+ $this->log(LOG_INFO, "INITIALIZE");
+ return true;
+ }
+
+ function handle_notice($notice) {
+ 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;
+
+$handler = new SmsQueueHandler($id);
+
+$handler->runOnce();
diff --git a/_darcs/pristine/scripts/sphinx-cron.sh b/_darcs/pristine/scripts/sphinx-cron.sh
new file mode 100644
index 000000000..9759adbd0
--- /dev/null
+++ b/_darcs/pristine/scripts/sphinx-cron.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# Laconica - a distributed open-source microblogging tool
+
+# Copyright (C) 2008, Controlez-Vous, 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/>.
+
+# This program tries to start the daemons for Laconica.
+# Note that the 'maildaemon' needs to run as a mail filter.
+
+/usr/local/bin/indexer --config /usr/local/etc/sphinx.conf --all --rotate
+
diff --git a/_darcs/pristine/scripts/sphinx-indexer.sh b/_darcs/pristine/scripts/sphinx-indexer.sh
new file mode 100644
index 000000000..3311b2ed1
--- /dev/null
+++ b/_darcs/pristine/scripts/sphinx-indexer.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# Laconica - a distributed open-source microblogging tool
+
+# Copyright (C) 2008, Controlez-Vous, 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/>.
+
+# This program tries to start the daemons for Laconica.
+# Note that the 'maildaemon' needs to run as a mail filter.
+
+/usr/local/bin/indexer --config /usr/local/etc/sphinx.conf --all
+
diff --git a/_darcs/pristine/scripts/sphinx.sh b/_darcs/pristine/scripts/sphinx.sh
new file mode 100644
index 000000000..b8edeb302
--- /dev/null
+++ b/_darcs/pristine/scripts/sphinx.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+if [[ $1 = "start" ]]
+then
+ echo "Stopping any running daemons..."
+ /usr/local/bin/searchd --config /usr/local/etc/sphinx.conf --stop 2> /dev/null
+ echo "Starting sphinx search daemon..."
+ /usr/local/bin/searchd --config /usr/local/etc/sphinx.conf 2> /dev/null
+fi
+
+if [[ $1 = "stop" ]]
+then
+ echo "Stopping sphinx search daemon..."
+ /usr/local/bin/searchd --config /usr/local/etc/sphinx.conf --stop 2> /dev/null
+fi
diff --git a/_darcs/pristine/scripts/startdaemons.sh b/_darcs/pristine/scripts/startdaemons.sh
new file mode 100644
index 000000000..685bd938f
--- /dev/null
+++ b/_darcs/pristine/scripts/startdaemons.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+# Laconica - a distributed open-source microblogging tool
+
+# Copyright (C) 2008, Controlez-Vous, 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/>.
+
+# This program tries to start the daemons for Laconica.
+# Note that the 'maildaemon' needs to run as a mail filter.
+
+DIR=`dirname $0`
+
+for f in xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php \
+ xmppconfirmhandler.php smsqueuehandler.php ombqueuehandler.php; do
+
+ echo -n "Starting $f...";
+ php $DIR/$f
+ echo "DONE."
+done
diff --git a/_darcs/pristine/scripts/stopdaemons.sh b/_darcs/pristine/scripts/stopdaemons.sh
new file mode 100644
index 000000000..08e1d4714
--- /dev/null
+++ b/_darcs/pristine/scripts/stopdaemons.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+# Laconica - a distributed open-source microblogging tool
+
+# Copyright (C) 2008, Controlez-Vous, 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/>.
+
+# This program tries to stop the daemons for Laconica that were
+# previously started by startdaemons.sh
+
+SDIR=`dirname $0`
+DIR=`php $SDIR/getpiddir.php`
+
+for f in jabberhandler ombhandler publichandler smshandler \
+ xmppconfirmhandler xmppdaemon; do
+
+ FILES="$DIR/$f.*.pid"
+ for ff in "$FILES" ; do
+
+ echo -n "Stopping $f..."
+ PID=`cat $ff`
+ kill -3 $PID
+ if kill -9 $PID ; then
+ echo "DONE."
+ else
+ echo "FAILED."
+ fi
+ rm -f $ff
+ done
+done
+
diff --git a/_darcs/pristine/scripts/synctwitterfriends.php b/_darcs/pristine/scripts/synctwitterfriends.php
new file mode 100644
index 000000000..070eb9bbb
--- /dev/null
+++ b/_darcs/pristine/scripts/synctwitterfriends.php
@@ -0,0 +1,58 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+$flink = new Foreign_link();
+$flink->service = 1; // Twitter
+$flink->find();
+
+while ($flink->fetch()) {
+
+ if (($flink->friendsync & FOREIGN_FRIEND_RECV) == FOREIGN_FRIEND_RECV) {
+
+ $user = User::staticGet($flink->user_id);
+
+ print "Updating Twitter friends for user $user->nickname ($user->id)\n";
+
+ $fuser = $flink->getForeignUser();
+
+ $result = save_twitter_friends($user, $fuser->id, $fuser->nickname, $flink->credentials);
+
+ if ($result == false) {
+ print "Problems updating Twitter friends! Check the log.\n";
+ exit(1);
+ }
+ }
+
+}
+
+exit(0);
+
+
diff --git a/_darcs/pristine/scripts/update_pot.sh b/_darcs/pristine/scripts/update_pot.sh
new file mode 100644
index 000000000..f3526d514
--- /dev/null
+++ b/_darcs/pristine/scripts/update_pot.sh
@@ -0,0 +1,3 @@
+cd `dirname $0`
+cd ..
+xgettext --from-code=UTF-8 --default-domain=laconica --output=locale/laconica.pot --language=PHP --join-existing actions/*.php classes/*.php lib/*.php scripts/*.php
diff --git a/_darcs/pristine/scripts/update_translations.php b/_darcs/pristine/scripts/update_translations.php
new file mode 100644
index 000000000..3eb7b3401
--- /dev/null
+++ b/_darcs/pristine/scripts/update_translations.php
@@ -0,0 +1,66 @@
+<?php
+
+set_time_limit(60);
+chdir(dirname(__FILE__) . '/..');
+
+/* Languages to pull */
+$languages = array(
+ 'da_DK' => 'http://laconi.ca/translate/download.php?file_id=23',
+ 'nl_NL' => 'http://laconi.ca/translate/download.php?file_id=39',
+ 'en_NZ' => 'http://laconi.ca/translate/download.php?file_id=15',
+ 'eo' => 'http://laconi.ca/translate/download.php?file_id=10',
+ 'fr_FR' => 'http://laconi.ca/translate/download.php?file_id=19',
+ 'de_DE' => 'http://laconi.ca/translate/download.php?file_id=18',
+ 'it_IT' => 'http://laconi.ca/translate/download.php?file_id=21',
+ 'ko' => 'http://laconi.ca/translate/download.php?file_id=33',
+ 'no_NB' => 'http://laconi.ca/translate/download.php?file_id=31',
+ 'pt' => 'http://laconi.ca/translate/download.php?file_id=8',
+ 'pt_BR' => 'http://laconi.ca/translate/download.php?file_id=72',
+ 'ru_RU' => 'http://laconi.ca/translate/download.php?file_id=26',
+ 'es' => 'http://laconi.ca/translate/download.php?file_id=9',
+ 'tr_TR' => 'http://laconi.ca/translate/download.php?file_id=37',
+ 'uk_UA' => 'http://laconi.ca/translate/download.php?file_id=44',
+ 'he_IL' => 'http://laconi.ca/translate/download.php?file_id=71',
+ 'mk_MK' => 'http://laconi.ca/translate/download.php?file_id=67',
+ 'ja_JP' => 'http://laconi.ca/translate/download.php?file_id=43',
+ 'cs_CZ' => 'http://laconi.ca/translate/download.php?file_id=63',
+ 'ca_ES' => 'http://laconi.ca/translate/download.php?file_id=49',
+ 'pl_PL' => 'http://laconi.ca/translate/download.php?file_id=51',
+ 'sv_SE' => 'http://laconi.ca/translate/download.php?file_id=55'
+);
+
+/* Update the languages */
+foreach ($languages as $code => $file) {
+
+ $lcdir='locale/'.$code;
+ $msgdir=$lcdir.'/LC_MESSAGES';
+ $pofile=$msgdir.'/laconica.po';
+ $mofile=$msgdir.'/laconica.mo';
+
+ /* Check for an existing */
+ if (!is_dir($msgdir)) {
+ mkdir($lcdir);
+ mkdir($msgdir);
+ $existingSHA1 = '';
+ } else {
+ $existingSHA1 = file_exists($pofile) ? sha1_file($pofile) : '';
+ }
+
+ /* Get the remote one */
+ $newFile = file_get_contents($file);
+
+ // Update if the local .po file is different to the one downloaded, or
+ // if the .mo file is not present.
+ if(sha1($newFile)!=$existingSHA1 || !file_exists($mofile)) {
+ echo "Updating ".$code."\n";
+ file_put_contents($pofile, $newFile);
+ $prevdir = getcwd();
+ chdir($msgdir);
+ system('msgmerge -U laconica.po ../../laconica.pot');
+ system('msgfmt -f -o laconica.mo laconica.po');
+ chdir($prevdir);
+ } else {
+ echo "Unchanged - ".$code."\n";
+ }
+}
+echo "Finished\n";
diff --git a/_darcs/pristine/scripts/xmppconfirmhandler.php b/_darcs/pristine/scripts/xmppconfirmhandler.php
new file mode 100644
index 000000000..8961b0b6e
--- /dev/null
+++ b/_darcs/pristine/scripts/xmppconfirmhandler.php
@@ -0,0 +1,148 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+set_error_handler('common_error_handler');
+
+define('CLAIM_TIMEOUT', 1200);
+
+class XmppConfirmHandler extends XmppQueueHandler {
+
+ var $_id = 'confirm';
+
+ function class_name() {
+ return 'XmppConfirmHandler';
+ }
+
+ function run() {
+ if (!$this->start()) {
+ return false;
+ }
+ $this->log(LOG_INFO, 'checking for queued confirmations');
+ do {
+ $confirm = $this->next_confirm();
+ if ($confirm) {
+ $this->log(LOG_INFO, 'Sending confirmation for ' . $confirm->address);
+ $user = User::staticGet($confirm->user_id);
+ if (!$user) {
+ $this->log(LOG_WARNING, 'Confirmation for unknown user ' . $confirm->user_id);
+ continue;
+ }
+ $success = jabber_confirm_address($confirm->code,
+ $user->nickname,
+ $confirm->address);
+ if (!$success) {
+ $this->log(LOG_ERR, 'Confirmation failed for ' . $confirm->address);
+ # Just let the claim age out; hopefully things work then
+ continue;
+ } else {
+ $this->log(LOG_INFO, 'Confirmation sent for ' . $confirm->address);
+ # Mark confirmation sent; need a dupe so we don't have the WHERE clause
+ $dupe = Confirm_address::staticGet('code', $confirm->code);
+ if (!$dupe) {
+ common_log(LOG_WARNING, 'Could not refetch confirm', __FILE__);
+ continue;
+ }
+ $orig = clone($dupe);
+ $dupe->sent = $dupe->claimed;
+ $result = $dupe->update($orig);
+ if (!$result) {
+ common_log_db_error($dupe, 'UPDATE', __FILE__);
+ # Just let the claim age out; hopefully things work then
+ continue;
+ }
+ $dupe->free();
+ unset($dupe);
+ }
+ $user->free();
+ unset($user);
+ $confirm->free();
+ unset($confirm);
+ $this->idle(0);
+ } else {
+# $this->clear_old_confirm_claims();
+ $this->idle(10);
+ }
+ } while (true);
+ if (!$this->finish()) {
+ return false;
+ }
+ return true;
+ }
+
+ function next_confirm() {
+ $confirm = new Confirm_address();
+ $confirm->whereAdd('claimed IS NULL');
+ $confirm->whereAdd('sent IS NULL');
+ # XXX: eventually we could do other confirmations in the queue, too
+ $confirm->address_type = 'jabber';
+ $confirm->orderBy('modified DESC');
+ $confirm->limit(1);
+ if ($confirm->find(TRUE)) {
+ $this->log(LOG_INFO, 'Claiming confirmation for ' . $confirm->address);
+ # working around some weird DB_DataObject behaviour
+ $confirm->whereAdd(''); # clears where stuff
+ $original = clone($confirm);
+ $confirm->claimed = common_sql_now();
+ $result = $confirm->update($original);
+ if ($result) {
+ $this->log(LOG_INFO, 'Succeeded in claim! '. $result);
+ return $confirm;
+ } else {
+ $this->log(LOG_INFO, 'Failed in claim!');
+ return false;
+ }
+ }
+ return NULL;
+ }
+
+ function clear_old_confirm_claims() {
+ $confirm = new Confirm();
+ $confirm->claimed = NULL;
+ $confirm->whereAdd('now() - claimed > '.CLAIM_TIMEOUT);
+ $confirm->update(DB_DATAOBJECT_WHEREADD_ONLY);
+ $confirm->free();
+ unset($confirm);
+ }
+}
+
+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');
+
+$handler = new XmppConfirmHandler($resource);
+
+$handler->runOnce();
+
diff --git a/_darcs/pristine/scripts/xmppdaemon.php b/_darcs/pristine/scripts/xmppdaemon.php
new file mode 100644
index 000000000..9a60970a6
--- /dev/null
+++ b/_darcs/pristine/scripts/xmppdaemon.php
@@ -0,0 +1,312 @@
+#!/usr/bin/env php
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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
+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');
+
+set_error_handler('common_error_handler');
+
+# 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
+# might be to use make this a subclass of XMPP.
+
+class XMPPDaemon extends Daemon {
+
+ function XMPPDaemon($resource=NULL) {
+ static $attrs = array('server', 'port', 'user', 'password', 'host');
+
+ foreach ($attrs as $attr)
+ {
+ $this->$attr = common_config('xmpp', $attr);
+ }
+
+ if ($resource) {
+ $this->resource = $resource;
+ } else {
+ $this->resource = common_config('xmpp', 'resource') . 'daemon';
+ }
+
+ $this->log(LOG_INFO, "INITIALIZE XMPPDaemon {$this->user}@{$this->server}/{$this->resource}");
+ }
+
+ function connect() {
+
+ $connect_to = ($this->host) ? $this->host : $this->server;
+
+ $this->log(LOG_INFO, "Connecting to $connect_to on port $this->port");
+
+ $this->conn = jabber_connect($this->resource);
+
+ if (!$this->conn) {
+ return false;
+ }
+
+ $this->conn->setReconnectTimeout(600);
+
+ jabber_send_presence("Send me a message to post a notice", 'available',
+ NULL, 'available', 100);
+ return !$this->conn->isDisconnected();
+ }
+
+ function name() {
+ return strtolower('xmppdaemon.'.$this->resource);
+ }
+
+ function run() {
+ if ($this->connect()) {
+
+ $this->conn->addEventHandler('message', 'handle_message', $this);
+ $this->conn->addEventHandler('presence', 'handle_presence', $this);
+ $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this);
+
+ $this->conn->process();
+ }
+ }
+
+ function handle_reconnect(&$pl) {
+ $this->conn->processUntil('session_start');
+ $this->conn->presence('Send me a message to post a notice', 'available', NULL, 'available', 100);
+ }
+
+ function get_user($from) {
+ $user = User::staticGet('jabber', jabber_normalize_jid($from));
+ return $user;
+ }
+
+ function handle_message(&$pl) {
+ if ($pl['type'] != 'chat') {
+ return;
+ }
+ if (mb_strlen($pl['body']) == 0) {
+ return;
+ }
+
+ $from = jabber_normalize_jid($pl['from']);
+
+ # Forwarded from another daemon (probably a broadcaster) for
+ # us to handle
+
+ if ($this->is_self($from)) {
+ $from = $this->get_ofrom($pl);
+ if (is_null($from) || $this->is_self($from)) {
+ return;
+ }
+ }
+
+ $user = $this->get_user($from);
+
+ if (!$user) {
+ $this->from_site($from, 'Unknown user; go to ' .
+ common_local_url('imsettings') .
+ ' to add your address to your account');
+ $this->log(LOG_WARNING, 'Message from unknown user ' . $from);
+ return;
+ }
+ if ($this->handle_command($user, $pl['body'])) {
+ return;
+ } else if ($this->is_autoreply($pl['body'])) {
+ $this->log(LOG_INFO, 'Ignoring auto reply from ' . $from);
+ return;
+ } else if ($this->is_otr($pl['body'])) {
+ $this->log(LOG_INFO, 'Ignoring OTR from ' . $from);
+ return;
+ } else if ($this->is_direct($pl['body'])) {
+ 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->add_direct($user, $body, $to, $from);
+ } else {
+ $len = mb_strlen($pl['body']);
+ if($len > 140) {
+ $this->from_site($from, 'Message too long - maximum is 140 characters, you sent ' . $len);
+ return;
+ }
+ $this->add_notice($user, $pl);
+ }
+
+ $user->free();
+ unset($user);
+ }
+
+ function is_self($from) {
+ return preg_match('/^'.strtolower(jabber_daemon_address()).'/', strtolower($from));
+ }
+
+ function get_ofrom($pl) {
+ $xml = $pl['xml'];
+ $addresses = $xml->sub('addresses');
+ if (!$addresses) {
+ $this->log(LOG_WARNING, 'Forwarded message without addresses');
+ return NULL;
+ }
+ $address = $addresses->sub('address');
+ if (!$address) {
+ $this->log(LOG_WARNING, 'Forwarded message without address');
+ return NULL;
+ }
+ if (!array_key_exists('type', $address->attrs)) {
+ $this->log(LOG_WARNING, 'No type for forwarded message');
+ return NULL;
+ }
+ $type = $address->attrs['type'];
+ if ($type != 'ofrom') {
+ $this->log(LOG_WARNING, 'Type of forwarded message is not ofrom');
+ return NULL;
+ }
+ if (!array_key_exists('jid', $address->attrs)) {
+ $this->log(LOG_WARNING, 'No jid for forwarded message');
+ return NULL;
+ }
+ $jid = $address->attrs['jid'];
+ if (!$jid) {
+ $this->log(LOG_WARNING, 'Could not get jid from address');
+ return NULL;
+ }
+ $this->log(LOG_DEBUG, 'Got message forwarded from jid ' . $jid);
+ return $jid;
+ }
+
+ function is_autoreply($txt) {
+ if (preg_match('/[\[\(]?[Aa]uto[-\s]?[Rr]e(ply|sponse)[\]\)]/', $txt)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function is_otr($txt) {
+ if (preg_match('/^\?OTR/', $txt)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ 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;
+ jabber_send_message($address, $text);
+ }
+
+ function handle_command($user, $body) {
+ $inter = new CommandInterpreter();
+ $cmd = $inter->handle_command($user, $body);
+ if ($cmd) {
+ $chan = new XMPPChannel($this->conn);
+ $cmd->execute($chan);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function add_notice(&$user, &$pl) {
+ $body = trim($pl['body']);
+ $content_shortened = common_shorten_link($body);
+ if (mb_strlen($content_shortened) > 140) {
+ $content = trim(mb_substr($body, 0, 140));
+ $content_shortened = common_shorten_link($content);
+ }
+ else {
+ $content = $body;
+ }
+ $notice = Notice::saveNew($user->id, $content, 'xmpp');
+ if (is_string($notice)) {
+ $this->log(LOG_ERR, $notice);
+ return;
+ }
+ common_broadcast_notice($notice);
+ $this->log(LOG_INFO,
+ 'Added notice ' . $notice->id . ' from user ' . $user->nickname);
+ $notice->free();
+ unset($notice);
+ }
+
+ function handle_presence(&$pl) {
+ $from = jabber_normalize_jid($pl['from']);
+ switch ($pl['type']) {
+ case 'subscribe':
+ # We let anyone subscribe
+ $this->subscribed($from);
+ $this->log(LOG_INFO,
+ 'Accepted subscription from ' . $from);
+ break;
+ case 'subscribed':
+ case 'unsubscribed':
+ case 'unsubscribe':
+ $this->log(LOG_INFO,
+ 'Ignoring "' . $pl['type'] . '" from ' . $from);
+ break;
+ default:
+ if (!$pl['type']) {
+ $user = User::staticGet('jabber', $from);
+ if (!$user) {
+ $this->log(LOG_WARNING, 'Presence from unknown user ' . $from);
+ return;
+ }
+ if ($user->updatefrompresence) {
+ $this->log(LOG_INFO, 'Updating ' . $user->nickname .
+ ' status from presence.');
+ $this->add_notice($user, $pl);
+ }
+ $user->free();
+ unset($user);
+ }
+ break;
+ }
+ }
+
+ function log($level, $msg) {
+ common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg);
+ }
+
+ function subscribed($to) {
+ jabber_special_presence('subscribed', $to);
+ }
+}
+
+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');
+
+$daemon = new XMPPDaemon($resource);
+
+$daemon->runOnce();