Marius van Witzenburg We fight for our survival, we fight!

17jul/110

How to check if a key exists in an array with in_array for Bash

Posted by mariusvw

When working with Bash it might become handy to have a way to check if a record exists in an array. In PHP you have in_array for this... The below code adds a function similar to the PHP variant.

function in_array() {
  local x
  ENTRY=$1
  shift 1
  ARRAY=( "$@" )
  [ -z "${ARRAY}" ] && return 1
  [ -z "${ENTRY}" ] && return 1
  for x in ${ARRAY[@]}; do
    [ "${x}" == "${ENTRY}" ] && return 0
  done
  return 1
}
 
MASTER=()
CURRENT=()
FIRST=1
for SERVER in ${SERVERS}; do
  # collect all builds from server and populate CURRENT list
  COMMAND="${LS} -1fd ${WEBROOT}/${SITE}.*"
  BUILDS=`${SSH} ${SSHOPTS} root@${SERVER} "${COMMAND}"`
  for BUILD in ${BUILDS}; do
    CURRENT=( ${CURRENT[@]-} ${BUILD} )
  done
 
  # if this is our first time around, copy CURRENT to MASTER
  if [ ${FIRST} -eq 1 ]; then
    MASTER=( ${CURRENT[@]} )
    FIRST=0
  fi
 
  # now we do a compare between MASTER and CURRENT to see what builds
  # are common
  INTERSECT=()
  for ENTRY in ${CURRENT[@]}; do
    in_array "${ENTRY}" "${MASTER[@]}"
    RET=$?
    if [ "${RET}" -eq 0 ]; then
      INTERSECT=( ${INTERSECT[@]-} ${ENTRY} )
    fi
  done
  MASTER=( ${INTERSECT[@]} )
 
  # clear the CURRENT array
  CURRENT=()
done

Source: http://mykospark.net/tag/in_array/

Geëtiketeerd als: , , , Geen reacties
5jul/110

How to test your mail server SMTP communication with Telnet

Posted by mariusvw

SMTP without Authentication

In the below example lines starting with the number 220, 221, 250 and 354 are the responses.

telnet smtp.xs4all.nl 25
220 smtp-vbr10.xs4all.nl ESMTP Sendmail 8.13.8/8.13.8; Tue, 5 Jul 2011 20:07:48 +0200 (CEST)
HELO kitara.nl
250 smtp-vbr10.xs4all.nl Hello srv.kitara.nl [77.74.48.170], pleased to meet you
MAIL FROM: reply@kitara.nl
250 2.1.0 reply@kitara.nl... Sender ok
RCPT TO: marius@kitara.nl
250 2.1.5 marius@kitara.nl... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Subject: Your Subject here
 
Your data here, note the blank line above!
.
250 2.0.0 smtp-vbr10.xs4all.nl accepted message p65I7m0V043931
quit
221 2.0.0 smtp-vbr10.xs4all.nl closing connection
Connection closed by foreign host.

SMTP with Authentication

This example is quite the same as the above one only it implements authentication.

telnet smtp.xs4all.nl 25
220 smtp-vbr10.xs4all.nl ESMTP Sendmail 8.13.8/8.13.8; Tue, 5 Jul 2011 20:07:48 +0200 (CEST)
HELO kitara.nl
250 smtp-vbr10.xs4all.nl Hello srv.kitara.nl [77.74.48.170], pleased to meet you
AUTH LOGIN
<base64 encoded username, mostly full email>
<base64 encoded password>
235 2.0.0 OK Authenticated
MAIL FROM: reply@kitara.nl
250 2.1.0 reply@kitara.nl... Sender ok
RCPT TO: marius@kitara.nl
250 2.1.5 marius@kitara.nl... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Subject: Your Subject here
 
Your data here, note the blank line above!
.
250 2.0.0 smtp-vbr10.xs4all.nl accepted message p65I7m0V043931
quit
221 2.0.0 smtp-vbr10.xs4all.nl closing connection
Connection closed by foreign host.

Here a handy tool to encode or decode your data to base64.
http://ostermiller.org/calc/encode.html (Zip)

And remember kids, don't spam ;-)

4jul/110

How to generate a Windows Live Messenger or MSN Messenger contactlist file with PHP

Posted by mariusvw

If you would like to generate a contact list with PHP to import email addresses into your contact list use the following...

PHP contactlist generator

mysql_connect('localhost', 'username', 'password');
mysql_select_db('database');
 
$doc = new DOMDocument('1.0');
$doc->formatOutput = true; 
 
$node = $doc->createElement('messenger');
$messenger = $doc->appendChild($node);
 
$node = $doc->createElement('service');
$node->setAttribute('name', '.NET Messenger Service');
$service = $messenger->appendChild($node);
 
$node = $doc->createElement('contactlist');
$contactlist = $service->appendChild($node);
 
$result = mysql_query("SELECT `email` FROM `contacts`");
while ($data = mysql_fetch_assoc($result)) {
    $node = $doc->createElement('contact', $data['email']);
    $contactlist->appendChild($node);
}
 
header('Content-type: text/xml');
header('Content-Disposition: attachment; filename=contacts.xml');
echo $doc->saveXML();

Output

<?xml version="1.0"?>
<messenger>
  <service name=".NET Messenger Service">
    <contactlist>
      <contact>email1@domain.tld</contact>
      <contact>email2@domain.tld</contact>
      <contact>email3@domain.tld</contact>
      <contact>email4@domain.tld</contact>
      <contact>email5@domain.tld</contact>
    </contactlist>
  </service>
</messenger>
1jul/110

How to fix ACL errors in diskutility

Posted by mariusvw

If you try to repair permissions and get a bunch of acls found but not expected.

To fix this some chmod commands need to be executed in the terminal.

Essentially open up a terminal and do the following:

cd /
ls -le

Look at the Applications and Library folders in the listing and you should see they have specific ACLs. On one of my machines the Applications folder had 2 and the Library had one. On the other both had just one.

To remove these ACLs do the following:

sudo chmod -a# 0 "/Applications"
sudo chmod -a# 0 "/Library"
# etc...

If you had more than one on either directory you can execute the same command until they are gone.

Geëtiketeerd als: , , , Geen reacties
1jul/110

How to paste into password fields in mobile Safari on your iPhone

Posted by mariusvw

On some sites its not possible to paste a password in a password field. Which sucks! Well this is a simple work around.

In this example I use Facebook.

On this login screen you can bring up the paste button but it is not pasting anything at all.

It becomes blue, nothing happens.

The solution, simply type some characters into the field. And tap hold until you see the menu. There press Select All.

Now you have the bogus password selected and will be able to paste your real password over the bogus one.

You can login now :-)

30jun/112

How to mount a Western Digital ShareSpace NFS share

Posted by mariusvw

This might become handy if you want to connect the drive on a FreeBSD or Linux machine to easy transfer files to it.

Enable NFS on your Western Digital ShareSpace

Log into your web interface and goto Advanced Mode

Goto the tab Network

Goto Services

Here check the Enable checkbox and add the IP of the machine you want to grant access

Next goto Storage

Edit the share preferences

Enable NFS support for this share

Goto Users

Edit the user preferences

Grand optional write access to this user

Connect to NFS mount of ShareSpace on FreeBSD

List mounts

showmount -e 192.168.2.3

Connect mountpoint

# Read only
mount -t nfs 192.168.2.3:/DataVolume/backup /mnt/
# Read / Write
mount -t nfs -o rw 192.168.2.3:/DataVolume/backup /mnt/

Add share to /etc/fstab

172.16.32.44:/DataVolume/backup /backup nfs rw  2   2

Mount with mount -a

Geëtiketeerd als: , , , , 2 Reacties
30jun/110

How to solve the problem that a bluetooth device not always auto connects

Posted by mariusvw

I have been irritating me about my mouse not connecting when I turned it on, the problem seems to be solved by adding the device as a favorite in the bluetooth settings.

First goto System Preferences:

Path:  » System Preferences...

Then goto the Bluetooth panel

Path:  » System Preferences... » Bluetooth

Select your device and click the gear at the bottom, there click Add to favorites.

This was my solution :-)

24jun/110

How to relocate repository root URL of your Subversion working copy

Posted by mariusvw

Ever had this issue a administrator changed the location of the repository?

Well, I had ;-)

Relocating the URL of the repository is quite simple with svn switch --relocate, here you have some simple steps to fix your working copy.

1. Go into the current working copy.

cd /path/to/your/working/copy

2. Get the current repository root URL.

svn info

3. Now switch the old repository root to the new repository root.

svn switch --relocate http://old_repository_root http://new_repository_root

4. Optionally you can verify if the relocate went successful.

svn info
22jun/111

How to make a VPN connection with Mac OS X on your iMac or Macbook (pro) to a FRITZ!Box

Posted by mariusvw

If you need some more info on how to configure your FRITZ!Box check out How to configure VPN on your FRITZ!Box 7340.

Configure your iMac or Macbook (Pro) to use VPN to your FRITZ!Box router VPN service.

First add a new VPN config by clicking the plus at the left bottom.

Next is to select Cisco IPsec and fill out a name at the Service Name field. This can be something like Home VPN.

Next is to fill out the VPN information in this configuration.

  • Server Address: add the IP or Host of your FRITZ!Box WAN connection.
  • Account Name: add YOUR_USERNAME.
  • Password: add YOUR_PASSWORD.

Click Authentication Settings and fill out the following.

  • Shared Secret: YOUR_SHARED_PASSWORD.
  • Group Name: add YOUR_MAIL_ADDRESS.

Geëtiketeerd als: , , , , , , , 1 Reactie
22jun/110

How to make a VPN connection with iOS on your iPod or iPhone to a FRITZ!Box

Posted by mariusvw

If you need some more info on how to configure your FRITZ!Box check out How to configure VPN on your FRITZ!Box 7340.

Configure your iPod or iPhone to use VPN to your FRITZ!Box router VPN.

Goto the "Settings" of your iPod or iPhone and then goto "General".

Goto "Network".

Goto "VPN".

Goto "Add VPN Configuration...".

Fill out the screen below...

  • 1. add your own fancy description.
  • 2. add the IP or Host of your FRITZ!Box WAN connection.
  • 3. add YOUR_USERNAME.
  • 4. add YOUR_MAIL_ADDRESS.
  • 5. add YOUR_SHARED_PASSWORD.

To setup a FRITZ!Box router check out the following, it might help you getting started.

How to configure VPN on your FRITZ!Box 7340

Geëtiketeerd als: , , , , , , , Geen reacties
Page 1 of 3123