Connect to MacOSX over vnc

One of the first unpleasant surprises I had when I first tried MacOSX was that I couldn't connect to it using standard vnc clients available for linux like realvnc or tinyvnc. I was actually able to connect but after the authentication the client would just hang.  I guess the protocol used by apple is a bit different then the protocol used by the rest of the vnc clients.

here are your options:

  1. use another Mac with a vnc client like  the  non free Timbuktu  or the open source Chicken of the VNC.
  2. if you have ssh access to the mac where you want to connect over vnc you can set up Vine server ( also known as OSXvnc ) . Vine is a vnc server that is compatible with realvnc client running on  linux or windows machines.

I chose the second option when possible because I don't want to fire up the macmini every time I needed to connect to a remote machine .

The vine  server comes with a nice GUI and can coexist with the standard MacOSX  vnc server listening on the next available port ( 5901 ) or you can just stop the standard server if you don't need it.

Of course if the system is really remote, you don't have another mac at hand and this is the first time you access it you wouldn't be able to use the GUI so here is how to set start vine form the command line:

  1. connect to the system where you want to install vine over ssh as root or su  root after you have connected as a normal user
  2. download  Vine3.0.dmg  in your home folder or  scp it there .
  3. attach the image:  hdiutil attach Vine3.0.dmg    -  This will make it's contents available in /Volumes/Vine3.0
  4. before you start the server you have to create a password for authentication:
    /Volumes/Vine3.0/Vine\ Server.app/storepasswd    <yourpasswordhere> password_file
  5. start the server:  /Volumes/Vine3.0/Vine\ Server.app/OSXvnc-server  -rfbauth password_file
    The server will output some debuggind information and the last line should be something like:
    Started Listener Thread on port 5901
    The port can be 5900 if the standard vnc server is not already listenting on 5900
  6. leave the ssh session open and use something like realvnc vncviewer  to connect to your server on port 5901 :
    vncviewer mac.machine.name:5901

The only disadvantage of this method is that it requires a bit of work in order to be able to connect but this can be avoided by setting the Vine server to start on boot and that will be explained in another post 🙂

Mount .dmg images from command line

DMG images are the way that a lot of MacOSX binary packages are distributed.  They are somehow like virtual hard disk images or .iso images that you can just mount with a simple double click if you have access to the gui.

But how do you do that from the command line?

quick answer:

  1.  

and the image should now be mounted somewhere in /Volumes

The hdiutil is a tool used to manipulate such disk images. It can do a lot more then just mount the images. It can even burn  them to an optical media, convert them to an iso  and some other formats , even compress them using gzip or bzip2 .

MacOSX case sensitivity

I just got the biggest slap from MacOSX. Yes, I was punished for my ignorance.  I had not idea that the HFS filesystem defaults to case insensitive. I thought it would be case sensitive like in Unix but no.

When I first saw it I didn't believe it. The first clue was when I ran mysql_install_db an I got some warnings about about the filesystem being case insensitive. I didn't believe it because I knew I was able to create files with lower and upper cases so I just ignored it.

The confusion comes from the fact that the HFS+ filesystem is  MyFile.txt would be the same as myfile.txt .  The filesystem preserves cases so it will remember the original file name and a ls will show that but you would be able to access the file with different names. At the first glance this seems like a neat feature but it can actually create big problems when you're interacting with files from case sensitive filesystems.

The slap came from using rsync to backup files from a Linux machine to a macmini machine.   Just imagine a directory with many files split over directories from a to z and A to Z on Linux, something like files/a , files/A, files/b, files/B .

Now rsync -avz -e ssh  files/  backup@macmini:~/files/   and you'll end up with a folder named files on macmini but it will only have the upper case subfolders. The files in the lower case subfolders would be put in the upper case subfolders. This if really bad, it can really break consistency and mess up the data ( imagine different files with the same name one in A and the other in a as just one of the possibilities, there are other like this)

So now, what ? Reformat and change the filesystem to be case sensitive and journaled for easier recovery.
Be careful the next operation will remove all data on your disk:

  1.  

YourDiskId is the disk that you want to erase.It can be disk1, disk2,etc... Look for it using diskutil list

MacOSX for Unix admins

I'm going to write some posts about doing stuff on MacOSX.

I'm a beginner mac user and I come from a Unix background. I use/administrate/patch/develop on Unix like machines ( mostly just Linux and FreeBSD ) on a daily basis.

Since MacOSX has Unix at it's roots using it shouldn't be hard for me to work with it...right...well I'll see how much it has changed.

Sometimes I find it difficult to do something on MacOSX mostly because I am used to how it is done in Unix and because I don't want or can't use the GUI tools.

The fact that most of the tutorials I find are also  explaining how to do stuff in the GUI makes this an even bigger problem.

So I decided that when I actually find out how to do what I want to do I will write a post  about it so I will not have to look for it again.

realtek 8180 on kernel 2.6.23

To make RealTek 8180 wireless cards work in Linux you need the open source drivers from rtl8180-sa2400. Actually this driver supports more realtek cards not just 8180, you can get the list of supported devices from their homepage.

The only problem with those drivers is that they are a bit outdated. They were initially build sometime in 2005 at a time when the kernel version was 2.6.12 . Since then there were patches released to make those drivers work with newer kernels and the latest patch I found was for kernel 2.6.22.You can download the patch from sourceforge . I downloaded that and it just complied and installed without problems.

I loaded the following kernel modules in the exact order :

  1.  

At this point I got the card working but there was no security. I knew this card supports WEP encryption and I was trying to set up a link between the card and a linksys WRT54G router that can also do WEP. When I tried to set a key (WEP ) I the card told me setting a key was not supported by hardware and I got the following error in dmesg: rtl_ieee80211_crypt_wep: could not allocate crypto API arc4

This was very weird because I knew I already loaded the arc4 crypto module . Then why doesn't it work?
After digging a bit in the code I realize that the ecb module is also needed for kernel versions higher then 2.6.15.

After I loaded the ecb module I was able to set a key with iwconfig and the link was up.

To summarize...
in order get this driver working you have to compile your kernel with the following options:

-> Networking
-> Networking support (NET [=y])
-> Wireless
-> Improved Wireless API

for the wireless tools ( iwconfig ) to work
Device Drivers
-> Wireless LAN
I'm not sure if this one is really needed cause the rtl8180 drivers user their own 802.11 stack but it doesn't hurt to enable it as a module, and if you have other wireless devices or you want to ue your card as a host ap you may need tis anyway.

From the Cryptographic API make sure you select ARC4 and ECB

After you compile the kernel you need to load the modules like this:

  1.  

bring up the interface :

  1.  

and set the ESSID and key with iwconfig in order to connect it with the Access point

  1.  

If everything went well you should see something like: wlan0 802.11b linked when typing iwconfig
Next i will try to configure this card to be used as a Host AP.
Did any of you try that ? feel free to share your experiences in the comments.

Update:

There is a new project that forked the rtl8180 driver and ported it to the new 802.11 stack in 2.6.23 kernel. This new project was already included in 2.6.23 but at the moment only support for  rtl8185 is available. The project is rtl-wifi and you might want to watch their page for when they add support for 8180

Explicitly ignorant in Unix

I'm working on a patch for antinat, to make it do some cool/weird stuff that it can't do at the moment.

In case you're wondering antinat is a great implementation of a socks server. It supports socks4, socks5 with user/password authentication, accept/reject acls based on user or ip, easy configuration in an XML file and it's also multithreaded ( ok maybe this is not so great for some but I like it ).

I'm not going to write about the patch I'm working on but maybe I'll write about that in another post.

While I was looking over it's source code I found this funny comment right before a function that was used to handle the SIGPIPE signal:

  1.  

This is funny but the comment has a good point. If you write an application and it tries to write to a connection that was closed, your program will receive a signal with the code SIGPIPE, which means ( according to the man page of the kill program) that if the proces does not have a default handler for SIGPIPE then it will just exit. So there you have a big problem.

The simple solution is to just set your own signal handler for SIGPIPE . So you have to set a function that will be called when the program receives a SIGPIPE and your function doesn't really have to do anything about it, so it will just ignore it and reset the handler to itself.

  1.  

But if you don't explicitly set this, your process will just die upon receiving a SIGPIPE and you really don't want that especially when writing server applications.

Weekend’s piece of shell magic

A few days ago I wrote a post about setting up squid as an anonymous proxy using multiple ips.

That setup would basically make squid listen for connections on certain ips and will create outgoing connections ( for fetching the requested page ) from the same ip that received the connection. The setup, as described in my previous post involves creating one acl and specifying one tcp_outgoing_address for each ip you want to use. Now that's ok if you have just a few ips or even a full class (because you can create one acl to match the whole class ) , but what do you do if you have multiple classes and in each class non consecutive ips? And I'm talking about many such ips not just 10, but 100 or more...

The shell Magic

Well if you have already defined the ips on your interface(s) and you want to use all those ips in squid then you can use this simple shell script that will parse the output of ifconfig and output the acls and tcp_outgoing_address directives for each ip.

  1.  

Run this script on the server where you want to install squid and it will output the acls and directives needed for using all the ips ( except 127.0.0.1 ) . then just copy and paste them into squid.conf.

Now shell magic is nice but if you want to get your hands dirty you might want to look into patching squid to do the same thing. With the squid outoing ip patch you will not have to write any acl or tcp_ougoing_address for it, but of course you'll have to do the "get source - patch - compile" stuff .. which some may find harder and others more fun 🙂

How to buy blogrush credits

I seems some bloggers trust blogrush so much that they bet their money on it.

Yesterday I was looking over my blog and I noticed this ad showing in one of the adsense boxes: "Get Awesome Traffic Results with new Blog Rush. Free...Fast"

It seems someone registered the domain blog-rush.ws and placed a 302 redirect to blogrush.com/rxxxxxx .

This guy is hoping to get enough subscriptions from some high traffic sites. If he's lucky this might even work.Blogrush adwords add

Since I made my first post about blog rush I only got one blog that subscribed from my referral code. But that blog is giving me almost 7000 credits / day.

If I could get a few more like that and blogrush would do something about their CTR I could increase my traffic significantly.

Of course I would have to also start writing some good stuff or else it would be just a waste of clicks.

I wonder how much he's paying for a click, and his returns are...

Hidden Affiliate Links update version 0.2

There is a new version of this plugin. Please download it from the plugin page

After the first release of the Hidden affiliate Links plugin some bloggers wanted to know if this plugin would be able to automatically replace some keywords in posts and turn them into affiliate links.

John Chow bought a plugin for wordpress that does something like that from DealDotCom (yes it's an afiliate link and it was created automatically ) but I know it wouldn't be that hard to add such a functionality to my plugin. So here's the real deal they should put on DealDotCom:

Now my plugin will let you define keywords and it will replace those keywords (when you save/update a post) with a new link you can specify. And it will still work for adding such links manually as the first version does (just don't put anything into keywords or Link fields ) .

The keywords field is actually a field where you can specify a regular expression ( so make sure you escape special characters like - or . (dot ) by placing a \ ( backslash ) in front of them.

Example Use

Let's say you write a post and you want this plugin to replace both the keywords/phrases DealDotCom and "Deal Dot Com" then the content of the keywords column should look like DealDotCom|Deal Dot Com . The "Match slug" field can be go/dealdotcom and the "New link" should be something like "/go/dealdotcom" or "http://patchlog.com/go/dealdotcom" ( without the quotes ) - this is what it looks like on your blog.

Download new version

Hidden Affiliate Links v0.2 zip file / tar.gz file

Installation

If you have already installed version 0.1 you will have to deactivate from wp-admin -> Plugins and delete the table wp_hal_links then just install the new plugin like any other plugin.

Notes

Because the plugin allows you to specify regular expression for the " Match Slug" field you will have to escape some special characters like . (dot ) , _ , - and / by placing a backslash in front of them . I could make the plugin so that this will not be necessary but that would make it lose the great flexibility that regular expression matching can offer.

ToDo:

  • make it configurable so that the user can chose to match case sensitive or insensitive keywords and link slugs. At the moment the match is case sensitive but some users may not like that. It would also be nice to be able to specify this for each link.
  • give the user the option to replace the keywords at runtime (every time the post is rendered). This has the advantage that the keywords on all posts will be replaced ( not just the ones you update after you install the plugin ) but has the disadvantage that it can slow down your blog
  • Anything else you would like ? feed free to let me know in the comments...

BlogRUSH statistics Working!

I just went to check my blogRush account and after login I was presented with a nice looking dashboard showing the number credits I have earned, the number of members I have referred, and how many credits I got from them. It shows how many of those credits were consumed and they even have a nice graph with those numbers.

It's good to see they finally got their statistics working. The reports section still looks looks like under construction.

It would be good if they would also show the number of visitors you got from the widget.

At first I thought I should post some screen shots but you would get a better idea by just logging in to your account.

Oh what is that ? you don't have an account ? Get one now! and drive some traffic to your blog.

 Update: They do show the number of visitors you gor from the widget. I just missed it when I look the first time.