Category: Linux

  • Pidgin XEP-0136 Plugin

    XEP-0136 is an XMPP protocol extension used for storing and accessing message archives. Daniel Kraic has written a Pidgin plugin for accessing these archived messages. Below are the brief instructions for installing this plugin in Debian and using it. Generic installation instructions can be found in INSTALL file.

    Installation:

    • Download the plugin (https://github.com/danielkraic/Pidgin-XEP-0136-plugin/tags) and extract it.
      # unzip danielkraic-Pidgin-XEP-0136-plugin-v0.6-0-g74aea04.zip
      # cd danielkraic-Pidgin-XEP-0136-plugin-b22950b
      
    • Install build dependencies and Pidgin headers
      # apt-get install gcc
      # apt-get install pidgin-dev
      
    • Build the plugin.
      # make xep136_plugin.so
      
    • Copy the plugin.
      # mkdir ~/.purple/plugins/
      # cp xep136_plugin.so ~/.purple/plugins/
      
    • To enable the plugin, start Pidgin, go to Tools -> Preferences and enable XEP-0136 plugin.
    • Author Notes:

      You can access history by clicking the “HISTORY” button located at the bottom of Pidgin conversation window. Then “XEP136” window should appears. Next click the “SHOW” button on the right of “XEP-136” window to see list of conversation dates on the left. Select conversation date to see its content.

      It is assumed that you use XMPP server with XEP-0136 extrension support. Ejabberd IM server should works with “mod_archive_odbc” enabled as well as Prosody IM server with “archive” module enabled.

      Feel free to report bugs. Check for future updates at https://github.com/danielkraic/Pidgin-XEP-0136-plugin

      Screenshots:


  • Buliding Vim 7.3 RPM packages for 64-bit CentOS 5 / 6

    Vim 7.3 has one really useful built-in feature – Blowfish encryption. With Blowfish encryption, strong encryption of files is now possible using vim. Here is a short tutorial on how to build RPM packages for Vim 7.3 on 64-bit CentOS 5 and CentOS 6. I have built the packages as user ‘root’. However, it is generally not recommended to build packages as ‘root’. Instead, this should be done as a normal user. I have not tried this but if you are interested, you can look at the links in the References section.

    1. Install rpmbuild and some other tools.
      # yum install rpm-build redhat-rpm-config
      # yum install make gcc
      
    2. Download and install vim 7.3 SRPM.
      # wget "http://download.fedora.redhat.com/pub/fedora/linux/releases/15/Everything/source/SRPMS/vim-7.3.138-1.fc15.src.rpm"
      # mkdir -p /usr/src/redhat/ #(for CentOS 5 only)
      # rpm --nomd5 -ivh vim-7.3.138-1.fc15.src.rpm
      
    3. Install vim build dependencies
      # grep -i 'BuildRequires:' /usr/src/redhat/SPECS/vim.spec
      # yum install hunspell-devel python-devel ncurses-devel gettext perl-devel \
      perl-ExtUtils-Embed libacl-devel gpm-devel autoconf libselinux-devel ruby-devel ruby \
      desktop-file-utils gtk2-devel libSM-devel libXt-devel libXpm-devel
      

      For CentOS 5 only, upgrade autoconf and m4 packages, and remove build dependency on ‘perl-devel’.

      # wget "ftp://rpmfind.net/linux/sourceforge/h/project/hp/hphp/CentOS%205%2064bit/RPM/autoconf-2.63-3.noarch.rpm"
      # wget "ftp://rpmfind.net/linux/sourceforge/h/project/hp/hphp/CentOS%205%2064bit/RPM/m4-1.4.13-4.x86_64.rpm"
      # rpm -Uvh autoconf-2.63-3.noarch.rpm m4-1.4.13-4.x86_64.rpm
      
      # sed -i 's/ perl-devel//' /usr/src/redhat/SPECS/vim.spec
      

      Alternatively, for CentOS 6, you can install the build dependencies using “yum-builddep” command.

      # yum install yum-utils
      # yum-builddep --nogpgcheck vim-7.3.138-1.fc15.src.rpm
      
    4. Finally build vim rpms using rpmbuild.
      # rpmbuild -ba /usr/src/redhat/SPECS/vim.spec #(for CentOS 5)
      # rpmbuild -ba ~/rpmbuild/SPECS/vim.spec #(for CentOS 6)
      

      You should find the rpms in /usr/src/redhat/RPMS/x86_64/ (CentOS 5) or ~/rpmbuild/RPMS/x86_64/ (CentOS 6). Unfortunately while the build was successful in CentOS 5, it failed in CentOS 6.

    Vim plugin for transparent editing of gpg encrypted files

    Although Vim now offers Blowfish encryption, I highly recommend using Vim’s gnupg plugin. The reason being apart from providing strong encryption, this plugin also takes care of not creating swap files and not writing any information to .viminfo file. The easiest way to convert any text file to GPG symmetric encrypted file is by running the command:

    # gpg -ac passwords.txt
    

    This will create the file “passwords.txt.asc”. Once the gnupg plugin is installed, vim can be used to open and modify this file.

    References

    • http://wiki.centos.org/HowTos/SetupRpmBuildEnvironment
    • http://wiki.centos.org/HowTos/RebuildSRPM
    • http://download.fedora.redhat.com/pub/fedora/linux/releases/15/Everything/source/SRPMS/
    • http://rpmfind.net/linux/rpm2html/search.php?query=m4
    • http://rpmfind.net/linux/rpm2html/search.php?query=autoconf
    • http://awesometrousers.net/post/vim-with-gpg-file-encryption/
  • Integrating iJab with Roundcube

    Integrating iJab with Roundcube is a good solution for having web based Mail+XMPP (jabber) client. Steps for configuring iJab can be found on its website. Here I shall mention how you can integrate both of them:

    • Below is a sample html file for loading both iJab and Roundcube together:
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <!-- The HTML 4.01 Transitional DOCTYPE declaration-->
      <!-- above set at the top of the file will set     -->
      <!-- the browser's rendering engine into           -->
      <!-- "Quirks Mode". Replacing this declaration     -->
      <!-- with a "Standards Mode" doctype is supported, -->
      <!-- but may lead to some differences in layout.   -->
      
      <html style="height: 100%; padding: 0; margin: 0; border: none;">
      <body style="height: 100%; padding: 0; margin: 0; border: none;">
        <iframe style="height: 100%; width: 100%; padding: 0; margin: 0; border: none;" src="/roundcubemail-0.4/"></iframe>
        <script type="text/javascript" language="javascript" src="/ijab-v1.0-beat3-2/ijab_config.js"></script>
        <script type="text/javascript" language="javascript" src="/ijab-v1.0-beat3-2/ijab_i18n_en.js"></script>
        <script type="text/javascript" language="javascript" src="/ijab-v1.0-beat3-2/ijab/ijab.nocache.js"></script>
      </body>
      </html>
      
    • Further to auto login to iJab when you enter username and password in roundcube webmail as well as auto logout when you logout from roundcube, download my Roundcube iJab plugin, extract it to roundcube “plugins” folder and add “ijab” to the list of roundcube plugins in “main.inc.php”.
      Previously I had used a dirty hack of modifying skins/default/templates/login.html file as I did not know how to write roundcube plugin then. If you had modified that file earlier, then I suggest you revert those changes and use the above plugin instead.
    • BONUS: Logout shortcut for iJab. Add the below shortcut to /ijab-v1.0-beat3-2/ijab_config.js:
      {
          href:"javascript:iJab.logout()",
          target:"_self",
          img:"/ijab-v1.0-beat3-2/ijab/images/logout.png",
          text:"Logout"
      }
      

      You can download logout.png here

    References:

    http://code.google.com/p/ijab/ – iJab Website
    http://code.google.com/p/ijab/w/list – iJab Wiki
    http://www.ijab.im/node/4 – iJab Demos
    http://www.ijab.im/node/88 – Integrating iJab into your website
    http://www.ijab.im/node/90 – iJab API
    http://code.google.com/p/ijab/wiki/iJabWithEjabberd – Integrating iJab with Ejabberd

  • Installing ZK Spreadsheet in Debian Lenny

    ZK spreadsheet is an online spreadsheet which enables users to import and export excel files and edit excel files within the browser. This can be thought to be similar to Google Spreadsheet. Only that it is open source and can be installed on your own server. Another very similar open source product which I came across was Sheetster but the setup was not very straight forward and also I was not really impressed with the UI and functionality.

    Below, I give the steps for installing ZK spreadsheet on Debian Lenny:

    1. First we install tomcat5.5.
      # apt-get install tomcat5.5 tomcat5.5-webapps tomcat5.5-admin

      Accessing http://localhost:8180/ should display the default Tomcat home page.

    2. Download ZK Spreadsheet Demo (Executable) from http://code.google.com/p/zkspreadsheet/. During the time of writing this article, the beta version did not have Save and Import features enabled. So I proceeded to download the stable version from http://sourceforge.net/projects/zss/files/ZK%20Spreadsheet/. Either way the procedure for installation is the same.
    3. Extract it and move the war files to webapps directory.
      # unzip zk-spreadsheet-demo-2.0.0-Beta.zip
      # cd zk-spreadsheet-demo-2.0.0-Beta
      # mv zssapp.war zssdemo.war /var/lib/tomcat5.5/webapps/
      
    4. Make the below modifications in /etc/tomcat5.5/policy.d/03catalina.policy.
      ...
      ...
      ...
      // These permissions apply to JULI
      grant codeBase "file:${catalina.home}/bin/tomcat-juli.jar" {
      ...
      ...
      ...
          permission java.io.FilePermission "${catalina.base}${file.separator}webapps${file.separator}zssapp${file.separator}WEB-INF${file.separator}classes${file.separator}logging.properties", "read";
          permission java.io.FilePermission "${catalina.base}${file.separator}webapps${file.separator}zssdemo${file.separator}WEB-INF${file.separator}classes${file.separator}logging.properties", "read";
      };
      ...
      ...
      ...
      //added for zssapp webapp
      grant codeBase "file:${catalina.base}/webapps/zssapp/-" {
             permission java.security.AllPermission;
      };
      
    5. Restart tomcat5.5.
      # /etc/init.d/tomcat5.5 restart

      The ZK spreadsheet should now be accessible at http://localhost:8180/zssapp/ and the demo at http://localhost:8180/zssdemo/.

    6. The spreadsheet documents are stored in the zssapp web application directory. To protect others from reading this data, you need to perform the below two steps:
      • First limit access to this directory in the filesystem.
        # chmod 700 /var/lib/tomcat5.5/webapps/zssapp/
      • Next add some kind of authentication for the webapp. The possible authentication mechanisms in Tomcat 5.5 are mentioned in http://tomcat.apache.org/tomcat-5.5-doc/realm-howto.html which can be used for reference. A sample configuration can be found at http://www.jguru.com/faq/view.jsp?EID=1131436.

    If you face any issues or have any queries reg. ZK Spreadsheet, you can post in the forum at http://www.zkoss.org/forum/.

    References:

    http://ostatic.com/question/open-source-web-spreadsheet
    http://en.wikipedia.org/wiki/List_of_spreadsheet_software#Online_spreadsheets
    http://en.wikipedia.org/wiki/List_of_online_spreadsheets

    How to setup Apache Tomcat 5.5 on Debian Etch


    http://www.mkyong.com/tomcat/tomcat-javasecurityaccesscontrolexception-access-denied-loggingproperties-read/
    http://www.zkoss.org/forum/listComment/9143

  • System Harware Information in Linux

    All-In-One Tools

    Hardware Lister:

    Hardware Lister can be used for getting all the hardware information of a system. Some example usage are given below:

    # apt-get install lshw lshw-gtk
    # lshw (Displays detailed hardware information)
    # lshw-gtk (Gives a nice graphical view of the hardware information) 
    # lshw -short (Lists hardware in a compact format)
    # lshw -class disk -class storage (Lists all disks and storage controllers in the system)
    # lshw -html -class network (Lists all network interfaces in HTML)
    

    Refer to the link in the References section to get the complete list of device classes.

    Dmidecode:

    Another tool which serves a similar purpose is dmidecode.

    # apt-get install dmidecode
    # dmidecode (Display detialed hardware information)
    # dmidecode --type bios (Display information related to BIOS)
    

    The various types permitted can be got from the manpage of dmidecode.

    Component Information

    Most of the below commands should be run as root.

    BIOS:
    Retrieve BIOS information such as Vendor, Version, Characteristics, etc.

    # dmidecode --type bios
    # biosdecode
    

    System:
    Retrieve a lot of useful information such as Manufacturer, Product Name, Version, Wake-up Type, etc.

    # lshw -class system
    # dmidecode --type system
    

    Motherboard:
    Prints motherboard information such as Manufacturer, Product Name, Serial Number and also information of onboard devices.

    # dmidecode --type baseboard
    # lspci
    

    Processor:
    Get processor information such as the Manufacturer, Version, etc.

    # lshw -class processor
    # dmidecode --type processor
    # cat /proc/cpuinfo
    

    Memory:
    Get memory information such as the numver of memory slots, RAM information in each slot (if installed), etc.

    # lshw -class memory
    # dmidecode --type memory
    # cat /proc/meminfo
    # free -m
    

    PCI/PCIe Slots and USB devices:
    Retrieve information about onboard PCI slots, attached USB devices, etc.

    # lshw -class bus
    # dmidecode --type connector --type slot
    # lspci
    # lsusb
    

    Hard Disk(s):
    Retrieve hard disk(s) details such as size, model, etc.

    # lshw -class storage -class disk --class volume
    # fdisk -l
    # hdparm -I /dev/sda
    

    VPD:
    VPD stands for “vital product data” information that can be found in almost all IBM and Lenovo computers.

    # vpddecode
    

    System Hardware Snapspot

    This is especially useful when giving your laptop or desktop to service centres for repair. You can take a snapshot before and after and compare them to ensure that no parts have been replaced. It is highly recommended that you run the below commands as root.

    # lshw -short > lshw.short
    # lshw -xml > lshw.xml
    # lshw -json > lshw.json
    # lshw -html > lshw.html
    

    References

    http://www.cyberciti.biz/faq/linux-list-hardware-information/
    http://www.cyberciti.biz/tips/querying-dumping-bios-from-linux-command-prompt.html
    http://legroom.net/2010/05/05/get-biosmotherboard-info-within-linux
    http://www.cyberciti.biz/tips/linux-command-to-gathers-up-information-about-a-linux-system.html
    http://www.cyberciti.biz/faq/find-hard-disk-hardware-specs-on-linux/

    http://www.nongnu.org/dmidecode/
    http://ezix.org/project/wiki/HardwareLiSter#Deviceclasses

  • Configuring OpenVPN Client in DD-WRT

    After spending almost a day in trying to configuring my dd-wrt router as an OpenVPN client and reading many complicated guides, I found a really simple way to configure OpenVPN. It is necessary that you have optware set up on your router. For setting up Optware, kindly read Optware, The Right Way.

    This configuration has been tested with DD-WRT K26 svn 14569 mega build (of Brainslayer) on a WRT610Nv1 router. Configuration of OpenVPN server is beyond the scope of this article. But here is an excellent article on how to setup OpenVPN server in Debian.

    1. Install openvpn using ipkg.
      # ipkg-opt update
      # ipkg-opt install openvpn
      
    2. Dump your vpn configuration file in /opt/etc/openvpn/. Let us assume the name of the configuratoin file is example.vpn.conf. You might have to make certain changes in the configuration file such as:
      • Setting the name of the user and group in the config file to that which are existing on the router. ‘nobody’ user and ‘nobody’ group exist on the system so you can use these. If you intend to use the route-down.sh script (see below), you will have to set these to ‘root’ user and ‘root’ group. For route-up.sh script though, it is fine if you use ‘nobody’ user and ‘nobody’ group because the downgrade of privileges by openvpn client happens after the route-up.sh script is called.
      • Setting the correct paths for key and certificate files in example.vpn.conf.
    3. Test if openvpn connection is being established by running the below command.
      # /opt/sbin/openvpn --cd /opt/etc/openvpn --config example.vpn.conf
      

      If the connection is being established properly you may proceed to the next step.

    4. Set up the scripts for allowing machines behind the dd-wrt router to access clients in the VPN network and for clients in the VPN network to access the dd-wrt router.

      /opt/etc/openvpn/route-up.sh:

      # Enable machines behind the router to access the clients in VPN network
      /usr/sbin/iptables -I POSTROUTING -t nat -o tun0 -j MASQUERADE
      
      # Enable the clients in the VPN network to access the router
      /usr/sbin/iptables -I INPUT -t filter -i tun0 -j ACCEPT
      

      /opt/etc/openvpn/route-down.sh:

      # Disable machines behind the router to access the clients in VPN network
      /usr/sbin/iptables -D POSTROUTING -t nat -o tun0 -j MASQUERADE
      
      # Disable the clients in the VPN network to access the router
      /usr/sbin/iptables -D INPUT -t filter -i tun0 -j ACCEPT
      

      Test the connection again.

      # chmod 755 route-up.sh route-down.sh
      # /opt/sbin/openvpn --cd /opt/etc/openvpn --config example.vpn.conf --script-security 2 system \
      --route-up /opt/etc/openvpn/route-up.sh --down /opt/etc/openvpn/route-down.sh
      

      Note: For advanced users who can configure OpenVPN server, it is possible for the clients in the VPN network to access the private subnet behind the router. Roughly summarizing, this can be achieved by setting up internal routes in the OpenVPN server to redirect all traffic to the private subnet to the router, pushing additional routes to the VPN clients, and allowing forward/masquerading in the router.

    5. In this last step, we enable openvpn client to connect automatically during startup. Edit /opt/etc/init.d/S20openvpn and make the following changes:
      • Comment the statement “return 0” so that we can keep run openvpn as a daemon.
      • Set the proper path for killall command (/usr/bin/killall).
      • Add the line “/opt/sbin/openvpn –daemon –cd /opt/etc/openvpn –config example.vpn.conf –script-security 2 system –route-up /opt/etc/openvpn/route-up.sh –down /opt/etc/openvpn/route-down.sh” at the bottom.

      /opt/etc/init.d/S20openvpn:

      #!/bin/sh
      #
      # Startup script for openvpn as standalone server
      #
      
      # Make sure IP forwarding is enabled
      echo 1 > /proc/sys/net/ipv4/ip_forward
      
      # Make device if not present (not devfs)
      if ( [ ! -c /dev/net/tun ] ) then
        # Make /dev/net directory if needed
        if ( [ ! -d /dev/net ] ) then
              mkdir -m 755 /dev/net
        fi
        mknod /dev/net/tun c 10 200
      fi
      
      # Make sure the tunnel driver is loaded
      if ( !(lsmod | grep -q "^tun") ); then
              insmod /opt/lib/modules/tun.o
      fi
      
      # I you want a standalone server (not xinetd), comment out the return statement below
      #return 0
      
      
      ## This is for standalone servers only!!!!
      # Kill old server if still there
      if [ -n "`pidof openvpn`" ]; then
          /usr/bin/killall openvpn 2>/dev/null
      fi
      
      # Start afresh - add as many daemons as you want
      #/opt/sbin/openvpn --daemon --cd /opt/etc/openvpn --config openvpn.conf
      /opt/sbin/openvpn --daemon --cd /opt/etc/openvpn --config example.vpn.conf --script-security 2 \
                        --route-up /opt/etc/openvpn/route-up.sh --down /opt/etc/openvpn/route-down.sh
      
      # [EOF]
      

      Test the script.

      # chmod u+x /opt/etc/init.d/S20openvpn
      # /opt/etc/init.d/S20openvpn
      
    6. Rebooting the router should now get you connected automatically to your VPN network.
  • Internet Radio Player

    UPDATE: Nightangle is now available for download. Ubuntu PPA repo is available as well . See http://getnightingale.com/all-versions.php.
    UPDATE: Songbird linux builds are available through contributed builds – http://wiki.songbirdnest.com/Developer/Articles/Builds/Contributed_Builds

    Long back, when I was in IIIT, I used a small player known as Nitin’s online radio player (runs only on Windows) which used to sit in the system tray and play online streaming radio channels. It had a small pop-up to switch between radio channels and was one of my favourite sources for listening to music. Six years later, I again wanted to have a similar radio but something which runs in Linux. My search revealed several players which supported this. But the best among them turned out to be mozilla based cross-platform Songbird with its Shoutcast Plugin. Shoutcast Radio is a website which publishes the list of online servers which stream using the shoutcast protocol. Among the other linux players I explored were Amarok, RhythmBox, Banshee, streamtuner, Listen, Banshee, Exaile and MPD (with GMPC). But only Songbird’s Shoutcast Plugin had all the options which I wanted such as viewing the current number of listens, browsing by genre and bookmarking the favourite station.

    The only problem with Songbird is that it has recently announced that it will no longer support Linux. Nevertheless, an open source project Nightingale has already spun off which will continue to support Linux.

  • trash-cli

    There is one feature I often missed in linux console – deleting to Trash. I often do a ‘rm -rf’ and then suddenly realize that I have accidentally deleted something which I shouldn’t have. From now on, I needn’t worry because I have started using trash-cli, a command line interface to the freedesktop.org trashcan. This small utility provides commands to delete and restore files from the console. The version shipped with Debian is really old and has a serious bug which could destroy data. Updated version now available in Debian repos and this should be preferred to the next mentioned method. Run the below commands as root to install it:

    # apt-get install python-setuptools
    # easy_install --prefix=/usr/local trash-cli
    

    Instructions for installing on other distributions are at http://code.google.com/p/trash-cli/wiki/Download. Usage instructions can be found in the home page of trash-cli itself.

    This is yet another one of those linux utilities which is very simple but is extremely useful. I love Linux !!!

  • BackupPC with Lighttpd in DD-WRT

    This tutorial covers the necessary steps to get BackupPC up and running on any device (such as the Linksys router WRT 610N) which has DD-WRT firmware installed on it.

    In case there are any steps which I have missed, kindly mention them in the comments section, and I will update the main article accordingly.

    Installing DD-WRT Firmware

    The first step obviously is to install the right DD-WRT firmware on your device. The instructions for this are beyond the scope of this tutorial. It should be noted that certain K26 builds have swap disabled. Make sure that swap is enabled in the firmware which you are installing.

    After installing DD-WRT, go to Setup->Basic Setup->Time Settings and enable NTP Client. I suggest you leave the timezone as UTC because setting any other timezone will make the system time go out of sync with DD-WRT time (this can be seen when you log into the router via SSH and type the “date” command).

    Enabling SSH

    Next you will have to enable SSH in DD-WRT. For this, you will have to enable the SSH server in Services -> Services -> Secure Shell -> SSHd. Make sure that you are able to SSH successfully to your router as user ‘root’.

    Checking internet access
    As soon as you log into the router via SSH, you need to check access for internet connectivity. This can be done by simply doing a ping on google.com. If your router is set up with proper internet connectivity, then you should get a proper ping response as below.

    # ping -c 3 google.com
    PING google.com (216.239.59.99): 56 data bytes
    64 bytes from 216.239.59.99: icmp_seq=0 ttl=51 time=295.261 ms
    64 bytes from 216.239.59.99: icmp_seq=1 ttl=51 time=298.034 ms
    64 bytes from 216.239.59.99: icmp_seq=2 ttl=51 time=301.029 ms
    --- google.com ping statistics ---
    3 packets transmitted, 3 packets received, 0% packet loss
    round-trip min/avg/max/stddev = 295.261/298.108/301.029/2.355 ms
    

    In my case though, my router was actually being used as a switch. Therefore I had to perform the below two additional steps to make internet accessible from within it:

    1. In Setup -> Basic Setup -> Network Setup -> Gateway, I had to give the IP address of the gateway.
    2. Next I had to add DNS servers. In order to do this at boot time, I appended the following line to Administration -> Commands -> Startup at the beginning:
      echo -e "nameserver 208.67.222.222\nnameserver 208.67.220.220" >> /tmp/resolv.conf

      This means that whenever the router starts it will add these two nameservers (which are those of OpenDNS) to /etc/resolv.conf.

      Alternatively, if you have enabled DHCP server, you can also try to setup OpenDNS (or any static DNS) by following the instructions at http://www.dd-wrt.com/wiki/index.php/OpenDNS#Basic_Setup.

    Setting up Optware
    Follow the instructions mentioned in http://www.dd-wrt.com/wiki/index.php/Optware%2C_the_Right_Way to set up your system with optware. The instructions are very clear and you should not face a lot of difficulty in setting it up.

    • Make sure that the size of the /opt partition is 1 GB (as we will be running a lot of installations) and the size of the swap space is at least 512 MB because BackupPC requires a lot of memory. Running the “free” command in the router should show give you memory details.
      # free
                   total       used       free     shared    buffers     cached
      Mem:         59984      58500       1484          0      28352      12568
      -/+ buffers/cache:      17580      42404
      Swap:      1052248       7868    104438
      
    • “ipkg-opt” is the utility which we use for package maintenance (this is similar to apt-get / yum). Just entering ipkg-opt without any arguments, should list all the available sub-commands (the most useful of them being “update”, “remove”, “install”, “list”, “files” and “search”).
      # ipkg-opt
      # ipkg-opt update
      
    • When using USB storage (or maybe other form of storage as well), in order to automount the remaining partitions, the packages ‘util-linux-ng’ and ‘grep’ should be installed as well. Restarting the automount service after installing these packages should mount the partitions.
      # ipkg-opt install util-linux-ng grep
      # service automount stop
      # service automount start
      

    BackupPC dependencies

    The documentation for BackupPC is available at http://backuppc.sourceforge.net/faq/BackupPC.html. First we need to install BackupPC dependencies mentioned in this page.

    • Most of the dependencies are installed while setting up Optware in the previous section. I will cover the remaining or the most important packages here:
      # ipkg-opt install perl
      # ipkg-opt install samba2
      # ipkg-opt install tar
      # ipkg-opt install rsync
      # ipkg-opt install par2cmdline 
      
    • The default SSH client provided by dd-wrt (at /usr/bin/ssh) might not be very useful to use with BackupPC because of its limited set of options. Therefore we install openssh package which should install the OpenSSH client at /opt/bin/ssh.
      # ipkg-opt install openssh
      

      But it should be noted that this package will also install the OpenSSH server. This has to be disabled so that it does not conflict with the default SSH server provided by DD-WRT. Therefore in /opt/etc/default/openssh, change

      SSHD_ENABLE=yes

      to

      SSHD_ENABLE=no

      This should prevent OpenSSH server from starting at boot time.

    • Apart from the above utilities, BackupPC has the following perl modules as dependencies – Compress::Zlib, Archive::Zip, File::RsyncP and XML::RSS.
      1. Compress::Zlib can be installed directly from the optware repo.
        # ipkg-opt install perl-compress-zlib
        
      2. Similarly, Archive::Zip can be installed directly from the optware repo.
        # ipkg-opt install perl-archive-zip
        
      3. For File::RsyncP, first we set up the build environment. This build environment will also be useful for installing other perl modules. Then we download the source from Perl CPAN and install it.
        # ipkg-opt remove wget
        # ipkg-opt install buildroot optware-devel
        
        # wget http://search.cpan.org/CPAN/authors/id/C/CB/CBARRATT/File-RsyncP-0.68.tar.gz
        # tar zxvf File-RsyncP-0.68.tar.gz
        # cd File-RsyncP-0.68
        # perl Makefile.PL
        # make CC=mipsel-linux-uclibc-gcc AR=ar LD=ld LINKTYPE=dynamic LDDLFLAGS="-shared -O2"
        # make CC=mipsel-linux-uclibc-gcc AR=ar LD=ld LINKTYPE=dynamic LDDLFLAGS="-shared -O2" test
        # make CC=mipsel-linux-uclibc-gcc AR=ar LD=ld LINKTYPE=dynamic LDDLFLAGS="-shared -O2" install
        
      4. Our last perl module, XML::RSS, has a lot of dependencies (this can be seen clearly in http://deps.cpantesters.org/?module=XML%3A%3ARSS&perl=5.8.8&os=any+OS). Therefore, following the steps similar to those mentioned in http://www.livejournal.com/doc/server/lj.install.perl_setup.modules.html, we can install from CPAN directly. Please note that XML::RSS module is necessary only if you plan to use BackupPC RSS feed. As I was not planning to use the RSS feed and the installation of the module was taking long, I chose to ignore this dependency. Therefore the below steps are not tested.

        First we start the CPAN shell.

        # export CC=mipsel-linux-uclibc-gcc AR=ar LD=ld LINKTYPE=dynamic LDDLFLAGS="-shared -O2"
        # perl -MCPAN -e shell
        cpan>
        

        (Optional) Upgrade the CPAN module.

        cpan> install Bundle::CPAN
        cpan> reload cpan
        

        Finally, install XML::RSS perl module.

        cpan> install XML::RSS
        cpan> exit
        

    Installing BackupPC

    Next we come to the installation of BackupPC. First download the package from http://backuppc.sourceforge.net/. Next run these commands.

    # tar -xvzf BackupPC-3.1.0.tar.gz
    # cd BackupPC-3.1.0
    # perl configure.pl --config-dir=/opt/etc/backuppc --log-dir=/opt/var/log/backuppc 
    
    Is this a new installation or upgrade for BackupPC?  If this is
    an upgrade please tell me the full path of the existing BackupPC
    configuration file (eg: /etc/BackupPC/config.pl).  Otherwise, just
    hit return.                                                       
    
    --> Full path to existing main config.pl []? 
    
    I found the following locations for these programs:
    
        bzip2        => /opt/bin/bzip2
        cat          => /opt/bin/cat  
        df           => /opt/bin/df   
        gtar/tar     => /opt/bin/tar  
        gzip         => /opt/bin/gzip 
        hostname     => /opt/bin/hostname
        nmblookup    => /opt/bin/nmblookup
        par2         => /opt/bin/par2     
        perl         => /opt/bin/perl     
        ping         => /opt/bin/ping     
        rsync        => /opt/bin/rsync    
        sendmail     => /usr/sbin/sendmail
        smbclient    => /opt/bin/smbclient
        split        => /opt/bin/split    
        ssh/ssh2     => /opt/bin/ssh      
    
    --> Are these paths correct? [y]? n
    --> bzip2 path [/opt/bin/bzip2]?
    --> cat path [/opt/bin/cat]?
    --> df path [/opt/bin/df]?
    --> gtar/tar path [/opt/bin/tar]? /bin/tar
    --> gzip path [/opt/bin/gzip]?
    --> hostname path [/opt/bin/hostname]?
    --> nmblookup path [/opt/bin/nmblookup]?
    --> par2 path [/opt/bin/par2]?
    --> perl path [/opt/bin/perl]?
    --> ping path [/opt/bin/ping]?
    --> rsync path [/opt/bin/rsync]? /usr/bin/rsync
    --> sendmail path [/usr/sbin/sendmail]?
    --> smbclient path [/opt/bin/smbclient]?
    --> split path [/opt/bin/split]?
    --> ssh/ssh2 path [/opt/bin/ssh]?
    
    I found the following locations for these programs:
    
        bzip2        => /opt/bin/bzip2
        cat          => /opt/bin/cat
        df           => /opt/bin/df
        gtar/tar     => /bin/tar
        gzip         => /opt/bin/gzip
        hostname     => /opt/bin/hostname
        nmblookup    => /opt/bin/nmblookup
        par2         => /opt/bin/par2
        perl         => /opt/bin/perl
        ping         => /opt/bin/ping
        rsync        => /usr/bin/rsync
        sendmail     => /usr/sbin/sendmail
        smbclient    => /opt/bin/smbclient
        split        => /opt/bin/split
        ssh/ssh2     => /opt/bin/ssh
    
    --> Are these paths correct? [y]? 
    
    Please tell me the hostname of the machine that BackupPC will run on.
    
    --> BackupPC will run on host [DD-WRT]? 
    
    BackupPC should run as a dedicated user with limited privileges.  You
    need to create a user.  This user will need read/write permission on 
    the main data directory and read/execute permission on the install   
    directory (these directories will be setup shortly).                 
    
    The primary group for this user should also be chosen carefully.
    The data directories and files will have group read permission, 
    so group members can access backup files.                       
    
    --> BackupPC should run as user [backuppc]? root
    
    Please specify an install directory for BackupPC.  This is where the
    BackupPC scripts, library and documentation will be installed.      
    
    --> Install directory (full path) [/usr/local/BackupPC]? /opt/local/backuppc
    
    Please specify a data directory for BackupPC.  This is where all the
    PC backup data is stored.  This file system needs to be big enough to
    accommodate all the PCs you expect to backup (eg: at least several GB
    per machine).                                                        
    
    --> Data directory (full path) [/data/BackupPC]? /mnt/backuppc
    
    BackupPC can compress pool files, providing around a 40% reduction in pool
    size (your mileage may vary). Specify the compression level (0 turns      
    off compression, and 1 to 9 represent good/fastest to best/slowest).      
    The recommended values are 0 (off) or 3 (reasonable compression and speed).
    Increasing the compression level to 5 will use around 20% more cpu time    
    and give perhaps 2-3% more compression.                                    
    
    --> Compression level [3]? 
    
    BackupPC has a powerful CGI perl interface that runs under Apache.
    A single executable needs to be installed in a cgi-bin directory. 
    This executable needs to run as set-uid backuppc, or              
    it can be run under mod_perl with Apache running as user backuppc.
    
    Leave this path empty if you don't want to install the CGI interface.
    
    --> CGI bin directory (full path) []? /opt/share/www/backuppc/cgi-bin
    
    BackupPC's CGI script needs to display various GIF images that
    should be stored where Apache can serve them.  They should be 
    placed somewhere under Apache's DocumentRoot.  BackupPC also  
    needs to know the URL to access these images.  Example:       
    
        Apache image directory:  /usr/local/apache/htdocs/BackupPC
        URL for image directory: /BackupPC                        
    
    The URL for the image directory should start with a slash.
    
    --> Apache image directory (full path) []? /opt/share/www/backuppc
    --> URL for image directory (omit http://host; starts with '/') []? /backuppc
    
    Ok, we're about to:
    
      - install the binaries, lib and docs in /opt/local/backuppc,
      - create the data directory /mnt/backuppc,                  
      - create/update the config.pl file /opt/etc/backuppc/config.pl,
      - optionally install the cgi-bin interface.                    
    
    --> Do you want to continue? [y]? 
    Created /mnt/backuppc             
    Created /mnt/backuppc/pool        
    Created /mnt/backuppc/cpool       
    Created /mnt/backuppc/pc          
    Created /mnt/backuppc/trash       
    Created /opt/etc/backuppc         
    Created /opt/var/log/backuppc     
    Installing binaries in /opt/local/backuppc/bin
    Installing library in /opt/local/backuppc/lib 
    Installing images in /opt/share/www/backuppc  
    Making init.d scripts                         
    Installing docs in /opt/local/backuppc/doc    
    Installing config.pl and hosts in /opt/etc/backuppc
    /opt/bin/ping: illegal option -- w                 
    ?: not implemented                                 
    Installing cgi script BackupPC_Admin in /opt/share/www/backuppc/cgi-bin
    
    Ok, it looks like we are finished.  There are several more things you
    will need to do:                                                     
    
      - Browse through the config file, /opt/etc/backuppc/config.pl,
        and make sure all the settings are correct.  In particular, 
        you will need to set $Conf{CgiAdminUsers} so you have       
        administration privileges in the CGI interface.             
    
      - Edit the list of hosts to backup in /opt/etc/backuppc/hosts.
    
      - Read the documentation in /opt/local/backuppc/doc/BackupPC.html.
        Please pay special attention to the security section.           
    
      - Verify that the CGI script BackupPC_Admin runs correctly.  You might
        need to change the permissions or group ownership of BackupPC_Admin.
        If this is an upgrade and you are using mod_perl, you will need     
        to restart Apache.  Otherwise it will have stale code.              
    
      - BackupPC should be ready to start.  Don't forget to run it
        as user backuppc!  The installation also contains an      
        init.d/backuppc script that can be copied to /etc/init.d  
        so that BackupPC can auto-start on boot.  This will also enable
        administrative users to start the server from the CGI interface.
        See init.d/README.                                              
    
    Enjoy!
    

    BackupPC init.d script

    Now we create the BackupPC init.d script to automatically start and stop the service. For this, first create a file /opt/etc/init.d/S95backuppc with the following content:

    #!/bin/sh
    
    export PATH=/opt/bin:/opt/sbin:/opt/usr/sbin:$PATH
    export LD_LIBRARY_PATH=/opt/lib:/opt/usr/lib:$LD_LIBRARY_PATH
    
    NAME=backuppc
    
    start() {
        #
        # You can set the SMB share password here is you wish.  Otherwise
        # you should put it in the config.pl script.
        # If you put it here make sure this file has no read permissions
        # for normal users!  See the documentation for more information.
        #
        #BPC_SMB_PASSWD=
        #export BPC_SMB_PASSWD
        #
        /opt/local/backuppc/bin/BackupPC -d
    }
    
    stop() {
        killall -9 BackupPC
    }
    
    restart() {
        stop
        start
    }
    
    reload() {
        killall -1 BackupPC
    }
    
    if [ -z "$1" ] ; then
        case `echo "$0" | sed 's:^.*/\(.*\):\1:g'` in
            S??*) rc="start" ;;
            K??*) rc="stop" ;;
            *) rc="usage" ;;
        esac
    else
        rc="$1"
    fi
    
    case "$rc" in
      start)
            start
            ;;
      stop)
            stop
            ;;
      restart)
            restart
            ;;
      reload)
            reload
            ;;
      *)
            echo "Usage: $0 {start|stop|restart|reload}"
            exit 1
    esac
    
    exit $?
    

    Now we link the stop script to this.

    # cd /opt/etc/init.d/
    # ln -s S95backuppc K05backuppc
    

    Finally we enable backuppc and start it.

    # service backuppc on
    # service backuppc start
    

    Configuring Lighttpd for BackupPC

    If you do not want a web interface, this section can be ignored. But I highly recommend you get the web interface for BackupPC up and running as it eases administration a lot. For using the BackupPC web interface, we can use Lighttpd web server.

    • Lighttpd gets installed by default when you setup Optware. But it is disabled. Therefore first we enable and start it.
      # service lighttpd on
      # service lighttpd restart
      
    • The log directory for Lighttpd is /opt/var/log/lighttpd/. When I started Lighttpd, I found the error ‘Error “fdevent_init failed”‘ in /opt/var/log/lighttp/error.log. Luckily, I found the fix for this error at http://www.mattgibson.ca/2009/11/05/fix-dd-wrt-lighttpd-error-server-c-1105-fdevent_init-failed-on-asus-wl-500/. To fix this error, in /opt/etc/lighttpd/lighttpd.conf, change
      # server.event-handler = "freebsd-kqueue" # needed on OS X

      to

      server.event-handler = "poll" # needed on OS X

      Restart Lighttpd once you have made this change.

      # service lighttpd restart
      

      and visit http://<<ROUTER_IP>>:8081/ to make sure that the server is running properly (you should see a page which displays the message “lighttpd server is running.”).

    • Now we perform the below steps to enable BackupPC web interface (most of these steps have been taken from http://backuppc.wiki.sourceforge.net/Install+Backuppc+with+Lighttpd). These changes have to be done in /opt/etc/lighttpd/lighttpd.conf.

      Edit this section to enable the needed Lighttpd server modules (mod_auth, mod_cgi):

      ## modules to load
      # at least mod_access and mod_accesslog should be loaded
      # all other module should only be loaded if really neccesary
      # - saves some time
      # - saves memory
      server.modules              = (
      #                               "mod_rewrite",
      #                               "mod_redirect",
      #                               "mod_alias",
                                      "mod_access",
      #                               "mod_cml",
      #                               "mod_trigger_b4_dl",
                                      "mod_auth",
      #                               "mod_status",
      #                               "mod_setenv",
      #                               "mod_fastcgi",
      #                               "mod_proxy",
      #                               "mod_simple_vhost",
      #                               "mod_evhost",
      #                               "mod_userdir",
                                      "mod_cgi",
      #                               "mod_compress",
      #                               "mod_ssi",
      #                               "mod_usertrack",
      #                               "mod_expire",
      #                               "mod_secdownload",
      #                               "mod_rrdtool",
                                      "mod_accesslog" )
      

      Edit this section to add index.cgi as an authorized index file:

      # files to check for if .../ is requested
      index-file.names            = ( "index.php", "index.html",
                                      "index.htm", "default.htm",
                                      "lighttpd/index.html",
                                      "index.cgi" )
      

      Edit this section in your configuration file to assign cgi files to the perl binary:

      #### CGI module
      cgi.assign                 = ( ".pl"  => "/opt/bin/perl",
                                     ".cgi" => "/opt/bin/perl" )
      #
      

      Edit this section to password protect backuppc.

      #### auth module
      ## read authentication.txt for more info
      auth.backend               = "plain"
      auth.backend.plain.userfile = "/opt/etc/lighttpd/lighttpd.user"
      #auth.backend.plain.groupfile = "lighttpd.group"
      
      #auth.backend.ldap.hostname = "localhost"
      #auth.backend.ldap.base-dn  = "dc=my-domain,dc=com"
      #auth.backend.ldap.filter   = "(uid=$)"
      
      auth.require               = ( "/backuppc/" =>
                                     (
                                       "method"  => "basic",
                                       "realm"   => "BackupPC",
                                       "require" => "user=root"
                                     ),
      #                               "/server-config" =>
      #                               (
      #                                 "method"  => "digest",
      #                                 "realm"   => "download archiv",
      #                                 "require" => "valid-user"
      #                               )
                                   )
      

      You will have to create lighttpd.user which contains username and the cleartext password seperated by a colon. Each entry is terminated by a single newline. e.g.:

        agent007:secret
      

      See /opt/share/doc/lighttpd/authentication.txt for available authentication methods and backends.

    • Next link index.cgi to the BackupPC cgi script.
      # cd /opt/share/www/backuppc
      # ln -s cgi-bin/BackupPC_Admin index.cgi
      

      And finally restart Lighttpd.

      # service lighttpd restart
      
    • The BackupPC web interface should now be accessible at: http://<<ROUTER_IP>>:8081/backuppc/.

      Using Backuppc user (backuppc) instead of root

      Personally I find it convenient to run BackupPC as root and as I do not use the router for any other service, I do not see much of a security hassle. But some of you might want to run BackupPC as another less privileged user due to some reason. Kindly note that the below steps have not been tested and are here only to give you a basic direction to run BackupPC as another user.

      • First it should be noted that whenever you add a user/group, this information gets lost whenever the router reboots. Therefore we have to add the steps for creating a user/group in the router Startup script. In the router web interface, go to Administration->Commands->Startup and add the below lines at the top and restart the router.

        echo "backuppc:x:1000:" >> /tmp/etc/group
        echo "backuppc:x:1000:1000:BackupPC,,,:/mnt/backuppc:/bin/sh" >> /tmp/etc/passwd
        chgrp backuppc /tmp/etc/
        chmod g+rx /tmp/etc/
        
      • Now while performing installation of the BackupPC (refer section “Installing BackupPC” above), when it prompts for the user BackupPC should run as, just press enter and let it take the default username of “backuppc”.
      • Next for the BackupPC init.d script, replace the startup command

        /opt/local/backuppc/bin/BackupPC -d

        with

        su backuppc -c "/opt/local/backuppc/bin/BackupPC -d"
      • Lastly for configuring Lighttpd to serve the BackupPC web interface, you can follow the relevant steps in http://backuppc.wiki.sourceforge.net/Install+Backuppc+with+Lighttpd.
      • Making BackupPC consume lesser resources

        Here is a response I got from a post I made to BackupPC mailing list reg. making BackupPC consume lesser resources.

        On Thu, 2010-12-16 at 08:25 +0530, Rahul Amaram wrote:
        > > For example, I think that the BackupPC pooling mechanism while very 
        > > useful is resource-intensive. Is it possible to disable BackupPC pooling 
        > > or add such an option to BackupPC in the future releases?
        That's pretty much the core idea behind BackupPC.
        
        If you just want to reduce CPU load, disable compression in the pool,
        and enable rsync checksum caching. That will help a great deal.
        
        Regards,
        Tyler
        
  • SFTP Console Client with Recursive Download/Upload Support

    I often find it difficult to use ‘scp’ program because I don’t know the exact path to the directory in the destination server and I do not find ‘sftp’ program very useful because it does not support recursive downloads. Here are two programs which offer recursive downloads over sftp protocol:

    1. psftp provided by package putty-tools

    # psftp user@server
    psftp> get -r directory_to_download
    psftp> put -r directory_to_upload

    2. lftp provided by package lftp. It seems that lftp is much more advanced than psftp but the commands might be slightly different from the ones we use in ‘sftp’ program.

    # lftp sftp://user@server
    lftp> mirror directory_to_download
    lftp> mirror -R directory_to_upload

    And if you are looking for a really good sftp GUI client, then I highly recommend ‘Filezilla’.

    The best part is that all these tools are available in the Debian Lenny repo.