|
Server : Apache/2.4.62 System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64 User : www ( 80) PHP Version : 8.3.8 Disable Function : NONE Directory : /domains/fatshado/cgi-bin/MT/lib/MT/ |
Upload File : |
# Copyright 2001, 2002 Benjamin Trott. This code cannot be redistributed without
# permission from www.movabletype.org.
#
# $Id: ConfigMgr.pm,v 1.56 2002/10/08 05:38:15 btrott Exp $
package MT::ConfigMgr;
use strict;
use MT::ErrorHandler;
@MT::ConfigMgr::ISA = qw( MT::ErrorHandler );
use vars qw( $cfg );
sub instance {
return $cfg if $cfg;
$cfg = __PACKAGE__->new;
}
sub new {
my $mgr = bless { __var => { } }, $_[0];
$mgr->init;
$mgr;
}
sub init {
my $mgr = shift;
$mgr->define('DataSource', Default => './db');
$mgr->define('Database');
$mgr->define('DBHost');
$mgr->define('DBSocket');
$mgr->define('DBUser');
$mgr->define('DBPassword');
$mgr->define('DefaultLanguage', Default => 'en_us');
$mgr->define('TemplatePath');
$mgr->define('ImportPath');
$mgr->define('PluginPath');
$mgr->define('SearchTemplatePath');
$mgr->define('ObjectDriver', Default => 'DBM');
$mgr->define('Serializer', Default => 'MT');
$mgr->define('SendMailPath', Default => '/usr/lib/sendmail');
$mgr->define('TimeOffset', Default => 0);
$mgr->define('StaticWebPath', Default => '');
$mgr->define('CGIPath', Default => '/cgi-bin/');
$mgr->define('AdminCGIPath');
$mgr->define('MailTransfer', Default => 'sendmail');
$mgr->define('SMTPServer', Default => 'localhost');
$mgr->define('WeblogsPingURL', Default => 'http://rpc.weblogs.com/RPC2');
$mgr->define('BlogsPingURL', Default => 'http://ping.blo.gs/');
$mgr->define('MTPingURL', Default => 'http://www.movabletype.org/update/');
$mgr->define('CGIMaxUpload', Default => 1_000_000);
$mgr->define('DBUmask', Default => '0111');
$mgr->define('HTMLUmask', Default => '0111');
$mgr->define('UploadUmask', Default => '0111');
$mgr->define('DirUmask', Default => '0000');
$mgr->define('HTMLPerms', Default => '0666');
$mgr->define('UploadPerms', Default => '0666');
$mgr->define('NoTempFiles', Default => 0);
$mgr->define('TempDir', Default => '/tmp');
$mgr->define('EntriesPerRebuild', Default => 40);
$mgr->define('UseNFSSafeLocking', Default => 0);
$mgr->define('NoLocking', Default => 0);
$mgr->define('NoHTMLEntities', Default => 0);
$mgr->define('NoPlacementCache', Default => 0);
$mgr->define('NoPublishMeansDraft', Default => 0);
$mgr->define('PingTimeout', Default => 15);
$mgr->define('ImageDriver', Default => 'ImageMagick');
$mgr->define('NetPBMPath');
$mgr->define('CommentScript', Default => 'mt-comments.cgi');
$mgr->define('TrackbackScript', Default => 'mt-tb.cgi');
$mgr->define('SearchScript', Default => 'mt-search.cgi');
## Search settings, copied from Jay's mt-search and integrated
## into default config.
$mgr->define('RegexSearch', Default => 0);
$mgr->define('CaseSearch', Default => 0);
$mgr->define('ResultDisplay', Default => 'descend');
$mgr->define('ExcerptWords', Default => 40);
$mgr->define('SearchElement', Default => 'entries');
$mgr->define('ExcludeBlogs');
$mgr->define('IncludeBlogs');
$mgr->define('DefaultTemplate', Default => 'default.tmpl');
$mgr->define('Type', Default => 'straight');
$mgr->define('MaxResults', Default => '9999999');
$mgr->define('SearchCutoff', Default => '9999999');
$mgr->define('CommentSearchCutoff', Default => '30');
$mgr->define('AltTemplate', Multiple => 1);
}
sub define {
my $mgr = shift;
my($var, %param) = @_;
$mgr->{__var}{$var} = undef;
$mgr->{__settings}{$var} = keys %param ? \%param : {};
if (exists $param{Default}) {
$mgr->{__var}{$var} = $param{Default};
}
}
sub get { $_[0]->{__var}{ $_[1] } }
sub set {
my $mgr = shift;
my($var, $val) = @_;
if ($mgr->{__settings}{$var}{Multiple}) {
push @{ $mgr->{__var}{$var} }, $val;
} else {
$mgr->{__var}{$var} = $val;
}
}
sub read_config {
my $class = shift;
my($cfg_file) = @_;
my $mgr = $class->instance;
local(*FH, $_, $/);
$/ = "\n";
open FH, $cfg_file or
return $class->error(MT->translate(
"Error opening file '[_1]': [_2]", $cfg_file, "$!" ));
while (<FH>) {
chomp;
next if !/\S/ || /^#/;
my($var, $val) = $_ =~ /^\s*(\S+)\s+(.+)$/;
$val =~ s/\s*$//;
next unless $var && $val;
return $class->error(MT->translate(
"[_1]:[_2]: variable '[_3]' not defined", $cfg_file, $., $var
)) unless exists $mgr->{__var}->{$var};
$mgr->set($var, $val);
}
close FH;
1;
}
sub DESTROY { }
use vars qw( $AUTOLOAD );
sub AUTOLOAD {
my $mgr = $_[0];
(my $var = $AUTOLOAD) =~ s!.+::!!;
return $mgr->error(MT->translate("No such config variable '[_1]'", $var))
unless exists $mgr->{__var}->{$var};
no strict 'refs';
*$AUTOLOAD = sub {
my $mgr = shift;
@_ ? $mgr->set($var, $_[0]) : $mgr->get($var);
};
goto &$AUTOLOAD;
}
1;
__END__
=head1 NAME
MT::ConfigMgr - Movable Type configuration manager
=head1 SYNOPSIS
use MT::ConfigMgr;
my $cfg = MT::ConfigMgr->instance;
$cfg->read_config('/path/to/mt.cfg')
or die $cfg->errstr;
=head1 DESCRIPTION
I<MT::ConfigMgr> is a singleton class that manages the Movable Type
configuration file (F<mt.cfg>), allowing access to the config directives
contained therin.
=head1 USAGE
=head2 MT::ConfigMgr->instance
Returns the singleton I<MT::ConfigMgr> object. Note that when you want the
object, you should always call I<instance>, never I<new>; I<new> will construct
a B<new> I<MT::ConfigMgr> object, and that isn't what you want. You want the
object that has already been initialized with the contents of F<mt.cfg>. This
initialization is done by I<MT::new>.
=head2 $cfg->read_config($file)
Reads the config file at the path I<$file> and initializes the I<$cfg> object
with the directives in that file. Returns true on success, C<undef> otherwise;
if an error occurs you can obtain the error message with C<$cfg-E<gt>errstr>.
=head2 $cfg->define($directive [, %arg ])
Defines the directive I<$directive> as a valid configuration directive; you
must define new configuration directives B<before> you read the configuration
file, or else the read will fail.
=head1 CONFIGURATION DIRECTIVES
The following configuration directives are allowed in F<mt.cfg>. To get the
value of a directive, treat it as a method that you are calling on the
I<$cfg> object. For example:
$cfg->CGIPath
To set the value of a directive, do the same as the above, but pass in a value
to the method:
$cfg->CGIPath('http://www.foo.com/mt/');
The following are the allowed configuration directives:
=over 4
=item * CGIPath
Movable Type uses the I<CGIPath> setting to construct links back to CGI
scripts; for example, the MT tag E<lt>$MTCGIPath$E<gt> is substituted with the
value of the I<CGIPath> setting. You will need to change this value when you
first install MT; instructions for doing so are in the Installation
Instructions, in I<INSTALLING THE MOVABLE TYPE APPLICATION CODE>, Step 3.
Default value: none
Example:
CGIPath http://www.your-site.com/path/to/mt/
=item * DataSource
The filesystem path to the F<db> directory, where your MT database files are
stored. You will probably need to change this when you first install MT;
instructions for doing so are in the Installation Instructions, in
I<INSTALLING THE MOVABLE TYPE APPLICATION CODE>, Step 8.
Default value: F<./db>
Example:
DataSource ./db
=item * StaticWebPath
If you place all of your MT files in a cgi-bin directory, you will need to
situate the static files (F<docs>, F<images>, F<styles.css>) elsewhere, so
that the webserver will not try to execute them. The I<TROUBLESHOOTING>
section of the manual has more information.
Default value: none
Example:
StaticWebPath /path/to/static-files/
=item * TemplatePath
The filesystem path to the F<tmpl> directory, which contains the front-end
templates used by the Movable Type application.
Default value: F<./tmpl>
Example:
TemplatePath ./tmpl
=item * MailTransfer
If you would rather use SMTP than sendmail, you should set the MailTransfer
config setting to 'smtp' (as below). Possible values for MailTransfer are:
C<smtp>, C<sendmail>, and C<debug> (which just writes out mail messages to
STDERR, for debugging purposes).
Default value: C<sendmail>
Example:
MailTransfer smtp
=item * SendMailPath
By default, Movable Type looks for sendmail in three locations:
F</usr/lib/sendmail>, F</usr/sbin/sendmail>, and F</usr/ucblib/sendmail>. If
your sendmail is in a different location, you can adjust the SendMailPath
configuration setting.
Default value: any of the above
Example:
SendMailPath /usr/sbin/sendmail
=item * SMTPServer
The address of your SMTP server, to be used along with C<MailTransfer smtp>.
Default value: C<localhost>
Example:
SMTPServer smtp.your-site.com
=item * NoTempFiles
By default, when writing to an output file (for example, one of your index or
archive pages), Movable Type will first write the data to a temp file, then
rename that temp file. In the case that the process writing the data dies
unexpectedly, this prevents the pages on your site from being erased. If you
do not like this behavior (because it requires you to set directory
permissions too liberally, for example), you can use C<NoTempFiles> to turn
it off.
Default value: C<0>
Example:
NoTempFiles 1
=item * WeblogsPingURL
The URL used to send the XML-RPC I<weblogs.com> ping.
Default value: C<http://rpc.weblogs.com/RPC2>
Example:
WeblogsPingURL http://some.alternate.weblogs.com.server/path/
=item * BlogsPingURL
The URL used to send the XML-RPC I<blo.gs> ping.
Default value: C<http://ping.blo.gs/>
Example:
BlogsPingURL http://some.alternate.blo.gs.server/path/
=item * MTPingURL
The URL used to send the XML-RPC ping to I<movabletype.org> (if you have a
Recently Updated Key).
Default value: C<http://www.movabletype.org/update/>
Example:
MTPingURL http://some.alternate.movabletype.org.server/path/
=item * CGIMaxUpload
When uploading files through Movable Type's upload mechanism, a ceiling is put
on the size of the files that can be uploaded to prevent denial-of-service
attacks.
Default value: C<1_000_000> (1MB)
Example:
CGIMaxUpload 500_000
=item * DBUmask
=item * HTMLUmask
=item * UploadUmask
=item * DirUmask
When creating files and directories, Movable Type uses umask settings to
control the permissions set on the files.
Default values: C<0111> (DBUmask, HTMLUmask, UploadUmask), 0000 (DirUmask)
Example:
DBUmask 0022
=item * HTMLPerms
=item * UploadPerms
In addition to controlling permissions via umask settings, you can also
use the I<HTMLPerms> and I<UploadPerms> settings to control the default
permissions for files created by the system (either as output files or
uploaded files). The only real use of this is to turn on the executable bit
of files created by the system--for example, if MT is generating PHP files
that need to have the executable bit turned on, you could set I<HTMLPerms>
to C<0777>.
Default value: C<0666>
Example:
HTMLPerms 0777
=item * TempDir
When processing uploaded files, if Movable Type notices that the file you
uploaded already exists, it will allow you to overwrite the original file, by
first asking for your confirmation. To do this, MT needs to write the uploaded
data to a temporary file. That temporary file is stored in the directory
specified by the TempDir setting.
Default value: C</tmp>
Example:
TempDir /tmp/
=item * EntriesPerRebuild
When rebuilding individual archives, Movable Type splits up the rebuilding
process into segments, where each segment consists of rebuilding N entries.
The default value for N is 40, so by default, MT will rebuild 40 entries at
a time, then move on to the next 40, etc. You can change that value globally
here; for example, if you have a very stable server, you might wish to just
get it all done with in one batch.
Default value: C<40>
Example:
EntriesPerRebuild 100
=item * ImportPath
The filesystem path to the F<import> directory, which is used when importing
entries and comments into the system--F<import> is the directory where the
files to be imported are placed.
Default value: F<./import>
Example:
ImportPath ./import
=item * UseNFSSafeLocking
By default Movable Type uses Perl's I<flock()> function to lock your databases
while reading and writing. On systems using NFS-mounted directories, however,
Perl's I<flock()> may fail, unless the I<perl> executable has been built to
use I<fnctl(2)> instead of I<flock(2)>; and even then, it is not certain that
the locking will truly work.
Thus, if you have problems running Movable Type on systems using NFS, you can
use the I<UseNFSSafeLocking> directive to use simpler file locking that will
work over NFS.
Default value: C<0> (don't use NFS-safe locking)
Example:
UseNFSSafeLocking 1
=item * NoLocking
On some Windows systems, neither I<flock()> nor I<link()> are available, so
you can't use the default I<flock()> locking, nor can you use the NFS-safe
locking. In such cases, you can turn on the I<NoLocking> option. Note that
you should B<ONLY> do this if your system supports nothing else--it is a
last resort, because it increases the likelihood of database corruption.
However, if you are the only person using the system (for example, if this is
your personal server), this should not be as much of an issue.
Default value: C<0> (use locking)
Example:
NoLocking 1
=item * NoHTMLEntities
By default Movable Type uses the Perl module I<HTML::Entities> to encode
characters into HTML entities, provided that you have this Perl module.
However, in some circumstances, even if you have this module, you may
not wish to use it for encoding; for example, if you are using a language
that uses a different character encoding (Polish, Russian, etc). In that
case, you should set the value of I<NoHTMLEntities> to C<1>.
Default value: C<0> (use I<HTML::Entities>, if it's available)
Example:
NoHTMLEntities 1
=item * PingTimeout
When sending pings--either TrackBack pings or update pings--Movable Type
sets a timeout on the ping, so that it doesn't take too long and appear to
freeze up the system. You can override the default setting of C<15> seconds
by setting a different value with the I<PingTimeout> directive. The value
is assumed to be in seconds.
Default value: C<15>
Example:
PingTimeout 5
=item * ImageDriver
Specifies the image toolkit used to create thumbnails from uploaded images.
By default, the ImageMagick library and Image::Magick Perl module are used;
if your system does not have these, you can use the NetPBM tools instead
(assuming that your system has these tools installed). Possible values for
this setting are I<ImageMagick> or I<NetPBM>.
Default value: C<ImageMagick>
Example:
ImageDriver NetPBM
=item * NetPBMPath
By default, Movable Type looks for the NetPBM tools in three locations:
F</usr/local/netpbm/bin>, F</usr/local/bin>, and F</usr/bin>. If your
NetPBM tools are installed in a different location, you can adjust the
NetPBMPath configuration setting. Note that this path should be the path
to the directory containing the NetPBM binaries; for example, if your
F<pnmscale> binary is at F</home/foo/netpbm/bin/pnmscale>, you should
set the value of NetPBMPath to F</home/foo/netpbm/bin>.
Default value: any of the above three locations
Example:
NetPBMPath /home/foo/netpbm/bin
=item * CommentScript
=item * TrackbackScript
=item * SearchScript
By default, the script that Movable Type uses for comments is called
F<mt-comments.cgi>, the TrackBack script is called F<mt-tb.cgi>, and the
search engine script is called F<mt-search.cgi>. In
some situations--for example, if you are running MT under mod_perl, or if
your server requires that your Perl scripts have the extension F<.pl>--you
may need different names for these scripts. You can set the names that will
be used throughout the default templates and Movable Type code by changing
these values.
Default value: for CommentScript, F<mt-comments.cgi>; for TrackbackScript,
F<mt-tb.cgi>; for SearchScript, F<mt-search.cgi>
Example:
CommentScript comments
TrackbackScript trackback
SearchScript search
=back
=head1 AUTHOR & COPYRIGHT
Please see the I<MT> manpage for author, copyright, and license information.
=cut