Archive for the ‘hacks’ Category.

How to use Redmine when your Ruby is too new

Recently my work switched to Redmine to keep track of our projects and such, I loved it so much, I wanted to use it at home for my personal projects. Seriously, if you have never used it, give it a try, you won’t be disappointed. However, there is a problem that I ran into when setting it up at home, my Ruby was too new! At the time of this writing Redmine version 1.2.2 was the current stable, and required Ruby 1.8.6 or 1.8.7. My server came with 1.9.1! I could either downgrade and risk possible incompatibility problems, or I could take another approach. After days of Goggling, I found a solution.

Check out https://rvm.beginrescueend.com/rvm/install/

I recommend the single user install. I did it with no problems. Things get a bit tricky when using RVM, so I decided to create this Quick and Dirty Guide.

How to Install and Setup Redmine with RVM

Be sure to pay attention to directories, I will make notes to help make things easy. Also, I recommend trying this out in a VM or a dev box. Please read the HowTos on redmine.org and do some research and testing before following this guide.

Note: This was done running Slackware 13.1. I do NOT use sudo on my machines. If you get a permissions error you can use sudo if your Linux distro is setup for it. The first part of this I did as the root user. If you use sudo, type ‘sudo su -’ to become full root. If you see Redmine (with the capital R), I’m referring to the Redmine program or website. Lowercase, is the user redmine.

After downloading the source from redmine.org extract it and rename the folder to redmine, you don’t have to do this, it’s just how I did it.

Setup a Redmine user

This user doesn’t need remote access, or the ability to login directly. We are going to create a new user and group for Redmine to run under.

groupadd redmine
useradd redmine -g redmine -m

Now set permission to where you extracted Redmine to. We are going to give everything to the redmine user and group.

chown redmine:redmine redmine/ -R

Now you need to su – redmine. Make sure you are in the redmine user’s home directory. Usually /home/redmine/

Setup RVM

Now that you are the redmine user and in their home directory, it’s time to install RVM. Be sure to check out their website for full and up to date information. The information listed here maybe out of date!

Lets install RVM for single user use. You are welcome to use the multi-user version, but this way worked just fine for me. Once again, make sure you are in the redmine user’s home directory.

bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )

This will get the installer going. Once it finishes, run this:

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile

Now logout. Log back in as the redmine user. and type:

type rvm | head -1

You should get back rvm in a function. If not, something went wrong. Try the commands listed above again. If you get an error about a broken pipe, don’t worry about it. I got it once, but never again. I have no idea why.

If you do get back the good news type:

rvm install 1.8.7

This will install ruby 1.8.7! Once it is complete type:

rvm use 1.8.7

If you don’t get back any errors, type:

rvm use 1.8.7 --default

This will set that ruby version as your default (only for the redmine user!) RVM is now setup. Good job!

Install Some Ruby Gems

Now that RVM is setup and Ruby 1.8.7 is installed, we need to setup some gems for ruby. First step is getting the correct version of RubyGems installed. As per the Redmine documentation, we want version 1.3.7. I find the easiest way of doing this is to grab their .tgz file. Once you get it (you can also find a list of versions available for download here. Extract it, and run setup.rb.

wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
tar zxf rubygems-1.3.7.tgz
ruby rubygems-1.3.7/setup.rb

It should only take a second or two to install. Once it’s complete there are two more gems that need to be installed before continuing. It is easy and straight forward. Note: If your system appears to freeze when running the commands below, do not worry. It’s working in the background a may take a minute or two.

gem install rails -v=2.3.11
gem install -v=0.4.2 i18n

Setup MySQL

Assuming you are still the redmine user and MySQL is setup and ready to go, these next steps are very easy and were taken right from Redmine’s website. Follow the steps below.

mysql -u root -p
create database redmine character set utf8;
create user 'redmine'@'localhost' identified by 'redpass';
grant all privileges on redmine.* to 'redmine'@'localhost';
flush privileges;

Take note of redpass. Change it to the password you want to use!

Log out of MySQL and stay logged in as the redmine user. Change directory to where the redmine program is stored. For this example, and the rest of the article, I’m going to assume it’s in /srv/redmine

Copy config/database.yml.example to config/database.yml then edit config/database.yml to include your db setup (under production. You can remove the others)

Copy public/dispatch.cgi.example to public/dispatch.cgi then changes first line to the path of the redmine user’s ruby location (/home/redmine/.rvm/bin/ruby in my case)

public/dispatch.cgi needs to have execute permissions. If it does not, type: chmod 755 public/dispatch.cgi

Uncomment NV['RAILS_ENV'] ||= ‘production’ in config/environment.rb

Now we need to setup MySQL access. Below are four (4) commands that will do all this including building the MySQL gem. Please note the path to mysql_config. Make sure this matches your setup!

rake generate_session_store
gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake redmine:load_default_data

If any of these fail, something may have gone wrong with RVM or MySQL. Check you meet the minimum qualifications listed on Redmine’s website and your paths are correct.

Setup Passenger

Passenger is designed to run as an apache module to keep Ruby of Rails running. If Redmine isn’t used for a while, Ruby of Rails may stop running, it’s not a big deal, it just means it will take a second longer to access your first request. It’s easy to setup, and can be done as the redmine user. So make sure you are still logged in as your redmine user.

I’m running version 3.0.11 or Passenger, you are welcome to do the same. There are only three (3) simple steps involved. So I put them below. Just give it some time to build, it can take a few minutes.

wget http://rubyforge.org/frs/download.php/75548/passenger-3.0.11.tar.gz
tar zxf passenger-3.0.11.tar.gz
./passenger-3.0.11/bin/passenger-install-apache2-module

Once the build finishes there are some lines you need to add to your apache.conf file. They are listed above, they are easy to see. Now, depending on your Linux distro, there are several names and locations for this file. You will need root access to edit the Apache config.

At this point you can stop being logged in as the redmine user. Go back to being root (or your regular user with sudo access)

Setup Apache

This setup worked well for me, I would recommend reading up on Apache config options at http://www.redmine.org/projects/redmine/wiki/HowTo_configure_Apache_to_run_Redmine

The page is a little hard to understand when talking about mod_fcgi and mod_fastcgi. You do NOT need them. They maybe faster, but I find that mod_cgi works just fine.

I’m getting a bit lazy here, and I don’t feel much like going into a lot of explanation on all the options you can use in Apache. Below is a sample of what I used.

<VirtualHost *:80>
   ServerName redmine.<YOUR-DOMAIN>.com
   ServerAdmin webmaster@<YOUR-DOMAIN>.com
   DocumentRoot /srv/redmine/redmine/public/
   ErrorLog /srv/redmine/redmine/log/redmine_error_log
   <Directory "/srv/redmine/redmine/public/">
      Options Indexes ExecCGI FollowSymLinks
      Order allow,deny
      Allow from all
      AllowOverride all
   </Directory>
</VirtualHost>

Obviously there are changes you need to make, like ServerName and ServerAdmin. Note how all the directories start with /srv/redmine/, Update it to where you extracted the Redmine program.

All done!

At this point you should just have to restart apache and you are good to go! Assuming you actually read the Redmine documentation, you can now login as admin (password admin) and give it a go. The first thing I recommend doing is creating a new Admin Level User and removing the default admin. If you get an Internal Error 500 when trying to add a new user, then something is definitely wrong. Check the redmine_error_log and production.log file (both should be in the same directory). If you see something about an error with US_ASCII, then Ruby is not running out of the redmine user’s home directory. Go back through and double check your settings.

I have been told that creating the redmine user in the fashion shown above can create a security risk. As root open /etc/shadow in your favorite editor. At the bottom of the list will be the redmine user. You may see something like:

redmine:!:12585:0:99999:7:::

If you change the exclamation point to an asterisk, it disables the account. That way you can not log into it remotely. Also, if you really want to play it safe, you can edit /etc/passwd also. Just change the last part of the file from /bin/bash to /bin/false. However, by doing this you will not be able to login, or su to that user.

Well?

Did this guide work for you? Do you have any suggestions that may work better? I would love to hear! Feel free to post a comment and let me know how it worked for you, and let me know what Linux distro and version you are running. Thank you.

Wireless Tethering Android with Slackware

Almost two years ago I wrote a how to on tethering with my G1 and Slackware, located here. This was back before I rooted my phone to breathe more life back into it. I still have the phone and plan on having it for a long time. Sure it is as slow as can be, but I still love the full qwerty keyboard… oops, sorry, I’m not here to talk about that. Anyways, like I was saying. I rooted my phone and I’m currently running CyanogenMod 6.0 on my G1.

Wireless Tethering allows you to connect your computer through the phone and use the 3G (or 4G, EDGE, etc) as your internet connection. Some new phones can do wireless tether without rooting, but often times you must pay extra for the service. If you rooted your phone there are two ways of doing wireless tether. First check and see if you have wireless tethering built into your MOD. Go to Settings –> Wireless & networks –> Tethering. If you only see USB tethering then there are extra steps you must take to enable wireless tethering. See the 3 images below. Note that my phone only lists USB Tethering. If your phone is the same, then continue.
img img img

Some people I know are also running CyanogenMod and they have wireless tether built in. Why is that? For starters, since the phone is newer than my G1, they have a more up to date wireless card. These cards can be put into AP mode. This is the same style mode that your wireless router at home uses. Some phones that have wireless tether can also put the card into Ad-Hoc mode. This mode is also known as Computer to Computer without an Access Point. However, it seems that you still need the extra software to do wireless tethering. It is kind of hard for me to explain as I don’t have access to many phone to see how they work. Let alone ones that are rooted. With my G1, I can say that the wireless card was not even designed to operate in Ad-Hoc mode. Thanks to the software I’m running I can force the card into Ad-Hoc mode and connect to it with my laptop.

Keep in mind that wireless tethering will kill your battery quickly. Be sure to have a USB charging cable with you as your battery will not last long. Also note that many service providers do not want you to tether without paying extra. Be sure to read the terms of service of your provider before continuing.

If you made it this far you are going to need extra software. Once again, if your phone is not rooted this will NOT work! Head on over to Google Code to download. At the time of this writing I am running version 2.0.2. A later version has been released, but I have not tested it as mine works very nicely. Download the software to your phone and install. If you don’t know how, I can’t help you.

After installing there are several features to the software. I highly recommend encryption and if you want, Access Control. By default the software uses wpa_supplicant to set the WEP key. This is done via a passphrase. If you like the shell (like I do) you will need to use iwconfig to set the key. Below are some pictures of the settings menu in Wireless Tether.
img img img
img img img

If you use Access Control, before a newly connected device can access the net you will have to allow it. I don’t have pictures, but if I remember it will be in the notification bar. Just drag it down, select the computer/device and hit allow. Later you can look in the Access Control Panel by hitting Menu then Access Control. Here is what mine looks like (and no, the computer is not actually connected. I just have it set to always allow the machines based on it’s MAC address.
img

My laptop has a Broadcom wireless card. I’m using the b43 drivers found here. As it turns out there are several problems found with my current kernel version (2.6.28) and the rc.wireless script that Slackware uses. There are two fixes. One is to remove the b43 module and reload it (this is so we can put the card in Ad-Hoc mode) and I have had problems setting the WEP key via iwconfig. With iwconfig you can set the key (default for this software being ‘abcdefghijklm’) by typing:

iwconfig <card-id> key s:<passphrase>

I always got an error. I solved the problem by using another computer to set the key then you can type iwconfig again and see the key. In this case, the key is 6162636465666768696A6B6C6D. If needs be, write down this key so you can use iwconfig to set it again.

Ok. I hope by now you have the wireless software installed on your Android phone and it is running. Note: I have found that sometimes even when encryption is set it doesn’t turn on. Be sure to scan for wireless networks to see your phone and if encryption is turned on or not. Also note that the software has created an Ad-Hoc style connection. If everything seems to be working here is what you do. In the next steps I will have some bash commands, then a note on what each command does. You may need a make changes to it to suit your needs. I turned it into a script I can run on my laptop so I don’t have to type every line in every time I tether.

rmmod b43   -unloads the b43 module
modprobe b43   -reloads the b43 module
ifconfig wlan0 down   -take the card offline
iwconfig wlan0 mode ad-hoc   -set to Ad-Hoc mode
iwconfig wlan0 essid android   -set the essid (be sure to check your configs)
iwconfig wlan0 key 6162636465666768696A6B6C6D   -set the WEP key (may differ!)
ifconfig wlan0 up   -bring the card online
dhclient wlan0   -get an IP address to your phone

Now type ifconfig and make sure you have an IP. If so, try surfing! If you are a hardcore Slackware user you may note that I use dhclient instead of dhcpcd. For some reason dhcpcd never gets me an IP. If this doesn’t work try it again. Sometimes I have to run the script twice, but I always get it working eventually.

I don’t have a problem with Windows 7 on the same machine. Windows will allow you to type in the paraphrase and it works great. If you’re running Linux and using the b43 module there are several things you can try to fix any problems. I hear the 2.6.33 and newer kernel have these problems fixed. Also if you don’t run a wireless script on boot, that may help. Most newer Linux distributions have GUI programs to help you connect to networks. I’m still running an older version of Slackware, and at the time, it didn’t come with those programs.

Now for some more pictures I took of the program. No reason. I just thought I would share.
img img img
img img img

I hope this all makes sense. If not you can always ask, if I know the answer I will reply. I would also recommend asking on a help forum or asking Google. Good luck and Happy Hacking!

Hacking moviebeam

Some time ago I posted in a forum that I was going to hack a moviebeam box.  Well lets put it this way, it’s kind of a waste of time.  Granted, they say it’s unhackable… not true. I found a great site at http://moviebeam.wikispaces.com/ that gave me a lot of good info.  However, upon my own experiments I have found that it’s a HUGE pain in the ass to try to retrieve movies.  The problem is when you hot swap the hard drive you only get to use it for about 3 min.  This is not enough time to copy a movie off the drive.  However, I was able to start playing a movie… at least once.  It appeared to be in a standard MPEG-2 format, just like DVDs.  So, if you do what is explained on the link above you can get movies.

NOTE! I do not condone stealing! It’s wrong! I did this as an experiment to see if I could do it! It was my first attempt at hardware hacking and I think I did a pretty good job.  Below is a way (only a theory, I did NOT test it) to get a movie.

After you have hot swapped the drive setup apache or an ftp server to point at the directory (ie /mnt/sdb2) so you can see the file listings.  Then from another computer use

wget 

then once the drive stops working repeat the hot swap and use

wget -c 

and it should continue where it left off.

I did NOT try this, it’s only a theory.  I have stopped my attempts to hack the moviebeam box (mostly because the last thing I want is a lawsuit).  If you are able to hack it and steal movies… well shame on you.