DSCAlarm:Router

From Oh Mad Lab
Revision as of 10:38, 3 August 2011 by Ohayden (talk | contribs) (→‎Copy Extras)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Customizing and Compiling the Firmware

Requirements

gcc g++ binutils patch bzip2 flex bison make gettext unzip ncurses (libncurses-dev) libz-dev 

Initial Checkout of Source

svn co https://svn.openwrt.org/openwrt/branches/whiterussian/

Customizing the Firmware

cd whiterussian/openwrt
make menuconfig
  • Select submenu "OpenWrt Package Selection":
  • Select submenu "Busybox Configuration --->"
  • Select submenu "Coreutils --->"
  • Select feature "stty"
  • Press ESC
  • Press ESC
  • Select feature "screen"
  • Select feature "arpwatch"
  • Select feature "bwm"
  • Select feature "nmap"
  • Select feature "rsync"
  • Select feature "tcpdump"
  • Select feature "wol"
  • Select feature "setserial"
  • Press ESC
  • Press ESC
  • Choose Yes to save

Building the Custom Firmware

*NOTE* If we are re-compiling, then do a 'make clean' before the next step.

make

Once complete, the file I want is the: openwrt-wrtsl54gs-squashfs.bin located in the ./bin directory. With the above packages selected, the build is 2,507,776 bytes.

Installing Firmware and Configuring the Router

Installing Firmware

  • Plug a network cable directly into the router (safer this way)
  • Login into web interface and turn on 'boot wait' (if anything happens boot wait will allow us to recover with tftp)
  • Use the web interface to upgrade the firmware
  • Open another tab on the brower and after about 5 minutes try getting to the web interface again (without closing the orginal tab)

If all goes well, then proceed to the next step, otherwise you may need to recover with tftp. I need to document this procedure the next time it happens to me.

Installing X-Wrt http://x-wrt.org/

  • ssh to the router, or telnet if you've not set a password yet
  • Add the X-Wrt package repository with this command:
echo "src X-Wrt http://download2.berlios.de/pub/xwrt/packages" >> /etc/ipkg.conf 
  • Refresh the package lists this command:
ipkg update 
  • Finally, install webif^2 via:
ipkg install http://ftp.berlios.de/pub/xwrt/webif_latest_stable.ipk
  • The router will reboot and the new web interface is loaded.

Initial X-Wrt Setup

  • Set host name
System->Settings->Host Name: <host_name>
  • Set timezone
System->Settings->Time Settings->Timezone: Pacific Time
  • Click Save
  • Enable cron
System->Cron->Cron Settings->Cron Daemon
  • Click Save
  • Set the password
System->Password->Password Change
  • Click Save
  • Install NAS package for WPA2/PSK support
System->Packages->non-free->nas
  • Setup network
Network->WAN-LAN:
 WAN Configuration
  Connection Type: None
 LAN Configuration
  LAN IP Address: 192.168.0.x
  Netmask: 255.255.255.0
  Default Gateway: 192.168.0.x
 LAN DNS Servers
  192.168.0.x
  • Click Save
  • Setup wireless network
Network->Wireless
 Wireless Configuration
  Wireless Interface: Enabled
  ESSID Braodcast: Show
  ESSID: <host_name>
  Channel: Auto
  Mode: Access Point
 Encryption Settings
  Encryption Type: WPA (PSK)
  WPA Mode: WPA2
  WPA PSK: <password_here>
  • Click Save
  • Setup host name
Network->Hosts
 Configured Hosts
  Host Names
   IP Address
    120.0.0.1 <host_name>
  • Click Save
  • Review and apply changes (buttons are in the lower right of the web interface)

Misc Configuration

  • Install libncurses (for screen)
ipkg install libncurses
  • Install sendmail / ssmtp (mini-sendmail was used, but it doesn't have authentication)
ipkg install ssmtp
  • Configure ssmtp
vim /etc/ssmtp/ssmtp.conf
root=<username here>@windstream.net
mailhub=smtp.windstream.net
AuthUser=<username here>@windstream.net
AuthPass=<password here>
rewriteDomain=crancho.com
hostname=crancho.com
FromLineOverride=YES
  • Install samba
ipkg install samba-server
/etc/init.d/samba enable
  • Install knockd
ipkg install knockd
  • Install USB hard drive support
ipkg install kmod-usb-ohci
ipkg install kmod-usb2
ipkg install kmod-usb-storage
ipkg install kmod-vfat
*Add "max_scsi_luns=8" to the end of the /etc/modules.d/60-usb-storage file.
reboot
  • Install EXT2/3 support for USB hard drive
ipkg install kmod-ext2 
ipkg install kmod-ext3
  • Mounting EXT3 USB hard drive
mount -t ext3 -o noatime /dev/scsi/host0/bus0/target0/lun0/part1 /mnt/disc0_1/

Copy Extras

  • cd \flc\wrt\extras\
  • scp -r * root@192.168.0.XXX:/
\extras\etc\
|          |-knockd.conf
|          |-\init.d\
|          |        |-S15serial
|          |        |-S55knockd
|          |        `-S61datetime
|          `-\samba\
|                  `-smb.conf
\sbin\
     `-\flc\
           |-allowssh.sh
           |-arpXBox360.sh
           |-backup.sh
           |-checkarp.sh
           |-checknetwork.sh
           |-emaillogs.sh
           |-mail_alarm.sh
           |-scanwifi.sh
           |-setip.sh
           `-who.sh
  • Add to cron:
vim /etc/crontabs/root
*/5  * * * * /sbin/flc/arpXBox360.sh          <--- Only needed on ORC
*/5  * * * * /sbin/flc/setip.sh
00   * * * * /sbin/flc/emaillogs.sh
01   * * * * /etc/init.d/S61datetime > /dev/null
00   1 * * 0 /sbin/flc/backup.sh > /dev/null
  • Change setip's ID
vim /sbin/flc/setip.sh

Fix Path

vi /etc/preinit
  • Search for PATH
/PATH   [ENTER]
  • Change the following:
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
  • to:
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/sbin/flc
  • Search again for PATH
n
  • Change the following:
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
  • to:
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/sbin/flc
vi /etc/profile
  • Search for PATH
/PATH   [ENTER]
  • Change the following:
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
  • to:
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/sbin/flc

Backup / Remote Logs

Since the router stores the logs in volatile memory, here how we save the alarm logging information for historical purposes.

  • Generate a key:
 dropbearkey -t rsa -f /sbin/flc/backup.key
  • It will output the public key as such:
 Will output 1024 bit rsa secret key to '/sbin/flc/backup.key'
 Generating key, this may take a while...
 Public key portion is:
 ssh-rsa XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 Fingerprint: md5 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
  • Copy the ssh-rsa XXX... line (include the ssh-rsa portion)
  • SSH into the backup server (obviously you need to have created an account, etc.)
  • Once in the backup server, cd into the .ssh and create a file called authorized_keys2 and paste the public key
  • Save the file and ensure that the authorized_keys2 file is chowned as 644 (-rw-r--r--)
  • Now you can test with the backup.sh (Don't forget to change the backup server name in the backup.sh script)

QoS

  • Install the QoS scripts:
 ipkg install qos-scripts

Optional

Adding a Web Cam with Motion Detection

Tricks and Tips

  • To control lights:
echo 1 > /proc/diag/led/ses_orange
echo f > /proc/diag/led/ses_orange
echo 0 > /proc/diag/led/ses_orange


Troubleshooting

Compiling Firmware Error #1

make[3]: *** [ZLib.o] Error 1
make[3]: Leaving directory `/home/ohayden/dev/whiterussian/openwrt/build_mipsel/lzma/SRC/7zip/Compress/LZMA_Lib'
make[2]: *** [/home/ohayden/dev/whiterussian/openwrt/build_mipsel/lzma/SRC/7zip/Compress/LZMA_Lib/liblzma.a] Error 2
make[2]: Leaving directory `/home/ohayden/dev/whiterussian/openwrt/target/lzma'
make[1]: *** [lzma-compile] Error 2
make[1]: Leaving directory `/home/ohayden/dev/whiterussian/openwrt/target'
make: *** [target/compile] Error 2

Solution

sudo apt-get install zlib1g-dev

Compiling Firmware Error #2

checking for GNU xgettext... configure: error:
  *** GNU gettext is required. The latest version
  *** is always available from ftp://ftp.gnu.org/gnu/gettext/.
make[2]: *** [/home/ohayden/dev/whiterussian/openwrt/build_mipsel/popt-1.7/.configured] Error 1
make[2]: Leaving directory `/home/ohayden/dev/whiterussian/openwrt/package/popt'
make[1]: *** [popt-compile] Error 2
make[1]: Leaving directory `/home/ohayden/dev/whiterussian/openwrt/package'
make: *** [package/compile] Error 2

Solution

sudo apt-get install gettext

Serial Problem

The serial port /dev/tts/1 is acting strange. Whenever I cat /dev/tts/1, it will sit there until I echo something into the port, which is normal behavior. As soon as I echo something into the port, it will spew a ton of white space and then what I echoed in an endless loop as if it keeps retrieving the same text over and over.

Another issue I had was if I sent a status packet "00191" two to three times in a row real fast then it would appear to freak out the IT-100 by resetting it.

Solution

  • Apparently my COM port wasn't setup properly and I resolved it with a bash script. See Setup COM Port.