summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/createsim.php142
-rwxr-xr-xscripts/getvaliddaemons.php3
-rwxr-xr-xscripts/maildaemon.php46
-rw-r--r--scripts/triminboxes.php40
-rwxr-xr-xscripts/twitterstatusfetcher.php29
-rwxr-xr-xscripts/xmppdaemon.php5
6 files changed, 205 insertions, 60 deletions
diff --git a/scripts/createsim.php b/scripts/createsim.php
new file mode 100644
index 000000000..71827ba5b
--- /dev/null
+++ b/scripts/createsim.php
@@ -0,0 +1,142 @@
+#!/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__) . '/..'));
+
+$shortoptions = 'u:n:b:t:x:';
+$longoptions = array('users=', 'notices=', 'subscriptions=', 'tags=', 'prefix=');
+
+$helptext = <<<END_OF_CREATESIM_HELP
+Creates a lot of test users and notices to (loosely) simulate a real server.
+
+ -u --users Number of users (default 100)
+ -n --notices Average notices per user (default 100)
+ -b --subscriptions Average subscriptions per user (default no. users/20)
+ -t --tags Number of distinct hash tags (default 10000)
+ -x --prefix User name prefix (default 'testuser')
+
+END_OF_CREATESIM_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+// XXX: make these command-line options
+
+function newUser($i)
+{
+ global $userprefix;
+ User::register(array('nickname' => sprintf('%s%d', $userprefix, $i),
+ 'password' => sprintf('password%d', $i),
+ 'fullname' => sprintf('Test User %d', $i)));
+}
+
+function newNotice($i, $tagmax)
+{
+ global $userprefix;
+
+ $n = rand(0, $i - 1);
+ $user = User::staticGet('nickname', sprintf('%s%d', $userprefix, $n));
+
+ $is_reply = rand(0, 4);
+
+ $content = 'Test notice content';
+
+ if ($is_reply == 0) {
+ $n = rand(0, $i - 1);
+ $content = "@$userprefix$n " . $content;
+ }
+
+ $has_hash = rand(0, 2);
+
+ if ($has_hash == 0) {
+ $hashcount = rand(0, 2);
+ for ($j = 0; $j < $hashcount; $j++) {
+ $h = rand(0, $tagmax);
+ $content .= " #tag{$h}";
+ }
+ }
+
+ $notice = Notice::saveNew($user->id, $content, 'system');
+}
+
+function newSub($i)
+{
+ global $userprefix;
+ $f = rand(0, $i - 1);
+
+ $fromnick = sprintf('%s%d', $userprefix, $f);
+
+ $from = User::staticGet('nickname', $fromnick);
+
+ if (empty($from)) {
+ throw new Exception("Can't find user '$fromnick'.");
+ }
+
+ $t = rand(0, $i - 1);
+
+ if ($t == $f) {
+ $t++;
+ if ($t > $i - 1) {
+ $t = 0;
+ }
+ }
+
+ $tunic = sprintf('%s%d', $userprefix, $t);
+
+ $to = User::staticGet('nickname', $tunic);
+
+ if (empty($from)) {
+ throw new Exception("Can't find user '$tunic'.");
+ }
+
+ subs_subscribe_to($from, $to);
+}
+
+function main($usercount, $noticeavg, $subsavg, $tagmax)
+{
+ $n = 1;
+
+ newUser(0);
+
+ // # registrations + # notices + # subs
+
+ $events = $usercount + ($usercount * ($noticeavg + $subsavg));
+
+ for ($i = 0; $i < $events; $i++)
+ {
+ $e = rand(0, 1 + $noticeavg + $subsavg);
+
+ if ($e == 0) {
+ newUser($n);
+ $n++;
+ } else if ($e < $noticeavg + 1) {
+ newNotice($n, $tagmax);
+ } else {
+ newSub($n);
+ }
+ }
+}
+
+$usercount = (have_option('u', 'users')) ? get_option_value('u', 'users') : 100;
+$noticeavg = (have_option('n', 'notices')) ? get_option_value('n', 'notices') : 100;
+$subsavg = (have_option('b', 'subscriptions')) ? get_option_value('b', 'subscriptions') : max($usercount/20, 10);
+$tagmax = (have_option('t', 'tags')) ? get_option_value('t', 'tags') : 10000;
+$userprefix = (have_option('x', 'prefix')) ? get_option_value('x', 'prefix') : 'testuser';
+
+main($usercount, $noticeavg, $subsavg, $tagmax);
diff --git a/scripts/getvaliddaemons.php b/scripts/getvaliddaemons.php
index 97c230784..1e4546dff 100755
--- a/scripts/getvaliddaemons.php
+++ b/scripts/getvaliddaemons.php
@@ -28,7 +28,8 @@
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
$helptext = <<<ENDOFHELP
-getvaliddaemons.php - print out the currently configured PID directory
+getvaliddaemons.php - print out a list of valid daemons that should be started
+by the startdaemons script
ENDOFHELP;
diff --git a/scripts/maildaemon.php b/scripts/maildaemon.php
index 11ddf06b7..3ef4d0638 100755
--- a/scripts/maildaemon.php
+++ b/scripts/maildaemon.php
@@ -299,25 +299,43 @@ class MailerDaemon
$attachments = array();
+ $this->extract_part($parsed,$msg,$attachments);
+
+ return array($from, $to, $msg, $attachments);
+ }
+
+ function extract_part($parsed,&$msg,&$attachments){
if ($parsed->ctype_primary == 'multipart') {
- foreach ($parsed->parts as $part) {
- if ($part->ctype_primary == 'text' &&
- $part->ctype_secondary == 'plain') {
- $msg = $part->body;
- }else{
- if ($part->body) {
- $attachment = tmpfile();
- fwrite($attachment, $part->body);
- $attachments[] = $attachment;
- }
+ if($parsed->ctype_secondary == 'alternative'){
+ $altmsg = $this->extract_msg_from_multipart_alternative_part($parsed);
+ if(!empty($altmsg)) $msg = $altmsg;
+ }else{
+ foreach($parsed->parts as $part){
+ $this->extract_part($part,$msg,$attachments);
}
}
- } else if ($type == 'text/plain') {
+ } else if ($parsed->ctype_primary == 'text'
+ && $parsed->ctype_secondary=='plain') {
$msg = $parsed->body;
- } else {
- $this->unsupported_type($type);
+ if(strtolower($parsed->ctype_parameters['charset']) != "utf-8"){
+ $msg = utf8_encode($msg);
+ }
+ }else if(!empty($parsed->body)){
+ if(common_config('attachments', 'uploads')){
+ //only save attachments if uploads are enabled
+ $attachment = tmpfile();
+ fwrite($attachment, $parsed->body);
+ $attachments[] = $attachment;
+ }
}
- return array($from, $to, $msg, $attachments);
+ }
+
+ function extract_msg_from_multipart_alternative_part($parsed){
+ foreach ($parsed->parts as $part) {
+ $this->extract_part($part,$msg,$attachments);
+ }
+ //we don't want any attachments that are a result of this parsing
+ return $msg;
}
function unsupported_type($type)
diff --git a/scripts/triminboxes.php b/scripts/triminboxes.php
index b2135d682..27e200fef 100644
--- a/scripts/triminboxes.php
+++ b/scripts/triminboxes.php
@@ -52,43 +52,5 @@ if (!empty($id)) {
$cnt = $user->find();
while ($user->fetch()) {
-
- $inbox_entry = new Notice_inbox();
- $inbox_entry->user_id = $user->id;
- $inbox_entry->orderBy('created DESC');
- $inbox_entry->limit(1000, 1);
-
- $id = null;
-
- if ($inbox_entry->find(true)) {
- $id = $inbox_entry->notice_id;
- }
-
- $inbox_entry->free();
- unset($inbox_entry);
-
- if (is_null($id)) {
- continue;
- }
-
- $start = microtime(true);
-
- $old_inbox = new Notice_inbox();
- $cnt = $old_inbox->query('DELETE from notice_inbox WHERE user_id = ' . $user->id . ' AND notice_id < ' . $id);
- $old_inbox->free();
- unset($old_inbox);
-
- print "Deleted $cnt notices for $user->nickname ($user->id).\n";
-
- $finish = microtime(true);
-
- $delay = 3.0 * ($finish - $start);
-
- print "Delaying $delay seconds...";
-
- // Wait to let slaves catch up
-
- usleep($delay * 1000000);
-
- print "DONE.\n";
+ Notice_inbox::gc($user->id);
}
diff --git a/scripts/twitterstatusfetcher.php b/scripts/twitterstatusfetcher.php
index 4a1ed8977..e1745cfc0 100755
--- a/scripts/twitterstatusfetcher.php
+++ b/scripts/twitterstatusfetcher.php
@@ -25,19 +25,18 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('MAXCHILDREN', 2);
define('POLL_INTERVAL', 60); // in seconds
-$shortoptions = 'i::';
-$longoptions = array('id::');
+$shortoptions = 'di::';
+$longoptions = array('id::', 'debug');
$helptext = <<<END_OF_TRIM_HELP
Batch script for retrieving Twitter messages from foreign service.
- -i --id Identity (default 'generic')
+ -i --id Identity (default 'generic')
+ -d --debug Debug (lots of log output)
END_OF_TRIM_HELP;
-require_once INSTALLDIR.'/scripts/commandline.inc';
-
-require_once INSTALLDIR . '/lib/common.php';
+require_once INSTALLDIR .'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/daemon.php';
/**
@@ -61,6 +60,15 @@ class TwitterStatusFetcher extends Daemon
{
private $_children = array();
+ function __construct($id=null, $daemonize=true)
+ {
+ parent::__construct($daemonize);
+
+ if ($id) {
+ $this->set_id($id);
+ }
+ }
+
/**
* Name of this daemon
*
@@ -80,6 +88,11 @@ class TwitterStatusFetcher extends Daemon
function run()
{
+ if (defined('SCRIPT_DEBUG')) {
+ common_debug($this->name() .
+ ': debugging log output enabled.');
+ }
+
do {
$flinks = $this->refreshFlinks();
@@ -640,6 +653,10 @@ if (have_option('i')) {
$id = null;
}
+if (have_option('d') || have_option('debug')) {
+ define('SCRIPT_DEBUG', true);
+}
+
$fetcher = new TwitterStatusFetcher($id);
$fetcher->runOnce();
diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php
index 488b4b514..69512f243 100755
--- a/scripts/xmppdaemon.php
+++ b/scripts/xmppdaemon.php
@@ -175,6 +175,10 @@ class XMPPDaemon extends Daemon
$user = $this->get_user($from);
+ // For common_current_user to work
+ global $_cur;
+ $_cur = $user;
+
if (!$user) {
$this->from_site($from, 'Unknown user; go to ' .
common_local_url('imsettings') .
@@ -211,6 +215,7 @@ class XMPPDaemon extends Daemon
$user->free();
unset($user);
+ unset($_cur);
unset($pl['xml']);
$pl['xml'] = null;