From 06cd3358970bfc27ff027cd1d8dc6974950c3793 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 27 Jan 2010 10:08:24 -0800 Subject: Add scripts/sendemail.php to send email to a user's address. Updated setup_status_network.sh to create a user with the site's nick, accept site tags, and send a mail to the user (if a template is set) Email and tag params added to the end: setup_status_net.sh mysite 'My Site' 'owner@example.com' '1user' (If multiple tags are needed, separate them with a pipe "|". Be sure to quote properly!) New parameters for setup.cfg need to be set: export PHPBASE=/var/www/statusnet export WILDCARD=example.net export MAILTEMPLATE=/etc/statusnet/newsite-mail.txt export MAILSUBJECT="Your new StatusNet site" $PHPBASE is the base dir for a callable StatusNet install, used to run command-line scripts for user setup. $WILDCARD is the wildcard domain, needed to build a full server name to pass into command-line scripts. $MAILTEMPLATE points to a file containing an e-mail message template. '$nickname', '$sitename', and '$userpass' can be used in the template for substitution. $MAILSUBJECT is the subject line for said email. To skip sending an email on creation, leave $MAILTEMPLATE blank or point to a non-existing file. --- scripts/sendemail.php | 82 +++++++++++++++++++++++++++++++++++++++++ scripts/setup.cfg.sample | 5 ++- scripts/setup_status_network.sh | 50 +++++++++++++++++++++++-- 3 files changed, 132 insertions(+), 5 deletions(-) create mode 100755 scripts/sendemail.php (limited to 'scripts') diff --git a/scripts/sendemail.php b/scripts/sendemail.php new file mode 100755 index 000000000..436e085be --- /dev/null +++ b/scripts/sendemail.php @@ -0,0 +1,82 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'i:n:'; +$longoptions = array('id=', 'nickname=', 'subject='); + +$helptext = << +Sends given email text to user. + + -i --id id of the user to query + -n --nickname nickname of the user to query + --subject mail subject line (required) + +END_OF_USEREMAIL_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +if (have_option('i', 'id')) { + $id = get_option_value('i', 'id'); + $user = User::staticGet('id', $id); + if (empty($user)) { + print "Can't find user 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 user with nickname '$nickname'\n"; + exit(1); + } +} else { + print "You must provide a user by --id or --nickname\n"; + exit(1); +} + +if (empty($user->email)) { + // @fixme unconfirmed address? + print "No email registered for user '$user->nickname'\n"; + exit(1); +} + +if (!have_option('subject')) { + echo "You must provide a subject line for the mail in --subject='...' param.\n"; + exit(1); +} +$subject = get_option_value('subject'); + +if (posix_isatty(STDIN)) { + print "You must provide message input on stdin!\n"; + exit(1); +} +$body = file_get_contents('php://stdin'); + +print "Sending to $user->email..."; +if (mail_to_user($user, $subject, $body)) { + print " done\n"; +} else { + print " failed.\n"; + exit(1); +} + diff --git a/scripts/setup.cfg.sample b/scripts/setup.cfg.sample index 8d03b06f5..a0f10b352 100644 --- a/scripts/setup.cfg.sample +++ b/scripts/setup.cfg.sample @@ -11,4 +11,7 @@ export AVATARBASE=/var/www/avatar.example.net export BACKGROUNDBASE=/var/www/background.example.net export FILEBASE=/var/www/file.example.net export PWDGEN="pwgen 20" - +export PHPBASE=/var/www/statusnet +export WILDCARD=example.net +export MAILTEMPLATE=/etc/statusnet/newsite-mail.txt +export MAILSUBJECT="Your new StatusNet site" diff --git a/scripts/setup_status_network.sh b/scripts/setup_status_network.sh index 777711fb5..d468df3ae 100755 --- a/scripts/setup_status_network.sh +++ b/scripts/setup_status_network.sh @@ -2,9 +2,22 @@ source /etc/statusnet/setup.cfg -export nickname=$1 -export sitename=$2 +# setup_status_net.sh mysite 'My Site' 'owner@example.com' '1user' +export nickname="$1" +export sitename="$2" +export email="$3" +export tags="$4" + +# Fixme: if this is changed later we need to update profile URLs +# for the created user. +export server="$nickname.$WILDCARD" + +# End-user info +export userpass=`$PWDGEN` +export roles="administrator moderator owner" + +# DB info export password=`$PWDGEN` export database=$nickname$DBBASE export username=$nickname$USERBASE @@ -21,8 +34,8 @@ mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB << ENDOFCOMMANDS GRANT ALL ON $database.* TO '$username'@'localhost' IDENTIFIED BY '$password'; GRANT ALL ON $database.* TO '$username'@'%' IDENTIFIED BY '$password'; -INSERT INTO status_network (nickname, dbhost, dbuser, dbpass, dbname, sitename, created) -VALUES ('$nickname', '$DBHOSTNAME', '$username', '$password', '$database', '$sitename', now()); +INSERT INTO status_network (nickname, dbhost, dbuser, dbpass, dbname, sitename, created, tags) +VALUES ('$nickname', '$DBHOSTNAME', '$username', '$password', '$database', '$sitename', now(), '$tags'); ENDOFCOMMANDS @@ -30,3 +43,32 @@ for top in $AVATARBASE $FILEBASE $BACKGROUNDBASE; do mkdir $top/$nickname chmod a+w $top/$nickname done + +php $PHPBASE/scripts/registeruser.php \ + -s"$server" \ + -n"$nickname" \ + -w"$userpass" \ + -e"$email" + +for role in $roles +do + php $PHPBASE/scripts/userrole.php \ + -s"$server" \ + -n"$nickname" \ + -r"$role" +done + +if [ -f "$MAILTEMPLATE" ] +then + # fixme how safe is this? are sitenames sanitized? + cat $MAILTEMPLATE | \ + sed "s/\$nickname/$nickname/" | \ + sed "s/\$sitename/$sitename/" | \ + sed "s/\$userpass/$userpass/" | \ + php $PHPBASE/scripts/sendemail.php \ + -s"$server" \ + -n"$nickname" \ + --subject="$MAILSUBJECT" +else + echo "No mail template, not sending email." +fi -- cgit v1.2.3-54-g00ecf From e7a5471287598902d4fefbb93f1247d8c025e66b Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 27 Jan 2010 15:37:18 -0800 Subject: add additional post-install shell script option for setup_status_network.sh to do any other site-specific setup --- scripts/setup.cfg.sample | 1 + scripts/setup_status_network.sh | 6 ++++++ 2 files changed, 7 insertions(+) (limited to 'scripts') diff --git a/scripts/setup.cfg.sample b/scripts/setup.cfg.sample index a0f10b352..f247a3bca 100644 --- a/scripts/setup.cfg.sample +++ b/scripts/setup.cfg.sample @@ -15,3 +15,4 @@ export PHPBASE=/var/www/statusnet export WILDCARD=example.net export MAILTEMPLATE=/etc/statusnet/newsite-mail.txt export MAILSUBJECT="Your new StatusNet site" +export POSTINSTALL=/etc/statusnet/morestuff.sh diff --git a/scripts/setup_status_network.sh b/scripts/setup_status_network.sh index d468df3ae..ae392191f 100755 --- a/scripts/setup_status_network.sh +++ b/scripts/setup_status_network.sh @@ -72,3 +72,9 @@ then else echo "No mail template, not sending email." fi + +if [ -f "$POSTINSTALL" ] +then + echo "Running $POSTINSTALL ..." + source "$POSTINSTALL" +fi -- cgit v1.2.3-54-g00ecf From fe531dfc6c9c700b5566db634a9078d4b4b87d87 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 27 Jan 2010 16:03:01 -0800 Subject: Shuffle params on setup_status_network; adding fullname and pushing tags up --- scripts/setup_status_network.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/setup_status_network.sh b/scripts/setup_status_network.sh index ae392191f..f502a169a 100755 --- a/scripts/setup_status_network.sh +++ b/scripts/setup_status_network.sh @@ -2,12 +2,13 @@ source /etc/statusnet/setup.cfg -# setup_status_net.sh mysite 'My Site' 'owner@example.com' '1user' +# setup_status_net.sh mysite 'My Site' '1user' 'owner@example.com' 'Firsty McLastname' export nickname="$1" export sitename="$2" -export email="$3" -export tags="$4" +export tags="$3" +export email="$4" +export fullname="$5" # Fixme: if this is changed later we need to update profile URLs # for the created user. @@ -47,6 +48,7 @@ done php $PHPBASE/scripts/registeruser.php \ -s"$server" \ -n"$nickname" \ + -f"$fullname" \ -w"$userpass" \ -e"$email" -- cgit v1.2.3-54-g00ecf From 4a0413c0270bcac456c20972342c2c29182bec4e Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 28 Jan 2010 01:42:52 -0500 Subject: Add a script to set tags for sites --- scripts/settag.php | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 scripts/settag.php (limited to 'scripts') diff --git a/scripts/settag.php b/scripts/settag.php new file mode 100644 index 000000000..1d7b60b90 --- /dev/null +++ b/scripts/settag.php @@ -0,0 +1,84 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'd'; +$longoptions = array('delete'); + +$helptext = << +Set the tag for site . + +With -d, delete the tag. + +END_OF_SETTAG_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +if (count($args) != 2) { + show_help(); + exit(1); +} + +$nickname = $args[0]; +$tag = strtolower($args[1]); + +$sn = Status_network::memGet('nickname', $nickname); + +if (empty($sn)) { + print "No such site.\n"; + exit(-1); +} + +$tags = $sn->getTags(); + +$i = array_search($tags, $tag); + +if ($i !== false) { + if (have_option('d', 'delete')) { // Delete + unset($tags[$i]); + + $orig = clone($sn); + $sn->tags = implode('|', $tags); + $result = $sn->update($orig); + if (!$result) { + print "Couldn't update.\n"; + exit(-1); + } + } else { + print "Already set.\n"; + exit(-1); + } +} else { + if (have_option('d', 'delete')) { // Delete + print "No such tag.\n"; + exit(-1); + } else { + $tags[] = $tag; + $orig = clone($sn); + $sn->tags = implode('|', $tags); + $result = $sn->update($orig); + if (!$result) { + print "Couldn't update.\n"; + exit(-1); + } + } +} -- cgit v1.2.3-54-g00ecf From 864ce8e276220262ef8a26a9138c929145ccf57e Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 28 Jan 2010 20:09:17 -0800 Subject: Fixes for status_network db object .ini and tag setter script --- classes/status_network.ini | 1 + scripts/settag.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/classes/status_network.ini b/classes/status_network.ini index 8123265e4..adb71cba7 100644 --- a/classes/status_network.ini +++ b/classes/status_network.ini @@ -11,6 +11,7 @@ theme = 2 logo = 2 created = 142 modified = 384 +tags = 34 [status_network__keys] nickname = K diff --git a/scripts/settag.php b/scripts/settag.php index 1d7b60b90..e91d5eb50 100644 --- a/scripts/settag.php +++ b/scripts/settag.php @@ -50,7 +50,7 @@ if (empty($sn)) { $tags = $sn->getTags(); -$i = array_search($tags, $tag); +$i = array_search($tag, $tags); if ($i !== false) { if (have_option('d', 'delete')) { // Delete -- cgit v1.2.3-54-g00ecf From 288dc3452f3c274d2165d8e7d502631a6eacc97c Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 28 Jan 2010 22:05:14 -0800 Subject: Log exceptions from queuedaemon.php if they're not already caught --- scripts/queuedaemon.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/queuedaemon.php b/scripts/queuedaemon.php index c2e2351c3..30a8a9602 100755 --- a/scripts/queuedaemon.php +++ b/scripts/queuedaemon.php @@ -109,7 +109,13 @@ class QueueDaemon extends SpawningDaemon $master = new QueueMaster($this->get_id()); $master->init($this->all); - $master->service(); + try { + $master->service(); + } catch (Exception $e) { + common_log(LOG_ERR, "Unhandled exception: " . $e->getMessage() . ' ' . + str_replace("\n", " ", $e->getTraceAsString())); + return self::EXIT_ERR; + } $this->log(LOG_INFO, 'finished servicing the queue'); -- cgit v1.2.3-54-g00ecf From 2a054a50fb404b01512a00872ab0f68481b0f470 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 29 Jan 2010 15:33:35 -0500 Subject: live fast, die young in bash scripts --- scripts/delete_status_network.sh | 4 ++++ scripts/setup_status_network.sh | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'scripts') diff --git a/scripts/delete_status_network.sh b/scripts/delete_status_network.sh index f55f1486b..3a8ebdcfd 100755 --- a/scripts/delete_status_network.sh +++ b/scripts/delete_status_network.sh @@ -1,5 +1,9 @@ #!/bin/bash +# live fast! die young! + +set -e + source /etc/statusnet/setup.cfg export nickname=$1 diff --git a/scripts/setup_status_network.sh b/scripts/setup_status_network.sh index f502a169a..4ad808011 100755 --- a/scripts/setup_status_network.sh +++ b/scripts/setup_status_network.sh @@ -1,5 +1,9 @@ #!/bin/bash +# live fast! die young! + +set -e + source /etc/statusnet/setup.cfg # setup_status_net.sh mysite 'My Site' '1user' 'owner@example.com' 'Firsty McLastname' -- cgit v1.2.3-54-g00ecf From 5d2c0838997824b2f2b9105a1aa269b5a8b79f82 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 31 Jan 2010 22:58:29 -0500 Subject: Add a script to clear the cache for a given key Like showcache.php, clearcache.php clears the cache for a given key. --- scripts/clearcache.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 scripts/clearcache.php (limited to 'scripts') diff --git a/scripts/clearcache.php b/scripts/clearcache.php new file mode 100644 index 000000000..702c1e3d6 --- /dev/null +++ b/scripts/clearcache.php @@ -0,0 +1,70 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = "t:c:v:k:"; + +$helptext = << +clears the cached object based on the args + + -t table Table to look up + -c column Column to look up, default "id" + -v value Value to look up + -k key Key to look up; other args are ignored + +ENDOFHELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +$karg = get_option_value('k'); + +if (!empty($karg)) { + $k = common_cache_key($karg); +} else { + $table = get_option_value('t'); + if (empty($table)) { + die("No table or key specified\n"); + } + $column = get_option_value('c'); + if (empty($column)) { + $column = 'id'; + } + $value = get_option_value('v'); + + $k = Memcached_DataObject::cacheKey($table, $column, $value); +} + +print "Clearing key '$k'..."; + +$c = common_memcache(); + +if (empty($c)) { + die("Can't initialize cache object!\n"); +} + +$result = $c->delete($k); + +if ($result) { + print "OK.\n"; +} else { + print "FAIL.\n"; +} -- cgit v1.2.3-54-g00ecf From 5f14301c55477e9989039bc04747608fdc7c932c Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 2 Feb 2010 06:15:01 -0800 Subject: setconfig.php: list all current settings if no parameters given --- scripts/setconfig.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) mode change 100644 => 100755 scripts/setconfig.php (limited to 'scripts') diff --git a/scripts/setconfig.php b/scripts/setconfig.php old mode 100644 new mode 100755 index b102f99b1..fe0e46d65 --- a/scripts/setconfig.php +++ b/scripts/setconfig.php @@ -28,6 +28,7 @@ setconfig.php [options] [section] [setting] With three args, set the setting to the value. With two args, just show the setting. With -d, delete the setting. +With no args, lists all currently set values. [section] section to use (required) [setting] setting to use (required) @@ -39,6 +40,21 @@ 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"; + } + exit(0); +} + if (count($args) < 2 || count($args) > 3) { show_help(); exit(1); -- cgit v1.2.3-54-g00ecf