" /> Braindump: septembre 2005 Archives

« août 2005 | Main | novembre 2005 »

septembre 30, 2005

NXClient for OSX

L'installation du NXClient se fait comme suit:
# Désarchiver le package .dmg de NXClient
# Copier les programmes ce situant dans le répertoire Application du client NX dans votre répertoire /Application sur votre MAC.
# Copier le contenu du répertoire usr du client NX dans votre répertoire /usr sur votre MAC. Et le tour est joué !

septembre 20, 2005

Cheatsheet for the .htaccess file

Here is a simple cheatsheet for the .htaccess file:

Enable Directory Browsing

Options +Indexes
## block a few types of files from showing
IndexIgnore *.wmv *.mp4 *.avi
Disable Directory Browsing

Options All -Indexes
Customize Error Messages

ErrorDocument 403 /forbidden.html
ErrorDocument 404 /notfound.html
ErrorDocument 500 /servererror.html
Get SSI working with HTML/SHTML

AddType text/html .html
AddType text/html .shtml
AddHandler server-parsed .html
AddHandler server-parsed .shtml
# AddHandler server-parsed .htm
Change Default Page (order is followed!)

DirectoryIndex myhome.htm index.htm index.php
Block Users from accessing the site


order deny,allow
deny from 202.54.122.33
deny from 8.70.44.53
deny from .spammers.com
allow from all

Allow only LAN users

order deny,allow
deny from all
allow from 192.168.0.0/24
Redirect Visitors to New Page/Directory

Redirect oldpage.html http://www.domainname.com/newpage.html
Redirect /olddir http://www.domainname.com/newdir/
Block site from specific referrers

RewriteEngine on
RewriteCond site-to-block\.com [NC]

RewriteCond
{HTTP_REFERER} site-to-block-2\.com [NC]
RewriteRule .* - [F]
Block Hot Linking/Bandwidth hogging

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
Want to show a “Stealing is Bad” message too?

Add this below the Hot Link Blocking code:

RewriteRule \.(gif|jpg)$ http://www.mydomain.com/dontsteal.gif [R,L]
Stop .htaccess (or any other file) from being viewed


order allow,deny
deny from all

Avoid the 500 Error

  1. Avoid 500 error by passing charset
    AddDefaultCharset utf-8
    Grant CGI Access in a directory

Options +ExecCGI
AddHandler cgi-script cgi pl
# To enable all scripts in a directory use the following
# SetHandler cgi-script
Save Bandwidth

  1. Only if you use PHP

    php_value zlib.output_compression 16386

    Password Protecting Directories

Use the .htaccess Password Generator and follow the brief instructions!

The CheckSpelling Directive

From Jens Meiert: CheckSpelling corrects simple spelling errors (for example, if someone forgets a letter or if any character is just wrong). Just add CheckSpelling On to your htaccess file.

The ContentDigest Directive

As the Apache core features documentation says: “This directive enables the generation of Content-MD5 headers as defined in RFC1864 respectively RFC2068. The Content-MD5 header provides an end-to-end message integrity check (MIC) of the entity-body. A proxy or client may check this header for detecting accidental modification of the entity-body in transit.

Note that this can cause performance problems on your server since the message digest is computed on every request (the values are not cached). Content-MD5 is only sent for documents served by the core, and not by any module. For example, SSI documents, output from CGI scripts, and byte range responses do not have this header.”

To turn this on, just add ContentDigest On.

septembre 17, 2005

MT Regex howto

DESCRIPTION

This plugin allows you to define search and replace parameters for
elements you produce from Movable Type templates.

Tags made available through this plugin:

- a utility tag to add a Perl regular expression that
can be used in conjunction with the global 'regex' post processor
attribute.

- a tag for including/excluding content compared with
either a constant value or a regular expression pattern.

- Container tag for processing any portion of a template.

- Returns matches from the contained text.

=======================================================================

These attributes are allowed:

* name
If given, the regular expression can be individually referenced
by name.

* no_html
If specified for a replacement regular expression, it will ignore
any tags

Perl regular expressions are incredibly powerful constructs that can
be used to manipulate text in a variety of ways.

Here's an example (place at the top of your template):

s|:-D||g

The above will replace all occurrances of :-D with a tag that
displays a smiley.gif instead.

In order to activate the search and replace for any given <$MT$>
variable, use the global "regex" modifier:

<$MTEntryBody regex="1"$>

This will 'turn on' the regex operation for that output.

Sometimes you might want to selectively pick and choose from various
regular expression patterns. To do that, name the expressions like
this:

s/Brad/Perl Nut/gi
s|google\(([^\)]+)\)|$1|g

Note: "patt2" shown above gives you the ability to write like this
in your blog entry:

google(some text)

That produces a "Google This" link right in your entry. This kind of
thing is what makes this plugin so useful!

Now, with your <$MT$> vars, you can specify things like this:

<$MTEntryTitle regex="patt1"$> (only applies patt1 to this part)
<$MTEntryBody regex="patt2"$> (only applies patt2 to this part)
<$MTEntryBody regex="1"$> (applies all regex patterns)
<$MTEntryBody regex="patt1 patt2"$> (applies both patt1 and patt2)

You can also specify an inline regex like this:

<$MTEntryBody regex="s/this/that/g"$>

You can only specify a single regular expression using that technique.
Also, you cannot currently use the letter '$' inside an inline
expression due to a parsing limitation in the current (2.21) version
of Movable Type. In order to use '$' in your expressions, create a
named expression using the MTRegexDefine tag.

=======================================================================


This tag allows you to output content based on whether it matches
a value or regular expression.

These attributes are allowed:

* var
If specified, var is evaluated as a Movable Type variable.
The result is used to compare against the constant 'val'
attribute value or the regular expression provided with
the 'pattern' attribute value.

If unspecified, the tag will use the contained data as the
value to compare against the constant/pattern.

* expr
An alternative to 'var' that allows for any Movable Type
expression (use [ and ] instead of < and > for the tag
delimiters).

* value
If specified, value is a string constant to compare with.

* pattern
If specified, pattern defines a named regular expression
or a matching pattern to compare against.

Usage examples:


.. other tags/values here-- outputs data only if content includes the
string 'something' somewhere inside ..

--



.. output entry data (only outputs data authored by Brad, Ben and
Mena ..

--


WOW! We've reached 1,000 blog entries!

--

m/something/


.. other tags/values-- outputs data only if content includes
a match for the named regular expression 'somematch' ..

=======================================================================

This tag allows you to process a block with previously defined regex
patterns, or an individual regex pattern.

These attributes are allowed:

* pattern
Can either be a matching regex which will select named regex
patterns that are selected using that pattern, or a replacement
regex pattern which will be applied by itself.

* no_html
Forces the regex operations to exclude any tags.A

Please note: Perl regular expressions are very powerful, but if you're
not familiar with them already, it will take some time to learn how to
use them. The links provided below are very helpful. Also, be patient
as you are creating them-- if they aren't working, don't assume that
this plugin is at fault-- more than likely, it is an improperly
constructed expression.

=======================================================================

This tag allows you to search the block contained by the Grep tag.
Lines that match the given pattern(s) are taken and joined together
using the 'glue' attribute given (or the newline character if no glue
attribute is specified).

These attributes are allowed:

* pattern
Can either be a matching regex which would be used for matching
the text block or a space-delimited list of named patterns (specified
previously using the RegexDefine tag).

* glue
Text to be used to piece the matches together.

* default
Text to be returned in case no matches are found.

=======================================================================

FOR MORE INFORMATION

Documenting Perl regular expressions goes way beyond the scope of this
readme.txt file. For a tutorial on using Perl regular expressions
visit this page:

http://www.perldoc.com/perl5.6.1/pod/perlretut.html

And for advanced documentation, look here:

http://www.perldoc.com/perl5.6.1/pod/perlre.html

septembre 14, 2005

Rails on Plesk

Rails on Plesk

Hi, folks! It seems a few of y’all might be interested in hearing how to get Ruby on Rails set up on a Plesk server. I did it last month, and it wasn’t terribly difficult, so I thought I’d write a quick guide to the process.
But first, two quick caveats:
1. I did this on a server running PSA 7.5.2 on Red Hat Enterprise Linux 3. The process is probably the same for other Red Hat/Fedora versions, but it might be a bit different on other distros or FreeBSD.
2. I’m assuming that you are comfortable with compiling and installing software from source. If that’s not something you’re familiar with, there is great little howto here that can help you get started.

Step one: Install Ruby

You need Ruby 1.8.2 or later to run rails. If your OS vendor supplies a packaged version for you, use that. Otherwise, you’ll need to download the latest source from ruby-lang.org) and compile it yourself. I didn’t do anything unusual on my ruby installation; just ./configure, make, and make install.

Step two: Install the FCGI Development Kit

There are three pieces of FastCGI software that must be installed on your server to run rails applications: The FastCGI development kit, the mod_fastcgi Apache module, and the Ruby FastCGI bindings. We’ll do the first one now. You can download it from fastcgi.com. This one is just like the Ruby installation: ./configure, make, and make install.

Step three: Install mod_fastcgi

Mod_fastcgi doesn’t have an automated installation process, so this one is a bit more complicated:
1. Download the source code from fastcgi.com and extract it into /usr/local/src.
2. cd mod_fastcgi-2.4.2
3. cp Makefile.AP2 Makefile (this is required since we’re using apache 2.x, not 1.3)
4. Open Makefile in your favorite editor. Change the line that says top_dir = /usr/local/apache2 to top_dir = /usr/lib/httpd
5. make
6. make install

Step four: Install RubyGems

RubyGems is the ruby package manager (If you’re familiar with Perl’s CPAN module, RubyGems is basically the same idea). It can be downloaded from rubyforge.
RubyGems doesn’t use GNU autoconf or automake, so the installation command is a bit different: instead of ./configure, make, and make install, you just do ruby setup.rb all.

Step five: Install Rails, Ruby-FCGI and Ruby-MySQL

Once you have Ruby and RubyGems installed, getting rails is easy: just gem install rails. It will ask you whether it should install some dependencies; say “y” to all of them. When that’s done, gem install fcgi to get the Ruby FastCGI bindings, and gem install mysql to get the Ruby MySQL bindings.

Step six: Configure Apache

To make Apache use the FastCGI module, copy this into /etc/httpd/conf.d/fastcgi.conf:
LoadModule fastcgi_module modules/mod_fastcgi.so
FastCgiWrapper on
FastCgiConfig -idle-timeout 900
Restart apache, and you’re done!

Wait—two more quick notes!

1. This guide only covers server-wide configuration; there are a few tricks to setting up individual rails apps in Plesk as well. If an article about setting up an individual rails app would be helpful to you, drop me a line and I’ll see what I can do. (Update: The follow-up article is available here)

2. This guide is only based on my own experience. If you use it, and find ways that it could be better or more complete, leave a response, and by all means, I’ll do my best to fix it.