summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorCraig Andrews <candrews@integralblue.com>2010-04-18 19:21:15 -0400
committerCraig Andrews <candrews@integralblue.com>2010-04-18 19:21:15 -0400
commit39392e03a71d94d6b984033b994b417edfc2d8d6 (patch)
treecb3ae36fc9a20a4cd884e271ef36dcce28f109c8 /scripts
parent727ea5a5163249eb40fa0c4b2c63054fc997473b (diff)
parent23bad16bba52a09f0cea3d2c40e6cf91e2945e37 (diff)
Merge branch '0.9.x' into 1.0.x
Conflicts: actions/confirmaddress.php actions/imsettings.php
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/fixup_blocks.php76
-rwxr-xr-xscripts/install_cli.php217
-rwxr-xr-xscripts/setconfig.php36
-rw-r--r--scripts/settag.php9
-rwxr-xr-xscripts/showplugins.php38
-rwxr-xr-xscripts/strip_geo.php122
6 files changed, 484 insertions, 14 deletions
diff --git a/scripts/fixup_blocks.php b/scripts/fixup_blocks.php
new file mode 100755
index 000000000..6b0255e72
--- /dev/null
+++ b/scripts/fixup_blocks.php
@@ -0,0 +1,76 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2010 StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+
+$longoptions = array('dry-run', 'start=', 'end=');
+
+$helptext = <<<END_OF_HELP
+fixup_blocks.php [options]
+Finds profile blocks where the unsubscription didn't complete,
+and removes the offending subscriptions.
+
+ --dry-run look but don't touch
+
+END_OF_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+/**
+ * Fetch subscriptions that should be disallowed by a block
+ */
+function get_blocked_subs()
+{
+ $query = "SELECT subscription.* " .
+ "FROM subscription " .
+ "INNER JOIN profile_block " .
+ "ON blocker=subscribed " .
+ "AND blocked=subscriber";
+ $subscription = new Subscription();
+ $subscription->query($query);
+ return $subscription;
+}
+
+
+$dry = have_option('dry-run');
+$sub = get_blocked_subs();
+$count = $sub->N;
+while ($sub->fetch()) {
+ $subber = Profile::staticGet('id', $sub->subscriber);
+ $subbed = Profile::staticGet('id', $sub->subscribed);
+ if (!$subber || !$subbed) {
+ print "Bogus entry! $sub->subscriber subbed to $sub->subscribed\n";
+ continue;
+ }
+ print "$subber->nickname ($subber->id) blocked but subbed to $subbed->nickname ($subbed->id)";
+ if ($dry) {
+ print ": skipping; dry run\n";
+ } else {
+ Subscription::cancel($subber, $subbed);
+ print ": removed\n";
+ }
+}
+print "\n";
+
+if ($dry && $count > 0) {
+ print "Be sure to run without --dry-run to remove the bad entries!\n";
+} else {
+ print "done.\n";
+}
diff --git a/scripts/install_cli.php b/scripts/install_cli.php
new file mode 100755
index 000000000..61fbe18ef
--- /dev/null
+++ b/scripts/install_cli.php
@@ -0,0 +1,217 @@
+#!/usr/bin/env php
+<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Installation
+ * @package Installation
+ *
+ * @author Brion Vibber <brion@status.net>
+ * @license GNU Affero General Public License http://www.gnu.org/licenses/
+ * @version 0.9.x
+ * @link http://status.net
+ */
+
+if (php_sapi_name() !== 'cli') {
+ exit(1);
+}
+
+define('INSTALLDIR', dirname(dirname(__FILE__)));
+set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib');
+
+require_once INSTALLDIR . '/lib/installer.php';
+require_once 'Console/Getopt.php';
+
+class CliInstaller extends Installer
+{
+ public $verbose = true;
+
+ /**
+ * Go for it!
+ * @return boolean success
+ */
+ function main()
+ {
+ if (!$this->checkPrereqs()) {
+ return false;
+ }
+ if ($this->prepare()) {
+ return $this->handle();
+ } else {
+ $this->showHelp();
+ return false;
+ }
+ }
+
+ /**
+ * Get our input parameters...
+ * @return boolean success
+ */
+ function prepare()
+ {
+ $shortoptions = 'qvh';
+ $longoptions = array('quiet', 'verbose', 'help', 'skip-config');
+ $map = array(
+ '-s' => 'server',
+ '--server' => 'server',
+ '-p' => 'path',
+ '--path' => 'path',
+ '--sitename' => 'sitename',
+ '--fancy' => 'fancy',
+
+ '--dbtype' => 'dbtype',
+ '--host' => 'host',
+ '--database' => 'database',
+ '--username' => 'username',
+ '--password' => 'password',
+
+ '--admin-nick' => 'adminNick',
+ '--admin-pass' => 'adminPass',
+ '--admin-email' => 'adminEmail',
+ '--admin-updates' => 'adminUpdates'
+ );
+ foreach ($map as $arg => $target) {
+ if (substr($arg, 0, 2) == '--') {
+ $longoptions[] = substr($arg, 2) . '=';
+ } else {
+ $shortoptions .= substr($arg, 1) . ':';
+ }
+ }
+
+ $parser = new Console_Getopt();
+ $result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions);
+ if (PEAR::isError($result)) {
+ $this->warning($result->getMessage());
+ return false;
+ }
+ list($options, $args) = $result;
+
+ // defaults
+ $this->dbtype = 'mysql';
+ $this->adminUpdates = true;
+ $this->verbose = true;
+
+ foreach ($options as $option) {
+ $arg = $option[0];
+ if (isset($map[$arg])) {
+ $var = $map[$arg];
+ $this->$var = $option[1];
+ if ($var == 'adminUpdates' || $arg == '--fancy') {
+ $this->$var = ($option[1] != 'false') && ($option[1] != 'no');
+ }
+ } else if ($arg == '--skip-config') {
+ $this->skipConfig = true;
+ } else if ($arg == 'q' || $arg == '--quiet') {
+ $this->verbose = false;
+ } else if ($arg == 'v' || $arg == '--verbose') {
+ $this->verbose = true;
+ } else if ($arg == 'h' || $arg == '--help') {
+ // will go back to show help
+ return false;
+ }
+ }
+
+ $fail = false;
+ if (empty($this->server)) {
+ $this->updateStatus("You must specify a web server for the site.", true);
+ // path is optional though
+ $fail = true;
+ }
+
+ if (!$this->validateDb()) {
+ $fail = true;
+ }
+
+ if (!$this->validateAdmin()) {
+ $fail = true;
+ }
+
+ return !$fail;
+ }
+
+ function handle()
+ {
+ return $this->doInstall();
+ }
+
+ function showHelp()
+ {
+ echo <<<END_HELP
+install_cli.php - StatusNet command-line installer
+
+ -s --server=<name> Use <name> as server name (required)
+ -p --path=<path> Use <path> as path name
+ --sitename User-friendly site name (required)
+ --fancy Whether to use fancy URLs (default no)
+
+ --dbtype 'mysql' (default) or 'pgsql'
+ --host Database hostname (required)
+ --database Database/schema name (required)
+ --username Database username (required)
+ --password Database password (required)
+
+ --admin-nick Administrator nickname (required)
+ --admin-pass Initial password for admin user (required)
+ --admin-email Initial email address for admin user
+ --admin-updates 'yes' (default) or 'no', whether to subscribe
+ admin to update@status.net (default yes)
+
+ --skip-config Don't write a config.php -- use with caution,
+ requires a global configuration file.
+
+ General options:
+
+ -q --quiet Quiet (little output)
+ -v --verbose Verbose (lots of output)
+ -h --help Show this message and quit.
+
+END_HELP;
+ }
+
+ function warning($message, $submessage='')
+ {
+ print $this->html2text($message) . "\n";
+ if ($submessage != '') {
+ print " " . $this->html2text($submessage) . "\n";
+ }
+ print "\n";
+ }
+
+ function updateStatus($status, $error=false)
+ {
+ if ($this->verbose || $error) {
+ if ($error) {
+ print "ERROR: ";
+ }
+ print $this->html2text($status);
+ print "\n";
+ }
+ }
+
+ private function html2text($html)
+ {
+ // break out any links for text legibility
+ $breakout = preg_replace('/<a[^>+]\bhref="(.*)"[^>]*>(.*)<\/a>/',
+ '\2 &lt;\1&gt;',
+ $html);
+ return html_entity_decode(strip_tags($breakout));
+ }
+}
+
+$installer = new CliInstaller();
+$ok = $installer->main();
+exit($ok ? 0 : 1);
diff --git a/scripts/setconfig.php b/scripts/setconfig.php
index fe0e46d65..401dda0f2 100755
--- a/scripts/setconfig.php
+++ b/scripts/setconfig.php
@@ -20,8 +20,8 @@
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
-$shortoptions = 'd';
-$longoptions = array('delete');
+$shortoptions = 'da';
+$longoptions = array('delete', 'all');
$helptext = <<<END_OF_SETCONFIG_HELP
setconfig.php [options] [section] [setting] <value>
@@ -35,22 +35,34 @@ With no args, lists all currently set values.
<value> value to set (optional)
-d --delete delete the setting (no value)
+ -a --all list all configuration, not just the database values
END_OF_SETCONFIG_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
if (empty($args)) {
- $count = 0;
- $config = new Config();
- $config->find();
- while ($config->fetch()) {
- $count++;
- printf("%-20s %-20s %s\n", $config->section, $config->setting,
- var_export($config->value, true));
- }
- if ($count == 0) {
- print "No configuration set in database for this site.\n";
+ if (have_option('a', 'all')) {
+ foreach ($config as $section => $section_value) {
+ foreach ($section_value as $setting => $value) {
+ if (have_option('v', 'verbose') || !is_array($value)) {
+ # Don't print array's without the verbose flag
+ printf("%-20s %-20s %s\n", $section, $setting, var_export($value, true));
+ }
+ }
+ }
+ } else {
+ $count = 0;
+ $config = new Config();
+ $config->find();
+ while ($config->fetch()) {
+ $count++;
+ printf("%-20s %-20s %s\n", $config->section, $config->setting,
+ var_export($config->value, true));
+ }
+ if ($count == 0) {
+ print "No configuration set in database for this site.\n";
+ }
}
exit(0);
}
diff --git a/scripts/settag.php b/scripts/settag.php
index e91d5eb50..d1b06ff10 100644
--- a/scripts/settag.php
+++ b/scripts/settag.php
@@ -33,13 +33,12 @@ END_OF_SETTAG_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
-if (count($args) != 2) {
+if (count($args) < 1) {
show_help();
exit(1);
}
$nickname = $args[0];
-$tag = strtolower($args[1]);
$sn = Status_network::memGet('nickname', $nickname);
@@ -50,6 +49,12 @@ if (empty($sn)) {
$tags = $sn->getTags();
+if (count($args) == 1) {
+ print(implode(', ', $tags) . "\n");
+ exit(0);
+}
+$tag = $args[1];
+
$i = array_search($tag, $tags);
if ($i !== false) {
diff --git a/scripts/showplugins.php b/scripts/showplugins.php
new file mode 100755
index 000000000..058393b0e
--- /dev/null
+++ b/scripts/showplugins.php
@@ -0,0 +1,38 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+foreach (StatusNet::getActivePlugins() as $data) {
+ list($plugin, $args) = $data;
+ echo "$plugin: ";
+ if ($args === null) {
+ echo "(no args)\n";
+ } else {
+ foreach ($args as $arg => $val) {
+ echo "\n $arg: ";
+ var_export($val);
+ }
+ echo "\n";
+ }
+ echo "\n";
+}
diff --git a/scripts/strip_geo.php b/scripts/strip_geo.php
new file mode 100755
index 000000000..b3f27be61
--- /dev/null
+++ b/scripts/strip_geo.php
@@ -0,0 +1,122 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2009-2010, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+
+$shortoptions = 'i::n::y';
+$longoptions = array('id=', 'nickname=', 'yes', 'dry-run', 'all');
+
+$helptext = <<<END_OF_HELP
+strip_geo.php [options]
+Removes geolocation info from the given user's notices.
+
+ -i --id ID of the user (may be a remote profile)
+ -n --nickname nickname of the user
+ -y --yes do not wait for confirmation
+ --dry-run list affected notices without deleting
+ --all run over and decache all messages, even if they don't
+ have geo data now (helps to fix cache bugs)
+
+END_OF_HELP;
+
+require_once INSTALLDIR.'/scripts/commandline.inc';
+
+if (have_option('i', 'id')) {
+ $id = get_option_value('i', 'id');
+ $profile = Profile::staticGet('id', $id);
+ if (empty($profile)) {
+ print "Can't find local or remote profile with ID $id\n";
+ exit(1);
+ }
+} else if (have_option('n', 'nickname')) {
+ $nickname = get_option_value('n', 'nickname');
+ $user = User::staticGet('nickname', $nickname);
+ if (empty($user)) {
+ print "Can't find local user with nickname '$nickname'\n";
+ exit(1);
+ }
+ $profile = $user->getProfile();
+} else {
+ print "You must provide either an ID or a nickname.\n\n";
+ show_help();
+ exit(1);
+}
+
+if (!have_option('y', 'yes') && !have_option('--dry-run')) {
+ print "About to PERMANENTLY remove geolocation data from user '{$profile->nickname}' ({$profile->id})'s notices. Are you sure? [y/N] ";
+ $response = fgets(STDIN);
+ if (strtolower(trim($response)) != 'y') {
+ print "Aborting.\n";
+ exit(0);
+ }
+}
+
+// @fixme for a very prolific poster this could be too many.
+$notice = new Notice();
+$notice->profile_id = $profile->id;
+if (have_option('--all')) {
+ print "Finding all notices by $profile->nickname...";
+} else {
+ print "Finding notices by $profile->nickname with geolocation data...";
+ $notice->whereAdd("lat != ''");
+}
+$notice->find();
+
+if ($notice->N) {
+ print " $notice->N found.\n";
+ while ($notice->fetch()) {
+ print "notice id $notice->id ";
+ if (have_option('v') || have_option('--verbose')) {
+ print "({$notice->lat},{$notice->lon}) ";
+ if ($notice->location_ns) {
+ print "ns {$notice->location_ns} id {$notice->location_id} ";
+ }
+ }
+ if (have_option('--dry-run')) {
+ // sucka
+ echo "(skipped)";
+ } else {
+ // note: setting fields to null and calling update() doesn't save the nulled fields
+ $orig = clone($notice);
+ $update = clone($notice);
+
+ // In theory we could hit a chunk of notices at once in the UPDATE,
+ // but we're going to have to decache them individually anyway and
+ // it doesn't hurt to make sure we don't hold up replication with
+ // what might be a very slow single UPDATE.
+ $query = sprintf('UPDATE notice ' .
+ 'SET lat=NULL,lon=NULL,location_ns=NULL,location_id=NULL ' .
+ 'WHERE id=%d', $notice->id);
+ $ok = $update->query($query);
+ if ($ok) {
+ // And now we decache him manually, as query() doesn't know what we're doing...
+ $orig->decache();
+ echo "(removed)";
+ } else {
+ echo "(unchanged?)";
+ }
+ }
+ print "\n";
+ }
+} else {
+ print " none found.\n";
+}
+
+print "DONE.\n";