Archive

Posts Tagged ‘IT’

Vyhledávání MP3 googlem

January 22nd, 2008 admin No comments

Sorry, this entry is only available in Czech.

Tags:

Instalace Linuxu do Asus WL-500gP

January 12th, 2008 admin 3 comments

Hey guys. Today, I’ve bought a new Asus WL-500g Premium multi functional wireless router. In folowing paragraphs, I’m going to show you, how to uninstall official firmware from Asus and instal open source project OpenWRT based on linux. After that it’s easy to use you router as a rsync, http, ssh, ftp server or as an video surveillance.

Install recipe of OpenWRT to this router is here.

Installing Linux

  • OK, first, I recommend to backup original firmware from your router. Follow the procedure described in section “Backup” here. The script was running about 5 minutes when backuping my router, so stay patient and don’t stop it or power off, otherwise you can destroy your Asus.
  • Download last version of Kamikaze OpenWRT linux clone. Current version for this router is here.
  • Make sure you are connected directly to LAN1 port and you have enabled receiving IP address from DHCP server on your computer’s settings.
  • Install Asus original software from attached CD. Run (but don’t upload fw yet) “Firmware Restoration” tool and enter diag mode on your router using following instructions.
  • Upload a new downloaded TRX file to the router and let it restart by “Firmware Restoration” tool. (takes about 1 minute)
  • Well, we are done. You can connect using telnet 192.168.1.1, without password.

Using USB as a Linux harddrive

There is just 32 MB of storage and RAM (shared) space. So first we need to install USB drivers to be able to install aditional software to the USB instead of internal Asus’es memory. The tutorial is here.

Attention: FAT doesn’t support symbolic links, so programs cannot be installed to FAT easily. We need to reformat FAT into e.g. EXT3. See folowing steps…

  • In the router is “ipkg” package management software. First we update list of resources using:
    ipkg update
  • Now we install drivers for USB (I assume you have USB 2.0 drive):
    ipkg install kmod-usb2ipkg install kmod-usb-storageipkg install kmod-fs-ext3
  • It’s time to reboot the router:
    reboot
  • Now we install tools for formating drive to EXT3 file system:
    ipkg install e2fsprogs
  • Check “dev” directory where is attached USB located:
    dmesg
    fdisk -l
  • Before formating, consider creating partition using fdisk for swap. Format the whole disk to EXT3 fs:
    ipkg install e2fsprogsmke2fs \
       -j /dev/scsi/host0/bus0/target0/lun0/part1

    Tool mke2fs may fail on 300GB and bigger disks. Replace “/dev/scsi/host0/bus0/target0/lun0/part1” with your particular location detected by fdisk -l or dmesg

  • Then we can remove tools for formating, if we know we are not going to need them:
    ipkg remove e2fsprogs libuuid
  • And then, we try to mount the USB as a drive:
    mkdir /mnt/usbmount \
      /dev/scsi/host0/bus0/target0/lun0/part1 /mnt/usb
  • Mount the USB automatically during startup is done by /etc/init.d/usb. Unfortunatelly it seemed to run too early. So let it run as late as possible - edit /etc/init.d/usb - modify START=98 and refresh the links inside rc.d directory and reboot using following commands:
    /etc/init.d/usb enable
    reboot

Learn ipkg to install to your USB drive

As described in this paragraph.

  • Create ipkg destination:
    echo dest usb /mnt/usb >> /etc/ipkg.conf
  • Create ipkg-link script which makes symbolic links to the root user, so you can run any installed software without specifying directory. Copy the source of ipkg-link from here.

Now you can simply install any sw using these 2 steps:

ipkg -dest usb install libncurses
ipkg-link add libncurses

Time to install Python

  • Probably you will first need to manually install libreadline library (or you can skip this step and see whether the installation of Python fails. This “patch” is descibed here.
    ipkg -dest usb install http://downloads.openwrt.org/..
      ..kamikaze/7.06/brcm47xx-2.6/packages/..
      ..libreadline_5.1-1_mipsel.ipk
    ipkg-link add libreadline
  • Install Python:
    ipkg -dest usb install python
    ipkg-link add libexpat
    ipkg-link add libopenssl
    ipkg-link add libpthread
    ipkg-link add uclibcxx
    ipkg-link add zlib
    ipkg-link add python
  • And also you gonna need some editor. For example I like joe.
    ipkg -dest usb install joe
    ipkg-link add joe

Configuring HTTPD to read from USB and to support Python scripts

There is already installed httpd server as a part of BusyBox. You just need to reconfigure it.

  • Change line START to value START=99 inside file /etc/init.d/httpd and e.g. following:
    [ -d /mnt/usb/www ] && httpd -p 80 \
       -h /mnt/usb/www -r ${hostname:-OpenWrt}
  • Refresh START value in rc.d and reboot:
    /etc/init.d/httpd enable
    reboot
  • Now you just need to create /mnt/usb/www and /mnt/usb/www/cgi-bin. Inside cgi-bin create some script and chmod a+x script.cgi. Try e.g. this script:
    #!/usr/bin/python
    print "Content-Type: text/html; charset=ISO-8859-2\n\n"
     
    import os
    import httplib
    import datetime
     
    def run(cmd):
      d = datetime.datetime.now()
      print '<pre>'
      toChild, fromChild, childError = os.popen3(cmd)
      for l in fromChild:
        print l,
      print '</pre>
    Duration: %s' % (datetime.datetime.now() - d)
     
    print '
    <h2>uptime</h2>
    '
    run('uptime')
     
    print '
    <h2>ps</h2>
    '
    run('ps')
     
    print '
    <h2>df</h2>
    '
    run('df')
     
    print '
    <h2>cpu info</h2>
    '
    run('cat /proc/cpuinfo')
     
    print '
    <h2>netstat</h2>
    '
    run('netstat')

Starting wifi

  • Start wifi, set SSID and PSK2 encryption using static key:
    uci set wireless.wl0.disabled=0
    uci set wireless.cfg2.encryption=psk2
    uci set wireless.cfg2.key=some_long_key
    uci set wireless.cfg2.ssid=mySSID
    uci commit wireless && wifi
  • If you want to perform MAC filtering on wifi, create file /etc/init.d/wlmacfilter with following content:
    #!/bin/sh /etc/rc.common
    # The macfilter 2 means that the filter works in "Allow" mode.
    # Other options are: 0 - disabled, or 1 - Deny.
    # wlc ifname wl0 maclist "xx:xx:xx:xx:xx:xx xx:xx:xx:xx:xx:xx"
     
    START=47
    start() {
       wlc ifname wl0 maclist "xx:xx:xx:xx:xx:xx"
       wlc ifname wl0 macfilter 2
    }
     
     
    stop() {
       wlc ifname wl0 maclist none
       wlc ifname wl0 macfilter 0
    }

    Then do following commands:

    chmod 755 /etc/init.d/wlmacfilter
    /etc/init.d/wlmacfilter enable
    reboot
Tags: