About this user

Jacques Marneweck http://www.powertrip.co.za/

« Newer Snippets
Older Snippets »
13 total  XML / RSS feed 

A shell script for setting up the initial lighttpd setup for you

Creates directories and gets the various files for you.

#!/bin/sh
# Setup Lighttpd
#
# $Id: setup-lighthttpd 13 2006-10-15 18:47:25Z jacques $

mkdir ~/var/
mkdir ~/var/log/
mkdir ~/var/run/
mkdir ~/etc/rc.d/
mkdir ~/etc/lighttpd/
mkdir ~/etc/lighttpd/vhosts.d/

cd ~/etc/lighttpd/
curl -o lighttpd.conf "http://help.textdrive.com/index.php?pg=file&from=2&id=77"
cd ~/etc/lighttpd/vhosts.d/
curl -o APPNAME.conf "http://help.textdrive.com/index.php?pg=file&from=2&id=75"
cd ~/etc/rc.d/
curl -o lighttpd.sh "http://help.textdrive.com/index.php?pg=file&from=2&id=79"
curl -o rails.sh "http://help.textdrive.com/index.php?pg=file&from=2&id=80"

chmod 755 lighttpd.sh

touch ~/var/log/lighttpd.access.log
touch ~/var/log/lighttpd.error.log

Johan Sørensen's code to do buffered file uploads in rails

Ruby code to do a buffered file write. Writes chunks of a file to disk from a form post. Ala Johan Sørensen.

File.open("", "wb") do |f|
  while buff = file_field.read(4096)
    f.write(buff)
  end
end

Look for files in a directory in reverse date order

Looking for files in a directory in reverse date order.

ls -la | sort -nr -k 7

Getting HTTP Auth to play nice with PHP run under FastCGI

<?php
/**
 * Get HTTP Auth to work with PHP+FastCGI
 *
 * @author  Jacques Marneweck 
 * @license PHP License v3.01
 */

/**
 * Get HTTP Auth to work with PHP+FastCGI
 */

    

if (isset($_SERVER["AUTHORIZATION"]) && !empty($_SERVER["AUTHORIZATION"])) {

    list ($type, $cred) = split (" ", $_SERVER['AUTHORIZATION']);

    if ($type == 'Basic') {
        list ($user, $pass) = explode (":", base64_decode($cred));
        $_SERVER['PHP_AUTH_USER'] = $user;
        $_SERVER['PHP_AUTH_PW'] = $pass;
    }

}

Not processing javascript in smarty templates

Use {literal}...{/literal} tags around the javascript within your smarty template:

{literal}
<script language="text/javascript">
...
script>
{/literal}

What to do when new kernel does not work

Ocassionally things go bad(tm). This has bit me for the second time in approx 3 years now, but generally one needs to load the old FreeBSD kernel to start debugging and going through a box with a fine toothcomb.

The following snipbit gives you an idea what steps to take when rebooting the server so that you can load the previous working copy of the FreeBSD kernel:
When the boot menu appears hit the spacebar to stop the countdown.
Press "6" for "to escape to loader prompt"
unload
load /boot/kernel.old/kernel
boot

Now the old working FreeBSD kerenl is booting up. It would be recommended to copy the last working version to /boot/kernel.last for example so that you can "load /boot/kernel.last/kernel", especially if you are going to be building your kernel multiple times on a server.

proxy.pac file for Firefox / Mozilla / et. al.

Quite useful for mobile users who work at different locations and require different proxy server settings for each location, just point your Automatic Proxy Configuration URL to your local proxy.pac file and it automatically pics up if it should use a proxy server or not.

function FindProxyForURL(url, host)
{
   if (isPlainHostName(host) ||
       dnsDomainIs(host, ".foobar"))
       return "DIRECT";
    else
        if (isInNet(myIpAddress(), "192.168.99.0", "255.255.0.0"))
            return "PROXY 192.168.99.2:3128; DIRECT";
        else
            return "DIRECT";
}

Backing up subversion repositories from a remote machine

#!/usr/local/bin/bash
#
# Author: Jacques Marneweck 
# License: http://www.php.net/license/3_0.txt PHP License v3.0
# http://www.powertrip.co.za/

LOCALVER=`/usr/local/bin/svnlook youngest /home/svn/livejournal`
REMOTEVER=`/usr/bin/ssh jacques@hostname /usr/local/bin/svnlook youngest /home/svn/livejournal`
echo "Local version is ${LOCALVER}"
echo "Remote version is ${REMOTEVER}"

if [ "$REMOTEVER" -gt "$LOCALVER" ];
then
  echo "Remote version is greater than local version"
  START=$(echo "${LOCALVER} + 1" | /usr/bin/bc -l)
  /usr/bin/ssh jacques@hostname /usr/local/bin/svnadmin dump --incremental --deltas --revision ${START}:${REMOTEVER} /path/to/repo | /usr/local/bin/svnadmin load --ignore-uuid /path/to/repo
else
  echo "Both local and remote version have the same data"
fi

Viewing php configuration settings

<?php
phpinfo();
?>

Getting a copy of a x509 certificate

If you need to easily retrieve a x509 certificate from a remote webserver, the easiest method is:

openssl s_client -showcerts -connect www.example.com:443


Which you can then go and copy from the line starting with '-----BEGIN CERTIFICATE-----' to '-----END CERTIFICATE-----' into the www.example.com.crt file.

Changing your hostname which your mail server sends out

Occassionaly you have a internal mailserver on a machine which has a hostname like machine.example but for mail purposes your machine is known to the outside world as mail.example.com one can use the following helo_data on in your transports for exim to announce yourself as mail.example.com:

remote_smtp:
  driver = smtp
  helo_data = mail.example.com

exim router for relaying via a smarthost

User the "begin routers" section add:

route_append:
    driver = manualroute
    domains = *
    transport = remote_smtp
    route_data = "smarthost.host.name byname"

Using a pre-commit script (written in python)

For some odd reason tortoise SVN loves to commit empty commit sets. So I managed to get the following pre-commit script working under FreeBSD, seeing that the pre-commit.tmpl does not work as expected.

#!/usr/local/bin/python
"""
Subversion pre-commit hook which currently checks that the commit contains
a commit message to avoid commiting empty changesets which tortoisesvn seems
to have a habbit of committing.

Based on http://svn.collab.net/repos/svn/branches/1.2.x/contrib/hook-scripts/commit-block-joke.py
and hooks/pre-commit.tmpl

Hacked together by Jacques Marneweck 

$Id$
"""

import sys, os, string

SVNLOOK='/usr/local/bin/svnlook'

def main(repos, txn):
    log_cmd = '%s log -t "%s" "%s"' % (SVNLOOK, txn, repos)
    log_msg = os.popen(log_cmd, 'r').readline().rstrip('\n')

    if len(log_msg) < 10:
        sys.stderr.write ("Please enter a commit message which details what has changed during this commit.\n")
        sys.exit(1)
    else:
        sys.exit(0)

if __name__ == '__main__':
    if len(sys.argv) < 3:
        sys.stderr.write("Usage: %s REPOS TXN\n" % (sys.argv[0]))
    else:
        main(sys.argv[1], sys.argv[2])
« Newer Snippets
Older Snippets »
13 total  XML / RSS feed