Merge branch '0.8.x' of git@gitorious.org:laconica/dev into 0.8.x

* '0.8.x' of git@gitorious.org:laconica/dev: (61 commits)
  Using default theme design values (it was previously set to identica
  Updated default colour theme and IE6 colours for transparent values
  chmod +x delete_status_network.sh
  rm -Rf, not rmdir
  script to delete a status network
  chmod allsites.php
  script to show all sites on a network
  use different name for connection and database
  use /etc/laconica/setup.cfg instead of local file
  other base directories
  On XHR notice post, calls NoticeAttachment to trigger thumbnail and
  oembed and thumbnail don't need sequences
  add innodb by default to status networks
  pwgen not pwdgen
  make pwgen command configurable
  a little sql script to drop full-text index and use innodb for profile and notice
  remove common_debug from newnotice
  append uploads to content rather than showing them double
  use a subclass for single notice items to show attachments
  make file command configurable
  ...
This commit is contained in:
Zach Copley 2009-06-23 14:29:46 -07:00
commit f04a54ed2f
46 changed files with 1835 additions and 658 deletions

5
README
View File

@ -180,6 +180,7 @@ and the URLs are listed here for your convenience.
- PEAR HTTP_Request is an oEmbed dependency. - PEAR HTTP_Request is an oEmbed dependency.
- PEAR Validate is an oEmbed dependency. - PEAR Validate is an oEmbed dependency.
- PEAR Net_URL2 is an oEmbed dependency. - PEAR Net_URL2 is an oEmbed dependency.
- Console_GetOpt for parsing command-line options.
A design goal of Laconica is that the basic Web functionality should A design goal of Laconica is that the basic Web functionality should
work on even the most restrictive commercial hosting services. work on even the most restrictive commercial hosting services.
@ -1231,6 +1232,10 @@ supported: an array of mime types you accept to store and distribute,
setup your server to properly reckognize the types you want to setup your server to properly reckognize the types you want to
support. support.
uploads: false to disable uploading files with notices (true by default). uploads: false to disable uploading files with notices (true by default).
filecommand: The required MIME_Type library may need to use the 'file'
command. It tries the one in the Web server's path, but if
you're having problems with uploads, try setting this to the
correct value. Note: 'file' must accept '-b' and '-i' options.
For quotas, be sure you've set the upload_max_filesize and post_max_size For quotas, be sure you've set the upload_max_filesize and post_max_size
in php.ini to be large enough to handle your upload. In httpd.conf in php.ini to be large enough to handle your upload. In httpd.conf

View File

@ -116,6 +116,9 @@ class NewnoticeAction extends Action
function getUploadedFileType() { function getUploadedFileType() {
require_once 'MIME/Type.php'; require_once 'MIME/Type.php';
$cmd = &PEAR::getStaticProperty('MIME_Type', 'fileCmd');
$cmd = common_config('attachments', 'filecommand');
$filetype = MIME_Type::autoDetect($_FILES['attach']['tmp_name']); $filetype = MIME_Type::autoDetect($_FILES['attach']['tmp_name']);
if (in_array($filetype, common_config('attachments', 'supported'))) { if (in_array($filetype, common_config('attachments', 'supported'))) {
return $filetype; return $filetype;
@ -221,16 +224,34 @@ class NewnoticeAction extends Action
} }
} }
if (isset($mimetype)) {
$filename = $this->saveFile($mimetype);
if (empty($filename)) {
$this->clientError(_('Couldn\'t save file.'));
}
$fileurl = File::url($filename);
$short_fileurl = common_shorten_url($fileurl);
$content_shortened .= ' ' . $short_fileurl;
if (mb_strlen($content_shortened) > 140) {
$this->deleteFile($filename);
$this->clientError(_('Max notice size is 140 chars, including attachment URL.'));
}
}
$notice = Notice::saveNew($user->id, $content_shortened, 'web', 1, $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
($replyto == 'false') ? null : $replyto); ($replyto == 'false') ? null : $replyto);
if (is_string($notice)) { if (is_string($notice)) {
if (isset($filename)) {
$this->deleteFile($filename);
}
$this->clientError($notice); $this->clientError($notice);
} }
if (isset($mimetype)) { if (isset($mimetype)) {
$this->storeFile($notice, $mimetype); $this->attachFile($notice, $filename, $mimetype, $short_fileurl);
} }
common_broadcast_notice($notice); common_broadcast_notice($notice);
if ($this->boolean('ajax')) { if ($this->boolean('ajax')) {
@ -256,53 +277,75 @@ class NewnoticeAction extends Action
} }
} }
function storeFile($notice, $mimetype) { function saveFile($mimetype) {
common_debug("NewnoticeAction::storeFile()"); $cur = common_current_user();
if (empty($cur)) {
$this->serverError(_('Somehow lost the login in saveFile'));
}
$basename = basename($_FILES['attach']['name']); $basename = basename($_FILES['attach']['name']);
common_debug("Basename: $basename"); $filename = File::filename($cur->getProfile(), $basename, $mimetype);
$filename = File::filename($notice->id, $basename);
common_debug("filename: $filename");
$filepath = File::path($filename); $filepath = File::path($filename);
common_debug("filepath: $filepath");
if (move_uploaded_file($_FILES['attach']['tmp_name'], $filepath)) { if (move_uploaded_file($_FILES['attach']['tmp_name'], $filepath)) {
return $filename;
$file = new File;
$file->filename = $filename;
$file->url = common_local_url('file', array('notice' => $notice->id));
common_debug("file->url =". $file->url);
$file->size = filesize($filepath);
$file->date = time();
$file->mimetype = $mimetype;
if ($file_id = $file->insert()) {
$file_redir = new File_redirection;
$file_redir->url = File::url($filename);
$file_redir->file_id = $file_id;
$file_redir->insert();
$f2p = new File_to_post;
$f2p->file_id = $file_id;
$f2p->post_id = $notice->id;
$f2p->insert();
} else {
$this->clientError(_('There was a database error while saving your file. Please try again.'));
}
} else { } else {
$this->clientError(_('File could not be moved to destination directory.')); $this->clientError(_('File could not be moved to destination directory.'));
} }
} }
function deleteFile($filename)
{
$filepath = File::path($filename);
@unlink($filepath);
}
function attachFile($notice, $filename, $mimetype, $short)
{
$file = new File;
$file->filename = $filename;
$file->url = common_local_url('file', array('notice' => $notice->id));
$filepath = File::path($filename);
$file->size = filesize($filepath);
$file->date = time();
$file->mimetype = $mimetype;
$file_id = $file->insert();
if (!$file_id) {
common_log_db_error($file, "INSERT", __FILE__);
$this->clientError(_('There was a database error while saving your file. Please try again.'));
}
$file_redir = new File_redirection;
$file_redir->url = File::url($filename);
$file_redir->file_id = $file_id;
$result = $file_redir->insert();
if (!$result) {
common_log_db_error($file_redir, "INSERT", __FILE__);
$this->clientError(_('There was a database error while saving your file. Please try again.'));
}
$f2p = new File_to_post;
$f2p->file_id = $file_id;
$f2p->post_id = $notice->id;
$f2p->insert();
if (!$result) {
common_log_db_error($f2p, "INSERT", __FILE__);
$this->clientError(_('There was a database error while saving your file. Please try again.'));
}
}
/** /**
* Show an Ajax-y error message * Show an Ajax-y error message
* *

View File

@ -209,7 +209,7 @@ class ShownoticeAction extends Action
function showContent() function showContent()
{ {
$this->elementStart('ol', array('class' => 'notices xoxo')); $this->elementStart('ol', array('class' => 'notices xoxo'));
$nli = new NoticeListItem($this->notice, $this); $nli = new SingleNoticeItem($this->notice, $this);
$nli->show(); $nli->show();
$this->elementEnd('ol'); $this->elementEnd('ol');
} }
@ -264,3 +264,29 @@ class ShownoticeAction extends Action
} }
} }
} }
class SingleNoticeItem extends NoticeListItem
{
/**
* recipe function for displaying a single notice.
*
* We overload to show attachments.
*
* @return void
*/
function show()
{
$this->showStart();
$this->showNotice();
$this->showNoticeAttachments();
$this->showNoticeInfo();
$this->showNoticeOptions();
$this->showEnd();
}
function showNoticeAttachments() {
$al = new AttachmentList($this->notice, $this->out);
$al->show();
}
}

View File

@ -124,8 +124,8 @@ class File extends Memcached_DataObject
function isRespectsQuota($user) { function isRespectsQuota($user) {
if ($_FILES['attach']['size'] > common_config('attachments', 'file_quota')) { if ($_FILES['attach']['size'] > common_config('attachments', 'file_quota')) {
return sprintf(_('No file may be larger than %d bytes ' . return sprintf(_('No file may be larger than %d bytes ' .
'and the file you sent was %d bytes. Try to upload a smaller version.'), 'and the file you sent was %d bytes. Try to upload a smaller version.'),
common_config('attachments', 'file_quota'), $_FILES['attach']['size']); common_config('attachments', 'file_quota'), $_FILES['attach']['size']);
} }
$query = "select sum(size) as total from file join file_to_post on file_to_post.file_id = file.id join notice on file_to_post.post_id = notice.id where profile_id = {$user->id} and file.url like '%/notice/%/file'"; $query = "select sum(size) as total from file join file_to_post on file_to_post.file_id = file.id join notice on file_to_post.post_id = notice.id where profile_id = {$user->id} and file.url like '%/notice/%/file'";
@ -148,44 +148,49 @@ class File extends Memcached_DataObject
// where should the file go? // where should the file go?
static function filename($notice_id, $basename) static function filename($profile, $basename, $mimetype)
{ {
return $notice_id . '-' . $basename; require_once 'MIME/Type/Extension.php';
} $mte = new MIME_Type_Extension();
$ext = $mte->getExtension($mimetype);
$nickname = $profile->nickname;
$datestamp = strftime('%Y%m%dT%H%M%S', time());
$random = strtolower(common_confirmation_code(32));
return "$nickname-$datestamp-$random.$ext";
}
static function path($filename) static function path($filename)
{ {
$dir = common_config('attachments', 'dir'); $dir = common_config('attachments', 'dir');
if ($dir[strlen($dir)-1] != '/') { if ($dir[strlen($dir)-1] != '/') {
$dir .= '/'; $dir .= '/';
} }
return $dir . $filename; return $dir . $filename;
} }
static function url($filename) static function url($filename)
{ {
$path = common_config('attachments', 'path'); $path = common_config('attachments', 'path');
if ($path[strlen($path)-1] != '/') { if ($path[strlen($path)-1] != '/') {
$path .= '/'; $path .= '/';
} }
if ($path[0] != '/') { if ($path[0] != '/') {
$path = '/'.$path; $path = '/'.$path;
} }
$server = common_config('attachments', 'server'); $server = common_config('attachments', 'server');
if (empty($server)) { if (empty($server)) {
$server = common_config('site', 'server'); $server = common_config('site', 'server');
} }
// XXX: protocol // XXX: protocol
return 'http://'.$server.$path.$filename;
}
return 'http://'.$server.$path.$filename;
}
} }

View File

@ -25,24 +25,24 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
* Table Definition for file_oembed * Table Definition for file_oembed
*/ */
class File_oembed extends Memcached_DataObject class File_oembed extends Memcached_DataObject
{ {
###START_AUTOCODE ###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */ /* the code below is auto generated do not remove the above tag */
public $__table = 'file_oembed'; // table name public $__table = 'file_oembed'; // table name
public $file_id; // int(4) primary_key not_null public $file_id; // int(4) primary_key not_null
public $version; // varchar(20) public $version; // varchar(20)
public $type; // varchar(20) public $type; // varchar(20)
public $provider; // varchar(50) public $provider; // varchar(50)
public $provider_url; // varchar(255) public $provider_url; // varchar(255)
public $width; // int(4) public $width; // int(4)
public $height; // int(4) public $height; // int(4)
public $html; // text() public $html; // text()
public $title; // varchar(255) public $title; // varchar(255)
public $author_name; // varchar(50) public $author_name; // varchar(50)
public $author_url; // varchar(255) public $author_url; // varchar(255)
public $url; // varchar(255) public $url; // varchar(255)
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */ /* Static get */
@ -51,6 +51,10 @@ class File_oembed extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */ /* the code above is auto generated do not remove the tag below */
###END_AUTOCODE ###END_AUTOCODE
function sequenceKey()
{
return array(false, false, false);
}
function _getOembed($url, $maxwidth = 500, $maxheight = 400, $format = 'json') { function _getOembed($url, $maxwidth = 500, $maxheight = 400, $format = 'json') {
$cmd = common_config('oohembed', 'endpoint') . '?url=' . urlencode($url); $cmd = common_config('oohembed', 'endpoint') . '?url=' . urlencode($url);
@ -84,4 +88,3 @@ class File_oembed extends Memcached_DataObject
} }
} }

View File

@ -25,21 +25,20 @@ require_once INSTALLDIR.'/classes/File_oembed.php';
define('USER_AGENT', 'Laconica user agent / file probe'); define('USER_AGENT', 'Laconica user agent / file probe');
/** /**
* Table Definition for file_redirection * Table Definition for file_redirection
*/ */
class File_redirection extends Memcached_DataObject class File_redirection extends Memcached_DataObject
{ {
###START_AUTOCODE ###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */ /* the code below is auto generated do not remove the above tag */
public $__table = 'file_redirection'; // table name public $__table = 'file_redirection'; // table name
public $url; // varchar(255) primary_key not_null public $url; // varchar(255) primary_key not_null
public $file_id; // int(4) public $file_id; // int(4)
public $redirections; // int(4) public $redirections; // int(4)
public $httpcode; // int(4) public $httpcode; // int(4)
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */ /* Static get */
@ -48,8 +47,6 @@ class File_redirection extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */ /* the code above is auto generated do not remove the tag below */
###END_AUTOCODE ###END_AUTOCODE
function _commonCurl($url, $redirs) { function _commonCurl($url, $redirs) {
$curlh = curl_init(); $curlh = curl_init();
curl_setopt($curlh, CURLOPT_URL, $url); curl_setopt($curlh, CURLOPT_URL, $url);
@ -86,8 +83,6 @@ class File_redirection extends Memcached_DataObject
return $url; return $url;
} }
$curlh = File_redirection::_commonCurl($short_url, $redirs); $curlh = File_redirection::_commonCurl($short_url, $redirs);
// Don't include body in output // Don't include body in output
curl_setopt($curlh, CURLOPT_NOBODY, true); curl_setopt($curlh, CURLOPT_NOBODY, true);
@ -143,62 +138,7 @@ class File_redirection extends Memcached_DataObject
} }
function _userMakeShort($long_url, $user) { function _userMakeShort($long_url, $user) {
if (empty($user)) { $short_url = common_shorten_url($long_url);
// common current user does not find a user when called from the XMPP daemon
// therefore we'll set one here fix, so that XMPP given URLs may be shortened
$user->urlshorteningservice = 'ur1.ca';
}
$curlh = curl_init();
curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait
curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica');
curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);
switch($user->urlshorteningservice) {
case 'ur1.ca':
require_once INSTALLDIR.'/lib/Shorturl_api.php';
$short_url_service = new LilUrl;
$short_url = $short_url_service->shorten($long_url);
break;
case '2tu.us':
$short_url_service = new TightUrl;
require_once INSTALLDIR.'/lib/Shorturl_api.php';
$short_url = $short_url_service->shorten($long_url);
break;
case 'ptiturl.com':
require_once INSTALLDIR.'/lib/Shorturl_api.php';
$short_url_service = new PtitUrl;
$short_url = $short_url_service->shorten($long_url);
break;
case 'bit.ly':
curl_setopt($curlh, CURLOPT_URL, 'http://bit.ly/api?method=shorten&long_url='.urlencode($long_url));
$short_url = current(json_decode(curl_exec($curlh))->results)->hashUrl;
break;
case 'is.gd':
curl_setopt($curlh, CURLOPT_URL, 'http://is.gd/api.php?longurl='.urlencode($long_url));
$short_url = curl_exec($curlh);
break;
case 'snipr.com':
curl_setopt($curlh, CURLOPT_URL, 'http://snipr.com/site/snip?r=simple&link='.urlencode($long_url));
$short_url = curl_exec($curlh);
break;
case 'metamark.net':
curl_setopt($curlh, CURLOPT_URL, 'http://metamark.net/api/rest/simple?long_url='.urlencode($long_url));
$short_url = curl_exec($curlh);
break;
case 'tinyurl.com':
curl_setopt($curlh, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url='.urlencode($long_url));
$short_url = curl_exec($curlh);
break;
default:
$short_url = false;
}
curl_close($curlh);
if ($short_url) { if ($short_url) {
$short_url = (string)$short_url; $short_url = (string)$short_url;
// store it // store it

View File

@ -25,7 +25,7 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
* Table Definition for file_thumbnail * Table Definition for file_thumbnail
*/ */
class File_thumbnail extends Memcached_DataObject class File_thumbnail extends Memcached_DataObject
{ {
###START_AUTOCODE ###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */ /* the code below is auto generated do not remove the above tag */
@ -33,8 +33,8 @@ class File_thumbnail extends Memcached_DataObject
public $__table = 'file_thumbnail'; // table name public $__table = 'file_thumbnail'; // table name
public $file_id; // int(4) primary_key not_null public $file_id; // int(4) primary_key not_null
public $url; // varchar(255) unique_key public $url; // varchar(255) unique_key
public $width; // int(4) public $width; // int(4)
public $height; // int(4) public $height; // int(4)
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */ /* Static get */
@ -43,6 +43,11 @@ class File_thumbnail extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */ /* the code above is auto generated do not remove the tag below */
###END_AUTOCODE ###END_AUTOCODE
function sequenceKey()
{
return array(false, false, false);
}
function saveNew($data, $file_id) { function saveNew($data, $file_id) {
$tn = new File_thumbnail; $tn = new File_thumbnail;
$tn->file_id = $file_id; $tn->file_id = $file_id;

2
db/innodb.sql Normal file
View File

@ -0,0 +1,2 @@
alter table profile drop index nickname, engine=InnoDB;
alter table notice drop index content, engine=InnoDB;

290
extlib/Console/Getopt.php Normal file
View File

@ -0,0 +1,290 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP Version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Andrei Zmievski <andrei@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: Getopt.php,v 1.4 2007/06/12 14:58:56 cellog Exp $
require_once 'PEAR.php';
/**
* Command-line options parsing class.
*
* @author Andrei Zmievski <andrei@php.net>
*
*/
class Console_Getopt {
/**
* Parses the command-line options.
*
* The first parameter to this function should be the list of command-line
* arguments without the leading reference to the running program.
*
* The second parameter is a string of allowed short options. Each of the
* option letters can be followed by a colon ':' to specify that the option
* requires an argument, or a double colon '::' to specify that the option
* takes an optional argument.
*
* The third argument is an optional array of allowed long options. The
* leading '--' should not be included in the option name. Options that
* require an argument should be followed by '=', and options that take an
* option argument should be followed by '=='.
*
* The return value is an array of two elements: the list of parsed
* options and the list of non-option command-line arguments. Each entry in
* the list of parsed options is a pair of elements - the first one
* specifies the option, and the second one specifies the option argument,
* if there was one.
*
* Long and short options can be mixed.
*
* Most of the semantics of this function are based on GNU getopt_long().
*
* @param array $args an array of command-line arguments
* @param string $short_options specifies the list of allowed short options
* @param array $long_options specifies the list of allowed long options
*
* @return array two-element array containing the list of parsed options and
* the non-option arguments
*
* @access public
*
*/
function getopt2($args, $short_options, $long_options = null)
{
return Console_Getopt::doGetopt(2, $args, $short_options, $long_options);
}
/**
* This function expects $args to start with the script name (POSIX-style).
* Preserved for backwards compatibility.
* @see getopt2()
*/
function getopt($args, $short_options, $long_options = null)
{
return Console_Getopt::doGetopt(1, $args, $short_options, $long_options);
}
/**
* The actual implementation of the argument parsing code.
*/
function doGetopt($version, $args, $short_options, $long_options = null)
{
// in case you pass directly readPHPArgv() as the first arg
if (PEAR::isError($args)) {
return $args;
}
if (empty($args)) {
return array(array(), array());
}
$opts = array();
$non_opts = array();
settype($args, 'array');
if ($long_options) {
sort($long_options);
}
/*
* Preserve backwards compatibility with callers that relied on
* erroneous POSIX fix.
*/
if ($version < 2) {
if (isset($args[0]{0}) && $args[0]{0} != '-') {
array_shift($args);
}
}
reset($args);
while (list($i, $arg) = each($args)) {
/* The special element '--' means explicit end of
options. Treat the rest of the arguments as non-options
and end the loop. */
if ($arg == '--') {
$non_opts = array_merge($non_opts, array_slice($args, $i + 1));
break;
}
if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$long_options)) {
$non_opts = array_merge($non_opts, array_slice($args, $i));
break;
} elseif (strlen($arg) > 1 && $arg{1} == '-') {
$error = Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args);
if (PEAR::isError($error))
return $error;
} elseif ($arg == '-') {
// - is stdin
$non_opts = array_merge($non_opts, array_slice($args, $i));
break;
} else {
$error = Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args);
if (PEAR::isError($error))
return $error;
}
}
return array($opts, $non_opts);
}
/**
* @access private
*
*/
function _parseShortOption($arg, $short_options, &$opts, &$args)
{
for ($i = 0; $i < strlen($arg); $i++) {
$opt = $arg{$i};
$opt_arg = null;
/* Try to find the short option in the specifier string. */
if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':')
{
return PEAR::raiseError("Console_Getopt: unrecognized option -- $opt");
}
if (strlen($spec) > 1 && $spec{1} == ':') {
if (strlen($spec) > 2 && $spec{2} == ':') {
if ($i + 1 < strlen($arg)) {
/* Option takes an optional argument. Use the remainder of
the arg string if there is anything left. */
$opts[] = array($opt, substr($arg, $i + 1));
break;
}
} else {
/* Option requires an argument. Use the remainder of the arg
string if there is anything left. */
if ($i + 1 < strlen($arg)) {
$opts[] = array($opt, substr($arg, $i + 1));
break;
} else if (list(, $opt_arg) = each($args)) {
/* Else use the next argument. */;
if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
}
} else {
return PEAR::raiseError("Console_Getopt: option requires an argument -- $opt");
}
}
}
$opts[] = array($opt, $opt_arg);
}
}
/**
* @access private
*
*/
function _isShortOpt($arg)
{
return strlen($arg) == 2 && $arg[0] == '-' && preg_match('/[a-zA-Z]/', $arg[1]);
}
/**
* @access private
*
*/
function _isLongOpt($arg)
{
return strlen($arg) > 2 && $arg[0] == '-' && $arg[1] == '-' &&
preg_match('/[a-zA-Z]+$/', substr($arg, 2));
}
/**
* @access private
*
*/
function _parseLongOption($arg, $long_options, &$opts, &$args)
{
@list($opt, $opt_arg) = explode('=', $arg, 2);
$opt_len = strlen($opt);
for ($i = 0; $i < count($long_options); $i++) {
$long_opt = $long_options[$i];
$opt_start = substr($long_opt, 0, $opt_len);
$long_opt_name = str_replace('=', '', $long_opt);
/* Option doesn't match. Go on to the next one. */
if ($long_opt_name != $opt) {
continue;
}
$opt_rest = substr($long_opt, $opt_len);
/* Check that the options uniquely matches one of the allowed
options. */
if ($i + 1 < count($long_options)) {
$next_option_rest = substr($long_options[$i + 1], $opt_len);
} else {
$next_option_rest = '';
}
if ($opt_rest != '' && $opt{0} != '=' &&
$i + 1 < count($long_options) &&
$opt == substr($long_options[$i+1], 0, $opt_len) &&
$next_option_rest != '' &&
$next_option_rest{0} != '=') {
return PEAR::raiseError("Console_Getopt: option --$opt is ambiguous");
}
if (substr($long_opt, -1) == '=') {
if (substr($long_opt, -2) != '==') {
/* Long option requires an argument.
Take the next argument if one wasn't specified. */;
if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
return PEAR::raiseError("Console_Getopt: option --$opt requires an argument");
}
if (Console_Getopt::_isShortOpt($opt_arg) || Console_Getopt::_isLongOpt($opt_arg)) {
return PEAR::raiseError("Console_Getopt: option requires an argument --$opt");
}
}
} else if ($opt_arg) {
return PEAR::raiseError("Console_Getopt: option --$opt doesn't allow an argument");
}
$opts[] = array('--' . $opt, $opt_arg);
return;
}
return PEAR::raiseError("Console_Getopt: unrecognized option --$opt");
}
/**
* Safely read the $argv PHP array across different PHP configurations.
* Will take care on register_globals and register_argc_argv ini directives
*
* @access public
* @return mixed the $argv PHP array or PEAR error if not registered
*/
function readPHPArgv()
{
global $argv;
if (!is_array($argv)) {
if (!@is_array($_SERVER['argv'])) {
if (!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) {
return PEAR::raiseError("Console_Getopt: Could not read cmd args (register_argc_argv=Off?)");
}
return $GLOBALS['HTTP_SERVER_VARS']['argv'];
}
return $_SERVER['argv'];
}
return $argv;
}
}
?>

587
extlib/System/Command.php Normal file
View File

@ -0,0 +1,587 @@
<?php
// {{{ license
// +----------------------------------------------------------------------+
// | PHP Version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Anders Johannsen <anders@johannsen.com> |
// | Author: Dan Allen <dan@mojavelinux.com>
// +----------------------------------------------------------------------+
// $Id: Command.php,v 1.9 2007/04/20 21:08:48 cconstantine Exp $
// }}}
// {{{ includes
require_once 'PEAR.php';
require_once 'System.php';
// }}}
// {{{ constants
define('SYSTEM_COMMAND_OK', 1);
define('SYSTEM_COMMAND_ERROR', -1);
define('SYSTEM_COMMAND_NO_SHELL', -2);
define('SYSTEM_COMMAND_INVALID_SHELL', -3);
define('SYSTEM_COMMAND_TMPDIR_ERROR', -4);
define('SYSTEM_COMMAND_INVALID_OPERATOR', -5);
define('SYSTEM_COMMAND_INVALID_COMMAND', -6);
define('SYSTEM_COMMAND_OPERATOR_PLACEMENT',-7);
define('SYSTEM_COMMAND_COMMAND_PLACEMENT', -8);
define('SYSTEM_COMMAND_NOHUP_MISSING', -9);
define('SYSTEM_COMMAND_NO_OUTPUT', -10);
define('SYSTEM_COMMAND_STDERR', -11);
define('SYSTEM_COMMAND_NONZERO_EXIT', -12);
// }}}
// {{{ class System_Command
/**
* The System_Command:: class implements an abstraction for various ways
* of executing commands (directly using the backtick operator,
* as a background task after the script has terminated using
* register_shutdown_function() or as a detached process using nohup).
*
* @author Anders Johannsen <anders@johannsen.com>
* @author Dan Allen <dan@mojavelinux.com>
* @version $Revision: 1.9 $
*/
// }}}
class System_Command {
// {{{ properties
/**
* Array of settings used when creating the shell command
*
* @var array
* @access private
*/
var $options = array();
/**
* Array of available shells to use to execute the command
*
* @var array
* @access private
*/
var $shells = array();
/**
* Array of available control operators used between commands
*
* @var array
* @access private
*/
var $controlOperators = array();
/**
* The system command to be executed
*
* @var string
* @access private
*/
var $systemCommand = null;
/**
* Previously added part to the command string
*
* @var string
* @access private
*/
var $previousElement = null;
/**
* Directory for writing stderr output
*
* @var string
* @access private
*/
var $tmpDir = null;
/**
* To allow the pear error object to accumulate when building
* the command, we use the command status to keep track when
* a pear error is raised
*
* @var int
* @access private
*/
var $commandStatus = 0;
/**
* Hold initialization PEAR_Error
*
* @var object
* @access private
**/
var $_initError = null;
// }}}
// {{{ constructor
/**
* Class constructor
*
* Defines all necessary constants and sets defaults
*
* @access public
*/
function System_Command($in_shell = null)
{
// Defining constants
$this->options = array(
'SEQUENCE' => true,
'SHUTDOWN' => false,
'SHELL' => $this->which($in_shell),
'OUTPUT' => true,
'NOHUP' => false,
'BACKGROUND' => false,
'STDERR' => false
);
// prepare the available control operators
$this->controlOperators = array(
'PIPE' => '|',
'AND' => '&&',
'OR' => '||',
'GROUP' => ';',
'LFIFO' => '<',
'RFIFO' => '>',
);
// List of allowed/available shells
$this->shells = array(
'sh',
'bash',
'zsh',
'tcsh',
'csh',
'ash',
'sash',
'esh',
'ksh'
);
// Find the first available shell
if (empty($this->options['SHELL'])) {
foreach ($this->shells as $shell) {
if ($this->options['SHELL'] = $this->which($shell)) {
break;
}
}
// see if we still have no shell
if (empty($this->options['SHELL'])) {
$this->_initError =& PEAR::raiseError(null, SYSTEM_COMMAND_NO_SHELL, null, E_USER_WARNING, null, 'System_Command_Error', true);
return;
}
}
// Caputre a temporary directory for capturing stderr from commands
$this->tmpDir = System::tmpdir();
if (!System::mkDir("-p {$this->tmpDir}")) {
$this->_initError =& PEAR::raiseError(null, SYSTEM_COMMAND_TMPDIR_ERROR, null, E_USER_WARNING, null, 'System_Command_Error', true);
return;
}
}
// }}}
// {{{ setOption()
/**
* Sets the value for an option. Each option should be set to true
* or false; except the 'SHELL' option which should be a string
* naming a shell. The options are:
*
* 'SEQUENCE' Allow a sequence command or not (right now this is always on);
*
* 'SHUTDOWN' Execute commands via a shutdown function;
*
* 'SHELL' Path to shell;
*
* 'OUTPUT' Output stdout from process;
*
* 'NOHUP' Use nohup to detach process;
*
* 'BACKGROUND' Run as a background process with &;
*
* 'STDERR' Output on stderr will raise an error, even if
* the command's exit value is zero. The output from
* stderr can be retrieved using the getDebugInfo()
* method of the Pear_ERROR object returned by
* execute().;
*
* @param string $in_option is a case-sensitive string,
* corresponding to the option
* that should be changed
* @param mixed $in_setting is the new value for the option
* @access public
* @return bool true if succes, else false
*/
function setOption($in_option, $in_setting)
{
if ($this->_initError) {
return $this->_initError;
}
$option = strtoupper($in_option);
if (!isset($this->options[$option])) {
PEAR::raiseError(null, SYSTEM_COMMAND_ERROR, null, E_USER_NOTICE, null, 'System_Command_Error', true);
return false;
}
switch ($option) {
case 'OUTPUT':
case 'SHUTDOWN':
case 'SEQUENCE':
case 'BACKGROUND':
case 'STDERR':
$this->options[$option] = !empty($in_setting);
return true;
break;
case 'SHELL':
if (($shell = $this->which($in_setting)) !== false) {
$this->options[$option] = $shell;
return true;
}
else {
PEAR::raiseError(null, SYSTEM_COMMAND_NO_SHELL, null, E_USER_NOTICE, $in_setting, 'System_Command_Error', true);
return false;
}
break;
case 'NOHUP':
if (empty($in_setting)) {
$this->options[$option] = false;
}
else if ($location = $this->which('nohup')) {
$this->options[$option] = $location;
}
else {
PEAR::raiseError(null, SYSTEM_COMMAND_NOHUP_MISSING, null, E_USER_NOTICE, null, 'System_Command_Error', true);
return false;
}
break;
}
}
// }}}
// {{{ pushCommand()
/**
* Used to push a command onto the running command to be executed
*
* @param string $in_command binary to be run
* @param string $in_argument either an option or argument value, to be handled appropriately
* @param string $in_argument
* @param ...
*
* @access public
* @return boolean true on success {or System_Command_Error Exception}
*/
function pushCommand($in_command)
{
if ($this->_initError) {
return $this->_initError;
}
if (!is_null($this->previousElement) && !in_array($this->previousElement, $this->controlOperators)) {
$this->commandStatus = -1;
$error = PEAR::raiseError(null, SYSTEM_COMMAND_COMMAND_PLACEMENT, null, E_USER_WARNING, null, 'System_Command_Error', true);
}
// check for error here
$command = escapeshellcmd($this->which($in_command));
if ($command === false) {
$error = PEAR::raiseError(null, SYSTEM_COMMAND_INVALID_COMMAND, null, E_USER_WARNING, null, 'System_Command_Error', true);
}
$argv = func_get_args();
array_shift($argv);
foreach($argv as $arg) {
if (strpos($arg, '-') === 0) {
$command .= ' ' . $arg;
}
elseif ($arg != '') {
$command .= ' ' . escapeshellarg($arg);
}
}
$this->previousElement = $command;
$this->systemCommand .= $command;
return isset($error) ? $error : true;
}
// }}}
// {{{ pushOperator()
/**
* Used to push an operator onto the running command to be executed
*
* @param string $in_operator Either string reprentation of operator or system character
*
* @access public
* @return boolean true on success {or System_Command_Error Exception}
*/
function pushOperator($in_operator)
{
if ($this->_initError) {
return $this->_initError;
}
$operator = isset($this->controlOperators[$in_operator]) ? $this->controlOperators[$in_operator] : $in_operator;
if (is_null($this->previousElement) || in_array($this->previousElement, $this->controlOperators)) {
$this->commandStatus = -1;
$error = PEAR::raiseError(null, SYSTEM_COMMAND_OPERATOR_PLACEMENT, null, E_USER_WARNING, null, 'System_Command_Error', true);
}
elseif (!in_array($operator, $this->controlOperators)) {
$this->commandStatus = -1;
$error = PEAR::raiseError(null, SYSTEM_COMMAND_INVALID_OPERATOR, null, E_USER_WARNING, $operator, 'System_Command_Error', true);
}
$this->previousElement = $operator;
$this->systemCommand .= ' ' . $operator . ' ';
return isset($error) ? $error : true;
}
// }}}
// {{{ execute()
/**
* Executes the code according to given options
*
* @return bool true if success {or System_Command_Exception}
*
* @access public
*/
function execute()
{
if ($this->_initError) {
return $this->_initError;
}
// if the command is empty or if the last element was a control operator, we can't continue
if (is_null($this->previousElement) || $this->commandStatus == -1 || in_array($this->previousElement, $this->controlOperators)) {
return PEAR::raiseError(null, SYSTEM_COMMAND_INVALID_COMMAND, null, E_USER_WARNING, $this->systemCommand, 'System_Command_Error', true);
}
// Warning about impossible mix of options
if (!empty($this->options['OUTPUT'])) {
if (!empty($this->options['SHUTDOWN']) || !empty($this->options['NOHUP'])) {
return PEAR::raiseError(null, SYSTEM_COMMAND_NO_OUTPUT, null, E_USER_WARNING, null, 'System_Command_Error', true);
}
}
// if this is not going to stdout, then redirect to /dev/null
if (empty($this->options['OUTPUT'])) {
$this->systemCommand .= ' >/dev/null';
}
$suffix = '';
// run a command immune to hangups, with output to a non-tty
if (!empty($this->options['NOHUP'])) {
$this->systemCommand = $this->options['NOHUP'] . $this->systemCommand;
}
// run a background process (only if not nohup)
elseif (!empty($this->options['BACKGROUND'])) {
$suffix = ' &';
}
// Register to be run on shutdown
if (!empty($this->options['SHUTDOWN'])) {
$line = "system(\"{$this->systemCommand}$suffix\");";
$function = create_function('', $line);
register_shutdown_function($function);
return true;
}
else {
// send stderr to a file so that we can reap the error message
$tmpFile = tempnam($this->tmpDir, 'System_Command-');
$this->systemCommand .= ' 2>' . $tmpFile . $suffix;
$shellPipe = $this->which('echo') . ' ' . escapeshellarg($this->systemCommand) . ' | ' . $this->options['SHELL'];
exec($shellPipe, $result, $returnVal);
if ($returnVal !== 0) {
// command returned nonzero; that's always an error
$return = PEAR::raiseError(null, SYSTEM_COMMAND_NONZERO_EXIT, null, E_USER_WARNING, null, 'System_Command_Error', true);
}
else if (!$this->options['STDERR']) {
// caller does not care about stderr; return success
$return = implode("\n", $result);
}
else {
// our caller cares about stderr; check stderr output
clearstatcache();
if (filesize($tmpFile) > 0) {
// the command actually wrote to stderr
$stderr_output = file_get_contents($tmpFile);
$return = PEAR::raiseError(null, SYSTEM_COMMAND_STDERR, null, E_USER_WARNING, $stderr_output, 'System_Command_Error', true);
} else {
// total success; return stdout gathered by exec()
$return = implode("\n", $result);
}
}
unlink($tmpFile);
return $return;
}
}
// }}}
// {{{ which()
/**
* Functionality similiar to unix 'which'. Searches the path
* for the specified program.
*
* @param $cmd name of the executable to search for
*
* @access private
* @return string returns the full path if found, false if not
*/
function which($in_cmd)
{
// only pass non-empty strings to System::which()
if (!is_string($in_cmd) || '' === $in_cmd) {
return(false);
}
// explicitly pass false as fallback value
return System::which($in_cmd, false);
}
// }}}
// {{{ reset()
/**
* Prepare for a new command to be built
*
* @access public
* @return void
*/
function reset()
{
$this->previousElement = null;
$this->systemCommand = null;
$this->commandStatus = 0;
}
// }}}
// {{{ errorMessage()
/**
* Return a textual error message for a System_Command error code
*
* @param integer error code
*
* @return string error message, or false if the error code was
* not recognized
*/
function errorMessage($in_value)
{
static $errorMessages;
if (!isset($errorMessages)) {
$errorMessages = array(
SYSTEM_COMMAND_OK => 'no error',
SYSTEM_COMMAND_ERROR => 'unknown error',
SYSTEM_COMMAND_NO_SHELL => 'no shell found',
SYSTEM_COMMAND_INVALID_SHELL => 'invalid shell',
SYSTEM_COMMAND_TMPDIR_ERROR => 'could not create temporary directory',
SYSTEM_COMMAND_INVALID_OPERATOR => 'control operator invalid',
SYSTEM_COMMAND_INVALID_COMMAND => 'invalid system command',
SYSTEM_COMMAND_OPERATOR_PLACEMENT => 'invalid placement of control operator',
SYSTEM_COMMAND_COMMAND_PLACEMENT => 'invalid placement of command',
SYSTEM_COMMAND_NOHUP_MISSING => 'nohup not found on system',
SYSTEM_COMMAND_NO_OUTPUT => 'output not allowed',
SYSTEM_COMMAND_STDERR => 'command wrote to stderr',
SYSTEM_COMMAND_NONZERO_EXIT => 'non-zero exit value from command',
);
}
if (System_Command::isError($in_value)) {
$in_value = $in_value->getCode();
}
return isset($errorMessages[$in_value]) ? $errorMessages[$in_value] : $errorMessages[SYSTEM_COMMAND_ERROR];
}
// }}}
// {{{ isError()
/**
* Tell whether a result code from a System_Command method is an error
*
* @param int result code
*
* @return bool whether $in_value is an error
*
* @access public
*/
function isError($in_value)
{
return (is_object($in_value) &&
(strtolower(get_class($in_value)) == 'system_command_error' ||
is_subclass_of($in_value, 'system_command_error')));
}
// }}}
}
// {{{ class System_Command_Error
/**
* System_Command_Error constructor.
*
* @param mixed System_Command error code, or string with error message.
* @param integer what "error mode" to operate in
* @param integer what error level to use for $mode & PEAR_ERROR_TRIGGER
* @param mixed additional debug info, such as the last query
*
* @access public
*
* @see PEAR_Error
*/
// }}}
class System_Command_Error extends PEAR_Error
{
// {{{ properties
/**
* Message in front of the error message
* @var string $error_message_prefix
*/
var $error_message_prefix = 'System_Command Error: ';
// }}}
// {{{ constructor
function System_Command_Error($code = SYSTEM_COMMAND_ERROR, $mode = PEAR_ERROR_RETURN,
$level = E_USER_NOTICE, $debuginfo = null)
{
if (is_int($code)) {
$this->PEAR_Error(System_Command::errorMessage($code), $code, $mode, $level, $debuginfo);
} else {
$this->PEAR_Error("Invalid error code: $code", SYSTEM_COMMAND_ERROR, $mode, $level, $debuginfo);
}
}
// }}}
}
?>

View File

@ -217,6 +217,7 @@ $(document).ready(function(){
$('#'+li.id).css({display:'none'}); $('#'+li.id).css({display:'none'});
$('#'+li.id).fadeIn(2500); $('#'+li.id).fadeIn(2500);
NoticeReply(); NoticeReply();
NoticeAttachments();
} }
} }
$("#notice_data-text").val(""); $("#notice_data-text").val("");

View File

@ -67,14 +67,25 @@ function _sn_to_path($sn)
return $p; return $p;
} }
// try to figure out where we are // try to figure out where we are. $server and $path
// can be set by including module, else we guess based
// on HTTP info.
$_server = array_key_exists('SERVER_NAME', $_SERVER) ? if (isset($server)) {
strtolower($_SERVER['SERVER_NAME']) : $_server = $server;
null; } else {
$_path = array_key_exists('SCRIPT_NAME', $_SERVER) ? $_server = array_key_exists('SERVER_NAME', $_SERVER) ?
_sn_to_path($_SERVER['SCRIPT_NAME']) : strtolower($_SERVER['SERVER_NAME']) :
null; null;
}
if (isset($path)) {
$_path = $path;
} else {
$_path = array_key_exists('SCRIPT_NAME', $_SERVER) ?
_sn_to_path($_SERVER['SCRIPT_NAME']) :
null;
}
// default configuration, overwritten in config.php // default configuration, overwritten in config.php
@ -84,9 +95,9 @@ $config =
'server' => $_server, 'server' => $_server,
'theme' => 'default', 'theme' => 'default',
'design' => 'design' =>
array('backgroundcolor' => '#F0F2F5', array('backgroundcolor' => '#CEE1E9',
'contentcolor' => '#FFFFFF', 'contentcolor' => '#FFFFFF',
'sidebarcolor' => '#CEE1E9', 'sidebarcolor' => '#C8D1D5',
'textcolor' => '#000000', 'textcolor' => '#000000',
'linkcolor' => '#002E6E', 'linkcolor' => '#002E6E',
'backgroundimage' => null, 'backgroundimage' => null,
@ -191,7 +202,7 @@ $config =
array('run' => 'web', array('run' => 'web',
'frequency' => 10000, 'frequency' => 10000,
'reporturl' => 'http://laconi.ca/stats/report'), 'reporturl' => 'http://laconi.ca/stats/report'),
'attachments' => 'attachments' =>
array('server' => null, array('server' => null,
'dir' => INSTALLDIR . '/file/', 'dir' => INSTALLDIR . '/file/',
'path' => $_path . '/file/', 'path' => $_path . '/file/',
@ -230,6 +241,7 @@ $config =
'user_quota' => 50000000, 'user_quota' => 50000000,
'monthly_quota' => 15000000, 'monthly_quota' => 15000000,
'uploads' => true, 'uploads' => true,
'filecommand' => '/usr/bin/file',
), ),
'group' => 'group' =>
array('maxaliases' => 3), array('maxaliases' => 3),
@ -261,15 +273,19 @@ if (function_exists('date_default_timezone_set')) {
// server-wide, then vhost-wide, then for a path, // server-wide, then vhost-wide, then for a path,
// finally for a dir (usually only need one of the last two). // finally for a dir (usually only need one of the last two).
$_config_files = array('/etc/laconica/laconica.php', if (isset($conffile)) {
'/etc/laconica/'.$_server.'.php'); $_config_files = array($conffile);
} else {
$_config_files = array('/etc/laconica/laconica.php',
'/etc/laconica/'.$_server.'.php');
if (strlen($_path) > 0) { if (strlen($_path) > 0) {
$_config_files[] = '/etc/laconica/'.$_server.'_'.$_path.'.php'; $_config_files[] = '/etc/laconica/'.$_server.'_'.$_path.'.php';
}
$_config_files[] = INSTALLDIR.'/config.php';
} }
$_config_files[] = INSTALLDIR.'/config.php';
$_have_a_config = false; $_have_a_config = false;
foreach ($_config_files as $_config_file) { foreach ($_config_files as $_config_file) {

View File

@ -179,7 +179,6 @@ class NoticeListItem extends Widget
{ {
$this->showStart(); $this->showStart();
$this->showNotice(); $this->showNotice();
$this->showNoticeAttachments();
$this->showNoticeInfo(); $this->showNoticeInfo();
$this->showNoticeOptions(); $this->showNoticeOptions();
$this->showEnd(); $this->showEnd();
@ -193,18 +192,6 @@ class NoticeListItem extends Widget
$this->out->elementEnd('div'); $this->out->elementEnd('div');
} }
function showNoticeAttachments() {
if ($this->isUsedInList()) {
return;
}
$al = new AttachmentList($this->notice, $this->out);
$al->show();
}
function isUsedInList() {
return 'shownotice' !== $this->out->args['action'];
}
function showNoticeInfo() function showNoticeInfo()
{ {
$this->out->elementStart('div', 'entry-content'); $this->out->elementStart('div', 'entry-content');
@ -349,10 +336,6 @@ class NoticeListItem extends Widget
// versions (>> 0.4.x) // versions (>> 0.4.x)
$this->out->raw(common_render_content($this->notice->content, $this->notice)); $this->out->raw(common_render_content($this->notice->content, $this->notice));
} }
$uploaded = $this->notice->getUploadedAttachment();
if ($uploaded) {
$this->out->element('a', array('href' => $uploaded[0], 'class' => 'attachment', 'id' => 'attachment-' . $uploaded[1]), $uploaded[0]);
}
$this->out->elementEnd('p'); $this->out->elementEnd('p');
} }

View File

@ -1377,3 +1377,68 @@ function common_database_tablename($tablename)
//table prefixes could be added here later //table prefixes could be added here later
return $tablename; return $tablename;
} }
function common_shorten_url($long_url)
{
$user = common_current_user();
if (empty($user)) {
// common current user does not find a user when called from the XMPP daemon
// therefore we'll set one here fix, so that XMPP given URLs may be shortened
$svc = 'ur1.ca';
} else {
$svc = $user->urlshorteningservice;
}
$curlh = curl_init();
curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait
curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica');
curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);
switch($svc) {
case 'ur1.ca':
require_once INSTALLDIR.'/lib/Shorturl_api.php';
$short_url_service = new LilUrl;
$short_url = $short_url_service->shorten($long_url);
break;
case '2tu.us':
$short_url_service = new TightUrl;
require_once INSTALLDIR.'/lib/Shorturl_api.php';
$short_url = $short_url_service->shorten($long_url);
break;
case 'ptiturl.com':
require_once INSTALLDIR.'/lib/Shorturl_api.php';
$short_url_service = new PtitUrl;
$short_url = $short_url_service->shorten($long_url);
break;
case 'bit.ly':
curl_setopt($curlh, CURLOPT_URL, 'http://bit.ly/api?method=shorten&long_url='.urlencode($long_url));
$short_url = current(json_decode(curl_exec($curlh))->results)->hashUrl;
break;
case 'is.gd':
curl_setopt($curlh, CURLOPT_URL, 'http://is.gd/api.php?longurl='.urlencode($long_url));
$short_url = curl_exec($curlh);
break;
case 'snipr.com':
curl_setopt($curlh, CURLOPT_URL, 'http://snipr.com/site/snip?r=simple&link='.urlencode($long_url));
$short_url = curl_exec($curlh);
break;
case 'metamark.net':
curl_setopt($curlh, CURLOPT_URL, 'http://metamark.net/api/rest/simple?long_url='.urlencode($long_url));
$short_url = curl_exec($curlh);
break;
case 'tinyurl.com':
curl_setopt($curlh, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url='.urlencode($long_url));
$short_url = curl_exec($curlh);
break;
default:
$short_url = false;
}
curl_close($curlh);
return $short_url;
}

40
scripts/allsites.php Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env php
<?php
/*
* Laconica - a distributed open-source microblogging tool
* Copyright (C) 2009, Control Yourself, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
# Abort if called from a web server
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
$helptext = <<<ENDOFHELP
allsites.php - list all sites configured for multi-site use
returns the nickname of each site configured for multi-site use
ENDOFHELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
$sn = new Status_network();
if ($sn->find()) {
while ($sn->fetch()) {
print "$sn->nickname\n";
}
}

138
scripts/commandline.inc Normal file
View File

@ -0,0 +1,138 @@
<?php
/*
* Laconica - a distributed open-source microblogging tool
* Copyright (C) 2008, 2009, Control Yourself, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// -*- mode: php -*-
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
print "This script must be run from the command line\n";
exit();
}
define('LACONICA', true);
// Set various flags so we don't time out on long-running processes
ini_set("max_execution_time", "0");
ini_set("max_input_time", "0");
set_time_limit(0);
mb_internal_encoding('UTF-8');
// Add extlib to our path so we can get Console_Getopt
$_extra_path = array(INSTALLDIR.'/extlib/');
set_include_path(implode(PATH_SEPARATOR, $_extra_path) . PATH_SEPARATOR . get_include_path());
require_once 'Console/Getopt.php';
// Note: $shortoptions and $longoptions should be pre-defined!
$_default_shortoptions = 'qvhc:s:p:';
$_default_longoptions = array('quiet', 'verbose', 'help', 'conf=', 'server=', 'path=');
if (isset($shortoptions)) {
$shortoptions .= $_default_shortoptions;
} else {
$shortoptions = $_default_shortoptions;
}
if (isset($longoptions)) {
$longoptions = array_merge($longoptions, $_default_longoptions);
} else {
$longoptions = $_default_longoptions;
}
$parser = new Console_Getopt();
list($options, $args) = $parser->getopt($argv, $shortoptions, $longoptions);
function show_help()
{
global $helptext;
$_default_help_text = <<<END_OF_DEFAULT
General options:
-q --quiet Quiet (little output)
-v --verbose Verbose (lots of output)
-c --conf=<filename> Use <filename> as config file
-s --server=<name> Use <name> as server name
-p --path=<path> Use <path> as path name
-h --help Show this message and quit.
END_OF_DEFAULT;
if (isset($helptext)) {
print $helptext;
}
print $_default_help_text;
exit(0);
}
foreach ($options as $option) {
switch ($option[0]) {
case '--server':
case 's':
$server = $option[1];
break;
case '--path':
case 'p':
$path = $option[1];
break;
case '--conf':
case 'c':
$conffile = $option[1];
break;
case '--help':
case 'h':
show_help();
}
}
require_once INSTALLDIR . '/lib/common.php';
set_error_handler('common_error_handler');
function have_option($str)
{
global $options;
foreach ($options as $option) {
if ($option[0] == $str) {
return true;
}
}
return false;
}
function get_option_value($str)
{
global $options;
foreach ($options as $option) {
if ($option[0] == $str) {
return $option[1];
}
}
return null;
}

View File

@ -18,35 +18,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $helptext = <<<ENDOFHELP
USAGE: decache.php <table> <id> [<column>]
Clears the cache for the object in table <table> with id <id>
If <column> is specified, use that instead of 'id'
ENDOFHELP;
if ($argc < 3 || $argc > 4) { require_once INSTALLDIR.'/scripts/commandline.inc';
print "USAGE: decache.php <table> <id> [<column>]\n";
print "Clears the cache for the object in table <table> with id <id>.\n\n"; if (count($args) < 2 || count($args) > 3) {
print "If <column> is specified, use that instead of 'id'\n"; show_help();
exit(1);
} }
$table = $argv[1]; $table = $args[0];
$id = $argv[2]; $id = $args[1];
if ($argc > 3) { if (count($args) > 2) {
$column = $argv[3]; $column = $args[2];
} else { } else {
$colum = 'id'; $column = 'id';
} }
$object = Memcached_DataObject::staticGet($table, $column, $id); $object = Memcached_DataObject::staticGet($table, $column, $id);

View File

@ -0,0 +1,21 @@
#!/bin/bash
source /etc/laconica/setup.cfg
export nickname=$1
export database=$nickname$DBBASE
# Create the db
mysqladmin -h $DBHOST -u $ADMIN --password=$ADMINPASS -f drop $database
mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB << ENDOFCOMMANDS
delete from status_network where nickname = '$nickname';
ENDOFCOMMANDS
for top in $AVATARBASE $FILEBASE $BACKGROUNDBASE; do
rm -Rf $top/$nickname
done

View File

@ -18,24 +18,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $shortoptions = 'i::';
require_once(INSTALLDIR . '/lib/mail.php'); $longoptions = array('id::');
require_once(INSTALLDIR . '/lib/queuehandler.php');
$helptext = <<<END_OF_ENJIT_HELP
Daemon script for watching new notices and posting to enjit.
-i --id Identity (default none)
END_OF_ENJIT_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/mail.php';
require_once INSTALLDIR . '/lib/queuehandler.php';
set_error_handler('common_error_handler'); set_error_handler('common_error_handler');
class EnjitQueueHandler extends QueueHandler class EnjitQueueHandler extends QueueHandler
{ {
function transport() function transport()
{ {
return 'enjit'; return 'enjit';
@ -60,7 +63,6 @@ class EnjitQueueHandler extends QueueHandler
return "skipped"; return "skipped";
} }
# #
# Build an Atom message from the notice # Build an Atom message from the notice
# #
@ -93,8 +95,8 @@ class EnjitQueueHandler extends QueueHandler
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1) ; curl_setopt($ch, CURLOPT_POST, 1) ;
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
@ -103,7 +105,7 @@ class EnjitQueueHandler extends QueueHandler
# #
# curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); # curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
# curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); # curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
# curl_setopt($ch, CURLOPT_VERBOSE, 1); # curl_setopt($ch, CURLOPT_VERBOSE, 1);
$result = curl_exec($ch); $result = curl_exec($ch);
@ -115,13 +117,18 @@ class EnjitQueueHandler extends QueueHandler
return $code; return $code;
} }
} }
mb_internal_encoding('UTF-8'); if (have_option('-i')) {
$id = get_option_value('-i');
$id = ($argc > 1) ? $argv[1] : null; } else if (have_option('--id')) {
$id = get_option_value('--id');
} else if (count($args) > 0) {
$id = $args[0];
} else {
$id = null;
}
$handler = new EnjitQueueHandler($id); $handler = new EnjitQueueHandler($id);

View File

@ -18,29 +18,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $shortoptions = 'i::';
require_once(INSTALLDIR . '/lib/facebookutil.php'); $longoptions = array('id::');
require_once(INSTALLDIR . '/lib/queuehandler.php');
set_error_handler('common_error_handler'); $helptext = <<<END_OF_FACEBOOK_HELP
Daemon script for pushing new notices to Facebook.
-i --id Identity (default none)
END_OF_FACEBOOK_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/facebookutil.php';
require_once INSTALLDIR . '/lib/queuehandler.php';
class FacebookQueueHandler extends QueueHandler class FacebookQueueHandler extends QueueHandler
{ {
function transport() function transport()
{ {
return 'facebook'; return 'facebook';
} }
function start() function start()
{ {
$this->log(LOG_INFO, "INITIALIZE"); $this->log(LOG_INFO, "INITIALIZE");
@ -51,20 +52,22 @@ class FacebookQueueHandler extends QueueHandler
{ {
return facebookBroadcastNotice($notice); return facebookBroadcastNotice($notice);
} }
function finish() function finish()
{ {
} }
} }
ini_set("max_execution_time", "0"); if (have_option('i')) {
ini_set("max_input_time", "0"); $id = get_option_value('i');
set_time_limit(0); } else if (have_option('--id')) {
$id = get_option_value('--id');
mb_internal_encoding('UTF-8'); } else if (count($args) > 0) {
$id = $args[0];
$id = ($argc > 1) ? $argv[1] : null; } else {
$id = null;
}
$handler = new FacebookQueueHandler($id); $handler = new FacebookQueueHandler($id);

View File

@ -18,16 +18,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); require_once INSTALLDIR.'/scripts/commandline.inc';
common_log(LOG_INFO, 'Fixing up conversations.'); common_log(LOG_INFO, 'Fixing up conversations.');
@ -72,8 +65,3 @@ while ($notice->fetch()) {
print ".\n"; print ".\n";
} }
ini_set("max_execution_time", "0");
ini_set("max_input_time", "0");
set_time_limit(0);
mb_internal_encoding('UTF-8');

View File

@ -19,21 +19,18 @@
*/ */
# Abort if called from a web server # 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $helptext = <<<ENDOFHELP
require_once('DB.php'); fixup_utf8.php <maxdate> <maxid> <minid>
Fixup records in a database that stored the data incorrectly (pre-0.7.4 for Laconica).
ENDOFHELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once 'DB.php';
class UTF8FixerUpper class UTF8FixerUpper
{ {
@ -356,9 +353,9 @@ class UTF8FixerUpper
} }
} }
$max_date = ($argc > 1) ? $argv[1] : null; $max_date = (count($args) > 0) ? $args[0] : null;
$max_id = ($argc > 2) ? $argv[2] : null; $max_id = (count($args) > 1) ? $args[1] : null;
$min_id = ($argc > 3) ? $argv[3] : null; $min_id = (count($args) > 2) ? $args[2] : null;
$fixer = new UTF8FixerUpper(array('max_date' => $max_date, $fixer = new UTF8FixerUpper(array('max_date' => $max_date,
'max_notice' => $max_id, 'max_notice' => $max_id,

View File

@ -18,15 +18,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $helptext = <<<ENDOFHELP
getpiddir.php - print out the currently configured PID directory
echo common_config('daemon','piddir'); ENDOFHELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
echo common_config('daemon', 'piddir');

View File

@ -25,16 +25,14 @@
* daemon names. * daemon names.
*/ */
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
print "This script must be run from the command line\n";
exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $helptext = <<<ENDOFHELP
getvaliddaemons.php - print out the currently configured PID directory
ENDOFHELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
if(common_config('xmpp','enabled')) { if(common_config('xmpp','enabled')) {
echo "xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php "; echo "xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php ";

View File

@ -20,59 +20,55 @@
# Abort if called from a web server # 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $helptext = <<<ENDOFHELP
inbox_users.php <idfile>
$id_file = ($argc > 1) ? $argv[1] : 'ids.txt'; Update users to use inbox table. Listed in an ID file, default 'ids.txt'.
ENDOFHELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
$id_file = (count($args) > 1) ? $args[0] : 'ids.txt';
common_log(LOG_INFO, 'Updating user inboxes.'); common_log(LOG_INFO, 'Updating user inboxes.');
$ids = file($id_file); $ids = file($id_file);
foreach ($ids as $id) { foreach ($ids as $id) {
$user = User::staticGet('id', $id); $user = User::staticGet('id', $id);
if (!$user) { if (!$user) {
common_log(LOG_WARNING, 'No such user: ' . $id); common_log(LOG_WARNING, 'No such user: ' . $id);
continue; continue;
} }
if ($user->inboxed) { if ($user->inboxed) {
common_log(LOG_WARNING, 'Already inboxed: ' . $id); common_log(LOG_WARNING, 'Already inboxed: ' . $id);
continue; continue;
} }
common_log(LOG_INFO, 'Updating inbox for user ' . $user->id); common_log(LOG_INFO, 'Updating inbox for user ' . $user->id);
$user->query('BEGIN'); $user->query('BEGIN');
$old_inbox = new Notice_inbox(); $old_inbox = new Notice_inbox();
$old_inbox->user_id = $user->id; $old_inbox->user_id = $user->id;
$result = $old_inbox->delete(); $result = $old_inbox->delete();
if (is_null($result) || $result === false) { if (is_null($result) || $result === false) {
common_log_db_error($old_inbox, 'DELETE', __FILE__); common_log_db_error($old_inbox, 'DELETE', __FILE__);
continue; continue;
} }
$old_inbox->free(); $old_inbox->free();
$inbox = new Notice_inbox(); $inbox = new Notice_inbox();
$result = $inbox->query('INSERT INTO notice_inbox (user_id, notice_id, created) ' . $result = $inbox->query('INSERT INTO notice_inbox (user_id, notice_id, created) ' .
'SELECT ' . $user->id . ', notice.id, notice.created ' . 'SELECT ' . $user->id . ', notice.id, notice.created ' .
'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' . 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' .
@ -80,30 +76,30 @@ foreach ($ids as $id) {
'AND notice.created >= subscription.created ' . 'AND notice.created >= subscription.created ' .
'AND NOT EXISTS (SELECT user_id, notice_id ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' .
'FROM notice_inbox ' . 'FROM notice_inbox ' .
'WHERE user_id = ' . $user->id . ' ' . 'WHERE user_id = ' . $user->id . ' ' .
'AND notice_id = notice.id) ' . 'AND notice_id = notice.id) ' .
'ORDER BY notice.created DESC ' . 'ORDER BY notice.created DESC ' .
'LIMIT 0, 1000'); 'LIMIT 0, 1000');
if (is_null($result) || $result === false) { if (is_null($result) || $result === false) {
common_log_db_error($inbox, 'INSERT', __FILE__); common_log_db_error($inbox, 'INSERT', __FILE__);
continue; continue;
} }
$orig = clone($user); $orig = clone($user);
$user->inboxed = 1; $user->inboxed = 1;
$result = $user->update($orig); $result = $user->update($orig);
if (!$result) { if (!$result) {
common_log_db_error($user, 'UPDATE', __FILE__); common_log_db_error($user, 'UPDATE', __FILE__);
continue; continue;
} }
$user->query('COMMIT'); $user->query('COMMIT');
$inbox->free(); $inbox->free();
unset($inbox); unset($inbox);
if ($cache) { if ($cache) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id . ';last')); $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id . ';last'));

View File

@ -18,24 +18,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $shortoptions = 'r::';
require_once(INSTALLDIR . '/lib/jabber.php'); $longoptions = array('resource::');
require_once(INSTALLDIR . '/lib/xmppqueuehandler.php');
set_error_handler('common_error_handler'); $helptext = <<<END_OF_JABBER_HELP
Daemon script for pushing new notices to Jabber users.
-r --resource Jabber Resource ID (default to config)
END_OF_JABBER_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/common.php';
require_once INSTALLDIR . '/lib/jabber.php';
require_once INSTALLDIR . '/lib/xmppqueuehandler.php';
class JabberQueueHandler extends XmppQueueHandler class JabberQueueHandler extends XmppQueueHandler
{ {
var $conn = null; var $conn = null;
function transport() function transport()
@ -61,12 +63,15 @@ if (common_config('xmpp','enabled')==false) {
exit(); exit();
} }
ini_set("max_execution_time", "0"); if (have_option('r')) {
ini_set("max_input_time", "0"); $resource = get_option_value('r');
set_time_limit(0); } else if (have_option('--resource')) {
mb_internal_encoding('UTF-8'); $resource = get_option_value('--resource');
} else if (count($args) > 0) {
$resource = ($argc > 1) ? $argv[1] : (common_config('xmpp','resource') . '-queuehandler'); $resource = $args[0];
} else {
$resource = null;
}
$handler = new JabberQueueHandler($resource); $handler = new JabberQueueHandler($resource);

View File

@ -18,16 +18,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $helptext = <<<END_OF_HELP
Script for converting mail messages into notices. Takes message body
as STDIN.
END_OF_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once(INSTALLDIR . '/lib/mail.php'); require_once(INSTALLDIR . '/lib/mail.php');
require_once('Mail/mimeDecode.php'); require_once('Mail/mimeDecode.php');
@ -36,7 +36,6 @@ require_once('Mail/mimeDecode.php');
class MailerDaemon class MailerDaemon
{ {
function __construct() function __construct()
{ {
} }

View File

@ -18,29 +18,33 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $shortoptions = 'i::';
require_once(INSTALLDIR . '/lib/omb.php'); $longoptions = array('id::');
require_once(INSTALLDIR . '/lib/queuehandler.php');
$helptext = <<<END_OF_OMB_HELP
Daemon script for pushing new notices to OpenMicroBlogging subscribers.
-i --id Identity (default none)
END_OF_OMB_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/omb.php';
require_once INSTALLDIR . '/lib/queuehandler.php';
set_error_handler('common_error_handler'); set_error_handler('common_error_handler');
class OmbQueueHandler extends QueueHandler class OmbQueueHandler extends QueueHandler
{ {
function transport() function transport()
{ {
return 'omb'; return 'omb';
} }
function start() function start()
{ {
$this->log(LOG_INFO, "INITIALIZE"); $this->log(LOG_INFO, "INITIALIZE");
@ -56,7 +60,7 @@ class OmbQueueHandler extends QueueHandler
return omb_broadcast_remote_subscribers($notice); return omb_broadcast_remote_subscribers($notice);
} }
} }
function finish() function finish()
{ {
} }
@ -68,12 +72,15 @@ class OmbQueueHandler extends QueueHandler
} }
} }
ini_set("max_execution_time", "0"); if (have_option('i')) {
ini_set("max_input_time", "0"); $id = get_option_value('i');
set_time_limit(0); } else if (have_option('--id')) {
mb_internal_encoding('UTF-8'); $id = get_option_value('--id');
} else if (count($args) > 0) {
$id = ($argc > 1) ? $argv[1] : null; $id = $args[0];
} else {
$id = null;
}
$handler = new OmbQueueHandler($id); $handler = new OmbQueueHandler($id);

View File

@ -18,20 +18,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $shortoptions = 'i::';
require_once(INSTALLDIR . '/lib/ping.php'); $longoptions = array('id::');
require_once(INSTALLDIR . '/lib/queuehandler.php');
set_error_handler('common_error_handler'); $helptext = <<<END_OF_PING_HELP
Daemon script for pushing new notices to ping servers.
-i --id Identity (default none)
END_OF_PING_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/ping.php';
require_once INSTALLDIR . '/lib/queuehandler.php';
class PingQueueHandler extends QueueHandler { class PingQueueHandler extends QueueHandler {
@ -52,12 +54,15 @@ class PingQueueHandler extends QueueHandler {
} }
} }
ini_set("max_execution_time", "0"); if (have_option('i')) {
ini_set("max_input_time", "0"); $id = get_option_value('i');
set_time_limit(0); } else if (have_option('--id')) {
mb_internal_encoding('UTF-8'); $id = get_option_value('--id');
} else if (count($args) > 0) {
$id = ($argc > 1) ? $argv[1] : NULL; $id = $args[0];
} else {
$id = null;
}
$handler = new PingQueueHandler($id); $handler = new PingQueueHandler($id);

View File

@ -18,29 +18,31 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $shortoptions = 'r::';
require_once(INSTALLDIR . '/lib/jabber.php'); $longoptions = array('resource::');
require_once(INSTALLDIR . '/lib/xmppqueuehandler.php');
set_error_handler('common_error_handler'); $helptext = <<<END_OF_PUBLIC_HELP
Daemon script for pushing new notices to public XMPP subscribers.
-r --resource Jabber Resource ID
END_OF_PUBLIC_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/jabber.php';
require_once INSTALLDIR . '/lib/xmppqueuehandler.php';
class PublicQueueHandler extends XmppQueueHandler class PublicQueueHandler extends XmppQueueHandler
{ {
function transport() function transport()
{ {
return 'public'; return 'public';
} }
function handle_notice($notice) function handle_notice($notice)
{ {
try { try {
@ -59,12 +61,15 @@ if (common_config('xmpp','enabled')==false) {
exit(); exit();
} }
ini_set("max_execution_time", "0"); if (have_option('r')) {
ini_set("max_input_time", "0"); $resource = get_option_value('r');
set_time_limit(0); } else if (have_option('--resource')) {
mb_internal_encoding('UTF-8'); $resource = get_option_value('--resource');
} else if (count($args) > 0) {
$resource = ($argc > 1) ? $argv[1] : (common_config('xmpp','resource') . '-public'); $resource = $args[0];
} else {
$resource = null;
}
$handler = new PublicQueueHandler($resource); $handler = new PublicQueueHandler($resource);

View File

@ -18,20 +18,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $helptext = <<<END_OF_SNAPSHOT_HELP
Batch script for sending snapshot information about this installation to devs.
END_OF_SNAPSHOT_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
Snapshot::check(); Snapshot::check();

View File

@ -18,30 +18,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $helptext = <<<END_OF_PASSWORD_HELP
setpassword.php <username> <password>
if ($argc != 3) { Sets the password of user with name <username> to <password>
print "USAGE: setpassword.php <username> <password>\n";
print "Sets the password of user with name <username> to <password>\n"; END_OF_PASSWORD_HELP;
exit(1);
require_once INSTALLDIR.'/scripts/commandline.inc';
if (count($args) < 2) {
show_help();
} }
$nickname = $argv[1]; $nickname = $args[0];
$password = $argv[2]; $password = $args[1];
if (mb_strlen($password) < 6) { if (mb_strlen($password) < 6) {
print "Password must be 6 characters or more.\n"; print "Password must be 6 characters or more.\n";

View File

@ -1,12 +1,14 @@
# CONFIGURATION FILE for setup_status_network.sh # CONFIGURATION FILE for setup_status_network.sh
# Base database name; full name will include nickname export DBHOST=localhost
export DBHOSTNAME=masterdb.example.net
export DBHOST=masterdb.example.net
export DBBASE=_example_net export DBBASE=_example_net
export USERBASE=_example_net export USERBASE=_example_net
export ADMIN=root export ADMIN=root
export ADMINPASS=yourpassword export ADMINPASS=yourpassword
export SITEDB=example_net_site export SITEDB=example_net_site
export AVATARBASE=/var/www/avatar.example.net 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"

View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
source ./setup.cfg source /etc/laconica/setup.cfg
export nickname=$1 export nickname=$1
export sitename=$2 export sitename=$2
export password=`pwgen 20` export password=`$PWDGEN`
export database=$nickname$DBBASE export database=$nickname$DBBASE
export username=$nickname$USERBASE export username=$nickname$USERBASE
@ -13,7 +13,7 @@ export username=$nickname$USERBASE
mysqladmin -h $DBHOST -u $ADMIN --password=$ADMINPASS create $database mysqladmin -h $DBHOST -u $ADMIN --password=$ADMINPASS create $database
for f in laconica.sql sms_carrier.sql foreign_services.sql notice_source.sql; do for f in laconica.sql innodb.sql sms_carrier.sql foreign_services.sql notice_source.sql; do
mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $database < ../db/$f; mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $database < ../db/$f;
done done
@ -22,9 +22,11 @@ mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB << ENDOFCOMMANDS
GRANT INSERT,SELECT,UPDATE,DELETE ON $database.* TO '$username'@'localhost' IDENTIFIED BY '$password'; GRANT INSERT,SELECT,UPDATE,DELETE ON $database.* TO '$username'@'localhost' IDENTIFIED BY '$password';
GRANT INSERT,SELECT,UPDATE,DELETE ON $database.* TO '$username'@'%' IDENTIFIED BY '$password'; GRANT INSERT,SELECT,UPDATE,DELETE ON $database.* TO '$username'@'%' IDENTIFIED BY '$password';
INSERT INTO status_network (nickname, dbhost, dbuser, dbpass, dbname, sitename, created) INSERT INTO status_network (nickname, dbhost, dbuser, dbpass, dbname, sitename, created)
VALUES ('$nickname', '$DBHOST', '$username', '$password', '$database', '$sitename', now()); VALUES ('$nickname', '$DBHOSTNAME', '$username', '$password', '$database', '$sitename', now());
ENDOFCOMMANDS ENDOFCOMMANDS
mkdir $AVATARBASE/$nickname for top in $AVATARBASE $FILEBASE $BACKGROUNDBASE; do
chmod a+w $AVATARBASE/$nickname mkdir $top/$nickname
chmod a+w $top/$nickname
done

View File

@ -1,10 +1,37 @@
#!/usr/bin/env php
<?php <?php
/*
* Laconica - a distributed open-source microblogging tool
* Copyright (C) 2008, 2009, Control Yourself, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $shortoptions = 'f:d:u:';
require_once(INSTALLDIR . '/lib/util.php');
$helptext = <<<END_OF_SITEMAP_HELP
Script for creating sitemaps files per http://sitemaps.org/
-f <indexfile> Use <indexfile> as output file
-d <outputdir> Use <outputdir> for new sitemaps
-u <outputurl> Use <outputurl> as root for URLs
END_OF_SITEMAP_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
$output_paths = parse_args(); $output_paths = parse_args();
@ -13,11 +40,11 @@ notices_map();
user_map(); user_map();
index_map(); index_map();
# ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
# Main functions: get data out and turn them into sitemaps // Main functions: get data out and turn them into sitemaps
# ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
# Generate index sitemap of all other sitemaps. // Generate index sitemap of all other sitemaps.
function index_map() function index_map()
{ {
global $output_paths; global $output_paths;
@ -26,7 +53,7 @@ function index_map()
foreach (glob("$output_dir*.xml") as $file_name) { foreach (glob("$output_dir*.xml") as $file_name) {
# Just the file name please. // Just the file name please.
$file_name = preg_replace("|$output_dir|", '', $file_name); $file_name = preg_replace("|$output_dir|", '', $file_name);
$index_urls .= sitemap( $index_urls .= sitemap(
@ -40,7 +67,7 @@ function index_map()
write_file($output_paths['index_file'], sitemapindex($index_urls)); write_file($output_paths['index_file'], sitemapindex($index_urls));
} }
# Generate sitemap of standard site elements. // Generate sitemap of standard site elements.
function standard_map() function standard_map()
{ {
global $output_paths; global $output_paths;
@ -61,7 +88,7 @@ function standard_map()
) )
); );
$docs = array('about', 'faq', 'contact', 'im', 'openid', 'openmublog', $docs = array('about', 'faq', 'contact', 'im', 'openid', 'openmublog',
'privacy', 'source', 'badge'); 'privacy', 'source', 'badge');
foreach($docs as $title) { foreach($docs as $title) {
@ -79,7 +106,7 @@ function standard_map()
write_file($urlset_path, urlset($standard_map_urls)); write_file($urlset_path, urlset($standard_map_urls));
} }
# Generate sitemaps of all notices. // Generate sitemaps of all notices.
function notices_map() function notices_map()
{ {
global $output_paths; global $output_paths;
@ -93,14 +120,14 @@ function notices_map()
while ($notices->fetch()) { while ($notices->fetch()) {
# Maximum 50,000 URLs per sitemap file. // Maximum 50,000 URLs per sitemap file.
if ($notice_count == 50000) { if ($notice_count == 50000) {
$notice_count = 0; $notice_count = 0;
$map_count++; $map_count++;
} }
# remote notices have an URL // remote notices have an URL
if (!$notices->url && $notices->uri) { if (!$notices->url && $notices->uri) {
$notice = array( $notice = array(
'url' => ($notices->uri) ? $notices->uri : common_local_url('shownotice', array('notice' => $notices->id)), 'url' => ($notices->uri) ? $notices->uri : common_local_url('shownotice', array('notice' => $notices->id)),
@ -114,11 +141,11 @@ function notices_map()
} }
} }
# Make full sitemaps from the lists and save them. // Make full sitemaps from the lists and save them.
array_to_map($notice_list, 'notice'); array_to_map($notice_list, 'notice');
} }
# Generate sitemaps of all users. // Generate sitemaps of all users.
function user_map() function user_map()
{ {
global $output_paths; global $output_paths;
@ -132,7 +159,7 @@ function user_map()
while ($users->fetch()) { while ($users->fetch()) {
# Maximum 50,000 URLs per sitemap file. // Maximum 50,000 URLs per sitemap file.
if ($user_count == 50000) { if ($user_count == 50000) {
$user_count = 0; $user_count = 0;
$map_count++; $map_count++;
@ -140,7 +167,7 @@ function user_map()
$user_args = array('nickname' => $users->nickname); $user_args = array('nickname' => $users->nickname);
# Define parameters for generating <url></url> elements. // Define parameters for generating <url></url> elements.
$user = array( $user = array(
'url' => common_local_url('showstream', $user_args), 'url' => common_local_url('showstream', $user_args),
'changefreq' => 'daily', 'changefreq' => 'daily',
@ -183,8 +210,8 @@ function user_map()
'priority' => '0.5', 'priority' => '0.5',
); );
# Construct a <url></url> element for each user facet and add it // Construct a <url></url> element for each user facet and add it
# to our existing list of those. // to our existing list of those.
$user_list[$map_count] .= url($user); $user_list[$map_count] .= url($user);
$user_rss_list[$map_count] .= url($user_rss); $user_rss_list[$map_count] .= url($user_rss);
$all_list[$map_count] .= url($all); $all_list[$map_count] .= url($all);
@ -196,9 +223,9 @@ function user_map()
$user_count++; $user_count++;
} }
# Make full sitemaps from the lists and save them. // Make full sitemaps from the lists and save them.
# Possible factoring: put all the lists into a master array, thus allowing // Possible factoring: put all the lists into a master array, thus allowing
# calling with single argument (i.e., array_to_map('user')). // calling with single argument (i.e., array_to_map('user')).
array_to_map($user_list, 'user'); array_to_map($user_list, 'user');
array_to_map($user_rss_list, 'user_rss'); array_to_map($user_rss_list, 'user_rss');
array_to_map($all_list, 'all'); array_to_map($all_list, 'all');
@ -208,14 +235,14 @@ function user_map()
array_to_map($foaf_list, 'foaf'); array_to_map($foaf_list, 'foaf');
} }
# ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
# XML generation functions // XML generation functions
# ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
# Generate a <url></url> element. // Generate a <url></url> element.
function url($url_args) function url($url_args)
{ {
$url = preg_replace('/&/', '&amp;', $url_args['url']); # escape ampersands for XML $url = preg_replace('/&/', '&amp;', $url_args['url']); // escape ampersands for XML
$lastmod = $url_args['lastmod']; $lastmod = $url_args['lastmod'];
$changefreq = $url_args['changefreq']; $changefreq = $url_args['changefreq'];
$priority = $url_args['priority']; $priority = $url_args['priority'];
@ -246,7 +273,7 @@ function url($url_args)
function sitemap($sitemap_args) function sitemap($sitemap_args)
{ {
$url = preg_replace('/&/', '&amp;', $sitemap_args['url']); # escape ampersands for XML $url = preg_replace('/&/', '&amp;', $sitemap_args['url']); // escape ampersands for XML
$lastmod = $sitemap_args['lastmod']; $lastmod = $sitemap_args['lastmod'];
if (is_null($url)) { if (is_null($url)) {
@ -265,7 +292,7 @@ function sitemap($sitemap_args)
return $sitemap_out; return $sitemap_out;
} }
# Generate a <urlset></urlset> element. // Generate a <urlset></urlset> element.
function urlset($urlset_text) function urlset($urlset_text)
{ {
$urlset = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $urlset = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
@ -276,7 +303,7 @@ function urlset($urlset_text)
return $urlset; return $urlset;
} }
# Generate a <urlset></urlset> element. // Generate a <urlset></urlset> element.
function sitemapindex($sitemapindex_text) function sitemapindex($sitemapindex_text)
{ {
$sitemapindex = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $sitemapindex = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
@ -287,49 +314,31 @@ function sitemapindex($sitemapindex_text)
return $sitemapindex; return $sitemapindex;
} }
# Generate a sitemap from an array containing <url></url> elements and write it to a file. // Generate a sitemap from an array containing <url></url> elements and write it to a file.
function array_to_map($url_list, $filename_prefix) function array_to_map($url_list, $filename_prefix)
{ {
global $output_paths; global $output_paths;
if ($url_list) { if ($url_list) {
# $map_urls is a long string containing concatenated <url></url> elements. // $map_urls is a long string containing concatenated <url></url> elements.
while (list($map_idx, $map_urls) = each($url_list)) { while (list($map_idx, $map_urls) = each($url_list)) {
$urlset_path = $output_paths['output_dir'] . "$filename_prefix-$map_idx.xml"; $urlset_path = $output_paths['output_dir'] . "$filename_prefix-$map_idx.xml";
write_file($urlset_path, urlset($map_urls)); write_file($urlset_path, urlset($map_urls));
} }
} }
} }
# ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
# Internal functions // Internal functions
# ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
# Parse command line arguments. // Parse command line arguments.
function parse_args() function parse_args()
{ {
$args = getopt('f:d:u:'); $index_file = get_option_value('f');
$output_dir = get_option_value('d');
if (is_null($args[f]) && is_null($args[d]) && is_null($args[u])) { $output_url = get_option_value('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 (file_exists($output_dir)) {
if (is_writable($output_dir) === false) { if (is_writable($output_dir) === false) {
@ -348,7 +357,7 @@ function parse_args()
return $paths; return $paths;
} }
# Ensure paths end with a "/". // Ensure paths end with a "/".
function trailing_slash($path) function trailing_slash($path)
{ {
if (preg_match('/\/$/', $path) == 0) { if (preg_match('/\/$/', $path) == 0) {
@ -358,7 +367,7 @@ function trailing_slash($path)
return $path; return $path;
} }
# Write data to disk. // Write data to disk.
function write_file($path, $data) function write_file($path, $data)
{ {
if (is_null($path)) { if (is_null($path)) {
@ -376,7 +385,7 @@ function write_file($path, $data)
} }
} }
# Display an error message and exit. // Display an error message and exit.
function error ($error_msg) function error ($error_msg)
{ {
if (is_null($error_msg)) { if (is_null($error_msg)) {

View File

@ -18,24 +18,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $shortoptions = 'i::';
require_once(INSTALLDIR . '/lib/mail.php'); $longoptions = array('id::');
require_once(INSTALLDIR . '/lib/queuehandler.php');
set_error_handler('common_error_handler'); $helptext = <<<END_OF_SMS_HELP
Daemon script for pushing new notices to local subscribers using SMS.
-i --id Identity (default none)
END_OF_SMS_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/mail.php';
require_once INSTALLDIR . '/lib/queuehandler.php';
class SmsQueueHandler extends QueueHandler class SmsQueueHandler extends QueueHandler
{ {
function transport() function transport()
{ {
return 'sms'; return 'sms';
@ -51,18 +52,21 @@ class SmsQueueHandler extends QueueHandler
{ {
return mail_broadcast_notice_sms($notice); return mail_broadcast_notice_sms($notice);
} }
function finish() function finish()
{ {
} }
} }
ini_set("max_execution_time", "0"); if (have_option('i')) {
ini_set("max_input_time", "0"); $id = get_option_value('i');
set_time_limit(0); } else if (have_option('--id')) {
mb_internal_encoding('UTF-8'); $id = get_option_value('--id');
} else if (count($args) > 0) {
$id = ($argc > 1) ? $argv[1] : null; $id = $args[0];
} else {
$id = null;
}
$handler = new SmsQueueHandler($id); $handler = new SmsQueueHandler($id);

View File

@ -18,19 +18,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
// Uncomment this to get useful console output // Uncomment this to get useful console output
//define('SCRIPT_DEBUG', true);
require_once(INSTALLDIR . '/lib/common.php'); $helptext = <<<END_OF_TWITTER_HELP
Batch script for synching local friends with Twitter friends.
END_OF_TWITTER_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
// Make a lockfile // Make a lockfile
$lockfilename = lockFilename(); $lockfilename = lockFilename();

View File

@ -18,26 +18,37 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $shortoptions = 'u::';
$longoptions = array('start-user-id::');
$helptext = <<<END_OF_TRIM_HELP
Batch script for trimming notice inboxes to a reasonable size.
-u <id>
--start-user-id=<id> User ID to start after. Default is all.
END_OF_TRIM_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
$id = null;
if (have_option('u')) {
$id = get_option_value('u');
} else if (have_option('--start-user-id')) {
$id = get_option_value('--start-user-id');
} else {
$id = null;
}
$user = new User(); $user = new User();
if ($argc > 1) {
$user->whereAdd('id > ' . $argv[1]); if (!empty($id)) {
$user->whereAdd('id > ' . $id);
} }
$cnt = $user->find(); $cnt = $user->find();
while ($user->fetch()) { while ($user->fetch()) {
@ -74,10 +85,10 @@ while ($user->fetch()) {
$delay = 3.0 * ($finish - $start); $delay = 3.0 * ($finish - $start);
print "Delaying $delay seconds..."; print "Delaying $delay seconds...";
// Wait to let slaves catch up // Wait to let slaves catch up
usleep($delay * 1000000); usleep($delay * 1000000);
print "DONE.\n"; print "DONE.\n";
} }

View File

@ -18,29 +18,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $shortoptions = 'i::';
require_once(INSTALLDIR . '/lib/twitter.php'); $longoptions = array('id::');
require_once(INSTALLDIR . '/lib/queuehandler.php');
set_error_handler('common_error_handler'); $helptext = <<<END_OF_ENJIT_HELP
Daemon script for pushing new notices to Twitter.
-i --id Identity (default none)
END_OF_ENJIT_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/twitter.php';
require_once INSTALLDIR . '/lib/queuehandler.php';
class TwitterQueueHandler extends QueueHandler class TwitterQueueHandler extends QueueHandler
{ {
function transport() function transport()
{ {
return 'twitter'; return 'twitter';
} }
function start() function start()
{ {
$this->log(LOG_INFO, "INITIALIZE"); $this->log(LOG_INFO, "INITIALIZE");
@ -51,20 +52,22 @@ class TwitterQueueHandler extends QueueHandler
{ {
return broadcast_twitter($notice); return broadcast_twitter($notice);
} }
function finish() function finish()
{ {
} }
} }
ini_set("max_execution_time", "0"); if (have_option('i')) {
ini_set("max_input_time", "0"); $id = get_option_value('i');
set_time_limit(0); } else if (have_option('--id')) {
$id = get_option_value('--id');
mb_internal_encoding('UTF-8'); } else if (count($args) > 0) {
$id = $args[0];
$id = ($argc > 1) ? $argv[1] : null; } else {
$id = null;
}
$handler = new TwitterQueueHandler($id); $handler = new TwitterQueueHandler($id);

View File

@ -18,22 +18,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
// Tune number of processes and how often to poll Twitter // Tune number of processes and how often to poll Twitter
// XXX: Should these things be in config.php? // XXX: Should these things be in config.php?
define('MAXCHILDREN', 2); define('MAXCHILDREN', 2);
define('POLL_INTERVAL', 60); // in seconds define('POLL_INTERVAL', 60); // in seconds
// Uncomment this to get useful logging $helptext = <<<END_OF_TRIM_HELP
define('SCRIPT_DEBUG', true); Batch script for retrieving Twitter messages from foreign service.
END_OF_TRIM_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/common.php'; require_once INSTALLDIR . '/lib/common.php';
require_once INSTALLDIR . '/lib/daemon.php'; require_once INSTALLDIR . '/lib/daemon.php';
@ -626,10 +623,6 @@ class TwitterStatusFetcher extends Daemon
} }
} }
ini_set("max_execution_time", "0");
ini_set("max_input_time", "0");
set_time_limit(0);
mb_internal_encoding('UTF-8');
declare(ticks = 1); declare(ticks = 1);
$fetcher = new TwitterStatusFetcher(); $fetcher = new TwitterStatusFetcher();

View File

@ -17,32 +17,27 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $helptext = <<<ENDOFHELP
uncache_users.php <idfile>
$id_file = ($argc > 1) ? $argv[1] : 'ids.txt'; Uncache users listed in an ID file, default 'ids.txt'.
ENDOFHELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
$id_file = (count($args) > 1) ? $args[0] : 'ids.txt';
common_log(LOG_INFO, 'Updating user inboxes.'); common_log(LOG_INFO, 'Updating user inboxes.');
$ids = file($id_file); $ids = file($id_file);
$memc = common_memcache();
foreach ($ids as $id) { foreach ($ids as $id) {
$user = User::staticGet('id', $id); $user = User::staticGet('id', $id);
if (!$user) { if (!$user) {
@ -51,9 +46,7 @@ foreach ($ids as $id) {
} }
$user->decache(); $user->decache();
$memc = common_memcache();
$memc->delete(common_cache_key('user:notices_with_friends:'. $user->id)); $memc->delete(common_cache_key('user:notices_with_friends:'. $user->id));
$memc->delete(common_cache_key('user:notices_with_friends:'. $user->id . ';last')); $memc->delete(common_cache_key('user:notices_with_friends:'. $user->id . ';last'));
} }

View File

@ -18,33 +18,33 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $shortoptions = 'r::';
require_once(INSTALLDIR . '/lib/jabber.php'); $longoptions = array('resource::');
require_once(INSTALLDIR . '/lib/xmppqueuehandler.php');
set_error_handler('common_error_handler'); $helptext = <<<END_OF_JABBER_HELP
Daemon script for pushing new confirmations to Jabber users.
-r --resource Jabber Resource ID (default to config)
END_OF_JABBER_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/jabber.php';
require_once INSTALLDIR . '/lib/xmppqueuehandler.php';
define('CLAIM_TIMEOUT', 1200); define('CLAIM_TIMEOUT', 1200);
class XmppConfirmHandler extends XmppQueueHandler class XmppConfirmHandler extends XmppQueueHandler
{ {
var $_id = 'confirm'; var $_id = 'confirm';
function class_name() function class_name()
{ {
return 'XmppConfirmHandler'; return 'XmppConfirmHandler';
} }
function run() function run()
{ {
if (!$this->start()) { if (!$this->start()) {
@ -147,12 +147,15 @@ if (common_config('xmpp','enabled')==false) {
exit(); exit();
} }
ini_set("max_execution_time", "0"); if (have_option('r')) {
ini_set("max_input_time", "0"); $resource = get_option_value('r');
set_time_limit(0); } else if (have_option('--resource')) {
mb_internal_encoding('UTF-8'); $resource = get_option_value('--resource');
} else if (count($args) > 0) {
$resource = ($argc > 1) ? $argv[1] : (common_config('xmpp', 'resource').'-confirm'); $resource = $args[0];
} else {
$resource = null;
}
$handler = new XmppConfirmHandler($resource); $handler = new XmppConfirmHandler($resource);

View File

@ -18,20 +18,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once(INSTALLDIR . '/lib/common.php'); $shortoptions = 'r::';
require_once(INSTALLDIR . '/lib/jabber.php'); $longoptions = array('resource::');
require_once(INSTALLDIR . '/lib/daemon.php');
set_error_handler('common_error_handler'); $helptext = <<<END_OF_XMPP_HELP
Daemon script for receiving new notices from Jabber users.
-r --resource Jabber Resource ID (default to config)
END_OF_XMPP_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/lib/common.php';
require_once INSTALLDIR . '/lib/jabber.php';
require_once INSTALLDIR . '/lib/daemon.php';
# This is kind of clunky; we create a class to call the global functions # 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 # in jabber.php, which create a new XMPP class. A more elegant (?) solution
@ -39,7 +42,6 @@ set_error_handler('common_error_handler');
class XMPPDaemon extends Daemon class XMPPDaemon extends Daemon
{ {
function XMPPDaemon($resource=null) function XMPPDaemon($resource=null)
{ {
static $attrs = array('server', 'port', 'user', 'password', 'host'); static $attrs = array('server', 'port', 'user', 'password', 'host');
@ -321,12 +323,15 @@ if (common_config('xmpp','enabled')==false) {
exit(); exit();
} }
ini_set("max_execution_time", "0"); if (have_option('r')) {
ini_set("max_input_time", "0"); $resource = get_option_value('r');
set_time_limit(0); } else if (have_option('--resource')) {
mb_internal_encoding('UTF-8'); $resource = get_option_value('--resource');
} else if (count($args) > 0) {
$resource = ($argc > 1) ? $argv[1] : (common_config('xmpp','resource') . '-listen'); $resource = $args[0];
} else {
$resource = null;
}
$daemon = new XMPPDaemon($resource); $daemon = new XMPPDaemon($resource);

View File

@ -11,7 +11,7 @@
body, body,
a:active { a:active {
background-color:#C3D6DF; background-color:#CEE1E9;
} }
body { body {
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
@ -29,7 +29,7 @@ input, textarea, select,
border-color:#AAAAAA; border-color:#AAAAAA;
} }
#filter_tags ul li { #filter_tags ul li {
border-color:#C3D6DF; border-color:#DDDDDD;
} }
.form_settings input.form_action-primary { .form_settings input.form_action-primary {
@ -40,12 +40,12 @@ input.submit,
#form_notice.warning #notice_text-count, #form_notice.warning #notice_text-count,
.form_settings .form_note, .form_settings .form_note,
.entity_remote_subscribe { .entity_remote_subscribe {
background-color:#A9BF4F; background-color:#9BB43E;
} }
input:focus, textarea:focus, select:focus, input:focus, textarea:focus, select:focus,
#form_notice.warning #notice_data-text { #form_notice.warning #notice_data-text {
border-color:#A9BF4F; border-color:#9BB43E;
box-shadow:3px 3px 3px rgba(194, 194, 194, 0.3); box-shadow:3px 3px 3px rgba(194, 194, 194, 0.3);
-moz-box-shadow:3px 3px 3px rgba(194, 194, 194, 0.3); -moz-box-shadow:3px 3px 3px rgba(194, 194, 194, 0.3);
-webkit-box-shadow:3px 3px 3px rgba(194, 194, 194, 0.3); -webkit-box-shadow:3px 3px 3px rgba(194, 194, 194, 0.3);
@ -71,14 +71,14 @@ color:#002E6E;
.notice, .notice,
.profile { .profile {
border-top-color:#D1D9E4; border-top-color:#C8D1D5;
} }
.section .profile { .section .profile {
border-top-color:#C3D6DF; border-top-color:#87B4C8;
} }
#aside_primary { #aside_primary {
background-color:#CEE1E9; background-color:#C8D1D5;
} }
#notice_text-count { #notice_text-count {
@ -136,13 +136,13 @@ background-color:#EFF3DC;
} }
#anon_notice { #anon_notice {
background-color:#C3D6DF; background-color:#87B4C8;
color:#FFFFFF; color:#FFFFFF;
border-color:#FFFFFF; border-color:#FFFFFF;
} }
#showstream #anon_notice { #showstream #anon_notice {
background-color:#A9BF4F; background-color:#9BB43E;
} }
#export_data li a { #export_data li a {
@ -176,13 +176,13 @@ background-color:transparent;
.form_group_leave input.submit .form_group_leave input.submit
.form_user_subscribe input.submit, .form_user_subscribe input.submit,
.form_user_unsubscribe input.submit { .form_user_unsubscribe input.submit {
background-color:#A9BF4F; background-color:#9BB43E;
color:#FFFFFF; color:#FFFFFF;
} }
.form_user_unsubscribe input.submit, .form_user_unsubscribe input.submit,
.form_group_leave input.submit, .form_group_leave input.submit,
.form_user_authorization input.reject { .form_user_authorization input.reject {
background-color:#C3D6DF; background-color:#87B4C8;
} }
.entity_edit a { .entity_edit a {
@ -272,7 +272,7 @@ background:transparent url(../../base/images/icons/twotone/green/news.gif) no-re
.pagination .nav_prev a, .pagination .nav_prev a,
.pagination .nav_next a { .pagination .nav_next a {
background-repeat:no-repeat; background-repeat:no-repeat;
border-color:#D1D9E4; border-color:#C8D1D5;
} }
.pagination .nav_prev a { .pagination .nav_prev a {
background-image:url(../../base/images/icons/twotone/green/arrow-left.gif); background-image:url(../../base/images/icons/twotone/green/arrow-left.gif);

View File

@ -1,14 +1,14 @@
/* IE specific styles */ /* IE specific styles */
.notice-options input.submit { .notice-options input.submit {
color:#fff; color:#FFFFFF;
} }
#site_nav_local_views a { #site_nav_local_views a {
background-color:#ACCCDA; background-color:#C8D1D5;
} }
#form_notice .form_note + label { #form_notice .form_note + label {
background:transparent url(../../base/images/icons/twotone/green/clip-01.gif) no-repeat 0 45%; background:transparent url(../../base/images/icons/twotone/green/clip-01.gif) no-repeat 0 45%;
} }
#form_notice #notice_data-attach { #form_notice #notice_data-attach {
filter: alpha(opacity=0); filter: alpha(opacity=0);
} }

View File

@ -1,14 +1,14 @@
/* IE specific styles */ /* IE specific styles */
.notice-options input.submit { .notice-options input.submit {
color:#fff; color:#FFFFFF;
} }
#site_nav_local_views a { #site_nav_local_views a {
background-color:#D0DFE7; background-color:#D9DADB;
} }
#form_notice .form_note + label { #form_notice .form_note + label {
background:transparent url(../../base/images/icons/twotone/green/clip-01.gif) no-repeat 0 45%; background:transparent url(../../base/images/icons/twotone/green/clip-01.gif) no-repeat 0 45%;
} }
#form_notice #notice_data-attach { #form_notice #notice_data-attach {
filter: alpha(opacity=0); filter: alpha(opacity=0);
} }